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