summaryrefslogtreecommitdiffstats
path: root/dom/media/test/test_eme_missing_pssh.html
blob: 29f77d021aecfa791a33daa766e04fe76bfc7f15 (plain)
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
<!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>
    <audio controls id="audio"></audio>
    <pre id="test">
    <script class="testbody" type="text/javascript">

      // Tests that a fragmented MP4 file without a PSSH, but with valid encrypted
      // tracks with valid TENC boxes, is able to load with EME.
      // We setup MSE before starting up EME, so that we exercise the "waiting for
      // cdm" step in the MediaDecoderStateMachine.

      SimpleTest.waitForExplicitFinish();

      var pssh = [
        0x00, 0x00, 0x00, 0x00,
        0x70, 0x73, 0x73, 0x68, // BMFF box header (76 bytes, 'pssh')
        0x01, 0x00, 0x00, 0x00,                         // Full box header (version = 1, flags = 0)
        0x10, 0x77, 0xef, 0xec, 0xc0, 0xb2, 0x4d, 0x02, // SystemID
        0xac, 0xe3, 0x3c, 0x1e, 0x52, 0xe2, 0xfb, 0x4b,
        0x00, 0x00, 0x00, 0x01,                         // KID_count (1)
        0x2f, 0xef, 0x8a, 0xd8, 0x12, 0xdf, 0x42, 0x97,
        0x83, 0xe9, 0xbf, 0x6e, 0x5e, 0x49, 0x3e, 0x53,
        0x00, 0x00, 0x00, 0x00                         // Size of Data (0)
      ];

      var audio = document.getElementById("audio");

      function LoadEME() {
        var options = [{
          initDataType: 'cenc',
          audioType: 'audio/mp4; codecs="mp4a.40.2"',
        }];
        navigator.requestMediaKeySystemAccess("org.w3.clearkey", options)
          .then((keySystemAccess) => {
            return keySystemAccess.createMediaKeys();
          }, bail("Failed to request key system access."))

          .then((mediaKeys) => {
            audio.setMediaKeys(mediaKeys);
            var session = mediaKeys.createSession();
            once(session, "message", (message) => {
              is(message.messageType, 'license-request', "Expected a license-request");
              var license = new TextEncoder().encode(JSON.stringify({
                'keys': [{
                  'kty':'oct',
                  'kid':'L--K2BLfQpeD6b9uXkk-Uw',
                  'k':HexToBase64('7f412f0575f44f718259beef56ec7771')
                 }],
                 'type': 'temporary'
              }));
              session.update(license);
            });
            session.generateRequest('cenc', new Uint8Array(pssh));
          });
      }

      function DownloadMedia(url, type, mediaSource) {
        return new Promise(function(resolve, reject) {
          var sourceBuffer = mediaSource.addSourceBuffer(type);
          fetchWithXHR(url, (response) => {
            once(sourceBuffer, "updateend", resolve);
            sourceBuffer.appendBuffer(new Uint8Array(response));
          });
        });
      }

      function LoadMSE() {
        var ms = new MediaSource();
        audio.src = URL.createObjectURL(ms);

        once(ms, "sourceopen", ()=>{
          DownloadMedia('short-audio-fragmented-cenc-without-pssh.mp4', 'audio/mp4; codecs="mp4a.40.2"', ms)
            .then(() => { ms.endOfStream(); LoadEME();});
        });

        audio.addEventListener("loadeddata", SimpleTest.finish);
      }

      LoadMSE();

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