diff --git a/src/server.cpp b/src/server.cpp index d24e5a142d..bf9f4f8290 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -894,6 +894,10 @@ void CServer::DecodeReceiveData ( const int iChanCnt, const int iNumClients ) else { CurOpusDecoder = nullptr; + + // no codec yet (e.g. a new client in a reused channel): nothing writes this buffer, and it + // still holds the audio last decoded at this position in the connected-channel list + vecvecsData[iChanCnt].Reset ( 0 ); } // get gains and pannings of all connected channels, compacted to the @@ -940,6 +944,13 @@ void CServer::DecodeReceiveData ( const int iChanCnt, const int iNumClients ) { emit ClientDisconnected ( iCurChanID ); // TODO do this outside the mutex lock? + // the decoders belong to the channel, not the client, so drop this client's state + // before the next client in this channel is decoded + opus_custom_decoder_ctl ( OpusDecoderMono[iCurChanID], OPUS_RESET_STATE ); + opus_custom_decoder_ctl ( OpusDecoderStereo[iCurChanID], OPUS_RESET_STATE ); + opus_custom_decoder_ctl ( Opus64DecoderMono[iCurChanID], OPUS_RESET_STATE ); + opus_custom_decoder_ctl ( Opus64DecoderStereo[iCurChanID], OPUS_RESET_STATE ); + FreeChannel ( iCurChanID ); // note that the channel is now not in use // note that no mutex is needed for this shared resource since it is a