react-native-webrtc 106.0.4 → 106.0.6

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 (92) hide show
  1. package/.clang-format +11 -0
  2. package/.github/workflows/android_ci.yml +29 -0
  3. package/.github/workflows/ci.yml +1 -1
  4. package/.github/workflows/ios_ci.yml +50 -0
  5. package/LICENSE +2 -1
  6. package/android/src/main/java/com/oney/WebRTCModule/AbstractVideoCaptureController.java +11 -1
  7. package/android/src/main/java/com/oney/WebRTCModule/CameraCaptureController.java +7 -15
  8. package/android/src/main/java/com/oney/WebRTCModule/CameraEventsHandler.java +4 -13
  9. package/android/src/main/java/com/oney/WebRTCModule/DataChannelWrapper.java +12 -16
  10. package/android/src/main/java/com/oney/WebRTCModule/DisplayUtils.java +1 -1
  11. package/android/src/main/java/com/oney/WebRTCModule/EglUtils.java +1 -1
  12. package/android/src/main/java/com/oney/WebRTCModule/GetUserMediaImpl.java +37 -47
  13. package/android/src/main/java/com/oney/WebRTCModule/PeerConnectionObserver.java +123 -116
  14. package/android/src/main/java/com/oney/WebRTCModule/RTCVideoViewManager.java +60 -61
  15. package/android/src/main/java/com/oney/WebRTCModule/ReactBridgeUtil.java +1 -2
  16. package/android/src/main/java/com/oney/WebRTCModule/ScreenCaptureController.java +12 -9
  17. package/android/src/main/java/com/oney/WebRTCModule/SerializeUtils.java +116 -121
  18. package/android/src/main/java/com/oney/WebRTCModule/StringUtils.java +8 -14
  19. package/android/src/main/java/com/oney/WebRTCModule/ThreadUtils.java +1 -2
  20. package/android/src/main/java/com/oney/WebRTCModule/TrackCapturerEventsEmitter.java +34 -0
  21. package/android/src/main/java/com/oney/WebRTCModule/VideoTrackAdapter.java +5 -9
  22. package/android/src/main/java/com/oney/WebRTCModule/WebRTCModule.java +383 -378
  23. package/android/src/main/java/com/oney/WebRTCModule/WebRTCModulePackage.java +4 -10
  24. package/android/src/main/java/com/oney/WebRTCModule/WebRTCView.java +74 -98
  25. package/android/src/main/java/com/oney/WebRTCModule/videoEffects/ProcessorProvider.java +10 -9
  26. package/android/src/main/java/com/oney/WebRTCModule/videoEffects/VideoEffectProcessor.java +2 -6
  27. package/android/src/main/java/com/oney/WebRTCModule/videoEffects/VideoFrameProcessorFactoryInterface.java +4 -5
  28. package/ios/RCTWebRTC/CaptureController.h +4 -8
  29. package/ios/RCTWebRTC/CaptureController.m +0 -7
  30. package/ios/RCTWebRTC/CapturerEventsDelegate.h +12 -0
  31. package/ios/RCTWebRTC/DataChannelWrapper.h +9 -13
  32. package/ios/RCTWebRTC/DataChannelWrapper.m +4 -5
  33. package/ios/RCTWebRTC/RCTConvert+WebRTC.h +2 -2
  34. package/ios/RCTWebRTC/RCTConvert+WebRTC.m +166 -171
  35. package/ios/RCTWebRTC/RTCMediaStreamTrack+React.h +1 -1
  36. package/ios/RCTWebRTC/RTCMediaStreamTrack+React.m +1 -1
  37. package/ios/RCTWebRTC/RTCVideoViewManager.h +0 -8
  38. package/ios/RCTWebRTC/RTCVideoViewManager.m +207 -239
  39. package/ios/RCTWebRTC/ScreenCaptureController.h +3 -9
  40. package/ios/RCTWebRTC/ScreenCaptureController.m +20 -15
  41. package/ios/RCTWebRTC/ScreenCapturePickerViewManager.h +0 -7
  42. package/ios/RCTWebRTC/ScreenCapturePickerViewManager.m +26 -34
  43. package/ios/RCTWebRTC/ScreenCapturer.h +4 -8
  44. package/ios/RCTWebRTC/ScreenCapturer.m +57 -55
  45. package/ios/RCTWebRTC/SerializeUtils.h +16 -16
  46. package/ios/RCTWebRTC/SerializeUtils.m +98 -99
  47. package/ios/RCTWebRTC/SocketConnection.h +1 -8
  48. package/ios/RCTWebRTC/SocketConnection.m +31 -38
  49. package/ios/RCTWebRTC/TrackCapturerEventsEmitter.h +14 -0
  50. package/ios/RCTWebRTC/TrackCapturerEventsEmitter.m +37 -0
  51. package/ios/RCTWebRTC/VideoCaptureController.h +6 -7
  52. package/ios/RCTWebRTC/VideoCaptureController.m +54 -53
  53. package/ios/RCTWebRTC/WebRTCModule+Permissions.m +14 -13
  54. package/ios/RCTWebRTC/WebRTCModule+RTCDataChannel.h +3 -3
  55. package/ios/RCTWebRTC/WebRTCModule+RTCDataChannel.m +105 -100
  56. package/ios/RCTWebRTC/WebRTCModule+RTCMediaStream.h +8 -0
  57. package/ios/RCTWebRTC/WebRTCModule+RTCMediaStream.m +218 -173
  58. package/ios/RCTWebRTC/WebRTCModule+RTCPeerConnection.h +7 -14
  59. package/ios/RCTWebRTC/WebRTCModule+RTCPeerConnection.m +625 -595
  60. package/ios/RCTWebRTC/WebRTCModule+Transceivers.m +128 -139
  61. package/ios/RCTWebRTC/WebRTCModule+VideoTrackAdapter.h +4 -5
  62. package/ios/RCTWebRTC/WebRTCModule+VideoTrackAdapter.m +26 -35
  63. package/ios/RCTWebRTC/WebRTCModule.h +14 -20
  64. package/ios/RCTWebRTC/WebRTCModule.m +69 -83
  65. package/ios/RCTWebRTC.xcodeproj/project.pbxproj +10 -1
  66. package/ios/RCTWebRTC.xcworkspace/xcuserdata/saghul.xcuserdatad/UserInterfaceState.xcuserstate +0 -0
  67. package/lib/commonjs/EventEmitter.js +1 -1
  68. package/lib/commonjs/EventEmitter.js.map +1 -1
  69. package/lib/commonjs/MediaStreamTrack.js +25 -0
  70. package/lib/commonjs/MediaStreamTrack.js.map +1 -1
  71. package/lib/commonjs/RTCPeerConnection.js +169 -162
  72. package/lib/commonjs/RTCPeerConnection.js.map +1 -1
  73. package/lib/commonjs/RTCRtpTransceiver.js +1 -1
  74. package/lib/commonjs/RTCRtpTransceiver.js.map +1 -1
  75. package/lib/module/EventEmitter.js +1 -1
  76. package/lib/module/EventEmitter.js.map +1 -1
  77. package/lib/module/MediaStreamTrack.js +21 -0
  78. package/lib/module/MediaStreamTrack.js.map +1 -1
  79. package/lib/module/RTCPeerConnection.js +169 -162
  80. package/lib/module/RTCPeerConnection.js.map +1 -1
  81. package/lib/module/RTCRtpTransceiver.js +1 -1
  82. package/lib/module/RTCRtpTransceiver.js.map +1 -1
  83. package/lib/typescript/MediaStreamTrack.d.ts +1 -0
  84. package/lib/typescript/RTCPeerConnection.d.ts +5 -4
  85. package/package.json +3 -2
  86. package/src/EventEmitter.ts +1 -0
  87. package/src/MediaStreamTrack.ts +23 -0
  88. package/src/RTCPeerConnection.ts +168 -174
  89. package/src/RTCRtpTransceiver.ts +1 -1
  90. package/ios/RCTWebRTC.xcodeproj/project.xcworkspace/contents.xcworkspacedata +0 -7
  91. package/ios/RCTWebRTC.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +0 -8
  92. package/ios/RCTWebRTC.xcodeproj/project.xcworkspace/xcuserdata/saghul.xcuserdatad/UserInterfaceState.xcuserstate +0 -0
@@ -1,26 +1,16 @@
1
- //
2
- // RTCVideoViewManager.m
3
- // TestReact
4
- //
5
- // Created by one on 2015/9/25.
6
- // Copyright © 2015年 Facebook. All rights reserved.
7
- //
8
1
  #import <AVFoundation/AVFoundation.h>
9
2
  #import <objc/runtime.h>
10
3
 
11
4
  #import <React/RCTLog.h>
12
- #if !TARGET_OS_OSX
13
- #import <WebRTC/RTCEAGLVideoView.h>
14
- #endif
15
5
  #import <WebRTC/RTCMediaStream.h>
16
6
  #if !TARGET_OS_OSX
17
7
  #import <WebRTC/RTCMTLVideoView.h>
18
8
  #else
19
9
  #import <WebRTC/RTCMTLNSVideoView.h>
20
10
  #endif
21
- #import <WebRTC/RTCVideoTrack.h>
22
11
  #import <WebRTC/RTCCVPixelBuffer.h>
23
12
  #import <WebRTC/RTCVideoFrame.h>
13
+ #import <WebRTC/RTCVideoTrack.h>
24
14
 
25
15
  #import "RTCVideoViewManager.h"
26
16
  #import "WebRTCModule.h"
@@ -32,20 +22,20 @@
32
22
  * the CSS style {@code object-fit}.
