コード例 #1
0
        public void Start()
        {
            lock (_syncRoot)
            {
                if (IsStreaming)
                {
                    return;
                }

                _streamingServer = new MJpegStreamingServer(Port);
                _streamingServer.Start();

                _device = GetCameraDevice();
                if (_device != null)
                {
                    _device.NewFrameEvent += OnNewFrame;
                    _device.Start();

                    string address = LocalMachine.HostName;
                    int    port    = int.Parse(_device.VideoSource.Source);
                    StartStream(_device, address, port);
                }

                IsStreaming = true;
            }
        }
コード例 #2
0
        private void OnNewFrame(object sender, EventArgs e)
        {
            MJpegStreamingServer server = _streamingServer;

            if (server != null)
            {
                lock (_syncSteamingFrame)
                {
                    if (_device != null)
                    {
                        Bitmap origin = _device.LastFrame;

                        if (origin != null)
                        {
                            Bitmap frame = origin.Clone() as Bitmap;

                            if (frame != null)
                            {
                                server.Write(frame);
                            }
                        }
                    }
                }
            }
        }
コード例 #3
0
        public void Stop()
        {
            lock (_syncRoot)
            {
                if (!IsStreaming)
                {
                    return;
                }

                if (_device != null)
                {
                    try
                    {
                        string address = LocalMachine.HostName;
                        int    port    = int.Parse(_device.VideoSource.Source);
                        StopStream(_device, address, port);

                        _device.NewFrameEvent -= OnNewFrame;
                        _device.Stop();
                    }
                    catch { }
                    _device = null;
                }

                if (_streamingServer != null)
                {
                    try
                    {
                        _streamingServer.Stop();
                    }
                    catch { }
                    _streamingServer = null;
                }

                IsStreaming = false;
            }
        }