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:
committed by
Commit Bot
parent
b537496520
commit
95a5f00484
@ -87,7 +87,22 @@ public class HardwareVideoEncoderTest {
|
||||
public void onEncodedFrame(EncodedImage frame, VideoEncoder.CodecSpecificInfo info) {
|
||||
assertNotNull(frame);
|
||||
assertNotNull(info);
|
||||
frameQueue.offer(frame);
|
||||
|
||||
// Make a copy because keeping a reference to the buffer is not allowed.
|
||||
final ByteBuffer bufferCopy = ByteBuffer.allocateDirect(frame.buffer.remaining());
|
||||
bufferCopy.put(frame.buffer);
|
||||
bufferCopy.rewind();
|
||||
|
||||
frameQueue.offer(EncodedImage.builder()
|
||||
.setBuffer(bufferCopy)
|
||||
.setEncodedWidth(frame.encodedWidth)
|
||||
.setEncodedHeight(frame.encodedHeight)
|
||||
.setCaptureTimeNs(frame.captureTimeNs)
|
||||
.setFrameType(frame.frameType)
|
||||
.setRotation(frame.rotation)
|
||||
.setCompleteFrame(frame.completeFrame)
|
||||
.setQp(frame.qp)
|
||||
.createEncodedImage());
|
||||
}
|
||||
|
||||
public EncodedImage poll() {
|
||||
|
||||
Reference in New Issue
Block a user