From b13fe9c56f5f26a7fd267c3d82edda399ecdf7eb Mon Sep 17 00:00:00 2001 From: Benjamin Reis Date: Thu, 2 Mar 2017 16:08:47 +0100 Subject: [PATCH] Clean code of Audio route management --- Classes/AudioHelper.m | 2 -- Classes/CallOutgoingView.m | 2 ++ Classes/CallView.m | 2 ++ Classes/LinphoneManager.m | 17 +++++++---------- Classes/LinphoneUI/UIBluetoothButton.m | 8 ++++---- Classes/LinphoneUI/UISpeakerButton.m | 4 ++-- Classes/Utils/AudioHelper.h | 3 +++ 7 files changed, 20 insertions(+), 18 deletions(-) diff --git a/Classes/AudioHelper.m b/Classes/AudioHelper.m index 2231daec4..d8e110899 100644 --- a/Classes/AudioHelper.m +++ b/Classes/AudioHelper.m @@ -7,8 +7,6 @@ // #import "AudioHelper.h" -#import -#import @implementation AudioHelper diff --git a/Classes/CallOutgoingView.m b/Classes/CallOutgoingView.m index 166382bb3..3cce9420e 100644 --- a/Classes/CallOutgoingView.m +++ b/Classes/CallOutgoingView.m @@ -94,6 +94,7 @@ static UICompositeViewDescription *compositeDescription = nil; - (IBAction)onRoutesBluetoothClick:(id)sender { [self hideRoutes:TRUE animated:TRUE]; + [LinphoneManager.instance setSpeakerEnabled:FALSE]; [LinphoneManager.instance setBluetoothEnabled:TRUE]; } @@ -105,6 +106,7 @@ static UICompositeViewDescription *compositeDescription = nil; - (IBAction)onRoutesSpeakerClick:(id)sender { [self hideRoutes:TRUE animated:TRUE]; + [LinphoneManager.instance setBluetoothEnabled:FALSE]; [LinphoneManager.instance setSpeakerEnabled:TRUE]; } diff --git a/Classes/CallView.m b/Classes/CallView.m index 2a367b150..18f53aa60 100644 --- a/Classes/CallView.m +++ b/Classes/CallView.m @@ -711,6 +711,7 @@ static void hideSpinner(LinphoneCall *call, void *user_data) { - (IBAction)onRoutesBluetoothClick:(id)sender { [self hideRoutes:TRUE animated:TRUE]; + [LinphoneManager.instance setSpeakerEnabled:FALSE]; [LinphoneManager.instance setBluetoothEnabled:TRUE]; } @@ -722,6 +723,7 @@ static void hideSpinner(LinphoneCall *call, void *user_data) { - (IBAction)onRoutesSpeakerClick:(id)sender { [self hideRoutes:TRUE animated:TRUE]; + [LinphoneManager.instance setBluetoothEnabled:FALSE]; [LinphoneManager.instance setSpeakerEnabled:TRUE]; } diff --git a/Classes/LinphoneManager.m b/Classes/LinphoneManager.m index 33f057ba7..f9b42be15 100644 --- a/Classes/LinphoneManager.m +++ b/Classes/LinphoneManager.m @@ -2564,17 +2564,14 @@ static int comp_call_state_paused(const LinphoneCall *call, const void *param) { - (void)setSpeakerEnabled:(BOOL)enable { _speakerEnabled = enable; - UInt32 override = kAudioSessionUnspecifiedError; NSError *err; - if (override != kAudioSessionNoError) { - if (enable && [self allowSpeaker]) { - [[AVAudioSession sharedInstance] overrideOutputAudioPort:AVAudioSessionPortOverrideSpeaker error:&err]; - _bluetoothEnabled = FALSE; - } else { - AVAudioSessionPortDescription *builtinPort = [AudioHelper builtinAudioDevice]; - [[AVAudioSession sharedInstance] setPreferredInput:builtinPort error:&err]; - } + if (enable && [self allowSpeaker]) { + [[AVAudioSession sharedInstance] overrideOutputAudioPort:AVAudioSessionPortOverrideSpeaker error:&err]; + _bluetoothEnabled = FALSE; + } else { + AVAudioSessionPortDescription *builtinPort = [AudioHelper builtinAudioDevice]; + [[AVAudioSession sharedInstance] setPreferredInput:builtinPort error:&err]; } if (err) { @@ -2593,7 +2590,7 @@ static int comp_call_state_paused(const LinphoneCall *call, const void *param) { // if setting bluetooth failed, it must be because the device is not available // anymore (disconnected), so deactivate bluetooth. if (err) { - _bluetoothAvailable = _bluetoothEnabled = FALSE; + _bluetoothEnabled = FALSE; } else { _speakerEnabled = FALSE; return; diff --git a/Classes/LinphoneUI/UIBluetoothButton.m b/Classes/LinphoneUI/UIBluetoothButton.m index 52ab9259b..b98cd72a4 100644 --- a/Classes/LinphoneUI/UIBluetoothButton.m +++ b/Classes/LinphoneUI/UIBluetoothButton.m @@ -31,13 +31,13 @@ LOGE(@"UIBluetoothButton error for %s: ret=%ld", method, au) - (void)onOn { - AVAudioSessionPortDescription *_bluetoothPort = [AudioHelper bluetoothAudioDevice]; - [[AVAudioSession sharedInstance] setPreferredInput:_bluetoothPort error:nil]; + // AVAudioSessionPortDescription *_bluetoothPort = [AudioHelper bluetoothAudioDevice]; + //[[AVAudioSession sharedInstance] setPreferredInput:_bluetoothPort error:nil]; } - (void)onOff { - AVAudioSessionPortDescription *builtinPort = [AudioHelper builtinAudioDevice]; - [[AVAudioSession sharedInstance] setPreferredInput:builtinPort error:nil]; + // AVAudioSessionPortDescription *builtinPort = [AudioHelper builtinAudioDevice]; + //[[AVAudioSession sharedInstance] setPreferredInput:builtinPort error:nil]; } - (bool)onUpdate { diff --git a/Classes/LinphoneUI/UISpeakerButton.m b/Classes/LinphoneUI/UISpeakerButton.m index 976e62339..37207ca4d 100644 --- a/Classes/LinphoneUI/UISpeakerButton.m +++ b/Classes/LinphoneUI/UISpeakerButton.m @@ -52,11 +52,11 @@ INIT_WITH_COMMON_CF { } - (void)onOn { - [LinphoneManager.instance setSpeakerEnabled:TRUE]; + //[LinphoneManager.instance setSpeakerEnabled:TRUE]; } - (void)onOff { - [LinphoneManager.instance setSpeakerEnabled:FALSE]; + //[LinphoneManager.instance setSpeakerEnabled:FALSE]; } - (bool)onUpdate { diff --git a/Classes/Utils/AudioHelper.h b/Classes/Utils/AudioHelper.h index d770d3b50..03ae31c66 100644 --- a/Classes/Utils/AudioHelper.h +++ b/Classes/Utils/AudioHelper.h @@ -9,6 +9,9 @@ #ifndef AudioHelper_h #define AudioHelper_h +#import +#import + @interface AudioHelper : NSObject + (NSArray *)bluetoothRoutes;