Commit 266c0dce by olly Committed by Oliver Woodman

Add DashTest to V2

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=124831095
parent f4e4fd51
...@@ -135,6 +135,7 @@ public interface AudioTrackRendererEventListener { ...@@ -135,6 +135,7 @@ public interface AudioTrackRendererEventListener {
handler.post(new Runnable() { handler.post(new Runnable() {
@Override @Override
public void run() { public void run() {
counters.ensureUpdated();
listener.onAudioDisabled(counters); listener.onAudioDisabled(counters);
} }
}); });
......
...@@ -34,6 +34,10 @@ public abstract class TrackSelectionPolicy { ...@@ -34,6 +34,10 @@ public abstract class TrackSelectionPolicy {
private InvalidationListener listener; private InvalidationListener listener;
/* package */ final void init(InvalidationListener listener) {
this.listener = listener;
}
/** /**
* Must be invoked by subclasses when a selection parameter has changed, invalidating previous * Must be invoked by subclasses when a selection parameter has changed, invalidating previous
* selections. * selections.
...@@ -55,13 +59,9 @@ public abstract class TrackSelectionPolicy { ...@@ -55,13 +59,9 @@ public abstract class TrackSelectionPolicy {
* defined by the {@link TrackRenderer} {@code FORMAT_*} constants. * defined by the {@link TrackRenderer} {@code FORMAT_*} constants.
* @throws ExoPlaybackException If an error occurs while selecting the tracks. * @throws ExoPlaybackException If an error occurs while selecting the tracks.
*/ */
/* package */ abstract TrackSelection[] selectTracks(TrackRenderer[] renderers, protected abstract TrackSelection[] selectTracks(TrackRenderer[] renderers,
TrackGroupArray[] rendererTrackGroupArrays, int[][][] rendererFormatSupports) TrackGroupArray[] rendererTrackGroupArrays, int[][][] rendererFormatSupports)
throws ExoPlaybackException; throws ExoPlaybackException;
/* package */ void init(InvalidationListener listener) {
this.listener = listener;
}
} }
...@@ -188,6 +188,7 @@ public interface VideoTrackRendererEventListener { ...@@ -188,6 +188,7 @@ public interface VideoTrackRendererEventListener {
handler.post(new Runnable() { handler.post(new Runnable() {
@Override @Override
public void run() { public void run() {
counters.ensureUpdated();
listener.onVideoDisabled(counters); listener.onVideoDisabled(counters);
} }
}); });
......
...@@ -36,6 +36,7 @@ import android.os.Handler; ...@@ -36,6 +36,7 @@ import android.os.Handler;
import android.os.SystemClock; import android.os.SystemClock;
import android.util.Log; import android.util.Log;
import android.view.Surface; import android.view.Surface;
import junit.framework.Assert;
/** /**
* A {@link HostedTest} for {@link ExoPlayer} playback tests. * A {@link HostedTest} for {@link ExoPlayer} playback tests.
...@@ -50,8 +51,12 @@ public abstract class ExoHostedTest implements HostedTest, ExoPlayer.EventListen ...@@ -50,8 +51,12 @@ public abstract class ExoHostedTest implements HostedTest, ExoPlayer.EventListen
AudioTrack.failOnSpuriousAudioTimestamp = true; AudioTrack.failOnSpuriousAudioTimestamp = true;
} }
public static final long MAX_PLAYING_TIME_DISCREPANCY_MS = 2000;
private final String tag; private final String tag;
private final boolean failOnPlayerError; private final boolean fullPlaybackNoSeeking;
private final CodecCounters videoCodecCounters;
private final CodecCounters audioCodecCounters;
private ActionSchedule pendingSchedule; private ActionSchedule pendingSchedule;
private Handler actionHandler; private Handler actionHandler;
...@@ -63,27 +68,19 @@ public abstract class ExoHostedTest implements HostedTest, ExoPlayer.EventListen ...@@ -63,27 +68,19 @@ public abstract class ExoHostedTest implements HostedTest, ExoPlayer.EventListen
private boolean playing; private boolean playing;
private long totalPlayingTimeMs; private long totalPlayingTimeMs;
private long lastPlayingStartTimeMs; private long lastPlayingStartTimeMs;
private long sourceDurationMs;
private CodecCounters videoCodecCounters;
private CodecCounters audioCodecCounters;
/**
* Constructs a test that fails if a player error occurs.
*
* @param tag A tag to use for logging.
*/
public ExoHostedTest(String tag) {
this(tag, true);
}
/** /**
* @param tag A tag to use for logging. * @param tag A tag to use for logging.
* @param failOnPlayerError True if a player error should be considered a test failure. False * @param fullPlaybackNoSeeking Whether the test will play the target media in full without
* otherwise. * seeking. If set to true, the test will assert that the total time spent playing the media
* was within {@link #MAX_PLAYING_TIME_DISCREPANCY_MS} of the media duration.
*/ */
public ExoHostedTest(String tag, boolean failOnPlayerError) { public ExoHostedTest(String tag, boolean fullPlaybackNoSeeking) {
this.tag = tag; this.tag = tag;
this.failOnPlayerError = failOnPlayerError; this.fullPlaybackNoSeeking = fullPlaybackNoSeeking;
videoCodecCounters = new CodecCounters();
audioCodecCounters = new CodecCounters();
} }
/** /**
...@@ -124,6 +121,7 @@ public abstract class ExoHostedTest implements HostedTest, ExoPlayer.EventListen ...@@ -124,6 +121,7 @@ public abstract class ExoHostedTest implements HostedTest, ExoPlayer.EventListen
@Override @Override
public final void onStop() { public final void onStop() {
actionHandler.removeCallbacksAndMessages(null); actionHandler.removeCallbacksAndMessages(null);
sourceDurationMs = player.getDuration();
player.release(); player.release();
player = null; player = null;
} }
...@@ -135,11 +133,20 @@ public abstract class ExoHostedTest implements HostedTest, ExoPlayer.EventListen ...@@ -135,11 +133,20 @@ public abstract class ExoHostedTest implements HostedTest, ExoPlayer.EventListen
@Override @Override
public final void onFinished() { public final void onFinished() {
if (failOnPlayerError && playerError != null) { if (playerError != null) {
throw new Error(playerError); throw new Error(playerError);
} }
logMetrics(); logMetrics(audioCodecCounters, videoCodecCounters);
assertPassed(); if (fullPlaybackNoSeeking) {
// Assert that the playback spanned the correct duration of time.
long minAllowedActualPlayingTimeMs = sourceDurationMs - MAX_PLAYING_TIME_DISCREPANCY_MS;
long maxAllowedActualPlayingTimeMs = sourceDurationMs + MAX_PLAYING_TIME_DISCREPANCY_MS;
Assert.assertTrue("Total playing time: " + totalPlayingTimeMs + ". Actual media duration: "
+ sourceDurationMs, minAllowedActualPlayingTimeMs <= totalPlayingTimeMs
&& totalPlayingTimeMs <= maxAllowedActualPlayingTimeMs);
}
// Make any additional assertions.
assertPassed(audioCodecCounters, videoCodecCounters);
} }
// ExoPlayer.Listener // ExoPlayer.Listener
...@@ -189,14 +196,12 @@ public abstract class ExoHostedTest implements HostedTest, ExoPlayer.EventListen ...@@ -189,14 +196,12 @@ public abstract class ExoHostedTest implements HostedTest, ExoPlayer.EventListen
@Override @Override
public void onAudioFormatChanged(Format format) { public void onAudioFormatChanged(Format format) {
Log.d(tag, "audioFormatChanged [" + format.id + "]"); Log.d(tag, "audioFormatChanged [" + format.id + "]");
if (format != null) {
audioCodecCounters = player.getVideoCodecCounters();
}
} }
@Override @Override
public void onAudioDisabled(CodecCounters counters) { public void onAudioDisabled(CodecCounters counters) {
Log.d(tag, "audioDisabled"); Log.d(tag, "audioDisabled");
audioCodecCounters.merge(counters);
} }
@Override @Override
...@@ -213,14 +218,12 @@ public abstract class ExoHostedTest implements HostedTest, ExoPlayer.EventListen ...@@ -213,14 +218,12 @@ public abstract class ExoHostedTest implements HostedTest, ExoPlayer.EventListen
@Override @Override
public void onVideoFormatChanged(Format format) { public void onVideoFormatChanged(Format format) {
Log.d(tag, "videoFormatChanged [" + format.id + "]"); Log.d(tag, "videoFormatChanged [" + format.id + "]");
if (format != null) {
videoCodecCounters = player.getVideoCodecCounters();
}
} }
@Override @Override
public void onVideoDisabled(CodecCounters counters) { public void onVideoDisabled(CodecCounters counters) {
Log.d(tag, "videoDisabled"); Log.d(tag, "videoDisabled");
videoCodecCounters.merge(counters);
} }
@Override @Override
...@@ -258,36 +261,12 @@ public abstract class ExoHostedTest implements HostedTest, ExoPlayer.EventListen ...@@ -258,36 +261,12 @@ public abstract class ExoHostedTest implements HostedTest, ExoPlayer.EventListen
// Do nothing. Interested subclasses may override. // Do nothing. Interested subclasses may override.
} }
protected void assertPassed() { protected void logMetrics(CodecCounters audioCounters, CodecCounters videoCounters) {
// Do nothing. Subclasses may override to add additional assertions.
}
protected void logMetrics() {
// Do nothing. Subclasses may override to log metrics. // Do nothing. Subclasses may override to log metrics.
} }
// Utility methods and actions for subclasses. protected void assertPassed(CodecCounters audioCounters, CodecCounters videoCounters) {
// Do nothing. Subclasses may override to add additional assertions.
protected final long getTotalPlayingTimeMs() {
return totalPlayingTimeMs;
}
protected final ExoPlaybackException getError() {
return playerError;
}
protected final CodecCounters getLastVideoCodecCounters() {
if (videoCodecCounters != null) {
videoCodecCounters.ensureUpdated();
}
return videoCodecCounters;
}
protected final CodecCounters getLastAudioCodecCounters() {
if (audioCodecCounters != null) {
audioCodecCounters.ensureUpdated();
}
return audioCodecCounters;
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment