Skip to content

Commit

Permalink
rtprecv: avoid concurrent r/w of rtcp_peer and cname
Browse files Browse the repository at this point in the history
  • Loading branch information
cspiel1 committed Jan 9, 2024
1 parent 212477a commit f919853
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions src/rtprecv.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@
#define MAGIC 0x00511eb3
#include "magic.h"

enum rtcp_state {
RTCP_IDLE,
RTCP_STARTING,
RTCP_RUNNING
};


/* Receive */
struct rtp_receiver {
#ifndef RELEASE
Expand All @@ -31,7 +38,7 @@ struct rtp_receiver {
bool pseq_set; /**< True if sequence number is set */
bool rtp_estab; /**< True if RTP stream established */
RE_ATOMIC bool run; /**< True if RX thread is running */
bool start_rtcp; /**< Start RTCP flag */
enum rtcp_state rtcp_state; /**< RTCP state */
char *cname; /**< Canonical Name for RTCP send */
struct sa rtcp_peer; /**< RTCP address of Peer */
bool pinhole; /**< Open RTCP NAT pinhole flag */
Expand Down Expand Up @@ -170,11 +177,11 @@ static void rtprecv_periodic(void *arg)
mtx_unlock(rx->mtx);
tmr_start(&rx->tmr, 10, rtprecv_periodic, rx);
mtx_lock(rx->mtx);
if (rx->start_rtcp) {
if (rx->rtcp_state == RTCP_STARTING) {
int err = 0;
rx->start_rtcp = false;
mtx_unlock(rx->mtx);
rx->rtcp_state = RTCP_RUNNING;
rtcp_start(rx->rtp, rx->cname, &rx->rtcp_peer);
mtx_unlock(rx->mtx);
if (pinhole) {
err = rtcp_send_app(rx->rtp, "PING",
(void *)"PONG", 4);
Expand Down Expand Up @@ -511,7 +518,9 @@ int rtprecv_start_rtcp(struct rtp_receiver *rx, const char *cname,

rx->cname = mem_deref(rx->cname);
err = str_dup(&rx->cname, cname);
rx->start_rtcp = true;
if (rx->rtcp_state == RTCP_IDLE)
rx->rtcp_state = RTCP_STARTING;

rx->pinhole = pinhole;
mtx_unlock(rx->mtx);

Expand Down

0 comments on commit f919853

Please sign in to comment.