Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mumble-voip/mumblekit.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMikkel Krautz <mikkel@krautz.dk>2013-09-17 03:49:24 +0400
committerMikkel Krautz <mikkel@krautz.dk>2013-09-17 03:49:24 +0400
commitfcf0beb8f18dae8525aedad77bccb53a09247905 (patch)
treee344ceec48fb5f734840ed965ba867839056d319
parent44a90fc0af51e8c4366b025cb33b4035cd3f6697 (diff)
MKAudio: add preferReceiverOverSpeaker setting.
-rw-r--r--src/MKAudio.m53
-rw-r--r--src/MumbleKit/MKAudio.h2
2 files changed, 53 insertions, 2 deletions
diff --git a/src/MKAudio.m b/src/MKAudio.m
index 1514f44..e4fea69 100644
--- a/src/MKAudio.m
+++ b/src/MKAudio.m
@@ -75,7 +75,12 @@ static void MKAudio_AudioInputAvailableCallback(MKAudio *audio, AudioSessionProp
}
if (val == kAudioSessionCategory_PlayAndRecord) {
+ MKAudioSettings settings;
+ [audio readAudioSettings:&settings];
val = 1;
+ if (settings.preferReceiverOverSpeaker) {
+ val = 0;
+ }
err = AudioSessionSetProperty(kAudioSessionProperty_OverrideCategoryDefaultToSpeaker, sizeof(val), &val);
if (err != kAudioSessionNoError) {
NSLog(@"MKAudio: unable to set OverrideCategoryDefaultToSpeaker property.");
@@ -172,8 +177,14 @@ static void MKAudio_SetupAudioSession(MKAudio *audio) {
if (audioInputAvailable) {
// The OverrideCategoryDefaultToSpeaker property makes us output to the speakers of the iOS device
- // as long as there's not a headset connected.
- val = TRUE;
+ // as long as there's not a headset connected. However, if the user prefers the audio to be output
+ // to the receiver, honor that.
+ MKAudioSettings settings;
+ [audio readAudioSettings:&settings];
+ val = 1;
+ if (settings.preferReceiverOverSpeaker) {
+ val = 0;
+ }
err = AudioSessionSetProperty(kAudioSessionProperty_OverrideCategoryDefaultToSpeaker, sizeof(val), &val);
if (err != kAudioSessionNoError) {
NSLog(@"MKAudio: unable to set OverrideCategoryDefaultToSpeaker property.");
@@ -213,10 +224,47 @@ static void MKAudio_SetupAudioSession(MKAudio *audio) {
return;
}
}
+
+static void MKAudio_UpdateAudioSessionSettings(MKAudio *audio) {
+ OSStatus err;
+ UInt32 val, valSize;
+ BOOL audioInputAvailable = YES;
+
+
+ // To be able to select the correct category, we must query whethe audio input is available.
+ valSize = sizeof(UInt32);
+ err = AudioSessionGetProperty(kAudioSessionProperty_AudioInputAvailable, &valSize, &val);
+ if (err != kAudioSessionNoError || valSize != sizeof(UInt32)) {
+ NSLog(@"MKAudio: unable to query for input availability.");
+ return;
+ }
+ audioInputAvailable = (BOOL) val;
+
+ if (audioInputAvailable) {
+ // The OverrideCategoryDefaultToSpeaker property makes us output to the speakers of the iOS device
+ // as long as there's not a headset connected. However, if the user prefers the audio to be output
+ // to the receiver, honor that.
+ MKAudioSettings settings;
+ [audio readAudioSettings:&settings];
+ val = 1;
+ if (settings.preferReceiverOverSpeaker) {
+ val = 0;
+ }
+ err = AudioSessionSetProperty(kAudioSessionProperty_OverrideCategoryDefaultToSpeaker, sizeof(val), &val);
+ if (err != kAudioSessionNoError) {
+ NSLog(@"MKAudio: unable to set OverrideCategoryDefaultToSpeaker property.");
+ return;
+ }
+ }
+}
#else
static void MKAudio_SetupAudioSession(MKAudio *audio) {
(void) audio;
}
+
+static void MKAudio_UpdateAudioSessionSettings(MKAudio *audio) {
+ (void) audio;
+}
#endif
@implementation MKAudio
@@ -322,6 +370,7 @@ static void MKAudio_SetupAudioSession(MKAudio *audio) {
// Restart the audio engine
- (void) restart {
[self stop];
+ MKAudio_UpdateAudioSessionSettings(self);
[self start];
[[NSNotificationCenter defaultCenter] postNotificationName:MKAudioDidRestartNotification object:self];
diff --git a/src/MumbleKit/MKAudio.h b/src/MumbleKit/MKAudio.h
index f199aa3..ae84eec 100644
--- a/src/MumbleKit/MKAudio.h
+++ b/src/MumbleKit/MKAudio.h
@@ -54,6 +54,8 @@ typedef struct _MKAudioSettings {
float comfortNoiseLevel;
BOOL enableVadGate;
double vadGateTimeSeconds;
+
+ BOOL preferReceiverOverSpeaker;
} MKAudioSettings;
/// @protocol MKAudioDelegate MKAudio.h MumbleKit/MKAudio.h