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.
- package/.clang-format +11 -0
- package/.github/workflows/android_ci.yml +29 -0
- package/.github/workflows/ci.yml +1 -1
- package/.github/workflows/ios_ci.yml +50 -0
- package/LICENSE +2 -1
- package/android/src/main/java/com/oney/WebRTCModule/AbstractVideoCaptureController.java +11 -1
- package/android/src/main/java/com/oney/WebRTCModule/CameraCaptureController.java +7 -15
- package/android/src/main/java/com/oney/WebRTCModule/CameraEventsHandler.java +4 -13
- 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 +37 -47
- 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 +12 -9
- package/android/src/main/java/com/oney/WebRTCModule/SerializeUtils.java +116 -121
- 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 +34 -0
- package/android/src/main/java/com/oney/WebRTCModule/VideoTrackAdapter.java +5 -9
- package/android/src/main/java/com/oney/WebRTCModule/WebRTCModule.java +383 -378
- 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 +4 -8
- package/ios/RCTWebRTC/CaptureController.m +0 -7
- package/ios/RCTWebRTC/CapturerEventsDelegate.h +12 -0
- 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 +207 -239
- package/ios/RCTWebRTC/ScreenCaptureController.h +3 -9
- package/ios/RCTWebRTC/ScreenCaptureController.m +20 -15
- package/ios/RCTWebRTC/ScreenCapturePickerViewManager.h +0 -7
- package/ios/RCTWebRTC/ScreenCapturePickerViewManager.m +26 -34
- package/ios/RCTWebRTC/ScreenCapturer.h +4 -8
- package/ios/RCTWebRTC/ScreenCapturer.m +57 -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 +14 -0
- package/ios/RCTWebRTC/TrackCapturerEventsEmitter.m +37 -0
- 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 +8 -0
- package/ios/RCTWebRTC/WebRTCModule+RTCMediaStream.m +218 -173
- package/ios/RCTWebRTC/WebRTCModule+RTCPeerConnection.h +7 -14
- package/ios/RCTWebRTC/WebRTCModule+RTCPeerConnection.m +625 -595
- 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 +14 -20
- package/ios/RCTWebRTC/WebRTCModule.m +69 -83
- package/ios/RCTWebRTC.xcodeproj/project.pbxproj +10 -1
- package/ios/RCTWebRTC.xcworkspace/xcuserdata/saghul.xcuserdatad/UserInterfaceState.xcuserstate +0 -0
- package/lib/commonjs/EventEmitter.js +1 -1
- package/lib/commonjs/EventEmitter.js.map +1 -1
- package/lib/commonjs/MediaStreamTrack.js +25 -0
- package/lib/commonjs/MediaStreamTrack.js.map +1 -1
- package/lib/commonjs/RTCPeerConnection.js +169 -162
- 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/EventEmitter.js +1 -1
- package/lib/module/EventEmitter.js.map +1 -1
- package/lib/module/MediaStreamTrack.js +21 -0
- package/lib/module/MediaStreamTrack.js.map +1 -1
- package/lib/module/RTCPeerConnection.js +169 -162
- 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/MediaStreamTrack.d.ts +1 -0
- package/lib/typescript/RTCPeerConnection.d.ts +5 -4
- package/package.json +3 -2
- package/src/EventEmitter.ts +1 -0
- package/src/MediaStreamTrack.ts +23 -0
- package/src/RTCPeerConnection.ts +168 -174
- 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
|
@@ -1,26 +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;
|
|
11
|
+
|
|
12
|
+
@end
|
|
18
13
|
|
|
14
|
+
@interface ScreenCaptureController (CapturerEventsDelegate)<CapturerEventsDelegate>
|
|
15
|
+
- (void)capturerDidEnd:(RTCVideoCapturer *)capturer;
|
|
19
16
|
@end
|
|
20
17
|
|
|
21
18
|
@interface ScreenCaptureController (Private)
|
|
22
19
|
|
|
23
|
-
@property
|
|
20
|
+
@property(nonatomic, readonly) NSString *appGroupIdentifier;
|
|
24
21
|
|
|
25
22
|
@end
|
|
26
23
|
|
|
@@ -31,7 +28,7 @@ NSString* const kRTCAppGroupIdentifier = @"RTCAppGroupIdentifier";
|
|
|
31
28
|
if (self) {
|
|
32
29
|
self.capturer = capturer;
|
|
33
30
|
}
|
|
34
|
-
|
|
31
|
+
|
|
35
32
|
return self;
|
|
36
33
|
}
|
|
37
34
|
|
|
@@ -43,7 +40,8 @@ NSString* const kRTCAppGroupIdentifier = @"RTCAppGroupIdentifier";
|
|
|
43
40
|
if (!self.appGroupIdentifier) {
|
|
44
41
|
return;
|
|
45
42
|
}
|
|
46
|
-
|
|
43
|
+
|
|
44
|
+
self.capturer.eventsDelegate = self;
|
|
47
45
|
NSString *socketFilePath = [self filePathForApplicationGroupIdentifier:self.appGroupIdentifier];
|
|
48
46
|
SocketConnection *connection = [[SocketConnection alloc] initWithFilePath:socketFilePath];
|
|
49
47
|
[self.capturer startCaptureWithConnection:connection];
|
|
@@ -53,6 +51,12 @@ NSString* const kRTCAppGroupIdentifier = @"RTCAppGroupIdentifier";
|
|
|
53
51
|
[self.capturer stopCapture];
|
|
54
52
|
}
|
|
55
53
|
|
|
54
|
+
// MARK: CapturerEventsDelegate Methods
|
|
55
|
+
|
|
56
|
+
- (void)capturerDidEnd:(RTCVideoCapturer *)capturer {
|
|
57
|
+
[self.eventsDelegate capturerDidEnd:capturer];
|
|
58
|
+
}
|
|
59
|
+
|
|
56
60
|
// MARK: Private Methods
|
|
57
61
|
|
|
58
62
|
- (NSString *)appGroupIdentifier {
|
|
@@ -61,9 +65,10 @@ NSString* const kRTCAppGroupIdentifier = @"RTCAppGroupIdentifier";
|
|
|
61
65
|
}
|
|
62
66
|
|
|
63
67
|
- (NSString *)filePathForApplicationGroupIdentifier:(nonnull NSString *)identifier {
|
|
64
|
-
NSURL *sharedContainer =
|
|
68
|
+
NSURL *sharedContainer =
|
|
69
|
+
[[NSFileManager defaultManager] containerURLForSecurityApplicationGroupIdentifier:identifier];
|
|
65
70
|
NSString *socketFilePath = [[sharedContainer URLByAppendingPathComponent:kRTCScreensharingSocketFD] path];
|
|
66
|
-
|
|
71
|
+
|
|
67
72
|
return socketFilePath;
|
|
68
73
|
}
|
|
69
74
|
|
|
@@ -1,18 +1,11 @@
|
|
|
1
|
-
//
|
|
2
|
-
// ScreenCapturePickerViewManager.m
|
|
3
|
-
// react-native-webrtc
|
|
4
|
-
//
|
|
5
|
-
// Created by Alex-Dan Bumbu on 20/01/2021.
|
|
6
|
-
//
|
|
7
|
-
|
|
8
1
|
#if !TARGET_OS_OSX
|
|
9
2
|
|
|
10
|
-
#import <ReplayKit/ReplayKit.h>
|
|
11
3
|
#import <React/RCTUIManager.h>
|
|
4
|
+
#import <ReplayKit/ReplayKit.h>
|
|
12
5
|
|
|
13
6
|
#import "ScreenCapturePickerViewManager.h"
|
|
14
7
|
|
|
15
|
-
NSString*
|
|
8
|
+
NSString *const kRTCScreenSharingExtension = @"RTCScreenSharingExtension";
|
|
16
9
|
|
|
17
10
|
@implementation ScreenCapturePickerViewManager {
|
|
18
11
|
RPSystemBroadcastPickerView *_broadcastPickerView;
|
|
@@ -25,7 +18,7 @@ RCT_EXPORT_MODULE()
|
|
|
25
18
|
_broadcastPickerView.preferredExtension = self.preferredExtension;
|
|
26
19
|
_broadcastPickerView.showsMicrophoneButton = false;
|
|
27
20
|
_broadcastPickerView.userInteractionEnabled = false;
|
|
28
|
-
|
|
21
|
+
|
|
29
22
|
return _broadcastPickerView;
|
|
30
23
|
}
|
|
31
24
|
|
|
@@ -36,33 +29,32 @@ RCT_EXPORT_MODULE()
|
|
|
36
29
|
return infoDictionary[kRTCScreenSharingExtension];
|
|
37
30
|
}
|
|
38
31
|
|
|
39
|
-
RCT_EXPORT_METHOD(show:(nonnull NSNumber *)reactTag) {
|
|
40
|
-
[self.bridge.uiManager
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
32
|
+
RCT_EXPORT_METHOD(show : (nonnull NSNumber *)reactTag) {
|
|
33
|
+
[self.bridge.uiManager
|
|
34
|
+
addUIBlock:^(__unused RCTUIManager *uiManager, NSDictionary<NSNumber *, UIView *> *viewRegistry) {
|
|
35
|
+
id view = viewRegistry[reactTag];
|
|
36
|
+
if (![view isKindOfClass:[RPSystemBroadcastPickerView class]]) {
|
|
37
|
+
RCTLogError(@"Invalid view returned from registry, expecting "
|
|
38
|
+
@"RPSystemBroadcastPickerView, got: %@",
|
|
39
|
+
view);
|
|
40
|
+
} else {
|
|
41
|
+
// Simulate a click
|
|
42
|
+
UIButton *btn = nil;
|
|
43
|
+
|
|
44
|
+
for (UIView *subview in ((RPSystemBroadcastPickerView *)view).subviews) {
|
|
45
|
+
if ([subview isKindOfClass:[UIButton class]]) {
|
|
46
|
+
btn = (UIButton *)subview;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
if (btn != nil) {
|
|
50
|
+
[btn sendActionsForControlEvents:UIControlEventTouchUpInside];
|
|
51
|
+
} else {
|
|
52
|
+
RCTLogError(@"RPSystemBroadcastPickerView button not found");
|
|
54
53
|
}
|
|
55
54
|
}
|
|
56
|
-
|
|
57
|
-
[btn sendActionsForControlEvents:UIControlEventTouchUpInside];
|
|
58
|
-
}
|
|
59
|
-
else {
|
|
60
|
-
RCTLogError(@"RPSystemBroadcastPickerView button not found");
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
}];
|
|
55
|
+
}];
|
|
64
56
|
}
|
|
65
57
|
|
|
66
58
|
@end
|
|
67
59
|
|
|
68
|
-
#endif
|
|
60
|
+
#endif // !TARGET_OS_OSX
|
|
@@ -1,18 +1,14 @@
|
|
|
1
|
-
//
|
|
2
|
-
// ScreenCapturer.h
|
|
3
|
-
// RCTWebRTC
|
|
4
|
-
//
|
|
5
|
-
// Created by Alex-Dan Bumbu on 06/01/2021.
|
|
6
|
-
//
|
|
7
|
-
|
|
8
1
|
#import <AVFoundation/AVFoundation.h>
|
|
9
2
|
#import <WebRTC/RTCVideoCapturer.h>
|
|
3
|
+
#import "CapturerEventsDelegate.h"
|
|
10
4
|
|
|
11
5
|
NS_ASSUME_NONNULL_BEGIN
|
|
12
6
|
|
|
13
7
|
@class SocketConnection;
|
|
14
8
|
|
|
15
|
-
@interface ScreenCapturer: RTCVideoCapturer
|
|
9
|
+
@interface ScreenCapturer : RTCVideoCapturer
|
|
10
|
+
|
|
11
|
+
@property(nonatomic, weak) id<CapturerEventsDelegate> eventsDelegate;
|
|
16
12
|
|
|
17
13
|
- (instancetype)initWithDelegate:(__weak id<RTCVideoCapturerDelegate>)delegate;
|
|
18
14
|
- (void)startCaptureWithConnection:(nonnull SocketConnection *)connection;
|
|
@@ -1,35 +1,28 @@
|
|
|
1
|
-
//
|
|
2
|
-
// ScreenCapturer.m
|
|
3
|
-
// RCTWebRTC
|
|
4
|
-
//
|
|
5
|
-
// Created by Alex-Dan Bumbu on 06/01/2021.
|
|
6
|
-
//
|
|
7
|
-
|
|
8
1
|
#include <mach/mach_time.h>
|
|
9
2
|
|
|
3
|
+
#import <ReplayKit/ReplayKit.h>
|
|
10
4
|
#import <WebRTC/RTCCVPixelBuffer.h>
|
|
11
5
|
#import <WebRTC/RTCVideoFrameBuffer.h>
|
|
12
|
-
#import <ReplayKit/ReplayKit.h>
|
|
13
6
|
|
|
14
7
|
#import "ScreenCapturer.h"
|
|
15
8
|
#import "SocketConnection.h"
|
|
16
9
|
|
|
17
10
|
const NSUInteger kMaxReadLength = 10 * 1024;
|
|
18
11
|
|
|
19
|
-
@interface Message: NSObject
|
|
12
|
+
@interface Message : NSObject
|
|
20
13
|
|
|
21
|
-
@property
|
|
22
|
-
@property
|
|
14
|
+
@property(nonatomic, assign, readonly) CVImageBufferRef imageBuffer;
|
|
15
|
+
@property(nonatomic, copy, nullable) void (^didComplete)(BOOL succes, Message *message);
|
|
23
16
|
|
|
24
|
-
- (NSInteger)appendBytes:
|
|
17
|
+
- (NSInteger)appendBytes:(UInt8 *)buffer length:(NSUInteger)length;
|
|
25
18
|
|
|
26
19
|
@end
|
|
27
20
|
|
|
28
21
|
@interface Message ()
|
|
29
22
|
|
|
30
|
-
@property
|
|
31
|
-
@property
|
|
32
|
-
@property
|
|
23
|
+
@property(nonatomic, assign) CVImageBufferRef imageBuffer;
|
|
24
|
+
@property(nonatomic, assign) int imageOrientation;
|
|
25
|
+
@property(nonatomic, assign) CFHTTPMessageRef framedMessage;
|
|
33
26
|
|
|
34
27
|
@end
|
|
35
28
|
|
|
@@ -40,7 +33,7 @@ const NSUInteger kMaxReadLength = 10 * 1024;
|
|
|
40
33
|
if (self) {
|
|
41
34
|
self.imageBuffer = NULL;
|
|
42
35
|
}
|
|
43
|
-
|
|
36
|
+
|
|
44
37
|
return self;
|
|
45
38
|
}
|
|
46
39
|
|
|
@@ -48,29 +41,32 @@ const NSUInteger kMaxReadLength = 10 * 1024;
|
|
|
48
41
|
CVPixelBufferRelease(_imageBuffer);
|
|
49
42
|
}
|
|
50
43
|
|
|
51
|
-
/** Returns the amount of missing bytes to complete the message, or -1 when not enough bytes were provided to compute
|
|
52
|
-
|
|
44
|
+
/** Returns the amount of missing bytes to complete the message, or -1 when not enough bytes were provided to compute
|
|
45
|
+
* the message length */
|
|
46
|
+
- (NSInteger)appendBytes:(UInt8 *)buffer length:(NSUInteger)length {
|
|
53
47
|
if (!_framedMessage) {
|
|
54
48
|
_framedMessage = CFHTTPMessageCreateEmpty(kCFAllocatorDefault, false);
|
|
55
49
|
}
|
|
56
|
-
|
|
50
|
+
|
|
57
51
|
CFHTTPMessageAppendBytes(_framedMessage, buffer, length);
|
|
58
52
|
if (!CFHTTPMessageIsHeaderComplete(_framedMessage)) {
|
|
59
53
|
return -1;
|
|
60
54
|
}
|
|
61
|
-
|
|
62
|
-
NSInteger contentLength =
|
|
55
|
+
|
|
56
|
+
NSInteger contentLength =
|
|
57
|
+
[CFBridgingRelease(CFHTTPMessageCopyHeaderFieldValue(_framedMessage, (__bridge CFStringRef) @"Content-Length"))
|
|
58
|
+
integerValue];
|
|
63
59
|
NSInteger bodyLength = (NSInteger)[CFBridgingRelease(CFHTTPMessageCopyBody(_framedMessage)) length];
|
|
64
60
|
|
|
65
61
|
NSInteger missingBytesCount = contentLength - bodyLength;
|
|
66
62
|
if (missingBytesCount == 0) {
|
|
67
63
|
BOOL success = [self unwrapMessage:self.framedMessage];
|
|
68
64
|
self.didComplete(success, self);
|
|
69
|
-
|
|
65
|
+
|
|
70
66
|
CFRelease(self.framedMessage);
|
|
71
67
|
self.framedMessage = NULL;
|
|
72
68
|
}
|
|
73
|
-
|
|
69
|
+
|
|
74
70
|
return missingBytesCount;
|
|
75
71
|
}
|
|
76
72
|
|
|
@@ -83,32 +79,38 @@ const NSUInteger kMaxReadLength = 10 * 1024;
|
|
|
83
79
|
dispatch_once(&onceToken, ^{
|
|
84
80
|
imageContext = [[CIContext alloc] initWithOptions:nil];
|
|
85
81
|
});
|
|
86
|
-
|
|
82
|
+
|
|
87
83
|
return imageContext;
|
|
88
84
|
}
|
|
89
85
|
|
|
90
86
|
- (BOOL)unwrapMessage:(CFHTTPMessageRef)framedMessage {
|
|
91
|
-
size_t width =
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
87
|
+
size_t width =
|
|
88
|
+
[CFBridgingRelease(CFHTTPMessageCopyHeaderFieldValue(_framedMessage, (__bridge CFStringRef) @"Buffer-Width"))
|
|
89
|
+
integerValue];
|
|
90
|
+
size_t height =
|
|
91
|
+
[CFBridgingRelease(CFHTTPMessageCopyHeaderFieldValue(_framedMessage, (__bridge CFStringRef) @"Buffer-Height"))
|
|
92
|
+
integerValue];
|
|
93
|
+
_imageOrientation = [CFBridgingRelease(
|
|
94
|
+
CFHTTPMessageCopyHeaderFieldValue(_framedMessage, (__bridge CFStringRef) @"Buffer-Orientation")) intValue];
|
|
95
|
+
|
|
95
96
|
NSData *messageData = CFBridgingRelease(CFHTTPMessageCopyBody(_framedMessage));
|
|
96
|
-
|
|
97
|
+
|
|
97
98
|
// Copy the pixel buffer
|
|
98
|
-
CVReturn status =
|
|
99
|
+
CVReturn status =
|
|
100
|
+
CVPixelBufferCreate(kCFAllocatorDefault, width, height, kCVPixelFormatType_32BGRA, NULL, &_imageBuffer);
|
|
99
101
|
if (status != kCVReturnSuccess) {
|
|
100
102
|
NSLog(@"CVPixelBufferCreate failed");
|
|
101
103
|
return false;
|
|
102
104
|
}
|
|
103
|
-
|
|
105
|
+
|
|
104
106
|
[self copyImageData:messageData toPixelBuffer:&_imageBuffer];
|
|
105
107
|
|
|
106
108
|
return true;
|
|
107
109
|
}
|
|
108
110
|
|
|
109
|
-
- (void)copyImageData:(NSData *)data toPixelBuffer:(CVPixelBufferRef*)pixelBuffer {
|
|
111
|
+
- (void)copyImageData:(NSData *)data toPixelBuffer:(CVPixelBufferRef *)pixelBuffer {
|
|
110
112
|
CVPixelBufferLockBaseAddress(*pixelBuffer, 0);
|
|
111
|
-
|
|
113
|
+
|
|
112
114
|
CIImage *image = [CIImage imageWithData:data];
|
|
113
115
|
[self.imageContext render:image toCVPixelBuffer:*pixelBuffer];
|
|
114
116
|
|
|
@@ -119,10 +121,10 @@ const NSUInteger kMaxReadLength = 10 * 1024;
|
|
|
119
121
|
|
|
120
122
|
// MARK: -
|
|
121
123
|
|
|
122
|
-
@interface ScreenCapturer ()
|
|
124
|
+
@interface ScreenCapturer ()<NSStreamDelegate>
|
|
123
125
|
|
|
124
|
-
@property
|
|
125
|
-
@property
|
|
126
|
+
@property(nonatomic, strong) SocketConnection *connection;
|
|
127
|
+
@property(nonatomic, strong) Message *message;
|
|
126
128
|
|
|
127
129
|
@end
|
|
128
130
|
|
|
@@ -137,7 +139,7 @@ const NSUInteger kMaxReadLength = 10 * 1024;
|
|
|
137
139
|
if (self) {
|
|
138
140
|
mach_timebase_info(&_timebaseInfo);
|
|
139
141
|
}
|
|
140
|
-
|
|
142
|
+
|
|
141
143
|
return self;
|
|
142
144
|
}
|
|
143
145
|
|
|
@@ -150,10 +152,10 @@ const NSUInteger kMaxReadLength = 10 * 1024;
|
|
|
150
152
|
|
|
151
153
|
- (void)startCaptureWithConnection:(SocketConnection *)connection {
|
|
152
154
|
_startTimeStampNs = -1;
|
|
153
|
-
|
|
155
|
+
|
|
154
156
|
self.connection = connection;
|
|
155
157
|
self.message = nil;
|
|
156
|
-
|
|
158
|
+
|
|
157
159
|
[self.connection openWithStreamDelegate:self];
|
|
158
160
|
}
|
|
159
161
|
|
|
@@ -167,46 +169,45 @@ const NSUInteger kMaxReadLength = 10 * 1024;
|
|
|
167
169
|
if (!stream.hasBytesAvailable) {
|
|
168
170
|
return;
|
|
169
171
|
}
|
|
170
|
-
|
|
172
|
+
|
|
171
173
|
if (!self.message) {
|
|
172
174
|
self.message = [[Message alloc] init];
|
|
173
175
|
_readLength = kMaxReadLength;
|
|
174
|
-
|
|
176
|
+
|
|
175
177
|
__weak __typeof__(self) weakSelf = self;
|
|
176
178
|
self.message.didComplete = ^(BOOL success, Message *message) {
|
|
177
179
|
if (success) {
|
|
178
180
|
[weakSelf didCaptureVideoFrame:message.imageBuffer withOrientation:message.imageOrientation];
|
|
179
181
|
}
|
|
180
|
-
|
|
182
|
+
|
|
181
183
|
weakSelf.message = nil;
|
|
182
184
|
};
|
|
183
185
|
}
|
|
184
|
-
|
|
186
|
+
|
|
185
187
|
uint8_t buffer[_readLength];
|
|
186
188
|
NSInteger numberOfBytesRead = [stream read:buffer maxLength:_readLength];
|
|
187
189
|
if (numberOfBytesRead < 0) {
|
|
188
190
|
NSLog(@"error reading bytes from stream");
|
|
189
191
|
return;
|
|
190
192
|
}
|
|
191
|
-
|
|
193
|
+
|
|
192
194
|
_readLength = [self.message appendBytes:buffer length:numberOfBytesRead];
|
|
193
195
|
if (_readLength == -1 || _readLength > kMaxReadLength) {
|
|
194
196
|
_readLength = kMaxReadLength;
|
|
195
197
|
}
|
|
196
198
|
}
|
|
197
199
|
|
|
198
|
-
- (void)didCaptureVideoFrame:(CVPixelBufferRef)pixelBuffer
|
|
199
|
-
withOrientation:(CGImagePropertyOrientation) orientation {
|
|
200
|
+
- (void)didCaptureVideoFrame:(CVPixelBufferRef)pixelBuffer withOrientation:(CGImagePropertyOrientation)orientation {
|
|
200
201
|
int64_t currentTime = mach_absolute_time();
|
|
201
202
|
int64_t currentTimeStampNs = currentTime * _timebaseInfo.numer / _timebaseInfo.denom;
|
|
202
|
-
|
|
203
|
+
|
|
203
204
|
if (_startTimeStampNs < 0) {
|
|
204
205
|
_startTimeStampNs = currentTimeStampNs;
|
|
205
206
|
}
|
|
206
|
-
|
|
207
|
-
RTCCVPixelBuffer *rtcPixelBuffer = [[RTCCVPixelBuffer alloc] initWithPixelBuffer:
|
|
207
|
+
|
|
208
|
+
RTCCVPixelBuffer *rtcPixelBuffer = [[RTCCVPixelBuffer alloc] initWithPixelBuffer:pixelBuffer];
|
|
208
209
|
int64_t frameTimeStampNs = currentTimeStampNs - _startTimeStampNs;
|
|
209
|
-
|
|
210
|
+
|
|
210
211
|
RTCVideoRotation rotation;
|
|
211
212
|
switch (orientation) {
|
|
212
213
|
case kCGImagePropertyOrientationLeft:
|
|
@@ -223,9 +224,9 @@ const NSUInteger kMaxReadLength = 10 * 1024;
|
|
|
223
224
|
break;
|
|
224
225
|
}
|
|
225
226
|
|
|
226
|
-
RTCVideoFrame *videoFrame = [[RTCVideoFrame alloc] initWithBuffer:
|
|
227
|
-
rotation:
|
|
228
|
-
timeStampNs:
|
|
227
|
+
RTCVideoFrame *videoFrame = [[RTCVideoFrame alloc] initWithBuffer:rtcPixelBuffer
|
|
228
|
+
rotation:rotation
|
|
229
|
+
timeStampNs:frameTimeStampNs];
|
|
229
230
|
|
|
230
231
|
[self.delegate capturer:self didCaptureVideoFrame:videoFrame];
|
|
231
232
|
}
|
|
@@ -240,16 +241,17 @@ const NSUInteger kMaxReadLength = 10 * 1024;
|
|
|
240
241
|
NSLog(@"server stream open completed");
|
|
241
242
|
break;
|
|
242
243
|
case NSStreamEventHasBytesAvailable:
|
|
243
|
-
[self readBytesFromStream:
|
|
244
|
+
[self readBytesFromStream:(NSInputStream *)aStream];
|
|
244
245
|
break;
|
|
245
246
|
case NSStreamEventEndEncountered:
|
|
246
247
|
NSLog(@"server stream end encountered");
|
|
247
248
|
[self stopCapture];
|
|
249
|
+
[self.eventsDelegate capturerDidEnd:self];
|
|
248
250
|
break;
|
|
249
251
|
case NSStreamEventErrorOccurred:
|
|
250
252
|
NSLog(@"server stream error encountered: %@", aStream.streamError.localizedDescription);
|
|
251
253
|
break;
|
|
252
|
-
|
|
254
|
+
|
|
253
255
|
default:
|
|
254
256
|
break;
|
|
255
257
|
}
|
|
@@ -6,20 +6,20 @@
|
|
|
6
6
|
|
|
7
7
|
@interface SerializeUtils : NSObject
|
|
8
8
|
|
|
9
|
-
+ (NSString *_Nonnull)transceiverToJSONWithPeerConnectionId:
|
|
10
|
-
|
|
11
|
-
+ (NSDictionary *_Nonnull)senderToJSONWithPeerConnectionId:
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
+ (NSString *_Nonnull)
|
|
18
|
-
+ (
|
|
19
|
-
+ (
|
|
20
|
-
+ (
|
|
21
|
-
|
|
22
|
-
+ (NSDictionary *_Nonnull)streamToJSONWithPeerConnectionId:
|
|
23
|
-
|
|
24
|
-
|
|
9
|
+
+ (NSString *_Nonnull)transceiverToJSONWithPeerConnectionId:(nonnull NSNumber *)id
|
|
10
|
+
transceiver:(RTCRtpTransceiver *_Nonnull)transceiver;
|
|
11
|
+
+ (NSDictionary *_Nonnull)senderToJSONWithPeerConnectionId:(nonnull NSNumber *)id sender:(RTCRtpSender *_Nonnull)sender;
|
|
12
|
+
+ (NSDictionary *_Nonnull)receiverToJSONWithPeerConnectionId:(nonnull NSNumber *)id
|
|
13
|
+
receiver:(RTCRtpReceiver *_Nonnull)receiver;
|
|
14
|
+
+ (NSDictionary *_Nonnull)trackToJSONWithPeerConnectionId:(nonnull NSNumber *)id
|
|
15
|
+
track:(RTCMediaStreamTrack *_Nonnull)track;
|
|
16
|
+
+ (NSString *_Nonnull)serializeDirection:(RTCRtpTransceiverDirection)direction;
|
|
17
|
+
+ (RTCRtpTransceiverDirection)parseDirection:(NSString *_Nonnull)direction;
|
|
18
|
+
+ (RTCRtpTransceiverInit *_Nonnull)parseTransceiverOptions:(NSDictionary *_Nonnull)parameters;
|
|
19
|
+
+ (NSDictionary *_Nonnull)parametersToJSON:(RTCRtpParameters *_Nonnull)parameters;
|
|
20
|
+
+ (NSMutableArray *_Nonnull)constructTransceiversInfoArrayWithPeerConnection:
|
|
21
|
+
(RTCPeerConnection *_Nonnull)peerConnection;
|
|
22
|
+
+ (NSDictionary *_Nonnull)streamToJSONWithPeerConnectionId:(NSNumber *_Nonnull)id
|
|
23
|
+
stream:(RTCMediaStream *_Nonnull)stream
|
|
24
|
+
streamReactTag:(NSString *_Nonnull)streamReactTag;
|
|
25
25
|
@end
|