Remove unnecessary thread in AssetLoader tests
Also queue textures from a different thread in TextureAssetLoader, to have a behaviour closer to reality. PiperOrigin-RevId: 538473089
This commit is contained in:
parent
e7f7e86f3e
commit
3ba8f6dd8f
@ -20,8 +20,6 @@ import static androidx.media3.transformer.TransformerUtil.getProcessedTrackType;
|
|||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.os.Handler;
|
|
||||||
import android.os.HandlerThread;
|
|
||||||
import android.os.Looper;
|
import android.os.Looper;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import androidx.media3.common.C;
|
import androidx.media3.common.C;
|
||||||
@ -44,9 +42,6 @@ public class ExoPlayerAssetLoaderTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void exoPlayerAssetLoader_callsListenerCallbacksInRightOrder() throws Exception {
|
public void exoPlayerAssetLoader_callsListenerCallbacksInRightOrder() throws Exception {
|
||||||
HandlerThread assetLoaderThread = new HandlerThread("AssetLoaderThread");
|
|
||||||
assetLoaderThread.start();
|
|
||||||
Looper assetLoaderLooper = assetLoaderThread.getLooper();
|
|
||||||
AtomicReference<Exception> exceptionRef = new AtomicReference<>();
|
AtomicReference<Exception> exceptionRef = new AtomicReference<>();
|
||||||
AtomicBoolean isAudioOutputFormatSet = new AtomicBoolean();
|
AtomicBoolean isAudioOutputFormatSet = new AtomicBoolean();
|
||||||
AtomicBoolean isVideoOutputFormatSet = new AtomicBoolean();
|
AtomicBoolean isVideoOutputFormatSet = new AtomicBoolean();
|
||||||
@ -128,9 +123,9 @@ public class ExoPlayerAssetLoaderTest {
|
|||||||
// Use default clock so that messages sent on different threads are not always executed in the
|
// Use default clock so that messages sent on different threads are not always executed in the
|
||||||
// order in which they are received.
|
// order in which they are received.
|
||||||
Clock clock = Clock.DEFAULT;
|
Clock clock = Clock.DEFAULT;
|
||||||
AssetLoader assetLoader = getAssetLoader(assetLoaderLooper, listener, clock);
|
AssetLoader assetLoader = getAssetLoader(listener, clock);
|
||||||
|
|
||||||
new Handler(assetLoaderLooper).post(assetLoader::start);
|
assetLoader.start();
|
||||||
runLooperUntil(
|
runLooperUntil(
|
||||||
Looper.myLooper(),
|
Looper.myLooper(),
|
||||||
() -> {
|
() -> {
|
||||||
@ -142,15 +137,14 @@ public class ExoPlayerAssetLoaderTest {
|
|||||||
assertThat(exceptionRef.get()).isNull();
|
assertThat(exceptionRef.get()).isNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static AssetLoader getAssetLoader(
|
private static AssetLoader getAssetLoader(AssetLoader.Listener listener, Clock clock) {
|
||||||
Looper looper, AssetLoader.Listener listener, Clock clock) {
|
|
||||||
Context context = ApplicationProvider.getApplicationContext();
|
Context context = ApplicationProvider.getApplicationContext();
|
||||||
Codec.DecoderFactory decoderFactory = new DefaultDecoderFactory(context);
|
Codec.DecoderFactory decoderFactory = new DefaultDecoderFactory(context);
|
||||||
EditedMediaItem editedMediaItem =
|
EditedMediaItem editedMediaItem =
|
||||||
new EditedMediaItem.Builder(MediaItem.fromUri("asset:///media/mp4/sample.mp4")).build();
|
new EditedMediaItem.Builder(MediaItem.fromUri("asset:///media/mp4/sample.mp4")).build();
|
||||||
return new ExoPlayerAssetLoader.Factory(
|
return new ExoPlayerAssetLoader.Factory(
|
||||||
context, decoderFactory, /* forceInterpretHdrAsSdr= */ false, clock)
|
context, decoderFactory, /* forceInterpretHdrAsSdr= */ false, clock)
|
||||||
.createAssetLoader(editedMediaItem, looper, listener);
|
.createAssetLoader(editedMediaItem, Looper.myLooper(), listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final class FakeSampleConsumer implements SampleConsumer {
|
private static final class FakeSampleConsumer implements SampleConsumer {
|
||||||
|
@ -19,8 +19,6 @@ import static androidx.media3.test.utils.robolectric.RobolectricUtil.runLooperUn
|
|||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
import android.os.Handler;
|
|
||||||
import android.os.HandlerThread;
|
|
||||||
import android.os.Looper;
|
import android.os.Looper;
|
||||||
import androidx.media3.common.Format;
|
import androidx.media3.common.Format;
|
||||||
import androidx.media3.common.MediaItem;
|
import androidx.media3.common.MediaItem;
|
||||||
@ -39,9 +37,6 @@ public class ImageAssetLoaderTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void imageAssetLoader_callsListenerCallbacksInRightOrder() throws Exception {
|
public void imageAssetLoader_callsListenerCallbacksInRightOrder() throws Exception {
|
||||||
HandlerThread assetLoaderThread = new HandlerThread("AssetLoaderThread");
|
|
||||||
assetLoaderThread.start();
|
|
||||||
Looper assetLoaderLooper = assetLoaderThread.getLooper();
|
|
||||||
AtomicReference<Exception> exceptionRef = new AtomicReference<>();
|
AtomicReference<Exception> exceptionRef = new AtomicReference<>();
|
||||||
AtomicBoolean isOutputFormatSet = new AtomicBoolean();
|
AtomicBoolean isOutputFormatSet = new AtomicBoolean();
|
||||||
AssetLoader.Listener listener =
|
AssetLoader.Listener listener =
|
||||||
@ -103,9 +98,9 @@ public class ImageAssetLoaderTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
AssetLoader assetLoader = getAssetLoader(assetLoaderLooper, listener);
|
AssetLoader assetLoader = getAssetLoader(listener);
|
||||||
|
|
||||||
new Handler(assetLoaderLooper).post(assetLoader::start);
|
assetLoader.start();
|
||||||
runLooperUntil(
|
runLooperUntil(
|
||||||
Looper.myLooper(),
|
Looper.myLooper(),
|
||||||
() -> {
|
() -> {
|
||||||
@ -116,7 +111,7 @@ public class ImageAssetLoaderTest {
|
|||||||
assertThat(exceptionRef.get()).isNull();
|
assertThat(exceptionRef.get()).isNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static AssetLoader getAssetLoader(Looper looper, AssetLoader.Listener listener) {
|
private static AssetLoader getAssetLoader(AssetLoader.Listener listener) {
|
||||||
EditedMediaItem editedMediaItem =
|
EditedMediaItem editedMediaItem =
|
||||||
new EditedMediaItem.Builder(
|
new EditedMediaItem.Builder(
|
||||||
MediaItem.fromUri("asset:///media/bitmap/input_images/media3test.png"))
|
MediaItem.fromUri("asset:///media/bitmap/input_images/media3test.png"))
|
||||||
@ -124,7 +119,7 @@ public class ImageAssetLoaderTest {
|
|||||||
.setFrameRate(30)
|
.setFrameRate(30)
|
||||||
.build();
|
.build();
|
||||||
return new ImageAssetLoader.Factory(ApplicationProvider.getApplicationContext())
|
return new ImageAssetLoader.Factory(ApplicationProvider.getApplicationContext())
|
||||||
.createAssetLoader(editedMediaItem, looper, listener);
|
.createAssetLoader(editedMediaItem, Looper.myLooper(), listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final class FakeSampleConsumer implements SampleConsumer {
|
private static final class FakeSampleConsumer implements SampleConsumer {
|
||||||
|
@ -18,8 +18,6 @@ package androidx.media3.transformer;
|
|||||||
import static androidx.media3.test.utils.robolectric.RobolectricUtil.runLooperUntil;
|
import static androidx.media3.test.utils.robolectric.RobolectricUtil.runLooperUntil;
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
import android.os.Handler;
|
|
||||||
import android.os.HandlerThread;
|
|
||||||
import android.os.Looper;
|
import android.os.Looper;
|
||||||
import androidx.media3.common.C;
|
import androidx.media3.common.C;
|
||||||
import androidx.media3.common.Format;
|
import androidx.media3.common.Format;
|
||||||
@ -27,6 +25,7 @@ import androidx.media3.common.MediaItem;
|
|||||||
import androidx.media3.common.OnInputFrameProcessedListener;
|
import androidx.media3.common.OnInputFrameProcessedListener;
|
||||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||||
import java.time.Duration;
|
import java.time.Duration;
|
||||||
|
import java.util.concurrent.Executors;
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
import java.util.concurrent.atomic.AtomicReference;
|
import java.util.concurrent.atomic.AtomicReference;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
@ -39,9 +38,6 @@ public class TextureAssetLoaderTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void textureAssetLoader_callsListenerCallbacksInRightOrder() throws Exception {
|
public void textureAssetLoader_callsListenerCallbacksInRightOrder() throws Exception {
|
||||||
HandlerThread assetLoaderThread = new HandlerThread("AssetLoaderThread");
|
|
||||||
assetLoaderThread.start();
|
|
||||||
Looper assetLoaderLooper = assetLoaderThread.getLooper();
|
|
||||||
AtomicReference<Exception> exceptionRef = new AtomicReference<>();
|
AtomicReference<Exception> exceptionRef = new AtomicReference<>();
|
||||||
AtomicBoolean isOutputFormatSet = new AtomicBoolean();
|
AtomicBoolean isOutputFormatSet = new AtomicBoolean();
|
||||||
AssetLoader.Listener listener =
|
AssetLoader.Listener listener =
|
||||||
@ -105,7 +101,7 @@ public class TextureAssetLoaderTest {
|
|||||||
};
|
};
|
||||||
TextureAssetLoader assetLoader = getAssetLoader(listener);
|
TextureAssetLoader assetLoader = getAssetLoader(listener);
|
||||||
|
|
||||||
new Handler(assetLoaderLooper).post(() -> runTextureAssetLoader(assetLoader));
|
runTextureAssetLoader(assetLoader);
|
||||||
runLooperUntil(
|
runLooperUntil(
|
||||||
Looper.myLooper(),
|
Looper.myLooper(),
|
||||||
() -> {
|
() -> {
|
||||||
@ -116,10 +112,16 @@ public class TextureAssetLoaderTest {
|
|||||||
assertThat(exceptionRef.get()).isNull();
|
assertThat(exceptionRef.get()).isNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("FutureReturnValueIgnored")
|
||||||
private static void runTextureAssetLoader(TextureAssetLoader assetLoader) {
|
private static void runTextureAssetLoader(TextureAssetLoader assetLoader) {
|
||||||
assetLoader.start();
|
assetLoader.start();
|
||||||
assetLoader.queueInputTexture(/* texId= */ 0, /* presentationTimeUs= */ 0);
|
|
||||||
assetLoader.signalEndOfVideoInput();
|
Executors.newSingleThreadExecutor()
|
||||||
|
.submit(
|
||||||
|
() -> {
|
||||||
|
assetLoader.queueInputTexture(/* texId= */ 0, /* presentationTimeUs= */ 0);
|
||||||
|
assetLoader.signalEndOfVideoInput();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private static TextureAssetLoader getAssetLoader(AssetLoader.Listener listener) {
|
private static TextureAssetLoader getAssetLoader(AssetLoader.Listener listener) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user