mirror of
https://github.com/androidx/media.git
synced 2025-04-30 06:46:50 +08:00
Inform ProgressiveMediaPeriod of known length earlier
PiperOrigin-RevId: 456753343 (cherry picked from commit 1d2ad39a4d4778124a6b87c3d3a7a4415eeb8865)
This commit is contained in:
parent
59fbb45506
commit
2f1260e346
@ -135,7 +135,7 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
|||||||
private boolean seenFirstTrackSelection;
|
private boolean seenFirstTrackSelection;
|
||||||
private boolean notifyDiscontinuity;
|
private boolean notifyDiscontinuity;
|
||||||
private int enabledTrackCount;
|
private int enabledTrackCount;
|
||||||
private long length;
|
private boolean isLengthKnown;
|
||||||
|
|
||||||
private long lastSeekPositionUs;
|
private long lastSeekPositionUs;
|
||||||
private long pendingResetPositionUs;
|
private long pendingResetPositionUs;
|
||||||
@ -201,7 +201,6 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
|||||||
sampleQueueTrackIds = new TrackId[0];
|
sampleQueueTrackIds = new TrackId[0];
|
||||||
sampleQueues = new SampleQueue[0];
|
sampleQueues = new SampleQueue[0];
|
||||||
pendingResetPositionUs = C.TIME_UNSET;
|
pendingResetPositionUs = C.TIME_UNSET;
|
||||||
length = C.LENGTH_UNSET;
|
|
||||||
durationUs = C.TIME_UNSET;
|
durationUs = C.TIME_UNSET;
|
||||||
dataType = C.DATA_TYPE_MEDIA;
|
dataType = C.DATA_TYPE_MEDIA;
|
||||||
}
|
}
|
||||||
@ -578,7 +577,6 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
|||||||
/* trackSelectionData= */ null,
|
/* trackSelectionData= */ null,
|
||||||
/* mediaStartTimeUs= */ loadable.seekTimeUs,
|
/* mediaStartTimeUs= */ loadable.seekTimeUs,
|
||||||
durationUs);
|
durationUs);
|
||||||
copyLengthFromLoader(loadable);
|
|
||||||
loadingFinished = true;
|
loadingFinished = true;
|
||||||
Assertions.checkNotNull(callback).onContinueLoadingRequested(this);
|
Assertions.checkNotNull(callback).onContinueLoadingRequested(this);
|
||||||
}
|
}
|
||||||
@ -607,7 +605,6 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
|||||||
/* mediaStartTimeUs= */ loadable.seekTimeUs,
|
/* mediaStartTimeUs= */ loadable.seekTimeUs,
|
||||||
durationUs);
|
durationUs);
|
||||||
if (!released) {
|
if (!released) {
|
||||||
copyLengthFromLoader(loadable);
|
|
||||||
for (SampleQueue sampleQueue : sampleQueues) {
|
for (SampleQueue sampleQueue : sampleQueues) {
|
||||||
sampleQueue.reset();
|
sampleQueue.reset();
|
||||||
}
|
}
|
||||||
@ -624,7 +621,6 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
|||||||
long loadDurationMs,
|
long loadDurationMs,
|
||||||
IOException error,
|
IOException error,
|
||||||
int errorCount) {
|
int errorCount) {
|
||||||
copyLengthFromLoader(loadable);
|
|
||||||
StatsDataSource dataSource = loadable.dataSource;
|
StatsDataSource dataSource = loadable.dataSource;
|
||||||
LoadEventInfo loadEventInfo =
|
LoadEventInfo loadEventInfo =
|
||||||
new LoadEventInfo(
|
new LoadEventInfo(
|
||||||
@ -710,6 +706,10 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
|||||||
|
|
||||||
// Internal methods.
|
// Internal methods.
|
||||||
|
|
||||||
|
private void onLengthKnown() {
|
||||||
|
handler.post(() -> isLengthKnown = true);
|
||||||
|
}
|
||||||
|
|
||||||
private TrackOutput prepareTrackOutput(TrackId id) {
|
private TrackOutput prepareTrackOutput(TrackId id) {
|
||||||
int trackCount = sampleQueues.length;
|
int trackCount = sampleQueues.length;
|
||||||
for (int i = 0; i < trackCount; i++) {
|
for (int i = 0; i < trackCount; i++) {
|
||||||
@ -733,7 +733,7 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
|||||||
private void setSeekMap(SeekMap seekMap) {
|
private void setSeekMap(SeekMap seekMap) {
|
||||||
this.seekMap = icyHeaders == null ? seekMap : new Unseekable(/* durationUs= */ C.TIME_UNSET);
|
this.seekMap = icyHeaders == null ? seekMap : new Unseekable(/* durationUs= */ C.TIME_UNSET);
|
||||||
durationUs = seekMap.getDurationUs();
|
durationUs = seekMap.getDurationUs();
|
||||||
isLive = length == C.LENGTH_UNSET && seekMap.getDurationUs() == C.TIME_UNSET;
|
isLive = !isLengthKnown && seekMap.getDurationUs() == C.TIME_UNSET;
|
||||||
dataType = isLive ? C.DATA_TYPE_MEDIA_PROGRESSIVE_LIVE : C.DATA_TYPE_MEDIA;
|
dataType = isLive ? C.DATA_TYPE_MEDIA_PROGRESSIVE_LIVE : C.DATA_TYPE_MEDIA;
|
||||||
listener.onSourceInfoRefreshed(durationUs, seekMap.isSeekable(), isLive);
|
listener.onSourceInfoRefreshed(durationUs, seekMap.isSeekable(), isLive);
|
||||||
if (!prepared) {
|
if (!prepared) {
|
||||||
@ -789,12 +789,6 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
|||||||
Assertions.checkNotNull(callback).onPrepared(this);
|
Assertions.checkNotNull(callback).onPrepared(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void copyLengthFromLoader(ExtractingLoadable loadable) {
|
|
||||||
if (length == C.LENGTH_UNSET) {
|
|
||||||
length = loadable.length;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void startLoading() {
|
private void startLoading() {
|
||||||
ExtractingLoadable loadable =
|
ExtractingLoadable loadable =
|
||||||
new ExtractingLoadable(
|
new ExtractingLoadable(
|
||||||
@ -840,7 +834,7 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
|||||||
* retry.
|
* retry.
|
||||||
*/
|
*/
|
||||||
private boolean configureRetry(ExtractingLoadable loadable, int currentExtractedSampleCount) {
|
private boolean configureRetry(ExtractingLoadable loadable, int currentExtractedSampleCount) {
|
||||||
if (length != C.LENGTH_UNSET || (seekMap != null && seekMap.getDurationUs() != C.TIME_UNSET)) {
|
if (isLengthKnown || (seekMap != null && seekMap.getDurationUs() != C.TIME_UNSET)) {
|
||||||
// We're playing an on-demand stream. Resume the current loadable, which will
|
// We're playing an on-demand stream. Resume the current loadable, which will
|
||||||
// request data starting from the point it left off.
|
// request data starting from the point it left off.
|
||||||
extractedSamplesCountAtStartOfLoad = currentExtractedSampleCount;
|
extractedSamplesCountAtStartOfLoad = currentExtractedSampleCount;
|
||||||
@ -970,7 +964,6 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
|||||||
private boolean pendingExtractorSeek;
|
private boolean pendingExtractorSeek;
|
||||||
private long seekTimeUs;
|
private long seekTimeUs;
|
||||||
private DataSpec dataSpec;
|
private DataSpec dataSpec;
|
||||||
private long length;
|
|
||||||
@Nullable private TrackOutput icyTrackOutput;
|
@Nullable private TrackOutput icyTrackOutput;
|
||||||
private boolean seenIcyMetadata;
|
private boolean seenIcyMetadata;
|
||||||
|
|
||||||
@ -988,7 +981,6 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
|||||||
this.loadCondition = loadCondition;
|
this.loadCondition = loadCondition;
|
||||||
this.positionHolder = new PositionHolder();
|
this.positionHolder = new PositionHolder();
|
||||||
this.pendingExtractorSeek = true;
|
this.pendingExtractorSeek = true;
|
||||||
this.length = C.LENGTH_UNSET;
|
|
||||||
loadTaskId = LoadEventInfo.getNewId();
|
loadTaskId = LoadEventInfo.getNewId();
|
||||||
dataSpec = buildDataSpec(/* position= */ 0);
|
dataSpec = buildDataSpec(/* position= */ 0);
|
||||||
}
|
}
|
||||||
@ -1007,9 +999,10 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
|||||||
try {
|
try {
|
||||||
long position = positionHolder.position;
|
long position = positionHolder.position;
|
||||||
dataSpec = buildDataSpec(position);
|
dataSpec = buildDataSpec(position);
|
||||||
length = dataSource.open(dataSpec);
|
long length = dataSource.open(dataSpec);
|
||||||
if (length != C.LENGTH_UNSET) {
|
if (length != C.LENGTH_UNSET) {
|
||||||
length += position;
|
length += position;
|
||||||
|
onLengthKnown();
|
||||||
}
|
}
|
||||||
icyHeaders = IcyHeaders.parse(dataSource.getResponseHeaders());
|
icyHeaders = IcyHeaders.parse(dataSource.getResponseHeaders());
|
||||||
DataSource extractorDataSource = dataSource;
|
DataSource extractorDataSource = dataSource;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user