Newer
Older
// No need to update the download loss as we have a more accurate value
// in the global reception stats, which are updated for each new packet
// received.

Boris Grozev
committed
}
/**
* Computes and updates information for a specific stream.

Boris Grozev
committed
*/

Boris Grozev
committed
{
// Gets the current time.
long currentTimeMs = System.currentTimeMillis();
// UPdates stats for the download stream.
updateStreamDirectionStats(StreamDirection.DOWNLOAD, currentTimeMs);
// UPdates stats for the upload stream.
updateStreamDirectionStats(StreamDirection.UPLOAD, currentTimeMs);
// Saves the last update values.
updateTimeMs = currentTimeMs;

Boris Grozev
committed
}
/**
* Computes and updates information for a specific stream.

Boris Grozev
committed
*
* @param streamDirection The stream direction (DOWNLOAD or UPLOAD) of the
* stream from which this function updates the stats.
* @param currentTimeMs The current time in ms.

Boris Grozev
committed
*/
private void updateStreamDirectionStats(
StreamDirection streamDirection,
long currentTimeMs)

Boris Grozev
committed
{
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
int streamDirectionIndex = streamDirection.ordinal();
// Gets the current number of packets correctly received since the
// beginning of this stream.
long newNbRecv = getNbPDU(streamDirection);
// Gets the number of byte received/sent since the beginning of this
// stream.
long newNbByte = getNbBytes(streamDirection);
// Computes the number of update steps which has not been done since
// last update.
long nbSteps = newNbRecv - nbPackets[streamDirectionIndex];
// Even if the remote peer does not send any packets (i.e. is
// microphone is muted), Jitsi must updates it stats. Thus, Jitsi
// computes a number of steps equivalent as if Jitsi receives a packet
// each 20ms (default value).
if(nbSteps == 0)
nbSteps = (currentTimeMs - updateTimeMs) / 20;
// The upload percentLoss is only computed when a new RTCP feedback is
// received. This is not the case for the download percentLoss which is
// updated for each new RTP packet received.
// Computes the loss rate for this stream.
if(streamDirection == StreamDirection.DOWNLOAD)

Boris Grozev
committed
{
// Gets the current number of losses in download since the beginning
// of this stream.
long newNbLost
= getDownloadNbPDULost() - nbLost[streamDirectionIndex];
updateNbLoss(streamDirection, newNbLost, nbSteps + newNbLost);
long newNbDiscarded = getNbDiscarded() - nbDiscarded;
updateNbDiscarded(newNbDiscarded, nbSteps + newNbDiscarded);

Boris Grozev
committed
}
// Computes the bandwidth used by this stream.
double newRateKiloBitPerSec
= MediaStreamStatsImpl.computeRateKiloBitPerSec(
newNbByte - nbByte[streamDirectionIndex],
currentTimeMs - updateTimeMs);
rateKiloBitPerSec[streamDirectionIndex]
= MediaStreamStatsImpl.computeEWMA(
nbSteps,
rateKiloBitPerSec[streamDirectionIndex],
newRateKiloBitPerSec);
// Saves the last update values.
nbPackets[streamDirectionIndex] = newNbRecv;
nbByte[streamDirectionIndex] = newNbByte;
updateNbFec();

Boris Grozev
committed
}