Make renderers ignore drmInitData if the MediaSource provides a DrmSession
Will allows to use a DrmSession for clear periods. Issue:#4867 PiperOrigin-RevId: 267576982
This commit is contained in:
parent
f1ccb47c3b
commit
2866b2b3e4
@ -15,13 +15,17 @@
|
|||||||
*/
|
*/
|
||||||
package com.google.android.exoplayer2;
|
package com.google.android.exoplayer2;
|
||||||
|
|
||||||
|
import android.os.Looper;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import com.google.android.exoplayer2.decoder.DecoderInputBuffer;
|
import com.google.android.exoplayer2.decoder.DecoderInputBuffer;
|
||||||
import com.google.android.exoplayer2.drm.DrmInitData;
|
import com.google.android.exoplayer2.drm.DrmInitData;
|
||||||
|
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.drm.ExoMediaCrypto;
|
||||||
import com.google.android.exoplayer2.source.SampleStream;
|
import com.google.android.exoplayer2.source.SampleStream;
|
||||||
import com.google.android.exoplayer2.util.Assertions;
|
import com.google.android.exoplayer2.util.Assertions;
|
||||||
import com.google.android.exoplayer2.util.MediaClock;
|
import com.google.android.exoplayer2.util.MediaClock;
|
||||||
|
import com.google.android.exoplayer2.util.Util;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -283,6 +287,35 @@ public abstract class BaseRenderer implements Renderer, RendererCapabilities {
|
|||||||
return configuration;
|
return configuration;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Returns a {@link DrmSession} ready for assignment, handling resource management. */
|
||||||
|
@Nullable
|
||||||
|
protected final <T extends ExoMediaCrypto> DrmSession<T> getUpdatedSourceDrmSession(
|
||||||
|
@Nullable Format oldFormat,
|
||||||
|
Format newFormat,
|
||||||
|
@Nullable DrmSessionManager<T> drmSessionManager,
|
||||||
|
@Nullable DrmSession<T> existingSourceSession)
|
||||||
|
throws ExoPlaybackException {
|
||||||
|
boolean drmInitDataChanged =
|
||||||
|
!Util.areEqual(newFormat.drmInitData, oldFormat == null ? null : oldFormat.drmInitData);
|
||||||
|
if (!drmInitDataChanged) {
|
||||||
|
return existingSourceSession;
|
||||||
|
}
|
||||||
|
@Nullable DrmSession<T> newSourceDrmSession = null;
|
||||||
|
if (newFormat.drmInitData != null) {
|
||||||
|
if (drmSessionManager == null) {
|
||||||
|
throw ExoPlaybackException.createForRenderer(
|
||||||
|
new IllegalStateException("Media requires a DrmSessionManager"), getIndex());
|
||||||
|
}
|
||||||
|
newSourceDrmSession =
|
||||||
|
drmSessionManager.acquireSession(
|
||||||
|
Assertions.checkNotNull(Looper.myLooper()), newFormat.drmInitData);
|
||||||
|
}
|
||||||
|
if (existingSourceSession != null) {
|
||||||
|
existingSourceSession.releaseReference();
|
||||||
|
}
|
||||||
|
return newSourceDrmSession;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the index of the renderer within the player.
|
* Returns the index of the renderer within the player.
|
||||||
*/
|
*/
|
||||||
|
@ -17,7 +17,6 @@ package com.google.android.exoplayer2.audio;
|
|||||||
|
|
||||||
import android.media.audiofx.Virtualizer;
|
import android.media.audiofx.Virtualizer;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.os.Looper;
|
|
||||||
import android.os.SystemClock;
|
import android.os.SystemClock;
|
||||||
import androidx.annotation.IntDef;
|
import androidx.annotation.IntDef;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
@ -673,32 +672,15 @@ public abstract class SimpleDecoderAudioRenderer extends BaseRenderer implements
|
|||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
private void onInputFormatChanged(FormatHolder formatHolder) throws ExoPlaybackException {
|
private void onInputFormatChanged(FormatHolder formatHolder) throws ExoPlaybackException {
|
||||||
Format oldFormat = inputFormat;
|
Format newFormat = Assertions.checkNotNull(formatHolder.format);
|
||||||
inputFormat = formatHolder.format;
|
|
||||||
|
|
||||||
boolean drmInitDataChanged = !Util.areEqual(inputFormat.drmInitData, oldFormat == null ? null
|
|
||||||
: oldFormat.drmInitData);
|
|
||||||
if (drmInitDataChanged) {
|
|
||||||
if (inputFormat.drmInitData != null) {
|
|
||||||
|
|
||||||
if (formatHolder.includesDrmSession) {
|
if (formatHolder.includesDrmSession) {
|
||||||
setSourceDrmSession((DrmSession<ExoMediaCrypto>) formatHolder.drmSession);
|
setSourceDrmSession((DrmSession<ExoMediaCrypto>) formatHolder.drmSession);
|
||||||
} else {
|
} else {
|
||||||
if (drmSessionManager == null) {
|
sourceDrmSession =
|
||||||
throw ExoPlaybackException.createForRenderer(
|
getUpdatedSourceDrmSession(inputFormat, newFormat, drmSessionManager, sourceDrmSession);
|
||||||
new IllegalStateException("Media requires a DrmSessionManager"), getIndex());
|
|
||||||
}
|
|
||||||
DrmSession<ExoMediaCrypto> session =
|
|
||||||
drmSessionManager.acquireSession(Looper.myLooper(), inputFormat.drmInitData);
|
|
||||||
if (sourceDrmSession != null) {
|
|
||||||
sourceDrmSession.releaseReference();
|
|
||||||
}
|
|
||||||
sourceDrmSession = session;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
setSourceDrmSession(null);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Format oldFormat = inputFormat;
|
||||||
|
inputFormat = newFormat;
|
||||||
|
|
||||||
if (!canKeepCodec(oldFormat, inputFormat)) {
|
if (!canKeepCodec(oldFormat, inputFormat)) {
|
||||||
if (decoderReceivedBuffers) {
|
if (decoderReceivedBuffers) {
|
||||||
|
@ -23,7 +23,6 @@ import android.media.MediaCrypto;
|
|||||||
import android.media.MediaCryptoException;
|
import android.media.MediaCryptoException;
|
||||||
import android.media.MediaFormat;
|
import android.media.MediaFormat;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Looper;
|
|
||||||
import android.os.SystemClock;
|
import android.os.SystemClock;
|
||||||
import androidx.annotation.CheckResult;
|
import androidx.annotation.CheckResult;
|
||||||
import androidx.annotation.IntDef;
|
import androidx.annotation.IntDef;
|
||||||
@ -1200,33 +1199,15 @@ public abstract class MediaCodecRenderer extends BaseRenderer {
|
|||||||
*/
|
*/
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
protected void onInputFormatChanged(FormatHolder formatHolder) throws ExoPlaybackException {
|
protected void onInputFormatChanged(FormatHolder formatHolder) throws ExoPlaybackException {
|
||||||
Format oldFormat = inputFormat;
|
|
||||||
Format newFormat = formatHolder.format;
|
|
||||||
inputFormat = newFormat;
|
|
||||||
waitingForFirstSampleInFormat = true;
|
waitingForFirstSampleInFormat = true;
|
||||||
|
Format newFormat = Assertions.checkNotNull(formatHolder.format);
|
||||||
boolean drmInitDataChanged =
|
|
||||||
!Util.areEqual(newFormat.drmInitData, oldFormat == null ? null : oldFormat.drmInitData);
|
|
||||||
if (drmInitDataChanged) {
|
|
||||||
if (newFormat.drmInitData != null) {
|
|
||||||
if (formatHolder.includesDrmSession) {
|
if (formatHolder.includesDrmSession) {
|
||||||
setSourceDrmSession((DrmSession<FrameworkMediaCrypto>) formatHolder.drmSession);
|
setSourceDrmSession((DrmSession<FrameworkMediaCrypto>) formatHolder.drmSession);
|
||||||
} else {
|
} else {
|
||||||
if (drmSessionManager == null) {
|
sourceDrmSession =
|
||||||
throw ExoPlaybackException.createForRenderer(
|
getUpdatedSourceDrmSession(inputFormat, newFormat, drmSessionManager, sourceDrmSession);
|
||||||
new IllegalStateException("Media requires a DrmSessionManager"), getIndex());
|
|
||||||
}
|
|
||||||
DrmSession<FrameworkMediaCrypto> session =
|
|
||||||
drmSessionManager.acquireSession(Looper.myLooper(), newFormat.drmInitData);
|
|
||||||
if (sourceDrmSession != null) {
|
|
||||||
sourceDrmSession.releaseReference();
|
|
||||||
}
|
|
||||||
sourceDrmSession = session;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
setSourceDrmSession(null);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
inputFormat = newFormat;
|
||||||
|
|
||||||
if (codec == null) {
|
if (codec == null) {
|
||||||
maybeInitCodec();
|
maybeInitCodec();
|
||||||
|
@ -16,7 +16,6 @@
|
|||||||
package com.google.android.exoplayer2.video;
|
package com.google.android.exoplayer2.video;
|
||||||
|
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.os.Looper;
|
|
||||||
import android.os.SystemClock;
|
import android.os.SystemClock;
|
||||||
import android.view.Surface;
|
import android.view.Surface;
|
||||||
import androidx.annotation.CallSuper;
|
import androidx.annotation.CallSuper;
|
||||||
@ -38,7 +37,6 @@ import com.google.android.exoplayer2.drm.ExoMediaCrypto;
|
|||||||
import com.google.android.exoplayer2.util.Assertions;
|
import com.google.android.exoplayer2.util.Assertions;
|
||||||
import com.google.android.exoplayer2.util.TimedValueQueue;
|
import com.google.android.exoplayer2.util.TimedValueQueue;
|
||||||
import com.google.android.exoplayer2.util.TraceUtil;
|
import com.google.android.exoplayer2.util.TraceUtil;
|
||||||
import com.google.android.exoplayer2.util.Util;
|
|
||||||
import com.google.android.exoplayer2.video.VideoRendererEventListener.EventDispatcher;
|
import com.google.android.exoplayer2.video.VideoRendererEventListener.EventDispatcher;
|
||||||
import java.lang.annotation.Documented;
|
import java.lang.annotation.Documented;
|
||||||
import java.lang.annotation.Retention;
|
import java.lang.annotation.Retention;
|
||||||
@ -363,32 +361,15 @@ public abstract class SimpleDecoderVideoRenderer extends BaseRenderer {
|
|||||||
@CallSuper
|
@CallSuper
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
protected void onInputFormatChanged(FormatHolder formatHolder) throws ExoPlaybackException {
|
protected void onInputFormatChanged(FormatHolder formatHolder) throws ExoPlaybackException {
|
||||||
Format oldFormat = format;
|
|
||||||
format = formatHolder.format;
|
|
||||||
pendingFormat = format;
|
pendingFormat = format;
|
||||||
|
Format newFormat = Assertions.checkNotNull(formatHolder.format);
|
||||||
boolean drmInitDataChanged =
|
|
||||||
!Util.areEqual(format.drmInitData, oldFormat == null ? null : oldFormat.drmInitData);
|
|
||||||
if (drmInitDataChanged) {
|
|
||||||
if (format.drmInitData != null) {
|
|
||||||
if (formatHolder.includesDrmSession) {
|
if (formatHolder.includesDrmSession) {
|
||||||
setSourceDrmSession((DrmSession<ExoMediaCrypto>) formatHolder.drmSession);
|
setSourceDrmSession((DrmSession<ExoMediaCrypto>) formatHolder.drmSession);
|
||||||
} else {
|
} else {
|
||||||
if (drmSessionManager == null) {
|
sourceDrmSession =
|
||||||
throw ExoPlaybackException.createForRenderer(
|
getUpdatedSourceDrmSession(format, newFormat, drmSessionManager, sourceDrmSession);
|
||||||
new IllegalStateException("Media requires a DrmSessionManager"), getIndex());
|
|
||||||
}
|
|
||||||
DrmSession<ExoMediaCrypto> session =
|
|
||||||
drmSessionManager.acquireSession(Looper.myLooper(), format.drmInitData);
|
|
||||||
if (sourceDrmSession != null) {
|
|
||||||
sourceDrmSession.releaseReference();
|
|
||||||
}
|
|
||||||
sourceDrmSession = session;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
setSourceDrmSession(null);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
format = newFormat;
|
||||||
|
|
||||||
if (sourceDrmSession != decoderDrmSession) {
|
if (sourceDrmSession != decoderDrmSession) {
|
||||||
if (decoderReceivedBuffers) {
|
if (decoderReceivedBuffers) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user