new management of network block size factors

This commit is contained in:
Volker Fischer 2006-03-13 19:32:23 +00:00
parent 95389cbf7a
commit c86cbcabdb
5 changed files with 50 additions and 36 deletions

View file

@ -90,7 +90,7 @@ protected:
class CAudioCompression
{
public:
enum EAudComprType {CT_NONE, CT_IMAADPCM};
enum EAudComprType { CT_NONE, CT_IMAADPCM };
CAudioCompression() {}
virtual ~CAudioCompression() {}

View file

@ -221,19 +221,29 @@ void CChannelSet::GetConCliParam ( CVector<CHostAddress>& vecHostAddresses,
* CChannel *
\******************************************************************************/
CChannel::CChannel()
{
/* init time stamp index counter */
{
// query all possible network in buffer sizes for determining if an
// audio packet was received
for ( int i = 0; i < ( NET_BLOCK_SIZE_FACTOR_MAX - 1 ); i++ )
{
// network block size factor must start from 1 -> ( i + 1 )
vecNetwInBufSizes[i] = AudioCompressionIn.Init (
( i + 1 ) * MIN_BLOCK_SIZE_SAMPLES,
CAudioCompression::CT_IMAADPCM );
}
/* init time stamp index counter */
byTimeStampIdxCnt = 0;
iCurNetwInBlSiFact = NET_BLOCK_SIZE_FACTOR;
/* init the socket buffer */
iCurNetwInBlSiFact = NET_BLOCK_SIZE_FACTOR;
/* init the socket buffer */
SetSockBufSize ( DEF_NET_BUF_SIZE_NUM_BL );
// set initial input and output block size factors
SetNetwBufSizeFact ( NET_BLOCK_SIZE_FACTOR );
/* init time-out for the buffer with zero -> no connection */
/* init time-out for the buffer with zero -> no connection */
iConTimeOut = 0;
@ -283,21 +293,17 @@ void CChannel::SetNetwOutBlSiFact ( const int iNewBlockSizeFactor )
void CChannel::OnSendProtMessage ( CVector<uint8_t> vecMessage )
{
// must be disabled to be able to receive network buffer size factor changes
// FIXME check, if this condition must be checked somewhere else!
// // only send messages if we are connected, otherwise delete complete queue
// if ( IsConnected() )
// {
// only send messages if we are connected, otherwise delete complete queue
if ( IsConnected() )
{
// emit message to actually send the data
emit MessReadyForSending ( vecMessage );
// }
// else
// {
// // delete send message queue
// Protocol.DeleteSendMessQueue();
// }
}
else
{
// delete send message queue
Protocol.DeleteSendMessQueue();
}
}
@ -366,10 +372,27 @@ EPutDataStat CChannel::PutData ( const CVector<unsigned char>& vecbyData,
int iNumBytes )
{
EPutDataStat eRet = PS_GEN_ERROR;
bool bNewConnection = false;
bool bNewConnection = false;
bool bIsAudioPacket = false;
// check if this is an audio packet by checking all possible lengths
for ( int i = 0; i < ( NET_BLOCK_SIZE_FACTOR_MAX - 1 ); i++ )
{
if ( iNumBytes == vecNetwInBufSizes[i] )
{
bIsAudioPacket = true;
// check if we are correctly initialized
if ( iAudComprSizeIn != vecNetwInBufSizes[i] )
{
// re-initialize to new value
SetNetwBufSizeFact ( i + 1 );
}
}
}
/* only process if packet has correct size */
if ( iNumBytes == iAudComprSizeIn )
if ( bIsAudioPacket )
{
Mutex.lock();
{
@ -456,7 +479,7 @@ bool CChannel::GetData ( CVector<double>& vecdData )
/* decrease time-out counter */
if ( iConTimeOut > 0 )
{
iConTimeOut--;
iConTimeOut--;
}
}
}
@ -479,13 +502,6 @@ CVector<unsigned char> CChannel::PrepSendPacket ( const CVector<short>& vecsNPac
vecbySendBuf.Init ( iAudComprSizeOut );
vecbySendBuf = AudioCompressionOut.Encode ( ConvBuf.Get() );
}
// if we are not connected, send network buffer size factor so that the
// server is able to process our audio packets
if ( !IsConnected() )
{
Protocol.CreateNetwBlSiFactMes ( iCurNetwBlSiFact );
}
return vecbySendBuf;
}

View file

@ -141,6 +141,8 @@ protected:
int iConTimeOut;
int iConTimeOutStartVal;
int vecNetwInBufSizes[NET_BLOCK_SIZE_FACTOR_MAX];
int iCurNetwInBlSiFact;
int iCurNetwBlSiFact; // TODO, will be replaced by in/out settings

View file

@ -57,10 +57,6 @@ for ( int i = 0; i < vecMessage.Size (); i++ ) {
void CClient::OnReqJittBufSize()
{
Channel.CreateJitBufMes ( Channel.GetSockBufSize() );
// FIXME: we set the network buffer size factor here, too -> in the
// future a separate request function for this parameter should be created
Channel.CreateNetwBlSiFactMes ( Channel.GetNetwBufSizeFact() );
}
bool CClient::SetServerAddr(QString strNAddr)

View file

@ -69,7 +69,7 @@
#define NET_BLOCK_SIZE_FACTOR 3 // 3 * 2 ms = 6 ms
// maximum value of factor for network block size
#define NET_BLOCK_SIZE_FACTOR_MAX 10
#define NET_BLOCK_SIZE_FACTOR_MAX 15
/* maximum network buffer size (which can be chosen by slider) */
#define MAX_NET_BUF_SIZE_NUM_BL 10 /* number of blocks */