fix for sound card buffer sizes which are not supported
This commit is contained in:
parent
17e5773c1e
commit
e77e8641d0
9 changed files with 638 additions and 557 deletions
|
@ -129,7 +129,8 @@ public:
|
|||
}
|
||||
|
||||
void CreateNetTranspPropsMessFromCurrentSettings();
|
||||
void CreateDisconnectionMes() { Protocol.CreateDisconnectionMes(); }
|
||||
void CreateAndImmSendDisconnectionMes()
|
||||
{ Protocol.CreateAndImmSendDisconnectionMes(); }
|
||||
|
||||
protected:
|
||||
bool ProtocolIsEnabled();
|
||||
|
|
|
@ -180,12 +180,23 @@ void CClient::SetSndCrdPrefFrameSizeFactor ( const int iNewFactor )
|
|||
iSndCrdPrefFrameSizeFactor = iNewFactor;
|
||||
|
||||
// init with new block size index parameter
|
||||
Init();
|
||||
const bool bInitWasOk = Init();
|
||||
|
||||
if ( bWasRunning )
|
||||
{
|
||||
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,12 +236,23 @@ QString CClient::SetSndCrdDev ( const int iNewDev )
|
|||
|
||||
// init again because the sound card actual buffer size might
|
||||
// be changed on new device
|
||||
Init();
|
||||
const bool bInitWasOk = Init();
|
||||
|
||||
if ( bWasRunning )
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
@ -248,23 +270,29 @@ void CClient::OnSndCrdReinitRequest()
|
|||
// reinit the driver (we use the currently selected driver) and
|
||||
// init client object, too
|
||||
Sound.SetDev ( Sound.GetDev() );
|
||||
Init();
|
||||
const bool bInitWasOk = Init();
|
||||
|
||||
if ( bWasRunning )
|
||||
{
|
||||
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()
|
||||
{
|
||||
// init object
|
||||
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 ) ) )
|
||||
if ( !Init() )
|
||||
{
|
||||
const QString strError = "The current sound card frame size of <b>" +
|
||||
QString().setNum ( iMonoBlockSizeSam ) + " samples</b> is not supported "
|
||||
|
@ -308,9 +336,9 @@ void CClient::Stop()
|
|||
// disconnects the connection anyway. Send the message three times
|
||||
// to increase the probability that at least one message makes it
|
||||
// through).
|
||||
Channel.CreateDisconnectionMes();
|
||||
Channel.CreateDisconnectionMes();
|
||||
Channel.CreateDisconnectionMes();
|
||||
Channel.CreateAndImmSendDisconnectionMes();
|
||||
Channel.CreateAndImmSendDisconnectionMes();
|
||||
Channel.CreateAndImmSendDisconnectionMes();
|
||||
|
||||
// disable channel
|
||||
Channel.SetEnable ( false );
|
||||
|
@ -329,7 +357,7 @@ void CClient::AudioCallback ( CVector<int16_t>& psData, void* arg )
|
|||
pMyClientObj->ProcessAudioData ( psData );
|
||||
}
|
||||
|
||||
void CClient::Init()
|
||||
bool CClient::Init()
|
||||
{
|
||||
// translate block size index in actual block size
|
||||
const int iPrefMonoFrameSize =
|
||||
|
@ -377,6 +405,18 @@ iSndCrdFrameSizeFactor = max ( 1, iMonoBlockSizeSam / SYSTEM_FRAME_SIZE_SAMPLES
|
|||
// set the channel network properties
|
||||
Channel.SetNetwFrameSizeAndFact ( iCeltNumCodedBytes,
|
||||
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 )
|
||||
|
|
|
@ -155,7 +155,7 @@ protected:
|
|||
// callback function must be static, otherwise it does not work
|
||||
static void AudioCallback ( CVector<short>& psData, void* arg );
|
||||
|
||||
void Init();
|
||||
bool Init();
|
||||
void ProcessAudioData ( CVector<short>& vecsStereoSndCrd );
|
||||
void UpdateSocketBufferSize();
|
||||
|
||||
|
@ -212,6 +212,7 @@ signals:
|
|||
void ChatTextReceived ( QString strChatText );
|
||||
void PingTimeReceived ( int iPingTime );
|
||||
void Disconnected();
|
||||
void Stopped();
|
||||
};
|
||||
|
||||
#endif /* !defined ( CLIENT_HOIHGE76GEKJH98_3_43445KJIUHF1912__INCLUDED_ ) */
|
||||
|
|
|
@ -211,11 +211,24 @@ void CClientSettingsDlg::UpdateSoundCardFrame()
|
|||
GenSndCrdBufferDelayString ( iCurActualBufSize );
|
||||
|
||||
if ( iPrefBufSize != iCurActualBufSize )
|
||||
{
|
||||
// yellow color if actual buffer size is not the selected one
|
||||
// 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
|
||||
{
|
||||
TextLabelActualSndCrdBufDelay->setText ( strActSizeValues );
|
||||
}
|
||||
|
|
|
@ -235,6 +235,9 @@ CLlconClientDlg::CLlconClientDlg ( CClient* pNCliP,
|
|||
QObject::connect ( pClient,
|
||||
SIGNAL ( Disconnected() ),
|
||||
this, SLOT ( OnDisconnected() ) );
|
||||
QObject::connect ( pClient,
|
||||
SIGNAL ( Stopped() ),
|
||||
this, SLOT ( OnStopped() ) );
|
||||
QObject::connect ( pClient,
|
||||
SIGNAL ( ChatTextReceived ( QString ) ),
|
||||
this, SLOT ( OnChatTextReceived ( QString ) ) );
|
||||
|
@ -340,6 +343,11 @@ void CLlconClientDlg::OnConnectDisconBut()
|
|||
ConnectDisconnect ( !pClient->IsRunning() );
|
||||
}
|
||||
|
||||
void CLlconClientDlg::OnStopped()
|
||||
{
|
||||
ConnectDisconnect ( false );
|
||||
}
|
||||
|
||||
void CLlconClientDlg::OnOpenGeneralSettings()
|
||||
{
|
||||
// open general settings dialog
|
||||
|
@ -463,8 +471,16 @@ void CLlconClientDlg::ConnectDisconnect ( const bool bDoStart )
|
|||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// 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 );
|
||||
|
||||
// stop timer for level meter bars and reset them
|
||||
|
|
|
@ -112,4 +112,5 @@ public slots:
|
|||
void OnLineEditServerAddrTextChanged ( const QString sNewText );
|
||||
void OnLineEditServerAddrActivated ( int index );
|
||||
void OnDisconnected();
|
||||
void OnStopped();
|
||||
};
|
||||
|
|
|
@ -278,7 +278,7 @@ void CProtocol::CreateAndSendMessage ( const int 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> vecData ( 2 ); // 2 bytes of data
|
||||
|
@ -317,7 +317,7 @@ bool CProtocol::ParseMessage ( const CVector<uint8_t>& vecbyData,
|
|||
if ( iRecID != PROTMESSID_ACKN )
|
||||
{
|
||||
// resend acknowledgement
|
||||
CreateAndSendAcknMess ( iRecID, iRecCounter );
|
||||
CreateAndImmSendAcknMess ( iRecID, iRecCounter );
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -412,8 +412,8 @@ bool CProtocol::ParseMessage ( const CVector<uint8_t>& vecbyData,
|
|||
break;
|
||||
}
|
||||
|
||||
// send acknowledge message
|
||||
CreateAndSendAcknMess ( iRecID, iRecCounter );
|
||||
// immediately send acknowledge message
|
||||
CreateAndImmSendAcknMess ( iRecID, iRecCounter );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -949,9 +949,18 @@ bool CProtocol::EvaluateReqNetwTranspPropsMes ( const CVector<uint8_t>& vecData
|
|||
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 )
|
||||
|
|
|
@ -82,9 +82,9 @@ public:
|
|||
void CreatePingMes ( const int iMs );
|
||||
void CreateNetwTranspPropsMes ( const CNetworkTransportProps& NetTrProps );
|
||||
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,
|
||||
const int iNumBytes );
|
||||
|
|
|
@ -120,7 +120,7 @@ public slots:
|
|||
break;
|
||||
|
||||
case 10:
|
||||
Protocol.CreateAndSendAcknMess ( GenRandomIntInRange ( -10, 100 ),
|
||||
Protocol.CreateAndImmSendAcknMess ( GenRandomIntInRange ( -10, 100 ),
|
||||
GenRandomIntInRange ( -100, 100 ) );
|
||||
break;
|
||||
|
||||
|
|
Loading…
Reference in a new issue