react-native-webrtc 111.0.6 → 118.0.1

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.
Files changed (217) hide show
  1. package/README.md +2 -1
  2. package/android/build.gradle +7 -1
  3. package/android/src/main/AndroidManifest.xml +8 -1
  4. package/android/src/main/java/com/oney/WebRTCModule/GetUserMediaImpl.java +10 -6
  5. package/android/src/main/java/com/oney/WebRTCModule/SerializeUtils.java +34 -5
  6. package/android/src/main/java/com/oney/WebRTCModule/UVCCamera2Enumerator.java +111 -0
  7. package/android/src/main/java/com/oney/WebRTCModule/UVCVideoCapturer.java +114 -0
  8. package/android/src/main/java/com/oney/WebRTCModule/WebRTCModule.java +85 -16
  9. package/ios/RCTWebRTC/SerializeUtils.h +3 -0
  10. package/ios/RCTWebRTC/SerializeUtils.m +42 -7
  11. package/ios/RCTWebRTC/WebRTCModule+Transceivers.m +89 -10
  12. package/lib/commonjs/EventEmitter.js.map +1 -1
  13. package/lib/commonjs/Logger.js +8 -2
  14. package/lib/commonjs/Logger.js.map +1 -1
  15. package/lib/commonjs/MediaDevices.js.map +1 -1
  16. package/lib/commonjs/MediaStream.js +4 -2
  17. package/lib/commonjs/MediaStream.js.map +1 -1
  18. package/lib/commonjs/MediaStreamError.js +4 -0
  19. package/lib/commonjs/MediaStreamError.js.map +1 -1
  20. package/lib/commonjs/MediaStreamErrorEvent.js +3 -0
  21. package/lib/commonjs/MediaStreamErrorEvent.js.map +1 -1
  22. package/lib/commonjs/MediaStreamTrack.js +11 -1
  23. package/lib/commonjs/MediaStreamTrack.js.map +1 -1
  24. package/lib/commonjs/MediaStreamTrackEvent.js +2 -0
  25. package/lib/commonjs/MediaStreamTrackEvent.js.map +1 -1
  26. package/lib/commonjs/MessageEvent.js +2 -0
  27. package/lib/commonjs/MessageEvent.js.map +1 -1
  28. package/lib/commonjs/Permissions.js +10 -9
  29. package/lib/commonjs/Permissions.js.map +1 -1
  30. package/lib/commonjs/RTCDataChannel.js +16 -2
  31. package/lib/commonjs/RTCDataChannel.js.map +1 -1
  32. package/lib/commonjs/RTCDataChannelEvent.js +2 -0
  33. package/lib/commonjs/RTCDataChannelEvent.js.map +1 -1
  34. package/lib/commonjs/RTCErrorEvent.js +3 -0
  35. package/lib/commonjs/RTCErrorEvent.js.map +1 -1
  36. package/lib/commonjs/RTCIceCandidate.js +4 -0
  37. package/lib/commonjs/RTCIceCandidate.js.map +1 -1
  38. package/lib/commonjs/RTCIceCandidateEvent.js +4 -1
  39. package/lib/commonjs/RTCIceCandidateEvent.js.map +1 -1
  40. package/lib/commonjs/RTCPeerConnection.js +45 -9
  41. package/lib/commonjs/RTCPeerConnection.js.map +1 -1
  42. package/lib/commonjs/RTCRtcpParameters.js +3 -0
  43. package/lib/commonjs/RTCRtcpParameters.js.map +1 -1
  44. package/lib/commonjs/RTCRtpCapabilities.js +4 -52
  45. package/lib/commonjs/RTCRtpCapabilities.js.map +1 -1
  46. package/lib/commonjs/RTCRtpCodecCapability.js +2 -0
  47. package/lib/commonjs/RTCRtpCodecCapability.js.map +1 -1
  48. package/lib/commonjs/RTCRtpCodecParameters.js +6 -0
  49. package/lib/commonjs/RTCRtpCodecParameters.js.map +1 -1
  50. package/lib/commonjs/RTCRtpEncodingParameters.js +11 -4
  51. package/lib/commonjs/RTCRtpEncodingParameters.js.map +1 -1
  52. package/lib/commonjs/RTCRtpHeaderExtension.js +4 -0
  53. package/lib/commonjs/RTCRtpHeaderExtension.js.map +1 -1
  54. package/lib/commonjs/RTCRtpParameters.js +4 -2
  55. package/lib/commonjs/RTCRtpParameters.js.map +1 -1
  56. package/lib/commonjs/RTCRtpReceiveParameters.js.map +1 -1
  57. package/lib/commonjs/RTCRtpReceiver.js +6 -9
  58. package/lib/commonjs/RTCRtpReceiver.js.map +1 -1
  59. package/lib/commonjs/RTCRtpSendParameters.js +4 -0
  60. package/lib/commonjs/RTCRtpSendParameters.js.map +1 -1
  61. package/lib/commonjs/RTCRtpSender.js +6 -9
  62. package/lib/commonjs/RTCRtpSender.js.map +1 -1
  63. package/lib/commonjs/RTCRtpTransceiver.js +14 -3
  64. package/lib/commonjs/RTCRtpTransceiver.js.map +1 -1
  65. package/lib/commonjs/RTCSessionDescription.js +3 -0
  66. package/lib/commonjs/RTCSessionDescription.js.map +1 -1
  67. package/lib/commonjs/RTCTrackEvent.js +5 -1
  68. package/lib/commonjs/RTCTrackEvent.js.map +1 -1
  69. package/lib/commonjs/RTCUtil.js.map +1 -1
  70. package/lib/commonjs/RTCView.js.map +1 -1
  71. package/lib/commonjs/ScreenCapturePickerView.js.map +1 -1
  72. package/lib/commonjs/getDisplayMedia.js.map +1 -1
  73. package/lib/commonjs/getUserMedia.js.map +1 -1
  74. package/lib/commonjs/index.js.map +1 -1
  75. package/lib/module/EventEmitter.js.map +1 -1
  76. package/lib/module/Logger.js +8 -2
  77. package/lib/module/Logger.js.map +1 -1
  78. package/lib/module/MediaDevices.js.map +1 -1
  79. package/lib/module/MediaStream.js +4 -2
  80. package/lib/module/MediaStream.js.map +1 -1
  81. package/lib/module/MediaStreamError.js +4 -0
  82. package/lib/module/MediaStreamError.js.map +1 -1
  83. package/lib/module/MediaStreamErrorEvent.js +3 -0
  84. package/lib/module/MediaStreamErrorEvent.js.map +1 -1
  85. package/lib/module/MediaStreamTrack.js +11 -1
  86. package/lib/module/MediaStreamTrack.js.map +1 -1
  87. package/lib/module/MediaStreamTrackEvent.js +2 -0
  88. package/lib/module/MediaStreamTrackEvent.js.map +1 -1
  89. package/lib/module/MessageEvent.js +2 -0
  90. package/lib/module/MessageEvent.js.map +1 -1
  91. package/lib/module/Permissions.js +10 -9
  92. package/lib/module/Permissions.js.map +1 -1
  93. package/lib/module/RTCDataChannel.js +16 -2
  94. package/lib/module/RTCDataChannel.js.map +1 -1
  95. package/lib/module/RTCDataChannelEvent.js +2 -0
  96. package/lib/module/RTCDataChannelEvent.js.map +1 -1
  97. package/lib/module/RTCErrorEvent.js +3 -0
  98. package/lib/module/RTCErrorEvent.js.map +1 -1
  99. package/lib/module/RTCIceCandidate.js +4 -0
  100. package/lib/module/RTCIceCandidate.js.map +1 -1
  101. package/lib/module/RTCIceCandidateEvent.js +4 -1
  102. package/lib/module/RTCIceCandidateEvent.js.map +1 -1
  103. package/lib/module/RTCPeerConnection.js +45 -9
  104. package/lib/module/RTCPeerConnection.js.map +1 -1
  105. package/lib/module/RTCRtcpParameters.js +3 -0
  106. package/lib/module/RTCRtcpParameters.js.map +1 -1
  107. package/lib/module/RTCRtpCapabilities.js +3 -47
  108. package/lib/module/RTCRtpCapabilities.js.map +1 -1
  109. package/lib/module/RTCRtpCodecCapability.js +2 -0
  110. package/lib/module/RTCRtpCodecCapability.js.map +1 -1
  111. package/lib/module/RTCRtpCodecParameters.js +6 -0
  112. package/lib/module/RTCRtpCodecParameters.js.map +1 -1
  113. package/lib/module/RTCRtpEncodingParameters.js +11 -4
  114. package/lib/module/RTCRtpEncodingParameters.js.map +1 -1
  115. package/lib/module/RTCRtpHeaderExtension.js +4 -0
  116. package/lib/module/RTCRtpHeaderExtension.js.map +1 -1
  117. package/lib/module/RTCRtpParameters.js +4 -2
  118. package/lib/module/RTCRtpParameters.js.map +1 -1
  119. package/lib/module/RTCRtpReceiveParameters.js.map +1 -1
  120. package/lib/module/RTCRtpReceiver.js +6 -9
  121. package/lib/module/RTCRtpReceiver.js.map +1 -1
  122. package/lib/module/RTCRtpSendParameters.js +4 -0
  123. package/lib/module/RTCRtpSendParameters.js.map +1 -1
  124. package/lib/module/RTCRtpSender.js +6 -9
  125. package/lib/module/RTCRtpSender.js.map +1 -1
  126. package/lib/module/RTCRtpTransceiver.js +14 -3
  127. package/lib/module/RTCRtpTransceiver.js.map +1 -1
  128. package/lib/module/RTCSessionDescription.js +3 -0
  129. package/lib/module/RTCSessionDescription.js.map +1 -1
  130. package/lib/module/RTCTrackEvent.js +5 -1
  131. package/lib/module/RTCTrackEvent.js.map +1 -1
  132. package/lib/module/RTCUtil.js.map +1 -1
  133. package/lib/module/RTCView.js.map +1 -1
  134. package/lib/module/ScreenCapturePickerView.js.map +1 -1
  135. package/lib/module/getDisplayMedia.js.map +1 -1
  136. package/lib/module/getUserMedia.js.map +1 -1
  137. package/lib/module/index.js.map +1 -1
  138. package/lib/typescript/EventEmitter.d.ts +2 -3
  139. package/lib/typescript/Logger.d.ts +0 -1
  140. package/lib/typescript/MediaDevices.d.ts +1 -2
  141. package/lib/typescript/MediaStream.d.ts +1 -2
  142. package/lib/typescript/MediaStreamError.d.ts +0 -1
  143. package/lib/typescript/MediaStreamErrorEvent.d.ts +0 -1
  144. package/lib/typescript/MediaStreamTrack.d.ts +3 -4
  145. package/lib/typescript/MediaStreamTrackEvent.d.ts +1 -2
  146. package/lib/typescript/MessageEvent.d.ts +2 -3
  147. package/lib/typescript/Permissions.d.ts +1 -2
  148. package/lib/typescript/RTCDataChannel.d.ts +2 -3
  149. package/lib/typescript/RTCDataChannelEvent.d.ts +1 -2
  150. package/lib/typescript/RTCErrorEvent.d.ts +1 -2
  151. package/lib/typescript/RTCIceCandidate.d.ts +0 -1
  152. package/lib/typescript/RTCIceCandidateEvent.d.ts +1 -2
  153. package/lib/typescript/RTCPeerConnection.d.ts +20 -8
  154. package/lib/typescript/RTCRtcpParameters.d.ts +0 -1
  155. package/lib/typescript/RTCRtpCapabilities.d.ts +1 -12
  156. package/lib/typescript/RTCRtpCodecCapability.d.ts +0 -1
  157. package/lib/typescript/RTCRtpCodecParameters.d.ts +0 -1
  158. package/lib/typescript/RTCRtpEncodingParameters.d.ts +0 -1
  159. package/lib/typescript/RTCRtpHeaderExtension.d.ts +0 -1
  160. package/lib/typescript/RTCRtpParameters.d.ts +0 -1
  161. package/lib/typescript/RTCRtpReceiveParameters.d.ts +0 -1
  162. package/lib/typescript/RTCRtpReceiver.d.ts +0 -1
  163. package/lib/typescript/RTCRtpSendParameters.d.ts +1 -2
  164. package/lib/typescript/RTCRtpSender.d.ts +0 -1
  165. package/lib/typescript/RTCRtpTransceiver.d.ts +2 -1
  166. package/lib/typescript/RTCSessionDescription.d.ts +0 -1
  167. package/lib/typescript/RTCTrackEvent.d.ts +1 -2
  168. package/lib/typescript/RTCUtil.d.ts +0 -1
  169. package/lib/typescript/RTCView.d.ts +1 -2
  170. package/lib/typescript/ScreenCapturePickerView.d.ts +0 -1
  171. package/lib/typescript/getDisplayMedia.d.ts +0 -1
  172. package/lib/typescript/getUserMedia.d.ts +0 -1
  173. package/lib/typescript/index.d.ts +0 -1
  174. package/package.json +1 -1
  175. package/react-native-webrtc.podspec +1 -1
  176. package/src/RTCPeerConnection.ts +46 -1
  177. package/src/RTCRtpCapabilities.ts +1 -50
  178. package/src/RTCRtpReceiver.ts +2 -10
  179. package/src/RTCRtpSender.ts +2 -10
  180. package/src/RTCRtpTransceiver.ts +9 -0
  181. package/src/RTCView.ts +1 -1
  182. package/lib/typescript/EventEmitter.d.ts.map +0 -1
  183. package/lib/typescript/Logger.d.ts.map +0 -1
  184. package/lib/typescript/MediaDevices.d.ts.map +0 -1
  185. package/lib/typescript/MediaStream.d.ts.map +0 -1
  186. package/lib/typescript/MediaStreamError.d.ts.map +0 -1
  187. package/lib/typescript/MediaStreamErrorEvent.d.ts.map +0 -1
  188. package/lib/typescript/MediaStreamTrack.d.ts.map +0 -1
  189. package/lib/typescript/MediaStreamTrackEvent.d.ts.map +0 -1
  190. package/lib/typescript/MessageEvent.d.ts.map +0 -1
  191. package/lib/typescript/Permissions.d.ts.map +0 -1
  192. package/lib/typescript/RTCDataChannel.d.ts.map +0 -1
  193. package/lib/typescript/RTCDataChannelEvent.d.ts.map +0 -1
  194. package/lib/typescript/RTCErrorEvent.d.ts.map +0 -1
  195. package/lib/typescript/RTCIceCandidate.d.ts.map +0 -1
  196. package/lib/typescript/RTCIceCandidateEvent.d.ts.map +0 -1
  197. package/lib/typescript/RTCPeerConnection.d.ts.map +0 -1
  198. package/lib/typescript/RTCRtcpParameters.d.ts.map +0 -1
  199. package/lib/typescript/RTCRtpCapabilities.d.ts.map +0 -1
  200. package/lib/typescript/RTCRtpCodecCapability.d.ts.map +0 -1
  201. package/lib/typescript/RTCRtpCodecParameters.d.ts.map +0 -1
  202. package/lib/typescript/RTCRtpEncodingParameters.d.ts.map +0 -1
  203. package/lib/typescript/RTCRtpHeaderExtension.d.ts.map +0 -1
  204. package/lib/typescript/RTCRtpParameters.d.ts.map +0 -1
  205. package/lib/typescript/RTCRtpReceiveParameters.d.ts.map +0 -1
  206. package/lib/typescript/RTCRtpReceiver.d.ts.map +0 -1
  207. package/lib/typescript/RTCRtpSendParameters.d.ts.map +0 -1
  208. package/lib/typescript/RTCRtpSender.d.ts.map +0 -1
  209. package/lib/typescript/RTCRtpTransceiver.d.ts.map +0 -1
  210. package/lib/typescript/RTCSessionDescription.d.ts.map +0 -1
  211. package/lib/typescript/RTCTrackEvent.d.ts.map +0 -1
  212. package/lib/typescript/RTCUtil.d.ts.map +0 -1
  213. package/lib/typescript/RTCView.d.ts.map +0 -1
  214. package/lib/typescript/ScreenCapturePickerView.d.ts.map +0 -1
  215. package/lib/typescript/getDisplayMedia.d.ts.map +0 -1
  216. package/lib/typescript/getUserMedia.d.ts.map +0 -1
  217. package/lib/typescript/index.d.ts.map +0 -1
