mirror of
https://github.com/samsonjs/media.git
synced 2026-04-25 14:47:40 +00:00
Fix a few issues with SmoothStreaming in V2.
------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=119049397
This commit is contained in:
parent
3c1239826c
commit
7c35e38b4e
2 changed files with 18 additions and 5 deletions
|
|
@ -32,6 +32,7 @@ import com.google.android.exoplayer.upstream.DataSource;
|
||||||
import com.google.android.exoplayer.upstream.DataSourceFactory;
|
import com.google.android.exoplayer.upstream.DataSourceFactory;
|
||||||
import com.google.android.exoplayer.upstream.DefaultAllocator;
|
import com.google.android.exoplayer.upstream.DefaultAllocator;
|
||||||
import com.google.android.exoplayer.util.ManifestFetcher;
|
import com.google.android.exoplayer.util.ManifestFetcher;
|
||||||
|
import com.google.android.exoplayer.util.Util;
|
||||||
|
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
|
|
@ -55,7 +56,7 @@ public class SmoothStreamingSourceBuilder implements SourceBuilder {
|
||||||
public SmoothStreamingSourceBuilder(DataSourceFactory dataSourceFactory, String url,
|
public SmoothStreamingSourceBuilder(DataSourceFactory dataSourceFactory, String url,
|
||||||
MediaDrmCallback drmCallback) {
|
MediaDrmCallback drmCallback) {
|
||||||
this.dataSourceFactory = dataSourceFactory;
|
this.dataSourceFactory = dataSourceFactory;
|
||||||
this.url = url;
|
this.url = Util.toLowerInvariant(url).endsWith("/manifest") ? url : url + "/Manifest";
|
||||||
this.drmCallback = drmCallback;
|
this.drmCallback = drmCallback;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -275,10 +275,8 @@ public class SmoothStreamingChunkSource implements ChunkSource {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean isLastChunk = !currentManifest.isLive && chunkIndex == streamElement.chunkCount - 1;
|
|
||||||
long chunkStartTimeUs = streamElement.getStartTimeUs(chunkIndex);
|
long chunkStartTimeUs = streamElement.getStartTimeUs(chunkIndex);
|
||||||
long chunkEndTimeUs = isLastChunk ? -1
|
long chunkEndTimeUs = chunkStartTimeUs + streamElement.getChunkDurationUs(chunkIndex);
|
||||||
: chunkStartTimeUs + streamElement.getChunkDurationUs(chunkIndex);
|
|
||||||
int currentAbsoluteChunkIndex = chunkIndex + currentManifestChunkOffset;
|
int currentAbsoluteChunkIndex = chunkIndex + currentManifestChunkOffset;
|
||||||
|
|
||||||
int trackGroupTrackIndex = getTrackGroupTrackIndex(trackGroup, selectedFormat);
|
int trackGroupTrackIndex = getTrackGroupTrackIndex(trackGroup, selectedFormat);
|
||||||
|
|
@ -325,7 +323,8 @@ public class SmoothStreamingChunkSource implements ChunkSource {
|
||||||
extractorWrappers = new ChunkExtractorWrapper[formats.length];
|
extractorWrappers = new ChunkExtractorWrapper[formats.length];
|
||||||
for (int j = 0; j < formats.length; j++) {
|
for (int j = 0; j < formats.length; j++) {
|
||||||
int nalUnitLengthFieldLength = streamElementType == StreamElement.TYPE_VIDEO ? 4 : -1;
|
int nalUnitLengthFieldLength = streamElementType == StreamElement.TYPE_VIDEO ? 4 : -1;
|
||||||
Track track = new Track(j, streamElementType, timescale, C.UNKNOWN_TIME_US, durationUs,
|
int mp4TrackType = getMp4TrackType(streamElementType);
|
||||||
|
Track track = new Track(j, mp4TrackType, timescale, C.UNKNOWN_TIME_US, durationUs,
|
||||||
formats[j], trackEncryptionBoxes, nalUnitLengthFieldLength, null, null);
|
formats[j], trackEncryptionBoxes, nalUnitLengthFieldLength, null, null);
|
||||||
FragmentedMp4Extractor extractor = new FragmentedMp4Extractor(
|
FragmentedMp4Extractor extractor = new FragmentedMp4Extractor(
|
||||||
FragmentedMp4Extractor.FLAG_WORKAROUND_EVERY_VIDEO_FRAME_IS_SYNC_FRAME
|
FragmentedMp4Extractor.FLAG_WORKAROUND_EVERY_VIDEO_FRAME_IS_SYNC_FRAME
|
||||||
|
|
@ -430,4 +429,17 @@ public class SmoothStreamingChunkSource implements ChunkSource {
|
||||||
data[secondPosition] = temp;
|
data[secondPosition] = temp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static int getMp4TrackType(int streamElementType) {
|
||||||
|
switch (streamElementType) {
|
||||||
|
case StreamElement.TYPE_AUDIO:
|
||||||
|
return Track.TYPE_soun;
|
||||||
|
case StreamElement.TYPE_VIDEO:
|
||||||
|
return Track.TYPE_vide;
|
||||||
|
case StreamElement.TYPE_TEXT:
|
||||||
|
return Track.TYPE_text;
|
||||||
|
default:
|
||||||
|
throw new IllegalArgumentException("Invalid stream type: " + streamElementType);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue