Re: change buffer size

Tech-Archive recommends: Speed Up your PC by fixing your registry

From: Chris P. [MVP] (msdn_at_chrisnet.net)
Date: 02/22/05


Date: Tue, 22 Feb 2005 11:03:14 -0500

On Mon, 21 Feb 2005 21:20:03 -0800, Mike Belina wrote:

> I have a DirectShow filter setup as follows:
>
> file.mp2 -> CLSID_MPEG1Splitter -> CLSID_SampleGrabber ->
> CLSID_CMpegAudioCodec -> CLSID_DSoundRender
>
> I can get the buffer using the SampleGrabber and GetCurrentBuffer.
> However, I want the buffer size smaller so I can get more samples.
>
> How can I change the buffer size in the graph? I tried to use an
> IAMBufferNegotiation all of the different In/Out pins. I can great the
> object using QueryInterface, but the GetAllocatorProperties call fails.
>
> Do I need to insert another graph filter to get what I want?
>
> Any help appreciated!!

If you want to change the delivery size I suggest using a custom
SampleGrabber. In the SampleGrabber override
CTransInPlaceInputPin::NotifyAllocator(), actually it already is overridden
in the sample. Replace the code with something that controls the buffer
size. Here's a crude sample.

STDMETHODIMP CSampleGrabberInPin::NotifyAllocator( IMemAllocator
*pAllocator, BOOL bReadOnly )
{
    if( m_pPrivateAllocator )
    {
        if( pAllocator != m_pPrivateAllocator )
        {
            return E_FAIL;
        }
        else
        {
            // if the upstream guy wants to be read only and we don't, then
that's bad
            // if the upstream guy doesn't request read only, but we do,
that's okay
            if( bReadOnly && !SampleGrabber( )->IsReadOnly( ) )
            {
                return E_FAIL;
            }
        }
    }

        // <inserted_code>
        ALLOCATOR_PROPERTIES Props, Actual;
        // get the current settings
        pAllocator->GetProperties(&Props);

    if( bReadOnly)
    { // return fail so that it will give us a buffer we can modify
settings
        return E_FAIL;
    }

        if (Props.cbBuffer > 88000)
                Props.cbBuffer = Props.cbBuffer / 100;
        if (Props.cbBuffer > 44000)
                Props.cbBuffer = Props.cbBuffer / 50;
        if (Props.cbBuffer >= 24000)
                Props.cbBuffer = Props.cbBuffer / 20;
        else if (Props.cbBuffer > 8000)
                Props.cbBuffer = Props.cbBuffer / 10;
        // set our desired settings
        pAllocator->SetProperties(&Props, &Actual);
        // </inserted_code>

    return CTransInPlaceInputPin::NotifyAllocator( pAllocator, bReadOnly );
}



Relevant Pages

  • Re: Video Mixing Renderer 9 freezes when using GMFBridge
    ... so that its internal buffer pool was loaded via a SampleGrabber ... PushSource filter into another. ... install itself into the SampleGrabber's callback and off you go. ...
    (microsoft.public.win32.programmer.directx.video)
  • Re: How do I get access to a wave file audio buffer?
    ... I think I will use the SampleGrabber since it seems like a good solution ... >> currently am using Directshow to play the wav files ... >> buffer from the DirectShow interfaces? ... > from a filter correctly connected inside the graph. ...
    (microsoft.public.win32.programmer.directx.audio)
  • Re: Sample Grabber Performance
    ... I have that SampleGrabber connected to live camera through input pin and ... I setup the callback, it works, but the buffer is black.. ... BITMAPINFO bi; // will place bitmap info here ...
    (microsoft.public.win32.programmer.directx.video)
  • SampleGrabber stops after a while (deadlock?)
    ... I have problem with SampleGrabber filter. ... StreamBufferSink is used in source graph (according Stream Buffer ...
    (microsoft.public.win32.programmer.directx.video)
  • change buffer size
    ... I have a DirectShow filter setup as follows: ... I can get the buffer using the SampleGrabber and GetCurrentBuffer. ... Do I need to insert another graph filter to get what I want? ...
    (microsoft.public.win32.programmer.directx.audio)