avoid allocating memory in time critical client thread -> improve socket send function in the channel

This commit is contained in:
Volker Fischer 2014-01-06 15:57:40 +00:00
parent 91b4823d37
commit f016e9e022
6 changed files with 15 additions and 20 deletions

View File

@ -469,7 +469,7 @@ public:
return false;
}
CVector<TData> Get()
CVector<TData>& Get()
{
iPutPos = 0;
return vecsMemory;

View File

@ -621,7 +621,8 @@ EGetDataStat CChannel::GetData ( CVector<uint8_t>& vecbyData )
return eGetStatus;
}
CVector<uint8_t> CChannel::PrepSendPacket ( const CVector<uint8_t>& vecbyNPacket )
void CChannel::PrepAndSendPacket ( CSocket* pSocket,
const CVector<uint8_t>& vecbyNPacket )
{
QMutexLocker locker ( &Mutex );
@ -629,13 +630,8 @@ CVector<uint8_t> CChannel::PrepSendPacket ( const CVector<uint8_t>& vecbyNPacket
// block size
if ( ConvBuf.Put ( vecbyNPacket ) )
{
// a packet is ready
return ConvBuf.Get();
pSocket->SendPacket ( ConvBuf.Get(), GetAddress() );
}
// if the block is not ready we have to initialize with zero length to
// tell the following network send routine that nothing should be sent
return CVector<uint8_t> ( 0 );
}
int CChannel::GetUploadRateKbps()

View File

@ -33,6 +33,7 @@
#include "buffer.h"
#include "util.h"
#include "protocol.h"
#include "socket.h"
/* Definitions ****************************************************************/
@ -66,7 +67,8 @@ public:
int iNumBytes );
EGetDataStat GetData ( CVector<uint8_t>& vecbyData );
CVector<uint8_t> PrepSendPacket ( const CVector<uint8_t>& vecbyNPacket );
void PrepAndSendPacket ( CSocket* pSocket,
const CVector<uint8_t>& vecbyNPacket );
void ResetTimeOutCounter() { iConTimeOut = iConTimeOutStartVal; }
bool IsConnected() const { return iConTimeOut > 0; }
@ -77,7 +79,7 @@ public:
void SetAddress ( const CHostAddress NAddr ) { InetAddr = NAddr; }
bool GetAddress ( CHostAddress& RetAddr );
CHostAddress GetAddress() const { return InetAddr; }
CHostAddress& GetAddress() { return InetAddr; }
void ResetInfo() { ChannelInfo = CChannelCoreInfo(); } // reset does not emit a message
void SetName ( const QString sNNa );

View File

@ -1092,8 +1092,7 @@ void CClient::ProcessAudioDataIntern ( CVector<int16_t>& vecsStereoSndCrd )
}
// send coded audio through the network
Socket.SendPacket ( Channel.PrepSendPacket ( vecCeltData ),
Channel.GetAddress() );
Channel.PrepAndSendPacket ( &Socket, vecCeltData );
}

View File

@ -898,9 +898,7 @@ opus_custom_encoder_ctl ( OpusEncoderStereo[iCurChanID],
}
// send separate mix to current clients
Socket.SendPacket (
vecChannels[iCurChanID].PrepSendPacket ( vecCeltData ),
vecChannels[iCurChanID].GetAddress() );
vecChannels[iCurChanID].PrepAndSendPacket ( &Socket, vecCeltData );
// update socket buffer size
vecChannels[iCurChanID].UpdateSocketBufferSize();

View File

@ -33,14 +33,14 @@
#include <QMutex>
#include <vector>
#include "global.h"
#include "channel.h"
#include "protocol.h"
#include "util.h"
// The header file server.h requires to include this header file so we get a
// cyclic dependency. To solve this issue, a prototype of the server class is
// defined here.
class CServer; // forward declaration of CServer
// The header files channel.h and server.h require to include this header file
// so we get a cyclic dependency. To solve this issue, a prototype of the
// channel class and server class is defined here.
class CServer; // forward declaration of CServer
class CChannel; // forward declaration of CChannel
/* Definitions ****************************************************************/