33
23
  */
34
24
  typedef NS_ENUM(NSInteger, RTCVideoViewObjectFit) {
35
- /**
36
- * The contain value defined by https://www.w3.org/TR/css3-images/#object-fit:
37
- *
38
- * The replaced content is sized to maintain its aspect ratio while fitting
39
- * within the element's content box.
40
- */
41
- RTCVideoViewObjectFitContain,
42
- /**
43
- * The cover value defined by https://www.w3.org/TR/css3-images/#object-fit:
44
- *
45
- * The replaced content is sized to maintain its aspect ratio while filling
46
- * the element's entire content box.
47
- */
48
- RTCVideoViewObjectFitCover
25
+ /**
26
+ * The contain value defined by https://www.w3.org/TR/css3-images/#object-fit:
27
+ *
28
+ * The replaced content is sized to maintain its aspect ratio while fitting
29
+ * within the element's content box.
30
+ */
31
+ RTCVideoViewObjectFitContain,
32
+ /**
33
+ * The cover value defined by https://www.w3.org/TR/css3-images/#object-fit:
34
+ *
35
+ * The replaced content is sized to maintain its aspect ratio while filling
36
+ * the element's entire content box.
37
+ */
38
+ RTCVideoViewObjectFitCover
49
39
  };
50
40
 
51
41
  /**
@@ -54,9 +44,9 @@ typedef NS_ENUM(NSInteger, RTCVideoViewObjectFit) {
54
44
  */
55
45
 
56
46
  #if !TARGET_OS_OSX
57
- @interface RTCVideoView : UIView <RTCVideoViewDelegate>
47
+ @interface RTCVideoView : UIView<RTCVideoViewDelegate>
58
48
  #else
59
- @interface RTCVideoView : NSView <RTCVideoViewDelegate>
49
+ @interface RTCVideoView : NSView<RTCVideoViewDelegate>
60
50
  #endif
61
51
 
62
52
  /**
@@ -64,7 +54,7 @@ typedef NS_ENUM(NSInteger, RTCVideoViewObjectFit) {
64
54
  * the video specified by {@link #videoTrack} during its rendering. Typically,
65
55
  * applications choose to mirror the front/user-facing camera.
66
56
  */
67
- @property (nonatomic) BOOL mirror;
57
+ @property(nonatomic) BOOL mirror;
68
58
 
69
59
  /**
70
60
  * In the fashion of
@@ -72,7 +62,7 @@ typedef NS_ENUM(NSInteger, RTCVideoViewObjectFit) {
72
62
  * and https://www.w3.org/TR/html5/rendering.html#video-object-fit, resembles
73
63
  * the CSS style {@code object-fit}.
74
64
  */
75
- @property (nonatomic) RTCVideoViewObjectFit objectFit;
65
+ @property(nonatomic) RTCVideoViewObjectFit objectFit;
76
66
 
77
67
  /**
78
68
  * The {@link RRTCVideoRenderer} which implements the actual rendering and which
@@ -80,28 +70,28 @@ typedef NS_ENUM(NSInteger, RTCVideoViewObjectFit) {
80
70
  * {@link #_videoSize}.
81
71
  */
82
72
  #if !TARGET_OS_OSX
83
- @property (nonatomic, readonly) __kindof UIView<RTCVideoRenderer> *videoView;
73
+ @property(nonatomic, readonly) __kindof UIView<RTCVideoRenderer> *videoView;
84
74
  #else
85
- @property (nonatomic, readonly) __kindof NSView<RTCVideoRenderer> *videoView;
75
+ @property(nonatomic, readonly) __kindof NSView<RTCVideoRenderer> *videoView;
86
76
  #endif
87
77
 
88
78
  /**
89
79
  * The {@link RTCVideoTrack}, if any, which this instance renders.
90
80
  */
91
- @property (nonatomic, strong) RTCVideoTrack *videoTrack;
81
+ @property(nonatomic, strong) RTCVideoTrack *videoTrack;
92
82
 
93
83
  /**
94
84
  * Reference to the main WebRTC RN module.
95
85
  */
96
- @property (nonatomic, weak) WebRTCModule *module;
86
+ @property(nonatomic, weak) WebRTCModule *module;
97
87
 
98
88
  @end
99
89
 
