Skip to content

Commit

Permalink
Ease the creation of SampleQueues without DRM management
Browse files Browse the repository at this point in the history
This is useful in cases where the client is not interested in DRM.

PiperOrigin-RevId: 346313024
  • Loading branch information
AquilesCanta authored and icbaker committed Dec 14, 2020
1 parent d148db5 commit 9eef7b0
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -715,7 +715,7 @@ private TrackOutput prepareTrackOutput(TrackId id) {
}
}
SampleQueue trackOutput =
new SampleQueue(
SampleQueue.createWithDrm(
allocator,
/* playbackLooper= */ handler.getLooper(),
drmSessionManager,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ public interface UpstreamFormatChangedListener {

private final SampleDataQueue sampleDataQueue;
private final SampleExtrasHolder extrasHolder;
private final Looper playbackLooper;
private final DrmSessionManager drmSessionManager;
private final DrmSessionEventListener.EventDispatcher drmEventDispatcher;
@Nullable private final DrmSessionManager drmSessionManager;
@Nullable private final DrmSessionEventListener.EventDispatcher drmEventDispatcher;
@Nullable private final Looper playbackLooper;
@Nullable private UpstreamFormatChangedListener upstreamFormatChangeListener;

@Nullable private Format downstreamFormat;
Expand Down Expand Up @@ -100,7 +100,23 @@ public interface UpstreamFormatChangedListener {
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 playbackLooper The looper associated with the media playback thread.
Expand All @@ -109,11 +125,23 @@ public interface UpstreamFormatChangedListener {
* @param drmEventDispatcher A {@link DrmSessionEventListener.EventDispatcher} to notify of events
* related to this SampleQueue.
*/
public SampleQueue(
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));
}

protected SampleQueue(
Allocator allocator,
@Nullable Looper playbackLooper,
@Nullable DrmSessionManager drmSessionManager,
@Nullable DrmSessionEventListener.EventDispatcher drmEventDispatcher) {
this.playbackLooper = playbackLooper;
this.drmSessionManager = drmSessionManager;
this.drmEventDispatcher = drmEventDispatcher;
Expand Down Expand Up @@ -844,6 +872,10 @@ private void onFormatResult(Format newFormat, FormatHolder outputFormatHolder) {
outputFormatHolder.format =
newFormat.copyWithExoMediaCryptoType(drmSessionManager.getExoMediaCryptoType(newFormat));
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)) {
// Nothing to do.
return;
Expand All @@ -852,7 +884,8 @@ private void onFormatResult(Format newFormat, FormatHolder outputFormatHolder) {
// is being used for both DrmInitData.
@Nullable DrmSession previousSession = currentDrmSession;
currentDrmSession =
drmSessionManager.acquireSession(playbackLooper, drmEventDispatcher, newFormat);
drmSessionManager.acquireSession(
Assertions.checkNotNull(playbackLooper), drmEventDispatcher, newFormat);
outputFormatHolder.drmSession = currentDrmSession;

if (previousSession != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ public ChunkSampleStream(
SampleQueue[] sampleQueues = new SampleQueue[1 + embeddedTrackCount];

primarySampleQueue =
new SampleQueue(
SampleQueue.createWithDrm(
allocator,
/* playbackLooper= */ checkNotNull(Looper.myLooper()),
drmSessionManager,
Expand All @@ -154,12 +154,7 @@ public ChunkSampleStream(
sampleQueues[0] = primarySampleQueue;

for (int i = 0; i < embeddedTrackCount; i++) {
SampleQueue sampleQueue =
new SampleQueue(
allocator,
/* playbackLooper= */ checkNotNull(Looper.myLooper()),
DrmSessionManager.getDummyDrmSessionManager(),
drmEventDispatcher);
SampleQueue sampleQueue = SampleQueue.createWithoutDrm(allocator);
embeddedSampleQueues[i] = sampleQueue;
sampleQueues[i + 1] = sampleQueue;
trackTypes[i + 1] = this.embeddedTrackTypes[i];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@
import com.google.android.exoplayer2.Format;
import com.google.android.exoplayer2.FormatHolder;
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.metadata.Metadata;
import com.google.android.exoplayer2.metadata.MetadataInputBuffer;
Expand Down Expand Up @@ -285,12 +283,7 @@ public final class PlayerTrackEmsgHandler implements TrackOutput {
private final MetadataInputBuffer buffer;

/* package */ PlayerTrackEmsgHandler(Allocator allocator) {
this.sampleQueue =
new SampleQueue(
allocator,
/* playbackLooper= */ handler.getLooper(),
DrmSessionManager.getDummyDrmSessionManager(),
new DrmSessionEventListener.EventDispatcher());
this.sampleQueue = SampleQueue.createWithoutDrm(allocator);
formatHolder = new FormatHolder();
buffer = new MetadataInputBuffer();
}
Expand Down

0 comments on commit 9eef7b0

Please sign in to comment.