Pass the session state to the onDrmSessionAcquired listener method
PiperOrigin-RevId: 358823166
This commit is contained in:
parent
c64a1a0c3c
commit
7b692f9676
@ -37,6 +37,7 @@
|
||||
when playing content that uses the same encryption keys for both audio &
|
||||
video tracks (previously separate acquire and release events were
|
||||
dispatched for each track in each period).
|
||||
* Include the session state in DRM session-acquired listener methods.
|
||||
* VP9 extension: Update to use NDK r22
|
||||
([#8581](https://github.com/google/ExoPlayer/issues/8581)).
|
||||
* FLAC extension: Update to use NDK r22
|
||||
|
@ -21,6 +21,7 @@ import static java.lang.Math.min;
|
||||
import android.os.Handler;
|
||||
import androidx.annotation.Nullable;
|
||||
import com.google.android.exoplayer2.analytics.AnalyticsCollector;
|
||||
import com.google.android.exoplayer2.drm.DrmSession;
|
||||
import com.google.android.exoplayer2.drm.DrmSessionEventListener;
|
||||
import com.google.android.exoplayer2.source.LoadEventInfo;
|
||||
import com.google.android.exoplayer2.source.MaskingMediaPeriod;
|
||||
@ -600,9 +601,11 @@ import java.util.Set;
|
||||
|
||||
@Override
|
||||
public void onDrmSessionAcquired(
|
||||
int windowIndex, @Nullable MediaSource.MediaPeriodId mediaPeriodId) {
|
||||
int windowIndex,
|
||||
@Nullable MediaSource.MediaPeriodId mediaPeriodId,
|
||||
@DrmSession.State int state) {
|
||||
if (maybeUpdateEventDispatcher(windowIndex, mediaPeriodId)) {
|
||||
drmEventDispatcher.drmSessionAcquired();
|
||||
drmEventDispatcher.drmSessionAcquired(state);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -37,6 +37,7 @@ import com.google.android.exoplayer2.audio.AudioAttributes;
|
||||
import com.google.android.exoplayer2.audio.AudioRendererEventListener;
|
||||
import com.google.android.exoplayer2.decoder.DecoderCounters;
|
||||
import com.google.android.exoplayer2.decoder.DecoderReuseEvaluation;
|
||||
import com.google.android.exoplayer2.drm.DrmSession;
|
||||
import com.google.android.exoplayer2.drm.DrmSessionEventListener;
|
||||
import com.google.android.exoplayer2.metadata.Metadata;
|
||||
import com.google.android.exoplayer2.source.LoadEventInfo;
|
||||
@ -753,12 +754,17 @@ public class AnalyticsCollector
|
||||
// DefaultDrmSessionManager.EventListener implementation.
|
||||
|
||||
@Override
|
||||
public final void onDrmSessionAcquired(int windowIndex, @Nullable MediaPeriodId mediaPeriodId) {
|
||||
@SuppressWarnings("deprecation") // Calls deprecated listener method.
|
||||
public final void onDrmSessionAcquired(
|
||||
int windowIndex, @Nullable MediaPeriodId mediaPeriodId, @DrmSession.State int state) {
|
||||
EventTime eventTime = generateMediaPeriodEventTime(windowIndex, mediaPeriodId);
|
||||
sendEvent(
|
||||
eventTime,
|
||||
AnalyticsListener.EVENT_DRM_SESSION_ACQUIRED,
|
||||
listener -> listener.onDrmSessionAcquired(eventTime));
|
||||
listener -> {
|
||||
listener.onDrmSessionAcquired(eventTime);
|
||||
listener.onDrmSessionAcquired(eventTime, state);
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -39,6 +39,7 @@ import com.google.android.exoplayer2.audio.AudioSink;
|
||||
import com.google.android.exoplayer2.decoder.DecoderCounters;
|
||||
import com.google.android.exoplayer2.decoder.DecoderException;
|
||||
import com.google.android.exoplayer2.decoder.DecoderReuseEvaluation;
|
||||
import com.google.android.exoplayer2.drm.DrmSession;
|
||||
import com.google.android.exoplayer2.metadata.Metadata;
|
||||
import com.google.android.exoplayer2.source.LoadEventInfo;
|
||||
import com.google.android.exoplayer2.source.MediaLoadData;
|
||||
@ -1021,12 +1022,17 @@ public interface AnalyticsListener {
|
||||
*/
|
||||
default void onSurfaceSizeChanged(EventTime eventTime, int width, int height) {}
|
||||
|
||||
/** @deprecated Implement {@link #onDrmSessionAcquired(EventTime, int)} instead. */
|
||||
@Deprecated
|
||||
default void onDrmSessionAcquired(EventTime eventTime) {}
|
||||
|
||||
/**
|
||||
* Called each time a drm session is acquired.
|
||||
*
|
||||
* @param eventTime The event time.
|
||||
* @param state The {@link DrmSession.State} of the session when the acquisition completed.
|
||||
*/
|
||||
default void onDrmSessionAcquired(EventTime eventTime) {}
|
||||
default void onDrmSessionAcquired(EventTime eventTime, @DrmSession.State int state) {}
|
||||
|
||||
/**
|
||||
* Called each time drm keys are loaded.
|
||||
|
@ -298,9 +298,7 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull;
|
||||
&& eventDispatchers.count(eventDispatcher) == 1) {
|
||||
// If the session is already open and this is the first instance of eventDispatcher we've
|
||||
// seen, then send the acquire event only to the provided dispatcher.
|
||||
// TODO: Add a parameter to onDrmSessionAcquired to indicate whether the session is being
|
||||
// re-used or not.
|
||||
eventDispatcher.drmSessionAcquired();
|
||||
eventDispatcher.drmSessionAcquired(state);
|
||||
}
|
||||
referenceCountListener.onReferenceCountIncremented(this, referenceCount);
|
||||
}
|
||||
@ -354,8 +352,10 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull;
|
||||
try {
|
||||
sessionId = mediaDrm.openSession();
|
||||
mediaCrypto = mediaDrm.createMediaCrypto(sessionId);
|
||||
dispatchEvent(DrmSessionEventListener.EventDispatcher::drmSessionAcquired);
|
||||
state = STATE_OPENED;
|
||||
// Capture state into a local so a consistent value is seen by the lambda.
|
||||
int localState = state;
|
||||
dispatchEvent(eventDispatcher -> eventDispatcher.drmSessionAcquired(localState));
|
||||
Assertions.checkNotNull(sessionId);
|
||||
return true;
|
||||
} catch (NotProvisionedException e) {
|
||||
|
@ -28,13 +28,19 @@ import java.util.concurrent.CopyOnWriteArrayList;
|
||||
/** Listener of {@link DrmSessionManager} events. */
|
||||
public interface DrmSessionEventListener {
|
||||
|
||||
/** @deprecated Implement {@link #onDrmSessionAcquired(int, MediaPeriodId, int)} instead. */
|
||||
@Deprecated
|
||||
default void onDrmSessionAcquired(int windowIndex, @Nullable MediaPeriodId mediaPeriodId) {}
|
||||
|
||||
/**
|
||||
* Called each time a drm session is acquired.
|
||||
*
|
||||
* @param windowIndex The window index in the timeline this media period belongs to.
|
||||
* @param mediaPeriodId The {@link MediaPeriodId} associated with the drm session.
|
||||
* @param state The {@link DrmSession.State} of the session when the acquisition completed.
|
||||
*/
|
||||
default void onDrmSessionAcquired(int windowIndex, @Nullable MediaPeriodId mediaPeriodId) {}
|
||||
default void onDrmSessionAcquired(
|
||||
int windowIndex, @Nullable MediaPeriodId mediaPeriodId, @DrmSession.State int state) {}
|
||||
|
||||
/**
|
||||
* Called each time keys are loaded.
|
||||
@ -149,13 +155,20 @@ public interface DrmSessionEventListener {
|
||||
}
|
||||
}
|
||||
|
||||
/** Dispatches {@link #onDrmSessionAcquired(int, MediaPeriodId)}. */
|
||||
public void drmSessionAcquired() {
|
||||
/**
|
||||
* Dispatches {@link #onDrmSessionAcquired(int, MediaPeriodId, int)} and {@link
|
||||
* #onDrmSessionAcquired(int, MediaPeriodId)}.
|
||||
*/
|
||||
@SuppressWarnings("deprecation") // Calls deprecated listener method.
|
||||
public void drmSessionAcquired(@DrmSession.State int state) {
|
||||
for (ListenerAndHandler listenerAndHandler : listenerAndHandlers) {
|
||||
DrmSessionEventListener listener = listenerAndHandler.listener;
|
||||
postOrRun(
|
||||
listenerAndHandler.handler,
|
||||
() -> listener.onDrmSessionAcquired(windowIndex, mediaPeriodId));
|
||||
() -> {
|
||||
listener.onDrmSessionAcquired(windowIndex, mediaPeriodId);
|
||||
listener.onDrmSessionAcquired(windowIndex, mediaPeriodId, state);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -19,6 +19,7 @@ import android.os.Handler;
|
||||
import androidx.annotation.CallSuper;
|
||||
import androidx.annotation.Nullable;
|
||||
import com.google.android.exoplayer2.Timeline;
|
||||
import com.google.android.exoplayer2.drm.DrmSession;
|
||||
import com.google.android.exoplayer2.drm.DrmSessionEventListener;
|
||||
import com.google.android.exoplayer2.upstream.TransferListener;
|
||||
import com.google.android.exoplayer2.util.Assertions;
|
||||
@ -290,9 +291,10 @@ public abstract class CompositeMediaSource<T> extends BaseMediaSource {
|
||||
// DrmSessionEventListener implementation
|
||||
|
||||
@Override
|
||||
public void onDrmSessionAcquired(int windowIndex, @Nullable MediaPeriodId mediaPeriodId) {
|
||||
public void onDrmSessionAcquired(
|
||||
int windowIndex, @Nullable MediaPeriodId mediaPeriodId, @DrmSession.State int state) {
|
||||
if (maybeUpdateEventDispatcher(windowIndex, mediaPeriodId)) {
|
||||
drmEventDispatcher.drmSessionAcquired();
|
||||
drmEventDispatcher.drmSessionAcquired(state);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -35,6 +35,7 @@ import com.google.android.exoplayer2.analytics.AnalyticsListener;
|
||||
import com.google.android.exoplayer2.audio.AudioAttributes;
|
||||
import com.google.android.exoplayer2.decoder.DecoderCounters;
|
||||
import com.google.android.exoplayer2.decoder.DecoderReuseEvaluation;
|
||||
import com.google.android.exoplayer2.drm.DrmSession;
|
||||
import com.google.android.exoplayer2.metadata.Metadata;
|
||||
import com.google.android.exoplayer2.source.LoadEventInfo;
|
||||
import com.google.android.exoplayer2.source.MediaLoadData;
|
||||
@ -479,8 +480,8 @@ public class EventLogger implements AnalyticsListener {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDrmSessionAcquired(EventTime eventTime) {
|
||||
logd(eventTime, "drmSessionAcquired");
|
||||
public void onDrmSessionAcquired(EventTime eventTime, @DrmSession.State int state) {
|
||||
logd(eventTime, "drmSessionAcquired", "state=" + state);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -80,6 +80,7 @@ import com.google.android.exoplayer2.Timeline.Window;
|
||||
import com.google.android.exoplayer2.decoder.DecoderCounters;
|
||||
import com.google.android.exoplayer2.drm.DefaultDrmSessionManager;
|
||||
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.ExoMediaDrm;
|
||||
import com.google.android.exoplayer2.drm.MediaDrmCallback;
|
||||
@ -2261,7 +2262,7 @@ public final class AnalyticsCollectorTest {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDrmSessionAcquired(EventTime eventTime) {
|
||||
public void onDrmSessionAcquired(EventTime eventTime, @DrmSession.State int state) {
|
||||
reportedEvents.add(new ReportedEvent(EVENT_DRM_SESSION_ACQUIRED, eventTime));
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user