From c120375fc6ce00023bb560b24f60c08252969d83 Mon Sep 17 00:00:00 2001 From: Benjamin Reis Date: Wed, 4 Jul 2018 11:51:51 +0200 Subject: [PATCH 1/3] begin dev --- Classes/AudioHelper.m | 2 +- Classes/LinphoneManager.m | 12 +++++------- Classes/ProviderDelegate.m | 2 +- 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/Classes/AudioHelper.m b/Classes/AudioHelper.m index d8e110899..dbc28f680 100644 --- a/Classes/AudioHelper.m +++ b/Classes/AudioHelper.m @@ -11,7 +11,7 @@ @implementation AudioHelper + (NSArray *)bluetoothRoutes { - return @[ AVAudioSessionPortBluetoothA2DP, AVAudioSessionPortBluetoothLE, AVAudioSessionPortBluetoothHFP ]; + return @[ AVAudioSessionPortBluetoothA2DP, AVAudioSessionPortBluetoothLE, AVAudioSessionPortBluetoothHFP, AVAudioSessionPortCarAudio ]; } + (AVAudioSessionPortDescription *)bluetoothAudioDevice { diff --git a/Classes/LinphoneManager.m b/Classes/LinphoneManager.m index 8fec2f9a8..6160c94b1 100644 --- a/Classes/LinphoneManager.m +++ b/Classes/LinphoneManager.m @@ -2460,10 +2460,9 @@ static int comp_call_state_paused(const LinphoneCall *call, const void *param) { // -bluetooth headset disconnected or // -user wanted to use earpiece // the only thing we can assume is that when we lost a device, it must be a bluetooth one (strong hypothesis though) - if ([[notif.userInfo valueForKey:AVAudioSessionRouteChangeReasonKey] integerValue] == - AVAudioSessionRouteChangeReasonOldDeviceUnavailable) { + if ([[notif.userInfo valueForKey:AVAudioSessionRouteChangeReasonKey] integerValue] == AVAudioSessionRouteChangeReasonOldDeviceUnavailable) _bluetoothAvailable = NO; - } + AVAudioSessionRouteDescription *newRoute = [AVAudioSession sharedInstance].currentRoute; if (newRoute) { @@ -2474,11 +2473,10 @@ static int comp_call_state_paused(const LinphoneCall *call, const void *param) { if (([[AudioHelper bluetoothRoutes] containsObject:route]) && !_speakerEnabled) { _bluetoothAvailable = TRUE; _bluetoothEnabled = TRUE; - } else { + } else _bluetoothEnabled = FALSE; - } - NSDictionary *dict = [NSDictionary - dictionaryWithObjectsAndKeys:[NSNumber numberWithBool:_bluetoothAvailable], @"available", nil]; + + NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithBool:_bluetoothAvailable], @"available", nil]; [NSNotificationCenter.defaultCenter postNotificationName:kLinphoneBluetoothAvailabilityUpdate object:self userInfo:dict]; diff --git a/Classes/ProviderDelegate.m b/Classes/ProviderDelegate.m index a3ee92e9f..108f0c8c7 100644 --- a/Classes/ProviderDelegate.m +++ b/Classes/ProviderDelegate.m @@ -52,7 +52,7 @@ - (void)configAudioSession:(AVAudioSession *)audioSession { NSError *err = nil; [audioSession setCategory:AVAudioSessionCategoryPlayAndRecord - withOptions:AVAudioSessionCategoryOptionAllowBluetooth + withOptions:AVAudioSessionCategoryOptionAllowBluetooth | AVAudioSessionCategoryOptionAllowBluetoothA2DP error:&err]; if (err) { LOGE(@"Unable to change audio category because : %@", err.localizedDescription); From 4239b6d46486ebead5954d5b15647e019e3d6c70 Mon Sep 17 00:00:00 2001 From: Benjamin Reis Date: Wed, 4 Jul 2018 11:56:17 +0200 Subject: [PATCH 2/3] refactor bluetooth management --- Classes/AudioHelper.m | 2 +- Classes/ProviderDelegate.m | 13 +++++-------- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/Classes/AudioHelper.m b/Classes/AudioHelper.m index dbc28f680..458aeb61f 100644 --- a/Classes/AudioHelper.m +++ b/Classes/AudioHelper.m @@ -11,7 +11,7 @@ @implementation AudioHelper + (NSArray *)bluetoothRoutes { - return @[ AVAudioSessionPortBluetoothA2DP, AVAudioSessionPortBluetoothLE, AVAudioSessionPortBluetoothHFP, AVAudioSessionPortCarAudio ]; + return @[AVAudioSessionPortBluetoothHFP, AVAudioSessionPortCarAudio, AVAudioSessionPortBluetoothA2DP, AVAudioSessionPortBluetoothLE ]; } + (AVAudioSessionPortDescription *)bluetoothAudioDevice { diff --git a/Classes/ProviderDelegate.m b/Classes/ProviderDelegate.m index 108f0c8c7..e046d0b5a 100644 --- a/Classes/ProviderDelegate.m +++ b/Classes/ProviderDelegate.m @@ -52,23 +52,20 @@ - (void)configAudioSession:(AVAudioSession *)audioSession { NSError *err = nil; [audioSession setCategory:AVAudioSessionCategoryPlayAndRecord - withOptions:AVAudioSessionCategoryOptionAllowBluetooth | AVAudioSessionCategoryOptionAllowBluetoothA2DP + mode:AVAudioSessionModeVoiceChat + options:AVAudioSessionCategoryOptionAllowBluetooth | AVAudioSessionCategoryOptionAllowBluetoothA2DP error:&err]; if (err) { LOGE(@"Unable to change audio category because : %@", err.localizedDescription); err = nil; } - [audioSession setMode:AVAudioSessionModeVoiceChat error:&err]; - if (err) { - LOGE(@"Unable to change audio mode because : %@", err.localizedDescription); - err = nil; - } - double sampleRate = 44100.0; + + /*double sampleRate = 44100.0; [audioSession setPreferredSampleRate:sampleRate error:&err]; if (err) { LOGE(@"Unable to change preferred sample rate because : %@", err.localizedDescription); err = nil; - } + }*/ } - (void)reportIncomingCall:(LinphoneCall *) call withUUID:(NSUUID *)uuid handle:(NSString *)handle video:(BOOL)video; { From 4fbc902eeee3839a1d3d6063186b6677ab5080bb Mon Sep 17 00:00:00 2001 From: Benjamin Reis Date: Thu, 5 Jul 2018 13:24:21 +0200 Subject: [PATCH 3/3] fix sound on some BT devices --- Classes/ProviderDelegate.m | 11 ++--------- submodules/mediastreamer2 | 2 +- 2 files changed, 3 insertions(+), 10 deletions(-) diff --git a/Classes/ProviderDelegate.m b/Classes/ProviderDelegate.m index e046d0b5a..991dfe30f 100644 --- a/Classes/ProviderDelegate.m +++ b/Classes/ProviderDelegate.m @@ -53,19 +53,12 @@ NSError *err = nil; [audioSession setCategory:AVAudioSessionCategoryPlayAndRecord mode:AVAudioSessionModeVoiceChat - options:AVAudioSessionCategoryOptionAllowBluetooth | AVAudioSessionCategoryOptionAllowBluetoothA2DP + options:AVAudioSessionCategoryOptionAllowBluetooth | AVAudioSessionCategoryOptionAllowBluetoothA2DP | AVAudioSessionCategoryOptionMixWithOthers error:&err]; if (err) { - LOGE(@"Unable to change audio category because : %@", err.localizedDescription); + LOGE(@"Unable to change audio session because: %@", err.localizedDescription); err = nil; } - - /*double sampleRate = 44100.0; - [audioSession setPreferredSampleRate:sampleRate error:&err]; - if (err) { - LOGE(@"Unable to change preferred sample rate because : %@", err.localizedDescription); - err = nil; - }*/ } - (void)reportIncomingCall:(LinphoneCall *) call withUUID:(NSUUID *)uuid handle:(NSString *)handle video:(BOOL)video; { diff --git a/submodules/mediastreamer2 b/submodules/mediastreamer2 index 54a79f731..d4ad04b1d 160000 --- a/submodules/mediastreamer2 +++ b/submodules/mediastreamer2 @@ -1 +1 @@ -Subproject commit 54a79f731fea61d345dfff4f8fcb2fc390c2fed7 +Subproject commit d4ad04b1dcf2a321f90e315a3fdf293fccedcdb8