Harald Welte has submitted this change and it was merged.

Change subject: mgcp_rtp_state: grup 'stats' members into sub-structure
......................................................................


mgcp_rtp_state: grup 'stats' members into sub-structure

Change-Id: I92a1bead01c6b85bf237b6edf64a1b76b9e97c78
---
M include/osmocom/mgcp/mgcp_internal.h
M src/libosmo-mgcp/mgcp_network.c
M src/libosmo-mgcp/mgcp_stat.c
M tests/mgcp/mgcp_test.c
4 files changed, 48 insertions(+), 45 deletions(-)

Approvals:
  Harald Welte: Looks good to me, approved
  Jenkins Builder: Verified



diff --git a/include/osmocom/mgcp/mgcp_internal.h 
b/include/osmocom/mgcp/mgcp_internal.h
index 8d82b14..9e7246e 100644
--- a/include/osmocom/mgcp/mgcp_internal.h
+++ b/include/osmocom/mgcp/mgcp_internal.h
@@ -71,13 +71,16 @@
        struct mgcp_rtp_stream_state out_stream;
 
        /* jitter and packet loss calculation */
-       int stats_initialized;
-       uint16_t stats_base_seq;
-       uint16_t stats_max_seq;
-       uint32_t stats_ssrc;
-       uint32_t stats_jitter;
-       int32_t stats_transit;
-       int stats_cycles;
+       struct {
+               int initialized;
+               uint16_t base_seq;
+               uint16_t max_seq;
+               uint32_t ssrc;
+               uint32_t jitter;
+               int32_t transit;
+               int cycles;
+       } stats;
+
        bool patched_first_rtp_payload; /* FIXME: drop this, see OS#2459 */
 };
 
diff --git a/src/libosmo-mgcp/mgcp_network.c b/src/libosmo-mgcp/mgcp_network.c
index 8c0a7e3..2056a8e 100644
--- a/src/libosmo-mgcp/mgcp_network.c
+++ b/src/libosmo-mgcp/mgcp_network.c
@@ -434,14 +434,14 @@
        int32_t d;
 
        /* initialize or re-initialize */
