server sends connected client list on a new connection
This commit is contained in:
parent
3d4153fd75
commit
efb83f15ac
5 changed files with 129 additions and 10 deletions
|
@ -56,6 +56,38 @@ CChannelSet::CChannelSet()
|
|||
// QObject::connect(&vecChannels[9],SIGNAL(NewConnection()),this,SLOT(OnNewConnectionCh9()));
|
||||
}
|
||||
|
||||
void CChannelSet::CreateAndSendChanListForAllConClients()
|
||||
{
|
||||
int i;
|
||||
CVector<uint32_t> veciIpAddrs ( 0 );
|
||||
CVector<std::string> vecstrNames ( 0 );
|
||||
|
||||
// the channel ID is defined as the order of the channels in the channel
|
||||
// set where we do not care about not-connected channels
|
||||
int iCurChanID = 0;
|
||||
|
||||
// look for free channels
|
||||
for ( i = 0; i < MAX_NUM_CHANNELS; i++ )
|
||||
{
|
||||
if ( vecChannels[i].IsConnected() )
|
||||
{
|
||||
// append IP address and channel name to storing vectors
|
||||
veciIpAddrs.Add ( vecChannels[i].GetAddress().InetAddr.ip4Addr() );
|
||||
vecstrNames.Add ( vecChannels[i].GetName() );
|
||||
}
|
||||
}
|
||||
|
||||
// now send connected channels list to all connected clients
|
||||
for ( i = 0; i < MAX_NUM_CHANNELS; i++ )
|
||||
{
|
||||
if ( vecChannels[i].IsConnected() )
|
||||
{
|
||||
// send message
|
||||
vecChannels[i].CreateConClientListMes ( veciIpAddrs, vecstrNames );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int CChannelSet::GetFreeChan()
|
||||
{
|
||||
/* look for a free channel */
|
||||
|
@ -97,6 +129,7 @@ bool CChannelSet::PutData ( const CVector<unsigned char>& vecbyRecBuf,
|
|||
const CHostAddress& HostAdr )
|
||||
{
|
||||
bool bRet = false;
|
||||
bool bCreateChanList = false;
|
||||
|
||||
Mutex.lock();
|
||||
{
|
||||
|
@ -114,6 +147,12 @@ bool CChannelSet::PutData ( const CVector<unsigned char>& vecbyRecBuf,
|
|||
if ( iCurChanID != INVALID_CHANNEL_ID )
|
||||
{
|
||||
vecChannels[iCurChanID].SetAddress ( HostAdr );
|
||||
|
||||
// a new client connected to the server, set flag to create and
|
||||
// send all clients the updated channel list, we cannot create
|
||||
// the message here since the received data has to be put to the
|
||||
// channel first so that this channel is marked as connected
|
||||
bCreateChanList = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -144,6 +183,14 @@ bool CChannelSet::PutData ( const CVector<unsigned char>& vecbyRecBuf,
|
|||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// after data is put in channel buffer, create channel list message if
|
||||
// requested
|
||||
if ( bCreateChanList )
|
||||
{
|
||||
CreateAndSendChanListForAllConClients();
|
||||
}
|
||||
}
|
||||
Mutex.unlock();
|
||||
|
||||
|
|
|
@ -112,6 +112,11 @@ public:
|
|||
}
|
||||
}
|
||||
|
||||
void CreateConClientListMes ( const CVector<uint32_t>& veciIpAddrs,
|
||||
const CVector<std::string>& vecstrNames )
|
||||
{
|
||||
Protocol.CreateConClientListMes ( veciIpAddrs, vecstrNames );
|
||||
}
|
||||
|
||||
protected:
|
||||
void SetNetwInBlSiFact ( const int iNewBlockSizeFactor );
|
||||
|
@ -134,6 +139,7 @@ protected:
|
|||
// channel name
|
||||
std::string sName;
|
||||
|
||||
// TODO we need mixer and effect settings for all the other channels, too!!!
|
||||
// mixer and effect settings
|
||||
double dGain;
|
||||
|
||||
|
@ -206,6 +212,8 @@ public:
|
|||
{ return vecChannels[iChanNum].GetAddress(); }
|
||||
|
||||
protected:
|
||||
void CreateAndSendChanListForAllConClients();
|
||||
|
||||
/* do not use the vector class since CChannel does not have appropriate
|
||||
copy constructor/operator */
|
||||
CChannel vecChannels[MAX_NUM_CHANNELS];
|
||||
|
|
|
@ -229,11 +229,12 @@ bool CProtocol::ParseMessage ( const CVector<unsigned char>& vecbyData,
|
|||
/*
|
||||
return code: true -> ok; false -> error
|
||||
*/
|
||||
bool bRet;
|
||||
int iRecCounter, iRecID, iData;
|
||||
bool bRet, bSendNextMess;
|
||||
int iRecCounter, iRecID, iData, iDataLen, iStringLen, iCurID;
|
||||
unsigned int iPos;
|
||||
CVector<uint8_t> vecData;
|
||||
bool bSendNextMess;
|
||||
std::string strCurString;
|
||||
double dNewGain;
|
||||
|
||||
|
||||
// convert unsigned char in uint8_t, TODO convert all buffers in uint8_t
|
||||
|
@ -332,6 +333,65 @@ vecbyDataConv[i] = static_cast<uint8_t> ( vecbyData[i] );
|
|||
// send acknowledge message
|
||||
CreateAndSendAcknMess ( iRecID, iRecCounter );
|
||||
|
||||
break;
|
||||
|
||||
case PROTMESSID_CHANNEL_GAIN:
|
||||
|
||||
// extract data from stream and emit signal for received value
|
||||
iPos = 0;
|
||||
|
||||
// channel ID
|
||||
iCurID = static_cast<int> ( GetValFromStream ( vecData, iPos, 2 ) );
|
||||
|
||||
// actual gain, we convert from integer to double with range 0..1
|
||||
iData = static_cast<int> ( GetValFromStream ( vecData, iPos, 2 ) );
|
||||
dNewGain = (double) iData / ( 1 << 16 );
|
||||
|
||||
// invoke message action
|
||||
emit ChangeChanGain ( iCurID, dNewGain );
|
||||
|
||||
// send acknowledge message
|
||||
CreateAndSendAcknMess ( iRecID, iRecCounter );
|
||||
|
||||
break;
|
||||
|
||||
case PROTMESSID_CONN_CLIENTS_LIST:
|
||||
|
||||
// extract data from stream and emit signal for received value
|
||||
iPos = 0;
|
||||
iDataLen = vecData.Size();
|
||||
|
||||
while ( iPos < iDataLen )
|
||||
{
|
||||
|
||||
// IP address (4 bytes)
|
||||
iData = static_cast<int> ( GetValFromStream ( vecData, iPos, 4 ) );
|
||||
|
||||
// TODO do something with the received IP address "iData"
|
||||
|
||||
// TEST
|
||||
QHostAddress addrTest ( iData );
|
||||
printf ( "%s ", addrTest.toString().latin1() );
|
||||
|
||||
// number of bytes for name string (2 bytes)
|
||||
iStringLen = static_cast<int> ( GetValFromStream ( vecData, iPos, 2 ) );
|
||||
|
||||
// name string (n bytes)
|
||||
strCurString = "";
|
||||
for ( int j = 0; j < iStringLen; j++ )
|
||||
{
|
||||
// byte-by-byte copying of the string data
|
||||
iData = static_cast<int> ( GetValFromStream ( vecData, iPos, 1 ) );
|
||||
strCurString += std::string ( (char*) &iData );
|
||||
}
|
||||
|
||||
// TODO do something with the received name string "strCurString"
|
||||
|
||||
}
|
||||
|
||||
// send acknowledge message
|
||||
CreateAndSendAcknMess ( iRecID, iRecCounter );
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -146,6 +146,7 @@ signals:
|
|||
// receiving
|
||||
void ChangeJittBufSize ( int iNewJitBufSize );
|
||||
void ChangeNetwBlSiFact ( int iNewNetwBlSiFact );
|
||||
void ChangeChanGain ( int iChanID, double dNewGain );
|
||||
void ReqJittBufSize();
|
||||
};
|
||||
|
||||
|
|
|
@ -97,6 +97,9 @@ void CServer::OnTimer()
|
|||
one client is connected */
|
||||
if ( iNumClients != 0 )
|
||||
{
|
||||
|
||||
// TODO generate a sparate mix for each channel
|
||||
|
||||
/* actual processing of audio data -> mix */
|
||||
vecsSendData = ProcessData ( vecvecdData, vecdGains );
|
||||
|
||||
|
|
Loading…
Reference in a new issue