diff --git a/src/channel.cpp b/src/channel.cpp index 552b9506..5a58ae18 100755 --- a/src/channel.cpp +++ b/src/channel.cpp @@ -151,13 +151,15 @@ bool CChannelSet::PutData ( const CVector& vecbyRecBuf, } void CChannelSet::GetBlockAllConC ( CVector& vecChanID, - CVector >& vecvecdData ) + CVector >& vecvecdData, + CVector& vecdGains ) { /* init temporal data vector and clear input buffers */ CVector vecdData ( MIN_BLOCK_SIZE_SAMPLES ); 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 afterwards! */ @@ -172,8 +174,9 @@ void CChannelSet::GetBlockAllConC ( CVector& vecChanID, if ( vecChannels[i].IsConnected() ) { - /* add ID and data */ - vecChanID.Add ( i ); + /* 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& 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 */ diff --git a/src/channel.h b/src/channel.h index a31c3f00..80f2c694 100755 --- a/src/channel.h +++ b/src/channel.h @@ -82,6 +82,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; } @@ -129,7 +132,10 @@ protected: CHostAddress InetAddr; // channel name - std::string sName; + std::string sName; + + // mixer and effect settings + double dGain; // network jitter-buffer CNetBuf SockBuf; @@ -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& vecChanID, - CVector >& vecvecdData ); + CVector >& vecvecdData, + CVector& vecdGains ); void GetConCliParam ( CVector& vecHostAddresses, CVector& veciJitBufSize, diff --git a/src/protocol.cpp b/src/protocol.cpp index e343bce8..046a7f4f 100755 --- a/src/protocol.cpp +++ b/src/protocol.cpp @@ -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 vecData ( 4 ); // 4 bytes of data + unsigned int iPos = 0; // init position pointer + // build data vector + // channel ID + PutValOnStream ( vecData, iPos, static_cast ( 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 ( iCurGain ), 2 ); + + CreateAndSendMessage ( PROTMESSID_CHANNEL_GAIN, vecData ); +} + +void CProtocol::CreateConClientListMes ( const CVector& veciIpAddrs, + const CVector& vecstrNames ) +{ + const int iNumClients = veciIpAddrs.Size(); + + // build data vector + CVector 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 ( veciIpAddrs[i] ), 4 ); + + // number of bytes for name string (2 bytes) + PutValOnStream ( vecData, iPos, + static_cast ( 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 ( vecstrNames[i][j] ), 1 ); + } + } + + CreateAndSendMessage ( PROTMESSID_CONN_CLIENTS_LIST, vecData ); +} /******************************************************************************\ diff --git a/src/protocol.h b/src/protocol.h index 9828923a..c1dc07b1 100755 --- a/src/protocol.h +++ b/src/protocol.h @@ -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& veciIpAddrs, + const CVector& vecstrNames ); void CreateAndSendAcknMess ( const int& iID, const int& iCnt ); diff --git a/src/server.cpp b/src/server.cpp index a4291980..be1b264a 100755 --- a/src/server.cpp +++ b/src/server.cpp @@ -86,18 +86,19 @@ void CServer::Stop() void CServer::OnTimer() { CVector vecChanID; - CVector > vecvecdData ( MIN_BLOCK_SIZE_SAMPLES ); + CVector > vecvecdData ( MIN_BLOCK_SIZE_SAMPLES ); + CVector 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 CServer::ProcessData ( CVector >& vecvecdData ) +CVector CServer::ProcessData ( CVector >& vecvecdData, + CVector& vecdGains ) { CVector vecsOutData; vecsOutData.Init ( MIN_BLOCK_SIZE_SAMPLES ); @@ -152,7 +154,7 @@ CVector CServer::ProcessData ( CVector >& vecvecdData ) for ( int j = 0; j < iNumClients; j++ ) { - dMixedData += vecvecdData[j][i]; + dMixedData += vecvecdData[j][i] * vecdGains[j]; } /* normalization and truncating to short */ diff --git a/src/server.h b/src/server.h index 4f12662e..297d7b04 100755 --- a/src/server.h +++ b/src/server.h @@ -62,7 +62,9 @@ public: CChannelSet* GetChannelSet () { return &ChannelSet; } protected: - CVector ProcessData ( CVector >& vecvecdData ); + CVector ProcessData ( CVector >& vecvecdData, + CVector& vecdGains ); + virtual void customEvent ( QCustomEvent* Event ); QTimer Timer;