even more work done

This commit is contained in:
Volker Fischer 2009-07-28 20:31:23 +00:00
parent 6768e0ebf9
commit bb7e32872f
8 changed files with 104 additions and 143 deletions

View file

@ -287,38 +287,3 @@ void CNetBuf::Clear ( const EClearType eClearType )
} }
} }
} }
/* conversion buffer implementation *******************************************/
void CConvBuf::Init ( const int iNewMemSize )
{
// set memory size
iMemSize = iNewMemSize;
// allocate and clear memory for actual data buffer
vecsMemory.Init ( iMemSize );
iPutPos = 0;
}
bool CConvBuf::Put ( const CVector<short>& vecsData )
{
const int iVecSize = vecsData.Size();
// copy new data in internal buffer
int iCurPos = 0;
const int iEnd = iPutPos + iVecSize;
while ( iPutPos < iEnd )
{
vecsMemory[iPutPos++] = vecsData[iCurPos++];
}
// return "buffer is ready for readout" flag
return iEnd == iMemSize;
}
CVector<short> CConvBuf::Get()
{
iPutPos = 0;
return vecsMemory;
}

View file

@ -58,20 +58,49 @@ protected:
// conversion buffer (very simple buffer) // conversion buffer (very simple buffer)
class CConvBuf template<class TData> class CConvBuf
{ {
public: public:
CConvBuf() {} CConvBuf() {}
virtual ~CConvBuf() {} virtual ~CConvBuf() {}
void Init ( const int iNewMemSize ); void Init ( const int iNewMemSize )
int GetSize() { return iMemSize; } {
// set memory size
iMemSize = iNewMemSize;
bool Put ( const CVector<short>& vecsData ); // allocate and clear memory for actual data buffer
CVector<short> Get(); vecsMemory.Init ( iMemSize );
iPutPos = 0;
}
int GetSize() const { return iMemSize; }
bool CConvBuf::Put ( const CVector<TData>& vecsData )
{
const int iVecSize = vecsData.Size();
// copy new data in internal buffer
int iCurPos = 0;
const int iEnd = iPutPos + iVecSize;
while ( iPutPos < iEnd )
{
vecsMemory[iPutPos++] = vecsData[iCurPos++];
}
// return "buffer is ready for readout" flag
return ( iEnd == iMemSize );
}
CVector<TData> CConvBuf::Get()
{
iPutPos = 0;
return vecsMemory;
}
protected: protected:
CVector<short> vecsMemory; CVector<TData> vecsMemory;
int iMemSize; int iMemSize;
int iPutPos; int iPutPos;
}; };

View file

