Skip to content

Commit

Permalink
Volume control for media playback
Browse files Browse the repository at this point in the history
  • Loading branch information
bear101 committed Sep 11, 2024
1 parent b1fb059 commit 7622674
Show file tree
Hide file tree
Showing 9 changed files with 162 additions and 40 deletions.
2 changes: 1 addition & 1 deletion Client/qtTeamTalk/audiopreprocessordlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ AudioPreprocessorDlg::AudioPreprocessorDlg(AudioPreprocessor preprocess, QWidget
ui.gainlevelSlider->setRange(SOUND_GAIN_MIN, SOUND_GAIN_MAX);

// SpeexDSP audio preprocessor
ui.gainlevelSpinBox->setRange(0, 0x7FFF);
ui.gainlevelSpinBox->setRange(SPEEXDSP_AGC_GAINLEVEL_MIN, SPEEXDSP_AGC_GAINLEVEL_MAX);
ui.maxdecSpinBox->setRange(-100, 0);
ui.maxdenoiseSpinBox->setRange(-100, 0);

Expand Down
35 changes: 35 additions & 0 deletions Client/qtTeamTalk/common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,41 @@ AudioPreprocessor loadAudioPreprocessor(AudioPreprocessorType preprocessortype)
return preprocessor;
}

void saveAudioPreprocessor(const AudioPreprocessor& preprocessor)
{
ttSettings->setValue(SETTINGS_STREAMMEDIA_AUDIOPREPROCESSOR, preprocessor.nPreprocessor);
switch (preprocessor.nPreprocessor)
{
case NO_AUDIOPREPROCESSOR:
break;
case SPEEXDSP_AUDIOPREPROCESSOR:
ttSettings->setValue(SETTINGS_STREAMMEDIA_SPX_AGC_ENABLE, preprocessor.speexdsp.bEnableAGC);
ttSettings->setValue(SETTINGS_STREAMMEDIA_SPX_AGC_GAINLEVEL, preprocessor.speexdsp.nGainLevel);
ttSettings->setValue(SETTINGS_STREAMMEDIA_SPX_AGC_INC_MAXDB, preprocessor.speexdsp.nMaxIncDBSec);
ttSettings->setValue(SETTINGS_STREAMMEDIA_SPX_AGC_DEC_MAXDB, preprocessor.speexdsp.nMaxDecDBSec);
ttSettings->setValue(SETTINGS_STREAMMEDIA_SPX_AGC_GAINMAXDB, preprocessor.speexdsp.nMaxGainDB);
ttSettings->setValue(SETTINGS_STREAMMEDIA_SPX_DENOISE_ENABLE, preprocessor.speexdsp.bEnableDenoise);
ttSettings->setValue(SETTINGS_STREAMMEDIA_SPX_DENOISE_SUPPRESS, preprocessor.speexdsp.nMaxNoiseSuppressDB);
break;
case TEAMTALK_AUDIOPREPROCESSOR:
ttSettings->setValue(SETTINGS_STREAMMEDIA_TTAP_MUTELEFT, preprocessor.ttpreprocessor.bMuteLeftSpeaker);
ttSettings->setValue(SETTINGS_STREAMMEDIA_TTAP_MUTERIGHT, preprocessor.ttpreprocessor.bMuteRightSpeaker);
ttSettings->setValue(SETTINGS_STREAMMEDIA_TTAP_GAINLEVEL, preprocessor.ttpreprocessor.nGainLevel);
break;
case WEBRTC_AUDIOPREPROCESSOR :
ttSettings->setValue(SETTINGS_STREAMMEDIA_WEBRTC_GAINCTL_ENABLE, preprocessor.webrtc.gaincontroller2.bEnable);
ttSettings->setValue(SETTINGS_STREAMMEDIA_WEBRTC_GAINDB, preprocessor.webrtc.gaincontroller2.fixeddigital.fGainDB);
ttSettings->setValue(SETTINGS_STREAMMEDIA_WEBRTC_SAT_PROT_ENABLE, preprocessor.webrtc.gaincontroller2.adaptivedigital.bEnable );
ttSettings->setValue(SETTINGS_STREAMMEDIA_WEBRTC_INIT_SAT_MARGIN_DB, preprocessor.webrtc.gaincontroller2.adaptivedigital.fInitialSaturationMarginDB);
ttSettings->setValue(SETTINGS_STREAMMEDIA_WEBRTC_EXTRA_SAT_MARGIN_DB, preprocessor.webrtc.gaincontroller2.adaptivedigital.fExtraSaturationMarginDB);
ttSettings->setValue(SETTINGS_STREAMMEDIA_WEBRTC_MAXGAIN_DBSEC, preprocessor.webrtc.gaincontroller2.adaptivedigital.fMaxGainChangeDBPerSecond);
ttSettings->setValue(SETTINGS_STREAMMEDIA_WEBRTC_MAX_OUT_NOISE, preprocessor.webrtc.gaincontroller2.adaptivedigital.fMaxOutputNoiseLevelDBFS);
ttSettings->setValue(SETTINGS_STREAMMEDIA_WEBRTC_NOISESUPPRESS_ENABLE, preprocessor.webrtc.noisesuppression.bEnable);
ttSettings->setValue(SETTINGS_STREAMMEDIA_WEBRTC_NOISESUPPRESS_LEVEL, preprocessor.webrtc.noisesuppression.nLevel);
break;
}
}

