Skip to content
Draft
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
3 changes: 2 additions & 1 deletion src/channel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,7 @@ void CChannel::OnNetTranspPropsReceived ( CNetworkTransportProps NetworkTranspor
iNetwFrameSizeFact = NetworkTransportProps.iBlockSizeFact;
iNetwFrameSize = static_cast<int> ( NetworkTransportProps.iBaseNetworkPacketSize );
bUseSequenceNumber = ( NetworkTransportProps.eFlags == NF_WITH_COUNTER );
iAudioCodingArg = NetworkTransportProps.iAudioCodingArg;

if ( bUseSequenceNumber )
{
Expand Down Expand Up @@ -522,7 +523,7 @@ CNetworkTransportProps CChannel::GetNetworkTransportPropsFromCurrentSettings()
SYSTEM_SAMPLE_RATE_HZ,
eAudioCompressionType,
eFlags,
0 );
iAudioCodingArg );
}

void CChannel::Disconnect()
Expand Down
3 changes: 3 additions & 0 deletions src/channel.h
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,8 @@ class CChannel : public QObject

EAudComprType GetAudioCompressionType() { return eAudioCompressionType; }
int GetNumAudioChannels() const { return iNumAudioChannels; }
int GetAudioCodingArg() const { return iAudioCodingArg; }
void SetAudioCodingArg ( int iNAudioCodingArg ) { iAudioCodingArg = iNAudioCodingArg; }

// network protocol interface
void CreateJitBufMes ( const int iJitBufSize )
Expand Down Expand Up @@ -245,6 +247,7 @@ class CChannel : public QObject
int iNetwFrameSize;
int iCeltNumCodedBytes;
int iAudioFrameSizeSamples;
int iAudioCodingArg;

EAudComprType eAudioCompressionType;
int iNumAudioChannels;
Expand Down
2 changes: 2 additions & 0 deletions src/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1441,6 +1441,8 @@ void CClient::Init()
}
}

Channel.SetAudioCodingArg ( eAudioQuality );

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes the server aware of the audio quality set in the client. Before that we had to guess by the packet sizes.


// calculate stereo (two channels) buffer size
iStereoBlockSizeSam = 2 * iMonoBlockSizeSam;

Expand Down
15 changes: 13 additions & 2 deletions src/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ CServer::CServer ( const int iNewMaxNumChan,
vecNumFrameSizeConvBlocks.Init ( iMaxNumChannels );
vecUseDoubleSysFraSizeConvBuf.Init ( iMaxNumChannels );
vecAudioComprType.Init ( iMaxNumChannels );
vecAudioCodingArg.Init ( iMaxNumChannels );

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

// get info about required frame size conversion properties
vecUseDoubleSysFraSizeConvBuf[iChanCnt] = ( !bUseDoubleSystemFrameSize && ( vecAudioComprType[iChanCnt] == CT_OPUS ) );
Expand Down Expand Up @@ -964,6 +966,7 @@ void CServer::DecodeReceiveData ( const int iChanCnt, const int iNumClients )
pCurCodedData = nullptr;
}

//### DEPRECATED: BEGIN ###//
// Recognise a raw audio packet by its size:
// The client doesn't pass a value for the selected audio quality implicitly.
// Rather the server is passed the length of the data sent by the client in iClientFrameSizeSamples.
Expand All @@ -973,8 +976,12 @@ void CServer::DecodeReceiveData ( const int iChanCnt, const int iNumClients )
// iNumAudioChannels is either 1 for mono or 2 for stereo and mono-in/stereo-out
// sizeof ( int16_t ) is the size in bytes for the raw pcm audio data = 2
// Sizes other than that are considered OPUS coded because those depend on hardcoded sizes in client.h
//### DEPRECATED: END ###//
// The client sent its audio quality setting. Check if raw audio was set
// for backwards compatibility the size check is left in, see above
const bool bIsRawAudio =
( iCeltNumCodedBytes == static_cast<int> ( sizeof ( int16_t ) * iClientFrameSizeSamples * vecNumAudioChannels[iChanCnt] ) );
( vecAudioCodingArg[iChanCnt] == AQ_RAW ||
iCeltNumCodedBytes == static_cast<int> ( sizeof ( int16_t ) * iClientFrameSizeSamples * vecNumAudioChannels[iChanCnt] ) );

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left this in for backwards compatibility. We could deprecate this with a TODO: to be removed, same for the transmitting side.


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

Expand Down Expand Up @@ -1249,6 +1256,9 @@ void CServer::MixEncodeTransmitData ( const int iChanCnt, const int iNumClients
}
}

// Check if the client wants raw audio rather than guessing by packet sizes
const bool bWantsRawAudio = vecAudioCodingArg[iChanCnt] == AQ_RAW;

// If the server frame size is smaller than the received OPUS frame size, we need a conversion
// buffer which stores the large buffer.
// Note that we have a shortcut here. If the conversion buffer is not needed, the boolean flag
Expand All @@ -1263,7 +1273,8 @@ void CServer::MixEncodeTransmitData ( const int iChanCnt, const int iNumClients
DoubleFrameSizeConvBufOut[iCurChanID].GetAll ( vecsSendData, DOUBLE_SYSTEM_FRAME_SIZE_SAMPLES * vecNumAudioChannels[iChanCnt] );
}

if ( iCeltNumCodedBytes != static_cast<int> ( sizeof ( int16_t ) * iClientFrameSizeSamples * vecNumAudioChannels[iChanCnt] ) )
if ( !bWantsRawAudio &&
iCeltNumCodedBytes != static_cast<int> ( sizeof ( int16_t ) * iClientFrameSizeSamples * vecNumAudioChannels[iChanCnt] ) )
{
// OPUS encoding
if ( CurOpusEncoder != nullptr )
Expand Down
1 change: 1 addition & 0 deletions src/server.h
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,7 @@ class CServer : public QObject, public CServerSlots<MAX_NUM_CHANNELS>
CVector<int> vecNumFrameSizeConvBlocks;
CVector<int> vecUseDoubleSysFraSizeConvBuf;
CVector<EAudComprType> vecAudioComprType;
CVector<int> vecAudioCodingArg;
CVector<CVector<int16_t>> vecvecsSendData;
CVector<CVector<float>> vecvecfIntermediateProcBuf;
CVector<CVector<uint8_t>> vecvecbyCodedData;
Expand Down
Loading