From 06216514765344926bda9f683e1fc8b9f466523e Mon Sep 17 00:00:00 2001 From: tonihei Date: Tue, 11 Jul 2017 07:43:38 -0700 Subject: [PATCH] Add buffer length metric to ABR playback test. This metric is measured once every second. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=161527345 --- .../exoplayer2/testutil/ActionSchedule.java | 40 ++++++++++++++++--- 1 file changed, 35 insertions(+), 5 deletions(-) diff --git a/testutils/src/main/java/com/google/android/exoplayer2/testutil/ActionSchedule.java b/testutils/src/main/java/com/google/android/exoplayer2/testutil/ActionSchedule.java index ede4dc5553..66f7ebca95 100644 --- a/testutils/src/main/java/com/google/android/exoplayer2/testutil/ActionSchedule.java +++ b/testutils/src/main/java/com/google/android/exoplayer2/testutil/ActionSchedule.java @@ -17,6 +17,7 @@ package com.google.android.exoplayer2.testutil; import android.os.Handler; import android.view.Surface; +import com.google.android.exoplayer2.C; import com.google.android.exoplayer2.SimpleExoPlayer; import com.google.android.exoplayer2.testutil.Action.ClearVideoSurface; import com.google.android.exoplayer2.testutil.Action.Seek; @@ -91,11 +92,18 @@ public final class ActionSchedule { * @return The builder, for convenience. */ public Builder apply(Action action) { - ActionNode next = new ActionNode(action, currentDelayMs); - previousNode.setNext(next); - previousNode = next; - currentDelayMs = 0; - return this; + return appendActionNode(new ActionNode(action, currentDelayMs)); + } + + /** + * Schedules an action to be executed repeatedly. + * + * @param action The action to schedule. + * @param intervalMs The interval between each repetition in milliseconds. + * @return The builder, for convenience. + */ + public Builder repeat(Action action, long intervalMs) { + return appendActionNode(new ActionNode(action, currentDelayMs, intervalMs)); } /** @@ -175,6 +183,13 @@ public final class ActionSchedule { return new ActionSchedule(rootNode); } + private Builder appendActionNode(ActionNode actionNode) { + previousNode.setNext(actionNode); + previousNode = actionNode; + currentDelayMs = 0; + return this; + } + } /** @@ -184,6 +199,7 @@ public final class ActionSchedule { private final Action action; private final long delayMs; + private final long repeatIntervalMs; private ActionNode next; @@ -197,8 +213,19 @@ public final class ActionSchedule { * @param delayMs The delay between the node being scheduled and the action being executed. */ public ActionNode(Action action, long delayMs) { + this(action, delayMs, C.TIME_UNSET); + } + + /** + * @param action The wrapped action. + * @param delayMs The delay between the node being scheduled and the action being executed. + * @param repeatIntervalMs The interval between one execution and the next repetition. If set to + * {@link C#TIME_UNSET}, the action is executed once only. + */ + public ActionNode(Action action, long delayMs, long repeatIntervalMs) { this.action = action; this.delayMs = delayMs; + this.repeatIntervalMs = repeatIntervalMs; } /** @@ -234,6 +261,9 @@ public final class ActionSchedule { if (next != null) { next.schedule(player, trackSelector, surface, mainHandler); } + if (repeatIntervalMs != C.TIME_UNSET) { + mainHandler.postDelayed(this, repeatIntervalMs); + } } }