Commit c5196e3b authored by QuentinArguillere's avatar QuentinArguillere
Browse files

Update the linphone core input device as well, previously only dealt with the...

Update the linphone core input device as well, previously only dealt with the output device. Also handle special cases for the speaker and the iPhone receiver. Use some more C++ friendly tools for readability. 
parent 125cd258
......@@ -76,15 +76,19 @@
std::string currentInputPort("No input");
std::string previousOutputPort("No output");
std::string currentOutputPort("No output");
bool currentOutputIsSpeaker = false, currentOutputIsReceiver = false;
if (previousRoute.inputs.count > 0)
previousInputPort = std::string([previousRoute.inputs[0].portName UTF8String]);
if (previousRoute.outputs.count > 0)
previousOutputPort = std::string([previousRoute.outputs[0].portName UTF8String]);
if (currentRoute.inputs.count > 0)
currentInputPort = std::string([currentRoute.inputs[0].portName UTF8String]);
if (currentRoute.outputs.count > 0)
if (currentRoute.outputs.count > 0) {
currentOutputPort = std::string([currentRoute.outputs[0].portName UTF8String]);
currentOutputIsReceiver = (strcmp(currentRoute.outputs[0].portType.UTF8String, AVAudioSessionPortBuiltInReceiver.UTF8String) == 0);
currentOutputIsSpeaker = (strcmp(currentRoute.outputs[0].portType.UTF8String, AVAudioSessionPortBuiltInSpeaker.UTF8String) == 0);
}
ms_message("Previous audio route: input=%s, output=%s, New audio route: input=%s, output=%s"
, previousInputPort.c_str(), previousOutputPort.c_str()
......@@ -99,7 +103,7 @@
if (currentInputPort == previousInputPort && currentOutputPort == previousOutputPort)
return;
pcore->doLater([currentOutputPort, currentInputPort, changeReason, self]() {
pcore->doLater([=]() {
switch (changeReason)
{
......@@ -114,20 +118,50 @@
default: {}
}
auto deviceMatchCurrentInput = [currentInputPort](std::string const& deviceName) -> bool {
return (deviceName == currentInputPort);
};
auto deviceMatchCurrentOutput = [currentOutputIsSpeaker, currentOutputPort](std::string const& deviceName) -> bool {
if (currentOutputIsSpeaker)
return (deviceName == "Speaker");
else
return (deviceName == currentOutputPort);
};
const LinphoneAudioDevice * inputDevice = linphone_core_get_input_audio_device(pcore->getCCore());
const LinphoneAudioDevice * outputDevice = linphone_core_get_output_audio_device(pcore->getCCore());
std::string currentInputDeviceInCore( (inputDevice == NULL) ? "" : linphone_audio_device_get_device_name(inputDevice) );
std::string currentOutputDeviceInCore( (outputDevice == NULL) ? "" : linphone_audio_device_get_device_name(inputDevice) );
// Make sure that the current device the core is using match the reality of the IOS audio route. If not, set it properly
const char * currentDeviceInCore = linphone_audio_device_get_device_name(linphone_core_get_output_audio_device(pcore->getCCore()));
if (currentDeviceInCore && strcmp(currentOutputPort.c_str(), currentDeviceInCore) == 0) {
if (deviceMatchCurrentInput(currentInputDeviceInCore) && deviceMatchCurrentOutput(currentOutputDeviceInCore) )
return;
}
bctbx_list_t * deviceIt = linphone_core_get_audio_devices(pcore->getCCore());
while (deviceIt != NULL) {
bool inputUpdated = false, outputUpdated = false;
while ( deviceIt != NULL && !(inputUpdated && outputUpdated) ) {
LinphoneAudioDevice * pDevice = (LinphoneAudioDevice *) deviceIt->data;
if (strcmp(currentInputPort.c_str(), linphone_audio_device_get_device_name(pDevice)) == 0)
{
std::string deviceName(linphone_audio_device_get_device_name(pDevice));
if (deviceMatchCurrentInput(deviceName) && deviceName != currentInputDeviceInCore && !inputUpdated) {
linphone_core_set_input_audio_device(pcore->getCCore(), pDevice);
inputUpdated = true;
// Special case : the LinphoneAudioDevice matching the IPhoneMicrophone and the IPhoneReceiver is the same.
// They are built using the AVAudioSession.availableInputs function, which is why the name will not match
// We make the assumption that if the output is the IPhone Receiver, then the input is always the IPhoneMicrophone,
// so also set the output here.
if (currentOutputIsReceiver) {
linphone_core_set_output_audio_device(pcore->getCCore(), pDevice);
outputUpdated = true;
}
}
if (deviceMatchCurrentOutput(deviceName) && deviceName != currentOutputDeviceInCore && !outputUpdated) {
linphone_core_set_output_audio_device(pcore->getCCore(), pDevice);
break;
outputUpdated = true;
}
deviceIt = deviceIt->next;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment