From 39827fad2781de4a5f3f3da0c6636b62f515f3fc Mon Sep 17 00:00:00 2001 From: eguven Date: Thu, 22 Dec 2016 09:27:20 -0800 Subject: [PATCH] Allow specifying a custom cacheKey to ExtractorMediaSource Issue: #2201 ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=142772885 --- demo/src/main/assets/media.exolist.json | 24 ---------------- .../source/ExtractorMediaPeriod.java | 8 ++++-- .../source/ExtractorMediaSource.java | 28 +++++++++++++++++-- 3 files changed, 31 insertions(+), 29 deletions(-) diff --git a/demo/src/main/assets/media.exolist.json b/demo/src/main/assets/media.exolist.json index 5a3015d506..6fba5bd65b 100644 --- a/demo/src/main/assets/media.exolist.json +++ b/demo/src/main/assets/media.exolist.json @@ -229,30 +229,6 @@ "uri": "https://storage.googleapis.com/wvmedia/cenc/vp9/subsample/24fps/tears/tears_uhd.mpd", "drm_scheme": "widevine", "drm_license_url": "https://proxy.uat.widevine.com/proxy?provider=widevine_test" - }, - { - "name": "WV: Secure Subsample (WebM, VP9 with altref)", - "uri": "https://storage.googleapis.com/widevine_test/vp9/sintel_1080p_vp9_altref_subsample/sintel_1080p_vp9_altref_subsample.mpd", - "drm_scheme": "widevine", - "drm_license_url": "https://widevine-proxy.appspot.com/proxy" - }, - { - "name": "WV: Secure Fullsample (WebM, VP9 with altref)", - "uri": "https://storage.googleapis.com/widevine_test/vp9/sintel_1080p_vp9_altref_fullsample/sintel_1080p_vp9_altref_fullsample.mpd", - "drm_scheme": "widevine", - "drm_license_url": "https://widevine-proxy.appspot.com/proxy" - }, - { - "name": "WV: Secure Subsample (WebM, VP9 without altref)", - "uri": "https://storage.googleapis.com/widevine_test/vp9/sintel_1080p_vp9_noaltref_subsample/sintel_1080p_vp9_noaltref_subsample.mpd", - "drm_scheme": "widevine", - "drm_license_url": "https://widevine-proxy.appspot.com/proxy" - }, - { - "name": "WV: Secure Fullsample (WebM, VP9 without altref)", - "uri": "https://storage.googleapis.com/widevine_test/vp9/sintel_1080p_vp9_noaltref_fullsample/sintel_1080p_vp9_noaltref_fullsample.mpd", - "drm_scheme": "widevine", - "drm_license_url": "https://widevine-proxy.appspot.com/proxy" } ] }, diff --git a/library/src/main/java/com/google/android/exoplayer2/source/ExtractorMediaPeriod.java b/library/src/main/java/com/google/android/exoplayer2/source/ExtractorMediaPeriod.java index 8ab4d45c47..dacc40253d 100644 --- a/library/src/main/java/com/google/android/exoplayer2/source/ExtractorMediaPeriod.java +++ b/library/src/main/java/com/google/android/exoplayer2/source/ExtractorMediaPeriod.java @@ -62,6 +62,7 @@ import java.io.IOException; private final ExtractorMediaSource.EventListener eventListener; private final MediaSource.Listener sourceListener; private final Allocator allocator; + private final String customCacheKey; private final Loader loader; private final ExtractorHolder extractorHolder; private final ConditionVariable loadCondition; @@ -101,11 +102,13 @@ import java.io.IOException; * @param eventListener A listener of events. May be null if delivery of events is not required. * @param sourceListener A listener to notify when the timeline has been loaded. * @param allocator An {@link Allocator} from which to obtain media buffer allocations. + * @param customCacheKey A custom key that uniquely identifies the original stream. Used for cache + * indexing. May be null. */ public ExtractorMediaPeriod(Uri uri, DataSource dataSource, Extractor[] extractors, int minLoadableRetryCount, Handler eventHandler, ExtractorMediaSource.EventListener eventListener, MediaSource.Listener sourceListener, - Allocator allocator) { + Allocator allocator, String customCacheKey) { this.uri = uri; this.dataSource = dataSource; this.minLoadableRetryCount = minLoadableRetryCount; @@ -113,6 +116,7 @@ import java.io.IOException; this.eventListener = eventListener; this.sourceListener = sourceListener; this.allocator = allocator; + this.customCacheKey = customCacheKey; loader = new Loader("Loader:ExtractorMediaPeriod"); extractorHolder = new ExtractorHolder(extractors, this); loadCondition = new ConditionVariable(); @@ -615,7 +619,7 @@ import java.io.IOException; ExtractorInput input = null; try { long position = positionHolder.position; - length = dataSource.open(new DataSpec(uri, position, C.LENGTH_UNSET, null)); + length = dataSource.open(new DataSpec(uri, position, C.LENGTH_UNSET, customCacheKey)); if (length != C.LENGTH_UNSET) { length += position; } diff --git a/library/src/main/java/com/google/android/exoplayer2/source/ExtractorMediaSource.java b/library/src/main/java/com/google/android/exoplayer2/source/ExtractorMediaSource.java index 559d241598..7b571bc289 100644 --- a/library/src/main/java/com/google/android/exoplayer2/source/ExtractorMediaSource.java +++ b/library/src/main/java/com/google/android/exoplayer2/source/ExtractorMediaSource.java @@ -93,6 +93,7 @@ public final class ExtractorMediaSource implements MediaSource, MediaSource.List private final Handler eventHandler; private final EventListener eventListener; private final Timeline.Period period; + private final String customCacheKey; private MediaSource.Listener sourceListener; private Timeline timeline; @@ -110,7 +111,25 @@ public final class ExtractorMediaSource implements MediaSource, MediaSource.List public ExtractorMediaSource(Uri uri, DataSource.Factory dataSourceFactory, ExtractorsFactory extractorsFactory, Handler eventHandler, EventListener eventListener) { this(uri, dataSourceFactory, extractorsFactory, MIN_RETRY_COUNT_DEFAULT_FOR_MEDIA, eventHandler, - eventListener); + eventListener, null); + } + + /** + * @param uri The {@link Uri} of the media stream. + * @param dataSourceFactory A factory for {@link DataSource}s to read the media. + * @param extractorsFactory A factory for {@link Extractor}s to process the media stream. If the + * possible formats are known, pass a factory that instantiates extractors for those formats. + * Otherwise, pass a {@link DefaultExtractorsFactory} to use default extractors. + * @param eventHandler A handler for events. May be null if delivery of events is not required. + * @param eventListener A listener of events. May be null if delivery of events is not required. + * @param customCacheKey A custom key that uniquely identifies the original stream. Used for cache + * indexing. May be null. + */ + public ExtractorMediaSource(Uri uri, DataSource.Factory dataSourceFactory, + ExtractorsFactory extractorsFactory, Handler eventHandler, EventListener eventListener, + String customCacheKey) { + this(uri, dataSourceFactory, extractorsFactory, MIN_RETRY_COUNT_DEFAULT_FOR_MEDIA, eventHandler, + eventListener, customCacheKey); } /** @@ -122,16 +141,19 @@ public final class ExtractorMediaSource implements MediaSource, MediaSource.List * @param minLoadableRetryCount The minimum number of times to retry if a loading error occurs. * @param eventHandler A handler for events. May be null if delivery of events is not required. * @param eventListener A listener of events. May be null if delivery of events is not required. + * @param customCacheKey A custom key that uniquely identifies the original stream. Used for cache + * indexing. May be null. */ public ExtractorMediaSource(Uri uri, DataSource.Factory dataSourceFactory, ExtractorsFactory extractorsFactory, int minLoadableRetryCount, Handler eventHandler, - EventListener eventListener) { + EventListener eventListener, String customCacheKey) { this.uri = uri; this.dataSourceFactory = dataSourceFactory; this.extractorsFactory = extractorsFactory; this.minLoadableRetryCount = minLoadableRetryCount; this.eventHandler = eventHandler; this.eventListener = eventListener; + this.customCacheKey = customCacheKey; period = new Timeline.Period(); } @@ -152,7 +174,7 @@ public final class ExtractorMediaSource implements MediaSource, MediaSource.List Assertions.checkArgument(index == 0); return new ExtractorMediaPeriod(uri, dataSourceFactory.createDataSource(), extractorsFactory.createExtractors(), minLoadableRetryCount, eventHandler, eventListener, - this, allocator); + this, allocator, customCacheKey); } @Override