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()));
|
// 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()
|
int CChannelSet::GetFreeChan()
|
||||||
{
|
{
|
||||||
/* look for a free channel */
|
/* look for a free channel */
|
||||||
|
@ -97,6 +129,7 @@ bool CChannelSet::PutData ( const CVector<unsigned char>& vecbyRecBuf,
|
||||||
const CHostAddress& HostAdr )
|
const CHostAddress& HostAdr )
|
||||||
{
|
{
|
||||||
bool bRet = false;
|
bool bRet = false;
|
||||||
|
bool bCreateChanList = false;
|
||||||
|
|
||||||
Mutex.lock();
|
Mutex.lock();
|
||||||
{
|
{
|
||||||
|
@ -114,6 +147,12 @@ bool CChannelSet::PutData ( const CVector<unsigned char>& vecbyRecBuf,
|
||||||
if ( iCurChanID != INVALID_CHANNEL_ID )
|
if ( iCurChanID != INVALID_CHANNEL_ID )
|
||||||
{
|
{
|
||||||
vecChannels[iCurChanID].SetAddress ( HostAdr );
|
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
|
else
|
||||||
{
|
{
|
||||||
|
@ -144,7 +183,15 @@ bool CChannelSet::PutData ( const CVector<unsigned char>& vecbyRecBuf,
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
// after data is put in channel buffer, create channel list message if
|
||||||
|
// requested
|
||||||
|
if ( bCreateChanList )
|
||||||
|
{
|
||||||
|
CreateAndSendChanListForAllConClients();
|
||||||
|
}
|
||||||
|
}
|
||||||
Mutex.unlock();
|
Mutex.unlock();
|
||||||
|
|
||||||
return bRet;
|
return bRet;
|
||||||
|
|
|
@ -112,6 +112,11 @@ public:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CreateConClientListMes ( const CVector<uint32_t>& veciIpAddrs,
|
||||||
|
const CVector<std::string>& vecstrNames )
|
||||||
|
{
|
||||||
|
Protocol.CreateConClientListMes ( veciIpAddrs, vecstrNames );
|
||||||
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void SetNetwInBlSiFact ( const int iNewBlockSizeFactor );
|
void SetNetwInBlSiFact ( const int iNewBlockSizeFactor );
|
||||||
|
@ -134,8 +139,9 @@ protected:
|
||||||
// channel name
|
// channel name
|
||||||
std::string sName;
|
std::string sName;
|
||||||
|
|
||||||
// mixer and effect settings
|
// TODO we need mixer and effect settings for all the other channels, too!!!
|
||||||
double dGain;
|
// mixer and effect settings
|
||||||
|
double dGain;
|
||||||
|
|
||||||
// network jitter-buffer
|
// network jitter-buffer
|
||||||
CNetBuf SockBuf;
|
CNetBuf SockBuf;
|
||||||
|
@ -206,6 +212,8 @@ public:
|
||||||
{ return vecChannels[iChanNum].GetAddress(); }
|
{ return vecChannels[iChanNum].GetAddress(); }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
void CreateAndSendChanListForAllConClients();
|
||||||
|
|
||||||
/* do not use the vector class since CChannel does not have appropriate
|
/* do not use the vector class since CChannel does not have appropriate
|
||||||
copy constructor/operator */
|
copy constructor/operator */
|
||||||
CChannel vecChannels[MAX_NUM_CHANNELS];
|
CChannel vecChannels[MAX_NUM_CHANNELS];
|
||||||
|
|
|
@ -229,17 +229,18 @@ bool CProtocol::ParseMessage ( const CVector<unsigned char>& vecbyData,
|
||||||
/*
|
/*
|
||||||
return code: true -> ok; false -> error
|
return code: true -> ok; false -> error
|
||||||
*/
|
*/
|
||||||
bool bRet;
|
bool bRet, bSendNextMess;
|
||||||
int iRecCounter, iRecID, iData;
|
int iRecCounter, iRecID, iData, iDataLen, iStringLen, iCurID;
|
||||||
unsigned int iPos;
|
unsigned int iPos;
|
||||||
CVector<uint8_t> vecData;
|
CVector<uint8_t> vecData;
|
||||||
bool bSendNextMess;
|
std::string strCurString;
|
||||||
|
double dNewGain;
|
||||||
|
|
||||||
|
|
||||||
// convert unsigned char in uint8_t, TODO convert all buffers in uint8_t
|
// convert unsigned char in uint8_t, TODO convert all buffers in uint8_t
|
||||||
CVector<uint8_t> vecbyDataConv ( iNumBytes );
|
CVector<uint8_t> vecbyDataConv ( iNumBytes );
|
||||||
for ( int i = 0; i < iNumBytes; i++ ) {
|
for ( int i = 0; i < iNumBytes; i++ ) {
|
||||||
vecbyDataConv[i] = static_cast<uint8_t> ( vecbyData[i] );
|
vecbyDataConv[i] = static_cast<uint8_t> ( vecbyData[i] );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -332,6 +333,65 @@ vecbyDataConv[i] = static_cast<uint8_t> ( vecbyData[i] );
|
||||||
// send acknowledge message
|
// send acknowledge message
|
||||||
CreateAndSendAcknMess ( iRecID, iRecCounter );
|
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;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -146,6 +146,7 @@ signals:
|
||||||
// receiving
|
// receiving
|
||||||
void ChangeJittBufSize ( int iNewJitBufSize );
|
void ChangeJittBufSize ( int iNewJitBufSize );
|
||||||
void ChangeNetwBlSiFact ( int iNewNetwBlSiFact );
|
void ChangeNetwBlSiFact ( int iNewNetwBlSiFact );
|
||||||
|
void ChangeChanGain ( int iChanID, double dNewGain );
|
||||||
void ReqJittBufSize();
|
void ReqJittBufSize();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -97,6 +97,9 @@ void CServer::OnTimer()
|
||||||
one client is connected */
|
one client is connected */
|
||||||
if ( iNumClients != 0 )
|
if ( iNumClients != 0 )
|
||||||
{
|
{
|
||||||
|
|
||||||
|
// TODO generate a sparate mix for each channel
|
||||||
|
|
||||||
/* actual processing of audio data -> mix */
|
/* actual processing of audio data -> mix */
|
||||||
vecsSendData = ProcessData ( vecvecdData, vecdGains );
|
vecsSendData = ProcessData ( vecvecdData, vecdGains );
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue