use of com.google.android.exoplayer2.source.MediaSourceEventListener.EventDispatcher in project ExoPlayer by google.
the class HlsMediaSource method prepareSource.
@Override
public void prepareSource(ExoPlayer player, boolean isTopLevelSource, Listener listener) {
Assertions.checkState(playlistTracker == null);
playlistTracker = new HlsPlaylistTracker(manifestUri, dataSourceFactory, eventDispatcher, minLoadableRetryCount, this);
sourceListener = listener;
playlistTracker.start();
}
use of com.google.android.exoplayer2.source.MediaSourceEventListener.EventDispatcher in project ExoPlayer by google.
the class DefaultDrmSessionManager method acquireSession.
// Must be called on the playback thread.
@Nullable
private DrmSession acquireSession(Looper playbackLooper, @Nullable DrmSessionEventListener.EventDispatcher eventDispatcher, Format format, boolean shouldReleasePreacquiredSessionsBeforeRetrying) {
maybeCreateMediaDrmHandler(playbackLooper);
if (format.drmInitData == null) {
// Content is not encrypted.
return maybeAcquirePlaceholderSession(MimeTypes.getTrackType(format.sampleMimeType), shouldReleasePreacquiredSessionsBeforeRetrying);
}
@Nullable List<SchemeData> schemeDatas = null;
if (offlineLicenseKeySetId == null) {
schemeDatas = getSchemeDatas(checkNotNull(format.drmInitData), uuid, false);
if (schemeDatas.isEmpty()) {
final MissingSchemeDataException error = new MissingSchemeDataException(uuid);
Log.e(TAG, "DRM error", error);
if (eventDispatcher != null) {
eventDispatcher.drmSessionManagerError(error);
}
return new ErrorStateDrmSession(new DrmSessionException(error, PlaybackException.ERROR_CODE_DRM_CONTENT_ERROR));
}
}
@Nullable DefaultDrmSession session;
if (!multiSession) {
session = noMultiSessionDrmSession;
} else {
// Only use an existing session if it has matching init data.
session = null;
for (DefaultDrmSession existingSession : sessions) {
if (Util.areEqual(existingSession.schemeDatas, schemeDatas)) {
session = existingSession;
break;
}
}
}
if (session == null) {
// Create a new session.
session = createAndAcquireSessionWithRetry(schemeDatas, /* isPlaceholderSession= */
false, eventDispatcher, shouldReleasePreacquiredSessionsBeforeRetrying);
if (!multiSession) {
noMultiSessionDrmSession = session;
}
sessions.add(session);
} else {
session.acquire(eventDispatcher);
}
return session;
}
use of com.google.android.exoplayer2.source.MediaSourceEventListener.EventDispatcher in project ExoPlayer by google.
the class OfflineLicenseHelper method getLicenseDurationRemainingSec.
/**
* Returns the remaining license and playback durations in seconds, for an offline license.
*
* @param offlineLicenseKeySetId The key set id of the license.
* @return The remaining license and playback durations, in seconds.
* @throws DrmSessionException Thrown when a DRM session error occurs.
*/
public synchronized Pair<Long, Long> getLicenseDurationRemainingSec(byte[] offlineLicenseKeySetId) throws DrmSessionException {
Assertions.checkNotNull(offlineLicenseKeySetId);
drmSessionManager.setPlayer(handlerThread.getLooper(), PlayerId.UNSET);
drmSessionManager.prepare();
DrmSession drmSession = openBlockingKeyRequest(DefaultDrmSessionManager.MODE_QUERY, offlineLicenseKeySetId, FORMAT_WITH_EMPTY_DRM_INIT_DATA);
DrmSessionException error = drmSession.getError();
Pair<Long, Long> licenseDurationRemainingSec = WidevineUtil.getLicenseDurationRemainingSec(drmSession);
drmSession.release(eventDispatcher);
drmSessionManager.release();
if (error != null) {
if (error.getCause() instanceof KeysExpiredException) {
return Pair.create(0L, 0L);
}
throw error;
}
return Assertions.checkNotNull(licenseDurationRemainingSec);
}
use of com.google.android.exoplayer2.source.MediaSourceEventListener.EventDispatcher in project ExoPlayer by google.
the class MergingMediaPeriodTest method prepareMergingPeriod.
private MergingMediaPeriod prepareMergingPeriod(MergingPeriodDefinition... definitions) throws Exception {
MediaPeriod[] mediaPeriods = new MediaPeriod[definitions.length];
long[] timeOffsetsUs = new long[definitions.length];
for (int i = 0; i < definitions.length; i++) {
MergingPeriodDefinition definition = definitions[i];
timeOffsetsUs[i] = definition.timeOffsetUs;
TrackGroup[] trackGroups = new TrackGroup[definition.formats.length];
for (int j = 0; j < definition.formats.length; j++) {
trackGroups[j] = new TrackGroup(definition.formats[j]);
}
mediaPeriods[i] = new FakeMediaPeriodWithSelectTracksPosition(new TrackGroupArray(trackGroups), new EventDispatcher().withParameters(/* windowIndex= */
i, new MediaPeriodId(/* periodUid= */
i), /* mediaTimeOffsetMs= */
0), /* trackDataFactory= */
(unusedFormat, unusedMediaPeriodId) -> ImmutableList.of(oneByteSample(definition.singleSampleTimeUs, C.BUFFER_FLAG_KEY_FRAME), END_OF_STREAM_ITEM));
}
MergingMediaPeriod mergingMediaPeriod = new MergingMediaPeriod(new DefaultCompositeSequenceableLoaderFactory(), timeOffsetsUs, mediaPeriods);
CountDownLatch prepareCountDown = new CountDownLatch(1);
mergingMediaPeriod.prepare(new MediaPeriod.Callback() {
@Override
public void onPrepared(MediaPeriod mediaPeriod) {
prepareCountDown.countDown();
}
@Override
public void onContinueLoadingRequested(MediaPeriod source) {
mergingMediaPeriod.continueLoading(/* positionUs= */
0);
}
}, /* positionUs= */
0);
prepareCountDown.await();
return mergingMediaPeriod;
}
use of com.google.android.exoplayer2.source.MediaSourceEventListener.EventDispatcher in project ExoPlayer by google.
the class DefaultDrmSessionManagerTest method managerRelease_mediaDrmNotReleasedUntilLastSessionReleased.
@Test(timeout = 10_000)
public void managerRelease_mediaDrmNotReleasedUntilLastSessionReleased() throws Exception {
FakeExoMediaDrm.LicenseServer licenseServer = FakeExoMediaDrm.LicenseServer.allowingSchemeDatas(DRM_SCHEME_DATAS);
FakeExoMediaDrm exoMediaDrm = new FakeExoMediaDrm();
DrmSessionManager drmSessionManager = new DefaultDrmSessionManager.Builder().setUuidAndExoMediaDrmProvider(DRM_SCHEME_UUID, new AppManagedProvider(exoMediaDrm)).setSessionKeepaliveMs(10_000).build(/* mediaDrmCallback= */
licenseServer);
drmSessionManager.prepare();
drmSessionManager.setPlayer(/* playbackLooper= */
Looper.myLooper(), PlayerId.UNSET);
DrmSession drmSession = checkNotNull(drmSessionManager.acquireSession(/* eventDispatcher= */
null, FORMAT_WITH_DRM_INIT_DATA));
drmSessionManager.release();
// The manager is now in a 'releasing' state because the session is still active - so the
// ExoMediaDrm instance should still be active (with 1 reference held by this test, and 1 held
// by the manager).
assertThat(exoMediaDrm.getReferenceCount()).isEqualTo(2);
// And re-preparing the session shouldn't acquire another reference.
drmSessionManager.prepare();
assertThat(exoMediaDrm.getReferenceCount()).isEqualTo(2);
drmSessionManager.release();
drmSession.release(/* eventDispatcher= */
null);
// The final session has been released, so now the ExoMediaDrm should be released too.
assertThat(exoMediaDrm.getReferenceCount()).isEqualTo(1);
// Re-preparing the fully released manager should now acquire another ExoMediaDrm reference.
drmSessionManager.prepare();
assertThat(exoMediaDrm.getReferenceCount()).isEqualTo(2);
drmSessionManager.release();
exoMediaDrm.release();
}
Aggregations