Esempio n. 1
0
        private void InitAudioGrabber(IBaseFilter sourceF)
        {
            audioGrabberFilter = new SampleGrabber() as IBaseFilter;
            if (audioGrabberFilter == null)
            {
                throw new COMException("Cannot create SampleGrabber");
            }

            int hr = graph.AddFilter(audioGrabberFilter, "Audio Sample Grabber");

            DsError.ThrowExceptionForHR(hr);

            audioGrabber = audioGrabberFilter as ISampleGrabber;
            if (audioGrabber == null)
            {
                throw new COMException("Cannot obtain ISampleGrabber");
            }

            {
                AMMediaType mt = new AMMediaType();
                mt.majorType = DirectShowLib.MediaType.Audio;
                mt.subType   = DirectShowLib.MediaSubType.PCM;

                hr = audioGrabber.SetMediaType(mt);
                DsError.ThrowExceptionForHR(hr);

                DsUtils.FreeAMMediaType(mt);
            }

            hr = ConnectSampleGrabber(graph, sourceF, audioGrabberFilter);

            if (0 != hr)
            {
                // Cannot connect the audio grabber. Remove the filter from the graph.
                hr = graph.RemoveFilter(audioGrabberFilter);
                DsError.ThrowExceptionForHR(hr);

                Util.ReleaseComObject(ref audioGrabberFilter);
                audioGrabber = null;
                return;
            }

            audioNullFilter = new NullRenderer() as IBaseFilter;
            if (audioNullFilter == null)
            {
                throw new COMException("Cannot create NullRenderer");
            }

            hr = graph.AddFilter(audioNullFilter, "Null Filter");
            DsError.ThrowExceptionForHR(hr);

            hr = Util.ConnectFilters(graph, audioGrabberFilter, audioNullFilter);
            DsError.ThrowExceptionForHR(hr);

            audioGrabberCB = new SampleGrabberCB();
            hr             = audioGrabber.SetCallback(audioGrabberCB, (int)CBMethod.Sample);
            DsError.ThrowExceptionForHR(hr);
        }
Esempio n. 2
0
        public void Reset()
        {
            mediaControl = null;
            mediaEvent   = null;
            Util.ReleaseComObject(ref graph);

            Util.ReleaseComObject(ref videoGrabberFilter);
            videoGrabber = null;
            Util.ReleaseComObject(ref videoNullFilter);
            videoGrabberCB = null;

            Util.ReleaseComObject(ref audioGrabberFilter);
            audioGrabber = null;
            Util.ReleaseComObject(ref audioNullFilter);
            audioGrabberCB = null;
        }