Skip to content
This repository has been archived by the owner on Feb 12, 2023. It is now read-only.

Commit

Permalink
feat(settings): make audio quality setting persistent
Browse files Browse the repository at this point in the history
  • Loading branch information
tox-user committed Sep 29, 2017
1 parent 61eddc1 commit 7ed2d97
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 36 deletions.
7 changes: 2 additions & 5 deletions src/core/coreav.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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});
Expand Down
1 change: 0 additions & 1 deletion src/core/coreav.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ class CoreAV : public QObject
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);
Expand Down
18 changes: 18 additions & 0 deletions src/persistence/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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};
Expand Down
6 changes: 6 additions & 0 deletions src/persistence/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -241,6 +242,7 @@ public slots:
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);

Expand Down Expand Up @@ -369,6 +371,9 @@ public slots:
int getOutVolume() const;
void setOutVolume(int volume);

int getAudioBitrate() const;
void setAudioBitrate(int bitrate);

bool getEnableTestSound() const;
void setEnableTestSound(bool newValue);

Expand Down Expand Up @@ -631,6 +636,7 @@ public slots:
QString outDev;
bool audioOutDevEnabled;
int outVolume;
int audioBitrate;
bool enableTestSound;
bool enableBackend2;

Expand Down
52 changes: 23 additions & 29 deletions src/widget/form/settings/avform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ AVForm::AVForm()
microphoneSlider->setTracking(false);
microphoneSlider->installEventFilter(this);

fillAudioQualityComboBox();

eventsInit();

QDesktopWidget* desktop = QApplication::desktop();
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion src/widget/form/settings/avform.ui
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down

0 comments on commit 7ed2d97

Please sign in to comment.