prepared implementation for connected client list and individual gains for mixing at server for each channel

This commit is contained in:
Volker Fischer 2006-11-04 09:57:59 +00:00
parent f2c6d5d244
commit 3d4153fd75
6 changed files with 98 additions and 27 deletions

View file

@ -151,13 +151,15 @@ bool CChannelSet::PutData ( const CVector<unsigned char>& vecbyRecBuf,
} }
void CChannelSet::GetBlockAllConC ( CVector<int>& vecChanID, void CChannelSet::GetBlockAllConC ( CVector<int>& vecChanID,
CVector<CVector<double> >& vecvecdData ) CVector<CVector<double> >& vecvecdData,
CVector<double>& vecdGains )
{ {
/* init temporal data vector and clear input buffers */ /* init temporal data vector and clear input buffers */
CVector<double> vecdData ( MIN_BLOCK_SIZE_SAMPLES ); CVector<double> vecdData ( MIN_BLOCK_SIZE_SAMPLES );
vecChanID.Init ( 0 ); vecChanID.Init ( 0 );
vecvecdData.Init ( 0 ); vecvecdData.Init ( 0 );
vecdGains.Init ( 0 );
/* make put and get calls thread safe. Do not forget to unlock mutex /* make put and get calls thread safe. Do not forget to unlock mutex
afterwards! */ afterwards! */
@ -172,8 +174,9 @@ void CChannelSet::GetBlockAllConC ( CVector<int>& vecChanID,
if ( vecChannels[i].IsConnected() ) if ( vecChannels[i].IsConnected() )
{ {
/* add ID and data */ /* add ID, gain and data */
vecChanID.Add ( i ); vecChanID.Add ( i );
vecdGains.Add ( vecChannels[i].GetGain() );
const int iOldSize = vecvecdData.Size(); const int iOldSize = vecvecdData.Size();
vecvecdData.Enlarge ( 1 ); vecvecdData.Enlarge ( 1 );
@ -226,7 +229,7 @@ void CChannelSet::GetConCliParam ( CVector<CHostAddress>& vecHostAddresses,
/******************************************************************************\ /******************************************************************************\
* CChannel * * CChannel *
\******************************************************************************/ \******************************************************************************/
CChannel::CChannel() : sName ( "" ) CChannel::CChannel() : sName ( "" ), dGain ( (double) 1.0 )
{ {
// 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 // audio packet was received
@ -238,9 +241,6 @@ CChannel::CChannel() : sName ( "" )
CAudioCompression::CT_IMAADPCM ); CAudioCompression::CT_IMAADPCM );
} }
/* init time stamp index counter */
byTimeStampIdxCnt = 0;
iCurNetwInBlSiFact = DEF_NET_BLOCK_SIZE_FACTOR; iCurNetwInBlSiFact = DEF_NET_BLOCK_SIZE_FACTOR;
/* init the socket buffer */ /* init the socket buffer */

View file

@ -82,6 +82,9 @@ public:
void SetName ( const std::string sNNa ) { sName = sNNa; } void SetName ( const std::string sNNa ) { sName = sNNa; }
std::string GetName() { return sName; } std::string GetName() { return sName; }
void SetGain ( const double dNG ) { dGain = dNG; }
double GetGain() { return dGain; }
void SetSockBufSize ( const int iNumBlocks ); void SetSockBufSize ( const int iNumBlocks );
int GetSockBufSize() { return iCurSockBufSize; } int GetSockBufSize() { return iCurSockBufSize; }
@ -129,7 +132,10 @@ protected:
CHostAddress InetAddr; CHostAddress InetAddr;
// channel name // channel name
std::string sName; std::string sName;
// mixer and effect settings
double dGain;
// network jitter-buffer // network jitter-buffer
CNetBuf SockBuf; CNetBuf SockBuf;
@ -141,10 +147,6 @@ protected:
// network protocol // network protocol
CProtocol Protocol; CProtocol Protocol;
// time stamp index counter
Q_UINT8 byTimeStampIdxCnt;
int iTimeStampActCnt;
int iConTimeOut; int iConTimeOut;
int iConTimeOutStartVal; int iConTimeOutStartVal;
@ -184,7 +186,8 @@ public:
int CheckAddr ( const CHostAddress& Addr ); int CheckAddr ( const CHostAddress& Addr );
void GetBlockAllConC ( CVector<int>& vecChanID, void GetBlockAllConC ( CVector<int>& vecChanID,
CVector<CVector<double> >& vecvecdData ); CVector<CVector<double> >& vecvecdData,
CVector<double>& vecdGains );
void GetConCliParam ( CVector<CHostAddress>& vecHostAddresses, void GetConCliParam ( CVector<CHostAddress>& vecHostAddresses,
CVector<int>& veciJitBufSize, CVector<int>& veciJitBufSize,

View file

@ -49,7 +49,7 @@ MESSAGES
note: does not have any data -> n = 0 note: does not have any data -> n = 0
- network buffer block size factor PROTMESSID_NET_BLSI_FACTOR - Network buffer block size factor PROTMESSID_NET_BLSI_FACTOR
note: size, relative to minimum block size note: size, relative to minimum block size
@ -57,6 +57,15 @@ MESSAGES
| 2 bytes factor | | 2 bytes factor |
+----------------+ +----------------+
- Gain of channel PROTMESSID_CHANNEL_GAIN
for each connected client append following data:
+--------------------+--------------+
| 2 bytes channel ID | 2 bytes gain |
+--------------------+--------------+
- IP number and name of connected clients PROTMESSID_CONN_CLIENTS_LIST - IP number and name of connected clients PROTMESSID_CONN_CLIENTS_LIST
for each connected client append following data: for each connected client append following data:
@ -370,13 +379,62 @@ void CProtocol::CreateNetwBlSiFactMes ( const int iNetwBlSiFact )
CreateAndSendMessage ( PROTMESSID_NET_BLSI_FACTOR, vecData ); CreateAndSendMessage ( PROTMESSID_NET_BLSI_FACTOR, vecData );
} }
//void CProtocol::CreateConClientListMes ( const ) void CProtocol::CreateChanGainMes ( const int iChanID, const double dGain )
//{ {
// TODO CVector<uint8_t> vecData ( 4 ); // 4 bytes of data
//PROTMESSID_CONN_CLIENTS_LIST unsigned int iPos = 0; // init position pointer
// build data vector
// channel ID
PutValOnStream ( vecData, iPos, static_cast<uint32_t> ( iChanID ), 2 );
//} // actual gain, we convert from double with range 0..1 to integer
const int iCurGain = (int) ( dGain * ( 1 << 16 ) );
PutValOnStream ( vecData, iPos, static_cast<uint32_t> ( iCurGain ), 2 );
CreateAndSendMessage ( PROTMESSID_CHANNEL_GAIN, vecData );
}
void CProtocol::CreateConClientListMes ( const CVector<uint32_t>& veciIpAddrs,
const CVector<std::string>& vecstrNames )
{
const int iNumClients = veciIpAddrs.Size();
// build data vector
CVector<uint8_t> vecData ( 0 );
unsigned int iPos = 0; // init position pointer
for ( int i = 0; i < iNumClients; i++ )
{
// current string size
const int iCurStrLen = vecstrNames[i].size();
// size of current list entry
const int iCurListEntrLen =
4 /* IP addr. */ + 2 /* str. size */ + iCurStrLen;
// make space for new data
vecData.Enlarge ( iCurListEntrLen );
// IP address (4 bytes)
PutValOnStream ( vecData, iPos,
static_cast<uint32_t> ( veciIpAddrs[i] ), 4 );
// number of bytes for name string (2 bytes)
PutValOnStream ( vecData, iPos,
static_cast<uint32_t> ( iCurStrLen ), 2 );
// name string (n bytes)
for ( int j = 0; j < iCurStrLen; j++ )
{
// byte-by-byte copying of the string data
PutValOnStream ( vecData, iPos,
static_cast<uint32_t> ( vecstrNames[i][j] ), 1 );
}
}
CreateAndSendMessage ( PROTMESSID_CONN_CLIENTS_LIST, vecData );
}
/******************************************************************************\ /******************************************************************************\

View file

@ -41,6 +41,8 @@
#define PROTMESSID_REQ_JITT_BUF_SIZE 11 // request jitter buffer size #define PROTMESSID_REQ_JITT_BUF_SIZE 11 // request jitter buffer size
#define PROTMESSID_PING 12 // for measuring ping time #define PROTMESSID_PING 12 // for measuring ping time
#define PROTMESSID_NET_BLSI_FACTOR 13 // network buffer size factor #define PROTMESSID_NET_BLSI_FACTOR 13 // network buffer size factor
#define PROTMESSID_CHANNEL_GAIN 14 // set channel gain for mix
#define PROTMESSID_CONN_CLIENTS_LIST 15 // connected client list
// lengths of message as defined in protocol.cpp file // lengths of message as defined in protocol.cpp file
#define MESS_HEADER_LENGTH_BYTE 5 /* ID, cnt, length */ #define MESS_HEADER_LENGTH_BYTE 5 /* ID, cnt, length */
@ -62,6 +64,10 @@ public:
void CreateJitBufMes ( const int iJitBufSize ); void CreateJitBufMes ( const int iJitBufSize );
void CreateReqJitBufMes(); void CreateReqJitBufMes();
void CreateNetwBlSiFactMes ( const int iNetwBlSiFact ); void CreateNetwBlSiFactMes ( const int iNetwBlSiFact );
void CreateChanGainMes ( const int iChanID, const double dGain );
void CreateConClientListMes ( const CVector<uint32_t>& veciIpAddrs,
const CVector<std::string>& vecstrNames );
void CreateAndSendAcknMess ( const int& iID, const int& iCnt ); void CreateAndSendAcknMess ( const int& iID, const int& iCnt );

View file

@ -86,18 +86,19 @@ void CServer::Stop()
void CServer::OnTimer() void CServer::OnTimer()
{ {
CVector<int> vecChanID; CVector<int> vecChanID;
CVector<CVector<double> > vecvecdData ( MIN_BLOCK_SIZE_SAMPLES ); CVector<CVector<double> > vecvecdData ( MIN_BLOCK_SIZE_SAMPLES );
CVector<double> vecdGains;
/* get data from all connected clients */ /* get data from all connected clients */
ChannelSet.GetBlockAllConC ( vecChanID, vecvecdData ); ChannelSet.GetBlockAllConC ( vecChanID, vecvecdData, vecdGains );
const int iNumClients = vecvecdData.Size (); const int iNumClients = vecChanID.Size();
/* Check if at least one client is connected. If not, stop server until /* Check if at least one client is connected. If not, stop server until
one client is connected */ one client is connected */
if ( iNumClients != 0 ) if ( iNumClients != 0 )
{ {
/* actual processing of audio data -> mix */ /* actual processing of audio data -> mix */
vecsSendData = ProcessData ( vecvecdData ); vecsSendData = ProcessData ( vecvecdData, vecdGains );
/* send the same data to all connected clients */ /* send the same data to all connected clients */
for ( int i = 0; i < iNumClients; i++ ) for ( int i = 0; i < iNumClients; i++ )
@ -134,7 +135,8 @@ void CServer::OnTimer()
} }
} }
CVector<short> CServer::ProcessData ( CVector<CVector<double> >& vecvecdData ) CVector<short> CServer::ProcessData ( CVector<CVector<double> >& vecvecdData,
CVector<double>& vecdGains )
{ {
CVector<short> vecsOutData; CVector<short> vecsOutData;
vecsOutData.Init ( MIN_BLOCK_SIZE_SAMPLES ); vecsOutData.Init ( MIN_BLOCK_SIZE_SAMPLES );
@ -152,7 +154,7 @@ CVector<short> CServer::ProcessData ( CVector<CVector<double> >& vecvecdData )
for ( int j = 0; j < iNumClients; j++ ) for ( int j = 0; j < iNumClients; j++ )
{ {
dMixedData += vecvecdData[j][i]; dMixedData += vecvecdData[j][i] * vecdGains[j];
} }
/* normalization and truncating to short */ /* normalization and truncating to short */

View file

@ -62,7 +62,9 @@ public:
CChannelSet* GetChannelSet () { return &ChannelSet; } CChannelSet* GetChannelSet () { return &ChannelSet; }
protected: protected:
CVector<short> ProcessData ( CVector<CVector<double> >& vecvecdData ); CVector<short> ProcessData ( CVector<CVector<double> >& vecvecdData,
CVector<double>& vecdGains );
virtual void customEvent ( QCustomEvent* Event ); virtual void customEvent ( QCustomEvent* Event );
QTimer Timer; QTimer Timer;