Commit 9eef7b06 by aquilescanta Committed by Ian Baker

Ease the creation of SampleQueues without DRM management

This is useful in cases where the client is not interested in DRM.

PiperOrigin-RevId: 346313024
parent d148db57
...@@ -715,7 +715,7 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull; ...@@ -715,7 +715,7 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
} }
} }
SampleQueue trackOutput = SampleQueue trackOutput =
new SampleQueue( SampleQueue.createWithDrm(
allocator, allocator,
/* playbackLooper= */ handler.getLooper(), /* playbackLooper= */ handler.getLooper(),
drmSessionManager, drmSessionManager,
......
...@@ -60,9 +60,9 @@ public class SampleQueue implements TrackOutput { ...@@ -60,9 +60,9 @@ public class SampleQueue implements TrackOutput {
private final SampleDataQueue sampleDataQueue; private final SampleDataQueue sampleDataQueue;
private final SampleExtrasHolder extrasHolder; private final SampleExtrasHolder extrasHolder;
private final Looper playbackLooper; @Nullable private final DrmSessionManager drmSessionManager;
private final DrmSessionManager drmSessionManager; @Nullable private final DrmSessionEventListener.EventDispatcher drmEventDispatcher;
private final DrmSessionEventListener.EventDispatcher drmEventDispatcher; @Nullable private final Looper playbackLooper;
@Nullable private UpstreamFormatChangedListener upstreamFormatChangeListener; @Nullable private UpstreamFormatChangedListener upstreamFormatChangeListener;
@Nullable private Format downstreamFormat; @Nullable private Format downstreamFormat;
...@@ -100,7 +100,23 @@ public class SampleQueue implements TrackOutput { ...@@ -100,7 +100,23 @@ public class SampleQueue implements TrackOutput {
private boolean pendingSplice; private boolean pendingSplice;
/** /**
* Creates a sample queue. * Creates a sample queue without DRM resource management.
*
* @param allocator An {@link Allocator} from which allocations for sample data can be obtained.
*/
public static SampleQueue createWithoutDrm(Allocator allocator) {
return new SampleQueue(
allocator,
/* playbackLooper= */ null,
/* drmSessionManager= */ null,
/* drmEventDispatcher= */ null);
}
/**
* Creates a sample queue with DRM resource management.
*
* <p>For each sample added to the queue, a {@link DrmSession} will be attached containing the
* keys needed to decrypt it.
* *
* @param allocator An {@link Allocator} from which allocations for sample data can be obtained. * @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 playbackLooper The looper associated with the media playback thread.
...@@ -109,11 +125,23 @@ public class SampleQueue implements TrackOutput { ...@@ -109,11 +125,23 @@ public class SampleQueue implements TrackOutput {
* @param drmEventDispatcher A {@link DrmSessionEventListener.EventDispatcher} to notify of events * @param drmEventDispatcher A {@link DrmSessionEventListener.EventDispatcher} to notify of events
* related to this SampleQueue. * related to this SampleQueue.
*/ */
public SampleQueue( public static SampleQueue createWithDrm(
Allocator allocator, Allocator allocator,
Looper playbackLooper, Looper playbackLooper,
DrmSessionManager drmSessionManager, DrmSessionManager drmSessionManager,
DrmSessionEventListener.EventDispatcher drmEventDispatcher) { DrmSessionEventListener.EventDispatcher drmEventDispatcher) {
return new SampleQueue(
allocator,
Assertions.checkNotNull(playbackLooper),
Assertions.checkNotNull(drmSessionManager),
Assertions.checkNotNull(drmEventDispatcher));
}
protected SampleQueue(
Allocator allocator,
@Nullable Looper playbackLooper,
@Nullable DrmSessionManager drmSessionManager,
@Nullable DrmSessionEventListener.EventDispatcher drmEventDispatcher) {
this.playbackLooper = playbackLooper; this.playbackLooper = playbackLooper;
this.drmSessionManager = drmSessionManager; this.drmSessionManager = drmSessionManager;
this.drmEventDispatcher = drmEventDispatcher; this.drmEventDispatcher = drmEventDispatcher;
...@@ -844,6 +872,10 @@ public class SampleQueue implements TrackOutput { ...@@ -844,6 +872,10 @@ public class SampleQueue implements TrackOutput {
outputFormatHolder.format = outputFormatHolder.format =
newFormat.copyWithExoMediaCryptoType(drmSessionManager.getExoMediaCryptoType(newFormat)); newFormat.copyWithExoMediaCryptoType(drmSessionManager.getExoMediaCryptoType(newFormat));
outputFormatHolder.drmSession = currentDrmSession; outputFormatHolder.drmSession = currentDrmSession;
if (drmSessionManager == null) {
// This sample queue is not expected to handle DRM. Nothing to do.
return;
}
if (!isFirstFormat && Util.areEqual(oldDrmInitData, newDrmInitData)) { if (!isFirstFormat && Util.areEqual(oldDrmInitData, newDrmInitData)) {
// Nothing to do. // Nothing to do.
return; return;
...@@ -852,7 +884,8 @@ public class SampleQueue implements TrackOutput { ...@@ -852,7 +884,8 @@ public class SampleQueue implements TrackOutput {
// is being used for both DrmInitData. // is being used for both DrmInitData.
@Nullable DrmSession previousSession = currentDrmSession; @Nullable DrmSession previousSession = currentDrmSession;
currentDrmSession = currentDrmSession =
drmSessionManager.acquireSession(playbackLooper, drmEventDispatcher, newFormat); drmSessionManager.acquireSession(
Assertions.checkNotNull(playbackLooper), drmEventDispatcher, newFormat);
outputFormatHolder.drmSession = currentDrmSession; outputFormatHolder.drmSession = currentDrmSession;
if (previousSession != null) { if (previousSession != null) {
......
...@@ -145,7 +145,7 @@ public class ChunkSampleStream<T extends ChunkSource> implements SampleStream, S ...@@ -145,7 +145,7 @@ public class ChunkSampleStream<T extends ChunkSource> implements SampleStream, S
SampleQueue[] sampleQueues = new SampleQueue[1 + embeddedTrackCount]; SampleQueue[] sampleQueues = new SampleQueue[1 + embeddedTrackCount];
primarySampleQueue = primarySampleQueue =
new SampleQueue( SampleQueue.createWithDrm(
allocator, allocator,
/* playbackLooper= */ checkNotNull(Looper.myLooper()), /* playbackLooper= */ checkNotNull(Looper.myLooper()),
drmSessionManager, drmSessionManager,
...@@ -154,12 +154,7 @@ public class ChunkSampleStream<T extends ChunkSource> implements SampleStream, S ...@@ -154,12 +154,7 @@ public class ChunkSampleStream<T extends ChunkSource> implements SampleStream, S
sampleQueues[0] = primarySampleQueue; sampleQueues[0] = primarySampleQueue;
for (int i = 0; i < embeddedTrackCount; i++) { for (int i = 0; i < embeddedTrackCount; i++) {
SampleQueue sampleQueue = SampleQueue sampleQueue = SampleQueue.createWithoutDrm(allocator);
new SampleQueue(
allocator,
/* playbackLooper= */ checkNotNull(Looper.myLooper()),
DrmSessionManager.getDummyDrmSessionManager(),
drmEventDispatcher);
embeddedSampleQueues[i] = sampleQueue; embeddedSampleQueues[i] = sampleQueue;
sampleQueues[i + 1] = sampleQueue; sampleQueues[i + 1] = sampleQueue;
trackTypes[i + 1] = this.embeddedTrackTypes[i]; trackTypes[i + 1] = this.embeddedTrackTypes[i];
......
...@@ -24,8 +24,6 @@ import com.google.android.exoplayer2.C; ...@@ -24,8 +24,6 @@ import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.Format; import com.google.android.exoplayer2.Format;
import com.google.android.exoplayer2.FormatHolder; import com.google.android.exoplayer2.FormatHolder;
import com.google.android.exoplayer2.ParserException; import com.google.android.exoplayer2.ParserException;
import com.google.android.exoplayer2.drm.DrmSessionEventListener;
import com.google.android.exoplayer2.drm.DrmSessionManager;
import com.google.android.exoplayer2.extractor.TrackOutput; import com.google.android.exoplayer2.extractor.TrackOutput;
import com.google.android.exoplayer2.metadata.Metadata; import com.google.android.exoplayer2.metadata.Metadata;
import com.google.android.exoplayer2.metadata.MetadataInputBuffer; import com.google.android.exoplayer2.metadata.MetadataInputBuffer;
...@@ -285,12 +283,7 @@ public final class PlayerEmsgHandler implements Handler.Callback { ...@@ -285,12 +283,7 @@ public final class PlayerEmsgHandler implements Handler.Callback {
private final MetadataInputBuffer buffer; private final MetadataInputBuffer buffer;
/* package */ PlayerTrackEmsgHandler(Allocator allocator) { /* package */ PlayerTrackEmsgHandler(Allocator allocator) {
this.sampleQueue = this.sampleQueue = SampleQueue.createWithoutDrm(allocator);
new SampleQueue(
allocator,
/* playbackLooper= */ handler.getLooper(),
DrmSessionManager.getDummyDrmSessionManager(),
new DrmSessionEventListener.EventDispatcher());
formatHolder = new FormatHolder(); formatHolder = new FormatHolder();
buffer = new MetadataInputBuffer(); buffer = new MetadataInputBuffer();
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment