react-native-webrtc 124.0.0 → 124.0.2
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/android/build.gradle
CHANGED
|
@@ -102,6 +102,9 @@ public class WebRTCModule extends ReactContextBaseJavaModule {
|
|
|
102
102
|
.setVideoDecoderFactory(decoderFactory)
|
|
103
103
|
.createPeerConnectionFactory();
|
|
104
104
|
|
|
105
|
+
// PeerConnectionFactory now owns the adm native pointer, and we don't need it anymore.
|
|
106
|
+
adm.release();
|
|
107
|
+
|
|
105
108
|
// Saving the encoder and decoder factories to get codec info later when needed.
|
|
106
109
|
mVideoEncoderFactory = encoderFactory;
|
|
107
110
|
mVideoDecoderFactory = decoderFactory;
|
|
@@ -116,14 +119,6 @@ public class WebRTCModule extends ReactContextBaseJavaModule {
|
|
|
116
119
|
return "WebRTCModule";
|
|
117
120
|
}
|
|
118
121
|
|
|
119
|
-
@Override
|
|
120
|
-
public void onCatalystInstanceDestroy() {
|
|
121
|
-
if (mAudioDeviceModule != null) {
|
|
122
|
-
mAudioDeviceModule.release();
|
|
123
|
-
}
|
|
124
|
-
super.onCatalystInstanceDestroy();
|
|
125
|
-
}
|
|
126
|
-
|
|
127
122
|
private PeerConnection getPeerConnection(int id) {
|
|
128
123
|
PeerConnectionObserver pco = mPeerConnectionObservers.get(id);
|
|
129
124
|
return (pco == null) ? null : pco.getPeerConnection();
|
|
@@ -2,11 +2,13 @@
|
|
|
2
2
|
#import <objc/runtime.h>
|
|
3
3
|
|
|
4
4
|
#import <React/RCTLog.h>
|
|
5
|
+
#import <React/RCTView.h>
|
|
6
|
+
|
|
5
7
|
#import <WebRTC/RTCMediaStream.h>
|
|
6
|
-
#if
|
|
7
|
-
#import <WebRTC/RTCMTLVideoView.h>
|
|
8
|
-
#else
|
|
8
|
+
#if TARGET_OS_OSX
|
|
9
9
|
#import <WebRTC/RTCMTLNSVideoView.h>
|
|
10
|
+
#else
|
|
11
|
+
#import <WebRTC/RTCMTLVideoView.h>
|
|
10
12
|
#endif
|
|
11
13
|
#import <WebRTC/RTCCVPixelBuffer.h>
|
|
12
14
|
#import <WebRTC/RTCVideoFrame.h>
|
|
@@ -28,7 +30,7 @@ typedef NS_ENUM(NSInteger, RTCVideoViewObjectFit) {
|
|
|
28
30
|
* The replaced content is sized to maintain its aspect ratio while fitting
|
|
29
31
|
* within the element's content box.
|
|
30
32
|
*/
|
|
31
|
-
RTCVideoViewObjectFitContain,
|
|
33
|
+
RTCVideoViewObjectFitContain = 1,
|
|
32
34
|
/**
|
|
33
35
|
* The cover value defined by https://www.w3.org/TR/css3-images/#object-fit:
|
|
34
36
|
*
|
|
@@ -42,12 +44,7 @@ typedef NS_ENUM(NSInteger, RTCVideoViewObjectFit) {
|
|
|
42
44
|
* Implements an equivalent of {@code HTMLVideoElement} i.e. Web's video
|
|
43
45
|
* element.
|
|
44
46
|
*/
|
|
45
|
-
|
|
46
|
-
#if !TARGET_OS_OSX
|
|
47
|
-
@interface RTCVideoView : UIView<RTCVideoViewDelegate>
|
|
48
|
-
#else
|
|
49
|
-
@interface RTCVideoView : NSView<RTCVideoViewDelegate>
|
|
50
|
-
#endif
|
|
47
|
+
@interface RTCVideoView : RCTView
|
|
51
48
|
|
|
52
49
|
/**
|
|
53
50
|
* The indicator which determines whether this {@code RTCVideoView} is to mirror
|
|
@@ -65,14 +62,12 @@ typedef NS_ENUM(NSInteger, RTCVideoViewObjectFit) {
|
|
|
65
62
|
@property(nonatomic) RTCVideoViewObjectFit objectFit;
|
|
66
63
|
|
|
67
64
|
/**
|
|
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}.
|
|
65
|
+
* The {@link RRTCVideoRenderer} which implements the actual rendering.
|
|
71
66
|
*/
|
|
72
|
-
#if
|
|
73
|
-
@property(nonatomic, readonly)
|
|
67
|
+
#if TARGET_OS_OSX
|
|
68
|
+
@property(nonatomic, readonly) RTCMTLNSVideoView *videoView;
|
|
74
69
|
#else
|
|
75
|
-
@property(nonatomic, readonly)
|
|
70
|
+
@property(nonatomic, readonly) RTCMTLVideoView *videoView;
|
|
76
71
|
#endif
|
|
77
72
|
|
|
78
73
|
/**
|
|
@@ -87,12 +82,7 @@ typedef NS_ENUM(NSInteger, RTCVideoViewObjectFit) {
|
|
|
87
82
|
|
|
88
83
|
@end
|
|
89
84
|
|
|
90
|
-
@implementation RTCVideoView
|
|
91
|
-
/**
|
|
92
|
-
* The width and height of the video (frames) rendered by {@link #subview}.
|
|
93
|
-
*/
|
|
94
|
-
CGSize _videoSize;
|
|
95
|
-
}
|
|
85
|
+
@implementation RTCVideoView
|
|
96
86
|
|
|
97
87
|
@synthesize videoView = _videoView;
|
|
98
88
|
|
|
@@ -100,11 +90,11 @@ typedef NS_ENUM(NSInteger, RTCVideoViewObjectFit) {
|
|
|
100
90
|
* Tells this view that its window object changed.
|
|
101
91
|
*/
|
|
102
92
|
- (void)didMoveToWindow {
|
|
103
|
-
//
|
|
93
|
+
// This RTCVideoView strongly retains its videoTrack. The latter strongly
|
|
104
94
|
// retains the former as well though because RTCVideoTrack strongly retains
|
|
105
95
|
// the RTCVideoRenderers added to it. In other words, there is a cycle of
|
|
106
|
-
// strong retainments
|
|
107
|
-
//
|
|
96
|
+
// strong retainments. In order to break the cycle, and avoid a leak,
|
|
97
|
+
// have this RTCVideoView as the RTCVideoRenderer of its
|
|
108
98
|
// videoTrack only while this view resides in a window.
|
|
109
99
|
RTCVideoTrack *videoTrack = self.videoTrack;
|
|
110
100
|
|
|
@@ -117,13 +107,6 @@ typedef NS_ENUM(NSInteger, RTCVideoViewObjectFit) {
|
|
|
117
107
|
dispatch_async(_module.workerQueue, ^{
|
|
118
108
|
[videoTrack removeRenderer:self.videoView];
|
|
119
109
|
});
|
|
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
110
|
}
|
|
128
111
|
}
|
|
129
112
|
}
|
|
@@ -136,88 +119,30 @@ typedef NS_ENUM(NSInteger, RTCVideoViewObjectFit) {
|
|
|
136
119
|
*/
|
|
137
120
|
- (instancetype)initWithFrame:(CGRect)frame {
|
|
138
121
|
if (self = [super initWithFrame:frame]) {
|
|
139
|
-
#if
|
|
140
|
-
RTCMTLVideoView *subview = [[RTCMTLVideoView alloc] initWithFrame:CGRectZero];
|
|
141
|
-
subview.delegate = self;
|
|
142
|
-
_videoView = subview;
|
|
143
|
-
#else
|
|
122
|
+
#if TARGET_OS_OSX
|
|
144
123
|
RTCMTLNSVideoView *subview = [[RTCMTLNSVideoView alloc] initWithFrame:CGRectZero];
|
|
145
124
|
subview.wantsLayer = true;
|
|
146
|
-
|
|
125
|
+
_videoView = subview;
|
|
126
|
+
#else
|
|
127
|
+
RTCMTLVideoView *subview = [[RTCMTLVideoView alloc] initWithFrame:CGRectZero];
|
|
147
128
|
_videoView = subview;
|
|
148
129
|
#endif
|
|
149
|
-
|
|
150
|
-
_videoSize.height = 0;
|
|
151
|
-
_videoSize.width = 0;
|
|
152
|
-
|
|
153
|
-
#if !TARGET_OS_OSX
|
|
154
|
-
self.opaque = NO;
|
|
155
|
-
#endif
|
|
156
|
-
|
|
157
130
|
[self addSubview:self.videoView];
|
|
158
131
|
}
|
|
132
|
+
|
|
159
133
|
return self;
|
|
160
134
|
}
|
|
161
135
|
|
|
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
|
|
136
|
+
#if TARGET_OS_OSX
|
|
170
137
|
- (void)layout {
|
|
171
|
-
|
|
172
|
-
#if !TARGET_OS_OSX
|
|
173
|
-
UIView *subview = self.videoView;
|
|
138
|
+
[super layout];
|
|
174
139
|
#else
|
|
175
|
-
|
|
140
|
+
- (void)layoutSubviews {
|
|
141
|
+
[super layoutSubviews];
|
|
176
142
|
#endif
|
|
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);
|
|
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
143
|
|
|
220
|
-
|
|
144
|
+
CGRect bounds = self.bounds;
|
|
145
|
+
self.videoView.frame = bounds;
|
|
221
146
|
}
|
|
222
147
|
|
|
223
148
|
/**
|
|
@@ -231,11 +156,7 @@ typedef NS_ENUM(NSInteger, RTCVideoViewObjectFit) {
|
|
|
231
156
|
if (_mirror != mirror) {
|
|
232
157
|
_mirror = mirror;
|
|
233
158
|
|
|
234
|
-
|
|
235
|
-
[self setNeedsLayout];
|
|
236
|
-
#else
|
|
237
|
-
self.needsLayout = YES;
|
|
238
|
-
#endif
|
|
159
|
+
self.videoView.transform = mirror ? CGAffineTransformMakeScale(-1.0, 1.0) : CGAffineTransformIdentity;
|
|
239
160
|
}
|
|
240
161
|
}
|
|
241
162
|
|
|
@@ -246,14 +167,16 @@ typedef NS_ENUM(NSInteger, RTCVideoViewObjectFit) {
|
|
|
246
167
|
* @param objectFit The value to set on the {@code objectFit} property of this
|
|
247
168
|
* {@code RTCVideoView}.
|
|
248
169
|
*/
|
|
249
|
-
- (void)setObjectFit:(RTCVideoViewObjectFit)
|
|
250
|
-
if (_objectFit !=
|
|
251
|
-
_objectFit =
|
|
170
|
+
- (void)setObjectFit:(RTCVideoViewObjectFit)fit {
|
|
171
|
+
if (_objectFit != fit) {
|
|
172
|
+
_objectFit = fit;
|
|
252
173
|
|
|
253
174
|
#if !TARGET_OS_OSX
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
175
|
+
if (fit == RTCVideoViewObjectFitCover) {
|
|
176
|
+
self.videoView.videoContentMode = UIViewContentModeScaleAspectFill;
|
|
177
|
+
} else {
|
|
178
|
+
self.videoView.videoContentMode = UIViewContentModeScaleAspectFit;
|
|
179
|
+
}
|
|
257
180
|
#endif
|
|
258
181
|
}
|
|
259
182
|
}
|
|
@@ -273,14 +196,6 @@ typedef NS_ENUM(NSInteger, RTCVideoViewObjectFit) {
|
|
|
273
196
|
dispatch_async(_module.workerQueue, ^{
|
|
274
197
|
[oldValue removeRenderer:self.videoView];
|
|
275
198
|
});
|
|
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
199
|
}
|
|
285
200
|
|
|
286
201
|
_videoTrack = videoTrack;
|
|
@@ -319,12 +234,7 @@ typedef NS_ENUM(NSInteger, RTCVideoViewObjectFit) {
|
|
|
319
234
|
CVPixelBufferRelease(pixelBuffer);
|
|
320
235
|
}
|
|
321
236
|
|
|
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.
|
|
237
|
+
// See "didMoveToWindow" above.
|
|
328
238
|
if (videoTrack && self.window) {
|
|
329
239
|
dispatch_async(_module.workerQueue, ^{
|
|
330
240
|
[videoTrack addRenderer:self.videoView];
|
|
@@ -333,46 +243,16 @@ typedef NS_ENUM(NSInteger, RTCVideoViewObjectFit) {
|
|
|
333
243
|
}
|
|
334
244
|
}
|
|
335
245
|
|
|
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
246
|
@end
|
|
361
247
|
|
|
362
248
|
@implementation RTCVideoViewManager
|
|
363
249
|
|
|
364
250
|
RCT_EXPORT_MODULE()
|
|
365
251
|
|
|
366
|
-
|
|
367
|
-
- (UIView *)view {
|
|
368
|
-
#else
|
|
369
|
-
- (NSView *)view {
|
|
370
|
-
#endif
|
|
252
|
+
- (RCTView *)view {
|
|
371
253
|
RTCVideoView *v = [[RTCVideoView alloc] init];
|
|
372
254
|
v.module = [self.bridge moduleForName:@"WebRTCModule"];
|
|
373
|
-
#if !TARGET_OS_OSX
|
|
374
255
|
v.clipsToBounds = YES;
|
|
375
|
-
#endif
|
|
376
256
|
return v;
|
|
377
257
|
}
|
|
378
258
|
|
|
@@ -380,6 +260,8 @@ RCT_EXPORT_MODULE()
|
|
|
380
260
|
return dispatch_get_main_queue();
|
|
381
261
|
}
|
|
382
262
|
|
|
263
|
+
#pragma mark - View properties
|
|
264
|
+
|
|
383
265
|
RCT_EXPORT_VIEW_PROPERTY(mirror, BOOL)
|
|
384
266
|
|
|
385
267
|
/**
|
|
@@ -389,11 +271,11 @@ RCT_EXPORT_VIEW_PROPERTY(mirror, BOOL)
|
|
|
389
271
|
* the CSS style {@code object-fit}.
|
|
390
272
|
*/
|
|
391
273
|
RCT_CUSTOM_VIEW_PROPERTY(objectFit, NSString *, RTCVideoView) {
|
|
392
|
-
NSString *
|
|
393
|
-
RTCVideoViewObjectFit
|
|
394
|
-
(
|
|
274
|
+
NSString *fitStr = json;
|
|
275
|
+
RTCVideoViewObjectFit fit =
|
|
276
|
+
(fitStr && [fitStr isEqualToString:@"cover"]) ? RTCVideoViewObjectFitCover : RTCVideoViewObjectFitContain;
|
|
395
277
|
|
|
396
|
-
view.objectFit =
|
|
278
|
+
view.objectFit = fit;
|
|
397
279
|
}
|
|
398
280
|
|
|
399
281
|
RCT_CUSTOM_VIEW_PROPERTY(streamURL, NSString *, RTCVideoView) {
|
|
@@ -402,7 +284,7 @@ RCT_CUSTOM_VIEW_PROPERTY(streamURL, NSString *, RTCVideoView) {
|
|
|
402
284
|
return;
|
|
403
285
|
}
|
|
404
286
|
|
|
405
|
-
NSString *streamReactTag =
|
|
287
|
+
NSString *streamReactTag = json;
|
|
406
288
|
WebRTCModule *module = view.module;
|
|
407
289
|
|
|
408
290
|
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) {
|