static void StartManagedStreaming(IMutliStreamManager Streams, string[] args) { Console.WriteLine("If the stream lags try pausing and unpausing the player."); Streams.Begin(); Console.ReadLine(); Console.WriteLine("Terminating threads..."); Streams.Stop(); Streams.Dispose(); }
static void StartUsbStreaming(IMutliStreamManager Streams, string[] args) { bool PrintStats = false; LogLevel UsbLogLevel = LogLevel.Error; bool HasArg(string arg) => Array.IndexOf(args, arg) != -1; if (HasArg("--desync-fix")) { Console.WriteLine("Warning: the --desync-fix fix option has been deprecated and will be ignored"); } PrintStats = HasArg("--print-stats"); if (HasArg("--usb-warn")) { UsbLogLevel = LogLevel.Info; } if (HasArg("--usb-debug")) { UsbLogLevel = LogLevel.Debug; } if (Streams == null || !Streams.HasAStream) { Console.WriteLine("Specify at least a video or audio target"); return; } var stream = GetDevice(UsbLogLevel); if (stream == null) { Console.WriteLine("Device not found, did you configure the drivers properly ?"); return; } CancellationTokenSource StopThreads = new CancellationTokenSource(); VideoStreamThread Video = null; if (Streams.Video != null) { Video = new VideoStreamThread(StopThreads.Token, Streams.Video, stream.OpenStreamDefault(), PrintStats); } AudioStreamThread Audio = null; if (Streams.Audio != null) { Audio = new AudioStreamThread(StopThreads.Token, Streams.Audio, stream.OpenStreamAlt(), PrintStats); } Video?.Start(); Audio?.Start(); //If streaming via RTSP use managed streaming, this part should be reworked in the future, maybe using "managed streams" only if (Streams is RTSP.SysDvrRTSPServer || Streams is TCPBridgeManager) { StartManagedStreaming(Streams, null); } else { Streams.Begin(); Console.WriteLine("If the stream lags press Q to force a resync"); ConsoleKey c; while ((c = Console.ReadKey().Key) != ConsoleKey.Enter) { if (c == ConsoleKey.Q) { Console.WriteLine("Pausing streams for 3 seconds to flush buffer data"); Video?.Pause(); Audio?.Pause(); Thread.Sleep(3000); Video?.Resume(); Audio?.Resume(); } } Console.WriteLine("Terminating threads..."); Streams.Stop(); Streams.Dispose(); } StopThreads.Cancel(); Video?.Join(); Audio?.Join(); Video?.Dispose(); Audio?.Dispose(); LibUsbCtx.Dispose(); }