react-native-webrtc 124.0.4 → 124.0.5
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 +2 -1
- package/android/consumer-rules.pro +2 -0
- package/android/src/main/java/com/oney/WebRTCModule/AbstractVideoCaptureController.java +29 -3
- package/android/src/main/java/com/oney/WebRTCModule/CameraCaptureController.java +181 -72
- package/android/src/main/java/com/oney/WebRTCModule/GetUserMediaImpl.java +22 -7
- package/android/src/main/java/com/oney/WebRTCModule/ScreenCaptureController.java +5 -0
- package/android/src/main/java/com/oney/WebRTCModule/WebRTCModule.java +4 -2
- package/ios/RCTWebRTC/CaptureController.h +3 -0
- package/ios/RCTWebRTC/CaptureController.m +13 -0
- package/ios/RCTWebRTC/I420Converter.h +21 -0
- package/ios/RCTWebRTC/I420Converter.m +156 -0
- package/ios/RCTWebRTC/PIPController.h +24 -0
- package/ios/RCTWebRTC/PIPController.m +242 -0
- package/ios/RCTWebRTC/RTCVideoViewManager.h +23 -0
- package/ios/RCTWebRTC/RTCVideoViewManager.m +105 -23
- package/ios/RCTWebRTC/SampleBufferVideoCallView.h +12 -0
- package/ios/RCTWebRTC/SampleBufferVideoCallView.m +180 -0
- package/ios/RCTWebRTC/ScreenCaptureController.m +8 -0
- package/ios/RCTWebRTC/VideoCaptureController.h +2 -0
- package/ios/RCTWebRTC/VideoCaptureController.m +96 -30
- package/ios/RCTWebRTC/WebRTCModule+RTCAudioSession.m +20 -0
- package/ios/RCTWebRTC/WebRTCModule+RTCMediaStream.m +40 -14
- package/ios/RCTWebRTC/WebRTCModuleOptions.h +1 -0
- package/ios/RCTWebRTC.xcodeproj/project.pbxproj +4 -0
- package/lib/commonjs/Constraints.js +2 -0
- package/lib/commonjs/Constraints.js.map +1 -0
- package/lib/commonjs/MediaDevices.js.map +1 -1
- package/lib/commonjs/MediaStreamTrack.js +26 -3
- package/lib/commonjs/MediaStreamTrack.js.map +1 -1
- package/lib/commonjs/RTCAudioSession.js +33 -0
- package/lib/commonjs/RTCAudioSession.js.map +1 -0
- package/lib/commonjs/RTCPIPView.js +42 -0
- package/lib/commonjs/RTCPIPView.js.map +1 -0
- package/lib/commonjs/RTCView.js.map +1 -1
- package/lib/commonjs/getUserMedia.js.map +1 -1
- package/lib/commonjs/index.js +28 -0
- package/lib/commonjs/index.js.map +1 -1
- package/lib/module/Constraints.js +2 -0
- package/lib/module/Constraints.js.map +1 -0
- package/lib/module/MediaDevices.js.map +1 -1
- package/lib/module/MediaStreamTrack.js +27 -4
- package/lib/module/MediaStreamTrack.js.map +1 -1
- package/lib/module/RTCAudioSession.js +26 -0
- package/lib/module/RTCAudioSession.js.map +1 -0
- package/lib/module/RTCPIPView.js +30 -0
- package/lib/module/RTCPIPView.js.map +1 -0
- package/lib/module/RTCView.js.map +1 -1
- package/lib/module/getUserMedia.js.map +1 -1
- package/lib/module/index.js +3 -1
- package/lib/module/index.js.map +1 -1
- package/lib/typescript/Constraints.d.ts +19 -0
- package/lib/typescript/MediaDevices.d.ts +2 -1
- package/lib/typescript/MediaStreamTrack.d.ts +26 -5
- package/lib/typescript/RTCAudioSession.d.ts +10 -0
- package/lib/typescript/RTCPIPView.d.ts +14 -0
- package/lib/typescript/RTCView.d.ts +44 -1
- package/lib/typescript/getUserMedia.d.ts +4 -4
- package/lib/typescript/index.d.ts +5 -3
- package/package.json +2 -1
- package/src/.eslintrc.cjs +1 -1
- package/src/Constraints.ts +21 -0
- package/src/MediaDevices.ts +2 -2
- package/src/MediaStreamTrack.ts +41 -7
- package/src/RTCAudioSession.ts +25 -0
- package/src/RTCPIPView.tsx +46 -0
- package/src/RTCView.ts +50 -2
- package/src/getUserMedia.ts +4 -3
- package/src/index.ts +12 -3
- package/tsconfig.json +3 -1
- package/ios/RCTWebRTC.xcodeproj/xcuserdata/saghul.xcuserdatad/xcschemes/xcschememanagement.plist +0 -14
- package/ios/RCTWebRTC.xcworkspace/xcuserdata/saghul.xcuserdatad/UserInterfaceState.xcuserstate +0 -0
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
//
|
|
2
|
+
// I420Converter.m
|
|
3
|
+
// VideoSampleCaptureRender
|
|
4
|
+
//
|
|
5
|
+
// Adapted from: https://github.com/twilio/video-ios-affectiva/blob/ed2e864324c40ad25e5a06cc2b05298b03caed09/EmoCall/I420Converter.m
|
|
6
|
+
// Created by Boisy Pitre on 5/21/16.
|
|
7
|
+
// Copyright © 2016 Twilio. All rights reserved.
|
|
8
|
+
//
|
|
9
|
+
|
|
10
|
+
#import "I420Converter.h"
|
|
11
|
+
|
|
12
|
+
@interface I420Converter()
|
|
13
|
+
|
|
14
|
+
@property (nonatomic, assign) vImage_YpCbCrToARGB *conversionInfo;
|
|
15
|
+
@property (nonatomic, assign) CVPixelBufferPoolRef pixelBufferPool;
|
|
16
|
+
@property (nonatomic, assign) size_t poolWidth;
|
|
17
|
+
@property (nonatomic, assign) size_t poolHeight;
|
|
18
|
+
@end
|
|
19
|
+
|
|
20
|
+
@implementation I420Converter
|
|
21
|
+
|
|
22
|
+
- (vImage_Error)prepareForAccelerateConversion
|
|
23
|
+
{
|
|
24
|
+
// Setup the YpCbCr to ARGB conversion.
|
|
25
|
+
if (_conversionInfo != NULL) {
|
|
26
|
+
return kvImageNoError;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// I420 uses limited range.
|
|
30
|
+
vImage_YpCbCrPixelRange pixelRange = { 16, 128, 235, 240, 255, 0, 255, 0 };
|
|
31
|
+
vImage_YpCbCrToARGB *outInfo = malloc(sizeof(vImage_YpCbCrToARGB));
|
|
32
|
+
vImageYpCbCrType inType = kvImage420Yp8_Cb8_Cr8;
|
|
33
|
+
vImageARGBType outType = kvImageARGB8888;
|
|
34
|
+
|
|
35
|
+
vImage_Error error = vImageConvert_YpCbCrToARGB_GenerateConversion(kvImage_YpCbCrToARGBMatrix_ITU_R_601_4,
|
|
36
|
+
&pixelRange,
|
|
37
|
+
outInfo,
|
|
38
|
+
inType,
|
|
39
|
+
outType,
|
|
40
|
+
kvImagePrintDiagnosticsToConsole);
|
|
41
|
+
|
|
42
|
+
_conversionInfo = outInfo;
|
|
43
|
+
|
|
44
|
+
return error;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
- (void)unprepareForAccelerateConversion
|
|
48
|
+
{
|
|
49
|
+
if (_conversionInfo != NULL) {
|
|
50
|
+
free(_conversionInfo);
|
|
51
|
+
_conversionInfo = NULL;
|
|
52
|
+
}
|
|
53
|
+
if (_pixelBufferPool != NULL) {
|
|
54
|
+
CVPixelBufferPoolRelease(_pixelBufferPool);
|
|
55
|
+
_pixelBufferPool = NULL;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
- (void)createPixelBufferPoolWithWidth:(size_t)width height:(size_t)height {
|
|
60
|
+
if (_pixelBufferPool != NULL) {
|
|
61
|
+
CVPixelBufferPoolRelease(_pixelBufferPool);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
_poolWidth = width;
|
|
65
|
+
_poolHeight = height;
|
|
66
|
+
NSDictionary *pixelBufferAttributes = @{
|
|
67
|
+
(id)kCVPixelBufferPixelFormatTypeKey: @(kCVPixelFormatType_32BGRA),
|
|
68
|
+
(id)kCVPixelBufferWidthKey: @(width),
|
|
69
|
+
(id)kCVPixelBufferHeightKey: @(height),
|
|
70
|
+
(id)kCVPixelBufferIOSurfacePropertiesKey: @{}
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
CVReturn ret = CVPixelBufferPoolCreate(kCFAllocatorDefault, NULL, (__bridge CFDictionaryRef)pixelBufferAttributes, &_pixelBufferPool);
|
|
74
|
+
|
|
75
|
+
if (ret != kCVReturnSuccess) {
|
|
76
|
+
NSLog(@"Error creating pixel buffer pool: %d", ret);
|
|
77
|
+
_pixelBufferPool = NULL;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
- (CVPixelBufferRef)convertI420ToPixelBuffer:(RTCI420Buffer *)buffer
|
|
82
|
+
{
|
|
83
|
+
if (_conversionInfo == nil) {
|
|
84
|
+
NSLog(@"%@: not prepared", NSStringFromSelector(_cmd));
|
|
85
|
+
return NULL;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
if (_pixelBufferPool == NULL || _poolWidth != buffer.width || _poolHeight != buffer.height) {
|
|
89
|
+
[self createPixelBufferPoolWithWidth:buffer.width height:buffer.height];
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
CVPixelBufferRef pixelBuffer = NULL;
|
|
93
|
+
CVReturn status = CVPixelBufferPoolCreatePixelBuffer(kCFAllocatorDefault, _pixelBufferPool, &pixelBuffer);
|
|
94
|
+
|
|
95
|
+
if (status != kCVReturnSuccess) {
|
|
96
|
+
return NULL;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
vImage_Error err = [self convertFrameVImageYUV:buffer toBuffer:pixelBuffer];
|
|
100
|
+
|
|
101
|
+
if(err != kvImageNoError) {
|
|
102
|
+
NSLog(@"%@: error during conversion: %ld", NSStringFromSelector(_cmd), err);
|
|
103
|
+
CVPixelBufferRelease(pixelBuffer);
|
|
104
|
+
return NULL;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
return pixelBuffer;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
- (vImage_Error)convertFrameVImageYUV:(RTCI420Buffer *)buffer toBuffer:(CVPixelBufferRef)pixelBufferRef
|
|
111
|
+
{
|
|
112
|
+
if (pixelBufferRef == NULL) {
|
|
113
|
+
return kvImageInvalidParameter;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// Compute info for I420 source.
|
|
117
|
+
vImagePixelCount width = buffer.width;
|
|
118
|
+
vImagePixelCount height = buffer.height;
|
|
119
|
+
vImagePixelCount subsampledWidth = buffer.chromaWidth;
|
|
120
|
+
vImagePixelCount subsampledHeight = buffer.chromaHeight;
|
|
121
|
+
|
|
122
|
+
const uint8_t *yPlane = buffer.dataY;
|
|
123
|
+
const uint8_t *uPlane = buffer.dataU;
|
|
124
|
+
const uint8_t *vPlane = buffer.dataV;
|
|
125
|
+
size_t yStride = (size_t)buffer.strideY;
|
|
126
|
+
size_t uStride = (size_t)buffer.strideU;
|
|
127
|
+
size_t vStride = (size_t)buffer.strideV;
|
|
128
|
+
|
|
129
|
+
// Create vImage buffers to represent each of the Y, U, and V planes
|
|
130
|
+
vImage_Buffer yPlaneBuffer = {.data = (void *)yPlane, .height = height, .width = width, .rowBytes = yStride};
|
|
131
|
+
vImage_Buffer uPlaneBuffer = {.data = (void *)uPlane, .height = subsampledHeight, .width = subsampledWidth, .rowBytes = uStride};
|
|
132
|
+
vImage_Buffer vPlaneBuffer = {.data = (void *)vPlane, .height = subsampledHeight, .width = subsampledWidth, .rowBytes = vStride};
|
|
133
|
+
|
|
134
|
+
// Create a vImage buffer for the destination pixel buffer.
|
|
135
|
+
CVPixelBufferLockBaseAddress(pixelBufferRef, 0);
|
|
136
|
+
|
|
137
|
+
void *pixelBufferData = CVPixelBufferGetBaseAddress(pixelBufferRef);
|
|
138
|
+
size_t rowBytes = CVPixelBufferGetBytesPerRow(pixelBufferRef);
|
|
139
|
+
vImage_Buffer destinationImageBuffer = {.data = pixelBufferData, .height = height, .width = width, .rowBytes = rowBytes};
|
|
140
|
+
|
|
141
|
+
// Do the conversion.
|
|
142
|
+
|
|
143
|
+
uint8_t permuteMap[4] = {3, 2, 1, 0}; // BGRA
|
|
144
|
+
vImage_Error convertError = vImageConvert_420Yp8_Cb8_Cr8ToARGB8888(&yPlaneBuffer, &uPlaneBuffer, &vPlaneBuffer, &destinationImageBuffer, self.conversionInfo, permuteMap, 255, kvImageNoFlags);
|
|
145
|
+
|
|
146
|
+
CVPixelBufferUnlockBaseAddress(pixelBufferRef, 0);
|
|
147
|
+
|
|
148
|
+
return convertError;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
- (void)dealloc {
|
|
152
|
+
[self unprepareForAccelerateConversion];
|
|
153
|
+
CVPixelBufferPoolRelease(_pixelBufferPool);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
@end
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
#import <UIKit/UIKit.h>
|
|
2
|
+
#import <WebRTC/RTCVideoTrack.h>
|
|
3
|
+
#import <AVKit/AVKit.h>
|
|
4
|
+
|
|
5
|
+
#import "RTCVideoViewManager.h"
|
|
6
|
+
|
|
7
|
+
API_AVAILABLE(ios(15.0))
|
|
8
|
+
@interface PIPController : NSObject <AVPictureInPictureControllerDelegate>
|
|
9
|
+
|
|
10
|
+
@property(nonatomic, weak) UIView *sourceView;
|
|
11
|
+
@property(nonatomic, strong) RTCVideoTrack *videoTrack;
|
|
12
|
+
|
|
13
|
+
@property(nonatomic, assign) BOOL startAutomatically;
|
|
14
|
+
@property(nonatomic, assign) BOOL stopAutomatically;
|
|
15
|
+
@property(nonatomic, assign) CGSize preferredSize;
|
|
16
|
+
|
|
17
|
+
- (instancetype)initWithSourceView:(UIView *)sourceView;
|
|
18
|
+
- (void)togglePIP;
|
|
19
|
+
- (void)startPIP;
|
|
20
|
+
- (void)stopPIP;
|
|
21
|
+
- (void)insertFallbackView:(UIView *)subview;
|
|
22
|
+
- (void)setObjectFit:(RTCVideoViewObjectFit)fit;
|
|
23
|
+
|
|
24
|
+
@end
|
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
#import <AVKit/AVKit.h>
|
|
2
|
+
#import "PIPController.h"
|
|
3
|
+
#import "SampleBufferVideoCallView.h"
|
|
4
|
+
|
|
5
|
+
@interface PIPController ()
|
|
6
|
+
|
|
7
|
+
@property(nonatomic, strong) AVPictureInPictureVideoCallViewController *pipCallViewController;
|
|
8
|
+
@property(nonatomic, strong) AVPictureInPictureControllerContentSource *contentSource;
|
|
9
|
+
@property(nonatomic, strong) AVPictureInPictureController *pipController;
|
|
10
|
+
@property(nonnull, nonatomic, strong) SampleBufferVideoCallView *sampleView;
|
|
11
|
+
|
|
12
|
+
@property(nonnull, nonatomic, strong) UIView *fallbackView;
|
|
13
|
+
|
|
14
|
+
@end
|
|
15
|
+
|
|
16
|
+
@implementation PIPController
|
|
17
|
+
|
|
18
|
+
- (instancetype)initWithSourceView:(UIView *)sourceView {
|
|
19
|
+
|
|
20
|
+
if (self = [super init]) {
|
|
21
|
+
self.sourceView = sourceView;
|
|
22
|
+
|
|
23
|
+
_fallbackView = [[UIView alloc] initWithFrame:CGRectZero];
|
|
24
|
+
_fallbackView.translatesAutoresizingMaskIntoConstraints = false;
|
|
25
|
+
|
|
26
|
+
SampleBufferVideoCallView * subview = [[SampleBufferVideoCallView alloc] initWithFrame:CGRectZero];
|
|
27
|
+
_sampleView = subview;
|
|
28
|
+
_sampleView.translatesAutoresizingMaskIntoConstraints = false;
|
|
29
|
+
_pipCallViewController = [[AVPictureInPictureVideoCallViewController alloc] init];
|
|
30
|
+
|
|
31
|
+
[self addToCallViewController:_fallbackView];
|
|
32
|
+
|
|
33
|
+
_contentSource = [[AVPictureInPictureControllerContentSource alloc] initWithActiveVideoCallSourceView:sourceView contentViewController:_pipCallViewController];
|
|
34
|
+
|
|
35
|
+
_pipController = [[AVPictureInPictureController alloc] initWithContentSource:_contentSource];
|
|
36
|
+
_pipController.canStartPictureInPictureAutomaticallyFromInline = YES;
|
|
37
|
+
_pipController.delegate = self;
|
|
38
|
+
|
|
39
|
+
[_pipController addObserver:self
|
|
40
|
+
forKeyPath:@"pictureInPictureActive"
|
|
41
|
+
options:NSKeyValueObservingOptionInitial|NSKeyValueObservingOptionNew
|
|
42
|
+
context:nil];
|
|
43
|
+
|
|
44
|
+
[[NSNotificationCenter defaultCenter] addObserver:self
|
|
45
|
+
selector:@selector(applicationWillEnterForeground:)
|
|
46
|
+
name:UIApplicationWillEnterForegroundNotification
|
|
47
|
+
object:nil];
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
return self;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
- (void)observeValueForKeyPath:(NSString *)keyPath
|
|
54
|
+
ofObject:(id)object
|
|
55
|
+
change:(NSDictionary *)change
|
|
56
|
+
context:(void *)context
|
|
57
|
+
{
|
|
58
|
+
if([keyPath isEqualToString:@"pictureInPictureActive"]) {
|
|
59
|
+
_sampleView.shouldRender = [change[NSKeyValueChangeNewKey] boolValue];
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
- (void)applicationWillEnterForeground:(NSNotification *)notification {
|
|
64
|
+
if (_stopAutomatically) {
|
|
65
|
+
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.5 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
|
|
66
|
+
[self.pipController stopPictureInPicture];
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
- (void)addToCallViewController:(UIView *)view {
|
|
72
|
+
[_pipCallViewController.view addSubview:view];
|
|
73
|
+
NSArray *constraints = @[
|
|
74
|
+
[view.leadingAnchor constraintEqualToAnchor:_pipCallViewController.view.leadingAnchor],
|
|
75
|
+
[view.trailingAnchor constraintEqualToAnchor: _pipCallViewController.view.trailingAnchor],
|
|
76
|
+
[view.topAnchor constraintEqualToAnchor: _pipCallViewController.view.topAnchor],
|
|
77
|
+
[view.bottomAnchor constraintEqualToAnchor: _pipCallViewController.view.bottomAnchor]
|
|
78
|
+
];
|
|
79
|
+
[NSLayoutConstraint activateConstraints:constraints];
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
- (void)setVideoTrack:(RTCVideoTrack *)videoTrack {
|
|
83
|
+
if (_videoTrack != videoTrack) {
|
|
84
|
+
[_videoTrack removeRenderer:_sampleView];
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
_videoTrack = videoTrack;
|
|
88
|
+
[videoTrack addRenderer:_sampleView];
|
|
89
|
+
|
|
90
|
+
if (_videoTrack) {
|
|
91
|
+
if (!_sampleView.superview) {
|
|
92
|
+
[self addToCallViewController:_sampleView];
|
|
93
|
+
}
|
|
94
|
+
if (_fallbackView.superview) {
|
|
95
|
+
[_fallbackView removeFromSuperview];
|
|
96
|
+
}
|
|
97
|
+
} else {
|
|
98
|
+
if (!_fallbackView.superview) {
|
|
99
|
+
[self addToCallViewController:_fallbackView];
|
|
100
|
+
}
|
|
101
|
+
if (_sampleView.superview) {
|
|
102
|
+
[_sampleView removeFromSuperview];
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
- (void)insertFallbackView:(UIView *)view {
|
|
108
|
+
[self.fallbackView addSubview:view];
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
- (void)setObjectFit:(RTCVideoViewObjectFit)fit {
|
|
112
|
+
if (fit == RTCVideoViewObjectFitCover) {
|
|
113
|
+
self.sampleView.sampleBufferLayer.videoGravity = AVLayerVideoGravityResizeAspectFill;
|
|
114
|
+
} else {
|
|
115
|
+
self.sampleView.sampleBufferLayer.videoGravity = AVLayerVideoGravityResizeAspect;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
- (CGSize)preferredSize {
|
|
120
|
+
return _pipCallViewController.preferredContentSize;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
- (void)setPreferredSize:(CGSize)size {
|
|
124
|
+
if (!CGSizeEqualToSize(size, _pipCallViewController.preferredContentSize)) {
|
|
125
|
+
_pipCallViewController.preferredContentSize = size;
|
|
126
|
+
[_sampleView requestScaleRecalculation];
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
- (BOOL)startAutomatically {
|
|
131
|
+
return _pipController.canStartPictureInPictureAutomaticallyFromInline;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
- (void)setStartAutomatically:(BOOL)value {
|
|
135
|
+
_pipController.canStartPictureInPictureAutomaticallyFromInline = value;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
- (void)togglePIP {
|
|
139
|
+
if(_pipController.isPictureInPictureActive) {
|
|
140
|
+
[_pipController stopPictureInPicture];
|
|
141
|
+
} else if(_pipController.isPictureInPicturePossible){
|
|
142
|
+
[_pipController startPictureInPicture];
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
- (void)startPIP {
|
|
147
|
+
if (_pipController.isPictureInPicturePossible) {
|
|
148
|
+
[_pipController startPictureInPicture];
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
- (void)stopPIP {
|
|
153
|
+
if(_pipController.isPictureInPictureActive) {
|
|
154
|
+
[_pipController stopPictureInPicture];
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
- (void)dealloc {
|
|
159
|
+
[_videoTrack removeRenderer:_sampleView];
|
|
160
|
+
[_pipController removeObserver:self forKeyPath:@"pictureInPictureActive"];
|
|
161
|
+
[[NSNotificationCenter defaultCenter] removeObserver:self
|
|
162
|
+
name:UIApplicationDidBecomeActiveNotification
|
|
163
|
+
object:nil];
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
@end
|
|
167
|
+
|
|
168
|
+
@implementation PIPController (AVPictureInPictureControllerDelegate)
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
/*!
|
|
172
|
+
@method pictureInPictureControllerWillStartPictureInPicture:
|
|
173
|
+
@param pictureInPictureController
|
|
174
|
+
The Picture in Picture controller.
|
|
175
|
+
@abstract Delegate can implement this method to be notified when Picture in Picture will start.
|
|
176
|
+
*/
|
|
177
|
+
- (void)pictureInPictureControllerWillStartPictureInPicture:(AVPictureInPictureController *)pictureInPictureController {
|
|
178
|
+
|
|
179
|
+
NSLog(@"%@", NSStringFromSelector(_cmd)); // Objective-C
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/*!
|
|
183
|
+
@method pictureInPictureControllerDidStartPictureInPicture:
|
|
184
|
+
@param pictureInPictureController
|
|
185
|
+
The Picture in Picture controller.
|
|
186
|
+
@abstract Delegate can implement this method to be notified when Picture in Picture did start.
|
|
187
|
+
*/
|
|
188
|
+
- (void)pictureInPictureControllerDidStartPictureInPicture:(AVPictureInPictureController *)pictureInPictureController {
|
|
189
|
+
|
|
190
|
+
NSLog(@"%@", NSStringFromSelector(_cmd)); // Objective-C
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
/*!
|
|
194
|
+
@method pictureInPictureController:failedToStartPictureInPictureWithError:
|
|
195
|
+
@param pictureInPictureController
|
|
196
|
+
The Picture in Picture controller.
|
|
197
|
+
@param error
|
|
198
|
+
An error describing why it failed.
|
|
199
|
+
@abstract Delegate can implement this method to be notified when Picture in Picture failed to start.
|
|
200
|
+
*/
|
|
201
|
+
- (void)pictureInPictureController:(AVPictureInPictureController *)pictureInPictureController failedToStartPictureInPictureWithError:(NSError *)error{
|
|
202
|
+
|
|
203
|
+
NSLog(@"%@: %@", NSStringFromSelector(_cmd), [error localizedDescription]); // Objective-C
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
/*!
|
|
207
|
+
@method pictureInPictureControllerWillStopPictureInPicture:
|
|
208
|
+
@param pictureInPictureController
|
|
209
|
+
The Picture in Picture controller.
|
|
210
|
+
@abstract Delegate can implement this method to be notified when Picture in Picture will stop.
|
|
211
|
+
*/
|
|
212
|
+
- (void)pictureInPictureControllerWillStopPictureInPicture:(AVPictureInPictureController *)pictureInPictureController {
|
|
213
|
+
|
|
214
|
+
NSLog(@"%@", NSStringFromSelector(_cmd)); // Objective-C
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
/*!
|
|
218
|
+
@method pictureInPictureControllerDidStopPictureInPicture:
|
|
219
|
+
@param pictureInPictureController
|
|
220
|
+
The Picture in Picture controller.
|
|
221
|
+
@abstract Delegate can implement this method to be notified when Picture in Picture did stop.
|
|
222
|
+
*/
|
|
223
|
+
- (void)pictureInPictureControllerDidStopPictureInPicture:(AVPictureInPictureController *)pictureInPictureController {
|
|
224
|
+
|
|
225
|
+
NSLog(@"%@", NSStringFromSelector(_cmd)); // Objective-C
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
/*!
|
|
229
|
+
@method pictureInPictureController:restoreUserInterfaceForPictureInPictureStopWithCompletionHandler:
|
|
230
|
+
@param pictureInPictureController
|
|
231
|
+
The Picture in Picture controller.
|
|
232
|
+
@param completionHandler
|
|
233
|
+
The completion handler the delegate needs to call after restore.
|
|
234
|
+
@abstract Delegate can implement this method to restore the user interface before Picture in Picture stops.
|
|
235
|
+
*/
|
|
236
|
+
- (void)pictureInPictureController:(AVPictureInPictureController *)pictureInPictureController restoreUserInterfaceForPictureInPictureStopWithCompletionHandler:(void (^)(BOOL restored))completionHandler {
|
|
237
|
+
|
|
238
|
+
NSLog(@"%@", NSStringFromSelector(_cmd)); // Objective-C
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
|
|
242
|
+
@end
|
|
@@ -1,6 +1,29 @@
|
|
|
1
1
|
#import <Foundation/Foundation.h>
|
|
2
2
|
#import <React/RCTViewManager.h>
|
|
3
3
|
|
|
4
|
+
/**
|
|
5
|
+
* In the fashion of
|
|
6
|
+
* https://www.w3.org/TR/html5/embedded-content-0.html#dom-video-videowidth
|
|
7
|
+
* and https://www.w3.org/TR/html5/rendering.html#video-object-fit, resembles
|
|
8
|
+
* the CSS style {@code object-fit}.
|
|
9
|
+
*/
|
|
10
|
+
typedef NS_ENUM(NSInteger, RTCVideoViewObjectFit) {
|
|
11
|
+
/**
|
|
12
|
+
* The contain value defined by https://www.w3.org/TR/css3-images/#object-fit:
|
|
13
|
+
*
|
|
14
|
+
* The replaced content is sized to maintain its aspect ratio while fitting
|
|
15
|
+
* within the element's content box.
|
|
16
|
+
*/
|
|
17
|
+
RTCVideoViewObjectFitContain = 1,
|
|
18
|
+
/**
|
|
19
|
+
* The cover value defined by https://www.w3.org/TR/css3-images/#object-fit:
|
|
20
|
+
*
|
|
21
|
+
* The replaced content is sized to maintain its aspect ratio while filling
|
|
22
|
+
* the element's entire content box.
|
|
23
|
+
*/
|
|
24
|
+
RTCVideoViewObjectFitCover
|
|
25
|
+
};
|
|
26
|
+
|
|
4
27
|
@interface RTCVideoViewManager : RCTViewManager
|
|
5
28
|
|
|
6
29
|
@end
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
#import <objc/runtime.h>
|
|
3
3
|
|
|
4
4
|
#import <React/RCTLog.h>
|
|
5
|
+
#import <React/RCTUIManager.h>
|
|
5
6
|
#import <React/RCTView.h>
|
|
6
7
|
|
|
7
8
|
#import <WebRTC/RTCMediaStream.h>
|
|
@@ -14,32 +15,10 @@
|
|
|
14
15
|
#import <WebRTC/RTCVideoFrame.h>
|
|
15
16
|
#import <WebRTC/RTCVideoTrack.h>
|
|
16
17
|
|
|
18
|
+
#import "PIPController.h"
|
|
17
19
|
#import "RTCVideoViewManager.h"
|
|
18
20
|
#import "WebRTCModule.h"
|
|
19
21
|
|
|
20
|
-
/**
|
|
21
|
-
* In the fashion of
|
|
22
|
-
* https://www.w3.org/TR/html5/embedded-content-0.html#dom-video-videowidth
|
|
23
|
-
* and https://www.w3.org/TR/html5/rendering.html#video-object-fit, resembles
|
|
24
|
-
* the CSS style {@code object-fit}.
|
|
25
|
-
*/
|
|
26
|
-
typedef NS_ENUM(NSInteger, RTCVideoViewObjectFit) {
|
|
27
|
-
/**
|
|
28
|
-
* The contain value defined by https://www.w3.org/TR/css3-images/#object-fit:
|
|
29
|
-
*
|
|
30
|
-
* The replaced content is sized to maintain its aspect ratio while fitting
|
|
31
|
-
* within the element's content box.
|
|
32
|
-
*/
|
|
33
|
-
RTCVideoViewObjectFitContain = 1,
|
|
34
|
-
/**
|
|
35
|
-
* The cover value defined by https://www.w3.org/TR/css3-images/#object-fit:
|
|
36
|
-
*
|
|
37
|
-
* The replaced content is sized to maintain its aspect ratio while filling
|
|
38
|
-
* the element's entire content box.
|
|
39
|
-
*/
|
|
40
|
-
RTCVideoViewObjectFitCover
|
|
41
|
-
};
|
|
42
|
-
|
|
43
22
|
/**
|
|
44
23
|
* Implements an equivalent of {@code HTMLVideoElement} i.e. Web's video
|
|
45
24
|
* element.
|
|
@@ -61,6 +40,10 @@ typedef NS_ENUM(NSInteger, RTCVideoViewObjectFit) {
|
|
|
61
40
|
*/
|
|
62
41
|
@property(nonatomic) RTCVideoViewObjectFit objectFit;
|
|
63
42
|
|
|
43
|
+
@property(nonatomic) BOOL enablePIP;
|
|
44
|
+
|
|
45
|
+
@property(nonatomic, strong) API_AVAILABLE(ios(15.0)) PIPController *pipController;
|
|
46
|
+
|
|
64
47
|
/**
|
|
65
48
|
* The {@link RRTCVideoRenderer} which implements the actual rendering.
|
|
66
49
|
*/
|
|
@@ -85,6 +68,7 @@ typedef NS_ENUM(NSInteger, RTCVideoViewObjectFit) {
|
|
|
85
68
|
@implementation RTCVideoView
|
|
86
69
|
|
|
87
70
|
@synthesize videoView = _videoView;
|
|
71
|
+
@synthesize pipController = _pipController;
|
|
88
72
|
|
|
89
73
|
/**
|
|
90
74
|
* Tells this view that its window object changed.
|
|
@@ -127,6 +111,7 @@ typedef NS_ENUM(NSInteger, RTCVideoViewObjectFit) {
|
|
|
127
111
|
RTCMTLVideoView *subview = [[RTCMTLVideoView alloc] initWithFrame:CGRectZero];
|
|
128
112
|
_videoView = subview;
|
|
129
113
|
#endif
|
|
114
|
+
_objectFit = RTCVideoViewObjectFitCover;
|
|
130
115
|
[self addSubview:self.videoView];
|
|
131
116
|
}
|
|
132
117
|
|
|
@@ -160,6 +145,66 @@ typedef NS_ENUM(NSInteger, RTCVideoViewObjectFit) {
|
|
|
160
145
|
}
|
|
161
146
|
}
|
|
162
147
|
|
|
148
|
+
- (void)insertReactSubview:(UIView *)subview atIndex:(NSInteger)atIndex {
|
|
149
|
+
// All subviews are treated as fallback views
|
|
150
|
+
[_pipController insertFallbackView:subview];
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
- (void) API_AVAILABLE(ios(15.0)) setPIPOptions:(NSDictionary *)pipOptions {
|
|
154
|
+
if (!pipOptions) {
|
|
155
|
+
_pipController = nil;
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
BOOL enabled = YES;
|
|
160
|
+
BOOL startAutomatically = YES;
|
|
161
|
+
BOOL stopAutomatically = YES;
|
|
162
|
+
|
|
163
|
+
CGSize preferredSize = CGSizeZero;
|
|
164
|
+
|
|
165
|
+
if ([pipOptions objectForKey:@"enabled"]) {
|
|
166
|
+
enabled = [pipOptions[@"enabled"] boolValue];
|
|
167
|
+
}
|
|
168
|
+
if ([pipOptions objectForKey:@"startAutomatically"]) {
|
|
169
|
+
startAutomatically = [pipOptions[@"startAutomatically"] boolValue];
|
|
170
|
+
}
|
|
171
|
+
if ([pipOptions objectForKey:@"stopAutomatically"]) {
|
|
172
|
+
stopAutomatically = [pipOptions[@"stopAutomatically"] boolValue];
|
|
173
|
+
}
|
|
174
|
+
if ([pipOptions objectForKey:@"preferredSize"]) {
|
|
175
|
+
NSDictionary *sizeDict = pipOptions[@"preferredSize"];
|
|
176
|
+
id width = sizeDict[@"width"];
|
|
177
|
+
id height = sizeDict[@"height"];
|
|
178
|
+
|
|
179
|
+
if ([width isKindOfClass:[NSNumber class]] && [height isKindOfClass:[NSNumber class]]) {
|
|
180
|
+
preferredSize = CGSizeMake([width doubleValue], [height doubleValue]);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
if (!enabled) {
|
|
185
|
+
_pipController = nil;
|
|
186
|
+
return;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
if (!_pipController) {
|
|
190
|
+
_pipController = [[PIPController alloc] initWithSourceView:self];
|
|
191
|
+
_pipController.videoTrack = _videoTrack;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
_pipController.startAutomatically = startAutomatically;
|
|
195
|
+
_pipController.stopAutomatically = stopAutomatically;
|
|
196
|
+
_pipController.objectFit = _objectFit;
|
|
197
|
+
_pipController.preferredSize = preferredSize;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
- (void) API_AVAILABLE(ios(15.0)) startPIP {
|
|
201
|
+
[_pipController startPIP];
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
- (void) API_AVAILABLE(ios(15.0)) stopPIP {
|
|
205
|
+
[_pipController stopPIP];
|
|
206
|
+
}
|
|
207
|
+
|
|
163
208
|
/**
|
|
164
209
|
* Implements the setter of the {@link #objectFit} property of this
|
|
165
210
|
* {@code RTCVideoView}.
|
|
@@ -178,6 +223,9 @@ typedef NS_ENUM(NSInteger, RTCVideoViewObjectFit) {
|
|
|
178
223
|
self.videoView.videoContentMode = UIViewContentModeScaleAspectFit;
|
|
179
224
|
}
|
|
180
225
|
#endif
|
|
226
|
+
if (@available(iOS 15.0, *)) {
|
|
227
|
+
_pipController.objectFit = fit;
|
|
228
|
+
}
|
|
181
229
|
}
|
|
182
230
|
}
|
|
183
231
|
|
|
@@ -198,6 +246,7 @@ typedef NS_ENUM(NSInteger, RTCVideoViewObjectFit) {
|
|
|
198
246
|
});
|
|
199
247
|
}
|
|
200
248
|
|
|
249
|
+
[_pipController setVideoTrack:videoTrack];
|
|
201
250
|
_videoTrack = videoTrack;
|
|
202
251
|
|
|
203
252
|
// Clear the videoView by rendering a 2x2 blank frame.
|
|
@@ -301,6 +350,39 @@ RCT_CUSTOM_VIEW_PROPERTY(streamURL, NSString *, RTCVideoView) {
|
|
|
301
350
|
});
|
|
302
351
|
}
|
|
303
352
|
|
|
353
|
+
RCT_CUSTOM_VIEW_PROPERTY(iosPIP, NSDictionary *, RTCVideoView) {
|
|
354
|
+
if (@available(iOS 15.0, *)) {
|
|
355
|
+
[view setPIPOptions:json];
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
RCT_EXPORT_METHOD(startIOSPIP:(nonnull NSNumber *)reactTag) {
|
|
360
|
+
if (@available(iOS 15.0, *)) {
|
|
361
|
+
RCTUIManager *uiManager = [self.bridge moduleForClass:[RCTUIManager class]];
|
|
362
|
+
[uiManager addUIBlock:^(RCTUIManager *uiManager, NSDictionary<NSNumber *,UIView *> *viewRegistry) {
|
|
363
|
+
UIView *view = viewRegistry[reactTag];
|
|
364
|
+
if (!view || ![view isKindOfClass:[RTCVideoView class]]) {
|
|
365
|
+
RCTLogError(@"Cannot find RTCVideoView with tag #%@", reactTag);
|
|
366
|
+
return;
|
|
367
|
+
}
|
|
368
|
+
[(RTCVideoView *)view startPIP];
|
|
369
|
+
}];
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
RCT_EXPORT_METHOD(stopIOSPIP:(nonnull NSNumber *)reactTag) {
|
|
374
|
+
if (@available(iOS 15.0, *)) {
|
|
375
|
+
RCTUIManager *uiManager = [self.bridge moduleForClass:[RCTUIManager class]];
|
|
376
|
+
[uiManager addUIBlock:^(RCTUIManager *uiManager, NSDictionary<NSNumber *,UIView *> *viewRegistry) {
|
|
377
|
+
UIView *view = viewRegistry[reactTag];
|
|
378
|
+
if (!view || ![view isKindOfClass:[RTCVideoView class]]) {
|
|
379
|
+
RCTLogError(@"Cannot find RTCVideoView with tag #%@", reactTag);
|
|
380
|
+
return;
|
|
381
|
+
}
|
|
382
|
+
[(RTCVideoView *)view stopPIP];
|
|
383
|
+
}];
|
|
384
|
+
}
|
|
385
|
+
}
|
|
304
386
|
+ (BOOL)requiresMainQueueSetup {
|
|
305
387
|
return NO;
|
|
306
388
|
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
#import <Foundation/Foundation.h>
|
|
2
|
+
#import <React/RCTViewManager.h>
|
|
3
|
+
#import <AVKit/AVKit.h>
|
|
4
|
+
#import <WebRTC/RTCVideoRenderer.h>
|
|
5
|
+
|
|
6
|
+
@interface SampleBufferVideoCallView : UIView <RTCVideoRenderer>
|
|
7
|
+
|
|
8
|
+
@property(nonnull, nonatomic, readonly) AVSampleBufferDisplayLayer *sampleBufferLayer;
|
|
9
|
+
@property(nonatomic, assign) BOOL shouldRender;
|
|
10
|
+
|
|
11
|
+
- (void)requestScaleRecalculation;
|
|
12
|
+
@end
|