locked
How do I play a TS or M2TS file using my own ByteStreamHandler?

    Question

  • Hi,

    I want to play back a TS / M2TS file from JS/HTML via my own ByteStreamHandler. At present I'd just like to pass the file through unchanged, if I can get that to work I will then look at modifying the stream.

    So I have a video window in html...

           <video id="byteStreamHandlerVideo" autoplay>
            </video>

    a function to send it the file in JS...

      function showVideo() { // on a button
            SdkSample.clearLastStatus();
            WinJS.Utilities.query("#byteStreamHandlerVideo")[0].src = "video/file.ts";
        }

    ...and a function to register my BSH...

        var page = WinJS.UI.Pages.define("/html/ByteStreamHandler.html", {
            extensions: null,
            ready: function (element, options) {
                if (!this.extensions) {
                    this.extensions = new Windows.Media.MediaExtensionManager();
                    this.extensions.registerByteStreamHandler("SmW8MediaPlayer.HLSByteStreamHandler", ".ts", "application/x-

    mpegURL");
                }

    ...then in C++ I have a BSH class, which is called, and which creates samples from the supplied input stream, which comes from the file (which plays OK in WMP and VLC). There seems to be a problem after my Media Source's CreatePresentationDescriptor function is called, since the Media Source is then shut down. So I'm guessing I haven't  created a valid PD.

    The PD is created like this:

    ComPtr<IMFStreamDescriptor> spStreamDesc;
    _spStream->GetStreamDescriptor(&spStreamDesc);
    MFCreatePresentationDescriptor(1,spStreamDesc.GetAddressOf(),_spPresentationDescriptor.ReleaseAndGetAddressOf());
    _spPresentationDescriptor->SelectStream(0);

    _spStream is a Media Stream, with a media type created like this:

    HRESULT CHLSMediaStream::CreateMediaType(IMFMediaType **ppMediaType)
    {
        HRESULT hr = S_OK;
        ComPtr<IMFMediaType> spOutputType;
        MFCreateMediaType(&spOutputType);
        spOutputType->SetGUID(MF_MT_MAJOR_TYPE, MFMediaType_Stream);
        spOutputType->SetGUID(MF_MT_SUBTYPE, MFStreamFormat_MPEG2Transport);
        *ppMediaType = spOutputType.Detach();
    Finally:
        return hr;
    }

    Then I have a deliver sample function which would return chunks of the input stream, but it never gets round to requesting them because the media source is shut down before it gets that far.

    As far as I can see this should read file.ts into a byte stream, then send it out, unchanged, as samples, with the type of the output being an MPEG2 transport stream. Am I doing anything obviously wrong, or not doing something I should be?

    Any advice appreciated!

    Tuesday, December 03, 2013 11:38 PM

All replies

  • I should have mentioned I've taken out the error checking to make the code more readable.
    Tuesday, December 03, 2013 11:42 PM