Update JavaI420Buffer.allocate to use native allocations.

This ensures memory is released timely and avoids problems with garbage
collection.

Native buffers don't support array operation, so FileVideoCapturer had
to be update to use FileChannel to write ByteBuffers directly.

Bug: None
Change-Id: I3f63d2adc159e9f39f0c68dd0bd6b1747686584e
Reviewed-on: https://webrtc-review.googlesource.com/55262
Commit-Queue: Sami Kalliomäki <sakal@webrtc.org>
Reviewed-by: Anders Carlsson <andersc@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#22118}
This commit is contained in:
Sami Kalliomäki
2018-02-20 11:19:58 +01:00
committed by Commit Bot
parent defad847b1
commit 0611065256
5 changed files with 43 additions and 18 deletions

View File

@ -85,7 +85,8 @@ public class JavaI420Buffer implements VideoFrame.I420Buffer {
int uPos = yPos + width * height;
int vPos = uPos + strideUV * chromaHeight;
ByteBuffer buffer = ByteBuffer.allocateDirect(width * height + 2 * strideUV * chromaHeight);
ByteBuffer buffer =
JniCommon.nativeAllocateByteBuffer(width * height + 2 * strideUV * chromaHeight);
buffer.position(yPos);
buffer.limit(uPos);
@ -99,8 +100,8 @@ public class JavaI420Buffer implements VideoFrame.I420Buffer {
buffer.limit(vPos + strideUV * chromaHeight);
ByteBuffer dataV = buffer.slice();
return new JavaI420Buffer(
width, height, dataY, width, dataU, strideUV, dataV, strideUV, null /* releaseCallback */);
return new JavaI420Buffer(width, height, dataY, width, dataU, strideUV, dataV, strideUV,
() -> { JniCommon.nativeFreeByteBuffer(buffer); });
}
@Override