diff --git a/src/core/coreav.cpp b/src/core/coreav.cpp index 80dca7eb4..4edd8b7c3 100644 --- a/src/core/coreav.cpp +++ b/src/core/coreav.cpp @@ -48,9 +48,6 @@ * @brief Sent when a call was ended by the peer. * @param friendId Id of friend in call list. * - * @var CoreAV::AUDIO_DEFAULT_BITRATE - * @brief In kb/s. More than enough for Opus. - * * @var CoreAV::VIDEO_DEFAULT_BITRATE * @brief Picked at random by fair dice roll. */ @@ -236,7 +233,7 @@ bool CoreAV::answerCall(uint32_t friendNum) qDebug() << QString("answering call %1").arg(friendNum); assert(calls.contains(friendNum)); TOXAV_ERR_ANSWER err; - if (toxav_answer(toxav, friendNum, AUDIO_DEFAULT_BITRATE, VIDEO_DEFAULT_BITRATE, &err)) { + if (toxav_answer(toxav, friendNum, Settings::getInstance().getAudioBitrate(), VIDEO_DEFAULT_BITRATE, &err)) { calls[friendNum].inactive = false; return true; } else { @@ -271,7 +268,7 @@ bool CoreAV::startCall(uint32_t friendNum, bool video) } uint32_t videoBitrate = video ? VIDEO_DEFAULT_BITRATE : 0; - if (!toxav_call(toxav, friendNum, AUDIO_DEFAULT_BITRATE, videoBitrate, nullptr)) + if (!toxav_call(toxav, friendNum, Settings::getInstance().getAudioBitrate(), videoBitrate, nullptr)) return false; auto call = calls.insert({friendNum, video, *this}); diff --git a/src/core/coreav.h b/src/core/coreav.h index 843e3c400..e7e56ab17 100644 --- a/src/core/coreav.h +++ b/src/core/coreav.h @@ -111,7 +111,6 @@ private: int32_t ystride, int32_t ustride, int32_t vstride, void* self); private: - static constexpr uint32_t AUDIO_DEFAULT_BITRATE = 64; static constexpr uint32_t VIDEO_DEFAULT_BITRATE = 6144; private: diff --git a/src/persistence/settings.cpp b/src/persistence/settings.cpp index 57d7f9142..361b0ce63 100644 --- a/src/persistence/settings.cpp +++ b/src/persistence/settings.cpp @@ -265,6 +265,7 @@ void Settings::loadGlobal() audioOutDevEnabled = s.value("audioOutDevEnabled", true).toBool(); audioInGainDecibel = s.value("inGain", 0).toReal(); outVolume = s.value("outVolume", 100).toInt(); + audioBitrate = s.value("audioBitrate", 64).toInt(); enableBackend2 = false; #ifdef USE_FILTERAUDIO enableBackend2 = s.value("enableBackend2", false).toBool(); @@ -566,6 +567,7 @@ void Settings::saveGlobal() s.setValue("audioOutDevEnabled", audioOutDevEnabled); s.setValue("inGain", audioInGainDecibel); s.setValue("outVolume", outVolume); + s.setValue("audioBitrate", audioBitrate); s.setValue("enableBackend2", enableBackend2); } s.endGroup(); @@ -1882,6 +1884,22 @@ void Settings::setOutVolume(int volume) } } +int Settings::getAudioBitrate() const +{ + const QMutexLocker locker{&bigLock}; + return audioBitrate; +} + +void Settings::setAudioBitrate(int bitrate) +{ + const QMutexLocker locker{&bigLock}; + + if (bitrate != audioBitrate) { + audioBitrate = bitrate; + emit audioBitrateChanged(audioBitrate); + } +} + bool Settings::getEnableBackend2() const { QMutexLocker locker{&bigLock}; diff --git a/src/persistence/settings.h b/src/persistence/settings.h index c3edc2d52..4c1408eb0 100644 --- a/src/persistence/settings.h +++ b/src/persistence/settings.h @@ -101,6 +101,7 @@ class Settings : public QObject Q_PROPERTY(bool audioOutDevEnabled READ getAudioOutDevEnabled WRITE setAudioOutDevEnabled NOTIFY audioOutDevEnabledChanged FINAL) Q_PROPERTY(int outVolume READ getOutVolume WRITE setOutVolume NOTIFY outVolumeChanged FINAL) + Q_PROPERTY(int audioBitrate READ getAudioBitrate WRITE setAudioBitrate NOTIFY audioBitrateChanged FINAL) Q_PROPERTY(bool enableBackend2 READ getEnableBackend2 WRITE setEnableBackend2 NOTIFY enableBackend2Changed FINAL) @@ -241,6 +242,7 @@ signals: void outDevChanged(const QString& name); void audioOutDevEnabledChanged(bool enabled); void outVolumeChanged(int volume); + void audioBitrateChanged(int bitrate); void enableTestSoundChanged(bool enabled); void enableBackend2Changed(bool enabled); @@ -369,6 +371,9 @@ public: int getOutVolume() const; void setOutVolume(int volume); + int getAudioBitrate() const; + void setAudioBitrate(int bitrate); + bool getEnableTestSound() const; void setEnableTestSound(bool newValue); @@ -631,6 +636,7 @@ private: QString outDev; bool audioOutDevEnabled; int outVolume; + int audioBitrate; bool enableTestSound; bool enableBackend2; diff --git a/src/widget/form/settings/avform.cpp b/src/widget/form/settings/avform.cpp index 22800b6eb..3fe283cdd 100644 --- a/src/widget/form/settings/avform.cpp +++ b/src/widget/form/settings/avform.cpp @@ -83,6 +83,8 @@ AVForm::AVForm() microphoneSlider->setTracking(false); microphoneSlider->installEventFilter(this); + fillAudioQualityComboBox(); + eventsInit(); QDesktopWidget* desktop = QApplication::desktop(); @@ -333,6 +335,22 @@ void AVForm::fillScreenModesComboBox() videoModescomboBox->blockSignals(previouslyBlocked); } +void AVForm::fillAudioQualityComboBox() +{ + const bool previouslyBlocked = audioQualityComboBox->blockSignals(true); + + audioQualityComboBox->addItem(tr("High (64 kbps)"), 64); + audioQualityComboBox->addItem(tr("Medium (32 kbps)"), 32); + audioQualityComboBox->addItem(tr("Low (16 kbps)"), 16); + audioQualityComboBox->addItem(tr("Very low (8 kbps)"), 8); + + const int currentBitrate = Settings::getInstance().getAudioBitrate(); + const int index = audioQualityComboBox->findData(currentBitrate); + + audioQualityComboBox->setCurrentIndex(index); + audioQualityComboBox->blockSignals(previouslyBlocked); +} + void AVForm::updateVideoModes(int curIndex) { if (curIndex < 0 || curIndex >= videoDeviceList.size()) { @@ -408,6 +426,11 @@ void AVForm::on_videoDevCombobox_currentIndexChanged(int index) Core::getInstance()->getAv()->sendNoVideo(); } +void AVForm::on_audioQualityComboBox_currentIndexChanged(int index) +{ + Settings::getInstance().setAudioBitrate(audioQualityComboBox->currentData().toInt()); +} + void AVForm::getVideoDevices() { QString settingsInDev = Settings::getInstance().getVideoDev(); diff --git a/src/widget/form/settings/avform.h b/src/widget/form/settings/avform.h index 21359813b..ec5b70c67 100644 --- a/src/widget/form/settings/avform.h +++ b/src/widget/form/settings/avform.h @@ -52,6 +52,7 @@ private: void selectBestModes(QVector& allVideoModes); void fillCameraModesComboBox(); void fillScreenModesComboBox(); + void fillAudioQualityComboBox(); int searchPreferredIndex(); void createVideoSurface(); @@ -66,6 +67,7 @@ private slots: void on_playbackSlider_valueChanged(int value); void on_cbEnableTestSound_stateChanged(); void on_microphoneSlider_valueChanged(int value); + void on_audioQualityComboBox_currentIndexChanged(int index); // camera void on_videoDevCombobox_currentIndexChanged(int index); diff --git a/src/widget/form/settings/avform.ui b/src/widget/form/settings/avform.ui index e0ed33f9b..a231f7b7a 100644 --- a/src/widget/form/settings/avform.ui +++ b/src/widget/form/settings/avform.ui @@ -108,7 +108,27 @@ - + + + + Audio quality + + + + + + + + 0 + 0 + + + + Transmitted audio quality. Lower this setting if your bandwidth is not high enough or if you want to lower the internet usage. + + + + true