DXR is a code search and navigation tool aimed at making sense of large projects. It supports full-text and regex searches as well as structural queries.

Mercurial (c68fe15a81fc)

VCS Links

Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141
<!DOCTYPE HTML>
<html>

  <head>
    <title>Test Encrypted Media Extensions</title>
    <script src="/tests/SimpleTest/SimpleTest.js"></script>
    <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
    <script type="text/javascript" src="manifest.js"></script>
    <script type="text/javascript" src="eme.js"></script>
  </head>

  <body>
    <script class="testbody" type="text/javascript">
    let manager = new MediaTestManager;

    let psshTests = [
      { name: "bear-640x360-cenc-key-rotation",
        tracks : [
          {
            name: "video",
            type: "video/mp4; codecs=\"avc1.64000d\"",
            fragments: ["bear-640x360-v_frag-cenc-key_rotation.mp4"],
            initDatas: 6
          },
          {
            name: "audio",
            type: "audio/mp4; codecs=\"mp4a.40.2\"",
            fragments: ["bear-640x360-a_frag-cenc-key_rotation.mp4"],
            initDatas: 7
          }
        ],
        keys : {
          "30313233343536373839303132333435" :
            "ebdd62f16814d27b68ef122afce4ae3c"
        }
      },
      { name: "bipbop-clearkey-keyrotation-clear-lead",
        tracks : [
          {
            name: "video",
            type: "video/mp4; codecs=\"avc1.4d4015\"",
            fragments: ["bipbop-clearkey-keyrotation-clear-lead-video.mp4"],
            initDatas: 3
          },
          {
            name: "audio",
            type: "audio/mp4; codecs=\"mp4a.40.2\"",
            fragments: ["bipbop-clearkey-keyrotation-clear-lead-audio.mp4"],
            initDatas: 3
          }
        ],
        keys : {
          "00112233445566778899aabbccddeeff" :
            "00112233445566778899aabbccddeeff",
          "112233445566778899aabbccddeeff00" :
            "112233445566778899aabbccddeeff00"
        }
      }
    ];

    // Specialized create media keys function, since the one in eme.js relies
    // on listening for encrypted events, and we want to manage those
    // ourselves within this test.
    async function createAndSetMediaKeys(video, test, token) {
      function streamType(type) {
        var x = test.tracks.find(o => o.name == type);
        return x ? x.type : undefined;
      }

      var configuration = { initDataTypes: ["cenc"] };
      if (streamType("video")) {
        configuration.videoCapabilities = [{contentType: streamType("video")}];
      }
      if (streamType("audio")) {
        configuration.audioCapabilities = [{contentType: streamType("audio")}];
      }
      let keySystemAccess = await navigator.requestMediaKeySystemAccess(
        "org.w3.clearkey", [configuration]);
      let mediaKeys = await keySystemAccess.createMediaKeys();
      return video.setMediaKeys(mediaKeys);
    }

    function startTest(test, token) {
      manager.started(token);
      let video = document.createElement("video");
      document.body.appendChild(video);

      let encryptedEventCount = 0;

      let initDatas = new Map();

      function handleEncrypted(event) {
        // We get one 'encrypted' event for every run of contiguous PSSH boxes
        // in each stream. Note that some of the PSSH boxes contained in the
        // "bear" streams aren't in the Common Open PSSH box format, so our
        // ClearKey CDM will reject those license requests. Some of the init
        // data is also repeated.
        encryptedEventCount++;

        let hexStr = StringToHex(new TextDecoder().decode(event.initData));
        if (initDatas.has(hexStr)) {
          // Already have a session for this.
          return;
        }

        let initData = new Uint8Array(event.initData);
        is(event.initDataType, "cenc", "'encrypted' event should have 'cenc' " +
           "initDataType");
        Log(token, "encrypted event => len=" + initData.length + " " + hexStr);
        let session = event.target.mediaKeys.createSession();
        initDatas.set(hexStr, session);
        session.addEventListener("message", e => {
          e.target.update(
            GenerateClearKeyLicense(e.message, test.keys));
        });

        session.generateRequest(event.initDataType, event.initData);
      }

      video.addEventListener("encrypted", handleEncrypted);

      video.addEventListener("ended", () => {
        let expectedEncryptedEvents =
          test.tracks.reduce((sum, track) => sum += track.initDatas, 0);
        is(encryptedEventCount, expectedEncryptedEvents,
           "Should get one 'encrypted' event per run of contiguous PSSH " +
           "boxes in media.");
        manager.finished(token);
      });

      video.autoplay = true;

      createAndSetMediaKeys(video, test, token)
        .then(() => LoadTest(test, video, token))
    }

    manager.runTests(psshTests, startTest);

    </script>
  </body>
</html>