-
Notifications
You must be signed in to change notification settings - Fork 3.6k
[video_player_avfoundation, camera_avfoundation] never overwrite but only upgrade audio session category #7143
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
787f41c
ef43db2
94a80df
f637396
86922ac
6746391
42bd00a
fde86f6
2f876dd
4ddc291
81a9449
4dd42c1
e02355c
6569354
1086400
9edbeef
6216653
59a7fab
8f013b6
acaad4c
3d4e638
948937e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -183,6 +183,8 @@ - (instancetype)initWithMediaSettings:(FCPPlatformMediaSettings *)mediaSettings | |
| _videoFormat = kCVPixelFormatType_32BGRA; | ||
| _inProgressSavePhotoDelegates = [NSMutableDictionary dictionary]; | ||
| _fileFormat = FCPPlatformImageFileFormatJpeg; | ||
| _videoCaptureSession.automaticallyConfiguresApplicationAudioSession = NO; | ||
| _audioCaptureSession.automaticallyConfiguresApplicationAudioSession = NO; | ||
|
|
||
| // To limit memory consumption, limit the number of frames pending processing. | ||
| // After some testing, 4 was determined to be the best maximum value. | ||
|
|
@@ -673,7 +675,8 @@ - (void)captureOutput:(AVCaptureOutput *)output | |
| [_videoWriter startWriting]; | ||
| [_videoWriter startSessionAtSourceTime:currentSampleTime]; | ||
| // fix sample times not being numeric when pause/resume happens before first sample buffer | ||
| // arrives https://github.com/flutter/flutter/issues/132014 | ||
| // arrives | ||
| // https://github.com/flutter/flutter/issues/132014 | ||
| _lastVideoSampleTime = currentSampleTime; | ||
| _lastAudioSampleTime = currentSampleTime; | ||
| } | ||
|
|
@@ -1220,9 +1223,7 @@ - (BOOL)setupWriterForPath:(NSString *)path { | |
| return NO; | ||
| } | ||
|
|
||
| if (_mediaSettings.enableAudio && !_isAudioSetup) { | ||
| [self setUpCaptureSessionForAudio]; | ||
| } | ||
| [self setUpCaptureSessionForAudio]; | ||
|
||
|
|
||
| _videoWriter = [[AVAssetWriter alloc] initWithURL:outputURL | ||
| fileType:AVFileTypeMPEG4 | ||
|
|
@@ -1302,9 +1303,47 @@ - (BOOL)setupWriterForPath:(NSString *)path { | |
| return YES; | ||
| } | ||
|
|
||
| // configure application wide audio session manually to prevent overwriting | ||
| // flag MixWithOthers by capture session, only change category if it is considered | ||
| // as upgrade which means it can only enable ability to play in silent mode or | ||
|
||
| // ability to record audio but never disables it, that could affect other plugins | ||
|
||
| // which depend on this global state, only change category or options if there is | ||
| // change to prevent unnecessary route changes which can cause lags | ||
|
||
| // https://github.com/flutter/flutter/issues/131553 | ||
|
||
| static void upgradeAudioSessionCategory(AVAudioSessionCategory category, | ||
| AVAudioSessionCategoryOptions options, | ||
| AVAudioSessionCategoryOptions clearOptions) { | ||
| if (!NSThread.isMainThread) { | ||
| dispatch_sync(dispatch_get_main_queue(), ^{ | ||
| upgradeAudioSessionCategory(category, options, clearOptions); | ||
|
||
| }); | ||
| return; | ||
| } | ||
| NSSet *playCategories = [NSSet | ||
| setWithObjects:AVAudioSessionCategoryPlayback, AVAudioSessionCategoryPlayAndRecord, nil]; | ||
| NSSet *recordCategories = | ||
| [NSSet setWithObjects:AVAudioSessionCategoryRecord, AVAudioSessionCategoryPlayAndRecord, nil]; | ||
| NSSet *categories = [NSSet setWithObjects:category, AVAudioSession.sharedInstance.category, nil]; | ||
|
||
| BOOL needPlay = [categories intersectsSet:playCategories]; | ||
| BOOL needRecord = [categories intersectsSet:recordCategories]; | ||
| if (needPlay && needRecord) { | ||
| category = AVAudioSessionCategoryPlayAndRecord; | ||
| } else if (needPlay) { | ||
| category = AVAudioSessionCategoryPlayback; | ||
| } else if (needRecord) { | ||
| category = AVAudioSessionCategoryRecord; | ||
| } | ||
| options = (AVAudioSession.sharedInstance.categoryOptions & ~clearOptions) | options; | ||
| if ([category isEqualToString:AVAudioSession.sharedInstance.category] && | ||
| options == AVAudioSession.sharedInstance.categoryOptions) { | ||
| return; | ||
| } | ||
| [AVAudioSession.sharedInstance setCategory:category withOptions:options error:nil]; | ||
| } | ||
|
|
||
| - (void)setUpCaptureSessionForAudio { | ||
| // Don't setup audio twice or we will lose the audio. | ||
| if (_isAudioSetup) { | ||
| if (!_mediaSettings.enableAudio || _isAudioSetup) { | ||
| return; | ||
| } | ||
|
|
||
|
|
@@ -1320,6 +1359,9 @@ - (void)setUpCaptureSessionForAudio { | |
| // Setup the audio output. | ||
| _audioOutput = [[AVCaptureAudioDataOutput alloc] init]; | ||
|
|
||
| upgradeAudioSessionCategory(AVAudioSessionCategoryPlayAndRecord, | ||
| AVAudioSessionCategoryOptionDefaultToSpeaker, 0); | ||
|
|
||
| if ([_audioCaptureSession canAddInput:audioInput]) { | ||
| [_audioCaptureSession addInput:audioInput]; | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,7 @@ | ||
| ## 2.6.2 | ||
|
|
||
| * Fixes audio recorded only with first recording. | ||
|
||
|
|
||
| ## 2.6.1 | ||
|
|
||
| * Adds files to make include directory permanent. | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.