Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support multiple #EXT-X-MAP tags #4164

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,8 @@ public void getNextChunk(HlsMediaChunk previous, long playbackPositionUs, long l
}

DataSpec initDataSpec = null;
Segment initSegment = mediaPlaylist.initializationSegment;
Segment initSegment =
mediaPlaylist.initializationSegments.get(segment.relativeDiscontinuitySequence);
if (initSegment != null) {
Uri initSegmentUri = UriUtil.resolveToUri(mediaPlaylist.baseUri, initSegment.url);
initDataSpec = new DataSpec(initSegmentUri, initSegment.byterangeOffset,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package com.google.android.exoplayer2.source.hls.offline;

import android.net.Uri;
import android.util.SparseArray;
import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.offline.DownloaderConstructorHelper;
import com.google.android.exoplayer2.offline.SegmentDownloader;
Expand Down Expand Up @@ -90,9 +91,9 @@ protected List<Segment> getSegments(DataSource dataSource, HlsMasterPlaylist man
continue;
}

HlsMediaPlaylist.Segment initSegment = mediaPlaylist.initializationSegment;
if (initSegment != null) {
addSegment(segments, mediaPlaylist, initSegment, encryptionKeyUris);
SparseArray<HlsMediaPlaylist.Segment> initSegments = mediaPlaylist.initializationSegments;
for (int i = 0; i < initSegments.size(); i++) {
addSegment(segments, mediaPlaylist, initSegments.valueAt(i), encryptionKeyUris);
}

List<HlsMediaPlaylist.Segment> hlsSegments = mediaPlaylist.segments;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import android.support.annotation.IntDef;
import android.support.annotation.NonNull;
import android.util.SparseArray;
import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.drm.DrmInitData;
import java.lang.annotation.Retention;
Expand Down Expand Up @@ -183,9 +184,9 @@ public int compareTo(@NonNull Long relativeStartTimeUs) {
*/
public final DrmInitData drmInitData;
/**
* The initialization segment, as defined by #EXT-X-MAP.
* The initialization segments, as defined by #EXT-X-MAP.
*/
public final Segment initializationSegment;
public final SparseArray<Segment> initializationSegments;
/**
* The list of segments in the playlist.
*/
Expand All @@ -210,7 +211,7 @@ public int compareTo(@NonNull Long relativeStartTimeUs) {
* @param hasEndTag See {@link #hasEndTag}.
* @param hasProgramDateTime See {@link #hasProgramDateTime}.
* @param drmInitData See {@link #drmInitData}.
* @param initializationSegment See {@link #initializationSegment}.
* @param initializationSegments See {@link #initializationSegments}.
* @param segments See {@link #segments}.
*/
public HlsMediaPlaylist(
Expand All @@ -228,7 +229,7 @@ public HlsMediaPlaylist(
boolean hasEndTag,
boolean hasProgramDateTime,
DrmInitData drmInitData,
Segment initializationSegment,
SparseArray<Segment> initializationSegments,
List<Segment> segments) {
super(baseUri, tags);
this.playlistType = playlistType;
Expand All @@ -242,7 +243,7 @@ public HlsMediaPlaylist(
this.hasEndTag = hasEndTag;
this.hasProgramDateTime = hasProgramDateTime;
this.drmInitData = drmInitData;
this.initializationSegment = initializationSegment;
this.initializationSegments = initializationSegments;
this.segments = Collections.unmodifiableList(segments);
if (!segments.isEmpty()) {
Segment last = segments.get(segments.size() - 1);
Expand Down Expand Up @@ -293,7 +294,7 @@ public long getEndTimeUs() {
public HlsMediaPlaylist copyWith(long startTimeUs, int discontinuitySequence) {
return new HlsMediaPlaylist(playlistType, baseUri, tags, startOffsetUs, startTimeUs, true,
discontinuitySequence, mediaSequence, version, targetDurationUs, hasIndependentSegmentsTag,
hasEndTag, hasProgramDateTime, drmInitData, initializationSegment, segments);
hasEndTag, hasProgramDateTime, drmInitData, initializationSegments, segments);
}

/**
Expand All @@ -308,7 +309,7 @@ public HlsMediaPlaylist copyWithEndTag() {
}
return new HlsMediaPlaylist(playlistType, baseUri, tags, startOffsetUs, startTimeUs,
hasDiscontinuitySequence, discontinuitySequence, mediaSequence, version, targetDurationUs,
hasIndependentSegmentsTag, true, hasProgramDateTime, drmInitData, initializationSegment,
hasIndependentSegmentsTag, true, hasProgramDateTime, drmInitData, initializationSegments,
segments);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import android.net.Uri;
import android.util.Base64;
import android.util.SparseArray;
import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.Format;
import com.google.android.exoplayer2.ParserException;
Expand Down Expand Up @@ -345,7 +346,7 @@ private static HlsMediaPlaylist parseMediaPlaylist(LineIterator iterator, String
long targetDurationUs = C.TIME_UNSET;
boolean hasIndependentSegmentsTag = false;
boolean hasEndTag = false;
Segment initializationSegment = null;
SparseArray<Segment> initializationSegments = new SparseArray<>();
List<Segment> segments = new ArrayList<>();
List<String> tags = new ArrayList<>();

Expand Down Expand Up @@ -392,7 +393,8 @@ private static HlsMediaPlaylist parseMediaPlaylist(LineIterator iterator, String
segmentByteRangeOffset = Long.parseLong(splitByteRange[1]);
}
}
initializationSegment = new Segment(uri, segmentByteRangeOffset, segmentByteRangeLength);
initializationSegments.put(relativeDiscontinuitySequence,
new Segment(uri, segmentByteRangeOffset, segmentByteRangeLength));
segmentByteRangeOffset = 0;
segmentByteRangeLength = C.LENGTH_UNSET;
} else if (line.startsWith(TAG_TARGET_DURATION)) {
Expand Down Expand Up @@ -493,7 +495,7 @@ private static HlsMediaPlaylist parseMediaPlaylist(LineIterator iterator, String
return new HlsMediaPlaylist(playlistType, baseUri, tags, startOffsetUs, playlistStartTimeUs,
hasDiscontinuitySequence, playlistDiscontinuitySequence, mediaSequence, version,
targetDurationUs, hasIndependentSegmentsTag, hasEndTag, playlistStartTimeUs != 0,
drmInitData, initializationSegment, segments);
drmInitData, initializationSegments, segments);
}

private static SchemeData parseWidevineSchemeData(String line, String keyFormat)
Expand Down