Skip to content

Commit bdbab52

Browse files
committed
[WIP] Use unused bytes in CNetworkTransportProps for raw audio (backwards compatible)
1 parent be8a775 commit bdbab52

5 files changed

Lines changed: 14 additions & 3 deletions

File tree

src/channel.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,7 @@ void CChannel::OnNetTranspPropsReceived ( CNetworkTransportProps NetworkTranspor
444444
iNetwFrameSizeFact = NetworkTransportProps.iBlockSizeFact;
445445
iNetwFrameSize = static_cast<int> ( NetworkTransportProps.iBaseNetworkPacketSize );
446446
bUseSequenceNumber = ( NetworkTransportProps.eFlags == NF_WITH_COUNTER );
447+
iAudioCodingArg = NetworkTransportProps.iAudioCodingArg;
447448

448449
if ( bUseSequenceNumber )
449450
{
@@ -522,7 +523,7 @@ CNetworkTransportProps CChannel::GetNetworkTransportPropsFromCurrentSettings()
522523
SYSTEM_SAMPLE_RATE_HZ,
523524
eAudioCompressionType,
524525
eFlags,
525-
0 );
526+
iAudioCodingArg );
526527
}
527528

528529
void CChannel::Disconnect()

src/channel.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,8 @@ class CChannel : public QObject
162162

163163
EAudComprType GetAudioCompressionType() { return eAudioCompressionType; }
164164
int GetNumAudioChannels() const { return iNumAudioChannels; }
165+
int GetAudioCodingArg() const { return iAudioCodingArg; }
166+
void SetAudioCodingArg ( int iNAudioCodingArg ) { iAudioCodingArg = iNAudioCodingArg; }
165167

166168
// network protocol interface
167169
void CreateJitBufMes ( const int iJitBufSize )
@@ -245,6 +247,7 @@ class CChannel : public QObject
245247
int iNetwFrameSize;
246248
int iCeltNumCodedBytes;
247249
int iAudioFrameSizeSamples;
250+
int iAudioCodingArg;
248251

249252
EAudComprType eAudioCompressionType;
250253
int iNumAudioChannels;

src/client.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1441,6 +1441,8 @@ void CClient::Init()
14411441
}
14421442
}
14431443

1444+
Channel.SetAudioCodingArg( eAudioQuality );
1445+
14441446
// calculate stereo (two channels) buffer size
14451447
iStereoBlockSizeSam = 2 * iMonoBlockSizeSam;
14461448

src/server.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ CServer::CServer ( const int iNewMaxNumChan,
183183
vecNumFrameSizeConvBlocks.Init ( iMaxNumChannels );
184184
vecUseDoubleSysFraSizeConvBuf.Init ( iMaxNumChannels );
185185
vecAudioComprType.Init ( iMaxNumChannels );
186+
vecAudioCodingArg.Init ( iMaxNumChannels );
186187

187188
for ( i = 0; i < iMaxNumChannels; i++ )
188189
{
@@ -844,6 +845,7 @@ void CServer::DecodeReceiveData ( const int iChanCnt, const int iNumClients )
844845
// get and store number of audio channels and compression type
845846
vecNumAudioChannels[iChanCnt] = vecChannels[iCurChanID].GetNumAudioChannels();
846847
vecAudioComprType[iChanCnt] = vecChannels[iCurChanID].GetAudioCompressionType();
848+
vecAudioCodingArg[iChanCnt] = vecChannels[iCurChanID].GetAudioCodingArg();
847849

848850
// get info about required frame size conversion properties
849851
vecUseDoubleSysFraSizeConvBuf[iChanCnt] = ( !bUseDoubleSystemFrameSize && ( vecAudioComprType[iChanCnt] == CT_OPUS ) );
@@ -974,7 +976,8 @@ void CServer::DecodeReceiveData ( const int iChanCnt, const int iNumClients )
974976
// sizeof ( int16_t ) is the size in bytes for the raw pcm audio data = 2
975977
// Sizes other than that are considered OPUS coded because those depend on hardcoded sizes in client.h
976978
const bool bIsRawAudio =
977-
( iCeltNumCodedBytes == static_cast<int> ( sizeof ( int16_t ) * iClientFrameSizeSamples * vecNumAudioChannels[iChanCnt] ) );
979+
( vecAudioCodingArg[iChanCnt] == AQ_RAW ||
980+
iCeltNumCodedBytes == static_cast<int> ( sizeof ( int16_t ) * iClientFrameSizeSamples * vecNumAudioChannels[iChanCnt] ) );
978981

979982
const int iOffset = iB * SYSTEM_FRAME_SIZE_SAMPLES * vecNumAudioChannels[iChanCnt];
980983

@@ -1263,7 +1266,8 @@ void CServer::MixEncodeTransmitData ( const int iChanCnt, const int iNumClients
12631266
DoubleFrameSizeConvBufOut[iCurChanID].GetAll ( vecsSendData, DOUBLE_SYSTEM_FRAME_SIZE_SAMPLES * vecNumAudioChannels[iChanCnt] );
12641267
}
12651268

1266-
if ( iCeltNumCodedBytes != static_cast<int> ( sizeof ( int16_t ) * iClientFrameSizeSamples * vecNumAudioChannels[iChanCnt] ) )
1269+
if ( vecAudioCodingArg[iChanCnt] != AQ_RAW &&
1270+
iCeltNumCodedBytes != static_cast<int> ( sizeof ( int16_t ) * iClientFrameSizeSamples * vecNumAudioChannels[iChanCnt] ) )
12671271
{
12681272
// OPUS encoding
12691273
if ( CurOpusEncoder != nullptr )

src/server.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,7 @@ class CServer : public QObject, public CServerSlots<MAX_NUM_CHANNELS>
285285
CVector<int> vecNumFrameSizeConvBlocks;
286286
CVector<int> vecUseDoubleSysFraSizeConvBuf;
287287
CVector<EAudComprType> vecAudioComprType;
288+
CVector<int> vecAudioCodingArg;
288289
CVector<CVector<int16_t>> vecvecsSendData;
289290
CVector<CVector<float>> vecvecfIntermediateProcBuf;
290291
CVector<CVector<uint8_t>> vecvecbyCodedData;

0 commit comments

Comments
 (0)