Index: webrtc/api/java/src/org/webrtc/VideoCapturer.java |
diff --git a/webrtc/api/java/src/org/webrtc/VideoCapturer.java b/webrtc/api/java/src/org/webrtc/VideoCapturer.java |
index 9a479a3d074127287e979c0233fd379f47f45070..21bfafaf96f59a61349c6e8964161e9fa8660f39 100644 |
--- a/webrtc/api/java/src/org/webrtc/VideoCapturer.java |
+++ b/webrtc/api/java/src/org/webrtc/VideoCapturer.java |
@@ -10,36 +10,89 @@ |
package org.webrtc; |
-/** Java version of cricket::VideoCapturer. */ |
-// TODO(perkj): Merge VideoCapturer and VideoCapturerAndroid. |
-public class VideoCapturer { |
- private long nativeVideoCapturer; |
+import android.content.Context; |
- protected VideoCapturer() { |
- } |
+import org.json.JSONException; |
+ |
+// Base interface for all VideoCapturers to implement. |
+// TODO(magjed): Simplify and improve this interface. |
+public interface VideoCapturer { |
+ // Interface used for providing callbacks to an observer. |
+ public interface CapturerObserver { |
+ // Notify if the camera have been started successfully or not. |
+ // Called on a Java thread owned by VideoCapturer. |
+ void onCapturerStarted(boolean success); |
+ |
+ // Delivers a captured frame. Called on a Java thread owned by VideoCapturer. |
+ void onByteBufferFrameCaptured(byte[] data, int width, int height, int rotation, |
+ long timeStamp); |
- // Sets |nativeCapturer| to be owned by VideoCapturer. |
- protected void setNativeCapturer(long nativeCapturer) { |
- this.nativeVideoCapturer = nativeCapturer; |
+ // Delivers a captured frame in a texture with id |oesTextureId|. Called on a Java thread |
+ // owned by VideoCapturer. |
+ void onTextureFrameCaptured( |
+ int width, int height, int oesTextureId, float[] transformMatrix, int rotation, |
+ long timestamp); |
+ |
+ // Requests an output format from the video capturer. Captured frames |
+ // by the camera will be scaled/or dropped by the video capturer. |
+ // Called on a Java thread owned by VideoCapturer. |
+ void onOutputFormatRequest(int width, int height, int framerate); |
} |
- // Package-visible for PeerConnectionFactory. |
- long takeNativeVideoCapturer() { |
- if (nativeVideoCapturer == 0) { |
- throw new RuntimeException("Capturer can only be taken once!"); |
+ // An implementation of CapturerObserver that forwards all calls from |
+ // Java to the C layer. |
+ static class NativeObserver implements CapturerObserver { |
+ private final long nativeCapturer; |
+ |
+ public NativeObserver(long nativeCapturer) { |
+ this.nativeCapturer = nativeCapturer; |
+ } |
+ |
+ @Override |
+ public void onCapturerStarted(boolean success) { |
+ nativeCapturerStarted(nativeCapturer, success); |
} |
- long ret = nativeVideoCapturer; |
- nativeVideoCapturer = 0; |
- return ret; |
- } |
- public void dispose() { |
- // No-op iff this capturer is owned by a source (see comment on |
- // PeerConnectionFactoryInterface::CreateVideoSource()). |
- if (nativeVideoCapturer != 0) { |
- free(nativeVideoCapturer); |
+ @Override |
+ public void onByteBufferFrameCaptured(byte[] data, int width, int height, |
+ int rotation, long timeStamp) { |
+ nativeOnByteBufferFrameCaptured(nativeCapturer, data, data.length, width, height, rotation, |
+ timeStamp); |
} |
+ |
+ @Override |
+ public void onTextureFrameCaptured( |
+ int width, int height, int oesTextureId, float[] transformMatrix, int rotation, |
+ long timestamp) { |
+ nativeOnTextureFrameCaptured(nativeCapturer, width, height, oesTextureId, transformMatrix, |
+ rotation, timestamp); |
+ } |
+ |
+ @Override |
+ public void onOutputFormatRequest(int width, int height, int framerate) { |
+ nativeOnOutputFormatRequest(nativeCapturer, width, height, framerate); |
+ } |
+ |
+ private native void nativeCapturerStarted(long nativeCapturer, |
+ boolean success); |
+ private native void nativeOnByteBufferFrameCaptured(long nativeCapturer, |
+ byte[] data, int length, int width, int height, int rotation, long timeStamp); |
+ private native void nativeOnTextureFrameCaptured(long nativeCapturer, int width, int height, |
+ int oesTextureId, float[] transformMatrix, int rotation, long timestamp); |
+ private native void nativeOnOutputFormatRequest(long nativeCapturer, |
+ int width, int height, int framerate); |
} |
- private static native void free(long nativeVideoCapturer); |
+ String getSupportedFormatsAsJson() throws JSONException; |
+ |
+ SurfaceTextureHelper getSurfaceTextureHelper(); |
+ |
+ void startCapture( |
+ final int width, final int height, final int framerate, |
+ final Context applicationContext, final CapturerObserver frameObserver); |
+ |
+ // Blocks until capture is stopped. |
+ void stopCapture() throws InterruptedException; |
+ |
+ void dispose(); |
} |