Skip to content

Commit

Permalink
workaround for google#2748
Browse files Browse the repository at this point in the history
  • Loading branch information
stari4ek committed Aug 3, 2017
1 parent a44c6f0 commit 57a4e4c
Showing 4 changed files with 64 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -19,6 +19,7 @@
import android.os.SystemClock;
import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.Format;
import com.google.android.exoplayer2.extractor.ts.DefaultTsPayloadReaderFactory;
import com.google.android.exoplayer2.source.BehindLiveWindowException;
import com.google.android.exoplayer2.source.TrackGroup;
import com.google.android.exoplayer2.source.chunk.Chunk;
@@ -89,6 +90,11 @@ public void clear() {
private final TrackGroup trackGroup;
private final List<Format> muxedCaptionFormats;

// TVirl: workaround for https://github.com/google/ExoPlayer/issues/2748
@DefaultTsPayloadReaderFactory.Flags
private final int defaultTsReaderFlags;
// !TVirl

private boolean isTimestampMaster;
private byte[] scratchSpace;
private IOException fatalError;
@@ -117,7 +123,9 @@ public void clear() {
*/
public HlsChunkSource(HlsPlaylistTracker playlistTracker, HlsUrl[] variants,
HlsDataSourceFactory dataSourceFactory, TimestampAdjusterProvider timestampAdjusterProvider,
List<Format> muxedCaptionFormats) {
List<Format> muxedCaptionFormats,
// TVirl
@DefaultTsPayloadReaderFactory.Flags int defaultTsReaderFlags) {
this.playlistTracker = playlistTracker;
this.variants = variants;
this.timestampAdjusterProvider = timestampAdjusterProvider;
@@ -132,8 +140,12 @@ public HlsChunkSource(HlsPlaylistTracker playlistTracker, HlsUrl[] variants,
encryptionDataSource = dataSourceFactory.createDataSource(C.DATA_TYPE_DRM);
trackGroup = new TrackGroup(variantFormats);
trackSelection = new InitializationTrackSelection(trackGroup, initialTrackSelection);

// TVirl
this.defaultTsReaderFlags = defaultTsReaderFlags;
}


/**
* If the source is currently having difficulty providing chunks, then this method throws the
* underlying error. Otherwise does nothing.
@@ -307,7 +319,9 @@ public void getNextChunk(HlsMediaChunk previous, long playbackPositionUs, HlsChu
out.chunk = new HlsMediaChunk(mediaDataSource, dataSpec, initDataSpec, selectedUrl,
muxedCaptionFormats, trackSelection.getSelectionReason(), trackSelection.getSelectionData(),
startTimeUs, startTimeUs + segment.durationUs, chunkMediaSequence, discontinuitySequence,
isTimestampMaster, timestampAdjuster, previous, encryptionKey, encryptionIv);
isTimestampMaster, timestampAdjuster, previous, encryptionKey, encryptionIv,
// TVirl
defaultTsReaderFlags);
}

/**
Original file line number Diff line number Diff line change
@@ -92,6 +92,11 @@
private final Id3Decoder id3Decoder;
private final ParsableByteArray id3Data;

// TVirl: workaround for https://github.com/google/ExoPlayer/issues/2748
@DefaultTsPayloadReaderFactory.Flags
private final int defaultTsReaderFlags;
// !TVirl

private Extractor extractor;
private int initSegmentBytesLoaded;
private int bytesLoaded;
@@ -124,7 +129,9 @@ public HlsMediaChunk(DataSource dataSource, DataSpec dataSpec, DataSpec initData
Object trackSelectionData, long startTimeUs, long endTimeUs, int chunkIndex,
int discontinuitySequenceNumber, boolean isMasterTimestampSource,
TimestampAdjuster timestampAdjuster, HlsMediaChunk previousChunk, byte[] encryptionKey,
byte[] encryptionIv) {
byte[] encryptionIv,
// TVirl
@DefaultTsPayloadReaderFactory.Flags int defaultTsReaderFlags) {
super(buildDataSource(dataSource, encryptionKey, encryptionIv), dataSpec, hlsUrl.format,
trackSelectionReason, trackSelectionData, startTimeUs, endTimeUs, chunkIndex);
this.discontinuitySequenceNumber = discontinuitySequenceNumber;
@@ -156,6 +163,9 @@ public HlsMediaChunk(DataSource dataSource, DataSpec dataSpec, DataSpec initData
}
initDataSource = dataSource;
uid = UID_SOURCE.getAndIncrement();

// TVirl
this.defaultTsReaderFlags = defaultTsReaderFlags;
}

/**
@@ -357,7 +367,9 @@ private Extractor createExtractor() {
// MPEG-2 TS segments, but we need a new extractor.
// This flag ensures the change of pid between streams does not affect the sample queues.
@DefaultTsPayloadReaderFactory.Flags
int esReaderFactoryFlags = DefaultTsPayloadReaderFactory.FLAG_IGNORE_SPLICE_INFO_STREAM;
int esReaderFactoryFlags = DefaultTsPayloadReaderFactory.FLAG_IGNORE_SPLICE_INFO_STREAM |
// TVirl
defaultTsReaderFlags;
List<Format> closedCaptionFormats = muxedCaptionFormats;
if (closedCaptionFormats != null) {
// The playlist declares closed caption renditions, we should ignore descriptors.
Original file line number Diff line number Diff line change
@@ -19,6 +19,7 @@
import android.text.TextUtils;
import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.Format;
import com.google.android.exoplayer2.extractor.ts.DefaultTsPayloadReaderFactory;
import com.google.android.exoplayer2.source.AdaptiveMediaSourceEventListener.EventDispatcher;
import com.google.android.exoplayer2.source.CompositeSequenceableLoader;
import com.google.android.exoplayer2.source.MediaPeriod;
@@ -60,8 +61,15 @@ public final class HlsMediaPeriod implements MediaPeriod, HlsSampleStreamWrapper
private HlsSampleStreamWrapper[] enabledSampleStreamWrappers;
private CompositeSequenceableLoader sequenceableLoader;

// TVirl: workaround for https://github.com/google/ExoPlayer/issues/2748
@DefaultTsPayloadReaderFactory.Flags
private final int defaultTsReaderFlags;
// !TVirl

public HlsMediaPeriod(HlsPlaylistTracker playlistTracker, HlsDataSourceFactory dataSourceFactory,
int minLoadableRetryCount, EventDispatcher eventDispatcher, Allocator allocator) {
int minLoadableRetryCount, EventDispatcher eventDispatcher, Allocator allocator,
// TVirl
@DefaultTsPayloadReaderFactory.Flags int defaultTsReaderFlags) {
this.playlistTracker = playlistTracker;
this.dataSourceFactory = dataSourceFactory;
this.minLoadableRetryCount = minLoadableRetryCount;
@@ -72,6 +80,8 @@ public HlsMediaPeriod(HlsPlaylistTracker playlistTracker, HlsDataSourceFactory d
continueLoadingHandler = new Handler();
sampleStreamWrappers = new HlsSampleStreamWrapper[0];
enabledSampleStreamWrappers = new HlsSampleStreamWrapper[0];
// TVirl
this.defaultTsReaderFlags = defaultTsReaderFlags;
}

public void release() {
@@ -344,8 +354,12 @@ private void buildAndPrepareSampleStreamWrappers(long positionUs) {

private HlsSampleStreamWrapper buildSampleStreamWrapper(int trackType, HlsUrl[] variants,
Format muxedAudioFormat, List<Format> muxedCaptionFormats, long positionUs) {

HlsChunkSource defaultChunkSource = new HlsChunkSource(playlistTracker, variants,
dataSourceFactory, timestampAdjusterProvider, muxedCaptionFormats);
dataSourceFactory, timestampAdjusterProvider, muxedCaptionFormats,
// TVirl
defaultTsReaderFlags);

return new HlsSampleStreamWrapper(trackType, this, defaultChunkSource, allocator, positionUs,
muxedAudioFormat, minLoadableRetryCount, eventDispatcher);
}
Original file line number Diff line number Diff line change
@@ -20,6 +20,7 @@
import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.ExoPlayer;
import com.google.android.exoplayer2.ExoPlayerLibraryInfo;
import com.google.android.exoplayer2.extractor.ts.DefaultTsPayloadReaderFactory;
import com.google.android.exoplayer2.source.AdaptiveMediaSourceEventListener;
import com.google.android.exoplayer2.source.AdaptiveMediaSourceEventListener.EventDispatcher;
import com.google.android.exoplayer2.source.MediaPeriod;
@@ -53,6 +54,11 @@ public final class HlsMediaSource implements MediaSource,
private final int minLoadableRetryCount;
private final EventDispatcher eventDispatcher;

// TVirl: workaround for https://github.com/google/ExoPlayer/issues/2748
@DefaultTsPayloadReaderFactory.Flags
private final int defaultTsReaderFlags;
// !TVirl

private HlsPlaylistTracker playlistTracker;
private Listener sourceListener;

@@ -66,16 +72,23 @@ public HlsMediaSource(Uri manifestUri, DataSource.Factory dataSourceFactory,
int minLoadableRetryCount, Handler eventHandler,
AdaptiveMediaSourceEventListener eventListener) {
this(manifestUri, new DefaultHlsDataSourceFactory(dataSourceFactory), minLoadableRetryCount,
eventHandler, eventListener);
eventHandler, eventListener,
// TVirl
0);
}

public HlsMediaSource(Uri manifestUri, HlsDataSourceFactory dataSourceFactory,
int minLoadableRetryCount, Handler eventHandler,
AdaptiveMediaSourceEventListener eventListener) {
AdaptiveMediaSourceEventListener eventListener,
// TVirl
@DefaultTsPayloadReaderFactory.Flags int defaultTsReaderFlags) {
this.manifestUri = manifestUri;
this.dataSourceFactory = dataSourceFactory;
this.minLoadableRetryCount = minLoadableRetryCount;
eventDispatcher = new EventDispatcher(eventHandler, eventListener);

// TVirl
this.defaultTsReaderFlags = defaultTsReaderFlags;
}

@Override
@@ -96,7 +109,9 @@ public void maybeThrowSourceInfoRefreshError() throws IOException {
public MediaPeriod createPeriod(MediaPeriodId id, Allocator allocator) {
Assertions.checkArgument(id.periodIndex == 0);
return new HlsMediaPeriod(playlistTracker, dataSourceFactory, minLoadableRetryCount,
eventDispatcher, allocator);
eventDispatcher, allocator,
// TVirl
defaultTsReaderFlags);
}

@Override

0 comments on commit 57a4e4c

Please # to comment.