diff --git a/demos/transformer/src/main/java/androidx/media3/demo/transformer/TransformerActivity.java b/demos/transformer/src/main/java/androidx/media3/demo/transformer/TransformerActivity.java index cfd10e10dc..57a13cfa22 100644 --- a/demos/transformer/src/main/java/androidx/media3/demo/transformer/TransformerActivity.java +++ b/demos/transformer/src/main/java/androidx/media3/demo/transformer/TransformerActivity.java @@ -827,7 +827,8 @@ public final class TransformerActivity extends AppCompatActivity { inputImageView.setVisibility(View.VISIBLE); inputTextView.setText(getString(R.string.input_image)); - BitmapLoader bitmapLoader = new DataSourceBitmapLoader(getApplicationContext()); + BitmapLoader bitmapLoader = + new DataSourceBitmapLoader.Builder(getApplicationContext()).build(); ListenableFuture future = bitmapLoader.loadBitmap(uri); try { Bitmap bitmap = future.get(); diff --git a/libraries/datasource/src/androidTest/java/androidx/media3/datasource/DataSourceBitmapLoaderTest.java b/libraries/datasource/src/androidTest/java/androidx/media3/datasource/DataSourceBitmapLoaderTest.java index d2271f0bcf..7529bc0f65 100644 --- a/libraries/datasource/src/androidTest/java/androidx/media3/datasource/DataSourceBitmapLoaderTest.java +++ b/libraries/datasource/src/androidTest/java/androidx/media3/datasource/DataSourceBitmapLoaderTest.java @@ -16,6 +16,7 @@ package androidx.media3.datasource; import static com.google.common.truth.Truth.assertThat; +import static com.google.common.util.concurrent.MoreExecutors.newDirectExecutorService; import static org.junit.Assert.assertThrows; import android.content.Context; @@ -31,7 +32,6 @@ import androidx.test.ext.junit.runners.AndroidJUnit4; import androidx.test.filters.SdkSuppress; import com.google.common.io.Files; import com.google.common.util.concurrent.ListenableFuture; -import com.google.common.util.concurrent.MoreExecutors; import java.io.File; import java.util.concurrent.ExecutionException; import okhttp3.mockwebserver.MockResponse; @@ -74,7 +74,10 @@ public class DataSourceBitmapLoaderTest { @Test public void decodeBitmap_withValidData_loadsCorrectData() throws Exception { DataSourceBitmapLoader bitmapLoader = - new DataSourceBitmapLoader(MoreExecutors.newDirectExecutorService(), dataSourceFactory); + new DataSourceBitmapLoader.Builder(context) + .setExecutorService(newDirectExecutorService()) + .setDataSourceFactory(dataSourceFactory) + .build(); byte[] imageData = TestUtil.getByteArray(context, TEST_IMAGE_PATH); Bitmap bitmap = bitmapLoader.decodeBitmap(imageData).get(); @@ -88,7 +91,10 @@ public class DataSourceBitmapLoaderTest { @Test public void decodeBitmap_withExifRotation_loadsCorrectData() throws Exception { DataSourceBitmapLoader bitmapLoader = - new DataSourceBitmapLoader(MoreExecutors.newDirectExecutorService(), dataSourceFactory); + new DataSourceBitmapLoader.Builder(context) + .setExecutorService(newDirectExecutorService()) + .setDataSourceFactory(dataSourceFactory) + .build(); byte[] imageData = TestUtil.getByteArray(context, TEST_IMAGE_FOLDER + "non-motion-photo-shortened.jpg"); Bitmap bitmapWithoutRotation = @@ -113,7 +119,10 @@ public class DataSourceBitmapLoaderTest { @Test public void decodeBitmap_withInvalidData_throws() { DataSourceBitmapLoader bitmapLoader = - new DataSourceBitmapLoader(MoreExecutors.newDirectExecutorService(), dataSourceFactory); + new DataSourceBitmapLoader.Builder(context) + .setExecutorService(newDirectExecutorService()) + .setDataSourceFactory(dataSourceFactory) + .build(); ListenableFuture future = bitmapLoader.decodeBitmap(new byte[0]); @@ -124,7 +133,10 @@ public class DataSourceBitmapLoaderTest { @Test public void loadBitmap_withHttpUri_loadsCorrectData() throws Exception { DataSourceBitmapLoader bitmapLoader = - new DataSourceBitmapLoader(MoreExecutors.newDirectExecutorService(), dataSourceFactory); + new DataSourceBitmapLoader.Builder(context) + .setExecutorService(newDirectExecutorService()) + .setDataSourceFactory(dataSourceFactory) + .build(); byte[] imageData = TestUtil.getByteArray(context, TEST_IMAGE_PATH); Buffer responseBody = new Buffer().write(imageData); Bitmap bitmap; @@ -143,7 +155,10 @@ public class DataSourceBitmapLoaderTest { @Test public void loadBitmap_httpUriAndServerError_throws() throws Exception { DataSourceBitmapLoader bitmapLoader = - new DataSourceBitmapLoader(MoreExecutors.newDirectExecutorService(), dataSourceFactory); + new DataSourceBitmapLoader.Builder(context) + .setExecutorService(newDirectExecutorService()) + .setDataSourceFactory(dataSourceFactory) + .build(); ListenableFuture future; try (MockWebServer mockWebServer = new MockWebServer()) { mockWebServer.enqueue(new MockResponse().setResponseCode(404)); @@ -158,7 +173,10 @@ public class DataSourceBitmapLoaderTest { @Test public void loadBitmap_assetUri_loadsCorrectData() throws Exception { DataSourceBitmapLoader bitmapLoader = - new DataSourceBitmapLoader(MoreExecutors.newDirectExecutorService(), dataSourceFactory); + new DataSourceBitmapLoader.Builder(context) + .setExecutorService(newDirectExecutorService()) + .setDataSourceFactory(dataSourceFactory) + .build(); byte[] imageData = TestUtil.getByteArray(context, TEST_IMAGE_PATH); Bitmap bitmap = bitmapLoader.loadBitmap(Uri.parse("asset:///" + TEST_IMAGE_PATH)).get(); @@ -172,7 +190,10 @@ public class DataSourceBitmapLoaderTest { @Test public void loadBitmap_assetUriWithAssetNotExisting_throws() { DataSourceBitmapLoader bitmapLoader = - new DataSourceBitmapLoader(MoreExecutors.newDirectExecutorService(), dataSourceFactory); + new DataSourceBitmapLoader.Builder(context) + .setExecutorService(newDirectExecutorService()) + .setDataSourceFactory(dataSourceFactory) + .build(); assertException( () -> bitmapLoader.loadBitmap(Uri.parse("asset:///not_valid/path/image.bmp")).get(), @@ -187,7 +208,10 @@ public class DataSourceBitmapLoaderTest { Files.write(imageData, file); Uri uri = Uri.fromFile(file); DataSourceBitmapLoader bitmapLoader = - new DataSourceBitmapLoader(MoreExecutors.newDirectExecutorService(), dataSourceFactory); + new DataSourceBitmapLoader.Builder(context) + .setExecutorService(newDirectExecutorService()) + .setDataSourceFactory(dataSourceFactory) + .build(); Bitmap bitmap = bitmapLoader.loadBitmap(uri).get(); @@ -206,8 +230,11 @@ public class DataSourceBitmapLoaderTest { BitmapFactory.Options options = new BitmapFactory.Options(); options.inMutable = true; DataSourceBitmapLoader bitmapLoader = - new DataSourceBitmapLoader( - MoreExecutors.newDirectExecutorService(), dataSourceFactory, options); + new DataSourceBitmapLoader.Builder(context) + .setExecutorService(newDirectExecutorService()) + .setDataSourceFactory(dataSourceFactory) + .setBitmapFactoryOptions(options) + .build(); Bitmap bitmap = bitmapLoader.loadBitmap(uri).get(); @@ -223,11 +250,11 @@ public class DataSourceBitmapLoaderTest { Uri uri = Uri.fromFile(file); int maximumOutputDimension = 2000; DataSourceBitmapLoader bitmapLoader = - new DataSourceBitmapLoader( - MoreExecutors.newDirectExecutorService(), - dataSourceFactory, - /* options= */ null, - maximumOutputDimension); + new DataSourceBitmapLoader.Builder(context) + .setExecutorService(newDirectExecutorService()) + .setDataSourceFactory(dataSourceFactory) + .setMaximumOutputDimension(maximumOutputDimension) + .build(); Bitmap bitmap = bitmapLoader.loadBitmap(uri).get(); @@ -245,7 +272,9 @@ public class DataSourceBitmapLoaderTest { int maximumOutputDimension = 720; DataSourceBitmapLoader bitmapLoader = - new DataSourceBitmapLoader(context, maximumOutputDimension); + new DataSourceBitmapLoader.Builder(context) + .setMaximumOutputDimension(maximumOutputDimension) + .build(); Bitmap bitmap = bitmapLoader.loadBitmap(uri).get(); @@ -256,7 +285,10 @@ public class DataSourceBitmapLoaderTest { @Test public void loadBitmap_fileUriWithFileNotExisting_throws() { DataSourceBitmapLoader bitmapLoader = - new DataSourceBitmapLoader(MoreExecutors.newDirectExecutorService(), dataSourceFactory); + new DataSourceBitmapLoader.Builder(context) + .setExecutorService(newDirectExecutorService()) + .setDataSourceFactory(dataSourceFactory) + .build(); assertException( () -> bitmapLoader.loadBitmap(Uri.parse("file:///not_valid/path/image.bmp")).get(), @@ -269,7 +301,10 @@ public class DataSourceBitmapLoaderTest { throws Exception { byte[] imageData = TestUtil.getByteArray(context, TEST_IMAGE_PATH); DataSourceBitmapLoader bitmapLoader = - new DataSourceBitmapLoader(MoreExecutors.newDirectExecutorService(), dataSourceFactory); + new DataSourceBitmapLoader.Builder(context) + .setExecutorService(newDirectExecutorService()) + .setDataSourceFactory(dataSourceFactory) + .build(); try (MockWebServer mockWebServer = new MockWebServer()) { Uri uri = Uri.parse(mockWebServer.url("test_path").toString()); MediaMetadata metadata = @@ -293,7 +328,10 @@ public class DataSourceBitmapLoaderTest { byte[] imageData = TestUtil.getByteArray(context, TEST_IMAGE_PATH); Buffer responseBody = new Buffer().write(imageData); DataSourceBitmapLoader bitmapLoader = - new DataSourceBitmapLoader(MoreExecutors.newDirectExecutorService(), dataSourceFactory); + new DataSourceBitmapLoader.Builder(context) + .setExecutorService(newDirectExecutorService()) + .setDataSourceFactory(dataSourceFactory) + .build(); try (MockWebServer mockWebServer = new MockWebServer()) { mockWebServer.enqueue(new MockResponse().setResponseCode(200).setBody(responseBody)); Uri uri = Uri.parse(mockWebServer.url("test_path").toString()); @@ -313,7 +351,10 @@ public class DataSourceBitmapLoaderTest { public void loadBitmapFromMetadata_withArtworkDataAndArtworkUriUnset_returnNull() { MediaMetadata metadata = new MediaMetadata.Builder().build(); DataSourceBitmapLoader bitmapLoader = - new DataSourceBitmapLoader(MoreExecutors.newDirectExecutorService(), dataSourceFactory); + new DataSourceBitmapLoader.Builder(context) + .setExecutorService(newDirectExecutorService()) + .setDataSourceFactory(dataSourceFactory) + .build(); ListenableFuture bitmapFuture = bitmapLoader.loadBitmapFromMetadata(metadata); diff --git a/libraries/datasource/src/main/java/androidx/media3/datasource/DataSourceBitmapLoader.java b/libraries/datasource/src/main/java/androidx/media3/datasource/DataSourceBitmapLoader.java index fab3b34cec..3e0918839b 100644 --- a/libraries/datasource/src/main/java/androidx/media3/datasource/DataSourceBitmapLoader.java +++ b/libraries/datasource/src/main/java/androidx/media3/datasource/DataSourceBitmapLoader.java @@ -31,6 +31,7 @@ import com.google.common.base.Suppliers; import com.google.common.util.concurrent.ListenableFuture; import com.google.common.util.concurrent.ListeningExecutorService; import com.google.common.util.concurrent.MoreExecutors; +import com.google.errorprone.annotations.CanIgnoreReturnValue; import java.io.IOException; import java.util.concurrent.Executors; @@ -49,55 +50,121 @@ public final class DataSourceBitmapLoader implements BitmapLoader { Suppliers.memoize( () -> MoreExecutors.listeningDecorator(Executors.newSingleThreadExecutor())); + /** A builder for {@link DataSourceBitmapLoader} instances. */ + public static final class Builder { + + private final Context context; + + @Nullable private ListeningExecutorService listeningExecutorService; + @Nullable private DataSource.Factory dataSourceFactory; + @Nullable private BitmapFactory.Options options; + private int maximumOutputDimension; + + /** + * Creates a builder. + * + * @param context The context. + */ + public Builder(Context context) { + this.context = context; + this.maximumOutputDimension = C.LENGTH_UNSET; + } + + /** + * Sets the {@link DataSource.Factory} to be used to create {@link DataSource} instances for + * loading bitmaps. + * + *

If not set, a {@link DefaultDataSource.Factory} will be used. + * + * @param dataSourceFactory A {@link DataSource.Factory}. + * @return This builder. + */ + @CanIgnoreReturnValue + public Builder setDataSourceFactory(DataSource.Factory dataSourceFactory) { + this.dataSourceFactory = dataSourceFactory; + return this; + } + + /** + * Sets the {@link ListeningExecutorService} to be used for loading bitmaps. + * + *

If not set, {@link #DEFAULT_EXECUTOR_SERVICE} will be used. + * + * @param listeningExecutorService A {@link ListeningExecutorService}. + * @return This builder. + */ + @CanIgnoreReturnValue + public Builder setExecutorService(ListeningExecutorService listeningExecutorService) { + this.listeningExecutorService = listeningExecutorService; + return this; + } + + /** + * Sets the {@link BitmapFactory.Options} to be used for decoding bitmaps. + * + * @param options A {@link BitmapFactory.Options}. + * @return This builder. + */ + @CanIgnoreReturnValue + public Builder setBitmapFactoryOptions(@Nullable BitmapFactory.Options options) { + this.options = options; + return this; + } + + /** + * Sets the maximum output dimension for decoded bitmaps. + * + * @param maximumOutputDimension The maximum output dimension in pixels. + * @return This builder. + */ + @CanIgnoreReturnValue + public Builder setMaximumOutputDimension(int maximumOutputDimension) { + this.maximumOutputDimension = maximumOutputDimension; + return this; + } + + /** Builds a {@link DataSourceBitmapLoader}. */ + public DataSourceBitmapLoader build() { + return new DataSourceBitmapLoader(this); + } + } + private final ListeningExecutorService listeningExecutorService; private final DataSource.Factory dataSourceFactory; @Nullable private final BitmapFactory.Options options; private final int maximumOutputDimension; /** - * Creates an instance that uses a {@link DefaultHttpDataSource} for image loading and delegates - * loading tasks to a {@link Executors#newSingleThreadExecutor()}. + * @deprecated Use {@link Builder} instead. */ + @Deprecated public DataSourceBitmapLoader(Context context) { - this(checkNotNull(DEFAULT_EXECUTOR_SERVICE.get()), new DefaultDataSource.Factory(context)); + this(new Builder(context)); } /** - * Creates an instance that uses a {@link DefaultHttpDataSource} for image loading and delegates - * loading tasks to a {@link Executors#newSingleThreadExecutor()} with specified maximum output - * dimension. - * - * @param context The context - * @param maximumOutputDimension The maximum dimension of the output Bitmap. + * @deprecated Use {@link Builder} instead. */ + @Deprecated public DataSourceBitmapLoader(Context context, int maximumOutputDimension) { - this( - checkNotNull(DEFAULT_EXECUTOR_SERVICE.get()), - new DefaultDataSource.Factory(context), - /* options= */ null, - maximumOutputDimension); + this(new Builder(context).setMaximumOutputDimension(maximumOutputDimension)); } /** - * Creates an instance that delegates loading tasks to the {@link ListeningExecutorService}. - * - * @param listeningExecutorService The {@link ListeningExecutorService}. - * @param dataSourceFactory The {@link DataSource.Factory} that creates the {@link DataSource} - * used to load the image. + * @deprecated Use {@link Builder} instead. */ + @SuppressWarnings("deprecation") // Calling deprecated constructor. + @Deprecated public DataSourceBitmapLoader( ListeningExecutorService listeningExecutorService, DataSource.Factory dataSourceFactory) { this(listeningExecutorService, dataSourceFactory, /* options= */ null); } /** - * Creates an instance that delegates loading tasks to the {@link ListeningExecutorService}. - * - * @param listeningExecutorService The {@link ListeningExecutorService}. - * @param dataSourceFactory The {@link DataSource.Factory} that creates the {@link DataSource} - * used to load the image. - * @param options The {@link BitmapFactory.Options} the image should be loaded with. + * @deprecated Use {@link Builder} instead. */ + @SuppressWarnings("deprecation") // Calling deprecated constructor. + @Deprecated public DataSourceBitmapLoader( ListeningExecutorService listeningExecutorService, DataSource.Factory dataSourceFactory, @@ -110,16 +177,9 @@ public final class DataSourceBitmapLoader implements BitmapLoader { } /** - * Creates an instance that delegates loading tasks to the {@link ListeningExecutorService}. - * - *

Use {@code maximumOutputDimension} to limit memory usage when loading large Bitmaps. - * - * @param listeningExecutorService The {@link ListeningExecutorService}. - * @param dataSourceFactory The {@link DataSource.Factory} that creates the {@link DataSource} - * used to load the image. - * @param options The {@link BitmapFactory.Options} the image should be loaded with. - * @param maximumOutputDimension The maximum dimension of the output Bitmap. + * @deprecated Use {@link Builder} instead. */ + @Deprecated public DataSourceBitmapLoader( ListeningExecutorService listeningExecutorService, DataSource.Factory dataSourceFactory, @@ -131,6 +191,19 @@ public final class DataSourceBitmapLoader implements BitmapLoader { this.maximumOutputDimension = maximumOutputDimension; } + private DataSourceBitmapLoader(Builder builder) { + this.dataSourceFactory = + builder.dataSourceFactory != null + ? builder.dataSourceFactory + : new DefaultDataSource.Factory(builder.context); + this.listeningExecutorService = + builder.listeningExecutorService != null + ? builder.listeningExecutorService + : checkNotNull(DEFAULT_EXECUTOR_SERVICE.get()); + this.options = builder.options; + this.maximumOutputDimension = builder.maximumOutputDimension; + } + @Override public boolean supportsMimeType(String mimeType) { return isBitmapFactorySupportedMimeType(mimeType); diff --git a/libraries/effect/src/main/java/androidx/media3/effect/BitmapOverlay.java b/libraries/effect/src/main/java/androidx/media3/effect/BitmapOverlay.java index 8042f8bd91..23df3ef294 100644 --- a/libraries/effect/src/main/java/androidx/media3/effect/BitmapOverlay.java +++ b/libraries/effect/src/main/java/androidx/media3/effect/BitmapOverlay.java @@ -111,7 +111,7 @@ public abstract class BitmapOverlay extends TextureOverlay { @Override public Bitmap getBitmap(long presentationTimeUs) throws VideoFrameProcessingException { if (lastBitmap == null) { - BitmapLoader bitmapLoader = new DataSourceBitmapLoader(context); + BitmapLoader bitmapLoader = new DataSourceBitmapLoader.Builder(context).build(); ListenableFuture future = bitmapLoader.loadBitmap(overlayBitmapUri); try { lastBitmap = future.get(); diff --git a/libraries/session/src/main/java/androidx/media3/session/MediaBrowser.java b/libraries/session/src/main/java/androidx/media3/session/MediaBrowser.java index f4c45b4d8a..d67a96bfb7 100644 --- a/libraries/session/src/main/java/androidx/media3/session/MediaBrowser.java +++ b/libraries/session/src/main/java/androidx/media3/session/MediaBrowser.java @@ -206,7 +206,7 @@ public final class MediaBrowser extends MediaController { public ListenableFuture buildAsync() { MediaControllerHolder holder = new MediaControllerHolder<>(applicationLooper); if (token.isLegacySession() && bitmapLoader == null) { - bitmapLoader = new CacheBitmapLoader(new DataSourceBitmapLoader(context)); + bitmapLoader = new CacheBitmapLoader(new DataSourceBitmapLoader.Builder(context).build()); } MediaBrowser browser = new MediaBrowser( diff --git a/libraries/session/src/main/java/androidx/media3/session/MediaController.java b/libraries/session/src/main/java/androidx/media3/session/MediaController.java index ccda17c608..a03bc403bd 100644 --- a/libraries/session/src/main/java/androidx/media3/session/MediaController.java +++ b/libraries/session/src/main/java/androidx/media3/session/MediaController.java @@ -375,7 +375,7 @@ public class MediaController implements Player { MediaControllerHolder holder = new MediaControllerHolder<>(applicationLooper); if (token.isLegacySession() && bitmapLoader == null) { - bitmapLoader = new CacheBitmapLoader(new DataSourceBitmapLoader(context)); + bitmapLoader = new CacheBitmapLoader(new DataSourceBitmapLoader.Builder(context).build()); } MediaController controller = new MediaController( diff --git a/libraries/session/src/main/java/androidx/media3/session/MediaSession.java b/libraries/session/src/main/java/androidx/media3/session/MediaSession.java index 6935c1b17d..aa8336fb99 100644 --- a/libraries/session/src/main/java/androidx/media3/session/MediaSession.java +++ b/libraries/session/src/main/java/androidx/media3/session/MediaSession.java @@ -2588,7 +2588,11 @@ public class MediaSession { protected final void ensureBitmapLoaderIsSizeLimited() { int dimensionLimit = MediaSession.getBitmapDimensionLimit(context); if (bitmapLoader == null) { - bitmapLoader = new CacheBitmapLoader(new DataSourceBitmapLoader(context, dimensionLimit)); + bitmapLoader = + new CacheBitmapLoader( + new DataSourceBitmapLoader.Builder(context) + .setMaximumOutputDimension(dimensionLimit) + .build()); } else { bitmapLoader = new SizeLimitedBitmapLoader(bitmapLoader, dimensionLimit); } diff --git a/libraries/session/src/test/java/androidx/media3/session/CacheBitmapLoaderTest.java b/libraries/session/src/test/java/androidx/media3/session/CacheBitmapLoaderTest.java index 3bb122a6ee..dc3c4a410b 100644 --- a/libraries/session/src/test/java/androidx/media3/session/CacheBitmapLoaderTest.java +++ b/libraries/session/src/test/java/androidx/media3/session/CacheBitmapLoaderTest.java @@ -78,7 +78,7 @@ public class CacheBitmapLoaderTest { @Test public void decodeBitmap_requestWithSameDataTwice_returnsCachedFuture() throws Exception { CacheBitmapLoader cacheBitmapLoader = - new CacheBitmapLoader(new DataSourceBitmapLoader(context)); + new CacheBitmapLoader(new DataSourceBitmapLoader.Builder(context).build()); byte[] imageData = TestUtil.getByteArray(context, TEST_IMAGE_PATH); Bitmap expectedBitmap = apply90DegreeExifRotation( @@ -98,7 +98,7 @@ public class CacheBitmapLoaderTest { @Test public void decodeBitmap_requestWithDifferentData_returnsNewFuture() throws Exception { CacheBitmapLoader cacheBitmapLoader = - new CacheBitmapLoader(new DataSourceBitmapLoader(context)); + new CacheBitmapLoader(new DataSourceBitmapLoader.Builder(context).build()); byte[] imageData1 = TestUtil.getByteArray(context, TEST_IMAGE_PATH); byte[] imageData2 = TestUtil.getByteArray(context, SECOND_TEST_IMAGE_PATH); Bitmap expectedBitmap1 = @@ -123,7 +123,7 @@ public class CacheBitmapLoaderTest { @Test public void decodeBitmap_requestWithSameDataTwice_throwsException() { CacheBitmapLoader cacheBitmapLoader = - new CacheBitmapLoader(new DataSourceBitmapLoader(context)); + new CacheBitmapLoader(new DataSourceBitmapLoader.Builder(context).build()); // First request, no cached bitmap load request. ListenableFuture future1 = cacheBitmapLoader.decodeBitmap(new byte[0]); @@ -141,7 +141,7 @@ public class CacheBitmapLoaderTest { @Test public void loadBitmap_httpUri_requestWithSameUriTwice_returnsCachedFuture() throws Exception { CacheBitmapLoader cacheBitmapLoader = - new CacheBitmapLoader(new DataSourceBitmapLoader(context)); + new CacheBitmapLoader(new DataSourceBitmapLoader.Builder(context).build()); byte[] imageData = TestUtil.getByteArray(context, TEST_IMAGE_PATH); Buffer responseBody = new Buffer().write(imageData); MockWebServer mockWebServer = new MockWebServer(); @@ -166,7 +166,7 @@ public class CacheBitmapLoaderTest { @Test public void loadBitmap_httpUri_requestWithDifferentUri_returnsNewFuture() throws Exception { CacheBitmapLoader cacheBitmapLoader = - new CacheBitmapLoader(new DataSourceBitmapLoader(context)); + new CacheBitmapLoader(new DataSourceBitmapLoader.Builder(context).build()); byte[] imageData1 = TestUtil.getByteArray(context, TEST_IMAGE_PATH); byte[] imageData2 = TestUtil.getByteArray(context, SECOND_TEST_IMAGE_PATH); Buffer responseBody1 = new Buffer().write(imageData1); @@ -198,7 +198,7 @@ public class CacheBitmapLoaderTest { @Test public void loadBitmap_httpUri_requestWithSameUriTwice_throwsException() { CacheBitmapLoader cacheBitmapLoader = - new CacheBitmapLoader(new DataSourceBitmapLoader(context)); + new CacheBitmapLoader(new DataSourceBitmapLoader.Builder(context).build()); MockWebServer mockWebServer = new MockWebServer(); mockWebServer.enqueue(new MockResponse().setResponseCode(404)); Uri uri = Uri.parse(mockWebServer.url("test_path").toString()); @@ -227,7 +227,8 @@ public class CacheBitmapLoaderTest { throws Exception { CacheBitmapLoader cacheBitmapLoader = new CacheBitmapLoader( - new LoadBitmapFromMetadataOnlyBitmapLoader(new DataSourceBitmapLoader(context))); + new LoadBitmapFromMetadataOnlyBitmapLoader( + new DataSourceBitmapLoader.Builder(context).build())); byte[] imageData = TestUtil.getByteArray(context, TEST_IMAGE_PATH); Bitmap expectedBitmap = apply90DegreeExifRotation( @@ -250,7 +251,8 @@ public class CacheBitmapLoaderTest { public void loadBitmapFromMetadata_requestWithDifferentData_returnsNewFuture() throws Exception { CacheBitmapLoader cacheBitmapLoader = new CacheBitmapLoader( - new LoadBitmapFromMetadataOnlyBitmapLoader(new DataSourceBitmapLoader(context))); + new LoadBitmapFromMetadataOnlyBitmapLoader( + new DataSourceBitmapLoader.Builder(context).build())); byte[] imageData1 = TestUtil.getByteArray(context, TEST_IMAGE_PATH); byte[] imageData2 = TestUtil.getByteArray(context, SECOND_TEST_IMAGE_PATH); Bitmap expectedBitmap1 = @@ -280,7 +282,8 @@ public class CacheBitmapLoaderTest { public void loadBitmapFromMetadata_requestWithSameDataTwice_throwsException() { CacheBitmapLoader cacheBitmapLoader = new CacheBitmapLoader( - new LoadBitmapFromMetadataOnlyBitmapLoader(new DataSourceBitmapLoader(context))); + new LoadBitmapFromMetadataOnlyBitmapLoader( + new DataSourceBitmapLoader.Builder(context).build())); MediaMetadata metadata = new MediaMetadata.Builder().setArtworkData(new byte[0], PICTURE_TYPE_MEDIA).build(); @@ -302,7 +305,8 @@ public class CacheBitmapLoaderTest { throws Exception { CacheBitmapLoader cacheBitmapLoader = new CacheBitmapLoader( - new LoadBitmapFromMetadataOnlyBitmapLoader(new DataSourceBitmapLoader(context))); + new LoadBitmapFromMetadataOnlyBitmapLoader( + new DataSourceBitmapLoader.Builder(context).build())); byte[] imageData = TestUtil.getByteArray(context, TEST_IMAGE_PATH); Buffer responseBody = new Buffer().write(imageData); MockWebServer mockWebServer = new MockWebServer(); @@ -329,7 +333,8 @@ public class CacheBitmapLoaderTest { public void loadBitmapFromMetadata_requestWithDifferentUri_returnsNewFuture() throws Exception { CacheBitmapLoader cacheBitmapLoader = new CacheBitmapLoader( - new LoadBitmapFromMetadataOnlyBitmapLoader(new DataSourceBitmapLoader(context))); + new LoadBitmapFromMetadataOnlyBitmapLoader( + new DataSourceBitmapLoader.Builder(context).build())); byte[] imageData1 = TestUtil.getByteArray(context, TEST_IMAGE_PATH); byte[] imageData2 = TestUtil.getByteArray(context, SECOND_TEST_IMAGE_PATH); Buffer responseBody1 = new Buffer().write(imageData1); @@ -364,7 +369,8 @@ public class CacheBitmapLoaderTest { public void loadBitmapFromMetadata_requestWithSameUriTwice_throwsException() { CacheBitmapLoader cacheBitmapLoader = new CacheBitmapLoader( - new LoadBitmapFromMetadataOnlyBitmapLoader(new DataSourceBitmapLoader(context))); + new LoadBitmapFromMetadataOnlyBitmapLoader( + new DataSourceBitmapLoader.Builder(context).build())); MockWebServer mockWebServer = new MockWebServer(); mockWebServer.enqueue(new MockResponse().setResponseCode(404)); Uri uri = Uri.parse(mockWebServer.url("test_path").toString()); diff --git a/libraries/session/src/test/java/androidx/media3/session/LegacyConversionsTest.java b/libraries/session/src/test/java/androidx/media3/session/LegacyConversionsTest.java index 6dd0457dee..5e3d3f7a7b 100644 --- a/libraries/session/src/test/java/androidx/media3/session/LegacyConversionsTest.java +++ b/libraries/session/src/test/java/androidx/media3/session/LegacyConversionsTest.java @@ -78,7 +78,7 @@ public final class LegacyConversionsTest { @Before public void setUp() { context = ApplicationProvider.getApplicationContext(); - bitmapLoader = new CacheBitmapLoader(new DataSourceBitmapLoader(context)); + bitmapLoader = new CacheBitmapLoader(new DataSourceBitmapLoader.Builder(context).build()); } @Test diff --git a/libraries/session/src/test/java/androidx/media3/session/SizeLimitedBitmapLoaderTest.java b/libraries/session/src/test/java/androidx/media3/session/SizeLimitedBitmapLoaderTest.java index e36a323e84..f2307fb6f5 100644 --- a/libraries/session/src/test/java/androidx/media3/session/SizeLimitedBitmapLoaderTest.java +++ b/libraries/session/src/test/java/androidx/media3/session/SizeLimitedBitmapLoaderTest.java @@ -72,7 +72,7 @@ public class SizeLimitedBitmapLoaderTest { public void decodeBitmapWithLimit() throws Exception { int limit = MediaSession.getBitmapDimensionLimit(context); SizeLimitedBitmapLoader sizeLimitedBitmapLoader = - new SizeLimitedBitmapLoader(new DataSourceBitmapLoader(context), limit); + new SizeLimitedBitmapLoader(new DataSourceBitmapLoader.Builder(context).build(), limit); byte[] imageData = TestUtil.getByteArray(context, TEST_IMAGE_PATH); Bitmap expectedBitmap = getExpectedBitmap(imageData, limit); @@ -85,7 +85,7 @@ public class SizeLimitedBitmapLoaderTest { public void loadBitmapWithLimit() throws Exception { int limit = MediaSession.getBitmapDimensionLimit(context); SizeLimitedBitmapLoader sizeLimitedBitmapLoader = - new SizeLimitedBitmapLoader(new DataSourceBitmapLoader(context), limit); + new SizeLimitedBitmapLoader(new DataSourceBitmapLoader.Builder(context).build(), limit); byte[] imageData = TestUtil.getByteArray(context, TEST_IMAGE_PATH); Buffer responseBody = new Buffer().write(imageData); MockWebServer mockWebServer = new MockWebServer(); @@ -103,7 +103,7 @@ public class SizeLimitedBitmapLoaderTest { public void loadBitmapWithLimitWithDifferentUris() throws Exception { int limit = MediaSession.getBitmapDimensionLimit(context); SizeLimitedBitmapLoader sizeLimitedBitmapLoader = - new SizeLimitedBitmapLoader(new DataSourceBitmapLoader(context), limit); + new SizeLimitedBitmapLoader(new DataSourceBitmapLoader.Builder(context).build(), limit); byte[] imageData1 = TestUtil.getByteArray(context, TEST_IMAGE_PATH); byte[] imageData2 = TestUtil.getByteArray(context, SECOND_TEST_IMAGE_PATH); Buffer responseBody1 = new Buffer().write(imageData1); @@ -132,7 +132,7 @@ public class SizeLimitedBitmapLoaderTest { public void loadBitmapWithLimitWithInvalidUri() { int limit = MediaSession.getBitmapDimensionLimit(context); SizeLimitedBitmapLoader sizeLimitedBitmapLoader = - new SizeLimitedBitmapLoader(new DataSourceBitmapLoader(context), limit); + new SizeLimitedBitmapLoader(new DataSourceBitmapLoader.Builder(context).build(), limit); MockWebServer mockWebServer = new MockWebServer(); mockWebServer.enqueue(new MockResponse().setResponseCode(404)); Uri uri = Uri.parse(mockWebServer.url("test_path").toString()); @@ -152,7 +152,8 @@ public class SizeLimitedBitmapLoaderTest { int limit = MediaSession.getBitmapDimensionLimit(context); byte[] imageData = TestUtil.getByteArray(context, TEST_IMAGE_PATH); LoadBitmapFromMetadataOnlyBitmapLoader testBitmapLoader = - new LoadBitmapFromMetadataOnlyBitmapLoader(new DataSourceBitmapLoader(context)); + new LoadBitmapFromMetadataOnlyBitmapLoader( + new DataSourceBitmapLoader.Builder(context).build()); SizeLimitedBitmapLoader sizeLimitedBitmapLoader = new SizeLimitedBitmapLoader(testBitmapLoader, limit); Buffer responseBody = new Buffer().write(imageData); diff --git a/libraries/test_session_current/src/androidTest/java/androidx/media3/session/MediaControllerMediaSessionCompatCallbackAggregationTest.java b/libraries/test_session_current/src/androidTest/java/androidx/media3/session/MediaControllerMediaSessionCompatCallbackAggregationTest.java index c0a7563538..08f80fc476 100644 --- a/libraries/test_session_current/src/androidTest/java/androidx/media3/session/MediaControllerMediaSessionCompatCallbackAggregationTest.java +++ b/libraries/test_session_current/src/androidTest/java/androidx/media3/session/MediaControllerMediaSessionCompatCallbackAggregationTest.java @@ -88,7 +88,7 @@ public class MediaControllerMediaSessionCompatCallbackAggregationTest { public void setUp() throws Exception { context = ApplicationProvider.getApplicationContext(); session = new RemoteMediaSessionCompat(DEFAULT_TEST_NAME, context); - bitmapLoader = new CacheBitmapLoader(new DataSourceBitmapLoader(context)); + bitmapLoader = new CacheBitmapLoader(new DataSourceBitmapLoader.Builder(context).build()); } @After diff --git a/libraries/test_session_current/src/androidTest/java/androidx/media3/session/MediaControllerWithMediaSessionCompatTest.java b/libraries/test_session_current/src/androidTest/java/androidx/media3/session/MediaControllerWithMediaSessionCompatTest.java index 656ca206e0..87aa796ea4 100644 --- a/libraries/test_session_current/src/androidTest/java/androidx/media3/session/MediaControllerWithMediaSessionCompatTest.java +++ b/libraries/test_session_current/src/androidTest/java/androidx/media3/session/MediaControllerWithMediaSessionCompatTest.java @@ -135,7 +135,7 @@ public class MediaControllerWithMediaSessionCompatTest { public void setUp() throws Exception { context = ApplicationProvider.getApplicationContext(); session = new RemoteMediaSessionCompat(DEFAULT_TEST_NAME, context); - bitmapLoader = new CacheBitmapLoader(new DataSourceBitmapLoader(context)); + bitmapLoader = new CacheBitmapLoader(new DataSourceBitmapLoader.Builder(context).build()); } @After diff --git a/libraries/transformer/src/androidTest/java/androidx/media3/transformer/RawAssetLoaderAndroidTest.java b/libraries/transformer/src/androidTest/java/androidx/media3/transformer/RawAssetLoaderAndroidTest.java index 95bd6ca580..3936bfcf87 100644 --- a/libraries/transformer/src/androidTest/java/androidx/media3/transformer/RawAssetLoaderAndroidTest.java +++ b/libraries/transformer/src/androidTest/java/androidx/media3/transformer/RawAssetLoaderAndroidTest.java @@ -146,7 +146,11 @@ public class RawAssetLoaderAndroidTest { @Test public void videoTranscoding_withTextureInput_completesWithCorrectFrameCountAndDuration() throws Exception { - Bitmap bitmap = new DataSourceBitmapLoader(context).loadBitmap(Uri.parse(PNG_ASSET.uri)).get(); + Bitmap bitmap = + new DataSourceBitmapLoader.Builder(context) + .build() + .loadBitmap(Uri.parse(PNG_ASSET.uri)) + .get(); DefaultVideoFrameProcessor.Factory videoFrameProcessorFactory = new DefaultVideoFrameProcessor.Factory.Builder() .setGlObjectsProvider(new DefaultGlObjectsProvider(createOpenGlObjects())) @@ -189,7 +193,11 @@ public class RawAssetLoaderAndroidTest { @Test public void videoEditing_withTextureInput_completesWithCorrectFrameCountAndDuration() throws Exception { - Bitmap bitmap = new DataSourceBitmapLoader(context).loadBitmap(Uri.parse(PNG_ASSET.uri)).get(); + Bitmap bitmap = + new DataSourceBitmapLoader.Builder(context) + .build() + .loadBitmap(Uri.parse(PNG_ASSET.uri)) + .get(); EGLContext currentContext = createOpenGlObjects(); DefaultVideoFrameProcessor.Factory videoFrameProcessorFactory = new DefaultVideoFrameProcessor.Factory.Builder() @@ -235,7 +243,11 @@ public class RawAssetLoaderAndroidTest { @Test public void audioAndVideoTranscoding_withRawData_completesWithCorrectFrameCountAndDuration() throws Exception { - Bitmap bitmap = new DataSourceBitmapLoader(context).loadBitmap(Uri.parse(PNG_ASSET.uri)).get(); + Bitmap bitmap = + new DataSourceBitmapLoader.Builder(context) + .build() + .loadBitmap(Uri.parse(PNG_ASSET.uri)) + .get(); DefaultVideoFrameProcessor.Factory videoFrameProcessorFactory = new DefaultVideoFrameProcessor.Factory.Builder() .setGlObjectsProvider(new DefaultGlObjectsProvider(createOpenGlObjects())) diff --git a/libraries/transformer/src/androidTest/java/androidx/media3/transformer/TransformerEndToEndTest.java b/libraries/transformer/src/androidTest/java/androidx/media3/transformer/TransformerEndToEndTest.java index 778d9239c4..48a47aaa8a 100644 --- a/libraries/transformer/src/androidTest/java/androidx/media3/transformer/TransformerEndToEndTest.java +++ b/libraries/transformer/src/androidTest/java/androidx/media3/transformer/TransformerEndToEndTest.java @@ -355,7 +355,11 @@ public class TransformerEndToEndTest { @Test public void videoEditing_withTextureInput_completesWithCorrectFrameCountAndDuration() throws Exception { - Bitmap bitmap = new DataSourceBitmapLoader(context).loadBitmap(Uri.parse(PNG_ASSET.uri)).get(); + Bitmap bitmap = + new DataSourceBitmapLoader.Builder(context) + .build() + .loadBitmap(Uri.parse(PNG_ASSET.uri)) + .get(); int expectedFrameCount = 2; EGLContext currentContext = createOpenGlObjects(); DefaultVideoFrameProcessor.Factory videoFrameProcessorFactory = @@ -409,7 +413,11 @@ public class TransformerEndToEndTest { @Test public void videoTranscoding_withTextureInput_completesWithCorrectFrameCountAndDuration() throws Exception { - Bitmap bitmap = new DataSourceBitmapLoader(context).loadBitmap(Uri.parse(PNG_ASSET.uri)).get(); + Bitmap bitmap = + new DataSourceBitmapLoader.Builder(context) + .build() + .loadBitmap(Uri.parse(PNG_ASSET.uri)) + .get(); int expectedFrameCount = 2; EGLContext currentContext = createOpenGlObjects(); DefaultVideoFrameProcessor.Factory videoFrameProcessorFactory = diff --git a/libraries/transformer/src/androidTest/java/androidx/media3/transformer/TransformerUltraHdrTest.java b/libraries/transformer/src/androidTest/java/androidx/media3/transformer/TransformerUltraHdrTest.java index d8e8216c4a..d78830f5ff 100644 --- a/libraries/transformer/src/androidTest/java/androidx/media3/transformer/TransformerUltraHdrTest.java +++ b/libraries/transformer/src/androidTest/java/androidx/media3/transformer/TransformerUltraHdrTest.java @@ -190,7 +190,7 @@ public final class TransformerUltraHdrTest { final BitmapLoader bitmapLoader; { - bitmapLoader = new DataSourceBitmapLoader(context); + bitmapLoader = new DataSourceBitmapLoader.Builder(context).build(); } @Override diff --git a/libraries/transformer/src/test/java/androidx/media3/transformer/ImageAssetLoaderTest.java b/libraries/transformer/src/test/java/androidx/media3/transformer/ImageAssetLoaderTest.java index 5692de4a2c..c7f91347b8 100644 --- a/libraries/transformer/src/test/java/androidx/media3/transformer/ImageAssetLoaderTest.java +++ b/libraries/transformer/src/test/java/androidx/media3/transformer/ImageAssetLoaderTest.java @@ -172,7 +172,8 @@ public class ImageAssetLoaderTest { .setFrameRate(30) .build(); return new ImageAssetLoader.Factory( - context, new DataSourceBitmapLoader(ApplicationProvider.getApplicationContext())) + context, + new DataSourceBitmapLoader.Builder(ApplicationProvider.getApplicationContext()).build()) .createAssetLoader( editedMediaItem, Looper.myLooper(), diff --git a/testapps/controller/src/main/java/androidx/media3/testapp/controller/MediaAppControllerActivity.kt b/testapps/controller/src/main/java/androidx/media3/testapp/controller/MediaAppControllerActivity.kt index 9fdecb19f5..686e42599a 100644 --- a/testapps/controller/src/main/java/androidx/media3/testapp/controller/MediaAppControllerActivity.kt +++ b/testapps/controller/src/main/java/androidx/media3/testapp/controller/MediaAppControllerActivity.kt @@ -107,7 +107,7 @@ class MediaAppControllerActivity : AppCompatActivity() { supportActionBar?.setDisplayHomeAsUpEnabled(true) toolbar.setNavigationOnClickListener { finish() } - bitmapLoader = CacheBitmapLoader(DataSourceBitmapLoader(this)) + bitmapLoader = CacheBitmapLoader(DataSourceBitmapLoader.Builder(this).build()) viewPager = findViewById(R.id.view_pager) ratingViewGroup = findViewById(R.id.rating) mediaInfoText = findViewById(R.id.media_info)