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

Unified Diff: webrtc/api/java/src/org/webrtc/VideoCapturer.java

Issue 1696553003: Android: Make VideoCapturer an interface for all VideoCapturers to implement (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Replace 'replace' with 'dispose' in jni as well Created 4 years, 10 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
« no previous file with comments | « webrtc/api/java/src/org/webrtc/PeerConnectionFactory.java ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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();
}
« no previous file with comments | « webrtc/api/java/src/org/webrtc/PeerConnectionFactory.java ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698