-
-
Save moritzuehling/5b0378d69f11d9c7dbe39cd4fb9fa8b1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
int toSleep = Math.Max(0, (int)(nextFrame - watch.ElapsedMilliseconds)); | |
var ts1 = watch.ElapsedMilliseconds; | |
Thread.Sleep(toSleep); | |
var ts2 = watch.ElapsedMilliseconds; | |
if (ts2 - ts1 > 16) | |
Console.WriteLine("Sleep took {0}ms", ts2 - ts1); | |
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)); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SubmitVideoData took 33ms | |
Sleep took 19ms | |
SubmitVideoData took 21ms | |
Sleep took 17ms | |
Sleep took 18ms | |
SubmitVideoData took 17ms | |
Sleep took 18ms | |
SubmitVideoData took 19ms | |
SubmitVideoData took 18ms | |
SubmitVideoData took 26ms | |
SubmitVideoData took 17ms | |
SubmitVideoData took 40ms | |
SubmitVideoData took 32ms | |
SubmitVideoData took 21ms | |
Sleep took 19ms | |
SubmitVideoData took 21ms | |
Sleep took 37ms | |
SubmitVideoData took 18ms | |
SubmitVideoData took 30ms | |
Sleep took 19ms | |
Sleep took 17ms | |
SubmitVideoData took 19ms | |
Sleep took 17ms | |
SubmitVideoData took 26ms | |
Sleep took 28ms | |
SubmitVideoData took 20ms | |
SubmitVideoData took 19ms | |
SubmitVideoData took 21ms | |
SubmitVideoData took 17ms | |
Sleep took 28ms |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment