mirror of
https://github.com/samsonjs/media.git
synced 2026-04-17 13:15:47 +00:00
Pass MediaSource instance through onSourceInfoRefreshed
------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=173382423
This commit is contained in:
parent
88b6df1d08
commit
3c201a0491
18 changed files with 67 additions and 36 deletions
|
|
@ -374,7 +374,7 @@ public final class DynamicConcatenatingMediaSourceTest extends TestCase {
|
|||
private void prepareAndListenToTimelineUpdates(MediaSource mediaSource) {
|
||||
mediaSource.prepareSource(new StubExoPlayer(), true, new Listener() {
|
||||
@Override
|
||||
public void onSourceInfoRefreshed(Timeline newTimeline, Object manifest) {
|
||||
public void onSourceInfoRefreshed(MediaSource source, Timeline newTimeline, Object manifest) {
|
||||
timeline = newTimeline;
|
||||
synchronized (DynamicConcatenatingMediaSourceTest.this) {
|
||||
timelineUpdated = true;
|
||||
|
|
@ -434,7 +434,7 @@ public final class DynamicConcatenatingMediaSourceTest extends TestCase {
|
|||
private Listener listener;
|
||||
|
||||
public void triggerTimelineUpdate(Timeline timeline) {
|
||||
listener.onSourceInfoRefreshed(timeline, null);
|
||||
listener.onSourceInfoRefreshed(this, timeline, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -313,8 +313,9 @@ import java.io.IOException;
|
|||
// MediaSource.Listener implementation.
|
||||
|
||||
@Override
|
||||
public void onSourceInfoRefreshed(Timeline timeline, Object manifest) {
|
||||
handler.obtainMessage(MSG_REFRESH_SOURCE_INFO, Pair.create(timeline, manifest)).sendToTarget();
|
||||
public void onSourceInfoRefreshed(MediaSource source, Timeline timeline, Object manifest) {
|
||||
handler.obtainMessage(MSG_REFRESH_SOURCE_INFO,
|
||||
new MediaSourceRefreshInfo(source, timeline, manifest)).sendToTarget();
|
||||
}
|
||||
|
||||
// MediaPeriod.Callback implementation.
|
||||
|
|
@ -384,7 +385,7 @@ import java.io.IOException;
|
|||
return true;
|
||||
}
|
||||
case MSG_REFRESH_SOURCE_INFO: {
|
||||
handleSourceInfoRefreshed((Pair<Timeline, Object>) msg.obj);
|
||||
handleSourceInfoRefreshed((MediaSourceRefreshInfo) msg.obj);
|
||||
return true;
|
||||
}
|
||||
case MSG_SOURCE_CONTINUE_LOADING_REQUESTED: {
|
||||
|
|
@ -1013,12 +1014,17 @@ import java.io.IOException;
|
|||
}
|
||||
}
|
||||
|
||||
private void handleSourceInfoRefreshed(Pair<Timeline, Object> timelineAndManifest)
|
||||
private void handleSourceInfoRefreshed(MediaSourceRefreshInfo sourceRefreshInfo)
|
||||
throws ExoPlaybackException {
|
||||
if (sourceRefreshInfo.source != mediaSource) {
|
||||
// Stale event.
|
||||
return;
|
||||
}
|
||||
|
||||
Timeline oldTimeline = timeline;
|
||||
timeline = timelineAndManifest.first;
|
||||
timeline = sourceRefreshInfo.timeline;
|
||||
mediaPeriodInfoSequence.setTimeline(timeline);
|
||||
Object manifest = timelineAndManifest.second;
|
||||
Object manifest = sourceRefreshInfo.manifest;
|
||||
|
||||
if (oldTimeline == null) {
|
||||
if (pendingInitialSeekCount > 0) {
|
||||
|
|
@ -1776,4 +1782,18 @@ import java.io.IOException;
|
|||
|
||||
}
|
||||
|
||||
private static final class MediaSourceRefreshInfo {
|
||||
|
||||
public final MediaSource source;
|
||||
public final Timeline timeline;
|
||||
public final Object manifest;
|
||||
|
||||
public MediaSourceRefreshInfo(MediaSource source, Timeline timeline, Object manifest) {
|
||||
this.source = source;
|
||||
this.timeline = timeline;
|
||||
this.manifest = manifest;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -115,8 +115,9 @@ public final class ClippingMediaSource implements MediaSource, MediaSource.Liste
|
|||
// MediaSource.Listener implementation.
|
||||
|
||||
@Override
|
||||
public void onSourceInfoRefreshed(Timeline timeline, Object manifest) {
|
||||
sourceListener.onSourceInfoRefreshed(new ClippingTimeline(timeline, startUs, endUs), manifest);
|
||||
public void onSourceInfoRefreshed(MediaSource source, Timeline timeline, Object manifest) {
|
||||
sourceListener.onSourceInfoRefreshed(this, new ClippingTimeline(timeline, startUs, endUs),
|
||||
manifest);
|
||||
int count = mediaPeriods.size();
|
||||
for (int i = 0; i < count; i++) {
|
||||
mediaPeriods.get(i).setClipping(startUs, endUs);
|
||||
|
|
|
|||
|
|
@ -91,14 +91,15 @@ public final class ConcatenatingMediaSource implements MediaSource {
|
|||
public void prepareSource(ExoPlayer player, boolean isTopLevelSource, Listener listener) {
|
||||
this.listener = listener;
|
||||
if (mediaSources.length == 0) {
|
||||
listener.onSourceInfoRefreshed(Timeline.EMPTY, null);
|
||||
listener.onSourceInfoRefreshed(this, Timeline.EMPTY, null);
|
||||
} else {
|
||||
for (int i = 0; i < mediaSources.length; i++) {
|
||||
if (!duplicateFlags[i]) {
|
||||
final int index = i;
|
||||
mediaSources[i].prepareSource(player, false, new Listener() {
|
||||
@Override
|
||||
public void onSourceInfoRefreshed(Timeline timeline, Object manifest) {
|
||||
public void onSourceInfoRefreshed(MediaSource source, Timeline timeline,
|
||||
Object manifest) {
|
||||
handleSourceInfoRefreshed(index, timeline, manifest);
|
||||
}
|
||||
});
|
||||
|
|
@ -161,7 +162,7 @@ public final class ConcatenatingMediaSource implements MediaSource {
|
|||
}
|
||||
}
|
||||
timeline = new ConcatenatedTimeline(timelines.clone(), isAtomic, shuffleOrder);
|
||||
listener.onSourceInfoRefreshed(timeline, manifests.clone());
|
||||
listener.onSourceInfoRefreshed(this, timeline, manifests.clone());
|
||||
}
|
||||
|
||||
private static boolean[] buildDuplicateFlags(MediaSource[] mediaSources) {
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@
|
|||
*/
|
||||
package com.google.android.exoplayer2.source;
|
||||
|
||||
import android.support.annotation.NonNull;
|
||||
import android.util.Pair;
|
||||
import android.util.SparseIntArray;
|
||||
import com.google.android.exoplayer2.C;
|
||||
|
|
@ -299,8 +300,9 @@ public final class DynamicConcatenatingMediaSource implements MediaSource, ExoPl
|
|||
|
||||
private void maybeNotifyListener() {
|
||||
if (!preventListenerNotification) {
|
||||
listener.onSourceInfoRefreshed(new ConcatenatedTimeline(mediaSourceHolders, windowCount,
|
||||
periodCount, shuffleOrder), null);
|
||||
listener.onSourceInfoRefreshed(this,
|
||||
new ConcatenatedTimeline(mediaSourceHolders, windowCount, periodCount, shuffleOrder),
|
||||
null);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -321,7 +323,7 @@ public final class DynamicConcatenatingMediaSource implements MediaSource, ExoPl
|
|||
mediaSourceHolders.add(newIndex, newMediaSourceHolder);
|
||||
newMediaSourceHolder.mediaSource.prepareSource(player, false, new Listener() {
|
||||
@Override
|
||||
public void onSourceInfoRefreshed(Timeline newTimeline, Object manifest) {
|
||||
public void onSourceInfoRefreshed(MediaSource source, Timeline newTimeline, Object manifest) {
|
||||
updateMediaSourceInternal(newMediaSourceHolder, newTimeline);
|
||||
}
|
||||
});
|
||||
|
|
@ -425,7 +427,7 @@ public final class DynamicConcatenatingMediaSource implements MediaSource, ExoPl
|
|||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(MediaSourceHolder other) {
|
||||
public int compareTo(@NonNull MediaSourceHolder other) {
|
||||
return this.firstPeriodIndexInChild - other.firstPeriodIndexInChild;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -197,7 +197,7 @@ public final class ExtractorMediaSource implements MediaSource, ExtractorMediaPe
|
|||
timelineDurationUs = durationUs;
|
||||
timelineIsSeekable = isSeekable;
|
||||
sourceListener.onSourceInfoRefreshed(
|
||||
new SinglePeriodTimeline(timelineDurationUs, timelineIsSeekable), null);
|
||||
this, new SinglePeriodTimeline(timelineDurationUs, timelineIsSeekable), null);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -63,11 +63,11 @@ public final class LoopingMediaSource implements MediaSource {
|
|||
public void prepareSource(ExoPlayer player, boolean isTopLevelSource, final Listener listener) {
|
||||
childSource.prepareSource(player, false, new Listener() {
|
||||
@Override
|
||||
public void onSourceInfoRefreshed(Timeline timeline, Object manifest) {
|
||||
public void onSourceInfoRefreshed(MediaSource source, Timeline timeline, Object manifest) {
|
||||
childPeriodCount = timeline.getPeriodCount();
|
||||
Timeline loopingTimeline = loopCount != Integer.MAX_VALUE
|
||||
? new LoopingTimeline(timeline, loopCount) : new InfinitelyLoopingTimeline(timeline);
|
||||
listener.onSourceInfoRefreshed(loopingTimeline, manifest);
|
||||
listener.onSourceInfoRefreshed(LoopingMediaSource.this, loopingTimeline, manifest);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -53,7 +53,8 @@ public interface MediaPeriod extends SequenceableLoader {
|
|||
* {@link #maybeThrowPrepareError()} will throw an {@link IOException}.
|
||||
* <p>
|
||||
* If preparation succeeds and results in a source timeline change (e.g. the period duration
|
||||
* becoming known), {@link MediaSource.Listener#onSourceInfoRefreshed(Timeline, Object)} will be
|
||||
* becoming known),
|
||||
* {@link MediaSource.Listener#onSourceInfoRefreshed(MediaSource, Timeline, Object)} will be
|
||||
* called before {@code callback.onPrepared}.
|
||||
*
|
||||
* @param callback Callback to receive updates from this period, including being notified when
|
||||
|
|
|
|||
|
|
@ -46,11 +46,14 @@ public interface MediaSource {
|
|||
|
||||
/**
|
||||
* Called when manifest and/or timeline has been refreshed.
|
||||
* <p>
|
||||
* Called on the playback thread.
|
||||
*
|
||||
* @param source The {@link MediaSource} whose info has been refreshed.
|
||||
* @param timeline The source's timeline.
|
||||
* @param manifest The loaded manifest. May be null.
|
||||
*/
|
||||
void onSourceInfoRefreshed(Timeline timeline, @Nullable Object manifest);
|
||||
void onSourceInfoRefreshed(MediaSource source, Timeline timeline, @Nullable Object manifest);
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -98,7 +98,7 @@ public final class MergingMediaSource implements MediaSource {
|
|||
final int sourceIndex = i;
|
||||
mediaSources[sourceIndex].prepareSource(player, false, new Listener() {
|
||||
@Override
|
||||
public void onSourceInfoRefreshed(Timeline timeline, Object manifest) {
|
||||
public void onSourceInfoRefreshed(MediaSource source, Timeline timeline, Object manifest) {
|
||||
handleSourceInfoRefreshed(sourceIndex, timeline, manifest);
|
||||
}
|
||||
});
|
||||
|
|
@ -152,7 +152,7 @@ public final class MergingMediaSource implements MediaSource {
|
|||
primaryManifest = manifest;
|
||||
}
|
||||
if (pendingTimelineSources.isEmpty()) {
|
||||
listener.onSourceInfoRefreshed(primaryTimeline, primaryManifest);
|
||||
listener.onSourceInfoRefreshed(this, primaryTimeline, primaryManifest);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -86,7 +86,7 @@ public final class SingleSampleMediaSource implements MediaSource {
|
|||
|
||||
@Override
|
||||
public void prepareSource(ExoPlayer player, boolean isTopLevelSource, Listener listener) {
|
||||
listener.onSourceInfoRefreshed(timeline, null);
|
||||
listener.onSourceInfoRefreshed(this, timeline, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -143,7 +143,7 @@ public final class AdsMediaSource implements MediaSource {
|
|||
playerHandler = new Handler();
|
||||
contentMediaSource.prepareSource(player, false, new Listener() {
|
||||
@Override
|
||||
public void onSourceInfoRefreshed(Timeline timeline, Object manifest) {
|
||||
public void onSourceInfoRefreshed(MediaSource source, Timeline timeline, Object manifest) {
|
||||
AdsMediaSource.this.onContentSourceInfoRefreshed(timeline, manifest);
|
||||
}
|
||||
});
|
||||
|
|
@ -187,7 +187,8 @@ public final class AdsMediaSource implements MediaSource {
|
|||
adGroupMediaSources[adGroupIndex][adIndexInAdGroup] = adMediaSource;
|
||||
adMediaSource.prepareSource(player, false, new Listener() {
|
||||
@Override
|
||||
public void onSourceInfoRefreshed(Timeline timeline, Object manifest) {
|
||||
public void onSourceInfoRefreshed(MediaSource source, Timeline timeline,
|
||||
Object manifest) {
|
||||
onAdSourceInfoRefreshed(adGroupIndex, adIndexInAdGroup, timeline);
|
||||
}
|
||||
});
|
||||
|
|
@ -275,7 +276,7 @@ public final class AdsMediaSource implements MediaSource {
|
|||
adPlaybackState.adCounts, adPlaybackState.adsLoadedCounts,
|
||||
adPlaybackState.adsPlayedCounts, adDurationsUs, adPlaybackState.adResumePositionUs,
|
||||
adPlaybackState.contentDurationUs);
|
||||
listener.onSourceInfoRefreshed(timeline, contentManifest);
|
||||
listener.onSourceInfoRefreshed(this, timeline, contentManifest);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -76,8 +76,8 @@ public final class DashMediaSource implements MediaSource {
|
|||
|
||||
/**
|
||||
* The interval in milliseconds between invocations of
|
||||
* {@link MediaSource.Listener#onSourceInfoRefreshed(Timeline, Object)} when the source's
|
||||
* {@link Timeline} is changing dynamically (for example, for incomplete live streams).
|
||||
* {@link MediaSource.Listener#onSourceInfoRefreshed(MediaSource, Timeline, Object)} when the
|
||||
* source's {@link Timeline} is changing dynamically (for example, for incomplete live streams).
|
||||
*/
|
||||
private static final int NOTIFY_MANIFEST_INTERVAL_MS = 5000;
|
||||
/**
|
||||
|
|
@ -527,7 +527,7 @@ public final class DashMediaSource implements MediaSource {
|
|||
DashTimeline timeline = new DashTimeline(manifest.availabilityStartTime, windowStartTimeMs,
|
||||
firstPeriodId, currentStartTimeUs, windowDurationUs, windowDefaultStartPositionUs,
|
||||
manifest);
|
||||
sourceListener.onSourceInfoRefreshed(timeline, manifest);
|
||||
sourceListener.onSourceInfoRefreshed(this, timeline, manifest);
|
||||
|
||||
if (!sideloadedManifest) {
|
||||
// Remove any pending simulated refresh.
|
||||
|
|
|
|||
|
|
@ -179,7 +179,7 @@ public final class HlsMediaSource implements MediaSource,
|
|||
playlist.startTimeUs + playlist.durationUs, playlist.durationUs, playlist.startTimeUs,
|
||||
windowDefaultStartPositionUs, true, false);
|
||||
}
|
||||
sourceListener.onSourceInfoRefreshed(timeline,
|
||||
sourceListener.onSourceInfoRefreshed(this, timeline,
|
||||
new HlsManifest(playlistTracker.getMasterPlaylist(), playlist));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -328,7 +328,7 @@ public final class SsMediaSource implements MediaSource,
|
|||
timeline = new SinglePeriodTimeline(startTimeUs + durationUs, durationUs, startTimeUs, 0,
|
||||
true /* isSeekable */, false /* isDynamic */);
|
||||
}
|
||||
sourceListener.onSourceInfoRefreshed(timeline, manifest);
|
||||
sourceListener.onSourceInfoRefreshed(this, timeline, manifest);
|
||||
}
|
||||
|
||||
private void scheduleManifestRefresh() {
|
||||
|
|
|
|||
|
|
@ -69,7 +69,7 @@ public class FakeMediaSource implements MediaSource {
|
|||
public void prepareSource(ExoPlayer player, boolean isTopLevelSource, Listener listener) {
|
||||
Assert.assertFalse(preparedSource);
|
||||
preparedSource = true;
|
||||
listener.onSourceInfoRefreshed(timeline, manifest);
|
||||
listener.onSourceInfoRefreshed(this, timeline, manifest);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -364,7 +364,8 @@ public class FakeSimpleExoPlayer extends SimpleExoPlayer {
|
|||
// MediaSource.Listener
|
||||
|
||||
@Override
|
||||
public void onSourceInfoRefreshed(final Timeline timeline, final @Nullable Object manifest) {
|
||||
public void onSourceInfoRefreshed(MediaSource source, final Timeline timeline,
|
||||
final @Nullable Object manifest) {
|
||||
if (this.timeline != null) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -141,7 +141,8 @@ public class TestUtil {
|
|||
class TimelineListener implements Listener {
|
||||
private Timeline timeline;
|
||||
@Override
|
||||
public synchronized void onSourceInfoRefreshed(Timeline timeline, Object manifest) {
|
||||
public synchronized void onSourceInfoRefreshed(MediaSource source, Timeline timeline,
|
||||
Object manifest) {
|
||||
this.timeline = timeline;
|
||||
this.notify();
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue