Android: Respect input buffer layout of MediaFormat

On Android, MediaCodec can request a specific layout of the input buffer.
One can use the stride and slice height to calculate the layout from
the Encoder's MediaFormat. The current code assumes
a specific layout, which is a problematic in Android 12.
Fix this by honoring the stride and slice-height.

Bug: webrtc:13427
Change-Id: I2d3e429309e3add3ae668e0390460b51e6a49eb9
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/240680
Reviewed-by: Niels Moller <nisse@webrtc.org>
Reviewed-by: Harald Alvestrand <hta@webrtc.org>
Commit-Queue: Daniel.L (Byoungchan) Lee <daniel.l@hpcnt.com>
Cr-Commit-Position: refs/heads/main@{#36033}
This commit is contained in:
Byoungchan Lee
2022-02-18 09:52:11 +09:00
committed by WebRTC LUCI CQ
parent 39f027e0b0
commit 0b06552ab3
8 changed files with 187 additions and 45 deletions

View File

@ -201,9 +201,10 @@ public class AndroidVideoDecoderTest {
MockitoAnnotations.initMocks(this);
when(mockSurfaceTextureHelper.getSurfaceTexture())
.thenReturn(new SurfaceTexture(/*texName=*/0));
MediaFormat inputFormat = new MediaFormat();
MediaFormat outputFormat = new MediaFormat();
// TODO(sakal): Add more details to output format as needed.
fakeMediaCodecWrapper = spy(new FakeMediaCodecWrapper(outputFormat));
fakeMediaCodecWrapper = spy(new FakeMediaCodecWrapper(inputFormat, outputFormat));
fakeDecoderCallback = new FakeDecoderCallback();
}

View File

@ -104,6 +104,7 @@ public class FakeMediaCodecWrapper implements MediaCodecWrapper {
private State state = State.STOPPED_UNINITIALIZED;
private @Nullable MediaFormat configuredFormat;
private int configuredFlags;
private final MediaFormat inputFormat;
private final MediaFormat outputFormat;
private final ByteBuffer[] inputBuffers = new ByteBuffer[NUM_INPUT_BUFFERS];
private final ByteBuffer[] outputBuffers = new ByteBuffer[NUM_OUTPUT_BUFFERS];
@ -111,7 +112,8 @@ public class FakeMediaCodecWrapper implements MediaCodecWrapper {
private final boolean[] outputBufferReserved = new boolean[NUM_OUTPUT_BUFFERS];
private final List<QueuedOutputBufferInfo> queuedOutputBuffers = new ArrayList<>();
public FakeMediaCodecWrapper(MediaFormat outputFormat) {
public FakeMediaCodecWrapper(MediaFormat inputFormat, MediaFormat outputFormat) {
this.inputFormat = inputFormat;
this.outputFormat = outputFormat;
}
@ -299,6 +301,11 @@ public class FakeMediaCodecWrapper implements MediaCodecWrapper {
return outputBuffers;
}
@Override
public MediaFormat getInputFormat() {
return inputFormat;
}
@Override
public MediaFormat getOutputFormat() {
return outputFormat;

View File

@ -161,9 +161,10 @@ public class HardwareVideoEncoderTest {
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
MediaFormat inputFormat = new MediaFormat();
MediaFormat outputFormat = new MediaFormat();
// TODO(sakal): Add more details to output format as needed.
fakeMediaCodecWrapper = spy(new FakeMediaCodecWrapper(outputFormat));
fakeMediaCodecWrapper = spy(new FakeMediaCodecWrapper(inputFormat, outputFormat));
}
@Test