Commit f0993287 authored by Simon Morlat's avatar Simon Morlat

Fix a race condition around rtpsession's auxiliary destinations.

parent 15d91556
......@@ -395,6 +395,7 @@ typedef struct _RtpSession RtpSession;
**/
struct _RtpSession
{
ortp_mutex_t main_mutex; /* To protect data that can be accessed simultaneously by a control thread and the real-time thread in charge of sending/receiving. */
RtpSession *next; /* next RtpSession, when the session are enqueued by the scheduler */
int mask_pos; /* the position in the scheduler mask of RtpSession : do not move this field: it is part of the ABI since the session_set macros use it*/
struct {
......
......@@ -233,6 +233,7 @@ rtp_session_init (RtpSession * session, int mode)
return;
}
memset (session, 0, sizeof (RtpSession));
ortp_mutex_init(&session->main_mutex, NULL);
session->mode = (RtpSessionMode) mode;
if ((mode == RTP_SESSION_RECVONLY) || (mode == RTP_SESSION_SENDRECV))
{
......@@ -1690,6 +1691,7 @@ void rtp_session_uninit (RtpSession * session)
freemsg(session->rtcp.tmmbr_info.received);
if (session->rtcp.send_algo.fb_packets)
freemsg(session->rtcp.send_algo.fb_packets);
ortp_mutex_destroy(&session->main_mutex);
}
/**
......
......@@ -929,8 +929,10 @@ end:
ortp_free(aux_rtp);
ortp_free(aux_rtcp);
}else{
ortp_mutex_lock(&session->main_mutex);
session->rtp.gs.aux_destinations=o_list_append(session->rtp.gs.aux_destinations,aux_rtp);
session->rtcp.gs.aux_destinations=o_list_append(session->rtcp.gs.aux_destinations,aux_rtcp);
ortp_mutex_unlock(&session->main_mutex);
}
}
return err;
......@@ -960,8 +962,10 @@ rtp_session_add_aux_remote_addr_full(RtpSession * session, const char * rtp_addr
}
void rtp_session_clear_aux_remote_addr(RtpSession * session){
ortp_mutex_lock(&session->main_mutex);
ortp_stream_clear_aux_addresses(&session->rtp.gs);
ortp_stream_clear_aux_addresses(&session->rtcp.gs);
ortp_mutex_unlock(&session->main_mutex);
}
void rtp_session_set_sockets(RtpSession *session, int rtpfd, int rtcpfd){
......@@ -1424,10 +1428,12 @@ int rtp_session_rtp_send (RtpSession * session, mblk_t * m){
/*first send to main destination*/
error=rtp_session_rtp_sendto(session,m,destaddr,destlen,FALSE);
/*then iterate over auxiliary destinations*/
ortp_mutex_lock(&session->main_mutex);
for(elem=session->rtp.gs.aux_destinations;elem!=NULL;elem=elem->next){
OrtpAddress *addr=(OrtpAddress*)elem->data;
rtp_session_rtp_sendto(session,m,(struct sockaddr*)&addr->addr,addr->len,TRUE);
}
ortp_mutex_unlock(&session->main_mutex);
freemsg(m);
return error;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment