3

I'm developing my own Custom Receiver Application and the stream I want to play is protected with widevine, I need to obtain my license from my own server and I need to pass content_id and payload. This my code:

playbackConfig.protectionSystem = cast.framework.ContentProtection.WIDEVINE;

playbackConfig.licenseRequestHandler = requestInfo => {

    requestInfo.headers["Authorization"] = token;
    requestInfo.headers["Content-Type"] = "application/json";

    requestInfo.content = JSON.stringify({ 
        type: "widevine", 
        type_request: "license",
        content_id: content_id, 
        payload: <<missing_data>>
    });

    return requestInfo
};

I have it implemented on Android implmementing my own MediaDrmCallback and the class KeyRequest contains the needed information but the param content from object requestInfo doesn't provide that information

aloj
  • 3,194
  • 7
  • 27
  • 38
  • Hi @aloj, any news on this? I'm in the same situation – riot Sep 10 '21 at 19:28
  • @riot https://stackoverflow.com/questions/66351516/how-to-obtain-widevine-payload-challenge-in-google-cast/69180958#69180958 – aloj Sep 14 '21 at 15:53

1 Answers1

0

I make it work by doing

   playbackConfig.licenseRequestHandler = requestInfo => {

        requestInfo.headers["Authorization"] = token
        requestInfo.headers["Content-Type"] = "application/json"

        const wrapped = {}
        wrapped.payload = arrayBufferToBase64(requestInfo.content)
        wrapped.type = 'widevine'
        wrapped.type_request = "license"
        wrapped.content_id = content_id
        const wrappedJson = JSON.stringify(wrapped)
        requestInfo.content = shaka.util.StringUtils.toUTF8(wrappedJson)
        return requestInfo
    }

function arrayBufferToBase64(buffer) {
    var binary = '';
    var bytes = new Uint8Array( buffer );
    var len = bytes.byteLength;
    for (var i = 0; i < len; i++) {
        binary += String.fromCharCode( bytes[ i ] );
    }
    return window.btoa( binary );
}
aloj
  • 3,194
  • 7
  • 27
  • 38
  • I also tried something like that but requestInfo.content only contains an empty JSON, just like you said in your original post. – riot Sep 15 '21 at 16:39