@svta/cml-drm 1.0.1 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,12 +1,12 @@
1
1
  import { UTF_16, decodeBase64, decodeText, stringToUint16 } from "@svta/cml-utils";
2
2
  import { getElementsByName, parseXml } from "@svta/cml-xml";
3
+ import { createAudioSampleEntryReader, createVisualSampleEntryReader, findIsoBox, fourCcToUint32, readIsoBoxes, readStsd, writeAudioSampleEntryBox, writeFrma, writeIsoBoxes, writeSchm, writeStsd, writeTenc, writeVisualSampleEntryBox } from "@svta/cml-iso-bmff";
3
4
 
4
5
  //#region src/common/CBCS.ts
5
6
  /**
6
7
  * Cipher Block Chaining Sample encryption scheme.
7
8
  *
8
- *
9
- * @beta
9
+ * @public
10
10
  */
11
11
  const CBCS = "cbcs";
12
12
 
@@ -15,8 +15,7 @@ const CBCS = "cbcs";
15
15
  /**
16
16
  * Common Encryption scheme.
17
17
  *
18
- *
19
- * @beta
18
+ * @public
20
19
  */
21
20
  const CENC = "cenc";
22
21
 
@@ -25,7 +24,7 @@ const CENC = "cenc";
25
24
  /**
26
25
  * The DASH MP4 Protection Scheme schemeIdUri.
27
26
  *
28
- * @beta
27
+ * @public
29
28
  */
30
29
  const MP4_PROTECTION_SCHEME = "urn:mpeg:dash:mp4protection:2011";
31
30
 
@@ -37,7 +36,7 @@ const MP4_PROTECTION_SCHEME = "urn:mpeg:dash:mp4protection:2011";
37
36
  * @param cpArray - Array of ContentProtection elements.
38
37
  * @returns The Common Encryption content protection element, or null if not found.
39
38
  *
40
- * @beta
39
+ * @public
41
40
  *
42
41
  * @example
