Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handling httpx in manifest #4146

Closed
koganiz opened this issue Apr 21, 2022 · 22 comments
Closed

Handling httpx in manifest #4146

koganiz opened this issue Apr 21, 2022 · 22 comments
Labels
status: archived Archived and locked; will not be updated type: question A question from the community

Comments

@koganiz
Copy link

koganiz commented Apr 21, 2022

Hi guys,

I'm trying to implement Shaka v3.1.6 with FairPlay on Mac Safari 15, and the manifests I get have unusual httpx urls:

#EXT-X-SESSION-KEY:METHOD=SAMPLE-AES,URI="httpx://drmproxy.dgosvc.com/drmProxy/1?keyid=86BAF6DEFAA8B7CC1D20B231EEFFE5AC",KEYFORMAT="com.apple.streamingkeydelivery",KEYFORMATVERSIONS="1"

It looks like Safari rejects the requests even before it get to the DRM handling, I see in console multiple errors:

Failed to load resource: unsupported URL: httpx://drmproxy.dgosvc.com/drmProxy/1?keyid=86BAF6DEFAA8B7CC1D20B231EEFFE5AC

I'd like to replace the httpx by https, but I don't know how to intercept the response.
The initDataTransform in drm config is not fired.
Any ideas?

@koganiz koganiz added the type: question A question from the community label Apr 21, 2022
@theodab
Copy link
Collaborator

theodab commented Apr 21, 2022

Are you setting streaming.useNativeHlsOnSafari to false? If not, the manifest is handled by the browser, which we have no control over.
If you do set that, I think you could handle httpx by registering a scheme plugin for it. As long as it can be handled with the normal fetch browser API, you could use our default plugin:

shaka.net.NetworkingEngine.registerScheme('httpx', shaka.net.HttpFetchPlugin.parse);

@koganiz
Copy link
Author

koganiz commented Apr 21, 2022

I was sure the FairPlay is not supported with the useNativeHlsOnSafari = false.
Thanks a lot, I'll try it.

@theodab
Copy link
Collaborator

theodab commented Apr 21, 2022

It was added by a PR, 6d76a13.

@koganiz
Copy link
Author

koganiz commented Apr 21, 2022

Now I'm getting this one :(

Player Event: Error: shaka.util.Error {
"severity": 2,
"category": 4,
"code": 4040,
"data": [],
"handled": false,
"message": "Shaka Error MANIFEST.HLS_MSE_ENCRYPTED_MP2T_NOT_SUPPORTED ()",
}

My stream is not supported.

@theodab
Copy link
Collaborator

theodab commented Apr 21, 2022

#3776 (comment)

If I'm following this discussion correctly, we don't support MediaSource-based FairPlay with TS on Safari because we use the mux.js library to play TS, because of a Safari bug. And mux.js doesn't expose some necessary events for FairPlay.

However, recently Apple fixed that bug, and we removed the restriction against playing TS in Safari by itself. See 8a3bed7.

Given that, that error condition might not be necessary anymore. Unfortunately, we don't have any FairPlay demo content, so I can't test it myself.

@koganiz
Copy link
Author

koganiz commented Apr 22, 2022

I removed the mp2t restriction, trying to play, getting

"message": "Shaka Error DRM.FAILED_TO_GENERATE_LICENSE_REQUEST (The operation is not supported.,NotSupportedError: The operation is not supported.,)",

I see no requests going to the drm server, also the initDataTransform is not fired.
Besides, after the failure, if I try to play another stream it's not even starting to load the new stream manifest and shaka not printing logs until I reload the website.

I guess it's more complicated then just removing the restriction :(

@joeyparrish
Copy link
Member

Can you try using the latest code from the main branch, rather than a release version? We'll be releasing v4.0 from main soon.

@koganiz
Copy link
Author

koganiz commented Apr 22, 2022

Trying.
btw, there is a linting issue:

D:\shaka-player\test\ui\ui_unit.js
  671:1  error  Trailing spaces not allowed  no-trailing-spaces

@joeyparrish
Copy link
Member

That was fixed last night. Apologies!

@koganiz
Copy link
Author

koganiz commented Apr 22, 2022

v3.1.6-master-91-g648ebdb0-debug - Is this the version you are referring to?

@koganiz
Copy link
Author

koganiz commented Apr 22, 2022

Invalid config, unrecognized key .drm.initDataTransform

@joeyparrish
Copy link
Member

Yes, that was removed for v4 (prerelease). It shouldn't be necessary any more. Here are the updated FairPlay docs: https://nightly-dot-shaka-player-demo.appspot.com/docs/api/tutorial-fairplay.html

@koganiz
Copy link
Author

koganiz commented Apr 22, 2022

It parses the manifest but I don't see it's trying to access the drm server.
Am I missing something?

