mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
feat(settings): make audio quality setting persistent
This commit is contained in:
parent
61eddc1f6b
commit
7ed2d97aad
|
@ -48,9 +48,6 @@
|
||||||
* @brief Sent when a call was ended by the peer.
|
* @brief Sent when a call was ended by the peer.
|
||||||
* @param friendId Id of friend in call list.
|
* @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
|
* @var CoreAV::VIDEO_DEFAULT_BITRATE
|
||||||
* @brief Picked at random by fair dice roll.
|
* @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);
|
qDebug() << QString("answering call %1").arg(friendNum);
|
||||||
assert(calls.contains(friendNum));
|
assert(calls.contains(friendNum));
|
||||||
TOXAV_ERR_ANSWER err;
|
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;
|
calls[friendNum].inactive = false;
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
|
@ -271,7 +268,7 @@ bool CoreAV::startCall(uint32_t friendNum, bool video)
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t videoBitrate = video ? VIDEO_DEFAULT_BITRATE : 0;
|
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;
|
return false;
|
||||||
|
|
||||||
auto call = calls.insert({friendNum, video, *this});
|
auto call = calls.insert({friendNum, video, *this});
|
||||||
|
|
|
@ -81,7 +81,6 @@ public:
|
||||||
uint8_t channels, unsigned sample_rate, void* core);
|
uint8_t channels, unsigned sample_rate, void* core);
|
||||||
static void invalidateGroupCallPeerSource(int group, int peer);
|
static void invalidateGroupCallPeerSource(int group, int peer);
|
||||||
|
|
||||||
uint32_t audioBitrate = 64;
|
|
||||||
public slots:
|
public slots:
|
||||||
bool startCall(uint32_t friendNum, bool video = false);
|
bool startCall(uint32_t friendNum, bool video = false);
|
||||||
bool answerCall(uint32_t friendNum);
|
bool answerCall(uint32_t friendNum);
|
||||||
|
|
|
@ -265,6 +265,7 @@ void Settings::loadGlobal()
|
||||||
audioOutDevEnabled = s.value("audioOutDevEnabled", true).toBool();
|
audioOutDevEnabled = s.value("audioOutDevEnabled", true).toBool();
|
||||||
audioInGainDecibel = s.value("inGain", 0).toReal();
|
audioInGainDecibel = s.value("inGain", 0).toReal();
|
||||||
outVolume = s.value("outVolume", 100).toInt();
|
outVolume = s.value("outVolume", 100).toInt();
|
||||||
|
audioBitrate = s.value("audioBitrate", 64).toInt();
|
||||||
enableBackend2 = false;
|
enableBackend2 = false;
|
||||||
#ifdef USE_FILTERAUDIO
|
#ifdef USE_FILTERAUDIO
|
||||||
enableBackend2 = s.value("enableBackend2", false).toBool();
|
enableBackend2 = s.value("enableBackend2", false).toBool();
|
||||||
|
@ -566,6 +567,7 @@ void Settings::saveGlobal()
|
||||||
s.setValue("audioOutDevEnabled", audioOutDevEnabled);
|
s.setValue("audioOutDevEnabled", audioOutDevEnabled);
|
||||||
s.setValue("inGain", audioInGainDecibel);
|
s.setValue("inGain", audioInGainDecibel);
|
||||||
s.setValue("outVolume", outVolume);
|
s.setValue("outVolume", outVolume);
|
||||||
|
s.setValue("audioBitrate", audioBitrate);
|
||||||
s.setValue("enableBackend2", enableBackend2);
|
s.setValue("enableBackend2", enableBackend2);
|
||||||
}
|
}
|
||||||
s.endGroup();
|
s.endGroup();
|
||||||
|
@ -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
|
bool Settings::getEnableBackend2() const
|
||||||
{
|
{
|
||||||
QMutexLocker locker{&bigLock};
|
QMutexLocker locker{&bigLock};
|
||||||
|
|
|
@ -101,6 +101,7 @@ class Settings : public QObject
|
||||||
Q_PROPERTY(bool audioOutDevEnabled READ getAudioOutDevEnabled WRITE setAudioOutDevEnabled NOTIFY
|
Q_PROPERTY(bool audioOutDevEnabled READ getAudioOutDevEnabled WRITE setAudioOutDevEnabled NOTIFY
|
||||||
audioOutDevEnabledChanged FINAL)
|
audioOutDevEnabledChanged FINAL)
|
||||||
Q_PROPERTY(int outVolume READ getOutVolume WRITE setOutVolume NOTIFY outVolumeChanged 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
|
Q_PROPERTY(bool enableBackend2 READ getEnableBackend2 WRITE setEnableBackend2 NOTIFY
|
||||||
enableBackend2Changed FINAL)
|
enableBackend2Changed FINAL)
|
||||||
|
|
||||||
|
@ -241,6 +242,7 @@ signals:
|
||||||
void outDevChanged(const QString& name);
|
void outDevChanged(const QString& name);
|
||||||
void audioOutDevEnabledChanged(bool enabled);
|
void audioOutDevEnabledChanged(bool enabled);
|
||||||
void outVolumeChanged(int volume);
|
void outVolumeChanged(int volume);
|
||||||
|
void audioBitrateChanged(int bitrate);
|
||||||
void enableTestSoundChanged(bool enabled);
|
void enableTestSoundChanged(bool enabled);
|
||||||
void enableBackend2Changed(bool enabled);
|
void enableBackend2Changed(bool enabled);
|
||||||
|
|
||||||
|
@ -369,6 +371,9 @@ public:
|
||||||
int getOutVolume() const;
|
int getOutVolume() const;
|
||||||
void setOutVolume(int volume);
|
void setOutVolume(int volume);
|
||||||
|
|
||||||
|
int getAudioBitrate() const;
|
||||||
|
void setAudioBitrate(int bitrate);
|
||||||
|
|
||||||
bool getEnableTestSound() const;
|
bool getEnableTestSound() const;
|
||||||
void setEnableTestSound(bool newValue);
|
void setEnableTestSound(bool newValue);
|
||||||
|
|
||||||
|
@ -631,6 +636,7 @@ private:
|
||||||
QString outDev;
|
QString outDev;
|
||||||
bool audioOutDevEnabled;
|
bool audioOutDevEnabled;
|
||||||
int outVolume;
|
int outVolume;
|
||||||
|
int audioBitrate;
|
||||||
bool enableTestSound;
|
bool enableTestSound;
|
||||||
bool enableBackend2;
|
bool enableBackend2;
|
||||||
|
|
||||||
|
|
|
@ -83,6 +83,8 @@ AVForm::AVForm()
|
||||||
microphoneSlider->setTracking(false);
|
microphoneSlider->setTracking(false);
|
||||||
microphoneSlider->installEventFilter(this);
|
microphoneSlider->installEventFilter(this);
|
||||||
|
|
||||||
|
fillAudioQualityComboBox();
|
||||||
|
|
||||||
eventsInit();
|
eventsInit();
|
||||||
|
|
||||||
QDesktopWidget* desktop = QApplication::desktop();
|
QDesktopWidget* desktop = QApplication::desktop();
|
||||||
|
@ -121,7 +123,6 @@ void AVForm::showEvent(QShowEvent* event)
|
||||||
getAudioInDevices();
|
getAudioInDevices();
|
||||||
createVideoSurface();
|
createVideoSurface();
|
||||||
getVideoDevices();
|
getVideoDevices();
|
||||||
fillAudioQualityComboBox();
|
|
||||||
|
|
||||||
if (!subscribedToAudioIn) {
|
if (!subscribedToAudioIn) {
|
||||||
// TODO: This should not be done in show/hide events
|
// TODO: This should not be done in show/hide events
|
||||||
|
@ -337,18 +338,25 @@ void AVForm::fillScreenModesComboBox()
|
||||||
void AVForm::fillAudioQualityComboBox()
|
void AVForm::fillAudioQualityComboBox()
|
||||||
{
|
{
|
||||||
bool previouslyBlocked = audioQualityComboBox->blockSignals(true);
|
bool previouslyBlocked = audioQualityComboBox->blockSignals(true);
|
||||||
audioQualityComboBox->clear();
|
|
||||||
|
|
||||||
QString name;
|
QStringList names;
|
||||||
name = tr("High (64 kbps)");
|
names << tr("High (64 kbps)") << tr("Medium (32 kbps)") << tr("Low (16 kbps")
|
||||||
audioQualityComboBox->addItem(name);
|
<< tr("Very low (8 kbps)");
|
||||||
name = tr("Medium (32 kbps)");
|
audioQualityComboBox->addItems(names);
|
||||||
audioQualityComboBox->addItem(name);
|
|
||||||
name = tr("Low (16 kbps)");
|
|
||||||
audioQualityComboBox->addItem(name);
|
|
||||||
name = tr("Very Low (8 kbps)");
|
|
||||||
audioQualityComboBox->addItem(name);
|
|
||||||
|
|
||||||
|
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);
|
audioQualityComboBox->blockSignals(previouslyBlocked);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -429,23 +437,9 @@ void AVForm::on_videoDevCombobox_currentIndexChanged(int index)
|
||||||
|
|
||||||
void AVForm::on_audioQualityComboBox_currentIndexChanged(int index)
|
void AVForm::on_audioQualityComboBox_currentIndexChanged(int index)
|
||||||
{
|
{
|
||||||
uint32_t bitrate;
|
int bitrates[] = { 64, 32, 16, 8 };
|
||||||
switch (index) {
|
int bitrate = bitrates[index];
|
||||||
case 1:
|
Settings::getInstance().setAudioBitrate(bitrate);
|
||||||
bitrate = 32;
|
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
bitrate = 16;
|
|
||||||
break;
|
|
||||||
case 3:
|
|
||||||
bitrate = 8;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
bitrate = 64;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
Core::getInstance()->getAv()->audioBitrate = bitrate;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void AVForm::getVideoDevices()
|
void AVForm::getVideoDevices()
|
||||||
|
|
|
@ -111,7 +111,7 @@
|
||||||
<item row="4" column="0">
|
<item row="4" column="0">
|
||||||
<widget class="QLabel" name="audioQualityLabel">
|
<widget class="QLabel" name="audioQualityLabel">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Audio Quality</string>
|
<string>Audio quality</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
|
Loading…
Reference in New Issue
Block a user