Skip to content

Commit

Permalink
Merge branch 'main' into coverity
Browse files Browse the repository at this point in the history
  • Loading branch information
sreimers committed Jan 24, 2024
2 parents 2423b5f + bb7eeea commit 079fa11
Show file tree
Hide file tree
Showing 10 changed files with 77 additions and 64 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/cmake_win.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ jobs:
- name: Install OpenSSL
if: ${{ matrix.config.openssl }}
run: |
choco install --no-progress ${{ matrix.config.choco }} openssl
choco install --no-progress ${{ matrix.config.choco }} openssl --version 3.1.1
- name: Build
shell: cmd
Expand Down
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ libre is a Generic library for real-time communications with async IO support.
* BFCP
* HTTP-stack with client/server
* Websockets
* Jitter-buffer
* Async I/O (select, epoll, kqueue)
* UDP/TCP/TLS/DTLS transport
* JSON parser
Expand Down
37 changes: 37 additions & 0 deletions include/re_rtp.h
Original file line number Diff line number Diff line change
Expand Up @@ -311,3 +311,40 @@ static inline int16_t rtp_seq_diff(uint16_t x, uint16_t y)
{
return (int16_t)(y - x);
}


/** NTP Time */
struct rtp_ntp_time {
uint32_t hi; /**< Seconds since 0h UTC on 1 January 1900 */
uint32_t lo; /**< Fraction of seconds */
};

/** Per-source state information */
struct rtp_source {
struct sa rtp_peer; /**< IP-address of the RTP source */
uint16_t max_seq; /**< Highest seq. number seen */
uint32_t cycles; /**< Shifted count of seq. number cycles */
uint32_t base_seq; /**< Base seq number */
uint32_t bad_seq; /**< Last 'bad' seq number + 1 */
uint32_t probation; /**< Sequ. packets till source is valid */
uint32_t received; /**< Packets received */
uint32_t expected_prior; /**< Packet expected at last interval */
uint32_t received_prior; /**< Packet received at last interval */
int transit; /**< Relative trans time for prev pkt */
uint32_t jitter; /**< Estimated jitter */
size_t rtp_rx_bytes; /**< Number of RTP bytes received */
uint64_t sr_recv; /**< When the last SR was received */
struct rtp_ntp_time last_sr;/**< NTP Timestamp from last SR recvd */
uint32_t rtp_ts; /**< RTP timestamp */
uint32_t last_rtp_ts; /**< Last RTP timestamp */
uint32_t psent; /**< RTP packets sent */
uint32_t osent; /**< RTP octets sent */
};

/* Source */
void rtp_source_init_seq(struct rtp_source *s, uint16_t seq);
int rtp_source_update_seq(struct rtp_source *s, uint16_t seq);
void rtp_source_calc_jitter(struct rtp_source *s, uint32_t rtp_ts,
uint32_t arrival);
int rtp_source_calc_lost(const struct rtp_source *s);
uint8_t rtp_source_calc_fraction_lost(struct rtp_source *s);
4 changes: 3 additions & 1 deletion rem/aubuf/aubuf.c
Original file line number Diff line number Diff line change
Expand Up @@ -352,10 +352,12 @@ void aubuf_read_auframe(struct aubuf *ab, struct auframe *af)
return;

sz = auframe_size(af);

mtx_lock(ab->lock);

if (!ab->ajb && ab->mode == AUBUF_ADAPTIVE)
ab->ajb = ajb_alloc(ab->silence, ab->wish_sz);

