OLD | NEW |
| (Empty) |
1 /* | |
2 * Copyright 2013 The WebRTC project authors. All Rights Reserved. | |
3 * | |
4 * Use of this source code is governed by a BSD-style license | |
5 * that can be found in the LICENSE file in the root of the source | |
6 * tree. An additional intellectual property rights grant can be found | |
7 * in the file PATENTS. All contributing project authors may | |
8 * be found in the AUTHORS file in the root of the source tree. | |
9 */ | |
10 | |
11 package org.webrtc; | |
12 | |
13 import android.content.Context; | |
14 | |
15 import java.util.List; | |
16 | |
17 // Base interface for all VideoCapturers to implement. | |
18 public interface VideoCapturer { | |
19 // Interface used for providing callbacks to an observer. | |
20 public interface CapturerObserver { | |
21 // Notify if the camera have been started successfully or not. | |
22 // Called on a Java thread owned by VideoCapturer. | |
23 void onCapturerStarted(boolean success); | |
24 | |
25 // Delivers a captured frame. Called on a Java thread owned by VideoCapturer
. | |
26 void onByteBufferFrameCaptured(byte[] data, int width, int height, int rotat
ion, | |
27 long timeStamp); | |
28 | |
29 // Delivers a captured frame in a texture with id |oesTextureId|. Called on
a Java thread | |
30 // owned by VideoCapturer. | |
31 void onTextureFrameCaptured( | |
32 int width, int height, int oesTextureId, float[] transformMatrix, int ro
tation, | |
33 long timestamp); | |
34 | |
35 // Requests an output format from the video capturer. Captured frames | |
36 // by the camera will be scaled/or dropped by the video capturer. | |
37 // Called on a Java thread owned by VideoCapturer. | |
38 void onOutputFormatRequest(int width, int height, int framerate); | |
39 } | |
40 | |
41 // An implementation of CapturerObserver that forwards all calls from | |
42 // Java to the C layer. | |
43 static class NativeObserver implements CapturerObserver { | |
44 private final long nativeCapturer; | |
45 | |
46 public NativeObserver(long nativeCapturer) { | |
47 this.nativeCapturer = nativeCapturer; | |
48 } | |
49 | |
50 @Override | |
51 public void onCapturerStarted(boolean success) { | |
52 nativeCapturerStarted(nativeCapturer, success); | |
53 } | |
54 | |
55 @Override | |
56 public void onByteBufferFrameCaptured(byte[] data, int width, int height, | |
57 int rotation, long timeStamp) { | |
58 nativeOnByteBufferFrameCaptured(nativeCapturer, data, data.length, width,
height, rotation, | |
59 timeStamp); | |
60 } | |
61 | |
62 @Override | |
63 public void onTextureFrameCaptured( | |
64 int width, int height, int oesTextureId, float[] transformMatrix, int ro
tation, | |
65 long timestamp) { | |
66 nativeOnTextureFrameCaptured(nativeCapturer, width, height, oesTextureId,
transformMatrix, | |
67 rotation, timestamp); | |
68 } | |
69 | |
70 @Override | |
71 public void onOutputFormatRequest(int width, int height, int framerate) { | |
72 nativeOnOutputFormatRequest(nativeCapturer, width, height, framerate); | |
73 } | |
74 | |
75 private native void nativeCapturerStarted(long nativeCapturer, | |
76 boolean success); | |
77 private native void nativeOnByteBufferFrameCaptured(long nativeCapturer, | |
78 byte[] data, int length, int width, int height, int rotation, long timeS
tamp); | |
79 private native void nativeOnTextureFrameCaptured(long nativeCapturer, int wi
dth, int height, | |
80 int oesTextureId, float[] transformMatrix, int rotation, long timestamp)
; | |
81 private native void nativeOnOutputFormatRequest(long nativeCapturer, | |
82 int width, int height, int framerate); | |
83 } | |
84 | |
85 /** | |
86 * Returns a list with all the formats this VideoCapturer supports. | |
87 */ | |
88 List<CameraEnumerationAndroid.CaptureFormat> getSupportedFormats(); | |
89 | |
90 /** | |
91 * Start capturing frames in a format that is as close as possible to |width|
x |height| and | |
92 * |framerate|. If the VideoCapturer wants to deliver texture frames, it shoul
d do this by | |
93 * rendering on the SurfaceTexture in |surfaceTextureHelper|, register itself
as a listener, | |
94 * and forward the texture frames to CapturerObserver.onTextureFrameCaptured()
. | |
95 */ | |
96 void startCapture( | |
97 int width, int height, int framerate, SurfaceTextureHelper surfaceTextureH
elper, | |
98 Context applicationContext, CapturerObserver frameObserver); | |
99 | |
100 /** | |
101 * Stop capturing. This function should block until capture is actually stoppe
d. | |
102 */ | |
103 void stopCapture() throws InterruptedException; | |
104 | |
105 void onOutputFormatRequest(int width, int height, int framerate); | |
106 | |
107 void changeCaptureFormat(int width, int height, int framerate); | |
108 | |
109 /** | |
110 * Perform any final cleanup here. No more capturing will be done after this c
all. | |
111 */ | |
112 void dispose(); | |
113 } | |
OLD | NEW |