Coverage Report

Created: 2023-06-07 06:37

/src/rtpproxy/src/rtp_packet.c
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * Copyright (c) 2007-2019 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 <stdlib.h>
29
#include <string.h>
30
#include <sys/types.h>
31
#include <netinet/in.h>
32
#include <assert.h>
33
#include <stddef.h>
34
35
#include "rtp.h"
36
#include "rtp_info.h"
37
#include "rtpp_time.h"
38
#include "rtp_packet.h"
39
#include "rtpp_types.h"
40
#include "rtpp_mallocs.h"
41
#include "rtpp_refcnt.h"
42
43
#include "rtpp_wi.h"
44
#include "rtpp_wi_private.h"
45
46
struct rtp_packet_full;
47
48
struct rtp_packet_priv {
49
    struct rtp_info rinfo;
50
    struct rtpp_wi_pvt wip;
51
};
52
53
struct rtp_packet_full {
54
    struct rtp_packet pub;
55
    struct rtp_packet_priv pvt;
56
};
57
58
void
59
rtp_packet_dup(struct rtp_packet *dpkt, const struct rtp_packet *spkt, int flags)
60
0
{
61
0
    int csize, offst;
62
0
    struct rtp_packet_full *dpkt_full, *spkt_full;
63
64
0
    csize = offsetof(struct rtp_packet, data.buf) + spkt->size;
65
0
    if ((flags & RTPP_DUP_HDRONLY) != 0) {
66
0
        assert(spkt->parse_result == RTP_PARSER_OK);
67
0
        csize -= spkt->parsed->data_size;
68
0
    }
69
0
    offst = RTP_PKT_COPYOFF(spkt);
70
0
    memcpy(((char *)dpkt) + offst, ((char *)spkt) + offst, csize - offst);
71
0
    if (spkt->parsed == NULL) {
72
0
        return;
73
0
    }
74
0
    PUB2PVT(dpkt, dpkt_full);
75
0
    PUB2PVT(spkt, spkt_full);
76
0
    dpkt_full->pvt.rinfo = spkt_full->pvt.rinfo;
77
0
    dpkt->parsed = &(dpkt_full->pvt.rinfo);
78
0
    if ((flags & RTPP_DUP_HDRONLY) != 0) {
79
0
        dpkt->size -= dpkt->parsed->data_size;
80
0
        dpkt->parsed->data_size = 0;
81
0
        dpkt->parsed->nsamples = 0;
82
0
    }
83
0
}
84
85
struct rtp_packet *
86
rtp_packet_alloc()
87
498
{
88
498
    struct rtp_packet_full *pkt;
89
90
498
    pkt = rtpp_rzmalloc(sizeof(*pkt), PVT_RCOFFS(pkt));
91
498
    if (pkt == NULL) {
92
0
        return (NULL);
93
0
    }
94
498
    CALL_SMETHOD(pkt->pub.rcnt, use_stdfree, pkt);
95
498
    pkt->pub.wi = &(pkt->pvt.wip.pub);
96
97
498
    return &(pkt->pub);
98
498
}
99
100
void 
101
rtp_packet_set_seq(struct rtp_packet *p, uint16_t seq)
102
0
{
103
104
0
    p->parsed->seq = seq;
105
0
    p->data.header.seq = htons(seq);
106
0
}
107
108
void 
109
rtp_packet_set_ts(struct rtp_packet *p, uint32_t ts)
110
0
{
111
112
0
    p->parsed->ts = ts;
113
0
    p->data.header.ts = htonl(ts);
114
0
}
115
116
rtp_parser_err_t
117
rtp_packet_parse(struct rtp_packet *pkt)
118
498
{
119
498
    struct rtp_packet_full *pkt_full;
120
498
    struct rtp_info *rinfo;
121
122
498
    if (pkt->parse_result != RTP_PARSER_NOTPARSED) {
123
0
        return (pkt->parse_result);
124
0
    }
125
498
    assert(pkt->parsed == NULL);
126
498
    pkt_full = (void *)pkt;
127
498
    rinfo = &(pkt_full->pvt.rinfo);
128
498
    pkt->parse_result = rtp_packet_parse_raw(pkt->data.buf, pkt->size, rinfo);
129
498
    if (pkt->parse_result == RTP_PARSER_OK) {
130
413
        pkt->parsed = rinfo;
131
413
    }
132
498
    return (pkt->parse_result);
133
498
}