Add a track type argument to DrmSessionManager.acquirePlaceholderSession

Issue:#4867
PiperOrigin-RevId: 279928345
This commit is contained in:
aquilescanta 2019-11-12 11:38:30 +00:00 committed by Oliver Woodman
parent b84a9bed2c
commit abe0330f39
4 changed files with 13 additions and 4 deletions

View File

@ -458,12 +458,15 @@ public class DefaultDrmSessionManager<T extends ExoMediaCrypto> implements DrmSe
@Override @Override
@Nullable @Nullable
public DrmSession<T> acquirePlaceholderSession(Looper playbackLooper) { public DrmSession<T> acquirePlaceholderSession(Looper playbackLooper, int trackType) {
assertExpectedPlaybackLooper(playbackLooper); assertExpectedPlaybackLooper(playbackLooper);
Assertions.checkNotNull(exoMediaDrm); Assertions.checkNotNull(exoMediaDrm);
boolean avoidPlaceholderDrmSessions = boolean avoidPlaceholderDrmSessions =
FrameworkMediaCrypto.class.equals(exoMediaDrm.getExoMediaCryptoType()) FrameworkMediaCrypto.class.equals(exoMediaDrm.getExoMediaCryptoType())
&& FrameworkMediaCrypto.WORKAROUND_DEVICE_NEEDS_KEYS_TO_CONFIGURE_CODEC; && FrameworkMediaCrypto.WORKAROUND_DEVICE_NEEDS_KEYS_TO_CONFIGURE_CODEC;
// Avoid attaching a session to sparse formats.
avoidPlaceholderDrmSessions |=
trackType != C.TRACK_TYPE_VIDEO && trackType != C.TRACK_TYPE_AUDIO;
if (avoidPlaceholderDrmSessions if (avoidPlaceholderDrmSessions
|| !preferSecureDecoders || !preferSecureDecoders
|| exoMediaDrm.getExoMediaCryptoType() == null) { || exoMediaDrm.getExoMediaCryptoType() == null) {

View File

@ -18,6 +18,7 @@ package com.google.android.exoplayer2.drm;
import android.os.Looper; import android.os.Looper;
import androidx.annotation.IntDef; import androidx.annotation.IntDef;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.drm.DrmInitData.SchemeData; import com.google.android.exoplayer2.drm.DrmInitData.SchemeData;
import java.lang.annotation.Documented; import java.lang.annotation.Documented;
import java.lang.annotation.Retention; import java.lang.annotation.Retention;
@ -112,11 +113,13 @@ public interface DrmSessionManager<T extends ExoMediaCrypto> {
* content periods. * content periods.
* *
* @param playbackLooper The looper associated with the media playback thread. * @param playbackLooper The looper associated with the media playback thread.
* @param trackType The type of the track to acquire a placeholder session for. Must be one of the
* {@link C}{@code .TRACK_TYPE_*} constants.
* @return The placeholder DRM session, or null if this DRM session manager does not support * @return The placeholder DRM session, or null if this DRM session manager does not support
* placeholder sessions. * placeholder sessions.
*/ */
@Nullable @Nullable
default DrmSession<T> acquirePlaceholderSession(Looper playbackLooper) { default DrmSession<T> acquirePlaceholderSession(Looper playbackLooper, int trackType) {
return null; return null;
} }

View File

@ -26,6 +26,7 @@ import com.google.android.exoplayer2.drm.DrmSession;
import com.google.android.exoplayer2.drm.DrmSessionManager; import com.google.android.exoplayer2.drm.DrmSessionManager;
import com.google.android.exoplayer2.extractor.TrackOutput.CryptoData; import com.google.android.exoplayer2.extractor.TrackOutput.CryptoData;
import com.google.android.exoplayer2.util.Assertions; import com.google.android.exoplayer2.util.Assertions;
import com.google.android.exoplayer2.util.MimeTypes;
import com.google.android.exoplayer2.util.Util; import com.google.android.exoplayer2.util.Util;
import java.io.IOException; import java.io.IOException;
@ -623,7 +624,8 @@ import java.io.IOException;
currentDrmSession = currentDrmSession =
newDrmInitData != null newDrmInitData != null
? drmSessionManager.acquireSession(playbackLooper, newDrmInitData) ? drmSessionManager.acquireSession(playbackLooper, newDrmInitData)
: drmSessionManager.acquirePlaceholderSession(playbackLooper); : drmSessionManager.acquirePlaceholderSession(
playbackLooper, MimeTypes.getTrackType(newFormat.sampleMimeType));
outputFormatHolder.drmSession = currentDrmSession; outputFormatHolder.drmSession = currentDrmSession;
if (previousSession != null) { if (previousSession != null) {

View File

@ -396,7 +396,8 @@ public final class SampleQueueTest {
DrmSession<ExoMediaCrypto> mockPlaceholderDrmSession = DrmSession<ExoMediaCrypto> mockPlaceholderDrmSession =
(DrmSession<ExoMediaCrypto>) Mockito.mock(DrmSession.class); (DrmSession<ExoMediaCrypto>) Mockito.mock(DrmSession.class);
when(mockPlaceholderDrmSession.getState()).thenReturn(DrmSession.STATE_OPENED_WITH_KEYS); when(mockPlaceholderDrmSession.getState()).thenReturn(DrmSession.STATE_OPENED_WITH_KEYS);
when(mockDrmSessionManager.acquirePlaceholderSession(ArgumentMatchers.any())) when(mockDrmSessionManager.acquirePlaceholderSession(
ArgumentMatchers.any(), ArgumentMatchers.anyInt()))
.thenReturn(mockPlaceholderDrmSession); .thenReturn(mockPlaceholderDrmSession);
writeTestDataWithEncryptedSections(); writeTestDataWithEncryptedSections();