Example #1
0
        private static IEnumerable <byte[]> PsshBox(byte[] pssh)
        {
            // Pssh box specs:
            // ISO IEC 23001-7 Cenc MP4

            // Check box type, 'pssh'
            if (pssh[4] != (byte)'p' ||
                pssh[5] != (byte)'s' ||
                pssh[6] != (byte)'s' ||
                pssh[7] != (byte)'h')
            {
                yield break;
            }

            // ISO IEC 23001-7 8.1.1
            // Check version. Must be > 0. Version 0 treat as:
            // (...) "Boxes without a list of applicable KID values, or with an empty list,
            // SHALL be considered to apply to all KIDs in the file or movie fragment"
            if (pssh[8] == 0)
            {
                // push out master key id.
                yield return(MasterKid);

                yield break;
            }

            uint kidCount = BigEndian.AsUInt32(pssh, 28);

            // 8.1.3 Semantics
            // KID identifies a key identifier that the Data field applies to. If not set, then the Data array SHALL
            // apply to all KIDs in the movie or movie fragment containing this box.
            if (kidCount == 0)
            {
                // push out master key id.
                yield return(MasterKid);

                yield break;
            }

            var offset = 32;

            for (var i = 0; i < kidCount; i++)
            {
                var uuid = new byte[16];
                Array.ConstrainedCopy(pssh, offset, uuid, 0, 16);
                offset += 16;
                Logger.Info(KeyToUuid(uuid));
                yield return(uuid);
            }
        }