mirror of
https://github.com/samsonjs/media.git
synced 2026-03-28 09:55:48 +00:00
Consolidate UnrecognizedInputFormatException
------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=145570097
This commit is contained in:
parent
6f5c7b38a7
commit
63e6bf5cf2
4 changed files with 50 additions and 35 deletions
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -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<HlsPlaylist> {
|
||||
|
||||
/**
|
||||
* 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<HlsPlayli
|
|||
String line;
|
||||
try {
|
||||
if (!checkPlaylistHeader(reader)) {
|
||||
throw new UnrecognizedInputFormatException(uri);
|
||||
throw new UnrecognizedInputFormatException("Input does not start with the #EXTM3U header.",
|
||||
uri);
|
||||
}
|
||||
while ((line = reader.readLine()) != null) {
|
||||
line = line.trim();
|
||||
|
|
|
|||
Loading…
Reference in a new issue