2
votes

I have a sample grabber hooked into my directshow graph, based on this example http://msdn.microsoft.com/en-us/library/dd407288(VS.85).aspx the problem is that it uses one shot and buffers. I want to continuously grab samples, and i'd rather have a callback than i guess polling for the samples.

How do use the SetCallback method?

SetCallback(ISampleGrabberCB *pCallback, long WhichMethodToCallback)

how do I point pCallback to my own method?

1
Hi, I have the exact problem so can you please share a complete code of grabbing the samples? Thank you,Basel
Yeah, if there is a working code of that would, would you share it please?mbaros

1 Answers

2
votes

I come from a c# background, and thought that at some level i could just pass a reference to a method. This doesn't seem to be case. Instead it requires you create a class the implements its interface that defines the method that it will call. You then pass an instance of the class to the filter in the SetCallback method. Certainly seems long winded in comparison to a delegate or lambda expression

Here is an example of a class implementing ISampleGrabberCB

class SampleGrabberCallback : public ISampleGrabberCB
{
public:
    // Fake referance counting.
    STDMETHODIMP_(ULONG) AddRef() { return 1; }
    STDMETHODIMP_(ULONG) Release() { return 2; }

    STDMETHODIMP QueryInterface(REFIID riid, void **ppvObject)
    {
        if (NULL == ppvObject) return E_POINTER;
        if (riid == __uuidof(IUnknown))
        {
            *ppvObject = static_cast<IUnknown*>(this);
             return S_OK;
        }
        if (riid == __uuidof(ISampleGrabberCB))
        {
            *ppvObject = static_cast<ISampleGrabberCB*>(this);
             return S_OK;
        }
        return E_NOTIMPL;
    }

    STDMETHODIMP SampleCB(double Time, IMediaSample *pSample)
    {
        return E_NOTIMPL;
    }

    STDMETHODIMP BufferCB(double Time, BYTE *pBuffer, long BufferLen)
    {
        return E_NOTIMPL;    
    }
};