Commit 78ecb10a by bachinger Committed by Ian Baker

Add RepresentationHolder.selectedBaseUrl and use it for new chunks

PiperOrigin-RevId: 384968532
parent 99abb4e1
...@@ -40,6 +40,7 @@ import com.google.android.exoplayer2.source.chunk.MediaChunkIterator; ...@@ -40,6 +40,7 @@ import com.google.android.exoplayer2.source.chunk.MediaChunkIterator;
import com.google.android.exoplayer2.source.chunk.SingleSampleMediaChunk; import com.google.android.exoplayer2.source.chunk.SingleSampleMediaChunk;
import com.google.android.exoplayer2.source.dash.PlayerEmsgHandler.PlayerTrackEmsgHandler; import com.google.android.exoplayer2.source.dash.PlayerEmsgHandler.PlayerTrackEmsgHandler;
import com.google.android.exoplayer2.source.dash.manifest.AdaptationSet; import com.google.android.exoplayer2.source.dash.manifest.AdaptationSet;
import com.google.android.exoplayer2.source.dash.manifest.BaseUrl;
import com.google.android.exoplayer2.source.dash.manifest.DashManifest; import com.google.android.exoplayer2.source.dash.manifest.DashManifest;
import com.google.android.exoplayer2.source.dash.manifest.RangedUri; import com.google.android.exoplayer2.source.dash.manifest.RangedUri;
import com.google.android.exoplayer2.source.dash.manifest.Representation; import com.google.android.exoplayer2.source.dash.manifest.Representation;
...@@ -203,6 +204,7 @@ public class DefaultDashChunkSource implements DashChunkSource { ...@@ -203,6 +204,7 @@ public class DefaultDashChunkSource implements DashChunkSource {
new RepresentationHolder( new RepresentationHolder(
periodDurationUs, periodDurationUs,
representation, representation,
representation.baseUrls.get(0),
BundledChunkExtractor.FACTORY.createProgressiveMediaExtractor( BundledChunkExtractor.FACTORY.createProgressiveMediaExtractor(
trackType, trackType,
representation.format, representation.format,
...@@ -562,14 +564,20 @@ public class DefaultDashChunkSource implements DashChunkSource { ...@@ -562,14 +564,20 @@ public class DefaultDashChunkSource implements DashChunkSource {
if (initializationUri != null) { if (initializationUri != null) {
// It's common for initialization and index data to be stored adjacently. Attempt to merge // It's common for initialization and index data to be stored adjacently. Attempt to merge
// the two requests together to request both at once. // the two requests together to request both at once.
requestUri = initializationUri.attemptMerge(indexUri, representation.baseUrls.get(0).url); requestUri =
initializationUri.attemptMerge(indexUri, representationHolder.selectedBaseUrl.url);
if (requestUri == null) { if (requestUri == null) {
requestUri = initializationUri; requestUri = initializationUri;
} }
} else { } else {
requestUri = indexUri; requestUri = indexUri;
} }
DataSpec dataSpec = DashUtil.buildDataSpec(representation, requestUri, /* flags= */ 0); DataSpec dataSpec =
DashUtil.buildDataSpec(
representationHolder.selectedBaseUrl.url,
requestUri,
representation.getCacheKey(),
/* flags= */ 0);
return new InitializationChunk( return new InitializationChunk(
dataSource, dataSource,
dataSpec, dataSpec,
...@@ -593,7 +601,6 @@ public class DefaultDashChunkSource implements DashChunkSource { ...@@ -593,7 +601,6 @@ public class DefaultDashChunkSource implements DashChunkSource {
Representation representation = representationHolder.representation; Representation representation = representationHolder.representation;
long startTimeUs = representationHolder.getSegmentStartTimeUs(firstSegmentNum); long startTimeUs = representationHolder.getSegmentStartTimeUs(firstSegmentNum);
RangedUri segmentUri = representationHolder.getSegmentUrl(firstSegmentNum); RangedUri segmentUri = representationHolder.getSegmentUrl(firstSegmentNum);
String baseUrl = representation.baseUrls.get(0).url;
if (representationHolder.chunkExtractor == null) { if (representationHolder.chunkExtractor == null) {
long endTimeUs = representationHolder.getSegmentEndTimeUs(firstSegmentNum); long endTimeUs = representationHolder.getSegmentEndTimeUs(firstSegmentNum);
int flags = int flags =
...@@ -601,7 +608,12 @@ public class DefaultDashChunkSource implements DashChunkSource { ...@@ -601,7 +608,12 @@ public class DefaultDashChunkSource implements DashChunkSource {
firstSegmentNum, nowPeriodTimeUs) firstSegmentNum, nowPeriodTimeUs)
? 0 ? 0
: DataSpec.FLAG_MIGHT_NOT_USE_FULL_NETWORK_SPEED; : DataSpec.FLAG_MIGHT_NOT_USE_FULL_NETWORK_SPEED;
DataSpec dataSpec = DashUtil.buildDataSpec(representation, segmentUri, flags); DataSpec dataSpec =
DashUtil.buildDataSpec(
representationHolder.selectedBaseUrl.url,
segmentUri,
representation.getCacheKey(),
flags);
return new SingleSampleMediaChunk( return new SingleSampleMediaChunk(
dataSource, dataSource,
dataSpec, dataSpec,
...@@ -617,7 +629,9 @@ public class DefaultDashChunkSource implements DashChunkSource { ...@@ -617,7 +629,9 @@ public class DefaultDashChunkSource implements DashChunkSource {
int segmentCount = 1; int segmentCount = 1;
for (int i = 1; i < maxSegmentCount; i++) { for (int i = 1; i < maxSegmentCount; i++) {
RangedUri nextSegmentUri = representationHolder.getSegmentUrl(firstSegmentNum + i); RangedUri nextSegmentUri = representationHolder.getSegmentUrl(firstSegmentNum + i);
@Nullable RangedUri mergedSegmentUri = segmentUri.attemptMerge(nextSegmentUri, baseUrl); @Nullable
RangedUri mergedSegmentUri =
segmentUri.attemptMerge(nextSegmentUri, representationHolder.selectedBaseUrl.url);
if (mergedSegmentUri == null) { if (mergedSegmentUri == null) {
// Unable to merge segment fetches because the URIs do not merge. // Unable to merge segment fetches because the URIs do not merge.
break; break;
...@@ -636,7 +650,12 @@ public class DefaultDashChunkSource implements DashChunkSource { ...@@ -636,7 +650,12 @@ public class DefaultDashChunkSource implements DashChunkSource {
representationHolder.isSegmentAvailableAtFullNetworkSpeed(segmentNum, nowPeriodTimeUs) representationHolder.isSegmentAvailableAtFullNetworkSpeed(segmentNum, nowPeriodTimeUs)
? 0 ? 0
: DataSpec.FLAG_MIGHT_NOT_USE_FULL_NETWORK_SPEED; : DataSpec.FLAG_MIGHT_NOT_USE_FULL_NETWORK_SPEED;
DataSpec dataSpec = DashUtil.buildDataSpec(representation, segmentUri, flags); DataSpec dataSpec =
DashUtil.buildDataSpec(
representationHolder.selectedBaseUrl.url,
segmentUri,
representation.getCacheKey(),
flags);
long sampleOffsetUs = -representation.presentationTimeOffsetUs; long sampleOffsetUs = -representation.presentationTimeOffsetUs;
return new ContainerMediaChunk( return new ContainerMediaChunk(
dataSource, dataSource,
...@@ -691,7 +710,11 @@ public class DefaultDashChunkSource implements DashChunkSource { ...@@ -691,7 +710,11 @@ public class DefaultDashChunkSource implements DashChunkSource {
representationHolder.isSegmentAvailableAtFullNetworkSpeed(currentIndex, nowPeriodTimeUs) representationHolder.isSegmentAvailableAtFullNetworkSpeed(currentIndex, nowPeriodTimeUs)
? 0 ? 0
: DataSpec.FLAG_MIGHT_NOT_USE_FULL_NETWORK_SPEED; : DataSpec.FLAG_MIGHT_NOT_USE_FULL_NETWORK_SPEED;
return DashUtil.buildDataSpec(representationHolder.representation, segmentUri, flags); return DashUtil.buildDataSpec(
representationHolder.selectedBaseUrl.url,
segmentUri,
representationHolder.representation.getCacheKey(),
flags);
} }
@Override @Override
...@@ -713,6 +736,7 @@ public class DefaultDashChunkSource implements DashChunkSource { ...@@ -713,6 +736,7 @@ public class DefaultDashChunkSource implements DashChunkSource {
@Nullable /* package */ final ChunkExtractor chunkExtractor; @Nullable /* package */ final ChunkExtractor chunkExtractor;
public final Representation representation; public final Representation representation;
public final BaseUrl selectedBaseUrl;
@Nullable public final DashSegmentIndex segmentIndex; @Nullable public final DashSegmentIndex segmentIndex;
private final long periodDurationUs; private final long periodDurationUs;
...@@ -721,11 +745,13 @@ public class DefaultDashChunkSource implements DashChunkSource { ...@@ -721,11 +745,13 @@ public class DefaultDashChunkSource implements DashChunkSource {
/* package */ RepresentationHolder( /* package */ RepresentationHolder(
long periodDurationUs, long periodDurationUs,
Representation representation, Representation representation,
BaseUrl selectedBaseUrl,
@Nullable ChunkExtractor chunkExtractor, @Nullable ChunkExtractor chunkExtractor,
long segmentNumShift, long segmentNumShift,
@Nullable DashSegmentIndex segmentIndex) { @Nullable DashSegmentIndex segmentIndex) {
this.periodDurationUs = periodDurationUs; this.periodDurationUs = periodDurationUs;
this.representation = representation; this.representation = representation;
this.selectedBaseUrl = selectedBaseUrl;
this.segmentNumShift = segmentNumShift; this.segmentNumShift = segmentNumShift;
this.chunkExtractor = chunkExtractor; this.chunkExtractor = chunkExtractor;
this.segmentIndex = segmentIndex; this.segmentIndex = segmentIndex;
...@@ -735,26 +761,41 @@ public class DefaultDashChunkSource implements DashChunkSource { ...@@ -735,26 +761,41 @@ public class DefaultDashChunkSource implements DashChunkSource {
/* package */ RepresentationHolder copyWithNewRepresentation( /* package */ RepresentationHolder copyWithNewRepresentation(
long newPeriodDurationUs, Representation newRepresentation) long newPeriodDurationUs, Representation newRepresentation)
throws BehindLiveWindowException { throws BehindLiveWindowException {
DashSegmentIndex oldIndex = representation.getIndex(); @Nullable DashSegmentIndex oldIndex = representation.getIndex();
DashSegmentIndex newIndex = newRepresentation.getIndex(); @Nullable DashSegmentIndex newIndex = newRepresentation.getIndex();
if (oldIndex == null) { if (oldIndex == null) {
// Segment numbers cannot shift if the index isn't defined by the manifest. // Segment numbers cannot shift if the index isn't defined by the manifest.
return new RepresentationHolder( return new RepresentationHolder(
newPeriodDurationUs, newRepresentation, chunkExtractor, segmentNumShift, oldIndex); newPeriodDurationUs,
newRepresentation,
selectedBaseUrl,
chunkExtractor,
segmentNumShift,
oldIndex);
} }
if (!oldIndex.isExplicit()) { if (!oldIndex.isExplicit()) {
// Segment numbers cannot shift if the index isn't explicit. // Segment numbers cannot shift if the index isn't explicit.
return new RepresentationHolder( return new RepresentationHolder(
newPeriodDurationUs, newRepresentation, chunkExtractor, segmentNumShift, newIndex); newPeriodDurationUs,
newRepresentation,
selectedBaseUrl,
chunkExtractor,
segmentNumShift,
newIndex);
} }
long oldIndexSegmentCount = oldIndex.getSegmentCount(newPeriodDurationUs); long oldIndexSegmentCount = oldIndex.getSegmentCount(newPeriodDurationUs);
if (oldIndexSegmentCount == 0) { if (oldIndexSegmentCount == 0) {
// Segment numbers cannot shift if the old index was empty. // Segment numbers cannot shift if the old index was empty.
return new RepresentationHolder( return new RepresentationHolder(
newPeriodDurationUs, newRepresentation, chunkExtractor, segmentNumShift, newIndex); newPeriodDurationUs,
newRepresentation,
selectedBaseUrl,
chunkExtractor,
segmentNumShift,
newIndex);
} }
long oldIndexFirstSegmentNum = oldIndex.getFirstSegmentNum(); long oldIndexFirstSegmentNum = oldIndex.getFirstSegmentNum();
...@@ -786,13 +827,23 @@ public class DefaultDashChunkSource implements DashChunkSource { ...@@ -786,13 +827,23 @@ public class DefaultDashChunkSource implements DashChunkSource {
- newIndexFirstSegmentNum; - newIndexFirstSegmentNum;
} }
return new RepresentationHolder( return new RepresentationHolder(
newPeriodDurationUs, newRepresentation, chunkExtractor, newSegmentNumShift, newIndex); newPeriodDurationUs,
newRepresentation,
selectedBaseUrl,
chunkExtractor,
newSegmentNumShift,
newIndex);
} }
@CheckResult @CheckResult
/* package */ RepresentationHolder copyWithNewSegmentIndex(DashSegmentIndex segmentIndex) { /* package */ RepresentationHolder copyWithNewSegmentIndex(DashSegmentIndex segmentIndex) {
return new RepresentationHolder( return new RepresentationHolder(
periodDurationUs, representation, chunkExtractor, segmentNumShift, segmentIndex); periodDurationUs,
representation,
selectedBaseUrl,
chunkExtractor,
segmentNumShift,
segmentIndex);
} }
public long getFirstSegmentNum() { public long getFirstSegmentNum() {
......
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