mirror of
https://github.com/samsonjs/media.git
synced 2026-04-01 10:35:48 +00:00
Naming cleanup.
- RollingSampleBuffer -> DefaultTrackOutput - TsChunk -> HlsMediaChunk - Established hls.playlist package for HLS playlist things ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=120325049
This commit is contained in:
parent
69b431b8c2
commit
48bc98f1ed
19 changed files with 102 additions and 95 deletions
|
|
@ -30,10 +30,10 @@ import com.google.android.exoplayer.dash.mpd.MediaPresentationDescriptionParser;
|
|||
import com.google.android.exoplayer.drm.MediaDrmCallback;
|
||||
import com.google.android.exoplayer.extractor.ExtractorSampleSource;
|
||||
import com.google.android.exoplayer.hls.HlsChunkSource;
|
||||
import com.google.android.exoplayer.hls.HlsPlaylist;
|
||||
import com.google.android.exoplayer.hls.HlsPlaylistParser;
|
||||
import com.google.android.exoplayer.hls.HlsSampleSource;
|
||||
import com.google.android.exoplayer.hls.PtsTimestampAdjusterProvider;
|
||||
import com.google.android.exoplayer.hls.playlist.HlsPlaylist;
|
||||
import com.google.android.exoplayer.hls.playlist.HlsPlaylistParser;
|
||||
import com.google.android.exoplayer.smoothstreaming.SmoothStreamingChunkSource;
|
||||
import com.google.android.exoplayer.smoothstreaming.SmoothStreamingManifest;
|
||||
import com.google.android.exoplayer.smoothstreaming.SmoothStreamingManifestParser;
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.google.android.exoplayer.hls;
|
||||
package com.google.android.exoplayer.hls.playlist;
|
||||
|
||||
import com.google.android.exoplayer.C;
|
||||
|
||||
|
|
@ -13,7 +13,7 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.google.android.exoplayer.hls;
|
||||
package com.google.android.exoplayer.hls.playlist;
|
||||
|
||||
import com.google.android.exoplayer.C;
|
||||
|
||||
|
|
@ -17,18 +17,18 @@ package com.google.android.exoplayer.chunk;
|
|||
|
||||
import com.google.android.exoplayer.Format;
|
||||
import com.google.android.exoplayer.drm.DrmInitData;
|
||||
import com.google.android.exoplayer.extractor.RollingSampleBuffer;
|
||||
import com.google.android.exoplayer.extractor.DefaultTrackOutput;
|
||||
import com.google.android.exoplayer.upstream.DataSource;
|
||||
import com.google.android.exoplayer.upstream.DataSpec;
|
||||
|
||||
/**
|
||||
* A base implementation of {@link MediaChunk}, for chunks that contain a single track.
|
||||
* <p>
|
||||
* Loaded samples are output to a {@link RollingSampleBuffer}.
|
||||
* Loaded samples are output to a {@link DefaultTrackOutput}.
|
||||
*/
|
||||
public abstract class BaseMediaChunk extends MediaChunk {
|
||||
|
||||
private RollingSampleBuffer trackOutput;
|
||||
private DefaultTrackOutput trackOutput;
|
||||
private int firstSampleIndex;
|
||||
|
||||
/**
|
||||
|
|
@ -46,19 +46,19 @@ public abstract class BaseMediaChunk extends MediaChunk {
|
|||
}
|
||||
|
||||
/**
|
||||
* Initializes the chunk for loading, setting the {@link RollingSampleBuffer} that will receive
|
||||
* Initializes the chunk for loading, setting the {@link DefaultTrackOutput} that will receive
|
||||
* samples as they are loaded.
|
||||
*
|
||||
* @param trackOutput The output that will receive the loaded samples.
|
||||
*/
|
||||
public void init(RollingSampleBuffer trackOutput) {
|
||||
public void init(DefaultTrackOutput trackOutput) {
|
||||
this.trackOutput = trackOutput;
|
||||
this.firstSampleIndex = trackOutput.getWriteIndex();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the index of the first sample in the output that was passed to
|
||||
* {@link #init(RollingSampleBuffer)} that will originate from this chunk.
|
||||
* {@link #init(DefaultTrackOutput)} that will originate from this chunk.
|
||||
*/
|
||||
public final int getFirstSampleIndex() {
|
||||
return firstSampleIndex;
|
||||
|
|
@ -72,9 +72,9 @@ public abstract class BaseMediaChunk extends MediaChunk {
|
|||
public abstract DrmInitData getDrmInitData();
|
||||
|
||||
/**
|
||||
* Returns the track output most recently passed to {@link #init(RollingSampleBuffer)}.
|
||||
* Returns the track output most recently passed to {@link #init(DefaultTrackOutput)}.
|
||||
*/
|
||||
protected final RollingSampleBuffer getTrackOutput() {
|
||||
protected final DefaultTrackOutput getTrackOutput() {
|
||||
return trackOutput;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ import com.google.android.exoplayer.TrackGroupArray;
|
|||
import com.google.android.exoplayer.TrackSelection;
|
||||
import com.google.android.exoplayer.TrackStream;
|
||||
import com.google.android.exoplayer.chunk.ChunkSampleSourceEventListener.EventDispatcher;
|
||||
import com.google.android.exoplayer.extractor.RollingSampleBuffer;
|
||||
import com.google.android.exoplayer.extractor.DefaultTrackOutput;
|
||||
import com.google.android.exoplayer.upstream.Loader;
|
||||
import com.google.android.exoplayer.upstream.Loader.Loadable;
|
||||
import com.google.android.exoplayer.util.Assertions;
|
||||
|
|
@ -56,7 +56,7 @@ public class ChunkSampleSource implements SampleSource, TrackStream, Loader.Call
|
|||
private final ChunkHolder nextChunkHolder;
|
||||
private final LinkedList<BaseMediaChunk> mediaChunks;
|
||||
private final List<BaseMediaChunk> readOnlyMediaChunks;
|
||||
private final RollingSampleBuffer sampleQueue;
|
||||
private final DefaultTrackOutput sampleQueue;
|
||||
private final int bufferSizeContribution;
|
||||
private final EventDispatcher eventDispatcher;
|
||||
|
||||
|
|
@ -125,7 +125,7 @@ public class ChunkSampleSource implements SampleSource, TrackStream, Loader.Call
|
|||
nextChunkHolder = new ChunkHolder();
|
||||
mediaChunks = new LinkedList<>();
|
||||
readOnlyMediaChunks = Collections.unmodifiableList(mediaChunks);
|
||||
sampleQueue = new RollingSampleBuffer(loadControl.getAllocator());
|
||||
sampleQueue = new DefaultTrackOutput(loadControl.getAllocator());
|
||||
pendingResetPositionUs = C.UNSET_TIME_US;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -19,9 +19,9 @@ import com.google.android.exoplayer.Format;
|
|||
import com.google.android.exoplayer.chunk.ChunkExtractorWrapper.SingleTrackMetadataOutput;
|
||||
import com.google.android.exoplayer.drm.DrmInitData;
|
||||
import com.google.android.exoplayer.extractor.DefaultExtractorInput;
|
||||
import com.google.android.exoplayer.extractor.DefaultTrackOutput;
|
||||
import com.google.android.exoplayer.extractor.Extractor;
|
||||
import com.google.android.exoplayer.extractor.ExtractorInput;
|
||||
import com.google.android.exoplayer.extractor.RollingSampleBuffer;
|
||||
import com.google.android.exoplayer.extractor.SeekMap;
|
||||
import com.google.android.exoplayer.upstream.DataSource;
|
||||
import com.google.android.exoplayer.upstream.DataSpec;
|
||||
|
|
@ -111,7 +111,7 @@ public class ContainerMediaChunk extends BaseMediaChunk implements SingleTrackMe
|
|||
loadDataSpec.absoluteStreamPosition, dataSource.open(loadDataSpec));
|
||||
if (bytesLoaded == 0) {
|
||||
// Set the target to ourselves.
|
||||
RollingSampleBuffer trackOutput = getTrackOutput();
|
||||
DefaultTrackOutput trackOutput = getTrackOutput();
|
||||
trackOutput.formatWithOffset(sampleFormat, sampleOffsetUs);
|
||||
extractorWrapper.init(this, trackOutput);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,8 +19,8 @@ import com.google.android.exoplayer.C;
|
|||
import com.google.android.exoplayer.Format;
|
||||
import com.google.android.exoplayer.drm.DrmInitData;
|
||||
import com.google.android.exoplayer.extractor.DefaultExtractorInput;
|
||||
import com.google.android.exoplayer.extractor.DefaultTrackOutput;
|
||||
import com.google.android.exoplayer.extractor.ExtractorInput;
|
||||
import com.google.android.exoplayer.extractor.RollingSampleBuffer;
|
||||
import com.google.android.exoplayer.upstream.DataSource;
|
||||
import com.google.android.exoplayer.upstream.DataSpec;
|
||||
import com.google.android.exoplayer.util.Util;
|
||||
|
|
@ -91,7 +91,7 @@ public final class SingleSampleMediaChunk extends BaseMediaChunk {
|
|||
length += bytesLoaded;
|
||||
}
|
||||
ExtractorInput extractorInput = new DefaultExtractorInput(dataSource, bytesLoaded, length);
|
||||
RollingSampleBuffer trackOutput = getTrackOutput();
|
||||
DefaultTrackOutput trackOutput = getTrackOutput();
|
||||
trackOutput.formatWithOffset(sampleFormat, 0);
|
||||
// Load the sample data.
|
||||
int result = 0;
|
||||
|
|
|
|||
|
|
@ -29,9 +29,10 @@ import java.nio.ByteBuffer;
|
|||
import java.util.concurrent.LinkedBlockingDeque;
|
||||
|
||||
/**
|
||||
* A rolling buffer of sample data and corresponding sample information.
|
||||
* A {@link TrackOutput} that buffers extracted samples in a queue and allows for consumption from
|
||||
* that queue.
|
||||
*/
|
||||
public final class RollingSampleBuffer implements TrackOutput {
|
||||
public final class DefaultTrackOutput implements TrackOutput {
|
||||
|
||||
private static final int INITIAL_SCRATCH_SIZE = 32;
|
||||
|
||||
|
|
@ -60,7 +61,7 @@ public final class RollingSampleBuffer implements TrackOutput {
|
|||
/**
|
||||
* @param allocator An {@link Allocator} from which allocations for sample data can be obtained.
|
||||
*/
|
||||
public RollingSampleBuffer(Allocator allocator) {
|
||||
public DefaultTrackOutput(Allocator allocator) {
|
||||
this.allocator = allocator;
|
||||
allocationLength = allocator.getIndividualAllocationLength();
|
||||
infoQueue = new InfoQueue();
|
||||
|
|
@ -208,7 +208,7 @@ public final class ExtractorSampleSource implements SampleSource, ExtractorOutpu
|
|||
private boolean prepared;
|
||||
private boolean seenFirstTrackSelection;
|
||||
private int enabledTrackCount;
|
||||
private RollingSampleBuffer[] sampleQueues;
|
||||
private DefaultTrackOutput[] sampleQueues;
|
||||
private TrackGroupArray tracks;
|
||||
private long durationUs;
|
||||
private boolean[] pendingMediaFormat;
|
||||
|
|
@ -324,7 +324,7 @@ public final class ExtractorSampleSource implements SampleSource, ExtractorOutpu
|
|||
}
|
||||
extractorHolder = new ExtractorHolder(extractors, this);
|
||||
pendingResetPositionUs = C.UNSET_TIME_US;
|
||||
sampleQueues = new RollingSampleBuffer[0];
|
||||
sampleQueues = new DefaultTrackOutput[0];
|
||||
}
|
||||
|
||||
// SampleSource implementation.
|
||||
|
|
@ -425,7 +425,7 @@ public final class ExtractorSampleSource implements SampleSource, ExtractorOutpu
|
|||
return pendingResetPositionUs;
|
||||
} else {
|
||||
long largestQueuedTimestampUs = Long.MIN_VALUE;
|
||||
for (RollingSampleBuffer sampleQueue : sampleQueues) {
|
||||
for (DefaultTrackOutput sampleQueue : sampleQueues) {
|
||||
largestQueuedTimestampUs = Math.max(largestQueuedTimestampUs,
|
||||
sampleQueue.getLargestQueuedTimestampUs());
|
||||
}
|
||||
|
|
@ -473,7 +473,7 @@ public final class ExtractorSampleSource implements SampleSource, ExtractorOutpu
|
|||
return TrackStream.NOTHING_READ;
|
||||
}
|
||||
|
||||
RollingSampleBuffer sampleQueue = sampleQueues[track];
|
||||
DefaultTrackOutput sampleQueue = sampleQueues[track];
|
||||
if (pendingMediaFormat[track]) {
|
||||
formatHolder.format = sampleQueue.getUpstreamFormat();
|
||||
formatHolder.drmInitData = drmInitData;
|
||||
|
|
@ -538,7 +538,7 @@ public final class ExtractorSampleSource implements SampleSource, ExtractorOutpu
|
|||
@Override
|
||||
public TrackOutput track(int id) {
|
||||
sampleQueues = Arrays.copyOf(sampleQueues, sampleQueues.length + 1);
|
||||
RollingSampleBuffer sampleQueue = new RollingSampleBuffer(allocator);
|
||||
DefaultTrackOutput sampleQueue = new DefaultTrackOutput(allocator);
|
||||
sampleQueues[sampleQueues.length - 1] = sampleQueue;
|
||||
return sampleQueue;
|
||||
}
|
||||
|
|
@ -634,14 +634,14 @@ public final class ExtractorSampleSource implements SampleSource, ExtractorOutpu
|
|||
|
||||
private int getExtractedSamplesCount() {
|
||||
int extractedSamplesCount = 0;
|
||||
for (RollingSampleBuffer sampleQueue : sampleQueues) {
|
||||
for (DefaultTrackOutput sampleQueue : sampleQueues) {
|
||||
extractedSamplesCount += sampleQueue.getWriteIndex();
|
||||
}
|
||||
return extractedSamplesCount;
|
||||
}
|
||||
|
||||
private boolean haveFormatsForAllTracks() {
|
||||
for (RollingSampleBuffer sampleQueue : sampleQueues) {
|
||||
for (DefaultTrackOutput sampleQueue : sampleQueues) {
|
||||
if (sampleQueue.getUpstreamFormat() == null) {
|
||||
return false;
|
||||
}
|
||||
|
|
@ -664,7 +664,7 @@ public final class ExtractorSampleSource implements SampleSource, ExtractorOutpu
|
|||
}
|
||||
|
||||
private void clearSampleQueues() {
|
||||
for (RollingSampleBuffer sampleQueue : sampleQueues) {
|
||||
for (DefaultTrackOutput sampleQueue : sampleQueues) {
|
||||
sampleQueue.clear();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,6 +28,11 @@ import com.google.android.exoplayer.extractor.mp3.Mp3Extractor;
|
|||
import com.google.android.exoplayer.extractor.ts.AdtsExtractor;
|
||||
import com.google.android.exoplayer.extractor.ts.PtsTimestampAdjuster;
|
||||
import com.google.android.exoplayer.extractor.ts.TsExtractor;
|
||||
import com.google.android.exoplayer.hls.playlist.HlsMasterPlaylist;
|
||||
import com.google.android.exoplayer.hls.playlist.HlsMediaPlaylist;
|
||||
import com.google.android.exoplayer.hls.playlist.HlsPlaylist;
|
||||
import com.google.android.exoplayer.hls.playlist.HlsPlaylistParser;
|
||||
import com.google.android.exoplayer.hls.playlist.Variant;
|
||||
import com.google.android.exoplayer.upstream.DataSource;
|
||||
import com.google.android.exoplayer.upstream.DataSpec;
|
||||
import com.google.android.exoplayer.upstream.HttpDataSource.InvalidResponseCodeException;
|
||||
|
|
@ -325,7 +330,7 @@ public class HlsChunkSource {
|
|||
* should be interpreted as a seek position.
|
||||
* @param out A holder to populate.
|
||||
*/
|
||||
public void getNextChunk(TsChunk previous, long playbackPositionUs, ChunkHolder out) {
|
||||
public void getNextChunk(HlsMediaChunk previous, long playbackPositionUs, ChunkHolder out) {
|
||||
int variantIndex = getNextVariantIndex(previous, playbackPositionUs);
|
||||
boolean switchingVariant = previous != null
|
||||
&& variants[variantIndex].format != previous.format;
|
||||
|
|
@ -450,7 +455,7 @@ public class HlsChunkSource {
|
|||
extractorNeedsInit = false;
|
||||
}
|
||||
|
||||
out.chunk = new TsChunk(dataSource, dataSpec, trigger, format, startTimeUs, endTimeUs,
|
||||
out.chunk = new HlsMediaChunk(dataSource, dataSpec, trigger, format, startTimeUs, endTimeUs,
|
||||
chunkMediaSequence, segment.discontinuitySequenceNumber, extractor, extractorNeedsInit,
|
||||
switchingVariant, encryptionKey, encryptionIv);
|
||||
}
|
||||
|
|
@ -576,7 +581,7 @@ public class HlsChunkSource {
|
|||
return false;
|
||||
}
|
||||
|
||||
private int getNextVariantIndex(TsChunk previous, long playbackPositionUs) {
|
||||
private int getNextVariantIndex(HlsMediaChunk previous, long playbackPositionUs) {
|
||||
clearStaleBlacklistedVariants();
|
||||
if (enabledVariants.length > 1) {
|
||||
long bufferedDurationUs;
|
||||
|
|
|
|||
|
|
@ -27,9 +27,9 @@ import com.google.android.exoplayer.util.Util;
|
|||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* An MPEG2TS chunk.
|
||||
* An HLS {@link MediaChunk}.
|
||||
*/
|
||||
public final class TsChunk extends MediaChunk {
|
||||
/* package */ final class HlsMediaChunk extends MediaChunk {
|
||||
|
||||
/**
|
||||
* The discontinuity sequence number of the chunk.
|
||||
|
|
@ -65,7 +65,7 @@ public final class TsChunk extends MediaChunk {
|
|||
* @param encryptionKey For AES encryption chunks, the encryption key.
|
||||
* @param encryptionIv For AES encryption chunks, the encryption initialization vector.
|
||||
*/
|
||||
public TsChunk(DataSource dataSource, DataSpec dataSpec, int trigger, Format format,
|
||||
public HlsMediaChunk(DataSource dataSource, DataSpec dataSpec, int trigger, Format format,
|
||||
long startTimeUs, long endTimeUs, int chunkIndex, int discontinuitySequenceNumber,
|
||||
Extractor extractor, boolean extractorNeedsInit, boolean shouldSpliceIn,
|
||||
byte[] encryptionKey, byte[] encryptionIv) {
|
||||
|
|
@ -16,8 +16,8 @@
|
|||
package com.google.android.exoplayer.hls;
|
||||
|
||||
import com.google.android.exoplayer.drm.DrmInitData;
|
||||
import com.google.android.exoplayer.extractor.DefaultTrackOutput;
|
||||
import com.google.android.exoplayer.extractor.ExtractorOutput;
|
||||
import com.google.android.exoplayer.extractor.RollingSampleBuffer;
|
||||
import com.google.android.exoplayer.extractor.SeekMap;
|
||||
import com.google.android.exoplayer.upstream.Allocator;
|
||||
|
||||
|
|
@ -29,10 +29,10 @@ import android.util.SparseArray;
|
|||
/* package */ final class HlsOutput implements ExtractorOutput {
|
||||
|
||||
private final Allocator allocator;
|
||||
private final SparseArray<RollingSampleBuffer> sampleQueues = new SparseArray<>();
|
||||
private final SparseArray<DefaultTrackOutput> sampleQueues = new SparseArray<>();
|
||||
|
||||
private boolean prepared;
|
||||
private RollingSampleBuffer[] trackOutputArray;
|
||||
private DefaultTrackOutput[] trackOutputArray;
|
||||
private volatile boolean tracksBuilt;
|
||||
|
||||
public HlsOutput(Allocator allocator) {
|
||||
|
|
@ -53,12 +53,12 @@ import android.util.SparseArray;
|
|||
return false;
|
||||
} else {
|
||||
if (trackOutputArray == null) {
|
||||
trackOutputArray = new RollingSampleBuffer[sampleQueues.size()];
|
||||
trackOutputArray = new DefaultTrackOutput[sampleQueues.size()];
|
||||
for (int i = 0; i < trackOutputArray.length; i++) {
|
||||
trackOutputArray[i] = sampleQueues.valueAt(i);
|
||||
}
|
||||
}
|
||||
for (RollingSampleBuffer sampleQueue : trackOutputArray) {
|
||||
for (DefaultTrackOutput sampleQueue : trackOutputArray) {
|
||||
if (sampleQueue.getUpstreamFormat() == null) {
|
||||
return false;
|
||||
}
|
||||
|
|
@ -71,7 +71,7 @@ import android.util.SparseArray;
|
|||
/**
|
||||
* Returns the array of track outputs, or null if the output is not yet prepared.
|
||||
*/
|
||||
public RollingSampleBuffer[] getTrackOutputs() {
|
||||
public DefaultTrackOutput[] getTrackOutputs() {
|
||||
return trackOutputArray;
|
||||
}
|
||||
|
||||
|
|
@ -98,11 +98,11 @@ import android.util.SparseArray;
|
|||
// ExtractorOutput implementation. Called by the loading thread.
|
||||
|
||||
@Override
|
||||
public RollingSampleBuffer track(int id) {
|
||||
public DefaultTrackOutput track(int id) {
|
||||
if (sampleQueues.indexOfKey(id) >= 0) {
|
||||
return sampleQueues.get(id);
|
||||
}
|
||||
RollingSampleBuffer trackOutput = new RollingSampleBuffer(allocator);
|
||||
DefaultTrackOutput trackOutput = new DefaultTrackOutput(allocator);
|
||||
sampleQueues.put(id, trackOutput);
|
||||
return trackOutput;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ import com.google.android.exoplayer.chunk.Chunk;
|
|||
import com.google.android.exoplayer.chunk.ChunkHolder;
|
||||
import com.google.android.exoplayer.chunk.ChunkSampleSourceEventListener;
|
||||
import com.google.android.exoplayer.chunk.ChunkSampleSourceEventListener.EventDispatcher;
|
||||
import com.google.android.exoplayer.extractor.RollingSampleBuffer;
|
||||
import com.google.android.exoplayer.extractor.DefaultTrackOutput;
|
||||
import com.google.android.exoplayer.upstream.Loader;
|
||||
import com.google.android.exoplayer.upstream.Loader.Loadable;
|
||||
import com.google.android.exoplayer.util.Assertions;
|
||||
|
|
@ -60,7 +60,7 @@ public final class HlsSampleSource implements SampleSource, Loader.Callback {
|
|||
|
||||
private final Loader loader;
|
||||
private final HlsChunkSource chunkSource;
|
||||
private final LinkedList<TsChunk> tsChunks = new LinkedList<TsChunk>();
|
||||
private final LinkedList<HlsMediaChunk> mediaChunks = new LinkedList<HlsMediaChunk>();
|
||||
private final HlsOutput output;
|
||||
private final int bufferSizeContribution;
|
||||
private final ChunkHolder nextChunkHolder;
|
||||
|
|
@ -71,7 +71,7 @@ public final class HlsSampleSource implements SampleSource, Loader.Callback {
|
|||
private boolean seenFirstTrackSelection;
|
||||
private int enabledTrackCount;
|
||||
|
||||
private RollingSampleBuffer[] trackOutputs;
|
||||
private DefaultTrackOutput[] sampleQueues;
|
||||
private Format downstreamFormat;
|
||||
|
||||
// Tracks are complicated in HLS. See documentation of buildTracks for details.
|
||||
|
|
@ -89,8 +89,8 @@ public final class HlsSampleSource implements SampleSource, Loader.Callback {
|
|||
|
||||
private boolean loadingFinished;
|
||||
private Chunk currentLoadable;
|
||||
private TsChunk currentTsLoadable;
|
||||
private TsChunk previousTsLoadable;
|
||||
private HlsMediaChunk currentMediaChunkLoadable;
|
||||
private HlsMediaChunk previousMediaChunkLoadable;
|
||||
|
||||
private long currentLoadStartTimeMs;
|
||||
|
||||
|
|
@ -135,7 +135,7 @@ public final class HlsSampleSource implements SampleSource, Loader.Callback {
|
|||
return true;
|
||||
}
|
||||
if (output.prepare()) {
|
||||
trackOutputs = output.getTrackOutputs();
|
||||
sampleQueues = output.getTrackOutputs();
|
||||
buildTracks();
|
||||
prepared = true;
|
||||
return true;
|
||||
|
|
@ -231,14 +231,14 @@ public final class HlsSampleSource implements SampleSource, Loader.Callback {
|
|||
return C.END_OF_SOURCE_US;
|
||||
} else {
|
||||
long bufferedPositionUs = downstreamPositionUs;
|
||||
if (previousTsLoadable != null) {
|
||||
if (previousMediaChunkLoadable != null) {
|
||||
// Buffered position should be at least as large as the end time of the previously loaded
|
||||
// chunk.
|
||||
bufferedPositionUs = Math.max(previousTsLoadable.endTimeUs, bufferedPositionUs);
|
||||
bufferedPositionUs = Math.max(previousMediaChunkLoadable.endTimeUs, bufferedPositionUs);
|
||||
}
|
||||
for (RollingSampleBuffer trackOutput : trackOutputs) {
|
||||
for (DefaultTrackOutput sampleQueue : sampleQueues) {
|
||||
bufferedPositionUs = Math.max(bufferedPositionUs,
|
||||
trackOutput.getLargestQueuedTimestampUs());
|
||||
sampleQueue.getLargestQueuedTimestampUs());
|
||||
}
|
||||
return bufferedPositionUs;
|
||||
}
|
||||
|
|
@ -268,7 +268,7 @@ public final class HlsSampleSource implements SampleSource, Loader.Callback {
|
|||
if (isPendingReset()) {
|
||||
return false;
|
||||
}
|
||||
return !trackOutputs[group].isEmpty();
|
||||
return !sampleQueues[group].isEmpty();
|
||||
}
|
||||
|
||||
/* package */ void maybeThrowError() throws IOException {
|
||||
|
|
@ -289,7 +289,7 @@ public final class HlsSampleSource implements SampleSource, Loader.Callback {
|
|||
return TrackStream.NOTHING_READ;
|
||||
}
|
||||
|
||||
TsChunk currentChunk = tsChunks.getFirst();
|
||||
HlsMediaChunk currentChunk = mediaChunks.getFirst();
|
||||
Format currentFormat = currentChunk.format;
|
||||
if (downstreamFormat == null || !downstreamFormat.equals(currentFormat)) {
|
||||
eventDispatcher.downstreamFormatChanged(currentFormat, currentChunk.trigger,
|
||||
|
|
@ -297,7 +297,7 @@ public final class HlsSampleSource implements SampleSource, Loader.Callback {
|
|||
downstreamFormat = currentFormat;
|
||||
}
|
||||
|
||||
RollingSampleBuffer sampleQueue = trackOutputs[group];
|
||||
DefaultTrackOutput sampleQueue = sampleQueues[group];
|
||||
if (sampleQueue.isEmpty()) {
|
||||
if (loadingFinished) {
|
||||
buffer.addFlag(C.BUFFER_FLAG_END_OF_STREAM);
|
||||
|
|
@ -315,8 +315,8 @@ public final class HlsSampleSource implements SampleSource, Loader.Callback {
|
|||
|
||||
if (sampleQueue.readSample(buffer)) {
|
||||
long sampleTimeUs = buffer.timeUs;
|
||||
while (tsChunks.size() > 1 && tsChunks.get(1).startTimeUs <= sampleTimeUs) {
|
||||
tsChunks.removeFirst();
|
||||
while (mediaChunks.size() > 1 && mediaChunks.get(1).startTimeUs <= sampleTimeUs) {
|
||||
mediaChunks.removeFirst();
|
||||
}
|
||||
if (sampleTimeUs < lastSeekPositionUs) {
|
||||
buffer.addFlag(C.BUFFER_FLAG_DECODE_ONLY);
|
||||
|
|
@ -335,12 +335,13 @@ public final class HlsSampleSource implements SampleSource, Loader.Callback {
|
|||
long now = SystemClock.elapsedRealtime();
|
||||
long loadDurationMs = now - currentLoadStartTimeMs;
|
||||
chunkSource.onChunkLoadCompleted(currentLoadable);
|
||||
if (isTsChunk(currentLoadable)) {
|
||||
Assertions.checkState(currentLoadable == currentTsLoadable);
|
||||
previousTsLoadable = currentTsLoadable;
|
||||
eventDispatcher.loadCompleted(currentLoadable.bytesLoaded(), currentTsLoadable.type,
|
||||
currentTsLoadable.trigger, currentTsLoadable.format, currentTsLoadable.startTimeUs,
|
||||
currentTsLoadable.endTimeUs, now, loadDurationMs);
|
||||
if (isMediaChunk(currentLoadable)) {
|
||||
Assertions.checkState(currentLoadable == currentMediaChunkLoadable);
|
||||
previousMediaChunkLoadable = currentMediaChunkLoadable;
|
||||
eventDispatcher.loadCompleted(currentLoadable.bytesLoaded(), currentMediaChunkLoadable.type,
|
||||
currentMediaChunkLoadable.trigger, currentMediaChunkLoadable.format,
|
||||
currentMediaChunkLoadable.startTimeUs, currentMediaChunkLoadable.endTimeUs, now,
|
||||
loadDurationMs);
|
||||
} else {
|
||||
eventDispatcher.loadCompleted(currentLoadable.bytesLoaded(), currentLoadable.type,
|
||||
currentLoadable.trigger, currentLoadable.format, -1, -1, now, loadDurationMs);
|
||||
|
|
@ -363,12 +364,12 @@ public final class HlsSampleSource implements SampleSource, Loader.Callback {
|
|||
@Override
|
||||
public int onLoadError(Loadable loadable, IOException e) {
|
||||
long bytesLoaded = currentLoadable.bytesLoaded();
|
||||
boolean cancelable = !isTsChunk(currentLoadable) || bytesLoaded == 0;
|
||||
boolean cancelable = !isMediaChunk(currentLoadable) || bytesLoaded == 0;
|
||||
if (chunkSource.onChunkLoadError(currentLoadable, cancelable, e)) {
|
||||
eventDispatcher.loadError(e);
|
||||
eventDispatcher.loadCanceled(bytesLoaded);
|
||||
clearCurrentLoadable();
|
||||
if (previousTsLoadable == null && !isPendingReset()) {
|
||||
if (previousMediaChunkLoadable == null && !isPendingReset()) {
|
||||
pendingResetPositionUs = lastSeekPositionUs;
|
||||
}
|
||||
maybeStartLoading();
|
||||
|
|
@ -415,9 +416,9 @@ public final class HlsSampleSource implements SampleSource, Loader.Callback {
|
|||
// of the single track of this type.
|
||||
int primaryExtractorTrackType = PRIMARY_TYPE_NONE;
|
||||
int primaryExtractorTrackIndex = -1;
|
||||
int extractorTrackCount = trackOutputs.length;
|
||||
int extractorTrackCount = sampleQueues.length;
|
||||
for (int i = 0; i < extractorTrackCount; i++) {
|
||||
String sampleMimeType = trackOutputs[i].getUpstreamFormat().sampleMimeType;
|
||||
String sampleMimeType = sampleQueues[i].getUpstreamFormat().sampleMimeType;
|
||||
int trackType;
|
||||
if (MimeTypes.isVideo(sampleMimeType)) {
|
||||
trackType = PRIMARY_TYPE_VIDEO;
|
||||
|
|
@ -450,7 +451,7 @@ public final class HlsSampleSource implements SampleSource, Loader.Callback {
|
|||
// Construct the set of exposed track groups.
|
||||
TrackGroup[] trackGroups = new TrackGroup[extractorTrackCount];
|
||||
for (int i = 0; i < extractorTrackCount; i++) {
|
||||
Format sampleFormat = trackOutputs[i].getUpstreamFormat();
|
||||
Format sampleFormat = sampleQueues[i].getUpstreamFormat();
|
||||
if (i == primaryExtractorTrackIndex) {
|
||||
Format[] formats = new Format[chunkSourceTrackCount];
|
||||
for (int j = 0; j < chunkSourceTrackCount; j++) {
|
||||
|
|
@ -522,7 +523,7 @@ public final class HlsSampleSource implements SampleSource, Loader.Callback {
|
|||
}
|
||||
for (int i = 0; i < groupEnabledStates.length; i++) {
|
||||
if (!groupEnabledStates[i]) {
|
||||
trackOutputs[i].skipAllSamples();
|
||||
sampleQueues[i].skipAllSamples();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -539,14 +540,14 @@ public final class HlsSampleSource implements SampleSource, Loader.Callback {
|
|||
}
|
||||
|
||||
private void clearState() {
|
||||
tsChunks.clear();
|
||||
mediaChunks.clear();
|
||||
output.clear();
|
||||
clearCurrentLoadable();
|
||||
previousTsLoadable = null;
|
||||
previousMediaChunkLoadable = null;
|
||||
}
|
||||
|
||||
private void clearCurrentLoadable() {
|
||||
currentTsLoadable = null;
|
||||
currentMediaChunkLoadable = null;
|
||||
currentLoadable = null;
|
||||
}
|
||||
|
||||
|
|
@ -557,7 +558,7 @@ public final class HlsSampleSource implements SampleSource, Loader.Callback {
|
|||
return;
|
||||
}
|
||||
|
||||
chunkSource.getNextChunk(previousTsLoadable,
|
||||
chunkSource.getNextChunk(previousMediaChunkLoadable,
|
||||
pendingResetPositionUs != C.UNSET_TIME_US ? pendingResetPositionUs : downstreamPositionUs,
|
||||
nextChunkHolder);
|
||||
boolean endOfStream = nextChunkHolder.endOfStream;
|
||||
|
|
@ -578,16 +579,16 @@ public final class HlsSampleSource implements SampleSource, Loader.Callback {
|
|||
|
||||
currentLoadStartTimeMs = SystemClock.elapsedRealtime();
|
||||
currentLoadable = nextLoadable;
|
||||
if (isTsChunk(currentLoadable)) {
|
||||
TsChunk tsChunk = (TsChunk) currentLoadable;
|
||||
if (isMediaChunk(currentLoadable)) {
|
||||
HlsMediaChunk mediaChunk = (HlsMediaChunk) currentLoadable;
|
||||
if (isPendingReset()) {
|
||||
pendingResetPositionUs = C.UNSET_TIME_US;
|
||||
}
|
||||
tsChunk.init(output);
|
||||
tsChunks.addLast(tsChunk);
|
||||
eventDispatcher.loadStarted(tsChunk.dataSpec.length, tsChunk.type, tsChunk.trigger,
|
||||
tsChunk.format, tsChunk.startTimeUs, tsChunk.endTimeUs);
|
||||
currentTsLoadable = tsChunk;
|
||||
mediaChunk.init(output);
|
||||
mediaChunks.addLast(mediaChunk);
|
||||
eventDispatcher.loadStarted(mediaChunk.dataSpec.length, mediaChunk.type, mediaChunk.trigger,
|
||||
mediaChunk.format, mediaChunk.startTimeUs, mediaChunk.endTimeUs);
|
||||
currentMediaChunkLoadable = mediaChunk;
|
||||
} else {
|
||||
eventDispatcher.loadStarted(currentLoadable.dataSpec.length, currentLoadable.type,
|
||||
currentLoadable.trigger, currentLoadable.format, -1, -1);
|
||||
|
|
@ -607,13 +608,13 @@ public final class HlsSampleSource implements SampleSource, Loader.Callback {
|
|||
if (isPendingReset()) {
|
||||
return pendingResetPositionUs;
|
||||
} else {
|
||||
return loadingFinished ? C.UNSET_TIME_US : (currentTsLoadable != null
|
||||
? currentTsLoadable.endTimeUs : previousTsLoadable.endTimeUs);
|
||||
return loadingFinished ? C.UNSET_TIME_US : (currentMediaChunkLoadable != null
|
||||
? currentMediaChunkLoadable.endTimeUs : previousMediaChunkLoadable.endTimeUs);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isTsChunk(Chunk chunk) {
|
||||
return chunk instanceof TsChunk;
|
||||
private boolean isMediaChunk(Chunk chunk) {
|
||||
return chunk instanceof HlsMediaChunk;
|
||||
}
|
||||
|
||||
private boolean isPendingReset() {
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.google.android.exoplayer.hls;
|
||||
package com.google.android.exoplayer.hls.playlist;
|
||||
|
||||
import com.google.android.exoplayer.Format;
|
||||
|
||||
|
|
@ -13,7 +13,7 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.google.android.exoplayer.hls;
|
||||
package com.google.android.exoplayer.hls.playlist;
|
||||
|
||||
import com.google.android.exoplayer.C;
|
||||
|
||||
|
|
@ -13,7 +13,7 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.google.android.exoplayer.hls;
|
||||
package com.google.android.exoplayer.hls.playlist;
|
||||
|
||||
import com.google.android.exoplayer.ParserException;
|
||||
|
||||
|
|
@ -13,15 +13,15 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.google.android.exoplayer.hls;
|
||||
package com.google.android.exoplayer.hls.playlist;
|
||||
|
||||
/**
|
||||
* Represents an HLS playlist.
|
||||
*/
|
||||
public abstract class HlsPlaylist {
|
||||
|
||||
public final static int TYPE_MASTER = 0;
|
||||
public final static int TYPE_MEDIA = 1;
|
||||
public static final int TYPE_MASTER = 0;
|
||||
public static final int TYPE_MEDIA = 1;
|
||||
|
||||
public final String baseUri;
|
||||
public final int type;
|
||||
|
|
@ -13,12 +13,12 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.google.android.exoplayer.hls;
|
||||
package com.google.android.exoplayer.hls.playlist;
|
||||
|
||||
import com.google.android.exoplayer.C;
|
||||
import com.google.android.exoplayer.Format;
|
||||
import com.google.android.exoplayer.ParserException;
|
||||
import com.google.android.exoplayer.hls.HlsMediaPlaylist.Segment;
|
||||
import com.google.android.exoplayer.hls.playlist.HlsMediaPlaylist.Segment;
|
||||
import com.google.android.exoplayer.upstream.UriLoadable;
|
||||
import com.google.android.exoplayer.util.MimeTypes;
|
||||
|
||||
|
|
@ -13,7 +13,7 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.google.android.exoplayer.hls;
|
||||
package com.google.android.exoplayer.hls.playlist;
|
||||
|
||||
import com.google.android.exoplayer.Format;
|
||||
|
||||
Loading…
Reference in a new issue