fix for mutex in channel object

This commit is contained in:
Volker Fischer 2009-03-02 09:36:00 +00:00
parent 10aea73304
commit c064b49576
3 changed files with 58 additions and 34 deletions

View file

@ -36,7 +36,7 @@
// the number of periods is critical for latency // the number of periods is critical for latency
#define NUM_PERIOD_BLOCKS_IN 2 #define NUM_PERIOD_BLOCKS_IN 2
#define NUM_PERIOD_BLOCKS_OUT 2 #define NUM_PERIOD_BLOCKS_OUT 1
#define MAX_SND_BUF_IN 200 #define MAX_SND_BUF_IN 200
#define MAX_SND_BUF_OUT 200 #define MAX_SND_BUF_OUT 200

View file

@ -914,7 +914,6 @@ void CChannel::OnNetTranspPropsReceived ( CNetworkTransportProps NetworkTranspor
QMutexLocker locker ( &Mutex ); QMutexLocker locker ( &Mutex );
// TEST // TEST
// TODO use mutex in Put function
// TODO check possiblity of received parameter -> error checking // TODO check possiblity of received parameter -> error checking
// utilize, e.g., MAX_MONO_AUD_BUFF_SIZE_AT_48KHZ // utilize, e.g., MAX_MONO_AUD_BUFF_SIZE_AT_48KHZ
vecNetwBufferInProps[0].iAudioBlockSize = NetworkTransportProps.iMonoAudioBlockSize; vecNetwBufferInProps[0].iAudioBlockSize = NetworkTransportProps.iMonoAudioBlockSize;
@ -954,7 +953,13 @@ EPutDataStat CChannel::PutData ( const CVector<unsigned char>& vecbyData,
// init flags // init flags
bool bIsProtocolPacket = false; bool bIsProtocolPacket = false;
bool bIsAudioPacket = false; bool bIsAudioPacket = false;
bool bNewConnection = false; bool bNewConnection = false;
bool bReinitializeIn = false;
bool bReinitializeOut = false;
// intermediate storage for new parameters
int iNewAudioBlockSize;
EAudComprType eNewAudComprType;
if ( bIsEnabled ) if ( bIsEnabled )
{ {
@ -973,41 +978,60 @@ EPutDataStat CChannel::PutData ( const CVector<unsigned char>& vecbyData,
// only try to parse audio if it was not a protocol packet // only try to parse audio if it was not a protocol packet
if ( !bIsProtocolPacket ) if ( !bIsProtocolPacket )
{ {
// check if this is an audio packet by checking all possible lengths Mutex.lock();
const int iPossNetwSizes = vecNetwBufferInProps.Size();
for ( int i = 0; i < iPossNetwSizes; i++ )
{ {
// check for low/high quality audio packets and set flags // check if this is an audio packet by checking all possible lengths
if ( iNumBytes == vecNetwBufferInProps[i].iNetwInBufSize ) const int iPossNetwSizes = vecNetwBufferInProps.Size();
for ( int i = 0; i < iPossNetwSizes; i++ )
{ {
bIsAudioPacket = true; // check for low/high quality audio packets and set flags
if ( iNumBytes == vecNetwBufferInProps[i].iNetwInBufSize )
// check if we are correctly initialized
const int iNewAudioBlockSize =
vecNetwBufferInProps[i].iAudioBlockSize;
const EAudComprType eNewAudComprType =
vecNetwBufferInProps[i].eAudComprType;
if ( ( iNewAudioBlockSize != iCurAudioBlockSizeIn ) ||
( eNewAudComprType != AudioCompressionIn.GetType() ) )
{ {
// re-initialize to new value bIsAudioPacket = true;
SetAudioBlockSizeAndComprIn (
iNewAudioBlockSize, eNewAudComprType );
}
// in case of a server channel, use the same audio // check if we are correctly initialized
// compression for output as for the input iNewAudioBlockSize =
if ( bIsServer ) vecNetwBufferInProps[i].iAudioBlockSize;
{
if ( GetAudioCompressionOut() != vecNetwBufferInProps[i].eAudComprType ) eNewAudComprType =
{ vecNetwBufferInProps[i].eAudComprType;
SetAudioCompressionOut ( vecNetwBufferInProps[i].eAudComprType );
if ( ( iNewAudioBlockSize != iCurAudioBlockSizeIn ) ||
( eNewAudComprType != AudioCompressionIn.GetType() ) )
{
bReinitializeIn = true;
} }
}
// in case of a server channel, use the same audio
// compression for output as for the input
if ( bIsServer )
{
if ( GetAudioCompressionOut() != eNewAudComprType )
{
bReinitializeOut = true;
}
}
}
}
Mutex.unlock();
// actual initialization calls have to be made
// outside the mutex region since they internally
// use the same mutex, too
if ( bReinitializeIn )
{
// re-initialize to new value
SetAudioBlockSizeAndComprIn (
iNewAudioBlockSize, eNewAudComprType );
}
if ( bReinitializeOut )
{
SetAudioCompressionOut ( eNewAudComprType );
} }
} }

View file

@ -161,7 +161,7 @@ void CClient::Start()
// init object // init object
// TEST // TEST
Init ( 192 ); Init ( 256 );
// enable channel // enable channel
Channel.SetEnable ( true ); Channel.SetEnable ( true );