react-native-webrtc 106.0.5 → 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.
- package/.clang-format +11 -0
- package/LICENSE +2 -1
- package/android/src/main/java/com/oney/WebRTCModule/AbstractVideoCaptureController.java +0 -1
- package/android/src/main/java/com/oney/WebRTCModule/CameraCaptureController.java +7 -15
- package/android/src/main/java/com/oney/WebRTCModule/CameraEventsHandler.java +3 -12
- package/android/src/main/java/com/oney/WebRTCModule/DataChannelWrapper.java +12 -16
- package/android/src/main/java/com/oney/WebRTCModule/DisplayUtils.java +1 -1
- package/android/src/main/java/com/oney/WebRTCModule/EglUtils.java +1 -1
- package/android/src/main/java/com/oney/WebRTCModule/GetUserMediaImpl.java +29 -43
- package/android/src/main/java/com/oney/WebRTCModule/PeerConnectionObserver.java +123 -116
- package/android/src/main/java/com/oney/WebRTCModule/RTCVideoViewManager.java +60 -61
- package/android/src/main/java/com/oney/WebRTCModule/ReactBridgeUtil.java +1 -2
- package/android/src/main/java/com/oney/WebRTCModule/ScreenCaptureController.java +11 -13
- package/android/src/main/java/com/oney/WebRTCModule/SerializeUtils.java +116 -119
- package/android/src/main/java/com/oney/WebRTCModule/StringUtils.java +8 -14
- package/android/src/main/java/com/oney/WebRTCModule/ThreadUtils.java +1 -2
- package/android/src/main/java/com/oney/WebRTCModule/TrackCapturerEventsEmitter.java +3 -4
- package/android/src/main/java/com/oney/WebRTCModule/VideoTrackAdapter.java +5 -9
- package/android/src/main/java/com/oney/WebRTCModule/WebRTCModule.java +335 -350
- package/android/src/main/java/com/oney/WebRTCModule/WebRTCModulePackage.java +4 -10
- package/android/src/main/java/com/oney/WebRTCModule/WebRTCView.java +74 -98
- package/android/src/main/java/com/oney/WebRTCModule/videoEffects/ProcessorProvider.java +10 -9
- package/android/src/main/java/com/oney/WebRTCModule/videoEffects/VideoEffectProcessor.java +2 -6
- package/android/src/main/java/com/oney/WebRTCModule/videoEffects/VideoFrameProcessorFactoryInterface.java +4 -5
- package/ios/RCTWebRTC/CaptureController.h +2 -9
- package/ios/RCTWebRTC/CaptureController.m +0 -7
- package/ios/RCTWebRTC/DataChannelWrapper.h +9 -13
- package/ios/RCTWebRTC/DataChannelWrapper.m +4 -5
- package/ios/RCTWebRTC/RCTConvert+WebRTC.h +2 -2
- package/ios/RCTWebRTC/RCTConvert+WebRTC.m +166 -171
- package/ios/RCTWebRTC/RTCMediaStreamTrack+React.h +1 -1
- package/ios/RCTWebRTC/RTCMediaStreamTrack+React.m +1 -1
- package/ios/RCTWebRTC/RTCVideoViewManager.h +0 -8
- package/ios/RCTWebRTC/RTCVideoViewManager.m +205 -214
- package/ios/RCTWebRTC/ScreenCaptureController.h +2 -9
- package/ios/RCTWebRTC/ScreenCaptureController.m +10 -16
- package/ios/RCTWebRTC/ScreenCapturePickerViewManager.h +0 -7
- package/ios/RCTWebRTC/ScreenCapturePickerViewManager.m +26 -34
- package/ios/RCTWebRTC/ScreenCapturer.h +1 -8
- package/ios/RCTWebRTC/ScreenCapturer.m +56 -55
- package/ios/RCTWebRTC/SerializeUtils.h +16 -16
- package/ios/RCTWebRTC/SerializeUtils.m +98 -99
- package/ios/RCTWebRTC/SocketConnection.h +1 -8
- package/ios/RCTWebRTC/SocketConnection.m +31 -38
- package/ios/RCTWebRTC/TrackCapturerEventsEmitter.h +4 -4
- package/ios/RCTWebRTC/TrackCapturerEventsEmitter.m +5 -6
- package/ios/RCTWebRTC/VideoCaptureController.h +6 -7
- package/ios/RCTWebRTC/VideoCaptureController.m +54 -53
- package/ios/RCTWebRTC/WebRTCModule+Permissions.m +14 -13
- package/ios/RCTWebRTC/WebRTCModule+RTCDataChannel.h +3 -3
- package/ios/RCTWebRTC/WebRTCModule+RTCDataChannel.m +105 -100
- package/ios/RCTWebRTC/WebRTCModule+RTCMediaStream.h +3 -2
- package/ios/RCTWebRTC/WebRTCModule+RTCMediaStream.m +196 -226
- package/ios/RCTWebRTC/WebRTCModule+RTCPeerConnection.h +7 -14
- package/ios/RCTWebRTC/WebRTCModule+RTCPeerConnection.m +625 -603
- package/ios/RCTWebRTC/WebRTCModule+Transceivers.m +128 -139
- package/ios/RCTWebRTC/WebRTCModule+VideoTrackAdapter.h +4 -5
- package/ios/RCTWebRTC/WebRTCModule+VideoTrackAdapter.m +26 -35
- package/ios/RCTWebRTC/WebRTCModule.h +13 -20
- package/ios/RCTWebRTC/WebRTCModule.m +69 -84
- package/ios/RCTWebRTC.xcworkspace/xcuserdata/saghul.xcuserdatad/UserInterfaceState.xcuserstate +0 -0
- package/lib/commonjs/RTCPeerConnection.js +79 -56
- package/lib/commonjs/RTCPeerConnection.js.map +1 -1
- package/lib/commonjs/RTCRtpTransceiver.js +1 -1
- package/lib/commonjs/RTCRtpTransceiver.js.map +1 -1
- package/lib/module/RTCPeerConnection.js +79 -56
- package/lib/module/RTCPeerConnection.js.map +1 -1
- package/lib/module/RTCRtpTransceiver.js +1 -1
- package/lib/module/RTCRtpTransceiver.js.map +1 -1
- package/lib/typescript/RTCPeerConnection.d.ts +4 -4
- package/package.json +3 -2
- package/src/RTCPeerConnection.ts +70 -63
- package/src/RTCRtpTransceiver.ts +1 -1
- package/ios/RCTWebRTC.xcodeproj/project.xcworkspace/contents.xcworkspacedata +0 -7
- package/ios/RCTWebRTC.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +0 -8
- package/ios/RCTWebRTC.xcodeproj/project.xcworkspace/xcuserdata/saghul.xcuserdatad/UserInterfaceState.xcuserstate +0 -0
|
@@ -8,9 +8,9 @@
|
|
|
8
8
|
#else
|
|
9
9
|
#import <WebRTC/RTCMTLNSVideoView.h>
|
|
10
10
|
#endif
|
|
11
|
-
#import <WebRTC/RTCVideoTrack.h>
|
|
12
11
|
#import <WebRTC/RTCCVPixelBuffer.h>
|
|
13
12
|
#import <WebRTC/RTCVideoFrame.h>
|
|
13
|
+
#import <WebRTC/RTCVideoTrack.h>
|
|
14
14
|
|
|
15
15
|
#import "RTCVideoViewManager.h"
|
|
16
16
|
#import "WebRTCModule.h"
|
|
@@ -22,20 +22,20 @@
|
|
|
22
22
|
* the CSS style {@code object-fit}.
|
|
23
23
|
*/
|
|
24
24
|
typedef NS_ENUM(NSInteger, RTCVideoViewObjectFit) {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
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
|
|
39
39
|
};
|
|
40
40
|
|
|
41
41
|
/**
|
|
@@ -44,9 +44,9 @@ typedef NS_ENUM(NSInteger, RTCVideoViewObjectFit) {
|
|
|
44
44
|
*/
|
|
45
45
|
|
|
46
46
|
#if !TARGET_OS_OSX
|
|
47
|
-
@interface RTCVideoView : UIView
|
|
47
|
+
@interface RTCVideoView : UIView<RTCVideoViewDelegate>
|
|
48
48
|
#else
|
|
49
|
-
@interface RTCVideoView : NSView
|
|
49
|
+
@interface RTCVideoView : NSView<RTCVideoViewDelegate>
|
|
50
50
|
#endif
|
|
51
51
|
|
|
52
52
|
/**
|
|
@@ -54,7 +54,7 @@ typedef NS_ENUM(NSInteger, RTCVideoViewObjectFit) {
|
|
|
54
54
|
* the video specified by {@link #videoTrack} during its rendering. Typically,
|
|
55
55
|
* applications choose to mirror the front/user-facing camera.
|
|
56
56
|
*/
|
|
57
|
-
@property
|
|
57
|
+
@property(nonatomic) BOOL mirror;
|
|
58
58
|
|
|
59
59
|
/**
|
|
60
60
|
* In the fashion of
|
|
@@ -62,7 +62,7 @@ typedef NS_ENUM(NSInteger, RTCVideoViewObjectFit) {
|
|
|
62
62
|
* and https://www.w3.org/TR/html5/rendering.html#video-object-fit, resembles
|
|
63
63
|
* the CSS style {@code object-fit}.
|
|
64
64
|
*/
|
|
65
|
-
@property
|
|
65
|
+
@property(nonatomic) RTCVideoViewObjectFit objectFit;
|
|
66
66
|
|
|
67
67
|
/**
|
|
68
68
|
* The {@link RRTCVideoRenderer} which implements the actual rendering and which
|
|
@@ -70,28 +70,28 @@ typedef NS_ENUM(NSInteger, RTCVideoViewObjectFit) {
|
|
|
70
70
|
* {@link #_videoSize}.
|
|
71
71
|
*/
|
|
72
72
|
#if !TARGET_OS_OSX
|
|
73
|
-
@property
|
|
73
|
+
@property(nonatomic, readonly) __kindof UIView<RTCVideoRenderer> *videoView;
|
|
74
74
|
#else
|
|
75
|
-
@property
|
|
75
|
+
@property(nonatomic, readonly) __kindof NSView<RTCVideoRenderer> *videoView;
|
|
76
76
|
#endif
|
|
77
77
|
|
|
78
78
|
/**
|
|
79
79
|
* The {@link RTCVideoTrack}, if any, which this instance renders.
|
|
80
80
|
*/
|
|
81
|
-
@property
|
|
81
|
+
@property(nonatomic, strong) RTCVideoTrack *videoTrack;
|
|
82
82
|
|
|
83
83
|
/**
|
|
84
84
|
* Reference to the main WebRTC RN module.
|
|
85
85
|
*/
|
|
86
|
-
@property
|
|
86
|
+
@property(nonatomic, weak) WebRTCModule *module;
|
|
87
87
|
|
|
88
88
|
@end
|
|
89
89
|
|
|
90
90
|
@implementation RTCVideoView {
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
91
|
+
/**
|
|
92
|
+
* The width and height of the video (frames) rendered by {@link #subview}.
|
|
93
|
+
*/
|
|
94
|
+
CGSize _videoSize;
|
|
95
95
|
}
|
|
96
96
|
|
|
97
97
|
@synthesize videoView = _videoView;
|
|
@@ -100,32 +100,32 @@ typedef NS_ENUM(NSInteger, RTCVideoViewObjectFit) {
|
|
|
100
100
|
* Tells this view that its window object changed.
|
|
101
101
|
*/
|
|
102
102
|
- (void)didMoveToWindow {
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
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;
|
|
122
122
|
#if !TARGET_OS_OSX
|
|
123
|
-
|
|
123
|
+
[self setNeedsLayout];
|
|
124
124
|
#else
|
|
125
|
-
|
|
125
|
+
self.needsLayout = YES;
|
|
126
126
|
#endif
|
|
127
|
+
}
|
|
127
128
|
}
|
|
128
|
-
}
|
|
129
129
|
}
|
|
130
130
|
|
|
131
131
|
/**
|
|
@@ -135,28 +135,28 @@ typedef NS_ENUM(NSInteger, RTCVideoViewObjectFit) {
|
|
|
135
135
|
* @param frame The frame rectangle for the view, measured in points.
|
|
136
136
|
*/
|
|
137
137
|
- (instancetype)initWithFrame:(CGRect)frame {
|
|
138
|
-
|
|
138
|
+
if (self = [super initWithFrame:frame]) {
|
|
139
139
|
#if !TARGET_OS_OSX
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
140
|
+
RTCMTLVideoView *subview = [[RTCMTLVideoView alloc] initWithFrame:CGRectZero];
|
|
141
|
+
subview.delegate = self;
|
|
142
|
+
_videoView = subview;
|
|
143
143
|
#else
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
144
|
+
RTCMTLNSVideoView *subview = [[RTCMTLNSVideoView alloc] initWithFrame:CGRectZero];
|
|
145
|
+
subview.wantsLayer = true;
|
|
146
|
+
subview.delegate = self;
|
|
147
|
+
_videoView = subview;
|
|
148
148
|
#endif
|
|
149
149
|
|
|
150
|
-
|
|
151
|
-
|
|
150
|
+
_videoSize.height = 0;
|
|
151
|
+
_videoSize.width = 0;
|
|
152
152
|
|
|
153
153
|
#if !TARGET_OS_OSX
|
|
154
|
-
|
|
154
|
+
self.opaque = NO;
|
|
155
155
|
#endif
|
|
156
156
|
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
157
|
+
[self addSubview:self.videoView];
|
|
158
|
+
}
|
|
159
|
+
return self;
|
|
160
160
|
}
|
|
161
161
|
|
|
162
162
|
/**
|
|
@@ -167,65 +167,57 @@ typedef NS_ENUM(NSInteger, RTCVideoViewObjectFit) {
|
|
|
167
167
|
#if !TARGET_OS_OSX
|
|
168
168
|
- (void)layoutSubviews {
|
|
169
169
|
#else
|
|
170
|
-
|
|
170
|
+
- (void)layout {
|
|
171
171
|
#endif
|
|
172
172
|
#if !TARGET_OS_OSX
|
|
173
|
-
|
|
173
|
+
UIView *subview = self.videoView;
|
|
174
174
|
#else
|
|
175
|
-
|
|
175
|
+
NSView *subview = self.videoView;
|
|
176
176
|
#endif
|
|
177
|
-
|
|
178
|
-
|
|
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
|
|
190
|
-
= MAX(newValue.size.width / width, newValue.size.height / height);
|
|
191
|
-
// Scale both width and height in order to make it obvious that the aspect
|
|
192
|
-
// ratio is preserved.
|
|
193
|
-
width *= scaleFactor;
|
|
194
|
-
height *= scaleFactor;
|
|
195
|
-
newValue.origin.x += (newValue.size.width - width) / 2.0;
|
|
196
|
-
newValue.origin.y += (newValue.size.height - height) / 2.0;
|
|
197
|
-
newValue.size.width = width;
|
|
198
|
-
newValue.size.height = height;
|
|
177
|
+
if (!subview) {
|
|
178
|
+
return;
|
|
199
179
|
}
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
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);
|
|
212
|
+
}
|
|
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];
|
|
229
221
|
}
|
|
230
222
|
|
|
231
223
|
/**
|
|
@@ -236,15 +228,15 @@ typedef NS_ENUM(NSInteger, RTCVideoViewObjectFit) {
|
|
|
236
228
|
* {@code RTCVideoView}.
|
|
237
229
|
*/
|
|
238
230
|
- (void)setMirror:(BOOL)mirror {
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
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
|
+
}
|
|
248
240
|
}
|
|
249
241
|
|
|
250
242
|
/**
|
|
@@ -255,15 +247,15 @@ typedef NS_ENUM(NSInteger, RTCVideoViewObjectFit) {
|
|
|
255
247
|
* {@code RTCVideoView}.
|
|
256
248
|
*/
|
|
257
249
|
- (void)setObjectFit:(RTCVideoViewObjectFit)objectFit {
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
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
|
+
}
|
|
267
259
|
}
|
|
268
260
|
|
|
269
261
|
/**
|
|
@@ -274,69 +266,71 @@ typedef NS_ENUM(NSInteger, RTCVideoViewObjectFit) {
|
|
|
274
266
|
* {@code RTCVideoView}.
|
|
275
267
|
*/
|
|
276
268
|
- (void)setVideoTrack:(RTCVideoTrack *)videoTrack {
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
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
|
|
288
280
|
[self setNeedsLayout];
|
|
289
|
-
|
|
281
|
+
#else
|
|
290
282
|
self.needsLayout = YES;
|
|
291
|
-
|
|
292
|
-
|
|
283
|
+
#endif
|
|
284
|
+
}
|
|
293
285
|
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
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);
|
|
315
320
|
}
|
|
316
|
-
}
|
|
317
|
-
|
|
318
|
-
CVPixelBufferUnlockBaseAddress(pixelBuffer, 0);
|
|
319
|
-
int64_t time = (int64_t)(CFAbsoluteTimeGetCurrent() * 1000000000);
|
|
320
|
-
RTCCVPixelBuffer *buffer = [[RTCCVPixelBuffer alloc] initWithPixelBuffer:pixelBuffer];
|
|
321
|
-
RTCVideoFrame *frame = [[[RTCVideoFrame alloc] initWithBuffer:buffer rotation:RTCVideoRotation_0 timeStampNs:time] newI420VideoFrame];
|
|
322
|
-
|
|
323
|
-
[self.videoView renderFrame: frame];
|
|
324
|
-
|
|
325
|
-
CVPixelBufferRelease(pixelBuffer);
|
|
326
|
-
}
|
|
327
321
|
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
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
|
+
}
|
|
338
333
|
}
|
|
339
|
-
}
|
|
340
334
|
}
|
|
341
335
|
|
|
342
336
|
#pragma mark - RTCVideoViewDelegate methods
|
|
@@ -352,15 +346,15 @@ typedef NS_ENUM(NSInteger, RTCVideoViewObjectFit) {
|
|
|
352
346
|
* specified {@code videoView}.
|
|
353
347
|
*/
|
|
354
348
|
- (void)videoView:(id<RTCVideoRenderer>)videoView didChangeVideoSize:(CGSize)size {
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
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
|
+
}
|
|
364
358
|
}
|
|
365
359
|
|
|
366
360
|
@end
|
|
@@ -374,16 +368,16 @@ RCT_EXPORT_MODULE()
|
|
|
374
368
|
#else
|
|
375
369
|
- (NSView *)view {
|
|
376
370
|
#endif
|
|
377
|
-
|
|
378
|
-
|
|
371
|
+
RTCVideoView *v = [[RTCVideoView alloc] init];
|
|
372
|
+
v.module = [self.bridge moduleForName:@"WebRTCModule"];
|
|
379
373
|
#if !TARGET_OS_OSX
|
|
380
|
-
|
|
374
|
+
v.clipsToBounds = YES;
|
|
381
375
|
#endif
|
|
382
|
-
|
|
376
|
+
return v;
|
|
383
377
|
}
|
|
384
378
|
|
|
385
379
|
- (dispatch_queue_t)methodQueue {
|
|
386
|
-
|
|
380
|
+
return dispatch_get_main_queue();
|
|
387
381
|
}
|
|
388
382
|
|
|
389
383
|
RCT_EXPORT_VIEW_PROPERTY(mirror, BOOL)
|
|
@@ -395,13 +389,11 @@ RCT_EXPORT_VIEW_PROPERTY(mirror, BOOL)
|
|
|
395
389
|
* the CSS style {@code object-fit}.
|
|
396
390
|
*/
|
|
397
391
|
RCT_CUSTOM_VIEW_PROPERTY(objectFit, NSString *, RTCVideoView) {
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
? RTCVideoViewObjectFitCover
|
|
402
|
-
: RTCVideoViewObjectFitContain;
|
|
392
|
+
NSString *s = [RCTConvert NSString:json];
|
|
393
|
+
RTCVideoViewObjectFit e =
|
|
394
|
+
(s && [s isEqualToString:@"cover"]) ? RTCVideoViewObjectFitCover : RTCVideoViewObjectFitContain;
|
|
403
395
|
|
|
404
|
-
|
|
396
|
+
view.objectFit = e;
|
|
405
397
|
}
|
|
406
398
|
|
|
407
399
|
RCT_CUSTOM_VIEW_PROPERTY(streamURL, NSString *, RTCVideoView) {
|
|
@@ -427,8 +419,7 @@ RCT_CUSTOM_VIEW_PROPERTY(streamURL, NSString *, RTCVideoView) {
|
|
|
427
419
|
});
|
|
428
420
|
}
|
|
429
421
|
|
|
430
|
-
+ (BOOL)requiresMainQueueSetup
|
|
431
|
-
{
|
|
422
|
+
+ (BOOL)requiresMainQueueSetup {
|
|
432
423
|
return NO;
|
|
433
424
|
}
|
|
434
425
|
|
|
@@ -1,18 +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"
|
|
10
3
|
#import "CapturerEventsDelegate.h"
|
|
11
4
|
|
|
12
5
|
NS_ASSUME_NONNULL_BEGIN
|
|
13
6
|
|
|
14
|
-
extern NSString*
|
|
15
|
-
extern NSString*
|
|
7
|
+
extern NSString *const kRTCScreensharingSocketFD;
|
|
8
|
+
extern NSString *const kRTCAppGroupIdentifier;
|
|
16
9
|
|
|
17
10
|
@class ScreenCapturer;
|
|
18
11
|
|
|
@@ -1,30 +1,23 @@
|
|
|
1
|
-
//
|
|
2
|
-
// ScreenCaptureController.m
|
|
3
|
-
// RCTWebRTC
|
|
4
|
-
//
|
|
5
|
-
// Created by Alex-Dan Bumbu on 06/01/2021.
|
|
6
|
-
//
|
|
7
|
-
|
|
8
1
|
#import "ScreenCaptureController.h"
|
|
9
2
|
#import "ScreenCapturer.h"
|
|
10
3
|
#import "SocketConnection.h"
|
|
11
4
|
|
|
12
|
-
NSString*
|
|
13
|
-
NSString*
|
|
5
|
+
NSString *const kRTCScreensharingSocketFD = @"rtc_SSFD";
|
|
6
|
+
NSString *const kRTCAppGroupIdentifier = @"RTCAppGroupIdentifier";
|
|
14
7
|
|
|
15
8
|
@interface ScreenCaptureController ()
|
|
16
9
|
|
|
17
|
-
@property
|
|
10
|
+
@property(nonatomic, retain) ScreenCapturer *capturer;
|
|
18
11
|
|
|
19
12
|
@end
|
|
20
13
|
|
|
21
|
-
@interface ScreenCaptureController (CapturerEventsDelegate)
|
|
14
|
+
@interface ScreenCaptureController (CapturerEventsDelegate)<CapturerEventsDelegate>
|
|
22
15
|
- (void)capturerDidEnd:(RTCVideoCapturer *)capturer;
|
|
23
16
|
@end
|
|
24
17
|
|
|
25
18
|
@interface ScreenCaptureController (Private)
|
|
26
19
|
|
|
27
|
-
@property
|
|
20
|
+
@property(nonatomic, readonly) NSString *appGroupIdentifier;
|
|
28
21
|
|
|
29
22
|
@end
|
|
30
23
|
|
|
@@ -35,7 +28,7 @@ NSString* const kRTCAppGroupIdentifier = @"RTCAppGroupIdentifier";
|
|
|
35
28
|
if (self) {
|
|
36
29
|
self.capturer = capturer;
|
|
37
30
|
}
|
|
38
|
-
|
|
31
|
+
|
|
39
32
|
return self;
|
|
40
33
|
}
|
|
41
34
|
|
|
@@ -47,7 +40,7 @@ NSString* const kRTCAppGroupIdentifier = @"RTCAppGroupIdentifier";
|
|
|
47
40
|
if (!self.appGroupIdentifier) {
|
|
48
41
|
return;
|
|
49
42
|
}
|
|
50
|
-
|
|
43
|
+
|
|
51
44
|
self.capturer.eventsDelegate = self;
|
|
52
45
|
NSString *socketFilePath = [self filePathForApplicationGroupIdentifier:self.appGroupIdentifier];
|
|
53
46
|
SocketConnection *connection = [[SocketConnection alloc] initWithFilePath:socketFilePath];
|
|
@@ -72,9 +65,10 @@ NSString* const kRTCAppGroupIdentifier = @"RTCAppGroupIdentifier";
|
|
|
72
65
|
}
|
|
73
66
|
|
|
74
67
|
- (NSString *)filePathForApplicationGroupIdentifier:(nonnull NSString *)identifier {
|
|
75
|
-
NSURL *sharedContainer =
|
|
68
|
+
NSURL *sharedContainer =
|
|
69
|
+
[[NSFileManager defaultManager] containerURLForSecurityApplicationGroupIdentifier:identifier];
|
|
76
70
|
NSString *socketFilePath = [[sharedContainer URLByAppendingPathComponent:kRTCScreensharingSocketFD] path];
|
|
77
|
-
|
|
71
|
+
|
|
78
72
|
return socketFilePath;
|
|
79
73
|
}
|
|
80
74
|
|