diff --git a/library/core/src/main/java/com/google/android/exoplayer2/extractor/ts/DefaultTsPayloadReaderFactory.java b/library/core/src/main/java/com/google/android/exoplayer2/extractor/ts/DefaultTsPayloadReaderFactory.java index 94fd7ceb13..a5506e2cfb 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/extractor/ts/DefaultTsPayloadReaderFactory.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/extractor/ts/DefaultTsPayloadReaderFactory.java @@ -54,11 +54,37 @@ public final class DefaultTsPayloadReaderFactory implements TsPayloadReader.Fact }) public @interface Flags {} + /** + * When extracting H.264 samples, whether to treat samples consisting of non-IDR I slices as + * synchronization samples (key-frames). + */ public static final int FLAG_ALLOW_NON_IDR_KEYFRAMES = 1; + /** + * Prevents the creation of {@link AdtsReader} and {@link LatmReader} instances. This flag should + * be enabled if the transport stream contains no packets for an AAC elementary stream that is + * declared in the PMT. + */ public static final int FLAG_IGNORE_AAC_STREAM = 1 << 1; + /** + * Prevents the creation of {@link H264Reader} instances. This flag should be enabled if the + * transport stream contains no packets for an H.264 elementary stream that is declared in the + * PMT. + */ public static final int FLAG_IGNORE_H264_STREAM = 1 << 2; + /** + * When extracting H.264 samples, whether to split the input stream into access units (samples) + * based on slice headers. This flag should be disabled if the stream contains access unit + * delimiters (AUDs). + */ public static final int FLAG_DETECT_ACCESS_UNITS = 1 << 3; + /** Prevents the creation of {@link SpliceInfoSectionReader} instances. */ public static final int FLAG_IGNORE_SPLICE_INFO_STREAM = 1 << 4; + /** + * Whether the list of {@code closedCaptionFormats} passed to {@link + * DefaultTsPayloadReaderFactory#DefaultTsPayloadReaderFactory(int, List)} should be used in spite + * of any closed captions service descriptors. If this flag is disabled, {@code + * closedCaptionFormats} will be ignored if the PMT contains closed captions service descriptors. + */ public static final int FLAG_OVERRIDE_CAPTION_DESCRIPTORS = 1 << 5; private static final int DESCRIPTOR_TAG_CAPTION_SERVICE = 0x86; diff --git a/library/hls/src/main/java/com/google/android/exoplayer2/source/hls/DefaultHlsExtractorFactory.java b/library/hls/src/main/java/com/google/android/exoplayer2/source/hls/DefaultHlsExtractorFactory.java index 951e6c95e0..3d75923553 100644 --- a/library/hls/src/main/java/com/google/android/exoplayer2/source/hls/DefaultHlsExtractorFactory.java +++ b/library/hls/src/main/java/com/google/android/exoplayer2/source/hls/DefaultHlsExtractorFactory.java @@ -51,6 +51,24 @@ public final class DefaultHlsExtractorFactory implements HlsExtractorFactory { public static final String VTT_FILE_EXTENSION = ".vtt"; public static final String WEBVTT_FILE_EXTENSION = ".webvtt"; + @DefaultTsPayloadReaderFactory.Flags private final int payloadReaderFactoryFlags; + + /** Creates a factory for HLS segment extractors. */ + public DefaultHlsExtractorFactory() { + this(/* payloadReaderFactoryFlags= */ 0); + } + + /** + * Creates a factory for HLS segment extractors. + * + * @param payloadReaderFactoryFlags Flags to add when constructing any {@link + * DefaultTsPayloadReaderFactory} instances. Other flags may be added on top of {@code + * payloadReaderFactoryFlags} when creating {@link DefaultTsPayloadReaderFactory}. + */ + public DefaultHlsExtractorFactory(int payloadReaderFactoryFlags) { + this.payloadReaderFactoryFlags = payloadReaderFactoryFlags; + } + @Override public Pair createExtractor( Extractor previousExtractor, @@ -138,7 +156,9 @@ public final class DefaultHlsExtractorFactory implements HlsExtractorFactory { } if (!(extractorByFileExtension instanceof TsExtractor)) { - TsExtractor tsExtractor = createTsExtractor(format, muxedCaptionFormats, timestampAdjuster); + TsExtractor tsExtractor = + createTsExtractor( + payloadReaderFactoryFlags, format, muxedCaptionFormats, timestampAdjuster); if (sniffQuietly(tsExtractor, extractorInput)) { return buildResult(tsExtractor); } @@ -180,17 +200,23 @@ public final class DefaultHlsExtractorFactory implements HlsExtractorFactory { muxedCaptionFormats != null ? muxedCaptionFormats : Collections.emptyList()); } else { // For any other file extension, we assume TS format. - return createTsExtractor(format, muxedCaptionFormats, timestampAdjuster); + return createTsExtractor( + payloadReaderFactoryFlags, format, muxedCaptionFormats, timestampAdjuster); } } private static TsExtractor createTsExtractor( - Format format, List muxedCaptionFormats, TimestampAdjuster timestampAdjuster) { + @DefaultTsPayloadReaderFactory.Flags int userProvidedPayloadReaderFactoryFlags, + Format format, + List muxedCaptionFormats, + TimestampAdjuster timestampAdjuster) { @DefaultTsPayloadReaderFactory.Flags - int esReaderFactoryFlags = DefaultTsPayloadReaderFactory.FLAG_IGNORE_SPLICE_INFO_STREAM; + int payloadReaderFactoryFlags = + DefaultTsPayloadReaderFactory.FLAG_IGNORE_SPLICE_INFO_STREAM + | userProvidedPayloadReaderFactoryFlags; if (muxedCaptionFormats != null) { // The playlist declares closed caption renditions, we should ignore descriptors. - esReaderFactoryFlags |= DefaultTsPayloadReaderFactory.FLAG_OVERRIDE_CAPTION_DESCRIPTORS; + payloadReaderFactoryFlags |= DefaultTsPayloadReaderFactory.FLAG_OVERRIDE_CAPTION_DESCRIPTORS; } else { // The playlist does not provide any closed caption information. We preemptively declare a // closed caption track on channel 0. @@ -208,17 +234,17 @@ public final class DefaultHlsExtractorFactory implements HlsExtractorFactory { // exist. If we know from the codec attribute that they don't exist, then we can // explicitly ignore them even if they're declared. if (!MimeTypes.AUDIO_AAC.equals(MimeTypes.getAudioMediaMimeType(codecs))) { - esReaderFactoryFlags |= DefaultTsPayloadReaderFactory.FLAG_IGNORE_AAC_STREAM; + payloadReaderFactoryFlags |= DefaultTsPayloadReaderFactory.FLAG_IGNORE_AAC_STREAM; } if (!MimeTypes.VIDEO_H264.equals(MimeTypes.getVideoMediaMimeType(codecs))) { - esReaderFactoryFlags |= DefaultTsPayloadReaderFactory.FLAG_IGNORE_H264_STREAM; + payloadReaderFactoryFlags |= DefaultTsPayloadReaderFactory.FLAG_IGNORE_H264_STREAM; } } return new TsExtractor( TsExtractor.MODE_HLS, timestampAdjuster, - new DefaultTsPayloadReaderFactory(esReaderFactoryFlags, muxedCaptionFormats)); + new DefaultTsPayloadReaderFactory(payloadReaderFactoryFlags, muxedCaptionFormats)); } private static Pair buildResult(Extractor extractor) {