From 877c6965c34e542f4dc8f4162f29ff685f0e01e5 Mon Sep 17 00:00:00 2001 From: tonihei Date: Mon, 11 Jun 2018 09:59:56 -0700 Subject: [PATCH] Correctly report type of ParsingLoadable. The helper method only reported DATA_TYPE_UNKNOWN even if the actual type is known. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=200067296 --- .../exoplayer2/upstream/ParsingLoadable.java | 23 ++++++++++--------- .../exoplayer2/source/dash/DashUtil.java | 2 +- .../dash/offline/DashDownloadHelper.java | 4 +++- .../source/hls/offline/HlsDownloadHelper.java | 3 ++- .../source/hls/offline/HlsDownloader.java | 5 +--- .../offline/SsDownloadHelper.java | 3 ++- .../smoothstreaming/offline/SsDownloader.java | 5 +--- 7 files changed, 22 insertions(+), 23 deletions(-) diff --git a/library/core/src/main/java/com/google/android/exoplayer2/upstream/ParsingLoadable.java b/library/core/src/main/java/com/google/android/exoplayer2/upstream/ParsingLoadable.java index 987effcf43..4a17b070a6 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/upstream/ParsingLoadable.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/upstream/ParsingLoadable.java @@ -16,9 +16,11 @@ package com.google.android.exoplayer2.upstream; import android.net.Uri; +import android.support.annotation.Nullable; import com.google.android.exoplayer2.C; import com.google.android.exoplayer2.ParserException; import com.google.android.exoplayer2.upstream.Loader.Loadable; +import com.google.android.exoplayer2.util.Assertions; import com.google.android.exoplayer2.util.Util; import java.io.IOException; import java.io.InputStream; @@ -52,16 +54,17 @@ public final class ParsingLoadable implements Loadable { * Loads a single parsable object. * * @param dataSource The {@link DataSource} through which the object should be read. + * @param parser The {@link Parser} to parse the object from the response. * @param uri The {@link Uri} of the object to read. + * @param type The type of the data. One of the {@link C}{@code DATA_TYPE_*} constants. * @return The parsed object * @throws IOException Thrown if there is an error while loading or parsing. */ - public static T load(DataSource dataSource, Parser parser, Uri uri) + public static T load(DataSource dataSource, Parser parser, Uri uri, int type) throws IOException { - ParsingLoadable loadable = - new ParsingLoadable<>(dataSource, uri, C.DATA_TYPE_UNKNOWN, parser); + ParsingLoadable loadable = new ParsingLoadable<>(dataSource, uri, type, parser); loadable.load(); - return loadable.getResult(); + return Assertions.checkNotNull(loadable.getResult()); } /** @@ -77,7 +80,7 @@ public final class ParsingLoadable implements Loadable { private final DataSource dataSource; private final Parser parser; - private volatile T result; + private volatile @Nullable T result; private volatile long bytesLoaded; /** @@ -108,10 +111,8 @@ public final class ParsingLoadable implements Loadable { this.parser = parser; } - /** - * Returns the loaded object, or null if an object has not been loaded. - */ - public final T getResult() { + /** Returns the loaded object, or null if an object has not been loaded. */ + public final @Nullable T getResult() { return result; } @@ -135,11 +136,11 @@ public final class ParsingLoadable implements Loadable { DataSourceInputStream inputStream = new DataSourceInputStream(dataSource, dataSpec); try { inputStream.open(); - result = parser.parse(dataSource.getUri(), inputStream); + Uri dataSourceUri = Assertions.checkNotNull(dataSource.getUri()); + result = parser.parse(dataSourceUri, inputStream); } finally { bytesLoaded = inputStream.bytesRead(); Util.closeQuietly(inputStream); } } - } diff --git a/library/dash/src/main/java/com/google/android/exoplayer2/source/dash/DashUtil.java b/library/dash/src/main/java/com/google/android/exoplayer2/source/dash/DashUtil.java index 6b481df46d..743462bd89 100644 --- a/library/dash/src/main/java/com/google/android/exoplayer2/source/dash/DashUtil.java +++ b/library/dash/src/main/java/com/google/android/exoplayer2/source/dash/DashUtil.java @@ -54,7 +54,7 @@ public final class DashUtil { */ public static DashManifest loadManifest(DataSource dataSource, Uri uri) throws IOException { - return ParsingLoadable.load(dataSource, new DashManifestParser(), uri); + return ParsingLoadable.load(dataSource, new DashManifestParser(), uri, C.DATA_TYPE_MANIFEST); } /** diff --git a/library/dash/src/main/java/com/google/android/exoplayer2/source/dash/offline/DashDownloadHelper.java b/library/dash/src/main/java/com/google/android/exoplayer2/source/dash/offline/DashDownloadHelper.java index d870d95f57..8f12377de7 100644 --- a/library/dash/src/main/java/com/google/android/exoplayer2/source/dash/offline/DashDownloadHelper.java +++ b/library/dash/src/main/java/com/google/android/exoplayer2/source/dash/offline/DashDownloadHelper.java @@ -17,6 +17,7 @@ package com.google.android.exoplayer2.source.dash.offline; import android.net.Uri; import android.support.annotation.Nullable; +import com.google.android.exoplayer2.C; import com.google.android.exoplayer2.Format; import com.google.android.exoplayer2.offline.DownloadHelper; import com.google.android.exoplayer2.offline.StreamKey; @@ -52,7 +53,8 @@ public final class DashDownloadHelper extends DownloadHelper { @Override protected void prepareInternal() throws IOException { DataSource dataSource = manifestDataSourceFactory.createDataSource(); - manifest = ParsingLoadable.load(dataSource, new DashManifestParser(), uri); + manifest = + ParsingLoadable.load(dataSource, new DashManifestParser(), uri, C.DATA_TYPE_MANIFEST); } /** Returns the DASH manifest. Must not be called until after preparation completes. */ diff --git a/library/hls/src/main/java/com/google/android/exoplayer2/source/hls/offline/HlsDownloadHelper.java b/library/hls/src/main/java/com/google/android/exoplayer2/source/hls/offline/HlsDownloadHelper.java index 245f903103..9b77293a5a 100644 --- a/library/hls/src/main/java/com/google/android/exoplayer2/source/hls/offline/HlsDownloadHelper.java +++ b/library/hls/src/main/java/com/google/android/exoplayer2/source/hls/offline/HlsDownloadHelper.java @@ -17,6 +17,7 @@ package com.google.android.exoplayer2.source.hls.offline; import android.net.Uri; import android.support.annotation.Nullable; +import com.google.android.exoplayer2.C; import com.google.android.exoplayer2.Format; import com.google.android.exoplayer2.offline.DownloadHelper; import com.google.android.exoplayer2.offline.StreamKey; @@ -54,7 +55,7 @@ public final class HlsDownloadHelper extends DownloadHelper { @Override protected void prepareInternal() throws IOException { DataSource dataSource = manifestDataSourceFactory.createDataSource(); - playlist = ParsingLoadable.load(dataSource, new HlsPlaylistParser(), uri); + playlist = ParsingLoadable.load(dataSource, new HlsPlaylistParser(), uri, C.DATA_TYPE_MANIFEST); } /** Returns the HLS playlist. Must not be called until after preparation completes. */ diff --git a/library/hls/src/main/java/com/google/android/exoplayer2/source/hls/offline/HlsDownloader.java b/library/hls/src/main/java/com/google/android/exoplayer2/source/hls/offline/HlsDownloader.java index f18945c0be..85f41df359 100644 --- a/library/hls/src/main/java/com/google/android/exoplayer2/source/hls/offline/HlsDownloader.java +++ b/library/hls/src/main/java/com/google/android/exoplayer2/source/hls/offline/HlsDownloader.java @@ -118,10 +118,7 @@ public final class HlsDownloader extends SegmentDownloader { } private static HlsPlaylist loadManifest(DataSource dataSource, Uri uri) throws IOException { - ParsingLoadable loadable = - new ParsingLoadable<>(dataSource, uri, C.DATA_TYPE_MANIFEST, new HlsPlaylistParser()); - loadable.load(); - return loadable.getResult(); + return ParsingLoadable.load(dataSource, new HlsPlaylistParser(), uri, C.DATA_TYPE_MANIFEST); } private static void addSegment( diff --git a/library/smoothstreaming/src/main/java/com/google/android/exoplayer2/source/smoothstreaming/offline/SsDownloadHelper.java b/library/smoothstreaming/src/main/java/com/google/android/exoplayer2/source/smoothstreaming/offline/SsDownloadHelper.java index 8364014b59..9932ecd955 100644 --- a/library/smoothstreaming/src/main/java/com/google/android/exoplayer2/source/smoothstreaming/offline/SsDownloadHelper.java +++ b/library/smoothstreaming/src/main/java/com/google/android/exoplayer2/source/smoothstreaming/offline/SsDownloadHelper.java @@ -17,6 +17,7 @@ package com.google.android.exoplayer2.source.smoothstreaming.offline; import android.net.Uri; import android.support.annotation.Nullable; +import com.google.android.exoplayer2.C; import com.google.android.exoplayer2.offline.DownloadHelper; import com.google.android.exoplayer2.offline.StreamKey; import com.google.android.exoplayer2.offline.TrackKey; @@ -49,7 +50,7 @@ public final class SsDownloadHelper extends DownloadHelper { @Override protected void prepareInternal() throws IOException { DataSource dataSource = manifestDataSourceFactory.createDataSource(); - manifest = ParsingLoadable.load(dataSource, new SsManifestParser(), uri); + manifest = ParsingLoadable.load(dataSource, new SsManifestParser(), uri, C.DATA_TYPE_MANIFEST); } /** Returns the SmoothStreaming manifest. Must not be called until after preparation completes. */ diff --git a/library/smoothstreaming/src/main/java/com/google/android/exoplayer2/source/smoothstreaming/offline/SsDownloader.java b/library/smoothstreaming/src/main/java/com/google/android/exoplayer2/source/smoothstreaming/offline/SsDownloader.java index 4a0134d39c..84ef251e5f 100644 --- a/library/smoothstreaming/src/main/java/com/google/android/exoplayer2/source/smoothstreaming/offline/SsDownloader.java +++ b/library/smoothstreaming/src/main/java/com/google/android/exoplayer2/source/smoothstreaming/offline/SsDownloader.java @@ -69,10 +69,7 @@ public final class SsDownloader extends SegmentDownloader { @Override protected SsManifest getManifest(DataSource dataSource, Uri uri) throws IOException { - ParsingLoadable loadable = - new ParsingLoadable<>(dataSource, uri, C.DATA_TYPE_MANIFEST, new SsManifestParser()); - loadable.load(); - return loadable.getResult(); + return ParsingLoadable.load(dataSource, new SsManifestParser(), uri, C.DATA_TYPE_MANIFEST); } @Override