mirror of
https://github.com/samsonjs/media.git
synced 2026-04-01 10:35:48 +00:00
Remove further potential flakiness from ExoPlayerTest.
These were caused by two issues: 1. The FakeMediaSource can be updated with a new timeline. The setNewSourceInfo is called from a different thread than prepareSource and both access local variables without synchronization. 2. For multi-window playback, the FakeRenderer claims that isReady and isEnded are both set to false if it read the end of the stream. However isReady should be true because it is able to "render" its data until the end of the stream. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=182785169
This commit is contained in:
parent
d8c61532b6
commit
32e6cf5509
4 changed files with 26 additions and 11 deletions
|
|
@ -1077,7 +1077,7 @@ public final class ExoPlayerTest extends TestCase {
|
|||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
mediaSource.setNewSourceInfo(timeline, /* manifest= */ null);
|
||||
mediaSource.setNewSourceInfo(timeline, /* newManifest= */ null);
|
||||
}
|
||||
})
|
||||
.waitForPlaybackState(Player.STATE_IDLE)
|
||||
|
|
|
|||
|
|
@ -234,7 +234,7 @@ public final class DynamicConcatenatingMediaSourceTest extends TestCase {
|
|||
lazySources[1].setNewSourceInfo(createFakeTimeline(8), null);
|
||||
}
|
||||
});
|
||||
timeline = testRunner.assertTimelineChange();
|
||||
timeline = testRunner.assertTimelineChangeBlocking();
|
||||
TimelineAsserts.assertPeriodCounts(timeline, 1, 9);
|
||||
TimelineAsserts.assertWindowIds(timeline, 111, 999);
|
||||
TimelineAsserts.assertWindowIsDynamic(timeline, false, false);
|
||||
|
|
@ -272,7 +272,7 @@ public final class DynamicConcatenatingMediaSourceTest extends TestCase {
|
|||
lazySources[3].setNewSourceInfo(createFakeTimeline(7), null);
|
||||
}
|
||||
});
|
||||
timeline = testRunner.assertTimelineChange();
|
||||
timeline = testRunner.assertTimelineChangeBlocking();
|
||||
TimelineAsserts.assertPeriodCounts(timeline, 8, 1, 2, 9);
|
||||
TimelineAsserts.assertWindowIds(timeline, 888, 111, 222, 999);
|
||||
TimelineAsserts.assertWindowIsDynamic(timeline, false, false, false, false);
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@
|
|||
*/
|
||||
package com.google.android.exoplayer2.testutil;
|
||||
|
||||
import android.os.Handler;
|
||||
import android.support.annotation.Nullable;
|
||||
import com.google.android.exoplayer2.ExoPlayer;
|
||||
import com.google.android.exoplayer2.Format;
|
||||
|
|
@ -35,15 +36,16 @@ import junit.framework.Assert;
|
|||
*/
|
||||
public class FakeMediaSource implements MediaSource {
|
||||
|
||||
private final Object manifest;
|
||||
private final TrackGroupArray trackGroupArray;
|
||||
private final ArrayList<FakeMediaPeriod> activeMediaPeriods;
|
||||
private final ArrayList<MediaPeriodId> createdMediaPeriods;
|
||||
|
||||
protected Timeline timeline;
|
||||
private Object manifest;
|
||||
private boolean preparedSource;
|
||||
private boolean releasedSource;
|
||||
private Listener listener;
|
||||
private Handler sourceInfoRefreshHandler;
|
||||
|
||||
/**
|
||||
* Creates a {@link FakeMediaSource}. This media source creates {@link FakeMediaPeriod}s with a
|
||||
|
|
@ -71,10 +73,12 @@ public class FakeMediaSource implements MediaSource {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void prepareSource(ExoPlayer player, boolean isTopLevelSource, Listener listener) {
|
||||
public synchronized void prepareSource(
|
||||
ExoPlayer player, boolean isTopLevelSource, Listener listener) {
|
||||
Assert.assertFalse(preparedSource);
|
||||
preparedSource = true;
|
||||
this.listener = listener;
|
||||
sourceInfoRefreshHandler = new Handler();
|
||||
if (timeline != null) {
|
||||
listener.onSourceInfoRefreshed(this, timeline, manifest);
|
||||
}
|
||||
|
|
@ -117,11 +121,22 @@ public class FakeMediaSource implements MediaSource {
|
|||
* Sets a new timeline and manifest. If the source is already prepared, this triggers a source
|
||||
* info refresh message being sent to the listener.
|
||||
*/
|
||||
public void setNewSourceInfo(Timeline newTimeline, Object manifest) {
|
||||
Assert.assertFalse(releasedSource);
|
||||
this.timeline = newTimeline;
|
||||
if (preparedSource) {
|
||||
listener.onSourceInfoRefreshed(this, timeline, manifest);
|
||||
public synchronized void setNewSourceInfo(final Timeline newTimeline, final Object newManifest) {
|
||||
if (sourceInfoRefreshHandler != null) {
|
||||
sourceInfoRefreshHandler.post(
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Assert.assertFalse(releasedSource);
|
||||
Assert.assertTrue(preparedSource);
|
||||
timeline = newTimeline;
|
||||
manifest = newManifest;
|
||||
listener.onSourceInfoRefreshed(FakeMediaSource.this, timeline, manifest);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
timeline = newTimeline;
|
||||
manifest = newManifest;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -73,7 +73,7 @@ public class FakeRenderer extends BaseRenderer {
|
|||
}
|
||||
}
|
||||
}
|
||||
isReady = buffer.timeUs >= positionUs;
|
||||
isReady = buffer.timeUs >= positionUs || hasReadStreamToEnd();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
Loading…
Reference in a new issue