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:
parent
f9a805070a
commit
10511e56cf
@ -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;
|
||||
|
@ -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<Extractor, Boolean> 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<Format> muxedCaptionFormats, TimestampAdjuster timestampAdjuster) {
|
||||
@DefaultTsPayloadReaderFactory.Flags int userProvidedPayloadReaderFactoryFlags,
|
||||
Format format,
|
||||
List<Format> 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<Extractor, Boolean> buildResult(Extractor extractor) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user