Fix DASH period duration reporting

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=129787235
This commit is contained in:
olly 2016-08-09 13:35:18 -07:00 committed by Oliver Woodman
parent cdb706bac8
commit 665c9fc14c
5 changed files with 16 additions and 19 deletions

View file

@ -68,7 +68,7 @@ import java.util.List;
this.eventDispatcher = eventDispatcher;
this.elapsedRealtimeOffset = elapsedRealtimeOffset;
this.manifestLoaderErrorThrower = manifestLoaderErrorThrower;
durationUs = manifest.dynamic ? C.UNSET_TIME_US : manifest.getPeriodDuration(index) * 1000;
durationUs = manifest.getPeriodDurationUs(index);
period = manifest.getPeriod(index);
trackGroups = buildTrackGroups(period);
}
@ -76,7 +76,7 @@ import java.util.List;
public void updateManifest(DashManifest manifest, int index) {
this.manifest = manifest;
this.index = index;
durationUs = manifest.dynamic ? C.UNSET_TIME_US : manifest.getPeriodDuration(index) * 1000;
durationUs = manifest.getPeriodDurationUs(index);
period = manifest.getPeriod(index);
if (sampleStreams != null) {
for (ChunkSampleStream<DashChunkSource> sampleStream : sampleStreams) {

View file

@ -168,7 +168,7 @@ public final class DashMediaSource implements MediaSource {
long positionUs = seekWindow.endTimeUs - LIVE_EDGE_OFFSET_US;
while (positionUs < 0 && periodIndex > seekWindow.startPeriodIndex) {
periodIndex--;
positionUs += manifest.getPeriodDuration(periodIndex) * 1000;
positionUs += manifest.getPeriodDurationUs(periodIndex);
}
positionUs = Math.max(positionUs,
periodIndex == seekWindow.startPeriodIndex ? seekWindow.startTimeUs : 0);
@ -374,9 +374,9 @@ public final class DashMediaSource implements MediaSource {
int periodCount = manifest.getPeriodCount();
int lastPeriodIndex = periodCount - 1;
PeriodSeekInfo firstPeriodSeekInfo = PeriodSeekInfo.createPeriodSeekInfo(manifest.getPeriod(0),
manifest.getPeriodDuration(0) * 1000);
manifest.getPeriodDurationUs(0));
PeriodSeekInfo lastPeriodSeekInfo = PeriodSeekInfo.createPeriodSeekInfo(
manifest.getPeriod(lastPeriodIndex), manifest.getPeriodDuration(lastPeriodIndex) * 1000);
manifest.getPeriod(lastPeriodIndex), manifest.getPeriodDurationUs(lastPeriodIndex));
long currentStartTimeUs;
long currentEndTimeUs;
if (manifest.dynamic && !lastPeriodSeekInfo.isIndexExplicit) {
@ -505,7 +505,7 @@ public final class DashMediaSource implements MediaSource {
@Override
public long getPeriodDuration(int index) {
return manifest.getPeriodDuration(index);
return manifest.getPeriodDurationMs(index);
}
@Override

View file

@ -16,7 +16,6 @@
package com.google.android.exoplayer2.source.dash;
import android.os.SystemClock;
import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.Format;
import com.google.android.exoplayer2.extractor.ChunkIndex;
import com.google.android.exoplayer2.extractor.Extractor;
@ -105,7 +104,7 @@ public class DefaultDashChunkSource implements DashChunkSource {
this.periodIndex = periodIndex;
this.elapsedRealtimeOffsetUs = elapsedRealtimeOffsetMs * 1000;
long periodDurationUs = getPeriodDurationUs();
long periodDurationUs = manifest.getPeriodDurationUs(periodIndex);
List<Representation> representations = getRepresentations();
representationHolders = new RepresentationHolder[trackSelection.length()];
for (int i = 0; i < representationHolders.length; i++) {
@ -119,7 +118,7 @@ public class DefaultDashChunkSource implements DashChunkSource {
try {
manifest = newManifest;
periodIndex = newPeriodIndex;
long periodDurationUs = getPeriodDurationUs();
long periodDurationUs = manifest.getPeriodDurationUs(periodIndex);
List<Representation> representations = getRepresentations();
for (int i = 0; i < representationHolders.length; i++) {
Representation representation = representations.get(trackSelection.getIndexInTrackGroup(i));
@ -323,15 +322,6 @@ public class DefaultDashChunkSource implements DashChunkSource {
}
}
private long getPeriodDurationUs() {
long durationMs = manifest.getPeriodDuration(periodIndex);
if (durationMs == -1) {
return C.UNSET_TIME_US;
} else {
return durationMs * 1000;
}
}
// Protected classes.
protected static final class RepresentationHolder {

View file

@ -16,6 +16,7 @@
package com.google.android.exoplayer2.source.dash.manifest;
import android.net.Uri;
import com.google.android.exoplayer2.C;
import java.util.Collections;
import java.util.List;
@ -64,10 +65,15 @@ public class DashManifest {
return periods.get(index);
}
public final long getPeriodDuration(int index) {
public final long getPeriodDurationMs(int index) {
return index == periods.size() - 1
? (duration == -1 ? -1 : duration - periods.get(index).startMs)
: periods.get(index + 1).startMs - periods.get(index).startMs;
}
public final long getPeriodDurationUs(int index) {
long durationMs = getPeriodDurationMs(index);
return durationMs == -1 ? C.UNSET_TIME_US : durationMs * 1000;
}
}

View file

@ -107,6 +107,7 @@ public final class TextRenderer extends BaseRenderer implements Callback {
protected void onStreamChanged(Format[] formats) throws ExoPlaybackException {
if (decoder != null) {
decoder.release();
nextInputBuffer = null;
}
decoder = decoderFactory.createDecoder(formats[0]);
}