locked
Rate control in custom source RRS feed

  • Question

  • I am implementing a custom source to admit h264 files directly in the Media Foundation pipeline. The custom source works Ok using the MFPlayback2 sample to embed the custom source.

    A step forward is to implement rate control and support for the custom control. To do that, the custom source implements the interfaces IMFGetService, IMFRateSupport, and IMFRateControl. I use the method QueryInterface of the custom media source to return an interface for IMFGetService. For getting an interface for IMFRateControl, I use the the method GetService, as follows:

    IFACEMETHODIMP NVRSource::GetService(REFGUID guidService, REFIID riid, LPVOID *ppvObject)
    {
        HRESULT hr = MF_E_UNSUPPORTED_SERVICE;

        if (guidService == MF_RATE_CONTROL_SERVICE)
        {
            if (riid == IID_IMFRateControl)
            {
                *ppvObject = static_cast<IMFRateControl*>(this);
                hr = S_OK;
            }
            if (riid == IID_IMFRateSupport)
            {
                *ppvObject = static_cast<IMFRateSupport*>(this);
                hr = S_OK;
            }
        }
        return hr;
    }

    The first time the application enters this method for getting an IMFRateSupport interface, it crashes because a stack problem. If I try to put the call to the IMFRateSupport interface in QueryInterface, the application doesn't crash, but no interface is returned.

    Any idea of what is happening? Thanks a lot in advance.

    Wednesday, June 17, 2015 5:26 PM

Answers

  • GetService should follow the QueryInterface contract. In your case you are not calling AddRef on the result object: ((LPUNKNOWN)*ppvObject)->AddRef();

    If your object is destroyed, you'll have undefined behavior.

    Common recommendation for such GetService implementations is to call into the QueryInterface.

    Tuesday, June 23, 2015 10:20 PM

All replies

  • GetService should follow the QueryInterface contract. In your case you are not calling AddRef on the result object: ((LPUNKNOWN)*ppvObject)->AddRef();

    If your object is destroyed, you'll have undefined behavior.

    Common recommendation for such GetService implementations is to call into the QueryInterface.

    Tuesday, June 23, 2015 10:20 PM
  • Thanks a lot, Aleksey. You are right. This was the problem.
    Wednesday, July 1, 2015 2:18 PM