Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions src/buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,12 +146,14 @@ bool CNetBuf::Put ( const CVector<uint8_t>& vecbyData, int iInSize )
const int iNumBlocks = /* floor */ ( iInSize / iBlockSize );

// copy new data in internal buffer
// iBlock is a long to avoid overflowing a mulitplication later in the code
for ( long iBlock = 0; iBlock < iNumBlocks; iBlock++ )
for ( int iBlock = 0; iBlock < iNumBlocks; iBlock++ )
{
// calculate the block offset once per loop instead of repeated multiplying
const int iBlockOffset = iBlock * ( iBlockSize + iNumBytesSeqNum );

// extract sequence number of current received block (per definition
// the sequence number is appended after the coded audio data)
const int iCurrentSequenceNumber = vecbyData[iBlock * ( iBlockSize + iNumBytesSeqNum ) + iBlockSize];
const int iCurrentSequenceNumber = vecbyData[iBlockOffset + iBlockSize];

// calculate the sequence number difference and take care of wrap
int iSeqNumDiff = iCurrentSequenceNumber - static_cast<int> ( iSequenceNumberAtGetPos );
Expand Down Expand Up @@ -243,9 +245,7 @@ bool CNetBuf::Put ( const CVector<uint8_t>& vecbyData, int iInSize )
if ( !bIsSimulation )
{
// copy one block of data in buffer
std::copy ( vecbyData.begin() + iBlock * ( iBlockSize + iNumBytesSeqNum ),
vecbyData.begin() + iBlock * ( iBlockSize + iNumBytesSeqNum ) + iBlockSize,
vecvecMemory[iBlockPutPos].begin() );
std::copy ( vecbyData.begin() + iBlockOffset, vecbyData.begin() + iBlockOffset + iBlockSize, vecvecMemory[iBlockPutPos].begin() );
}

// valid packet added, set flag
Expand All @@ -264,16 +264,16 @@ bool CNetBuf::Put ( const CVector<uint8_t>& vecbyData, int iInSize )
// copy new data in internal buffer
const int iNumBlocks = iInSize / iBlockSize;

// iBlock is a long to avoid overflowing a mulitplication later in the code
for ( long iBlock = 0; iBlock < iNumBlocks; iBlock++ )
for ( int iBlock = 0; iBlock < iNumBlocks; iBlock++ )
{
// for simultion buffer only update pointer, no data copying
if ( !bIsSimulation )
{
// calculate the block offset once per loop instead of repeated multiplying
const int iBlockOffset = iBlock * iBlockSize;

// copy one block of data in buffer
std::copy ( vecbyData.begin() + iBlock * iBlockSize,
vecbyData.begin() + iBlock * iBlockSize + iBlockSize,
vecvecMemory[iBlockPutPos].begin() );
std::copy ( vecbyData.begin() + iBlockOffset, vecbyData.begin() + iBlockOffset + iBlockSize, vecvecMemory[iBlockPutPos].begin() );
}

// set the put position one block further
Expand Down
12 changes: 8 additions & 4 deletions src/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1041,7 +1041,7 @@ void CServer::DecodeReceiveData ( const int iChanCnt, const int iNumClients )
// get current number of OPUS coded bytes
const int iCeltNumCodedBytes = vecChannels[iCurChanID].GetCeltNumCodedBytes();

for ( size_t iB = 0; iB < (size_t) vecNumFrameSizeConvBlocks[iChanCnt]; iB++ )
for ( int iB = 0; iB < vecNumFrameSizeConvBlocks[iChanCnt]; iB++ )
{
// get data
const EGetDataStat eGetStat = vecChannels[iCurChanID].GetData ( vecvecbyCodedData[iChanCnt], iCeltNumCodedBytes );
Expand Down Expand Up @@ -1081,10 +1081,12 @@ void CServer::DecodeReceiveData ( const int iChanCnt, const int iNumClients )
// OPUS decode received data stream
if ( CurOpusDecoder != nullptr )
{
const int iOffset = iB * SYSTEM_FRAME_SIZE_SAMPLES * vecNumAudioChannels[iChanCnt];

iUnused = opus_custom_decode ( CurOpusDecoder,
pCurCodedData,
iCeltNumCodedBytes,
&vecvecsData[iChanCnt][iB * SYSTEM_FRAME_SIZE_SAMPLES * vecNumAudioChannels[iChanCnt]],
&vecvecsData[iChanCnt][iOffset],
iClientFrameSizeSamples );
}
}
Expand Down Expand Up @@ -1354,10 +1356,12 @@ void CServer::MixEncodeTransmitData ( const int iChanCnt, const int iNumClients
opus_custom_encoder_ctl ( pCurOpusEncoder, OPUS_SET_BITRATE ( CalcBitRateBitsPerSecFromCodedBytes ( iCeltNumCodedBytes, iClientFrameSizeSamples ) ) );
// clang-format on

for ( size_t iB = 0; iB < (size_t) vecNumFrameSizeConvBlocks[iChanCnt]; iB++ )
for ( int iB = 0; iB < vecNumFrameSizeConvBlocks[iChanCnt]; iB++ )
Comment thread
ann0see marked this conversation as resolved.
{
const int iOffset = iB * SYSTEM_FRAME_SIZE_SAMPLES * vecNumAudioChannels[iChanCnt];

iUnused = opus_custom_encode ( pCurOpusEncoder,
&vecsSendData[iB * SYSTEM_FRAME_SIZE_SAMPLES * vecNumAudioChannels[iChanCnt]],
&vecsSendData[iOffset],
iClientFrameSizeSamples,
&vecvecbyCodedData[iChanCnt][0],
iCeltNumCodedBytes );
Expand Down