Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(905)

Unified Diff: talk/app/webrtc/java/src/org/webrtc/VideoCapturerAndroid.java

Issue 1307973002: AndroidVideoCapturerJni: Fix threading issues (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Addressing tommi@s comments Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: talk/app/webrtc/java/src/org/webrtc/VideoCapturerAndroid.java
diff --git a/talk/app/webrtc/java/src/org/webrtc/VideoCapturerAndroid.java b/talk/app/webrtc/java/src/org/webrtc/VideoCapturerAndroid.java
index dee414673c202ce279a7cd6779af761436562876..ac42883e98cc7fbf8432e9aa4b30078aeb7b1704 100644
--- a/talk/app/webrtc/java/src/org/webrtc/VideoCapturerAndroid.java
+++ b/talk/app/webrtc/java/src/org/webrtc/VideoCapturerAndroid.java
@@ -720,17 +720,8 @@ public class VideoCapturerAndroid extends VideoCapturer implements PreviewCallba
frameObserver.OnOutputFormatRequest(width, height, fps);
}
- synchronized void returnBuffer(final long timeStamp) {
- if (cameraThreadHandler == null) {
- // The camera has been stopped.
- videoBuffers.returnBuffer(timeStamp);
- return;
- }
- cameraThreadHandler.post(new Runnable() {
- @Override public void run() {
- videoBuffers.returnBuffer(timeStamp);
- }
- });
+ void returnBuffer(long timeStamp) {
+ videoBuffers.returnBuffer(timeStamp);
}
private int getDeviceOrientation() {
@@ -854,7 +845,8 @@ public class VideoCapturerAndroid extends VideoCapturer implements PreviewCallba
}
// Class used for allocating and bookkeeping video frames. All buffers are
- // direct allocated so that they can be directly used from native code.
+ // direct allocated so that they can be directly used from native code. This class is
+ // synchronized and can be called from multiple threads.
private static class FramePool {
// Arbitrary queue depth. Higher number means more memory allocated & held,
// lower number means more sensitivity to processing time in the client (and
@@ -869,12 +861,12 @@ public class VideoCapturerAndroid extends VideoCapturer implements PreviewCallba
private int frameSize = 0;
private Camera camera;
- int numCaptureBuffersAvailable() {
+ synchronized int numCaptureBuffersAvailable() {
return queuedBuffers.size();
}
// Discards previous queued buffers and adds new callback buffers to camera.
- void queueCameraBuffers(int frameSize, Camera camera) {
+ synchronized void queueCameraBuffers(int frameSize, Camera camera) {
this.camera = camera;
this.frameSize = frameSize;
@@ -888,7 +880,7 @@ public class VideoCapturerAndroid extends VideoCapturer implements PreviewCallba
+ " buffers of size " + frameSize + ".");
}
- String pendingFramesTimeStamps() {
+ synchronized String pendingFramesTimeStamps() {
List<Long> timeStampsMs = new ArrayList<Long>();
for (Long timeStampNs : pendingBuffers.keySet()) {
timeStampsMs.add(TimeUnit.NANOSECONDS.toMillis(timeStampNs));
@@ -896,7 +888,7 @@ public class VideoCapturerAndroid extends VideoCapturer implements PreviewCallba
return timeStampsMs.toString();
}
- void stopReturnBuffersToCamera() {
+ synchronized void stopReturnBuffersToCamera() {
this.camera = null;
queuedBuffers.clear();
// Frames in |pendingBuffers| need to be kept alive until they are returned.
@@ -906,7 +898,7 @@ public class VideoCapturerAndroid extends VideoCapturer implements PreviewCallba
: " Pending buffers: " + pendingFramesTimeStamps() + "."));
}
- boolean reserveByteBuffer(byte[] data, long timeStamp) {
+ synchronized boolean reserveByteBuffer(byte[] data, long timeStamp) {
final ByteBuffer buffer = queuedBuffers.remove(data);
if (buffer == null) {
// Frames might be posted to |onPreviewFrame| with the previous format while changing
@@ -930,7 +922,7 @@ public class VideoCapturerAndroid extends VideoCapturer implements PreviewCallba
return true;
}
- void returnBuffer(long timeStamp) {
+ synchronized void returnBuffer(long timeStamp) {
final ByteBuffer returnedFrame = pendingBuffers.remove(timeStamp);
if (returnedFrame == null) {
throw new RuntimeException("unknown data buffer with time stamp "
« no previous file with comments | « talk/app/webrtc/java/jni/androidvideocapturer_jni.cc ('k') | webrtc/common_video/interface/video_frame_buffer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698