made the CChannel class more thread safe
This commit is contained in:
parent
c50dd2fc56
commit
7445505c12
2 changed files with 129 additions and 53 deletions
142
src/channel.cpp
142
src/channel.cpp
|
@ -624,6 +624,8 @@ void CChannel::SetEnable ( const bool bNEnStat )
|
||||||
void CChannel::SetNetwInBlSiFactAndCompr ( const int iNewBlockSizeFactor,
|
void CChannel::SetNetwInBlSiFactAndCompr ( const int iNewBlockSizeFactor,
|
||||||
const CAudioCompression::EAudComprType eNewAudComprType )
|
const CAudioCompression::EAudComprType eNewAudComprType )
|
||||||
{
|
{
|
||||||
|
Mutex.lock();
|
||||||
|
{
|
||||||
// store new value
|
// store new value
|
||||||
iCurNetwInBlSiFact = iNewBlockSizeFactor;
|
iCurNetwInBlSiFact = iNewBlockSizeFactor;
|
||||||
|
|
||||||
|
@ -636,7 +638,9 @@ void CChannel::SetNetwInBlSiFactAndCompr ( const int iNewBlockSizeFactor,
|
||||||
( iNewBlockSizeFactor * MIN_BLOCK_DURATION_MS );
|
( iNewBlockSizeFactor * MIN_BLOCK_DURATION_MS );
|
||||||
|
|
||||||
// socket buffer must be adjusted
|
// socket buffer must be adjusted
|
||||||
SetSockBufSize ( GetSockBufSize() );
|
SetSockBufSizeIntern ( GetSockBufSize() );
|
||||||
|
}
|
||||||
|
Mutex.unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CChannel::SetNetwBufSizeFactOut ( const int iNewNetwBlSiFactOut )
|
void CChannel::SetNetwBufSizeFactOut ( const int iNewNetwBlSiFactOut )
|
||||||
|
@ -667,6 +671,97 @@ void CChannel::SetAudioCompressionOut ( const CAudioCompression::EAudComprType e
|
||||||
SetNetwBufSizeFactOut ( iCurNetwOutBlSiFact );
|
SetNetwBufSizeFactOut ( iCurNetwOutBlSiFact );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CChannel::SetSockBufSize ( const int iNumBlocks )
|
||||||
|
{
|
||||||
|
// this opperation must be done with mutex
|
||||||
|
Mutex.lock();
|
||||||
|
{
|
||||||
|
SetSockBufSizeIntern ( iNumBlocks );
|
||||||
|
}
|
||||||
|
Mutex.unlock();
|
||||||
|
}
|
||||||
|
|
||||||
|
void CChannel::SetSockBufSizeIntern ( const int iNumBlocks )
|
||||||
|
{
|
||||||
|
iCurSockBufSize = iNumBlocks;
|
||||||
|
|
||||||
|
// the idea of setting the jitter buffer is as follows:
|
||||||
|
// The network block size is a multiple of the internal minimal
|
||||||
|
// block size. Therefore, the minimum jitter buffer size must be
|
||||||
|
// so that it can take one network buffer -> NET_BLOCK_SIZE_FACTOR.
|
||||||
|
// The actual jitter compensation are then the additional blocks of
|
||||||
|
// the internal block size, which is set with SetSockBufSize
|
||||||
|
SockBuf.Init ( MIN_BLOCK_SIZE_SAMPLES,
|
||||||
|
iNumBlocks + iCurNetwInBlSiFact );
|
||||||
|
}
|
||||||
|
|
||||||
|
void CChannel::SetGain ( const int iChanID, const double dNewGain )
|
||||||
|
{
|
||||||
|
Mutex.lock();
|
||||||
|
{
|
||||||
|
// set value (make sure channel ID is in range)
|
||||||
|
if ( ( iChanID >= 0 ) && ( iChanID < MAX_NUM_CHANNELS ) )
|
||||||
|
{
|
||||||
|
vecdGains[iChanID] = dNewGain;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Mutex.unlock();
|
||||||
|
}
|
||||||
|
|
||||||
|
double CChannel::GetGain ( const int iChanID )
|
||||||
|
{
|
||||||
|
double dReturnVal = 0;
|
||||||
|
|
||||||
|
Mutex.lock();
|
||||||
|
{
|
||||||
|
// get value (make sure channel ID is in range)
|
||||||
|
if ( ( iChanID >= 0 ) && ( iChanID < MAX_NUM_CHANNELS ) )
|
||||||
|
{
|
||||||
|
dReturnVal = vecdGains[iChanID];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Mutex.unlock();
|
||||||
|
|
||||||
|
return dReturnVal;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CChannel::SetName ( const QString strNewName )
|
||||||
|
{
|
||||||
|
bool bNameHasChanged = false;
|
||||||
|
|
||||||
|
Mutex.lock();
|
||||||
|
{
|
||||||
|
// apply value (if different from previous name)
|
||||||
|
if ( sName.compare ( strNewName ) )
|
||||||
|
{
|
||||||
|
sName = strNewName;
|
||||||
|
bNameHasChanged = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Mutex.unlock();
|
||||||
|
|
||||||
|
// fire message that name has changed
|
||||||
|
if ( bNameHasChanged )
|
||||||
|
{
|
||||||
|
// the "emit" has to be done outside the mutexed region
|
||||||
|
emit NameHasChanged();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
QString CChannel::GetName()
|
||||||
|
{
|
||||||
|
// make sure the string is not written at the same time when it is
|
||||||
|
// read here -> use mutex to secure access
|
||||||
|
QString strReturn;
|
||||||
|
|
||||||
|
Mutex.lock();
|
||||||
|
{
|
||||||
|
strReturn = sName;
|
||||||
|
}
|
||||||
|
Mutex.unlock();
|
||||||
|
|
||||||
|
return strReturn;
|
||||||
|
}
|
||||||
|
|
||||||
void CChannel::OnSendProtMessage ( CVector<uint8_t> vecMessage )
|
void CChannel::OnSendProtMessage ( CVector<uint8_t> vecMessage )
|
||||||
{
|
{
|
||||||
// only send messages if we are connected, otherwise delete complete queue
|
// only send messages if we are connected, otherwise delete complete queue
|
||||||
|
@ -682,25 +777,6 @@ void CChannel::OnSendProtMessage ( CVector<uint8_t> vecMessage )
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CChannel::SetSockBufSize ( const int iNumBlocks )
|
|
||||||
{
|
|
||||||
// this opperation must be done with mutex
|
|
||||||
Mutex.lock();
|
|
||||||
{
|
|
||||||
iCurSockBufSize = iNumBlocks;
|
|
||||||
|
|
||||||
// the idea of setting the jitter buffer is as follows:
|
|
||||||
// The network block size is a multiple of the internal minimal
|
|
||||||
// block size. Therefore, the minimum jitter buffer size must be
|
|
||||||
// so that it can take one network buffer -> NET_BLOCK_SIZE_FACTOR.
|
|
||||||
// The actual jitter compensation are then the additional blocks of
|
|
||||||
// the internal block size, which is set with SetSockBufSize
|
|
||||||
SockBuf.Init ( MIN_BLOCK_SIZE_SAMPLES,
|
|
||||||
iNumBlocks + iCurNetwInBlSiFact );
|
|
||||||
}
|
|
||||||
Mutex.unlock();
|
|
||||||
}
|
|
||||||
|
|
||||||
void CChannel::OnNetwBlSiFactChange ( int iNewNetwBlSiFact )
|
void CChannel::OnNetwBlSiFactChange ( int iNewNetwBlSiFact )
|
||||||
{
|
{
|
||||||
SetNetwBufSizeFactOut ( iNewNetwBlSiFact );
|
SetNetwBufSizeFactOut ( iNewNetwBlSiFact );
|
||||||
|
@ -713,36 +789,34 @@ void CChannel::OnJittBufSizeChange ( int iNewJitBufSize )
|
||||||
|
|
||||||
void CChannel::OnChangeChanGain ( int iChanID, double dNewGain )
|
void CChannel::OnChangeChanGain ( int iChanID, double dNewGain )
|
||||||
{
|
{
|
||||||
Q_ASSERT ( ( iChanID >= 0 ) && ( iChanID < MAX_NUM_CHANNELS ) );
|
SetGain ( iChanID, dNewGain );
|
||||||
|
|
||||||
// set value
|
|
||||||
vecdGains[iChanID] = dNewGain;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CChannel::OnChangeChanName ( QString strName )
|
void CChannel::OnChangeChanName ( QString strName )
|
||||||
{
|
{
|
||||||
// apply value (if different from previous name)
|
SetName ( strName );
|
||||||
if ( sName.compare ( strName ) )
|
|
||||||
{
|
|
||||||
sName = strName;
|
|
||||||
|
|
||||||
// fire message that name has changed
|
|
||||||
emit NameHasChanged();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CChannel::GetAddress(CHostAddress& RetAddr)
|
bool CChannel::GetAddress(CHostAddress& RetAddr)
|
||||||
{
|
{
|
||||||
|
bool bReturnFlag;
|
||||||
|
|
||||||
|
Mutex.lock();
|
||||||
|
{
|
||||||
if ( IsConnected() )
|
if ( IsConnected() )
|
||||||
{
|
{
|
||||||
RetAddr = InetAddr;
|
RetAddr = InetAddr;
|
||||||
return true;
|
bReturnFlag = true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
RetAddr = CHostAddress();
|
RetAddr = CHostAddress();
|
||||||
return false;
|
bReturnFlag = false;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
Mutex.unlock();
|
||||||
|
|
||||||
|
return bReturnFlag;
|
||||||
}
|
}
|
||||||
|
|
||||||
EPutDataStat CChannel::PutData ( const CVector<unsigned char>& vecbyData,
|
EPutDataStat CChannel::PutData ( const CVector<unsigned char>& vecbyData,
|
||||||
|
|
|
@ -89,14 +89,14 @@ public:
|
||||||
bool GetAddress ( CHostAddress& RetAddr );
|
bool GetAddress ( CHostAddress& RetAddr );
|
||||||
CHostAddress GetAddress() { return InetAddr; }
|
CHostAddress GetAddress() { return InetAddr; }
|
||||||
|
|
||||||
void SetName ( const QString sNNa ) { sName = sNNa; }
|
void SetName ( const QString sNNa );
|
||||||
QString GetName() { return sName; }
|
QString GetName();
|
||||||
|
|
||||||
void SetRemoteName ( const QString strName )
|
void SetRemoteName ( const QString strName )
|
||||||
{ Protocol.CreateChanNameMes ( strName ); }
|
{ Protocol.CreateChanNameMes ( strName ); }
|
||||||
|
|
||||||
void SetGain ( const int iNID, const double dNG ) { vecdGains[iNID] = dNG; }
|
void SetGain ( const int iChanID, const double dNewGain );
|
||||||
double GetGain( const int iNID ) { return vecdGains[iNID]; }
|
double GetGain ( const int iChanID );
|
||||||
|
|
||||||
void SetRemoteChanGain ( const int iId, const double dGain )
|
void SetRemoteChanGain ( const int iId, const double dGain )
|
||||||
{ Protocol.CreateChanGainMes ( iId, dGain ); }
|
{ Protocol.CreateChanGainMes ( iId, dGain ); }
|
||||||
|
@ -142,6 +142,8 @@ protected:
|
||||||
void SetNetwInBlSiFactAndCompr ( const int iNewBlockSizeFactor,
|
void SetNetwInBlSiFactAndCompr ( const int iNewBlockSizeFactor,
|
||||||
const CAudioCompression::EAudComprType eNewAudComprType );
|
const CAudioCompression::EAudComprType eNewAudComprType );
|
||||||
|
|
||||||
|
void SetSockBufSizeIntern ( const int iNumBlocks );
|
||||||
|
|
||||||
// audio compression
|
// audio compression
|
||||||
CAudioCompression AudioCompressionIn;
|
CAudioCompression AudioCompressionIn;
|
||||||
CAudioCompression AudioCompressionOut;
|
CAudioCompression AudioCompressionOut;
|
||||||
|
|
Loading…
Reference in a new issue