[svn-commits] file: branch file/media_formats-impl r408872 - in /team/file/media_formats-im...
SVN commits to the Digium repositories
svn-commits at lists.digium.com
Mon Feb 24 12:50:09 CST 2014
Author: file
Date: Mon Feb 24 12:50:04 2014
New Revision: 408872
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=408872
Log:
Make formats completely opaque.
Modified:
team/file/media_formats-impl/include/asterisk/format_ng.h
team/file/media_formats-impl/main/format_cap_ng.c
team/file/media_formats-impl/main/format_ng.c
team/file/media_formats-impl/tests/test_core_format.c
Modified: team/file/media_formats-impl/include/asterisk/format_ng.h
URL: http://svnview.digium.com/svn/asterisk/team/file/media_formats-impl/include/asterisk/format_ng.h?view=diff&rev=408872&r1=408871&r2=408872
==============================================================================
--- team/file/media_formats-impl/include/asterisk/format_ng.h (original)
+++ team/file/media_formats-impl/include/asterisk/format_ng.h Mon Feb 24 12:50:04 2014
@@ -109,16 +109,6 @@
struct ast_str **str);
};
-/*! \brief Definition of a media format */
-struct ast_format {
- /*! \brief Pointer to the codec in use for this format */
- struct ast_codec *codec;
- /*! \brief Attribute specific data, implementation specific */
- void *attribute_data;
- /*! \brief Pointer to the optional format interface */
- struct ast_format_interface *interface;
-};
-
/*!
* \brief Initialize media format support
*
@@ -222,4 +212,67 @@
*/
#define ast_format_ng_interface_register(codec, interface) __ast_format_interface_register(codec, interface, ast_module_info->self)
+/*!
+ * \brief Get the codec identifier associated with a format
+ *
+ * \param format The media format
+ *
+ * \return codec identifier
+ */
+unsigned int ast_format_get_codec_id(const struct ast_format *format);
+
+/*!
+ * \brief Get the codec name associated with a format
+ *
+ * \param format The media format
+ *
+ * \return codec name
+ */
+const char *ast_format_get_name(const struct ast_format *format);
+
+/*!
+ * \brief Get the media type of a format
+ *
+ * \param format The media format
+ *
+ * \return the media type
+ */
+enum ast_media_type ast_format_get_type(const struct ast_format *format);
+
+/*!
+ * \brief Get the default framing size (in milliseconds) for a format
+ *
+ * \param format The media format
+ *
+ * \return default framing size in milliseconds
+ */
+unsigned int ast_format_get_default_ms(const struct ast_format *format);
+
+/*!
+ * \brief Get the minimum amount of media carried in this format
+ *
+ * \param format The media format
+ *
+ * \return minimum framing size in milliseconds
+ */
+unsigned int ast_format_get_minimum_ms(const struct ast_format *format);
+
+/*!
+ * \brief Get the maximum amount of media carried in this format
+ *
+ * \param format The media format
+ *
+ * \return maximum framing size in milliseconds
+ */
+unsigned int ast_format_get_maximum_ms(const struct ast_format *format);
+
+/*!
+ * \brief Get the sample rate of a media format
+ *
+ * \param format The media format
+ *
+ * \return sample rate
+ */
+unsigned int ast_format_get_sample_rate(const struct ast_format *format);
+
#endif /* _AST_FORMAT_H */
Modified: team/file/media_formats-impl/main/format_cap_ng.c
URL: http://svnview.digium.com/svn/asterisk/team/file/media_formats-impl/main/format_cap_ng.c?view=diff&rev=408872&r1=408871&r2=408872
==============================================================================
--- team/file/media_formats-impl/main/format_cap_ng.c (original)
+++ team/file/media_formats-impl/main/format_cap_ng.c Mon Feb 24 12:50:04 2014
@@ -134,13 +134,13 @@
framed->format = ao2_bump(format);
framed->framing = framing;
- if (format->codec->id >= AST_VECTOR_SIZE(&cap->formats)) {
- if (AST_VECTOR_INSERT(&cap->formats, format->codec->id, format_cap_framed_list_empty)) {
+ if (ast_format_get_codec_id(format) >= AST_VECTOR_SIZE(&cap->formats)) {
+ if (AST_VECTOR_INSERT(&cap->formats, ast_format_get_codec_id(format), 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, ast_format_get_codec_id(format));
/* Order doesn't matter for formats, so insert at the head for performance reasons */
ao2_ref(framed, +1);
@@ -227,12 +227,12 @@
struct format_cap_framed_list *list;
struct format_cap_framed *framed, *result = NULL;
- if (format->codec->id >= AST_VECTOR_SIZE(&cap->formats)) {
+ if (ast_format_get_codec_id(format) >= AST_VECTOR_SIZE(&cap->formats)) {
return 0;
}
- framing = cap->framing ? cap->framing : format->codec->default_ms;
- list = AST_VECTOR_GET_ADDR(&cap->formats, format->codec->id);
+ framing = cap->framing ? cap->framing : ast_format_get_default_ms(format);
+ list = AST_VECTOR_GET_ADDR(&cap->formats, ast_format_get_codec_id(format));
AST_LIST_TRAVERSE(list, framed, entry) {
enum ast_format_cmp_res res = ast_format_ng_cmp(format, framed->format);
@@ -280,11 +280,11 @@
struct format_cap_framed_list *list;
struct format_cap_framed *framed;
- if (format->codec->id >= AST_VECTOR_SIZE(&cap->formats)) {
+ if (ast_format_get_codec_id(format) >= AST_VECTOR_SIZE(&cap->formats)) {
return -1;
}
- list = AST_VECTOR_GET_ADDR(&cap->formats, format->codec->id);
+ list = AST_VECTOR_GET_ADDR(&cap->formats, ast_format_get_codec_id(format));
AST_LIST_TRAVERSE_SAFE_BEGIN(list, framed, entry) {
if (!FORMAT_CAP_FRAMED_ELEM_CMP(framed, format)) {
@@ -311,7 +311,7 @@
AST_LIST_TRAVERSE_SAFE_BEGIN(list, framed, entry) {
if ((type != AST_MEDIA_TYPE_UNKNOWN) &&
- framed->format->codec->type != type) {
+ ast_format_get_type(framed->format) != type) {
continue;
}
@@ -330,11 +330,11 @@
struct format_cap_framed *framed;
struct ast_format *result = NULL;
- if (format->codec->id >= AST_VECTOR_SIZE(&cap->formats)) {
+ if (ast_format_get_codec_id(format) >= AST_VECTOR_SIZE(&cap->formats)) {
return NULL;
}
- list = AST_VECTOR_GET_ADDR(&cap->formats, format->codec->id);
+ list = AST_VECTOR_GET_ADDR(&cap->formats, ast_format_get_codec_id(format));
AST_LIST_TRAVERSE(list, framed, entry) {
enum ast_format_cmp_res res = ast_format_ng_cmp(format, framed->format);
@@ -364,11 +364,11 @@
struct format_cap_framed_list *list;
struct format_cap_framed *framed;
- if (format->codec->id >= AST_VECTOR_SIZE(&cap->formats)) {
+ if (ast_format_get_codec_id(format) >= AST_VECTOR_SIZE(&cap->formats)) {
return AST_FORMAT_CMP_NOT_EQUAL;
}
- list = AST_VECTOR_GET_ADDR(&cap->formats, format->codec->id);
+ list = AST_VECTOR_GET_ADDR(&cap->formats, ast_format_get_codec_id(format));
AST_LIST_TRAVERSE(list, framed, entry) {
enum ast_format_cmp_res cmp = ast_format_ng_cmp(format, framed->format);
@@ -394,7 +394,7 @@
for (idx = 0; idx < AST_VECTOR_SIZE(&cap->preference_order); ++idx) {
struct format_cap_framed *framed = AST_VECTOR_GET(&cap->preference_order, idx);
- if (framed->format->codec->type == type) {
+ if (ast_format_get_type(framed->format) == type) {
return 1;
}
}
@@ -461,7 +461,7 @@
for (idx = 0; idx < AST_VECTOR_SIZE(&cap->preference_order); ++idx) {
struct format_cap_framed *framed = AST_VECTOR_GET(&cap->preference_order, idx);
- snprintf(end, size, "%s|", framed->format->codec->name);
+ snprintf(end, size, "%s|", ast_format_get_name(framed->format));
len = strlen(end);
end += len;
size -= len;
Modified: team/file/media_formats-impl/main/format_ng.c
URL: http://svnview.digium.com/svn/asterisk/team/file/media_formats-impl/main/format_ng.c?view=diff&rev=408872&r1=408871&r2=408872
==============================================================================
--- team/file/media_formats-impl/main/format_ng.c (original)
+++ team/file/media_formats-impl/main/format_ng.c Mon Feb 24 12:50:04 2014
@@ -39,6 +39,16 @@
/*! \brief Number of buckets to use for format interfaces (should be prime for performance reasons) */
#define FORMAT_INTERFACE_BUCKETS 53
+
+/*! \brief Definition of a media format */
+struct ast_format {
+ /*! \brief Pointer to the codec in use for this format */
+ struct ast_codec *codec;
+ /*! \brief Attribute specific data, implementation specific */
+ void *attribute_data;
+ /*! \brief Pointer to the optional format interface */
+ struct ast_format_interface *interface;
+};
/*! \brief Structure used when registering a format interface */
struct format_interface {
@@ -245,3 +255,37 @@
format->interface->format_sdp_generate(format, payload, str);
}
+unsigned int ast_format_get_codec_id(const struct ast_format *format)
+{
+ return format->codec->id;
+}
+
+const char *ast_format_get_name(const struct ast_format *format)
+{
+ return format->codec->name;
+}
+
+enum ast_media_type ast_format_get_type(const struct ast_format *format)
+{
+ return format->codec->type;
+}
+
+unsigned int ast_format_get_default_ms(const struct ast_format *format)
+{
+ return format->codec->default_ms;
+}
+
+unsigned int ast_format_get_minimum_ms(const struct ast_format *format)
+{
+ return format->codec->minimum_ms;
+}
+
+unsigned int ast_format_get_maximum_ms(const struct ast_format *format)
+{
+ return format->codec->maximum_ms;
+}
+
+unsigned int ast_format_get_sample_rate(const struct ast_format *format)
+{
+ return format->codec->sample_rate;
+}
Modified: team/file/media_formats-impl/tests/test_core_format.c
URL: http://svnview.digium.com/svn/asterisk/team/file/media_formats-impl/tests/test_core_format.c?view=diff&rev=408872&r1=408871&r2=408872
==============================================================================
--- team/file/media_formats-impl/tests/test_core_format.c (original)
+++ team/file/media_formats-impl/tests/test_core_format.c Mon Feb 24 12:50:04 2014
@@ -65,11 +65,8 @@
if (!format) {
ast_test_status_update(test, "Could not create format using built-in codec\n");
return AST_TEST_FAIL;
- } else if (format->codec != codec) {
+ } else if (ast_format_get_codec_id(format) != codec->id) {
ast_test_status_update(test, "Created format does not contain provided codec\n");
- return AST_TEST_FAIL;
- } else if (format->interface) {
- ast_test_status_update(test, "Created format contains interface when it should not\n");
return AST_TEST_FAIL;
}
@@ -212,7 +209,7 @@
if (!joint) {
ast_test_status_update(test, "Failed to create a joint format using two formats of same codec\n");
return AST_TEST_FAIL;
- } else if (joint->codec != codec) {
+ } else if (ast_format_get_codec_id(joint) != codec->id) {
ast_test_status_update(test, "Returned joint format does not contain expected codec\n");
return AST_TEST_FAIL;
}
More information about the svn-commits
mailing list