From 9af85d9b25218d0cd088e41b0cf8f0e06c7fa0e2 Mon Sep 17 00:00:00 2001 From: tonihei Date: Fri, 19 Nov 2021 09:14:29 +0000 Subject: [PATCH] Move DrmSessionManager initial player setup to its own method. Currently, DrmSessionManager takes player specific values (= the playback looper) through (pre)acquireSession calls and requires the caller to pass in the same values every time. Instead, we can configure the DrmSessionManager for playback with a player once before it's being used. We can't simply extend the prepare() method as prepare may be called before the player is created to prewarm the DrmSessionManager. The new method also takes a PlayerId which is bound to the lifetime of the player similar to the playback looper. To avoid breakage of custom MediaSources with DRM, we can keep the old the SampleQueue.createWithDrm method as deprecated. PiperOrigin-RevId: 410998240 --- .../drm/DefaultDrmSessionManager.java | 29 ++-- .../exoplayer/drm/DrmSessionManager.java | 37 +++-- .../exoplayer/drm/OfflineLicenseHelper.java | 6 +- .../source/ProgressiveMediaPeriod.java | 6 +- .../source/ProgressiveMediaSource.java | 3 + .../media3/exoplayer/source/SampleQueue.java | 38 +++-- .../source/chunk/ChunkSampleStream.java | 7 +- .../drm/DefaultDrmSessionManagerTest.java | 157 ++++++------------ .../exoplayer/source/SampleQueueTest.java | 42 ++--- .../exoplayer/dash/DashMediaSource.java | 2 + .../media3/exoplayer/hls/HlsMediaSource.java | 3 + .../exoplayer/hls/HlsSampleStreamWrapper.java | 11 +- .../smoothstreaming/SsMediaSource.java | 2 + .../media3/test/utils/FakeMediaSource.java | 4 + .../media3/test/utils/FakeSampleStream.java | 8 +- 15 files changed, 147 insertions(+), 208 deletions(-) diff --git a/libraries/exoplayer/src/main/java/androidx/media3/exoplayer/drm/DefaultDrmSessionManager.java b/libraries/exoplayer/src/main/java/androidx/media3/exoplayer/drm/DefaultDrmSessionManager.java index ca4eb1fa0f..b2aca0f79b 100644 --- a/libraries/exoplayer/src/main/java/androidx/media3/exoplayer/drm/DefaultDrmSessionManager.java +++ b/libraries/exoplayer/src/main/java/androidx/media3/exoplayer/drm/DefaultDrmSessionManager.java @@ -18,6 +18,7 @@ package androidx.media3.exoplayer.drm; import static androidx.media3.common.util.Assertions.checkArgument; import static androidx.media3.common.util.Assertions.checkNotNull; import static androidx.media3.common.util.Assertions.checkState; +import static androidx.media3.common.util.Assertions.checkStateNotNull; import android.annotation.SuppressLint; import android.media.ResourceBusyException; @@ -37,6 +38,7 @@ import androidx.media3.common.PlaybackException; import androidx.media3.common.util.Log; import androidx.media3.common.util.UnstableApi; import androidx.media3.common.util.Util; +import androidx.media3.exoplayer.analytics.PlayerId; import androidx.media3.exoplayer.drm.DrmSession.DrmSessionException; import androidx.media3.exoplayer.drm.ExoMediaDrm.OnEventListener; import androidx.media3.exoplayer.upstream.DefaultLoadErrorHandlingPolicy; @@ -61,7 +63,7 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull; * A {@link DrmSessionManager} that supports playbacks using {@link ExoMediaDrm}. * *

