diff -ru asterisk-11.5.0/channels/chan_sip.c asterisk-11.5.0.new/channels/chan_sip.c --- asterisk-11.5.0/channels/chan_sip.c 2013-05-13 23:05:38.000000000 +0200 +++ asterisk-11.5.0.new/channels/chan_sip.c 2013-08-05 21:52:34.806158287 +0200 @@ -13193,7 +13193,7 @@ /* Prefer the audio codec we were requested to use, first, no matter what Note that p->prefcodec can include video codecs, so mask them out */ - if (ast_format_cap_has_joint(tmpcap, p->prefcaps)) { + if (ast_format_cap_has_joint_type(tmpcap, p->prefcaps, AST_FORMAT_TYPE_AUDIO)) { ast_format_cap_iter_start(p->prefcaps); while (!(ast_format_cap_iter_next(p->prefcaps, &tmp_fmt))) { if (AST_FORMAT_GET_TYPE(tmp_fmt.id) != AST_FORMAT_TYPE_AUDIO) { diff -ru asterisk-11.5.0/include/asterisk/format_cap.h asterisk-11.5.0.new/include/asterisk/format_cap.h --- asterisk-11.5.0/include/asterisk/format_cap.h 2011-02-23 00:04:49.000000000 +0100 +++ asterisk-11.5.0.new/include/asterisk/format_cap.h 2013-08-05 21:51:20.678701341 +0200 @@ -226,6 +226,15 @@ int ast_format_cap_has_joint(const struct ast_format_cap *cap1, const struct ast_format_cap *cap2); /*! + * \brief Find out if capability structures have any joint capabilities of the + * given type without returning those capabilities. + * + * \retval 1 true, has joint capabilities + * \retval 0 false, failure + */ +int ast_format_cap_has_joint_type(const struct ast_format_cap *cap1, const struct ast_format_cap *cap2, const enum ast_format_type type); + +/*! * \brief Get all capabilities for a specific media type * * \retval !NULL success, new capabilities structure with _NO_ locking enabled on the new structure. diff -ru asterisk-11.5.0/main/format_cap.c asterisk-11.5.0.new/main/format_cap.c --- asterisk-11.5.0/main/format_cap.c 2012-06-15 18:20:16.000000000 +0200 +++ asterisk-11.5.0.new/main/format_cap.c 2013-08-05 21:51:47.406505645 +0200 @@ -408,6 +408,31 @@ return data.joint_found ? 1 : 0; } +int ast_format_cap_has_joint_type(const struct ast_format_cap *cap1, const struct ast_format_cap *cap2, const enum ast_format_type type) +{ + struct ao2_iterator it; + struct ast_format *tmp; + struct find_joint_data data = { + .joint_found = 0, + .joint_cap = NULL, + }; + + it = ao2_iterator_init(cap1->formats, 0); + while ((tmp = ao2_iterator_next(&it))) { + if (AST_FORMAT_GET_TYPE(tmp->id) == type) { + data.format = tmp; + ao2_callback(cap2->formats, + OBJ_MULTIPLE | OBJ_NODATA, + find_joint_cb, + &data); + } + ao2_ref(tmp, -1); + } + ao2_iterator_destroy(&it); + + return data.joint_found ? 1 : 0; +} + int ast_format_cap_identical(const struct ast_format_cap *cap1, const struct ast_format_cap *cap2) { struct ao2_iterator it;