mirror of
https://github.com/samsonjs/media.git
synced 2026-04-01 10:35:48 +00:00
Merge seek/playback positions in ChunkSource interface.
This commit is contained in:
parent
f11a204b4a
commit
6f62b499c5
6 changed files with 23 additions and 22 deletions
|
|
@ -128,7 +128,7 @@ public class DashChunkSourceTest extends InstrumentationTestCase {
|
|||
ChunkOperationHolder out = new ChunkOperationHolder();
|
||||
|
||||
// request first chunk; should get back initialization chunk
|
||||
chunkSource.getChunkOperation(queue, 0, 0, out);
|
||||
chunkSource.getChunkOperation(queue, 0, out);
|
||||
|
||||
assertNotNull(out.chunk);
|
||||
assertNotNull(((InitializationChunk) out.chunk).dataSpec);
|
||||
|
|
@ -386,7 +386,7 @@ public class DashChunkSourceTest extends InstrumentationTestCase {
|
|||
private static void checkLiveEdgeConsistency(DashChunkSource chunkSource, List<MediaChunk> queue,
|
||||
ChunkOperationHolder out, long seekPositionMs, long availableRangeStartMs,
|
||||
long availableRangeEndMs, long chunkStartTimeMs, long chunkEndTimeMs) {
|
||||
chunkSource.getChunkOperation(queue, seekPositionMs * 1000, 0, out);
|
||||
chunkSource.getChunkOperation(queue, seekPositionMs * 1000, out);
|
||||
TimeRange availableRange = chunkSource.getAvailableRange();
|
||||
checkAvailableRange(availableRange, availableRangeStartMs * 1000, availableRangeEndMs * 1000);
|
||||
if (chunkStartTimeMs < availableRangeEndMs) {
|
||||
|
|
@ -487,7 +487,7 @@ public class DashChunkSourceTest extends InstrumentationTestCase {
|
|||
|
||||
// request "eleventh" chunk; this chunk isn't available yet, so we should get null
|
||||
out.chunk = null;
|
||||
chunkSource.getChunkOperation(queue, seekPositionMs * 1000, 0, out);
|
||||
chunkSource.getChunkOperation(queue, seekPositionMs * 1000, out);
|
||||
assertNull(out.chunk);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -533,7 +533,8 @@ public class ChunkSampleSource implements SampleSource, SampleSourceReader, Load
|
|||
private void doChunkOperation() {
|
||||
currentLoadableHolder.endOfStream = false;
|
||||
currentLoadableHolder.queueSize = readOnlyMediaChunks.size();
|
||||
chunkSource.getChunkOperation(readOnlyMediaChunks, pendingResetPositionUs, downstreamPositionUs,
|
||||
chunkSource.getChunkOperation(readOnlyMediaChunks,
|
||||
pendingResetPositionUs != NO_RESET_PENDING ? pendingResetPositionUs : downstreamPositionUs,
|
||||
currentLoadableHolder);
|
||||
loadingFinished = currentLoadableHolder.endOfStream;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -92,9 +92,9 @@ public interface ChunkSource {
|
|||
* This method should only be called when the source is enabled.
|
||||
*
|
||||
* @param queue A representation of the currently buffered {@link MediaChunk}s.
|
||||
* @param seekPositionUs If the queue is empty, this parameter must specify the seek position. If
|
||||
* the queue is non-empty then this parameter is ignored.
|
||||
* @param playbackPositionUs The current playback position.
|
||||
* @param playbackPositionUs The current playback position. If the queue is empty then this
|
||||
* parameter is the position from which playback is expected to start (or restart) and hence
|
||||
* should be interpreted as a seek position.
|
||||
* @param out A holder for the next operation, whose {@link ChunkOperationHolder#endOfStream} is
|
||||
* initially set to false, whose {@link ChunkOperationHolder#queueSize} is initially equal to
|
||||
* the length of the queue, and whose {@link ChunkOperationHolder#chunk} is initially equal to
|
||||
|
|
@ -103,8 +103,8 @@ public interface ChunkSource {
|
|||
* unchanged. Note that leaving the chunk unchanged is both preferred and more efficient than
|
||||
* replacing it with a new but identical chunk.
|
||||
*/
|
||||
void getChunkOperation(List<? extends MediaChunk> queue, long seekPositionUs,
|
||||
long playbackPositionUs, ChunkOperationHolder out);
|
||||
void getChunkOperation(List<? extends MediaChunk> queue, long playbackPositionUs,
|
||||
ChunkOperationHolder out);
|
||||
|
||||
/**
|
||||
* Invoked when the {@link ChunkSampleSource} has finished loading a chunk obtained from this
|
||||
|
|
|
|||
|
|
@ -80,8 +80,8 @@ public final class SingleSampleChunkSource implements ChunkSource {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void getChunkOperation(List<? extends MediaChunk> queue, long seekPositionUs,
|
||||
long playbackPositionUs, ChunkOperationHolder out) {
|
||||
public void getChunkOperation(List<? extends MediaChunk> queue, long playbackPositionUs,
|
||||
ChunkOperationHolder out) {
|
||||
if (!queue.isEmpty()) {
|
||||
// We've already provided the single sample.
|
||||
out.endOfStream = true;
|
||||
|
|
|
|||
|
|
@ -346,8 +346,8 @@ public class DashChunkSource implements ChunkSource, Output {
|
|||
}
|
||||
|
||||
@Override
|
||||
public final void getChunkOperation(List<? extends MediaChunk> queue, long seekPositionUs,
|
||||
long playbackPositionUs, ChunkOperationHolder out) {
|
||||
public final void getChunkOperation(List<? extends MediaChunk> queue, long playbackPositionUs,
|
||||
ChunkOperationHolder out) {
|
||||
if (fatalError != null) {
|
||||
out.chunk = null;
|
||||
return;
|
||||
|
|
@ -389,16 +389,16 @@ public class DashChunkSource implements ChunkSource, Output {
|
|||
if (startAtLiveEdge) {
|
||||
// We want live streams to start at the live edge instead of the beginning of the
|
||||
// manifest
|
||||
seekPositionUs = Math.max(availableRangeValues[0],
|
||||
playbackPositionUs = Math.max(availableRangeValues[0],
|
||||
availableRangeValues[1] - liveEdgeLatencyUs);
|
||||
} else {
|
||||
// we subtract 1 from the upper bound because it's exclusive for that bound
|
||||
seekPositionUs = Math.min(seekPositionUs, availableRangeValues[1] - 1);
|
||||
seekPositionUs = Math.max(seekPositionUs, availableRangeValues[0]);
|
||||
playbackPositionUs = Math.min(playbackPositionUs, availableRangeValues[1] - 1);
|
||||
playbackPositionUs = Math.max(playbackPositionUs, availableRangeValues[0]);
|
||||
}
|
||||
}
|
||||
|
||||
periodHolder = findPeriodHolder(seekPositionUs);
|
||||
periodHolder = findPeriodHolder(playbackPositionUs);
|
||||
startingNewPeriod = true;
|
||||
} else {
|
||||
if (startAtLiveEdge) {
|
||||
|
|
@ -476,7 +476,7 @@ public class DashChunkSource implements ChunkSource, Output {
|
|||
return;
|
||||
}
|
||||
|
||||
int segmentNum = queue.isEmpty() ? representationHolder.getSegmentNum(seekPositionUs)
|
||||
int segmentNum = queue.isEmpty() ? representationHolder.getSegmentNum(playbackPositionUs)
|
||||
: startingNewPeriod ? representationHolder.getFirstAvailableSegmentNum()
|
||||
: queue.get(out.queueSize - 1).chunkIndex + 1;
|
||||
Chunk nextMediaChunk = newMediaChunk(periodHolder, representationHolder, dataSource,
|
||||
|
|
|
|||
|
|
@ -236,8 +236,8 @@ public class SmoothStreamingChunkSource implements ChunkSource,
|
|||
}
|
||||
|
||||
@Override
|
||||
public final void getChunkOperation(List<? extends MediaChunk> queue, long seekPositionUs,
|
||||
long playbackPositionUs, ChunkOperationHolder out) {
|
||||
public final void getChunkOperation(List<? extends MediaChunk> queue, long playbackPositionUs,
|
||||
ChunkOperationHolder out) {
|
||||
if (fatalError != null) {
|
||||
out.chunk = null;
|
||||
return;
|
||||
|
|
@ -281,9 +281,9 @@ public class SmoothStreamingChunkSource implements ChunkSource,
|
|||
int chunkIndex;
|
||||
if (queue.isEmpty()) {
|
||||
if (live) {
|
||||
seekPositionUs = getLiveSeekPosition(currentManifest, liveEdgeLatencyUs);
|
||||
playbackPositionUs = getLiveSeekPosition(currentManifest, liveEdgeLatencyUs);
|
||||
}
|
||||
chunkIndex = streamElement.getChunkIndex(seekPositionUs);
|
||||
chunkIndex = streamElement.getChunkIndex(playbackPositionUs);
|
||||
} else {
|
||||
MediaChunk previous = queue.get(out.queueSize - 1);
|
||||
chunkIndex = previous.chunkIndex + 1 - currentManifestChunkOffset;
|
||||
|
|
|
|||
Loading…
Reference in a new issue