finished implementation of a separate socket high priority thread
This commit is contained in:
parent
2e5f7781ce
commit
2ac7a92eaf
3 changed files with 124 additions and 171 deletions
18
src/client.h
18
src/client.h
|
@ -327,11 +327,7 @@ void SetAudoCompressiontype ( const EAudComprType eNAudCompressionType );
|
||||||
bool bIsInitializationPhase;
|
bool bIsInitializationPhase;
|
||||||
CVector<unsigned char> vecCeltData;
|
CVector<unsigned char> vecCeltData;
|
||||||
|
|
||||||
#ifdef ENABLE_RECEIVE_SOCKET_IN_SEPARATE_THREAD
|
|
||||||
CHighPrioSocket Socket;
|
CHighPrioSocket Socket;
|
||||||
#else
|
|
||||||
CSocket Socket;
|
|
||||||
#endif
|
|
||||||
CSound Sound;
|
CSound Sound;
|
||||||
CStereoSignalLevelMeter SignalLevelMeter;
|
CStereoSignalLevelMeter SignalLevelMeter;
|
||||||
|
|
||||||
|
@ -377,10 +373,12 @@ void SetAudoCompressiontype ( const EAudComprType eNAudCompressionType );
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void OnSendProtMessage ( CVector<uint8_t> vecMessage );
|
void OnSendProtMessage ( CVector<uint8_t> vecMessage );
|
||||||
void OnInvalidPacketReceived ( CVector<uint8_t> vecbyRecBuf,
|
void OnInvalidPacketReceived ( CHostAddress RecHostAddr );
|
||||||
int iNumBytesRead,
|
|
||||||
|
void OnDetectedCLMessage ( CVector<uint8_t> vecbyMesBodyData,
|
||||||
|
int iRecID,
|
||||||
CHostAddress RecHostAddr );
|
CHostAddress RecHostAddr );
|
||||||
void OnDetectedCLMessage ( CVector<uint8_t> vecbyMesBodyData, int iRecID );
|
|
||||||
void OnReqJittBufSize() { CreateServerJitterBufferMessage(); }
|
void OnReqJittBufSize() { CreateServerJitterBufferMessage(); }
|
||||||
void OnJittBufSizeChanged ( int iNewJitBufSize );
|
void OnJittBufSizeChanged ( int iNewJitBufSize );
|
||||||
void OnReqChanInfo() { Channel.SetRemoteInfo ( ChannelInfo ); }
|
void OnReqChanInfo() { Channel.SetRemoteInfo ( ChannelInfo ); }
|
||||||
|
@ -388,7 +386,9 @@ public slots:
|
||||||
void OnCLPingReceived ( CHostAddress InetAddr,
|
void OnCLPingReceived ( CHostAddress InetAddr,
|
||||||
int iMs );
|
int iMs );
|
||||||
|
|
||||||
void OnSendCLProtMessage ( CHostAddress InetAddr, CVector<uint8_t> vecMessage );
|
void OnSendCLProtMessage ( CHostAddress InetAddr,
|
||||||
|
CVector<uint8_t> vecMessage );
|
||||||
|
|
||||||
void OnCLPingWithNumClientsReceived ( CHostAddress InetAddr,
|
void OnCLPingWithNumClientsReceived ( CHostAddress InetAddr,
|
||||||
int iMs,
|
int iMs,
|
||||||
int iNumClients );
|
int iNumClients );
|
||||||
|
@ -403,8 +403,10 @@ signals:
|
||||||
void ConClientListMesReceived ( CVector<CChannelInfo> vecChanInfo );
|
void ConClientListMesReceived ( CVector<CChannelInfo> vecChanInfo );
|
||||||
void ChatTextReceived ( QString strChatText );
|
void ChatTextReceived ( QString strChatText );
|
||||||
void PingTimeReceived ( int iPingTime );
|
void PingTimeReceived ( int iPingTime );
|
||||||
|
|
||||||
void CLServerListReceived ( CHostAddress InetAddr,
|
void CLServerListReceived ( CHostAddress InetAddr,
|
||||||
CVector<CServerInfo> vecServerInfo );
|
CVector<CServerInfo> vecServerInfo );
|
||||||
|
|
||||||
void CLPingTimeWithNumClientsReceived ( CHostAddress InetAddr,
|
void CLPingTimeWithNumClientsReceived ( CHostAddress InetAddr,
|
||||||
int iPingTime,
|
int iPingTime,
|
||||||
int iNumClients );
|
int iNumClients );
|
||||||
|
|
15
src/global.h
15
src/global.h
|
@ -65,21 +65,6 @@ LED bar: lbr
|
||||||
|
|
||||||
|
|
||||||
/* Definitions ****************************************************************/
|
/* Definitions ****************************************************************/
|
||||||
// The receive socket should be put in a high priority thread to ensure the GUI
|
|
||||||
// does not effect the stability of the audio stream (e.g. if the GUI is on
|
|
||||||
// high load because of a table update, the incoming network packets must still
|
|
||||||
// be put in the jitter buffer with highest priority).
|
|
||||||
// Since the new code is still in "experimental state", we introduced this macro
|
|
||||||
// to enable/disable the new code.
|
|
||||||
//
|
|
||||||
// I disabled the new code again since it seems not to improve the situation
|
|
||||||
// much. Maybe things must be tweaked for it to work correctly. Since the more
|
|
||||||
// threads we have the higher is the risk of software crashes, I will only
|
|
||||||
// enable the new code on significant performance gain.
|
|
||||||
//
|
|
||||||
//#define ENABLE_RECEIVE_SOCKET_IN_SEPARATE_THREAD
|
|
||||||
#undef ENABLE_RECEIVE_SOCKET_IN_SEPARATE_THREAD
|
|
||||||
|
|
||||||
// define this macro to get debug output
|
// define this macro to get debug output
|
||||||
//#define _DEBUG_
|
//#define _DEBUG_
|
||||||
#undef _DEBUG_
|
#undef _DEBUG_
|
||||||
|
|
222
src/server.cpp
222
src/server.cpp
|
@ -447,50 +447,6 @@ CServer::CServer ( const int iNewMaxNumChan,
|
||||||
QObject::connect ( &vecChannels[18], SIGNAL ( MessReadyForSending ( CVector<uint8_t> ) ), this, SLOT ( OnSendProtMessCh18 ( CVector<uint8_t> ) ) );
|
QObject::connect ( &vecChannels[18], SIGNAL ( MessReadyForSending ( CVector<uint8_t> ) ), this, SLOT ( OnSendProtMessCh18 ( CVector<uint8_t> ) ) );
|
||||||
QObject::connect ( &vecChannels[19], SIGNAL ( MessReadyForSending ( CVector<uint8_t> ) ), this, SLOT ( OnSendProtMessCh19 ( CVector<uint8_t> ) ) );
|
QObject::connect ( &vecChannels[19], SIGNAL ( MessReadyForSending ( CVector<uint8_t> ) ), this, SLOT ( OnSendProtMessCh19 ( CVector<uint8_t> ) ) );
|
||||||
|
|
||||||
// a connection less protocol message was detected
|
|
||||||
QObject::connect ( &vecChannels[0], SIGNAL ( DetectedCLMessage ( CVector<uint8_t>, int ) ), this, SLOT ( OnDetCLMessCh0 ( CVector<uint8_t>, int ) ) );
|
|
||||||
QObject::connect ( &vecChannels[1], SIGNAL ( DetectedCLMessage ( CVector<uint8_t>, int ) ), this, SLOT ( OnDetCLMessCh1 ( CVector<uint8_t>, int ) ) );
|
|
||||||
QObject::connect ( &vecChannels[2], SIGNAL ( DetectedCLMessage ( CVector<uint8_t>, int ) ), this, SLOT ( OnDetCLMessCh2 ( CVector<uint8_t>, int ) ) );
|
|
||||||
QObject::connect ( &vecChannels[3], SIGNAL ( DetectedCLMessage ( CVector<uint8_t>, int ) ), this, SLOT ( OnDetCLMessCh3 ( CVector<uint8_t>, int ) ) );
|
|
||||||
QObject::connect ( &vecChannels[4], SIGNAL ( DetectedCLMessage ( CVector<uint8_t>, int ) ), this, SLOT ( OnDetCLMessCh4 ( CVector<uint8_t>, int ) ) );
|
|
||||||
QObject::connect ( &vecChannels[5], SIGNAL ( DetectedCLMessage ( CVector<uint8_t>, int ) ), this, SLOT ( OnDetCLMessCh5 ( CVector<uint8_t>, int ) ) );
|
|
||||||
QObject::connect ( &vecChannels[6], SIGNAL ( DetectedCLMessage ( CVector<uint8_t>, int ) ), this, SLOT ( OnDetCLMessCh6 ( CVector<uint8_t>, int ) ) );
|
|
||||||
QObject::connect ( &vecChannels[7], SIGNAL ( DetectedCLMessage ( CVector<uint8_t>, int ) ), this, SLOT ( OnDetCLMessCh7 ( CVector<uint8_t>, int ) ) );
|
|
||||||
QObject::connect ( &vecChannels[8], SIGNAL ( DetectedCLMessage ( CVector<uint8_t>, int ) ), this, SLOT ( OnDetCLMessCh8 ( CVector<uint8_t>, int ) ) );
|
|
||||||
QObject::connect ( &vecChannels[9], SIGNAL ( DetectedCLMessage ( CVector<uint8_t>, int ) ), this, SLOT ( OnDetCLMessCh9 ( CVector<uint8_t>, int ) ) );
|
|
||||||
QObject::connect ( &vecChannels[10], SIGNAL ( DetectedCLMessage ( CVector<uint8_t>, int ) ), this, SLOT ( OnDetCLMessCh10 ( CVector<uint8_t>, int ) ) );
|
|
||||||
QObject::connect ( &vecChannels[11], SIGNAL ( DetectedCLMessage ( CVector<uint8_t>, int ) ), this, SLOT ( OnDetCLMessCh11 ( CVector<uint8_t>, int ) ) );
|
|
||||||
QObject::connect ( &vecChannels[12], SIGNAL ( DetectedCLMessage ( CVector<uint8_t>, int ) ), this, SLOT ( OnDetCLMessCh12 ( CVector<uint8_t>, int ) ) );
|
|
||||||
QObject::connect ( &vecChannels[13], SIGNAL ( DetectedCLMessage ( CVector<uint8_t>, int ) ), this, SLOT ( OnDetCLMessCh13 ( CVector<uint8_t>, int ) ) );
|
|
||||||
QObject::connect ( &vecChannels[14], SIGNAL ( DetectedCLMessage ( CVector<uint8_t>, int ) ), this, SLOT ( OnDetCLMessCh14 ( CVector<uint8_t>, int ) ) );
|
|
||||||
QObject::connect ( &vecChannels[15], SIGNAL ( DetectedCLMessage ( CVector<uint8_t>, int ) ), this, SLOT ( OnDetCLMessCh15 ( CVector<uint8_t>, int ) ) );
|
|
||||||
QObject::connect ( &vecChannels[16], SIGNAL ( DetectedCLMessage ( CVector<uint8_t>, int ) ), this, SLOT ( OnDetCLMessCh16 ( CVector<uint8_t>, int ) ) );
|
|
||||||
QObject::connect ( &vecChannels[17], SIGNAL ( DetectedCLMessage ( CVector<uint8_t>, int ) ), this, SLOT ( OnDetCLMessCh17 ( CVector<uint8_t>, int ) ) );
|
|
||||||
QObject::connect ( &vecChannels[18], SIGNAL ( DetectedCLMessage ( CVector<uint8_t>, int ) ), this, SLOT ( OnDetCLMessCh18 ( CVector<uint8_t>, int ) ) );
|
|
||||||
QObject::connect ( &vecChannels[19], SIGNAL ( DetectedCLMessage ( CVector<uint8_t>, int ) ), this, SLOT ( OnDetCLMessCh19 ( CVector<uint8_t>, int ) ) );
|
|
||||||
|
|
||||||
// request jitter buffer size
|
|
||||||
QObject::connect ( &vecChannels[0], SIGNAL ( NewConnection() ), this, SLOT ( OnNewConnectionCh0() ) );
|
|
||||||
QObject::connect ( &vecChannels[1], SIGNAL ( NewConnection() ), this, SLOT ( OnNewConnectionCh1() ) );
|
|
||||||
QObject::connect ( &vecChannels[2], SIGNAL ( NewConnection() ), this, SLOT ( OnNewConnectionCh2() ) );
|
|
||||||
QObject::connect ( &vecChannels[3], SIGNAL ( NewConnection() ), this, SLOT ( OnNewConnectionCh3() ) );
|
|
||||||
QObject::connect ( &vecChannels[4], SIGNAL ( NewConnection() ), this, SLOT ( OnNewConnectionCh4() ) );
|
|
||||||
QObject::connect ( &vecChannels[5], SIGNAL ( NewConnection() ), this, SLOT ( OnNewConnectionCh5() ) );
|
|
||||||
QObject::connect ( &vecChannels[6], SIGNAL ( NewConnection() ), this, SLOT ( OnNewConnectionCh6() ) );
|
|
||||||
QObject::connect ( &vecChannels[7], SIGNAL ( NewConnection() ), this, SLOT ( OnNewConnectionCh7() ) );
|
|
||||||
QObject::connect ( &vecChannels[8], SIGNAL ( NewConnection() ), this, SLOT ( OnNewConnectionCh8() ) );
|
|
||||||
QObject::connect ( &vecChannels[9], SIGNAL ( NewConnection() ), this, SLOT ( OnNewConnectionCh9() ) );
|
|
||||||
QObject::connect ( &vecChannels[10], SIGNAL ( NewConnection() ), this, SLOT ( OnNewConnectionCh10() ) );
|
|
||||||
QObject::connect ( &vecChannels[11], SIGNAL ( NewConnection() ), this, SLOT ( OnNewConnectionCh11() ) );
|
|
||||||
QObject::connect ( &vecChannels[12], SIGNAL ( NewConnection() ), this, SLOT ( OnNewConnectionCh12() ) );
|
|
||||||
QObject::connect ( &vecChannels[13], SIGNAL ( NewConnection() ), this, SLOT ( OnNewConnectionCh13() ) );
|
|
||||||
QObject::connect ( &vecChannels[14], SIGNAL ( NewConnection() ), this, SLOT ( OnNewConnectionCh14() ) );
|
|
||||||
QObject::connect ( &vecChannels[15], SIGNAL ( NewConnection() ), this, SLOT ( OnNewConnectionCh15() ) );
|
|
||||||
QObject::connect ( &vecChannels[16], SIGNAL ( NewConnection() ), this, SLOT ( OnNewConnectionCh16() ) );
|
|
||||||
QObject::connect ( &vecChannels[17], SIGNAL ( NewConnection() ), this, SLOT ( OnNewConnectionCh17() ) );
|
|
||||||
QObject::connect ( &vecChannels[18], SIGNAL ( NewConnection() ), this, SLOT ( OnNewConnectionCh18() ) );
|
|
||||||
QObject::connect ( &vecChannels[19], SIGNAL ( NewConnection() ), this, SLOT ( OnNewConnectionCh19() ) );
|
|
||||||
|
|
||||||
// request connected clients list
|
// request connected clients list
|
||||||
QObject::connect ( &vecChannels[0], SIGNAL ( ReqConnClientsList() ), this, SLOT ( OnReqConnClientsListCh0() ) );
|
QObject::connect ( &vecChannels[0], SIGNAL ( ReqConnClientsList() ), this, SLOT ( OnReqConnClientsListCh0() ) );
|
||||||
QObject::connect ( &vecChannels[1], SIGNAL ( ReqConnClientsList() ), this, SLOT ( OnReqConnClientsListCh1() ) );
|
QObject::connect ( &vecChannels[1], SIGNAL ( ReqConnClientsList() ), this, SLOT ( OnReqConnClientsListCh1() ) );
|
||||||
|
@ -578,6 +534,11 @@ CServer::CServer ( const int iNewMaxNumChan,
|
||||||
QObject::connect ( &vecChannels[17], SIGNAL ( ServerAutoSockBufSizeChange ( int ) ), this, SLOT ( OnServerAutoSockBufSizeChangeCh17 ( int ) ) );
|
QObject::connect ( &vecChannels[17], SIGNAL ( ServerAutoSockBufSizeChange ( int ) ), this, SLOT ( OnServerAutoSockBufSizeChangeCh17 ( int ) ) );
|
||||||
QObject::connect ( &vecChannels[18], SIGNAL ( ServerAutoSockBufSizeChange ( int ) ), this, SLOT ( OnServerAutoSockBufSizeChangeCh18 ( int ) ) );
|
QObject::connect ( &vecChannels[18], SIGNAL ( ServerAutoSockBufSizeChange ( int ) ), this, SLOT ( OnServerAutoSockBufSizeChangeCh18 ( int ) ) );
|
||||||
QObject::connect ( &vecChannels[19], SIGNAL ( ServerAutoSockBufSizeChange ( int ) ), this, SLOT ( OnServerAutoSockBufSizeChangeCh19 ( int ) ) );
|
QObject::connect ( &vecChannels[19], SIGNAL ( ServerAutoSockBufSizeChange ( int ) ), this, SLOT ( OnServerAutoSockBufSizeChangeCh19 ( int ) ) );
|
||||||
|
|
||||||
|
|
||||||
|
// start the socket (it is important to start the socket after all
|
||||||
|
// initializations and connections)
|
||||||
|
Socket.Start();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CServer::OnSendProtMessage ( int iChID, CVector<uint8_t> vecMessage )
|
void CServer::OnSendProtMessage ( int iChID, CVector<uint8_t> vecMessage )
|
||||||
|
@ -587,7 +548,8 @@ void CServer::OnSendProtMessage ( int iChID, CVector<uint8_t> vecMessage )
|
||||||
Socket.SendPacket ( vecMessage, vecChannels[iChID].GetAddress() );
|
Socket.SendPacket ( vecMessage, vecChannels[iChID].GetAddress() );
|
||||||
}
|
}
|
||||||
|
|
||||||
void CServer::OnNewConnection ( int iChID )
|
void CServer::OnNewConnection ( int iChID,
|
||||||
|
CHostAddress RecHostAddr )
|
||||||
{
|
{
|
||||||
// on a new connection we query the network transport properties for the
|
// on a new connection we query the network transport properties for the
|
||||||
// audio packets (to use the correct network block size and audio
|
// audio packets (to use the correct network block size and audio
|
||||||
|
@ -600,6 +562,51 @@ void CServer::OnNewConnection ( int iChID )
|
||||||
// reached a state where this did not happen because of network trouble,
|
// reached a state where this did not happen because of network trouble,
|
||||||
// client or server thinks that the connection was still active, etc.)
|
// client or server thinks that the connection was still active, etc.)
|
||||||
vecChannels[iChID].CreateReqJitBufMes();
|
vecChannels[iChID].CreateReqJitBufMes();
|
||||||
|
|
||||||
|
// logging of new connected channel
|
||||||
|
Logging.AddNewConnection ( RecHostAddr.InetAddr );
|
||||||
|
|
||||||
|
// A new client connected to the server, the channel list
|
||||||
|
// at all clients have to be updated. This is done by sending
|
||||||
|
// a channel name request to the client which causes a channel
|
||||||
|
// name message to be transmitted to the server. If the server
|
||||||
|
// receives this message, the channel list will be automatically
|
||||||
|
// updated (implicitely).
|
||||||
|
// To make sure the protocol message is transmitted, the channel
|
||||||
|
// first has to be marked as connected.
|
||||||
|
//
|
||||||
|
// Usually it is not required to send the channel list to the
|
||||||
|
// client currently connecting since it automatically requests
|
||||||
|
// the channel list on a new connection (as a result, he will
|
||||||
|
// usually get the list twice which has no impact on functionality
|
||||||
|
// but will only increase the network load a tiny little bit). But
|
||||||
|
// in case the client thinks he is still connected but the server
|
||||||
|
// was restartet, it is important that we send the channel list
|
||||||
|
// at this place.
|
||||||
|
vecChannels[iChID].ResetTimeOutCounter();
|
||||||
|
vecChannels[iChID].CreateReqChanInfoMes();
|
||||||
|
|
||||||
|
// COMPATIBILITY ISSUE
|
||||||
|
// since old versions of the software did not implement the channel name
|
||||||
|
// request message, we have to explicitely send the channel list here
|
||||||
|
CreateAndSendChanListForAllConChannels();
|
||||||
|
|
||||||
|
// send welcome message (if enabled)
|
||||||
|
if ( !strWelcomeMessage.isEmpty() )
|
||||||
|
{
|
||||||
|
// create formated server welcome message and send it just to
|
||||||
|
// the client which just connected to the server
|
||||||
|
const QString strWelcomeMessageFormated =
|
||||||
|
"<b>Server Welcome Message:</b> " + strWelcomeMessage;
|
||||||
|
|
||||||
|
vecChannels[iChID].CreateChatTextMes ( strWelcomeMessageFormated );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void CServer::OnServerFull ( CHostAddress RecHostAddr )
|
||||||
|
{
|
||||||
|
// inform the calling client that no channel is free
|
||||||
|
ConnLessProtocol.CreateCLServerFullMes ( RecHostAddr );
|
||||||
}
|
}
|
||||||
|
|
||||||
void CServer::OnSendCLProtMessage ( CHostAddress InetAddr,
|
void CServer::OnSendCLProtMessage ( CHostAddress InetAddr,
|
||||||
|
@ -610,15 +617,14 @@ void CServer::OnSendCLProtMessage ( CHostAddress InetAddr,
|
||||||
Socket.SendPacket ( vecMessage, InetAddr );
|
Socket.SendPacket ( vecMessage, InetAddr );
|
||||||
}
|
}
|
||||||
|
|
||||||
void CServer::OnDetCLMess ( const CVector<uint8_t>& vecbyMesBodyData,
|
void CServer::OnProtcolCLMessageReceived ( int iRecID,
|
||||||
const int iRecID,
|
CVector<uint8_t> vecbyMesBodyData,
|
||||||
const CHostAddress& InetAddr )
|
CHostAddress RecHostAddr )
|
||||||
{
|
{
|
||||||
// this is a special case: we received a connection less message but we are
|
// connection less messages are always processed
|
||||||
// in a connection
|
|
||||||
ConnLessProtocol.ParseConnectionLessMessageBody ( vecbyMesBodyData,
|
ConnLessProtocol.ParseConnectionLessMessageBody ( vecbyMesBodyData,
|
||||||
iRecID,
|
iRecID,
|
||||||
InetAddr );
|
RecHostAddr );
|
||||||
}
|
}
|
||||||
|
|
||||||
void CServer::OnCLDisconnection ( CHostAddress InetAddr )
|
void CServer::OnCLDisconnection ( CHostAddress InetAddr )
|
||||||
|
@ -835,7 +841,7 @@ void CServer::OnTimer()
|
||||||
// Process data ------------------------------------------------------------
|
// Process data ------------------------------------------------------------
|
||||||
// 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 )
|
||||||
{
|
{
|
||||||
for ( int i = 0; i < iNumClients; i++ )
|
for ( int i = 0; i < iNumClients; i++ )
|
||||||
{
|
{
|
||||||
|
@ -1214,27 +1220,43 @@ int CServer::FindChannel ( const CHostAddress& CheckAddr )
|
||||||
return INVALID_CHANNEL_ID;
|
return INVALID_CHANNEL_ID;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CServer::PutData ( const CVector<uint8_t>& vecbyRecBuf,
|
void CServer::OnProtcolMessageReceived ( int iRecCounter,
|
||||||
const int iNumBytesRead,
|
int iRecID,
|
||||||
const CHostAddress& HostAdr )
|
CVector<uint8_t> vecbyMesBodyData,
|
||||||
|
CHostAddress RecHostAddr )
|
||||||
{
|
{
|
||||||
|
Mutex.lock();
|
||||||
|
{
|
||||||
|
// find the channel with the received address
|
||||||
|
const int iCurChanID = FindChannel ( RecHostAddr );
|
||||||
|
|
||||||
|
// if the channel exists, apply the protocol message to the channel
|
||||||
|
if ( iCurChanID != INVALID_CHANNEL_ID )
|
||||||
|
{
|
||||||
|
vecChannels[iCurChanID].PutProtcolData ( iRecCounter,
|
||||||
|
iRecID,
|
||||||
|
vecbyMesBodyData,
|
||||||
|
RecHostAddr );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Mutex.unlock();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool CServer::PutAudioData ( const CVector<uint8_t>& vecbyRecBuf,
|
||||||
|
const int iNumBytesRead,
|
||||||
|
const CHostAddress& HostAdr,
|
||||||
|
int& iCurChanID )
|
||||||
|
{
|
||||||
|
bool bNewConnection = false; // init return value
|
||||||
bool bChanOK = true; // init with ok, might be overwritten
|
bool bChanOK = true; // init with ok, might be overwritten
|
||||||
bool bNewChannelReserved = false;
|
|
||||||
bool bIsNotEvaluatedProtocolMessage = false;
|
|
||||||
|
|
||||||
Mutex.lock();
|
Mutex.lock();
|
||||||
{
|
{
|
||||||
// Get channel ID ------------------------------------------------------
|
// Get channel ID ------------------------------------------------------
|
||||||
// check address
|
// check address
|
||||||
int iCurChanID = FindChannel ( HostAdr );
|
iCurChanID = FindChannel ( HostAdr );
|
||||||
|
|
||||||
if ( iCurChanID == INVALID_CHANNEL_ID )
|
if ( iCurChanID == INVALID_CHANNEL_ID )
|
||||||
{
|
|
||||||
// this is a new client, we then first check if this is a connection
|
|
||||||
// less message before we create a new official channel
|
|
||||||
if ( ConnLessProtocol.ParseConnectionLessMessageWithFrame ( vecbyRecBuf,
|
|
||||||
iNumBytesRead,
|
|
||||||
HostAdr ) )
|
|
||||||
{
|
{
|
||||||
// a new client is calling, look for free channel
|
// a new client is calling, look for free channel
|
||||||
iCurChanID = GetFreeChan();
|
iCurChanID = GetFreeChan();
|
||||||
|
@ -1258,88 +1280,32 @@ bool CServer::PutData ( const CVector<uint8_t>& vecbyRecBuf,
|
||||||
// i == iCurChanID for simplicity)
|
// i == iCurChanID for simplicity)
|
||||||
vecChannels[i].SetGain ( iCurChanID, (double) 1.0 );
|
vecChannels[i].SetGain ( iCurChanID, (double) 1.0 );
|
||||||
}
|
}
|
||||||
|
|
||||||
// set flag for new reserved channel
|
|
||||||
bNewChannelReserved = true;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// no free channel available
|
// no free channel available
|
||||||
bChanOK = false;
|
bChanOK = false;
|
||||||
|
|
||||||
// create and send "server full" message
|
|
||||||
ConnLessProtocol.CreateCLServerFullMes ( HostAdr );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// this was a connection less protocol message, return according
|
|
||||||
// state
|
|
||||||
bChanOK = false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Put received data in jitter buffer ----------------------------------
|
// Put received audio data in jitter buffer ----------------------------
|
||||||
if ( bChanOK )
|
if ( bChanOK )
|
||||||
{
|
{
|
||||||
// put packet in socket buffer
|
// put packet in socket buffer
|
||||||
if ( vecChannels[iCurChanID].PutData ( vecbyRecBuf,
|
if ( vecChannels[iCurChanID].PutAudioData ( vecbyRecBuf,
|
||||||
iNumBytesRead ) == PS_PROT_OK_MESS_NOT_EVALUATED )
|
iNumBytesRead,
|
||||||
|
HostAdr ) == PS_NEW_CONNECTION )
|
||||||
{
|
{
|
||||||
// set flag
|
// in case we have a new connection return this information
|
||||||
bIsNotEvaluatedProtocolMessage = true;
|
bNewConnection = true;
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// act on new channel connection
|
|
||||||
if ( bNewChannelReserved && ( !bIsNotEvaluatedProtocolMessage ) )
|
|
||||||
{
|
|
||||||
// logging of new connected channel
|
|
||||||
Logging.AddNewConnection ( HostAdr.InetAddr );
|
|
||||||
|
|
||||||
// A new client connected to the server, the channel list
|
|
||||||
// at all clients have to be updated. This is done by sending
|
|
||||||
// a channel name request to the client which causes a channel
|
|
||||||
// name message to be transmitted to the server. If the server
|
|
||||||
// receives this message, the channel list will be automatically
|
|
||||||
// updated (implicitely).
|
|
||||||
// To make sure the protocol message is transmitted, the channel
|
|
||||||
// first has to be marked as connected.
|
|
||||||
//
|
|
||||||
// Usually it is not required to send the channel list to the
|
|
||||||
// client currently connecting since it automatically requests
|
|
||||||
// the channel list on a new connection (as a result, he will
|
|
||||||
// usually get the list twice which has no impact on functionality
|
|
||||||
// but will only increase the network load a tiny little bit). But
|
|
||||||
// in case the client thinks he is still connected but the server
|
|
||||||
// was restartet, it is important that we send the channel list
|
|
||||||
// at this place.
|
|
||||||
vecChannels[iCurChanID].ResetTimeOutCounter();
|
|
||||||
vecChannels[iCurChanID].CreateReqChanInfoMes();
|
|
||||||
|
|
||||||
// COMPATIBILITY ISSUE
|
|
||||||
// since old versions of the software did not implement the channel name
|
|
||||||
// request message, we have to explicitely send the channel list here
|
|
||||||
CreateAndSendChanListForAllConChannels();
|
|
||||||
|
|
||||||
// send welcome message (if enabled)
|
|
||||||
if ( !strWelcomeMessage.isEmpty() )
|
|
||||||
{
|
|
||||||
// create formated server welcome message and send it just to
|
|
||||||
// the client which just connected to the server
|
|
||||||
const QString strWelcomeMessageFormated =
|
|
||||||
"<b>Server Welcome Message:</b> " + strWelcomeMessage;
|
|
||||||
|
|
||||||
vecChannels[iCurChanID].CreateChatTextMes ( strWelcomeMessageFormated );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Mutex.unlock();
|
Mutex.unlock();
|
||||||
|
|
||||||
// we do not want the server to be started on a protocol message but only on
|
// return the state if a new connection was happening
|
||||||
// an audio packet -> consider "bIsNotEvaluatedProtocolMessage", too
|
return bNewConnection;
|
||||||
return bChanOK && ( !bIsNotEvaluatedProtocolMessage );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CServer::GetConCliParam ( CVector<CHostAddress>& vecHostAddresses,
|
void CServer::GetConCliParam ( CVector<CHostAddress>& vecHostAddresses,
|
||||||
|
|
Loading…
Reference in a new issue