コード例 #1
0
ファイル: ServerSession.cs プロジェクト: krisives/GRemote
        /// <summary>
        /// Stops the server from capturing, encoding video, and all network activity. It's
        /// safe to stop a server more than once.
        /// </summary>
        public void StopServer()
        {
            if (!IsRunning)
            {
                return;
            }

            lock (this)
            {
                running = false;
            }

            if (videoCapture != null)
            {
                videoCapture.StopCapturing();
                videoCapture = null;
            }

            if (videoEncoder != null)
            {
                videoEncoder.StopEncoding();
                videoEncoder = null;
            }

            if (socket != null)
            {
                socket.Close();
                socket = null;
            }

            if (outputBuffers != null)
            {
                outputBuffers.Clear();
            }

            if (readThread != null)
            {
                readThread.Stop();
                readThread = null;
            }

            if (writeThread != null)
            {
                writeThread.Stop();
                writeThread = null;
            }

            if (listenThread != null)
            {
                listenThread.Stop();
                listenThread = null;
            }

            if (inputPlayback != null)
            {
                inputPlayback.StopPlayback();
                inputPlayback = null;
            }

            outputBuffers = new BufferPool();
        }
コード例 #2
0
ファイル: ServerSession.cs プロジェクト: krisives/GRemote
        /// <summary>
        /// Starts the server. This begins the video capture, encoding, and network
        /// processes. It's safe to start a server more than once.
        /// </summary>
        public void StartServer()
        {
            if (IsRunning)
            {
                return;
            }

            lock (this)
            {
                running = true;
            }

            // Start the listening socket
            socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

            // Begin the capture and encoding process
            videoCapture.Listener = Snapshot;
            inputPlayback = new InputPlayback();

            videoEncoder = new VideoEncoder(ffmpeg, videoCapture.Width, videoCapture.Height);

            if (settings.FileOutputEnabled)
            {
                videoEncoder.EnableFileOutput(settings.FileOutputPath);
            }

            videoEncoder.StartEncoding(settings.EncoderSettings);

            // Create networking threads
            listenThread = new ServerListenThread(this, clients, socket);
            readThread = new ServerReadThread(this);
            writeThread = new ServerWriteThread(this, outputBuffers, clients, killList);

            // Start networking threads
            listenThread.Start();
            readThread.Start();
            writeThread.Start();

            videoCapture.StartCapturing();
            inputPlayback.StartPlayback();
        }