// Pause the capture graph. public void Stop() { // Can only Stop when playing or paused if (m_State == GraphState.Running || m_State == GraphState.Paused) { int hr = m_mediaCtrl.Stop(); DsError.ThrowExceptionForHR(hr); m_State = GraphState.Stopped; } }
public void Stop(TrackCompletionReason reason, int?newTrackIndex) { var hr = 0; var pos = CurrentPositionTicks; // Stop media playback if (_mediaControl != null) { hr = _mediaControl.Stop(); } DsError.ThrowExceptionForHR(hr); OnStopped(reason, pos, newTrackIndex); }
bool ProcessSample(IntPtr pBuffer, int dataLen, double sampleTime) { // not initialized if (null == transcoder) { return(true); } if (sampleTime < 0) { sampleTime = 0; } if ((null == sampleBuffer) || (sampleBuffer.Length != dataLen)) { sampleBuffer = new byte[dataLen]; } Marshal.Copy(pBuffer, sampleBuffer, 0, dataLen); MediaSample inputSample = new MediaSample(); inputSample.Buffer = new MediaBuffer(sampleBuffer); inputSample.StartTime = sampleTime; System.Diagnostics.Debug.WriteLine(string.Format("transcoder.Push(stream: {0}, sampleTime: {1}, sampleData: {2})", transcoderInputIndex, inputSample.StartTime, inputSample.Buffer.DataSize)); // transcoder.Push() is not threads safe. // lock (transcoder){ } ensure that only one thread is calling transcoder.Push() lock (transcoder) { if (!transcoder.Push(transcoderInputIndex, inputSample)) { transcoderError = transcoder.Error.Clone() as ErrorInfo; System.Threading.ThreadPool.QueueUserWorkItem(delegate { // call mediaControl.Stop() from a new thread otherwise it will deadlock int hr = mediaControl.Stop(); }, null); return(false); } } return(true); }
/// <summary> Shut down capture </summary> private void CloseInterfaces() { int hr; try { if (m_mediaCtrl != null) { // Stop the graph hr = m_mediaCtrl.Stop(); m_bRunning = false; } } catch (Exception ex) { Debug.WriteLine(ex); } if (m_graphBuilder != null) { Marshal.ReleaseComObject(m_graphBuilder); m_graphBuilder = null; } }