rx-player
Version:
Canal+ HTML5 Video Player
59 lines (58 loc) • 2.51 kB
JavaScript
/**
* Copyright 2015 CANAL+ Group
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { base64ToBytes } from "../../../../../../utils/base64";
import { hexToBytes } from "../../../../../../utils/string_parsing";
import { parseString } from "../utils";
/**
* @param {Object} cp
* @param {WebAssembly.Memory} linearMemory
* @returns {Function}
*/
export function generateContentProtectionAttrParser(cp, linearMemory) {
const cpAttrs = cp.attributes;
const cpChildren = cp.children;
const textDecoder = new TextDecoder();
return function onContentProtectionAttribute(attr, ptr, len) {
switch (attr) {
case 16 /* AttributeName.SchemeIdUri */:
cpAttrs.schemeIdUri = parseString(textDecoder, linearMemory.buffer, ptr, len);
break;
case 13 /* AttributeName.ContentProtectionValue */:
cpAttrs.value = parseString(textDecoder, linearMemory.buffer, ptr, len);
break;
case 14 /* AttributeName.ContentProtectionKeyId */: {
const kid = parseString(textDecoder, linearMemory.buffer, ptr, len);
cpAttrs.keyId = hexToBytes(kid.replace(/-/g, ""));
break;
}
case 15 /* AttributeName.ContentProtectionCencPSSH */:
try {
const b64 = parseString(textDecoder, linearMemory.buffer, ptr, len);
cpChildren.cencPssh.push(base64ToBytes(b64));
}
catch (_) {
/* TODO log error? register as warning? */
}
break;
case 78 /* AttributeName.ContentProtectionRef */:
cpAttrs.ref = parseString(textDecoder, linearMemory.buffer, ptr, len);
break;
case 79 /* AttributeName.ContentProtectionRefId */:
cpAttrs.refId = parseString(textDecoder, linearMemory.buffer, ptr, len);
break;
}
};
}