[asterisk-commits] kharwell: branch kharwell/pimp_sip_media_neg r386612 - /team/kharwell/pimp_si...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Fri Apr 26 09:47:29 CDT 2013
Author: kharwell
Date: Fri Apr 26 09:47:25 2013
New Revision: 386612
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=386612
Log:
addressed review items
Modified:
team/kharwell/pimp_sip_media_neg/channels/chan_gulp.c
Modified: team/kharwell/pimp_sip_media_neg/channels/chan_gulp.c
URL: http://svnview.digium.com/svn/asterisk/team/kharwell/pimp_sip_media_neg/channels/chan_gulp.c?view=diff&rev=386612&r1=386611&r2=386612
==============================================================================
--- team/kharwell/pimp_sip_media_neg/channels/chan_gulp.c (original)
+++ team/kharwell/pimp_sip_media_neg/channels/chan_gulp.c Fri Apr 26 09:47:25 2013
@@ -79,7 +79,7 @@
</function>
<function name="MEDIA_OFFER" language="en_US">
<synopsis>
- Media and codec offerings to be set on an outbound channel prior to dialing.
+ Media and codec offerings to be set on an outbound SIP channel prior to dialing.
</synopsis>
<syntax>
<parameter name="media" required="true">
@@ -275,6 +275,7 @@
name = ast_getformatname(&fmt);
if (ast_strlen_zero(name)) {
+ ast_log(LOG_WARNING, "MEDIA_OFFER unrecognized format %s\n", name);
continue;
}
@@ -284,9 +285,11 @@
if ((len) < 0) {
break;
}
-
- strncat(buf, name, size);
- strncat(buf, ",", 1);
+
+ /* no reason to use strncat here since we have already ensured buf has
+ enough space, so strcat can be safely used */
+ strcat(buf, name);
+ strcat(buf, ",");
}
if (size) {
@@ -296,19 +299,50 @@
return 0;
}
-static int media_offer_write_av(struct ast_sip_session *session, const char *value,
- enum ast_format_type media_type)
-{
+struct media_offer_data {
+ struct ast_sip_session *session;
+ enum ast_format_type media_type;
+ char value[0];
+};
+
+static void media_offer_data_destroy(void *obj)
+{
+ struct media_offer_data *data = obj;
+ ao2_ref(data->session, -1);
+}
+
+static struct media_offer_data* media_offer_data_create(struct ast_sip_session *session, const char *value,
+ enum ast_format_type media_type)
+{
+ int size = strlen(value) + 1;
+ struct media_offer_data *data = ao2_alloc(sizeof(*data)+size, media_offer_data_destroy);
+
+ if (!data) {
+ return NULL;
+ }
+
+ data->session = session;
+ data->media_type = media_type;
+ ast_copy_string(data->value, value, size);
+
+ ao2_ref(data->session, +1);
+ return data;
+}
+
+static int media_offer_write_av(void *obj)
+{
+ RAII_VAR(struct media_offer_data *, data, obj, ao2_cleanup);
+
int i;
struct ast_format fmt;
/* remove all of the given media type first */
- for (i = 0; ast_codec_pref_index(&session->override_prefs, i, &fmt); ++i) {
- if (AST_FORMAT_GET_TYPE(fmt.id) == media_type) {
- ast_codec_pref_remove(&session->override_prefs, &fmt);
- }
- }
- ast_format_cap_remove_bytype(session->req_caps, media_type);
- ast_parse_allow_disallow(&session->override_prefs, session->req_caps, value, 1);
+ for (i = 0; ast_codec_pref_index(&data->session->override_prefs, i, &fmt); ++i) {
+ if (AST_FORMAT_GET_TYPE(fmt.id) == data->media_type) {
+ ast_codec_pref_remove(&data->session->override_prefs, &fmt);
+ }
+ }
+ ast_format_cap_remove_bytype(data->session->req_caps, data->media_type);
+ ast_parse_allow_disallow(&data->session->override_prefs, data->session->req_caps, data->value, 1);
return 0;
}
@@ -329,13 +363,18 @@
static int media_offer_write(struct ast_channel *chan, const char *cmd, char *data, const char *value)
{
struct gulp_pvt *pvt = ast_channel_tech_pvt(chan);
+ struct media_offer_data *mdata = NULL;
if (!strcmp(data, "audio")) {
- return media_offer_write_av(pvt->session, value, AST_FORMAT_TYPE_AUDIO);
+ mdata = media_offer_data_create(pvt->session, value, AST_FORMAT_TYPE_AUDIO);
} else if (!strcmp(data, "video")) {
- return media_offer_write_av(pvt->session, value, AST_FORMAT_TYPE_VIDEO);
- }
-
+ mdata = media_offer_data_create(pvt->session, value, AST_FORMAT_TYPE_VIDEO);
+ }
+
+ if (mdata && ast_sip_push_task_synchronous(pvt->session->serializer, media_offer_write_av, mdata)) {
+ ao2_ref(mdata, -1);
+ return -1;
+ }
return 0;
}
More information about the asterisk-commits
mailing list