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:
committed by
Commit Bot
parent
11bf2fa43c
commit
61db3fd77f
@ -11,22 +11,21 @@
|
||||
package org.webrtc;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
@JNINamespace("webrtc::jni")
|
||||
public class NV21Buffer implements VideoFrame.Buffer {
|
||||
private final byte[] data;
|
||||
private final int width;
|
||||
private final int height;
|
||||
private final Runnable releaseCallback;
|
||||
private final Object refCountLock = new Object();
|
||||
private final RefCountDelegate refCountDelegate;
|
||||
|
||||
private int refCount = 1;
|
||||
|
||||
public NV21Buffer(byte[] data, int width, int height, Runnable releaseCallback) {
|
||||
public NV21Buffer(byte[] data, int width, int height, @Nullable Runnable releaseCallback) {
|
||||
this.data = data;
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
this.releaseCallback = releaseCallback;
|
||||
this.refCountDelegate = new RefCountDelegate(releaseCallback);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -48,18 +47,12 @@ public class NV21Buffer implements VideoFrame.Buffer {
|
||||
|
||||
@Override
|
||||
public void retain() {
|
||||
synchronized (refCountLock) {
|
||||
++refCount;
|
||||
}
|
||||
refCountDelegate.retain();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void release() {
|
||||
synchronized (refCountLock) {
|
||||
if (--refCount == 0 && releaseCallback != null) {
|
||||
releaseCallback.run();
|
||||
}
|
||||
}
|
||||
refCountDelegate.release();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user