[asterisk-commits] kharwell: branch kharwell/pimp_sip_media_neg r385380 - in /team/kharwell/pimp...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Thu Apr 11 16:47:40 CDT 2013
Author: kharwell
Date: Thu Apr 11 16:47:36 2013
New Revision: 385380
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=385380
Log:
changed media offer codecs to a pref structure so ordering would work correctly
Modified:
team/kharwell/pimp_sip_media_neg/channels/chan_gulp.c
team/kharwell/pimp_sip_media_neg/include/asterisk/res_sip_session.h
team/kharwell/pimp_sip_media_neg/res/res_sip_sdp_rtp.c
team/kharwell/pimp_sip_media_neg/res/res_sip_session.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=385380&r1=385379&r2=385380
==============================================================================
--- team/kharwell/pimp_sip_media_neg/channels/chan_gulp.c (original)
+++ team/kharwell/pimp_sip_media_neg/channels/chan_gulp.c Thu Apr 11 16:47:36 2013
@@ -297,10 +297,6 @@
struct gulp_pvt *pvt = ast_channel_tech_pvt(chan);
struct media_offering *i;
- if (!pvt->session->offer_caps) {
- return 0;
- }
-
AST_LIST_TRAVERSE(&media_offerings, i, next) {
if (!strcmp(data, i->name) && i->get) {
return i->get(pvt->session, buf, len);
@@ -315,10 +311,6 @@
{
struct gulp_pvt *pvt = ast_channel_tech_pvt(chan);
struct media_offering *i;
-
- if (!pvt->session->offer_caps) {
- pvt->session->offer_caps = ast_format_cap_alloc_nolock();
- }
AST_LIST_TRAVERSE(&media_offerings, i, next) {
if (!strcmp(data, i->name) && i->set) {
@@ -338,12 +330,11 @@
static int media_offer_av_get(struct ast_sip_session *session, char *buf, size_t len, enum ast_format_type media_type)
{
+ int i, size = 0;
struct ast_format fmt;
const char *name;
- int size = 0;
-
- ast_format_cap_iter_start(session->offer_caps);
- while (!ast_format_cap_iter_next(session->offer_caps, &fmt)) {
+
+ for (i = 0; ast_codec_pref_index(&session->override_prefs, i, &fmt); ++i) {
if (AST_FORMAT_GET_TYPE(fmt.id) != media_type) {
continue;
}
@@ -364,19 +355,59 @@
strncat(buf, name, size);
strncat(buf, ",", 1);
}
- ast_format_cap_iter_end(session->offer_caps);
-
+
if (size) {
/* remove the extra comma */
buf[strlen(buf) - 1] = '\0';
}
return 0;
+
+ /* struct ast_format fmt; */
+ /* const char *name; */
+ /* int size = 0; */
+
+ /* ast_format_cap_iter_start(session->offer_caps); */
+ /* while (!ast_format_cap_iter_next(session->offer_caps, &fmt)) { */
+ /* if (AST_FORMAT_GET_TYPE(fmt.id) != media_type) { */
+ /* continue; */
+ /* } */
+
+ /* name = ast_rtp_lookup_mime_subtype2(1, &fmt, 0, 0); */
+
+ /* if (ast_strlen_zero(name)) { */
+ /* continue; */
+ /* } */
+
+ /* /\* add one since we'll include a comma *\/ */
+ /* size = strlen(name) + 1; */
+ /* len -= size; */
+ /* if ((len) < 0) { */
+ /* break; */
+ /* } */
+
+ /* strncat(buf, name, size); */
+ /* strncat(buf, ",", 1); */
+ /* } */
+ /* ast_format_cap_iter_end(session->offer_caps); */
+
+ /* if (size) { */
+ /* /\* remove the extra comma *\/ */
+ /* buf[strlen(buf) - 1] = '\0'; */
+ /* } */
+ /* return 0; */
}
static int media_offer_av_set(struct ast_sip_session *session, const char *value, enum ast_format_type media_type)
{
- ast_format_cap_remove_bytype(session->offer_caps, media_type);
- ast_parse_allow_disallow(NULL, session->offer_caps, value, 1);
+ 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_parse_allow_disallow(&session->override_prefs, NULL, value, 1);
return 0;
}
Modified: team/kharwell/pimp_sip_media_neg/include/asterisk/res_sip_session.h
URL: http://svnview.digium.com/svn/asterisk/team/kharwell/pimp_sip_media_neg/include/asterisk/res_sip_session.h?view=diff&rev=385380&r1=385379&r2=385380
==============================================================================
--- team/kharwell/pimp_sip_media_neg/include/asterisk/res_sip_session.h (original)
+++ team/kharwell/pimp_sip_media_neg/include/asterisk/res_sip_session.h Thu Apr 11 16:47:36 2013
@@ -101,8 +101,8 @@
struct ast_party_id id;
/* Requested capabilities */
struct ast_format_cap *req_caps;
- /* Capabilities offered by dialplan for an outgoing request */
- struct ast_format_cap *offer_caps;
+ /* Codecs overriden by dialplan on an outgoing request */
+ struct ast_codec_pref override_prefs;
};
typedef int (*ast_sip_session_request_creation_cb)(struct ast_sip_session *session, pjsip_tx_data *tdata);
Modified: team/kharwell/pimp_sip_media_neg/res/res_sip_sdp_rtp.c
URL: http://svnview.digium.com/svn/asterisk/team/kharwell/pimp_sip_media_neg/res/res_sip_sdp_rtp.c?view=diff&rev=385380&r1=385379&r2=385380
==============================================================================
--- team/kharwell/pimp_sip_media_neg/res/res_sip_sdp_rtp.c (original)
+++ team/kharwell/pimp_sip_media_neg/res/res_sip_sdp_rtp.c Thu Apr 11 16:47:36 2013
@@ -286,76 +286,16 @@
return attr;
}
-/*! \brief Generates an attribute based up on the given ast format */
-static int generate_attr(pj_pool_t *pool, pjmedia_sdp_media *media, enum ast_format_type media_type,
- struct ast_rtp_codecs *codecs, struct ast_format *fmt, int *min_packet_size)
-{
- int rtp_code;
- pjmedia_sdp_attr *attr;
-
- if ((rtp_code = ast_rtp_codecs_payload_code(codecs, 1, fmt, 0)) == -1) {
- return -1;
- }
-
- if (!(attr = generate_rtpmap_attr(media, pool, rtp_code, 1, fmt, 0))) {
- return 0;
- }
-
- media->attr[media->attr_count++] = attr;
-
- if ((attr = generate_fmtp_attr(pool, fmt, rtp_code))) {
- media->attr[media->attr_count++] = attr;
- }
-
- if (&codecs->pref && media_type != AST_FORMAT_TYPE_VIDEO) {
- struct ast_format_list list = ast_codec_pref_getsize(&codecs->pref, fmt);
- if (list.cur_ms && ((list.cur_ms < *min_packet_size) || !*min_packet_size)) {
- *min_packet_size = list.cur_ms;
- }
- }
- return 0;
-}
-
-/*! \brief Converts the given capabilities to media attributes */
-static int caps_to_attrs(pj_pool_t *pool, pjmedia_sdp_media *media, enum ast_format_type media_type,
- struct ast_rtp_codecs *codecs, struct ast_format_cap *caps,
- int *min_packet_size, struct ast_sip_session *session)
+static int codec_pref_has_type(struct ast_codec_pref *prefs, enum ast_format_type media_type)
{
int i;
struct ast_format fmt;
- struct ast_format compat_fmt;
-
- for (i = 0; ast_codec_pref_index(&session->endpoint->prefs, i, &fmt); ++i) {
- if ((AST_FORMAT_GET_TYPE(fmt.id) != media_type) ||
- (!ast_format_cap_get_compatible_format(caps, &fmt, &compat_fmt))) {
- continue;
- }
-
- if (generate_attr(pool, media, media_type, codecs, &compat_fmt, min_packet_size)) {
- return -1;
+ for (i = 0; ast_codec_pref_index(prefs, i, &fmt); ++i) {
+ if (AST_FORMAT_GET_TYPE(fmt.id) == media_type) {
+ return 1;
}
}
return 0;
-}
-
-/*! \brief Converts offered capabilities to media attributes */
-static int offer_caps_to_attrs(pj_pool_t *pool, pjmedia_sdp_media *media, enum ast_format_type media_type,
- struct ast_rtp_codecs *codecs, struct ast_format_cap *caps, int *min_packet_size)
-{
- int res = 0;
- struct ast_format fmt;
- ast_format_cap_iter_start(caps);
- while (!ast_format_cap_iter_next(caps, &fmt)) {
- if (AST_FORMAT_GET_TYPE(fmt.id) != media_type) {
- continue;
- }
-
- if ((res = generate_attr(pool, media, media_type, codecs, &fmt, min_packet_size))) {
- break;
- }
- }
- ast_format_cap_iter_end(caps);
- return res;
}
/*! \brief Function which adds ICE attributes to a media stream */
@@ -576,21 +516,21 @@
pjmedia_sdp_attr *attr;
int index = 0, min_packet_size = 0, noncodec = (session->endpoint->dtmf == AST_SIP_DTMF_RFC_4733) ? AST_RTP_DTMF : 0;
int rtp_code;
+ struct ast_format format;
RAII_VAR(struct ast_format_cap *, caps, NULL, ast_format_cap_destroy);
enum ast_format_type media_type = stream_to_media_type(session_media->stream_type);
int direct_media_enabled = !ast_sockaddr_isnull(&session_media->direct_media_addr) &&
!ast_format_cap_is_empty(session->direct_media_cap);
- int use_offer_caps = !ast_format_cap_is_empty(session->offer_caps);
-
- if ((use_offer_caps && !ast_format_cap_has_type(session->offer_caps, media_type)) ||
- (!use_offer_caps && !ast_format_cap_has_type(session->endpoint->codecs, media_type))) {
+ int use_override_prefs = session->override_prefs.formats[0].id;
+ struct ast_codec_pref *prefs = use_override_prefs ?
+ &session->override_prefs : &session->endpoint->prefs;
+
+ if ((use_override_prefs && !codec_pref_has_type(&session->override_prefs, media_type)) ||
+ (!use_override_prefs && !ast_format_cap_has_type(session->endpoint->codecs, media_type))) {
/* If no type formats are configured don't add a stream */
return 0;
- /* if (!ast_format_cap_has_type(session->endpoint->codecs, media_type)) { */
- /* /\* If no type formats are configured don't add a stream *\/ */
- /* return 0; */
} else if (!session_media->rtp && create_rtp(session, session_media, session->endpoint->rtp_ipv6)) {
return -1;
}
@@ -633,23 +573,44 @@
return -1;
}
- if (use_offer_caps) {
- if (offer_caps_to_attrs(pool, media, media_type, ast_rtp_instance_get_codecs(session_media->rtp),
- session->offer_caps, &min_packet_size)) {
+ if (direct_media_enabled) {
+ ast_format_cap_joint_copy(session->endpoint->codecs, session->direct_media_cap, caps);
+ } else if (ast_format_cap_is_empty(session->req_caps)) {
+ ast_format_cap_copy(caps, session->endpoint->codecs);
+ } else {
+ ast_format_cap_copy(caps, session->req_caps);
+ }
+
+ for (index = 0; ast_codec_pref_index(prefs, index, &format); ++index) {
+ struct ast_codec_pref *pref = &ast_rtp_instance_get_codecs(session_media->rtp)->pref;
+
+ if (AST_FORMAT_GET_TYPE(format.id) != media_type) {
+ continue;
+ }
+
+ if (!use_override_prefs && !ast_format_cap_get_compatible_format(caps, &format, &format)) {
+ continue;
+ }
+
+ if ((rtp_code = ast_rtp_codecs_payload_code(ast_rtp_instance_get_codecs(session_media->rtp), 1, &format, 0)) == -1) {
return -1;
}
- } else {
- if (direct_media_enabled) {
- ast_format_cap_joint_copy(session->endpoint->codecs, session->direct_media_cap, caps);
- } else if (ast_format_cap_is_empty(session->req_caps)) {
- ast_format_cap_copy(caps, session->endpoint->codecs);
- } else {
- ast_format_cap_joint_copy(session->endpoint->codecs, session->req_caps, caps);
- }
-
- if (caps_to_attrs(pool, media, media_type, ast_rtp_instance_get_codecs(session_media->rtp),
- caps, &min_packet_size, session)) {
- return -1;
+
+ if (!(attr = generate_rtpmap_attr(media, pool, rtp_code, 1, &format, 0))) {
+ continue;
+ }
+
+ media->attr[media->attr_count++] = attr;
+
+ if ((attr = generate_fmtp_attr(pool, &format, rtp_code))) {
+ media->attr[media->attr_count++] = attr;
+ }
+
+ if (pref && media_type != AST_FORMAT_TYPE_VIDEO) {
+ struct ast_format_list fmt = ast_codec_pref_getsize(pref, &format);
+ if (fmt.cur_ms && ((fmt.cur_ms < min_packet_size) || !min_packet_size)) {
+ min_packet_size = fmt.cur_ms;
+ }
}
}
Modified: team/kharwell/pimp_sip_media_neg/res/res_sip_session.c
URL: http://svnview.digium.com/svn/asterisk/team/kharwell/pimp_sip_media_neg/res/res_sip_session.c?view=diff&rev=385380&r1=385379&r2=385380
==============================================================================
--- team/kharwell/pimp_sip_media_neg/res/res_sip_session.c (original)
+++ team/kharwell/pimp_sip_media_neg/res/res_sip_session.c Thu Apr 11 16:47:36 2013
@@ -905,7 +905,6 @@
ast_party_id_free(&session->id);
ao2_cleanup(session->endpoint);
ast_format_cap_destroy(session->req_caps);
- ast_format_cap_destroy(session->offer_caps);
}
static int add_supplements(struct ast_sip_session *session)
More information about the asterisk-commits
mailing list