-       if (!state->stats_initialized || state->stats_ssrc != ssrc) {
-               state->stats_initialized = 1;
-               state->stats_base_seq = seq;
-               state->stats_max_seq = seq - 1;
-               state->stats_ssrc = ssrc;
-               state->stats_jitter = 0;
-               state->stats_transit = transit;
-               state->stats_cycles = 0;
+       if (!state->stats.initialized || state->stats.ssrc != ssrc) {
+               state->stats.initialized = 1;
+               state->stats.base_seq = seq;
+               state->stats.max_seq = seq - 1;
+               state->stats.ssrc = ssrc;
+               state->stats.jitter = 0;
+               state->stats.transit = transit;
+               state->stats.cycles = 0;
        } else {
                uint16_t udelta;
 
@@ -452,10 +452,10 @@
                 * It can't wrap during the initialization so let's
                 * skip it here. The Appendix A probably doesn't have
                 * this issue because of the probation. */
-               udelta = seq - state->stats_max_seq;
+               udelta = seq - state->stats.max_seq;
                if (udelta < RTP_MAX_DROPOUT) {
-                       if (seq < state->stats_max_seq)
-                               state->stats_cycles += RTP_SEQ_MOD;
+                       if (seq < state->stats.max_seq)
+                               state->stats.cycles += RTP_SEQ_MOD;
                } else if (udelta <= RTP_SEQ_MOD - RTP_MAX_MISORDER) {
                        LOGP(DRTP, LOGL_NOTICE,
                             "RTP seqno made a very large jump on 0x%x delta: 
%u\n",
@@ -467,12 +467,12 @@
         * taken closer to the read function. This was taken from the
         * Appendix A of RFC 3550. Timestamp and arrival_time have a 1/rate
         * resolution. */
-       d = transit - state->stats_transit;
-       state->stats_transit = transit;
+       d = transit - state->stats.transit;
+       state->stats.transit = transit;
        if (d < 0)
                d = -d;
-       state->stats_jitter += d - ((state->stats_jitter + 8) >> 4);
-       state->stats_max_seq = seq;
+       state->stats.jitter += d - ((state->stats.jitter + 8) >> 4);
+       state->stats.max_seq = seq;
 }
 
 /* The RFC 3550 Appendix A assumes there are multiple sources but
diff --git a/src/libosmo-mgcp/mgcp_stat.c b/src/libosmo-mgcp/mgcp_stat.c
index b84f5f2..54c4b66 100644
--- a/src/libosmo-mgcp/mgcp_stat.c
+++ b/src/libosmo-mgcp/mgcp_stat.c
@@ -30,10 +30,10 @@
                        struct mgcp_rtp_end *end, uint32_t *expected,
                        int *loss)
 {
-       *expected = state->stats_cycles + state->stats_max_seq;
-       *expected = *expected - state->stats_base_seq + 1;
+       *expected = state->stats.cycles + state->stats.max_seq;
+       *expected = *expected - state->stats.base_seq + 1;
 
-       if (!state->stats_initialized) {
+       if (!state->stats.initialized) {
                *expected = 0;
                *loss = 0;
                return;
@@ -56,9 +56,9 @@
 /* Helper function for mgcp_format_stats_rtp() to calculate jitter */
 uint32_t calc_jitter(struct mgcp_rtp_state *state)
 {
-       if (!state->stats_initialized)
+       if (!state->stats.initialized)
                return 0;
-       return state->stats_jitter >> 4;
+       return state->stats.jitter >> 4;
 }
 
 /* Generate statistics for an RTP connection */
diff --git a/tests/mgcp/mgcp_test.c b/tests/mgcp/mgcp_test.c
index 330d24d..6f8e4ca 100644
--- a/tests/mgcp/mgcp_test.c
+++ b/tests/mgcp/mgcp_test.c
@@ -916,10 +916,10 @@
                memset(&state, 0, sizeof(state));
                memset(&rtp, 0, sizeof(rtp));
 
-               state.stats_initialized = 1;
-               state.stats_base_seq = pl_test_dat[i].base_seq;
-               state.stats_max_seq = pl_test_dat[i].max_seq;
-               state.stats_cycles = pl_test_dat[i].cycles;
+               state.stats.initialized = 1;
+               state.stats.base_seq = pl_test_dat[i].base_seq;
+               state.stats.max_seq = pl_test_dat[i].max_seq;
+               state.stats.cycles = pl_test_dat[i].cycles;
 
                rtp.packets_rx = pl_test_dat[i].packets;
                calc_loss(&state, &rtp, &expected, &loss);
@@ -1183,7 +1183,7 @@
                       state.out_stream.err_ts_counter - last_out_ts_err_cnt);
 
                printf("Stats: Jitter = %u, Transit = %d\n",
-                      calc_jitter(&state), state.stats_transit);
+                      calc_jitter(&state), state.stats.transit);
 
                last_in_ts_err_cnt = state.in_stream.err_ts_counter;
                last_out_ts_err_cnt = state.out_stream.err_ts_counter;
@@ -1362,29 +1362,29 @@
        conn = mgcp_conn_get_rtp(endp, _conn->id);
        OSMO_ASSERT(conn);
 
-       OSMO_ASSERT(conn->state.stats_initialized == 0);
+       OSMO_ASSERT(conn->state.stats.initialized == 0);
 
        mgcp_rtp_annex_count(endp, &conn->state, 0, 0, 2342);
-       OSMO_ASSERT(conn->state.stats_initialized == 1);
-       OSMO_ASSERT(conn->state.stats_cycles == 0);
-       OSMO_ASSERT(conn->state.stats_max_seq == 0);
+       OSMO_ASSERT(conn->state.stats.initialized == 1);
+       OSMO_ASSERT(conn->state.stats.cycles == 0);
+       OSMO_ASSERT(conn->state.stats.max_seq == 0);
 
        mgcp_rtp_annex_count(endp, &conn->state, 1, 0, 2342);
-       OSMO_ASSERT(conn->state.stats_initialized == 1);
-       OSMO_ASSERT(conn->state.stats_cycles == 0);
-       OSMO_ASSERT(conn->state.stats_max_seq == 1);
+       OSMO_ASSERT(conn->state.stats.initialized == 1);
+       OSMO_ASSERT(conn->state.stats.cycles == 0);
+       OSMO_ASSERT(conn->state.stats.max_seq == 1);
 
        /* now jump.. */
        mgcp_rtp_annex_count(endp, &conn->state, UINT16_MAX, 0, 2342);
-       OSMO_ASSERT(conn->state.stats_initialized == 1);
-       OSMO_ASSERT(conn->state.stats_cycles == 0);
-       OSMO_ASSERT(conn->state.stats_max_seq == UINT16_MAX);
+       OSMO_ASSERT(conn->state.stats.initialized == 1);
+       OSMO_ASSERT(conn->state.stats.cycles == 0);
+       OSMO_ASSERT(conn->state.stats.max_seq == UINT16_MAX);
 
        /* and wrap */
        mgcp_rtp_annex_count(endp, &conn->state, 0, 0, 2342);
-       OSMO_ASSERT(conn->state.stats_initialized == 1);
-       OSMO_ASSERT(conn->state.stats_cycles == UINT16_MAX + 1);
-       OSMO_ASSERT(conn->state.stats_max_seq == 0);
+       OSMO_ASSERT(conn->state.stats.initialized == 1);
+       OSMO_ASSERT(conn->state.stats.cycles == UINT16_MAX + 1);
+       OSMO_ASSERT(conn->state.stats.max_seq == 0);
 
        mgcp_release_endp(endp);
        talloc_free(cfg);

-- 
To view, visit https://gerrit.osmocom.org/5582
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I92a1bead01c6b85bf237b6edf64a1b76b9e97c78
Gerrit-PatchSet: 2
Gerrit-Project: osmo-mgw
Gerrit-Branch: master
Gerrit-Owner: Harald Welte <[email protected]>
Gerrit-Reviewer: Harald Welte <[email protected]>
Gerrit-Reviewer: Jenkins Builder

Reply via email to