/// <summary> /// Stop the encoding process. It's safe to stop the encoder more than /// once. /// </summary> public void StopEncoding() { if (!IsEncoding) { return; } lock (this) { started = false; } frameBuffers.Clear(); encodedBuffers.Clear(); try { process.StandardInput.Close(); process.StandardError.Close(); process.Close(); } catch (Exception e) { Console.WriteLine(e); } process = null; if (readThread != null) { readThread.Stop(); readThread = null; } if (writeThread != null) { writeThread.Stop(); writeThread = null; } if (errorThread != null) { errorThread.Stop(); errorThread = null; } }
/// <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(); }
public void StartEncoding(EncoderSettings settings) { if (IsEncoding) { return; } lock (this) { started = true; } totalBytes = 0; frameBuffers.Clear(); // Create new buffer pools in case threads are still doing things frameBuffers = new BufferPool(); encodedBuffers = new BufferPool(); process = new Process(); process.StartInfo.Arguments = GetFFMpegArguments(settings); process.StartInfo.FileName = ffmpeg.Path; process.StartInfo.RedirectStandardInput = true; process.StartInfo.RedirectStandardError = true; process.StartInfo.RedirectStandardOutput = true; process.StartInfo.UseShellExecute = false; process.StartInfo.CreateNoWindow = true; process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; process.Start(); readThread = new VideoEncoderReadThread(this, process, encodedBuffers); writeThread = new VideoEncoderWriteThread(this, process, frameBuffers); errorThread = new VideoEncoderErrorThread(this, process); errorThread.Start(); readThread.Start(); writeThread.Start(); }
/// <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(); }