Coverage Report

Created: 2026-05-30 06:35

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/rtpproxy/src/rtpp_analyzer.c
Line
Count
Source
1
/*
2
 * Copyright (c) 2015 Sippy Software, Inc., http://www.sippysoft.com
3
 * All rights reserved.
4
 *
5
 * Redistribution and use in source and binary forms, with or without
6
 * modification, are permitted provided that the following conditions
7
 * are met:
8
 * 1. Redistributions of source code must retain the above copyright
9
 *    notice, this list of conditions and the following disclaimer.
10
 * 2. Redistributions in binary form must reproduce the above copyright
11
 *    notice, this list of conditions and the following disclaimer in the
12
 *    documentation and/or other materials provided with the distribution.
13
 *
14
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24
 * SUCH DAMAGE.
25
 *
26
 */
27
28
#include <sys/types.h>
29
#include <netinet/in.h>
30
#include <stddef.h>
31
#include <stdlib.h>
32
#include <string.h>
33
34
#include "rtpp_ssrc.h"
35
#include "rtpa_stats.h"
36
#include "rtpp_types.h"
37
#include "rtpp_codeptr.h"
38
#include "rtpp_refcnt.h"
39
#include "rtpp_log_obj.h"
40
#include "rtp.h"
41
#include "rtpp_time.h"
42
#include "rtp_packet.h"
43
#include "rtp_analyze.h"
44
#include "rtpp_analyzer.h"
45
#include "rtpp_analyzer_fin.h"
46
#include "rtpp_mallocs.h"
47
48
struct rtpp_analyzer_priv {
49
    struct rtpp_analyzer pub;
50
    struct rtpp_session_stat rstat;
51
    uint32_t pecount;
52
    uint32_t aecount;
53
    struct rtpp_log *log;
54
};
55
56
static enum update_rtpp_stats_rval rtpp_analyzer_update(struct rtpp_analyzer *,
57
  struct rtp_packet *);
58
static void rtpp_analyzer_get_stats(struct rtpp_analyzer *,
59
  struct rtpa_stats *);
60
static int rtpp_analyzer_get_jstats(struct rtpp_analyzer *,
61
  struct rtpa_stats_jitter *);
62
static void rtpp_analyzer_dtor(struct rtpp_analyzer_priv *);
63
64
DEFINE_SMETHODS(rtpp_analyzer,
65
    .update = &rtpp_analyzer_update,
66
    .get_stats = &rtpp_analyzer_get_stats,
67
    .get_jstats = &rtpp_analyzer_get_jstats,
68
);
69
70
struct rtpp_analyzer *
71
rtpp_analyzer_ctor(struct rtpp_log *log)
72
74.5k
{
73
74.5k
    struct rtpp_analyzer_priv *pvt;
74
74.5k
    struct rtpp_analyzer *rap;
75
76
74.5k
    pvt = rtpp_rzmalloc(sizeof(struct rtpp_analyzer_priv), PVT_RCOFFS(pvt));
77
74.5k
    if (pvt == NULL) {
78
0
        return (NULL);
79
0
    }
80
74.5k
    rap = &pvt->pub;
81
74.5k
    if (rtpp_stats_init(&pvt->rstat) != 0) {
82
0
        goto e0;
83
0
    }
84
74.5k
    pvt->log = log;
85
74.5k
    RTPP_OBJ_INCREF(log);
86
74.5k
    PUBINST_FININIT(&pvt->pub, pvt, rtpp_analyzer_dtor);
87
74.5k
    return (rap);
88
0
e0:
89
0
    RTPP_OBJ_DECREF(&(pvt->pub));
90
0
    return (NULL);
91
74.5k
}
92
93
static enum update_rtpp_stats_rval
94
rtpp_analyzer_update(struct rtpp_analyzer *rap, struct rtp_packet *pkt)
95
0
{
96
0
    struct rtpp_analyzer_priv *pvt;
97
0
    enum update_rtpp_stats_rval rval;
98
99
0
    PUB2PVT(rap, pvt);
100
0
    if (rtp_packet_parse(pkt) != RTP_PARSER_OK) {
101
0
        pvt->pecount++;
102
0
        return (UPDATE_ERR);
103
0
    }
104
0
    rval = update_rtpp_stats(pvt->log, &(pvt->rstat), &(pkt->data.header),
105
0
      pkt->parsed, pkt->rtime.mono);
106
0
    if (rval == UPDATE_ERR) {
107
0
        pvt->aecount++;
108
0
    }
109
0
    pvt->rstat.last.pt = pkt->data.header.pt;
110
0
    return (rval);
111
0
}
112
113
static void
114
rtpp_analyzer_get_stats(struct rtpp_analyzer *rap, struct rtpa_stats *rsp)
115
150k
{
116
150k
    struct rtpp_session_stat ostat;
117
150k
    struct rtpp_analyzer_priv *pvt;
118
119
150k
    PUB2PVT(rap, pvt);
120
150k
    rsp->pecount = pvt->pecount;
121
150k
    rsp->aecount = pvt->aecount;
122
150k
    memset(&ostat, '\0', sizeof(ostat));
123
150k
    update_rtpp_totals(&(pvt->rstat), &ostat);
124
150k
    rsp->psent = ostat.psent;
125
150k
    rsp->precvd = ostat.precvd;
126
150k
    rsp->pdups = ostat.duplicates;
127
150k
    rsp->ssrc_changes = pvt->rstat.ssrc_changes;
128
150k
    rsp->last_ssrc = pvt->rstat.last.ssrc;
129
150k
    rsp->plost = ostat.psent - ostat.precvd;
130
150k
    if (pvt->rstat.last.pt != PT_UNKN) {
131
0
        rsp->last_pt = pvt->rstat.last.pt;
132
150k
    } else {
133
150k
        rsp->last_pt = -1;
134
150k
    }
135
150k
}
136
137
static int
138
rtpp_analyzer_get_jstats(struct rtpp_analyzer *rap,
139
  struct rtpa_stats_jitter *jrsp)
140
75.3k
{
141
75.3k
    struct rtpp_analyzer_priv *pvt;
142
75.3k
    int rval;
143
144
75.3k
    PUB2PVT(rap, pvt);
145
75.3k
    rval = get_jitter_stats(pvt->rstat.jdata, jrsp, pvt->log);
146
75.3k
    return (rval);
147
75.3k
}
148
149
static void
150
rtpp_analyzer_dtor(struct rtpp_analyzer_priv *pvt)
151
74.4k
{
152
153
74.4k
    rtpp_analyzer_fin(&(pvt->pub));
154
74.4k
    rtpp_stats_destroy(&pvt->rstat);
155
74.4k
    RTPP_OBJ_DECREF(pvt->log);
156
74.4k
}