From 5b3491082b112183ffbb05c87ddd7e5003cf3ea9 Mon Sep 17 00:00:00 2001 From: tofunmi Date: Thu, 30 Nov 2023 04:51:36 -0800 Subject: [PATCH] fix: make BitmapOverlay constructor public So developers can subclass it #minor-release PiperOrigin-RevId: 586638134 --- .../androidx/media3/effect/BitmapOverlay.java | 98 +++++++++---------- 1 file changed, 49 insertions(+), 49 deletions(-) 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 fb0f4f2674..f39d1f5a10 100644 --- a/libraries/effect/src/main/java/androidx/media3/effect/BitmapOverlay.java +++ b/libraries/effect/src/main/java/androidx/media3/effect/BitmapOverlay.java @@ -47,7 +47,7 @@ public abstract class BitmapOverlay extends TextureOverlay { private int lastBitmapGenerationId; private @Nullable Bitmap lastBitmap; - /* package */ BitmapOverlay() { + public BitmapOverlay() { float[] temp = GlUtil.create4x4IdentityMatrix(); Matrix.scaleM(temp, /* offset */ 0, /* x= */ 1f, /* y= */ -1f, /* z= */ 1f); flipVerticallyMatrix = temp; @@ -55,54 +55,6 @@ public abstract class BitmapOverlay extends TextureOverlay { lastTextureId = C.INDEX_UNSET; } - /** - * Returns the overlay bitmap displayed at the specified timestamp. - * - * @param presentationTimeUs The presentation timestamp of the current frame, in microseconds. - * @throws VideoFrameProcessingException If an error occurs while processing or drawing the frame. - */ - public abstract Bitmap getBitmap(long presentationTimeUs) throws VideoFrameProcessingException; - - /** - * {@inheritDoc} - * - *

Gets the width and height of the cached bitmap. - * - * @param presentationTimeUs The presentation timestamp of the current frame, in microseconds. - */ - @Override - public Size getTextureSize(long presentationTimeUs) { - return new Size(checkNotNull(lastBitmap).getWidth(), checkNotNull(lastBitmap).getHeight()); - } - - @Override - public int getTextureId(long presentationTimeUs) throws VideoFrameProcessingException { - Bitmap bitmap = getBitmap(presentationTimeUs); - int generationId = bitmap.getGenerationId(); - if (bitmap != lastBitmap || generationId != lastBitmapGenerationId) { - lastBitmap = bitmap; - lastBitmapGenerationId = generationId; - try { - if (lastTextureId == C.INDEX_UNSET) { - lastTextureId = GlUtil.generateTexture(); - } - GlUtil.setTexture(lastTextureId, bitmap); - } catch (GlUtil.GlException e) { - throw new VideoFrameProcessingException(e); - } - } - return lastTextureId; - } - - @Override - public float[] getVertexTransformation(long presentationTimeUs) { - // Whereas the Android system uses the top-left corner as (0,0) of the - // coordinate system, OpenGL uses the bottom-left corner as (0,0), so the - // texture gets flipped. Flip the texture vertically to ensure the - // orientation of the output is correct. - return flipVerticallyMatrix; - } - /** * Creates a {@link BitmapOverlay} that shows the {@code overlayBitmap} in the same position and * size throughout the whole video. @@ -179,6 +131,54 @@ public abstract class BitmapOverlay extends TextureOverlay { }; } + /** + * Returns the overlay bitmap displayed at the specified timestamp. + * + * @param presentationTimeUs The presentation timestamp of the current frame, in microseconds. + * @throws VideoFrameProcessingException If an error occurs while processing or drawing the frame. + */ + public abstract Bitmap getBitmap(long presentationTimeUs) throws VideoFrameProcessingException; + + /** + * {@inheritDoc} + * + *

Gets the width and height of the cached bitmap. + * + * @param presentationTimeUs The presentation timestamp of the current frame, in microseconds. + */ + @Override + public Size getTextureSize(long presentationTimeUs) { + return new Size(checkNotNull(lastBitmap).getWidth(), checkNotNull(lastBitmap).getHeight()); + } + + @Override + public int getTextureId(long presentationTimeUs) throws VideoFrameProcessingException { + Bitmap bitmap = getBitmap(presentationTimeUs); + int generationId = bitmap.getGenerationId(); + if (bitmap != lastBitmap || generationId != lastBitmapGenerationId) { + lastBitmap = bitmap; + lastBitmapGenerationId = generationId; + try { + if (lastTextureId == C.INDEX_UNSET) { + lastTextureId = GlUtil.generateTexture(); + } + GlUtil.setTexture(lastTextureId, bitmap); + } catch (GlUtil.GlException e) { + throw new VideoFrameProcessingException(e); + } + } + return lastTextureId; + } + + @Override + public float[] getVertexTransformation(long presentationTimeUs) { + // Whereas the Android system uses the top-left corner as (0,0) of the + // coordinate system, OpenGL uses the bottom-left corner as (0,0), so the + // texture gets flipped. Flip the texture vertically to ensure the + // orientation of the output is correct. + return flipVerticallyMatrix; + } + @Override public void release() throws VideoFrameProcessingException { super.release();