diff --git a/libraries/transformer/src/androidTest/java/androidx/media3/transformer/mh/performance/EffectPlaybackTest.java b/libraries/transformer/src/androidTest/java/androidx/media3/transformer/mh/performance/EffectPlaybackTest.java index 9533f772e4..0c241eb08d 100644 --- a/libraries/transformer/src/androidTest/java/androidx/media3/transformer/mh/performance/EffectPlaybackTest.java +++ b/libraries/transformer/src/androidTest/java/androidx/media3/transformer/mh/performance/EffectPlaybackTest.java @@ -25,21 +25,16 @@ import static androidx.media3.test.utils.BitmapPixelTestUtil.createArgb8888Bitma import static androidx.media3.test.utils.BitmapPixelTestUtil.createArgb8888BitmapFromRgba8888ImageBuffer; import static androidx.media3.test.utils.BitmapPixelTestUtil.getBitmapAveragePixelAbsoluteDifferenceArgb8888; import static androidx.media3.test.utils.BitmapPixelTestUtil.readBitmap; +import static androidx.media3.transformer.mh.performance.PlaybackTestUtil.createTimestampOverlay; import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertWithMessage; import static org.junit.Assume.assumeTrue; import android.app.Instrumentation; import android.graphics.Bitmap; -import android.graphics.Color; import android.graphics.PixelFormat; import android.media.Image; import android.media.ImageReader; -import android.text.Spannable; -import android.text.SpannableString; -import android.text.style.AbsoluteSizeSpan; -import android.text.style.ForegroundColorSpan; -import android.text.style.TypefaceSpan; import android.view.Surface; import androidx.annotation.Nullable; import androidx.media3.common.C; @@ -51,8 +46,6 @@ import androidx.media3.common.util.ConditionVariable; import androidx.media3.common.util.Size; import androidx.media3.common.util.Util; import androidx.media3.effect.Brightness; -import androidx.media3.effect.OverlayEffect; -import androidx.media3.effect.TextOverlay; import androidx.media3.effect.TimestampWrapper; import androidx.media3.exoplayer.ExoPlayer; import androidx.media3.exoplayer.Renderer; @@ -418,34 +411,6 @@ public class EffectPlaybackTest { .send(); } - /** Creates an {@link OverlayEffect} that draws the timestamp onto frames. */ - private static OverlayEffect createTimestampOverlay() { - return new OverlayEffect( - ImmutableList.of( - new TextOverlay() { - @Override - public SpannableString getText(long presentationTimeUs) { - SpannableString text = new SpannableString(String.valueOf(presentationTimeUs)); - text.setSpan( - new ForegroundColorSpan(Color.WHITE), - /* start= */ 0, - text.length(), - Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); - text.setSpan( - new AbsoluteSizeSpan(/* size= */ 96), - /* start= */ 0, - text.length(), - Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); - text.setSpan( - new TypefaceSpan(/* family= */ "sans-serif"), - /* start= */ 0, - text.length(), - Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); - return text; - } - })); - } - private static void release(@Nullable Player player, @Nullable ImageReader imageReader) { if (player != null) { player.release(); diff --git a/libraries/transformer/src/androidTest/java/androidx/media3/transformer/mh/performance/PlaybackTestUtil.java b/libraries/transformer/src/androidTest/java/androidx/media3/transformer/mh/performance/PlaybackTestUtil.java new file mode 100644 index 0000000000..dabce30ec5 --- /dev/null +++ b/libraries/transformer/src/androidTest/java/androidx/media3/transformer/mh/performance/PlaybackTestUtil.java @@ -0,0 +1,61 @@ +/* + * Copyright 2024 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package androidx.media3.transformer.mh.performance; + +import android.graphics.Color; +import android.text.Spannable; +import android.text.SpannableString; +import android.text.style.AbsoluteSizeSpan; +import android.text.style.ForegroundColorSpan; +import android.text.style.TypefaceSpan; +import androidx.media3.effect.OverlayEffect; +import androidx.media3.effect.TextOverlay; +import com.google.common.collect.ImmutableList; + +/** Utilities for playback tests. */ +/* package */ final class PlaybackTestUtil { + + private PlaybackTestUtil() {} + + /** Creates an {@link OverlayEffect} that draws the timestamp onto frames. */ + public static OverlayEffect createTimestampOverlay() { + return new OverlayEffect( + ImmutableList.of( + new TextOverlay() { + @Override + public SpannableString getText(long presentationTimeUs) { + SpannableString text = new SpannableString(String.valueOf(presentationTimeUs)); + text.setSpan( + new ForegroundColorSpan(Color.WHITE), + /* start= */ 0, + text.length(), + Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); + text.setSpan( + new AbsoluteSizeSpan(/* size= */ 96), + /* start= */ 0, + text.length(), + Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); + text.setSpan( + new TypefaceSpan(/* family= */ "sans-serif"), + /* start= */ 0, + text.length(), + Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); + return text; + } + })); + } +}