[asterisk-commits] file: branch group/media_formats r406629 - in /team/group/media_formats: incl...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Mon Jan 27 06:51:34 CST 2014
Author: file
Date: Mon Jan 27 06:51:29 2014
New Revision: 406629
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=406629
Log:
Implement some of the removal functions.
Modified:
team/group/media_formats/include/asterisk/format_cap_ng.h
team/group/media_formats/main/format_cap_ng.c
Modified: team/group/media_formats/include/asterisk/format_cap_ng.h
URL: http://svnview.digium.com/svn/asterisk/team/group/media_formats/include/asterisk/format_cap_ng.h?view=diff&rev=406629&r1=406628&r2=406629
==============================================================================
--- team/group/media_formats/include/asterisk/format_cap_ng.h (original)
+++ team/group/media_formats/include/asterisk/format_cap_ng.h Mon Jan 27 06:51:29 2014
@@ -96,6 +96,46 @@
*
* \return the number of formats
*/
-size_t ast_format_cap_count(const struct ast_format_cap *cap);
+size_t ast_format_cap_count(const struct ast_format_cap *cap);
+
+/*!
+ * \brief Get the format at a specific position
+ *
+ * \param cap The capabilities structure
+ * \param position The position to get
+ *
+ * \retval non-NULL success
+ * \retval NULL failure
+ *
+ * \note The reference count of the returned format is increased. It must be released using ao2_ref
+ * or ao2_cleanup.
+ */
+struct ast_format *ast_format_cap_get_format(struct ast_format_cap *cap, int position);
+
+/*!
+ * \brief Remove format capability from capability structure.
+ *
+ * \note format must match Exactly to format in ast_format_cap object in order
+ * to be removed.
+ *
+ * \retval 0, remove was successful
+ * \retval -1, remove failed. Could not find format to remove
+ */
+int ast_format_cap_remove(struct ast_format_cap *cap, struct ast_format *format);
+
+/*!
+ * \brief Remove all formats matching a specific format type.
+ *
+ * \param cap The capabilities structure
+ * \param type The media type to remove formats of
+ */
+void ast_format_cap_remove_bytype(struct ast_format_cap *cap, enum ast_media_type type);
+
+/*!
+ * \brief Remove all format capabilities from capability structure
+ *
+ * \param cap The capabilities structure
+ */
+void ast_format_cap_remove_all(struct ast_format_cap *cap);
#endif /* _AST_FORMAT_CAP_H */
Modified: team/group/media_formats/main/format_cap_ng.c
URL: http://svnview.digium.com/svn/asterisk/team/group/media_formats/main/format_cap_ng.c?view=diff&rev=406629&r1=406628&r2=406629
==============================================================================
--- team/group/media_formats/main/format_cap_ng.c (original)
+++ team/group/media_formats/main/format_cap_ng.c Mon Jan 27 06:51:29 2014
@@ -80,6 +80,7 @@
ao2_ref(framed, -1);
}
}
+ AST_VECTOR_FREE(&cap->formats);
for (idx = 0; idx < AST_VECTOR_SIZE(&cap->preference_order); idx++) {
struct format_cap_framed *framed = AST_VECTOR_GET(&cap->preference_order, idx);
@@ -127,14 +128,13 @@
framed->format = ao2_bump(format);
- list = AST_VECTOR_GET_ADDR(&cap->formats, format->codec->id);
- if (!list) {
+ if (format->codec->id >= cap->formats.current) {
if (AST_VECTOR_INSERT(&cap->formats, format->codec->id, format_cap_framed_list_empty)) {
ao2_ref(framed, -1);
return -1;
}
- list = AST_VECTOR_GET_ADDR(&cap->formats, format->codec->id);
- }
+ }
+ list = AST_VECTOR_GET_ADDR(&cap->formats, format->codec->id);
/* Order doesn't matter for formats, so insert at the head for performance reasons */
ao2_ref(framed, +1);
@@ -167,4 +167,78 @@
size_t ast_format_cap_count(const struct ast_format_cap *cap)
{
return AST_VECTOR_SIZE(&cap->preference_order);
+}
+
+struct ast_format *ast_format_cap_get_format(struct ast_format_cap *cap, int position)
+{
+ struct format_cap_framed *framed;
+
+ if (position >= cap->preference_order.current) {
+ return NULL;
+ }
+
+ framed = AST_VECTOR_GET(&cap->preference_order, position);
+
+ ao2_ref(framed->format, +1);
+ return framed->format;
+}
+
+/*!
+ * \brief format_cap_framed comparator for AST_VECTOR_REMOVE_CMP_ORDERED()
+ *
+ * \param elem Element to compare against
+ * \param value Value to compare with the vector element.
+ *
+ * \return 0 if element does not match.
+ * \return Non-zero if element matches.
+ */
+#define FORMAT_CAP_FRAMED_ELEM_CMP(elem, value) ((elem)->format == (value))
+
+/*!
+ * \brief format_cap_framed vector element cleanup.
+ *
+ * \param elem Element to cleanup
+ *
+ * \return Nothing
+ */
+#define FORMAT_CAP_FRAMED_ELEM_CLEANUP(elem) ao2_cleanup((elem))
+
+int ast_format_cap_remove(struct ast_format_cap *cap, struct ast_format *format)
+{
+ struct format_cap_framed_list *list;
+ struct format_cap_framed *framed;
+
+ if (format->codec->id >= cap->formats.current) {
+ return -1;
+ }
+
+ list = AST_VECTOR_GET_ADDR(&cap->formats, format->codec->id);
+
+ AST_LIST_TRAVERSE_SAFE_BEGIN(list, framed, entry) {
+ if (!FORMAT_CAP_FRAMED_ELEM_CMP(framed, format)) {
+ continue;
+ }
+
+ AST_LIST_REMOVE_CURRENT(entry);
+ FORMAT_CAP_FRAMED_ELEM_CLEANUP(framed);
+ break;
+ }
+ AST_LIST_TRAVERSE_SAFE_END;
+
+ return AST_VECTOR_REMOVE_CMP_ORDERED(&cap->preference_order, format,
+ FORMAT_CAP_FRAMED_ELEM_CMP, FORMAT_CAP_FRAMED_ELEM_CLEANUP);
+}
+
+void ast_format_cap_remove_bytype(struct ast_format_cap *cap, enum ast_media_type type)
+{
+}
+
+void ast_format_cap_remove_all(struct ast_format_cap *cap)
+{
+ format_cap_destroy(cap);
+
+ AST_VECTOR_INIT(&cap->formats, 0);
+
+ /* TODO: Look at common usage of this and determine a good starting point */
+ AST_VECTOR_INIT(&cap->preference_order, 5);
}
More information about the asterisk-commits
mailing list