Make VideoFrame.Buffer implementations lock-free.

Replaces lock-based implementation with AtomicInteger.

Bug: webrtc:7749
Change-Id: I226093b0af2090c080dfd4f87ed8f33a3f9efbd8
Reviewed-on: https://webrtc-review.googlesource.com/64162
Commit-Queue: Sami Kalliomäki <sakal@webrtc.org>
Reviewed-by: Magnus Jedvert <magjed@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#22798}
This commit is contained in:
Sami Kalliomäki
2018-04-09 17:51:19 +02:00
committed by Commit Bot
parent 11bf2fa43c
commit 61db3fd77f
8 changed files with 115 additions and 71 deletions

View File

@ -27,8 +27,15 @@ import javax.annotation.Nullable;
* WebRTC software encoders.
*/
@JNINamespace("webrtc::jni")
public class VideoFrame {
public interface Buffer {
public class VideoFrame implements RefCounted {
/**
* Implements image storage medium. Might be for example an OpenGL texture or a memory region
* containing I420-data.
*
* <p>Reference counting is needed since a video buffer can be shared between multiple VideoSinks,
* and the buffer needs to be returned to the VideoSource as soon as all references are gone.
*/
public interface Buffer extends RefCounted {
/**
* Resolution of the buffer in pixels.
*/
@ -42,12 +49,8 @@ public class VideoFrame {
*/
@CalledByNative("Buffer") I420Buffer toI420();
/**
* Reference counting is needed since a video buffer can be shared between multiple VideoSinks,
* and the buffer needs to be returned to the VideoSource as soon as all references are gone.
*/
@CalledByNative("Buffer") void retain();
@CalledByNative("Buffer") void release();
@Override @CalledByNative("Buffer") void retain();
@Override @CalledByNative("Buffer") void release();
/**
* Crops a region defined by |cropx|, |cropY|, |cropWidth| and |cropHeight|. Scales it to size
@ -123,6 +126,11 @@ public class VideoFrame {
private final int rotation;
private final long timestampNs;
/**
* Constructs a new VideoFrame backed by the given {@code buffer}.
*
* @note Ownership of the buffer object is tranferred to the new VideoFrame.
*/
@CalledByNative
public VideoFrame(Buffer buffer, int rotation, long timestampNs) {
if (buffer == null) {
@ -171,13 +179,12 @@ public class VideoFrame {
return buffer.getWidth();
}
/**
* Reference counting of the underlying buffer.
*/
@Override
public void retain() {
buffer.retain();
}
@Override
@CalledByNative
public void release() {
buffer.release();