mirror of
https://github.com/asterisk/asterisk.git
synced 2025-10-02 10:22:46 +00:00
SDP: Misc cleanups (Mostly memory leaks)
Change-Id: I74431b385da333f2c5f5a6d7c55e70b69a4f05d2
This commit is contained in:
@@ -535,8 +535,8 @@ struct ast_sdp_payload *ast_sdp_m_get_payload(const struct ast_sdp_m_line *m_lin
|
|||||||
* \param format Format
|
* \param format Format
|
||||||
* \param code from AST_RTP list
|
* \param code from AST_RTP list
|
||||||
*
|
*
|
||||||
* \retval non-NULL Success
|
* \retval 0 Success
|
||||||
* \retval NULL Failure
|
* \retval non-0 Failure
|
||||||
*
|
*
|
||||||
* \since 15
|
* \since 15
|
||||||
*/
|
*/
|
||||||
|
21
main/sdp.c
21
main/sdp.c
@@ -435,11 +435,13 @@ static int sdp_m_add_fmtp(struct ast_sdp_m_line *m_line, const struct ast_format
|
|||||||
int rtp_code)
|
int rtp_code)
|
||||||
{
|
{
|
||||||
struct ast_str *fmtp0 = ast_str_alloca(256);
|
struct ast_str *fmtp0 = ast_str_alloca(256);
|
||||||
|
struct ast_sdp_a_line *a_line;
|
||||||
char *tmp;
|
char *tmp;
|
||||||
|
|
||||||
ast_format_generate_sdp_fmtp(format, rtp_code, &fmtp0);
|
ast_format_generate_sdp_fmtp(format, rtp_code, &fmtp0);
|
||||||
if (ast_str_strlen(fmtp0) == 0) {
|
if (ast_str_strlen(fmtp0) == 0) {
|
||||||
return -1;
|
/* Format doesn't have fmtp attributes */
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
tmp = ast_str_buffer(fmtp0) + ast_str_strlen(fmtp0) - 1;
|
tmp = ast_str_buffer(fmtp0) + ast_str_strlen(fmtp0) - 1;
|
||||||
@@ -447,7 +449,11 @@ static int sdp_m_add_fmtp(struct ast_sdp_m_line *m_line, const struct ast_format
|
|||||||
while (*tmp == '\r' || *tmp == '\n') --tmp;
|
while (*tmp == '\r' || *tmp == '\n') --tmp;
|
||||||
*++tmp = '\0';
|
*++tmp = '\0';
|
||||||
|
|
||||||
/* ast...generate gives us everything, just need value */
|
/*
|
||||||
|
* ast...generate gives us everything, just need value
|
||||||
|
*
|
||||||
|
* It can also give multiple fmtp attribute lines. (silk does)
|
||||||
|
*/
|
||||||
tmp = strchr(ast_str_buffer(fmtp0), ':');
|
tmp = strchr(ast_str_buffer(fmtp0), ':');
|
||||||
if (tmp && tmp[1] != '\0') {
|
if (tmp && tmp[1] != '\0') {
|
||||||
tmp++;
|
tmp++;
|
||||||
@@ -455,7 +461,10 @@ static int sdp_m_add_fmtp(struct ast_sdp_m_line *m_line, const struct ast_format
|
|||||||
tmp = ast_str_buffer(fmtp0);
|
tmp = ast_str_buffer(fmtp0);
|
||||||
}
|
}
|
||||||
|
|
||||||
ast_sdp_m_add_a(m_line, ast_sdp_a_alloc("fmtp", tmp));
|
a_line = ast_sdp_a_alloc("fmtp", tmp);
|
||||||
|
if (!a_line || ast_sdp_m_add_a(m_line, a_line)) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -495,10 +504,8 @@ static int sdp_m_add_rtpmap(struct ast_sdp_m_line *m_line,
|
|||||||
int ast_sdp_m_add_format(struct ast_sdp_m_line *m_line, const struct ast_sdp_options *options,
|
int ast_sdp_m_add_format(struct ast_sdp_m_line *m_line, const struct ast_sdp_options *options,
|
||||||
int rtp_code, int asterisk_format, const struct ast_format *format, int code)
|
int rtp_code, int asterisk_format, const struct ast_format *format, int code)
|
||||||
{
|
{
|
||||||
sdp_m_add_rtpmap(m_line, options, rtp_code, asterisk_format, format, code);
|
return sdp_m_add_rtpmap(m_line, options, rtp_code, asterisk_format, format, code)
|
||||||
sdp_m_add_fmtp(m_line, format, rtp_code);
|
|| sdp_m_add_fmtp(m_line, format, rtp_code) ? -1 : 0;
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct ast_sdp_a_line *sdp_find_attribute_common(const struct ast_sdp_a_lines *a_lines,
|
static struct ast_sdp_a_line *sdp_find_attribute_common(const struct ast_sdp_a_lines *a_lines,
|
||||||
|
@@ -30,7 +30,7 @@
|
|||||||
#include "asterisk/codec.h"
|
#include "asterisk/codec.h"
|
||||||
#include "asterisk/udptl.h"
|
#include "asterisk/udptl.h"
|
||||||
|
|
||||||
#include "../include/asterisk/sdp.h"
|
#include "asterisk/sdp.h"
|
||||||
#include "asterisk/stream.h"
|
#include "asterisk/stream.h"
|
||||||
|
|
||||||
#include "sdp_private.h"
|
#include "sdp_private.h"
|
||||||
@@ -171,7 +171,7 @@ static struct ast_rtp_instance *create_rtp(const struct ast_sdp_options *options
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
ast_rtp_instance_set_prop(rtp, AST_RTP_PROPERTY_RTCP, 1);
|
ast_rtp_instance_set_prop(rtp, AST_RTP_PROPERTY_RTCP, AST_RTP_INSTANCE_RTCP_STANDARD);
|
||||||
ast_rtp_instance_set_prop(rtp, AST_RTP_PROPERTY_NAT, options->rtp_symmetric);
|
ast_rtp_instance_set_prop(rtp, AST_RTP_PROPERTY_NAT, options->rtp_symmetric);
|
||||||
|
|
||||||
if (options->ice == AST_SDP_ICE_DISABLED && (ice = ast_rtp_instance_get_ice(rtp))) {
|
if (options->ice == AST_SDP_ICE_DISABLED && (ice = ast_rtp_instance_get_ice(rtp))) {
|
||||||
@@ -252,8 +252,7 @@ static struct sdp_state_capabilities *sdp_initialize_state_capabilities(const st
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (AST_VECTOR_INIT(&capabilities->streams,
|
if (AST_VECTOR_INIT(&capabilities->streams, ast_stream_topology_get_count(topology))) {
|
||||||
ast_stream_topology_get_count(topology))) {
|
|
||||||
sdp_state_capabilities_free(capabilities);
|
sdp_state_capabilities_free(capabilities);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@@ -264,17 +263,18 @@ static struct sdp_state_capabilities *sdp_initialize_state_capabilities(const st
|
|||||||
|
|
||||||
state_stream = ast_calloc(1, sizeof(*state_stream));
|
state_stream = ast_calloc(1, sizeof(*state_stream));
|
||||||
if (!state_stream) {
|
if (!state_stream) {
|
||||||
|
sdp_state_capabilities_free(capabilities);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
state_stream->type = ast_stream_get_type(ast_stream_topology_get_stream(topology, i));
|
state_stream->type = ast_stream_get_type(ast_stream_topology_get_stream(topology, i));
|
||||||
|
|
||||||
switch (state_stream->type) {
|
switch (state_stream->type) {
|
||||||
case AST_MEDIA_TYPE_AUDIO:
|
case AST_MEDIA_TYPE_AUDIO:
|
||||||
case AST_MEDIA_TYPE_VIDEO:
|
case AST_MEDIA_TYPE_VIDEO:
|
||||||
state_stream->instance = create_rtp(options, state_stream->type);
|
state_stream->instance = create_rtp(options, state_stream->type);
|
||||||
if (!state_stream->instance) {
|
if (!state_stream->instance) {
|
||||||
sdp_state_stream_free(state_stream);
|
sdp_state_stream_free(state_stream);
|
||||||
|
sdp_state_capabilities_free(capabilities);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -282,16 +282,24 @@ static struct sdp_state_capabilities *sdp_initialize_state_capabilities(const st
|
|||||||
state_stream->udptl = create_udptl(options);
|
state_stream->udptl = create_udptl(options);
|
||||||
if (!state_stream->udptl) {
|
if (!state_stream->udptl) {
|
||||||
sdp_state_stream_free(state_stream);
|
sdp_state_stream_free(state_stream);
|
||||||
|
sdp_state_capabilities_free(capabilities);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case AST_MEDIA_TYPE_UNKNOWN:
|
case AST_MEDIA_TYPE_UNKNOWN:
|
||||||
case AST_MEDIA_TYPE_TEXT:
|
case AST_MEDIA_TYPE_TEXT:
|
||||||
case AST_MEDIA_TYPE_END:
|
case AST_MEDIA_TYPE_END:
|
||||||
break;
|
ast_assert(0);
|
||||||
|
sdp_state_stream_free(state_stream);
|
||||||
|
sdp_state_capabilities_free(capabilities);
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
AST_VECTOR_APPEND(&capabilities->streams, state_stream);
|
if (AST_VECTOR_APPEND(&capabilities->streams, state_stream)) {
|
||||||
|
sdp_state_stream_free(state_stream);
|
||||||
|
sdp_state_capabilities_free(capabilities);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return capabilities;
|
return capabilities;
|
||||||
@@ -632,7 +640,9 @@ static struct sdp_state_capabilities *merge_capabilities(const struct sdp_state_
|
|||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
AST_VECTOR_INIT(&joint_capabilities->streams, AST_VECTOR_SIZE(¤t->streams));
|
if (AST_VECTOR_INIT(&joint_capabilities->streams, AST_VECTOR_SIZE(¤t->streams))) {
|
||||||
|
goto fail;
|
||||||
|
}
|
||||||
ast_sockaddr_copy(&joint_capabilities->connection_address, ¤t->connection_address);
|
ast_sockaddr_copy(&joint_capabilities->connection_address, ¤t->connection_address);
|
||||||
topology = current->topology;
|
topology = current->topology;
|
||||||
|
|
||||||
@@ -654,11 +664,11 @@ static struct sdp_state_capabilities *merge_capabilities(const struct sdp_state_
|
|||||||
new_stream_type = ast_stream_get_type(new_stream);
|
new_stream_type = ast_stream_get_type(new_stream);
|
||||||
|
|
||||||
current_index = get_corresponding_index(topology, new_stream_type, media_indices);
|
current_index = get_corresponding_index(topology, new_stream_type, media_indices);
|
||||||
|
|
||||||
if (current_index >= 0) {
|
if (current_index >= 0) {
|
||||||
current_stream = ast_stream_topology_get_stream(topology, current_index);
|
current_stream = ast_stream_topology_get_stream(topology, current_index);
|
||||||
joint_stream = merge_streams(current_stream, new_stream);
|
joint_stream = merge_streams(current_stream, new_stream);
|
||||||
if (!joint_stream) {
|
if (!joint_stream) {
|
||||||
|
sdp_state_stream_free(joint_state_stream);
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -692,6 +702,7 @@ static struct sdp_state_capabilities *merge_capabilities(const struct sdp_state_
|
|||||||
*/
|
*/
|
||||||
joint_stream = ast_stream_clone(new_stream);
|
joint_stream = ast_stream_clone(new_stream);
|
||||||
if (!joint_stream) {
|
if (!joint_stream) {
|
||||||
|
sdp_state_stream_free(joint_state_stream);
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -700,12 +711,16 @@ static struct sdp_state_capabilities *merge_capabilities(const struct sdp_state_
|
|||||||
case AST_MEDIA_TYPE_VIDEO:
|
case AST_MEDIA_TYPE_VIDEO:
|
||||||
joint_state_stream->instance = create_rtp(options, new_stream_type);
|
joint_state_stream->instance = create_rtp(options, new_stream_type);
|
||||||
if (!joint_state_stream->instance) {
|
if (!joint_state_stream->instance) {
|
||||||
|
ast_stream_free(joint_stream);
|
||||||
|
sdp_state_stream_free(joint_state_stream);
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case AST_MEDIA_TYPE_IMAGE:
|
case AST_MEDIA_TYPE_IMAGE:
|
||||||
joint_state_stream->udptl = create_udptl(options);
|
joint_state_stream->udptl = create_udptl(options);
|
||||||
if (!joint_state_stream->udptl) {
|
if (!joint_state_stream->udptl) {
|
||||||
|
ast_stream_free(joint_stream);
|
||||||
|
sdp_state_stream_free(joint_state_stream);
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -723,12 +738,20 @@ static struct sdp_state_capabilities *merge_capabilities(const struct sdp_state_
|
|||||||
*/
|
*/
|
||||||
joint_stream = ast_stream_alloc("dummy", new_stream_type);
|
joint_stream = ast_stream_alloc("dummy", new_stream_type);
|
||||||
if (!joint_stream) {
|
if (!joint_stream) {
|
||||||
|
sdp_state_stream_free(joint_state_stream);
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ast_stream_topology_append_stream(joint_capabilities->topology, joint_stream);
|
if (ast_stream_topology_append_stream(joint_capabilities->topology, joint_stream) < 0) {
|
||||||
AST_VECTOR_APPEND(&joint_capabilities->streams, joint_state_stream);
|
ast_stream_free(joint_stream);
|
||||||
|
sdp_state_stream_free(joint_state_stream);
|
||||||
|
goto fail;
|
||||||
|
}
|
||||||
|
if (AST_VECTOR_APPEND(&joint_capabilities->streams, joint_state_stream)) {
|
||||||
|
sdp_state_stream_free(joint_state_stream);
|
||||||
|
goto fail;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return joint_capabilities;
|
return joint_capabilities;
|
||||||
@@ -974,8 +997,7 @@ static struct ast_sdp *sdp_create_from_state(const struct ast_sdp_state *sdp_sta
|
|||||||
* \retval -1 Failure
|
* \retval -1 Failure
|
||||||
* \retval 0 Success
|
* \retval 0 Success
|
||||||
*/
|
*/
|
||||||
static int merge_sdps(struct ast_sdp_state *sdp_state,
|
static int merge_sdps(struct ast_sdp_state *sdp_state, const struct ast_sdp *remote_sdp)
|
||||||
const struct ast_sdp *remote_sdp)
|
|
||||||
{
|
{
|
||||||
struct sdp_state_capabilities *joint_capabilities;
|
struct sdp_state_capabilities *joint_capabilities;
|
||||||
int i;
|
int i;
|
||||||
@@ -1073,7 +1095,7 @@ int ast_sdp_state_set_remote_sdp_from_impl(struct ast_sdp_state *sdp_state, void
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
ast_sdp_state_set_remote_sdp(sdp_state, sdp);
|
ast_sdp_state_set_remote_sdp(sdp_state, sdp);
|
||||||
|
ast_sdp_free(sdp);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1254,13 +1276,13 @@ static int sdp_add_m_from_rtp_stream(struct ast_sdp *sdp, const struct ast_sdp_s
|
|||||||
|
|
||||||
rtp_code = ast_rtp_codecs_payload_code(
|
rtp_code = ast_rtp_codecs_payload_code(
|
||||||
ast_rtp_instance_get_codecs(rtp), 0, NULL, i);
|
ast_rtp_instance_get_codecs(rtp), 0, NULL, i);
|
||||||
|
|
||||||
if (rtp_code == -1) {
|
if (rtp_code == -1) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ast_sdp_m_add_format(m_line, options, rtp_code, 0, NULL, i)) {
|
if (ast_sdp_m_add_format(m_line, options, rtp_code, 0, NULL, i)) {
|
||||||
continue;
|
ast_sdp_m_free(m_line);
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (i == AST_RTP_DTMF) {
|
if (i == AST_RTP_DTMF) {
|
||||||
@@ -1276,6 +1298,7 @@ static int sdp_add_m_from_rtp_stream(struct ast_sdp *sdp, const struct ast_sdp_s
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (ast_sdp_m_get_a_count(m_line) == 0) {
|
if (ast_sdp_m_get_a_count(m_line) == 0) {
|
||||||
|
ast_sdp_m_free(m_line);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -84,6 +84,9 @@ struct ast_sdp_translator *ast_sdp_translator_new(enum ast_sdp_options_impl repr
|
|||||||
|
|
||||||
void ast_sdp_translator_free(struct ast_sdp_translator *translator)
|
void ast_sdp_translator_free(struct ast_sdp_translator *translator)
|
||||||
{
|
{
|
||||||
|
if (!translator) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
translator->ops->translator_free(translator->translator_priv);
|
translator->ops->translator_free(translator->translator_priv);
|
||||||
ast_free(translator);
|
ast_free(translator);
|
||||||
}
|
}
|
||||||
|
@@ -26,7 +26,7 @@
|
|||||||
#include "asterisk/test.h"
|
#include "asterisk/test.h"
|
||||||
#include "asterisk/module.h"
|
#include "asterisk/module.h"
|
||||||
|
|
||||||
#include "../include/asterisk/sdp.h"
|
#include "asterisk/sdp.h"
|
||||||
#ifdef HAVE_PJPROJECT
|
#ifdef HAVE_PJPROJECT
|
||||||
#include <pjlib.h>
|
#include <pjlib.h>
|
||||||
#include <pjmedia.h>
|
#include <pjmedia.h>
|
||||||
|
Reference in New Issue
Block a user