Commit 967e44c0 by tofunmi Committed by Marc Baechinger

Add TextureOverlay.configure() to configure overlay before frame processing

This change allows an overlay to be sized with respect to the video dimensions.

PiperOrigin-RevId: 497337734
parent 2716ff89
...@@ -150,14 +150,33 @@ public class OverlayTextureProcessorPixelTest { ...@@ -150,14 +150,33 @@ public class OverlayTextureProcessorPixelTest {
} }
@Test @Test
public void drawFrame_scaledBitmapOverlay_blendsBitmapIntoFrame() throws Exception { public void drawFrame_scaledBitmapOverlay_letterboxStretchesOverlay() throws Exception {
String testId = "drawFrame_scaledBitmapOverlay"; String testId = "drawFrame_scaledBitmapOverlay";
Bitmap overlayBitmap = readBitmap(OVERLAY_PNG_ASSET_PATH); Bitmap overlayBitmap = readBitmap(OVERLAY_PNG_ASSET_PATH);
float[] scaleMatrix = GlUtil.create4x4IdentityMatrix(); float[] scaleMatrix = GlUtil.create4x4IdentityMatrix();
Matrix.scaleM(scaleMatrix, /* mOffset= */ 0, /* x= */ 3, /* y= */ 3, /* z= */ 1);
OverlaySettings overlaySettings = new OverlaySettings.Builder().setMatrix(scaleMatrix).build(); OverlaySettings overlaySettings = new OverlaySettings.Builder().setMatrix(scaleMatrix).build();
BitmapOverlay staticBitmapOverlay = BitmapOverlay staticBitmapOverlay =
BitmapOverlay.createStaticBitmapOverlay(overlayBitmap, overlaySettings); new BitmapOverlay() {
@Override
public Bitmap getBitmap(long presentationTimeUs) {
return overlayBitmap;
}
@Override
public void configure(Size videoSize) {
Matrix.scaleM(
scaleMatrix,
/* mOffset= */ 0,
/* x= */ videoSize.getWidth() / (float) overlayBitmap.getWidth(),
/* y= */ 1,
/* z= */ 1);
}
@Override
public OverlaySettings getOverlaySettings(long presentationTimeUs) {
return overlaySettings;
}
};
overlayTextureProcessor = overlayTextureProcessor =
new OverlayEffect(ImmutableList.of(staticBitmapOverlay)) new OverlayEffect(ImmutableList.of(staticBitmapOverlay))
.toGlTextureProcessor(context, /* useHdr= */ false); .toGlTextureProcessor(context, /* useHdr= */ false);
......
...@@ -83,7 +83,11 @@ import com.google.common.collect.ImmutableList; ...@@ -83,7 +83,11 @@ import com.google.common.collect.ImmutableList;
public Size configure(int inputWidth, int inputHeight) { public Size configure(int inputWidth, int inputHeight) {
videoWidth = inputWidth; videoWidth = inputWidth;
videoHeight = inputHeight; videoHeight = inputHeight;
return new Size(inputWidth, inputHeight); Size videoSize = new Size(inputWidth, inputHeight);
for (TextureOverlay overlay : overlays) {
overlay.configure(videoSize);
}
return videoSize;
} }
@Override @Override
......
...@@ -40,6 +40,16 @@ public abstract class TextureOverlay { ...@@ -40,6 +40,16 @@ public abstract class TextureOverlay {
public abstract Size getTextureSize(long presentationTimeUs); public abstract Size getTextureSize(long presentationTimeUs);
/** /**
* Set up resources for the overlay given the input video’s dimensions.
*
* <p>This method will be called before drawing the first frame and before drawing subsequent
* frames with different input dimensions.
*
* @param videoSize The width and height of the input video, in pixels.
*/
public void configure(Size videoSize) {}
/**
* Returns the {@link OverlaySettings} controlling how the overlay is displayed at the specified * Returns the {@link OverlaySettings} controlling how the overlay is displayed at the specified
* timestamp. * timestamp.
* *
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment