From e5aedf6998a6a005e7e01a9653fddb3071dad378 Mon Sep 17 00:00:00 2001 From: Volker Fischer Date: Wed, 29 Jan 2014 16:06:52 +0000 Subject: [PATCH] fix for high prio socket --- src/channel.cpp | 25 +++++++++++++++++++++++-- src/channel.h | 7 +++++++ src/client.cpp | 6 ++++++ src/socket.h | 7 +------ 4 files changed, 37 insertions(+), 8 deletions(-) diff --git a/src/channel.cpp b/src/channel.cpp index 7529d404..ed5dd6c9 100755 --- a/src/channel.cpp +++ b/src/channel.cpp @@ -51,8 +51,10 @@ CChannel::CChannel ( const bool bNIsServer ) : // Connections ------------------------------------------------------------- - qRegisterMetaType > ( "CVector" ); - qRegisterMetaType ( "CHostAddress" ); + +// TODO if we later do not fire vectors in the emits, we can remove this again +qRegisterMetaType > ( "CVector" ); +qRegisterMetaType ( "CHostAddress" ); QObject::connect ( &Protocol, SIGNAL ( MessReadyForSending ( CVector ) ), @@ -477,6 +479,7 @@ EPutDataStat CChannel::PutData ( const CVector& vecbyData, { // fire a signal so that an other class can process this type of // message +// TODO a copy of the vector is used -> avoid malloc in real-time routine emit DetectedCLMessage ( vecbyMesBodyData, iRecID ); // set status flag @@ -485,6 +488,7 @@ EPutDataStat CChannel::PutData ( const CVector& vecbyData, else { // parse the message assuming this is a regular protocol message +// TODO a copy of the vector is used -> avoid malloc in real-time routine emit ParseMessageBody ( vecbyMesBodyData, iRecCounter, iRecID ); // note that protocol OK is not correct here since we do not @@ -625,6 +629,23 @@ EGetDataStat CChannel::GetData ( CVector& vecbyData, return eGetStatus; } +#ifdef ENABLE_RECEIVE_SOCKET_IN_SEPARATE_THREAD +void CChannel::PrepAndSendPacketHPS ( CHighPrioSocket* pSocket, + const CVector& vecbyNPacket, + const int iNPacketLen ) +{ +// TODO Doubled code!!! Same code as in PrepAndSendPacket (see below)!!! + QMutexLocker locker ( &Mutex ); + + // use conversion buffer to convert sound card block size in network + // block size + if ( ConvBuf.Put ( vecbyNPacket, iNPacketLen ) ) + { + pSocket->SendPacket ( ConvBuf.Get(), GetAddress() ); + } +} +#endif + void CChannel::PrepAndSendPacket ( CSocket* pSocket, const CVector& vecbyNPacket, const int iNPacketLen ) diff --git a/src/channel.h b/src/channel.h index 994a75b3..34021572 100755 --- a/src/channel.h +++ b/src/channel.h @@ -68,10 +68,17 @@ public: EGetDataStat GetData ( CVector& vecbyData, const int iNumBytes ); +#ifdef ENABLE_RECEIVE_SOCKET_IN_SEPARATE_THREAD + void PrepAndSendPacketHPS ( CHighPrioSocket* pSocket, + const CVector& vecbyNPacket, + const int iNPacketLen ); +#endif + void PrepAndSendPacket ( CSocket* pSocket, const CVector& vecbyNPacket, const int iNPacketLen ); + void ResetTimeOutCounter() { iConTimeOut = iConTimeOutStartVal; } bool IsConnected() const { return iConTimeOut > 0; } void Disconnect(); diff --git a/src/client.cpp b/src/client.cpp index 3cc92eae..93e06c39 100755 --- a/src/client.cpp +++ b/src/client.cpp @@ -1093,9 +1093,15 @@ void CClient::ProcessAudioDataIntern ( CVector& vecsStereoSndCrd ) } // send coded audio through the network +#ifdef ENABLE_RECEIVE_SOCKET_IN_SEPARATE_THREAD + Channel.PrepAndSendPacketHPS ( &Socket, + vecCeltData, + iCeltNumCodedBytes ); +#else Channel.PrepAndSendPacket ( &Socket, vecCeltData, iCeltNumCodedBytes ); +#endif } diff --git a/src/socket.h b/src/socket.h index 9cf58632..12952651 100755 --- a/src/socket.h +++ b/src/socket.h @@ -110,11 +110,6 @@ public: CHighPrioSocket ( CChannel* pNewChannel, const quint16 iPortNumber ) { - // we have to register some classes to the Qt signal/slot mechanism - // since we have thread crossings with the threaded code - qRegisterMetaType > ( "CVector" ); - qRegisterMetaType ( "CHostAddress" ); - // Creation of the new socket thread which has to have the highest // possible thread priority to make sure the jitter buffer is reliably // filled with the network audio packets and does not get interrupted @@ -143,7 +138,7 @@ public: bool GetAndResetbJitterBufferOKFlag() { - pSocket->GetAndResetbJitterBufferOKFlag(); + return pSocket->GetAndResetbJitterBufferOKFlag(); } protected: