protected virtual void Dispose(bool disposing) { if (!disposeValue) { if (disposing) { this.disposing = true; _dispatcher.Invoke(() => { _usbDevice.Dispose(); _context.Dispose(); }); } disposeValue = true; } }
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(); }
public void Dispose() { Console.WriteLine("Closing connection to Switch"); LibUsbContext.Dispose(); NX.Dispose(); }
public void Teardown() { TrezorManager?.Dispose(); TrezorManager = null; _UsbContext?.Dispose(); }
static void Main(string[] args) { Console.WriteLine("UsbStream - 2.0 by exelix"); Console.WriteLine("https://github.com/exelix11/SysDVR \r\n"); if (args.Length < 3) { PrintGuide(); return; } IOutTarget VTarget = null; IOutTarget ATarget = null; bool PrintStats = false; bool DesyncFix = false; LogLevel UsbLogLevel = LogLevel.Error; void ParseTargetArgs(int baseIndex, ref IOutTarget t) { switch (args[baseIndex + 1]) { case "mpv": case "stdin": { string fargs = ""; if (args[baseIndex + 1] == "mpv") { fargs = args[baseIndex] == "video" ? "- --no-correct-pts --fps=30 " : "- --no-video --demuxer=rawaudio --demuxer-rawaudio-rate=48000 "; } if (args.Length > baseIndex + 4 && args[baseIndex + 3] == "args") { fargs += args[baseIndex + 4]; } t = new StdInTarget(args[baseIndex + 2], fargs); break; } case "tcp": { int port = int.Parse(args[baseIndex + 2]); Console.WriteLine($"Waiting for a client to connect on {port} ..."); t = new TCPTarget(System.Net.IPAddress.Any, port); break; } case "file": t = new OutFileTarget(args[baseIndex + 2]); break; default: throw new Exception($"{args[baseIndex + 1]} is not a valid video mode"); } } bool HasArg(string arg) => Array.IndexOf(args, arg) != -1; { int index = Array.IndexOf(args, "video"); if (index >= 0) { ParseTargetArgs(index, ref VTarget); } index = Array.IndexOf(args, "audio"); if (index >= 0) { ParseTargetArgs(index, ref ATarget); } DesyncFix = HasArg("--desync-fix"); PrintStats = HasArg("--print-stats"); if (HasArg("--usb-warn")) { UsbLogLevel = LogLevel.Info; } if (HasArg("--usb-debug")) { UsbLogLevel = LogLevel.Debug; } } if (VTarget == null && ATarget == null) { 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 (VTarget != null) { Video = new VideoStreamThread(StopThreads.Token, VTarget, stream.OpenStreamDefault(), PrintStats, DesyncFix); } AudioStreamThread Audio = null; if (ATarget != null) { Audio = new AudioStreamThread(StopThreads.Token, ATarget, stream.OpenStreamAlt(), PrintStats); } Video?.StartThread(); Audio?.StartThread(); Console.WriteLine("Starting stream, press return to stop"); Console.ReadLine(); Console.WriteLine("Terminating threads..."); StopThreads.Cancel(); Video?.JoinThread(); Audio?.JoinThread(); Video?.Dispose(); Audio?.Dispose(); LibUsbCtx.Dispose(); }