package/README.md CHANGED
@@ -39,7 +39,7 @@ Software encode/decode factories have been enabled by default.
39
39
 
40
40
  ## WebRTC Revision
41
41
 
42
- * Currently used revision: [M111](https://github.com/jitsi/webrtc/tree/M111)
42
+ * Currently used revision: [M118](https://github.com/jitsi/webrtc/tree/M118)
43
43
  * Supported architectures
44
44
  * Android: armeabi-v7a, arm64-v8a, x86, x86_64
45
45
  * iOS: arm64, x86_64
@@ -63,6 +63,7 @@ Don't forget to follow platform guides below to cover any extra required steps.
63
63
  - [Basic Usage](./Documentation/BasicUsage.md)
64
64
  - [Step by Step Call Guide](./Documentation/CallGuide.md)
65
65
  - [Improving Call Reliability](./Documentation/ImprovingCallReliability.md)
66
+ - [Migrating to Unified Plan](https://docs.google.com/document/d/1-ZfikoUtoJa9k-GZG1daN0BU3IjIanQ_JSscHxQesvU/edit#heading=h.wuu7dx8tnifl)
66
67
 
67
68
  ## Example Projects
68
69
 
@@ -5,6 +5,11 @@ def safeExtGet(prop, fallback) {
5
5
  }
6
6
 
7
7
  android {
8
+ def agpVersion = com.android.Version.ANDROID_GRADLE_PLUGIN_VERSION
9
+ if (agpVersion.tokenize('.')[0].toInteger() >= 7) {
10
+ namespace "com.oney.WebRTCModule"
11
+ }
12
+
8
13
  compileSdkVersion safeExtGet('compileSdkVersion', 24)
9
14
  buildToolsVersion safeExtGet('buildToolsVersion', "23.0.1")
10
15
 
@@ -25,5 +30,6 @@ android {
25
30
 
26
31
  dependencies {
27
32
  implementation 'com.facebook.react:react-native:+'
28
- api 'org.jitsi:webrtc:111.+'
33
+ implementation 'com.github.jiangdongguo.AndroidUSBCamera:libausbc:3.3.3'
34
+ api 'org.jitsi:webrtc:118.+'
29
35
  }
@@ -1,3 +1,10 @@
1
1
  <manifest xmlns:android="http://schemas.android.com/apk/res/android"
2
- package="com.oney.WebRTCModule">
2
+ package="com.oney.WebRTCModule"
3
+ xmlns:tools="http://schemas.android.com/tools"
4
+ >
5
+ <uses-feature
6
+ android:name="android.hardware.usb.host"
7
+ android:required="false"
8
+ tools:node="replace"
9
+ />
3
10
  </manifest>
@@ -3,6 +3,7 @@ package com.oney.WebRTCModule;
3
3
  import android.app.Activity;
4
4
  import android.content.Context;
5
5
  import android.content.Intent;
6
+ import android.content.pm.PackageManager;
6
7
  import android.media.projection.MediaProjectionManager;
7
8
  import android.util.DisplayMetrics;
8
9
  import android.util.Log;
@@ -70,8 +71,13 @@ class GetUserMediaImpl {
70
71
  }
71
72
 
72
73
  if (camera2supported) {
73
- Log.d(TAG, "Creating video capturer using Camera2 API.");
74
- cameraEnumerator = new Camera2Enumerator(reactContext);
74
+ if (reactContext.getPackageManager().hasSystemFeature(PackageManager.FEATURE_USB_HOST)) {
75
+ Log.d(TAG, "Creating video capturer using Camera2 API with UVC support.");
76
+ cameraEnumerator = new UVCCamera2Enumerator(reactContext);
77
+ } else {
78
+ Log.d(TAG, "Creating video capturer using Camera2 API.");
79
+ cameraEnumerator = new Camera2Enumerator(reactContext);
80
+ }
75
81
  } else {
76
82
  Log.d(TAG, "Creating video capturer using Camera1 API.");
77
83
  cameraEnumerator = new Camera1Enumerator(false);
@@ -321,7 +327,7 @@ class GetUserMediaImpl {
321
327
  trackInfo.putBoolean("enabled", track.enabled());
322
328
  trackInfo.putString("id", trackId);
323
329
  trackInfo.putString("kind", track.kind());
324
- trackInfo.putString("readyState", track.state().toString().toLowerCase());
330
+ trackInfo.putString("readyState", "live");
325
331
  trackInfo.putBoolean("remote", false);
326
332
 
327
333
  if (track instanceof VideoTrack) {
@@ -488,7 +494,5 @@ class GetUserMediaImpl {
488
494
  }
489
495
  }
490
496
 
491
- public interface BiConsumer<T, U> {
492
- void accept(T t, U u);
493
- }
497
+ public interface BiConsumer<T, U> { void accept(T t, U u); }
494
498
  }
@@ -170,11 +170,7 @@ public class SerializeUtils {
170
170
  }
171
171
  // Serializing sdpFmptLine.
172
172
  if (!codec.parameters.isEmpty()) {
173
- final String sdpFmptLineParams = codec.parameters.keySet()
174
- .stream()
175
- .map(key -> key + "=" + codec.parameters.get(key))
176
- .collect(Collectors.joining(";"));
177
- codecMap.putString("sdpFmtpLine", sdpFmptLineParams);
173
+ codecMap.putString("sdpFmtpLine", serializeSdpParameters(codec.parameters));
178
174
  }
179
175
 
180
176
  codecs.pushMap(codecMap);
@@ -192,6 +188,39 @@ public class SerializeUtils {
192
188
  return result;
193
189
  }
194
190
 
191
+ public static ReadableMap serializeRtpCapabilities(RtpCapabilities capabilities) {
192
+ WritableMap result = Arguments.createMap();
193
+ WritableArray codecs = Arguments.createArray();
194
+
195
+ capabilities.codecs.forEach(codec -> codecs.pushMap(serializeRtpCapabilitiesCodec(codec)));
196
+
197
+ result.putArray("codecs", codecs);
198
+ return result;
199
+ }
200
+
201
+ public static ReadableMap serializeRtpCapabilitiesCodec(RtpCapabilities.CodecCapability codec) {
202
+ WritableMap codecMap = Arguments.createMap();
203
+ codecMap.putInt("payloadType", codec.preferredPayloadType);
204
+ codecMap.putString("mimeType", codec.mimeType);
205
+ codecMap.putInt("clockRate", codec.clockRate);
206
+ if (codec.numChannels != null) {
207
+ codecMap.putInt("channels", codec.numChannels);
208
+ }
209
+ if (!codec.parameters.isEmpty()) {
210
+ codecMap.putString("sdpFmtpLine", serializeSdpParameters(codec.parameters));
211
+ }
212
+
213
+ return codecMap;
214
+ }
215
+
216
+ // For serializing sdpFmptLine.
217
+ public static String serializeSdpParameters(Map<String, String> parameters) {
218
+ return parameters.keySet()
219
+ .stream()
220
+ .map(key -> key + "=" + parameters.get(key))
221
+ .collect(Collectors.joining(";"));
222
+ }
223
+
195
224
  /**
196
225
  * Parsing APIs
197
226
  */
@@ -0,0 +1,111 @@
1
+ package com.oney.WebRTCModule;
2
+
3
+ import android.content.Context;
4
+ import android.hardware.usb.UsbDevice;
5
+ import android.util.Log;
6
+
7
+ import androidx.annotation.Nullable;
8
+
9
+ import com.jiangdg.ausbc.camera.CameraUvcStrategy;
10
+ import com.jiangdg.ausbc.camera.bean.PreviewSize;
11
+
12
+ import org.webrtc.Camera2Enumerator;
13
+ import org.webrtc.CameraEnumerationAndroid;
14
+ import org.webrtc.CameraVideoCapturer;
15
+
16
+ import java.util.ArrayList;
17
+ import java.util.Arrays;
18
+ import java.util.List;
19
+ import java.util.stream.Collectors;
20
+
21
+ /**
22
+ * Camera2Enumerator with UVC Camera support.
23
+ * <p/>
24
+ * This implementation only adds support for UVC camera devices.
25
+ * Ie. Device's (back and/or front) cameras will use the basic implementation of {@link Camera2Enumerator}.
26
+ */
27
+ public class UVCCamera2Enumerator extends Camera2Enumerator {
28
+ /**
29
+ * UVC camera names will be prefix with this value. Currently, there is no other way to
30
+ * easily distinguish between device's own and external uvc cameras in JS-side.
31
+ */
32
+ public static final String UVC_PREFIX = "uvc-camera:";
33
+ private final Context context;
34
+
35
+ public UVCCamera2Enumerator(Context context) {
36
+ super(context);
37
+ this.context = context;
38
+ }
39
+
40
+ @Override
41
+ public String[] getDeviceNames() {
42
+ ArrayList<String> devicesNames = new ArrayList<>(Arrays.asList(super.getDeviceNames()));
43
+
44
+ try {
45
+ CameraUvcStrategy uvcStrategy = new CameraUvcStrategy(context);
46
+ List<UsbDevice> uvcCameras = uvcStrategy.getUsbDeviceList(null); // null := no filtering
47
+ if (uvcCameras != null) {
48
+ uvcCameras.forEach(camera -> devicesNames.add(UVC_PREFIX + camera.getDeviceName()));
49
+ }
50
+ uvcStrategy.unRegister();
51
+ } catch (Exception e) {
52
+ Log.e(WebRTCModule.TAG, "Error in uvc camera enumeration", e);
53
+ }
54
+
55
+ return devicesNames.toArray(new String[0]);
56
+ }
57
+
58
+ @Override
59
+ public boolean isFrontFacing(String deviceName) {
60
+ if (isUvcCamera(deviceName)) {
61
+ return true;
62
+ }
63
+
64
+ return super.isFrontFacing(deviceName);
65
+ }
66
+
67
+ public boolean isBackFacing(String deviceName) {
68
+ if (isUvcCamera(deviceName)) {
69
+ return false;
70
+ }
71
+
72
+ return super.isBackFacing(deviceName);
73
+ }
74
+
75
+ @Nullable
76
+ public List<CameraEnumerationAndroid.CaptureFormat> getSupportedFormats(String deviceName) {
77
+ if (isUvcCamera(deviceName)) {
78
+ CameraUvcStrategy cameraUvcStrategy = new CameraUvcStrategy(this.context);
79
+ List<PreviewSize> sizes =
80
+ cameraUvcStrategy.getAllPreviewSizes(null); // null := Ask all sizes for all aspect ratios.
81
+ cameraUvcStrategy.unRegister();
82
+ if (sizes == null) {
83
+ return null;
84
+ }
85
+
86
+ int minFps = 1;
87
+ int maxFps = 30;
88
+ return sizes.stream()
89
+ .map(size
90
+ -> new CameraEnumerationAndroid.CaptureFormat(
91
+ size.getWidth(), size.getHeight(), minFps, maxFps))
92
+ .collect(Collectors.toList());
93
+ }
94
+
95
+ return super.getSupportedFormats(deviceName);
96
+ }
97
+
98
+ @Override
99
+ public CameraVideoCapturer createCapturer(
100
+ String cameraName, CameraVideoCapturer.CameraEventsHandler eventsHandler) {
101
+ if (isUvcCamera(cameraName)) {
102
+ return new UVCVideoCapturer();
103
+ }
104
+
105
+ return super.createCapturer(cameraName, eventsHandler);
106
+ }
107
+
108
+ public static boolean isUvcCamera(String deviceName) {
109
+ return deviceName != null && deviceName.startsWith(UVC_PREFIX);
110
+ }
111
+ }
@@ -0,0 +1,114 @@
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
+ }
@@ -1,6 +1,7 @@
1
1
  package com.oney.WebRTCModule;
2
2
 
3
3
  import android.util.Log;
4
+ import android.util.Pair;
4
5
  import android.util.SparseArray;
5
6
 
6
7
  import androidx.annotation.NonNull;
@@ -709,6 +710,68 @@ public class WebRTCModule extends ReactContextBaseJavaModule {
709
710
  });
710
711
  }
711
712
 
713
+ @ReactMethod(isBlockingSynchronousMethod = true)
714
+ public void transceiverSetCodecPreferences(int id, String senderId, ReadableArray codecPreferences) {
715
+ ThreadUtils.runOnExecutor(() -> {
716
+ WritableMap identifier = Arguments.createMap();
717
+ WritableMap params = Arguments.createMap();
718
+ identifier.putInt("peerConnectionId", id);
719
+ identifier.putString("transceiverId", senderId);
720
+ try {
721
+ PeerConnectionObserver pco = mPeerConnectionObservers.get(id);
722
+ if (pco == null) {
723
+ Log.d(TAG, "transceiverSetDirection() peerConnectionObserver is null");
724
+ return;
725
+ }
726
+ RtpTransceiver transceiver = pco.getTransceiver(senderId);
727
+ if (transceiver == null) {
728
+ Log.d(TAG, "transceiverSetDirection() transceiver is null");
729
+ return;
730
+ }
731
+
732
+ // Convert JSON codec capabilities to the actual objects.
733
+ RtpTransceiver.RtpTransceiverDirection direction = transceiver.getDirection();
734
+ List<Pair<Map<String, Object>, RtpCapabilities.CodecCapability>> availableCodecs = new ArrayList<>();
735
+
736
+ if (direction.equals(RtpTransceiver.RtpTransceiverDirection.SEND_RECV)
737
+ || direction.equals(RtpTransceiver.RtpTransceiverDirection.SEND_ONLY)) {
738
+ RtpCapabilities capabilities = mFactory.getRtpSenderCapabilities(transceiver.getMediaType());
739
+ for (RtpCapabilities.CodecCapability codec : capabilities.codecs) {
740
+ Map<String, Object> codecDict = SerializeUtils.serializeRtpCapabilitiesCodec(codec).toHashMap();
741
+ availableCodecs.add(new Pair<>(codecDict, codec));
742
+ }
743
+ }
744
+
745
+ if (direction.equals(RtpTransceiver.RtpTransceiverDirection.SEND_RECV)
746
+ || direction.equals(RtpTransceiver.RtpTransceiverDirection.RECV_ONLY)) {
747
+ RtpCapabilities capabilities = mFactory.getRtpReceiverCapabilities(transceiver.getMediaType());
748
+ for (RtpCapabilities.CodecCapability codec : capabilities.codecs) {
749
+ Map<String, Object> codecDict = SerializeUtils.serializeRtpCapabilitiesCodec(codec).toHashMap();
750
+ availableCodecs.add(new Pair<>(codecDict, codec));
751
+ }
752
+ }
753
+
754
+ // Codec preferences is order sensitive.
755
+ List<RtpCapabilities.CodecCapability> codecsToSet = new ArrayList<>();
756
+
757
+ for (int i = 0; i < codecPreferences.size(); i++) {
758
+ Map<String, Object> codecPref = codecPreferences.getMap(i).toHashMap();
759
+ for (Pair<Map<String, Object>, RtpCapabilities.CodecCapability> pair : availableCodecs) {
760
+ Map<String, Object> availableCodecDict = pair.first;
761
+ if (codecPref.equals(availableCodecDict)) {
762
+ codecsToSet.add(pair.second);
763
+ break;
764
+ }
765
+ }
766
+ }
767
+
768
+ transceiver.setCodecPreferences(codecsToSet);
769
+ } catch (Exception e) {
770
+ Log.d(TAG, "transceiverSetCodecPreferences(): " + e.getMessage());
771
+ }
772
+ });
773
+ }
774
+
712
775
  @ReactMethod
713
776
  public void getDisplayMedia(Promise promise) {
714
777
  ThreadUtils.runOnExecutor(() -> getUserMediaImpl.getDisplayMedia(promise));
@@ -1129,18 +1192,21 @@ public class WebRTCModule extends ReactContextBaseJavaModule {
1129
1192
  }
1130
1193
 
1131
1194
  @ReactMethod(isBlockingSynchronousMethod = true)
1132
- public WritableMap receiverGetCapabilities() {
1195
+ public WritableMap receiverGetCapabilities(String kind) {
1133
1196
  try {
1134
1197
  return (WritableMap) ThreadUtils
1135
1198
  .submitToExecutor((Callable<Object>) () -> {
1136
- VideoCodecInfo[] videoCodecInfos = mVideoDecoderFactory.getSupportedCodecs();
1137
- WritableMap params = Arguments.createMap();
1138
- WritableArray codecs = Arguments.createArray();
1139
- for (VideoCodecInfo codecInfo : videoCodecInfos) {
1140
- codecs.pushMap(SerializeUtils.serializeVideoCodecInfo(codecInfo));
1199
+ MediaStreamTrack.MediaType mediaType;
1200
+ if (kind.equals("audio")) {
1201
+ mediaType = MediaStreamTrack.MediaType.MEDIA_TYPE_AUDIO;
1202
+ } else if (kind.equals("video")) {
1203
+ mediaType = MediaStreamTrack.MediaType.MEDIA_TYPE_VIDEO;
1204
+ } else {
1205
+ return Arguments.createMap();
1141
1206
  }
1142
- params.putArray("codecs", codecs);
1143
- return params;
1207
+
1208
+ RtpCapabilities capabilities = mFactory.getRtpReceiverCapabilities(mediaType);
1209
+ return SerializeUtils.serializeRtpCapabilities(capabilities);
1144
1210
  })
1145
1211
  .get();
1146
1212
  } catch (ExecutionException | InterruptedException e) {
@@ -1150,18 +1216,21 @@ public class WebRTCModule extends ReactContextBaseJavaModule {
1150
1216
  }
1151
1217
 
1152
1218
  @ReactMethod(isBlockingSynchronousMethod = true)
1153
- public WritableMap senderGetCapabilities() {
1219
+ public WritableMap senderGetCapabilities(String kind) {
1154
1220
  try {
1155
1221
  return (WritableMap) ThreadUtils
1156
1222
  .submitToExecutor((Callable<Object>) () -> {
1157
- VideoCodecInfo[] videoCodecInfos = mVideoEncoderFactory.getSupportedCodecs();
1158
- WritableMap params = Arguments.createMap();
1159
- WritableArray codecs = Arguments.createArray();
1160
- for (VideoCodecInfo codecInfo : videoCodecInfos) {
1161
- codecs.pushMap(SerializeUtils.serializeVideoCodecInfo(codecInfo));
1223
+ MediaStreamTrack.MediaType mediaType;
1224
+ if (kind.equals("audio")) {
1225
+ mediaType = MediaStreamTrack.MediaType.MEDIA_TYPE_AUDIO;
1226
+ } else if (kind.equals("video")) {
1227
+ mediaType = MediaStreamTrack.MediaType.MEDIA_TYPE_VIDEO;
1228
+ } else {
1229
+ return Arguments.createMap();
1162
1230
  }
1163
- params.putArray("codecs", codecs);
1164
- return params;
1231
+
1232
+ RtpCapabilities capabilities = mFactory.getRtpSenderCapabilities(mediaType);
1233
+ return SerializeUtils.serializeRtpCapabilities(capabilities);
1165
1234
  })
1166
1235
  .get();
1167
1236
  } catch (ExecutionException | InterruptedException e) {
@@ -1,4 +1,5 @@
1
1
  #import <WebRTC/RTCMediaStreamTrack.h>
2
+ #import <WebRTC/RTCPeerConnectionFactory.h>
2
3
  #import <WebRTC/RTCRtpReceiver.h>
3
4
  #import <WebRTC/RTCRtpTransceiver.h>
4
5
  #import <WebRTC/RTCVideoCodecInfo.h>
@@ -13,6 +14,8 @@
13
14
  receiver:(RTCRtpReceiver *_Nonnull)receiver;
14
15
  + (NSDictionary *_Nonnull)trackToJSONWithPeerConnectionId:(nonnull NSNumber *)id
15
16
  track:(RTCMediaStreamTrack *_Nonnull)track;
17
+ + (NSDictionary *_Nonnull)capabilitiesToJSON:(RTCRtpCapabilities *_Nonnull)capabilities;
18
+ + (NSDictionary *_Nonnull)codecCapabilityToJSON:(RTCRtpCodecCapability *_Nonnull)codec;
16
19
  + (NSString *_Nonnull)serializeDirection:(RTCRtpTransceiverDirection)direction;
17
20
  + (RTCRtpTransceiverDirection)parseDirection:(NSString *_Nonnull)direction;
18
21
  + (RTCRtpTransceiverInit *_Nonnull)parseTransceiverOptions:(NSDictionary *_Nonnull)parameters;
@@ -130,13 +130,7 @@
130
130
  }
131
131
 
132
132
  if (codec.parameters.count) {
133
- NSMutableArray *parts = [NSMutableArray arrayWithCapacity:codec.parameters.count];
134
- [codec.parameters
135
- enumerateKeysAndObjectsUsingBlock:^(id _Nonnull key, id _Nonnull value, BOOL *_Nonnull stop) {
136
- [parts addObject:[NSString stringWithFormat:@"%@=%@", key, value]];
137
- }];
138
-
139
- codecDictionary[@"sdpFmtpLine"] = [parts componentsJoinedByString:@";"];
133
+ codecDictionary[@"sdpFmtpLine"] = [self serializeSdpParameters:codec.parameters];
140
134
  }
141
135
 
142
136
  [codecs addObject:codecDictionary];
@@ -176,6 +170,47 @@
176
170
  };
177
171
  }
178
172
 
173
+ + (NSDictionary *)capabilitiesToJSON:(RTCRtpCapabilities *)capabilities {
174
+ NSMutableArray *codecs = [NSMutableArray new];
175
+
176
+ for (RTCRtpCodecCapability *codec in capabilities.codecs) {
177
+ [codecs addObject:[self codecCapabilityToJSON:codec]];
178
+ }
179
+
180
+ return @{@"codecs" : codecs};
181
+ }
182
+
183
+ + (NSDictionary *)codecCapabilityToJSON:(RTCRtpCodecCapability *)codec {
184
+ NSMutableDictionary *codecDictionary = [NSMutableDictionary new];
185
+
186
+ codecDictionary[@"payloadType"] = codec.preferredPayloadType;
187
+ codecDictionary[@"mimeType"] = codec.mimeType;
188
+ codecDictionary[@"clockRate"] = codec.clockRate;
189
+
190
+ if (codec.numChannels) {
191
+ codecDictionary[@"channels"] = codec.numChannels;
192
+ }
193
+
194
+ if (codec.parameters.count) {
195
+ codecDictionary[@"sdpFmtpLine"] = [self serializeSdpParameters:codec.parameters];
196
+ }
197
+
198
+ return codecDictionary;
199
+ }
200
+
201
+ + (NSString *)serializeSdpParameters:(NSDictionary *)parameters {
202
+ if (parameters == nil || parameters.count == 0) {
203
+ return nil;
204
+ }
205
+
206
+ NSMutableArray *parts = [NSMutableArray arrayWithCapacity:parameters.count];
207
+ [parameters enumerateKeysAndObjectsUsingBlock:^(id _Nonnull key, id _Nonnull value, BOOL *_Nonnull stop) {
208
+ [parts addObject:[NSString stringWithFormat:@"%@=%@", key, value]];
209
+ }];
210
+
211
+ return [parts componentsJoinedByString:@";"];
212
+ }
213
+
179
214
  + (NSString *)serializeDirection:(RTCRtpTransceiverDirection)direction {
180
215
  if (direction == RTCRtpTransceiverDirectionInactive) {
181
216
  return @"inactive";