From a02f90691e7e87197d3ef56f0b2d0a72fd3566b9 Mon Sep 17 00:00:00 2001 From: Sergey Silkin Date: Tue, 7 Mar 2023 16:39:37 +0100 Subject: [PATCH] Remove resolution alignment requirement (part 2) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit https://webrtc-review.googlesource.com/c/src/+/296340 removed hard resolution alignment requirement from HardwareVideoEncoder.initEncode(). This CL removes the hard resolution alignment requirement from HardwareVideoEncoder.resetCodec(). Bug: webrtc:13089 Change-Id: Ia9fcd4d6a7ea16509ec3f12c3c78a76d1eb6c6f0 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/296520 Commit-Queue: Sergey Silkin Reviewed-by: Åsa Persson Cr-Commit-Position: refs/heads/main@{#39498} --- ...ndroidVideoDecoderInstrumentationTest.java | 24 +++------- .../org/webrtc/HardwareVideoEncoderTest.java | 48 +------------------ .../java/org/webrtc/HardwareVideoEncoder.java | 6 --- 3 files changed, 8 insertions(+), 70 deletions(-) diff --git a/sdk/android/instrumentationtests/src/org/webrtc/AndroidVideoDecoderInstrumentationTest.java b/sdk/android/instrumentationtests/src/org/webrtc/AndroidVideoDecoderInstrumentationTest.java index 8166f5b544..6f448124e8 100644 --- a/sdk/android/instrumentationtests/src/org/webrtc/AndroidVideoDecoderInstrumentationTest.java +++ b/sdk/android/instrumentationtests/src/org/webrtc/AndroidVideoDecoderInstrumentationTest.java @@ -62,17 +62,14 @@ public final class AndroidVideoDecoderInstrumentationTest { private static final boolean ENABLE_INTEL_VP8_ENCODER = true; private static final boolean ENABLE_H264_HIGH_PROFILE = true; - private static final VideoEncoder.Settings ENCODER_SETTINGS = new VideoEncoder.Settings( - 1 /* core */, - getAlignedNumber(TEST_FRAME_WIDTH, HardwareVideoEncoderTest.getPixelAlignmentRequired()), - getAlignedNumber(TEST_FRAME_HEIGHT, HardwareVideoEncoderTest.getPixelAlignmentRequired()), - 300 /* kbps */, 30 /* fps */, 1 /* numberOfSimulcastStreams */, true /* automaticResizeOn */, - /* capabilities= */ new VideoEncoder.Capabilities(false /* lossNotification */)); + private static final VideoEncoder.Settings ENCODER_SETTINGS = + new VideoEncoder.Settings(1 /* core */, TEST_FRAME_WIDTH, TEST_FRAME_HEIGHT, 300 /* kbps */, + 30 /* fps */, 1 /* numberOfSimulcastStreams */, true /* automaticResizeOn */, + /* capabilities= */ new VideoEncoder.Capabilities(false /* lossNotification */)); private static final int DECODE_TIMEOUT_MS = 1000; - private static final VideoDecoder.Settings SETTINGS = new VideoDecoder.Settings(1 /* core */, - getAlignedNumber(TEST_FRAME_WIDTH, HardwareVideoEncoderTest.getPixelAlignmentRequired()), - getAlignedNumber(TEST_FRAME_HEIGHT, HardwareVideoEncoderTest.getPixelAlignmentRequired())); + private static final VideoDecoder.Settings SETTINGS = + new VideoDecoder.Settings(1 /* core */, TEST_FRAME_WIDTH, TEST_FRAME_HEIGHT); private static class MockDecodeCallback implements VideoDecoder.Callback { private BlockingQueue frameQueue = new LinkedBlockingQueue<>(); @@ -108,10 +105,7 @@ public final class AndroidVideoDecoderInstrumentationTest { private static VideoFrame.I420Buffer[] generateTestFrames() { VideoFrame.I420Buffer[] result = new VideoFrame.I420Buffer[TEST_FRAME_COUNT]; for (int i = 0; i < TEST_FRAME_COUNT; i++) { - result[i] = JavaI420Buffer.allocate( - getAlignedNumber(TEST_FRAME_WIDTH, HardwareVideoEncoderTest.getPixelAlignmentRequired()), - getAlignedNumber( - TEST_FRAME_HEIGHT, HardwareVideoEncoderTest.getPixelAlignmentRequired())); + result[i] = JavaI420Buffer.allocate(TEST_FRAME_WIDTH, TEST_FRAME_HEIGHT); // TODO(sakal): Generate content for the test frames. } return result; @@ -151,10 +145,6 @@ public final class AndroidVideoDecoderInstrumentationTest { assertEquals(VideoCodecStatus.OK, encoder.release()); } - private static int getAlignedNumber(int number, int alignment) { - return (number / alignment) * alignment; - } - @Before public void setUp() { NativeLibrary.initialize(new NativeLibrary.DefaultLoader(), TestConstants.NATIVE_LIBRARY); diff --git a/sdk/android/instrumentationtests/src/org/webrtc/HardwareVideoEncoderTest.java b/sdk/android/instrumentationtests/src/org/webrtc/HardwareVideoEncoderTest.java index 092d617270..ab8490e4ce 100644 --- a/sdk/android/instrumentationtests/src/org/webrtc/HardwareVideoEncoderTest.java +++ b/sdk/android/instrumentationtests/src/org/webrtc/HardwareVideoEncoderTest.java @@ -11,7 +11,6 @@ package org.webrtc; import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; @@ -344,14 +343,6 @@ public class HardwareVideoEncoderTest { } } - private static int getAlignedNumber(int number, int alignment) { - return (number / alignment) * alignment; - } - - public static int getPixelAlignmentRequired() { - return PIXEL_ALIGNMENT_REQUIRED; - } - // # Tests @Before public void setUp() { @@ -448,10 +439,7 @@ public class HardwareVideoEncoderTest { callback.assertFrameEncoded(frame); frame.release(); - // Android MediaCodec only guarantees of proper operation with 16-pixel-aligned input frame. - // Force the size of input frame with the greatest multiple of 16 below the original size. - frame = generateFrame(getAlignedNumber(SETTINGS.width / 4, PIXEL_ALIGNMENT_REQUIRED), - getAlignedNumber(SETTINGS.height / 4, PIXEL_ALIGNMENT_REQUIRED)); + frame = generateFrame(SETTINGS.width / 4, SETTINGS.height / 4); testEncodeFrame(encoder, frame, info); callback.assertFrameEncoded(frame); frame.release(); @@ -459,40 +447,6 @@ public class HardwareVideoEncoderTest { assertEquals(VideoCodecStatus.OK, encoder.release()); } - @Test - @SmallTest - public void testEncodeAlignmentCheck() { - VideoEncoder encoder = createEncoder(); - org.webrtc.HardwareVideoEncoderTest.MockEncoderCallback callback = - new org.webrtc.HardwareVideoEncoderTest.MockEncoderCallback(); - assertEquals(VideoCodecStatus.OK, encoder.initEncode(SETTINGS, callback)); - - VideoFrame frame; - VideoEncoder.EncodeInfo info = new VideoEncoder.EncodeInfo( - new EncodedImage.FrameType[] {EncodedImage.FrameType.VideoFrameDelta}); - - frame = generateFrame(SETTINGS.width / 2, SETTINGS.height / 2); - assertEquals(VideoCodecStatus.OK, testEncodeFrame(encoder, frame, info)); - frame.release(); - - // Android MediaCodec only guarantees of proper operation with 16-pixel-aligned input frame. - // Following input frame with non-aligned size would return ERR_SIZE. - frame = generateFrame(SETTINGS.width / 4, SETTINGS.height / 4); - assertNotEquals(VideoCodecStatus.OK, testEncodeFrame(encoder, frame, info)); - frame.release(); - - // Since our encoder has returned with an error, we reinitialize the encoder. - assertEquals(VideoCodecStatus.OK, encoder.release()); - assertEquals(VideoCodecStatus.OK, encoder.initEncode(SETTINGS, callback)); - - frame = generateFrame(getAlignedNumber(SETTINGS.width / 4, PIXEL_ALIGNMENT_REQUIRED), - getAlignedNumber(SETTINGS.height / 4, PIXEL_ALIGNMENT_REQUIRED)); - assertEquals(VideoCodecStatus.OK, testEncodeFrame(encoder, frame, info)); - frame.release(); - - assertEquals(VideoCodecStatus.OK, encoder.release()); - } - @Test @SmallTest public void testGetEncoderInfo() { diff --git a/sdk/android/src/java/org/webrtc/HardwareVideoEncoder.java b/sdk/android/src/java/org/webrtc/HardwareVideoEncoder.java index 4d3ca7de83..915383b89c 100644 --- a/sdk/android/src/java/org/webrtc/HardwareVideoEncoder.java +++ b/sdk/android/src/java/org/webrtc/HardwareVideoEncoder.java @@ -518,12 +518,6 @@ class HardwareVideoEncoder implements VideoEncoder { if (status != VideoCodecStatus.OK) { return status; } - - if (newWidth % REQUIRED_RESOLUTION_ALIGNMENT != 0 - || newHeight % REQUIRED_RESOLUTION_ALIGNMENT != 0) { - Logging.e(TAG, "MediaCodec is only tested with resolutions that are 16x16 aligned."); - return VideoCodecStatus.ERR_SIZE; - } width = newWidth; height = newHeight; useSurfaceMode = newUseSurfaceMode;