function configure() {
    player.getNetworkingEngine().registerRequestFilter(function(type, request) {
        if (type != shaka.net.NetworkingEngine.RequestType.LICENSE) {
            return;
          }
          const originalPayload = new Uint8Array(request.body);
          const base64Payload = shaka.util.Uint8ArrayUtils.toStandardBase64(originalPayload);
          const params = 'spc=' + base64Payload;
          request.headers['Content-Type'] = 'application/x-www-form-urlencoded';
          request.body = shaka.util.StringUtils.toUTF8(encodeURIComponent(params));
      });
      
      player.getNetworkingEngine().registerResponseFilter(function(type, response) {
        if (type != shaka.net.NetworkingEngine.RequestType.LICENSE) {
          return;
        }
        let responseText = shaka.util.StringUtils.fromUTF8(response.data);
        // Trim whitespace.
        responseText = responseText.trim();
        // Look for <ckc> wrapper and remove it.
        if (responseText.substr(0, 5) === '<ckc>' &&
            responseText.substr(-6) === '</ckc>') {
          responseText = responseText.slice(5, -6);
        }
        // Decode the base64-encoded data into the format the browser expects.
        response.data = shaka.util.Uint8ArrayUtils.fromBase64(responseText).buffer;
      });
	  shaka.net.NetworkingEngine.registerScheme('httpx', shaka.net.HttpFetchPlugin.parse);
	  player.configure({
        drm: {
            servers: {
                "com.apple.fps": "https://drmproxy-stg.dgosvc.com/drmProxy/1?keyid=CA130A3FD0AA3B05B60AF74D498A1056&deviceid=5171540__2EDC36E4-81B5-4C1D-8345-DF83549DAEE2"
            },
            advanced: {
                "com.apple.fps": {
                    serverCertificateUri: siteUrl + 'fairplay.der'
                }
            }
        },
        streaming: {
			useNativeHlsOnSafari: false,
        }
    });
}

async function play() {
    try {
        await player.load(MRL).then(function() {
            container.play();
        });
    } catch(e) {
        console.log("PLAY ERROR: " + e);
    }
}

@koganiz
Copy link
Author

koganiz commented Apr 22, 2022

And the mp2t limitation code is still in the branch (I removed it for testing purposes):

    if (mimeType == 'video/mp2t') {
      throw new shaka.util.Error(
          shaka.util.Error.Severity.CRITICAL,
          shaka.util.Error.Category.MANIFEST,
          shaka.util.Error.Code.HLS_MSE_ENCRYPTED_MP2T_NOT_SUPPORTED);
    }

@joeyparrish
Copy link
Member

Ah, that restriction is different from the one we were thinking of, which was a general restriction against TS on Safari. I would have to dig into the repo history a bit to figure out why we have that restriction in place against encrypted TS. It could be as simple as "it wasn't tested", or it could be something more serious.

@koganiz
Copy link
Author

koganiz commented Apr 22, 2022

Thank you!

@avelad
Copy link
Collaborator

avelad commented Apr 28, 2022

See: #3776

real MSE: encrypted event received, but with incorrect sinf initData (*1)

But recently the HLS implementation has been changed and also TS has been enabled in Safari (8a3bed7)

Maybe it's worth trying again if it works. @valotvince can you help us with it?

@valotvince
Copy link
Contributor

valotvince commented Apr 28, 2022

👋 I've tried a mp2t content with Fairplay encryption: it is still resulting in weird initData, and the MediaKeys session doesn't seem to send the "message" event to request a license

ewogICJjb250IiA6ICJtcHRzIiwKICAiY29kYyIgOiAyMDUzMjA3NjUxLAogICJtdHlwIiA6IDE5ODY2MTg0NjkKfQ==
{
  "cont" : "mpts",
  "codc" : 2053207651,
  "mtyp" : 1986618469
}

@avelad
Copy link
Collaborator

avelad commented May 3, 2022

@koganiz Well it seems that TS does not work with FairPlay on MSE. Therefore only src= can be used in this case.

@koganiz
Copy link
Author

koganiz commented May 3, 2022

@avelad Without the MSE I don't have a chance to intercept the httpx requests, they handled by Safari itself and fail because httpx is not a registered schema. I see the errors in console, but no such requests go through the network tab...

@avelad
Copy link
Collaborator

avelad commented May 3, 2022

There is nothing else we can do from the player, since this is managed by Safari.

@joeyparrish joeyparrish added the status: waiting on response Waiting on a response from the reporter(s) of the issue label May 3, 2022
@github-actions
Copy link
Contributor

Closing due to inactivity. If this is still an issue for you or if you have further questions, the OP can ask shaka-bot to reopen it by including @shaka-bot reopen in a comment.

@github-actions github-actions bot removed the status: waiting on response Waiting on a response from the reporter(s) of the issue label May 10, 2022
@github-actions github-actions bot added the status: archived Archived and locked; will not be updated label Jul 9, 2022
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 9, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
status: archived Archived and locked; will not be updated type: question A question from the community
Projects
None yet
Development

No branches or pull requests

5 participants