This implementation supports pre-acquisition of sessions using {@link - * #preacquireSession(Looper, DrmSessionEventListener.EventDispatcher, Format)}. + * #preacquireSession(DrmSessionEventListener.EventDispatcher, Format)}. */ @RequiresApi(18) @UnstableApi @@ -422,8 +424,8 @@ public class DefaultDrmSessionManager implements DrmSessionManager { /** * Sets the mode, which determines the role of sessions acquired from the instance. This must be - * called before {@link #acquireSession(Looper, DrmSessionEventListener.EventDispatcher, Format)} - * is called. + * called before {@link #acquireSession(DrmSessionEventListener.EventDispatcher, Format)} is + * called. * *

By default, the mode is {@link #MODE_PLAYBACK} and a streaming license is requested when * required. @@ -491,12 +493,15 @@ public class DefaultDrmSessionManager implements DrmSessionManager { } @Override - public DrmSessionReference preacquireSession( - Looper playbackLooper, - @Nullable DrmSessionEventListener.EventDispatcher eventDispatcher, - Format format) { - checkState(prepareCallsCount > 0); + public void setPlayer(Looper playbackLooper, PlayerId playerId) { initPlaybackLooper(playbackLooper); + } + + @Override + public DrmSessionReference preacquireSession( + @Nullable DrmSessionEventListener.EventDispatcher eventDispatcher, Format format) { + checkState(prepareCallsCount > 0); + checkStateNotNull(playbackLooper); PreacquiredSessionReference preacquiredSessionReference = new PreacquiredSessionReference(eventDispatcher); preacquiredSessionReference.acquire(format); @@ -506,11 +511,9 @@ public class DefaultDrmSessionManager implements DrmSessionManager { @Override @Nullable public DrmSession acquireSession( - Looper playbackLooper, - @Nullable DrmSessionEventListener.EventDispatcher eventDispatcher, - Format format) { + @Nullable DrmSessionEventListener.EventDispatcher eventDispatcher, Format format) { checkState(prepareCallsCount > 0); - initPlaybackLooper(playbackLooper); + checkStateNotNull(playbackLooper); return acquireSession( playbackLooper, eventDispatcher, @@ -980,7 +983,7 @@ public class DefaultDrmSessionManager implements DrmSessionManager { * Constructs an instance. * * @param eventDispatcher The {@link DrmSessionEventListener.EventDispatcher} passed to {@link - * #acquireSession(Looper, DrmSessionEventListener.EventDispatcher, Format)}. + * #acquireSession(DrmSessionEventListener.EventDispatcher, Format)}. */ public PreacquiredSessionReference( @Nullable DrmSessionEventListener.EventDispatcher eventDispatcher) { diff --git a/libraries/exoplayer/src/main/java/androidx/media3/exoplayer/drm/DrmSessionManager.java b/libraries/exoplayer/src/main/java/androidx/media3/exoplayer/drm/DrmSessionManager.java index 95a9106170..a1b1bae06e 100644 --- a/libraries/exoplayer/src/main/java/androidx/media3/exoplayer/drm/DrmSessionManager.java +++ b/libraries/exoplayer/src/main/java/androidx/media3/exoplayer/drm/DrmSessionManager.java @@ -21,6 +21,7 @@ import androidx.media3.common.C; import androidx.media3.common.Format; import androidx.media3.common.PlaybackException; import androidx.media3.common.util.UnstableApi; +import androidx.media3.exoplayer.analytics.PlayerId; /** Manages a DRM session. */ @UnstableApi @@ -47,12 +48,13 @@ public interface DrmSessionManager { DrmSessionManager DRM_UNSUPPORTED = new DrmSessionManager() { + @Override + public void setPlayer(Looper playbackLooper, PlayerId playerId) {} + @Override @Nullable public DrmSession acquireSession( - Looper playbackLooper, - @Nullable DrmSessionEventListener.EventDispatcher eventDispatcher, - Format format) { + @Nullable DrmSessionEventListener.EventDispatcher eventDispatcher, Format format) { if (format.drmInitData == null) { return null; } else { @@ -102,25 +104,33 @@ public interface DrmSessionManager { // Do nothing. } + /** + * Sets information about the player using this DRM session manager. + * + * @param playbackLooper The {@link Looper} associated with the player's playback thread. + * @param playerId The {@link PlayerId} of the player. + */ + void setPlayer(Looper playbackLooper, PlayerId playerId); + /** * Pre-acquires a DRM session for the specified {@link Format}. * - *

This notifies the manager that a subsequent call to {@link #acquireSession(Looper, + *

This notifies the manager that a subsequent call to {@link #acquireSession( * DrmSessionEventListener.EventDispatcher, Format)} with the same {@link Format} is likely, * allowing a manager that supports pre-acquisition to get the required {@link DrmSession} ready * in the background. * *

The caller must call {@link DrmSessionReference#release()} on the returned instance when * they no longer require the pre-acquisition (i.e. they know they won't be making a matching call - * to {@link #acquireSession(Looper, DrmSessionEventListener.EventDispatcher, Format)} in the near + * to {@link #acquireSession(DrmSessionEventListener.EventDispatcher, Format)} in the near * future). * *

This manager may silently release the underlying session in order to allow another operation - * to complete. This will result in a subsequent call to {@link #acquireSession(Looper, + * to complete. This will result in a subsequent call to {@link #acquireSession( * DrmSessionEventListener.EventDispatcher, Format)} re-initializing a new session, including * repeating key loads and other async initialization steps. * - *

The caller must separately call {@link #acquireSession(Looper, + *

The caller must separately call {@link #acquireSession( * DrmSessionEventListener.EventDispatcher, Format)} in order to obtain a session suitable for * playback. The pre-acquired {@link DrmSessionReference} and full {@link DrmSession} instances * are distinct. The caller must release both, and can release the {@link DrmSessionReference} @@ -131,19 +141,15 @@ public interface DrmSessionManager { *

Implementations that do not support pre-acquisition always return an empty {@link * DrmSessionReference} instance. * - * @param playbackLooper The looper associated with the media playback thread. * @param eventDispatcher The {@link DrmSessionEventListener.EventDispatcher} used to distribute * events, and passed on to {@link * DrmSession#acquire(DrmSessionEventListener.EventDispatcher)}. * @param format The {@link Format} for which to pre-acquire a {@link DrmSession}. * @return A releaser for the pre-acquired session. Guaranteed to be non-null even if the matching - * {@link #acquireSession(Looper, DrmSessionEventListener.EventDispatcher, Format)} would - * return null. + * {@link #acquireSession(DrmSessionEventListener.EventDispatcher, Format)} would return null. */ default DrmSessionReference preacquireSession( - Looper playbackLooper, - @Nullable DrmSessionEventListener.EventDispatcher eventDispatcher, - Format format) { + @Nullable DrmSessionEventListener.EventDispatcher eventDispatcher, Format format) { return DrmSessionReference.EMPTY; } @@ -160,7 +166,6 @@ public interface DrmSessionManager { * used to configure secure decoders for playback of clear content periods, which can reduce the * cost of transitioning between clear and encrypted content. * - * @param playbackLooper The looper associated with the media playback thread. * @param eventDispatcher The {@link DrmSessionEventListener.EventDispatcher} used to distribute * events, and passed on to {@link * DrmSession#acquire(DrmSessionEventListener.EventDispatcher)}. @@ -169,9 +174,7 @@ public interface DrmSessionManager { */ @Nullable DrmSession acquireSession( - Looper playbackLooper, - @Nullable DrmSessionEventListener.EventDispatcher eventDispatcher, - Format format); + @Nullable DrmSessionEventListener.EventDispatcher eventDispatcher, Format format); /** * Returns the {@link C.CryptoType} that the DRM session manager will use for a given {@link diff --git a/libraries/exoplayer/src/main/java/androidx/media3/exoplayer/drm/OfflineLicenseHelper.java b/libraries/exoplayer/src/main/java/androidx/media3/exoplayer/drm/OfflineLicenseHelper.java index 6f248b52db..cae26bbf4e 100644 --- a/libraries/exoplayer/src/main/java/androidx/media3/exoplayer/drm/OfflineLicenseHelper.java +++ b/libraries/exoplayer/src/main/java/androidx/media3/exoplayer/drm/OfflineLicenseHelper.java @@ -27,6 +27,7 @@ import androidx.media3.common.Format; import androidx.media3.common.util.Assertions; import androidx.media3.common.util.UnstableApi; import androidx.media3.datasource.HttpDataSource; +import androidx.media3.exoplayer.analytics.PlayerId; import androidx.media3.exoplayer.drm.DefaultDrmSessionManager.Mode; import androidx.media3.exoplayer.drm.DrmSession.DrmSessionException; import androidx.media3.exoplayer.source.MediaSource.MediaPeriodId; @@ -238,6 +239,7 @@ public final class OfflineLicenseHelper { public synchronized Pair getLicenseDurationRemainingSec(byte[] offlineLicenseKeySetId) throws DrmSessionException { Assertions.checkNotNull(offlineLicenseKeySetId); + drmSessionManager.setPlayer(handlerThread.getLooper(), PlayerId.UNSET); drmSessionManager.prepare(); DrmSession drmSession = openBlockingKeyRequest( @@ -266,6 +268,7 @@ public final class OfflineLicenseHelper { private byte[] blockingKeyRequest( @Mode int licenseMode, @Nullable byte[] offlineLicenseKeySetId, Format format) throws DrmSessionException { + drmSessionManager.setPlayer(handlerThread.getLooper(), PlayerId.UNSET); drmSessionManager.prepare(); DrmSession drmSession = openBlockingKeyRequest(licenseMode, offlineLicenseKeySetId, format); DrmSessionException error = drmSession.getError(); @@ -283,8 +286,7 @@ public final class OfflineLicenseHelper { Assertions.checkNotNull(format.drmInitData); drmSessionManager.setMode(licenseMode, offlineLicenseKeySetId); conditionVariable.close(); - DrmSession drmSession = - drmSessionManager.acquireSession(handlerThread.getLooper(), eventDispatcher, format); + DrmSession drmSession = drmSessionManager.acquireSession(eventDispatcher, format); // Block current thread until key loading is finished conditionVariable.block(); return Assertions.checkNotNull(drmSession); diff --git a/libraries/exoplayer/src/main/java/androidx/media3/exoplayer/source/ProgressiveMediaPeriod.java b/libraries/exoplayer/src/main/java/androidx/media3/exoplayer/source/ProgressiveMediaPeriod.java index 95ab231af4..d98fcec67d 100644 --- a/libraries/exoplayer/src/main/java/androidx/media3/exoplayer/source/ProgressiveMediaPeriod.java +++ b/libraries/exoplayer/src/main/java/androidx/media3/exoplayer/source/ProgressiveMediaPeriod.java @@ -719,11 +719,7 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull; } } SampleQueue trackOutput = - SampleQueue.createWithDrm( - allocator, - /* playbackLooper= */ handler.getLooper(), - drmSessionManager, - drmEventDispatcher); + SampleQueue.createWithDrm(allocator, drmSessionManager, drmEventDispatcher); trackOutput.setUpstreamFormatChangeListener(this); @NullableType TrackId[] sampleQueueTrackIds = Arrays.copyOf(this.sampleQueueTrackIds, trackCount + 1); diff --git a/libraries/exoplayer/src/main/java/androidx/media3/exoplayer/source/ProgressiveMediaSource.java b/libraries/exoplayer/src/main/java/androidx/media3/exoplayer/source/ProgressiveMediaSource.java index 7965a19e16..2ceb4be8c8 100644 --- a/libraries/exoplayer/src/main/java/androidx/media3/exoplayer/source/ProgressiveMediaSource.java +++ b/libraries/exoplayer/src/main/java/androidx/media3/exoplayer/source/ProgressiveMediaSource.java @@ -18,6 +18,7 @@ package androidx.media3.exoplayer.source; import static androidx.media3.common.util.Assertions.checkNotNull; import android.net.Uri; +import android.os.Looper; import androidx.annotation.Nullable; import androidx.media3.common.C; import androidx.media3.common.MediaItem; @@ -298,6 +299,8 @@ public final class ProgressiveMediaSource extends BaseMediaSource protected void prepareSourceInternal(@Nullable TransferListener mediaTransferListener) { transferListener = mediaTransferListener; drmSessionManager.prepare(); + drmSessionManager.setPlayer( + /* playbackLooper= */ checkNotNull(Looper.myLooper()), getPlayerId()); notifySourceInfoRefreshed(); } diff --git a/libraries/exoplayer/src/main/java/androidx/media3/exoplayer/source/SampleQueue.java b/libraries/exoplayer/src/main/java/androidx/media3/exoplayer/source/SampleQueue.java index 5f04a63755..aad102c1e2 100644 --- a/libraries/exoplayer/src/main/java/androidx/media3/exoplayer/source/SampleQueue.java +++ b/libraries/exoplayer/src/main/java/androidx/media3/exoplayer/source/SampleQueue.java @@ -40,8 +40,10 @@ import androidx.media3.common.util.Util; import androidx.media3.decoder.DecoderInputBuffer; import androidx.media3.decoder.DecoderInputBuffer.InsufficientCapacityException; import androidx.media3.exoplayer.FormatHolder; +import androidx.media3.exoplayer.analytics.PlayerId; import androidx.media3.exoplayer.drm.DrmSession; import androidx.media3.exoplayer.drm.DrmSessionEventListener; +import androidx.media3.exoplayer.drm.DrmSessionEventListener.EventDispatcher; import androidx.media3.exoplayer.drm.DrmSessionManager; import androidx.media3.exoplayer.drm.DrmSessionManager.DrmSessionReference; import androidx.media3.exoplayer.source.SampleStream.ReadFlags; @@ -73,7 +75,6 @@ public class SampleQueue implements TrackOutput { private final SpannedData sharedSampleMetadata; @Nullable private final DrmSessionManager drmSessionManager; @Nullable private final DrmSessionEventListener.EventDispatcher drmEventDispatcher; - @Nullable private final Looper playbackLooper; @Nullable private UpstreamFormatChangedListener upstreamFormatChangeListener; @Nullable private Format downstreamFormat; @@ -115,10 +116,7 @@ public class SampleQueue implements TrackOutput { */ public static SampleQueue createWithoutDrm(Allocator allocator) { return new SampleQueue( - allocator, - /* playbackLooper= */ null, - /* drmSessionManager= */ null, - /* drmEventDispatcher= */ null); + allocator, /* drmSessionManager= */ null, /* drmEventDispatcher= */ null); } /** @@ -128,7 +126,6 @@ public class SampleQueue implements TrackOutput { * keys needed to decrypt it. * * @param allocator An {@link Allocator} from which allocations for sample data can be obtained. - * @param playbackLooper The looper associated with the media playback thread. * @param drmSessionManager The {@link DrmSessionManager} to obtain {@link DrmSession DrmSessions} * from. The created instance does not take ownership of this {@link DrmSessionManager}. * @param drmEventDispatcher A {@link DrmSessionEventListener.EventDispatcher} to notify of events @@ -136,22 +133,36 @@ public class SampleQueue implements TrackOutput { */ public static SampleQueue createWithDrm( Allocator allocator, - Looper playbackLooper, DrmSessionManager drmSessionManager, DrmSessionEventListener.EventDispatcher drmEventDispatcher) { return new SampleQueue( allocator, - Assertions.checkNotNull(playbackLooper), + Assertions.checkNotNull(drmSessionManager), + Assertions.checkNotNull(drmEventDispatcher)); + } + + /** + * @deprecated Use {@link #createWithDrm(Allocator, DrmSessionManager, EventDispatcher)} instead. + * The {@code playbackLooper} should be configured on the {@link DrmSessionManager} with + * {@link DrmSessionManager#setPlayer(Looper, PlayerId)}. + */ + @Deprecated + public static SampleQueue createWithDrm( + Allocator allocator, + Looper playbackLooper, + DrmSessionManager drmSessionManager, + DrmSessionEventListener.EventDispatcher drmEventDispatcher) { + drmSessionManager.setPlayer(playbackLooper, PlayerId.UNSET); + return new SampleQueue( + allocator, Assertions.checkNotNull(drmSessionManager), Assertions.checkNotNull(drmEventDispatcher)); } protected SampleQueue( Allocator allocator, - @Nullable Looper playbackLooper, @Nullable DrmSessionManager drmSessionManager, @Nullable DrmSessionEventListener.EventDispatcher drmEventDispatcher) { - this.playbackLooper = playbackLooper; this.drmSessionManager = drmSessionManager; this.drmEventDispatcher = drmEventDispatcher; sampleDataQueue = new SampleDataQueue(allocator); @@ -805,8 +816,7 @@ public class SampleQueue implements TrackOutput { || !sharedSampleMetadata.getEndValue().format.equals(upstreamFormat)) { DrmSessionReference drmSessionReference = drmSessionManager != null - ? drmSessionManager.preacquireSession( - checkNotNull(playbackLooper), drmEventDispatcher, upstreamFormat) + ? drmSessionManager.preacquireSession(drmEventDispatcher, upstreamFormat) : DrmSessionReference.EMPTY; sharedSampleMetadata.appendSpan( @@ -915,9 +925,7 @@ public class SampleQueue implements TrackOutput { // Ensure we acquire the new session before releasing the previous one in case the same session // is being used for both DrmInitData. @Nullable DrmSession previousSession = currentDrmSession; - currentDrmSession = - drmSessionManager.acquireSession( - Assertions.checkNotNull(playbackLooper), drmEventDispatcher, newFormat); + currentDrmSession = drmSessionManager.acquireSession(drmEventDispatcher, newFormat); outputFormatHolder.drmSession = currentDrmSession; if (previousSession != null) { diff --git a/libraries/exoplayer/src/main/java/androidx/media3/exoplayer/source/chunk/ChunkSampleStream.java b/libraries/exoplayer/src/main/java/androidx/media3/exoplayer/source/chunk/ChunkSampleStream.java index 4593b70f23..84a62381af 100644 --- a/libraries/exoplayer/src/main/java/androidx/media3/exoplayer/source/chunk/ChunkSampleStream.java +++ b/libraries/exoplayer/src/main/java/androidx/media3/exoplayer/source/chunk/ChunkSampleStream.java @@ -19,7 +19,6 @@ import static androidx.media3.common.util.Assertions.checkNotNull; import static java.lang.Math.max; import static java.lang.Math.min; -import android.os.Looper; import androidx.annotation.Nullable; import androidx.media3.common.C; import androidx.media3.common.Format; @@ -146,11 +145,7 @@ public class ChunkSampleStream SampleQueue[] sampleQueues = new SampleQueue[1 + embeddedTrackCount]; primarySampleQueue = - SampleQueue.createWithDrm( - allocator, - /* playbackLooper= */ checkNotNull(Looper.myLooper()), - drmSessionManager, - drmEventDispatcher); + SampleQueue.createWithDrm(allocator, drmSessionManager, drmEventDispatcher); trackTypes[0] = primaryTrackType; sampleQueues[0] = primarySampleQueue; diff --git a/libraries/exoplayer/src/test/java/androidx/media3/exoplayer/drm/DefaultDrmSessionManagerTest.java b/libraries/exoplayer/src/test/java/androidx/media3/exoplayer/drm/DefaultDrmSessionManagerTest.java index 41eac806b6..3bd3545968 100644 --- a/libraries/exoplayer/src/test/java/androidx/media3/exoplayer/drm/DefaultDrmSessionManagerTest.java +++ b/libraries/exoplayer/src/test/java/androidx/media3/exoplayer/drm/DefaultDrmSessionManagerTest.java @@ -27,6 +27,7 @@ import androidx.media3.common.DrmInitData; import androidx.media3.common.Format; import androidx.media3.common.MimeTypes; import androidx.media3.common.util.Util; +import androidx.media3.exoplayer.analytics.PlayerId; import androidx.media3.exoplayer.drm.DrmSessionManager.DrmSessionReference; import androidx.media3.exoplayer.drm.ExoMediaDrm.AppManagedProvider; import androidx.media3.exoplayer.source.MediaSource; @@ -68,12 +69,11 @@ public class DefaultDrmSessionManagerTest { .setUuidAndExoMediaDrmProvider(DRM_SCHEME_UUID, uuid -> new FakeExoMediaDrm()) .build(/* mediaDrmCallback= */ licenseServer); drmSessionManager.prepare(); + drmSessionManager.setPlayer(/* playbackLooper= */ Looper.myLooper(), PlayerId.UNSET); DrmSession drmSession = checkNotNull( drmSessionManager.acquireSession( - /* playbackLooper= */ checkNotNull(Looper.myLooper()), - /* eventDispatcher= */ null, - FORMAT_WITH_DRM_INIT_DATA)); + /* eventDispatcher= */ null, FORMAT_WITH_DRM_INIT_DATA)); waitForOpenedWithKeys(drmSession); assertThat(drmSession.getState()).isEqualTo(DrmSession.STATE_OPENED_WITH_KEYS); @@ -92,12 +92,11 @@ public class DefaultDrmSessionManagerTest { .build(/* mediaDrmCallback= */ licenseServer); drmSessionManager.prepare(); + drmSessionManager.setPlayer(/* playbackLooper= */ Looper.myLooper(), PlayerId.UNSET); DrmSession drmSession = checkNotNull( drmSessionManager.acquireSession( - /* playbackLooper= */ checkNotNull(Looper.myLooper()), - /* eventDispatcher= */ null, - FORMAT_WITH_DRM_INIT_DATA)); + /* eventDispatcher= */ null, FORMAT_WITH_DRM_INIT_DATA)); waitForOpenedWithKeys(drmSession); assertThat(drmSession.getState()).isEqualTo(DrmSession.STATE_OPENED_WITH_KEYS); @@ -118,12 +117,11 @@ public class DefaultDrmSessionManagerTest { .build(/* mediaDrmCallback= */ licenseServer); drmSessionManager.prepare(); + drmSessionManager.setPlayer(/* playbackLooper= */ Looper.myLooper(), PlayerId.UNSET); DrmSession drmSession = checkNotNull( drmSessionManager.acquireSession( - /* playbackLooper= */ checkNotNull(Looper.myLooper()), - /* eventDispatcher= */ null, - FORMAT_WITH_DRM_INIT_DATA)); + /* eventDispatcher= */ null, FORMAT_WITH_DRM_INIT_DATA)); waitForOpenedWithKeys(drmSession); drmSession.release(/* eventDispatcher= */ null); @@ -141,12 +139,11 @@ public class DefaultDrmSessionManagerTest { .build(/* mediaDrmCallback= */ licenseServer); drmSessionManager.prepare(); + drmSessionManager.setPlayer(/* playbackLooper= */ Looper.myLooper(), PlayerId.UNSET); DrmSession drmSession = checkNotNull( drmSessionManager.acquireSession( - /* playbackLooper= */ checkNotNull(Looper.myLooper()), - /* eventDispatcher= */ null, - FORMAT_WITH_DRM_INIT_DATA)); + /* eventDispatcher= */ null, FORMAT_WITH_DRM_INIT_DATA)); waitForOpenedWithKeys(drmSession); drmSession.release(/* eventDispatcher= */ null); @@ -166,12 +163,11 @@ public class DefaultDrmSessionManagerTest { .build(/* mediaDrmCallback= */ licenseServer); drmSessionManager.prepare(); + drmSessionManager.setPlayer(/* playbackLooper= */ Looper.myLooper(), PlayerId.UNSET); DrmSession drmSession = checkNotNull( drmSessionManager.acquireSession( - /* playbackLooper= */ checkNotNull(Looper.myLooper()), - /* eventDispatcher= */ null, - FORMAT_WITH_DRM_INIT_DATA)); + /* eventDispatcher= */ null, FORMAT_WITH_DRM_INIT_DATA)); waitForOpenedWithKeys(drmSession); assertThat(drmSession.getState()).isEqualTo(DrmSession.STATE_OPENED_WITH_KEYS); @@ -193,12 +189,11 @@ public class DefaultDrmSessionManagerTest { .build(/* mediaDrmCallback= */ licenseServer); drmSessionManager.prepare(); + drmSessionManager.setPlayer(/* playbackLooper= */ Looper.myLooper(), PlayerId.UNSET); DrmSession drmSession = checkNotNull( drmSessionManager.acquireSession( - /* playbackLooper= */ checkNotNull(Looper.myLooper()), - /* eventDispatcher= */ null, - FORMAT_WITH_DRM_INIT_DATA)); + /* eventDispatcher= */ null, FORMAT_WITH_DRM_INIT_DATA)); drmSessionManager.release(); // The manager is now in a 'releasing' state because the session is still active - so the @@ -239,12 +234,11 @@ public class DefaultDrmSessionManagerTest { .build(/* mediaDrmCallback= */ licenseServer); drmSessionManager.prepare(); + drmSessionManager.setPlayer(/* playbackLooper= */ Looper.myLooper(), PlayerId.UNSET); DrmSession drmSession = checkNotNull( drmSessionManager.acquireSession( - /* playbackLooper= */ checkNotNull(Looper.myLooper()), - /* eventDispatcher= */ null, - FORMAT_WITH_DRM_INIT_DATA)); + /* eventDispatcher= */ null, FORMAT_WITH_DRM_INIT_DATA)); waitForOpenedWithKeys(drmSession); // Release the manager (there's still an explicit reference to the session from acquireSession). @@ -279,12 +273,11 @@ public class DefaultDrmSessionManagerTest { .build(/* mediaDrmCallback= */ licenseServer); drmSessionManager.prepare(); + drmSessionManager.setPlayer(/* playbackLooper= */ Looper.myLooper(), PlayerId.UNSET); DrmSession firstDrmSession = checkNotNull( drmSessionManager.acquireSession( - /* playbackLooper= */ checkNotNull(Looper.myLooper()), - /* eventDispatcher= */ null, - FORMAT_WITH_DRM_INIT_DATA)); + /* eventDispatcher= */ null, FORMAT_WITH_DRM_INIT_DATA)); waitForOpenedWithKeys(firstDrmSession); firstDrmSession.release(/* eventDispatcher= */ null); @@ -294,9 +287,7 @@ public class DefaultDrmSessionManagerTest { DrmSession secondDrmSession = checkNotNull( drmSessionManager.acquireSession( - /* playbackLooper= */ checkNotNull(Looper.myLooper()), - /* eventDispatcher= */ null, - secondFormatWithDrmInitData)); + /* eventDispatcher= */ null, secondFormatWithDrmInitData)); // The drmSessionManager had to release firstDrmSession in order to acquire secondDrmSession. assertThat(firstDrmSession.getState()).isEqualTo(DrmSession.STATE_RELEASED); @@ -323,18 +314,15 @@ public class DefaultDrmSessionManagerTest { .build(/* mediaDrmCallback= */ licenseServer); drmSessionManager.prepare(); + drmSessionManager.setPlayer(/* playbackLooper= */ Looper.myLooper(), PlayerId.UNSET); DrmSessionReference firstDrmSessionReference = checkNotNull( drmSessionManager.preacquireSession( - /* playbackLooper= */ checkNotNull(Looper.myLooper()), - /* eventDispatcher= */ null, - FORMAT_WITH_DRM_INIT_DATA)); + /* eventDispatcher= */ null, FORMAT_WITH_DRM_INIT_DATA)); DrmSession firstDrmSession = checkNotNull( drmSessionManager.acquireSession( - /* playbackLooper= */ checkNotNull(Looper.myLooper()), - /* eventDispatcher= */ null, - FORMAT_WITH_DRM_INIT_DATA)); + /* eventDispatcher= */ null, FORMAT_WITH_DRM_INIT_DATA)); waitForOpenedWithKeys(firstDrmSession); firstDrmSession.release(/* eventDispatcher= */ null); @@ -344,9 +332,7 @@ public class DefaultDrmSessionManagerTest { DrmSession secondDrmSession = checkNotNull( drmSessionManager.acquireSession( - /* playbackLooper= */ checkNotNull(Looper.myLooper()), - /* eventDispatcher= */ null, - secondFormatWithDrmInitData)); + /* eventDispatcher= */ null, secondFormatWithDrmInitData)); // The drmSessionManager had to release both it's internal keep-alive reference and the // reference represented by firstDrmSessionReference in order to acquire secondDrmSession. assertThat(firstDrmSession.getState()).isEqualTo(DrmSession.STATE_RELEASED); @@ -373,12 +359,11 @@ public class DefaultDrmSessionManagerTest { .build(/* mediaDrmCallback= */ licenseServer); drmSessionManager.prepare(); + drmSessionManager.setPlayer(/* playbackLooper= */ Looper.myLooper(), PlayerId.UNSET); DrmSession firstDrmSession = checkNotNull( drmSessionManager.acquireSession( - /* playbackLooper= */ checkNotNull(Looper.myLooper()), - /* eventDispatcher= */ null, - FORMAT_WITH_DRM_INIT_DATA)); + /* eventDispatcher= */ null, FORMAT_WITH_DRM_INIT_DATA)); waitForOpenedWithKeys(firstDrmSession); firstDrmSession.release(/* eventDispatcher= */ null); @@ -389,9 +374,7 @@ public class DefaultDrmSessionManagerTest { DrmSession secondDrmSession = checkNotNull( drmSessionManager.acquireSession( - /* playbackLooper= */ checkNotNull(Looper.myLooper()), - /* eventDispatcher= */ null, - FORMAT_WITH_DRM_INIT_DATA)); + /* eventDispatcher= */ null, FORMAT_WITH_DRM_INIT_DATA)); assertThat(secondDrmSession).isSameInstanceAs(firstDrmSession); // Let the timeout definitely expire, and check the session didn't get released. @@ -423,12 +406,10 @@ public class DefaultDrmSessionManagerTest { .build(/* mediaDrmCallback= */ licenseServer); drmSessionManager.prepare(); + drmSessionManager.setPlayer(/* playbackLooper= */ Looper.myLooper(), PlayerId.UNSET); DrmSessionReference sessionReference = - drmSessionManager.preacquireSession( - /* playbackLooper= */ checkNotNull(Looper.myLooper()), - eventDispatcher, - FORMAT_WITH_DRM_INIT_DATA); + drmSessionManager.preacquireSession(eventDispatcher, FORMAT_WITH_DRM_INIT_DATA); // Wait for the key load event to propagate, indicating the pre-acquired session is in // STATE_OPENED_WITH_KEYS. @@ -440,9 +421,7 @@ public class DefaultDrmSessionManagerTest { DrmSession drmSession = checkNotNull( drmSessionManager.acquireSession( - /* playbackLooper= */ checkNotNull(Looper.myLooper()), - /* eventDispatcher= */ null, - FORMAT_WITH_DRM_INIT_DATA)); + /* eventDispatcher= */ null, FORMAT_WITH_DRM_INIT_DATA)); // Without idling the main/playback looper, we assert the session is already in OPENED_WITH_KEYS assertThat(drmSession.getState()).isEqualTo(DrmSession.STATE_OPENED_WITH_KEYS); @@ -472,12 +451,10 @@ public class DefaultDrmSessionManagerTest { .build(/* mediaDrmCallback= */ licenseServer); drmSessionManager.prepare(); + drmSessionManager.setPlayer(/* playbackLooper= */ Looper.myLooper(), PlayerId.UNSET); DrmSessionReference sessionReference = - drmSessionManager.preacquireSession( - /* playbackLooper= */ checkNotNull(Looper.myLooper()), - /* eventDispatcher= */ null, - FORMAT_WITH_DRM_INIT_DATA); + drmSessionManager.preacquireSession(/* eventDispatcher= */ null, FORMAT_WITH_DRM_INIT_DATA); // Release the pre-acquired reference before the underlying session has had a chance to be // constructed. @@ -488,9 +465,7 @@ public class DefaultDrmSessionManagerTest { DrmSession drmSession = checkNotNull( drmSessionManager.acquireSession( - /* playbackLooper= */ checkNotNull(Looper.myLooper()), - /* eventDispatcher= */ null, - FORMAT_WITH_DRM_INIT_DATA)); + /* eventDispatcher= */ null, FORMAT_WITH_DRM_INIT_DATA)); assertThat(drmSession.getState()).isEqualTo(DrmSession.STATE_OPENED); waitForOpenedWithKeys(drmSession); @@ -512,12 +487,10 @@ public class DefaultDrmSessionManagerTest { .build(/* mediaDrmCallback= */ licenseServer); drmSessionManager.prepare(); + drmSessionManager.setPlayer(/* playbackLooper= */ Looper.myLooper(), PlayerId.UNSET); DrmSessionReference sessionReference = - drmSessionManager.preacquireSession( - /* playbackLooper= */ checkNotNull(Looper.myLooper()), - /* eventDispatcher= */ null, - FORMAT_WITH_DRM_INIT_DATA); + drmSessionManager.preacquireSession(/* eventDispatcher= */ null, FORMAT_WITH_DRM_INIT_DATA); // Release the manager before the underlying session has had a chance to be constructed. This // will release all pre-acquired sessions. @@ -532,9 +505,7 @@ public class DefaultDrmSessionManagerTest { DrmSession drmSession = checkNotNull( drmSessionManager.acquireSession( - /* playbackLooper= */ checkNotNull(Looper.myLooper()), - /* eventDispatcher= */ null, - FORMAT_WITH_DRM_INIT_DATA)); + /* eventDispatcher= */ null, FORMAT_WITH_DRM_INIT_DATA)); assertThat(drmSession.getState()).isEqualTo(DrmSession.STATE_OPENED); waitForOpenedWithKeys(drmSession); @@ -560,14 +531,13 @@ public class DefaultDrmSessionManagerTest { .build(/* mediaDrmCallback= */ licenseServer); drmSessionManager.prepare(); + drmSessionManager.setPlayer(/* playbackLooper= */ Looper.myLooper(), PlayerId.UNSET); DefaultDrmSession drmSession = (DefaultDrmSession) checkNotNull( drmSessionManager.acquireSession( - /* playbackLooper= */ checkNotNull(Looper.myLooper()), - /* eventDispatcher= */ null, - FORMAT_WITH_DRM_INIT_DATA)); + /* eventDispatcher= */ null, FORMAT_WITH_DRM_INIT_DATA)); waitForOpenedWithKeys(drmSession); assertThat(licenseServer.getReceivedSchemeDatas()).hasSize(1); @@ -602,14 +572,13 @@ public class DefaultDrmSessionManagerTest { .build(/* mediaDrmCallback= */ licenseServer); drmSessionManager.prepare(); + drmSessionManager.setPlayer(/* playbackLooper= */ Looper.myLooper(), PlayerId.UNSET); DefaultDrmSession drmSession = (DefaultDrmSession) checkNotNull( drmSessionManager.acquireSession( - /* playbackLooper= */ checkNotNull(Looper.myLooper()), - /* eventDispatcher= */ null, - FORMAT_WITH_DRM_INIT_DATA)); + /* eventDispatcher= */ null, FORMAT_WITH_DRM_INIT_DATA)); waitForOpenedWithKeys(drmSession); assertThat(licenseServer.getReceivedSchemeDatas()).hasSize(1); @@ -647,12 +616,11 @@ public class DefaultDrmSessionManagerTest { uuid -> new FakeExoMediaDrm.Builder().setProvisionsRequired(1).build()) .build(/* mediaDrmCallback= */ licenseServer); drmSessionManager.prepare(); + drmSessionManager.setPlayer(/* playbackLooper= */ Looper.myLooper(), PlayerId.UNSET); DrmSession drmSession = checkNotNull( drmSessionManager.acquireSession( - /* playbackLooper= */ checkNotNull(Looper.myLooper()), - /* eventDispatcher= */ null, - FORMAT_WITH_DRM_INIT_DATA)); + /* eventDispatcher= */ null, FORMAT_WITH_DRM_INIT_DATA)); // Confirm that opening the session threw NotProvisionedException (otherwise state would be // OPENED) assertThat(drmSession.getState()).isEqualTo(DrmSession.STATE_OPENING); @@ -681,12 +649,11 @@ public class DefaultDrmSessionManagerTest { .build()) .build(/* mediaDrmCallback= */ licenseServer); drmSessionManager.prepare(); + drmSessionManager.setPlayer(/* playbackLooper= */ Looper.myLooper(), PlayerId.UNSET); DrmSession drmSession = checkNotNull( drmSessionManager.acquireSession( - /* playbackLooper= */ checkNotNull(Looper.myLooper()), - /* eventDispatcher= */ null, - FORMAT_WITH_DRM_INIT_DATA)); + /* eventDispatcher= */ null, FORMAT_WITH_DRM_INIT_DATA)); assertThat(drmSession.getState()).isEqualTo(DrmSession.STATE_OPENED); waitForOpenedWithKeys(drmSession); @@ -708,12 +675,11 @@ public class DefaultDrmSessionManagerTest { uuid -> new FakeExoMediaDrm.Builder().setProvisionsRequired(2).build()) .build(/* mediaDrmCallback= */ licenseServer); drmSessionManager.prepare(); + drmSessionManager.setPlayer(/* playbackLooper= */ Looper.myLooper(), PlayerId.UNSET); DrmSession drmSession = checkNotNull( drmSessionManager.acquireSession( - /* playbackLooper= */ checkNotNull(Looper.myLooper()), - /* eventDispatcher= */ null, - FORMAT_WITH_DRM_INIT_DATA)); + /* eventDispatcher= */ null, FORMAT_WITH_DRM_INIT_DATA)); // Confirm that opening the session threw NotProvisionedException (otherwise state would be // OPENED) assertThat(drmSession.getState()).isEqualTo(DrmSession.STATE_OPENING); @@ -737,12 +703,11 @@ public class DefaultDrmSessionManagerTest { DRM_SCHEME_UUID, uuid -> new FakeExoMediaDrm.Builder().build()) .build(/* mediaDrmCallback= */ licenseServer); drmSessionManager.prepare(); + drmSessionManager.setPlayer(/* playbackLooper= */ Looper.myLooper(), PlayerId.UNSET); DrmSession drmSession = checkNotNull( drmSessionManager.acquireSession( - /* playbackLooper= */ checkNotNull(Looper.myLooper()), - /* eventDispatcher= */ null, - FORMAT_WITH_DRM_INIT_DATA)); + /* eventDispatcher= */ null, FORMAT_WITH_DRM_INIT_DATA)); assertThat(drmSession.getState()).isEqualTo(DrmSession.STATE_OPENED); waitForOpenedWithKeys(drmSession); @@ -764,12 +729,11 @@ public class DefaultDrmSessionManagerTest { .setSessionKeepaliveMs(C.TIME_UNSET) .build(/* mediaDrmCallback= */ licenseServer); drmSessionManager.prepare(); + drmSessionManager.setPlayer(/* playbackLooper= */ Looper.myLooper(), PlayerId.UNSET); DrmSession drmSession = checkNotNull( drmSessionManager.acquireSession( - /* playbackLooper= */ checkNotNull(Looper.myLooper()), - /* eventDispatcher= */ null, - FORMAT_WITH_DRM_INIT_DATA)); + /* eventDispatcher= */ null, FORMAT_WITH_DRM_INIT_DATA)); // Confirm that opening the session threw NotProvisionedException (otherwise state would be // OPENED) assertThat(drmSession.getState()).isEqualTo(DrmSession.STATE_OPENING); @@ -781,9 +745,7 @@ public class DefaultDrmSessionManagerTest { drmSession = checkNotNull( drmSessionManager.acquireSession( - /* playbackLooper= */ checkNotNull(Looper.myLooper()), - /* eventDispatcher= */ null, - FORMAT_WITH_DRM_INIT_DATA)); + /* eventDispatcher= */ null, FORMAT_WITH_DRM_INIT_DATA)); // Confirm that opening the session threw NotProvisionedException (otherwise state would be // OPENED) assertThat(drmSession.getState()).isEqualTo(DrmSession.STATE_OPENING); @@ -804,16 +766,12 @@ public class DefaultDrmSessionManagerTest { Exception.class, () -> drmSessionManager.acquireSession( - /* playbackLooper= */ checkNotNull(Looper.myLooper()), - /* eventDispatcher= */ null, - FORMAT_WITH_DRM_INIT_DATA)); + /* eventDispatcher= */ null, FORMAT_WITH_DRM_INIT_DATA)); assertThrows( Exception.class, () -> drmSessionManager.preacquireSession( - /* playbackLooper= */ checkNotNull(Looper.myLooper()), - /* eventDispatcher= */ null, - FORMAT_WITH_DRM_INIT_DATA)); + /* eventDispatcher= */ null, FORMAT_WITH_DRM_INIT_DATA)); } @Test @@ -826,12 +784,11 @@ public class DefaultDrmSessionManagerTest { .build(/* mediaDrmCallback= */ licenseServer); drmSessionManager.prepare(); + drmSessionManager.setPlayer(/* playbackLooper= */ Looper.myLooper(), PlayerId.UNSET); DrmSession drmSession = checkNotNull( drmSessionManager.acquireSession( - /* playbackLooper= */ checkNotNull(Looper.myLooper()), - /* eventDispatcher= */ null, - FORMAT_WITH_DRM_INIT_DATA)); + /* eventDispatcher= */ null, FORMAT_WITH_DRM_INIT_DATA)); drmSessionManager.release(); // The manager's prepareCount is now zero, but the drmSession is keeping it in a 'releasing' @@ -840,16 +797,12 @@ public class DefaultDrmSessionManagerTest { Exception.class, () -> drmSessionManager.acquireSession( - /* playbackLooper= */ checkNotNull(Looper.myLooper()), - /* eventDispatcher= */ null, - FORMAT_WITH_DRM_INIT_DATA)); + /* eventDispatcher= */ null, FORMAT_WITH_DRM_INIT_DATA)); assertThrows( Exception.class, () -> drmSessionManager.preacquireSession( - /* playbackLooper= */ checkNotNull(Looper.myLooper()), - /* eventDispatcher= */ null, - FORMAT_WITH_DRM_INIT_DATA)); + /* eventDispatcher= */ null, FORMAT_WITH_DRM_INIT_DATA)); drmSession.release(/* eventDispatcher= */ null); } diff --git a/libraries/exoplayer/src/test/java/androidx/media3/exoplayer/source/SampleQueueTest.java b/libraries/exoplayer/src/test/java/androidx/media3/exoplayer/source/SampleQueueTest.java index d301f4494d..b0ed736d5a 100644 --- a/libraries/exoplayer/src/test/java/androidx/media3/exoplayer/source/SampleQueueTest.java +++ b/libraries/exoplayer/src/test/java/androidx/media3/exoplayer/source/SampleQueueTest.java @@ -36,10 +36,10 @@ import androidx.media3.common.DrmInitData; import androidx.media3.common.Format; import androidx.media3.common.MimeTypes; import androidx.media3.common.PlaybackException; -import androidx.media3.common.util.Assertions; import androidx.media3.common.util.ParsableByteArray; import androidx.media3.decoder.DecoderInputBuffer; import androidx.media3.exoplayer.FormatHolder; +import androidx.media3.exoplayer.analytics.PlayerId; import androidx.media3.exoplayer.drm.DrmSession; import androidx.media3.exoplayer.drm.DrmSessionEventListener; import androidx.media3.exoplayer.drm.DrmSessionManager; @@ -146,12 +146,7 @@ public final class SampleQueueTest { mockDrmSession = Mockito.mock(DrmSession.class); mockDrmSessionManager = new MockDrmSessionManager(mockDrmSession); eventDispatcher = new DrmSessionEventListener.EventDispatcher(); - sampleQueue = - new SampleQueue( - allocator, - /* playbackLooper= */ Assertions.checkNotNull(Looper.myLooper()), - mockDrmSessionManager, - eventDispatcher); + sampleQueue = new SampleQueue(allocator, mockDrmSessionManager, eventDispatcher); formatHolder = new FormatHolder(); inputBuffer = new DecoderInputBuffer(DecoderInputBuffer.BUFFER_REPLACEMENT_MODE_NORMAL); } @@ -424,12 +419,7 @@ public final class SampleQueueTest { public void isReadyReturnsTrueForClearSampleAndPlayClearSamplesWithoutKeysIsTrue() { when(mockDrmSession.playClearSamplesWithoutKeys()).thenReturn(true); // We recreate the queue to ensure the mock DRM session manager flags are taken into account. - sampleQueue = - new SampleQueue( - allocator, - /* playbackLooper= */ Assertions.checkNotNull(Looper.myLooper()), - mockDrmSessionManager, - eventDispatcher); + sampleQueue = new SampleQueue(allocator, mockDrmSessionManager, eventDispatcher); writeTestDataWithEncryptedSections(); assertThat(sampleQueue.isReady(/* loadingFinished= */ false)).isTrue(); } @@ -574,12 +564,7 @@ public final class SampleQueueTest { public void allowPlayClearSamplesWithoutKeysReadsClearSamples() { when(mockDrmSession.playClearSamplesWithoutKeys()).thenReturn(true); // We recreate the queue to ensure the mock DRM session manager flags are taken into account. - sampleQueue = - new SampleQueue( - allocator, - /* playbackLooper= */ Assertions.checkNotNull(Looper.myLooper()), - mockDrmSessionManager, - eventDispatcher); + sampleQueue = new SampleQueue(allocator, mockDrmSessionManager, eventDispatcher); when(mockDrmSession.getState()).thenReturn(DrmSession.STATE_OPENED); writeTestDataWithEncryptedSections(); @@ -1246,11 +1231,7 @@ public final class SampleQueueTest { public void adjustUpstreamFormat() { String label = "label"; sampleQueue = - new SampleQueue( - allocator, - /* playbackLooper= */ Assertions.checkNotNull(Looper.myLooper()), - mockDrmSessionManager, - eventDispatcher) { + new SampleQueue(allocator, mockDrmSessionManager, eventDispatcher) { @Override public Format getAdjustedUpstreamFormat(Format format) { return super.getAdjustedUpstreamFormat(copyWithLabel(format, label)); @@ -1266,11 +1247,7 @@ public final class SampleQueueTest { public void invalidateUpstreamFormatAdjustment() { AtomicReference label = new AtomicReference<>("label1"); sampleQueue = - new SampleQueue( - allocator, - /* playbackLooper= */ Assertions.checkNotNull(Looper.myLooper()), - mockDrmSessionManager, - eventDispatcher) { + new SampleQueue(allocator, mockDrmSessionManager, eventDispatcher) { @Override public Format getAdjustedUpstreamFormat(Format format) { return super.getAdjustedUpstreamFormat(copyWithLabel(format, label.get())); @@ -1770,12 +1747,13 @@ public final class SampleQueueTest { this.mockDrmSession = mockDrmSession; } + @Override + public void setPlayer(Looper playbackLooper, PlayerId playerId) {} + @Override @Nullable public DrmSession acquireSession( - Looper playbackLooper, - @Nullable DrmSessionEventListener.EventDispatcher eventDispatcher, - Format format) { + @Nullable DrmSessionEventListener.EventDispatcher eventDispatcher, Format format) { return format.drmInitData != null ? mockDrmSession : mockPlaceholderDrmSession; } diff --git a/libraries/exoplayer_dash/src/main/java/androidx/media3/exoplayer/dash/DashMediaSource.java b/libraries/exoplayer_dash/src/main/java/androidx/media3/exoplayer/dash/DashMediaSource.java index 3cf5b51ade..aa23d56b79 100644 --- a/libraries/exoplayer_dash/src/main/java/androidx/media3/exoplayer/dash/DashMediaSource.java +++ b/libraries/exoplayer_dash/src/main/java/androidx/media3/exoplayer/dash/DashMediaSource.java @@ -22,6 +22,7 @@ import static java.lang.Math.min; import android.net.Uri; import android.os.Handler; +import android.os.Looper; import android.os.SystemClock; import android.text.TextUtils; import android.util.SparseArray; @@ -561,6 +562,7 @@ public final class DashMediaSource extends BaseMediaSource { protected void prepareSourceInternal(@Nullable TransferListener mediaTransferListener) { this.mediaTransferListener = mediaTransferListener; drmSessionManager.prepare(); + drmSessionManager.setPlayer(/* playbackLooper= */ Looper.myLooper(), getPlayerId()); if (sideloadedManifest) { processManifest(false); } else { diff --git a/libraries/exoplayer_hls/src/main/java/androidx/media3/exoplayer/hls/HlsMediaSource.java b/libraries/exoplayer_hls/src/main/java/androidx/media3/exoplayer/hls/HlsMediaSource.java index f76757a511..7549468ac7 100644 --- a/libraries/exoplayer_hls/src/main/java/androidx/media3/exoplayer/hls/HlsMediaSource.java +++ b/libraries/exoplayer_hls/src/main/java/androidx/media3/exoplayer/hls/HlsMediaSource.java @@ -19,6 +19,7 @@ import static androidx.media3.common.util.Assertions.checkNotNull; import static java.lang.annotation.RetentionPolicy.SOURCE; import android.net.Uri; +import android.os.Looper; import android.os.SystemClock; import androidx.annotation.IntDef; import androidx.annotation.Nullable; @@ -468,6 +469,8 @@ public final class HlsMediaSource extends BaseMediaSource protected void prepareSourceInternal(@Nullable TransferListener mediaTransferListener) { this.mediaTransferListener = mediaTransferListener; drmSessionManager.prepare(); + drmSessionManager.setPlayer( + /* playbackLooper= */ checkNotNull(Looper.myLooper()), getPlayerId()); MediaSourceEventListener.EventDispatcher eventDispatcher = createEventDispatcher(/* mediaPeriodId= */ null); playlistTracker.start( diff --git a/libraries/exoplayer_hls/src/main/java/androidx/media3/exoplayer/hls/HlsSampleStreamWrapper.java b/libraries/exoplayer_hls/src/main/java/androidx/media3/exoplayer/hls/HlsSampleStreamWrapper.java index 6ae634ebb8..ccc413b07a 100644 --- a/libraries/exoplayer_hls/src/main/java/androidx/media3/exoplayer/hls/HlsSampleStreamWrapper.java +++ b/libraries/exoplayer_hls/src/main/java/androidx/media3/exoplayer/hls/HlsSampleStreamWrapper.java @@ -23,7 +23,6 @@ import static java.lang.Math.min; import android.net.Uri; import android.os.Handler; -import android.os.Looper; import android.util.SparseIntArray; import androidx.annotation.Nullable; import androidx.media3.common.C; @@ -1100,12 +1099,7 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull; boolean isAudioVideo = type == C.TRACK_TYPE_AUDIO || type == C.TRACK_TYPE_VIDEO; HlsSampleQueue sampleQueue = - new HlsSampleQueue( - allocator, - /* playbackLooper= */ handler.getLooper(), - drmSessionManager, - drmEventDispatcher, - overridingDrmInitData); + new HlsSampleQueue(allocator, drmSessionManager, drmEventDispatcher, overridingDrmInitData); sampleQueue.setStartTimeUs(lastSeekPositionUs); if (isAudioVideo) { sampleQueue.setDrmInitData(drmInitData); @@ -1639,11 +1633,10 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull; private HlsSampleQueue( Allocator allocator, - Looper playbackLooper, DrmSessionManager drmSessionManager, DrmSessionEventListener.EventDispatcher eventDispatcher, Map overridingDrmInitData) { - super(allocator, playbackLooper, drmSessionManager, eventDispatcher); + super(allocator, drmSessionManager, eventDispatcher); this.overridingDrmInitData = overridingDrmInitData; } diff --git a/libraries/exoplayer_smoothstreaming/src/main/java/androidx/media3/exoplayer/smoothstreaming/SsMediaSource.java b/libraries/exoplayer_smoothstreaming/src/main/java/androidx/media3/exoplayer/smoothstreaming/SsMediaSource.java index df5588a6bb..909382622f 100644 --- a/libraries/exoplayer_smoothstreaming/src/main/java/androidx/media3/exoplayer/smoothstreaming/SsMediaSource.java +++ b/libraries/exoplayer_smoothstreaming/src/main/java/androidx/media3/exoplayer/smoothstreaming/SsMediaSource.java @@ -21,6 +21,7 @@ import static java.lang.Math.min; import android.net.Uri; import android.os.Handler; +import android.os.Looper; import android.os.SystemClock; import androidx.annotation.Nullable; import androidx.media3.common.C; @@ -438,6 +439,7 @@ public final class SsMediaSource extends BaseMediaSource protected void prepareSourceInternal(@Nullable TransferListener mediaTransferListener) { this.mediaTransferListener = mediaTransferListener; drmSessionManager.prepare(); + drmSessionManager.setPlayer(/* playbackLooper= */ Looper.myLooper(), getPlayerId()); if (sideloadedManifest) { manifestLoaderErrorThrower = new LoaderErrorThrower.Dummy(); processManifest(); diff --git a/libraries/test_utils/src/main/java/androidx/media3/test/utils/FakeMediaSource.java b/libraries/test_utils/src/main/java/androidx/media3/test/utils/FakeMediaSource.java index b52f7dc414..1779b3ef71 100644 --- a/libraries/test_utils/src/main/java/androidx/media3/test/utils/FakeMediaSource.java +++ b/libraries/test_utils/src/main/java/androidx/media3/test/utils/FakeMediaSource.java @@ -15,11 +15,13 @@ */ package androidx.media3.test.utils; +import static androidx.media3.common.util.Assertions.checkNotNull; import static androidx.media3.common.util.Assertions.checkState; import static androidx.media3.common.util.Util.castNonNull; import static com.google.common.truth.Truth.assertThat; import android.os.Handler; +import android.os.Looper; import android.os.SystemClock; import androidx.annotation.Nullable; import androidx.media3.common.C; @@ -214,6 +216,8 @@ public class FakeMediaSource extends BaseMediaSource { assertThat(preparedSource).isFalse(); transferListener = mediaTransferListener; drmSessionManager.prepare(); + drmSessionManager.setPlayer( + /* playbackLooper= */ checkNotNull(Looper.myLooper()), getPlayerId()); preparedSource = true; releasedSource = false; sourceInfoRefreshHandler = Util.createHandlerForCurrentLooper(); diff --git a/libraries/test_utils/src/main/java/androidx/media3/test/utils/FakeSampleStream.java b/libraries/test_utils/src/main/java/androidx/media3/test/utils/FakeSampleStream.java index d42ffaa12d..d072791b45 100644 --- a/libraries/test_utils/src/main/java/androidx/media3/test/utils/FakeSampleStream.java +++ b/libraries/test_utils/src/main/java/androidx/media3/test/utils/FakeSampleStream.java @@ -17,7 +17,6 @@ package androidx.media3.test.utils; import static androidx.media3.common.util.Assertions.checkNotNull; -import android.os.Looper; import androidx.annotation.Nullable; import androidx.media3.common.C; import androidx.media3.common.Format; @@ -138,12 +137,7 @@ public class FakeSampleStream implements SampleStream { DrmSessionEventListener.EventDispatcher drmEventDispatcher, Format initialFormat, List fakeSampleStreamItems) { - this.sampleQueue = - SampleQueue.createWithDrm( - allocator, - /* playbackLooper= */ checkNotNull(Looper.myLooper()), - drmSessionManager, - drmEventDispatcher); + this.sampleQueue = SampleQueue.createWithDrm(allocator, drmSessionManager, drmEventDispatcher); this.mediaSourceEventDispatcher = mediaSourceEventDispatcher; this.sampleStreamItems = new ArrayList<>(); sampleStreamItems.add(FakeSampleStreamItem.format(initialFormat));