react-native-webrtc 118.0.4 → 118.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -30,6 +30,5 @@ android {
30
30
 
31
31
  dependencies {
32
32
  implementation 'com.facebook.react:react-native:+'
33
- implementation 'com.github.jiangdongguo.AndroidUSBCamera:libausbc:3.3.3'
34
33
  api 'org.jitsi:webrtc:118.+'
35
34
  }
@@ -40,7 +40,7 @@ class GetUserMediaImpl {
40
40
 
41
41
  private static final int PERMISSION_REQUEST_CODE = (int) (Math.random() * Short.MAX_VALUE);
42
42
 
43
- private final CameraEnumerator cameraEnumerator;
43
+ private CameraEnumerator cameraEnumerator;
44
44
  private final ReactApplicationContext reactContext;
45
45
 
46
46
  /**
@@ -59,29 +59,6 @@ class GetUserMediaImpl {
59
59
  this.webRTCModule = webRTCModule;
60
60
  this.reactContext = reactContext;
61
61
 
62
- boolean camera2supported = false;
63
-
64
- try {
65
- camera2supported = Camera2Enumerator.isSupported(reactContext);
66
- } catch (Throwable tr) {
67
- // Some devices will crash here with: Fatal Exception: java.lang.AssertionError: Supported FPS ranges cannot
68
- // be null. Make sure we don't.
69
- Log.w(TAG, "Error checking for Camera2 API support.", tr);
70
- }
71
-
72
- if (camera2supported) {
73
- if (UVCCamera2Enumerator.isSupported(reactContext)) {
74
- Log.d(TAG, "Creating video capturer using Camera2 API with UVC support.");
75
- cameraEnumerator = new UVCCamera2Enumerator(reactContext);
76
- } else {
77
- Log.d(TAG, "Creating video capturer using Camera2 API.");
78
- cameraEnumerator = new Camera2Enumerator(reactContext);
79
- }
80
- } else {
81
- Log.d(TAG, "Creating video capturer using Camera1 API.");
82
- cameraEnumerator = new Camera1Enumerator(false);
83
- }
84
-
85
62
  reactContext.addActivityEventListener(new BaseActivityEventListener() {
86
63
  @Override
87
64
  public void onActivityResult(Activity activity, int requestCode, int resultCode, Intent data) {
@@ -141,16 +118,30 @@ class GetUserMediaImpl {
141
118
  peerConstraints.mandatory.addAll(valid);
142
119
  }
143
120
 
121
+ private CameraEnumerator getCameraEnumerator() {
122
+ if (cameraEnumerator == null) {
123
+ if (Camera2Enumerator.isSupported(reactContext)) {
124
+ Log.d(TAG, "Creating camera enumerator using the Camera2 API");
125
+ cameraEnumerator = new Camera2Enumerator(reactContext);
126
+ } else {
127
+ Log.d(TAG, "Creating camera enumerator using the Camera1 API");
128
+ cameraEnumerator = new Camera1Enumerator(false);
129
+ }
130
+ }
131
+
132
+ return cameraEnumerator;
133
+ }
134
+
144
135
  ReadableArray enumerateDevices() {
145
136
  WritableArray array = Arguments.createArray();
146
- String[] devices = cameraEnumerator.getDeviceNames();
137
+ String[] devices = getCameraEnumerator().getDeviceNames();
147
138
 
148
139
  for (int i = 0; i < devices.length; ++i) {
149
140
  String deviceName = devices[i];
150
141
  boolean isFrontFacing;
151
142
  try {
152
143
  // This can throw an exception when using the Camera 1 API.
153
- isFrontFacing = cameraEnumerator.isFrontFacing(deviceName);
144
+ isFrontFacing = getCameraEnumerator().isFrontFacing(deviceName);
154
145
  } catch (Exception e) {
155
146
  Log.e(TAG, "Failed to check the facing mode of camera");
156
147
  continue;
@@ -201,7 +192,7 @@ class GetUserMediaImpl {
201
192
  Log.d(TAG, "getUserMedia(video): " + videoConstraintsMap);
202
193
 
203
194
  CameraCaptureController cameraCaptureController =
204
- new CameraCaptureController(cameraEnumerator, videoConstraintsMap);
195
+ new CameraCaptureController(getCameraEnumerator(), videoConstraintsMap);
205
196
 
206
197
  videoTrack = createVideoTrack(cameraCaptureController);
207
198
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-webrtc",
3
- "version": "118.0.4",
3
+ "version": "118.0.5",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/react-native-webrtc/react-native-webrtc.git"
@@ -1,122 +0,0 @@
1
- package com.oney.WebRTCModule;
2
-
3
- import android.content.Context;
4
- import android.content.pm.PackageManager;
5
- import android.hardware.usb.UsbDevice;
6
- import android.os.Build;
7
- import android.util.Log;
8
-
9
- import androidx.annotation.Nullable;
10
-
11
- import com.jiangdg.ausbc.camera.CameraUvcStrategy;
12
- import com.jiangdg.ausbc.camera.bean.PreviewSize;
13
-
14
- import org.webrtc.Camera2Enumerator;
15
- import org.webrtc.CameraEnumerationAndroid;
16
- import org.webrtc.CameraVideoCapturer;
17
-
18
- import java.util.ArrayList;
19
- import java.util.Arrays;
20
- import java.util.List;
21
- import java.util.stream.Collectors;
22
-
23
- /**
24
- * Camera2Enumerator with UVC Camera support.
25
- * <p/>
26
- * This implementation only adds support for UVC camera devices.
27
- * Ie. Device's (back and/or front) cameras will use the basic implementation of {@link Camera2Enumerator}.
28
- */
29
- public class UVCCamera2Enumerator extends Camera2Enumerator {
30
- /**
31
- * UVC camera names will be prefix with this value. Currently, there is no other way to
32
- * easily distinguish between device's own and external uvc cameras in JS-side.
33
- */
34
- public static final String UVC_PREFIX = "uvc-camera:";
35
- private final Context context;
36
-
37
- public UVCCamera2Enumerator(Context context) {
38
- super(context);
39
- this.context = context;
40
- }
41
-
42
- public static boolean isSupported(Context context) {
43
- // Disable for Android 14 because of: https://github.com/jiangdongguo/AndroidUSBCamera/pull/647
44
- if (Build.VERSION.SDK_INT < 34) {
45
- return context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_USB_HOST);
46
- }
47
-
48
- return false;
49
- }
50
-
51
- @Override
52
- public String[] getDeviceNames() {
53
- ArrayList<String> devicesNames = new ArrayList<>(Arrays.asList(super.getDeviceNames()));
54
-
55
- try {
56
- CameraUvcStrategy uvcStrategy = new CameraUvcStrategy(context);
57
- List<UsbDevice> uvcCameras = uvcStrategy.getUsbDeviceList(null); // null := no filtering
58
- if (uvcCameras != null) {
59
- uvcCameras.forEach(camera -> devicesNames.add(UVC_PREFIX + camera.getDeviceName()));
60
- }
61
- uvcStrategy.unRegister();
62
- } catch (Exception e) {
63
- Log.e(WebRTCModule.TAG, "Error in uvc camera enumeration", e);
64
- }
65
-
66
- return devicesNames.toArray(new String[0]);
67
- }
68
-
69
- @Override
70
- public boolean isFrontFacing(String deviceName) {
71
- if (isUvcCamera(deviceName)) {
72
- return true;
73
- }
74
-
75
- return super.isFrontFacing(deviceName);
76
- }
77
-
78
- public boolean isBackFacing(String deviceName) {
79
- if (isUvcCamera(deviceName)) {
80
- return false;
81
- }
82
-
83
- return super.isBackFacing(deviceName);
84
- }
85
-
86
- @Nullable
87
- public List<CameraEnumerationAndroid.CaptureFormat> getSupportedFormats(String deviceName) {
88
- if (isUvcCamera(deviceName)) {
89
- CameraUvcStrategy cameraUvcStrategy = new CameraUvcStrategy(this.context);
90
- List<PreviewSize> sizes =
91
- cameraUvcStrategy.getAllPreviewSizes(null); // null := Ask all sizes for all aspect ratios.
92
- cameraUvcStrategy.unRegister();
93
- if (sizes == null) {
94
- return null;
95
- }
96
-
97
- int minFps = 1;
98
- int maxFps = 30;
99
- return sizes.stream()
100
- .map(size
101
- -> new CameraEnumerationAndroid.CaptureFormat(
102
- size.getWidth(), size.getHeight(), minFps, maxFps))
103
- .collect(Collectors.toList());
104
- }
105
-
106
- return super.getSupportedFormats(deviceName);
107
- }
108
-
109
- @Override
110
- public CameraVideoCapturer createCapturer(
111
- String cameraName, CameraVideoCapturer.CameraEventsHandler eventsHandler) {
112
- if (isUvcCamera(cameraName)) {
113
- return new UVCVideoCapturer();
114
- }
115
-
116
- return super.createCapturer(cameraName, eventsHandler);
117
- }
118
-
119
- public static boolean isUvcCamera(String deviceName) {
120
- return deviceName != null && deviceName.startsWith(UVC_PREFIX);
121
- }
122
- }
@@ -1,114 +0,0 @@
1
- package com.oney.WebRTCModule;
2
-
3
- import android.content.Context;
4
- import android.util.Log;
5
-
6
- import androidx.annotation.NonNull;
7
- import androidx.annotation.Nullable;
8
-
9
- import com.jiangdg.ausbc.callback.IPreviewDataCallBack;
10
- import com.jiangdg.ausbc.camera.CameraUvcStrategy;
11
- import com.jiangdg.ausbc.camera.bean.CameraRequest;
12
-
13
- import org.webrtc.CameraVideoCapturer;
14
- import org.webrtc.CapturerObserver;
15
- import org.webrtc.NV21Buffer;
16
- import org.webrtc.SurfaceTextureHelper;
17
- import org.webrtc.VideoFrame;
18
-
19
- import java.util.function.Consumer;
20
-
21
- public class UVCVideoCapturer implements CameraVideoCapturer {
22
- private SurfaceTextureHelper surfaceTextureHelper;
23
- private CapturerObserver capturerObserver;
24
- private CameraUvcStrategy cameraUvcStrategy;
25
- private PreviewDataCallback previewDataCallback;
26
- private boolean isCapturerStarted;
27
-
28
- @Override
29
- public synchronized void initialize(
30
- SurfaceTextureHelper surfaceTextureHelper, Context context, CapturerObserver capturerObserver) {
31
- this.surfaceTextureHelper = surfaceTextureHelper;
32
- this.capturerObserver = capturerObserver;
33
- this.previewDataCallback = new PreviewDataCallback(this.capturerObserver::onFrameCaptured);
34
- this.cameraUvcStrategy = new CameraUvcStrategy(context);
35
- this.cameraUvcStrategy.register();
36
- }
37
-
38
- @Override
39
- public synchronized void startCapture(int width, int height, int fps) {
40
- stopCapture();
41
-
42
- Log.i(WebRTCModule.TAG, String.format("Starting uvc capture with %d x %d @ %d", width, height, fps));
43
- this.capturerObserver.onCapturerStarted(true);
44
- this.isCapturerStarted = true;
45
- this.cameraUvcStrategy.addPreviewDataCallBack(this.previewDataCallback);
46
- this.cameraUvcStrategy.startPreview(
47
- createCameraRequest(width, height), this.surfaceTextureHelper.getSurfaceTexture());
48
- }
49
-
50
- @Override
51
- public synchronized void stopCapture() {
52
- Log.d(WebRTCModule.TAG, "Stopping uvc capture");
53
- this.cameraUvcStrategy.removePreviewDataCallBack(this.previewDataCallback);
54
- this.cameraUvcStrategy.stopPreview();
55
- if (this.isCapturerStarted) {
56
- this.capturerObserver.onCapturerStopped();
57
- this.isCapturerStarted = false;
58
- }
59
- }
60
-
61
- @Override
62
- public synchronized void changeCaptureFormat(int width, int height, int fps) {
63
- Log.d(WebRTCModule.TAG, String.format("Capture format changed to %d x %d @ %d", width, height, fps));
64
- this.stopCapture();
65
- this.startCapture(width, height, fps);
66
- }
67
-
68
- @Override
69
- public synchronized void dispose() {
70
- Log.d(WebRTCModule.TAG, "Disposing uvc capturer");
71
- stopCapture();
72
- this.cameraUvcStrategy.unRegister();
73
- }
74
-
75
- @Override
76
- public boolean isScreencast() {
77
- return false;
78
- }
79
-
80
- @Override
81
- public void switchCamera(CameraSwitchHandler cameraSwitchHandler) {
82
- cameraSwitchHandler.onCameraSwitchError("Not supported yet with uvc");
83
- }
84
-
85
- @Override
86
- public void switchCamera(CameraSwitchHandler cameraSwitchHandler, String s) {
87
- cameraSwitchHandler.onCameraSwitchError("Not supported yet with uvc");
88
- }
89
-
90
- private CameraRequest createCameraRequest(int width, int height) {
91
- return new CameraRequest.Builder().setPreviewWidth(width).setPreviewHeight(height).create();
92
- }
93
-
94
- private static class PreviewDataCallback implements IPreviewDataCallBack {
95
- private final Consumer<VideoFrame> videoFrameConsumer;
96
-
97
- public PreviewDataCallback(Consumer<VideoFrame> videoFrameConsumer) {
98
- this.videoFrameConsumer = videoFrameConsumer;
99
- }
100
-
101
- @Override
102
- public void onPreviewData(@Nullable byte[] bytes, int width, int height, @NonNull DataFormat dataFormat) {
103
- if (DataFormat.NV21.equals(dataFormat)) {
104
- NV21Buffer nv21Buffer = new NV21Buffer(bytes, width, height, null);
105
- VideoFrame frame = new VideoFrame(nv21Buffer, 0, System.nanoTime());
106
- videoFrameConsumer.accept(frame);
107
- frame.release();
108
- } else {
109
- Log.e(WebRTCModule.TAG,
110
- String.format("Support for data format '%s' has not been implemented.", dataFormat));
111
- }
112
- }
113
- }
114
- }