Fix audio device selection by using the correct AudioDevice.

Fix stats display (percent showing, units, and rounded value).
This commit is contained in:
Julien Wadel 2024-10-15 13:30:59 +02:00
parent b07eca28e4
commit 1d0e9f145b
4 changed files with 30 additions and 42 deletions

View file

@ -345,9 +345,8 @@ void CallCore::setSelf(QSharedPointer<CallCore> me) {
});
mCallModelConnection->makeConnectToCore(&CallCore::lSetInputAudioDevice, [this](QString id) {
mCallModelConnection->invokeToModel([this, id]() {
if (auto device = ToolModel::findAudioDevice(id)) {
mCallModel->setInputAudioDevice(device);
}
auto device = ToolModel::findAudioDevice(id, linphone::AudioDevice::Capabilities::CapabilityRecord);
if (device) mCallModel->setInputAudioDevice(device);
});
});
mCallModelConnection->makeConnectToModel(&CallModel::inputAudioDeviceChanged, [this](const std::string &id) {
@ -355,9 +354,8 @@ void CallCore::setSelf(QSharedPointer<CallCore> me) {
});
mCallModelConnection->makeConnectToCore(&CallCore::lSetOutputAudioDevice, [this](QString id) {
mCallModelConnection->invokeToModel([this, id]() {
if (auto device = ToolModel::findAudioDevice(id)) {
mCallModel->setOutputAudioDevice(device);
}
auto device = ToolModel::findAudioDevice(id, linphone::AudioDevice::Capabilities::CapabilityPlay);
if (device) mCallModel->setOutputAudioDevice(device);
});
});
mCallModelConnection->makeConnectToModel(&CallModel::conferenceChanged, [this]() {
@ -410,12 +408,12 @@ void CallCore::setSelf(QSharedPointer<CallCore> me) {
tr("Codec: %1 / %2 kHz").arg(Utils::coreStringToAppString(codecType)).arg(codecRate);
auto linAudioStats = call->getAudioStats();
if (linAudioStats) {
audioStats.mBandwidth = tr("Bande passante : %1 %2 %3 %4")
audioStats.mBandwidth = tr("Bande passante : %1 %2 kbits/s %3 %4 kbits/s")
.arg("")
.arg(linAudioStats->getUploadBandwidth())
.arg(round(linAudioStats->getUploadBandwidth()))
.arg("")
.arg(linAudioStats->getDownloadBandwidth());
audioStats.mLossRate = tr("Taux de perte: %1 \% %2 \%")
.arg(round(linAudioStats->getDownloadBandwidth()));
audioStats.mLossRate = tr("Taux de perte: %1% %2%")
.arg(linAudioStats->getSenderLossRate())
.arg(linAudioStats->getReceiverLossRate());
audioStats.mJitterBufferSize =
@ -432,12 +430,12 @@ void CallCore::setSelf(QSharedPointer<CallCore> me) {
tr("Codec: %1 / %2 kHz").arg(Utils::coreStringToAppString(codecType)).arg(codecRate);
auto linVideoStats = call->getVideoStats();
if (stats) {
videoStats.mBandwidth = tr("Bande passante : %1 %2 %3 %4")
videoStats.mBandwidth = tr("Bande passante : %1 %2 kbits/s %3 %4 kbits/s")
.arg("")
.arg(linVideoStats->getUploadBandwidth())
.arg(round(linVideoStats->getUploadBandwidth()))
.arg("")
.arg(linVideoStats->getDownloadBandwidth());
videoStats.mLossRate = tr("Taux de perte: %1 \% %2 \%")
.arg(round(linVideoStats->getDownloadBandwidth()));
videoStats.mLossRate = tr("Taux de perte: %1% %2%")
.arg(linVideoStats->getSenderLossRate())
.arg(linVideoStats->getReceiverLossRate());
}

View file

@ -293,14 +293,10 @@ QString SettingsModel::getCaptureDevice() const {
void SettingsModel::setCaptureDevice(const QString &device) {
mustBeInLinphoneThread(log().arg(Q_FUNC_INFO));
std::string devId = Utils::appStringToCoreString(device);
auto list = CoreModel::getInstance()->getCore()->getExtendedAudioDevices();
auto audioDevice =
find_if(list.cbegin(), list.cend(),
[&](const std::shared_ptr<linphone::AudioDevice> &audioItem) { return audioItem->getId() == devId; });
if (audioDevice != list.cend()) {
CoreModel::getInstance()->getCore()->setDefaultInputAudioDevice(*audioDevice);
CoreModel::getInstance()->getCore()->setInputAudioDevice(*audioDevice);
auto audioDevice = ToolModel::findAudioDevice(device, linphone::AudioDevice::Capabilities::CapabilityRecord);
if (audioDevice) {
CoreModel::getInstance()->getCore()->setDefaultInputAudioDevice(audioDevice);
CoreModel::getInstance()->getCore()->setInputAudioDevice(audioDevice);
emit captureDeviceChanged(device);
resetCaptureGraph();
} else qWarning() << "Cannot set Capture device. The ID cannot be matched with an existant device : " << device;
@ -317,15 +313,10 @@ QString SettingsModel::getPlaybackDevice() const {
void SettingsModel::setPlaybackDevice(const QString &device) {
mustBeInLinphoneThread(log().arg(Q_FUNC_INFO));
std::string devId = Utils::appStringToCoreString(device);
auto list = CoreModel::getInstance()->getCore()->getExtendedAudioDevices();
auto audioDevice =
find_if(list.cbegin(), list.cend(),
[&](const std::shared_ptr<linphone::AudioDevice> &audioItem) { return audioItem->getId() == devId; });
if (audioDevice != list.cend()) {
CoreModel::getInstance()->getCore()->setDefaultOutputAudioDevice(*audioDevice);
CoreModel::getInstance()->getCore()->setOutputAudioDevice(*audioDevice);
auto audioDevice = ToolModel::findAudioDevice(device, linphone::AudioDevice::Capabilities::CapabilityPlay);
if (audioDevice) {
CoreModel::getInstance()->getCore()->setDefaultOutputAudioDevice(audioDevice);
CoreModel::getInstance()->getCore()->setOutputAudioDevice(audioDevice);
emit playbackDeviceChanged(device);
resetCaptureGraph();
} else qWarning() << "Cannot set Playback device. The ID cannot be matched with an existant device : " << device;
@ -340,14 +331,10 @@ QString SettingsModel::getRingerDevice() const {
void SettingsModel::setRingerDevice(const QString &device) {
mustBeInLinphoneThread(log().arg(Q_FUNC_INFO));
std::string devId = Utils::appStringToCoreString(device);
auto audioDevice = ToolModel::findAudioDevice(device, linphone::AudioDevice::Capabilities::CapabilityPlay);
auto list = CoreModel::getInstance()->getCore()->getExtendedAudioDevices();
auto audioDevice =
find_if(list.cbegin(), list.cend(),
[&](const std::shared_ptr<linphone::AudioDevice> &audioItem) { return audioItem->getId() == devId; });
if (audioDevice != list.cend()) {
CoreModel::getInstance()->getCore()->setRingerDevice(devId);
if (audioDevice) {
CoreModel::getInstance()->getCore()->setRingerDevice(audioDevice->getId());
emit ringerDeviceChanged(device);
} else qWarning() << "Cannot set Ringer device. The ID cannot be matched with an existant device : " << device;
}

View file

@ -56,12 +56,14 @@ std::shared_ptr<linphone::FriendPhoneNumber> ToolModel::makeLinphoneNumber(const
return linphoneNumber;
}
std::shared_ptr<linphone::AudioDevice> ToolModel::findAudioDevice(const QString &id) {
std::shared_ptr<linphone::AudioDevice> ToolModel::findAudioDevice(const QString &id,
linphone::AudioDevice::Capabilities capability) {
std::string devId = Utils::appStringToCoreString(id);
auto devices = CoreModel::getInstance()->getCore()->getExtendedAudioDevices();
auto audioDevice =
find_if(devices.cbegin(), devices.cend(),
[&](const std::shared_ptr<linphone::AudioDevice> &audioItem) { return audioItem->getId() == devId; });
find_if(devices.cbegin(), devices.cend(), [&](const std::shared_ptr<linphone::AudioDevice> &audioItem) {
return audioItem->hasCapability(capability) && audioItem->getId() == devId;
});
if (audioDevice != devices.cend()) {
return *audioDevice;
}

View file

@ -36,7 +36,8 @@ public:
static std::shared_ptr<linphone::Address> interpretUrl(const QString &address);
static std::shared_ptr<linphone::FriendPhoneNumber> makeLinphoneNumber(const QString &label, const QString &number);
static std::shared_ptr<linphone::AudioDevice> findAudioDevice(const QString &id);
static std::shared_ptr<linphone::AudioDevice> findAudioDevice(const QString &id,
linphone::AudioDevice::Capabilities capability);
static std::shared_ptr<linphone::Account> findAccount(const std::shared_ptr<const linphone::Address> &address);
static bool isMe(const QString &address);
static bool isLocal(const QString &address);