Index: main/format.c =================================================================== --- main/format.c (revision 406168) +++ main/format.c (working copy) @@ -43,6 +43,11 @@ #include "asterisk/rtp_engine.h" #include "asterisk/config.h" +/* The following disables format attr interfaces, improving performance */ +/* #define WITHOUT_FORMAT_ATTR_INTERFACE */ + +#ifndef WITHOUT_FORMAT_ATTR_INTERFACE + #define FORMAT_CONFIG "codecs.conf" /*! @@ -57,6 +62,7 @@ enum ast_format_id id; const struct ast_format_attr_interface *interface; }; +#endif /*! \brief Format List container, This container is never directly accessed outside * of this file, and It only exists for building the format_list_array. */ @@ -69,6 +75,7 @@ /*! \brief Locks the format list array so a reference can be taken safely. */ static ast_rwlock_t format_list_array_lock; +#ifndef WITHOUT_FORMAT_ATTR_INTERFACE static int interface_cmp_cb(void *obj, void *arg, int flags) { struct interface_ao2_wrapper *wrapper1 = obj; @@ -82,6 +89,7 @@ const struct interface_ao2_wrapper *wrapper = obj; return wrapper->id; } +#endif void ast_format_copy(struct ast_format *dst, const struct ast_format *src) { @@ -98,6 +106,7 @@ return format->fattr.rtp_marker_bit; } +#ifndef WITHOUT_FORMAT_ATTR_INTERFACE static struct interface_ao2_wrapper *find_interface(const struct ast_format *format) { struct interface_ao2_wrapper tmp_wrapper = { @@ -118,9 +127,11 @@ ao2_ref(wrapper, -1); return 1; } +#endif int ast_format_sdp_parse(struct ast_format *format, const char *attributes) { +#ifndef WITHOUT_FORMAT_ATTR_INTERFACE struct interface_ao2_wrapper *wrapper; int res; @@ -141,10 +152,14 @@ ao2_ref(wrapper, -1); return res; +#else + return 0; +#endif } void ast_format_sdp_generate(const struct ast_format *format, unsigned int payload, struct ast_str **str) { +#ifndef WITHOUT_FORMAT_ATTR_INTERFACE struct interface_ao2_wrapper *wrapper; if (!(wrapper = find_interface(format))) { @@ -162,8 +177,12 @@ ao2_unlock(wrapper); ao2_ref(wrapper, -1); +#else + return; +#endif } +#ifndef WITHOUT_FORMAT_ATTR_INTERFACE /*! \internal * \brief set format attributes using an interface */ @@ -190,13 +209,16 @@ return 0; } +#endif struct ast_format *ast_format_append(struct ast_format *format, ... ) { +#ifndef WITHOUT_FORMAT_ATTR_INTERFACE va_list ap; va_start(ap, format); format_set_helper(format, ap); va_end(ap); +#endif return format; } @@ -209,10 +231,14 @@ format->id = id; if (set_attributes) { +#ifndef WITHOUT_FORMAT_ATTR_INTERFACE va_list ap; va_start(ap, set_attributes); format_set_helper(format, ap); va_end(ap); +#else + ast_log(LOG_WARNING, "Could not find format interface to set.\n"); +#endif } return format; @@ -224,6 +250,7 @@ memset(&format->fattr, 0, sizeof(format->fattr)); } +#ifndef WITHOUT_FORMAT_ATTR_INTERFACE /*! \internal * \brief determine if a list of attribute key value pairs are set on a format */ @@ -266,9 +293,11 @@ return res; } +#endif int ast_format_isset(const struct ast_format *format, ... ) { +#ifndef WITHOUT_FORMAT_ATTR_INTERFACE va_list ap; int res; @@ -276,10 +305,14 @@ res = format_isset_helper(format, ap); va_end(ap); return res; +#else + return -1; +#endif } int ast_format_get_value(const struct ast_format *format, int key, void *value) { +#ifndef WITHOUT_FORMAT_ATTR_INTERFACE int res = 0; struct interface_ao2_wrapper *wrapper; @@ -301,8 +334,12 @@ ao2_ref(wrapper, -1); return res; +#else + return -1; +#endif } +#ifndef WITHOUT_FORMAT_ATTR_INTERFACE /*! \internal * \brief cmp format attributes using an interface */ @@ -329,6 +366,9 @@ return res; } +#else +#define format_cmp_helper(format1,format2) AST_FORMAT_CMP_EQUAL +#endif enum ast_format_cmp_res ast_format_cmp(const struct ast_format *format1, const struct ast_format *format2) { @@ -339,6 +379,7 @@ return format_cmp_helper(format1, format2); } +#ifndef WITHOUT_FORMAT_ATTR_INTERFACE /*! \internal * \brief get joint format attributes using an interface */ @@ -362,6 +403,9 @@ return res; } +#else +#define format_joint_helper(format1,format2,result) 0 +#endif int ast_format_joint(const struct ast_format *format1, const struct ast_format *format2, struct ast_format *result) { @@ -914,6 +958,7 @@ return 0; } +#ifndef WITHOUT_FORMAT_ATTR_INTERFACE static int format_list_add_custom(struct ast_format_list *new) { RAII_VAR(struct ast_format_list *, entry, NULL, ao2_cleanup); @@ -925,6 +970,8 @@ ao2_link(format_list, entry); return 0; } +#endif + static int format_list_add_static( const struct ast_format *format, const char *name, @@ -960,11 +1007,13 @@ return 0; } +#ifndef WITHOUT_FORMAT_ATTR_INTERFACE static int list_all_custom(void *obj, void *arg, int flag) { struct ast_format_list *entry = obj; return entry->custom_entry ? CMP_MATCH : 0; } +#endif static int list_cmp_cb(void *obj, void *arg, int flags) { @@ -1113,25 +1162,30 @@ static void format_attr_shutdown(void) { ast_cli_unregister_multiple(my_clis, ARRAY_LEN(my_clis)); +#ifndef WITHOUT_FORMAT_ATTR_INTERFACE if (interfaces) { ao2_ref(interfaces, -1); interfaces = NULL; } +#endif } int ast_format_attr_init(void) { +#ifndef WITHOUT_FORMAT_ATTR_INTERFACE interfaces = ao2_container_alloc_options(AO2_ALLOC_OPT_LOCK_RWLOCK, 283, interface_hash_cb, interface_cmp_cb); if (!interfaces) { return -1; } +#endif ast_cli_register_multiple(my_clis, ARRAY_LEN(my_clis)); ast_register_atexit(format_attr_shutdown); return 0; } +#ifndef WITHOUT_FORMAT_ATTR_INTERFACE static int custom_celt_format(struct ast_format_list *entry, unsigned int maxbitrate, unsigned int framesize) { if (!entry->samplespersecond) { @@ -1343,9 +1397,11 @@ build_format_list_array(); return 0; } +#endif int ast_format_attr_reg_interface(const struct ast_format_attr_interface *interface) { +#ifndef WITHOUT_FORMAT_ATTR_INTERFACE int x; size_t f_len; const struct ast_format_list *f_list; @@ -1396,10 +1452,15 @@ } f_list = ast_format_list_destroy(f_list); return 0; +#else + ast_log(LOG_ERROR, "Can not register attribute interface for format id %d, attribute interfaces are disabled.\n", interface->id); + return -1; +#endif } int ast_format_attr_unreg_interface(const struct ast_format_attr_interface *interface) { +#ifndef WITHOUT_FORMAT_ATTR_INTERFACE int x; size_t f_len; const struct ast_format_list *f_list; @@ -1430,4 +1491,7 @@ load_format_config(); f_list = ast_format_list_destroy(f_list); return 0; +#else + return -1; +#endif }