Format with google-java-format

This commit is contained in:
microkatz 2024-08-28 12:41:44 +00:00
parent 7473156853
commit 0ac26c4004
2 changed files with 34 additions and 38 deletions

View File

@ -1342,12 +1342,16 @@ public class MediaCodecVideoRenderer extends MediaCodecRenderer
? mediaFormat.getInteger(KEY_CROP_BOTTOM) - mediaFormat.getInteger(KEY_CROP_TOP) + 1 ? mediaFormat.getInteger(KEY_CROP_BOTTOM) - mediaFormat.getInteger(KEY_CROP_TOP) + 1
: mediaFormat.getInteger(MediaFormat.KEY_HEIGHT); : mediaFormat.getInteger(MediaFormat.KEY_HEIGHT);
} }
boolean hasPixelAspectRatio = (Util.SDK_INT >= 30) && mediaFormat != null && mediaFormat.containsKey(MediaFormat.KEY_PIXEL_ASPECT_RATIO_WIDTH) boolean hasPixelAspectRatio =
&& mediaFormat.containsKey(MediaFormat.KEY_PIXEL_ASPECT_RATIO_HEIGHT); (Util.SDK_INT >= 30)
pixelWidthHeightRatio = hasPixelAspectRatio ? && mediaFormat != null
(float)mediaFormat.getInteger(MediaFormat.KEY_PIXEL_ASPECT_RATIO_WIDTH) / && mediaFormat.containsKey(MediaFormat.KEY_PIXEL_ASPECT_RATIO_WIDTH)
mediaFormat.getInteger(MediaFormat.KEY_PIXEL_ASPECT_RATIO_HEIGHT) && mediaFormat.containsKey(MediaFormat.KEY_PIXEL_ASPECT_RATIO_HEIGHT);
: format.pixelWidthHeightRatio; pixelWidthHeightRatio =
hasPixelAspectRatio
? (float) mediaFormat.getInteger(MediaFormat.KEY_PIXEL_ASPECT_RATIO_WIDTH)
/ mediaFormat.getInteger(MediaFormat.KEY_PIXEL_ASPECT_RATIO_HEIGHT)
: format.pixelWidthHeightRatio;
// The decoder applies the rotation when rendering to the surface. For 90 and 270 degree // The decoder applies the rotation when rendering to the surface. For 90 and 270 degree
// rotations, we need to flip the width, height and pixel aspect ratio to reflect the rotation // rotations, we need to flip the width, height and pixel aspect ratio to reflect the rotation
// that was applied. // that was applied.

View File

