@@ -28,17 +28,11 @@ @interface FLTCam () <AVCaptureVideoDataOutputSampleBufferDelegate,
28
28
@property (strong , nonatomic )
29
29
NSObject <FLTAssetWriterInputPixelBufferAdaptor> *assetWriterPixelBufferAdaptor;
30
30
@property (strong , nonatomic ) AVCaptureVideoDataOutput *videoOutput;
31
- @property (assign , nonatomic ) BOOL isAudioSetup;
32
31
33
32
// / A wrapper for CMVideoFormatDescriptionGetDimensions.
34
33
// / Allows for alternate implementations in tests.
35
34
@property (nonatomic , copy ) VideoDimensionsForFormat videoDimensionsForFormat;
36
- // / A wrapper for AVCaptureDevice creation to allow for dependency injection in tests.
37
- @property (nonatomic , copy ) AudioCaptureDeviceFactory audioCaptureDeviceFactory;
38
- // / Reports the given error message to the Dart side of the plugin.
39
- // /
40
- // / Can be called from any thread.
41
- - (void )reportErrorMessage : (NSString *)errorMessage ;
35
+
42
36
@end
43
37
44
38
@implementation FLTCam
@@ -308,92 +302,4 @@ - (BOOL)setCaptureSessionPreset:(FCPPlatformResolutionPreset)resolutionPreset
308
302
return bestFormat;
309
303
}
310
304
311
- // This function, although slightly modified, is also in video_player_avfoundation.
312
- // Both need to do the same thing and run on the same thread (for example main thread).
313
- // Configure application wide audio session manually to prevent overwriting flag
314
- // MixWithOthers by capture session.
315
- // Only change category if it is considered an upgrade which means it can only enable
316
- // ability to play in silent mode or ability to record audio but never disables it,
317
- // that could affect other plugins which depend on this global state. Only change
318
- // category or options if there is change to prevent unnecessary lags and silence.
319
- static void upgradeAudioSessionCategory (AVAudioSessionCategory requestedCategory,
320
- AVAudioSessionCategoryOptions options) {
321
- NSSet *playCategories = [NSSet
322
- setWithObjects: AVAudioSessionCategoryPlayback, AVAudioSessionCategoryPlayAndRecord, nil ];
323
- NSSet *recordCategories =
324
- [NSSet setWithObjects: AVAudioSessionCategoryRecord, AVAudioSessionCategoryPlayAndRecord, nil ];
325
- NSSet *requiredCategories =
326
- [NSSet setWithObjects: requestedCategory, AVAudioSession.sharedInstance.category, nil ];
327
- BOOL requiresPlay = [requiredCategories intersectsSet: playCategories];
328
- BOOL requiresRecord = [requiredCategories intersectsSet: recordCategories];
329
- if (requiresPlay && requiresRecord) {
330
- requestedCategory = AVAudioSessionCategoryPlayAndRecord;
331
- } else if (requiresPlay) {
332
- requestedCategory = AVAudioSessionCategoryPlayback;
333
- } else if (requiresRecord) {
334
- requestedCategory = AVAudioSessionCategoryRecord;
335
- }
336
- options = AVAudioSession.sharedInstance .categoryOptions | options;
337
- if ([requestedCategory isEqualToString: AVAudioSession.sharedInstance.category] &&
338
- options == AVAudioSession.sharedInstance .categoryOptions ) {
339
- return ;
340
- }
341
- [AVAudioSession.sharedInstance setCategory: requestedCategory withOptions: options error: nil ];
342
- }
343
-
344
- - (void )setUpCaptureSessionForAudioIfNeeded {
345
- // Don't setup audio twice or we will lose the audio.
346
- if (!_mediaSettings.enableAudio || _isAudioSetup) {
347
- return ;
348
- }
349
-
350
- NSError *error = nil ;
351
- // Create a device input with the device and add it to the session.
352
- // Setup the audio input.
353
- NSObject <FLTCaptureDevice> *audioDevice = self.audioCaptureDeviceFactory ();
354
- NSObject <FLTCaptureInput> *audioInput =
355
- [_captureDeviceInputFactory deviceInputWithDevice: audioDevice error: &error];
356
- if (error) {
357
- [self reportErrorMessage: error.description];
358
- }
359
- // Setup the audio output.
360
- _audioOutput = [[AVCaptureAudioDataOutput alloc ] init ];
361
-
362
- dispatch_block_t block = ^{
363
- // Set up options implicit to AVAudioSessionCategoryPlayback to avoid conflicts with other
364
- // plugins like video_player.
365
- upgradeAudioSessionCategory (AVAudioSessionCategoryPlayAndRecord,
366
- AVAudioSessionCategoryOptionDefaultToSpeaker |
367
- AVAudioSessionCategoryOptionAllowBluetoothA2DP |
368
- AVAudioSessionCategoryOptionAllowAirPlay);
369
- };
370
- if (!NSThread .isMainThread ) {
371
- dispatch_sync (dispatch_get_main_queue (), block);
372
- } else {
373
- block ();
374
- }
375
-
376
- if ([_audioCaptureSession canAddInput: audioInput]) {
377
- [_audioCaptureSession addInput: audioInput];
378
-
379
- if ([_audioCaptureSession canAddOutput: _audioOutput]) {
380
- [_audioCaptureSession addOutput: _audioOutput];
381
- _isAudioSetup = YES ;
382
- } else {
383
- [self reportErrorMessage: @" Unable to add Audio input/output to session capture" ];
384
- _isAudioSetup = NO ;
385
- }
386
- }
387
- }
388
-
389
- - (void )reportErrorMessage : (NSString *)errorMessage {
390
- __weak typeof (self) weakSelf = self;
391
- FLTEnsureToRunOnMainQueue (^{
392
- [weakSelf.dartAPI reportError: errorMessage
393
- completion: ^(FlutterError *error){
394
- // Ignore any errors, as this is just an event broadcast.
395
- }];
396
- });
397
- }
398
-
399
305
@end
0 commit comments