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,22 +58,51 @@ protected:
// conversion buffer (very simple buffer)
class CConvBuf
template<class TData> class CConvBuf
{
public:
CConvBuf() {}
virtual ~CConvBuf() {}
void Init ( const int iNewMemSize );
int GetSize() { return iMemSize; }
void Init ( const int iNewMemSize )
{
// set memory size
iMemSize = iNewMemSize;
bool Put ( const CVector<short>& vecsData );
CVector<short> Get();
// allocate and clear memory for actual data buffer
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:
CVector<short> vecsMemory;
int iMemSize;
int iPutPos;
CVector<TData> vecsMemory;
int iMemSize;
int iPutPos;
};
#endif /* !defined ( BUFFER_H__3B123453_4344_BB23945IUHF1912__INCLUDED_ ) */

View File

@ -31,13 +31,9 @@ CChannel::CChannel ( const bool bNIsServer ) :
sName ( "" ),
vecdGains ( USED_NUM_CHANNELS, (double) 1.0 ),
bIsEnabled ( false ),
iCurNetwFrameSizeFactOut ( 0 ),
iCurNetwFrameSizeOut ( 0 )
iNetwFrameSizeFact ( 0 ),
iNetwFrameSize ( 0 )
{
// init network input properties
NetwBufferInProps.iAudioBlockSize = 0;
NetwBufferInProps.iNetwInBufSize = 0;
// initial value for connection time out counter, we calculate the total
// 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
@ -49,18 +45,6 @@ CChannel::CChannel ( const bool bNIsServer ) :
// init the socket buffer
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 -------------------------------------------------------------
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)
QMutexLocker locker ( &Mutex );
// store new value
iCurNetwOutBlSiFact = iNewNetwBlSiFactOut;
// init audio compression and get audio compression block size
// iAudComprSizeOut = AudioCompressionOut.Init (
// iNewNetwBlSiFactOut * SYSTEM_BLOCK_SIZE_SAMPLES, eAudComprTypeOut );
iAudComprSizeOut = iNewNetwBlSiFactOut * SYSTEM_BLOCK_SIZE_SAMPLES;
// store new values
iNetwFrameSize = iNewNetwFrameSize;
iNetwFrameSizeFact = iNewNetwFrameSizeFact;
// 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 )
@ -263,7 +250,7 @@ void CChannel::OnChangeChanName ( QString strName )
SetName ( strName );
}
bool CChannel::GetAddress(CHostAddress& RetAddr)
bool CChannel::GetAddress ( CHostAddress& RetAddr )
{
QMutexLocker locker ( &Mutex );
@ -281,34 +268,16 @@ bool CChannel::GetAddress(CHostAddress& RetAddr)
void CChannel::OnNetTranspPropsReceived ( CNetworkTransportProps NetworkTransportProps )
{
QMutexLocker locker ( &Mutex );
// 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
// only the server shall act on network transport properties message
if ( bIsServer )
{
QMutexLocker locker ( &Mutex );
// TODO
// if size is not equal
// change size
// store received parameters
iNetwFrameSizeFact = NetworkTransportProps.iBlockSizeFact;
iNetwFrameSize =
NetworkTransportProps.iNetworkPacketSize /
NetworkTransportProps.iBlockSizeFact;
}
}
@ -320,8 +289,8 @@ void CChannel::OnReqNetTranspProps()
void CChannel::CreateNetTranspPropsMessFromCurrentSettings()
{
CNetworkTransportProps NetworkTransportProps (
iAudComprSizeOut,
0, // TODO
iNetwFrameSize * iNetwFrameSizeFact,
iNetwFrameSizeFact,
1, // right now we only use mono
SYSTEM_SAMPLE_RATE,
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
if ( iNumBytes == NetwBufferInProps.iNetwInBufSize )
if ( iNumBytes == ( iNetwFrameSize * iNetwFrameSizeFact ) )
{
// set audio packet flag
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
// neither an audio or protocol packet, we have to query the
// 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();
}
@ -493,7 +465,7 @@ EGetDataStat CChannel::GetData ( CVector<uint8_t>& vecbyData )
return eGetStatus;
}
CVector<uint8_t> CChannel::PrepSendPacket ( const CVector<short>& vecsNPacket )
CVector<uint8_t> CChannel::PrepSendPacket ( const CVector<uint8_t>& vecbyNPacket )
{
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
// block size
if ( ConvBuf.Put ( vecsNPacket ) )
if ( ConvBuf.Put ( vecbyNPacket ) )
{
// a packet is ready, compress audio
vecbySendBuf.Init ( iAudComprSizeOut );
// vecbySendBuf = AudioCompressionOut.Encode ( ConvBuf.Get() );
// a packet is ready
vecbySendBuf.Init ( iNetwFrameSize * iNetwFrameSizeFact );
vecbySendBuf = ConvBuf.Get();
}
return vecbySendBuf;
@ -515,11 +487,12 @@ CVector<uint8_t> CChannel::PrepSendPacket ( const CVector<short>& vecsNPacket )
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
// additional header size of
// 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;
}

View File

@ -66,7 +66,7 @@ public:
int iNumBytes );
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; }
@ -96,10 +96,10 @@ public:
double GetTimingStdDev() { return CycleTimeVariance.GetStdDev(); }
// set/get network out buffer size and size factor
void SetNetwFrameSizeAndFactOut ( const int iNewNetwFrameSizeOut,
const int iNewNetwFrameSizeFactOut );
int GetNetwFrameSizeFactOut() const { return iCurNetwFrameSizeFactOut; }
int GetNetwFrameSizeOut() const { return iCurNetwFrameSizeOut; }
void SetNetwFrameSizeAndFact ( const int iNewNetwFrameSize,
const int iNewNetwFrameSizeFact );
int GetNetwFrameSizeFact() const { return iNetwFrameSizeFact; }
int GetNetwFrameSize() const { return iNetwFrameSize; }
// network protocol interface
@ -150,7 +150,7 @@ protected:
CCycleTimeVariance CycleTimeVariance;
// network output conversion buffer
CConvBuf ConvBuf;
CConvBuf<uint8_t> ConvBuf;
// network protocol
CProtocol Protocol;
@ -161,18 +161,11 @@ protected:
bool bIsEnabled;
bool bIsServer;
int iCurNetwFrameSizeFactOut;
int iCurNetwFrameSizeOut;
int iNetwFrameSizeFact;
int iNetwFrameSize;
QMutex Mutex;
struct sNetwProperties
{
int iNetwFrameSizeFact;
int iNetwFrameSize;
};
sNetwProperties NetwBufferInProps;
public slots:
void OnSendProtMessage ( CVector<uint8_t> vecMessage );
void OnJittBufSizeChange ( int iNewJitBufSize );

View File

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

View File

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

View File

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

View File

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