10000 Fix compilation warning under darwin. · next-coder/flutter-webrtc@05fa74f · GitHub
[go: up one dir, main page]

Skip to content

Commit 05fa74f

Browse files
committed
Fix compilation warning under darwin.
1 parent 59336ff commit 05fa74f

11 files changed

+135
-100
lines changed

android/src/main/java/com/cloudwebrtc/webrtc/PeerConnectionObserver.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,6 @@ void createDataChannel(String label, ConstraintsMap config, Result result) {
101101
if (config.hasKey("ordered")) {
102102
init.ordered = config.getBoolean("ordered");
103103
}
104-
if (config.hasKey("maxRetransmitTime")) {
105-
init.maxRetransmitTimeMs = config.getInt("maxRetransmitTime");
106-
}
107104
if (config.hasKey("maxRetransmits")) {
108105
init.maxRetransmits = config.getInt("maxRetransmits");
109106
}

common/darwin/Classes/FlutterRPScreenRecorder.m

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,26 +22,36 @@ -(void)startCapture
2222
[screenRecorder setMicrophoneEnabled:NO];
2323

2424
if (![screenRecorder isAvailable]) {
25-
NSLog(@"Screen recorder is not available!");
25+
NSLog(@"FlutterRPScreenRecorder.startCapture: Screen recorder is not available!");
2626
return;
2727
}
2828

29-
[screenRecorder startCaptureWithHandler:^(CMSampleBufferRef _Nonnull sampleBuffer, RPSampleBufferType bufferType, NSError * _Nullable error) {
30-
if (bufferType == RPSampleBufferTypeVideo) {// We want video only now
31-
[self handleSourceBuffer:sampleBuffer sampleType:bufferType];
32-
}
33-
} completionHandler:^(NSError * _Nullable error) {
34-
if (error != nil)
35-
NSLog(@"!!! startCaptureWithHandler/completionHandler %@ !!!", error);
36-
}];
29+
if (@available(iOS 11.0, *)) {
30+
[screenRecorder startCaptureWithHandler:^(CMSampleBufferRef _Nonnull sampleBuffer, RPSampleBufferType bufferType, NSError * _Nullable error) {
31+
if (bufferType == RPSampleBufferTypeVideo) {// We want video only now
32+
[self handleSourceBuffer:sampleBuffer sampleType:bufferType];
33+
}
34+
} completionHandler:^(NSError * _Nullable error) {
35+
if (error != nil)
36+
NSLog(@"!!! startCaptureWithHandler/completionHandler %@ !!!", error);
37+
}];
38+
} else {
39+
// Fallback on earlier versions
40+
NSLog(@"FlutterRPScreenRecorder.startCapture: Screen recorder is not available in versions lower than iOS 11 !");
41+
}
3742
}
3843

3944
-(void)stopCapture
4045
{
41-
[screenRecorder stopCaptureWithHandler:^(NSError * _Nullable error) {
42-
if (error != nil)
43-
NSLog(@"!!! stopCaptureWithHandler/completionHandler %@ !!!", error);
44-
}];
46+
if (@available(iOS 11.0, *)) {
47+
[screenRecorder stopCaptureWithHandler:^(NSError * _Nullable error) {
48+
if (error != nil)
49+
NSLog(@"!!! stopCaptureWithHandler/completionHandler %@ !!!", error);
50+
}];
51+
} else {
52+
// Fallback on earlier versions
53+
NSLog(@"FlutterRPScreenRecorder.stopCapture: Screen recorder is not available in versions lower than iOS 11 !");
54+
}
4555
}
4656

