/
dash.protection.debug.js
5413 lines (4643 loc) · 223 KB
/
dash.protection.debug.js
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}(g.dashjs || (g.dashjs = {})).Protection = f()}})(function(){var define,module,exports;return (function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(_dereq_,module,exports){
/**
* The copyright in this software is being made available under the BSD License,
* included below. This software may be subject to other third party and contributor
* rights, including patent rights, and no such rights are granted under this license.
*
* Copyright (c) 2013, Dash Industry Forum.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * Neither the name of Dash Industry Forum nor the names of its
* contributors may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/**
* @class
* @ignore
*/
'use strict';
Object.defineProperty(exports, '__esModule', {
value: true
});
var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
var ErrorsBase = (function () {
function ErrorsBase() {
_classCallCheck(this, ErrorsBase);
}
_createClass(ErrorsBase, [{
key: 'extend',
value: function extend(errors, config) {
if (!errors) return;
var override = config ? config.override : false;
var publicOnly = config ? config.publicOnly : false;
for (var err in errors) {
if (!errors.hasOwnProperty(err) || this[err] && !override) continue;
if (publicOnly && errors[err].indexOf('public_') === -1) continue;
this[err] = errors[err];
}
}
}]);
return ErrorsBase;
})();
exports['default'] = ErrorsBase;
module.exports = exports['default'];
},{}],2:[function(_dereq_,module,exports){
/**
* The copyright in this software is being made available under the BSD License,
* included below. This software may be subject to other third party and contributor
* rights, including patent rights, and no such rights are granted under this license.
*
* Copyright (c) 2013, Dash Industry Forum.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * Neither the name of Dash Industry Forum nor the names of its
* contributors may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/**
* @class
* @ignore
*/
'use strict';
Object.defineProperty(exports, '__esModule', {
value: true
});
var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
var EventsBase = (function () {
function EventsBase() {
_classCallCheck(this, EventsBase);
}
_createClass(EventsBase, [{
key: 'extend',
value: function extend(events, config) {
if (!events) return;
var override = config ? config.override : false;
var publicOnly = config ? config.publicOnly : false;
for (var evt in events) {
if (!events.hasOwnProperty(evt) || this[evt] && !override) continue;
if (publicOnly && events[evt].indexOf('public_') === -1) continue;
this[evt] = events[evt];
}
}
}]);
return EventsBase;
})();
exports['default'] = EventsBase;
module.exports = exports['default'];
},{}],3:[function(_dereq_,module,exports){
/**
* The copyright in this software is being made available under the BSD License,
* included below. This software may be subject to other third party and contributor
* rights, including patent rights, and no such rights are granted under this license.
*
* Copyright (c) 2013, Dash Industry Forum.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * Neither the name of Dash Industry Forum nor the names of its
* contributors may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/**
* Protection Constants declaration
* @class
* @ignore
*/
'use strict';
Object.defineProperty(exports, '__esModule', {
value: true
});
var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
var ProtectionConstants = (function () {
_createClass(ProtectionConstants, [{
key: 'init',
value: function init() {
this.CLEARKEY_KEYSTEM_STRING = 'org.w3.clearkey';
this.WIDEVINE_KEYSTEM_STRING = 'com.widevine.alpha';
this.PLAYREADY_KEYSTEM_STRING = 'com.microsoft.playready';
}
}]);
function ProtectionConstants() {
_classCallCheck(this, ProtectionConstants);
this.init();
}
return ProtectionConstants;
})();
var constants = new ProtectionConstants();
exports['default'] = constants;
module.exports = exports['default'];
},{}],4:[function(_dereq_,module,exports){
/**
* The copyright in this software is being made available under the BSD License,
* included below. This software may be subject to other third party and contributor
* rights, including patent rights, and no such rights are granted under this license.
*
* Copyright (c) 2013, Dash Industry Forum.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * Neither the name of Dash Industry Forum nor the names of its
* contributors may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/**
* @class
* @ignore
*/
'use strict';
Object.defineProperty(exports, '__esModule', {
value: true
});
var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
var CommonEncryption = (function () {
function CommonEncryption() {
_classCallCheck(this, CommonEncryption);
}
_createClass(CommonEncryption, null, [{
key: 'findCencContentProtection',
/**
* Find and return the ContentProtection element in the given array
* that indicates support for MPEG Common Encryption
*
* @param {Array} cpArray array of content protection elements
* @returns {Object|null} the Common Encryption content protection element or
* null if one was not found
*/
value: function findCencContentProtection(cpArray) {
var retVal = null;
for (var i = 0; i < cpArray.length; ++i) {
var cp = cpArray[i];
if (cp.schemeIdUri.toLowerCase() === 'urn:mpeg:dash:mp4protection:2011' && cp.value.toLowerCase() === 'cenc') retVal = cp;
}
return retVal;
}
/**
* Returns just the data portion of a single PSSH
*
* @param {ArrayBuffer} pssh - the PSSH
* @return {ArrayBuffer} data portion of the PSSH
*/
}, {
key: 'getPSSHData',
value: function getPSSHData(pssh) {
var offset = 8; // Box size and type fields
var view = new DataView(pssh);
// Read version
var version = view.getUint8(offset);
offset += 20; // Version (1), flags (3), system ID (16)
if (version > 0) {
offset += 4 + 16 * view.getUint32(offset); // Key ID count (4) and All key IDs (16*count)
}
offset += 4; // Data size
return pssh.slice(offset);
}
/**
* Returns the PSSH associated with the given key system from the concatenated
* list of PSSH boxes in the given initData
*
* @param {KeySystem} keySystem the desired
* key system
* @param {ArrayBuffer} initData 'cenc' initialization data. Concatenated list of PSSH.
* @returns {ArrayBuffer|null} The PSSH box data corresponding to the given key system, null if not found
* or null if a valid association could not be found.
*/
}, {
key: 'getPSSHForKeySystem',
value: function getPSSHForKeySystem(keySystem, initData) {
var psshList = CommonEncryption.parsePSSHList(initData);
if (keySystem && psshList.hasOwnProperty(keySystem.uuid.toLowerCase())) {
return psshList[keySystem.uuid.toLowerCase()];
}
return null;
}
/**
* Parse a standard common encryption PSSH which contains a simple
* base64-encoding of the init data
*
* @param {Object} cpData the ContentProtection element
* @param {BASE64} BASE64 reference
* @returns {ArrayBuffer|null} the init data or null if not found
*/
}, {
key: 'parseInitDataFromContentProtection',
value: function parseInitDataFromContentProtection(cpData, BASE64) {
if ('pssh' in cpData) {
// Remove whitespaces and newlines from pssh text
cpData.pssh.__text = cpData.pssh.__text.replace(/\r?\n|\r/g, '').replace(/\s+/g, '');
return BASE64.decodeArray(cpData.pssh.__text).buffer;
}
return null;
}
/**
* Parses list of PSSH boxes into keysystem-specific PSSH data
*
* @param {ArrayBuffer} data - the concatenated list of PSSH boxes as provided by
* CDM as initialization data when CommonEncryption content is detected
* @returns {Object|Array} an object that has a property named according to each of
* the detected key system UUIDs (e.g. 00000000-0000-0000-0000-0000000000)
* and a ArrayBuffer (the entire PSSH box) as the property value
*/
}, {
key: 'parsePSSHList',
value: function parsePSSHList(data) {
if (data === null || data === undefined) return [];
var dv = new DataView(data.buffer || data); // data.buffer first for Uint8Array support
var done = false;
var pssh = {};
// TODO: Need to check every data read for end of buffer
var byteCursor = 0;
while (!done) {
var size = undefined,
nextBox = undefined,
version = undefined,
systemID = undefined,
psshDataSize = undefined;
var boxStart = byteCursor;
if (byteCursor >= dv.buffer.byteLength) break;
/* Box size */
size = dv.getUint32(byteCursor);
nextBox = byteCursor + size;
byteCursor += 4;
/* Verify PSSH */
if (dv.getUint32(byteCursor) !== 0x70737368) {
byteCursor = nextBox;
continue;
}
byteCursor += 4;
/* Version must be 0 or 1 */
version = dv.getUint8(byteCursor);
if (version !== 0 && version !== 1) {
byteCursor = nextBox;
continue;
}
byteCursor++;
byteCursor += 3; /* skip flags */
// 16-byte UUID/SystemID
systemID = '';
var i = undefined,
val = undefined;
for (i = 0; i < 4; i++) {
val = dv.getUint8(byteCursor + i).toString(16);
systemID += val.length === 1 ? '0' + val : val;
}
byteCursor += 4;
systemID += '-';
for (i = 0; i < 2; i++) {
val = dv.getUint8(byteCursor + i).toString(16);
systemID += val.length === 1 ? '0' + val : val;
}
byteCursor += 2;
systemID += '-';
for (i = 0; i < 2; i++) {
val = dv.getUint8(byteCursor + i).toString(16);
systemID += val.length === 1 ? '0' + val : val;
}
byteCursor += 2;
systemID += '-';
for (i = 0; i < 2; i++) {
val = dv.getUint8(byteCursor + i).toString(16);
systemID += val.length === 1 ? '0' + val : val;
}
byteCursor += 2;
systemID += '-';
for (i = 0; i < 6; i++) {
val = dv.getUint8(byteCursor + i).toString(16);
systemID += val.length === 1 ? '0' + val : val;
}
byteCursor += 6;
systemID = systemID.toLowerCase();
/* PSSH Data Size */
psshDataSize = dv.getUint32(byteCursor);
byteCursor += 4;
/* PSSH Data */
pssh[systemID] = dv.buffer.slice(boxStart, nextBox);
byteCursor = nextBox;
}
return pssh;
}
}]);
return CommonEncryption;
})();
exports['default'] = CommonEncryption;
module.exports = exports['default'];
},{}],5:[function(_dereq_,module,exports){
/**
* The copyright in this software is being made available under the BSD License,
* included below. This software may be subject to other third party and contributor
* rights, including patent rights, and no such rights are granted under this license.
*
* Copyright (c) 2013, Dash Industry Forum.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * Neither the name of Dash Industry Forum nor the names of its
* contributors may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
'use strict';
Object.defineProperty(exports, '__esModule', {
value: true
});
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
var _controllersProtectionController = _dereq_(7);
var _controllersProtectionController2 = _interopRequireDefault(_controllersProtectionController);
var _controllersProtectionKeyController = _dereq_(8);
var _controllersProtectionKeyController2 = _interopRequireDefault(_controllersProtectionKeyController);
var _ProtectionEvents = _dereq_(6);
var _ProtectionEvents2 = _interopRequireDefault(_ProtectionEvents);
var _errorsProtectionErrors = _dereq_(13);
var _errorsProtectionErrors2 = _interopRequireDefault(_errorsProtectionErrors);
var _modelsProtectionModel_21Jan2015 = _dereq_(15);
var _modelsProtectionModel_21Jan20152 = _interopRequireDefault(_modelsProtectionModel_21Jan2015);
var _modelsProtectionModel_3Feb2014 = _dereq_(16);
var _modelsProtectionModel_3Feb20142 = _interopRequireDefault(_modelsProtectionModel_3Feb2014);
var _modelsProtectionModel_01b = _dereq_(14);
var _modelsProtectionModel_01b2 = _interopRequireDefault(_modelsProtectionModel_01b);
var APIS_ProtectionModel_01b = [
// Un-prefixed as per spec
{
// Video Element
generateKeyRequest: 'generateKeyRequest',
addKey: 'addKey',
cancelKeyRequest: 'cancelKeyRequest',
// Events
needkey: 'needkey',
keyerror: 'keyerror',
keyadded: 'keyadded',
keymessage: 'keymessage'
},
// Webkit-prefixed (early Chrome versions and Chrome with EME disabled in chrome://flags)
{
// Video Element
generateKeyRequest: 'webkitGenerateKeyRequest',
addKey: 'webkitAddKey',
cancelKeyRequest: 'webkitCancelKeyRequest',
// Events
needkey: 'webkitneedkey',
keyerror: 'webkitkeyerror',
keyadded: 'webkitkeyadded',
keymessage: 'webkitkeymessage'
}];
var APIS_ProtectionModel_3Feb2014 = [
// Un-prefixed as per spec
// Chrome 38-39 (and some earlier versions) with chrome://flags -- Enable Encrypted Media Extensions
{
// Video Element
setMediaKeys: 'setMediaKeys',
// MediaKeys
MediaKeys: 'MediaKeys',
// MediaKeySession
release: 'close',
// Events
needkey: 'needkey',
error: 'keyerror',
message: 'keymessage',
ready: 'keyadded',
close: 'keyclose'
},
// MS-prefixed (IE11, Windows 8.1)
{
// Video Element
setMediaKeys: 'msSetMediaKeys',
// MediaKeys
MediaKeys: 'MSMediaKeys',
// MediaKeySession
release: 'close',
// Events
needkey: 'msneedkey',
error: 'mskeyerror',
message: 'mskeymessage',
ready: 'mskeyadded',
close: 'mskeyclose'
}];
function Protection() {
var instance = undefined;
var context = this.context;
/**
* Create a ProtectionController and associated ProtectionModel for use with
* a single piece of content.
*
* @param {Object} config
* @return {ProtectionController} protection controller
*
*/
function createProtectionSystem(config) {
var controller = null;
var protectionKeyController = (0, _controllersProtectionKeyController2['default'])(context).getInstance();
protectionKeyController.setConfig({ debug: config.debug, BASE64: config.BASE64 });
protectionKeyController.initialize();
var protectionModel = getProtectionModel(config);
if (!controller && protectionModel) {
//TODO add ability to set external controller if still needed at all?
controller = (0, _controllersProtectionController2['default'])(context).create({
protectionModel: protectionModel,
protectionKeyController: protectionKeyController,
eventBus: config.eventBus,
debug: config.debug,
events: config.events,
BASE64: config.BASE64,
constants: config.constants
});
config.capabilities.setEncryptedMediaSupported(true);
}
return controller;
}
function getProtectionModel(config) {
var debug = config.debug;
var logger = debug.getLogger(instance);
var eventBus = config.eventBus;
var errHandler = config.errHandler;
var videoElement = config.videoModel ? config.videoModel.getElement() : null;
if ((!videoElement || videoElement.onencrypted !== undefined) && (!videoElement || videoElement.mediaKeys !== undefined)) {
logger.info('EME detected on this user agent! (ProtectionModel_21Jan2015)');
return (0, _modelsProtectionModel_21Jan20152['default'])(context).create({ debug: debug, eventBus: eventBus, events: config.events });
} else if (getAPI(videoElement, APIS_ProtectionModel_3Feb2014)) {
logger.info('EME detected on this user agent! (ProtectionModel_3Feb2014)');
return (0, _modelsProtectionModel_3Feb20142['default'])(context).create({ debug: debug, eventBus: eventBus, events: config.events, api: getAPI(videoElement, APIS_ProtectionModel_3Feb2014) });
} else if (getAPI(videoElement, APIS_ProtectionModel_01b)) {
logger.info('EME detected on this user agent! (ProtectionModel_01b)');
return (0, _modelsProtectionModel_01b2['default'])(context).create({ debug: debug, eventBus: eventBus, errHandler: errHandler, events: config.events, api: getAPI(videoElement, APIS_ProtectionModel_01b) });
} else {
logger.warn('No supported version of EME detected on this user agent! - Attempts to play encrypted content will fail!');
return null;
}
}
function getAPI(videoElement, apis) {
for (var i = 0; i < apis.length; i++) {
var api = apis[i];
// detect if api is supported by browser
// check only first function in api -> should be fine
if (typeof videoElement[api[Object.keys(api)[0]]] !== 'function') {
continue;
}
return api;
}
return null;
}
instance = {
createProtectionSystem: createProtectionSystem
};
return instance;
}
Protection.__dashjs_factory_name = 'Protection';
var factory = dashjs.FactoryMaker.getClassFactory(Protection); /* jshint ignore:line */
factory.events = _ProtectionEvents2['default'];
factory.errors = _errorsProtectionErrors2['default'];
dashjs.FactoryMaker.updateClassFactory(Protection.__dashjs_factory_name, factory); /* jshint ignore:line */
exports['default'] = factory;
module.exports = exports['default'];
},{"13":13,"14":14,"15":15,"16":16,"6":6,"7":7,"8":8}],6:[function(_dereq_,module,exports){
/**
* The copyright in this software is being made available under the BSD License,
* included below. This software may be subject to other third party and contributor
* rights, including patent rights, and no such rights are granted under this license.
*
* Copyright (c) 2013, Dash Industry Forum.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * Neither the name of Dash Industry Forum nor the names of its
* contributors may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
'use strict';
Object.defineProperty(exports, '__esModule', {
value: true
});
var _get = function get(_x, _x2, _x3) { var _again = true; _function: while (_again) { var object = _x, property = _x2, receiver = _x3; _again = false; if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { _x = parent; _x2 = property; _x3 = receiver; _again = true; desc = parent = undefined; continue _function; } } else if ('value' in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } } };
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
function _inherits(subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
var _coreEventsEventsBase = _dereq_(2);
var _coreEventsEventsBase2 = _interopRequireDefault(_coreEventsEventsBase);
/**
* @class
*/
var ProtectionEvents = (function (_EventsBase) {
_inherits(ProtectionEvents, _EventsBase);
/**
* @description Public facing external events to be used when including protection package.
* All public events will be aggregated into the MediaPlayerEvents Class and can be accessed
* via MediaPlayer.events. public_ is the prefix that we use to move event names to MediaPlayerEvents.
*/
function ProtectionEvents() {
_classCallCheck(this, ProtectionEvents);
_get(Object.getPrototypeOf(ProtectionEvents.prototype), 'constructor', this).call(this);
/**
* Event ID for events delivered when the protection set receives
* a key message from the CDM
*
* @ignore
*/
this.INTERNAL_KEY_MESSAGE = 'internalKeyMessage';
/**
* Event ID for events delivered when a key system selection procedure
* completes
* @ignore
*/
this.INTERNAL_KEY_SYSTEM_SELECTED = 'internalKeySystemSelected';
/**
* Event ID for events delivered when the status of one decryption keys has changed
* @ignore
*/
this.INTERNAL_KEY_STATUS_CHANGED = 'internalkeyStatusChanged';
/**
* Event ID for events delivered when a new key has been added
*
* @constant
* @deprecated The latest versions of the EME specification no longer
* use this event. {@MediaPlayer.models.protectionModel.eventList.KEY_STATUSES_CHANGED}
* is preferred.
* @event ProtectionEvents#KEY_ADDED
*/
this.KEY_ADDED = 'public_keyAdded';
/**
* Event ID for events delivered when an error is encountered by the CDM
* while processing a license server response message
* @event ProtectionEvents#KEY_ERROR
*/
this.KEY_ERROR = 'public_keyError';
/**
* Event ID for events delivered when the protection set receives
* a key message from the CDM
* @event ProtectionEvents#KEY_MESSAGE
*/
this.KEY_MESSAGE = 'public_keyMessage';
/**
* Event ID for events delivered when a key session close
* process has completed
* @event ProtectionEvents#KEY_SESSION_CLOSED
*/
this.KEY_SESSION_CLOSED = 'public_keySessionClosed';
/**
* Event ID for events delivered when a new key sessions creation
* process has completed
* @event ProtectionEvents#KEY_SESSION_CREATED
*/
this.KEY_SESSION_CREATED = 'public_keySessionCreated';
/**
* Event ID for events delivered when a key session removal
* process has completed
* @event ProtectionEvents#KEY_SESSION_REMOVED
*/
this.KEY_SESSION_REMOVED = 'public_keySessionRemoved';
/**
* Event ID for events delivered when the status of one or more
* decryption keys has changed
* @event ProtectionEvents#KEY_STATUSES_CHANGED
*/
this.KEY_STATUSES_CHANGED = 'public_keyStatusesChanged';
/**
* Event ID for events delivered when a key system access procedure
* has completed
* @ignore
*/
this.KEY_SYSTEM_ACCESS_COMPLETE = 'public_keySystemAccessComplete';
/**
* Event ID for events delivered when a key system selection procedure
* completes
* @event ProtectionEvents#KEY_SYSTEM_SELECTED
*/
this.KEY_SYSTEM_SELECTED = 'public_keySystemSelected';
/**
* Event ID for events delivered when a license request procedure
* has completed
* @event ProtectionEvents#LICENSE_REQUEST_COMPLETE
*/
this.LICENSE_REQUEST_COMPLETE = 'public_licenseRequestComplete';
/**
* Event ID for needkey/encrypted events
* @ignore
*/
this.NEED_KEY = 'needkey';
/**
* Event ID for events delivered when the Protection system is detected and created.
* @event ProtectionEvents#PROTECTION_CREATED
*/
this.PROTECTION_CREATED = 'public_protectioncreated';
/**
* Event ID for events delivered when the Protection system is destroyed.
* @event ProtectionEvents#PROTECTION_DESTROYED
*/
this.PROTECTION_DESTROYED = 'public_protectiondestroyed';
/**
* Event ID for events delivered when a new server certificate has
* been delivered to the CDM
* @ignore
*/
this.SERVER_CERTIFICATE_UPDATED = 'serverCertificateUpdated';
/**
* Event ID for events delivered when the process of shutting down
* a protection set has completed
* @ignore
*/
this.TEARDOWN_COMPLETE = 'protectionTeardownComplete';
/**
* Event ID for events delivered when a HTMLMediaElement has been
* associated with the protection set
* @ignore
*/
this.VIDEO_ELEMENT_SELECTED = 'videoElementSelected';
}
return ProtectionEvents;
})(_coreEventsEventsBase2['default']);
var protectionEvents = new ProtectionEvents();
exports['default'] = protectionEvents;
module.exports = exports['default'];
},{"2":2}],7:[function(_dereq_,module,exports){
/**
* The copyright in this software is being made available under the BSD License,
* included below. This software may be subject to other third party and contributor
* rights, including patent rights, and no such rights are granted under this license.
*
* Copyright (c) 2013, Dash Industry Forum.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * Neither the name of Dash Industry Forum nor the names of its
* contributors may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
'use strict';
Object.defineProperty(exports, '__esModule', {
value: true
});
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
var _CommonEncryption = _dereq_(4);
var _CommonEncryption2 = _interopRequireDefault(_CommonEncryption);
var _voMediaCapability = _dereq_(26);
var _voMediaCapability2 = _interopRequireDefault(_voMediaCapability);
var _voKeySystemConfiguration = _dereq_(25);
var _voKeySystemConfiguration2 = _interopRequireDefault(_voKeySystemConfiguration);
var _errorsProtectionErrors = _dereq_(13);
var _errorsProtectionErrors2 = _interopRequireDefault(_errorsProtectionErrors);
var _voDashJSError = _dereq_(28);
var _voDashJSError2 = _interopRequireDefault(_voDashJSError);
var NEEDKEY_BEFORE_INITIALIZE_RETRIES = 5;
var NEEDKEY_BEFORE_INITIALIZE_TIMEOUT = 500;
var LICENSE_SERVER_REQUEST_RETRIES = 3;
var LICENSE_SERVER_REQUEST_RETRY_INTERVAL = 1000;
var LICENSE_SERVER_REQUEST_DEFAULT_TIMEOUT = 8000;
/**
* @module ProtectionController
* @description Provides access to media protection information and functionality. Each
* ProtectionController manages a single {@link MediaPlayer.models.ProtectionModel}
* which encapsulates a set of protection information (EME APIs, selected key system,
* key sessions). The APIs of ProtectionController mostly align with the latest EME
* APIs. Key system selection is mostly automated when combined with app-overrideable
* functionality provided in {@link ProtectionKeyController}.
* @todo ProtectionController does almost all of its tasks automatically after init() is
* called. Applications might want more control over this process and want to go through
* each step manually (key system selection, session creation, session maintenance).
* @param {Object} config
*/
function ProtectionController(config) {
config = config || {};
var protectionKeyController = config.protectionKeyController;
var protectionModel = config.protectionModel;
var eventBus = config.eventBus;
var events = config.events;
var debug = config.debug;
var BASE64 = config.BASE64;
var constants = config.constants;
var needkeyRetries = [];
var instance = undefined,
logger = undefined,
pendingNeedKeyData = undefined,
mediaInfoArr = undefined,
protDataSet = undefined,
sessionType = undefined,
robustnessLevel = undefined,
keySystem = undefined;
function setup() {
logger = debug.getLogger(instance);
pendingNeedKeyData = [];
mediaInfoArr = [];
sessionType = 'temporary';
robustnessLevel = '';
}
function checkConfig() {
if (!eventBus || !eventBus.hasOwnProperty('on') || !protectionKeyController || !protectionKeyController.hasOwnProperty('getSupportedKeySystemsFromContentProtection')) {
throw new Error('Missing config parameter(s)');
}