From 63e6bf5cf2d2be41eff2725ce241f9f523beaee6 Mon Sep 17 00:00:00 2001 From: olly Date: Wed, 25 Jan 2017 11:06:56 -0800 Subject: [PATCH] Consolidate UnrecognizedInputFormatException ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=145570097 --- .../source/ExtractorMediaPeriod.java | 13 +++--- .../source/ExtractorMediaSource.java | 14 ------- .../UnrecognizedInputFormatException.java | 40 +++++++++++++++++++ .../hls/playlist/HlsPlaylistParser.java | 18 ++------- 4 files changed, 50 insertions(+), 35 deletions(-) create mode 100644 library/src/main/java/com/google/android/exoplayer2/source/UnrecognizedInputFormatException.java 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 bc0a3f1cf8..5226043593 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 @@ -519,7 +519,7 @@ import java.io.IOException; } private boolean isLoadableExceptionFatal(IOException e) { - return e instanceof ExtractorMediaSource.UnrecognizedInputFormatException; + return e instanceof UnrecognizedInputFormatException; } private void notifyLoadError(final IOException error) { @@ -625,7 +625,7 @@ import java.io.IOException; length += position; } input = new DefaultExtractorInput(dataSource, position, length); - Extractor extractor = extractorHolder.selectExtractor(input); + Extractor extractor = extractorHolder.selectExtractor(input, dataSource.getUri()); if (pendingExtractorSeek) { extractor.seek(position, seekTimeUs); pendingExtractorSeek = false; @@ -677,13 +677,13 @@ import java.io.IOException; * later calls. * * @param input The {@link ExtractorInput} from which data should be read. + * @param uri The {@link Uri} of the data. * @return An initialized extractor for reading {@code input}. - * @throws ExtractorMediaSource.UnrecognizedInputFormatException Thrown if the input format - * could not be detected. + * @throws UnrecognizedInputFormatException Thrown if the input format could not be detected. * @throws IOException Thrown if the input could not be read. * @throws InterruptedException Thrown if the thread was interrupted. */ - public Extractor selectExtractor(ExtractorInput input) + public Extractor selectExtractor(ExtractorInput input, Uri uri) throws IOException, InterruptedException { if (extractor != null) { return extractor; @@ -701,7 +701,8 @@ import java.io.IOException; } } if (extractor == null) { - throw new ExtractorMediaSource.UnrecognizedInputFormatException(extractors); + throw new UnrecognizedInputFormatException("None of the available extractors (" + + Util.getCommaDelimitedSimpleClassNames(extractors) + ") could read the stream.", uri); } extractor.init(extractorOutput); return extractor; 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 7b571bc289..c560616aae 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 @@ -19,7 +19,6 @@ import android.net.Uri; import android.os.Handler; import com.google.android.exoplayer2.C; import com.google.android.exoplayer2.ExoPlayer; -import com.google.android.exoplayer2.ParserException; import com.google.android.exoplayer2.Timeline; import com.google.android.exoplayer2.extractor.DefaultExtractorsFactory; import com.google.android.exoplayer2.extractor.Extractor; @@ -27,7 +26,6 @@ import com.google.android.exoplayer2.extractor.ExtractorsFactory; import com.google.android.exoplayer2.upstream.Allocator; import com.google.android.exoplayer2.upstream.DataSource; import com.google.android.exoplayer2.util.Assertions; -import com.google.android.exoplayer2.util.Util; import java.io.IOException; /** @@ -57,18 +55,6 @@ public final class ExtractorMediaSource implements MediaSource, MediaSource.List } - /** - * Thrown if the input format could not recognized. - */ - public static final class UnrecognizedInputFormatException extends ParserException { - - public UnrecognizedInputFormatException(Extractor[] extractors) { - super("None of the available extractors (" - + Util.getCommaDelimitedSimpleClassNames(extractors) + ") could read the stream."); - } - - } - /** * The default minimum number of times to retry loading prior to failing for on-demand streams. */ diff --git a/library/src/main/java/com/google/android/exoplayer2/source/UnrecognizedInputFormatException.java b/library/src/main/java/com/google/android/exoplayer2/source/UnrecognizedInputFormatException.java new file mode 100644 index 0000000000..508bf0e365 --- /dev/null +++ b/library/src/main/java/com/google/android/exoplayer2/source/UnrecognizedInputFormatException.java @@ -0,0 +1,40 @@ +/* + * Copyright (C) 2017 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.google.android.exoplayer2.source; + +import android.net.Uri; +import com.google.android.exoplayer2.ParserException; + +/** + * Thrown if the input format was not recognized. + */ +public class UnrecognizedInputFormatException extends ParserException { + + /** + * The {@link Uri} from which the unrecognized data was read. + */ + public final Uri uri; + + /** + * @param message The detail message for the exception. + * @param uri The {@link Uri} from which the unrecognized data was read. + */ + public UnrecognizedInputFormatException(String message, Uri uri) { + super(message); + this.uri = uri; + } + +} diff --git a/library/src/main/java/com/google/android/exoplayer2/source/hls/playlist/HlsPlaylistParser.java b/library/src/main/java/com/google/android/exoplayer2/source/hls/playlist/HlsPlaylistParser.java index c349bbee05..0cd861c369 100644 --- a/library/src/main/java/com/google/android/exoplayer2/source/hls/playlist/HlsPlaylistParser.java +++ b/library/src/main/java/com/google/android/exoplayer2/source/hls/playlist/HlsPlaylistParser.java @@ -19,6 +19,7 @@ import android.net.Uri; import com.google.android.exoplayer2.C; import com.google.android.exoplayer2.Format; import com.google.android.exoplayer2.ParserException; +import com.google.android.exoplayer2.source.UnrecognizedInputFormatException; import com.google.android.exoplayer2.source.hls.playlist.HlsMediaPlaylist.Segment; import com.google.android.exoplayer2.upstream.ParsingLoadable; import com.google.android.exoplayer2.util.MimeTypes; @@ -39,20 +40,6 @@ import java.util.regex.Pattern; */ public final class HlsPlaylistParser implements ParsingLoadable.Parser { - /** - * Thrown if the input does not start with an HLS playlist header. - */ - public static final class UnrecognizedInputFormatException extends ParserException { - - public final Uri inputUri; - - public UnrecognizedInputFormatException(Uri inputUri) { - super("Input does not start with the #EXTM3U header. Uri: " + inputUri); - this.inputUri = inputUri; - } - - } - private static final String PLAYLIST_HEADER = "#EXTM3U"; private static final String TAG_VERSION = "#EXT-X-VERSION"; @@ -116,7 +103,8 @@ public final class HlsPlaylistParser implements ParsingLoadable.Parser