From 7c35e38b4e284b5f5f5b094500a7da02f019a671 Mon Sep 17 00:00:00 2001 From: olly Date: Tue, 5 Apr 2016 07:59:25 -0700 Subject: [PATCH] Fix a few issues with SmoothStreaming in V2. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=119049397 --- .../player/SmoothStreamingSourceBuilder.java | 3 ++- .../SmoothStreamingChunkSource.java | 20 +++++++++++++++---- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/demo/src/main/java/com/google/android/exoplayer/demo/player/SmoothStreamingSourceBuilder.java b/demo/src/main/java/com/google/android/exoplayer/demo/player/SmoothStreamingSourceBuilder.java index e7c45a7954..6be884eecc 100644 --- a/demo/src/main/java/com/google/android/exoplayer/demo/player/SmoothStreamingSourceBuilder.java +++ b/demo/src/main/java/com/google/android/exoplayer/demo/player/SmoothStreamingSourceBuilder.java @@ -32,6 +32,7 @@ import com.google.android.exoplayer.upstream.DataSource; import com.google.android.exoplayer.upstream.DataSourceFactory; import com.google.android.exoplayer.upstream.DefaultAllocator; import com.google.android.exoplayer.util.ManifestFetcher; +import com.google.android.exoplayer.util.Util; import android.net.Uri; import android.os.Handler; @@ -55,7 +56,7 @@ public class SmoothStreamingSourceBuilder implements SourceBuilder { public SmoothStreamingSourceBuilder(DataSourceFactory dataSourceFactory, String url, MediaDrmCallback drmCallback) { this.dataSourceFactory = dataSourceFactory; - this.url = url; + this.url = Util.toLowerInvariant(url).endsWith("/manifest") ? url : url + "/Manifest"; this.drmCallback = drmCallback; } diff --git a/library/src/main/java/com/google/android/exoplayer/smoothstreaming/SmoothStreamingChunkSource.java b/library/src/main/java/com/google/android/exoplayer/smoothstreaming/SmoothStreamingChunkSource.java index 1c9df96849..a6fcc53552 100644 --- a/library/src/main/java/com/google/android/exoplayer/smoothstreaming/SmoothStreamingChunkSource.java +++ b/library/src/main/java/com/google/android/exoplayer/smoothstreaming/SmoothStreamingChunkSource.java @@ -275,10 +275,8 @@ public class SmoothStreamingChunkSource implements ChunkSource { return; } - boolean isLastChunk = !currentManifest.isLive && chunkIndex == streamElement.chunkCount - 1; long chunkStartTimeUs = streamElement.getStartTimeUs(chunkIndex); - long chunkEndTimeUs = isLastChunk ? -1 - : chunkStartTimeUs + streamElement.getChunkDurationUs(chunkIndex); + long chunkEndTimeUs = chunkStartTimeUs + streamElement.getChunkDurationUs(chunkIndex); int currentAbsoluteChunkIndex = chunkIndex + currentManifestChunkOffset; int trackGroupTrackIndex = getTrackGroupTrackIndex(trackGroup, selectedFormat); @@ -325,7 +323,8 @@ public class SmoothStreamingChunkSource implements ChunkSource { extractorWrappers = new ChunkExtractorWrapper[formats.length]; for (int j = 0; j < formats.length; j++) { 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); FragmentedMp4Extractor extractor = new FragmentedMp4Extractor( FragmentedMp4Extractor.FLAG_WORKAROUND_EVERY_VIDEO_FRAME_IS_SYNC_FRAME @@ -430,4 +429,17 @@ public class SmoothStreamingChunkSource implements ChunkSource { 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); + } + } + }