Align flags between the core and extension FLAC extractors

- It seems conceptually simpler for DefaultExtractorsFactory
- It seems unlikely we'll need to diverge the two. In the case of
  workaround flags we can just have them be no-ops in the version
  that doesn't need them.

PiperOrigin-RevId: 317151955
This commit is contained in:
olly 2020-06-18 20:04:48 +01:00 committed by Andrew Lewis
parent 816a364a51
commit f8843441a2
4 changed files with 26 additions and 10 deletions

View File

@ -53,6 +53,11 @@ public final class FlacExtractor implements Extractor {
/** Factory that returns one extractor which is a {@link FlacExtractor}. */
public static final ExtractorsFactory FACTORY = () -> new Extractor[] {new FlacExtractor()};
// LINT.IfChange
/*
* Flags in the two FLAC extractors should be kept in sync. If we ever change this then
* DefaultExtractorsFactory will need modifying, because it currently assumes this is the case.
*/
/**
* Flags controlling the behavior of the extractor. Possible flag value is {@link
* #FLAG_DISABLE_ID3_METADATA}.
@ -68,7 +73,9 @@ public final class FlacExtractor implements Extractor {
* Flag to disable parsing of ID3 metadata. Can be set to save memory if ID3 metadata is not
* required.
*/
public static final int FLAG_DISABLE_ID3_METADATA = 1;
public static final int FLAG_DISABLE_ID3_METADATA =
com.google.android.exoplayer2.extractor.flac.FlacExtractor.FLAG_DISABLE_ID3_METADATA;
// LINT.ThenChange(../../../../../../../../../../../library/extractor/src/main/java/com/google/android/exoplayer2/extractor/flac/FlacExtractor.java)
private final ParsableByteArray outputBuffer;
private final boolean id3MetadataDisabled;

View File

@ -3,7 +3,7 @@
# Constructors accessed via reflection in DefaultExtractorsFactory
-dontnote com.google.android.exoplayer2.ext.flac.FlacExtractor
-keepclassmembers class com.google.android.exoplayer2.ext.flac.FlacExtractor {
<init>();
<init>(int);
}
# Don't warn about checkerframework and Kotlin annotations

View File

@ -63,7 +63,8 @@ import java.util.Map;
* <li>AMR ({@link AmrExtractor})
* <li>FLAC
* <ul>
* <li>If available, the FLAC extension extractor is used.
* <li>If available, the FLAC extension's {@code
* com.google.android.exoplayer2.ext.flac.FlacExtractor} is used.
* <li>Otherwise, the core {@link FlacExtractor} is used. Note that Android devices do not
* generally include a FLAC decoder before API 27. This can be worked around by using
* the FLAC extension or the FFmpeg extension.
@ -108,7 +109,7 @@ public final class DefaultExtractorsFactory implements ExtractorsFactory {
flacExtensionExtractorConstructor =
Class.forName("com.google.android.exoplayer2.ext.flac.FlacExtractor")
.asSubclass(Extractor.class)
.getConstructor();
.getConstructor(int.class);
}
// LINT.ThenChange(../../../../../../../../proguard-rules.txt)
} catch (ClassNotFoundException e) {
@ -123,7 +124,7 @@ public final class DefaultExtractorsFactory implements ExtractorsFactory {
private boolean constantBitrateSeekingEnabled;
@AdtsExtractor.Flags private int adtsFlags;
@AmrExtractor.Flags private int amrFlags;
@FlacExtractor.Flags private int coreFlacFlags;
@FlacExtractor.Flags private int flacFlags;
@MatroskaExtractor.Flags private int matroskaFlags;
@Mp4Extractor.Flags private int mp4Flags;
@FragmentedMp4Extractor.Flags private int fragmentedMp4Flags;
@ -178,15 +179,17 @@ public final class DefaultExtractorsFactory implements ExtractorsFactory {
}
/**
* Sets flags for {@link FlacExtractor} instances created by the factory.
* Sets flags for {@link FlacExtractor} instances created by the factory. The flags are also used
* by {@code com.google.android.exoplayer2.ext.flac.FlacExtractor} instances if the FLAC extension
* is being used.
*
* @see FlacExtractor#FlacExtractor(int)
* @param flags The flags to use.
* @return The factory, for convenience.
*/
public synchronized DefaultExtractorsFactory setCoreFlacExtractorFlags(
public synchronized DefaultExtractorsFactory setFlacExtractorFlags(
@FlacExtractor.Flags int flags) {
this.coreFlacFlags = flags;
this.flacFlags = flags;
return this;
}
@ -324,13 +327,13 @@ public final class DefaultExtractorsFactory implements ExtractorsFactory {
case FileTypes.FLAC:
if (FLAC_EXTENSION_EXTRACTOR_CONSTRUCTOR != null) {
try {
extractors.add(FLAC_EXTENSION_EXTRACTOR_CONSTRUCTOR.newInstance());
extractors.add(FLAC_EXTENSION_EXTRACTOR_CONSTRUCTOR.newInstance(flacFlags));
} catch (Exception e) {
// Should never happen.
throw new IllegalStateException("Unexpected error creating FLAC extractor", e);
}
} else {
extractors.add(new FlacExtractor(coreFlacFlags));
extractors.add(new FlacExtractor(flacFlags));
}
break;
case FileTypes.FLV:

View File

@ -52,6 +52,11 @@ public final class FlacExtractor implements Extractor {
/** Factory for {@link FlacExtractor} instances. */
public static final ExtractorsFactory FACTORY = () -> new Extractor[] {new FlacExtractor()};
// LINT.IfChange
/*
* Flags in the two FLAC extractors should be kept in sync. If we ever change this then
* DefaultExtractorsFactory will need modifying, because it currently assumes this is the case.
*/
/**
* Flags controlling the behavior of the extractor. Possible flag value is {@link
* #FLAG_DISABLE_ID3_METADATA}.
@ -68,6 +73,7 @@ public final class FlacExtractor implements Extractor {
* required.
*/
public static final int FLAG_DISABLE_ID3_METADATA = 1;
// LINT.ThenChange(../../../../../../../../../../../extensions/flac/src/main/java/com/google/android/exoplayer2/ext/flac/FlacExtractor.java)
/** Parser state. */
@Documented