@@ -757,7 +757,7 @@ void CServer::DecodeReceiveData ( const int iChanCnt, const int iNumClients )
757757 int iUnused;
758758 int iClientFrameSizeSamples = 0 ; // initialize to avoid a compiler warning
759759 OpusCustomDecoder* CurOpusDecoder;
760- unsigned char * pCurCodedData = nullptr ; // Only used with opus coding, nullptr in case of raw or packet loss
760+ unsigned char * pCurCodedData;
761761
762762 // get actual ID of current channel
763763 const int iCurChanID = vecChanIDsCurConChan[iChanCnt];
@@ -877,7 +877,17 @@ void CServer::DecodeReceiveData ( const int iChanCnt, const int iNumClients )
877877 return ;
878878 }
879879
880- const int iOffset = iB * SYSTEM_FRAME_SIZE_SAMPLES * vecNumAudioChannels[iChanCnt];
880+ // get pointer to coded data
881+ if ( eGetStat == GS_BUFFER_OK )
882+ {
883+ pCurCodedData = &vecvecbyCodedData[iChanCnt][0 ];
884+ }
885+ else
886+ {
887+ // for lost packets use null pointer as coded input data
888+ pCurCodedData = nullptr ;
889+ }
890+
881891 // Recognise a raw audio packet by its size:
882892 // The client doesn't pass a value for the selected audio quality implicitly.
883893 // Rather the server is passed the length of the data sent by the client in iClientFrameSizeSamples.
@@ -890,34 +900,29 @@ void CServer::DecodeReceiveData ( const int iChanCnt, const int iNumClients )
890900 const bool bIsRawAudio =
891901 ( iCeltNumCodedBytes == static_cast <int > ( sizeof ( int16_t ) * iClientFrameSizeSamples * vecNumAudioChannels[iChanCnt] ) );
892902
893- // get pointer to coded data
894- if ( eGetStat == GS_BUFFER_OK )
903+ const int iOffset = iB * SYSTEM_FRAME_SIZE_SAMPLES * vecNumAudioChannels[iChanCnt];
904+
905+ if ( !bIsRawAudio )
895906 {
896- if ( bIsRawAudio )
897- {
898- memcpy ( &vecvecsData[iChanCnt][iOffset], &vecvecbyCodedData[iChanCnt][0 ], iCeltNumCodedBytes );
899- }
900- else
907+ // OPUS decode received data stream
908+ if ( CurOpusDecoder != nullptr )
901909 {
902- pCurCodedData = &vecvecbyCodedData[iChanCnt][0 ];
910+ iUnused = opus_custom_decode ( CurOpusDecoder,
911+ pCurCodedData,
912+ iCeltNumCodedBytes,
913+ &vecvecsData[iChanCnt][iOffset],
914+ iClientFrameSizeSamples );
903915 }
904916 }
905- else
917+ else if ( pCurCodedData != nullptr )
906918 {
907- if ( bIsRawAudio )
908- {
909- memset ( &vecvecsData[iChanCnt][iOffset], 0 , iCeltNumCodedBytes );
910- }
919+ // copy received raw data stream
920+ memcpy ( &vecvecsData[iChanCnt][iOffset], pCurCodedData, iCeltNumCodedBytes );
911921 }
912-
913- // OPUS decode received data stream
914- if ( !bIsRawAudio && CurOpusDecoder != nullptr )
922+ else
915923 {
916- iUnused = opus_custom_decode ( CurOpusDecoder,
917- pCurCodedData,
918- iCeltNumCodedBytes,
919- &vecvecsData[iChanCnt][iOffset],
920- iClientFrameSizeSamples );
924+ // lost packet - fill with silence
925+ memset ( &vecvecsData[iChanCnt][iOffset], 0 , iCeltNumCodedBytes );
921926 }
922927 }
923928
0 commit comments