Exemplo n.º 1
0
 public UsbStreamingSourceBase(StreamKind kind)
 {
     (reader, writer) = UsbHelper.GetForInterface(kind);
 }
Exemplo n.º 2
0
 public void StopStreaming()
 {
     UsbHelper.MarkInterfaceClosed();
 }
Exemplo n.º 3
0
        static void Main(string[] args)
        {
            bool HasArg(string arg) => Array.IndexOf(args, arg) != -1;

            bool StreamStdout = HasArg("--stdout");

            if (StreamStdout)
            {
                Console.SetOut(Console.Error);
            }

            Console.WriteLine($"SysDVR-Client - {VersionString()} by exelix");
            Console.WriteLine("https://github.com/exelix11/SysDVR \r\n");
            if (args.Length < 1)
            {
                PrintGuide(false);
            }
            else if (args[0].Contains("help"))
            {
                PrintGuide(true);
                return;
            }

            BaseStreamManager StreamManager;
            bool NoAudio, NoVideo;

            string ArgValue(string arg)
            {
                int index = Array.IndexOf(args, arg);

                if (index == -1)
                {
                    return(null);
                }
                if (args.Length <= index + 1)
                {
                    return(null);
                }
                return(args[index + 1]);
            }

            int?ArgValueInt(string arg)
            {
                var a = ArgValue(arg);

                if (int.TryParse(a, out int res))
                {
                    return(res);
                }
                return(null);
            }

            if (HasArg("--usb-warn"))
            {
                UsbHelper.LogLevel = LogLevel.Info;
            }
            if (HasArg("--usb-debug"))
            {
                UsbHelper.LogLevel = LogLevel.Debug;
            }

            NoAudio = HasArg("--no-audio");
            NoVideo = HasArg("--no-video");
            StreamingThread.Logging = HasArg("--print-stats");
            UsbHelper.ForceLibUsb   = HasArg("--no-winusb");

            if (NoVideo && NoAudio)
            {
                Console.WriteLine("Specify at least a video or audio target");
                return;
            }

            if (HasArg("--mpv"))
            {
                string mpvPath = ArgValue("--mpv");
                if (mpvPath == null || !File.Exists(mpvPath))
                {
                    Console.WriteLine("The specified mpv path is not valid");
                    return;
                }
                if (!NoVideo && !NoAudio)
                {
                    NoAudio = true;
                }
                StreamManager = new MpvStdinManager(NoAudio ? StreamKind.Video : StreamKind.Audio, mpvPath);
            }
            else if (StreamStdout)
            {
                if (!NoVideo && !NoAudio)
                {
                    NoAudio = true;
                }
                StreamManager = new StdOutManager(NoAudio ? StreamKind.Video : StreamKind.Audio);
            }
            else if (HasArg("--file"))
            {
                string diskPath = ArgValue("--file").Replace("\"", "");
                if (diskPath == null || !Directory.Exists(diskPath))
                {
                    Console.WriteLine("The specified directory is not valid");
                    return;
                }
                StreamManager = new SaveToDiskManager(!NoVideo, !NoAudio, diskPath);
            }
            else             // use RTSP by default
            {
                int port = ArgValueInt("--rtsp-port") ?? 6666;
                if (port <= 1024)
                {
                    Console.WriteLine("Warning: ports lower than 1024 are usually reserved and may require administrator/root privileges");
                }
                StreamManager = new RTSP.SysDvrRTSPManager(!NoVideo, !NoAudio, !HasArg("--rtsp-any-addr"), port);
            }

            if (args.Length == 0 || args[0].ToLower() == "usb")
            {
                if (!NoVideo)
                {
                    StreamManager.VideoSource = UsbHelper.MakeStreamingSource(StreamKind.Video);
                }
                if (!NoAudio)
                {
                    StreamManager.AudioSource = UsbHelper.MakeStreamingSource(StreamKind.Audio);
                }
            }
            else if (args[0].ToLower() == "bridge")
            {
                if (args.Length < 2)
                {
                    Console.WriteLine("Specify an ip address for bridge mode");
                    return;
                }

                string ip = args[1];

                if (!NoVideo)
                {
                    StreamManager.VideoSource = new TCPBridgeSource(ip, StreamKind.Video);
                }
                if (!NoAudio)
                {
                    StreamManager.AudioSource = new TCPBridgeSource(ip, StreamKind.Audio);
                }
            }
            else
            {
                Console.WriteLine("Invalid source");
                return;
            }

            StartStreaming(StreamManager);
        }