@ -751,11 +751,27 @@ public class MediaCodecVideoRendererTest {
@Config(minSdk = 30) @Config(minSdk = 30)
@Test @Test
public void render_withMediaCodecAlteringPixelAspectRatioWidthHeight_sendsVideoSizeChangeWithMediaFormatValues() throws Exception { public void
render_withMediaCodecModifyingPixelAspectRatioWidthHeight_sendsVideoSizeChangeWithMediaFormatValues()
throws Exception {
MediaCodecAdapter.Factory codecAdapterFactory = MediaCodecAdapter.Factory codecAdapterFactory =
configuration -> configuration ->
new ForwardingSynchronousMediaCodecAdapterAlteringPixelAspectRatio( new ForwardingSynchronousMediaCodecAdapter(
new SynchronousMediaCodecAdapter.Factory().createAdapter(configuration)); new SynchronousMediaCodecAdapter.Factory().createAdapter(configuration)) {
@Override
public MediaFormat getOutputFormat() {
MediaFormat mediaFormat = adapter.getOutputFormat();
if (Util.SDK_INT >= 30) {
int pixelAspectRatioHeight = 1 << 30; // Max integer power of 2.
int pixelAspectRatioWidth = (int) (0.5f * pixelAspectRatioHeight);
mediaFormat.setInteger(
MediaFormat.KEY_PIXEL_ASPECT_RATIO_WIDTH, pixelAspectRatioWidth);
mediaFormat.setInteger(
MediaFormat.KEY_PIXEL_ASPECT_RATIO_HEIGHT, pixelAspectRatioHeight);
}
return mediaFormat;
}
};
MediaCodecVideoRenderer mediaCodecVideoRendererWithCustomAdapter = MediaCodecVideoRenderer mediaCodecVideoRendererWithCustomAdapter =
new MediaCodecVideoRenderer( new MediaCodecVideoRenderer(
ApplicationProvider.getApplicationContext(), ApplicationProvider.getApplicationContext(),
@ -773,9 +789,8 @@ public class MediaCodecVideoRendererTest {
} }
}; };
mediaCodecVideoRendererWithCustomAdapter.init(/* index= */ 0, PlayerId.UNSET, Clock.DEFAULT); mediaCodecVideoRendererWithCustomAdapter.init(/* index= */ 0, PlayerId.UNSET, Clock.DEFAULT);
surface = new Surface(new SurfaceTexture(/* texName= */ 0)); mediaCodecVideoRendererWithCustomAdapter.handleMessage(
mediaCodecVideoRendererWithCustomAdapter.handleMessage(Renderer.MSG_SET_VIDEO_OUTPUT, surface); Renderer.MSG_SET_VIDEO_OUTPUT, new Surface(new SurfaceTexture(/* texName= */ 0)));
FakeSampleStream fakeSampleStream = FakeSampleStream fakeSampleStream =
new FakeSampleStream( new FakeSampleStream(
new DefaultAllocator(/* trimOnReset= */ true, /* individualAllocationSize= */ 1024), new DefaultAllocator(/* trimOnReset= */ true, /* individualAllocationSize= */ 1024),
@ -801,7 +816,8 @@ public class MediaCodecVideoRendererTest {
int positionUs = 0; int positionUs = 0;
do { do {
mediaCodecVideoRendererWithCustomAdapter.render(positionUs, SystemClock.elapsedRealtime() * 1000); mediaCodecVideoRendererWithCustomAdapter.render(
positionUs, SystemClock.elapsedRealtime() * 1000);
positionUs += 10; positionUs += 10;
} while (!mediaCodecVideoRendererWithCustomAdapter.isEnded()); } while (!mediaCodecVideoRendererWithCustomAdapter.isEnded());
shadowOf(testMainLooper).idle(); shadowOf(testMainLooper).idle();
@ -809,9 +825,7 @@ public class MediaCodecVideoRendererTest {
verify(eventListener) verify(eventListener)
.onVideoSizeChanged( .onVideoSizeChanged(
new VideoSize( new VideoSize(
VIDEO_H264.width, VIDEO_H264.width, VIDEO_H264.height, VIDEO_H264.pixelWidthHeightRatio / 2));
VIDEO_H264.height,
VIDEO_H264.pixelWidthHeightRatio / 2));
} }
@Test @Test
@ -1968,28 +1982,6 @@ public class MediaCodecVideoRendererTest {
} }
} }
private static final class ForwardingSynchronousMediaCodecAdapterAlteringPixelAspectRatio
extends ForwardingSynchronousMediaCodecAdapter {
ForwardingSynchronousMediaCodecAdapterAlteringPixelAspectRatio(MediaCodecAdapter adapter) {
super(adapter);
}
@Override
public MediaFormat getOutputFormat() {
MediaFormat mediaFormat = adapter.getOutputFormat();
if (Util.SDK_INT >= 30) {
int pixelAspectRatioHeight = 1 << 30;
int pixelAspectRatioWidth = (int) (0.5f * pixelAspectRatioHeight);
mediaFormat.setInteger(MediaFormat.KEY_PIXEL_ASPECT_RATIO_WIDTH,
pixelAspectRatioWidth);
mediaFormat.setInteger(MediaFormat.KEY_PIXEL_ASPECT_RATIO_HEIGHT,
pixelAspectRatioHeight);
}
return mediaFormat;
}
}
private abstract static class ForwardingSynchronousMediaCodecAdapter private abstract static class ForwardingSynchronousMediaCodecAdapter
implements MediaCodecAdapter { implements MediaCodecAdapter {
protected final MediaCodecAdapter adapter; protected final MediaCodecAdapter adapter;