Remove resolution alignment requirement (part 2)

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 <ssilkin@webrtc.org>
Reviewed-by: Åsa Persson <asapersson@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#39498}
This commit is contained in:
Sergey Silkin 2023-03-07 16:39:37 +01:00 committed by WebRTC LUCI CQ
parent 1f98b466b8
commit a02f90691e
3 changed files with 8 additions and 70 deletions

View File

@ -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<VideoFrame> 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);

View File

@ -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() {

View File

@ -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;