@ -31,13 +31,9 @@ CChannel::CChannel ( const bool bNIsServer ) :
sName ( "" ), sName ( "" ),
vecdGains ( USED_NUM_CHANNELS, (double) 1.0 ), vecdGains ( USED_NUM_CHANNELS, (double) 1.0 ),
bIsEnabled ( false ), bIsEnabled ( false ),
iCurNetwFrameSizeFactOut ( 0 ), iNetwFrameSizeFact ( 0 ),
iCurNetwFrameSizeOut ( 0 ) iNetwFrameSize ( 0 )
{ {
// init network input properties
NetwBufferInProps.iAudioBlockSize = 0;
NetwBufferInProps.iNetwInBufSize = 0;
// initial value for connection time out counter, we calculate the total // initial value for connection time out counter, we calculate the total
// number of samples here and subtract the number of samples of the block // number of samples here and subtract the number of samples of the block
// which we take out of the buffer to be independent of block sizes // which we take out of the buffer to be independent of block sizes
@ -49,18 +45,6 @@ CChannel::CChannel ( const bool bNIsServer ) :
// init the socket buffer // init the socket buffer
SetSockBufSize ( DEF_NET_BUF_SIZE_NUM_BL ); SetSockBufSize ( DEF_NET_BUF_SIZE_NUM_BL );
// set initial output block size factors
/*
if ( bIsServer )
{
SetNetwBufSizeFactOut ( DEF_NET_BLOCK_SIZE_FACTOR );
}
else
{
SetNetwBufSizeOut ( MIN_SERVER_BLOCK_SIZE_SAMPLES );
}
*/
// connections ------------------------------------------------------------- // connections -------------------------------------------------------------
QObject::connect ( &Protocol, QObject::connect ( &Protocol,
@ -138,21 +122,24 @@ void CChannel::SetEnable ( const bool bNEnStat )
} }
} }
void CChannel::SetNetwBufSizeFactOut ( const int iNewNetwBlSiFactOut ) void CChannel::SetNetwFrameSizeAndFact ( const int iNewNetwFrameSize,
const int iNewNetwFrameSizeFact )
{ {
// this function is intended for the server (not the client) // this function is intended for the server (not the client)
QMutexLocker locker ( &Mutex ); QMutexLocker locker ( &Mutex );
// store new value // store new values
iCurNetwOutBlSiFact = iNewNetwBlSiFactOut; iNetwFrameSize = iNewNetwFrameSize;
iNetwFrameSizeFact = iNewNetwFrameSizeFact;
// init audio compression and get audio compression block size
// iAudComprSizeOut = AudioCompressionOut.Init (
// iNewNetwBlSiFactOut * SYSTEM_BLOCK_SIZE_SAMPLES, eAudComprTypeOut );
iAudComprSizeOut = iNewNetwBlSiFactOut * SYSTEM_BLOCK_SIZE_SAMPLES;
// init conversion buffer // init conversion buffer
ConvBuf.Init ( iNewNetwBlSiFactOut * SYSTEM_BLOCK_SIZE_SAMPLES ); ConvBuf.Init ( iNetwFrameSize * iNetwFrameSizeFact );
// initialize and reset cycle time variance measurement
CycleTimeVariance.Init ( iNetwFrameSizeFact * SYSTEM_BLOCK_SIZE_SAMPLES,
SYSTEM_SAMPLE_RATE, TIME_MOV_AV_RESPONSE );
CycleTimeVariance.Reset();
} }
bool CChannel::SetSockBufSize ( const int iNumBlocks ) bool CChannel::SetSockBufSize ( const int iNumBlocks )
@ -281,34 +268,16 @@ bool CChannel::GetAddress(CHostAddress& RetAddr)
void CChannel::OnNetTranspPropsReceived ( CNetworkTransportProps NetworkTransportProps ) void CChannel::OnNetTranspPropsReceived ( CNetworkTransportProps NetworkTransportProps )
{ {
QMutexLocker locker ( &Mutex ); // only the server shall act on network transport properties message
// apply received parameters to internal data struct
// NetwBufferInProps.iAudioBlockSize = NetworkTransportProps.iMonoAudioBlockSize;
NetwBufferInProps.iNetwInBufSize = NetworkTransportProps.iNetworkPacketSize;
// re-initialize cycle time variance measurement if necessary
if ( NetwBufferInProps.iAudioBlockSize != CycleTimeVariance.GetBlockLength() )
{
// re-init (we have to use the buffer size which works
// on the system sample rate, therefore we use the
// decompressed audio buffer size instead of the network
// buffer size)
CycleTimeVariance.Init ( NetwBufferInProps.iAudioBlockSize,
SYSTEM_SAMPLE_RATE, TIME_MOV_AV_RESPONSE );
CycleTimeVariance.Reset();
}
// in case of a server channel, use the same network buffer
// size factor as the connected client
if ( bIsServer ) if ( bIsServer )
{ {
QMutexLocker locker ( &Mutex );
// TODO // store received parameters
// if size is not equal iNetwFrameSizeFact = NetworkTransportProps.iBlockSizeFact;
// change size iNetwFrameSize =
NetworkTransportProps.iNetworkPacketSize /
NetworkTransportProps.iBlockSizeFact;
} }
} }
@ -320,8 +289,8 @@ void CChannel::OnReqNetTranspProps()
void CChannel::CreateNetTranspPropsMessFromCurrentSettings() void CChannel::CreateNetTranspPropsMessFromCurrentSettings()
{ {
CNetworkTransportProps NetworkTransportProps ( CNetworkTransportProps NetworkTransportProps (
iAudComprSizeOut, iNetwFrameSize * iNetwFrameSizeFact,
0, // TODO iNetwFrameSizeFact,
1, // right now we only use mono 1, // right now we only use mono
SYSTEM_SAMPLE_RATE, SYSTEM_SAMPLE_RATE,
CT_CELT, // always CELT coding CT_CELT, // always CELT coding
@ -376,7 +345,7 @@ EPutDataStat CChannel::PutData ( const CVector<uint8_t>& vecbyData,
// only process audio if packet has correct size // only process audio if packet has correct size
if ( iNumBytes == NetwBufferInProps.iNetwInBufSize ) if ( iNumBytes == ( iNetwFrameSize * iNetwFrameSizeFact ) )
{ {
// set audio packet flag // set audio packet flag
bIsAudioPacket = true; bIsAudioPacket = true;
@ -427,7 +396,10 @@ EPutDataStat CChannel::PutData ( const CVector<uint8_t>& vecbyData,
// if this is a new connection and the current network packet is // if this is a new connection and the current network packet is
// neither an audio or protocol packet, we have to query the // neither an audio or protocol packet, we have to query the
// network transport properties for the audio packets // network transport properties for the audio packets
if ( ( !bIsProtocolPacket ) && ( !bIsAudioPacket ) ) // (this is only required for server since we defined that the
// server has to send with the same properties as sent by
// the client)
if ( bIsServer && ( !bIsProtocolPacket ) && ( !bIsAudioPacket ) )
{ {
Protocol.CreateReqNetwTranspPropsMes(); Protocol.CreateReqNetwTranspPropsMes();
} }
@ -493,7 +465,7 @@ EGetDataStat CChannel::GetData ( CVector<uint8_t>& vecbyData )
return eGetStatus; return eGetStatus;
} }
CVector<uint8_t> CChannel::PrepSendPacket ( const CVector<short>& vecsNPacket ) CVector<uint8_t> CChannel::PrepSendPacket ( const CVector<uint8_t>& vecbyNPacket )
{ {
QMutexLocker locker ( &Mutex ); QMutexLocker locker ( &Mutex );
@ -503,11 +475,11 @@ CVector<uint8_t> CChannel::PrepSendPacket ( const CVector<short>& vecsNPacket )
// use conversion buffer to convert sound card block size in network // use conversion buffer to convert sound card block size in network
// block size // block size
if ( ConvBuf.Put ( vecsNPacket ) ) if ( ConvBuf.Put ( vecbyNPacket ) )
{ {
// a packet is ready, compress audio // a packet is ready
vecbySendBuf.Init ( iAudComprSizeOut ); vecbySendBuf.Init ( iNetwFrameSize * iNetwFrameSizeFact );
// vecbySendBuf = AudioCompressionOut.Encode ( ConvBuf.Get() ); vecbySendBuf = ConvBuf.Get();
} }
return vecbySendBuf; return vecbySendBuf;
@ -515,11 +487,12 @@ CVector<uint8_t> CChannel::PrepSendPacket ( const CVector<short>& vecsNPacket )
int CChannel::GetUploadRateKbps() int CChannel::GetUploadRateKbps()
{ {
const int iAudioSizeOut = iCurNetwOutBlSiFact * SYSTEM_BLOCK_SIZE_SAMPLES; const int iAudioSizeOut = iNetwFrameSizeFact * SYSTEM_BLOCK_SIZE_SAMPLES;
// we assume that the UDP packet which is transported via IP has an // we assume that the UDP packet which is transported via IP has an
// additional header size of // additional header size of
// 8 (UDP) + 20 (IP without optional fields) = 28 bytes // 8 (UDP) + 20 (IP without optional fields) = 28 bytes
return ( iAudComprSizeOut + 28 /* header */ ) * 8 /* bits per byte */ * return ( iNetwFrameSize * iNetwFrameSizeFact + 28 /* header */ ) *
8 /* bits per byte */ *
SYSTEM_SAMPLE_RATE / iAudioSizeOut / 1000; SYSTEM_SAMPLE_RATE / iAudioSizeOut / 1000;
} }

View file

@ -66,7 +66,7 @@ public:
int iNumBytes ); int iNumBytes );
EGetDataStat GetData ( CVector<uint8_t>& vecbyData ); EGetDataStat GetData ( CVector<uint8_t>& vecbyData );
CVector<uint8_t> PrepSendPacket ( const CVector<short>& vecsNPacket ); CVector<uint8_t> PrepSendPacket ( const CVector<uint8_t>& vecbyNPacket );
bool IsConnected() const { return iConTimeOut > 0; } bool IsConnected() const { return iConTimeOut > 0; }
@ -96,10 +96,10 @@ public:
double GetTimingStdDev() { return CycleTimeVariance.GetStdDev(); } double GetTimingStdDev() { return CycleTimeVariance.GetStdDev(); }
// set/get network out buffer size and size factor // set/get network out buffer size and size factor
void SetNetwFrameSizeAndFactOut ( const int iNewNetwFrameSizeOut, void SetNetwFrameSizeAndFact ( const int iNewNetwFrameSize,
const int iNewNetwFrameSizeFactOut ); const int iNewNetwFrameSizeFact );
int GetNetwFrameSizeFactOut() const { return iCurNetwFrameSizeFactOut; } int GetNetwFrameSizeFact() const { return iNetwFrameSizeFact; }
int GetNetwFrameSizeOut() const { return iCurNetwFrameSizeOut; } int GetNetwFrameSize() const { return iNetwFrameSize; }
// network protocol interface // network protocol interface
@ -150,7 +150,7 @@ protected:
CCycleTimeVariance CycleTimeVariance; CCycleTimeVariance CycleTimeVariance;
// network output conversion buffer // network output conversion buffer
CConvBuf ConvBuf; CConvBuf<uint8_t> ConvBuf;
// network protocol // network protocol
CProtocol Protocol; CProtocol Protocol;
@ -161,17 +161,10 @@ protected:
bool bIsEnabled; bool bIsEnabled;
bool bIsServer; bool bIsServer;
int iCurNetwFrameSizeFactOut;
int iCurNetwFrameSizeOut;
QMutex Mutex;
struct sNetwProperties
{
int iNetwFrameSizeFact; int iNetwFrameSizeFact;
int iNetwFrameSize; int iNetwFrameSize;
};
sNetwProperties NetwBufferInProps; QMutex Mutex;
public slots: public slots:
void OnSendProtMessage ( CVector<uint8_t> vecMessage ); void OnSendProtMessage ( CVector<uint8_t> vecMessage );

View file

@ -304,7 +304,7 @@ void CClient::Init ( const int iPrefMonoBlockSizeSamIndexAtSndCrdSamRate )
// set the channel network properties // set the channel network properties
// TEST right now we only support 128 samples, later 256 and 512, too // TEST right now we only support 128 samples, later 256 and 512, too
Channel.SetNetwFrameSizeAndFactOut ( iCeltNumCodedBytes, Channel.SetNetwFrameSizeAndFact ( iCeltNumCodedBytes,
1 ); // TEST "1" 1 ); // TEST "1"
} }

View file

@ -78,13 +78,13 @@ void CLlconServerDlg::OnTimer()
CVector<CHostAddress> vecHostAddresses; CVector<CHostAddress> vecHostAddresses;
CVector<QString> vecsName; CVector<QString> vecsName;
CVector<int> veciJitBufSize; CVector<int> veciJitBufSize;
CVector<int> veciNetwOutBlSiFact; CVector<int> veciNetwFrameSizeFact;
double dCurTiStdDev; double dCurTiStdDev;
ListViewMutex.lock(); ListViewMutex.lock();
pServer->GetConCliParam ( vecHostAddresses, vecsName, veciJitBufSize, pServer->GetConCliParam ( vecHostAddresses, vecsName, veciJitBufSize,
veciNetwOutBlSiFact ); veciNetwFrameSizeFact );
// fill list with connected clients // fill list with connected clients
for ( int i = 0; i < USED_NUM_CHANNELS; i++ ) for ( int i = 0; i < USED_NUM_CHANNELS; i++ )
@ -105,8 +105,9 @@ void CLlconServerDlg::OnTimer()
// out network block size // out network block size
vecpListViewItems[i]->setText ( 5, vecpListViewItems[i]->setText ( 5,
QString().setNum ( QString().setNum ( static_cast<double> (
static_cast<double> ( veciNetwOutBlSiFact[i] * SYSTEM_BLOCK_DURATION_MS_FLOAT ), 'f', 2 ) ); veciNetwFrameSizeFact[i] * SYSTEM_BLOCK_DURATION_MS_FLOAT
), 'f', 2 ) );
vecpListViewItems[i]->setHidden ( false ); vecpListViewItems[i]->setHidden ( false );
} }

View file

@ -216,9 +216,9 @@ void CServer::OnTimer()
vecsSendData = ProcessData ( vecvecdData, vecvecdGains[i] ); vecsSendData = ProcessData ( vecvecdData, vecvecdGains[i] );
// send separate mix to current clients // send separate mix to current clients
Socket.SendPacket ( // Socket.SendPacket (
PrepSendPacket ( vecChanID[i], vecsSendData ), // PrepSendPacket ( vecChanID[i], vecsSendData ),
GetAddress ( vecChanID[i] ) ); // GetAddress ( vecChanID[i] ) );
} }
} }
else else
@ -566,7 +566,7 @@ bAudioOK = true;
void CServer::GetConCliParam ( CVector<CHostAddress>& vecHostAddresses, void CServer::GetConCliParam ( CVector<CHostAddress>& vecHostAddresses,
CVector<QString>& vecsName, CVector<QString>& vecsName,
CVector<int>& veciJitBufSize, CVector<int>& veciJitBufSize,
CVector<int>& veciNetwFrameSizeFactOut ) CVector<int>& veciNetwFrameSizeFact )
{ {
CHostAddress InetAddr; CHostAddress InetAddr;
@ -574,7 +574,7 @@ void CServer::GetConCliParam ( CVector<CHostAddress>& vecHostAddresses,
vecHostAddresses.Init ( USED_NUM_CHANNELS ); vecHostAddresses.Init ( USED_NUM_CHANNELS );
vecsName.Init ( USED_NUM_CHANNELS ); vecsName.Init ( USED_NUM_CHANNELS );
veciJitBufSize.Init ( USED_NUM_CHANNELS ); veciJitBufSize.Init ( USED_NUM_CHANNELS );
veciNetwFrameSizeFactOut.Init ( USED_NUM_CHANNELS ); veciNetwFrameSizeFact.Init ( USED_NUM_CHANNELS );
// check all possible channels // check all possible channels
for ( int i = 0; i < USED_NUM_CHANNELS; i++ ) for ( int i = 0; i < USED_NUM_CHANNELS; i++ )
@ -585,7 +585,7 @@ void CServer::GetConCliParam ( CVector<CHostAddress>& vecHostAddresses,
vecHostAddresses[i] = InetAddr; vecHostAddresses[i] = InetAddr;
vecsName[i] = vecChannels[i].GetName(); vecsName[i] = vecChannels[i].GetName();
veciJitBufSize[i] = vecChannels[i].GetSockBufSize(); veciJitBufSize[i] = vecChannels[i].GetSockBufSize();
veciNetwFrameSizeFactOut[i] = vecChannels[i].GetNetwFrameSizeFactOut(); veciNetwFrameSizeFact[i] = vecChannels[i].GetNetwFrameSizeFact();
} }
} }
} }

