Audio distortion with Smart Tee preview

  • clint

    clint - 2013-01-30

    I'm pretty raw as far as DirectShow goes, but I have gotten my project very close to what I'm trying to achieve, but I have run into a strange problem. I am doing a live preview of video and audio capture in a resized window that I need to run for several hours at a time. Everything is working fine, except that after a couple of hours, the audio starts to distort rather severely. i have looked and it doesn't seem to be a memory leak issue, the audio just becomes distorted.

    I am using a Smart Tee filter to preview the graph. Here is the code snipper for creating this graph setup that I have pieced together from the sample apps for my device and this forum. Any tips on anything I might be doing wrong or a better way to do this would be greatly appreciated.

                graphBuilder = (IFilterGraph2)new FilterGraph();
                mediaControl = (IMediaControl)graphBuilder;
                vmr9 = (IBaseFilter)new VideoMixingRenderer9();
                hr = graphBuilder.AddFilter(vmr9, "Video Mixing Renderer 9");
                // Get DirectShow interfaces
                // Attach the filter graph to the capture graph
                hr = this.captureGraphBuilder.SetFiltergraph(this.graphBuilder);
                sourceFilter = FindCaptureDevice(videoDevice, FilterCategory.VideoInputDevice);
                IAMStreamConfig cfg;
                IPin pi;
                pi = DsFindPin.ByDirection(sourceFilter, PinDirection.Output, 0);
                AMMediaType pmt = null;
                cfg = pi as IAMStreamConfig;
                FormatCollection fc = new FormatCollection(sourceFilter);
                pmt = fc.GetMediaType(videoFormat, null);
                hr = cfg.SetFormat(pmt);
                fc = null;
                graphBuilder.AddFilter((IBaseFilter)vmr9, "Renderer");
                hr = this.graphBuilder.AddFilter(sourceFilter, "Video Capture");
                audio = FindCaptureDevice(audioDevice, FilterCategory.AudioInputDevice);
                hr = this.graphBuilder.AddFilter(audio, "Audio Capture");
                pi = DsFindPin.ByDirection(audio, PinDirection.Output, 0);
                cfg = pi as IAMStreamConfig;
                fc = new FormatCollection(audio);
                pmt = fc.GetMediaType(null, audioFormat);
                fc = null;
                IBaseFilter smart = (IBaseFilter)new SmartTee();
                hr = this.graphBuilder.AddFilter(smart, "Smart Tee");
                IPin pSmart = DsFindPin.ByDirection(smart,PinDirection.Input,0);
                IPin pOut = DsFindPin.ByDirection(sourceFilter, PinDirection.Output, 0);
                hr = graphBuilder.Connect(pOut, pSmart);
                pSmart = DsFindPin.ByName(smart, "Preview");
                pOut = DsFindPin.ByDirection(vmr9, PinDirection.Input, 0);
                hr = graphBuilder.Connect(pSmart, pOut);
                hr = this.captureGraphBuilder.RenderStream(PinCategory.Preview, MediaType.Audio, audio, null, null);
                hr = this.mediaControl.Run();
  • snarfle

    snarfle - 2013-01-30

    So are you calling this code over and over again for hours? Or do you call it once and let it run for hours?

  • clint

    clint - 2013-01-31

    I call this once, then let it run for hours. After a couple of hours, the audio becomes very distorted. Basically what I'm doing is using a BlackMagic Intensity to caputre live TV and then resize this and add come content around it on the monitor, and this may be running for very logn periods of time without stopping.


Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

No, thanks