mirror of
https://github.com/androidx/media.git
synced 2025-05-16 20:19:57 +08:00
Make HLS and SS chunk iterators private.
They don't need to be accessed publicly and are can be moved into the respective chunk sources. This is the same structure used for Dash. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=209507217
This commit is contained in:
parent
d51b98dd1f
commit
56aecf6614
@ -22,8 +22,10 @@ import com.google.android.exoplayer2.C;
|
||||
import com.google.android.exoplayer2.Format;
|
||||
import com.google.android.exoplayer2.source.BehindLiveWindowException;
|
||||
import com.google.android.exoplayer2.source.TrackGroup;
|
||||
import com.google.android.exoplayer2.source.chunk.BaseMediaChunkIterator;
|
||||
import com.google.android.exoplayer2.source.chunk.Chunk;
|
||||
import com.google.android.exoplayer2.source.chunk.DataChunk;
|
||||
import com.google.android.exoplayer2.source.chunk.MediaChunkIterator;
|
||||
import com.google.android.exoplayer2.source.hls.playlist.HlsMasterPlaylist.HlsUrl;
|
||||
import com.google.android.exoplayer2.source.hls.playlist.HlsMediaPlaylist;
|
||||
import com.google.android.exoplayer2.source.hls.playlist.HlsMediaPlaylist.Segment;
|
||||
@ -554,4 +556,49 @@ import java.util.List;
|
||||
|
||||
}
|
||||
|
||||
/** {@link MediaChunkIterator} wrapping a {@link HlsMediaPlaylist}. */
|
||||
private static final class HlsMediaPlaylistSegmentIterator extends BaseMediaChunkIterator {
|
||||
|
||||
private final HlsMediaPlaylist playlist;
|
||||
private final long startOfPlaylistInPeriodUs;
|
||||
|
||||
/**
|
||||
* Creates iterator.
|
||||
*
|
||||
* @param playlist The {@link HlsMediaPlaylist} to wrap.
|
||||
* @param startOfPlaylistInPeriodUs The start time of the playlist in the period, in
|
||||
* microseconds.
|
||||
* @param chunkIndex The chunk index in the playlist at which the iterator will start.
|
||||
*/
|
||||
public HlsMediaPlaylistSegmentIterator(
|
||||
HlsMediaPlaylist playlist, long startOfPlaylistInPeriodUs, int chunkIndex) {
|
||||
super(/* fromIndex= */ chunkIndex, /* toIndex= */ playlist.segments.size() - 1);
|
||||
this.playlist = playlist;
|
||||
this.startOfPlaylistInPeriodUs = startOfPlaylistInPeriodUs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DataSpec getDataSpec() {
|
||||
checkInBounds();
|
||||
Segment segment = playlist.segments.get((int) getCurrentIndex());
|
||||
Uri chunkUri = UriUtil.resolveToUri(playlist.baseUri, segment.url);
|
||||
return new DataSpec(
|
||||
chunkUri, segment.byterangeOffset, segment.byterangeLength, /* key= */ null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getChunkStartTimeUs() {
|
||||
checkInBounds();
|
||||
Segment segment = playlist.segments.get((int) getCurrentIndex());
|
||||
return startOfPlaylistInPeriodUs + segment.relativeStartTimeUs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getChunkEndTimeUs() {
|
||||
checkInBounds();
|
||||
Segment segment = playlist.segments.get((int) getCurrentIndex());
|
||||
long segmentStartTimeInPeriodUs = startOfPlaylistInPeriodUs + segment.relativeStartTimeUs;
|
||||
return segmentStartTimeInPeriodUs + segment.durationUs;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,67 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2018 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.google.android.exoplayer2.source.hls.playlist;
|
||||
|
||||
import android.net.Uri;
|
||||
import com.google.android.exoplayer2.source.chunk.BaseMediaChunkIterator;
|
||||
import com.google.android.exoplayer2.source.chunk.MediaChunkIterator;
|
||||
import com.google.android.exoplayer2.upstream.DataSpec;
|
||||
import com.google.android.exoplayer2.util.UriUtil;
|
||||
|
||||
/** {@link MediaChunkIterator} wrapping a {@link HlsMediaPlaylist}. */
|
||||
public final class HlsMediaPlaylistSegmentIterator extends BaseMediaChunkIterator {
|
||||
|
||||
private final HlsMediaPlaylist playlist;
|
||||
private final long startOfPlaylistInPeriodUs;
|
||||
|
||||
/**
|
||||
* Creates iterator.
|
||||
*
|
||||
* @param playlist The {@link HlsMediaPlaylist} to wrap.
|
||||
* @param startOfPlaylistInPeriodUs The start time of the playlist in the period, in microseconds.
|
||||
* @param chunkIndex The chunk index in the playlist at which the iterator will start.
|
||||
*/
|
||||
public HlsMediaPlaylistSegmentIterator(
|
||||
HlsMediaPlaylist playlist, long startOfPlaylistInPeriodUs, int chunkIndex) {
|
||||
super(/* fromIndex= */ chunkIndex, /* toIndex= */ playlist.segments.size() - 1);
|
||||
this.playlist = playlist;
|
||||
this.startOfPlaylistInPeriodUs = startOfPlaylistInPeriodUs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DataSpec getDataSpec() {
|
||||
checkInBounds();
|
||||
HlsMediaPlaylist.Segment segment = playlist.segments.get((int) getCurrentIndex());
|
||||
Uri chunkUri = UriUtil.resolveToUri(playlist.baseUri, segment.url);
|
||||
return new DataSpec(
|
||||
chunkUri, segment.byterangeOffset, segment.byterangeLength, /* key= */ null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getChunkStartTimeUs() {
|
||||
checkInBounds();
|
||||
HlsMediaPlaylist.Segment segment = playlist.segments.get((int) getCurrentIndex());
|
||||
return startOfPlaylistInPeriodUs + segment.relativeStartTimeUs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getChunkEndTimeUs() {
|
||||
checkInBounds();
|
||||
HlsMediaPlaylist.Segment segment = playlist.segments.get((int) getCurrentIndex());
|
||||
long segmentStartTimeInPeriodUs = startOfPlaylistInPeriodUs + segment.relativeStartTimeUs;
|
||||
return segmentStartTimeInPeriodUs + segment.durationUs;
|
||||
}
|
||||
}
|
@ -24,11 +24,13 @@ import com.google.android.exoplayer2.extractor.mp4.FragmentedMp4Extractor;
|
||||
import com.google.android.exoplayer2.extractor.mp4.Track;
|
||||
import com.google.android.exoplayer2.extractor.mp4.TrackEncryptionBox;
|
||||
import com.google.android.exoplayer2.source.BehindLiveWindowException;
|
||||
import com.google.android.exoplayer2.source.chunk.BaseMediaChunkIterator;
|
||||
import com.google.android.exoplayer2.source.chunk.Chunk;
|
||||
import com.google.android.exoplayer2.source.chunk.ChunkExtractorWrapper;
|
||||
import com.google.android.exoplayer2.source.chunk.ChunkHolder;
|
||||
import com.google.android.exoplayer2.source.chunk.ContainerMediaChunk;
|
||||
import com.google.android.exoplayer2.source.chunk.MediaChunk;
|
||||
import com.google.android.exoplayer2.source.chunk.MediaChunkIterator;
|
||||
import com.google.android.exoplayer2.source.smoothstreaming.manifest.SsManifest;
|
||||
import com.google.android.exoplayer2.source.smoothstreaming.manifest.SsManifest.StreamElement;
|
||||
import com.google.android.exoplayer2.trackselection.TrackSelection;
|
||||
@ -297,4 +299,42 @@ public class DefaultSsChunkSource implements SsChunkSource {
|
||||
return lastChunkEndTimeUs - playbackPositionUs;
|
||||
}
|
||||
|
||||
/** {@link MediaChunkIterator} wrapping a track of a {@link StreamElement}. */
|
||||
private static final class StreamElementIterator extends BaseMediaChunkIterator {
|
||||
|
||||
private final StreamElement streamElement;
|
||||
private final int trackIndex;
|
||||
|
||||
/**
|
||||
* Creates iterator.
|
||||
*
|
||||
* @param streamElement The {@link StreamElement} to wrap.
|
||||
* @param trackIndex The track index in the stream element.
|
||||
* @param chunkIndex The chunk index at which the iterator will start.
|
||||
*/
|
||||
public StreamElementIterator(StreamElement streamElement, int trackIndex, int chunkIndex) {
|
||||
super(/* fromIndex= */ chunkIndex, /* toIndex= */ streamElement.chunkCount - 1);
|
||||
this.streamElement = streamElement;
|
||||
this.trackIndex = trackIndex;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DataSpec getDataSpec() {
|
||||
checkInBounds();
|
||||
Uri uri = streamElement.buildRequestUri(trackIndex, (int) getCurrentIndex());
|
||||
return new DataSpec(uri);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getChunkStartTimeUs() {
|
||||
checkInBounds();
|
||||
return streamElement.getStartTimeUs((int) getCurrentIndex());
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getChunkEndTimeUs() {
|
||||
long chunkStartTimeUs = getChunkStartTimeUs();
|
||||
return chunkStartTimeUs + streamElement.getChunkDurationUs((int) getCurrentIndex());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -20,9 +20,6 @@ import com.google.android.exoplayer2.C;
|
||||
import com.google.android.exoplayer2.Format;
|
||||
import com.google.android.exoplayer2.offline.FilterableManifest;
|
||||
import com.google.android.exoplayer2.offline.StreamKey;
|
||||
import com.google.android.exoplayer2.source.chunk.BaseMediaChunkIterator;
|
||||
import com.google.android.exoplayer2.source.chunk.MediaChunkIterator;
|
||||
import com.google.android.exoplayer2.upstream.DataSpec;
|
||||
import com.google.android.exoplayer2.util.Assertions;
|
||||
import com.google.android.exoplayer2.util.UriUtil;
|
||||
import com.google.android.exoplayer2.util.Util;
|
||||
@ -51,45 +48,6 @@ public class SsManifest implements FilterableManifest<SsManifest> {
|
||||
}
|
||||
}
|
||||
|
||||
/** {@link MediaChunkIterator} wrapping a track of a {@link StreamElement}. */
|
||||
public static final class StreamElementIterator extends BaseMediaChunkIterator {
|
||||
|
||||
private final StreamElement streamElement;
|
||||
private final int trackIndex;
|
||||
|
||||
/**
|
||||
* Creates iterator.
|
||||
*
|
||||
* @param streamElement The {@link StreamElement} to wrap.
|
||||
* @param trackIndex The track index in the stream element.
|
||||
* @param chunkIndex The chunk index at which the iterator will start.
|
||||
*/
|
||||
public StreamElementIterator(StreamElement streamElement, int trackIndex, int chunkIndex) {
|
||||
super(/* fromIndex= */ chunkIndex, /* toIndex= */ streamElement.chunkCount - 1);
|
||||
this.streamElement = streamElement;
|
||||
this.trackIndex = trackIndex;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DataSpec getDataSpec() {
|
||||
checkInBounds();
|
||||
Uri uri = streamElement.buildRequestUri(trackIndex, (int) getCurrentIndex());
|
||||
return new DataSpec(uri);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getChunkStartTimeUs() {
|
||||
checkInBounds();
|
||||
return streamElement.getStartTimeUs((int) getCurrentIndex());
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getChunkEndTimeUs() {
|
||||
long chunkStartTimeUs = getChunkStartTimeUs();
|
||||
return chunkStartTimeUs + streamElement.getChunkDurationUs((int) getCurrentIndex());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents a StreamIndex element.
|
||||
*/
|
||||
|
Loading…
x
Reference in New Issue
Block a user