diff --git a/src/client.cpp b/src/client.cpp index 99f74caf10..15284e23fa 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -119,6 +119,7 @@ CClient::CClient ( const quint16 iPortNumber, QObject::connect ( &Channel, &CChannel::ReqChanInfo, this, &CClient::OnReqChanInfo ); QObject::connect ( &Channel, &CChannel::ConClientListMesReceived, this, &CClient::ConClientListMesReceived ); + QObject::connect ( &Channel, &CChannel::ConClientListMesReceived, this, &CClient::OnConClientListMesReceived ); QObject::connect ( &Channel, &CChannel::Disconnected, this, &CClient::Disconnected ); @@ -261,6 +262,15 @@ void CClient::OnJittBufSizeChanged ( int iNewJitBufSize ) void CClient::OnNewConnection() { + // The oldGain and newGain arrays are used to avoid sending duplicate gain change messages. + // As these values depend on the channel IDs of a specific server, we have + // to reset those upon connect. + // We reset to 1 because this is what the server part sets by default. + for ( int iId = 0; iId < MAX_NUM_CHANNELS; iId++ ) + { + oldGain[iId] = newGain[iId] = 1; + } + // a new connection was successfully initiated, send infos and request // connected clients list Channel.SetRemoteInfo ( ChannelInfo ); @@ -280,6 +290,33 @@ void CClient::OnNewConnection() //### TODO: END ###// } +void CClient::OnConClientListMesReceived ( CVector vecChanInfo ) +{ + // Upon receiving a new client list, we have to reset oldGain and newGain + // entries for unused channels. This ensures that a disconnected channel + // does not leave behind wrong cached gain values which would leak into + // any new channel which reused this channel id. + int iNumConnectedClients = vecChanInfo.Size(); + + // Save what channel IDs are in use: + bool bChanIdInUse[MAX_NUM_CHANNELS] = {}; + for ( int i = 0; i < iNumConnectedClients; i++ ) + { + bChanIdInUse[vecChanInfo[i].iChanID] = true; + } + + // Reset all gains for unused channel IDs: + for ( int iId = 0; iId < MAX_NUM_CHANNELS; iId++ ) + { + if ( !bChanIdInUse[iId] ) + { + // reset oldGain and newGain as this channel id is currently unused and will + // start with a server-side gain at 1 (100%) again. + oldGain[iId] = newGain[iId] = 1; + } + } +} + void CClient::CreateServerJitterBufferMessage() { // per definition in the client: if auto jitter buffer is enabled, both, diff --git a/src/client.h b/src/client.h index 1a5d590c75..f7553446a5 100644 --- a/src/client.h +++ b/src/client.h @@ -403,6 +403,7 @@ protected slots: void OnControllerInFaderIsMute ( int iChannelIdx, bool bIsMute ); void OnControllerInMuteMyself ( bool bMute ); void OnClientIDReceived ( int iChanID ); + void OnConClientListMesReceived ( CVector vecChanInfo ); signals: void ConClientListMesReceived ( CVector vecChanInfo );