react-native-webrtc 124.0.0 → 124.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.
|
@@ -3,10 +3,10 @@
|
|
|
3
3
|
|
|
4
4
|
#import <React/RCTLog.h>
|
|
5
5
|
#import <WebRTC/RTCMediaStream.h>
|
|
6
|
-
#if
|
|
7
|
-
#import <WebRTC/RTCMTLVideoView.h>
|
|
8
|
-
#else
|
|
6
|
+
#if TARGET_OS_OSX
|
|
9
7
|
#import <WebRTC/RTCMTLNSVideoView.h>
|
|
8
|
+
#else
|
|
9
|
+
#import <WebRTC/RTCMTLVideoView.h>
|
|
10
10
|
#endif
|
|
11
11
|
#import <WebRTC/RTCCVPixelBuffer.h>
|
|
12
12
|
#import <WebRTC/RTCVideoFrame.h>
|
|
@@ -28,7 +28,7 @@ typedef NS_ENUM(NSInteger, RTCVideoViewObjectFit) {
|
|
|
28
28
|
* The replaced content is sized to maintain its aspect ratio while fitting
|
|
29
29
|
* within the element's content box.
|
|
30
30
|
*/
|
|
31
|
-
RTCVideoViewObjectFitContain,
|
|
31
|
+
RTCVideoViewObjectFitContain = 1,
|
|
32
32
|
/**
|
|
33
33
|
* The cover value defined by https://www.w3.org/TR/css3-images/#object-fit:
|
|
34
34
|
*
|
|
@@ -43,10 +43,10 @@ typedef NS_ENUM(NSInteger, RTCVideoViewObjectFit) {
|
|
|
43
43
|
* element.
|
|
44
44
|
*/
|
|
45
45
|
|
|
46
|
-
#if
|
|
47
|
-
@interface RTCVideoView :
|
|
46
|
+
#if TARGET_OS_OSX
|
|
47
|
+
@interface RTCVideoView : NSView
|
|
48
48
|
#else
|
|
49
|
-
@interface RTCVideoView :
|
|
49
|
+
@interface RTCVideoView : UIView
|
|
50
50
|
#endif
|
|
51
51
|
|
|
52
52
|
/**
|
|
@@ -65,14 +65,12 @@ typedef NS_ENUM(NSInteger, RTCVideoViewObjectFit) {
|
|
|
65
65
|
@property(nonatomic) RTCVideoViewObjectFit objectFit;
|
|
66
66
|
|
|
67
67
|
/**
|
|
68
|
-
* The {@link RRTCVideoRenderer} which implements the actual rendering
|
|
69
|
-
* fits within this view so that the rendered video preserves the aspect ratio of
|
|
70
|
-
* {@link #_videoSize}.
|
|
68
|
+
* The {@link RRTCVideoRenderer} which implements the actual rendering.
|
|
71
69
|
*/
|
|
72
|
-
#if
|
|
73
|
-
@property(nonatomic, readonly)
|
|
70
|
+
#if TARGET_OS_OSX
|
|
71
|
+
@property(nonatomic, readonly) RTCMTLNSVideoView *videoView;
|
|
74
72
|
#else
|
|
75
|
-
@property(nonatomic, readonly)
|
|
73
|
+
@property(nonatomic, readonly) RTCMTLVideoView *videoView;
|
|
76
74
|
#endif
|
|
77
75
|
|
|
78
76
|
/**
|
|
@@ -87,12 +85,7 @@ typedef NS_ENUM(NSInteger, RTCVideoViewObjectFit) {
|
|
|
87
85
|
|
|
88
86
|
@end
|
|
89
87
|
|
|
90
|
-
@implementation RTCVideoView
|
|
91
|
-
/**
|
|
92
|
-
* The width and height of the video (frames) rendered by {@link #subview}.
|
|
93
|
-
*/
|
|
94
|
-
CGSize _videoSize;
|
|
95
|
-
}
|
|
88
|
+
@implementation RTCVideoView
|
|
96
89
|
|
|
97
90
|
@synthesize videoView = _videoView;
|
|
98
91
|
|
|
@@ -100,11 +93,11 @@ typedef NS_ENUM(NSInteger, RTCVideoViewObjectFit) {
|
|
|
100
93
|
* Tells this view that its window object changed.
|
|
101
94
|
*/
|
|
102
95
|
- (void)didMoveToWindow {
|
|
103
|
-
//
|
|
96
|
+
// This RTCVideoView strongly retains its videoTrack. The latter strongly
|
|
104
97
|
// retains the former as well though because RTCVideoTrack strongly retains
|
|
105
98
|
// the RTCVideoRenderers added to it. In other words, there is a cycle of
|
|
106
|
-
// strong retainments
|
|
107
|
-
//
|
|
99
|
+
// strong retainments. In order to break the cycle, and avoid a leak,
|
|
100
|
+
// have this RTCVideoView as the RTCVideoRenderer of its
|
|
108
101
|
// videoTrack only while this view resides in a window.
|
|
109
102
|
RTCVideoTrack *videoTrack = self.videoTrack;
|
|
110
103
|
|
|
@@ -117,13 +110,6 @@ typedef NS_ENUM(NSInteger, RTCVideoViewObjectFit) {
|
|
|
117
110
|
dispatch_async(_module.workerQueue, ^{
|
|
118
111
|
[videoTrack removeRenderer:self.videoView];
|
|
119
112
|
});
|
|
120
|
-
_videoSize.height = 0;
|
|
121
|
-
_videoSize.width = 0;
|
|
122
|
-
#if !TARGET_OS_OSX
|
|
123
|
-
[self setNeedsLayout];
|
|
124
|
-
#else
|
|
125
|
-
self.needsLayout = YES;
|
|
126
|
-
#endif
|
|
127
113
|
}
|
|
128
114
|
}
|
|
129
115
|
}
|
|
@@ -136,88 +122,30 @@ typedef NS_ENUM(NSInteger, RTCVideoViewObjectFit) {
|
|
|
136
122
|
*/
|
|
137
123
|
- (instancetype)initWithFrame:(CGRect)frame {
|
|
138
124
|
if (self = [super initWithFrame:frame]) {
|
|
139
|
-
#if
|
|
140
|
-
RTCMTLVideoView *subview = [[RTCMTLVideoView alloc] initWithFrame:CGRectZero];
|
|
141
|
-
subview.delegate = self;
|
|
142
|
-
_videoView = subview;
|
|
143
|
-
#else
|
|
125
|
+
#if TARGET_OS_OSX
|
|
144
126
|
RTCMTLNSVideoView *subview = [[RTCMTLNSVideoView alloc] initWithFrame:CGRectZero];
|
|
145
127
|
subview.wantsLayer = true;
|
|
146
|
-
|
|
128
|
+
_videoView = subview;
|
|
129
|
+
#else
|
|
130
|
+
RTCMTLVideoView *subview = [[RTCMTLVideoView alloc] initWithFrame:CGRectZero];
|
|
147
131
|
_videoView = subview;
|
|
148
132
|
#endif
|
|
149
|
-
|
|
150
|
-
_videoSize.height = 0;
|
|
151
|
-
_videoSize.width = 0;
|
|
152
|
-
|
|
153
|
-
#if !TARGET_OS_OSX
|
|
154
|
-
self.opaque = NO;
|
|
155
|
-
#endif
|
|
156
|
-
|
|
157
133
|
[self addSubview:self.videoView];
|
|
158
134
|
}
|
|
135
|
+
|
|
159
136
|
return self;
|
|
160
137
|
}
|
|
161
138
|
|
|
162
|
-
|
|
163
|
-
* Lays out the subview of this instance while preserving the aspect ratio of
|
|
164
|
-
* the video it renders.
|
|
165
|
-
*/
|
|
166
|
-
|
|
167
|
-
#if !TARGET_OS_OSX
|
|
168
|
-
- (void)layoutSubviews {
|
|
169
|
-
#else
|
|
139
|
+
#if TARGET_OS_OSX
|
|
170
140
|
- (void)layout {
|
|
171
|
-
|
|
172
|
-
#if !TARGET_OS_OSX
|
|
173
|
-
UIView *subview = self.videoView;
|
|
141
|
+
[super layout];
|
|
174
142
|
#else
|
|
175
|
-
|
|
143
|
+
- (void)layoutSubviews {
|
|
144
|
+
[super layoutSubviews];
|
|
176
145
|
#endif
|
|
177
|
-
if (!subview) {
|
|
178
|
-
return;
|
|
179
|
-
}
|
|
180
146
|
|
|
181
|
-
|
|
182
|
-
|
|
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];
|
|
147
|
+
CGRect bounds = self.bounds;
|
|
148
|
+
self.videoView.frame = bounds;
|
|
221
149
|
}
|
|
222
150
|
|
|
223
151
|
/**
|
|
@@ -231,11 +159,7 @@ typedef NS_ENUM(NSInteger, RTCVideoViewObjectFit) {
|
|
|
231
159
|
if (_mirror != mirror) {
|
|
232
160
|
_mirror = mirror;
|
|
233
161
|
|
|
234
|
-
|
|
235
|
-
[self setNeedsLayout];
|
|
236
|
-
#else
|
|
237
|
-
self.needsLayout = YES;
|
|
238
|
-
#endif
|
|
162
|
+
self.videoView.transform = mirror ? CGAffineTransformMakeScale(-1.0, 1.0) : CGAffineTransformIdentity;
|
|
239
163
|
}
|
|
240
164
|
}
|
|
241
165
|
|
|
@@ -246,14 +170,16 @@ typedef NS_ENUM(NSInteger, RTCVideoViewObjectFit) {
|
|
|
246
170
|
* @param objectFit The value to set on the {@code objectFit} property of this
|
|
247
171
|
* {@code RTCVideoView}.
|
|
248
172
|
*/
|
|
249
|
-
- (void)setObjectFit:(RTCVideoViewObjectFit)
|
|
250
|
-
if (_objectFit !=
|
|
251
|
-
_objectFit =
|
|
173
|
+
- (void)setObjectFit:(RTCVideoViewObjectFit)fit {
|
|
174
|
+
if (_objectFit != fit) {
|
|
175
|
+
_objectFit = fit;
|
|
252
176
|
|
|
253
177
|
#if !TARGET_OS_OSX
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
178
|
+
if (fit == RTCVideoViewObjectFitCover) {
|
|
179
|
+
self.videoView.videoContentMode = UIViewContentModeScaleAspectFill;
|
|
180
|
+
} else {
|
|
181
|
+
self.videoView.videoContentMode = UIViewContentModeScaleAspectFit;
|
|
182
|
+
}
|
|
257
183
|
#endif
|
|
258
184
|
}
|
|
259
185
|
}
|
|
@@ -273,14 +199,6 @@ typedef NS_ENUM(NSInteger, RTCVideoViewObjectFit) {
|
|
|
273
199
|
dispatch_async(_module.workerQueue, ^{
|
|
274
200
|
[oldValue removeRenderer:self.videoView];
|
|
275
201
|
});
|
|
276
|
-
_videoSize.height = 0;
|
|
277
|
-
_videoSize.width = 0;
|
|
278
|
-
|
|
279
|
-
#if !TARGET_OS_OSX
|
|
280
|
-
[self setNeedsLayout];
|
|
281
|
-
#else
|
|
282
|
-
self.needsLayout = YES;
|
|
283
|
-
#endif
|
|
284
202
|
}
|
|
285
203
|
|
|
286
204
|
_videoTrack = videoTrack;
|
|
@@ -319,12 +237,7 @@ typedef NS_ENUM(NSInteger, RTCVideoViewObjectFit) {
|
|
|
319
237
|
CVPixelBufferRelease(pixelBuffer);
|
|
320
238
|
}
|
|
321
239
|
|
|
322
|
-
//
|
|
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.
|
|
240
|
+
// See "didMoveToWindow" above.
|
|
328
241
|
if (videoTrack && self.window) {
|
|
329
242
|
dispatch_async(_module.workerQueue, ^{
|
|
330
243
|
[videoTrack addRenderer:self.videoView];
|
|
@@ -333,46 +246,20 @@ typedef NS_ENUM(NSInteger, RTCVideoViewObjectFit) {
|
|
|
333
246
|
}
|
|
334
247
|
}
|
|
335
248
|
|
|
336
|
-
#pragma mark - RTCVideoViewDelegate methods
|
|
337
|
-
|
|
338
|
-
/**
|
|
339
|
-
* Notifies this {@link RTCVideoViewDelegate} that a specific
|
|
340
|
-
* {@link RTCVideoRenderer} had the size of the video (frames) it renders
|
|
341
|
-
* changed.
|
|
342
|
-
*
|
|
343
|
-
* @param videoView The {@code RTCVideoRenderer} which had the size of the video
|
|
344
|
-
* (frames) it renders changed to the specified size.
|
|
345
|
-
* @param size The new size of the video (frames) to be rendered by the
|
|
346
|
-
* specified {@code videoView}.
|
|
347
|
-
*/
|
|
348
|
-
- (void)videoView:(id<RTCVideoRenderer>)videoView didChangeVideoSize:(CGSize)size {
|
|
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
|
-
}
|
|
358
|
-
}
|
|
359
|
-
|
|
360
249
|
@end
|
|
361
250
|
|
|
362
251
|
@implementation RTCVideoViewManager
|
|
363
252
|
|
|
364
253
|
RCT_EXPORT_MODULE()
|
|
365
254
|
|
|
366
|
-
#if
|
|
367
|
-
- (UIView *)view {
|
|
368
|
-
#else
|
|
255
|
+
#if TARGET_OS_OSX
|
|
369
256
|
- (NSView *)view {
|
|
257
|
+
#else
|
|
258
|
+
- (UIView *)view {
|
|
370
259
|
#endif
|
|
371
260
|
RTCVideoView *v = [[RTCVideoView alloc] init];
|
|
372
261
|
v.module = [self.bridge moduleForName:@"WebRTCModule"];
|
|
373
|
-
#if !TARGET_OS_OSX
|
|
374
262
|
v.clipsToBounds = YES;
|
|
375
|
-
#endif
|
|
376
263
|
return v;
|
|
377
264
|
}
|
|
378
265
|
|
|
@@ -380,6 +267,8 @@ RCT_EXPORT_MODULE()
|
|
|
380
267
|
return dispatch_get_main_queue();
|
|
381
268
|
}
|
|
382
269
|
|
|
270
|
+
#pragma mark - View properties
|
|
271
|
+
|
|
383
272
|
RCT_EXPORT_VIEW_PROPERTY(mirror, BOOL)
|
|
384
273
|
|
|
385
274
|
/**
|
|
@@ -389,11 +278,11 @@ RCT_EXPORT_VIEW_PROPERTY(mirror, BOOL)
|
|
|
389
278
|
* the CSS style {@code object-fit}.
|
|
390
279
|
*/
|
|
391
280
|
RCT_CUSTOM_VIEW_PROPERTY(objectFit, NSString *, RTCVideoView) {
|
|
392
|
-
NSString *
|
|
393
|
-
RTCVideoViewObjectFit
|
|
394
|
-
(
|
|
281
|
+
NSString *fitStr = json;
|
|
282
|
+
RTCVideoViewObjectFit fit =
|
|
283
|
+
(fitStr && [fitStr isEqualToString:@"cover"]) ? RTCVideoViewObjectFitCover : RTCVideoViewObjectFitContain;
|
|
395
284
|
|
|
396
|
-
view.objectFit =
|
|
285
|
+
view.objectFit = fit;
|
|
397
286
|
}
|
|
398
287
|
|
|
399
288
|
RCT_CUSTOM_VIEW_PROPERTY(streamURL, NSString *, RTCVideoView) {
|
|
@@ -402,7 +291,7 @@ RCT_CUSTOM_VIEW_PROPERTY(streamURL, NSString *, RTCVideoView) {
|
|
|
402
291
|
return;
|
|
403
292
|
}
|
|
404
293
|
|
|
405
|
-
NSString *streamReactTag =
|
|
294
|
+
NSString *streamReactTag = json;
|
|
406
295
|
WebRTCModule *module = view.module;
|
|
407
296
|
|
|
408
297
|
dispatch_async(module.workerQueue, ^{
|
|
@@ -263,7 +263,7 @@ RCT_EXPORT_METHOD(enumerateDevices : (RCTResponseSenderBlock)callback) {
|
|
|
263
263
|
#else
|
|
264
264
|
NSMutableArray *devices = [NSMutableArray array];
|
|
265
265
|
AVCaptureDeviceDiscoverySession *videoevicesSession =
|
|
266
|
-
[AVCaptureDeviceDiscoverySession discoverySessionWithDeviceTypes:@[ AVCaptureDeviceTypeBuiltInWideAngleCamera ]
|
|
266
|
+
[AVCaptureDeviceDiscoverySession discoverySessionWithDeviceTypes:@[ AVCaptureDeviceTypeBuiltInWideAngleCamera, AVCaptureDeviceTypeBuiltInUltraWideCamera, AVCaptureDeviceTypeBuiltInTelephotoCamera, AVCaptureDeviceTypeBuiltInDualCamera, AVCaptureDeviceTypeBuiltInDualWideCamera, AVCaptureDeviceTypeBuiltInTripleCamera]
|
|
267
267
|
mediaType:AVMediaTypeVideo
|
|
268
268
|
position:AVCaptureDevicePositionUnspecified];
|
|
269
269
|
for (AVCaptureDevice *device in videoevicesSession.devices) {
|