fix for sound card buffer sizes which are not supported

This commit is contained in:
Volker Fischer 2009-08-19 07:23:33 +00:00
parent 17e5773c1e
commit e77e8641d0
9 changed files with 638 additions and 557 deletions

View file

@ -129,7 +129,8 @@ public:
} }
void CreateNetTranspPropsMessFromCurrentSettings(); void CreateNetTranspPropsMessFromCurrentSettings();
void CreateDisconnectionMes() { Protocol.CreateDisconnectionMes(); } void CreateAndImmSendDisconnectionMes()
{ Protocol.CreateAndImmSendDisconnectionMes(); }
protected: protected:
bool ProtocolIsEnabled(); bool ProtocolIsEnabled();

View file

@ -180,11 +180,22 @@ void CClient::SetSndCrdPrefFrameSizeFactor ( const int iNewFactor )
iSndCrdPrefFrameSizeFactor = iNewFactor; iSndCrdPrefFrameSizeFactor = iNewFactor;
// init with new block size index parameter // init with new block size index parameter
Init(); const bool bInitWasOk = Init();
if ( bWasRunning ) if ( bWasRunning )
{ {
Sound.Start(); if ( bInitWasOk )
{
// init was ok, restart client
Sound.Start();
}
else
{
// init was not successful, do not restart client and
// inform main window of the stopped client
Stop();
emit Stopped();
}
} }
} }
} }
@ -225,11 +236,22 @@ QString CClient::SetSndCrdDev ( const int iNewDev )
// init again because the sound card actual buffer size might // init again because the sound card actual buffer size might
// be changed on new device // be changed on new device
Init(); const bool bInitWasOk = Init();
if ( bWasRunning ) if ( bWasRunning )
{ {
Sound.Start(); if ( bInitWasOk )
{
// init was ok, restart client
Sound.Start();
}
else
{
// init was not successful, do not restart client and
// inform main window of the stopped client
Stop();
emit Stopped();
}
} }
return strReturn; return strReturn;
@ -248,23 +270,29 @@ void CClient::OnSndCrdReinitRequest()
// reinit the driver (we use the currently selected driver) and // reinit the driver (we use the currently selected driver) and
// init client object, too // init client object, too
Sound.SetDev ( Sound.GetDev() ); Sound.SetDev ( Sound.GetDev() );
Init(); const bool bInitWasOk = Init();
if ( bWasRunning ) if ( bWasRunning )
{ {
Sound.Start(); if ( bInitWasOk )
{
// init was ok, restart client
Sound.Start();
}
else
{
// init was not successful, do not restart client and
// inform main window of the stopped client
Stop();
emit Stopped();
}
} }
} }
void CClient::Start() void CClient::Start()
{ {
// init object // init object
Init(); if ( !Init() )
// check sound card buffer sizes, if not supported, fire error message
if ( ( iMonoBlockSizeSam != ( SYSTEM_FRAME_SIZE_SAMPLES * FRAME_SIZE_FACTOR_PREFERRED ) ) &&
( iMonoBlockSizeSam != ( SYSTEM_FRAME_SIZE_SAMPLES * FRAME_SIZE_FACTOR_DEFAULT ) ) &&
( iMonoBlockSizeSam != ( SYSTEM_FRAME_SIZE_SAMPLES * FRAME_SIZE_FACTOR_SAFE ) ) )
{ {
const QString strError = "The current sound card frame size of <b>" + const QString strError = "The current sound card frame size of <b>" +
QString().setNum ( iMonoBlockSizeSam ) + " samples</b> is not supported " QString().setNum ( iMonoBlockSizeSam ) + " samples</b> is not supported "
@ -308,9 +336,9 @@ void CClient::Stop()
// disconnects the connection anyway. Send the message three times // disconnects the connection anyway. Send the message three times
// to increase the probability that at least one message makes it // to increase the probability that at least one message makes it
// through). // through).
Channel.CreateDisconnectionMes(); Channel.CreateAndImmSendDisconnectionMes();
Channel.CreateDisconnectionMes(); Channel.CreateAndImmSendDisconnectionMes();
Channel.CreateDisconnectionMes(); Channel.CreateAndImmSendDisconnectionMes();
// disable channel // disable channel
Channel.SetEnable ( false ); Channel.SetEnable ( false );
@ -329,7 +357,7 @@ void CClient::AudioCallback ( CVector<int16_t>& psData, void* arg )
pMyClientObj->ProcessAudioData ( psData ); pMyClientObj->ProcessAudioData ( psData );
} }
void CClient::Init() bool CClient::Init()
{ {
// translate block size index in actual block size // translate block size index in actual block size
const int iPrefMonoFrameSize = const int iPrefMonoFrameSize =
@ -377,6 +405,18 @@ iSndCrdFrameSizeFactor = max ( 1, iMonoBlockSizeSam / SYSTEM_FRAME_SIZE_SAMPLES
// set the channel network properties // set the channel network properties
Channel.SetNetwFrameSizeAndFact ( iCeltNumCodedBytes, Channel.SetNetwFrameSizeAndFact ( iCeltNumCodedBytes,
iSndCrdFrameSizeFactor ); iSndCrdFrameSizeFactor );
// check sound card buffer sizes, if not supported, return error flag
if ( ( iMonoBlockSizeSam != ( SYSTEM_FRAME_SIZE_SAMPLES * FRAME_SIZE_FACTOR_PREFERRED ) ) &&
( iMonoBlockSizeSam != ( SYSTEM_FRAME_SIZE_SAMPLES * FRAME_SIZE_FACTOR_DEFAULT ) ) &&
( iMonoBlockSizeSam != ( SYSTEM_FRAME_SIZE_SAMPLES * FRAME_SIZE_FACTOR_SAFE ) ) )
{
return false; // init was not successful
}
else
{
return true; // ok
}
} }
void CClient::ProcessAudioData ( CVector<int16_t>& vecsStereoSndCrd ) void CClient::ProcessAudioData ( CVector<int16_t>& vecsStereoSndCrd )

View file

@ -155,7 +155,7 @@ protected:
// callback function must be static, otherwise it does not work // callback function must be static, otherwise it does not work
static void AudioCallback ( CVector<short>& psData, void* arg ); static void AudioCallback ( CVector<short>& psData, void* arg );
void Init(); bool Init();
void ProcessAudioData ( CVector<short>& vecsStereoSndCrd ); void ProcessAudioData ( CVector<short>& vecsStereoSndCrd );
void UpdateSocketBufferSize(); void UpdateSocketBufferSize();
@ -212,6 +212,7 @@ signals:
void ChatTextReceived ( QString strChatText ); void ChatTextReceived ( QString strChatText );
void PingTimeReceived ( int iPingTime ); void PingTimeReceived ( int iPingTime );
void Disconnected(); void Disconnected();
void Stopped();
}; };
#endif /* !defined ( CLIENT_HOIHGE76GEKJH98_3_43445KJIUHF1912__INCLUDED_ ) */ #endif /* !defined ( CLIENT_HOIHGE76GEKJH98_3_43445KJIUHF1912__INCLUDED_ ) */

View file

@ -212,8 +212,21 @@ void CClientSettingsDlg::UpdateSoundCardFrame()
if ( iPrefBufSize != iCurActualBufSize ) if ( iPrefBufSize != iCurActualBufSize )
{ {
TextLabelActualSndCrdBufDelay->setText ( "<font color=""red"">" + // yellow color if actual buffer size is not the selected one
strActSizeValues + "</font>" ); // but a valid one, red color if actual buffer size is not the
// selected one and is not a vaild one
if ( ( iCurActualBufSize != ( SYSTEM_FRAME_SIZE_SAMPLES * FRAME_SIZE_FACTOR_PREFERRED ) ) &&
( iCurActualBufSize != ( SYSTEM_FRAME_SIZE_SAMPLES * FRAME_SIZE_FACTOR_DEFAULT ) ) &&
( iCurActualBufSize != ( SYSTEM_FRAME_SIZE_SAMPLES * FRAME_SIZE_FACTOR_SAFE ) ) )
{
TextLabelActualSndCrdBufDelay->setText ( "<font color=""red"">" +
strActSizeValues + "</font>" );
}
else
{
TextLabelActualSndCrdBufDelay->setText ( "<font color=""yellow"">" +
strActSizeValues + "</font>" );
}
} }
else else
{ {

View file

@ -235,6 +235,9 @@ CLlconClientDlg::CLlconClientDlg ( CClient* pNCliP,
QObject::connect ( pClient, QObject::connect ( pClient,
SIGNAL ( Disconnected() ), SIGNAL ( Disconnected() ),
this, SLOT ( OnDisconnected() ) ); this, SLOT ( OnDisconnected() ) );
QObject::connect ( pClient,
SIGNAL ( Stopped() ),
this, SLOT ( OnStopped() ) );
QObject::connect ( pClient, QObject::connect ( pClient,
SIGNAL ( ChatTextReceived ( QString ) ), SIGNAL ( ChatTextReceived ( QString ) ),
this, SLOT ( OnChatTextReceived ( QString ) ) ); this, SLOT ( OnChatTextReceived ( QString ) ) );
@ -340,6 +343,11 @@ void CLlconClientDlg::OnConnectDisconBut()
ConnectDisconnect ( !pClient->IsRunning() ); ConnectDisconnect ( !pClient->IsRunning() );
} }
void CLlconClientDlg::OnStopped()
{
ConnectDisconnect ( false );
}
void CLlconClientDlg::OnOpenGeneralSettings() void CLlconClientDlg::OnOpenGeneralSettings()
{ {
// open general settings dialog // open general settings dialog
@ -464,7 +472,15 @@ void CLlconClientDlg::ConnectDisconnect ( const bool bDoStart )
} }
else else
{ {
pClient->Stop(); // only stop client if currently running, in case we received
// the stopped message, the client is already stopped but the
// connect/disconnect button and other GUI controls must be
// updated
if ( pClient->IsRunning() )
{
pClient->Stop();
}
PushButtonConnect->setText ( CON_BUT_CONNECTTEXT ); PushButtonConnect->setText ( CON_BUT_CONNECTTEXT );
// stop timer for level meter bars and reset them // stop timer for level meter bars and reset them

View file

@ -112,4 +112,5 @@ public slots:
void OnLineEditServerAddrTextChanged ( const QString sNewText ); void OnLineEditServerAddrTextChanged ( const QString sNewText );
void OnLineEditServerAddrActivated ( int index ); void OnLineEditServerAddrActivated ( int index );
void OnDisconnected(); void OnDisconnected();
void OnStopped();
}; };

View file

@ -278,7 +278,7 @@ void CProtocol::CreateAndSendMessage ( const int iID,
EnqueueMessage ( vecNewMessage, iCurCounter, iID ); EnqueueMessage ( vecNewMessage, iCurCounter, iID );
} }
void CProtocol::CreateAndSendAcknMess ( const int& iID, const int& iCnt ) void CProtocol::CreateAndImmSendAcknMess ( const int& iID, const int& iCnt )
{ {
CVector<uint8_t> vecAcknMessage; CVector<uint8_t> vecAcknMessage;
CVector<uint8_t> vecData ( 2 ); // 2 bytes of data CVector<uint8_t> vecData ( 2 ); // 2 bytes of data
@ -317,7 +317,7 @@ bool CProtocol::ParseMessage ( const CVector<uint8_t>& vecbyData,
if ( iRecID != PROTMESSID_ACKN ) if ( iRecID != PROTMESSID_ACKN )
{ {
// resend acknowledgement // resend acknowledgement
CreateAndSendAcknMess ( iRecID, iRecCounter ); CreateAndImmSendAcknMess ( iRecID, iRecCounter );
} }
} }
else else
@ -412,8 +412,8 @@ bool CProtocol::ParseMessage ( const CVector<uint8_t>& vecbyData,
break; break;
} }
// send acknowledge message // immediately send acknowledge message
CreateAndSendAcknMess ( iRecID, iRecCounter ); CreateAndImmSendAcknMess ( iRecID, iRecCounter );
} }
} }
@ -949,9 +949,18 @@ bool CProtocol::EvaluateReqNetwTranspPropsMes ( const CVector<uint8_t>& vecData
return false; // no error return false; // no error
} }
void CProtocol::CreateDisconnectionMes() void CProtocol::CreateAndImmSendDisconnectionMes()
{ {
CreateAndSendMessage ( PROTMESSID_DISCONNECTION, CVector<uint8_t> ( 0 ) ); CVector<uint8_t> vecDisconMessage;
// build complete message (special case, there is not actual data
// and we do not use the counter since this is the very last message
// of the connection, after that no message will be evaluated)
GenMessageFrame ( vecDisconMessage, 0,
PROTMESSID_DISCONNECTION, CVector<uint8_t> ( 0 ) );
// immediately send acknowledge message
emit MessReadyForSending ( vecDisconMessage );
} }
bool CProtocol::EvaluateDisconnectionMes ( const CVector<uint8_t>& vecData ) bool CProtocol::EvaluateDisconnectionMes ( const CVector<uint8_t>& vecData )

View file

@ -82,9 +82,9 @@ public:
void CreatePingMes ( const int iMs ); void CreatePingMes ( const int iMs );
void CreateNetwTranspPropsMes ( const CNetworkTransportProps& NetTrProps ); void CreateNetwTranspPropsMes ( const CNetworkTransportProps& NetTrProps );
void CreateReqNetwTranspPropsMes(); void CreateReqNetwTranspPropsMes();
void CreateDisconnectionMes();
void CreateAndSendAcknMess ( const int& iID, const int& iCnt ); void CreateAndImmSendDisconnectionMes();
void CreateAndImmSendAcknMess ( const int& iID, const int& iCnt );
bool ParseMessage ( const CVector<uint8_t>& vecbyData, bool ParseMessage ( const CVector<uint8_t>& vecbyData,
const int iNumBytes ); const int iNumBytes );

View file

@ -120,7 +120,7 @@ public slots:
break; break;
case 10: case 10:
Protocol.CreateAndSendAcknMess ( GenRandomIntInRange ( -10, 100 ), Protocol.CreateAndImmSendAcknMess ( GenRandomIntInRange ( -10, 100 ),
GenRandomIntInRange ( -100, 100 ) ); GenRandomIntInRange ( -100, 100 ) );
break; break;