Skip to content

Commit

Permalink
Add constructor for adding payload reader factory flags
Browse files Browse the repository at this point in the history
Issue:#4861

-------------
Created by MOE: https:/google/moe
MOE_MIGRATED_REVID=214772527
  • Loading branch information
AquilesCanta authored and ojw28 committed Sep 27, 2018
1 parent 2a50621 commit e50214a
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 8 deletions.
3 changes: 3 additions & 0 deletions RELEASENOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
* Add convenience methods `Player.next`, `Player.previous`, `Player.hasNext`
and `Player.hasPrevious`
([#4863](https:/google/ExoPlayer/issues/4863)).
* HLS:
* Add constructor to `DefaultHlsExtractorFactory` for adding TS payload reader
factory flags ([#4861](https:/google/ExoPlayer/issues/4861)).

### 2.9.0 ###

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -138,7 +156,9 @@ public Pair<Extractor, Boolean> createExtractor(
}

if (!(extractorByFileExtension instanceof TsExtractor)) {
TsExtractor tsExtractor = createTsExtractor(format, muxedCaptionFormats, timestampAdjuster);
TsExtractor tsExtractor =
createTsExtractor(
payloadReaderFactoryFlags, format, muxedCaptionFormats, timestampAdjuster);
if (sniffQuietly(tsExtractor, extractorInput)) {
return buildResult(tsExtractor);
}
Expand Down Expand Up @@ -180,17 +200,23 @@ private Extractor createExtractorByFileExtension(
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.
Expand All @@ -208,17 +234,17 @@ private static TsExtractor createTsExtractor(
// 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) {
Expand Down

0 comments on commit e50214a

Please sign in to comment.