diff --git a/src/channel.cpp b/src/channel.cpp index a3024e52..b361ff6d 100755 --- a/src/channel.cpp +++ b/src/channel.cpp @@ -93,6 +93,10 @@ CChannel::CChannel ( const bool bNIsServer ) : SIGNAL ( PingReceived ( int ) ), SIGNAL ( PingReceived ( int ) ) ); + QObject::connect ( &Protocol, + SIGNAL ( DetectedCLMessage ( CVector, int ) ), + SIGNAL ( DetectedCLMessage ( CVector, int ) ) ); + QObject::connect ( &Protocol, SIGNAL ( NetTranspPropsReceived ( CNetworkTransportProps ) ), this, SLOT ( OnNetTranspPropsReceived ( CNetworkTransportProps ) ) ); @@ -100,9 +104,6 @@ CChannel::CChannel ( const bool bNIsServer ) : QObject::connect ( &Protocol, SIGNAL ( ReqNetTranspProps() ), this, SLOT ( OnReqNetTranspProps() ) ); - - QObject::connect ( &Protocol, SIGNAL ( Disconnection() ), - this, SLOT ( OnDisconnection() ) ); } bool CChannel::ProtocolIsEnabled() @@ -351,10 +352,14 @@ void CChannel::CreateNetTranspPropsMessFromCurrentSettings() void CChannel::Disconnect() { - // set time out counter to a small value > 0 so that the next time a - // received audio block is queried, the disconnection is performed - // (assuming that no audio packet is received in the meantime) - iConTimeOut = 1; // a small number > 0 + // we only have to disconnect the channel if it is actually connected + if ( IsConnected() ) + { + // set time out counter to a small value > 0 so that the next time a + // received audio block is queried, the disconnection is performed + // (assuming that no audio packet is received in the meantime) + iConTimeOut = 1; // a small number > 0 + } } EPutDataStat CChannel::PutData ( const CVector& vecbyData, diff --git a/src/channel.h b/src/channel.h index 253b3656..54b22e6f 100755 --- a/src/channel.h +++ b/src/channel.h @@ -138,8 +138,6 @@ void UpdateSocketBufferSize ( const double dAudioBufferDurationMs, } void CreateNetTranspPropsMessFromCurrentSettings(); - void CreateAndImmSendDisconnectionMes() - { Protocol.CreateAndImmSendDisconnectionMes(); } protected: bool ProtocolIsEnabled(); @@ -186,7 +184,6 @@ public slots: void OnChangeChanName ( QString strName ); void OnNetTranspPropsReceived ( CNetworkTransportProps NetworkTransportProps ); void OnReqNetTranspProps(); - void OnDisconnection() { Disconnect(); } signals: void MessReadyForSending ( CVector vecMessage ); @@ -200,6 +197,8 @@ signals: void PingReceived ( int iMs ); void ReqNetTranspProps(); void Disconnected(); + void DetectedCLMessage ( CVector vecbyData, + int iNumBytes ); }; #endif /* !defined ( CHANNEL_HOIH9345KJH98_3_4344_BB23945IUHF1912__INCLUDED_ ) */ diff --git a/src/client.cpp b/src/client.cpp index 88e44262..87377b18 100755 --- a/src/client.cpp +++ b/src/client.cpp @@ -83,6 +83,10 @@ CClient::CClient ( const quint16 iPortNumber ) : SIGNAL ( MessReadyForSending ( CVector ) ), this, SLOT ( OnSendProtMessage ( CVector ) ) ); + QObject::connect ( &Channel, + SIGNAL ( DetectedCLMessage ( CVector, int ) ), + this, SLOT ( OnDetectedCLMessage ( CVector, int ) ) ); + QObject::connect ( &Channel, SIGNAL ( ReqJittBufSize() ), this, SLOT ( OnReqJittBufSize() ) ); @@ -138,6 +142,16 @@ void CClient::OnSendCLProtMessage ( CHostAddress InetAddr, Socket.SendPacket ( vecMessage, InetAddr ); } +void CClient::OnDetectedCLMessage ( CVector vecbyData, + int iNumBytes ) +{ + // this is a special case: we received a connection less message but we are + // in a connection + ConnLessProtocol.ParseConnectionLessMessage ( vecbyData, + iNumBytes, + Channel.GetAddress() ); +} + void CClient::OnNewConnection() { // a new connection was successfully initiated, send name and request @@ -420,6 +434,9 @@ void CClient::Stop() // stop audio interface Sound.Stop(); + // disable channel + Channel.SetEnable ( false ); + // wait for approx. 100 ms to make sure no audio packet is still in the // network queue causing the channel to be reconnected right after having // received the disconnect message (seems not to gain much, disconnect is @@ -440,10 +457,7 @@ void CClient::Stop() // respond from the server, therefore we just hope that the message // gets its way to the server, if not, the old behaviour time-out // disconnects the connection anyway). - Channel.CreateAndImmSendDisconnectionMes(); - - // disable channel - Channel.SetEnable ( false ); + ConnLessProtocol.CreateCLDisconnection ( Channel.GetAddress() ); // reset current signal level and LEDs SignalLevelMeter.Reset(); diff --git a/src/client.h b/src/client.h index fff8eaf7..1373270e 100755 --- a/src/client.h +++ b/src/client.h @@ -318,6 +318,7 @@ protected: public slots: void OnSendProtMessage ( CVector vecMessage ); + void OnDetectedCLMessage ( CVector vecbyData, int iNumBytes ); void OnReqJittBufSize() { Channel.CreateJitBufMes ( Channel.GetSockBufNumFrames() ); } void OnReqChanName() { Channel.SetRemoteName ( strName ); } void OnNewConnection(); @@ -325,8 +326,8 @@ public slots: void OnSendCLProtMessage ( CHostAddress InetAddr, CVector vecMessage ); void OnCLPingWithNumClientsReceived ( CHostAddress InetAddr, - int iMs, - int iNumClients ); + int iMs, + int iNumClients ); void OnSndCrdReinitRequest(); @@ -337,8 +338,8 @@ signals: void CLServerListReceived ( CHostAddress InetAddr, CVector vecServerInfo ); void CLPingTimeWithNumClientsReceived ( CHostAddress InetAddr, - int iPingTime, - int iNumClients ); + int iPingTime, + int iNumClients ); void Disconnected(); }; diff --git a/src/protocol.cpp b/src/protocol.cpp index c5a619d5..460b99d4 100755 --- a/src/protocol.cpp +++ b/src/protocol.cpp @@ -140,11 +140,6 @@ MESSAGES (with connection) note: does not have any data -> n = 0 -- PROTMESSID_DISCONNECTION: Disconnect message - - note: does not have any data -> n = 0 - - CONNECTION LESS MESSAGES ------------------------ @@ -436,10 +431,9 @@ if ( rand() < ( RAND_MAX / 2 ) ) return false; // in case this is a connection less message, we do not process it here if ( IsConnectionLessMessageID ( iRecID ) ) { - - -// TODO fire signal so that an other class can process this type of message - + // fire a signal so that an other class can process this type of + // message + emit DetectedCLMessage ( vecbyData, iNumBytes ); // return function without issuing an error code (since it is a // regular message but will just not processed here) @@ -541,10 +535,6 @@ if ( rand() < ( RAND_MAX / 2 ) ) return false; case PROTMESSID_REQ_NETW_TRANSPORT_PROPS: bRet = EvaluateReqNetwTranspPropsMes(); break; - - case PROTMESSID_DISCONNECTION: - bRet = EvaluateDisconnectionMes(); - break; } // immediately send acknowledge message @@ -1108,37 +1098,6 @@ bool CProtocol::EvaluateReqNetwTranspPropsMes() return false; // no error } -void CProtocol::CreateAndImmSendDisconnectionMes() -{ - CVector vecDisconMessage; - int iCurCounter; - - Mutex.lock(); - { - // store current counter value - iCurCounter = iCounter; - - // increase counter (wraps around automatically) - iCounter++; - } - Mutex.unlock(); - - // build complete message - GenMessageFrame ( vecDisconMessage, iCurCounter, - PROTMESSID_DISCONNECTION, CVector ( 0 ) ); - - // immediately send acknowledge message - emit MessReadyForSending ( vecDisconMessage ); -} - -bool CProtocol::EvaluateDisconnectionMes() -{ - // invoke message action - emit Disconnection(); - - return false; // no error -} - // Connection less messages ---------------------------------------------------- void CProtocol::CreateCLPingMes ( const CHostAddress& InetAddr, const int iMs ) diff --git a/src/protocol.h b/src/protocol.h index 3921a3cb..5d388945 100755 --- a/src/protocol.h +++ b/src/protocol.h @@ -50,7 +50,7 @@ #define PROTMESSID_PING_MS 19 // for measuring ping time #define PROTMESSID_NETW_TRANSPORT_PROPS 20 // properties for network transport #define PROTMESSID_REQ_NETW_TRANSPORT_PROPS 21 // request properties for network transport -#define PROTMESSID_DISCONNECTION 22 // disconnection +#define PROTMESSID_DISCONNECTION 22 // OLD (not used anymore) #define PROTMESSID_REQ_CHANNEL_NAME 23 // request channel name for fader tag // message IDs of connection less messages (CLM) @@ -123,8 +123,6 @@ public: bool IsProtocolMessage ( const CVector& vecbyData, const int iNumBytes ); - void CreateAndImmSendDisconnectionMes(); - // this function is public because we need it in the test bench void CreateAndImmSendAcknMess ( const int& iID, const int& iCnt ); @@ -209,7 +207,6 @@ protected: bool EvaluatePingMes ( const CVector& vecData ); bool EvaluateNetwTranspPropsMes ( const CVector& vecData ); bool EvaluateReqNetwTranspPropsMes(); - bool EvaluateDisconnectionMes(); bool EvaluateCLPingMes ( const CHostAddress& InetAddr, const CVector& vecData ); @@ -240,7 +237,7 @@ public slots: signals: // transmitting - void MessReadyForSending ( CVector vecMessage ); + void MessReadyForSending ( CVector vecMessage ); void CLMessReadyForSending ( CHostAddress InetAddr, CVector vecMessage ); @@ -258,20 +255,23 @@ signals: void PingReceived ( int iMs ); void NetTranspPropsReceived ( CNetworkTransportProps NetworkTransportProps ); void ReqNetTranspProps(); - void Disconnection(); - void CLPingReceived ( CHostAddress InetAddr, int iMs ); - void CLPingWithNumClientsReceived ( CHostAddress InetAddr, - int iMs, - int iNumClients ); - void CLRegisterServerReceived ( CHostAddress InetAddr, - CServerCoreInfo ServerInfo ); - void CLUnregisterServerReceived ( CHostAddress InetAddr ); - void CLServerListReceived ( CHostAddress InetAddr, - CVector vecServerInfo ); - void CLReqServerList ( CHostAddress InetAddr ); - void CLSendEmptyMes ( CHostAddress TargetInetAddr ); - void CLDisconnection ( CHostAddress InetAddr ); + void CLPingReceived ( CHostAddress InetAddr, + int iMs ); + void CLPingWithNumClientsReceived ( CHostAddress InetAddr, + int iMs, + int iNumClients ); + void CLRegisterServerReceived ( CHostAddress InetAddr, + CServerCoreInfo ServerInfo ); + void CLUnregisterServerReceived ( CHostAddress InetAddr ); + void CLServerListReceived ( CHostAddress InetAddr, + CVector vecServerInfo ); + void CLReqServerList ( CHostAddress InetAddr ); + void CLSendEmptyMes ( CHostAddress TargetInetAddr ); + void CLDisconnection ( CHostAddress InetAddr ); + + void DetectedCLMessage ( CVector vecbyData, + int iNumBytes ); }; #endif /* !defined ( PROTOCOL_H__3B123453_4344_BB2392354455IUHF1912__INCLUDED_ ) */ diff --git a/src/server.cpp b/src/server.cpp index 4dfc1a21..f6967a17 100755 --- a/src/server.cpp +++ b/src/server.cpp @@ -325,6 +325,20 @@ CServer::CServer ( const int iNewNumChan, QObject::connect ( &vecChannels[10], SIGNAL ( MessReadyForSending ( CVector ) ), this, SLOT ( OnSendProtMessCh10 ( CVector ) ) ); QObject::connect ( &vecChannels[11], SIGNAL ( MessReadyForSending ( CVector ) ), this, SLOT ( OnSendProtMessCh11 ( CVector ) ) ); + // a connection less protocol message was detected + QObject::connect ( &vecChannels[0], SIGNAL ( DetectedCLMessage ( CVector, int ) ), this, SLOT ( OnDetCLMessCh0 ( CVector, int ) ) ); + QObject::connect ( &vecChannels[1], SIGNAL ( DetectedCLMessage ( CVector, int ) ), this, SLOT ( OnDetCLMessCh1 ( CVector, int ) ) ); + QObject::connect ( &vecChannels[2], SIGNAL ( DetectedCLMessage ( CVector, int ) ), this, SLOT ( OnDetCLMessCh2 ( CVector, int ) ) ); + QObject::connect ( &vecChannels[3], SIGNAL ( DetectedCLMessage ( CVector, int ) ), this, SLOT ( OnDetCLMessCh3 ( CVector, int ) ) ); + QObject::connect ( &vecChannels[4], SIGNAL ( DetectedCLMessage ( CVector, int ) ), this, SLOT ( OnDetCLMessCh4 ( CVector, int ) ) ); + QObject::connect ( &vecChannels[5], SIGNAL ( DetectedCLMessage ( CVector, int ) ), this, SLOT ( OnDetCLMessCh5 ( CVector, int ) ) ); + QObject::connect ( &vecChannels[6], SIGNAL ( DetectedCLMessage ( CVector, int ) ), this, SLOT ( OnDetCLMessCh6 ( CVector, int ) ) ); + QObject::connect ( &vecChannels[7], SIGNAL ( DetectedCLMessage ( CVector, int ) ), this, SLOT ( OnDetCLMessCh7 ( CVector, int ) ) ); + QObject::connect ( &vecChannels[8], SIGNAL ( DetectedCLMessage ( CVector, int ) ), this, SLOT ( OnDetCLMessCh8 ( CVector, int ) ) ); + QObject::connect ( &vecChannels[9], SIGNAL ( DetectedCLMessage ( CVector, int ) ), this, SLOT ( OnDetCLMessCh9 ( CVector, int ) ) ); + QObject::connect ( &vecChannels[10], SIGNAL ( DetectedCLMessage ( CVector, int ) ), this, SLOT ( OnDetCLMessCh10 ( CVector, int ) ) ); + QObject::connect ( &vecChannels[11], SIGNAL ( DetectedCLMessage ( CVector, int ) ), this, SLOT ( OnDetCLMessCh11 ( CVector, int ) ) ); + // request jitter buffer size QObject::connect ( &vecChannels[0], SIGNAL ( NewConnection() ), this, SLOT ( OnNewConnectionCh0() ) ); QObject::connect ( &vecChannels[1], SIGNAL ( NewConnection() ), this, SLOT ( OnNewConnectionCh1() ) ); @@ -411,6 +425,17 @@ void CServer::OnSendCLProtMessage ( CHostAddress InetAddr, Socket.SendPacket ( vecMessage, InetAddr ); } +void CServer::OnDetCLMess ( const CVector& vecbyData, + const int iNumBytes, + const CHostAddress& InetAddr ) +{ + // this is a special case: we received a connection less message but we are + // in a connection + ConnLessProtocol.ParseConnectionLessMessage ( vecbyData, + iNumBytes, + InetAddr ); +} + void CServer::OnCLDisconnection ( CHostAddress InetAddr ) { // check if the given address is actually a client which is connected to diff --git a/src/server.h b/src/server.h index fab4012a..deffc57a 100755 --- a/src/server.h +++ b/src/server.h @@ -245,6 +245,10 @@ public slots: void OnSendProtMessage ( int iChID, CVector vecMessage ); void OnSendCLProtMessage ( CHostAddress InetAddr, CVector vecMessage ); + void OnDetCLMess ( const CVector& vecbyData, + const int iNumBytes, + const CHostAddress& InetAddr ); + void OnCLPingReceived ( CHostAddress InetAddr, int iMs ) { ConnLessProtocol.CreateCLPingWithNumClientsMes ( InetAddr, @@ -296,6 +300,19 @@ public slots: void OnSendProtMessCh10 ( CVector mess ) { OnSendProtMessage ( 10, mess ); } void OnSendProtMessCh11 ( CVector mess ) { OnSendProtMessage ( 11, mess ); } + void OnDetCLMessCh0 ( CVector vData, int iNBy ) { OnDetCLMess ( vData, iNBy, vecChannels[0].GetAddress() ); } + void OnDetCLMessCh1 ( CVector vData, int iNBy ) { OnDetCLMess ( vData, iNBy, vecChannels[1].GetAddress() ); } + void OnDetCLMessCh2 ( CVector vData, int iNBy ) { OnDetCLMess ( vData, iNBy, vecChannels[2].GetAddress() ); } + void OnDetCLMessCh3 ( CVector vData, int iNBy ) { OnDetCLMess ( vData, iNBy, vecChannels[3].GetAddress() ); } + void OnDetCLMessCh4 ( CVector vData, int iNBy ) { OnDetCLMess ( vData, iNBy, vecChannels[4].GetAddress() ); } + void OnDetCLMessCh5 ( CVector vData, int iNBy ) { OnDetCLMess ( vData, iNBy, vecChannels[5].GetAddress() ); } + void OnDetCLMessCh6 ( CVector vData, int iNBy ) { OnDetCLMess ( vData, iNBy, vecChannels[6].GetAddress() ); } + void OnDetCLMessCh7 ( CVector vData, int iNBy ) { OnDetCLMess ( vData, iNBy, vecChannels[7].GetAddress() ); } + void OnDetCLMessCh8 ( CVector vData, int iNBy ) { OnDetCLMess ( vData, iNBy, vecChannels[8].GetAddress() ); } + void OnDetCLMessCh9 ( CVector vData, int iNBy ) { OnDetCLMess ( vData, iNBy, vecChannels[9].GetAddress() ); } + void OnDetCLMessCh10 ( CVector vData, int iNBy ) { OnDetCLMess ( vData, iNBy, vecChannels[10].GetAddress() ); } + void OnDetCLMessCh11 ( CVector vData, int iNBy ) { OnDetCLMess ( vData, iNBy, vecChannels[11].GetAddress() ); } + void OnNewConnectionCh0() { vecChannels[0].CreateReqJitBufMes(); } void OnNewConnectionCh1() { vecChannels[1].CreateReqJitBufMes(); } void OnNewConnectionCh2() { vecChannels[2].CreateReqJitBufMes(); } diff --git a/src/socket.cpp b/src/socket.cpp index 975651ef..af1524db 100755 --- a/src/socket.cpp +++ b/src/socket.cpp @@ -137,20 +137,7 @@ void CSocket::OnDataReceived() // are not connected anymore if ( pChannel->GetAddress() == RecHostAddr ) { - - -// TEST old code -> to be removed because this is not working!!! -/* -pChannel->SetEnable ( true ); -pChannel->CreateAndImmSendDisconnectionMes(); -pChannel->SetEnable ( false ); -*/ - -// TODO this does not work because for a connected channel at the server, no -// connection less protocol messages are accepted - -// pConnLessProtocol->CreateCLDisconnection ( RecHostAddr ); - + pConnLessProtocol->CreateCLDisconnection ( RecHostAddr ); } }