]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
res_rtp_asterisk: Don't count 0 as a minimum lost packets
authorKevin Harwell <kharwell@sangoma.com>
Mon, 29 Mar 2021 22:40:49 +0000 (17:40 -0500)
committerKevin Harwell <kharwell@digium.com>
Wed, 31 Mar 2021 20:08:38 +0000 (15:08 -0500)
The calculated minimum lost packets represents the lowest number of
lost packets missed during an RTCP report interval. Zero of course
is the lowest, but the idea is that this value contain the lowest
number of lost packets once some have been missed.

This patch checks to make sure the number of lost packets over an
interval is not zero before checking and setting the minimum value.

Also, this patch updates the rtp lost packet test to check for
packet loss over several reports vs one.

Change-Id: I07d6e21cec61e289c2326138d6bcbcb3c3d5e008

res/res_rtp_asterisk.c
tests/test_res_rtp.c

index 16c3be01acb9401bacac6dbcb846fc9275d45134..4fd803bc335a510d7aa44aa00938a9e24688cd7d 100644 (file)
@@ -4472,7 +4472,7 @@ static void calculate_lost_packet_statistics(struct ast_rtp *rtp,
        if (rtp->rtcp->rxlost_count == 0) {
                rtp->rtcp->minrxlost = rtp->rtcp->rxlost;
        }
-       if (lost_interval < rtp->rtcp->minrxlost) {
+       if (lost_interval && lost_interval < rtp->rtcp->minrxlost) {
                rtp->rtcp->minrxlost = rtp->rtcp->rxlost;
        }
        if (lost_interval > rtp->rtcp->maxrxlost) {
index 08c9971777e4df32d0d6b05fe303b88a4401fa75..1d36116745c4278c7dfbeb60d91239daee4fad4f 100644 (file)
@@ -269,7 +269,7 @@ AST_TEST_DEFINE(lost_packet_stats_nominal)
        RAII_VAR(struct ast_rtp_instance *, instance2, NULL, ast_rtp_instance_destroy);
        RAII_VAR(struct ast_sched_context *, test_sched, NULL, ast_sched_context_destroy_wrapper);
        struct ast_rtp_instance_stats stats = { 0, };
-       enum ast_rtp_instance_stat stat = AST_RTP_INSTANCE_STAT_RXPLOSS;
+       enum ast_rtp_instance_stat stat = AST_RTP_INSTANCE_STAT_ALL;
 
        switch (cmd) {
        case TEST_INIT:
@@ -303,8 +303,42 @@ AST_TEST_DEFINE(lost_packet_stats_nominal)
 
        /* Check RTCP stats to see if we got the expected packet loss count */
        ast_rtp_instance_get_stats(instance2, &stats, stat);
-       ast_test_validate(test, stats.rxploss == 5,
-               "Condition of 5 lost packets was not met");
+       ast_test_validate(test, stats.rxploss == 5 && stats.local_minrxploss == 5 &&
+               stats.local_maxrxploss == 5, "Condition of 5 lost packets was not met");
+
+       /* Drop 3 before writing 5 more */
+       test_write_and_read_frames(instance1, instance2, 1023, 5);
+
+       ast_rtp_instance_queue_report(instance1);
+       test_write_frames(instance2, 1001, 1);
+       ast_rtp_instance_get_stats(instance2, &stats, stat);
+
+       /* Should now be missing 8 total packets with a change in min */
+       ast_test_validate(test, stats.rxploss == 8 && stats.local_minrxploss == 3 &&
+               stats.local_maxrxploss == 5);
+
+       /* Write 5 more with no gaps */
+       test_write_and_read_frames(instance1, instance2, 1028, 5);
+
+       ast_rtp_instance_queue_report(instance1);
+       test_write_frames(instance2, 1002, 1);
+       ast_rtp_instance_get_stats(instance2, &stats, stat);
+
+       /* Should still only be missing 8 total packets */
+       ast_test_validate(test, stats.rxploss == 8 && stats.local_minrxploss == 3 &&
+               stats.local_maxrxploss == 5);
+
+       /* Now drop 1, write another 5, drop 8, and then write 5 */
+       test_write_and_read_frames(instance1, instance2, 1034, 5);
+       test_write_and_read_frames(instance1, instance2, 1047, 5);
+
+       ast_rtp_instance_queue_report(instance1);
+       test_write_frames(instance2, 1003, 1);
+       ast_rtp_instance_get_stats(instance2, &stats, stat);
+
+       /* Now it should be missing 17 total packets, with a change in max */
+       ast_test_validate(test, stats.rxploss == 17 && stats.local_minrxploss == 3 &&
+               stats.local_maxrxploss == 9);
 
        return AST_TEST_PASS;
 }