43
42
  * {@includeCode ../../test/cenc/findCencContentProtection.test.ts#example}
@@ -57,7 +56,7 @@ function findCencContentProtection(cpArray) {
57
56
  * @param schemeIdUri - schemeIdUri we are searching for.
58
57
  * @returns The license server URL, and if not found then null.
59
58
  *
60
- * @beta
59
+ * @public
61
60
  *
62
61
  * @example
63
62
  * {@includeCode ../../test/cenc/getLicenseServerUrlFromContentProtection.test.ts#example}
@@ -74,7 +73,7 @@ function getLicenseServerUrlFromContentProtection(contentProtectionElements, sch
74
73
  * @param pssh - The PSSH ArrayBuffer.
75
74
  * @returns The data portion of the PSSH.
76
75
  *
77
- * @beta
76
+ * @public
78
77
  *
79
78
  * @example
80
79
  * {@includeCode ../../test/cenc/getPsshData.test.ts#example}
@@ -103,7 +102,7 @@ function getPsshData(pssh) {
103
102
  * the detected key system UUIDs (e.g. 00000000-0000-0000-0000-0000000000)
104
103
  * and a ArrayBuffer (the entire PSSH box) as the property value
105
104
  *
106
- * @beta
105
+ * @public
107
106
  *
108
107
  * @example
109
108
  * {@includeCode ../../test/cenc/parsePsshList.test.ts#example}
@@ -180,7 +179,7 @@ function parsePsshList(data) {
180
179
  * @param initData - 'cenc' initialization data. Concatenated list of PSSH boxes.
181
180
  * @returns The PSSH box ArrayBuffer corresponding to the given key system, or null if not found.
182
181
  *
183
- * @beta
182
+ * @public
184
183
  *
185
184
  * @example
186
185
  * {@includeCode ../../test/cenc/getPsshForKeySystem.test.ts#example}
@@ -200,7 +199,7 @@ function getPsshForKeySystem(uuid, initData) {
200
199
  * @param BASE64 - The BASE64 reference.
201
200
  * @returns init data as an ArrayBuffer, or null if not found.
202
201
  *
203
- * @beta
202
+ * @public
204
203
  *
205
204
  * @example
206
205
  * {@includeCode ../../test/cenc/parseInitDataFromContentProtection.test.ts#example}
@@ -222,7 +221,7 @@ function parseInitDataFromContentProtection(cpData, BASE64) {
222
221
  * @param supportedVideo - supported video capabilities.
223
222
  * @returns KeySystemConfiguration object.
224
223
  *
225
- * @beta
224
+ * @public
226
225
  *
227
226
  * @example
228
227
  * {@includeCode ../../test/keysystem/createMediaKeySystemConfiguration.test.ts#example}
@@ -245,7 +244,7 @@ function createMediaKeySystemConfiguration(supportedAudio, supportedVideo) {
245
244
  * @param requests - An array of key system access requests.
246
245
  * @returns MediaKeySystemAccess object if successful, or null if no system is supported.
247
246
  *
248
- * @beta
247
+ * @public
249
248
  */
250
249
  async function getKeySystemAccess(requests) {
251
250
  for (const { keySystem, configurations } of requests) try {
@@ -264,7 +263,7 @@ const isTypeSupported = typeof MediaKeys !== "undefined" && typeof MediaKeys.isT
264
263
  * @param configs - An array of key system configurations.
265
264
  * @returns The first supported configuration or null if none are supported.
266
265
  *
267
- * @beta
266
+ * @public
268
267
  */
269
268
  function getSupportedKeySystemConfiguration(keySystem, configs) {
270
269
  if (!configs || typeof isTypeSupported === "undefined") return {
@@ -297,7 +296,7 @@ function getSupportedKeySystemConfiguration(keySystem, configs) {
297
296
  * @param requests - An array of key system access requests.
298
297
  * @returns A KeySystemAccess object if successful, or null if no system is supported.
299
298
  *
300
- * @beta
299
+ * @public
301
300
  */
302
301
  function getLegacyKeySystemAccess(requests) {
303
302
  for (const { keySystem, configurations } of requests) {
@@ -320,7 +319,7 @@ function getLegacyKeySystemAccess(requests) {
320
319
  * @param cert - The application certificate (Uint8Array)
321
320
  * @returns A Uint8Array containing the concatenated data
322
321
  *
323
- * @beta
322
+ * @public
324
323
  *
325
324
  * @example
326
325
  * {@includeCode ../../test/fairplay/concatInitDataIdAndCertificate.test.ts#example}
@@ -350,7 +349,7 @@ function concatInitDataIdAndCertificate(initData, id, cert) {
350
349
  * @param response - The license response, either a base64 string or ArrayBuffer
351
350
  * @returns A Uint8Array containing the decoded license
352
351
  *
353
- * @beta
352
+ * @public
354
353
  *
355
354
  * @example
356
355
  * {@includeCode ../../test/fairplay/decodeFairPlayLicense.test.ts#example}
@@ -367,7 +366,7 @@ function decodeFairPlayLicense(response) {
367
366
  * @param initData - The initialization data (PSSH box)
368
367
  * @returns The extracted content ID
369
368
  *
370
- * @beta
369
+ * @public
371
370
  *
372
371
  * @example
373
372
  * {@includeCode ../../test/fairplay/extractContentId.test.ts#example}
@@ -386,7 +385,7 @@ function extractContentId(initData, encoding = UTF_16) {
386
385
  * @param queryParam - The query parameter key to extract (default: 'ContentId')
387
386
  * @returns The extracted content ID as a string or null if not found
388
387
  *
389
- * @beta
388
+ * @public
390
389
  *
391
390
  * @example
392
391
  * {@includeCode ../../test/fairplay/getId.test.ts#example}
@@ -408,7 +407,7 @@ function getId(licenseServerUrl, initData, queryParam = "ContentId") {
408
407
  * @param initData - The initialization data (PSSH box)
409
408
  * @returns The license server URL as a string
410
409
  *
411
- * @beta
410
+ * @public
412
411
  *
413
412
  * @example
414
413
  * {@includeCode ../../test/fairplay/getLicenseServerUrl.test.ts#example}
@@ -425,8 +424,7 @@ function getLicenseServerUrl(initData) {
425
424
  /**
426
425
  * License Challenge.
427
426
  *
428
- *
429
- * @beta
427
+ * @public
430
428
  */
431
429
  const CHALLENGE = "Challenge";
432
430
 
@@ -435,8 +433,7 @@ const CHALLENGE = "Challenge";
435
433
  /**
436
434
  * Playready Key Message.
437
435
  *
438
- *
439
- * @beta
436
+ * @public
440
437
  */
441
438
  const PLAYREADY_KEY_MESSAGE = "PlayReadyKeyMessage";
442
439
 
@@ -449,7 +446,7 @@ const PLAYREADY_KEY_MESSAGE = "PlayReadyKeyMessage";
449
446
  * @param encoding - The message encoding type. Default is UTF-16.
450
447
  * @returns The license request as an ArrayBuffer.
451
448
  *
452
- * @beta
449
+ * @public
453
450
  *
454
451
  * @example
455
452
  * {@includeCode ../../test/playready/getLicenseRequestFromMessage.test.ts#example}
@@ -468,8 +465,7 @@ function getLicenseRequestFromMessage(message, encoding = UTF_16) {
468
465
  /**
469
466
  * Content-Type header.
470
467
  *
471
- *
472
- * @beta
468
+ * @public
473
469
  */
474
470
  const CONTENT_TYPE = "Content-Type";
475
471
 
@@ -478,8 +474,7 @@ const CONTENT_TYPE = "Content-Type";
478
474
  /**
479
475
  * Playready HTTP Headers.
480
476
  *
481
- *
482
- * @beta
477
+ * @public
483
478
  */
484
479
  const HTTP_HEADERS = "HttpHeaders";
485
480
 
@@ -488,8 +483,7 @@ const HTTP_HEADERS = "HttpHeaders";
488
483
  /**
489
484
  * XML formatted, UTF-8 encoded, text header.
490
485
  *
491
- *
492
- * @beta
486
+ * @public
493
487
  */
494
488
  const TEXT_XML_UTF8 = "text/xml; charset=utf-8";
495
489
 
@@ -502,7 +496,7 @@ const TEXT_XML_UTF8 = "text/xml; charset=utf-8";
502
496
  * @param encoding - The message encoding type. Default is UTF-16.
503
497
  * @returns Request headers.
504
498
  *
505
- * @beta
499
+ * @public
506
500
  *
507
501
  * @example
508
502
  * {@includeCode ../../test/playready/getRequestHeadersFromMessage.test.ts#example}
@@ -536,7 +530,7 @@ function getRequestHeadersFromMessage(message, encoding = UTF_16) {
536
530
  * @param keyId - The little-endian key ID to convert.
537
531
  * @returns The big-endian representation of the key ID.
538
532
  *
539
- * @beta
533
+ * @public
540
534
  *
541
535
  * @example
542
536
  * {@includeCode ../../test/playready/toBigEndianKeyId.test.ts#example}
@@ -556,8 +550,7 @@ function toBigEndianKeyId(keyId) {
556
550
  /**
557
551
  * Clear Key System.
558
552
  *
559
- *
560
- * @beta
553
+ * @public
561
554
  */
562
555
  const CLEAR_KEY_SYSTEM = "org.w3.clearkey";
563
556
 
@@ -566,8 +559,7 @@ const CLEAR_KEY_SYSTEM = "org.w3.clearkey";
566
559
  /**
567
560
  * Clear Key UUID.
568
561
  *
569
- *
570
- * @beta
562
+ * @public
571
563
  */
572
564
  const CLEAR_KEY_UUID = "e2719d58-a985-b3c9-781a-b030af78d30e";
573
565
 
@@ -576,8 +568,7 @@ const CLEAR_KEY_UUID = "e2719d58-a985-b3c9-781a-b030af78d30e";
576
568
  /**
577
569
  * Encryption schemes.
578
570
  *
579
- *
580
- * @beta
571
+ * @public
581
572
  */
582
573
  const EncryptionScheme = {
583
574
  CENC,
@@ -589,8 +580,7 @@ const EncryptionScheme = {
589
580
  /**
590
581
  * Expired Media Key Status.
591
582
  *
592
- *
593
- * @beta
583
+ * @public
594
584
  */
595
585
  const EXPIRED = "expired";
596
586
 
@@ -599,8 +589,7 @@ const EXPIRED = "expired";
599
589
  /**
600
590
  * FairPlay Key System.
601
591
  *
602
- *
603
- * @beta
592
+ * @public
604
593
  */
605
594
  const FAIRPLAY_KEY_SYSTEM = "com.apple.fps.1_0";
606
595
 
@@ -609,8 +598,7 @@ const FAIRPLAY_KEY_SYSTEM = "com.apple.fps.1_0";
609
598
  /**
610
599
  * FairPlay UUID.
611
600
  *
612
- *
613
- * @beta
601
+ * @public
614
602
  */
615
603
  const FAIRPLAY_UUID = "29701fe4-3cc7-4a34-8c5b-ae90c7439a47";
616
604
 
@@ -619,8 +607,7 @@ const FAIRPLAY_UUID = "29701fe4-3cc7-4a34-8c5b-ae90c7439a47";
619
607
  /**
620
608
  * Hardware Secure All Robustness.
621
609
  *
622
- *
623
- * @beta
610
+ * @public
624
611
  */
625
612
  const HW_SECURE_ALL = "HW_SECURE_ALL";
626
613
 
@@ -629,8 +616,7 @@ const HW_SECURE_ALL = "HW_SECURE_ALL";
629
616
  /**
630
617
  * Hardware Secure Crypto Robustness.
631
618
  *
632
- *
633
- * @beta
619
+ * @public
634
620
  */
635
621
  const HW_SECURE_CRYPTO = "HW_SECURE_CRYPTO";
636
622
 
@@ -639,8 +625,7 @@ const HW_SECURE_CRYPTO = "HW_SECURE_CRYPTO";
639
625
  /**
640
626
  * Hardware Secure Decode Robustness.
641
627
  *
642
- *
643
- * @beta
628
+ * @public
644
629
  */
645
630
  const HW_SECURE_DECODE = "HW_SECURE_DECODE";
646
631
 
@@ -649,8 +634,7 @@ const HW_SECURE_DECODE = "HW_SECURE_DECODE";
649
634
  /**
650
635
  * Individualization Request.
651
636
  *
652
- *
653
- * @beta
637
+ * @public
654
638
  */
655
639
  const INDIVIDUALIZATION_REQUEST = "individualization-request";
656
640
 
@@ -659,8 +643,7 @@ const INDIVIDUALIZATION_REQUEST = "individualization-request";
659
643
  /**
660
644
  * Key IDs.
661
645
  *
662
- *
663
- * @beta
646
+ * @public
664
647
  */
665
648
  const KEYIDS = "keyids";
666
649
 
@@ -669,8 +652,7 @@ const KEYIDS = "keyids";
669
652
  /**
670
653
  * WEBM.
671
654
  *
672
- *
673
- * @beta
655
+ * @public
674
656
  */
675
657
  const WEBM = "webm";
676
658
 
@@ -679,8 +661,7 @@ const WEBM = "webm";
679
661
  /**
680
662
  * Initialization Data Type.
681
663
  *
682
- *
683
- * @beta
664
+ * @public
684
665
  */
685
666
  const InitializationDataType = {
686
667
  CENC,
@@ -694,8 +675,7 @@ const InitializationDataType = {
694
675
  /**
695
676
  * Internal Error Media Key Status.
696
677
  *
697
- *
698
- * @beta
678
+ * @public
699
679
  */
700
680
  const INTERNAL_ERROR = "internal-error";
701
681
 
@@ -704,8 +684,7 @@ const INTERNAL_ERROR = "internal-error";
704
684
  /**
705
685
  * License Acquisition.
706
686
  *
707
- *
708
- * @beta
687
+ * @public
709
688
  */
710
689
  const LICENSE_ACQUISITION = "LicenseAcquisition";
711
690
 
@@ -714,8 +693,7 @@ const LICENSE_ACQUISITION = "LicenseAcquisition";
714
693
  /**
715
694
  * License Release.
716
695
  *
717
- *
718
- * @beta
696
+ * @public
719
697
  */
720
698
  const LICENSE_RELEASE = "license-release";
721
699
 
@@ -724,8 +702,7 @@ const LICENSE_RELEASE = "license-release";
724
702
  /**
725
703
  * License Renewal.
726
704
  *
727
- *
728
- * @beta
705
+ * @public
729
706
  */
730
707
  const LICENSE_RENEWAL = "license-renewal";
731
708
 
@@ -734,8 +711,7 @@ const LICENSE_RENEWAL = "license-renewal";
734
711
  /**
735
712
  * License Request.
736
713
  *
737
- *
738
- * @beta
714
+ * @public
739
715
  */
740
716
  const LICENSE_REQUEST = "license-request";
741
717
 
@@ -744,8 +720,7 @@ const LICENSE_REQUEST = "license-request";
744
720
  /**
745
721
  * Media Key Message Types.
746
722
  *
747
- *
748
- * @beta
723
+ * @public
749
724
  */
750
725
  const MediaKeyMessageType = {
751
726
  LICENSE_REQUEST,
@@ -759,8 +734,7 @@ const MediaKeyMessageType = {
759
734
  /**
760
735
  * Output Downscaled Media Key Status.
761
736
  *
762
- *
763
- * @beta
737
+ * @public
764
738
  */
765
739
  const OUTPUT_DOWNSCALED = "output-downscaled";
766
740
 
@@ -769,8 +743,7 @@ const OUTPUT_DOWNSCALED = "output-downscaled";
769
743
  /**
770
744
  * Output Restricted Media Key Status.
771
745
  *
772
- *
773
- * @beta
746
+ * @public
774
747
  */
775
748
  const OUTPUT_RESTRICTED = "output-restricted";
776
749
 
@@ -779,8 +752,7 @@ const OUTPUT_RESTRICTED = "output-restricted";
779
752
  /**
780
753
  * Released Media Key Status.
781
754
  *
782
- *
783
- * @beta
755
+ * @public
784
756
  */
785
757
  const RELEASED = "released";
786
758
 
@@ -789,8 +761,7 @@ const RELEASED = "released";
789
761
  /**
790
762
  * Status Pending Media Key Status.
791
763
  *
792
- *
793
- * @beta
764
+ * @public
794
765
  */
795
766
  const STATUS_PENDING = "status-pending";
796
767
 
@@ -799,8 +770,7 @@ const STATUS_PENDING = "status-pending";
799
770
  /**
800
771
  * Usable Media Key Status.
801
772
  *
802
- *
803
- * @beta
773
+ * @public
804
774
  */
805
775
  const USABLE = "usable";
806
776
 
@@ -809,8 +779,7 @@ const USABLE = "usable";
809
779
  /**
810
780
  * Media Key Statuses.
811
781
  *
812
- *
813
- * @beta
782
+ * @public
814
783
  */
815
784
  const MediaKeyStatus = {
816
785
  USABLE,
@@ -827,8 +796,7 @@ const MediaKeyStatus = {
827
796
  /**
828
797
  * Playready Key System.
829
798
  *
830
- *
831
- * @beta
799
+ * @public
832
800
  */
833
801
  const PLAYREADY_KEY_SYSTEM = "com.microsoft.playready";
834
802
 
@@ -837,8 +805,7 @@ const PLAYREADY_KEY_SYSTEM = "com.microsoft.playready";
837
805
  /**
838
806
  * Playready Recommendation Key System.
839
807
  *
840
- *
841
- * @beta
808
+ * @public
842
809
  */
843
810
  const PLAYREADY_RECOMMENDATION_KEY_SYSTEM = "com.microsoft.playready.recommendation";
844
811
 
@@ -847,8 +814,7 @@ const PLAYREADY_RECOMMENDATION_KEY_SYSTEM = "com.microsoft.playready.recommendat
847
814
  /**
848
815
  * Playready UUID.
849
816
  *
850
- *
851
- * @beta
817
+ * @public
852
818
  */
853
819
  const PLAYREADY_UUID = "9a04f079-9840-4286-ab92-e65be0885f95";
854
820
 
@@ -857,8 +823,7 @@ const PLAYREADY_UUID = "9a04f079-9840-4286-ab92-e65be0885f95";
857
823
  /**
858
824
  * Software Secure Crypto Robustness.
859
825
  *
860
- *
861
- * @beta
826
+ * @public
862
827
  */
863
828
  const SW_SECURE_CRYPTO = "SW_SECURE_CRYPTO";
864
829
 
@@ -867,8 +832,7 @@ const SW_SECURE_CRYPTO = "SW_SECURE_CRYPTO";
867
832
  /**
868
833
  * Software Secure Decode Robustness.
869
834
  *
870
- *
871
- * @beta
835
+ * @public
872
836
  */
873
837
  const SW_SECURE_DECODE = "SW_SECURE_DECODE";
874
838
 
@@ -877,8 +841,7 @@ const SW_SECURE_DECODE = "SW_SECURE_DECODE";
877
841
  /**
878
842
  * W3C Clear Key UUID.
879
843
  *
880
- *
881
- * @beta
844
+ * @public
882
845
  */
883
846
  const W3C_CLEAR_KEY_UUID = "1077efec-c0b2-4d02-ace3-3c1e52e2fb4b";
884
847
 
@@ -887,8 +850,7 @@ const W3C_CLEAR_KEY_UUID = "1077efec-c0b2-4d02-ace3-3c1e52e2fb4b";
887
850
  /**
888
851
  * Widevine Key System.
889
852
  *
890
- *
891
- * @beta
853
+ * @public
892
854
  */
893
855
  const WIDEVINE_KEY_SYSTEM = "com.widevine.alpha";
894
856
 
@@ -897,8 +859,7 @@ const WIDEVINE_KEY_SYSTEM = "com.widevine.alpha";
897
859
  /**
898
860
  * Widevine UUID.
899
861
  *
900
- *
901
- * @beta
862
+ * @public
902
863
  */
903
864
  const WIDEVINE_UUID = "edef8ba9-79d6-4ace-a3c8-27dcd51d21ed";
904
865
 
@@ -907,8 +868,7 @@ const WIDEVINE_UUID = "edef8ba9-79d6-4ace-a3c8-27dcd51d21ed";
907
868
  /**
908
869
  * Widevine Robustness.
909
870
  *
910
- *
911
- * @beta
871
+ * @public
912
872
  */
913
873
  const WidevineRobustness = {
914
874
  SW_SECURE_CRYPTO,
@@ -919,5 +879,128 @@ const WidevineRobustness = {
919
879
  };
920
880
 
921
881
  //#endregion
922
- export { CBCS, CENC, CHALLENGE, CLEAR_KEY_SYSTEM, CLEAR_KEY_UUID, CONTENT_TYPE, EXPIRED, EncryptionScheme, FAIRPLAY_KEY_SYSTEM, FAIRPLAY_UUID, HTTP_HEADERS, HW_SECURE_ALL, HW_SECURE_CRYPTO, HW_SECURE_DECODE, INDIVIDUALIZATION_REQUEST, INTERNAL_ERROR, InitializationDataType, KEYIDS, LICENSE_ACQUISITION, LICENSE_RELEASE, LICENSE_RENEWAL, LICENSE_REQUEST, MP4_PROTECTION_SCHEME, MediaKeyMessageType, MediaKeyStatus, OUTPUT_DOWNSCALED, OUTPUT_RESTRICTED, PLAYREADY_KEY_MESSAGE, PLAYREADY_KEY_SYSTEM, PLAYREADY_RECOMMENDATION_KEY_SYSTEM, PLAYREADY_UUID, RELEASED, STATUS_PENDING, SW_SECURE_CRYPTO, SW_SECURE_DECODE, TEXT_XML_UTF8, USABLE, W3C_CLEAR_KEY_UUID, WEBM, WIDEVINE_KEY_SYSTEM, WIDEVINE_UUID, WidevineRobustness, concatInitDataIdAndCertificate, createMediaKeySystemConfiguration, decodeFairPlayLicense, extractContentId, findCencContentProtection, getId, getKeySystemAccess, getLegacyKeySystemAccess, getLicenseRequestFromMessage, getLicenseServerUrl, getLicenseServerUrlFromContentProtection, getPsshData, getPsshForKeySystem, getRequestHeadersFromMessage, getSupportedKeySystemConfiguration, parseInitDataFromContentProtection, parsePsshList, toBigEndianKeyId };
882
+ //#region src/ensureEncryptedInit.ts
883
+ const audioTypes = [
884
+ "mp4a",
885
+ "ac-3",
886
+ "ec-3",
887
+ "ac-4",
888
+ "fLaC",
889
+ "Opus"
890
+ ];
891
+ const videoTypes = [
892
+ "dvh1",
893
+ "dvhe",
894
+ "hev1",
895
+ "hvc1",
896
+ "avc1",
897
+ "avc3",
898
+ "dvav",
899
+ "dva1",
900
+ "dvc1",
901
+ "dvi1"
902
+ ];
903
+ const readers = { stsd: readStsd };
904
+ audioTypes.forEach((type) => readers[type] = createAudioSampleEntryReader(type));
905
+ videoTypes.forEach((type) => readers[type] = createVisualSampleEntryReader(type));
906
+ const writers = {
907
+ stsd: writeStsd,
908
+ frma: writeFrma,
909
+ schm: writeSchm,
910
+ tenc: writeTenc,
911
+ encv: writeVisualSampleEntryBox,
912
+ enca: writeAudioSampleEntryBox
913
+ };
914
+ audioTypes.forEach((type) => writers[type] = writeAudioSampleEntryBox);
915
+ videoTypes.forEach((type) => writers[type] = writeVisualSampleEntryBox);
916
+ /**
917
+ * Ensures that the init segment is encrypted. Used on platforms that have issues playing unencrypted
918
+ * content before playing encrypted content. Both prepend and includeOriginal are optional.
919
+ *
920
+ * @param init - The init segment to ensure is encrypted.
921
+ * @param options - The options for the encryption.
922
+ *
923
+ * @returns The encrypted init segment.
924
+ *
925
+ * @public
926
+ *
927
+ * @example
928
+ * {@includeCode ../test/ensureEncryptedInit.test.ts#example}
929
+ */
930
+ function ensureEncryptedInit(init, options) {
931
+ const { prepend = true, includeOriginal = true, schemeType = 1667591779, defaultKid = [
932
+ 0,
933
+ 0,
934
+ 0,
935
+ 0,
936
+ 0,
937
+ 0,
938
+ 0,
939
+ 0,
940
+ 0,
941
+ 0,
942
+ 0,
943
+ 0,
944
+ 0,
945
+ 0,
946
+ 0,
947
+ 0
948
+ ] } = options ?? {};
949
+ const boxes = readIsoBoxes(init, { readers });
950
+ const stsd = findIsoBox(boxes, (box) => box.type === "stsd");
951
+ if (stsd?.type !== "stsd") return init;
952
+ if (stsd.entries.find(({ type }) => type === "enca" || type === "encv")) return init;
953
+ const entries = stsd.entries.filter(({ type }) => videoTypes.includes(type) || audioTypes.includes(type));
954
+ for (const entry of entries) {
955
+ const type = videoTypes.includes(entry.type) ? "encv" : "enca";
956
+ const box = {
957
+ ...entry,
958
+ boxes: entry.boxes.slice(),
959
+ type
960
+ };
961
+ if (prepend) stsd.entries.unshift(box);
962
+ else stsd.entries.push(box);
963
+ box.boxes.push({
964
+ type: "sinf",
965
+ boxes: [
966
+ {
967
+ type: "frma",
968
+ dataFormat: fourCcToUint32(entry.type)
969
+ },
970
+ {
971
+ type: "schm",
972
+ version: 0,
973
+ flags: 0,
974
+ schemeType,
975
+ schemeVersion: 65536
976
+ },
977
+ {
978
+ type: "schi",
979
+ boxes: [{
980
+ type: "tenc",
981
+ version: 0,
982
+ flags: 0,
983
+ defaultIsEncrypted: 1,
984
+ defaultIvSize: 8,
985
+ defaultKid
986
+ }]
987
+ }
988
+ ]
989
+ });
990
+ }
991
+ const chunks = writeIsoBoxes(boxes, { writers });
992
+ const size = chunks.reduce((acc, chunk) => acc + chunk.byteLength, 0);
993
+ const length = includeOriginal ? init.length + size : size;
994
+ const result = new Uint8Array(length);
995
+ let offset = 0;
996
+ for (const box of chunks) {
997
+ result.set(box, offset);
998
+ offset += box.byteLength;
999
+ }
1000
+ if (includeOriginal) result.set(init, offset);
1001
+ return result;
1002
+ }
1003
+
1004
+ //#endregion
1005
+ export { CBCS, CENC, CHALLENGE, CLEAR_KEY_SYSTEM, CLEAR_KEY_UUID, CONTENT_TYPE, EXPIRED, EncryptionScheme, FAIRPLAY_KEY_SYSTEM, FAIRPLAY_UUID, HTTP_HEADERS, HW_SECURE_ALL, HW_SECURE_CRYPTO, HW_SECURE_DECODE, INDIVIDUALIZATION_REQUEST, INTERNAL_ERROR, InitializationDataType, KEYIDS, LICENSE_ACQUISITION, LICENSE_RELEASE, LICENSE_RENEWAL, LICENSE_REQUEST, MP4_PROTECTION_SCHEME, MediaKeyMessageType, MediaKeyStatus, OUTPUT_DOWNSCALED, OUTPUT_RESTRICTED, PLAYREADY_KEY_MESSAGE, PLAYREADY_KEY_SYSTEM, PLAYREADY_RECOMMENDATION_KEY_SYSTEM, PLAYREADY_UUID, RELEASED, STATUS_PENDING, SW_SECURE_CRYPTO, SW_SECURE_DECODE, TEXT_XML_UTF8, USABLE, W3C_CLEAR_KEY_UUID, WEBM, WIDEVINE_KEY_SYSTEM, WIDEVINE_UUID, WidevineRobustness, concatInitDataIdAndCertificate, createMediaKeySystemConfiguration, decodeFairPlayLicense, ensureEncryptedInit, extractContentId, findCencContentProtection, getId, getKeySystemAccess, getLegacyKeySystemAccess, getLicenseRequestFromMessage, getLicenseServerUrl, getLicenseServerUrlFromContentProtection, getPsshData, getPsshForKeySystem, getRequestHeadersFromMessage, getSupportedKeySystemConfiguration, parseInitDataFromContentProtection, parsePsshList, toBigEndianKeyId };
923
1006
  //# sourceMappingURL=index.js.map