public MediaPeriodQueueTracker() { mediaPeriodInfoQueue = new ArrayList<>(); mediaPeriodIdToInfo = new HashMap<>(); period = new Period(); timeline = Timeline.EMPTY; }
/** * Creates event logger. * * @param trackSelector The mapping track selector used by the player. May be null if detailed * logging of track mapping is not required. * @param tag The tag used for logging. */ public EventLogger(@Nullable MappingTrackSelector trackSelector, String tag) { this.trackSelector = trackSelector; this.tag = tag; window = new Timeline.Window(); period = new Timeline.Period(); startTimeMs = SystemClock.elapsedRealtime(); }
public EventLogger(MappingTrackSelector trackSelector) { this.trackSelector = trackSelector; window = new Timeline.Window(); period = new Timeline.Period(); startTimeMs = SystemClock.elapsedRealtime(); }
/** * @param castContext The context from which the cast session is obtained. */ public CastPlayer(CastContext castContext) { this.castContext = castContext; timelineTracker = new CastTimelineTracker(); period = new Timeline.Period(); statusListener = new StatusListener(); seekResultCallback = new SeekResultCallback(); listeners = new CopyOnWriteArraySet<>(); SessionManager sessionManager = castContext.getSessionManager(); sessionManager.addSessionManagerListener(statusListener, CastSession.class); CastSession session = sessionManager.getCurrentCastSession(); remoteMediaClient = session != null ? session.getRemoteMediaClient() : null; playbackState = STATE_IDLE; repeatMode = REPEAT_MODE_OFF; currentTimeline = CastTimeline.EMPTY_CAST_TIMELINE; currentTrackGroups = TrackGroupArray.EMPTY; currentTrackSelection = EMPTY_TRACK_SELECTION_ARRAY; pendingSeekWindowIndex = C.INDEX_UNSET; pendingSeekPositionMs = C.TIME_UNSET; updateInternalState(); }
/** * Asserts that the media source reported completed loads via {@link * MediaSourceEventListener#onLoadCompleted(int, MediaPeriodId, LoadEventInfo, MediaLoadData)} for * each specified media period id, and asserts that the associated window index matches the one in * the last known timeline returned from {@link #prepareSource()}, {@link #assertTimelineChange()} * or {@link #assertTimelineChangeBlocking()}. */ public void assertCompletedMediaPeriodLoads(MediaPeriodId... mediaPeriodIds) { Timeline.Period period = new Timeline.Period(); HashSet<MediaPeriodId> expectedLoads = new HashSet<>(Arrays.asList(mediaPeriodIds)); for (Pair<Integer, MediaPeriodId> windowIndexAndMediaPeriodId : completedLoads) { int windowIndex = windowIndexAndMediaPeriodId.first; MediaPeriodId mediaPeriodId = windowIndexAndMediaPeriodId.second; if (expectedLoads.remove(mediaPeriodId)) { int periodIndex = timeline.getIndexOfPeriod(mediaPeriodId.periodUid); assertThat(windowIndex).isEqualTo(timeline.getPeriod(periodIndex, period).windowIndex); } } assertWithMessage("Not all expected media source loads have been completed.") .that(expectedLoads) .isEmpty(); }
private void assertCompletedAllMediaPeriodLoads(Timeline timeline) { Timeline.Period period = new Timeline.Period(); Timeline.Window window = new Timeline.Window(); ArrayList<MediaPeriodId> expectedMediaPeriodIds = new ArrayList<>(); for (int windowIndex = 0; windowIndex < timeline.getWindowCount(); windowIndex++) { timeline.getWindow(windowIndex, window); for (int periodIndex = window.firstPeriodIndex; periodIndex <= window.lastPeriodIndex; periodIndex++) { timeline.getPeriod(periodIndex, period); Object periodUid = timeline.getUidOfPeriod(periodIndex); expectedMediaPeriodIds.add(new MediaPeriodId(periodUid, windowIndex)); for (int adGroupIndex = 0; adGroupIndex < period.getAdGroupCount(); adGroupIndex++) { for (int adIndex = 0; adIndex < period.getAdCountInAdGroup(adGroupIndex); adIndex++) { expectedMediaPeriodIds.add( new MediaPeriodId(periodUid, adGroupIndex, adIndex, windowIndex)); } } } } testRunner.assertCompletedMediaPeriodLoads( expectedMediaPeriodIds.toArray(new MediaPeriodId[0])); }
/** * Creates and releases all periods (including ad periods) defined in the last timeline to be * returned from {@link #prepareSource()}, {@link #assertTimelineChange()} or {@link * #assertTimelineChangeBlocking()}. The {@link MediaPeriodId#windowSequenceNumber} is set to the * index of the window. */ public void assertPrepareAndReleaseAllPeriods() throws InterruptedException { Timeline.Period period = new Timeline.Period(); for (int i = 0; i < timeline.getPeriodCount(); i++) { timeline.getPeriod(i, period, /* setIds= */ true); assertPrepareAndReleasePeriod(new MediaPeriodId(period.uid, period.windowIndex)); for (int adGroupIndex = 0; adGroupIndex < period.getAdGroupCount(); adGroupIndex++) { for (int adIndex = 0; adIndex < period.getAdCountInAdGroup(adGroupIndex); adIndex++) { assertPrepareAndReleasePeriod( new MediaPeriodId(period.uid, adGroupIndex, adIndex, period.windowIndex)); } } } }
/** * Creates and releases all periods (including ad periods) defined in the last timeline to be * returned from {@link #prepareSource()}, {@link #assertTimelineChange()} or {@link * #assertTimelineChangeBlocking()}. The {@link MediaPeriodId#windowSequenceNumber} is set to the * index of the window. */ public void assertPrepareAndReleaseAllPeriods() throws InterruptedException { Timeline.Period period = new Timeline.Period(); for (int i = 0; i < timeline.getPeriodCount(); i++) { timeline.getPeriod(i, period, /* setIds= */ true); assertPrepareAndReleasePeriod(new MediaPeriodId(period.uid, period.windowIndex)); for (int adGroupIndex = 0; adGroupIndex < period.getAdGroupCount(); adGroupIndex++) { for (int adIndex = 0; adIndex < period.getAdCountInAdGroup(adGroupIndex); adIndex++) { assertPrepareAndReleasePeriod( new MediaPeriodId(period.uid, adGroupIndex, adIndex, period.windowIndex)); } } } }
@Override protected FakeMediaPeriod createFakeMediaPeriod( MediaPeriodId id, TrackGroupArray trackGroupArray, Allocator allocator, EventDispatcher eventDispatcher, @Nullable TransferListener transferListener) { Period period = timeline.getPeriodByUid(id.periodUid, new Period()); return new FakeAdaptiveMediaPeriod( trackGroupArray, eventDispatcher, allocator, chunkSourceFactory, period.durationUs, transferListener); }
@Override protected FakeMediaPeriod createFakeMediaPeriod( MediaPeriodId id, TrackGroupArray trackGroupArray, Allocator allocator, EventDispatcher eventDispatcher, @Nullable TransferListener transferListener) { Period period = timeline.getPeriodByUid(id.periodUid, new Period()); return new FakeAdaptiveMediaPeriod( trackGroupArray, eventDispatcher, allocator, chunkSourceFactory, period.durationUs, transferListener); }
@Override public MediaPeriod createPeriod(MediaPeriodId id, Allocator allocator, long startPositionUs) { assertThat(preparedSource).isTrue(); assertThat(releasedSource).isFalse(); int periodIndex = timeline.getIndexOfPeriod(id.periodUid); Assertions.checkArgument(periodIndex != C.INDEX_UNSET); Period period = timeline.getPeriod(periodIndex, new Period()); EventDispatcher eventDispatcher = createEventDispatcher(period.windowIndex, id, period.getPositionInWindowMs()); FakeMediaPeriod mediaPeriod = createFakeMediaPeriod(id, trackGroupArray, allocator, eventDispatcher, transferListener); activeMediaPeriods.add(mediaPeriod); createdMediaPeriods.add(id); return mediaPeriod; }
@Override public MediaPeriod createPeriod(MediaPeriodId id, Allocator allocator, long startPositionUs) { assertThat(preparedSource).isTrue(); assertThat(releasedSource).isFalse(); int periodIndex = timeline.getIndexOfPeriod(id.periodUid); Assertions.checkArgument(periodIndex != C.INDEX_UNSET); Period period = timeline.getPeriod(periodIndex, new Period()); EventDispatcher eventDispatcher = createEventDispatcher(period.windowIndex, id, period.getPositionInWindowMs()); FakeMediaPeriod mediaPeriod = createFakeMediaPeriod(id, trackGroupArray, allocator, eventDispatcher, transferListener); activeMediaPeriods.add(mediaPeriod); createdMediaPeriods.add(id); return mediaPeriod; }
/** Asserts that periods' {@link Period#getAdGroupCount()} are set correctly. */ public static void assertAdGroupCounts(Timeline timeline, int... expectedAdGroupCounts) { Period period = new Period(); for (int i = 0; i < timeline.getPeriodCount(); i++) { timeline.getPeriod(i, period); assertThat(period.getAdGroupCount()).isEqualTo(expectedAdGroupCounts[i]); } } }
/** Creates a new media period queue. */ public MediaPeriodQueue() { period = new Timeline.Period(); window = new Timeline.Window(); timeline = Timeline.EMPTY; }
@Before public void setUp() throws Exception { window = new Window(); period = new Period(); }
@Before public void setUp() throws Exception { window = new Timeline.Window(); period = new Timeline.Period(); }
/** * Asserts that the durations of the periods in the {@link Timeline} and the durations in the * given sequence are equal. */ public static void assertPeriodDurations(Timeline timeline, long... durationsUs) { int periodCount = timeline.getPeriodCount(); assertThat(periodCount).isEqualTo(durationsUs.length); Period period = new Period(); for (int i = 0; i < periodCount; i++) { assertThat(timeline.getPeriod(i, period).durationUs).isEqualTo(durationsUs[i]); } }
/** Asserts that periods' {@link Period#getAdGroupCount()} are set correctly. */ public static void assertAdGroupCounts(Timeline timeline, int... expectedAdGroupCounts) { Period period = new Period(); for (int i = 0; i < timeline.getPeriodCount(); i++) { timeline.getPeriod(i, period); assertThat(period.getAdGroupCount()).isEqualTo(expectedAdGroupCounts[i]); } } }
/** * Asserts that the durations of the periods in the {@link Timeline} and the durations in the * given sequence are equal. */ public static void assertPeriodDurations(Timeline timeline, long... durationsUs) { int periodCount = timeline.getPeriodCount(); assertThat(periodCount).isEqualTo(durationsUs.length); Period period = new Period(); for (int i = 0; i < periodCount; i++) { assertThat(timeline.getPeriod(i, period).durationUs).isEqualTo(durationsUs[i]); } }
public FakePlayer() { listeners = new ArrayList<>(); period = new Timeline.Period(); state = Player.STATE_IDLE; playWhenReady = true; timeline = Timeline.EMPTY; }