locked
Getting MF_OBJECT_INVALID in a custom IMFSchemeHandler when creating a ByteStream from mp4 file

    Question

  • Hi,

    I'm trying to create a custom IMFSchemeHandler where I create my own ByteStream from a url such as myscheme://myfile.mp4 and then pass it to the media foundation to resolve it using the default decoder. I don't want to create the samples myself (e.g. I don't want to create a MediaSource), I just want to generate a ByteStream and pass it to the SourceResolver to find the default MediaSource.

    My code looks like this:

    IFACEMETHODIMP CGeometricSchemeHandler::BeginCreateObject( _In_ LPCWSTR pwszURL, _In_ DWORD dwFlags, _In_ IPropertyStore *pProps, _Out_opt_ IUnknown **ppIUnknownCancelCookie, _In_ IMFAsyncCallback *pCallback, _In_ IUnknown *punkState) // ... // ... here was code to get a IRandomAccessStream (ras) from a file // ... HRESULT convert_OK = S_OK; this->spMFByteStream = nullptr; convert_OK = MFCreateMFByteStreamOnStreamEx((IUnknown*)ras, &this->spMFByteStream); HRESULT status = MFCreateSourceResolver(&this->sourceResolver); status = this->sourceResolver->BeginCreateObjectFromByteStream(spMFByteStream.Get(), L"myfile.mp4", dwFlags, pProps, ppIUnknownCancelCookie, pCallback, punkState); } IFACEMETHODIMP CGeometricSchemeHandler::EndCreateObject( _In_ IMFAsyncResult *pResult, _Out_ MF_OBJECT_TYPE *pObjectType, _Out_ IUnknown **ppObject) { if (pResult == nullptr || pObjectType == nullptr || ppObject == nullptr) { return E_INVALIDARG; } // pObjectType is MF_OBJECT_INVALID !!! HRESULT hr = pResult->GetStatus();

    // hr returns 0xc00d36c4

    //...

    Is this the right way to create a ByteStream in a SchemeHandler to pass it to the SourceResolver?

    I'm registering SchemeHandler like this in the metro app:

    rootPage.ExtensionManager.RegisterSchemeHandler("GeometricSource.GeometricSchemeHandler", "myscheme:");

    If I pass the file directly to the MediaElement it plays so it's not a problem of the video encoding.

    Thank you,

    Tuesday, November 06, 2012 11:45 AM

Answers

  • Hello James,

    Thank you for your reply, I had tried that flag but it didn't help because, as it turned out, the problem was with the video, it had the headers at the end of the file. I fixed the video and now it's working fine as expected.

    Now I'm trying to make HttpRequests, from the Scheme Handler, to get a progressive download of the video (get it in chunks), and feeding those chunks to some sort of IMFByteStream simultaneously (consumer/producer), but I'm still not sure how it should be done correctly. I'll create another thread for that.

    Thanks,
    Ricardo

    Thursday, November 08, 2012 2:47 PM

All replies

  • Hello,

    Your code looks fine. Can you try passing "MF_RESOLUTION_KEEP_BYTE_STREAM_ALIVE_ON_FAIL" in the flags?

    I hope this helps,

    James


    Windows Media SDK Technologies - Microsoft Developer Services - http://blogs.msdn.com/mediasdkstuff/

    Thursday, November 08, 2012 12:50 AM
    Moderator
  • Hello James,

    Thank you for your reply, I had tried that flag but it didn't help because, as it turned out, the problem was with the video, it had the headers at the end of the file. I fixed the video and now it's working fine as expected.

    Now I'm trying to make HttpRequests, from the Scheme Handler, to get a progressive download of the video (get it in chunks), and feeding those chunks to some sort of IMFByteStream simultaneously (consumer/producer), but I'm still not sure how it should be done correctly. I'll create another thread for that.

    Thanks,
    Ricardo

    Thursday, November 08, 2012 2:47 PM