From 7af7dc92ae49084c1dbf144d982119c5228972f5 Mon Sep 17 00:00:00 2001 From: Nanang Izzuddin Date: Thu, 8 Mar 2012 08:34:30 +0000 Subject: Fix #1440: - Use separate buffer for outgoing RTCP. Previously, RTCP generation might override outgoing RTP payload (because of shared buffer). - Use exact size for RTCP-XR content buffer. Previously RTCP-XR content buffer size was set to PJMEDIA_MAX_MTU, quite huge wasted space. git-svn-id: http://svn.pjsip.org/repos/pjproject/branches/1.x@3969 74dad513-b988-da41-8d7b-12977e46ad98 --- pjmedia/include/pjmedia/rtcp_xr.h | 14 +++++++++++++- pjmedia/src/pjmedia/stream.c | 35 +++++++++++++++++++++++------------ 2 files changed, 36 insertions(+), 13 deletions(-) diff --git a/pjmedia/include/pjmedia/rtcp_xr.h b/pjmedia/include/pjmedia/rtcp_xr.h index e44bf1b1..fb204852 100644 --- a/pjmedia/include/pjmedia/rtcp_xr.h +++ b/pjmedia/include/pjmedia/rtcp_xr.h @@ -200,6 +200,17 @@ typedef struct pjmedia_rtcp_xr_rb_voip_mtc jitter buffer */ } pjmedia_rtcp_xr_rb_voip_mtc; + +/** + * Constant of RTCP-XR content size. + */ +#define PJMEDIA_RTCP_XR_BUF_SIZE \ + sizeof(pjmedia_rtcp_xr_rb_rr_time) + \ + sizeof(pjmedia_rtcp_xr_rb_dlrr) + \ + sizeof(pjmedia_rtcp_xr_rb_stats) + \ + sizeof(pjmedia_rtcp_xr_rb_voip_mtc) + + /** * This structure declares RTCP XR (Extended Report) packet. */ @@ -221,7 +232,8 @@ typedef struct pjmedia_rtcp_xr_pkt pj_uint32_t ssrc; /**< SSRC identification */ } common; - pj_int8_t buf[PJMEDIA_MAX_MTU];/**< Content buffer */ + pj_int8_t buf[PJMEDIA_RTCP_XR_BUF_SIZE]; + /**< Content buffer */ } pjmedia_rtcp_xr_pkt; #pragma pack() diff --git a/pjmedia/src/pjmedia/stream.c b/pjmedia/src/pjmedia/stream.c index a6301315..8b8dc7f4 100644 --- a/pjmedia/src/pjmedia/stream.c +++ b/pjmedia/src/pjmedia/stream.c @@ -144,6 +144,9 @@ struct pjmedia_stream pj_uint32_t rtcp_interval; /**< Interval, in timestamp. */ pj_bool_t initial_rr; /**< Initial RTCP RR sent */ pj_bool_t rtcp_sdes_bye_disabled;/**< Send RTCP SDES/BYE?*/ + void *out_rtcp_pkt; /**< Outgoing RTCP packet. */ + unsigned out_rtcp_pkt_size; + /**< Outgoing RTCP packet size. */ /* RFC 2833 DTMF transmission queue: */ int tx_event_pt; /**< Outgoing pt for dtmf. */ @@ -926,9 +929,9 @@ static pj_status_t send_rtcp(pjmedia_stream *stream, #endif if (with_sdes || with_bye || with_xr) { - pkt = (pj_uint8_t*) stream->enc->out_pkt; + pkt = (pj_uint8_t*) stream->out_rtcp_pkt; pj_memcpy(pkt, sr_rr_pkt, len); - max_len = stream->enc->out_pkt_size; + max_len = stream->out_rtcp_pkt_size; } else { pkt = sr_rr_pkt; max_len = len; @@ -1889,7 +1892,6 @@ static pj_status_t create_channel( pj_pool_t *pool, { pjmedia_channel *channel; pj_status_t status; - unsigned min_out_pkt_size; /* Allocate memory for channel descriptor */ @@ -1914,15 +1916,6 @@ static pj_status_t create_channel( pj_pool_t *pool, if (channel->out_pkt_size > PJMEDIA_MAX_MTU) channel->out_pkt_size = PJMEDIA_MAX_MTU; - /* It should big enough to hold (minimally) RTCP SR with an SDES. */ - min_out_pkt_size = sizeof(pjmedia_rtcp_sr_pkt) + - sizeof(pjmedia_rtcp_common) + - (4 + stream->cname.slen) + - 32; - - if (channel->out_pkt_size < min_out_pkt_size) - channel->out_pkt_size = min_out_pkt_size; - channel->out_pkt = pj_pool_alloc(pool, channel->out_pkt_size); PJ_ASSERT_RETURN(channel->out_pkt != NULL, PJ_ENOMEM); @@ -2261,6 +2254,24 @@ PJ_DEF(pj_status_t) pjmedia_stream_create( pjmedia_endpt *endpt, } } + /* Allocate outgoing RTCP buffer, should be enough to hold SR/RR, SDES, + * BYE, and XR. + */ + stream->out_rtcp_pkt_size = sizeof(pjmedia_rtcp_sr_pkt) + + sizeof(pjmedia_rtcp_common) + + (4 + stream->cname.slen) + + 32; +#if defined(PJMEDIA_HAS_RTCP_XR) && (PJMEDIA_HAS_RTCP_XR != 0) + if (info->rtcp_xr_enabled) { + stream->out_rtcp_pkt_size += sizeof(pjmedia_rtcp_xr_pkt); + } +#endif + + if (stream->out_rtcp_pkt_size > PJMEDIA_MAX_MTU) + stream->out_rtcp_pkt_size = PJMEDIA_MAX_MTU; + + stream->out_rtcp_pkt = pj_pool_alloc(pool, stream->out_rtcp_pkt_size); + /* Only attach transport when stream is ready. */ status = pjmedia_transport_attach(tp, stream, &info->rem_addr, &info->rem_rtcp, -- cgit v1.2.3