mirror of
https://github.com/samsonjs/media.git
synced 2026-04-27 15:07:40 +00:00
Add HlsTest to V2.
The ones that are commented out are legitimately broken and will need a library fix. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=124978438
This commit is contained in:
parent
e9f9df8faa
commit
aab551e907
2 changed files with 57 additions and 22 deletions
|
|
@ -266,23 +266,25 @@ public interface FormatEvaluator {
|
||||||
public void evaluateFormat(long bufferedDurationUs, boolean[] blacklistFlags,
|
public void evaluateFormat(long bufferedDurationUs, boolean[] blacklistFlags,
|
||||||
Evaluation evaluation) {
|
Evaluation evaluation) {
|
||||||
Format current = evaluation.format;
|
Format current = evaluation.format;
|
||||||
Format ideal = determineIdealFormat(formats, blacklistFlags,
|
Format selected = determineIdealFormat(formats, blacklistFlags,
|
||||||
bandwidthMeter.getBitrateEstimate());
|
bandwidthMeter.getBitrateEstimate());
|
||||||
boolean isHigher = current != null && ideal.bitrate > current.bitrate;
|
if (current != null && isEnabledFormat(current, blacklistFlags)) {
|
||||||
boolean isLower = current != null && ideal.bitrate < current.bitrate;
|
if (selected.bitrate > current.bitrate
|
||||||
if (isHigher && bufferedDurationUs < minDurationForQualityIncreaseUs) {
|
&& bufferedDurationUs < minDurationForQualityIncreaseUs) {
|
||||||
// The ideal format is a higher quality, but we have insufficient buffer to safely switch
|
// The ideal format is a higher quality, but we have insufficient buffer to safely switch
|
||||||
// up. Defer switching up for now.
|
// up. Defer switching up for now.
|
||||||
ideal = current;
|
selected = current;
|
||||||
} else if (isLower && bufferedDurationUs >= maxDurationForQualityDecreaseUs) {
|
} else if (selected.bitrate < current.bitrate
|
||||||
// The ideal format is a lower quality, but we have sufficient buffer to defer switching
|
&& bufferedDurationUs >= maxDurationForQualityDecreaseUs) {
|
||||||
// down for now.
|
// The ideal format is a lower quality, but we have sufficient buffer to defer switching
|
||||||
ideal = current;
|
// down for now.
|
||||||
|
selected = current;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (current != null && ideal != current) {
|
if (current != null && selected != current) {
|
||||||
evaluation.trigger = TRIGGER_ADAPTIVE;
|
evaluation.trigger = TRIGGER_ADAPTIVE;
|
||||||
}
|
}
|
||||||
evaluation.format = ideal;
|
evaluation.format = selected;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -340,6 +342,15 @@ public interface FormatEvaluator {
|
||||||
return formats[lowestBitrateNonBlacklistedIndex];
|
return formats[lowestBitrateNonBlacklistedIndex];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean isEnabledFormat(Format format, boolean[] blacklistFlags) {
|
||||||
|
for (int i = 0; i < formats.length; i++) {
|
||||||
|
if (format == formats[i]) {
|
||||||
|
return !blacklistFlags[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -52,9 +52,12 @@ public abstract class ExoHostedTest implements HostedTest, ExoPlayer.EventListen
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final long MAX_PLAYING_TIME_DISCREPANCY_MS = 2000;
|
public static final long MAX_PLAYING_TIME_DISCREPANCY_MS = 2000;
|
||||||
|
public static final long EXPECTED_PLAYING_TIME_MEDIA_DURATION_MS = -1;
|
||||||
|
public static final long EXPECTED_PLAYING_TIME_UNSET = -2;
|
||||||
|
|
||||||
private final String tag;
|
private final String tag;
|
||||||
private final boolean fullPlaybackNoSeeking;
|
private final boolean failOnPlayerError;
|
||||||
|
private final long expectedPlayingTimeMs;
|
||||||
private final CodecCounters videoCodecCounters;
|
private final CodecCounters videoCodecCounters;
|
||||||
private final CodecCounters audioCodecCounters;
|
private final CodecCounters audioCodecCounters;
|
||||||
|
|
||||||
|
|
@ -74,11 +77,30 @@ public abstract class ExoHostedTest implements HostedTest, ExoPlayer.EventListen
|
||||||
* @param tag A tag to use for logging.
|
* @param tag A tag to use for logging.
|
||||||
* @param fullPlaybackNoSeeking Whether the test will play the target media in full without
|
* @param fullPlaybackNoSeeking Whether the test will play the target media in full without
|
||||||
* seeking. If set to true, the test will assert that the total time spent playing the media
|
* 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.
|
* was within {@link #MAX_PLAYING_TIME_DISCREPANCY_MS} of the media duration. If set to false,
|
||||||
|
* the test will not assert an expected playing time.
|
||||||
*/
|
*/
|
||||||
public ExoHostedTest(String tag, boolean fullPlaybackNoSeeking) {
|
public ExoHostedTest(String tag, boolean fullPlaybackNoSeeking) {
|
||||||
|
this(tag, fullPlaybackNoSeeking ? EXPECTED_PLAYING_TIME_MEDIA_DURATION_MS
|
||||||
|
: EXPECTED_PLAYING_TIME_UNSET, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param tag A tag to use for logging.
|
||||||
|
* @param expectedPlayingTimeMs The expected playing time. If set to a non-negative value, the
|
||||||
|
* test will assert that the total time spent playing the media was within
|
||||||
|
* {@link #MAX_PLAYING_TIME_DISCREPANCY_MS} of the specified value.
|
||||||
|
* {@link #EXPECTED_PLAYING_TIME_MEDIA_DURATION_MS} should be passed to assert that the
|
||||||
|
* expected playing time equals the duration of the media being played. Else
|
||||||
|
* {@link #EXPECTED_PLAYING_TIME_UNSET} should be passed to indicate that the test should not
|
||||||
|
* assert an expected playing time.
|
||||||
|
* @param failOnPlayerError True if a player error should be considered a test failure. False
|
||||||
|
* otherwise.
|
||||||
|
*/
|
||||||
|
public ExoHostedTest(String tag, long expectedPlayingTimeMs, boolean failOnPlayerError) {
|
||||||
this.tag = tag;
|
this.tag = tag;
|
||||||
this.fullPlaybackNoSeeking = fullPlaybackNoSeeking;
|
this.expectedPlayingTimeMs = expectedPlayingTimeMs;
|
||||||
|
this.failOnPlayerError = failOnPlayerError;
|
||||||
videoCodecCounters = new CodecCounters();
|
videoCodecCounters = new CodecCounters();
|
||||||
audioCodecCounters = new CodecCounters();
|
audioCodecCounters = new CodecCounters();
|
||||||
}
|
}
|
||||||
|
|
@ -133,16 +155,18 @@ public abstract class ExoHostedTest implements HostedTest, ExoPlayer.EventListen
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final void onFinished() {
|
public final void onFinished() {
|
||||||
if (playerError != null) {
|
if (failOnPlayerError && playerError != null) {
|
||||||
throw new Error(playerError);
|
throw new Error(playerError);
|
||||||
}
|
}
|
||||||
logMetrics(audioCodecCounters, videoCodecCounters);
|
logMetrics(audioCodecCounters, videoCodecCounters);
|
||||||
if (fullPlaybackNoSeeking) {
|
if (expectedPlayingTimeMs != EXPECTED_PLAYING_TIME_UNSET) {
|
||||||
|
long playingTimeToAssertMs = expectedPlayingTimeMs == EXPECTED_PLAYING_TIME_MEDIA_DURATION_MS
|
||||||
|
? sourceDurationMs : expectedPlayingTimeMs;
|
||||||
// Assert that the playback spanned the correct duration of time.
|
// Assert that the playback spanned the correct duration of time.
|
||||||
long minAllowedActualPlayingTimeMs = sourceDurationMs - MAX_PLAYING_TIME_DISCREPANCY_MS;
|
long minAllowedActualPlayingTimeMs = playingTimeToAssertMs - MAX_PLAYING_TIME_DISCREPANCY_MS;
|
||||||
long maxAllowedActualPlayingTimeMs = sourceDurationMs + MAX_PLAYING_TIME_DISCREPANCY_MS;
|
long maxAllowedActualPlayingTimeMs = playingTimeToAssertMs + MAX_PLAYING_TIME_DISCREPANCY_MS;
|
||||||
Assert.assertTrue("Total playing time: " + totalPlayingTimeMs + ". Actual media duration: "
|
Assert.assertTrue("Total playing time: " + totalPlayingTimeMs + ". Expected: "
|
||||||
+ sourceDurationMs, minAllowedActualPlayingTimeMs <= totalPlayingTimeMs
|
+ playingTimeToAssertMs, minAllowedActualPlayingTimeMs <= totalPlayingTimeMs
|
||||||
&& totalPlayingTimeMs <= maxAllowedActualPlayingTimeMs);
|
&& totalPlayingTimeMs <= maxAllowedActualPlayingTimeMs);
|
||||||
}
|
}
|
||||||
// Make any additional assertions.
|
// Make any additional assertions.
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue