Skip to content

Instantly share code, notes, and snippets.

@moritzuehling
Created January 21, 2018 21:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save moritzuehling/7f201a1b3c3f19734d674cc0cd2a4554 to your computer and use it in GitHub Desktop.
Save moritzuehling/7f201a1b3c3f19734d674cc0cd2a4554 to your computer and use it in GitHub Desktop.
#define _CRT_SECURE_NO_WARNINGS
#include <chrono>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <sstream>
#include <string>
#include <fstream>
#include <Windows.h>
#include "genvid.h";
GenvidStatus GS;
void checkGS(char* gs)
{
if (GS == GenvidStatus_Success)
{
std::cout << "[GV_CALL] " << gs << " suceeded!" << std::endl;
}
else
{
std::cout << "[GV_CALL] " << gs << " failed!" << std::endl;
}
}
void generateImage(uint8_t* data)
{
for (int x = 0; x < 1280; x++)
{
for (int y = 0; y < 720; y++)
{
int firstPixel = (x + (y * 1280)) * 3;
data[firstPixel + 0] = 255; //(uint8_t)(255 - (x / 1280.0f) * 255);
data[firstPixel + 1] = 0;//(uint8_t)((y / 720.0f) * 255);
data[firstPixel + 2] = 255; (uint8_t)((sin(3.14159 * 2 * x / 720.0) + 1) * 127);
}
}
}
const char* VIDEO = "video";
const char* AUDIO = "audio";
int WINAPI wWinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _In_ LPWSTR lpCmdLine, _In_ int nCmdShow)
{
AllocConsole();
freopen("conin$", "r", stdin);
freopen("conout$", "w", stdout);
freopen("conout$", "w", stderr);
GS = Genvid_Initialize();
checkGS("Initialize");
GS = Genvid_CreateStream(AUDIO);
checkGS("CreateStream(AUDIO)");
GS = Genvid_SetParameterInt(AUDIO, "Audio.Source.WASAPI", 1);
checkGS("SetParameter(AUDIO, \"Audio.Source.WASAPI\", 1)");
GS = Genvid_CreateStream(VIDEO);
checkGS("CreateStream(VIDEO)");
GS = Genvid_SetParameterInt(VIDEO, "framerate", 60);
checkGS("Genvid_SetParameterInt(VIDEO, \"framerate\", 60)");
GS = Genvid_SetParameterInt(VIDEO, "video.width", 1280);
checkGS("Genvid_SetParameterInt(VIDEO, \"video.width\", 1280)");
GS = Genvid_SetParameterInt(VIDEO, "video.height", 720);
checkGS("Genvid_SetParameterInt(VIDEO, \"video.height\", 720)");
GS = Genvid_SetParameterInt(VIDEO, "video.pixel_format", GenvidPixelFormat_R8G8B8);
checkGS("Genvid_SetParameterInt(VIDEO, \"video.pixel_format\", GenvidPixelFormat_R8G8B8);");
uint8_t* data = new uint8_t[1280 * 720 * 3];
generateImage(data);
LARGE_INTEGER StartingTime, EndingTime, ElapsedMicroseconds;
LARGE_INTEGER Frequency;
QueryPerformanceFrequency(&Frequency);
while (true)
{
QueryPerformanceCounter(&StartingTime);
GS = Genvid_SubmitVideoData(-1, VIDEO, data, 1280 * 720 * 3);
QueryPerformanceCounter(&EndingTime);
ElapsedMicroseconds.QuadPart = EndingTime.QuadPart - StartingTime.QuadPart;
ElapsedMicroseconds.QuadPart *= 1000;
ElapsedMicroseconds.QuadPart /= Frequency.QuadPart;
if (ElapsedMicroseconds.QuadPart > 4)
{
printf("Slow Genvid_SubmitVideoData(%d ms)\n", ElapsedMicroseconds.QuadPart);
}
if (GS != GenvidStatus_Success)
checkGS("Genvid_SubmitVideoData(-1, VIDEO, data, 1280 * 720 * 3)");
Sleep(15);
}
Genvid_Terminate();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment