void IRecorder.Play(string filename)
        {
            int           hr;
            IMediaControl mediaControl2 = this.graphBuilder2 as IMediaControl;
            FilterState   pfs2;

            mediaControl2.GetState(0, out pfs2);
            if (pfs2 == FilterState.Running || pfs2 == FilterState.Paused)
            {
                hr = mediaControl2.Stop();
                DsError.ThrowExceptionForHR(hr);
            }

            //IStreamBufferSink sink = this.streamBufferSink as IStreamBufferSink;
            IStreamBufferSource source = this.streamBufferSource as IStreamBufferSource;

            hr = source.SetStreamSink(null);
            hr = (source as IFileSourceFilter).Load(filename, null);

            mediaControl2.GetState(0, out pfs2);
            if (pfs2 != FilterState.Running)
            {
                hr = mediaControl2.Run();
                DsError.ThrowExceptionForHR(hr);
            }
        }
Ejemplo n.º 2
0
        private void TestSetSink()
        {
            int hr;

            IBaseFilter   streamBuffer   = null;
            IFilterGraph2 m_FilterGraph2 = (IFilterGraph2) new FilterGraph();

            streamBuffer = (IBaseFilter) new StreamBufferSource();

            hr = m_FilterGraph2.AddFilter(streamBuffer, "Stream buffer sink");
            DsError.ThrowExceptionForHR(hr);

            IStreamBufferSource sbsrc = (IStreamBufferSource)streamBuffer;

            hr = sbsrc.SetStreamSink(m_isbc);
            DsError.ThrowExceptionForHR(hr);

            Marshal.ReleaseComObject(streamBuffer);
            Marshal.ReleaseComObject(m_FilterGraph2);
        }
        private void ConnectStreamBufferSinkToSource()
        {
            if (!Directory.Exists(Settings.VideosFolder))
            {
                Directory.CreateDirectory(Settings.VideosFolder);
            }

            string currentSBEProfile         = Settings.VideosFolder + "\\CurrentRecording.sbe-stub";
            string currentSBEProfileFilename = FileUtils.GetAbsolutePath(currentSBEProfile as string);

            IStreamBufferSink sink = this.streamBufferSink as IStreamBufferSink;
            int hr = sink.LockProfile(currentSBEProfile); //currentSBEProfileFilename); //currentSBEProfile);

            DsError.ThrowExceptionForHR(hr);

            IStreamBufferSource source = this.streamBufferSource as IStreamBufferSource;

            hr = source.SetStreamSink(sink);                                  // This line does not seem to be compatible with SBE2Sink.
            //So, I commented out the generation of exception   DsError.ThrowExceptionForHR(hr);
            hr = (source as IFileSourceFilter).Load(currentSBEProfile, null); //currentSBEProfileFilename, null); //currentSBEProfile, null);
            DsError.ThrowExceptionForHR(hr);
        }
        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.
            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);

            IStreamBufferSink isbc = (IStreamBufferSink)sbk;

            hr = isbc.LockProfile(null);
            DsError.ThrowExceptionForHR(hr);

            ((IMediaControl)m_FilterGraph).Run();
            // --------------------------
            IBaseFilter streamBuffer = null;

            m_FilterGraph2 = (IFilterGraph2) new FilterGraph();

            streamBuffer = (IBaseFilter) new StreamBufferSource();

            hr = m_FilterGraph2.AddFilter(streamBuffer, "Stream buffer sink");
            DsError.ThrowExceptionForHR(hr);

            IStreamBufferSource sbsrc = (IStreamBufferSource)streamBuffer;

            hr = sbsrc.SetStreamSink(isbc);
            DsError.ThrowExceptionForHR(hr);

            ((IMediaControl)m_FilterGraph2).Run();

            m_sbms = (IStreamBufferMediaSeeking)sbsrc;
            // --------------------------

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