27
27
import android .os .Looper ;
28
28
import android .os .Message ;
29
29
import android .os .SystemClock ;
30
+ import android .util .Base64 ;
30
31
import androidx .annotation .IntDef ;
31
32
import androidx .annotation .Nullable ;
32
33
import androidx .media3 .common .C ;
52
53
import java .lang .annotation .RetentionPolicy ;
53
54
import java .lang .annotation .Target ;
54
55
import java .util .ArrayList ;
55
- import java .util .Arrays ;
56
56
import java .util .Collections ;
57
57
import java .util .HashMap ;
58
58
import java .util .HashSet ;
@@ -329,7 +329,7 @@ private MissingSchemeDataException(UUID uuid) {
329
329
330
330
// MIREGO: multiple offline DRM keys.
331
331
private List <byte []> offlineLicenseKeySetIdList ;
332
- private List <Integer > drmInitDataHashList ;
332
+ private List <String > drmInitDataUidList ;
333
333
334
334
private @ MonotonicNonNull PlayerId playerId ;
335
335
@@ -396,19 +396,29 @@ public void setMode(@Mode int mode, @Nullable byte[] offlineLicenseKeySetId) {
396
396
this .mode = mode ;
397
397
// MIREGO: multiple offline DRM keys.
398
398
this .offlineLicenseKeySetIdList = (offlineLicenseKeySetId != null ) ? ImmutableList .of (offlineLicenseKeySetId ) : Collections .emptyList ();
399
- this .drmInitDataHashList = Collections .emptyList ();
399
+ this .drmInitDataUidList = Collections .emptyList ();
400
400
}
401
401
402
402
// MIREGO: multiple offline DRM keys. Added function
403
- public void setMode (@ Mode int mode , List <byte []> offlineLicenseKeySetIdList , List <Integer > drmInitDataHashList ) {
403
+ public void setMode (@ Mode int mode , List <byte []> offlineLicenseKeySetIdList , List <String > drmInitDataUidList ) {
404
404
Log .d (TAG , "setMode %d offlineLicenseKeySetId size=%s" , mode , offlineLicenseKeySetIdList .size ());
405
405
checkState (sessions .isEmpty ());
406
406
if (mode == MODE_QUERY || mode == MODE_RELEASE ) {
407
407
checkArgument (!offlineLicenseKeySetIdList .isEmpty ());
408
408
}
409
409
this .mode = mode ;
410
410
this .offlineLicenseKeySetIdList = offlineLicenseKeySetIdList ;
411
- this .drmInitDataHashList = drmInitDataHashList ;
411
+ this .drmInitDataUidList = drmInitDataUidList ;
412
+ }
413
+
414
+ public static String getDrmInitDataUuid (DrmInitData drmInitData ) {
415
+ for (int i = 0 ; i < drmInitData .schemeDataCount ; i ++) {
416
+ SchemeData schemeData = drmInitData .get (i );
417
+ if (schemeData .matches (C .WIDEVINE_UUID ) && schemeData .hasData ()) {
418
+ return Base64 .encodeToString (schemeData .data , Base64 .DEFAULT );
419
+ }
420
+ }
421
+ return "" ;
412
422
}
413
423
414
424
// DrmSessionManager implementation.
@@ -535,7 +545,7 @@ private DrmSession acquireSession(
535
545
session =
536
546
createAndAcquireSessionWithRetry (
537
547
schemeDatas ,
538
- format .drmInitData . hashCode ( ), // MIREGO: multiple offline DRM keys
548
+ getDrmInitDataUuid ( format .drmInitData ), // MIREGO: multiple offline DRM keys
539
549
/* isPlaceholderSession= */ false ,
540
550
eventDispatcher ,
541
551
shouldReleasePreacquiredSessionsBeforeRetrying );
@@ -583,7 +593,7 @@ private DrmSession maybeAcquirePlaceholderSession(
583
593
DefaultDrmSession placeholderDrmSession =
584
594
createAndAcquireSessionWithRetry (
585
595
/* schemeDatas= */ ImmutableList .of (),
586
- 0 , // MIREGO: multiple offline DRM keys
596
+ "" , // MIREGO: multiple offline DRM keys
587
597
/* isPlaceholderSession= */ true ,
588
598
/* eventDispatcher= */ null ,
589
599
shouldReleasePreacquiredSessionsBeforeRetrying );
@@ -649,18 +659,18 @@ private void maybeCreateMediaDrmHandler(Looper playbackLooper) {
649
659
650
660
private DefaultDrmSession createAndAcquireSessionWithRetry (
651
661
@ Nullable List <SchemeData > schemeDatas ,
652
- int drmInitDataHash , // MIREGO: multiple offline DRM keys
662
+ String drmInitDataUid , // MIREGO: multiple offline DRM keys
653
663
boolean isPlaceholderSession ,
654
664
@ Nullable DrmSessionEventListener .EventDispatcher eventDispatcher ,
655
665
boolean shouldReleasePreacquiredSessionsBeforeRetrying ) {
656
666
DefaultDrmSession session =
657
- createAndAcquireSession (schemeDatas , drmInitDataHash , isPlaceholderSession , eventDispatcher ); // MIREGO: multiple offline DRM keys
667
+ createAndAcquireSession (schemeDatas , drmInitDataUid , isPlaceholderSession , eventDispatcher ); // MIREGO: multiple offline DRM keys
658
668
// If we're short on DRM session resources, first try eagerly releasing all our keepalive
659
669
// sessions and then retry the acquisition.
660
670
if (acquisitionFailedIndicatingResourceShortage (session ) && !keepaliveSessions .isEmpty ()) {
661
671
releaseAllKeepaliveSessions ();
662
672
undoAcquisition (session , eventDispatcher );
663
- session = createAndAcquireSession (schemeDatas , drmInitDataHash , isPlaceholderSession , eventDispatcher ); // MIREGO: multiple offline DRM keys
673
+ session = createAndAcquireSession (schemeDatas , drmInitDataUid , isPlaceholderSession , eventDispatcher ); // MIREGO: multiple offline DRM keys
664
674
}
665
675
666
676
// If the acquisition failed again due to continued resource shortage, and
@@ -676,7 +686,7 @@ private DefaultDrmSession createAndAcquireSessionWithRetry(
676
686
releaseAllKeepaliveSessions ();
677
687
}
678
688
undoAcquisition (session , eventDispatcher );
679
- session = createAndAcquireSession (schemeDatas , drmInitDataHash , isPlaceholderSession , eventDispatcher ); // MIREGO: multiple offline DRM keys
689
+ session = createAndAcquireSession (schemeDatas , drmInitDataUid , isPlaceholderSession , eventDispatcher ); // MIREGO: multiple offline DRM keys
680
690
}
681
691
return session ;
682
692
}
@@ -691,7 +701,7 @@ private static boolean acquisitionFailedIndicatingResourceShortage(DrmSession se
691
701
}
692
702
693
703
/**
694
- * Undoes the acquisitions from {@link #createAndAcquireSession(List, boolean,
704
+ * Undoes the acquisitions from {@link #createAndAcquireSession(List, int, boolean,
695
705
* DrmSessionEventListener.EventDispatcher)}.
696
706
*/
697
707
private void undoAcquisition (
@@ -730,7 +740,7 @@ private void releaseAllPreacquiredSessions() {
730
740
*/
731
741
private DefaultDrmSession createAndAcquireSession (
732
742
@ Nullable List <SchemeData > schemeDatas ,
733
- int drmInitDataHash , // MIREGO: multiple offline DRM keys
743
+ String drmInitDataUid , // MIREGO: multiple offline DRM keys
734
744
boolean isPlaceholderSession ,
735
745
@ Nullable DrmSessionEventListener .EventDispatcher eventDispatcher ) {
736
746
checkNotNull (exoMediaDrm );
@@ -742,7 +752,7 @@ private DefaultDrmSession createAndAcquireSession(
742
752
if (offlineLicenseKeySetIdList .size () == 1 ) { // Keep legacy behavior with single offline key (just use it)
743
753
offlineLicenseKeySetId = offlineLicenseKeySetIdList .get (0 );
744
754
} else if (!offlineLicenseKeySetIdList .isEmpty ()){ //multiple offline DRM keys. Find the right keyId from the drmInitData hash
745
- int index = drmInitDataHashList .indexOf (drmInitDataHash );
755
+ int index = drmInitDataUidList .indexOf (drmInitDataUid );
746
756
if (index >= 0 ) {
747
757
offlineLicenseKeySetId = offlineLicenseKeySetIdList .get (index );
748
758
} else { // oops, we haven't found the drmInitData hash. We might as well fallback to the first key.
0 commit comments