1
1
/**
2
- * ©2023 NodeMedia
2
+ * ©2024 NodeMedia
3
3
* <p>
4
- * Copyright © 2015 - 2023 NodeMedia.All Rights Reserved.
4
+ * Copyright © 2015 - 2024 NodeMedia.All Rights Reserved.
5
5
*/
6
6
7
7
package cn .nodemedia ;
15
15
import android .view .ViewGroup ;
16
16
import android .view .WindowManager ;
17
17
import android .widget .FrameLayout ;
18
+
18
19
import androidx .annotation .NonNull ;
19
20
import androidx .camera .core .Camera ;
20
- import androidx .camera .core .CameraInfo ;
21
21
import androidx .camera .core .CameraSelector ;
22
+ import androidx .camera .core .FocusMeteringAction ;
23
+ import androidx .camera .core .MeteringPoint ;
22
24
import androidx .camera .core .Preview ;
25
+ import androidx .camera .core .SurfaceOrientedMeteringPointFactory ;
23
26
import androidx .camera .lifecycle .ProcessCameraProvider ;
24
27
import androidx .core .content .ContextCompat ;
25
28
import androidx .lifecycle .LifecycleOwner ;
29
+
26
30
import com .google .common .util .concurrent .ListenableFuture ;
31
+
27
32
import java .util .concurrent .ExecutionException ;
33
+ import java .util .concurrent .TimeUnit ;
34
+
28
35
import javax .microedition .khronos .egl .EGLConfig ;
29
36
import javax .microedition .khronos .opengles .GL10 ;
30
37
@@ -64,6 +71,21 @@ public class NodePublisher {
64
71
public static final int EffectorTextureTypeT2D = 0 ;
65
72
public static final int EffectorTextureTypeEOS = 1 ;
66
73
74
+ /**
75
+ * 自动对焦
76
+ */
77
+ public static final int FLAG_AF = 1 ;
78
+
79
+ /**
80
+ * 自动曝光
81
+ */
82
+ public static final int FLAG_AE = 1 << 1 ;
83
+
84
+ /**
85
+ * 自动白平衡
86
+ */
87
+ public static final int FLAG_AWB = 1 << 2 ;
88
+
67
89
68
90
private static final String TAG = "NodeMedia.java" ;
69
91
private OnNodePublisherEventListener onNodePublisherEventListener ;
@@ -158,8 +180,65 @@ public Camera getCamera() {
158
180
return mCamera ;
159
181
}
160
182
161
- public CameraInfo getCameraInfo () {
162
- return mCamera .getCameraInfo ();
183
+ public float getMinZoomRatio () {
184
+ if (mCamera != null && mCamera .getCameraInfo ().getZoomState ().getValue () != null ) {
185
+ return mCamera .getCameraInfo ().getZoomState ().getValue ().getMinZoomRatio ();
186
+ }
187
+ return 1.0f ;
188
+ }
189
+
190
+ public float getMaxZoomRatio () {
191
+ if (mCamera != null && mCamera .getCameraInfo ().getZoomState ().getValue () != null ) {
192
+ return mCamera .getCameraInfo ().getZoomState ().getValue ().getMaxZoomRatio ();
193
+ }
194
+ return 1.0f ;
195
+ }
196
+
197
+ public float getZoomRatio () {
198
+ if (mCamera != null && mCamera .getCameraInfo ().getZoomState ().getValue () != null ) {
199
+ return mCamera .getCameraInfo ().getZoomState ().getValue ().getZoomRatio ();
200
+ }
201
+ return 1.0f ;
202
+ }
203
+
204
+ public float getLinearZoom () {
205
+ if (mCamera != null && mCamera .getCameraInfo ().getZoomState ().getValue () != null ) {
206
+ return mCamera .getCameraInfo ().getZoomState ().getValue ().getLinearZoom ();
207
+ }
208
+ return 0.0f ;
209
+ }
210
+
211
+ public void setRoomRatio (float ratio ) {
212
+ if (mCamera != null ) {
213
+ mCamera .getCameraControl ().setZoomRatio (ratio );
214
+ }
215
+ }
216
+
217
+ public void setLinearZoom (float zoom ) {
218
+ if (mCamera != null ) {
219
+ mCamera .getCameraControl ().setLinearZoom (zoom );
220
+ }
221
+ }
222
+
223
+ public void enableTorch (boolean enable ) {
224
+ if (mCamera != null ) {
225
+ mCamera .getCameraControl ().enableTorch (enable );
226
+ }
227
+ }
228
+
229
+ public void startFocusAndMeteringCenter () {
230
+ startFocusAndMetering (1f , 1f , .5f , .5f , FocusMeteringAction .FLAG_AF | FocusMeteringAction .FLAG_AE | FocusMeteringAction .FLAG_AWB );
231
+ }
232
+
233
+ public void startFocusAndMetering (float w , float h , float x , float y , int mod ) {
234
+ if (mCamera == null || glpv == null ) {
235
+ return ;
236
+ }
237
+ MeteringPoint point = new SurfaceOrientedMeteringPointFactory (w , h ).createPoint (x , y );
238
+ FocusMeteringAction action = new FocusMeteringAction .Builder (point , mod )
239
+ .setAutoCancelDuration (2 , TimeUnit .SECONDS )
240
+ .build ();
241
+ mCamera .getCameraControl ().startFocusAndMetering (action );
163
242
}
164
243
165
244
private void bindImageAnalysis (@ NonNull ProcessCameraProvider cameraProvider , boolean front ) {
@@ -170,7 +249,7 @@ private void bindImageAnalysis(@NonNull ProcessCameraProvider cameraProvider, bo
170
249
.setTargetRotation (videoOrientation )
171
250
.build ();
172
251
preview .setSurfaceProvider (this .glpv .getSurfaceProvider ());
173
- mCamera = cameraProvider .bindToLifecycle ((LifecycleOwner ) this .ctx , cameraSelector , preview );
252
+ mCamera = cameraProvider .bindToLifecycle ((LifecycleOwner ) this .ctx , cameraSelector , preview );
174
253
}
175
254
176
255
private void onEvent (int event , String msg ) {
@@ -234,6 +313,7 @@ protected void finalize() {
234
313
235
314
/**
236
315
* 设置是否使用enhanced-rtmp 标准推流
316
+ *
237
317
* @param enhancedRtmp
238
318
*/
239
319
public native void setEnhancedRtmp (boolean enhancedRtmp );
@@ -243,6 +323,7 @@ protected void finalize() {
243
323
* 0.0 最小值 麦克风静音
244
324
* 1.0 默认值 原始音量
245
325
* 2.0 最大值 增益音量
326
+ *
246
327
* @param volume 0.0 ~~ 2.0
247
328
*/
248
329
public native void setVolume (float volume );
@@ -273,7 +354,7 @@ private void onViewChange() {
273
354
}
274
355
WindowManager wm = (WindowManager ) this .ctx .getSystemService (Context .WINDOW_SERVICE );
275
356
int surfaceRotation = wm .getDefaultDisplay ().getRotation ();
276
- int sensorRotationDegrees = getCameraInfo ().getSensorRotationDegrees (this .videoOrientation );
357
+ int sensorRotationDegrees = mCamera . getCameraInfo ().getSensorRotationDegrees (this .videoOrientation );
277
358
GPUImageChange (this .surfaceWidth , this .surfaceHeight , this .cameraWidth , this .cameraHeight , surfaceRotation , sensorRotationDegrees , this .isOpenFrontCamera );
278
359
}
279
360
0 commit comments