From 00b9ef2c7f4b88f2eb0b9e4da958964e14a9b3dc Mon Sep 17 00:00:00 2001 From: Jehan Monnier Date: Tue, 8 Mar 2011 11:29:13 +0100 Subject: [PATCH] start adding bluetooth support --- Classes/LinphoneUI/UIBluetoothButton.h | 27 +++++++++ Classes/LinphoneUI/UIBluetoothButton.m | 79 ++++++++++++++++++++++++++ linphone.xcodeproj/project.pbxproj | 6 ++ 3 files changed, 112 insertions(+) create mode 100644 Classes/LinphoneUI/UIBluetoothButton.h create mode 100644 Classes/LinphoneUI/UIBluetoothButton.m diff --git a/Classes/LinphoneUI/UIBluetoothButton.h b/Classes/LinphoneUI/UIBluetoothButton.h new file mode 100644 index 000000000..154e387e3 --- /dev/null +++ b/Classes/LinphoneUI/UIBluetoothButton.h @@ -0,0 +1,27 @@ +/* UISpeakerButton.h + * + * Copyright (C) 2011 Belledonne Comunications, Grenoble, France + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Library General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#import +#import "UIToggleButton.h" + +@interface UIBluetoothButton : UIToggleButton { + +} + +@end diff --git a/Classes/LinphoneUI/UIBluetoothButton.m b/Classes/LinphoneUI/UIBluetoothButton.m new file mode 100644 index 000000000..3b4024d0f --- /dev/null +++ b/Classes/LinphoneUI/UIBluetoothButton.m @@ -0,0 +1,79 @@ +/* UISpeakerButton.m + * + * Copyright (C) 2011 Belledonne Comunications, Grenoble, France + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Library General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#import "UIBluetoothButton.h" +#import +#include "linphonecore.h" + +@implementation UIBluetoothButton +#define check_auresult(au,method) \ +if (au!=0) ms_error("UIBluetoothButton error for %s: ret=%i",method,au) + +-(void) onOn { + //redirect audio to bluetooth + + UInt32 size = sizeof(CFStringRef); + CFStringRef route="HeadsetBT"; + OSStatus result = AudioSessionSetProperty(kAudioSessionProperty_AudioRoute, &size, &route); + check_auresult(result,"set kAudioSessionProperty_AudioRoute HeadsetBT"); + + int allowBluetoothInput = 1; + result = AudioSessionSetProperty ( + kAudioSessionProperty_OverrideCategoryEnableBluetoothInput, + sizeof (allowBluetoothInput), + &allowBluetoothInput + ); + check_auresult(result,"set kAudioSessionProperty_OverrideCategoryEnableBluetoothInput 1"); + +} +-(void) onOff { + //redirect audio to bluetooth + int allowBluetoothInput = 0; + OSStatus result = AudioSessionSetProperty ( + kAudioSessionProperty_OverrideCategoryEnableBluetoothInput, + sizeof (allowBluetoothInput), + &allowBluetoothInput + ); + check_auresult(result,"set kAudioSessionProperty_OverrideCategoryEnableBluetoothInput 0"); + UInt32 size = sizeof(CFStringRef); + CFStringRef route="ReceiverAndMicrophone"; + result = AudioSessionSetProperty(kAudioSessionProperty_AudioRoute, &size, &route); + check_auresult(result,"set kAudioSessionProperty_AudioRoute ReceiverAndMicrophone"); + + +} +-(bool) isInitialStateOn { + return false; +} + + +/* + // Only override drawRect: if you perform custom drawing. + // An empty implementation adversely affects performance during animation. + - (void)drawRect:(CGRect)rect { + // Drawing code. + } + */ + +- (void)dealloc { + [super dealloc]; +} + + +@end diff --git a/linphone.xcodeproj/project.pbxproj b/linphone.xcodeproj/project.pbxproj index 10e9b3819..e6a924f2d 100755 --- a/linphone.xcodeproj/project.pbxproj +++ b/linphone.xcodeproj/project.pbxproj @@ -64,6 +64,7 @@ 22B5EFA310CE50BD00777D97 /* AddressBookUI.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 22B5EFA210CE50BD00777D97 /* AddressBookUI.framework */; }; 22B5EFE510CE5E5800777D97 /* ContactPickerDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 22B5EFE410CE5E5800777D97 /* ContactPickerDelegate.m */; }; 22B5F03510CE6B2F00777D97 /* AddressBook.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 22B5F03410CE6B2F00777D97 /* AddressBook.framework */; }; + 22C755601317E59C007BC101 /* UIBluetoothButton.m in Sources */ = {isa = PBXBuildFile; fileRef = 22C7555F1317E59C007BC101 /* UIBluetoothButton.m */; }; 22D1B68112A3E0BE001AE361 /* libresolv.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 22D1B68012A3E0BE001AE361 /* libresolv.dylib */; }; 22E0A785111C1BA800B04932 /* Speaker-32-on.png in Resources */ = {isa = PBXBuildFile; fileRef = 22E0A783111C1BA800B04932 /* Speaker-32-on.png */; }; 22E0A786111C1BA800B04932 /* Speaker-32-off.png in Resources */ = {isa = PBXBuildFile; fileRef = 22E0A784111C1BA800B04932 /* Speaker-32-off.png */; }; @@ -285,6 +286,8 @@ 22B5EFE310CE5E5800777D97 /* ContactPickerDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ContactPickerDelegate.h; sourceTree = ""; }; 22B5EFE410CE5E5800777D97 /* ContactPickerDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ContactPickerDelegate.m; sourceTree = ""; }; 22B5F03410CE6B2F00777D97 /* AddressBook.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AddressBook.framework; path = System/Library/Frameworks/AddressBook.framework; sourceTree = SDKROOT; }; + 22C7555E1317E59C007BC101 /* UIBluetoothButton.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UIBluetoothButton.h; sourceTree = ""; }; + 22C7555F1317E59C007BC101 /* UIBluetoothButton.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = UIBluetoothButton.m; sourceTree = ""; }; 22D1B68012A3E0BE001AE361 /* libresolv.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libresolv.dylib; path = usr/lib/libresolv.dylib; sourceTree = SDKROOT; }; 22E0A783111C1BA800B04932 /* Speaker-32-on.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = "Speaker-32-on.png"; path = "Resources/Speaker-32-on.png"; sourceTree = ""; }; 22E0A784111C1BA800B04932 /* Speaker-32-off.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = "Speaker-32-off.png"; path = "Resources/Speaker-32-off.png"; sourceTree = ""; }; @@ -586,6 +589,8 @@ 22968A8712F87C2000588287 /* UIDuration.m */, 2218A5C412F9597B0088A667 /* LinphoneUIDelegates.h */, 2218A5CE12F973450088A667 /* LogView.h */, + 22C7555E1317E59C007BC101 /* UIBluetoothButton.h */, + 22C7555F1317E59C007BC101 /* UIBluetoothButton.m */, ); path = LinphoneUI; sourceTree = ""; @@ -807,6 +812,7 @@ 22968A5F12F875C600588287 /* UISpeakerButton.m in Sources */, 22968A8812F87C2000588287 /* UIDuration.m in Sources */, 2218A92512FBE1340088A667 /* FirstLoginViewController.m in Sources */, + 22C755601317E59C007BC101 /* UIBluetoothButton.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; };