prepared implementation for connected client list and individual gains for mixing at server for each channel
This commit is contained in:
parent
f2c6d5d244
commit
3d4153fd75
6 changed files with 98 additions and 27 deletions
|
@ -151,13 +151,15 @@ bool CChannelSet::PutData ( const CVector<unsigned char>& vecbyRecBuf,
|
|||
}
|
||||
|
||||
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 */
|
||||
CVector<double> vecdData ( MIN_BLOCK_SIZE_SAMPLES );
|
||||
|
||||
vecChanID.Init ( 0 );
|
||||
vecvecdData.Init ( 0 );
|
||||
vecdGains.Init ( 0 );
|
||||
|
||||
/* make put and get calls thread safe. Do not forget to unlock mutex
|
||||
afterwards! */
|
||||
|
@ -172,8 +174,9 @@ void CChannelSet::GetBlockAllConC ( CVector<int>& vecChanID,
|
|||
|
||||
if ( vecChannels[i].IsConnected() )
|
||||
{
|
||||
/* add ID and data */
|
||||
/* add ID, gain and data */
|
||||
vecChanID.Add ( i );
|
||||
vecdGains.Add ( vecChannels[i].GetGain() );
|
||||
|
||||
const int iOldSize = vecvecdData.Size();
|
||||
vecvecdData.Enlarge ( 1 );
|
||||
|
@ -226,7 +229,7 @@ void CChannelSet::GetConCliParam ( CVector<CHostAddress>& vecHostAddresses,
|
|||
/******************************************************************************\
|
||||
* CChannel *
|
||||
\******************************************************************************/
|
||||
CChannel::CChannel() : sName ( "" )
|
||||
CChannel::CChannel() : sName ( "" ), dGain ( (double) 1.0 )
|
||||
{
|
||||
// query all possible network in buffer sizes for determining if an
|
||||
// audio packet was received
|
||||
|
@ -238,9 +241,6 @@ CChannel::CChannel() : sName ( "" )
|
|||
CAudioCompression::CT_IMAADPCM );
|
||||
}
|
||||
|
||||
/* init time stamp index counter */
|
||||
byTimeStampIdxCnt = 0;
|
||||
|
||||
iCurNetwInBlSiFact = DEF_NET_BLOCK_SIZE_FACTOR;
|
||||
|
||||
/* init the socket buffer */
|
||||
|
|
|
@ -83,6 +83,9 @@ public:
|
|||
void SetName ( const std::string sNNa ) { sName = sNNa; }
|
||||
std::string GetName() { return sName; }
|
||||
|
||||
void SetGain ( const double dNG ) { dGain = dNG; }
|
||||
double GetGain() { return dGain; }
|
||||
|
||||
void SetSockBufSize ( const int iNumBlocks );
|
||||
int GetSockBufSize() { return iCurSockBufSize; }
|
||||
|
||||
|
@ -131,6 +134,9 @@ protected:
|
|||
// channel name
|
||||
std::string sName;
|
||||
|
||||
// mixer and effect settings
|
||||
double dGain;
|
||||
|
||||
// network jitter-buffer
|
||||
CNetBuf SockBuf;
|
||||
int iCurSockBufSize;
|
||||
|
@ -141,10 +147,6 @@ protected:
|
|||
// network protocol
|
||||
CProtocol Protocol;
|
||||
|
||||
// time stamp index counter
|
||||
Q_UINT8 byTimeStampIdxCnt;
|
||||
int iTimeStampActCnt;
|
||||
|
||||
int iConTimeOut;
|
||||
int iConTimeOutStartVal;
|
||||
|
||||
|
@ -184,7 +186,8 @@ public:
|
|||
int CheckAddr ( const CHostAddress& Addr );
|
||||
|
||||
void GetBlockAllConC ( CVector<int>& vecChanID,
|
||||
CVector<CVector<double> >& vecvecdData );
|
||||
CVector<CVector<double> >& vecvecdData,
|
||||
CVector<double>& vecdGains );
|
||||
|
||||
void GetConCliParam ( CVector<CHostAddress>& vecHostAddresses,
|
||||
CVector<int>& veciJitBufSize,
|
||||
|
|
|
@ -49,7 +49,7 @@ MESSAGES
|
|||
|
||||
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
|
||||
|
||||
|
@ -57,6 +57,15 @@ MESSAGES
|
|||
| 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
|
||||
|
||||
for each connected client append following data:
|
||||
|
@ -370,13 +379,62 @@ void CProtocol::CreateNetwBlSiFactMes ( const int iNetwBlSiFact )
|
|||
CreateAndSendMessage ( PROTMESSID_NET_BLSI_FACTOR, vecData );
|
||||
}
|
||||
|
||||
//void CProtocol::CreateConClientListMes ( const )
|
||||
//{
|
||||
// TODO
|
||||
//PROTMESSID_CONN_CLIENTS_LIST
|
||||
void CProtocol::CreateChanGainMes ( const int iChanID, const double dGain )
|
||||
{
|
||||
CVector<uint8_t> vecData ( 4 ); // 4 bytes of data
|
||||
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 );
|
||||
}
|
||||
|
||||
|
||||
/******************************************************************************\
|
||||
|
|
|
@ -41,6 +41,8 @@
|
|||
#define PROTMESSID_REQ_JITT_BUF_SIZE 11 // request jitter buffer size
|
||||
#define PROTMESSID_PING 12 // for measuring ping time
|
||||
#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
|
||||
#define MESS_HEADER_LENGTH_BYTE 5 /* ID, cnt, length */
|
||||
|
@ -62,6 +64,10 @@ public:
|
|||
void CreateJitBufMes ( const int iJitBufSize );
|
||||
void CreateReqJitBufMes();
|
||||
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 );
|
||||
|
||||
|
|
|
@ -87,17 +87,18 @@ void CServer::OnTimer()
|
|||
{
|
||||
CVector<int> vecChanID;
|
||||
CVector<CVector<double> > vecvecdData ( MIN_BLOCK_SIZE_SAMPLES );
|
||||
CVector<double> vecdGains;
|
||||
|
||||
/* get data from all connected clients */
|
||||
ChannelSet.GetBlockAllConC ( vecChanID, vecvecdData );
|
||||
const int iNumClients = vecvecdData.Size ();
|
||||
ChannelSet.GetBlockAllConC ( vecChanID, vecvecdData, vecdGains );
|
||||
const int iNumClients = vecChanID.Size();
|
||||
|
||||
/* Check if at least one client is connected. If not, stop server until
|
||||
one client is connected */
|
||||
if ( iNumClients != 0 )
|
||||
{
|
||||
/* actual processing of audio data -> mix */
|
||||
vecsSendData = ProcessData ( vecvecdData );
|
||||
vecsSendData = ProcessData ( vecvecdData, vecdGains );
|
||||
|
||||
/* send the same data to all connected clients */
|
||||
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;
|
||||
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++ )
|
||||
{
|
||||
dMixedData += vecvecdData[j][i];
|
||||
dMixedData += vecvecdData[j][i] * vecdGains[j];
|
||||
}
|
||||
|
||||
/* normalization and truncating to short */
|
||||
|
|
|
@ -62,7 +62,9 @@ public:
|
|||
CChannelSet* GetChannelSet () { return &ChannelSet; }
|
||||
|
||||
protected:
|
||||
CVector<short> ProcessData ( CVector<CVector<double> >& vecvecdData );
|
||||
CVector<short> ProcessData ( CVector<CVector<double> >& vecvecdData,
|
||||
CVector<double>& vecdGains );
|
||||
|
||||
virtual void customEvent ( QCustomEvent* Event );
|
||||
|
||||
QTimer Timer;
|
||||
|
|
Loading…
Reference in a new issue