Browse Source

feat(settings): make audio quality setting persistent

reviewable/pr4697/r2
tox-user 8 years ago
parent
commit
7ed2d97aad
  1. 7
      src/core/coreav.cpp
  2. 1
      src/core/coreav.h
  3. 18
      src/persistence/settings.cpp
  4. 6
      src/persistence/settings.h
  5. 52
      src/widget/form/settings/avform.cpp
  6. 2
      src/widget/form/settings/avform.ui

7
src/core/coreav.cpp

@ -48,9 +48,6 @@ @@ -48,9 +48,6 @@
* @brief Sent when a call was ended by the peer.
* @param friendId Id of friend in call list.
*
* @var CoreAV::audioBitrate
* @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) @@ -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, audioBitrate, 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) @@ -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, audioBitrate, videoBitrate, nullptr))
if (!toxav_call(toxav, friendNum, Settings::getInstance().getAudioBitrate(), videoBitrate, nullptr))
return false;
auto call = calls.insert({friendNum, video, *this});

1
src/core/coreav.h

@ -81,7 +81,6 @@ public: @@ -81,7 +81,6 @@ public:
uint8_t channels, unsigned sample_rate, void* core);
static void invalidateGroupCallPeerSource(int group, int peer);
uint32_t audioBitrate = 64;
public slots:
bool startCall(uint32_t friendNum, bool video = false);
bool answerCall(uint32_t friendNum);

18
src/persistence/settings.cpp

@ -265,6 +265,7 @@ void Settings::loadGlobal() @@ -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() @@ -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) @@ -1882,6 +1884,22 @@ void Settings::setOutVolume(int volume)
}
}
int Settings::getAudioBitrate() const
{
QMutexLocker locker{&bigLock};
return audioBitrate;
}
void Settings::setAudioBitrate(int bitrate)
{
QMutexLocker locker{&bigLock};
if (bitrate != audioBitrate) {
audioBitrate = bitrate;
emit audioBitrateChanged(audioBitrate);
}
}
bool Settings::getEnableBackend2() const
{
QMutexLocker locker{&bigLock};

6
src/persistence/settings.h

@ -101,6 +101,7 @@ class Settings : public QObject @@ -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: @@ -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: @@ -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: @@ -631,6 +636,7 @@ private:
QString outDev;
bool audioOutDevEnabled;
int outVolume;
int audioBitrate;
bool enableTestSound;
bool enableBackend2;

52
src/widget/form/settings/avform.cpp

@ -83,6 +83,8 @@ AVForm::AVForm() @@ -83,6 +83,8 @@ AVForm::AVForm()
microphoneSlider->setTracking(false);
microphoneSlider->installEventFilter(this);
fillAudioQualityComboBox();
eventsInit();
QDesktopWidget* desktop = QApplication::desktop();
@ -121,7 +123,6 @@ void AVForm::showEvent(QShowEvent* event) @@ -121,7 +123,6 @@ void AVForm::showEvent(QShowEvent* event)
getAudioInDevices();
createVideoSurface();
getVideoDevices();
fillAudioQualityComboBox();
if (!subscribedToAudioIn) {
// TODO: This should not be done in show/hide events
@ -337,18 +338,25 @@ void AVForm::fillScreenModesComboBox() @@ -337,18 +338,25 @@ void AVForm::fillScreenModesComboBox()
void AVForm::fillAudioQualityComboBox()
{
bool previouslyBlocked = audioQualityComboBox->blockSignals(true);
audioQualityComboBox->clear();
QString name;
name = tr("High (64 kbps)");
audioQualityComboBox->addItem(name);
name = tr("Medium (32 kbps)");
audioQualityComboBox->addItem(name);
name = tr("Low (16 kbps)");
audioQualityComboBox->addItem(name);
name = tr("Very Low (8 kbps)");
audioQualityComboBox->addItem(name);
QStringList names;
names << tr("High (64 kbps)") << tr("Medium (32 kbps)") << tr("Low (16 kbps")
<< tr("Very low (8 kbps)");
audioQualityComboBox->addItems(names);
int currentBitrate = Settings::getInstance().getAudioBitrate();
QString currentBitrateString = QString::number(currentBitrate);
int index = 0;
for (int i = 0; i < names.length(); i++) {
QString name = names.at(i);
if (name.contains(currentBitrateString)) {
index = i;
break;
}
}
audioQualityComboBox->setCurrentIndex(index);
audioQualityComboBox->blockSignals(previouslyBlocked);
}
@ -429,23 +437,9 @@ void AVForm::on_videoDevCombobox_currentIndexChanged(int index) @@ -429,23 +437,9 @@ void AVForm::on_videoDevCombobox_currentIndexChanged(int index)
void AVForm::on_audioQualityComboBox_currentIndexChanged(int index)
{
uint32_t bitrate;
switch (index) {
case 1:
bitrate = 32;
break;
case 2:
bitrate = 16;
break;
case 3:
bitrate = 8;
break;
default:
bitrate = 64;
break;
}
Core::getInstance()->getAv()->audioBitrate = bitrate;
int bitrates[] = { 64, 32, 16, 8 };
int bitrate = bitrates[index];
Settings::getInstance().setAudioBitrate(bitrate);
}
void AVForm::getVideoDevices()

2
src/widget/form/settings/avform.ui

@ -111,7 +111,7 @@ @@ -111,7 +111,7 @@
<item row="4" column="0">
<widget class="QLabel" name="audioQualityLabel">
<property name="text">
<string>Audio Quality</string>
<string>Audio quality</string>
</property>
</widget>
</item>

Loading…
Cancel
Save