Add special value for unknown current parser name
Bug: 150855259
Test: atest CtsMediaParserTestCases
Change-Id: I9328104875e3daeeb1a9f0ac3e47ca5df8acea14
diff --git a/apex/media/framework/api/current.txt b/apex/media/framework/api/current.txt
index 839fb51..9cec748 100644
--- a/apex/media/framework/api/current.txt
+++ b/apex/media/framework/api/current.txt
@@ -29,7 +29,7 @@
method public boolean advance(@NonNull android.media.MediaParser.SeekableInputReader) throws java.io.IOException;
method @NonNull public static android.media.MediaParser create(@NonNull android.media.MediaParser.OutputConsumer, @NonNull java.lang.String...);
method @NonNull public static android.media.MediaParser createByName(@NonNull String, @NonNull android.media.MediaParser.OutputConsumer);
- method @Nullable public String getParserName();
+ method @NonNull public String getParserName();
method @NonNull public static java.util.List<java.lang.String> getParserNames(@NonNull android.media.MediaFormat);
method public void release();
method public void seek(@NonNull android.media.MediaParser.SeekPoint);
@@ -65,6 +65,7 @@
field public static final String PARSER_NAME_OGG = "android.media.mediaparser.OggParser";
field public static final String PARSER_NAME_PS = "android.media.mediaparser.PsParser";
field public static final String PARSER_NAME_TS = "android.media.mediaparser.TsParser";
+ field public static final String PARSER_NAME_UNKNOWN = "android.media.mediaparser.UNKNOWN";
field public static final String PARSER_NAME_WAV = "android.media.mediaparser.WavParser";
}
diff --git a/apex/media/framework/java/android/media/MediaParser.java b/apex/media/framework/java/android/media/MediaParser.java
index 5f86ed6..c0e3d55 100644
--- a/apex/media/framework/java/android/media/MediaParser.java
+++ b/apex/media/framework/java/android/media/MediaParser.java
@@ -452,6 +452,7 @@
@StringDef(
prefix = {"PARSER_NAME_"},
value = {
+ PARSER_NAME_UNKNOWN,
PARSER_NAME_MATROSKA,
PARSER_NAME_FMP4,
PARSER_NAME_MP4,
@@ -469,6 +470,7 @@
})
public @interface ParserName {}
+ public static final String PARSER_NAME_UNKNOWN = "android.media.mediaparser.UNKNOWN";
public static final String PARSER_NAME_MATROSKA = "android.media.mediaparser.MatroskaParser";
public static final String PARSER_NAME_FMP4 = "android.media.mediaparser.FragmentedMp4Parser";
public static final String PARSER_NAME_MP4 = "android.media.mediaparser.Mp4Parser";
@@ -836,14 +838,14 @@
* Returns the name of the backing parser implementation.
*
* <p>If this instance was creating using {@link #createByName}, the provided name is returned.
- * If this instance was created using {@link #create}, this method will return null until the
- * first call to {@link #advance}, after which the name of the backing parser implementation is
- * returned.
+ * If this instance was created using {@link #create}, this method will return {@link
+ * #PARSER_NAME_UNKNOWN} until the first call to {@link #advance}, after which the name of the
+ * backing parser implementation is returned.
*
* @return The name of the backing parser implementation, or null if the backing parser
* implementation has not yet been selected.
*/
- @Nullable
+ @NonNull
@ParserName
public String getParserName() {
return mExtractorName;
@@ -880,7 +882,7 @@
// TODO: Apply parameters when creating extractor instances.
if (mExtractor == null) {
- if (mExtractorName != null) {
+ if (!mExtractorName.equals(PARSER_NAME_UNKNOWN)) {
mExtractor = EXTRACTOR_FACTORIES_BY_NAME.get(mExtractorName).createInstance();
mExtractor.init(new ExtractorOutputAdapter());
} else {
@@ -974,9 +976,7 @@
mParserParameters = new HashMap<>();
mOutputConsumer = outputConsumer;
mParserNamesPool = parserNamesPool;
- if (!sniff) {
- mExtractorName = parserNamesPool[0];
- }
+ mExtractorName = sniff ? PARSER_NAME_UNKNOWN : parserNamesPool[0];
mPositionHolder = new PositionHolder();
mDataSource = new InputReadingDataSource();
removePendingSeek();
diff --git a/api/current.txt b/api/current.txt
index ff74ce8..d33b8bd 100644
--- a/api/current.txt
+++ b/api/current.txt
@@ -26401,7 +26401,7 @@
method public boolean advance(@NonNull android.media.MediaParser.SeekableInputReader) throws java.io.IOException;
method @NonNull public static android.media.MediaParser create(@NonNull android.media.MediaParser.OutputConsumer, @NonNull java.lang.String...);
method @NonNull public static android.media.MediaParser createByName(@NonNull String, @NonNull android.media.MediaParser.OutputConsumer);
- method @Nullable public String getParserName();
+ method @NonNull public String getParserName();
method @NonNull public static java.util.List<java.lang.String> getParserNames(@NonNull android.media.MediaFormat);
method public void release();
method public void seek(@NonNull android.media.MediaParser.SeekPoint);
@@ -26437,6 +26437,7 @@
field public static final String PARSER_NAME_OGG = "android.media.mediaparser.OggParser";
field public static final String PARSER_NAME_PS = "android.media.mediaparser.PsParser";
field public static final String PARSER_NAME_TS = "android.media.mediaparser.TsParser";
+ field public static final String PARSER_NAME_UNKNOWN = "android.media.mediaparser.UNKNOWN";
field public static final String PARSER_NAME_WAV = "android.media.mediaparser.WavParser";
}