google-castgoogle-cast-sdkshaka

How to obtain widevine payload (challenge) in google cast?


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


Solution

  • 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 );
    }