mirror of
https://github.com/samsonjs/media.git
synced 2026-04-27 15:07:40 +00:00
Internal refactor.
------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=111746825
This commit is contained in:
parent
bb55fd8e47
commit
aec9657c76
2 changed files with 31 additions and 16 deletions
|
|
@ -43,6 +43,10 @@ public abstract class MediaChunk extends Chunk {
|
||||||
Chunk.NO_PARENT_ID);
|
Chunk.NO_PARENT_ID);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getNextChunkIndex() {
|
||||||
|
return chunkIndex + 1;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param dataSource A {@link DataSource} for loading the data.
|
* @param dataSource A {@link DataSource} for loading the data.
|
||||||
* @param dataSpec Defines the data to be loaded.
|
* @param dataSpec Defines the data to be loaded.
|
||||||
|
|
|
||||||
|
|
@ -424,7 +424,7 @@ public class DashChunkSource implements ChunkSource, Output {
|
||||||
if (previous.parentId == lastPeriodHolder.localIndex) {
|
if (previous.parentId == lastPeriodHolder.localIndex) {
|
||||||
RepresentationHolder representationHolder =
|
RepresentationHolder representationHolder =
|
||||||
lastPeriodHolder.representationHolders.get(previous.format.id);
|
lastPeriodHolder.representationHolders.get(previous.format.id);
|
||||||
if (representationHolder.isLastSegment(previous.chunkIndex)) {
|
if (representationHolder.isBeyondLastSegment(previous.getNextChunkIndex())) {
|
||||||
out.endOfStream = true;
|
out.endOfStream = true;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -443,7 +443,7 @@ public class DashChunkSource implements ChunkSource, Output {
|
||||||
} else if (!periodHolder.isIndexUnbounded()) {
|
} else if (!periodHolder.isIndexUnbounded()) {
|
||||||
RepresentationHolder representationHolder =
|
RepresentationHolder representationHolder =
|
||||||
periodHolder.representationHolders.get(previous.format.id);
|
periodHolder.representationHolders.get(previous.format.id);
|
||||||
if (representationHolder.isLastSegment(previous.chunkIndex)) {
|
if (representationHolder.isBeyondLastSegment(previous.getNextChunkIndex())) {
|
||||||
// We reached the end of a period. Start the next one.
|
// We reached the end of a period. Start the next one.
|
||||||
periodHolder = periodHolders.get(previous.parentId + 1);
|
periodHolder = periodHolders.get(previous.parentId + 1);
|
||||||
startingNewPeriod = true;
|
startingNewPeriod = true;
|
||||||
|
|
@ -478,9 +478,9 @@ public class DashChunkSource implements ChunkSource, Output {
|
||||||
|
|
||||||
int segmentNum = queue.isEmpty() ? representationHolder.getSegmentNum(playbackPositionUs)
|
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).getNextChunkIndex();
|
||||||
Chunk nextMediaChunk = newMediaChunk(periodHolder, representationHolder, dataSource,
|
Chunk nextMediaChunk = newMediaChunk(periodHolder, representationHolder, dataSource,
|
||||||
mediaFormat, segmentNum, evaluation.trigger);
|
mediaFormat, enabledTrack, segmentNum, evaluation.trigger);
|
||||||
lastChunkWasInitialization = false;
|
lastChunkWasInitialization = false;
|
||||||
out.chunk = nextMediaChunk;
|
out.chunk = nextMediaChunk;
|
||||||
}
|
}
|
||||||
|
|
@ -672,8 +672,9 @@ public class DashChunkSource implements ChunkSource, Output {
|
||||||
extractor, manifestIndex);
|
extractor, manifestIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Chunk newMediaChunk(PeriodHolder periodHolder, RepresentationHolder representationHolder,
|
protected Chunk newMediaChunk(
|
||||||
DataSource dataSource, MediaFormat mediaFormat, int segmentNum, int trigger) {
|
PeriodHolder periodHolder, RepresentationHolder representationHolder, DataSource dataSource,
|
||||||
|
MediaFormat mediaFormat, ExposedTrack enabledTrack, int segmentNum, int trigger) {
|
||||||
Representation representation = representationHolder.representation;
|
Representation representation = representationHolder.representation;
|
||||||
Format format = representation.format;
|
Format format = representation.format;
|
||||||
long startTimeUs = representationHolder.getSegmentStartTimeUs(segmentNum);
|
long startTimeUs = representationHolder.getSegmentStartTimeUs(segmentNum);
|
||||||
|
|
@ -802,11 +803,13 @@ public class DashChunkSource implements ChunkSource, Output {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Private classes.
|
// Protected classes.
|
||||||
|
|
||||||
private static final class ExposedTrack {
|
protected static final class ExposedTrack {
|
||||||
|
|
||||||
public final MediaFormat trackFormat;
|
public final MediaFormat trackFormat;
|
||||||
|
public final int adaptiveMaxWidth;
|
||||||
|
public final int adaptiveMaxHeight;
|
||||||
|
|
||||||
private final int adaptationSetIndex;
|
private final int adaptationSetIndex;
|
||||||
|
|
||||||
|
|
@ -815,8 +818,6 @@ public class DashChunkSource implements ChunkSource, Output {
|
||||||
|
|
||||||
// Adaptive track variables.
|
// Adaptive track variables.
|
||||||
private final Format[] adaptiveFormats;
|
private final Format[] adaptiveFormats;
|
||||||
private final int adaptiveMaxWidth;
|
|
||||||
private final int adaptiveMaxHeight;
|
|
||||||
|
|
||||||
public ExposedTrack(MediaFormat trackFormat, int adaptationSetIndex, Format fixedFormat) {
|
public ExposedTrack(MediaFormat trackFormat, int adaptationSetIndex, Format fixedFormat) {
|
||||||
this.trackFormat = trackFormat;
|
this.trackFormat = trackFormat;
|
||||||
|
|
@ -843,8 +844,9 @@ public class DashChunkSource implements ChunkSource, Output {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final class RepresentationHolder {
|
protected static final class RepresentationHolder {
|
||||||
|
|
||||||
|
public final boolean mimeTypeIsRawText;
|
||||||
public final ChunkExtractorWrapper extractorWrapper;
|
public final ChunkExtractorWrapper extractorWrapper;
|
||||||
|
|
||||||
public Representation representation;
|
public Representation representation;
|
||||||
|
|
@ -862,7 +864,8 @@ public class DashChunkSource implements ChunkSource, Output {
|
||||||
this.periodDurationUs = periodDurationUs;
|
this.periodDurationUs = periodDurationUs;
|
||||||
this.representation = representation;
|
this.representation = representation;
|
||||||
String mimeType = representation.format.mimeType;
|
String mimeType = representation.format.mimeType;
|
||||||
extractorWrapper = mimeTypeIsRawText(mimeType) ? null : new ChunkExtractorWrapper(
|
mimeTypeIsRawText = mimeTypeIsRawText(mimeType);
|
||||||
|
extractorWrapper = mimeTypeIsRawText ? null : new ChunkExtractorWrapper(
|
||||||
mimeTypeIsWebm(mimeType) ? new WebmExtractor() : new FragmentedMp4Extractor());
|
mimeTypeIsWebm(mimeType) ? new WebmExtractor() : new FragmentedMp4Extractor());
|
||||||
segmentIndex = representation.getIndex();
|
segmentIndex = representation.getIndex();
|
||||||
}
|
}
|
||||||
|
|
@ -919,10 +922,14 @@ public class DashChunkSource implements ChunkSource, Output {
|
||||||
+ segmentIndex.getDurationUs(segmentNum - segmentNumShift, periodDurationUs);
|
+ segmentIndex.getDurationUs(segmentNum - segmentNumShift, periodDurationUs);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isLastSegment(int segmentNum) {
|
public int getLastSegmentNum() {
|
||||||
int lastSegmentNum = segmentIndex.getLastSegmentNum(periodDurationUs);
|
return segmentIndex.getLastSegmentNum(periodDurationUs);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isBeyondLastSegment(int segmentNum) {
|
||||||
|
int lastSegmentNum = getLastSegmentNum();
|
||||||
return lastSegmentNum == DashSegmentIndex.INDEX_UNBOUNDED ? false
|
return lastSegmentNum == DashSegmentIndex.INDEX_UNBOUNDED ? false
|
||||||
: segmentNum == (lastSegmentNum + segmentNumShift);
|
: segmentNum > (lastSegmentNum + segmentNumShift);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getFirstAvailableSegmentNum() {
|
public int getFirstAvailableSegmentNum() {
|
||||||
|
|
@ -935,7 +942,7 @@ public class DashChunkSource implements ChunkSource, Output {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final class PeriodHolder {
|
protected static final class PeriodHolder {
|
||||||
|
|
||||||
public final int localIndex;
|
public final int localIndex;
|
||||||
public final long startTimeUs;
|
public final long startTimeUs;
|
||||||
|
|
@ -1019,6 +1026,10 @@ public class DashChunkSource implements ChunkSource, Output {
|
||||||
return indexIsExplicit;
|
return indexIsExplicit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public DrmInitData getDrmInitData() {
|
||||||
|
return drmInitData;
|
||||||
|
}
|
||||||
|
|
||||||
// Private methods.
|
// Private methods.
|
||||||
|
|
||||||
private void updateRepresentationIndependentProperties(long periodDurationUs,
|
private void updateRepresentationIndependentProperties(long periodDurationUs,
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue