From b15979637be530a66fd474af2303c9eb85f16a7b Mon Sep 17 00:00:00 2001 From: Gautier Pelloux-Prayer Date: Mon, 25 Jan 2016 10:06:07 +0100 Subject: [PATCH] audio: only speaker on ipad for now --- Classes/Base.lproj/CallOutgoingView.xib | 48 ++++++++++++------------- Classes/LinphoneManager.m | 14 +++++--- Classes/LinphoneUI/UISpeakerButton.m | 2 -- Classes/LinphoneUI/UIToggleButton.m | 24 ++++++++++++- Classes/Utils/Utils.h | 12 ++----- 5 files changed, 60 insertions(+), 40 deletions(-) diff --git a/Classes/Base.lproj/CallOutgoingView.xib b/Classes/Base.lproj/CallOutgoingView.xib index 6d3ac0234..6390f692e 100644 --- a/Classes/Base.lproj/CallOutgoingView.xib +++ b/Classes/Base.lproj/CallOutgoingView.xib @@ -147,18 +147,6 @@ - + @@ -344,18 +344,6 @@ - + diff --git a/Classes/LinphoneManager.m b/Classes/LinphoneManager.m index 489891d47..3817a54b8 100644 --- a/Classes/LinphoneManager.m +++ b/Classes/LinphoneManager.m @@ -1775,19 +1775,25 @@ static int comp_call_state_paused(const LinphoneCall *call, const void *param) { #pragma mark - Audio route Functions - (bool)allowSpeaker { - bool notallow = false; + if (IPAD) + return true; + + bool allow = true; CFStringRef lNewRoute = CFSTR("Unknown"); UInt32 lNewRouteSize = sizeof(lNewRoute); OSStatus lStatus = AudioSessionGetProperty(kAudioSessionProperty_AudioRoute, &lNewRouteSize, &lNewRoute); if (!lStatus && lNewRouteSize > 0) { NSString *route = (__bridge NSString *)lNewRoute; - notallow = [route containsString:@"Heads"] || [route isEqualToString:@"Lineout"]; + allow = ![route containsString:@"Heads"] && ![route isEqualToString:@"Lineout"]; CFRelease(lNewRoute); } - return !notallow; + return allow; } - (void)audioRouteChangeListenerCallback:(NSNotification *)notif { + if (IPAD) + return; + // there is at least one bug when you disconnect an audio bluetooth headset // since we only get notification of route having changed, we cannot tell if that is due to: // -bluetooth headset disconnected or @@ -1839,7 +1845,7 @@ static int comp_call_state_paused(const LinphoneCall *call, const void *param) { } if (override != kAudioSessionNoError) { - if (enable && (IPAD || [self allowSpeaker])) { + if (enable && [self allowSpeaker]) { override = kAudioSessionOverrideAudioRoute_Speaker; ret = AudioSessionSetProperty(kAudioSessionProperty_OverrideAudioRoute, sizeof(override), &override); _bluetoothEnabled = FALSE; diff --git a/Classes/LinphoneUI/UISpeakerButton.m b/Classes/LinphoneUI/UISpeakerButton.m index 695b652d4..460a2def1 100644 --- a/Classes/LinphoneUI/UISpeakerButton.m +++ b/Classes/LinphoneUI/UISpeakerButton.m @@ -57,8 +57,6 @@ INIT_WITH_COMMON_CF { - (bool)onUpdate { self.enabled = [LinphoneManager.instance allowSpeaker]; - if (IPAD) - self.selected = !LinphoneManager.instance.bluetoothEnabled; return [LinphoneManager.instance speakerEnabled]; } diff --git a/Classes/LinphoneUI/UIToggleButton.m b/Classes/LinphoneUI/UIToggleButton.m index cd05bbc7f..44b692cba 100644 --- a/Classes/LinphoneUI/UIToggleButton.m +++ b/Classes/LinphoneUI/UIToggleButton.m @@ -23,12 +23,34 @@ #pragma mark - Lifecycle Functions -INIT_WITH_COMMON_CF { +- (void)initUIToggleButton { [self update]; [self addTarget:self action:@selector(touchUp:) forControlEvents:UIControlEventTouchUpInside]; +} + +- (id)init { + self = [super init]; + if (self) { + [self initUIToggleButton]; + } return self; } +- (id)initWithFrame:(CGRect)frame { + self = [super initWithFrame:frame]; + if (self) { + [self initUIToggleButton]; + } + return self; +} + +- (id)initWithCoder:(NSCoder *)decoder { + self = [super initWithCoder:decoder]; + if (self) { + [self initUIToggleButton]; + } + return self; +} #pragma mark - - (void)touchUp:(id)sender { diff --git a/Classes/Utils/Utils.h b/Classes/Utils/Utils.h index eb139926c..db9f7dee1 100644 --- a/Classes/Utils/Utils.h +++ b/Classes/Utils/Utils.h @@ -100,21 +100,15 @@ typedef enum { whatever is using it (xib, source code, etc., tableview cell) */ #define INIT_WITH_COMMON_C \ -(instancetype)init { \ - self = [super init]; \ - [self commonInit]; \ - return self; \ + return [[super init] commonInit]; \ } \ -(instancetype)initWithCoder : (NSCoder *)aDecoder { \ - self = [super initWithCoder:aDecoder]; \ - [self commonInit]; \ - return self; \ + return [[super initWithCoder:aDecoder] commonInit]; \ } \ -(instancetype)commonInit #define INIT_WITH_COMMON_CF \ -(instancetype)initWithFrame : (CGRect)frame { \ - self = [super initWithFrame:frame]; \ - [self commonInit]; \ - return self; \ + return [[super initWithFrame:frame] commonInit]; \ } \ INIT_WITH_COMMON_C