void IRecorder.Start(string filename)
        {
            IStreamBufferSink sink = this.streamBufferSink as IStreamBufferSink;

            object pRecUnk;
            //int hr = sink.CreateRecorder(filename, RecordingType.Reference, out pRecUnk);
            int hr = sink.CreateRecorder(filename, RecordingType.Content, out pRecUnk);

            if (hr >= 0)
            {
                long rtStart = 0;
                //IStreamBufferMediaSeeking mediaSeeking = this.streamBufferSource as IStreamBufferMediaSeeking;
                //if (mediaSeeking != null)
                //{
                //    // Reference time (100-nanosecond units). 100 * 10e-9 = 10e-7 = 10000000
                //    mediaSeeking.GetCurrentPosition(out rtStart);
                //}

                // Start the recording.
                this.currentRecorderControl = pRecUnk as IStreamBufferRecordControl;
                //long rtStart = -10000000; // Start 1 seconds ago.
                hr = this.currentRecorderControl.Start(ref rtStart);
                DsError.ThrowExceptionForHR(hr);

                IsPossibleRecorderStart = false;
                IsPossibleRecorderStop  = true;
            }
        }
        private void Configure()
        {
            // In order to lock a profile, you have to have at least one stream
            // connected to the sink. I connect a video thru the DVVideoEnc into
            // the StreamBufferSink.
            const string FileName = "delme.out";

            int         hr;
            IBaseFilter pFilter;

            ICaptureGraphBuilder2 icgb = (ICaptureGraphBuilder2) new CaptureGraphBuilder2();
            StreamBufferSink      sbk  = new StreamBufferSink();

            m_FilterGraph = (IFilterGraph2) new FilterGraph();
            DsROTEntry ds = new DsROTEntry(m_FilterGraph);

            hr = icgb.SetFiltergraph(m_FilterGraph);
            DsError.ThrowExceptionForHR(hr);

            hr = m_FilterGraph.AddFilter((IBaseFilter)sbk, "StreamBufferSink");
            DsError.ThrowExceptionForHR(hr);

            DsDevice [] devs = DsDevice.GetDevicesOfCat(FilterCategory.VideoInputDevice);
            hr = m_FilterGraph.AddSourceFilterForMoniker(devs[0].Mon, null, devs[0].Name, out pFilter);
            DsError.ThrowExceptionForHR(hr);

            DVVideoEnc  dve         = new DVVideoEnc();
            IBaseFilter ibfVideoEnc = (IBaseFilter)dve;

            hr = m_FilterGraph.AddFilter(ibfVideoEnc, "dvenc");
            DsError.ThrowExceptionForHR(hr);

            hr = icgb.RenderStream(null, null, pFilter, ibfVideoEnc, (IBaseFilter)sbk);
            DsError.ThrowExceptionForHR(hr);

            Marshal.ReleaseComObject(pFilter);
            Marshal.ReleaseComObject(icgb);

            IStreamBufferSink isbc = (IStreamBufferSink)sbk;

            hr = isbc.LockProfile("delme.prf");
            DsError.ThrowExceptionForHR(hr);

            File.Delete(FileName);

            object o;

            hr = isbc.CreateRecorder("delme.out", RecordingType.Reference, out o);
            DsError.ThrowExceptionForHR(hr);

            m_sbrc = (IStreamBufferRecordControl)o;

            hr = ((IMediaControl)m_FilterGraph).Run();
            DsError.ThrowExceptionForHR(hr);
        }
        void IRecorder.Stop()
        {
            if (this.currentRecorderControl != null)
            {
                int hr = this.currentRecorderControl.Stop(0);                 // Stop the recording and close the file.
                Marshal.ReleaseComObject(this.currentRecorderControl);
                this.currentRecorderControl = null;
                DsError.ThrowExceptionForHR(hr);

                IsPossibleRecorderStart = true;
                IsPossibleRecorderStop  = false;
            }
        }
        void IRecorder.Stop()
        {
            if (this.currentRecorderControl != null)
            {
                int hr = this.currentRecorderControl.Stop(0); // Stop the recording and close the file.
                Marshal.ReleaseComObject(this.currentRecorderControl);
                this.currentRecorderControl = null;
                DsError.ThrowExceptionForHR(hr);

                IsPossibleRecorderStart = true;
                IsPossibleRecorderStop = false;
            }
        }
        void IRecorder.Start(string filename)
        {
            IStreamBufferSink sink = this.streamBufferSink as IStreamBufferSink;

            object pRecUnk;
            //int hr = sink.CreateRecorder(filename, RecordingType.Reference, out pRecUnk);
            int hr = sink.CreateRecorder(filename, RecordingType.Content, out pRecUnk);
            if (hr >= 0)
            {
                long rtStart = 0;
                //IStreamBufferMediaSeeking mediaSeeking = this.streamBufferSource as IStreamBufferMediaSeeking;
                //if (mediaSeeking != null)
                //{
                //    // Reference time (100-nanosecond units). 100 * 10e-9 = 10e-7 = 10000000
                //    mediaSeeking.GetCurrentPosition(out rtStart);
                //}

                // Start the recording.
                this.currentRecorderControl = pRecUnk as IStreamBufferRecordControl;
                //long rtStart = -10000000; // Start 1 seconds ago.
                hr = this.currentRecorderControl.Start(ref rtStart);
                DsError.ThrowExceptionForHR(hr);

                IsPossibleRecorderStart = false;
                IsPossibleRecorderStop = true;
            }
        }