Skip to content

Instantly share code, notes, and snippets.

@moritzuehling
Last active January 21, 2018 21:09
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/b52a909b2bdbd8c9664170617613a3c0 to your computer and use it in GitHub Desktop.
Save moritzuehling/b52a909b2bdbd8c9664170617613a3c0 to your computer and use it in GitHub Desktop.
const string AudioStream = "Audio";
const string VideoStream = "Video";
static int Width = 1280, Height = 720, FPS = 60;
public static void StartStream()
{
Check(GenvidSDK.Initialize());
Check(GenvidSDK.CreateStream(AudioStream));
Check(GenvidSDK.SetParameter(AudioStream, "Audio.Source.WASAPI", 1));
Check(GenvidSDK.CreateStream(VideoStream));
Check(GenvidSDK.SetParameter(VideoStream, "framerate", FPS));
Check(GenvidSDK.SetParameter(VideoStream, "video.width", Width));
Check(GenvidSDK.SetParameter(VideoStream, "video.height", Height));
Check(GenvidSDK.SetParameter(VideoStream, "video.pixel_format", (int)GenvidSDK.PixelFormat.R8G8B8));
byte[] data = new byte[Width * Height * 3];
for (int x = 0; x < data.Length; x += 3)
{
data[x + 0] = 255;
data[x + 1] = 0;
data[x + 2] = 128;
}
Stopwatch watch = new Stopwatch();
watch.Start();
var nextFrame = 0.0;
while (true)
{
while (watch.Elapsed.TotalMilliseconds > nextFrame)
nextFrame += (1000.0 / FPS);
while (nextFrame > watch.Elapsed.TotalMilliseconds)
{
// busy-wait until it's our turn to submit.
}
var t1 = watch.ElapsedMilliseconds;
Check(GenvidSDK.SubmitVideoData(-1, VideoStream, data));
var t2 = watch.ElapsedMilliseconds;
if (t2 - t1 > 16)
Console.WriteLine("SubmitVideoData took {0}ms", t2 - t1);
}
}
private static void Check(GenvidSDK.Status result)
{
if (result != GenvidSDK.Status.Success)
throw new Exception(string.Format("Genvid error: ({0}): {1}", (int)result, result));
}
SubmitVideoData took 18ms
SubmitVideoData took 17ms
SubmitVideoData took 17ms
SubmitVideoData took 18ms
SubmitVideoData took 18ms
SubmitVideoData took 17ms
SubmitVideoData took 19ms
SubmitVideoData took 29ms
SubmitVideoData took 27ms
SubmitVideoData took 17ms
SubmitVideoData took 47ms
SubmitVideoData took 44ms
SubmitVideoData took 30ms
SubmitVideoData took 18ms
SubmitVideoData took 17ms
SubmitVideoData took 18ms
SubmitVideoData took 29ms
SubmitVideoData took 22ms
SubmitVideoData took 26ms
SubmitVideoData took 20ms
SubmitVideoData took 17ms
SubmitVideoData took 23ms
SubmitVideoData took 18ms
SubmitVideoData took 17ms
SubmitVideoData took 30ms
SubmitVideoData took 20ms
SubmitVideoData took 19ms
SubmitVideoData took 17ms
SubmitVideoData took 32ms
SubmitVideoData took 19ms
SubmitVideoData took 26ms
SubmitVideoData took 43ms
SubmitVideoData took 18ms
SubmitVideoData took 17ms
SubmitVideoData took 21ms
SubmitVideoData took 23ms
SubmitVideoData took 17ms
SubmitVideoData took 17ms
SubmitVideoData took 24ms
SubmitVideoData took 21ms
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment