5
5
#import " FlutterRTCFrameCapturer.h"
6
6
#import " FlutterRTCMediaStream.h"
7
7
#import " FlutterRTCPeerConnection.h"
8
+ #import " AudioUtils.h"
8
9
9
10
#if TARGET_OS_IPHONE
10
11
#import " FlutterRPScreenRecorder.h"
@@ -71,9 +72,12 @@ - (void)getUserAudio:(NSDictionary *)constraints
71
72
NSString *trackId = [[NSUUID UUID ] UUIDString ];
72
73
RTCAudioTrack *audioTrack
73
74
= [self .peerConnectionFactory audioTrackWithTrackId: trackId];
74
-
75
+
75
76
[mediaStream addAudioTrack: audioTrack];
76
-
77
+
78
+ // allow audio capture
79
+ [AudioUtils ensureAudioSessionWithRecording: YES ];
80
+
77
81
successCallback (mediaStream);
78
82
}
79
83
@@ -88,20 +92,20 @@ -(void)getUserMedia:(NSDictionary *)constraints
88
92
NSString *mediaStreamId = [[NSUUID UUID ] UUIDString ];
89
93
RTCMediaStream *mediaStream
90
94
= [self .peerConnectionFactory mediaStreamWithStreamId: mediaStreamId];
91
-
95
+
92
96
[self
93
97
getUserMedia: constraints
94
98
successCallback: ^ (RTCMediaStream *mediaStream) {
95
99
NSString *mediaStreamId = mediaStream.streamId ;
96
-
100
+
97
101
NSMutableArray *audioTracks = [NSMutableArray array ];
98
102
NSMutableArray *videoTracks = [NSMutableArray array ];
99
-
103
+
100
104
for (RTCAudioTrack *track in mediaStream.audioTracks ) {
101
105
[self .localTracks setObject: track forKey: track.trackId];
102
106
[audioTracks addObject: @{@" id" : track.trackId , @" kind" : track.kind , @" label" : track.trackId , @" enabled" : @(track.isEnabled ), @" remote" : @(YES ), @" readyState" : @" live" }];
103
107
}
104
-
108
+
105
109
for (RTCVideoTrack *track in mediaStream.videoTracks ) {
106
110
[self .localTracks setObject: track forKey: track.trackId];
107
111
[videoTracks addObject: @{@" id" : track.trackId , @" kind" : track.kind , @" label" : track.trackId , @" enabled" : @(track.isEnabled ), @" remote" : @(YES ), @" readyState" : @" live" }];
@@ -161,7 +165,7 @@ - (void)getUserMedia:(NSDictionary *)constraints
161
165
return ;
162
166
}
163
167
}
164
-
168
+
165
169
// If mediaStream contains no videoTracks and the constraints request such a
166
170
// track, then run an iteration of the getUserMedia() algorithm to obtain
167
171
// local video content.
@@ -185,7 +189,7 @@ - (void)getUserMedia:(NSDictionary *)constraints
185
189
#endif
186
190
}
187
191
}
188
-
192
+
189
193
// There are audioTracks and/or videoTracks in mediaStream as requested by
190
194
// constraints so the getUserMedia() is to conclude with success.
191
195
successCallback (mediaStream);
@@ -258,17 +262,17 @@ - (void)getUserVideo:(NSDictionary *)constraints
258
262
videoDevice = [AVCaptureDevice defaultDeviceWithMediaType: AVMediaTypeVideo];
259
263
}
260
264
}
261
-
265
+
262
266
// TODO(rostopira): refactor to separate function and add support for max
263
267
264
268
self._targetWidth = 1280 ;
265
269
self._targetHeight = 720 ;
266
270
self._targetFps = 30 ;
267
-
271
+
268
272
if (!videoDevice && [constraints[@" video" ] boolValue ] == YES ) {
269
273
videoDevice = [AVCaptureDevice defaultDeviceWithMediaType: AVMediaTypeVideo];
270
274
}
271
-
275
+
272
276
id mandatory = [videoConstraints isKindOfClass: [NSDictionary class ]]? videoConstraints[@" mandatory" ] : nil ;
273
277
274
278
// constraints.video.mandatory
@@ -296,7 +300,7 @@ - (void)getUserVideo:(NSDictionary *)constraints
296
300
}
297
301
}
298
302
}
299
-
303
+
300
304
if (videoDevice) {
301
305
RTCVideoSource *videoSource = [self .peerConnectionFactory videoSource ];
302
306
if (self.videoCapturer ) {
@@ -310,11 +314,11 @@ - (void)getUserVideo:(NSDictionary *)constraints
310
314
NSLog (@" Start capture error: %@ " , [error localizedDescription ]);
311
315
}
312
316
}];
313
-
317
+
314
318
NSString *trackUUID = [[NSUUID UUID ] UUIDString ];
315
319
RTCVideoTrack *videoTrack = [self .peerConnectionFactory videoTrackWithSource: videoSource trackId: trackUUID];
316
320
[mediaStream addVideoTrack: videoTrack];
317
-
321
+
318
322
successCallback (mediaStream);
319
323
} else {
320
324
// According to step 6.2.3 of the getUserMedia() algorithm, if there is no
@@ -390,7 +394,7 @@ - (void)requestAccessForMediaType:(NSString *)mediaType
390
394
errorCallback: errorCallback
391
395
mediaStream: mediaStream];
392
396
};
393
-
397
+
394
398
if (mediaType == AVMediaTypeAudio) {
395
399
[self getUserAudio: constraints
396
400
successCallback: scb
@@ -441,27 +445,27 @@ -(void)getDisplayMedia:(NSDictionary *)constraints
441
445
result:(FlutterResult)result {
442
446
NSString *mediaStreamId = [[NSUUID UUID ] UUIDString ];
443
447
RTCMediaStream *mediaStream = [self .peerConnectionFactory mediaStreamWithStreamId: mediaStreamId];
444
-
448
+
445
449
RTCVideoSource *videoSource = [self .peerConnectionFactory videoSource ];
446
450
FlutterRPScreenRecorder *screenCapturer = [[FlutterRPScreenRecorder alloc ] initWithDelegate: videoSource];
447
451
448
452
[screenCapturer startCapture ];
449
-
453
+
450
454
// TODO:
451
455
self.videoCapturer = screenCapturer;
452
-
456
+
453
457
NSString *trackUUID = [[NSUUID UUID ] UUIDString ];
454
458
RTCVideoTrack *videoTrack = [self .peerConnectionFactory videoTrackWithSource: videoSource trackId: trackUUID];
455
459
[mediaStream addVideoTrack: videoTrack];
456
-
460
+
457
461
NSMutableArray *audioTracks = [NSMutableArray array ];
458
462
NSMutableArray *videoTracks = [NSMutableArray array ];
459
463
460
464
for (RTCVideoTrack *track in mediaStream.videoTracks ) {
461
465
[self .localTracks setObject: track forKey: track.trackId];
462
466
[videoTracks addObject: @{@" id" : track.trackId , @" kind" : track.kind , @" label" : track.trackId , @" enabled" : @(track.isEnabled ), @" remote" : @(YES ), @" readyState" : @" live" }];
463
467
}
464
-
468
+
465
469
self.localStreams [mediaStreamId] = mediaStream;
466
470
result (@{@" streamId" : mediaStreamId, @" audioTracks" : audioTracks, @" videoTracks" : videoTracks });
467
471
}
0 commit comments