From bc5d7f9c37fe8a4ff5744ab8620898ccae6a7d2a Mon Sep 17 00:00:00 2001 From: Richard Mudgett Date: Fri, 17 Jul 2015 16:23:53 -0500 Subject: [PATCH 1/4] chan_sip.c: Tweak glue->update_peer() parameter nil value. Change glue->update_peer() parameter from 0 to NULL to better indicate it is a pointer. Change-Id: I8ff2e5087f0e19f6998e3488a712a2470cc823bd --- channels/chan_sip.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/channels/chan_sip.c b/channels/chan_sip.c index 1838bdaadd..9ab429e83c 100644 --- a/channels/chan_sip.c +++ b/channels/chan_sip.c @@ -7350,7 +7350,7 @@ static int sip_fixup(struct ast_channel *oldchan, struct ast_channel *newchan) redirect of both channels). Note that a channel can not be masqueraded *into* a native bridge. So there is no danger that this breaks a native bridge that should stay up. */ - sip_set_rtp_peer(newchan, NULL, NULL, 0, 0, 0); + sip_set_rtp_peer(newchan, NULL, NULL, NULL, NULL, 0); ret = 0; } ast_debug(3, "SIP Fixup: New owner for dialogue %s: %s (Old parent: %s)\n", p->callid, ast_channel_name(p->owner), ast_channel_name(oldchan)); From e20f435b6093c2c72e678b9fad1ed037c3191b88 Mon Sep 17 00:00:00 2001 From: Richard Mudgett Date: Thu, 23 Jul 2015 12:41:12 -0500 Subject: [PATCH 2/4] rtp_engine.h: Misc comment fixes. Change-Id: If98139264d5d97427b4685ecbdc54518f725bc43 --- include/asterisk/rtp_engine.h | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/include/asterisk/rtp_engine.h b/include/asterisk/rtp_engine.h index b7ac2a149e..376fac8dc7 100644 --- a/include/asterisk/rtp_engine.h +++ b/include/asterisk/rtp_engine.h @@ -1,4 +1,4 @@ - /* +/* * Asterisk -- An open source telephony toolkit. * * Copyright (C) 1999 - 2009, Digium, Inc. @@ -625,7 +625,7 @@ struct ast_rtp_glue { enum ast_rtp_glue_result (*get_trtp_info)(struct ast_channel *chan, struct ast_rtp_instance **instance); /*! Callback for updating the destination that the remote side should send RTP to */ int (*update_peer)(struct ast_channel *chan, struct ast_rtp_instance *instance, struct ast_rtp_instance *vinstance, struct ast_rtp_instance *tinstance, const struct ast_format_cap *cap, int nat_active); - /*! Callback for retrieving codecs that the channel can do. Result returned in result_cap*/ + /*! Callback for retrieving codecs that the channel can do. Result returned in result_cap. */ void (*get_codec)(struct ast_channel *chan, struct ast_format_cap *result_cap); /*! Linked list information */ AST_RWLIST_ENTRY(ast_rtp_glue) entry; @@ -1418,7 +1418,7 @@ unsigned int ast_rtp_lookup_sample_rate2(int asterisk_format, struct ast_format * \code * struct ast_format_cap *astformats = ast_format_cap_alloc_nolock() * int nonastformats; - * ast_rtp_codecs_payload_formats(&codecs, &astformats, &nonastformats); + * ast_rtp_codecs_payload_formats(&codecs, astformats, &nonastformats); * \endcode * * This retrieves all the formats known about in the codecs structure and puts the Asterisk ones in the integer @@ -1449,6 +1449,7 @@ void ast_rtp_codecs_payload_formats(struct ast_rtp_codecs *codecs, struct ast_fo * \since 1.8 */ int ast_rtp_codecs_payload_code(struct ast_rtp_codecs *codecs, int asterisk_format, const struct ast_format *format, int code); + /*! * \brief Search for a payload code in the ast_rtp_codecs structure * From 7427c7f13b1d0c9095e83a3ea38394f521d3a75e Mon Sep 17 00:00:00 2001 From: Richard Mudgett Date: Thu, 23 Jul 2015 14:04:16 -0500 Subject: [PATCH 3/4] rtp_engine.c: Minor tweaks. * Fix off nominial ref leak of new_type in ast_rtp_codecs_payloads_set_m_type(). * No need to lock static_RTP_PT_lock in ast_rtp_codecs_payloads_set_m_type() and ast_rtp_codecs_payloads_set_rtpmap_type_rate() before the payload type parameter sanity check. * No need to create ast_rtp_payload_type ao2 objects with a lock since the lock is not used. Change-Id: I64dd1bb4dfabdc7e981e3f61448beac9bb7504d4 --- main/rtp_engine.c | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/main/rtp_engine.c b/main/rtp_engine.c index 0fca0dded4..f139dc4545 100644 --- a/main/rtp_engine.c +++ b/main/rtp_engine.c @@ -236,7 +236,10 @@ static ast_rwlock_t static_RTP_PT_lock; static struct stasis_topic *rtp_topic; -/*! \internal \brief Destructor for \c ast_rtp_payload_type */ +/*! + * \internal + * \brief Destructor for \c ast_rtp_payload_type + */ static void rtp_payload_type_dtor(void *obj) { struct ast_rtp_payload_type *payload = obj; @@ -248,7 +251,8 @@ struct ast_rtp_payload_type *ast_rtp_engine_alloc_payload_type(void) { struct ast_rtp_payload_type *payload; - payload = ao2_alloc(sizeof(*payload), rtp_payload_type_dtor); + payload = ao2_alloc_options(sizeof(*payload), rtp_payload_type_dtor, + AO2_ALLOC_OPT_LOCK_NOLOCK); return payload; } @@ -644,17 +648,16 @@ void ast_rtp_codecs_payloads_set_m_type(struct ast_rtp_codecs *codecs, struct as { struct ast_rtp_payload_type *new_type; - new_type = ast_rtp_engine_alloc_payload_type(); - if (!new_type) { + if (payload < 0 || payload >= AST_RTP_MAX_PT) { return; } - ast_rwlock_rdlock(&static_RTP_PT_lock); - if (payload < 0 || payload >= AST_RTP_MAX_PT) { - ast_rwlock_unlock(&static_RTP_PT_lock); + new_type = ast_rtp_engine_alloc_payload_type(); + if (!new_type) { return; } + ast_rwlock_rdlock(&static_RTP_PT_lock); ast_rwlock_wrlock(&codecs->codecs_lock); if (payload < AST_VECTOR_SIZE(&codecs->payloads)) { ao2_t_cleanup(AST_VECTOR_GET(&codecs->payloads, payload), "cleaning up replaced payload type"); @@ -684,12 +687,11 @@ int ast_rtp_codecs_payloads_set_rtpmap_type_rate(struct ast_rtp_codecs *codecs, unsigned int i; int found = 0; - ast_rwlock_rdlock(&mime_types_lock); if (pt < 0 || pt >= AST_RTP_MAX_PT) { - ast_rwlock_unlock(&mime_types_lock); return -1; /* bogus payload type */ } + ast_rwlock_rdlock(&mime_types_lock); ast_rwlock_wrlock(&codecs->codecs_lock); for (i = 0; i < mime_types_len; ++i) { const struct ast_rtp_mime_type *t = &ast_rtp_mime_types[i]; @@ -2094,7 +2096,7 @@ static void rtp_engine_shutdown(void) ast_rwlock_unlock(&mime_types_lock); } -int ast_rtp_engine_init() +int ast_rtp_engine_init(void) { ast_rwlock_init(&mime_types_lock); ast_rwlock_init(&static_RTP_PT_lock); From 89b21fd9a38bcd89402249440c1670ce48781f30 Mon Sep 17 00:00:00 2001 From: Richard Mudgett Date: Mon, 27 Jul 2015 19:10:11 -0500 Subject: [PATCH 4/4] rtp_engine.h: No sense allowing payload types larger than RFC allows. * Tweaked add_static_payload() to not use magic numbers. Change-Id: I1719ff0f6d3ce537a91572501eae5bcd912a420b --- include/asterisk/rtp_engine.h | 11 +++++------ main/rtp_engine.c | 18 ++++++++++-------- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/include/asterisk/rtp_engine.h b/include/asterisk/rtp_engine.h index 376fac8dc7..80183ede7f 100644 --- a/include/asterisk/rtp_engine.h +++ b/include/asterisk/rtp_engine.h @@ -78,14 +78,13 @@ extern "C" { #include "asterisk/stasis.h" #include "asterisk/vector.h" -/* Maximum number of payloads supported */ -#if defined(LOW_MEMORY) +/*! Maximum number of payload types RTP can support. */ #define AST_RTP_MAX_PT 128 -#else -#define AST_RTP_MAX_PT 196 -#endif -/* Maximum number of generations */ +/*! First dynamic RTP payload type */ +#define AST_RTP_PT_FIRST_DYNAMIC 96 + +/*! Maximum number of generations */ #define AST_RED_MAX_GENERATION 5 /*! diff --git a/main/rtp_engine.c b/main/rtp_engine.c index f139dc4545..296d84f2c4 100644 --- a/main/rtp_engine.c +++ b/main/rtp_engine.c @@ -1740,22 +1740,24 @@ static void set_next_mime_type(struct ast_format *format, int rtp_code, const ch static void add_static_payload(int map, struct ast_format *format, int rtp_code) { int x; + + ast_assert(map < ARRAY_LEN(static_RTP_PT)); + ast_rwlock_wrlock(&static_RTP_PT_lock); if (map < 0) { /* find next available dynamic payload slot */ - for (x = 96; x < 127; x++) { + for (x = AST_RTP_PT_FIRST_DYNAMIC; x < AST_RTP_MAX_PT; ++x) { if (!static_RTP_PT[x].asterisk_format && !static_RTP_PT[x].rtp_code) { map = x; break; } } - } - - if (map < 0) { - ast_log(LOG_WARNING, "No Dynamic RTP mapping available for format %s\n", - ast_format_get_name(format)); - ast_rwlock_unlock(&static_RTP_PT_lock); - return; + if (map < 0) { + ast_log(LOG_WARNING, "No Dynamic RTP mapping available for format %s\n", + ast_format_get_name(format)); + ast_rwlock_unlock(&static_RTP_PT_lock); + return; + } } if (format) {