100
90
  @implementation RTCVideoView {
101
- /**
102
- * The width and height of the video (frames) rendered by {@link #subview}.
103
- */
104
- CGSize _videoSize;
91
+ /**
92
+ * The width and height of the video (frames) rendered by {@link #subview}.
93
+ */
94
+ CGSize _videoSize;
105
95
  }
106
96
 
107
97
  @synthesize videoView = _videoView;
@@ -110,32 +100,32 @@ typedef NS_ENUM(NSInteger, RTCVideoViewObjectFit) {
110
100
  * Tells this view that its window object changed.
111
101
  */
112
102
  - (void)didMoveToWindow {
113
- // XXX This RTCVideoView strongly retains its videoTrack. The latter strongly
114
- // retains the former as well though because RTCVideoTrack strongly retains
115
- // the RTCVideoRenderers added to it. In other words, there is a cycle of
116
- // strong retainments and, consequently, there is a memory leak. In order to
117
- // break the cycle, have this RTCVideoView as the RTCVideoRenderer of its
118
- // videoTrack only while this view resides in a window.
119
- RTCVideoTrack *videoTrack = self.videoTrack;
120
-
121
- if (videoTrack) {
122
- if (self.window) {
123
- dispatch_async(_module.workerQueue, ^{
124
- [videoTrack addRenderer:self.videoView];
125
- });
126
- } else {
127
- dispatch_async(_module.workerQueue, ^{
128
- [videoTrack removeRenderer:self.videoView];
129
- });
130
- _videoSize.height = 0;
131
- _videoSize.width = 0;
103
+ // XXX This RTCVideoView strongly retains its videoTrack. The latter strongly
104
+ // retains the former as well though because RTCVideoTrack strongly retains
105
+ // the RTCVideoRenderers added to it. In other words, there is a cycle of
106
+ // strong retainments and, consequently, there is a memory leak. In order to
107
+ // break the cycle, have this RTCVideoView as the RTCVideoRenderer of its
108
+ // videoTrack only while this view resides in a window.
109
+ RTCVideoTrack *videoTrack = self.videoTrack;
110
+
111
+ if (videoTrack) {
112
+ if (self.window) {
113
+ dispatch_async(_module.workerQueue, ^{
114
+ [videoTrack addRenderer:self.videoView];
115
+ });
116
+ } else {
117
+ dispatch_async(_module.workerQueue, ^{
118
+ [videoTrack removeRenderer:self.videoView];
119
+ });
120
+ _videoSize.height = 0;
121
+ _videoSize.width = 0;
132
122
  #if !TARGET_OS_OSX
133
- [self setNeedsLayout];
123
+ [self setNeedsLayout];
134
124
  #else
135
- self.needsLayout = YES;
125
+ self.needsLayout = YES;
136
126
  #endif
127
+ }
137
128
  }
138
- }
139
129
  }
140
130
 
141
131
  /**
@@ -145,41 +135,28 @@ typedef NS_ENUM(NSInteger, RTCVideoViewObjectFit) {
145
135
  * @param frame The frame rectangle for the view, measured in points.
146
136
  */
147
137
  - (instancetype)initWithFrame:(CGRect)frame {
148
- if (self = [super initWithFrame:frame]) {
149
- #if defined(RTC_SUPPORTS_METAL)
150
- #if !TARGET_OS_OSX
151
- RTCMTLVideoView *subview = [[RTCMTLVideoView alloc] initWithFrame:CGRectZero];
152
- subview.delegate = self;
153
- _videoView = subview;
154
- #else
155
- RTCMTLNSVideoView *subview = [[RTCMTLNSVideoView alloc] initWithFrame:CGRectZero];
156
- subview.wantsLayer = true;
157
- subview.delegate = self;
158
- _videoView = subview;
159
- #endif
160
- #else
138
+ if (self = [super initWithFrame:frame]) {
161
139
  #if !TARGET_OS_OSX
162
- RTCEAGLVideoView *subview = [[RTCEAGLVideoView alloc] initWithFrame:CGRectZero];
163
- subview.delegate = self;
164
- _videoView = subview;
140
+ RTCMTLVideoView *subview = [[RTCMTLVideoView alloc] initWithFrame:CGRectZero];
141
+ subview.delegate = self;
142
+ _videoView = subview;
165
143
  #else
166
- RTCMTLNSVideoView *subview = [[RTCMTLNSVideoView alloc] initWithFrame:CGRectZero];
167
- subview.wantsLayer = true;
168
- subview.delegate = self;
169
- _videoView = subview;
170
- #endif
144
+ RTCMTLNSVideoView *subview = [[RTCMTLNSVideoView alloc] initWithFrame:CGRectZero];
145
+ subview.wantsLayer = true;
146
+ subview.delegate = self;
147
+ _videoView = subview;
171
148
  #endif
172
149
 
173
- _videoSize.height = 0;
174
- _videoSize.width = 0;
150
+ _videoSize.height = 0;
151
+ _videoSize.width = 0;
175
152
 
153
+ #if !TARGET_OS_OSX
154
+ self.opaque = NO;
155
+ #endif
176
156
 
177
- #if !TARGET_OS_OSX
178
- self.opaque = NO;
179
- #endif
180
- [self addSubview:self.videoView];
181
- }
182
- return self;
157
+ [self addSubview:self.videoView];
158
+ }
159
+ return self;
183
160
  }
184
161
 
185
162
  /**
@@ -190,65 +167,57 @@ typedef NS_ENUM(NSInteger, RTCVideoViewObjectFit) {
190
167
  #if !TARGET_OS_OSX
191
168
  - (void)layoutSubviews {
192
169
  #else
193
- - (void)layout {
170
+ - (void)layout {
194
171
  #endif
195
172
  #if !TARGET_OS_OSX
196
- UIView *subview = self.videoView;
173
+ UIView *subview = self.videoView;
197
174
  #else
198
- NSView *subview = self.videoView;
175
+ NSView *subview = self.videoView;
199
176
  #endif
200
- if (!subview) {
201
- return;
202
- }
203
-
204
- CGFloat width = _videoSize.width, height = _videoSize.height;
205
- CGRect newValue;
206
- if (width <= 0 || height <= 0) {
207
- newValue = self.bounds;
208
- } else if (RTCVideoViewObjectFitCover == self.objectFit) { // cover
209
- newValue = self.bounds;
210
- // Is there a real need to scale subview?
211
- if (newValue.size.width != width || newValue.size.height != height) {
212
- CGFloat scaleFactor
213
- = MAX(newValue.size.width / width, newValue.size.height / height);
214
- // Scale both width and height in order to make it obvious that the aspect
215
- // ratio is preserved.
216
- width *= scaleFactor;
217
- height *= scaleFactor;
218
- newValue.origin.x += (newValue.size.width - width) / 2.0;
219
- newValue.origin.y += (newValue.size.height - height) / 2.0;
220
- newValue.size.width = width;
221
- newValue.size.height = height;
177
+ if (!subview) {
178
+ return;
179
+ }
180
+
181
+ CGFloat width = _videoSize.width, height = _videoSize.height;
182
+ CGRect newValue;
183
+ if (width <= 0 || height <= 0) {
184
+ newValue = self.bounds;
185
+ } else if (RTCVideoViewObjectFitCover == self.objectFit) { // cover
186
+ newValue = self.bounds;
187
+ // Is there a real need to scale subview?
188
+ if (newValue.size.width != width || newValue.size.height != height) {
189
+ CGFloat scaleFactor = MAX(newValue.size.width / width, newValue.size.height / height);
190
+ // Scale both width and height in order to make it obvious that the aspect
191
+ // ratio is preserved.
192
+ width *= scaleFactor;
193
+ height *= scaleFactor;
194
+ newValue.origin.x += (newValue.size.width - width) / 2.0;
195
+ newValue.origin.y += (newValue.size.height - height) / 2.0;
196
+ newValue.size.width = width;
197
+ newValue.size.height = height;
198
+ }
199
+ } else { // contain
200
+ // The implementation is in accord with
201
+ // https://www.w3.org/TR/html5/embedded-content-0.html#the-video-element:
202
+ //
203
+ // In the absence of style rules to the contrary, video content should be
204
+ // rendered inside the element's playback area such that the video content
205
+ // is shown centered in the playback area at the largest possible size that
206
+ // fits completely within it, with the video content's aspect ratio being
207
+ // preserved. Thus, if the aspect ratio of the playback area does not match
208
+ // the aspect ratio of the video, the video will be shown letterboxed or
209
+ // pillarboxed. Areas of the element's playback area that do not contain the
210
+ // video represent nothing.
211
+ newValue = AVMakeRectWithAspectRatioInsideRect(CGSizeMake(width, height), self.bounds);
222
212
  }
223
- } else { // contain
224
- // The implementation is in accord with
225
- // https://www.w3.org/TR/html5/embedded-content-0.html#the-video-element:
226
- //
227
- // In the absence of style rules to the contrary, video content should be
228
- // rendered inside the element's playback area such that the video content
229
- // is shown centered in the playback area at the largest possible size that
230
- // fits completely within it, with the video content's aspect ratio being
231
- // preserved. Thus, if the aspect ratio of the playback area does not match
232
- // the aspect ratio of the video, the video will be shown letterboxed or
233
- // pillarboxed. Areas of the element's playback area that do not contain the
234
- // video represent nothing.
235
- newValue
236
- = AVMakeRectWithAspectRatioInsideRect(
237
- CGSizeMake(width, height),
238
- self.bounds);
239
- }
240
-
241
- CGRect oldValue = subview.frame;
242
- if (newValue.origin.x != oldValue.origin.x
243
- || newValue.origin.y != oldValue.origin.y
244
- || newValue.size.width != oldValue.size.width
245
- || newValue.size.height != oldValue.size.height) {
246
- subview.frame = newValue;
247
- }
248
-
249
- [subview.layer setAffineTransform:self.mirror
250
- ? CGAffineTransformMakeScale(-1.0, 1.0)
251
- : CGAffineTransformIdentity];
213
+
214
+ CGRect oldValue = subview.frame;
215
+ if (newValue.origin.x != oldValue.origin.x || newValue.origin.y != oldValue.origin.y ||
216
+ newValue.size.width != oldValue.size.width || newValue.size.height != oldValue.size.height) {
217
+ subview.frame = newValue;
218
+ }
219
+
220
+ [subview.layer setAffineTransform:self.mirror ? CGAffineTransformMakeScale(-1.0, 1.0) : CGAffineTransformIdentity];
252
221
  }
253
222
 
254
223
  /**
@@ -259,15 +228,15 @@ typedef NS_ENUM(NSInteger, RTCVideoViewObjectFit) {
259
228
  * {@code RTCVideoView}.
260
229
  */
261
230
  - (void)setMirror:(BOOL)mirror {
262
- if (_mirror != mirror) {
263
- _mirror = mirror;
264
-
265
- #if !TARGET_OS_OSX
266
- [self setNeedsLayout];
267
- #else
268
- self.needsLayout = YES;
269
- #endif
270
- }
231
+ if (_mirror != mirror) {
232
+ _mirror = mirror;
233
+
234
+ #if !TARGET_OS_OSX
235
+ [self setNeedsLayout];
236
+ #else
237
+ self.needsLayout = YES;
238
+ #endif
239
+ }
271
240
  }
272
241
 
273
242
  /**
@@ -278,15 +247,15 @@ typedef NS_ENUM(NSInteger, RTCVideoViewObjectFit) {
278
247
  * {@code RTCVideoView}.
279
248
  */
280
249
  - (void)setObjectFit:(RTCVideoViewObjectFit)objectFit {
281
- if (_objectFit != objectFit) {
282
- _objectFit = objectFit;
283
-
284
- #if !TARGET_OS_OSX
285
- [self setNeedsLayout];
286
- #else
287
- self.needsLayout = YES;
288
- #endif
289
- }
250
+ if (_objectFit != objectFit) {
251
+ _objectFit = objectFit;
252
+
253
+ #if !TARGET_OS_OSX
254
+ [self setNeedsLayout];
255
+ #else
256
+ self.needsLayout = YES;
257
+ #endif
258
+ }
290
259
  }
291
260
 
292
261
  /**
@@ -297,69 +266,71 @@ typedef NS_ENUM(NSInteger, RTCVideoViewObjectFit) {
297
266
  * {@code RTCVideoView}.
298
267
  */
299
268
  - (void)setVideoTrack:(RTCVideoTrack *)videoTrack {
300
- RTCVideoTrack *oldValue = self.videoTrack;
301
-
302
- if (oldValue != videoTrack) {
303
- if (oldValue) {
304
- dispatch_async(_module.workerQueue, ^{
305
- [oldValue removeRenderer:self.videoView];
306
- });
307
- _videoSize.height = 0;
308
- _videoSize.width = 0;
309
-
310
- #if !TARGET_OS_OSX
269
+ RTCVideoTrack *oldValue = self.videoTrack;
270
+
271
+ if (oldValue != videoTrack) {
272
+ if (oldValue) {
273
+ dispatch_async(_module.workerQueue, ^{
274
+ [oldValue removeRenderer:self.videoView];
275
+ });
276
+ _videoSize.height = 0;
277
+ _videoSize.width = 0;
278
+
279
+ #if !TARGET_OS_OSX
311
280
  [self setNeedsLayout];
312
- #else
281
+ #else
313
282
  self.needsLayout = YES;
314
- #endif
315
- }
283
+ #endif
284
+ }
316
285
 
317
- _videoTrack = videoTrack;
318
-
319
- // Clear the videoView by rendering a 1x1 blank frame.
320
- CVPixelBufferRef pixelBuffer;
321
- CVReturn err = CVPixelBufferCreate(NULL, 1, 1, kCVPixelFormatType_32BGRA, NULL, &pixelBuffer);
322
- if (err == kCVReturnSuccess) {
323
- const int kBytesPerPixel = 4;
324
- CVPixelBufferLockBaseAddress(pixelBuffer, 0);
325
- int bufferWidth = (int)CVPixelBufferGetWidth(pixelBuffer);
326
- int bufferHeight = (int)CVPixelBufferGetHeight(pixelBuffer);
327
- size_t bytesPerRow = CVPixelBufferGetBytesPerRow(pixelBuffer);
328
- uint8_t *baseAddress = CVPixelBufferGetBaseAddress(pixelBuffer);
329
-
330
- for (int row = 0; row < bufferHeight; row++) {
331
- uint8_t *pixel = baseAddress + row * bytesPerRow;
332
- for (int column = 0; column < bufferWidth; column++) {
333
- pixel[0] = 0; // BGRA, Blue value
334
- pixel[1] = 0; // Green value
335
- pixel[2] = 0; // Red value
336
- pixel[3] = 0; // Alpha value
337
- pixel += kBytesPerPixel;
286
+ _videoTrack = videoTrack;
287
+
288
+ // Clear the videoView by rendering a 2x2 blank frame.
289
+ CVPixelBufferRef pixelBuffer;
290
+ CVReturn err = CVPixelBufferCreate(NULL, 2, 2, kCVPixelFormatType_32BGRA, NULL, &pixelBuffer);
291
+ if (err == kCVReturnSuccess) {
292
+ const int kBytesPerPixel = 4;
293
+ CVPixelBufferLockBaseAddress(pixelBuffer, 0);
294
+ int bufferWidth = (int)CVPixelBufferGetWidth(pixelBuffer);
295
+ int bufferHeight = (int)CVPixelBufferGetHeight(pixelBuffer);
296
+ size_t bytesPerRow = CVPixelBufferGetBytesPerRow(pixelBuffer);
297
+ uint8_t *baseAddress = CVPixelBufferGetBaseAddress(pixelBuffer);
298
+
299
+ for (int row = 0; row < bufferHeight; row++) {
300
+ uint8_t *pixel = baseAddress + row * bytesPerRow;
301
+ for (int column = 0; column < bufferWidth; column++) {
302
+ pixel[0] = 0; // BGRA, Blue value
303
+ pixel[1] = 0; // Green value
304
+ pixel[2] = 0; // Red value
305
+ pixel[3] = 0; // Alpha value
306
+ pixel += kBytesPerPixel;
307
+ }
308
+ }
309
+
310
+ CVPixelBufferUnlockBaseAddress(pixelBuffer, 0);
311
+ int64_t time = (int64_t)(CFAbsoluteTimeGetCurrent() * 1000000000);
312
+ RTCCVPixelBuffer *buffer = [[RTCCVPixelBuffer alloc] initWithPixelBuffer:pixelBuffer];
313
+ RTCVideoFrame *frame = [[[RTCVideoFrame alloc] initWithBuffer:buffer
314
+ rotation:RTCVideoRotation_0
315
+ timeStampNs:time] newI420VideoFrame];
316
+
317
+ [self.videoView renderFrame:frame];
318
+
319
+ CVPixelBufferRelease(pixelBuffer);
338
320
  }
339
- }
340
-
341
- CVPixelBufferUnlockBaseAddress(pixelBuffer, 0);
342
- int64_t time = (int64_t)(CFAbsoluteTimeGetCurrent() * 1000000000);
343
- RTCCVPixelBuffer *buffer = [[RTCCVPixelBuffer alloc] initWithPixelBuffer:pixelBuffer];
344
- RTCVideoFrame *frame = [[[RTCVideoFrame alloc] initWithBuffer:buffer rotation:RTCVideoRotation_0 timeStampNs:time] newI420VideoFrame];
345
-
346
- [self.videoView renderFrame: frame];
347
-
348
- CVPixelBufferRelease(pixelBuffer);
349
- }
350
321
 
351
- // XXX This RTCVideoView strongly retains its videoTrack. The latter
352
- // strongly retains the former as well though because RTCVideoTrack strongly
353
- // retains the RTCVideoRenderers added to it. In other words, there is a
354
- // cycle of strong retainments and, consequently, there is a memory leak. In
355
- // order to break the cycle, have this RTCVideoView as the RTCVideoRenderer
356
- // of its videoTrack only while this view resides in a window.
357
- if (videoTrack && self.window) {
358
- dispatch_async(_module.workerQueue, ^{
359
- [videoTrack addRenderer:self.videoView];
360
- });
322
+ // XXX This RTCVideoView strongly retains its videoTrack. The latter
323
+ // strongly retains the former as well though because RTCVideoTrack strongly
324
+ // retains the RTCVideoRenderers added to it. In other words, there is a
325
+ // cycle of strong retainments and, consequently, there is a memory leak. In
326
+ // order to break the cycle, have this RTCVideoView as the RTCVideoRenderer
327
+ // of its videoTrack only while this view resides in a window.
328
+ if (videoTrack && self.window) {
329
+ dispatch_async(_module.workerQueue, ^{
330
+ [videoTrack addRenderer:self.videoView];
331
+ });
332
+ }
361
333
  }
362
- }
363
334
  }
364
335
 
365
336
  #pragma mark - RTCVideoViewDelegate methods
@@ -375,15 +346,15 @@ typedef NS_ENUM(NSInteger, RTCVideoViewObjectFit) {
375
346
  * specified {@code videoView}.
376
347
  */
377
348
  - (void)videoView:(id<RTCVideoRenderer>)videoView didChangeVideoSize:(CGSize)size {
378
- if (videoView == self.videoView) {
379
- _videoSize = size;
380
-
381
- #if !TARGET_OS_OSX
382
- [self setNeedsLayout];
383
- #else
384
- self.needsLayout = YES;
385
- #endif
386
- }
349
+ if (videoView == self.videoView) {
350
+ _videoSize = size;
351
+
352
+ #if !TARGET_OS_OSX
353
+ [self setNeedsLayout];
354
+ #else
355
+ self.needsLayout = YES;
356
+ #endif
357
+ }
387
358
  }
388
359
 
389
360
  @end
@@ -397,16 +368,16 @@ RCT_EXPORT_MODULE()
397
368
  #else
398
369
  - (NSView *)view {
399
370
  #endif
400
- RTCVideoView *v = [[RTCVideoView alloc] init];
401
- v.module = [self.bridge moduleForName:@"WebRTCModule"];
371
+ RTCVideoView *v = [[RTCVideoView alloc] init];
372
+ v.module = [self.bridge moduleForName:@"WebRTCModule"];
402
373
  #if !TARGET_OS_OSX
403
- v.clipsToBounds = YES;
374
+ v.clipsToBounds = YES;
404
375
  #endif
405
- return v;
376
+ return v;
406
377
  }
407
378
 
408
379
  - (dispatch_queue_t)methodQueue {
409
- return dispatch_get_main_queue();
380
+ return dispatch_get_main_queue();
410
381
  }
411
382
 
412
383
  RCT_EXPORT_VIEW_PROPERTY(mirror, BOOL)
@@ -418,13 +389,11 @@ RCT_EXPORT_VIEW_PROPERTY(mirror, BOOL)
418
389
  * the CSS style {@code object-fit}.
419
390
  */
420
391
  RCT_CUSTOM_VIEW_PROPERTY(objectFit, NSString *, RTCVideoView) {
421
- NSString *s = [RCTConvert NSString:json];
422
- RTCVideoViewObjectFit e
423
- = (s && [s isEqualToString:@"cover"])
424
- ? RTCVideoViewObjectFitCover
425
- : RTCVideoViewObjectFitContain;
392
+ NSString *s = [RCTConvert NSString:json];
393
+ RTCVideoViewObjectFit e =
394
+ (s && [s isEqualToString:@"cover"]) ? RTCVideoViewObjectFitCover : RTCVideoViewObjectFitContain;
426
395
 
427
- view.objectFit = e;
396
+ view.objectFit = e;
428
397
  }
429
398
 
430
399
  RCT_CUSTOM_VIEW_PROPERTY(streamURL, NSString *, RTCVideoView) {
@@ -450,8 +419,7 @@ RCT_CUSTOM_VIEW_PROPERTY(streamURL, NSString *, RTCVideoView) {
450
419
  });
451
420
  }
452
421
 
453
- + (BOOL)requiresMainQueueSetup
454
- {
422
+ + (BOOL)requiresMainQueueSetup {
455
423
  return NO;
456
424
  }
457
425
 
@@ -1,17 +1,11 @@
1
- //
2
- // ScreenCaptureController.h
3
- // RCTWebRTC
4
- //
5
- // Created by Alex-Dan Bumbu on 06/01/2021.
6
- //
7
-
8
1
  #import <Foundation/Foundation.h>
9
2
  #import "CaptureController.h"
3
+ #import "CapturerEventsDelegate.h"
10
4
 
11
5
  NS_ASSUME_NONNULL_BEGIN
12
6
 
13
- extern NSString* const kRTCScreensharingSocketFD;
14
- extern NSString* const kRTCAppGroupIdentifier;
7
+ extern NSString *const kRTCScreensharingSocketFD;
8
+ extern NSString *const kRTCAppGroupIdentifier;
15
9
 
16
10
  @class ScreenCapturer;
17
11