bug fix, new command line parameter for maximum upload rate for server
This commit is contained in:
parent
c61b9d593a
commit
0278d83d4d
5 changed files with 77 additions and 69 deletions
117
src/channel.cpp
117
src/channel.cpp
|
@ -28,15 +28,14 @@
|
||||||
/******************************************************************************\
|
/******************************************************************************\
|
||||||
* CChannelSet *
|
* CChannelSet *
|
||||||
\******************************************************************************/
|
\******************************************************************************/
|
||||||
CChannelSet::CChannelSet ( const bool bForceLowUploadRate ) :
|
CChannelSet::CChannelSet ( const int iNewUploadRateLimitKbps ) :
|
||||||
bWriteStatusHTMLFile ( false ),
|
bWriteStatusHTMLFile ( false ),
|
||||||
iUploadRateLimit ( DEF_MAX_UPLOAD_RATE_KBPS )
|
iUploadRateLimitKbps ( iNewUploadRateLimitKbps )
|
||||||
{
|
{
|
||||||
// enable all channels and set server flag
|
// enable all channels
|
||||||
for ( int i = 0; i < USED_NUM_CHANNELS; i++ )
|
for ( int i = 0; i < USED_NUM_CHANNELS; i++ )
|
||||||
{
|
{
|
||||||
vecChannels[i].SetEnable ( true );
|
vecChannels[i].SetEnable ( true );
|
||||||
vecChannels[i].SetForceLowUploadRate ( bForceLowUploadRate );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// define colors for chat window identifiers
|
// define colors for chat window identifiers
|
||||||
|
@ -253,33 +252,46 @@ void CChannelSet::SetOutputParameters()
|
||||||
// is not enough, we start to increase the buffer size factor out.
|
// is not enough, we start to increase the buffer size factor out.
|
||||||
bool bUploadRateIsBelowLimit = false;
|
bool bUploadRateIsBelowLimit = false;
|
||||||
|
|
||||||
const int iNumTrials = 4;
|
// first initialize all channels with the first parameter set (highest
|
||||||
|
// upload data rate)
|
||||||
|
for ( int i = 0; i < USED_NUM_CHANNELS; i++ )
|
||||||
|
{
|
||||||
|
if ( vecChannels[i].IsConnected() )
|
||||||
|
{
|
||||||
|
// set new parameters
|
||||||
|
vecChannels[i].SetNetwBufSizeFactOut ( 1 );
|
||||||
|
vecChannels[i].SetAudioCompressionOut ( CT_NONE );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// calculate and check total upload rate (maybe the initialization already
|
||||||
|
// gives desired upload rate)
|
||||||
|
bUploadRateIsBelowLimit =
|
||||||
|
( CalculateTotalUploadRateKbps() <= iUploadRateLimitKbps );
|
||||||
|
|
||||||
|
// try other parameter sets if required
|
||||||
|
const int iNumTrials = 3;
|
||||||
EAudComprType eCurAudComprType;
|
EAudComprType eCurAudComprType;
|
||||||
int iCurBlockSizeFact;
|
int iCurBlockSizeFact;
|
||||||
|
|
||||||
for ( int iCurTrialIdx = 0; iCurTrialIdx < iNumTrials; iCurTrialIdx++ )
|
int iCurTrialIdx = 0;
|
||||||
|
while ( ( iCurTrialIdx < iNumTrials ) && ( !bUploadRateIsBelowLimit ) )
|
||||||
{
|
{
|
||||||
switch ( iCurTrialIdx )
|
switch ( iCurTrialIdx )
|
||||||
{
|
{
|
||||||
case 0:
|
case 0:
|
||||||
// highest data rate
|
|
||||||
eCurAudComprType = CT_NONE;
|
|
||||||
iCurBlockSizeFact = 1;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 1:
|
|
||||||
// using other audio compression gives most reduction
|
// using other audio compression gives most reduction
|
||||||
eCurAudComprType = CT_MSADPCM;
|
eCurAudComprType = CT_MSADPCM;
|
||||||
iCurBlockSizeFact = 1;
|
iCurBlockSizeFact = 1;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 2:
|
case 1:
|
||||||
// trying to use larger block size factor to further reduce rate
|
// trying to use larger block size factor to further reduce rate
|
||||||
eCurAudComprType = CT_MSADPCM;
|
eCurAudComprType = CT_MSADPCM;
|
||||||
iCurBlockSizeFact = 2;
|
iCurBlockSizeFact = 2;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 3:
|
case 2:
|
||||||
// trying to use larger block size factor to further reduce rate
|
// trying to use larger block size factor to further reduce rate
|
||||||
eCurAudComprType = CT_MSADPCM;
|
eCurAudComprType = CT_MSADPCM;
|
||||||
iCurBlockSizeFact = 3;
|
iCurBlockSizeFact = 3;
|
||||||
|
@ -296,24 +308,34 @@ void CChannelSet::SetOutputParameters()
|
||||||
vecChannels[iCurCh].SetAudioCompressionOut ( eCurAudComprType );
|
vecChannels[iCurCh].SetAudioCompressionOut ( eCurAudComprType );
|
||||||
|
|
||||||
// calculate and check total upload rate
|
// calculate and check total upload rate
|
||||||
int iTotalUploadRate = 0;
|
bUploadRateIsBelowLimit =
|
||||||
for ( int j = 0; j < USED_NUM_CHANNELS; j++ )
|
( CalculateTotalUploadRateKbps() <= iUploadRateLimitKbps );
|
||||||
{
|
|
||||||
if ( vecChannels[j].IsConnected() )
|
|
||||||
{
|
|
||||||
// accumulate the upload rates from all channels
|
|
||||||
iTotalUploadRate += vecChannels[j].GetUploadRateKbps();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
bUploadRateIsBelowLimit = ( iTotalUploadRate <= iUploadRateLimit );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// next channel
|
// next channel
|
||||||
iCurCh++;
|
iCurCh++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// next trial index
|
||||||
|
iCurTrialIdx++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int CChannelSet::CalculateTotalUploadRateKbps()
|
||||||
|
{
|
||||||
|
// calculate total upload rate
|
||||||
|
int iTotalUploadRate = 0;
|
||||||
|
for ( int i = 0; i < USED_NUM_CHANNELS; i++ )
|
||||||
|
{
|
||||||
|
if ( vecChannels[i].IsConnected() )
|
||||||
|
{
|
||||||
|
// accumulate the upload rates from all channels
|
||||||
|
iTotalUploadRate += vecChannels[i].GetUploadRateKbps();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return iTotalUploadRate;
|
||||||
|
}
|
||||||
|
|
||||||
int CChannelSet::CheckAddr ( const CHostAddress& Addr )
|
int CChannelSet::CheckAddr ( const CHostAddress& Addr )
|
||||||
{
|
{
|
||||||
CHostAddress InetAddr;
|
CHostAddress InetAddr;
|
||||||
|
@ -639,8 +661,7 @@ void CChannelSet::WriteHTMLChannelList()
|
||||||
\******************************************************************************/
|
\******************************************************************************/
|
||||||
CChannel::CChannel ( const bool bNIsServer ) : bIsServer ( bNIsServer ),
|
CChannel::CChannel ( const bool bNIsServer ) : bIsServer ( bNIsServer ),
|
||||||
sName ( "" ), vecdGains ( USED_NUM_CHANNELS, (double) 1.0 ),
|
sName ( "" ), vecdGains ( USED_NUM_CHANNELS, (double) 1.0 ),
|
||||||
bIsEnabled ( false ), bForceLowUploadRate ( false ),
|
bIsEnabled ( false ), iCurNetwOutBlSiFact ( DEF_NET_BLOCK_SIZE_FACTOR )
|
||||||
iCurNetwOutBlSiFact ( DEF_NET_BLOCK_SIZE_FACTOR )
|
|
||||||
{
|
{
|
||||||
// query all possible network in buffer sizes for determining if an
|
// query all possible network in buffer sizes for determining if an
|
||||||
// audio packet was received (the following code only works if all
|
// audio packet was received (the following code only works if all
|
||||||
|
@ -790,19 +811,6 @@ void CChannel::SetEnable ( const bool bNEnStat )
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CChannel::SetForceLowUploadRate ( const bool bNFoLoUpRat )
|
|
||||||
{
|
|
||||||
if ( bNFoLoUpRat )
|
|
||||||
{
|
|
||||||
// initialize with low upload rate parameters and set flag so that
|
|
||||||
// these parameters are not changed anymore
|
|
||||||
SetNetwBufSizeFactOut ( LOW_UPL_SET_BLOCK_SIZE_FACTOR_OUT );
|
|
||||||
SetAudioCompressionOut ( LOW_UPL_SET_AUDIO_COMPRESSION );
|
|
||||||
}
|
|
||||||
|
|
||||||
bForceLowUploadRate = bNFoLoUpRat;
|
|
||||||
}
|
|
||||||
|
|
||||||
void CChannel::SetAudioBlockSizeAndComprIn ( const int iNewBlockSize,
|
void CChannel::SetAudioBlockSizeAndComprIn ( const int iNewBlockSize,
|
||||||
const EAudComprType eNewAudComprType )
|
const EAudComprType eNewAudComprType )
|
||||||
{
|
{
|
||||||
|
@ -838,7 +846,7 @@ void CChannel::SetNetwBufSizeFactOut ( const int iNewNetwBlSiFactOut )
|
||||||
QMutexLocker locker ( &Mutex );
|
QMutexLocker locker ( &Mutex );
|
||||||
|
|
||||||
// use the network block size factor only for the server
|
// use the network block size factor only for the server
|
||||||
if ( ( !bForceLowUploadRate ) && bIsServer )
|
if ( bIsServer )
|
||||||
{
|
{
|
||||||
// store new value
|
// store new value
|
||||||
iCurNetwOutBlSiFact = iNewNetwBlSiFactOut;
|
iCurNetwOutBlSiFact = iNewNetwBlSiFactOut;
|
||||||
|
@ -854,23 +862,20 @@ void CChannel::SetNetwBufSizeFactOut ( const int iNewNetwBlSiFactOut )
|
||||||
|
|
||||||
void CChannel::SetAudioCompressionOut ( const EAudComprType eNewAudComprTypeOut )
|
void CChannel::SetAudioCompressionOut ( const EAudComprType eNewAudComprTypeOut )
|
||||||
{
|
{
|
||||||
if ( !bForceLowUploadRate )
|
// store new value
|
||||||
{
|
eAudComprTypeOut = eNewAudComprTypeOut;
|
||||||
// store new value
|
|
||||||
eAudComprTypeOut = eNewAudComprTypeOut;
|
|
||||||
|
|
||||||
if ( bIsServer )
|
if ( bIsServer )
|
||||||
{
|
{
|
||||||
// call "set network buffer size factor" function because its
|
// call "set network buffer size factor" function because its
|
||||||
// initialization depends on the audio compression format and
|
// initialization depends on the audio compression format and
|
||||||
// implicitely, the audio compression is initialized
|
// implicitely, the audio compression is initialized
|
||||||
SetNetwBufSizeFactOut ( iCurNetwOutBlSiFact );
|
SetNetwBufSizeFactOut ( iCurNetwOutBlSiFact );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// for client set arbitrary block size
|
// for client set arbitrary block size
|
||||||
SetNetwBufSizeOut ( iCurAudioBlockSizeOut );
|
SetNetwBufSizeOut ( iCurAudioBlockSizeOut );
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -89,7 +89,6 @@ public:
|
||||||
bool IsConnected() const { return iConTimeOut > 0; }
|
bool IsConnected() const { return iConTimeOut > 0; }
|
||||||
|
|
||||||
void SetEnable ( const bool bNEnStat );
|
void SetEnable ( const bool bNEnStat );
|
||||||
void SetForceLowUploadRate ( const bool bNFoLoUpRat );
|
|
||||||
|
|
||||||
void SetAddress ( const CHostAddress NAddr ) { InetAddr = NAddr; }
|
void SetAddress ( const CHostAddress NAddr ) { InetAddr = NAddr; }
|
||||||
bool GetAddress ( CHostAddress& RetAddr );
|
bool GetAddress ( CHostAddress& RetAddr );
|
||||||
|
@ -185,7 +184,6 @@ protected:
|
||||||
|
|
||||||
bool bIsEnabled;
|
bool bIsEnabled;
|
||||||
bool bIsServer;
|
bool bIsServer;
|
||||||
bool bForceLowUploadRate;
|
|
||||||
|
|
||||||
int iCurAudioBlockSizeIn;
|
int iCurAudioBlockSizeIn;
|
||||||
int iCurNetwOutBlSiFact;
|
int iCurNetwOutBlSiFact;
|
||||||
|
@ -230,7 +228,7 @@ class CChannelSet : public QObject
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
CChannelSet ( const bool bForceLowUploadRate );
|
CChannelSet ( const int iNewUploadRateLimitKbps = DEF_MAX_UPLOAD_RATE_KBPS );
|
||||||
virtual ~CChannelSet() {}
|
virtual ~CChannelSet() {}
|
||||||
|
|
||||||
bool PutData ( const CVector<unsigned char>& vecbyRecBuf,
|
bool PutData ( const CVector<unsigned char>& vecbyRecBuf,
|
||||||
|
@ -264,6 +262,9 @@ public:
|
||||||
void StartStatusHTMLFileWriting ( const QString& strNewFileName,
|
void StartStatusHTMLFileWriting ( const QString& strNewFileName,
|
||||||
const QString& strNewServerNameWithPort );
|
const QString& strNewServerNameWithPort );
|
||||||
|
|
||||||
|
void SetUploadRateLimitKbps ( const int iNewUploadRateLimitKbps )
|
||||||
|
{ iUploadRateLimitKbps = iNewUploadRateLimitKbps; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
CVector<CChannelShortInfo> CreateChannelList();
|
CVector<CChannelShortInfo> CreateChannelList();
|
||||||
void CreateAndSendChanListForAllConChannels();
|
void CreateAndSendChanListForAllConChannels();
|
||||||
|
@ -272,6 +273,7 @@ protected:
|
||||||
void CreateAndSendChatTextForAllConChannels ( const int iCurChanID, const QString& strChatText );
|
void CreateAndSendChatTextForAllConChannels ( const int iCurChanID, const QString& strChatText );
|
||||||
void WriteHTMLChannelList();
|
void WriteHTMLChannelList();
|
||||||
void SetOutputParameters();
|
void SetOutputParameters();
|
||||||
|
int CalculateTotalUploadRateKbps();
|
||||||
|
|
||||||
/* do not use the vector class since CChannel does not have appropriate
|
/* do not use the vector class since CChannel does not have appropriate
|
||||||
copy constructor/operator */
|
copy constructor/operator */
|
||||||
|
@ -280,7 +282,7 @@ protected:
|
||||||
|
|
||||||
CVector<QString> vstrChatColors;
|
CVector<QString> vstrChatColors;
|
||||||
|
|
||||||
int iUploadRateLimit;
|
int iUploadRateLimitKbps;
|
||||||
|
|
||||||
// HTML file server status
|
// HTML file server status
|
||||||
bool bWriteStatusHTMLFile;
|
bool bWriteStatusHTMLFile;
|
||||||
|
|
13
src/main.cpp
13
src/main.cpp
|
@ -45,7 +45,7 @@ int main ( int argc, char** argv )
|
||||||
/* check if server or client application shall be started */
|
/* check if server or client application shall be started */
|
||||||
bool bIsClient = true;
|
bool bIsClient = true;
|
||||||
bool bUseGUI = true;
|
bool bUseGUI = true;
|
||||||
bool bForceLowUploadRate = false;
|
int iUploadRateLimitKbps = DEF_MAX_UPLOAD_RATE_KBPS;
|
||||||
quint16 iPortNumber = LLCON_DFAULT_PORT_NUMBER;
|
quint16 iPortNumber = LLCON_DFAULT_PORT_NUMBER;
|
||||||
std::string strIniFileName = "";
|
std::string strIniFileName = "";
|
||||||
std::string strHTMLStatusFileName = "";
|
std::string strHTMLStatusFileName = "";
|
||||||
|
@ -82,10 +82,11 @@ int main ( int argc, char** argv )
|
||||||
}
|
}
|
||||||
|
|
||||||
// force low upload data rate flag -------------------------------------------
|
// force low upload data rate flag -------------------------------------------
|
||||||
if ( GetFlagArgument ( argc, argv, i, "-u", "--lowuploadrate" ) )
|
if ( GetNumericArgument ( argc, argv, i, "-u", "--maxuploadrate",
|
||||||
|
100, 1000000, rDbleArgument ) )
|
||||||
{
|
{
|
||||||
bForceLowUploadRate = true;
|
iUploadRateLimitKbps = static_cast<int> ( rDbleArgument );
|
||||||
cout << "force low upload rate" << std::endl;
|
cout << "maximum upload rate: " << iUploadRateLimitKbps << std::endl;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -194,7 +195,7 @@ int main ( int argc, char** argv )
|
||||||
iPortNumber,
|
iPortNumber,
|
||||||
strHTMLStatusFileName.c_str(),
|
strHTMLStatusFileName.c_str(),
|
||||||
strServerName.c_str(),
|
strServerName.c_str(),
|
||||||
bForceLowUploadRate );
|
iUploadRateLimitKbps );
|
||||||
|
|
||||||
if ( bUseGUI )
|
if ( bUseGUI )
|
||||||
{
|
{
|
||||||
|
@ -249,7 +250,7 @@ std::string UsageArguments ( char **argv )
|
||||||
" -i, --inifile initialization file name (only available for client)\n"
|
" -i, --inifile initialization file name (only available for client)\n"
|
||||||
" -p, --port local port number (only avaiable for server)\n"
|
" -p, --port local port number (only avaiable for server)\n"
|
||||||
" -m, --htmlstatus enable HTML status file, set file name (only avaiable for server)\n"
|
" -m, --htmlstatus enable HTML status file, set file name (only avaiable for server)\n"
|
||||||
" -u, --lowuploadrate force low upload rate (only avaiable for server)\n"
|
" -u, --maxuploadrate maximum upload rate (only avaiable for server)\n"
|
||||||
" -h, -?, --help this help text\n"
|
" -h, -?, --help this help text\n"
|
||||||
"Example: " + std::string ( argv[0] ) + " -l -inifile myinifile.ini\n";
|
"Example: " + std::string ( argv[0] ) + " -l -inifile myinifile.ini\n";
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,9 +30,9 @@ CServer::CServer ( const QString& strLoggingFileName,
|
||||||
const quint16 iPortNumber,
|
const quint16 iPortNumber,
|
||||||
const QString& strHTMLStatusFileName,
|
const QString& strHTMLStatusFileName,
|
||||||
const QString& strServerNameForHTMLStatusFile,
|
const QString& strServerNameForHTMLStatusFile,
|
||||||
const bool bForceLowUploadRate ) :
|
const int iNewUploadRateLimitKbps ) :
|
||||||
Socket ( &ChannelSet, this, iPortNumber ),
|
Socket ( &ChannelSet, this, iPortNumber ),
|
||||||
ChannelSet ( bForceLowUploadRate )
|
ChannelSet ( iNewUploadRateLimitKbps )
|
||||||
{
|
{
|
||||||
vecsSendData.Init ( MIN_SERVER_BLOCK_SIZE_SAMPLES );
|
vecsSendData.Init ( MIN_SERVER_BLOCK_SIZE_SAMPLES );
|
||||||
|
|
||||||
|
|
|
@ -45,7 +45,7 @@ public:
|
||||||
const quint16 iPortNumber,
|
const quint16 iPortNumber,
|
||||||
const QString& strHTMLStatusFileName,
|
const QString& strHTMLStatusFileName,
|
||||||
const QString& strServerNameForHTMLStatusFile,
|
const QString& strServerNameForHTMLStatusFile,
|
||||||
const bool bForceLowUploadRate );
|
const int iNewUploadRateLimitKbps );
|
||||||
virtual ~CServer() {}
|
virtual ~CServer() {}
|
||||||
|
|
||||||
void Start();
|
void Start();
|
||||||
|
|
Loading…
Add table
Reference in a new issue