Skip to content

Commit 42e466b

Browse files
committed
fix jitter calculation. better packet loss calculation
1 parent 48fc6c7 commit 42e466b

File tree

1 file changed

+20
-8
lines changed

1 file changed

+20
-8
lines changed

reliable.c

+20-8
Original file line numberDiff line numberDiff line change
@@ -1393,6 +1393,7 @@ void reliable_endpoint_update( struct reliable_endpoint_t * endpoint, double tim
13931393
if ( endpoint->rtt_history_buffer[i] >= 0.0f )
13941394
{
13951395
sum += endpoint->rtt_history_buffer[i];
1396+
count++;
13961397
}
13971398
}
13981399
if ( count > 0 )
@@ -1409,26 +1410,37 @@ void reliable_endpoint_update( struct reliable_endpoint_t * endpoint, double tim
14091410
{
14101411
uint32_t base_sequence = ( endpoint->sent_packets->sequence - endpoint->config.sent_packets_buffer_size + 1 ) + 0xFFFF;
14111412
int i;
1413+
int num_sent = 0;
14121414
int num_dropped = 0;
14131415
int num_samples = endpoint->config.sent_packets_buffer_size / 2;
14141416
for ( i = 0; i < num_samples; ++i )
14151417
{
14161418
uint16_t sequence = (uint16_t) ( base_sequence + i );
1417-
struct reliable_sent_packet_data_t * sent_packet_data = (struct reliable_sent_packet_data_t*)
1418-
reliable_sequence_buffer_find( endpoint->sent_packets, sequence );
1419-
if ( sent_packet_data && !sent_packet_data->acked )
1419+
struct reliable_sent_packet_data_t * sent_packet_data = (struct reliable_sent_packet_data_t*) reliable_sequence_buffer_find( endpoint->sent_packets, sequence );
1420+
if ( sent_packet_data )
14201421
{
1421-
num_dropped++;
1422+
num_sent++;
1423+
if ( !sent_packet_data->acked )
1424+
{
1425+
num_dropped++;
1426+
}
14221427
}
14231428
}
1424-
float packet_loss = ( (float) num_dropped ) / ( (float) num_samples ) * 100.0f;
1425-
if ( fabs( endpoint->packet_loss - packet_loss ) > 0.00001 )
1429+
if ( num_sent > 0 )
14261430
{
1427-
endpoint->packet_loss += ( packet_loss - endpoint->packet_loss ) * endpoint->config.packet_loss_smoothing_factor;
1431+
float packet_loss = ( (float) num_dropped ) / ( (float) num_sent ) * 100.0f;
1432+
if ( fabs( endpoint->packet_loss - packet_loss ) > 0.00001 )
1433+
{
1434+
endpoint->packet_loss += ( packet_loss - endpoint->packet_loss ) * endpoint->config.packet_loss_smoothing_factor;
1435+
}
1436+
else
1437+
{
1438+
endpoint->packet_loss = packet_loss;
1439+
}
14281440
}
14291441
else
14301442
{
1431-
endpoint->packet_loss = packet_loss;
1443+
endpoint->packet_loss = 0.0f;
14321444
}
14331445
}
14341446

0 commit comments

Comments
 (0)