View file

@ -66,7 +66,7 @@ public:
void GetConCliParam ( CVector<CHostAddress>& vecHostAddresses, void GetConCliParam ( CVector<CHostAddress>& vecHostAddresses,
CVector<QString>& vecsName, CVector<QString>& vecsName,
CVector<int>& veciJitBufSize, CVector<int>& veciJitBufSize,
CVector<int>& veciNetwFrameSizeFactOut ); CVector<int>& veciNetwFrameSizeFact );
protected: protected:
// access functions for actual channels // access functions for actual channels
@ -74,8 +74,8 @@ protected:
{ return vecChannels[iChanNum].IsConnected(); } { return vecChannels[iChanNum].IsConnected(); }
CVector<uint8_t> PrepSendPacket ( const int iChanNum, CVector<uint8_t> PrepSendPacket ( const int iChanNum,
const CVector<short>& vecsNPacket ) const CVector<uint8_t>& vecbyNPacket )
{ return vecChannels[iChanNum].PrepSendPacket ( vecsNPacket ); } { return vecChannels[iChanNum].PrepSendPacket ( vecbyNPacket ); }
CHostAddress GetAddress ( const int iChanNum ) CHostAddress GetAddress ( const int iChanNum )
{ return vecChannels[iChanNum].GetAddress(); } { return vecChannels[iChanNum].GetAddress(); }