How to correctly use in CreateObjectFromByteStream RRS feed

  • Question

  • I am trying to figure out how to correctly use the CreateObjectFromByteStream function.

    I took an .MP4 file and tried to open it in 2 ways. 

    The first using CreateObjectFromByteStream and the second using CreateObjectFromURL (both using the same file from the same path)
    Here's my code snippet:

    HRESULT CreateMediaSource(PCWSTR sURL, IMFMediaSource **ppSource) { MF_OBJECT_TYPE ObjectType = MF_OBJECT_INVALID; IMFSourceResolver* pSourceResolver = NULL; IUnknown* pSource = NULL; // Create the source resolver. HRESULT hr = MFCreateSourceResolver(&pSourceResolver); if (FAILED(hr)) { goto done; } //First try -> create IMFByteStream from mp4 file // and use it with CreateObjectFromByteStream function IMFByteStream *pStream = NULL; hr = MFCreateFile( MF_ACCESSMODE_READ, // AccessMode, MF_OPENMODE_FAIL_IF_NOT_EXIST , // OpenMode, MF_FILEFLAGS_NONE, // fFlags, L"C:\\try_file.mp4", &pStream // **ppIByteStream ); if (FAILED(hr)) { goto done; } // results of first try: "hr 0xc00d36c4 : The byte stream type of the given URL is unsupported." hr = pSourceResolver->CreateObjectFromByteStream(pStream,





    &pSource); //Second try (using the same file at the same path hr = pSourceResolver->CreateObjectFromURL( sURL, // URL of the source. MF_RESOLUTION_MEDIASOURCE, // Create a source object. NULL, // Optional property store. &ObjectType, // Receives the created object type. &pSource // Receives a pointer to the media source. ); // results s_ok if (FAILED(hr)) { goto done; } // Get the IMFMediaSource interface from the media source. hr = pSource->QueryInterface(IID_PPV_ARGS(ppSource)); done: SafeRelease(&pSourceResolver); SafeRelease(&pSource); return hr; }

    For a reason I do not understand the first fails and the second succeeds ...
    why is it happening?

    (My ultimate goal is to use MFCreateFile to easily create my own version of IMFByteStream where I can only change the reading and writing and not mess around with the realization that I will call the corresponding functions in the object I got back from MFCreateFile and in the functions I want to change a bit I will add my changes)

    Saturday, March 31, 2018 6:59 PM

All replies

  • Your use of CreateObjectFromByteStream is incorrect and MSDN article for IMFSourceResolver::CreateObjectFromByteStream method explains why exactly.

    As you created a byte stream from file already, you hid the file extension from source resolver and it is no longer able to derive respective media source handler. So you need to add MF_BYTESTREAM_CONTENT_TYPE to let know that it's an MPEG-4 file.

    Next, as you supply a byte stream your resolution target has to be a media source. The fixed code is:

    IMFAttributes* pAttributes;
    pAttributes->SetString(MF_BYTESTREAM_CONTENT_TYPE, L"video/mp4");
    // Failure to specify content type above results in "hr 0xc00d36c4 : The byte stream type of the given URL is unsupported."	
    hr = pSourceResolver->CreateObjectFromByteStream(pStream, NULL, MF_RESOLUTION_MEDIASOURCE, NULL, &ObjectType, &pSource);


    Sunday, April 1, 2018 10:26 AM