videojs / mpd-parser

https://videojs.github.io/mpd-parser/
Other
78 stars 54 forks source link

Matching upper-case keysystem UUID string in generateKeySystemInformation #156

Closed mhk-etn closed 2 years ago

mhk-etn commented 2 years ago

Hello,

we encountered an issue where during parsing/reading of the adaptation set content protection information from the manifest it does not consider upper case keySystem UUID string on input. The matching is done against fixed lower case UUID string in the videojs/mpd-parser and there shouldn't be any reason not to convert the manifest value to lower case before the keySystem UUID matching.

Of course we considered changing the uuid case in the output manifest but we are sadly unable to do so in the streaming provider delivery application.

Example content protection segment from the manifest.

<ContentProtection
  schemeIdUri="urn:uuid:EDEF8BA9-79D6-4ACE-A3C8-27DCD51D21ED">
  <cenc:pssh>some base 64 encoded string</cenc:pssh>
</ContentProtection>

KeySystemsMap from inheritAttributes.js:

const keySystemsMap = {
  'urn:uuid:1077efec-c0b2-4d02-ace3-3c1e52e2fb4b': 'org.w3.clearkey',
  'urn:uuid:edef8ba9-79d6-4ace-a3c8-27dcd51d21ed': 'com.widevine.alpha',
  'urn:uuid:9a04f079-9840-4286-ab92-e65be0885f95': 'com.microsoft.playready',
  'urn:uuid:f239e769-efa3-4850-9c16-a903c6932efb': 'com.adobe.primetime'
};

The matching itself is done in the generateKeySystemInformation method:

const generateKeySystemInformation = (contentProtectionNodes) => {
  return contentProtectionNodes.reduce((acc, node) => {
    const attributes = parseAttributes(node);
    const keySystem = keySystemsMap[attributes.schemeIdUri];

    if (keySystem) {
      acc[keySystem] = { attributes };

      const psshNode = findChildren(node, 'cenc:pssh')[0];

      if (psshNode) {
        const pssh = getContent(psshNode);
        const psshBuffer = pssh && decodeB64ToUint8Array(pssh);

        acc[keySystem].pssh = psshBuffer;
      }
    }

    return acc;
  }, {});
};

Specifically this is the line where keySystems UUID matching is done: const keySystem = keySystemsMap[attributes.schemeIdUri];

Although it could be argued that according to the UUID RFC spec the UUID string (a-f chars) should be generated as a lowercase string it also mentions it should be treated as case-insensitive on input. Since the key system UUIDs in the keySystemsMap are hardcoded as lowercase in the codebase there isn't any reason not to do .toLowerCase() on the input UUID string from the manifest (at least I could not think of one). RFC 4122

I created this issue mostly for the reason of hearing your opinions on the matter and whether such a minor change would make sense and whether a subsequent PR would be considered/accepted.

gkatsev commented 2 years ago

Can't see any problems with toLowerCase()ing all the things