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 CreateDisconnectionMes() { Protocol.CreateDisconnectionMes(); }
void CreateAndImmSendDisconnectionMes()
{ Protocol.CreateAndImmSendDisconnectionMes(); }
protected:
bool ProtocolIsEnabled();

View file

@ -180,11 +180,22 @@ void CClient::SetSndCrdPrefFrameSizeFactor ( const int iNewFactor )
iSndCrdPrefFrameSizeFactor = iNewFactor;
// init with new block size index parameter
Init();
const bool bInitWasOk = Init();
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
// be changed on new device
Init();
const bool bInitWasOk = Init();
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;
@ -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 )
{
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()
{
// 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 )

View file

@ -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_ ) */

View file

@ -212,8 +212,21 @@ void CClientSettingsDlg::UpdateSoundCardFrame()
if ( iPrefBufSize != iCurActualBufSize )
{
TextLabelActualSndCrdBufDelay->setText ( "<font color=""red"">" +
strActSizeValues + "</font>" );
// 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
{

File diff suppressed because it is too large Load diff

View file

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

View file

@ -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 )

View file

@ -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 );

View file

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