avoid allocating memory in time critical client thread -> improve socket send function in the channel
This commit is contained in:
parent
91b4823d37
commit
f016e9e022
6 changed files with 15 additions and 20 deletions
|
@ -469,7 +469,7 @@ public:
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
CVector<TData> Get()
|
CVector<TData>& Get()
|
||||||
{
|
{
|
||||||
iPutPos = 0;
|
iPutPos = 0;
|
||||||
return vecsMemory;
|
return vecsMemory;
|
||||||
|
|
|
@ -621,7 +621,8 @@ EGetDataStat CChannel::GetData ( CVector<uint8_t>& vecbyData )
|
||||||
return eGetStatus;
|
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 );
|
QMutexLocker locker ( &Mutex );
|
||||||
|
|
||||||
|
@ -629,13 +630,8 @@ CVector<uint8_t> CChannel::PrepSendPacket ( const CVector<uint8_t>& vecbyNPacket
|
||||||
// block size
|
// block size
|
||||||
if ( ConvBuf.Put ( vecbyNPacket ) )
|
if ( ConvBuf.Put ( vecbyNPacket ) )
|
||||||
{
|
{
|
||||||
// a packet is ready
|
pSocket->SendPacket ( ConvBuf.Get(), GetAddress() );
|
||||||
return ConvBuf.Get();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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()
|
int CChannel::GetUploadRateKbps()
|
||||||
|
|
|
@ -33,6 +33,7 @@
|
||||||
#include "buffer.h"
|
#include "buffer.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
#include "protocol.h"
|
#include "protocol.h"
|
||||||
|
#include "socket.h"
|
||||||
|
|
||||||
|
|
||||||
/* Definitions ****************************************************************/
|
/* Definitions ****************************************************************/
|
||||||
|
@ -66,7 +67,8 @@ public:
|
||||||
int iNumBytes );
|
int iNumBytes );
|
||||||
EGetDataStat GetData ( CVector<uint8_t>& vecbyData );
|
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; }
|
void ResetTimeOutCounter() { iConTimeOut = iConTimeOutStartVal; }
|
||||||
bool IsConnected() const { return iConTimeOut > 0; }
|
bool IsConnected() const { return iConTimeOut > 0; }
|
||||||
|
@ -77,7 +79,7 @@ public:
|
||||||
|
|
||||||
void SetAddress ( const CHostAddress NAddr ) { InetAddr = NAddr; }
|
void SetAddress ( const CHostAddress NAddr ) { InetAddr = NAddr; }
|
||||||
bool GetAddress ( CHostAddress& RetAddr );
|
bool GetAddress ( CHostAddress& RetAddr );
|
||||||
CHostAddress GetAddress() const { return InetAddr; }
|
CHostAddress& GetAddress() { return InetAddr; }
|
||||||
|
|
||||||
void ResetInfo() { ChannelInfo = CChannelCoreInfo(); } // reset does not emit a message
|
void ResetInfo() { ChannelInfo = CChannelCoreInfo(); } // reset does not emit a message
|
||||||
void SetName ( const QString sNNa );
|
void SetName ( const QString sNNa );
|
||||||
|
|
|
@ -1092,8 +1092,7 @@ void CClient::ProcessAudioDataIntern ( CVector<int16_t>& vecsStereoSndCrd )
|
||||||
}
|
}
|
||||||
|
|
||||||
// send coded audio through the network
|
// send coded audio through the network
|
||||||
Socket.SendPacket ( Channel.PrepSendPacket ( vecCeltData ),
|
Channel.PrepAndSendPacket ( &Socket, vecCeltData );
|
||||||
Channel.GetAddress() );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -898,9 +898,7 @@ opus_custom_encoder_ctl ( OpusEncoderStereo[iCurChanID],
|
||||||
}
|
}
|
||||||
|
|
||||||
// send separate mix to current clients
|
// send separate mix to current clients
|
||||||
Socket.SendPacket (
|
vecChannels[iCurChanID].PrepAndSendPacket ( &Socket, vecCeltData );
|
||||||
vecChannels[iCurChanID].PrepSendPacket ( vecCeltData ),
|
|
||||||
vecChannels[iCurChanID].GetAddress() );
|
|
||||||
|
|
||||||
// update socket buffer size
|
// update socket buffer size
|
||||||
vecChannels[iCurChanID].UpdateSocketBufferSize();
|
vecChannels[iCurChanID].UpdateSocketBufferSize();
|
||||||
|
|
10
src/socket.h
10
src/socket.h
|
@ -33,14 +33,14 @@
|
||||||
#include <QMutex>
|
#include <QMutex>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include "global.h"
|
#include "global.h"
|
||||||
#include "channel.h"
|
|
||||||
#include "protocol.h"
|
#include "protocol.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
|
||||||
// The header file server.h requires to include this header file so we get a
|
// The header files channel.h and server.h require to include this header file
|
||||||
// cyclic dependency. To solve this issue, a prototype of the server class is
|
// so we get a cyclic dependency. To solve this issue, a prototype of the
|
||||||
// defined here.
|
// channel class and server class is defined here.
|
||||||
class CServer; // forward declaration of CServer
|
class CServer; // forward declaration of CServer
|
||||||
|
class CChannel; // forward declaration of CChannel
|
||||||
|
|
||||||
|
|
||||||
/* Definitions ****************************************************************/
|
/* Definitions ****************************************************************/
|
||||||
|
|
Loading…
Reference in a new issue