mirror of
https://github.com/androidx/media.git
synced 2025-04-30 06:46:50 +08:00
CompositionPlayerSeekTest: don't hide exception while waiting on latch
If a playback exception was thrown before or during awaiting the frameCountBeforeBlockLatch, a TimeoutException was thrown instead of the playback exception, hiding the actual cause of the failing test. PiperOrigin-RevId: 713279627
This commit is contained in:
parent
30038079c4
commit
bb3b85a359
@ -23,6 +23,7 @@ import static androidx.media3.transformer.AndroidTestUtil.PNG_ASSET;
|
|||||||
import static androidx.test.platform.app.InstrumentationRegistry.getInstrumentation;
|
import static androidx.test.platform.app.InstrumentationRegistry.getInstrumentation;
|
||||||
import static com.google.common.collect.Iterables.getLast;
|
import static com.google.common.collect.Iterables.getLast;
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
import static com.google.common.truth.Truth.assertWithMessage;
|
||||||
import static java.util.concurrent.TimeUnit.MILLISECONDS;
|
import static java.util.concurrent.TimeUnit.MILLISECONDS;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
@ -33,9 +34,12 @@ import androidx.media3.common.Effect;
|
|||||||
import androidx.media3.common.GlObjectsProvider;
|
import androidx.media3.common.GlObjectsProvider;
|
||||||
import androidx.media3.common.GlTextureInfo;
|
import androidx.media3.common.GlTextureInfo;
|
||||||
import androidx.media3.common.MediaItem;
|
import androidx.media3.common.MediaItem;
|
||||||
|
import androidx.media3.common.PlaybackException;
|
||||||
|
import androidx.media3.common.Player;
|
||||||
import androidx.media3.common.PreviewingVideoGraph;
|
import androidx.media3.common.PreviewingVideoGraph;
|
||||||
import androidx.media3.common.VideoFrameProcessingException;
|
import androidx.media3.common.VideoFrameProcessingException;
|
||||||
import androidx.media3.common.VideoGraph;
|
import androidx.media3.common.VideoGraph;
|
||||||
|
import androidx.media3.common.util.NullableType;
|
||||||
import androidx.media3.common.util.Util;
|
import androidx.media3.common.util.Util;
|
||||||
import androidx.media3.effect.GlEffect;
|
import androidx.media3.effect.GlEffect;
|
||||||
import androidx.media3.effect.PreviewingSingleInputVideoGraph;
|
import androidx.media3.effect.PreviewingSingleInputVideoGraph;
|
||||||
@ -47,8 +51,8 @@ import java.util.ArrayList;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.CountDownLatch;
|
import java.util.concurrent.CountDownLatch;
|
||||||
import java.util.concurrent.Executor;
|
import java.util.concurrent.Executor;
|
||||||
import java.util.concurrent.TimeoutException;
|
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
|
import java.util.concurrent.atomic.AtomicReference;
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Rule;
|
import org.junit.Rule;
|
||||||
@ -587,6 +591,7 @@ public class CompositionPlayerSeekTest {
|
|||||||
List<EditedMediaItem> editedMediaItems =
|
List<EditedMediaItem> editedMediaItems =
|
||||||
createEditedMediaItems(mediaItems, durationsUs, videoEffect);
|
createEditedMediaItems(mediaItems, durationsUs, videoEffect);
|
||||||
CountDownLatch videoGraphEnded = new CountDownLatch(1);
|
CountDownLatch videoGraphEnded = new CountDownLatch(1);
|
||||||
|
AtomicReference<@NullableType PlaybackException> playbackException = new AtomicReference<>();
|
||||||
|
|
||||||
getInstrumentation()
|
getInstrumentation()
|
||||||
.runOnMainSync(
|
.runOnMainSync(
|
||||||
@ -600,6 +605,14 @@ public class CompositionPlayerSeekTest {
|
|||||||
// surface otherwise the player will skip/drop video frames.
|
// surface otherwise the player will skip/drop video frames.
|
||||||
compositionPlayer.setVideoSurfaceView(surfaceView);
|
compositionPlayer.setVideoSurfaceView(surfaceView);
|
||||||
compositionPlayer.addListener(playerTestListener);
|
compositionPlayer.addListener(playerTestListener);
|
||||||
|
compositionPlayer.addListener(
|
||||||
|
new Player.Listener() {
|
||||||
|
@Override
|
||||||
|
public void onPlayerError(PlaybackException error) {
|
||||||
|
playbackException.set(error);
|
||||||
|
frameCountBeforeBlockLatch.unblock();
|
||||||
|
}
|
||||||
|
});
|
||||||
compositionPlayer.setComposition(
|
compositionPlayer.setComposition(
|
||||||
new Composition.Builder(
|
new Composition.Builder(
|
||||||
new EditedMediaItemSequence.Builder(editedMediaItems).build())
|
new EditedMediaItemSequence.Builder(editedMediaItems).build())
|
||||||
@ -609,7 +622,12 @@ public class CompositionPlayerSeekTest {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Wait until the number of frames are received, block further input on the shader program.
|
// Wait until the number of frames are received, block further input on the shader program.
|
||||||
frameCountBeforeBlockLatch.await();
|
assertWithMessage("Timeout reached while waiting for frames.")
|
||||||
|
.that(frameCountBeforeBlockLatch.await())
|
||||||
|
.isTrue();
|
||||||
|
if (playbackException.get() != null) {
|
||||||
|
throw playbackException.get();
|
||||||
|
}
|
||||||
getInstrumentation().runOnMainSync(() -> compositionPlayer.seekTo(seekTimeMs));
|
getInstrumentation().runOnMainSync(() -> compositionPlayer.seekTo(seekTimeMs));
|
||||||
playerTestListener.waitUntilPlayerEnded();
|
playerTestListener.waitUntilPlayerEnded();
|
||||||
|
|
||||||
@ -757,10 +775,8 @@ public class CompositionPlayerSeekTest {
|
|||||||
latch = new CountDownLatch(count);
|
latch = new CountDownLatch(count);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void await() throws InterruptedException, TimeoutException {
|
public boolean await() throws InterruptedException {
|
||||||
if (!latch.await(TEST_TIMEOUT_MS, MILLISECONDS)) {
|
return latch.await(TEST_TIMEOUT_MS, MILLISECONDS);
|
||||||
throw new TimeoutException();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void countDown() {
|
public void countDown() {
|
||||||
@ -771,6 +787,12 @@ public class CompositionPlayerSeekTest {
|
|||||||
return latch.getCount();
|
return latch.getCount();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void unblock() {
|
||||||
|
while (latch.getCount() > 0) {
|
||||||
|
latch.countDown();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void reset(int count) {
|
public void reset(int count) {
|
||||||
latch = new CountDownLatch(count);
|
latch = new CountDownLatch(count);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user