4757
-(void)handleSourceBuffer:(CMSampleBufferRef)sampleBuffer sampleType:(RPSampleBufferType)sampleType
@@ -59,7 +69,7 @@ -(void)handleSourceBuffer:(CMSampleBufferRef)sampleBuffer sampleType:(RPSampleBu
5969
size_t width = CVPixelBufferGetWidth(pixelBuffer);
6070
size_t height = CVPixelBufferGetHeight(pixelBuffer);
6171

62-
[source adaptOutputFormatToWidth:width/2 height:height/2 fps:8];
72+
[source adaptOutputFormatToWidth:(int)(width/2) height:(int)(height/2) fps:8];
6373

6474
RTCCVPixelBuffer *rtcPixelBuffer = [[RTCCVPixelBuffer alloc] initWithPixelBuffer:pixelBuffer];
6575
int64_t timeStampNs =

common/darwin/Classes/FlutterRTCDataChannel.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
#import <WebRTC/RTCDataChannel.h>
33

44
@interface RTCDataChannel (Flutter) <FlutterStreamHandler>
5-
@property (nonatomic, strong) NSString *peerConnectionId;
6-
@property (nonatomic, strong) NSNumber *flutterChannelId;
7-
@property (nonatomic, strong) FlutterEventSink eventSink;
8-
@property (nonatomic, strong) FlutterEventChannel* eventChannel;
5+
@property (nonatomic, strong, nonnull) NSString *peerConnectionId;
6+
@property (nonatomic, strong, nonnull) NSNumber *flutterChannelId;
7+
@property (nonatomic, strong, nullable) FlutterEventSink eventSink;
8+
@property (nonatomic, strong, nullable) FlutterEventChannel *eventChannel;
99
@end
1010

1111
@interface FlutterWebRTCPlugin (RTCDataChannel) <RTCDataChannelDelegate>
@@ -14,14 +14,14 @@
1414
-(void)createDataChannel:(nonnull NSString *)peerConnectionId
1515
label:(nonnull NSString *)label
1616
config:(nonnull RTCDataChannelConfiguration *)config
17-
messenger:(NSObject<FlutterBinaryMessenger>*)messenger;
17+
messenger:(nonnull NSObject<FlutterBinaryMessenger> *)messenger;
1818

1919
-(void)dataChannelClose:(nonnull NSString *)peerConnectionId
2020
dataChannelId:(nonnull NSString *)dataChannelId;
2121

2222

2323
-(void)dataChannelSend:(nonnull NSString *)peerConnectionId
24-
dataChannelId:(nonnull NSString *)dataChannelId
24+
dataChannelId:(nonnull NSNumber *)dataChannelId
2525
data:(nonnull NSString *)data
2626
type:(nonnull NSString *)type;
2727

common/darwin/Classes/FlutterRTCDataChannel.m

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ -(void)dataChannelClose:(nonnull NSString *)peerConnectionId
9999
}
100100

101101
-(void)dataChannelSend:(nonnull NSString *)peerConnectionId
102-
dataChannelId:(nonnull NSString *)dataChannelId
102+
dataChannelId:(nonnull NSNumber *)dataChannelId
103103
data:(id)data
104104
type:(NSString *)type
105105
{
@@ -130,7 +130,6 @@ - (NSString *)stringForDataChannelState:(RTCDataChannelState)state
130130
// Called when the data channel state has changed.
131131
- (void)dataChannelDidChangeState:(RTCDataChannel*)channel
132132
{
133-
RTCPeerConnection *peerConnection = self.peerConnections[channel.peerConnectionId];
134133
FlutterEventSink eventSink = channel.eventSink;
135134
if(eventSink) {
136135
eventSink(@{ @"event" : @"dataChannelStateChanged",
@@ -152,7 +151,7 @@ - (void)dataChannel:(RTCDataChannel *)channel didReceiveMessageWithBuffer:(RTCDa
152151
data = [[NSString alloc] initWithData:buffer.data
153152
encoding:NSUTF8StringEncoding];
154153
}
155-
RTCPeerConnection *peerConnection = self.peerConnections[channel.peerConnectionId];
154+
156155
FlutterEventSink eventSink = channel.eventSink;
157156
if(eventSink) {
158157
eventSink(@{ @"event" : @"dataChannelReceiveMessage",

common/darwin/Classes/FlutterRTCMediaStream.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55

66
-(void)getUserMedia:(NSDictionary *)constraints
77
result:(FlutterResult)result;
8-
8+
#if TARGET_OS_IPHONE
99
-(void)getDisplayMedia:(NSDictionary *)constraints
1010
result:(FlutterResult)result;
11-
11+
#endif
1212
-(void)createLocalMediaStream:(FlutterResult)result;
1313

1414
-(void)getSources:(FlutterResult)result;

common/darwin/Classes/FlutterRTCMediaStream.m

Lines changed: 61 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -369,40 +369,66 @@ - (void)requestAccessForMediaType:(NSString *)mediaType
369369
});
370370
return;
371371
}
372-
373-
[AVCaptureDevice
374-
requestAccessForMediaType:mediaType
375-
completionHandler:^ (BOOL granted) {
376-
dispatch_async(dispatch_get_main_queue(), ^ {
377-
if (granted) {
378-
NavigatorUserMediaSuccessCallback scb
379-
= ^ (RTCMediaStream *mediaStream) {
380-
[self getUserMedia:constraints
381-
successCallback:successCallback
382-
errorCallback:errorCallback
383-
mediaStream:mediaStream];
384-
};
385-
386-
if (mediaType == AVMediaTypeAudio) {
387-
[self getUserAudio:constraints
388-
successCallback:scb
389-
errorCallback:errorCallback
390-
mediaStream:mediaStream];
391-
} else if (mediaType == AVMediaTypeVideo) {
392-
[self getUserVideo:constraints
393-
successCallback:scb
394-
errorCallback:errorCallback
395-
mediaStream:mediaStream];
396-
}
397-
} else {
398-
// According to step 10 Permission Failure of the getUserMedia()
399-
// algorithm, if the user has denied permission, fail "with a new
400-
// DOMException object whose name attribute has the value
401-
// NotAllowedError."
402-
errorCallback(@"DOMException", @"NotAllowedError");
403-
}
404-
});
405-
}];
372+
373+
#if TARGET_OS_OSX
374+
if (@available(macOS 10.14, *)) {
375+
#endif
376+
[AVCaptureDevice
377+
requestAccessForMediaType:mediaType
378+
completionHandler:^ (BOOL granted) {
379+
dispatch_async(dispatch_get_main_queue(), ^ {
380+
if (granted) {
381+
NavigatorUserMediaSuccessCallback scb
382+
= ^ (RTCMediaStream *mediaStream) {
383+
[self getUserMedia:constraints
384+
successCallback:successCallback
385+
errorCallback:errorCallback
386+
mediaStream:mediaStream];
387+
};
388+
389+
if (mediaType == AVMediaTypeAudio) {
390+
[self getUserAudio:c 10000 onstraints
391+
successCallback:scb
392+
errorCallback:errorCallback
393+
mediaStream:mediaStream];
394+
} else if (mediaType == AVMediaTypeVideo) {
395+
[self getUserVideo:constraints
396+
successCallback:scb
397+
errorCallback:errorCallback
398+
mediaStream:mediaStream];
399+
}
400+
} else {
401+
// According to step 10 Permission Failure of the getUserMedia()
402+
// algorithm, if the user has denied permission, fail "with a new
403+
// DOMException object whose name attribute has the value
404+
// NotAllowedError."
405+
errorCallback(@"DOMException", @"NotAllowedError");
406+
}
407+
});
408+
}];
409+
#if TARGET_OS_OSX
410+
} else {
411+
// Fallback on earlier versions
412+
NavigatorUserMediaSuccessCallback scb
413+
= ^ (RTCMediaStream *mediaStream) {
414+
[self getUserMedia:constraints
415+
successCallback:successCallback
416+
errorCallback:errorCallback
417+
mediaStream:mediaStream];
418+
};
419+
if (mediaType == AVMediaTypeAudio) {
420+
[self getUserAudio:constraints
421+
successCallback:scb
422+
errorCallback:errorCallback
423+
mediaStream:mediaStream];
424+
} else if (mediaType == AVMediaTypeVideo) {
425+
[self getUserVideo:constraints
426+
successCallback:scb
427+
errorCallback:errorCallback
428+
mediaStream:mediaStream];
429+
}
430+
}
431+
#endif
406432
}
407433

408434
#if TARGET_OS_IPHONE
@@ -563,7 +589,7 @@ -(void)mediaStreamTrackCaptureFrame:(RTCVideoTrack *)track toPath:(NSString *) p
563589
return;
564590
}
565591

566-
FlutterRTCFrameCapturer *capturer = [[FlutterRTCFrameCapturer alloc] initWithTrack:track toPath:path result:result];
592+
self.frameCapturer = [[FlutterRTCFrameCapturer alloc] initWithTrack:track toPath:path result:result];
567593
}
568594

569595
-(void)mediaStreamTrackStop:(RTCMediaStreamTrack *)track
Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,43 @@
11
#import "FlutterWebRTCPlugin.h"
22

33
@interface RTCPeerConnection (Flutter) <FlutterStreamHandler>
4-
@property (nonatomic, strong) NSMutableDictionary<NSString *, RTCDataChannel *> *dataChannels;
5-
@property (nonatomic, strong) NSMutableDictionary<NSString *, RTCMediaStream *> *remoteStreams;
6-
@property (nonatomic, strong) NSMutableDictionary<NSString *, RTCMediaStreamTrack *> *remoteTracks;
7-
@property (nonatomic, strong) NSString *flutterId;
8-
@property (nonatomic, strong) FlutterEventSink eventSink;
9-
@property (nonatomic, strong) FlutterEventChannel* eventChannel;
4+
@property (nonatomic, strong, nonnull) NSMutableDictionary<NSNumber *, RTCDataChannel *> *dataChannels;
5+
@property (nonatomic, strong, nonnull) NSMutableDictionary<NSString *, RTCMediaStream *> *remoteStreams;
6+
@property (nonatomic, strong, nonnull) NSMutableDictionary<NSString *, RTCMediaStreamTrack *> *remoteTracks;
7+
@property (nonatomic, strong, nonnull) NSString *flutterId;
8+
@property (nonatomic, strong, nullable) FlutterEventSink eventSink;
9+
@property (nonatomic, strong, nullable) FlutterEventChannel* eventChannel;
1010
@end
1111

1212
@interface FlutterWebRTCPlugin (RTCPeerConnection)
1313

14-
-(void) peerConnectionCreateOffer:(NSDictionary *)constraints
15-
peerConnection:(RTCPeerConnection*)peerConnection
16-
result:(FlutterResult)result;
14+
-(void) peerConnectionCreateOffer:(nonnull NSDictionary *)constraints
15+
peerConnection:(nonnull RTCPeerConnection*)peerConnection
16+
result:(nonnull FlutterResult)result;
1717

18-
-(void) peerConnectionCreateAnswer:(NSDictionary *)constraints
19-
peerConnection:(RTCPeerConnection *)peerConnection
20-
result:(FlutterResult)result;
18+
-(void) peerConnectionCreateAnswer:(nonnull NSDictionary *)constraints
19+
peerConnection:(nonnull RTCPeerConnection *)peerConnection
20+
result:(nonnull FlutterResult)result;
2121

22-
-(void) peerConnectionSetLocalDescription:(RTCSessionDescription *)sdp
23-
peerConnection:(RTCPeerConnection *)peerConnection
24-
result:(FlutterResult)result;
22+
-(void) peerConnectionSetLocalDescription:(nonnull RTCSessionDescription *)sdp
23+
peerConnection:(nonnull RTCPeerConnection *)peerConnection
24+
result:(nonnull FlutterResult)result;
2525

26-
-(void) peerConnectionSetRemoteDescription:(RTCSessionDescription *)sdp
27-
peerConnection:(RTCPeerConnection *)peerConnection
28-
result:(FlutterResult)result;
26+
-(void) peerConnectionSetRemoteDescription:(nonnull RTCSessionDescription *)sdp
27+
peerConnection:(nonnull RTCPeerConnection *)peerConnection
28+
result:(nonnull FlutterResult)result;
2929

30-
-(void) peerConnectionAddICECandidate:(RTCIceCandidate*)candidate
31-
peerConnection:(RTCPeerConnection *)peerConnection
32-
result:(FlutterResult)result;
30+
-(void) peerConnectionAddICECandidate:(nonnull RTCIceCandidate*)candidate
31+
peerConnection:(nonnull RTCPeerConnection *)peerConnection
32+
result:(nonnull FlutterResult)result;
3333

3434
-(void) peerConnectionGetStats:(nonnull NSString *)trackID
3535
peerConnection:(nonnull RTCPeerConnection *)peerConnection
3636
result:(nonnull FlutterResult)result;
3737

38-
-(RTCMediaConstraints *) parseMediaConstraints:(nonnull NSDictionary *)constraints;
38+
-(nonnull RTCMediaConstraints *) parseMediaConstraints:(nonnull NSDictionary *)constraints;
3939

40-
-(void) peerConnectionSetConfiguration:(RTCConfiguration*)configuration
41-
peerConnection:(RTCPeerConnection*)peerConnection;
40+
-(void) peerConnectionSetConfiguration:(nonnull RTCConfiguration*)configuration
41+
peerConnection:(nonnull RTCPeerConnection*)peerConnection;
4242

4343
@end

common/darwin/Classes/FlutterRTCPeerConnection.m

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ - (void)setEventChannel:(FlutterEventChannel *)eventChannel
3939
objc_setAssociatedObject(self, @selector(eventChannel), eventChannel, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
4040
}
4141

42-
- (NSMutableDictionary<NSString *, RTCDataChannel *> *)dataChannels
42+
- (NSMutableDictionary<NSNumber *, RTCDataChannel *> *)dataChannels
4343
{
4444
return objc_getAssociatedObject(self, _cmd);
4545
}
@@ -176,9 +176,9 @@ -(void) peerConnectionClose:(RTCPeerConnection *)peerConnection
176176
[peerConnection.remoteTracks removeAllObjects];
177177

178178
// Clean up peerConnection's dataChannels.
179-
NSMutableDictionary<NSString *, RTCDataChannel *> *dataChannels
179+
NSMutableDictionary<NSNumber *, RTCDataChannel *> *dataChannels
180180
= peerConnection.dataChannels;
181-
for (NSString *dataChannelId in dataChannels) {
181+
for (NSNumber *dataChannelId in dataChannels) {
182182
dataChannels[dataChannelId].delegate = nil;
183183
// There is no need to close the RTCDataChannel because it is owned by the
184184
// RTCPeerConnection and the latter will close the former.
@@ -328,7 +328,8 @@ - (RTCMediaConstraints *)parseMediaConstraints:(NSDictionary *)constraints {
328328
}
329329

330330
#pragma mark - RTCPeerConnectionDelegate methods
331-
331+
#pragma clang diagnostic push
332+
#pragma clang diagnostic ignored "-Wobjc-protocol-method-implementation"
332333
- (void)peerConnection:(RTCPeerConnection *)peerConnection didChangeSignalingState:(RTCSignalingState)newState {
333334
FlutterEventSink eventSink = peerConnection.eventSink;
334335
if(eventSink){

common/darwin/Classes/FlutterWebRTCPlugin.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#import <WebRTC/WebRTC.h>
99

1010
@class FlutterRTCVideoRenderer;
11+
@class FlutterRTCFrameCapturer;
1112

1213
@interface FlutterWebRTCPlugin : NSObject<FlutterPlugin, RTCPeerConnectionDelegate>
1314

@@ -21,6 +22,7 @@
2122
#endif
2223
@property (nonatomic, strong) NSObject<FlutterBinaryMessenger>* messenger;
2324
@property (nonatomic, strong) RTCCameraVideoCapturer *videoCapturer;
25+
@property (nonatomic, strong) FlutterRTCFrameCapturer *frameCapturer;
2426
@property (nonatomic) BOOL _usingFrontCamera;
2527
@property (nonatomic) int _targetWidth;
2628
@property (nonatomic) int _targetHeight;

0 commit comments

Comments
 (0)
0