@@ -262,15 +262,6 @@ void CClient::OnJittBufSizeChanged ( int iNewJitBufSize )
262262
263263void CClient::OnNewConnection ()
264264{
265- // The oldGain and newGain arrays are used to avoid sending duplicate gain change messages.
266- // As these values depend on the channel IDs of a specific server, we have
267- // to reset those upon connect.
268- // We reset to 1 because this is what the server part sets by default.
269- for ( int iId = 0 ; iId < MAX_NUM_CHANNELS; iId++ )
270- {
271- oldGain[iId] = newGain[iId] = 1 ;
272- }
273-
274265 // a new connection was successfully initiated, send infos and request
275266 // connected clients list
276267 Channel.SetRemoteInfo ( ChannelInfo );
@@ -313,11 +304,6 @@ void CClient::OnConClientListMesReceived ( CVector<CChannelInfo> vecChanInfo )
313304 // translate from server channel IDs to client channel IDs
314305 // ALSO here is where we allocate and free client channels as required
315306
316- // Upon receiving a new client list, we have to reset oldGain and newGain
317- // entries for unused channels. This ensures that a disconnected channel
318- // does not leave behind wrong cached gain values which would leak into
319- // any new channel which reused this channel id.
320-
321307 const int iNumConnectedClients = vecChanInfo.Size ();
322308 int i, iSrvIdx;
323309
@@ -345,10 +331,6 @@ void CClient::OnConClientListMesReceived ( CVector<CChannelInfo> vecChanInfo )
345331
346332 if ( iId != INVALID_INDEX )
347333 {
348- // reset oldGain and newGain as this channel id is currently unused and will
349- // start with a server-side gain at 1 (100%) again.
350- oldGain[iId] = newGain[iId] = 1 ;
351-
352334 // iSrvIdx contains a server channel number that has now gone
353335 FreeClientChannel ( iSrvIdx );
354336 }
@@ -370,10 +352,6 @@ void CClient::OnConClientListMesReceived ( CVector<CChannelInfo> vecChanInfo )
370352
371353 if ( iId != INVALID_INDEX )
372354 {
373- // reset oldGain and newGain as this channel id is currently unused and will
374- // start with a server-side gain at 1 (100%) again.
375- oldGain[iId] = newGain[iId] = 1 ;
376-
377355 // iSrvIdx contains a server channel number that has now gone
378356 FreeClientChannel ( iSrvIdx );
379357 }
@@ -461,19 +439,21 @@ void CClient::SetDoAutoSockBufSize ( const bool bValue )
461439// running), it will be sent immediately, and a 300ms timer started.
462440//
463441// If a gain change message is requested while the timer is still running, the new gain is not sent,
464- // but just stored in newGain [iId], and the minGainId and maxGainId updated to note the range of
465- // IDs that must be checked when the time expires (this will usually be a single channel
442+ // but just stored in clientChannels [iId].newGain , and the minGainId and maxGainId updated to note
443+ // the range of IDs that must be checked when the time expires (this will usually be a single channel
466444// unless channel grouping is being used). This avoids having to check all possible channels.
467445//
468- // When the timer fires, the channels minGainId <= iId < maxGainId are checked by comparing
469- // the last sent value in oldGain [iId] with any pending value in newGain [iId], and if they differ,
470- // the new value is sent, updating oldGain [iId] with the sent value. If any new values are
446+ // When the timer fires, the channels minGainId <= iId < maxGainId are checked by comparing the last sent value
447+ // in clientChannels [iId].oldGain with any pending value in clientChannels [iId].newGain , and if they differ,
448+ // the new value is sent, updating clientChannels [iId].oldGain with the sent value. If any new values are
471449// sent, the timer is restarted so that further immediate updates will be pended.
472450
473451void CClient::SetRemoteChanGain ( const int iId, const float fGain , const bool bIsMyOwnFader )
474452{
475453 QMutexLocker locker ( &MutexGain );
476454
455+ CClientChannel* clientChan = &clientChannels[iId];
456+
477457 // if this gain is for my own channel, apply the value for the Mute Myself function
478458 if ( bIsMyOwnFader )
479459 {
@@ -483,8 +463,8 @@ void CClient::SetRemoteChanGain ( const int iId, const float fGain, const bool b
483463 if ( TimerGain.isActive () )
484464 {
485465 // just update the new value for sending later;
486- // will compare with oldGain[iId] when the timer fires
487- newGain[iId] = fGain ;
466+ // will compare with oldGain when the timer fires
467+ clientChan-> newGain = fGain ;
488468
489469 // update range of channel IDs to check in the timer
490470 if ( iId < minGainId )
@@ -497,8 +477,8 @@ void CClient::SetRemoteChanGain ( const int iId, const float fGain, const bool b
497477
498478 // here the timer was not active:
499479 // send the actual gain and reset the range of channel IDs to empty
500- oldGain[iId] = newGain[iId] = fGain ;
501- Channel.SetRemoteChanGain ( clientChannels[iId]. iServerChannelID , fGain ); // translate client channel to server channel ID
480+ clientChan-> oldGain = clientChan-> newGain = fGain ;
481+ Channel.SetRemoteChanGain ( clientChan-> iServerChannelID , fGain ); // translate client channel to server channel ID
502482
503483 StartDelayTimer ();
504484}
@@ -510,11 +490,13 @@ void CClient::OnTimerRemoteChanGain()
510490
511491 for ( int iId = minGainId; iId < maxGainId; iId++ )
512492 {
513- if ( newGain[iId] != oldGain[iId] )
493+ CClientChannel* clientChan = &clientChannels[iId];
494+
495+ if ( clientChan->newGain != clientChan->oldGain )
514496 {
515497 // send new gain and record as old gain
516- float fGain = oldGain[iId] = newGain[iId] ;
517- Channel.SetRemoteChanGain ( clientChannels[iId]. iServerChannelID , fGain ); // translate client channel to server channel ID
498+ float fGain = clientChan-> oldGain = clientChan-> newGain ;
499+ Channel.SetRemoteChanGain ( clientChan-> iServerChannelID , fGain ); // translate client channel to server channel ID
518500 bSent = true ;
519501 }
520502 }
0 commit comments