Skip to content

Commit

Permalink
[Customize] Allow ExtractorMediaSource specify addition track selecti…
Browse files Browse the repository at this point in the history
…on flags
  • Loading branch information
Khang-NT committed Oct 28, 2018
1 parent df0504f commit f1327c4
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1274,6 +1274,37 @@ public Format copyWithRotationDegrees(int rotationDegrees) {
metadata);
}

public Format copyWithSelectionFlag(@C.SelectionFlags int selectionFlags) {
return new Format(
id,
label,
containerMimeType,
sampleMimeType,
codecs,
bitrate,
maxInputSize,
width,
height,
frameRate,
rotationDegrees,
pixelWidthHeightRatio,
projectionData,
stereoMode,
colorInfo,
channelCount,
sampleRate,
pcmEncoding,
encoderDelay,
encoderPadding,
selectionFlags,
language,
accessibilityChannel,
subsampleOffsetUs,
initializationData,
drmInitData,
metadata);
}

/**
* Returns the number of pixels if this is a video format whose {@link #width} and {@link #height}
* are known, or {@link #NO_VALUE} otherwise
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ interface Listener {
private final Listener listener;
private final Allocator allocator;
private final @Nullable String customCacheKey;
private final @C.SelectionFlags int additionSelectionFlag;
private final long continueLoadingCheckIntervalBytes;
private final Loader loader;
private final ExtractorHolder extractorHolder;
Expand Down Expand Up @@ -144,6 +145,7 @@ public ExtractorMediaPeriod(
Listener listener,
Allocator allocator,
@Nullable String customCacheKey,
@C.SelectionFlags int additionSelectionFlag,
int continueLoadingCheckIntervalBytes) {
this.uri = uri;
this.dataSource = dataSource;
Expand All @@ -152,6 +154,7 @@ public ExtractorMediaPeriod(
this.listener = listener;
this.allocator = allocator;
this.customCacheKey = customCacheKey;
this.additionSelectionFlag = additionSelectionFlag;
this.continueLoadingCheckIntervalBytes = continueLoadingCheckIntervalBytes;
loader = new Loader("Loader:ExtractorMediaPeriod");
extractorHolder = new ExtractorHolder(extractors);
Expand Down Expand Up @@ -653,6 +656,7 @@ private void maybeFinishPrepare() {
durationUs = seekMap.getDurationUs();
for (int i = 0; i < trackCount; i++) {
Format trackFormat = sampleQueues[i].getUpstreamFormat();
trackFormat = trackFormat.copyWithSelectionFlag(trackFormat.selectionFlags | additionSelectionFlag);
trackArray[i] = new TrackGroup(trackFormat);
String mimeType = trackFormat.sampleMimeType;
boolean isAudioVideo = MimeTypes.isVideo(mimeType) || MimeTypes.isAudio(mimeType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ public static final class Factory implements AdsMediaSource.MediaSourceFactory {

private @Nullable ExtractorsFactory extractorsFactory;
private @Nullable String customCacheKey;
private @C.SelectionFlags int additionSelectionFlag;
private @Nullable Object tag;
private LoadErrorHandlingPolicy loadErrorHandlingPolicy;
private int continueLoadingCheckIntervalBytes;
Expand Down Expand Up @@ -140,6 +141,11 @@ public Factory setTag(Object tag) {
return this;
}

public Factory setAdditionSelectionFlag(@C.SelectionFlags int additionSelectionFlag) {
this.additionSelectionFlag = additionSelectionFlag;
return this;
}

/**
* Sets the minimum number of times to retry if a loading error occurs. See {@link
* #setLoadErrorHandlingPolicy} for the default value.
Expand Down Expand Up @@ -209,6 +215,7 @@ public ExtractorMediaSource createMediaSource(Uri uri) {
extractorsFactory,
loadErrorHandlingPolicy,
customCacheKey,
additionSelectionFlag,
continueLoadingCheckIntervalBytes,
tag);
}
Expand Down Expand Up @@ -244,6 +251,7 @@ public int[] getSupportedTypes() {
private final ExtractorsFactory extractorsFactory;
private final LoadErrorHandlingPolicy loadableLoadErrorHandlingPolicy;
private final String customCacheKey;
private final @C.SelectionFlags int additionSelectionFlag;
private final int continueLoadingCheckIntervalBytes;
private final @Nullable Object tag;

Expand All @@ -269,7 +277,7 @@ public ExtractorMediaSource(
ExtractorsFactory extractorsFactory,
Handler eventHandler,
EventListener eventListener) {
this(uri, dataSourceFactory, extractorsFactory, eventHandler, eventListener, null);
this(uri, dataSourceFactory, extractorsFactory, eventHandler, eventListener, null, 0);
}

/**
Expand All @@ -292,14 +300,16 @@ public ExtractorMediaSource(
ExtractorsFactory extractorsFactory,
Handler eventHandler,
EventListener eventListener,
String customCacheKey) {
String customCacheKey,
int additionSelectionFlag) {
this(
uri,
dataSourceFactory,
extractorsFactory,
eventHandler,
eventListener,
customCacheKey,
additionSelectionFlag,
DEFAULT_LOADING_CHECK_INTERVAL_BYTES);
}

Expand All @@ -326,13 +336,15 @@ public ExtractorMediaSource(
Handler eventHandler,
EventListener eventListener,
String customCacheKey,
int additionSelectionFlag,
int continueLoadingCheckIntervalBytes) {
this(
uri,
dataSourceFactory,
extractorsFactory,
new DefaultLoadErrorHandlingPolicy(),
customCacheKey,
additionSelectionFlag,
continueLoadingCheckIntervalBytes,
/* tag= */ null);
if (eventListener != null && eventHandler != null) {
Expand All @@ -346,13 +358,15 @@ private ExtractorMediaSource(
ExtractorsFactory extractorsFactory,
LoadErrorHandlingPolicy loadableLoadErrorHandlingPolicy,
@Nullable String customCacheKey,
@C.SelectionFlags int additionSelectionFlag,
int continueLoadingCheckIntervalBytes,
@Nullable Object tag) {
this.uri = uri;
this.dataSourceFactory = dataSourceFactory;
this.extractorsFactory = extractorsFactory;
this.loadableLoadErrorHandlingPolicy = loadableLoadErrorHandlingPolicy;
this.customCacheKey = customCacheKey;
this.additionSelectionFlag = additionSelectionFlag;
this.continueLoadingCheckIntervalBytes = continueLoadingCheckIntervalBytes;
this.timelineDurationUs = C.TIME_UNSET;
this.tag = tag;
Expand Down Expand Up @@ -387,6 +401,7 @@ public MediaPeriod createPeriod(MediaPeriodId id, Allocator allocator) {
this,
allocator,
customCacheKey,
additionSelectionFlag,
continueLoadingCheckIntervalBytes);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,8 @@ public void onTimelineChanged(EventTime eventTime, @Player.TimelineChangeReason
+ window.isSeekable
+ ", "
+ window.isDynamic
+ ", "
+ window.tag
+ "]");
}
if (windowCount > MAX_TIMELINE_ITEM_LINES) {
Expand Down

0 comments on commit f1327c4

Please sign in to comment.