mirror of
https://github.com/androidx/media.git
synced 2025-05-21 23:56:32 +08:00
Plumb DrmSessionManager into ProgressiveMediaSource
PiperOrigin-RevId: 257777513
This commit is contained in:
parent
df81bd6a68
commit
510f1883b0
@ -486,7 +486,9 @@ public class PlayerActivity extends AppCompatActivity
|
||||
case C.TYPE_HLS:
|
||||
return new HlsMediaSource.Factory(dataSourceFactory).createMediaSource(uri);
|
||||
case C.TYPE_OTHER:
|
||||
return new ProgressiveMediaSource.Factory(dataSourceFactory).createMediaSource(uri);
|
||||
return new ProgressiveMediaSource.Factory(dataSourceFactory)
|
||||
.setDrmSessionManager(drmSessionManager)
|
||||
.createMediaSource(uri);
|
||||
default:
|
||||
throw new IllegalStateException("Unsupported type: " + type);
|
||||
}
|
||||
|
@ -21,6 +21,7 @@ import androidx.annotation.Nullable;
|
||||
import com.google.android.exoplayer2.C;
|
||||
import com.google.android.exoplayer2.Player;
|
||||
import com.google.android.exoplayer2.Timeline;
|
||||
import com.google.android.exoplayer2.drm.DrmSessionManager;
|
||||
import com.google.android.exoplayer2.extractor.DefaultExtractorsFactory;
|
||||
import com.google.android.exoplayer2.extractor.Extractor;
|
||||
import com.google.android.exoplayer2.extractor.ExtractorsFactory;
|
||||
@ -325,6 +326,7 @@ public final class ExtractorMediaSource extends CompositeMediaSource<Void> {
|
||||
uri,
|
||||
dataSourceFactory,
|
||||
extractorsFactory,
|
||||
DrmSessionManager.getDummyDrmSessionManager(),
|
||||
loadableLoadErrorHandlingPolicy,
|
||||
customCacheKey,
|
||||
continueLoadingCheckIntervalBytes,
|
||||
|
@ -24,6 +24,7 @@ import com.google.android.exoplayer2.FormatHolder;
|
||||
import com.google.android.exoplayer2.ParserException;
|
||||
import com.google.android.exoplayer2.SeekParameters;
|
||||
import com.google.android.exoplayer2.decoder.DecoderInputBuffer;
|
||||
import com.google.android.exoplayer2.drm.DrmSessionManager;
|
||||
import com.google.android.exoplayer2.extractor.DefaultExtractorInput;
|
||||
import com.google.android.exoplayer2.extractor.Extractor;
|
||||
import com.google.android.exoplayer2.extractor.ExtractorInput;
|
||||
@ -90,6 +91,7 @@ import org.checkerframework.checker.nullness.compatqual.NullableType;
|
||||
|
||||
private final Uri uri;
|
||||
private final DataSource dataSource;
|
||||
private final DrmSessionManager<?> drmSessionManager;
|
||||
private final LoadErrorHandlingPolicy loadErrorHandlingPolicy;
|
||||
private final EventDispatcher eventDispatcher;
|
||||
private final Listener listener;
|
||||
@ -107,6 +109,7 @@ import org.checkerframework.checker.nullness.compatqual.NullableType;
|
||||
@Nullable private SeekMap seekMap;
|
||||
@Nullable private IcyHeaders icyHeaders;
|
||||
private SampleQueue[] sampleQueues;
|
||||
private DecryptableSampleQueueReader[] sampleQueueReaders;
|
||||
private TrackId[] sampleQueueTrackIds;
|
||||
private boolean sampleQueuesBuilt;
|
||||
private boolean prepared;
|
||||
@ -152,6 +155,7 @@ import org.checkerframework.checker.nullness.compatqual.NullableType;
|
||||
Uri uri,
|
||||
DataSource dataSource,
|
||||
Extractor[] extractors,
|
||||
DrmSessionManager<?> drmSessionManager,
|
||||
LoadErrorHandlingPolicy loadErrorHandlingPolicy,
|
||||
EventDispatcher eventDispatcher,
|
||||
Listener listener,
|
||||
@ -160,6 +164,7 @@ import org.checkerframework.checker.nullness.compatqual.NullableType;
|
||||
int continueLoadingCheckIntervalBytes) {
|
||||
this.uri = uri;
|
||||
this.dataSource = dataSource;
|
||||
this.drmSessionManager = drmSessionManager;
|
||||
this.loadErrorHandlingPolicy = loadErrorHandlingPolicy;
|
||||
this.eventDispatcher = eventDispatcher;
|
||||
this.listener = listener;
|
||||
@ -180,6 +185,7 @@ import org.checkerframework.checker.nullness.compatqual.NullableType;
|
||||
handler = new Handler();
|
||||
sampleQueueTrackIds = new TrackId[0];
|
||||
sampleQueues = new SampleQueue[0];
|
||||
sampleQueueReaders = new DecryptableSampleQueueReader[0];
|
||||
pendingResetPositionUs = C.TIME_UNSET;
|
||||
length = C.LENGTH_UNSET;
|
||||
durationUs = C.TIME_UNSET;
|
||||
@ -195,6 +201,9 @@ import org.checkerframework.checker.nullness.compatqual.NullableType;
|
||||
sampleQueue.discardToEnd();
|
||||
}
|
||||
}
|
||||
for (DecryptableSampleQueueReader reader : sampleQueueReaders) {
|
||||
reader.release();
|
||||
}
|
||||
loader.release(/* callback= */ this);
|
||||
handler.removeCallbacksAndMessages(null);
|
||||
callback = null;
|
||||
@ -432,29 +441,32 @@ import org.checkerframework.checker.nullness.compatqual.NullableType;
|
||||
// SampleStream methods.
|
||||
|
||||
/* package */ boolean isReady(int track) {
|
||||
return !suppressRead() && (loadingFinished || sampleQueues[track].hasNextSample());
|
||||
return !suppressRead() && sampleQueueReaders[track].isReady(loadingFinished);
|
||||
}
|
||||
|
||||
/* package */ void maybeThrowError(int sampleQueueIndex) throws IOException {
|
||||
sampleQueueReaders[sampleQueueIndex].maybeThrowError();
|
||||
maybeThrowError();
|
||||
}
|
||||
|
||||
/* package */ void maybeThrowError() throws IOException {
|
||||
loader.maybeThrowError(loadErrorHandlingPolicy.getMinimumLoadableRetryCount(dataType));
|
||||
}
|
||||
|
||||
/* package */ int readData(int track, FormatHolder formatHolder, DecoderInputBuffer buffer,
|
||||
/* package */ int readData(
|
||||
int sampleQueueIndex,
|
||||
FormatHolder formatHolder,
|
||||
DecoderInputBuffer buffer,
|
||||
boolean formatRequired) {
|
||||
if (suppressRead()) {
|
||||
return C.RESULT_NOTHING_READ;
|
||||
}
|
||||
maybeNotifyDownstreamFormat(track);
|
||||
maybeNotifyDownstreamFormat(sampleQueueIndex);
|
||||
int result =
|
||||
sampleQueues[track].read(
|
||||
formatHolder,
|
||||
buffer,
|
||||
formatRequired,
|
||||
/* allowOnlyClearBuffers= */ false,
|
||||
loadingFinished,
|
||||
lastSeekPositionUs);
|
||||
sampleQueueReaders[sampleQueueIndex].read(
|
||||
formatHolder, buffer, formatRequired, loadingFinished, lastSeekPositionUs);
|
||||
if (result == C.RESULT_NOTHING_READ) {
|
||||
maybeStartDeferredRetry(track);
|
||||
maybeStartDeferredRetry(sampleQueueIndex);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@ -667,6 +679,12 @@ import org.checkerframework.checker.nullness.compatqual.NullableType;
|
||||
@NullableType SampleQueue[] sampleQueues = Arrays.copyOf(this.sampleQueues, trackCount + 1);
|
||||
sampleQueues[trackCount] = trackOutput;
|
||||
this.sampleQueues = Util.castNonNullTypeArray(sampleQueues);
|
||||
@NullableType
|
||||
DecryptableSampleQueueReader[] sampleQueueReaders =
|
||||
Arrays.copyOf(this.sampleQueueReaders, trackCount + 1);
|
||||
sampleQueueReaders[trackCount] =
|
||||
new DecryptableSampleQueueReader(this.sampleQueues[trackCount], drmSessionManager);
|
||||
this.sampleQueueReaders = Util.castNonNullTypeArray(sampleQueueReaders);
|
||||
return trackOutput;
|
||||
}
|
||||
|
||||
@ -868,7 +886,7 @@ import org.checkerframework.checker.nullness.compatqual.NullableType;
|
||||
|
||||
@Override
|
||||
public void maybeThrowError() throws IOException {
|
||||
ProgressiveMediaPeriod.this.maybeThrowError();
|
||||
ProgressiveMediaPeriod.this.maybeThrowError(track);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -18,6 +18,8 @@ package com.google.android.exoplayer2.source;
|
||||
import android.net.Uri;
|
||||
import androidx.annotation.Nullable;
|
||||
import com.google.android.exoplayer2.C;
|
||||
import com.google.android.exoplayer2.drm.DrmSession;
|
||||
import com.google.android.exoplayer2.drm.DrmSessionManager;
|
||||
import com.google.android.exoplayer2.extractor.DefaultExtractorsFactory;
|
||||
import com.google.android.exoplayer2.extractor.Extractor;
|
||||
import com.google.android.exoplayer2.extractor.ExtractorsFactory;
|
||||
@ -51,6 +53,7 @@ public final class ProgressiveMediaSource extends BaseMediaSource
|
||||
private ExtractorsFactory extractorsFactory;
|
||||
@Nullable private String customCacheKey;
|
||||
@Nullable private Object tag;
|
||||
private DrmSessionManager<?> drmSessionManager;
|
||||
private LoadErrorHandlingPolicy loadErrorHandlingPolicy;
|
||||
private int continueLoadingCheckIntervalBytes;
|
||||
private boolean isCreateCalled;
|
||||
@ -74,6 +77,7 @@ public final class ProgressiveMediaSource extends BaseMediaSource
|
||||
public Factory(DataSource.Factory dataSourceFactory, ExtractorsFactory extractorsFactory) {
|
||||
this.dataSourceFactory = dataSourceFactory;
|
||||
this.extractorsFactory = extractorsFactory;
|
||||
drmSessionManager = DrmSessionManager.getDummyDrmSessionManager();
|
||||
loadErrorHandlingPolicy = new DefaultLoadErrorHandlingPolicy();
|
||||
continueLoadingCheckIntervalBytes = DEFAULT_LOADING_CHECK_INTERVAL_BYTES;
|
||||
}
|
||||
@ -128,6 +132,20 @@ public final class ProgressiveMediaSource extends BaseMediaSource
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the {@link DrmSessionManager} to use for acquiring {@link DrmSession DrmSessions}. The
|
||||
* default value is {@link DrmSessionManager#DUMMY}.
|
||||
*
|
||||
* @param drmSessionManager The {@link DrmSessionManager}.
|
||||
* @return This factory, for convenience.
|
||||
* @throws IllegalStateException If one of the {@code create} methods has already been called.
|
||||
*/
|
||||
public Factory setDrmSessionManager(DrmSessionManager<?> drmSessionManager) {
|
||||
Assertions.checkState(!isCreateCalled);
|
||||
this.drmSessionManager = drmSessionManager;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the {@link LoadErrorHandlingPolicy}. The default value is created by calling {@link
|
||||
* DefaultLoadErrorHandlingPolicy#DefaultLoadErrorHandlingPolicy()}.
|
||||
@ -172,6 +190,7 @@ public final class ProgressiveMediaSource extends BaseMediaSource
|
||||
uri,
|
||||
dataSourceFactory,
|
||||
extractorsFactory,
|
||||
drmSessionManager,
|
||||
loadErrorHandlingPolicy,
|
||||
customCacheKey,
|
||||
continueLoadingCheckIntervalBytes,
|
||||
@ -193,6 +212,7 @@ public final class ProgressiveMediaSource extends BaseMediaSource
|
||||
private final Uri uri;
|
||||
private final DataSource.Factory dataSourceFactory;
|
||||
private final ExtractorsFactory extractorsFactory;
|
||||
private final DrmSessionManager<?> drmSessionManager;
|
||||
private final LoadErrorHandlingPolicy loadableLoadErrorHandlingPolicy;
|
||||
@Nullable private final String customCacheKey;
|
||||
private final int continueLoadingCheckIntervalBytes;
|
||||
@ -207,6 +227,7 @@ public final class ProgressiveMediaSource extends BaseMediaSource
|
||||
Uri uri,
|
||||
DataSource.Factory dataSourceFactory,
|
||||
ExtractorsFactory extractorsFactory,
|
||||
DrmSessionManager<?> drmSessionManager,
|
||||
LoadErrorHandlingPolicy loadableLoadErrorHandlingPolicy,
|
||||
@Nullable String customCacheKey,
|
||||
int continueLoadingCheckIntervalBytes,
|
||||
@ -214,6 +235,7 @@ public final class ProgressiveMediaSource extends BaseMediaSource
|
||||
this.uri = uri;
|
||||
this.dataSourceFactory = dataSourceFactory;
|
||||
this.extractorsFactory = extractorsFactory;
|
||||
this.drmSessionManager = drmSessionManager;
|
||||
this.loadableLoadErrorHandlingPolicy = loadableLoadErrorHandlingPolicy;
|
||||
this.customCacheKey = customCacheKey;
|
||||
this.continueLoadingCheckIntervalBytes = continueLoadingCheckIntervalBytes;
|
||||
@ -248,6 +270,7 @@ public final class ProgressiveMediaSource extends BaseMediaSource
|
||||
uri,
|
||||
dataSource,
|
||||
extractorsFactory.createExtractors(),
|
||||
drmSessionManager,
|
||||
loadableLoadErrorHandlingPolicy,
|
||||
createEventDispatcher(id),
|
||||
this,
|
||||
|
Loading…
x
Reference in New Issue
Block a user