Add constructor for adding payload reader factory flags

Issue:#4861

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=214772527
This commit is contained in:
aquilescanta 2018-09-27 07:37:39 -07:00 committed by Oliver Woodman
parent f9a805070a
commit 10511e56cf
2 changed files with 60 additions and 8 deletions

View File

@ -54,11 +54,37 @@ public final class DefaultTsPayloadReaderFactory implements TsPayloadReader.Fact
}) })
public @interface Flags {} 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; 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; 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; 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; 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; 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; public static final int FLAG_OVERRIDE_CAPTION_DESCRIPTORS = 1 << 5;
private static final int DESCRIPTOR_TAG_CAPTION_SERVICE = 0x86; private static final int DESCRIPTOR_TAG_CAPTION_SERVICE = 0x86;

View File

@ -51,6 +51,24 @@ public final class DefaultHlsExtractorFactory implements HlsExtractorFactory {
public static final String VTT_FILE_EXTENSION = ".vtt"; public static final String VTT_FILE_EXTENSION = ".vtt";
public static final String WEBVTT_FILE_EXTENSION = ".webvtt"; 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 @Override
public Pair<Extractor, Boolean> createExtractor( public Pair<Extractor, Boolean> createExtractor(
Extractor previousExtractor, Extractor previousExtractor,
@ -138,7 +156,9 @@ public final class DefaultHlsExtractorFactory implements HlsExtractorFactory {
} }
if (!(extractorByFileExtension instanceof TsExtractor)) { if (!(extractorByFileExtension instanceof TsExtractor)) {
TsExtractor tsExtractor = createTsExtractor(format, muxedCaptionFormats, timestampAdjuster); TsExtractor tsExtractor =
createTsExtractor(
payloadReaderFactoryFlags, format, muxedCaptionFormats, timestampAdjuster);
if (sniffQuietly(tsExtractor, extractorInput)) { if (sniffQuietly(tsExtractor, extractorInput)) {
return buildResult(tsExtractor); return buildResult(tsExtractor);
} }
@ -180,17 +200,23 @@ public final class DefaultHlsExtractorFactory implements HlsExtractorFactory {
muxedCaptionFormats != null ? muxedCaptionFormats : Collections.emptyList()); muxedCaptionFormats != null ? muxedCaptionFormats : Collections.emptyList());
} else { } else {
// For any other file extension, we assume TS format. // For any other file extension, we assume TS format.
return createTsExtractor(format, muxedCaptionFormats, timestampAdjuster); return createTsExtractor(
payloadReaderFactoryFlags, format, muxedCaptionFormats, timestampAdjuster);
} }
} }
private static TsExtractor createTsExtractor( private static TsExtractor createTsExtractor(
Format format, List<Format> muxedCaptionFormats, TimestampAdjuster timestampAdjuster) { @DefaultTsPayloadReaderFactory.Flags int userProvidedPayloadReaderFactoryFlags,
Format format,
List<Format> muxedCaptionFormats,
TimestampAdjuster timestampAdjuster) {
@DefaultTsPayloadReaderFactory.Flags @DefaultTsPayloadReaderFactory.Flags
int esReaderFactoryFlags = DefaultTsPayloadReaderFactory.FLAG_IGNORE_SPLICE_INFO_STREAM; int payloadReaderFactoryFlags =
DefaultTsPayloadReaderFactory.FLAG_IGNORE_SPLICE_INFO_STREAM
| userProvidedPayloadReaderFactoryFlags;
if (muxedCaptionFormats != null) { if (muxedCaptionFormats != null) {
// The playlist declares closed caption renditions, we should ignore descriptors. // The playlist declares closed caption renditions, we should ignore descriptors.
esReaderFactoryFlags |= DefaultTsPayloadReaderFactory.FLAG_OVERRIDE_CAPTION_DESCRIPTORS; payloadReaderFactoryFlags |= DefaultTsPayloadReaderFactory.FLAG_OVERRIDE_CAPTION_DESCRIPTORS;
} else { } else {
// The playlist does not provide any closed caption information. We preemptively declare a // The playlist does not provide any closed caption information. We preemptively declare a
// closed caption track on channel 0. // 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 // exist. If we know from the codec attribute that they don't exist, then we can
// explicitly ignore them even if they're declared. // explicitly ignore them even if they're declared.
if (!MimeTypes.AUDIO_AAC.equals(MimeTypes.getAudioMediaMimeType(codecs))) { 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))) { if (!MimeTypes.VIDEO_H264.equals(MimeTypes.getVideoMediaMimeType(codecs))) {
esReaderFactoryFlags |= DefaultTsPayloadReaderFactory.FLAG_IGNORE_H264_STREAM; payloadReaderFactoryFlags |= DefaultTsPayloadReaderFactory.FLAG_IGNORE_H264_STREAM;
} }
} }
return new TsExtractor( return new TsExtractor(
TsExtractor.MODE_HLS, TsExtractor.MODE_HLS,
timestampAdjuster, timestampAdjuster,
new DefaultTsPayloadReaderFactory(esReaderFactoryFlags, muxedCaptionFormats)); new DefaultTsPayloadReaderFactory(payloadReaderFactoryFlags, muxedCaptionFormats));
} }
private static Pair<Extractor, Boolean> buildResult(Extractor extractor) { private static Pair<Extractor, Boolean> buildResult(Extractor extractor) {