Commit 85adecf9 by olly Committed by Oliver Woodman

Remove reflection + make it easy to set extractor flags

The idea of using reflection was so that a developer could
delete a package they didn't want and have everything else
still compile. However, a developer doing this is likely
building from source, in which case editing the factories
too is pretty trivial.

Removing the reflection makes specifying extractor flags
via the default factory easy, and removes the need for
special proguard config.

Issue: #2657

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=152810423
parent 1dc8bb5b
...@@ -20,7 +20,6 @@ android { ...@@ -20,7 +20,6 @@ android {
defaultConfig { defaultConfig {
minSdkVersion project.ext.minSdkVersion minSdkVersion project.ext.minSdkVersion
targetSdkVersion project.ext.targetSdkVersion targetSdkVersion project.ext.targetSdkVersion
consumerProguardFiles 'proguard-rules.txt'
} }
sourceSets { sourceSets {
......
# Accessed via reflection in SubtitleDecoderFactory.DEFAULT
-keepclassmembers class com.google.android.exoplayer2.text.cea.Cea608Decoder {
public <init>(java.lang.String, int);
}
-keepclassmembers class com.google.android.exoplayer2.text.cea.Cea708Decoder {
public <init>(int);
}
-keepclassmembers class com.google.android.exoplayer2.text.dvb.DvbDecoder {
public <init>(java.util.List);
}
...@@ -39,8 +39,7 @@ public final class DefaultTsPayloadReaderFactory implements TsPayloadReader.Fact ...@@ -39,8 +39,7 @@ public final class DefaultTsPayloadReaderFactory implements TsPayloadReader.Fact
@IntDef(flag = true, value = {FLAG_ALLOW_NON_IDR_KEYFRAMES, FLAG_IGNORE_AAC_STREAM, @IntDef(flag = true, value = {FLAG_ALLOW_NON_IDR_KEYFRAMES, FLAG_IGNORE_AAC_STREAM,
FLAG_IGNORE_H264_STREAM, FLAG_DETECT_ACCESS_UNITS, FLAG_IGNORE_SPLICE_INFO_STREAM, FLAG_IGNORE_H264_STREAM, FLAG_DETECT_ACCESS_UNITS, FLAG_IGNORE_SPLICE_INFO_STREAM,
FLAG_OVERRIDE_CAPTION_DESCRIPTORS}) FLAG_OVERRIDE_CAPTION_DESCRIPTORS})
public @interface Flags { public @interface Flags {}
}
public static final int FLAG_ALLOW_NON_IDR_KEYFRAMES = 1; public static final int FLAG_ALLOW_NON_IDR_KEYFRAMES = 1;
public static final int FLAG_IGNORE_AAC_STREAM = 1 << 1; public static final int FLAG_IGNORE_AAC_STREAM = 1 << 1;
public static final int FLAG_IGNORE_H264_STREAM = 1 << 2; public static final int FLAG_IGNORE_H264_STREAM = 1 << 2;
...@@ -54,11 +53,19 @@ public final class DefaultTsPayloadReaderFactory implements TsPayloadReader.Fact ...@@ -54,11 +53,19 @@ public final class DefaultTsPayloadReaderFactory implements TsPayloadReader.Fact
private final List<Format> closedCaptionFormats; private final List<Format> closedCaptionFormats;
public DefaultTsPayloadReaderFactory() { public DefaultTsPayloadReaderFactory() {
this(0, Collections.<Format>emptyList()); this(0);
}
/**
* @param flags A combination of {@code FLAG_*} values that control the behavior of the created
* readers.
*/
public DefaultTsPayloadReaderFactory(@Flags int flags) {
this(flags, Collections.<Format>emptyList());
} }
/** /**
* @param flags A combination of {@code FLAG_*} values, which control the behavior of the created * @param flags A combination of {@code FLAG_*} values that control the behavior of the created
* readers. * readers.
* @param closedCaptionFormats {@link Format}s to be exposed by payload readers for streams with * @param closedCaptionFormats {@link Format}s to be exposed by payload readers for streams with
* embedded closed captions when no caption service descriptors are provided. If * embedded closed captions when no caption service descriptors are provided. If
......
...@@ -27,6 +27,7 @@ import com.google.android.exoplayer2.extractor.ExtractorsFactory; ...@@ -27,6 +27,7 @@ import com.google.android.exoplayer2.extractor.ExtractorsFactory;
import com.google.android.exoplayer2.extractor.PositionHolder; import com.google.android.exoplayer2.extractor.PositionHolder;
import com.google.android.exoplayer2.extractor.SeekMap; import com.google.android.exoplayer2.extractor.SeekMap;
import com.google.android.exoplayer2.extractor.TrackOutput; import com.google.android.exoplayer2.extractor.TrackOutput;
import com.google.android.exoplayer2.extractor.ts.DefaultTsPayloadReaderFactory.Flags;
import com.google.android.exoplayer2.extractor.ts.TsPayloadReader.EsInfo; import com.google.android.exoplayer2.extractor.ts.TsPayloadReader.EsInfo;
import com.google.android.exoplayer2.extractor.ts.TsPayloadReader.TrackIdGenerator; import com.google.android.exoplayer2.extractor.ts.TsPayloadReader.TrackIdGenerator;
import com.google.android.exoplayer2.util.Assertions; import com.google.android.exoplayer2.util.Assertions;
...@@ -122,7 +123,16 @@ public final class TsExtractor implements Extractor { ...@@ -122,7 +123,16 @@ public final class TsExtractor implements Extractor {
private TsPayloadReader id3Reader; private TsPayloadReader id3Reader;
public TsExtractor() { public TsExtractor() {
this(MODE_NORMAL, new TimestampAdjuster(0), new DefaultTsPayloadReaderFactory()); this(0);
}
/**
* @param defaultTsPayloadReaderFlags A combination of {@link DefaultTsPayloadReaderFactory}
* {@code FLAG_*} values that control the behavior of the payload readers.
*/
public TsExtractor(@Flags int defaultTsPayloadReaderFlags) {
this(MODE_NORMAL, new TimestampAdjuster(0),
new DefaultTsPayloadReaderFactory(defaultTsPayloadReaderFlags));
} }
/** /**
......
...@@ -58,39 +58,23 @@ public interface MetadataDecoderFactory { ...@@ -58,39 +58,23 @@ public interface MetadataDecoderFactory {
@Override @Override
public boolean supportsFormat(Format format) { public boolean supportsFormat(Format format) {
return getDecoderClass(format.sampleMimeType) != null; String mimeType = format.sampleMimeType;
return MimeTypes.APPLICATION_ID3.equals(mimeType)
|| MimeTypes.APPLICATION_EMSG.equals(mimeType)
|| MimeTypes.APPLICATION_SCTE35.equals(mimeType);
} }
@Override @Override
public MetadataDecoder createDecoder(Format format) { public MetadataDecoder createDecoder(Format format) {
try { switch (format.sampleMimeType) {
Class<?> clazz = getDecoderClass(format.sampleMimeType); case MimeTypes.APPLICATION_ID3:
if (clazz == null) { return new Id3Decoder();
case MimeTypes.APPLICATION_EMSG:
return new EventMessageDecoder();
case MimeTypes.APPLICATION_SCTE35:
return new SpliceInfoDecoder();
default:
throw new IllegalArgumentException("Attempted to create decoder for unsupported format"); throw new IllegalArgumentException("Attempted to create decoder for unsupported format");
}
return clazz.asSubclass(MetadataDecoder.class).getConstructor().newInstance();
} catch (Exception e) {
throw new IllegalStateException("Unexpected error instantiating decoder", e);
}
}
private Class<?> getDecoderClass(String mimeType) {
if (mimeType == null) {
return null;
}
try {
switch (mimeType) {
case MimeTypes.APPLICATION_ID3:
return Class.forName("com.google.android.exoplayer2.metadata.id3.Id3Decoder");
case MimeTypes.APPLICATION_EMSG:
return Class.forName("com.google.android.exoplayer2.metadata.emsg.EventMessageDecoder");
case MimeTypes.APPLICATION_SCTE35:
return Class.forName("com.google.android.exoplayer2.metadata.scte35.SpliceInfoDecoder");
default:
return null;
}
} catch (ClassNotFoundException e) {
return null;
} }
} }
......
...@@ -18,13 +18,13 @@ package com.google.android.exoplayer2.text; ...@@ -18,13 +18,13 @@ package com.google.android.exoplayer2.text;
import com.google.android.exoplayer2.Format; import com.google.android.exoplayer2.Format;
import com.google.android.exoplayer2.text.cea.Cea608Decoder; import com.google.android.exoplayer2.text.cea.Cea608Decoder;
import com.google.android.exoplayer2.text.cea.Cea708Decoder; import com.google.android.exoplayer2.text.cea.Cea708Decoder;
import com.google.android.exoplayer2.text.dvb.DvbDecoder;
import com.google.android.exoplayer2.text.subrip.SubripDecoder; import com.google.android.exoplayer2.text.subrip.SubripDecoder;
import com.google.android.exoplayer2.text.ttml.TtmlDecoder; import com.google.android.exoplayer2.text.ttml.TtmlDecoder;
import com.google.android.exoplayer2.text.tx3g.Tx3gDecoder; import com.google.android.exoplayer2.text.tx3g.Tx3gDecoder;
import com.google.android.exoplayer2.text.webvtt.Mp4WebvttDecoder; import com.google.android.exoplayer2.text.webvtt.Mp4WebvttDecoder;
import com.google.android.exoplayer2.text.webvtt.WebvttDecoder; import com.google.android.exoplayer2.text.webvtt.WebvttDecoder;
import com.google.android.exoplayer2.util.MimeTypes; import com.google.android.exoplayer2.util.MimeTypes;
import java.util.List;
/** /**
* A factory for {@link SubtitleDecoder} instances. * A factory for {@link SubtitleDecoder} instances.
...@@ -61,68 +61,47 @@ public interface SubtitleDecoderFactory { ...@@ -61,68 +61,47 @@ public interface SubtitleDecoderFactory {
* <li>TX3G ({@link Tx3gDecoder})</li> * <li>TX3G ({@link Tx3gDecoder})</li>
* <li>Cea608 ({@link Cea608Decoder})</li> * <li>Cea608 ({@link Cea608Decoder})</li>
* <li>Cea708 ({@link Cea708Decoder})</li> * <li>Cea708 ({@link Cea708Decoder})</li>
* <li>DVB ({@link DvbDecoder})</li>
* </ul> * </ul>
*/ */
SubtitleDecoderFactory DEFAULT = new SubtitleDecoderFactory() { SubtitleDecoderFactory DEFAULT = new SubtitleDecoderFactory() {
@Override @Override
public boolean supportsFormat(Format format) { public boolean supportsFormat(Format format) {
return getDecoderClass(format.sampleMimeType) != null; String mimeType = format.sampleMimeType;
return MimeTypes.TEXT_VTT.equals(mimeType)
|| MimeTypes.APPLICATION_TTML.equals(mimeType)
|| MimeTypes.APPLICATION_MP4VTT.equals(mimeType)
|| MimeTypes.APPLICATION_SUBRIP.equals(mimeType)
|| MimeTypes.APPLICATION_TX3G.equals(mimeType)
|| MimeTypes.APPLICATION_CEA608.equals(mimeType)
|| MimeTypes.APPLICATION_MP4CEA608.equals(mimeType)
|| MimeTypes.APPLICATION_CEA708.equals(mimeType)
|| MimeTypes.APPLICATION_DVBSUBS.equals(mimeType);
} }
@Override @Override
public SubtitleDecoder createDecoder(Format format) { public SubtitleDecoder createDecoder(Format format) {
try { switch (format.sampleMimeType) {
Class<?> clazz = getDecoderClass(format.sampleMimeType); case MimeTypes.TEXT_VTT:
if (clazz == null) { return new WebvttDecoder();
case MimeTypes.APPLICATION_MP4VTT:
return new Mp4WebvttDecoder();
case MimeTypes.APPLICATION_TTML:
return new TtmlDecoder();
case MimeTypes.APPLICATION_SUBRIP:
return new SubripDecoder();
case MimeTypes.APPLICATION_TX3G:
return new Tx3gDecoder();
case MimeTypes.APPLICATION_CEA608:
case MimeTypes.APPLICATION_MP4CEA608:
return new Cea608Decoder(format.sampleMimeType, format.accessibilityChannel);
case MimeTypes.APPLICATION_CEA708:
return new Cea708Decoder(format.accessibilityChannel);
case MimeTypes.APPLICATION_DVBSUBS:
return new DvbDecoder(format.initializationData);
default:
throw new IllegalArgumentException("Attempted to create decoder for unsupported format"); throw new IllegalArgumentException("Attempted to create decoder for unsupported format");
}
if (format.sampleMimeType.equals(MimeTypes.APPLICATION_CEA608)
|| format.sampleMimeType.equals(MimeTypes.APPLICATION_MP4CEA608)) {
return clazz.asSubclass(SubtitleDecoder.class).getConstructor(String.class, Integer.TYPE)
.newInstance(format.sampleMimeType, format.accessibilityChannel);
} else if (format.sampleMimeType.equals(MimeTypes.APPLICATION_CEA708)) {
return clazz.asSubclass(SubtitleDecoder.class).getConstructor(Integer.TYPE)
.newInstance(format.accessibilityChannel);
} else if (format.sampleMimeType.equals(MimeTypes.APPLICATION_DVBSUBS)) {
return clazz.asSubclass(SubtitleDecoder.class).getConstructor(List.class)
.newInstance(format.initializationData);
} else {
return clazz.asSubclass(SubtitleDecoder.class).getConstructor().newInstance();
}
} catch (Exception e) {
throw new IllegalStateException("Unexpected error instantiating decoder", e);
}
}
private Class<?> getDecoderClass(String mimeType) {
if (mimeType == null) {
return null;
}
try {
switch (mimeType) {
case MimeTypes.TEXT_VTT:
return Class.forName("com.google.android.exoplayer2.text.webvtt.WebvttDecoder");
case MimeTypes.APPLICATION_TTML:
return Class.forName("com.google.android.exoplayer2.text.ttml.TtmlDecoder");
case MimeTypes.APPLICATION_MP4VTT:
return Class.forName("com.google.android.exoplayer2.text.webvtt.Mp4WebvttDecoder");
case MimeTypes.APPLICATION_SUBRIP:
return Class.forName("com.google.android.exoplayer2.text.subrip.SubripDecoder");
case MimeTypes.APPLICATION_TX3G:
return Class.forName("com.google.android.exoplayer2.text.tx3g.Tx3gDecoder");
case MimeTypes.APPLICATION_CEA608:
case MimeTypes.APPLICATION_MP4CEA608:
return Class.forName("com.google.android.exoplayer2.text.cea.Cea608Decoder");
case MimeTypes.APPLICATION_CEA708:
return Class.forName("com.google.android.exoplayer2.text.cea.Cea708Decoder");
case MimeTypes.APPLICATION_DVBSUBS:
return Class.forName("com.google.android.exoplayer2.text.dvb.DvbDecoder");
default:
return null;
}
} catch (ClassNotFoundException e) {
return null;
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment