--- include/asterisk/format_cap.h (Asterisk 13.38.1) +++ include/asterisk/format_cap.h (working copy) @@ -149,6 +149,20 @@ int ast_format_cap_append_by_type(struct int ast_format_cap_append_from_cap(struct ast_format_cap *dst, const struct ast_format_cap *src, enum ast_media_type type); /*! + * \brief Append all formats except of provided type in src to dst + * + * \param dst The destination capabilities structure + * \param src The source capabilities structure + * \param type The type of formats not to append. + * + * \retval 0 success + * \retval -1 failure + * + * \note If AST_MEDIA_TYPE_UNKNOWN is passed as the type all codecs will be removed. + */ +int ast_format_cap_append_from_cap_except(struct ast_format_cap *dst, const struct ast_format_cap *src, enum ast_media_type type); + +/*! * \brief Replace the formats of provided type in dst with equivalent formats from src * * \param dst The destination capabilities structure --- main/format_cap.c (Asterisk 13.38.1) +++ main/format_cap.c (working copy) @@ -320,2 +320,18 @@ int ast_format_cap_append_from_cap(struc +int ast_format_cap_append_from_cap_except(struct ast_format_cap *dst, const struct ast_format_cap *src, + enum ast_media_type type) +{ + int idx, res = 0; + + for (idx = 0; (idx < AST_VECTOR_SIZE(&src->preference_order)) && !res; ++idx) { + struct format_cap_framed *framed = AST_VECTOR_GET(&src->preference_order, idx); + + if (ast_format_get_type(framed->format) != type) { + res = ast_format_cap_append(dst, framed->format, framed->framing); + } + } + + return res; +} + static int format_cap_replace(struct ast_format_cap *cap, struct ast_format *format, unsigned int framing) --- main/channel.c (Asterisk 13.38.1) +++ main/channel.c (working copy) @@ -6419,5 +6419,4 @@ struct ast_channel *ast_request(const ch } - ast_format_cap_append_from_cap(joint_cap, request_cap, AST_MEDIA_TYPE_UNKNOWN); - ast_format_cap_remove_by_type(joint_cap, AST_MEDIA_TYPE_AUDIO); ast_format_cap_append(joint_cap, best_audio_fmt, 0); + ast_format_cap_append_from_cap_except(joint_cap, request_cap, AST_MEDIA_TYPE_AUDIO);