bool isWebLogin(const QString& username, bool includeParentLoginName)
{
if (username.endsWith(WEBLOGIN_BEARWARE_USERNAMEPOSTFIX, Qt::CaseInsensitive))
Expand Down
1 change: 1 addition & 0 deletions Client/qtTeamTalk/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ bool hasDesktopAccess(const QVector<DesktopAccessEntry>& entries,
void deleteDesktopAccessEntries();

AudioPreprocessor loadAudioPreprocessor(AudioPreprocessorType preprocessortype);
void saveAudioPreprocessor(const AudioPreprocessor& preprocess);

bool isWebLogin(const QString& username, bool includeParentLoginName);
QString userCacheID(const User& user);
Expand Down
59 changes: 57 additions & 2 deletions Client/qtTeamTalk/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,7 @@ MainWindow::MainWindow(const QString& cfgfile)
});
connect(ui.stopMediaFileButton, &QAbstractButton::clicked, this,
&MainWindow::stopStreamMediaFile);
connect(ui.mediaVolumeSlider, &QSlider::sliderMoved, this, &MainWindow::changeMediaFileVolume);

/* Files-tab */
connect(ui.uploadButton, &QAbstractButton::clicked, this, &MainWindow::slotChannelsUploadFile);
Expand Down Expand Up @@ -2131,6 +2132,7 @@ void MainWindow::disconnectFromServer()
m_mychannel = {};
m_myuseraccount = {};
relayAudioStream(0, STREAMTYPE_NONE, false);
stopStreamMediaFile();

m_useraccounts.clear();
m_bannedusers.clear();
Expand Down Expand Up @@ -5399,11 +5401,15 @@ void MainWindow::stopStreamMediaFile()

m_statusmode &= ~(STATUSMODE_STREAM_MEDIAFILE | STATUSMODE_STREAM_MEDIAFILE_PAUSED);

QString statusmsg = ttSettings->value(SETTINGS_GENERAL_STATUSMESSAGE).toString();
TT_DoChangeStatus(ttInst, m_statusmode, _W(statusmsg));
if (TT_GetFlags(ttInst) & CLIENT_AUTHORIZED)
{
QString statusmsg = ttSettings->value(SETTINGS_GENERAL_STATUSMESSAGE).toString();
TT_DoChangeStatus(ttInst, m_statusmode, _W(statusmsg));
}

m_mfi.reset();
m_mfp = {};
ttSettings->remove(SETTINGS_STREAMMEDIA_OFFSET);

slotUpdateUI();
slotUpdateMediaTabUI();
Expand Down Expand Up @@ -5466,6 +5472,35 @@ void MainWindow::changeMediaFileOffset(int pos)
m_timers.insert(startTimer(500), TIMER_CHANGE_MEDIAFILE_POSITION);
}

void MainWindow::changeMediaFileVolume(int pos)
{
switch (m_mfp.audioPreprocessor.nPreprocessor)
{
case TEAMTALK_AUDIOPREPROCESSOR :
if (m_mfp.audioPreprocessor.ttpreprocessor.nGainLevel == pos)
return;
m_mfp.audioPreprocessor.ttpreprocessor.nGainLevel = pos;
break;
case SPEEXDSP_AUDIOPREPROCESSOR :
if (m_mfp.audioPreprocessor.speexdsp.nGainLevel == pos)
return;
m_mfp.audioPreprocessor.speexdsp.nGainLevel = pos;
break;
case WEBRTC_AUDIOPREPROCESSOR :
case NO_AUDIOPREPROCESSOR :
return;
}

saveAudioPreprocessor(m_mfp.audioPreprocessor);

m_mfp.uOffsetMSec = TT_MEDIAPLAYBACK_OFFSET_IGNORE;
if (!TT_UpdateStreamingMediaFileToChannel(ttInst, &m_mfp, &m_mfp_videocodec))
{
QMessageBox::critical(this, MENUTEXT(ui.actionPauseResumeStream->text()), tr("Failed to change volume of the stream"));
stopStreamMediaFile();
}
}

void MainWindow::setMediaFilePosition()
{
if (!m_mfi)
Expand All @@ -5480,6 +5515,7 @@ void MainWindow::setMediaFilePosition()
{
QMessageBox::critical(this, MENUTEXT(ui.actionPauseResumeStream->text()), tr("Failed to change playback position"));
}
ttSettings->setValue(SETTINGS_STREAMMEDIA_OFFSET, m_mfp.uOffsetMSec);
}

void MainWindow::slotChannelsUploadFile(bool /*checked =false */)
Expand Down Expand Up @@ -6358,6 +6394,25 @@ void MainWindow::slotUpdateMediaTabUI()
ui.videoLabel->setText("");
break;
}

// init volume slider for media streaming
switch (m_mfp.audioPreprocessor.nPreprocessor) {
case SPEEXDSP_AUDIOPREPROCESSOR :
ui.mediaVolumeSlider->setEnabled(true);
ui.mediaVolumeSlider->setRange(SPEEXDSP_AGC_GAINLEVEL_MIN, SPEEXDSP_AGC_GAINLEVEL_MAX);
ui.mediaVolumeSlider->setValue(m_mfp.audioPreprocessor.speexdsp.nGainLevel);
break;
case TEAMTALK_AUDIOPREPROCESSOR :
ui.mediaVolumeSlider->setEnabled(true);
ui.mediaVolumeSlider->setRange(SOUND_GAIN_MIN, SOUND_GAIN_MAX);
ui.mediaVolumeSlider->setValue(m_mfp.audioPreprocessor.ttpreprocessor.nGainLevel);
break;
case NO_AUDIOPREPROCESSOR :
case WEBRTC_AUDIOPREPROCESSOR :
ui.mediaVolumeSlider->setEnabled(false);
ui.mediaVolumeSlider->setValue(0);
break;
}
}

void MainWindow::slotUpdateVideoTabUI()
Expand Down
1 change: 1 addition & 0 deletions Client/qtTeamTalk/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,7 @@ class MainWindow : public QMainWindow
void startStreamMediaFile();
void stopStreamMediaFile();
void changeMediaFileOffset(int pos);
void changeMediaFileVolume(int pos);
void setMediaFilePosition();
void loadHotKeys();
void enableHotKey(HotKeyID id, const hotkey_t& hk);
Expand Down
39 changes: 38 additions & 1 deletion Client/qtTeamTalk/mainwindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,7 @@
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_11">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_7">
<layout class="QHBoxLayout" name="horizontalLayout_7" stretch="0,10,1,0">
<item>
<widget class="QLabel" name="label_6">
<property name="text">
Expand All @@ -539,8 +539,27 @@
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Orientation::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="playbackTimeLabel">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string notr="true">0:00:00.000</string>
</property>
Expand Down Expand Up @@ -597,6 +616,24 @@
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_12">
<item>
<widget class="QLabel" name="label_8">
<property name="text">
<string>Volume</string>
</property>
</widget>
</item>
<item>
<widget class="QSlider" name="mediaVolumeSlider">
<property name="orientation">
<enum>Qt::Orientation::Horizontal</enum>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_9" stretch="0,1">
<item>
Expand Down
38 changes: 25 additions & 13 deletions Client/qtTeamTalk/streammediafile.ui
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>511</width>
<height>523</height>
<height>527</height>
</rect>
</property>
<property name="windowTitle">
Expand Down Expand Up @@ -124,7 +124,7 @@
<string/>
</property>
<property name="textInteractionFlags">
<set>Qt::LinksAccessibleByKeyboard|Qt::LinksAccessibleByMouse|Qt::TextBrowserInteraction|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse</set>
<set>Qt::TextInteractionFlag::LinksAccessibleByKeyboard|Qt::TextInteractionFlag::LinksAccessibleByMouse|Qt::TextInteractionFlag::TextBrowserInteraction|Qt::TextInteractionFlag::TextSelectableByKeyboard|Qt::TextInteractionFlag::TextSelectableByMouse</set>
</property>
</widget>
</item>
Expand All @@ -145,7 +145,7 @@
<string/>
</property>
<property name="textInteractionFlags">
<set>Qt::LinksAccessibleByKeyboard|Qt::LinksAccessibleByMouse|Qt::TextBrowserInteraction|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse</set>
<set>Qt::TextInteractionFlag::LinksAccessibleByKeyboard|Qt::TextInteractionFlag::LinksAccessibleByMouse|Qt::TextInteractionFlag::TextBrowserInteraction|Qt::TextInteractionFlag::TextSelectableByKeyboard|Qt::TextInteractionFlag::TextSelectableByMouse</set>
</property>
</widget>
</item>
Expand All @@ -166,7 +166,7 @@
<string/>
</property>
<property name="textInteractionFlags">
<set>Qt::LinksAccessibleByKeyboard|Qt::LinksAccessibleByMouse|Qt::TextBrowserInteraction|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse</set>
<set>Qt::TextInteractionFlag::LinksAccessibleByKeyboard|Qt::TextInteractionFlag::LinksAccessibleByMouse|Qt::TextInteractionFlag::TextBrowserInteraction|Qt::TextInteractionFlag::TextSelectableByKeyboard|Qt::TextInteractionFlag::TextSelectableByMouse</set>
</property>
</widget>
</item>
Expand Down Expand Up @@ -216,7 +216,7 @@
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
<enum>Qt::Orientation::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
Expand All @@ -229,7 +229,7 @@
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_6">
<layout class="QHBoxLayout" name="horizontalLayout_6" stretch="0,10,1,0">
<item>
<widget class="QLabel" name="label_6">
<property name="text">
Expand All @@ -243,10 +243,23 @@
<string>Start position</string>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
<enum>Qt::Orientation::Horizontal</enum>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_4">
<property name="orientation">
<enum>Qt::Orientation::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="playbackTimeLabel">
<property name="text">
Expand Down Expand Up @@ -296,7 +309,7 @@
<item>
<spacer name="horizontalSpacer_3">
<property name="orientation">
<enum>Qt::Horizontal</enum>
<enum>Qt::Orientation::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
Expand Down Expand Up @@ -351,7 +364,7 @@
<item>
<spacer name="horizontalSpacer_21">
<property name="orientation">
<enum>Qt::Horizontal</enum>
<enum>Qt::Orientation::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
Expand Down Expand Up @@ -423,7 +436,7 @@
<item>
<spacer name="horizontalSpacer_22">
<property name="orientation">
<enum>Qt::Horizontal</enum>
<enum>Qt::Orientation::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
Expand All @@ -445,7 +458,7 @@
<item>
<spacer name="verticalSpacer_9">
<property name="orientation">
<enum>Qt::Vertical</enum>
<enum>Qt::Orientation::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
Expand All @@ -460,7 +473,7 @@
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
<enum>Qt::Orientation::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
Expand Down Expand Up @@ -497,7 +510,6 @@
</customwidgets>
<resources>
<include location="resources.qrc"/>
<include location="resources.qrc"/>
</resources>
<connections>
<connection>
Expand Down
24 changes: 1 addition & 23 deletions Client/qtTeamTalk/streammediafiledlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -340,29 +340,7 @@ void StreamMediaFileDlg::slotSetupPreprocessor(bool)
{
m_mfp.audioPreprocessor = dlg.m_preprocess;

ttSettings->setValue(SETTINGS_STREAMMEDIA_AUDIOPREPROCESSOR, m_mfp.audioPreprocessor.nPreprocessor);
switch(m_mfp.audioPreprocessor.nPreprocessor)
{
case NO_AUDIOPREPROCESSOR :
break;
case SPEEXDSP_AUDIOPREPROCESSOR:
ttSettings->setValue(SETTINGS_STREAMMEDIA_SPX_AGC_ENABLE, m_mfp.audioPreprocessor.speexdsp.bEnableAGC);
ttSettings->setValue(SETTINGS_STREAMMEDIA_SPX_AGC_GAINLEVEL, m_mfp.audioPreprocessor.speexdsp.nGainLevel);
ttSettings->setValue(SETTINGS_STREAMMEDIA_SPX_AGC_INC_MAXDB, m_mfp.audioPreprocessor.speexdsp.nMaxIncDBSec);
ttSettings->setValue(SETTINGS_STREAMMEDIA_SPX_AGC_DEC_MAXDB, m_mfp.audioPreprocessor.speexdsp.nMaxDecDBSec);
ttSettings->setValue(SETTINGS_STREAMMEDIA_SPX_AGC_GAINMAXDB, m_mfp.audioPreprocessor.speexdsp.nMaxGainDB);
ttSettings->setValue(SETTINGS_STREAMMEDIA_SPX_DENOISE_ENABLE, m_mfp.audioPreprocessor.speexdsp.bEnableDenoise);
ttSettings->setValue(SETTINGS_STREAMMEDIA_SPX_DENOISE_SUPPRESS, m_mfp.audioPreprocessor.speexdsp.nMaxNoiseSuppressDB);
break;
case TEAMTALK_AUDIOPREPROCESSOR:
ttSettings->setValue(SETTINGS_STREAMMEDIA_TTAP_MUTELEFT, m_mfp.audioPreprocessor.ttpreprocessor.bMuteLeftSpeaker);
ttSettings->setValue(SETTINGS_STREAMMEDIA_TTAP_MUTERIGHT, m_mfp.audioPreprocessor.ttpreprocessor.bMuteRightSpeaker);
ttSettings->setValue(SETTINGS_STREAMMEDIA_TTAP_GAINLEVEL, m_mfp.audioPreprocessor.ttpreprocessor.nGainLevel);
break;
case WEBRTC_AUDIOPREPROCESSOR :
// TODO: no dialog for WebRTC so far.
break;
}
saveAudioPreprocessor(m_mfp.audioPreprocessor);

m_mfp.uOffsetMSec = TT_MEDIAPLAYBACK_OFFSET_IGNORE;
if (m_playbackid > 0)
Expand Down
Loading

0 comments on commit 7622674

Please sign in to comment.