Пример #1
0
        void InitGStreamerPipeline()
        {
            _mainLoop       = new GLib.MainLoop();
            _mainGlibThread = new System.Threading.Thread(_mainLoop.Run);
            _mainGlibThread.Start();

            _pipeline = CreatePipeline("camera-pipeline");
            Assert(_pipeline != null, "Pipeline could not be created");

            _pipeline.Bus.EnableSyncMessageEmission();
            _pipeline.Bus.SyncMessage += OnBusSyncMessage;
            _pipeline.Bus.AddWatch(OnBusMessage);

            _devMon = new DeviceMonitor();
            var caps   = new Caps("video/x-raw");
            var filtId = _devMon.AddFilter("Video/Source", caps);

            foreach (var d in _devMon.Devices.Select(d => d.DisplayName))
            {
                _devices.Add(d);
            }

            var cam = _devMon.Devices.FirstOrDefault(d => d.DeviceClass == "Video/Source");

            if (cam != null)
            {
                ShowCamera(cam.DisplayName);
            }

            Assert(_devMon.Start(), "Device monitor cannot start");
            _devMon.Bus.AddWatch(OnBusMessage);
        }
Пример #2
0
        public static void Run(string[] args)
        {
            Application.Init(ref args);
            GtkSharp.GstreamerSharp.ObjectManager.Initialize();

            _pipeline = CreatePipeline("cam_pipeline");

            var bus = _pipeline.Bus;

            bus.AddWatch(OnBusMessage);

            _devMon = new DeviceMonitor();
            var caps   = new Caps("video/x-raw");
            var filtId = _devMon.AddFilter("Video/Source", caps);

            if (!_devMon.Start())
            {
                "Device monitor cannot start".PrintErr();
                return;
            }

            if (_devMon.Devices.Length == 0)
            {
                Console.WriteLine("No video sources");
            }
            else
            {
                Console.WriteLine($"Video devices count = {_devMon.Devices.Length}");
                foreach (var dev in _devMon.Devices)
                {
                    DumpDevice(dev);
                }
                var cam = _devMon.Devices.FirstOrDefault(d => d.DeviceClass == "Video/Source");
                if (cam != null)
                {
                    Console.WriteLine("Cam found");
                    ShowCamera(cam.DisplayName);
                }
            }

            var devMonBus = _devMon.Bus;

            devMonBus.AddWatch(OnBusMessage);

            var loop = new GLib.MainLoop();

            loop.Run();
        }