Update HWVideoEncoder to reuse codec buffer instead of copying the data.

In practice, this is safe since WebRTC doesn't access the buffer after the
callback returns. This avoids unnecessary memory allocations causing out of
memory errors.

Bug: b/72675429
Change-Id: I2ed0224f40b7e1fa67c7aba625b99211f9c1e0a3
Reviewed-on: https://webrtc-review.googlesource.com/49162
Commit-Queue: Sami Kalliomäki <sakal@webrtc.org>
Reviewed-by: Magnus Jedvert <magjed@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#21932}
This commit is contained in:
Sami Kalliomäki
2018-02-07 13:54:12 +01:00
committed by Commit Bot
parent b537496520
commit 95a5f00484
2 changed files with 19 additions and 4 deletions

View File

@ -506,11 +506,11 @@ class HardwareVideoEncoder implements VideoEncoder {
frameBuffer = ByteBuffer.allocateDirect(info.size + configBuffer.capacity());
configBuffer.rewind();
frameBuffer.put(configBuffer);
frameBuffer.put(codecOutputBuffer);
frameBuffer.rewind();
} else {
frameBuffer = ByteBuffer.allocateDirect(info.size);
frameBuffer = codecOutputBuffer.slice();
}
frameBuffer.put(codecOutputBuffer);
frameBuffer.rewind();
final EncodedImage.FrameType frameType = isKeyFrame
? EncodedImage.FrameType.VideoFrameKey