Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
remove nil check and rename variables and arguments
  • Loading branch information
misos1 committed Sep 6, 2024
commit 4ddc2917b3b47d0c83f402a4d8aad199d1bc67b8
Original file line number Diff line number Diff line change
Expand Up @@ -1322,32 +1322,28 @@ - (BOOL)setupWriterForPath:(NSString *)path {
// which depend on this global state, only change category or options if there is
// change to prevent unnecessary lags and silence
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not clear to me how this last part is different from what the comment already said so far (possibly because the sentence is a run-on by this point so it's hard to follow). Please reword to clarify if this is supposed to be adding new details.

// https://github.com/flutter/flutter/issues/131553
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't need an issue link; we generally only link to issues for TODOs, or cases that are not understandable from a comment (e.g., very subtle edge cases). The idea of only upgrading global mode is clear enough.

static void upgradeAudioSessionCategory(AVAudioSessionCategory category,
AVAudioSessionCategoryOptions options,
AVAudioSessionCategoryOptions clearOptions) {
if (category == nil) {
category = AVAudioSession.sharedInstance.category;
}
static void upgradeAudioSessionCategory(AVAudioSessionCategory requestedCategory,
AVAudioSessionCategoryOptions options) {
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];
NSSet *requiredCategories = [NSSet setWithObjects:requestedCategory, AVAudioSession.sharedInstance.category, nil];
BOOL needPlay = [requiredCategories intersectsSet:playCategories];
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: requiresPlay, requiresRecord (rather than introduce a second term that means the same thing within the same method).

BOOL needRecord = [requiredCategories intersectsSet:recordCategories];
if (needPlay && needRecord) {
category = AVAudioSessionCategoryPlayAndRecord;
requestedCategory = AVAudioSessionCategoryPlayAndRecord;
} else if (needPlay) {
category = AVAudioSessionCategoryPlayback;
requestedCategory = AVAudioSessionCategoryPlayback;
} else if (needRecord) {
category = AVAudioSessionCategoryRecord;
requestedCategory = AVAudioSessionCategoryRecord;
}
options = (AVAudioSession.sharedInstance.categoryOptions & ~clearOptions) | options;
if ([category isEqualToString:AVAudioSession.sharedInstance.category] &&
options = AVAudioSession.sharedInstance.categoryOptions | options;
if ([requestedCategory isEqualToString:AVAudioSession.sharedInstance.category] &&
options == AVAudioSession.sharedInstance.categoryOptions) {
return;
}
[AVAudioSession.sharedInstance setCategory:category withOptions:options error:nil];
[AVAudioSession.sharedInstance setCategory:requestedCategory withOptions:options error:nil];
}

- (void)setUpCaptureSessionForAudioIfNeeded {
Expand All @@ -1369,11 +1365,11 @@ - (void)setUpCaptureSessionForAudioIfNeeded {
_audioOutput = [[AVCaptureAudioDataOutput alloc] init];

dispatch_block_t block = ^{
// Setup options implicit to AVAudioSessionCategoryPlayback to not disturb video_player.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment doesn't make sense to me in this context; this call is primarily about making a change, not not making a change. The comment on the function itself covers this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is to explain why there are such options: #7143 (comment)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on the function does not cover this.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about Upgrade options requested by camera without conflicting other plugins like video_player.

upgradeAudioSessionCategory(AVAudioSessionCategoryPlayAndRecord,
AVAudioSessionCategoryOptionDefaultToSpeaker |
AVAudioSessionCategoryOptionAllowBluetoothA2DP |
AVAudioSessionCategoryOptionAllowAirPlay,
0);
AVAudioSessionCategoryOptionAllowAirPlay);
};
if (!NSThread.isMainThread) {
dispatch_sync(dispatch_get_main_queue(), block);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -822,32 +822,29 @@ - (void)pausePlayer:(NSInteger)textureId error:(FlutterError **)error {
// change to prevent unnecessary lags and silence
// https://github.com/flutter/flutter/issues/131553
#if TARGET_OS_IOS
static void upgradeAudioSessionCategory(AVAudioSessionCategory category,
static void upgradeAudioSessionCategory(AVAudioSessionCategory requestedCategory,
AVAudioSessionCategoryOptions options,
AVAudioSessionCategoryOptions clearOptions) {
if (category == nil) {
category = AVAudioSession.sharedInstance.category;
}
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];
NSSet *requiredCategories = [NSSet setWithObjects:requestedCategory, AVAudioSession.sharedInstance.category, nil];
BOOL needPlay = [requiredCategories intersectsSet:playCategories];
BOOL needRecord = [requiredCategories intersectsSet:recordCategories];
if (needPlay && needRecord) {
category = AVAudioSessionCategoryPlayAndRecord;
requestedCategory = AVAudioSessionCategoryPlayAndRecord;
} else if (needPlay) {
category = AVAudioSessionCategoryPlayback;
requestedCategory = AVAudioSessionCategoryPlayback;
} else if (needRecord) {
category = AVAudioSessionCategoryRecord;
requestedCategory = AVAudioSessionCategoryRecord;
}
options = (AVAudioSession.sharedInstance.categoryOptions & ~clearOptions) | options;
if ([category isEqualToString:AVAudioSession.sharedInstance.category] &&
if ([requestedCategory isEqualToString:AVAudioSession.sharedInstance.category] &&
options == AVAudioSession.sharedInstance.categoryOptions) {
return;
}
[AVAudioSession.sharedInstance setCategory:category withOptions:options error:nil];
[AVAudioSession.sharedInstance setCategory:requestedCategory withOptions:options error:nil];
}
#endif

Expand All @@ -857,9 +854,9 @@ - (void)setMixWithOthers:(BOOL)mixWithOthers
// AVAudioSession doesn't exist on macOS, and audio always mixes, so just no-op.
#else
if (mixWithOthers) {
upgradeAudioSessionCategory(nil, AVAudioSessionCategoryOptionMixWithOthers, 0);
upgradeAudioSessionCategory(AVAudioSession.sharedInstance.category, AVAudioSessionCategoryOptionMixWithOthers, 0);
} else {
upgradeAudioSessionCategory(nil, 0, AVAudioSessionCategoryOptionMixWithOthers);
upgradeAudioSessionCategory(AVAudioSession.sharedInstance.category, 0, AVAudioSessionCategoryOptionMixWithOthers);
}
#endif
}
Expand Down