mtx_lock(ab->lock);
as = ajb_get(ab->ajb, af);
if (as == AJB_LOW) {
#if AUBUF_DEBUG
Expand Down
2 changes: 1 addition & 1 deletion src/btrace/btrace.c
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ static int print_debug(struct re_printf *pf, struct btrace *bt,
re_regex(symbols[j], str_len(symbols[j]), "([^)]+",
&addr);

re_snprintf(addr2l, sizeof(addr2l),
(void)re_snprintf(addr2l, sizeof(addr2l),
"addr2line -p -f -e %s %r", exe, &addr);

pipe = popen(addr2l, "r");
Expand Down
7 changes: 5 additions & 2 deletions src/http/client.c
Original file line number Diff line number Diff line change
Expand Up @@ -608,12 +608,15 @@ static int conn_connect(struct http_req *req)
laddr = &req->cli->laddr6;
#endif

if (sa_isset(laddr, SA_ADDR))
if (sa_isset(laddr, SA_ADDR)) {
sa_set_scopeid(&conn->addr, sa_scopeid(laddr));
err = tcp_connect_bind(&conn->tc, addr, estab_handler,
recv_handler,close_handler, laddr, conn);
else
}
else {
err = tcp_connect(&conn->tc, addr, estab_handler, recv_handler,
close_handler, conn);
}
if (err)
goto out;

Expand Down
8 changes: 4 additions & 4 deletions src/rtp/ntp.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
* @param ntp NTP time to convert to (output)
* @param tv Unix time to convert from (input)
*/
void unix2ntp(struct ntp_time *ntp, const struct timeval *tv)
void unix2ntp(struct rtp_ntp_time *ntp, const struct timeval *tv)
{
ntp->hi = (uint32_t)(tv->tv_sec + UNIX_NTP_OFFSET);
ntp->lo = (uint32_t)((double)tv->tv_usec*(double)(1LL<<32)*1.0e-6);
Expand All @@ -45,7 +45,7 @@ void unix2ntp(struct ntp_time *ntp, const struct timeval *tv)
* @param tv Unix time to convert to (output)
* @param ntp NTP time to convert from (input)
*/
void ntp2unix(struct timeval *tv, const struct ntp_time *ntp)
void ntp2unix(struct timeval *tv, const struct rtp_ntp_time *ntp)
{
tv->tv_sec = ntp->hi - UNIX_NTP_OFFSET;
tv->tv_usec = (uint32_t)(1.0e6 * (double) ntp->lo / (1LL<<32));
Expand All @@ -58,7 +58,7 @@ void ntp2unix(struct timeval *tv, const struct ntp_time *ntp)
* @param ntp NTP time
* @param jfs_rt Microseconds since UNIX epoch. Optional, may be NULL.
*/
void ntp_time_get(struct ntp_time *ntp, uint64_t *jfs_rt)
void ntp_time_get(struct rtp_ntp_time *ntp, uint64_t *jfs_rt)
{
#if defined(WIN32)
/* timeval::tv_sec on Windows is 32-bit, and it doesn't
Expand Down Expand Up @@ -88,7 +88,7 @@ void ntp_time_get(struct ntp_time *ntp, uint64_t *jfs_rt)
*
* @return NTP time in compact representation
*/
uint32_t ntp_compact(const struct ntp_time *ntp)
uint32_t ntp_compact(const struct rtp_ntp_time *ntp)
{
return ntp ? ((ntp->hi & 0xffff) << 16 | (ntp->lo >> 16)) : 0;
}
Expand Down
41 changes: 4 additions & 37 deletions src/rtp/rtcp.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,35 +19,9 @@ enum {
RTCP_HEADROOM = 4, /**< Headroom in RTCP packets */
};

/** NTP Time */
struct ntp_time {
uint32_t hi; /**< Seconds since 0h UTC on 1 January 1900 */
uint32_t lo; /**< Fraction of seconds */
};

struct hash;

/** Per-source state information */
struct rtp_source {
struct sa rtp_peer; /**< IP-address of the RTP source */
uint16_t max_seq; /**< Highest seq. number seen */
uint32_t cycles; /**< Shifted count of seq. number cycles */
uint32_t base_seq; /**< Base seq number */
uint32_t bad_seq; /**< Last 'bad' seq number + 1 */
uint32_t probation; /**< Sequ. packets till source is valid */
uint32_t received; /**< Packets received */
uint32_t expected_prior; /**< Packet expected at last interval */
uint32_t received_prior; /**< Packet received at last interval */
int transit; /**< Relative trans time for prev pkt */
uint32_t jitter; /**< Estimated jitter */
size_t rtp_rx_bytes; /**< Number of RTP bytes received */
uint64_t sr_recv; /**< When the last SR was received */
struct ntp_time last_sr; /**< NTP Timestamp from last SR received */
uint32_t rtp_ts; /**< RTP timestamp */
uint32_t last_rtp_ts; /**< Last RTP timestamp */
uint32_t psent; /**< RTP packets sent */
uint32_t osent; /**< RTP octets sent */
};

/** RTP Member */
struct rtp_member {
Expand All @@ -64,13 +38,6 @@ struct rtp_member {
struct rtp_member *member_add(struct hash *ht, uint32_t src);
struct rtp_member *member_find(struct hash *ht, uint32_t src);

/* Source */
void source_init_seq(struct rtp_source *s, uint16_t seq);
int source_update_seq(struct rtp_source *s, uint16_t seq);
void source_calc_jitter(struct rtp_source *s, uint32_t rtp_ts,
uint32_t arrival);
int source_calc_lost(const struct rtp_source *s);
uint8_t source_calc_fraction_lost(struct rtp_source *s);

/* RR (Reception report) */
int rtcp_rr_alloc(struct rtcp_rr **rrp, size_t count);
Expand All @@ -90,10 +57,10 @@ int rtcp_psfb_decode(struct mbuf *mb, struct rtcp_msg *msg);

/** NTP Time */
struct timeval;
void unix2ntp(struct ntp_time *ntp, const struct timeval *tv);
void ntp2unix(struct timeval *tv, const struct ntp_time *ntp);
void ntp_time_get(struct ntp_time *ntp, uint64_t* jfs_rt);
uint32_t ntp_compact(const struct ntp_time *ntp);
void unix2ntp(struct rtp_ntp_time *ntp, const struct timeval *tv);
void ntp2unix(struct timeval *tv, const struct rtp_ntp_time *ntp);
void ntp_time_get(struct rtp_ntp_time *ntp, uint64_t* jfs_rt);
uint32_t ntp_compact(const struct rtp_ntp_time *ntp);
uint64_t ntp_compact2us(uint32_t ntpc);

/* RTP Socket */
Expand Down
25 changes: 15 additions & 10 deletions src/rtp/sess.c
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ static struct rtp_member *get_member(struct rtcp_sess *sess, uint32_t src)
*/
void rtcp_calc_rtt(uint32_t *rtt, uint32_t lsr, uint32_t dlsr)
{
struct ntp_time ntp_time;
struct rtp_ntp_time ntp_time;
uint64_t a_us, lsr_us, dlsr_us;

ntp_time_get(&ntp_time, NULL);
Expand Down Expand Up @@ -371,7 +371,7 @@ int rtcp_enable(struct rtcp_sess *sess, bool enabled, const char *cname)


/** Calculate LSR (middle 32 bits out of 64 in the NTP timestamp) */
static uint32_t calc_lsr(const struct ntp_time *last_sr)
static uint32_t calc_lsr(const struct rtp_ntp_time *last_sr)
{
return last_sr->hi ? ntp_compact(last_sr) : 0;
}
Expand Down Expand Up @@ -401,8 +401,8 @@ static bool sender_apply_handler(struct le *le, void *arg)

/* Initialise the members */
rr.ssrc = mbr->src;
rr.fraction = source_calc_fraction_lost(s);
rr.lost = source_calc_lost(s);
rr.fraction = rtp_source_calc_fraction_lost(s);
rr.lost = rtp_source_calc_lost(s);
rr.last_seq = s->cycles | s->max_seq;
rr.jitter = s->jitter >> 4;
rr.lsr = calc_lsr(&s->last_sr);
Expand Down Expand Up @@ -436,7 +436,7 @@ static int mk_sr(struct rtcp_sess *sess, struct mbuf *mb)
mtx_unlock(sess->lock);

if (txstat.jfs_rt_ref) {
struct ntp_time ntp;
struct rtp_ntp_time ntp;
uint64_t jfs_rt, dur;
uint32_t rtp_ts;

Expand Down Expand Up @@ -466,9 +466,14 @@ static int mk_sr(struct rtcp_sess *sess, struct mbuf *mb)
static int sdes_encode_handler(struct mbuf *mb, void *arg)
{
struct rtcp_sess *sess = arg;
int err;

return rtcp_sdes_encode(mb, rtp_sess_ssrc(sess->rs), 1,
mtx_lock(sess->lock);
err = rtcp_sdes_encode(mb, rtp_sess_ssrc(sess->rs), 1,
RTCP_SDES_CNAME, sess->cname);
mtx_unlock(sess->lock);

return err;
}


Expand Down Expand Up @@ -596,13 +601,13 @@ void rtcp_sess_rx_rtp(struct rtcp_sess *sess, struct rtp_header *hdr,
}

/* first packet - init sequence number */
source_init_seq(mbr->s, hdr->seq);
rtp_source_init_seq(mbr->s, hdr->seq);
/* probation not used */
sa_cpy(&mbr->s->rtp_peer, peer);
++sess->senderc;
}

if (!source_update_seq(mbr->s, hdr->seq)) {
if (!rtp_source_update_seq(mbr->s, hdr->seq)) {
DEBUG_WARNING("rtp_update_seq() returned 0\n");
}

Expand All @@ -616,7 +621,7 @@ void rtcp_sess_rx_rtp(struct rtcp_sess *sess, struct rtp_header *hdr,
* https://www.cs.columbia.edu/~hgs/rtp/faq.html#jitter).
*/
if (hdr->ts != mbr->s->last_rtp_ts)
source_calc_jitter(mbr->s, hdr->ts,
rtp_source_calc_jitter(mbr->s, hdr->ts,
(uint32_t)hdr->ts_arrive);
}

Expand Down Expand Up @@ -665,7 +670,7 @@ int rtcp_stats(struct rtp_sock *rs, uint32_t ssrc, struct rtcp_stats *stats)
}

stats->rx.sent = mbr->s->received;
stats->rx.lost = source_calc_lost(mbr->s);
stats->rx.lost = rtp_source_calc_lost(mbr->s);
stats->rx.jit = sess->srate_rx ?
1000000 * (mbr->s->jitter>>4) / sess->srate_rx : 0;

Expand Down
14 changes: 7 additions & 7 deletions src/rtp/source.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ enum {
};


void source_init_seq(struct rtp_source *s, uint16_t seq)
void rtp_source_init_seq(struct rtp_source *s, uint16_t seq)
{
if (!s)
return;
Expand All @@ -39,7 +39,7 @@ void source_init_seq(struct rtp_source *s, uint16_t seq)
/*
* See RFC 3550 - A.1 RTP Data Header Validity Checks
*/
int source_update_seq(struct rtp_source *s, uint16_t seq)
int rtp_source_update_seq(struct rtp_source *s, uint16_t seq)
{
uint16_t udelta = seq - s->max_seq;
const int MAX_DROPOUT = 3000;
Expand All @@ -57,7 +57,7 @@ int source_update_seq(struct rtp_source *s, uint16_t seq)
s->probation--;
s->max_seq = seq;
if (s->probation == 0) {
source_init_seq(s, seq);
rtp_source_init_seq(s, seq);
s->received++;
return 1;
}
Expand Down Expand Up @@ -88,7 +88,7 @@ int source_update_seq(struct rtp_source *s, uint16_t seq)
* restarted without telling us so just re-sync
* (i.e., pretend this was the first packet).
*/
source_init_seq(s, seq);
rtp_source_init_seq(s, seq);
}
else {
s->bad_seq = (seq + 1) & (RTP_SEQ_MOD-1);
Expand All @@ -111,7 +111,7 @@ int source_update_seq(struct rtp_source *s, uint16_t seq)
* rtp_ts: the timestamp from the incoming RTP packet
* arrival: the current time in the same units.
*/
void source_calc_jitter(struct rtp_source *s, uint32_t rtp_ts,
void rtp_source_calc_jitter(struct rtp_source *s, uint32_t rtp_ts,
uint32_t arrival)
{
const int transit = arrival - rtp_ts;
Expand All @@ -132,7 +132,7 @@ void source_calc_jitter(struct rtp_source *s, uint32_t rtp_ts,


/* A.3 */
int source_calc_lost(const struct rtp_source *s)
int rtp_source_calc_lost(const struct rtp_source *s)
{
int extended_max = s->cycles + s->max_seq;
int expected = extended_max - s->base_seq + 1;
Expand All @@ -151,7 +151,7 @@ int source_calc_lost(const struct rtp_source *s)


/* A.3 */
uint8_t source_calc_fraction_lost(struct rtp_source *s)
uint8_t rtp_source_calc_fraction_lost(struct rtp_source *s)
{
int extended_max = s->cycles + s->max_seq;
int expected = extended_max - s->base_seq + 1;
Expand Down

0 comments on commit 079fa11

Please sign in to comment.