Commit 7a564030 by tonihei Committed by Oliver Woodman

Add missing downstreamFormatChanged to Extractor and SingleSample media source.

These haven't been included in the recent changes but can be reported as
soon as the first sample of each stream is read.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=181753141
parent ad3e6ef4
......@@ -105,6 +105,7 @@ import java.util.Arrays;
private long durationUs;
private boolean[] trackEnabledStates;
private boolean[] trackIsAudioVideoFlags;
private boolean[] trackFormatNotificationSent;
private boolean haveAudioVideoTracks;
private long length;
......@@ -398,8 +399,13 @@ import java.util.Arrays;
if (suppressRead()) {
return C.RESULT_NOTHING_READ;
}
return sampleQueues[track].read(formatHolder, buffer, formatRequired, loadingFinished,
lastSeekPositionUs);
int result =
sampleQueues[track].read(
formatHolder, buffer, formatRequired, loadingFinished, lastSeekPositionUs);
if (result == C.RESULT_BUFFER_READ) {
maybeNotifyTrackFormat(track);
}
return result;
}
/* package */ int skipData(int track, long positionUs) {
......@@ -407,11 +413,31 @@ import java.util.Arrays;
return 0;
}
SampleQueue sampleQueue = sampleQueues[track];
int skipCount;
if (loadingFinished && positionUs > sampleQueue.getLargestQueuedTimestampUs()) {
return sampleQueue.advanceToEnd();
skipCount = sampleQueue.advanceToEnd();
} else {
int skipCount = sampleQueue.advanceTo(positionUs, true, true);
return skipCount == SampleQueue.ADVANCE_FAILED ? 0 : skipCount;
skipCount = sampleQueue.advanceTo(positionUs, true, true);
if (skipCount == SampleQueue.ADVANCE_FAILED) {
skipCount = 0;
}
}
if (skipCount > 0) {
maybeNotifyTrackFormat(track);
}
return skipCount;
}
private void maybeNotifyTrackFormat(int track) {
if (!trackFormatNotificationSent[track]) {
Format trackFormat = tracks.get(track).getFormat(0);
eventDispatcher.downstreamFormatChanged(
MimeTypes.getTrackType(trackFormat.sampleMimeType),
trackFormat,
C.SELECTION_REASON_UNKNOWN,
/* trackSelectionData= */ null,
lastSeekPositionUs);
trackFormatNotificationSent[track] = true;
}
}
......@@ -556,6 +582,7 @@ import java.util.Arrays;
TrackGroup[] trackArray = new TrackGroup[trackCount];
trackIsAudioVideoFlags = new boolean[trackCount];
trackEnabledStates = new boolean[trackCount];
trackFormatNotificationSent = new boolean[trackCount];
durationUs = seekMap.getDurationUs();
for (int i = 0; i < trackCount; i++) {
Format trackFormat = sampleQueues[i].getUpstreamFormat();
......
......@@ -26,6 +26,7 @@ import com.google.android.exoplayer2.upstream.DataSource;
import com.google.android.exoplayer2.upstream.DataSpec;
import com.google.android.exoplayer2.upstream.Loader;
import com.google.android.exoplayer2.upstream.Loader.Loadable;
import com.google.android.exoplayer2.util.MimeTypes;
import com.google.android.exoplayer2.util.Util;
import java.io.IOException;
import java.util.ArrayList;
......@@ -252,6 +253,7 @@ import java.util.Arrays;
private static final int STREAM_STATE_END_OF_STREAM = 2;
private int streamState;
private boolean formatSent;
public void reset() {
if (streamState == STREAM_STATE_END_OF_STREAM) {
......@@ -287,6 +289,7 @@ import java.util.Arrays;
buffer.addFlag(C.BUFFER_FLAG_KEY_FRAME);
buffer.ensureSpaceForWrite(sampleSize);
buffer.data.put(sampleData, 0, sampleSize);
sendFormat();
} else {
buffer.addFlag(C.BUFFER_FLAG_END_OF_STREAM);
}
......@@ -300,11 +303,23 @@ import java.util.Arrays;
public int skipData(long positionUs) {
if (positionUs > 0 && streamState != STREAM_STATE_END_OF_STREAM) {
streamState = STREAM_STATE_END_OF_STREAM;
sendFormat();
return 1;
}
return 0;
}
private void sendFormat() {
if (!formatSent) {
eventDispatcher.downstreamFormatChanged(
MimeTypes.getTrackType(format.sampleMimeType),
format,
C.SELECTION_REASON_UNKNOWN,
/* trackSelectionData= */ null,
/* mediaTimeUs= */ 0);
formatSent = true;
}
}
}
/* package */ static final class SourceLoadable implements Loadable {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment