jamulus/src/clientsettingsdlg.cpp

361 lines
13 KiB
C++
Raw Normal View History

/******************************************************************************\
2008-08-03 00:01:19 +02:00
* Copyright (c) 2004-2008
*
* Author(s):
* Volker Fischer
*
******************************************************************************
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation; either version 2 of the License, or (at your option) any later
* version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
\******************************************************************************/
#include "clientsettingsdlg.h"
/* Implementation *************************************************************/
CClientSettingsDlg::CClientSettingsDlg ( CClient* pNCliP, QWidget* parent,
Qt::WindowFlags f ) : pClient ( pNCliP ), QDialog ( parent, f )
{
setupUi ( this );
2008-08-10 11:56:06 +02:00
// add help text to controls
QString strJitterBufferSize = tr ( "<b>Jitter Buffer Size:</b> The size of "
"the network buffer (jitter buffer). The jitter buffer compensates for "
"the network jitter. The larger this buffer is, the more robust the "
"connection is against network jitter but the higher is the latency. "
"This setting is therefore a trade-off between audio drop outs and "
"overall audio delay.<br>By changing this setting, both, the client "
"and the server jitter buffer is set to the same value." );
SliderNetBuf->setWhatsThis ( strJitterBufferSize );
TextNetBuf->setWhatsThis ( strJitterBufferSize );
GroupBoxJitterBuffer->setWhatsThis ( strJitterBufferSize );
QString strNetwBlockSize = tr ( "<b>Network Block Size:</b> The size of "
"the network audio blocks for input and output (upstream and "
"downstream). The lower these values are set, the lower is the "
"overall audio delay but the greater is the network protocoll "
"overhead (UDP protocol overhead) which means more bandwidth is "
"required. If the upstream/downstream bandwidth is not sufficient "
"for the audio stream bandwidth, audio dropouts occur and the "
"ping time will increase significantly (the connection is stodged)." );
SliderNetBufSiFactIn->setWhatsThis ( strNetwBlockSize );
SliderNetBufSiFactOut->setWhatsThis ( strNetwBlockSize );
TextNetBufSiFactIn->setWhatsThis ( strNetwBlockSize );
TextNetBufSiFactOut->setWhatsThis ( strNetwBlockSize );
GroupBoxNetwBuf->setWhatsThis ( strNetwBlockSize );
2008-01-22 20:58:53 +01:00
// init timing jitter text label
TextLabelStdDevTimer->setText ( "" );
2008-08-03 00:01:19 +02:00
// ping time controls
CLEDPingTime->SetUpdateTime ( 2 * PING_UPDATE_TIME );
CLEDPingTime->Reset();
TextLabelPingTime->setText ( "" );
2008-01-22 20:58:53 +01:00
// init slider controls ---
// sound buffer in
2008-07-14 00:57:31 +02:00
#ifdef _WIN32
SliderSndBufIn->setRange ( 1, AUD_SLIDER_LENGTH ); // for ASIO we only need one buffer
#else
2007-09-08 12:45:14 +02:00
SliderSndBufIn->setRange ( 2, AUD_SLIDER_LENGTH );
2008-07-14 00:57:31 +02:00
#endif
const int iCurNumInBuf = pClient->GetSndInterface()->GetInNumBuf();
2007-09-08 12:45:14 +02:00
SliderSndBufIn->setValue ( iCurNumInBuf );
TextSndBufIn->setText ( "In: " + QString().setNum ( iCurNumInBuf ) );
2008-01-22 20:58:53 +01:00
// sound buffer out
2008-07-14 00:57:31 +02:00
#ifdef _WIN32
SliderSndBufOut->setRange ( 1, AUD_SLIDER_LENGTH ); // for ASIO we only need one buffer
#else
2007-09-08 12:45:14 +02:00
SliderSndBufOut->setRange ( 2, AUD_SLIDER_LENGTH );
2008-07-14 00:57:31 +02:00
#endif
const int iCurNumOutBuf = pClient->GetSndInterface()->GetOutNumBuf();
2007-09-08 12:45:14 +02:00
SliderSndBufOut->setValue ( iCurNumOutBuf );
TextSndBufOut->setText ( "Out: " + QString().setNum ( iCurNumOutBuf ) );
2008-01-22 20:58:53 +01:00
// network buffer
2007-09-08 12:45:14 +02:00
SliderNetBuf->setRange ( 0, MAX_NET_BUF_SIZE_NUM_BL );
const int iCurNumNetBuf = pClient->GetSockBufSize();
2007-09-08 12:45:14 +02:00
SliderNetBuf->setValue ( iCurNumNetBuf );
TextNetBuf->setText ( "Size: " + QString().setNum ( iCurNumNetBuf ) );
2008-01-22 20:58:53 +01:00
// network buffer size factor in
2007-09-08 12:45:14 +02:00
SliderNetBufSiFactIn->setRange ( 1, MAX_NET_BLOCK_SIZE_FACTOR );
const int iCurNetBufSiFactIn = pClient->GetNetwBufSizeFactIn();
2007-09-08 12:45:14 +02:00
SliderNetBufSiFactIn->setValue ( iCurNetBufSiFactIn );
TextNetBufSiFactIn->setText ( "In:\n" + QString().setNum (
double ( iCurNetBufSiFactIn * MIN_BLOCK_DURATION_MS ), 'f', 2 ) +
" ms" );
2008-01-22 20:58:53 +01:00
// network buffer size factor out
2007-09-08 12:45:14 +02:00
SliderNetBufSiFactOut->setRange ( 1, MAX_NET_BLOCK_SIZE_FACTOR );
const int iCurNetBufSiFactOut = pClient->GetNetwBufSizeFactOut();
2007-09-08 12:45:14 +02:00
SliderNetBufSiFactOut->setValue ( iCurNetBufSiFactOut );
TextNetBufSiFactOut->setText ( "Out:\n" + QString().setNum (
double ( iCurNetBufSiFactOut * MIN_BLOCK_DURATION_MS), 'f', 2 ) +
" ms" );
2008-10-31 00:23:26 +01:00
// init combo box containing all available sound cards in the system
cbSoundcard->clear();
for ( int iSndDevIdx = 0; iSndDevIdx < pClient->GetSndInterface()->GetNumDev(); iSndDevIdx++ )
{
cbSoundcard->addItem ( pClient->GetSndInterface()->GetDeviceName ( iSndDevIdx ).c_str() );
}
cbSoundcard->setCurrentIndex ( pClient->GetSndInterface()->GetDev() );
// "OpenChatOnNewMessage" check box
if ( pClient->GetOpenChatOnNewMessage() )
{
cbOpenChatOnNewMessage->setCheckState ( Qt::Checked );
}
else
{
cbOpenChatOnNewMessage->setCheckState ( Qt::Unchecked );
}
// audio compression type
switch ( pClient->GetAudioCompressionOut() )
{
case CAudioCompression::CT_NONE:
radioButtonNoAudioCompr->setChecked ( true );
break;
case CAudioCompression::CT_IMAADPCM:
radioButtonIMA_ADPCM->setChecked ( true );
break;
case CAudioCompression::CT_MSADPCM:
radioButtonMS_ADPCM->setChecked ( true );
break;
}
AudioCompressionButtonGroup.addButton ( radioButtonNoAudioCompr );
AudioCompressionButtonGroup.addButton ( radioButtonIMA_ADPCM );
AudioCompressionButtonGroup.addButton ( radioButtonMS_ADPCM );
2008-01-22 20:58:53 +01:00
// Connections -------------------------------------------------------------
// timers
2007-09-08 12:45:14 +02:00
QObject::connect ( &TimerStatus, SIGNAL ( timeout() ),
this, SLOT ( OnTimerStatus() ) );
2008-08-03 00:01:19 +02:00
QObject::connect ( &TimerPing, SIGNAL ( timeout() ),
this, SLOT ( OnTimerPing() ) );
2008-01-22 20:58:53 +01:00
// sliders
2007-09-08 12:45:14 +02:00
QObject::connect ( SliderSndBufIn, SIGNAL ( valueChanged ( int ) ),
this, SLOT ( OnSliderSndBufInChange ( int ) ) );
QObject::connect ( SliderSndBufOut, SIGNAL ( valueChanged ( int ) ),
this, SLOT ( OnSliderSndBufOutChange ( int ) ) );
2007-09-08 12:45:14 +02:00
QObject::connect ( SliderNetBuf, SIGNAL ( valueChanged ( int ) ),
this, SLOT ( OnSliderNetBuf ( int ) ) );
2007-09-08 12:45:14 +02:00
QObject::connect ( SliderNetBufSiFactIn, SIGNAL ( valueChanged ( int ) ),
this, SLOT ( OnSliderNetBufSiFactIn ( int ) ) );
QObject::connect ( SliderNetBufSiFactOut, SIGNAL ( valueChanged ( int ) ),
this, SLOT ( OnSliderNetBufSiFactOut ( int ) ) );
// check boxes
QObject::connect ( cbOpenChatOnNewMessage, SIGNAL ( stateChanged ( int ) ),
this, SLOT ( OnOpenChatOnNewMessageStateChanged ( int ) ) );
2008-10-31 00:23:26 +01:00
// combo boxes
QObject::connect ( cbSoundcard, SIGNAL ( activated ( int ) ),
this, SLOT ( OnSoundCrdSelection ( int ) ) );
2008-08-02 15:42:24 +02:00
// misc
QObject::connect ( pClient, SIGNAL ( PingTimeReceived ( int ) ),
this, SLOT ( OnPingTimeResult ( int ) ) );
QObject::connect ( &AudioCompressionButtonGroup, SIGNAL ( buttonClicked ( QAbstractButton* ) ),
this, SLOT ( OnAudioCompressionButtonGroupClicked ( QAbstractButton* ) ) );
2008-01-22 20:58:53 +01:00
// Timers ------------------------------------------------------------------
// start timer for status bar
2007-09-08 12:45:14 +02:00
TimerStatus.start ( DISPLAY_UPDATE_TIME );
}
2008-08-03 00:01:19 +02:00
void CClientSettingsDlg::showEvent ( QShowEvent* showEvent )
{
// only activate ping timer if window is actually shown
TimerPing.start ( PING_UPDATE_TIME );
}
void CClientSettingsDlg::hideEvent ( QHideEvent* hideEvent )
{
// if window is closed, stop timer for ping
TimerPing.stop();
}
2007-09-08 12:45:14 +02:00
void CClientSettingsDlg::OnSliderSndBufInChange ( int value )
{
2007-09-08 12:45:14 +02:00
pClient->GetSndInterface()->SetInNumBuf ( value );
TextSndBufIn->setText ( "In: " + QString().setNum ( value ) );
UpdateDisplay();
}
2007-09-08 12:45:14 +02:00
void CClientSettingsDlg::OnSliderSndBufOutChange ( int value )
{
2007-09-08 12:45:14 +02:00
pClient->GetSndInterface()->SetOutNumBuf ( value );
TextSndBufOut->setText ( "Out: " + QString().setNum ( value ) );
UpdateDisplay();
}
2007-09-08 12:45:14 +02:00
void CClientSettingsDlg::OnSliderNetBuf ( int value )
{
pClient->SetSockBufSize ( value );
2007-09-08 12:45:14 +02:00
TextNetBuf->setText ( "Size: " + QString().setNum ( value ) );
UpdateDisplay();
}
2007-09-08 12:45:14 +02:00
void CClientSettingsDlg::OnSliderNetBufSiFactIn ( int value )
{
pClient->SetNetwBufSizeFactIn ( value );
2007-09-08 12:45:14 +02:00
TextNetBufSiFactIn->setText ( "In:\n" + QString().setNum (
double ( value * MIN_BLOCK_DURATION_MS ), 'f', 2 ) +
" ms" );
UpdateDisplay();
}
2007-09-08 12:45:14 +02:00
void CClientSettingsDlg::OnSliderNetBufSiFactOut ( int value )
{
pClient->SetNetwBufSizeFactOut ( value );
2007-09-08 12:45:14 +02:00
TextNetBufSiFactOut->setText ( "Out:\n" + QString().setNum (
double ( value * MIN_BLOCK_DURATION_MS ), 'f', 2 ) +
" ms" );
UpdateDisplay();
}
2008-10-31 00:23:26 +01:00
void CClientSettingsDlg::OnSoundCrdSelection ( int iSndDevIdx )
{
try
{
pClient->GetSndInterface()->SetDev ( iSndDevIdx );
}
catch ( CGenErr generr )
{
QMessageBox::critical ( 0, APP_NAME,
QString ( "The selected audio device could not be used because "
"of the following error: " ) + generr.GetErrorText() +
QString ( " The previous driver will be selected." ), "Ok", 0 );
2008-10-31 00:23:26 +01:00
// recover old selection
cbSoundcard->setCurrentIndex ( pClient->GetSndInterface()->GetDev() );
}
}
void CClientSettingsDlg::OnOpenChatOnNewMessageStateChanged ( int value )
{
pClient->SetOpenChatOnNewMessage ( value == Qt::Checked );
UpdateDisplay();
2008-08-02 15:42:24 +02:00
}
void CClientSettingsDlg::OnAudioCompressionButtonGroupClicked ( QAbstractButton* button )
{
if ( button == radioButtonNoAudioCompr )
{
pClient->SetAudioCompressionOut ( CAudioCompression::CT_NONE );
}
if ( button == radioButtonIMA_ADPCM )
{
pClient->SetAudioCompressionOut ( CAudioCompression::CT_IMAADPCM );
}
if ( button == radioButtonMS_ADPCM )
{
pClient->SetAudioCompressionOut ( CAudioCompression::CT_MSADPCM );
}
UpdateDisplay();
}
2008-08-03 00:01:19 +02:00
void CClientSettingsDlg::OnTimerPing()
2008-08-02 15:42:24 +02:00
{
2008-08-03 00:01:19 +02:00
// send ping message to server
pClient->SendPingMess();
}
2008-08-02 15:42:24 +02:00
2008-08-03 00:01:19 +02:00
void CClientSettingsDlg::OnPingTimeResult ( int iPingTime )
{
2008-08-10 11:37:47 +02:00
// color definition: < 27 ms green, < 50 ms yellow, otherwise red
if ( iPingTime < 27 )
2008-08-03 00:01:19 +02:00
{
CLEDPingTime->SetLight ( MUL_COL_LED_GREEN );
}
else
{
if ( iPingTime < 50 )
{
CLEDPingTime->SetLight ( MUL_COL_LED_YELLOW );
}
else
{
CLEDPingTime->SetLight ( MUL_COL_LED_RED );
}
}
TextLabelPingTime->setText ( QString().setNum ( iPingTime ) + " ms" );
}
void CClientSettingsDlg::UpdateDisplay()
{
2008-08-03 23:38:24 +02:00
if ( pClient->IsRunning() )
{
// response time
TextLabelStdDevTimer->setText ( QString().
setNum ( pClient->GetTimingStdDev(), 'f', 2 ) + " ms" );
}
else
{
// clear text labels with client parameters
TextLabelStdDevTimer->setText ( "" );
TextLabelPingTime->setText ( "" );
}
}
void CClientSettingsDlg::SetStatus ( const int iMessType, const int iStatus )
{
2007-09-08 12:45:14 +02:00
switch ( iMessType )
{
case MS_SOUND_IN:
2007-09-08 12:45:14 +02:00
CLEDSoundIn->SetLight ( iStatus );
break;
case MS_SOUND_OUT:
2007-09-08 12:45:14 +02:00
CLEDSoundOut->SetLight ( iStatus );
break;
case MS_JIT_BUF_PUT:
2007-09-08 12:45:14 +02:00
CLEDNetwPut->SetLight ( iStatus );
break;
case MS_JIT_BUF_GET:
2007-09-08 12:45:14 +02:00
CLEDNetwGet->SetLight ( iStatus );
break;
case MS_PROTOCOL:
2007-09-08 12:45:14 +02:00
CLEDProtocolStatus->SetLight ( iStatus );
case MS_RESET_ALL:
CLEDSoundIn->Reset();
CLEDSoundOut->Reset();
CLEDNetwPut->Reset();
CLEDNetwGet->Reset();
CLEDProtocolStatus->Reset();
break;
}
}