mirror of
https://github.com/androidx/media.git
synced 2025-05-03 21:57:46 +08:00
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
This commit is contained in:
parent
88fd9e18f5
commit
18f58d1790
@ -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;
|
|||||||
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
|
||||||
|
@ -41,6 +41,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.
|
||||||
|
Binary file not shown.
Before Width: | Height: | Size: 540 KiB After Width: | Height: | Size: 539 KiB |
Loading…
x
Reference in New Issue
Block a user