OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2013 The WebRTC project authors. All Rights Reserved. | 2 * Copyright 2013 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
11 package org.webrtc; | 11 package org.webrtc; |
12 | 12 |
13 import android.content.Context; | 13 import android.content.Context; |
14 | 14 |
15 import java.util.List; | 15 import java.util.List; |
16 | 16 |
17 // Base interface for all VideoCapturers to implement. | 17 // Base interface for all VideoCapturers to implement. |
18 public interface VideoCapturer { | 18 public interface VideoCapturer { |
19 // Interface used for providing callbacks to an observer. | 19 // Interface used for providing callbacks to an observer. |
20 public interface CapturerObserver { | 20 public interface CapturerObserver { |
21 // Notify if the camera have been started successfully or not. | 21 // Notify if the camera have been started successfully or not. |
22 // Called on a Java thread owned by VideoCapturer. | 22 // Called on a Java thread owned by VideoCapturer. |
23 void onCapturerStarted(boolean success); | 23 void onCapturerStarted(boolean success); |
| 24 void onCapturerStopped(); |
24 | 25 |
25 // Delivers a captured frame. Called on a Java thread owned by VideoCapturer
. | 26 // 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 void onByteBufferFrameCaptured(byte[] data, int width, int height, int rotat
ion, |
27 long timeStamp); | 28 long timeStamp); |
28 | 29 |
29 // Delivers a captured frame in a texture with id |oesTextureId|. Called on
a Java thread | 30 // Delivers a captured frame in a texture with id |oesTextureId|. Called on
a Java thread |
30 // owned by VideoCapturer. | 31 // owned by VideoCapturer. |
31 void onTextureFrameCaptured( | 32 void onTextureFrameCaptured( |
32 int width, int height, int oesTextureId, float[] transformMatrix, int ro
tation, | 33 int width, int height, int oesTextureId, float[] transformMatrix, int ro
tation, |
33 long timestamp); | 34 long timestamp); |
(...skipping 12 matching lines...) Expand all Loading... |
46 public NativeObserver(long nativeCapturer) { | 47 public NativeObserver(long nativeCapturer) { |
47 this.nativeCapturer = nativeCapturer; | 48 this.nativeCapturer = nativeCapturer; |
48 } | 49 } |
49 | 50 |
50 @Override | 51 @Override |
51 public void onCapturerStarted(boolean success) { | 52 public void onCapturerStarted(boolean success) { |
52 nativeCapturerStarted(nativeCapturer, success); | 53 nativeCapturerStarted(nativeCapturer, success); |
53 } | 54 } |
54 | 55 |
55 @Override | 56 @Override |
| 57 public void onCapturerStopped() {} |
| 58 |
| 59 @Override |
56 public void onByteBufferFrameCaptured(byte[] data, int width, int height, | 60 public void onByteBufferFrameCaptured(byte[] data, int width, int height, |
57 int rotation, long timeStamp) { | 61 int rotation, long timeStamp) { |
58 nativeOnByteBufferFrameCaptured(nativeCapturer, data, data.length, width,
height, rotation, | 62 nativeOnByteBufferFrameCaptured(nativeCapturer, data, data.length, width,
height, rotation, |
59 timeStamp); | 63 timeStamp); |
60 } | 64 } |
61 | 65 |
62 @Override | 66 @Override |
63 public void onTextureFrameCaptured( | 67 public void onTextureFrameCaptured( |
64 int width, int height, int oesTextureId, float[] transformMatrix, int ro
tation, | 68 int width, int height, int oesTextureId, float[] transformMatrix, int ro
tation, |
65 long timestamp) { | 69 long timestamp) { |
66 nativeOnTextureFrameCaptured(nativeCapturer, width, height, oesTextureId,
transformMatrix, | 70 nativeOnTextureFrameCaptured(nativeCapturer, width, height, oesTextureId,
transformMatrix, |
67 rotation, timestamp); | 71 rotation, timestamp); |
68 } | 72 } |
69 | 73 |
70 @Override | 74 @Override |
71 public void onOutputFormatRequest(int width, int height, int framerate) { | 75 public void onOutputFormatRequest(int width, int height, int framerate) { |
72 nativeOnOutputFormatRequest(nativeCapturer, width, height, framerate); | 76 nativeOnOutputFormatRequest(nativeCapturer, width, height, framerate); |
73 } | 77 } |
74 | 78 |
75 private native void nativeCapturerStarted(long nativeCapturer, | 79 private native void nativeCapturerStarted(long nativeCapturer, |
76 boolean success); | 80 boolean success); |
77 private native void nativeOnByteBufferFrameCaptured(long nativeCapturer, | 81 private native void nativeOnByteBufferFrameCaptured(long nativeCapturer, |
78 byte[] data, int length, int width, int height, int rotation, long timeS
tamp); | 82 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, | 83 private native void nativeOnTextureFrameCaptured(long nativeCapturer, int wi
dth, int height, |
80 int oesTextureId, float[] transformMatrix, int rotation, long timestamp)
; | 84 int oesTextureId, float[] transformMatrix, int rotation, long timestamp)
; |
81 private native void nativeOnOutputFormatRequest(long nativeCapturer, | 85 private native void nativeOnOutputFormatRequest(long nativeCapturer, |
82 int width, int height, int framerate); | 86 int width, int height, int framerate); |
83 } | 87 } |
84 | 88 |
| 89 // An implementation of CapturerObserver that forwards all calls from |
| 90 // Java to the C layer. |
| 91 static class AndroidVideoTrackSourceObserver implements CapturerObserver { |
| 92 // Pointer to VideoTrackSourceProxy proxying AndroidVideoTrackSource. |
| 93 private final long nativeSource; |
| 94 |
| 95 public AndroidVideoTrackSourceObserver(long nativeSource) { |
| 96 this.nativeSource = nativeSource; |
| 97 } |
| 98 |
| 99 @Override |
| 100 public void onCapturerStarted(boolean success) { |
| 101 nativeCapturerStarted(nativeSource, success); |
| 102 } |
| 103 |
| 104 @Override |
| 105 public void onCapturerStopped() { |
| 106 nativeCapturerStopped(nativeSource); |
| 107 } |
| 108 |
| 109 @Override |
| 110 public void onByteBufferFrameCaptured(byte[] data, int width, int height, |
| 111 int rotation, long timeStamp) { |
| 112 nativeOnByteBufferFrameCaptured(nativeSource, data, data.length, width, he
ight, rotation, |
| 113 timeStamp); |
| 114 } |
| 115 |
| 116 @Override |
| 117 public void onTextureFrameCaptured( |
| 118 int width, int height, int oesTextureId, float[] transformMatrix, int ro
tation, |
| 119 long timestamp) { |
| 120 nativeOnTextureFrameCaptured(nativeSource, width, height, oesTextureId, tr
ansformMatrix, |
| 121 rotation, timestamp); |
| 122 } |
| 123 |
| 124 @Override |
| 125 public void onOutputFormatRequest(int width, int height, int framerate) { |
| 126 nativeOnOutputFormatRequest(nativeSource, width, height, framerate); |
| 127 } |
| 128 |
| 129 private native void nativeCapturerStarted(long nativeSource, |
| 130 boolean success); |
| 131 private native void nativeCapturerStopped(long nativeSource); |
| 132 private native void nativeOnByteBufferFrameCaptured(long nativeSource, |
| 133 byte[] data, int length, int width, int height, int rotation, long timeS
tamp); |
| 134 private native void nativeOnTextureFrameCaptured(long nativeSource, int widt
h, int height, |
| 135 int oesTextureId, float[] transformMatrix, int rotation, long timestamp)
; |
| 136 private native void nativeOnOutputFormatRequest(long nativeSource, |
| 137 int width, int height, int framerate); |
| 138 } |
| 139 |
85 /** | 140 /** |
86 * Returns a list with all the formats this VideoCapturer supports. | 141 * Returns a list with all the formats this VideoCapturer supports. |
87 */ | 142 */ |
88 List<CameraEnumerationAndroid.CaptureFormat> getSupportedFormats(); | 143 List<CameraEnumerationAndroid.CaptureFormat> getSupportedFormats(); |
89 | 144 |
90 /** | 145 /** |
91 * This function is used to initialize the camera thread, the android applicat
ion context, and the | 146 * This function is used to initialize the camera thread, the android applicat
ion context, and the |
92 * capture observer. It will be called only once and before any startCapture()
request. The | 147 * capture observer. It will be called only once and before any startCapture()
request. The |
93 * camera thread is guaranteed to be valid until dispose() is called. If the V
ideoCapturer wants | 148 * camera thread is guaranteed to be valid until dispose() is called. If the V
ideoCapturer wants |
94 * to deliver texture frames, it should do this by rendering on the SurfaceTex
ture in | 149 * to deliver texture frames, it should do this by rendering on the SurfaceTex
ture in |
(...skipping 16 matching lines...) Expand all Loading... |
111 | 166 |
112 void onOutputFormatRequest(int width, int height, int framerate); | 167 void onOutputFormatRequest(int width, int height, int framerate); |
113 | 168 |
114 void changeCaptureFormat(int width, int height, int framerate); | 169 void changeCaptureFormat(int width, int height, int framerate); |
115 | 170 |
116 /** | 171 /** |
117 * Perform any final cleanup here. No more capturing will be done after this c
all. | 172 * Perform any final cleanup here. No more capturing will be done after this c
all. |
118 */ | 173 */ |
119 void dispose(); | 174 void dispose(); |
120 } | 175 } |
OLD | NEW |