diff options
author | Joshua Colp <jcolp@digium.com> | 2012-08-07 13:07:58 +0000 |
---|---|---|
committer | Joshua Colp <jcolp@digium.com> | 2012-08-07 13:07:58 +0000 |
commit | 15e41c7542fba77244ec709a76c49efdc74d450e (patch) | |
tree | 08a86fa9d8e990a70f46121e79ed348b44cc0a33 /channels/chan_sip.c | |
parent | 5c4578f4ad9af0d13638ec72a2bc141227ec8b3c (diff) |
Reduce memory consumption significantly for users of the RTP engine API by storing only the payloads present and in use instead of every possible one.
Review: https://reviewboard.asterisk.org/r/2052/
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@370832 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'channels/chan_sip.c')
-rw-r--r-- | channels/chan_sip.c | 48 |
1 files changed, 21 insertions, 27 deletions
diff --git a/channels/chan_sip.c b/channels/chan_sip.c index b002254ef..b65390aac 100644 --- a/channels/chan_sip.c +++ b/channels/chan_sip.c @@ -9450,7 +9450,7 @@ static int process_sdp(struct sip_pvt *p, struct sip_request *req, int t38action int peernoncodeccapability = 0, vpeernoncodeccapability = 0, tpeernoncodeccapability = 0; - struct ast_rtp_codecs *newaudiortp = NULL, *newvideortp = NULL, *newtextrtp = NULL; + struct ast_rtp_codecs newaudiortp = { 0, }, newvideortp = { 0, }, newtextrtp = { 0, }; struct ast_format_cap *newjointcapability = ast_format_cap_alloc_nolock(); /* Negotiated capability */ struct ast_format_cap *newpeercapability = ast_format_cap_alloc_nolock(); int newnoncodeccapability; @@ -9487,8 +9487,8 @@ static int process_sdp(struct sip_pvt *p, struct sip_request *req, int t38action goto process_sdp_cleanup; } - if (!(newaudiortp = ast_calloc(1, sizeof(*newaudiortp))) || !(newvideortp = ast_calloc(1, sizeof(*newvideortp))) || - !(newtextrtp = ast_calloc(1, sizeof(*newtextrtp)))) { + if (ast_rtp_codecs_payloads_initialize(&newaudiortp) || ast_rtp_codecs_payloads_initialize(&newvideortp) || + ast_rtp_codecs_payloads_initialize(&newtextrtp)) { res = -1; goto process_sdp_cleanup; } @@ -9532,11 +9532,11 @@ static int process_sdp(struct sip_pvt *p, struct sip_request *req, int t38action if (process_sdp_a_sendonly(value, &sendonly)) { processed = TRUE; } - else if (process_sdp_a_audio(value, p, newaudiortp, &last_rtpmap_codec)) + else if (process_sdp_a_audio(value, p, &newaudiortp, &last_rtpmap_codec)) processed = TRUE; - else if (process_sdp_a_video(value, p, newvideortp, &last_rtpmap_codec)) + else if (process_sdp_a_video(value, p, &newvideortp, &last_rtpmap_codec)) processed = TRUE; - else if (process_sdp_a_text(value, p, newtextrtp, red_fmtp, &red_num_gen, red_data_pt, &last_rtpmap_codec)) + else if (process_sdp_a_text(value, p, &newtextrtp, red_fmtp, &red_num_gen, red_data_pt, &last_rtpmap_codec)) processed = TRUE; else if (process_sdp_a_image(value, p)) processed = TRUE; @@ -9650,7 +9650,7 @@ static int process_sdp(struct sip_pvt *p, struct sip_request *req, int t38action ast_verbose("Found RTP audio format %d\n", codec); } - ast_rtp_codecs_payloads_set_m_type(newaudiortp, NULL, codec); + ast_rtp_codecs_payloads_set_m_type(&newaudiortp, NULL, codec); } } else { ast_log(LOG_WARNING, "Rejecting audio media offer due to invalid or unsupported syntax: %s\n", m); @@ -9722,7 +9722,7 @@ static int process_sdp(struct sip_pvt *p, struct sip_request *req, int t38action if (debug) { ast_verbose("Found RTP video format %d\n", codec); } - ast_rtp_codecs_payloads_set_m_type(newvideortp, NULL, codec); + ast_rtp_codecs_payloads_set_m_type(&newvideortp, NULL, codec); } } else { ast_log(LOG_WARNING, "Rejecting video media offer due to invalid or unsupported syntax: %s\n", m); @@ -9786,7 +9786,7 @@ static int process_sdp(struct sip_pvt *p, struct sip_request *req, int t38action if (debug) { ast_verbose("Found RTP text format %d\n", codec); } - ast_rtp_codecs_payloads_set_m_type(newtextrtp, NULL, codec); + ast_rtp_codecs_payloads_set_m_type(&newtextrtp, NULL, codec); } } else { ast_log(LOG_WARNING, "Rejecting text stream offer due to invalid or unsupported syntax: %s\n", m); @@ -9904,7 +9904,7 @@ static int process_sdp(struct sip_pvt *p, struct sip_request *req, int t38action } else if (!processed_crypto && process_crypto(p, p->rtp, &p->srtp, value)) { processed_crypto = TRUE; processed = TRUE; - } else if (process_sdp_a_audio(value, p, newaudiortp, &last_rtpmap_codec)) { + } else if (process_sdp_a_audio(value, p, &newaudiortp, &last_rtpmap_codec)) { processed = TRUE; } } @@ -9915,7 +9915,7 @@ static int process_sdp(struct sip_pvt *p, struct sip_request *req, int t38action } else if (!processed_crypto && process_crypto(p, p->vrtp, &p->vsrtp, value)) { processed_crypto = TRUE; processed = TRUE; - } else if (process_sdp_a_video(value, p, newvideortp, &last_rtpmap_codec)) { + } else if (process_sdp_a_video(value, p, &newvideortp, &last_rtpmap_codec)) { processed = TRUE; } } @@ -9923,7 +9923,7 @@ static int process_sdp(struct sip_pvt *p, struct sip_request *req, int t38action else if (text) { if (process_sdp_a_ice(value, p, p->trtp)) { processed = TRUE; - } if (process_sdp_a_text(value, p, newtextrtp, red_fmtp, &red_num_gen, red_data_pt, &last_rtpmap_codec)) { + } if (process_sdp_a_text(value, p, &newtextrtp, red_fmtp, &red_num_gen, red_data_pt, &last_rtpmap_codec)) { processed = TRUE; } else if (!processed_crypto && process_crypto(p, p->trtp, &p->tsrtp, value)) { processed_crypto = TRUE; @@ -9996,9 +9996,9 @@ static int process_sdp(struct sip_pvt *p, struct sip_request *req, int t38action } /* Now gather all of the codecs that we are asked for: */ - ast_rtp_codecs_payload_formats(newaudiortp, peercapability, &peernoncodeccapability); - ast_rtp_codecs_payload_formats(newvideortp, vpeercapability, &vpeernoncodeccapability); - ast_rtp_codecs_payload_formats(newtextrtp, tpeercapability, &tpeernoncodeccapability); + ast_rtp_codecs_payload_formats(&newaudiortp, peercapability, &peernoncodeccapability); + ast_rtp_codecs_payload_formats(&newvideortp, vpeercapability, &vpeernoncodeccapability); + ast_rtp_codecs_payload_formats(&newtextrtp, tpeercapability, &tpeernoncodeccapability); ast_format_cap_append(newpeercapability, peercapability); ast_format_cap_append(newpeercapability, vpeercapability); @@ -10061,7 +10061,7 @@ static int process_sdp(struct sip_pvt *p, struct sip_request *req, int t38action ast_sockaddr_stringify(sa)); } - ast_rtp_codecs_payloads_copy(newaudiortp, ast_rtp_instance_get_codecs(p->rtp), p->rtp); + ast_rtp_codecs_payloads_copy(&newaudiortp, ast_rtp_instance_get_codecs(p->rtp), p->rtp); /* Ensure RTCP is enabled since it may be inactive if we're coming back from a T.38 session */ ast_rtp_instance_set_prop(p->rtp, AST_RTP_PROPERTY_RTCP, 1); @@ -10108,7 +10108,7 @@ static int process_sdp(struct sip_pvt *p, struct sip_request *req, int t38action ast_verbose("Peer video RTP is at port %s\n", ast_sockaddr_stringify(vsa)); } - ast_rtp_codecs_payloads_copy(newvideortp, ast_rtp_instance_get_codecs(p->vrtp), p->vrtp); + ast_rtp_codecs_payloads_copy(&newvideortp, ast_rtp_instance_get_codecs(p->vrtp), p->vrtp); } else { ast_rtp_instance_stop(p->vrtp); if (debug) @@ -10132,7 +10132,7 @@ static int process_sdp(struct sip_pvt *p, struct sip_request *req, int t38action } else { p->red = 0; } - ast_rtp_codecs_payloads_copy(newtextrtp, ast_rtp_instance_get_codecs(p->trtp), p->trtp); + ast_rtp_codecs_payloads_copy(&newtextrtp, ast_rtp_instance_get_codecs(p->trtp), p->trtp); } else { ast_rtp_instance_stop(p->trtp); if (debug) @@ -10250,15 +10250,9 @@ process_sdp_cleanup: if (res) { offered_media_list_destroy(p); } - if (newtextrtp) { - ast_free(newtextrtp); - } - if (newvideortp) { - ast_free(newvideortp); - } - if (newaudiortp) { - ast_free(newaudiortp); - } + ast_rtp_codecs_payloads_destroy(&newtextrtp); + ast_rtp_codecs_payloads_destroy(&newvideortp); + ast_rtp_codecs_payloads_destroy(&newaudiortp); ast_format_cap_destroy(peercapability); ast_format_cap_destroy(vpeercapability); ast_format_cap_destroy(tpeercapability); |