From 066bda572aa27a0b0f9378939b8de3a833977845 Mon Sep 17 00:00:00 2001 From: Corey Farrell Date: Thu, 7 Jul 2016 19:00:22 -0400 Subject: [PATCH 2/2] RFC: ao2 reference storage location logging part 2. This contains changes to reduce output of refcounter.py from random parts of Asterisk. This is meant as a demo of what can be done with reference storage location logging. ASTERISK-26171 Change-Id: Ic66d2e8b4267e86eaeac2fac2f88d83dbcad5bde --- include/asterisk/codec.h | 13 ++- include/asterisk/format.h | 25 ++++- include/asterisk/format_cache.h | 11 +- include/asterisk/format_cap.h | 27 +++-- main/cel.c | 30 ++--- main/channel.c | 24 ++-- main/channel_internal_api.c | 12 +- main/codec.c | 17 +-- main/codec_builtin.c | 22 ++-- main/format.c | 25 +++-- main/format_cache.c | 189 ++++++++++++++++---------------- main/format_cap.c | 68 ++++++------ main/frame.c | 8 +- main/rtp_engine.c | 4 +- main/stasis_message.c | 10 +- main/threadpool.c | 16 +-- main/translate.c | 77 +++++++------ 17 files changed, 313 insertions(+), 265 deletions(-) diff --git a/include/asterisk/codec.h b/include/asterisk/codec.h index 79798acd08..a1124db2e9 100644 --- a/include/asterisk/codec.h +++ b/include/asterisk/codec.h @@ -134,7 +134,12 @@ int __ast_codec_register(struct ast_codec *codec, struct ast_module *mod); * \note The returned codec is reference counted and ao2_ref or ao2_cleanup * must be used to release the reference. */ -struct ast_codec *ast_codec_get(const char *name, enum ast_media_type type, unsigned int sample_rate); +#define ast_codec_get(name, type, sample_rate) \ + __ast_codec_get((name), (type), (sample_rate), NULL) +struct ast_codec *__ast_codec_get(const char *name, enum ast_media_type type, + unsigned int sample_rate, void *debugstorage); +#define ast_s_codec_get(storage, name, type, sample_rate) \ + __ao2_s_getter(storage, __ast_codec_get, (name), (type), (sample_rate)) /*! * \brief Retrieve a codec given the unique identifier @@ -149,7 +154,11 @@ struct ast_codec *ast_codec_get(const char *name, enum ast_media_type type, unsi * \note The returned codec is reference counted and ao2_ref or ao2_cleanup * must be used to release the reference. */ -struct ast_codec *ast_codec_get_by_id(int id); +#define ast_codec_get_by_id(id) \ + __ast_codec_get_by_id((id), NULL) +struct ast_codec *__ast_codec_get_by_id(int id, void *debugstorage); +#define ast_s_codec_get_by_id(storage, id) \ + __ao2_s_getter(storage, __ast_codec_get_by_id, (id)) /*! * \brief Retrieve the current maximum identifier for codec iteration diff --git a/include/asterisk/format.h b/include/asterisk/format.h index 62fb1ef26e..b1e86835a6 100644 --- a/include/asterisk/format.h +++ b/include/asterisk/format.h @@ -153,7 +153,11 @@ int ast_format_init(void); * \note The format is returned with reference count incremented. It must be released using * ao2_ref or ao2_cleanup. */ -struct ast_format *ast_format_create(struct ast_codec *codec); +#define ast_format_create(codec) \ + __ast_format_create((codec), NULL) +struct ast_format *__ast_format_create(struct ast_codec *codec, void *debugstorage); +#define ast_s_format_create(storage, codec) \ + __ao2_s_getter(storage, __ast_format_create, (codec)) /*! * \brief Create a new media format with a specific name @@ -171,7 +175,12 @@ struct ast_format *ast_format_create(struct ast_codec *codec); * \retval non-NULL success * \retval NULL failure */ -struct ast_format *ast_format_create_named(const char *format_name, struct ast_codec *codec); +#define ast_format_create_named(format_name, codec) \ + __ast_format_create_named((format_name), (codec), NULL) +struct ast_format *__ast_format_create_named(const char *format_name, + struct ast_codec *codec, void *debugstorage); +#define ast_s_format_create_named(storage, format_name, codec) \ + __ao2_s_getter(storage, __ast_format_create_named, (format_name), (codec)) /*! * \brief Clone an existing media format so it can be modified @@ -183,7 +192,11 @@ struct ast_format *ast_format_create_named(const char *format_name, struct ast_c * \retval non-NULL success * \retval NULL failure */ -struct ast_format *ast_format_clone(const struct ast_format *format); +#define ast_format_clone(format) \ + __ast_format_clone((format), NULL) +struct ast_format *__ast_format_clone(const struct ast_format *format, void *debugstorage); +#define ast_s_format_clone(storage, format) \ + __ao2_s_getter(storage, __ast_format_clone, (format)) /*! * \brief Compare two formats @@ -325,7 +338,11 @@ void ast_format_set_channel_count(struct ast_format *format, unsigned int channe * * \note The reference count of the returned codec is increased by 1 and must be decremented */ -struct ast_codec *ast_format_get_codec(const struct ast_format *format); +#define ast_format_get_codec(format) \ + __ast_format_get_codec((format), NULL) +struct ast_codec *__ast_format_get_codec(const struct ast_format *format, void *debugstorage); +#define ast_s_format_get_codec(storage, format) \ + __ao2_s_getter(storage, __ast_format_get_codec, (format)) /*! * \brief Get the codec identifier associated with a format diff --git a/include/asterisk/format_cache.h b/include/asterisk/format_cache.h index 067546310f..e37c6cd6d6 100644 --- a/include/asterisk/format_cache.h +++ b/include/asterisk/format_cache.h @@ -276,13 +276,14 @@ int ast_format_cache_set(struct ast_format *format); * dropped using ao2_ref or ao2_cleanup. */ struct ast_format *__ast_format_cache_get(const char *name, - const char *tag, const char *file, int line, const char *func); + const char *tag, const char *file, int line, const char *func, void *debugstorage); -#define ast_format_cache_get(name) \ - __ast_format_cache_get((name), "ast_format_cache_get", __FILE__, __LINE__, __PRETTY_FUNCTION__) #define ast_t_format_cache_get(name, tag) \ - __ast_format_cache_get((name), (tag), __FILE__, __LINE__, __PRETTY_FUNCTION__) - + __ast_format_cache_get((name), (tag), __FILE__, __LINE__, __PRETTY_FUNCTION__, NULL) +#define ast_format_cache_get(name) \ + __ast_format_cache_get((name), NULL, __FILE__, __LINE__, __PRETTY_FUNCTION__, NULL) +#define ast_s_format_cache_get(storage, name) \ + ao2_s_getter(storage, __ast_format_cache_get, name, NULL) /*! * \brief Retrieve the best signed linear format given a sample rate. diff --git a/include/asterisk/format_cap.h b/include/asterisk/format_cap.h index 8b69e08b19..5b4b7385d3 100644 --- a/include/asterisk/format_cap.h +++ b/include/asterisk/format_cap.h @@ -46,14 +46,15 @@ enum ast_format_cap_flags { * \retval ast_format_cap object on success. * \retval NULL on failure. */ +#define ast_format_cap_alloc(flags) \ + __ast_format_cap_alloc((flags), NULL, __FILE__, __LINE__, __PRETTY_FUNCTION__, NULL) struct ast_format_cap *__ast_format_cap_alloc(enum ast_format_cap_flags flags, - const char *tag, const char *file, int line, const char *func); + const char *tag, const char *file, int line, const char *func, void *debugstorage); -#define ast_format_cap_alloc(flags) \ - __ast_format_cap_alloc((flags), "ast_format_cap_alloc", \ - __FILE__, __LINE__, __PRETTY_FUNCTION__) #define ast_t_format_cap_alloc(flags, tag) \ - __ast_format_cap_alloc((flags), (tag), __FILE__, __LINE__, __PRETTY_FUNCTION__) + __ast_format_cap_alloc((flags), (tag), __FILE__, __LINE__, __PRETTY_FUNCTION__, NULL) +#define ast_s_format_cap_alloc(storage, flags) \ + ao2_s_getter(storage, __ast_format_cap_alloc, (flags), NULL) /*! * \brief Set the global framing. @@ -101,7 +102,7 @@ int __ast_format_cap_append(struct ast_format_cap *cap, struct ast_format *forma const char *tag, const char *file, int line, const char *func); #define ast_format_cap_append(cap, format, framing) \ - __ast_format_cap_append((cap), (format), (framing), "ast_format_cap_append", \ + __ast_format_cap_append((cap), (format), (framing), NULL, \ __FILE__, __LINE__, __PRETTY_FUNCTION__) #define ast_t_format_cap_append(cap, format, framing, tag) \ __ast_format_cap_append((cap), (format), (framing), (tag), \ @@ -187,7 +188,12 @@ size_t ast_format_cap_count(const struct ast_format_cap *cap); * \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(const struct ast_format_cap *cap, int position); +#define ast_format_cap_get_format(cap, position) \ + __ast_format_cap_get_format((cap), (position), NULL) +struct ast_format *__ast_format_cap_get_format(const struct ast_format_cap *cap, + int position, void *debugstorage); +#define ast_s_format_cap_get_format(storage, cap, position) \ + __ao2_s_getter(storage, __ast_format_cap_get_format, (cap), (position)) /*! * \brief Get the most preferred format for a particular media type @@ -201,7 +207,12 @@ struct ast_format *ast_format_cap_get_format(const struct ast_format_cap *cap, i * \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_best_by_type(const struct ast_format_cap *cap, enum ast_media_type type); +#define ast_format_cap_get_best_by_type(cap, type) \ + __ast_format_cap_get_best_by_type((cap), (type), NULL) +struct ast_format *__ast_format_cap_get_best_by_type(const struct ast_format_cap *cap, + enum ast_media_type type, void *debugstorage); +#define ast_s_format_cap_get_best_by_type(storage, cap, type) \ + __ao2_s_getter(storage, __ast_format_cap_get_best_by_type, (cap), (type)) /*! * \brief Get the framing for a format diff --git a/main/cel.c b/main/cel.c index 0ec728e558..20b3454eed 100644 --- a/main/cel.c +++ b/main/cel.c @@ -353,8 +353,8 @@ unsigned int ast_cel_check_enabled(void) static char *handle_cli_status(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) { unsigned int i; - RAII_VAR(struct cel_config *, cfg, ao2_global_obj_ref(cel_configs), ao2_cleanup); - RAII_VAR(struct ao2_container *, backends, ao2_global_obj_ref(cel_backends), ao2_cleanup); + RAII_AO2_S_GLOBAL(struct cel_config *, cfg, cel_configs); + RAII_AO2_S_GLOBAL(struct ao2_container *, backends, cel_backends); struct ao2_iterator iter; char *app; @@ -431,7 +431,7 @@ enum ast_cel_event_type ast_cel_str_to_event_type(const char *name) static int ast_cel_track_event(enum ast_cel_event_type et) { - RAII_VAR(struct cel_config *, cfg, ao2_global_obj_ref(cel_configs), ao2_cleanup); + RAII_AO2_S_GLOBAL(struct cel_config *, cfg, cel_configs); if (!cfg || !cfg->general) { return 0; @@ -495,8 +495,8 @@ const char *ast_cel_get_type_name(enum ast_cel_event_type type) static int cel_track_app(const char *const_app) { - RAII_VAR(struct cel_config *, cfg, ao2_global_obj_ref(cel_configs), ao2_cleanup); - RAII_VAR(char *, app, NULL, ao2_cleanup); + RAII_AO2_S_GLOBAL(struct cel_config *, cfg, cel_configs); + RAII_AO2_S(char *, app, NULL); char *app_lower; if (!cfg || !cfg->general) { @@ -504,7 +504,7 @@ static int cel_track_app(const char *const_app) } app_lower = ast_str_to_lower(ast_strdupa(const_app)); - app = ao2_find(cfg->general->apps, app_lower, OBJ_SEARCH_KEY); + ao2_s_find(&app, cfg->general->apps, app_lower, OBJ_SEARCH_KEY, ""); if (!app) { return 0; } @@ -562,8 +562,8 @@ static int cel_report_event(struct ast_channel_snapshot *snapshot, struct ast_json *extra, const char *peer_str) { struct ast_event *ev; - RAII_VAR(struct cel_config *, cfg, ao2_global_obj_ref(cel_configs), ao2_cleanup); - RAII_VAR(struct ao2_container *, backends, ao2_global_obj_ref(cel_backends), ao2_cleanup); + RAII_AO2_S_GLOBAL(struct cel_config *, cfg, cel_configs); + RAII_AO2_S_GLOBAL(struct ao2_container *, backends, cel_backends); if (!cfg || !cfg->general || !cfg->general->enable || !backends) { return 0; @@ -603,7 +603,7 @@ static int cel_report_event(struct ast_channel_snapshot *snapshot, * potentially emit a CEL_LINKEDID_END event */ static void check_retire_linkedid(struct ast_channel_snapshot *snapshot) { - RAII_VAR(struct ao2_container *, linkedids, ao2_global_obj_ref(cel_linkedids), ao2_cleanup); + RAII_AO2_S_GLOBAL(struct ao2_container *, linkedids, cel_linkedids); struct cel_linkedid *lid; if (!linkedids || ast_strlen_zero(snapshot->linkedid)) { @@ -613,7 +613,7 @@ static void check_retire_linkedid(struct ast_channel_snapshot *snapshot) ao2_lock(linkedids); - lid = ao2_find(linkedids, (void *) snapshot->linkedid, OBJ_SEARCH_KEY); + ao2_s_find(&lid, linkedids, (void *) snapshot->linkedid, OBJ_SEARCH_KEY, ""); if (!lid) { ao2_unlock(linkedids); @@ -636,7 +636,7 @@ static void check_retire_linkedid(struct ast_channel_snapshot *snapshot) } else { ao2_unlock(linkedids); } - ao2_ref(lid, -1); + ao2_s_cleanup(&lid); } /* Note that no 'chan_fixup' function is provided for this datastore type, @@ -659,7 +659,7 @@ struct ast_channel *ast_cel_fabricate_channel_from_event(const struct ast_event }; struct ast_datastore *datastore; char *app_data; - RAII_VAR(struct cel_config *, cfg, ao2_global_obj_ref(cel_configs), ao2_cleanup); + RAII_AO2_S_GLOBAL(struct cel_config *, cfg, cel_configs); if (!cfg || !cfg->general) { return NULL; @@ -770,7 +770,7 @@ struct ast_channel *ast_cel_fabricate_channel_from_event(const struct ast_event static int cel_linkedid_ref(const char *linkedid) { - RAII_VAR(struct ao2_container *, linkedids, ao2_global_obj_ref(cel_linkedids), ao2_cleanup); + RAII_AO2_S_GLOBAL(struct ao2_container *, linkedids, cel_linkedids); struct cel_linkedid *lid; if (ast_strlen_zero(linkedid)) { @@ -1676,7 +1676,7 @@ struct stasis_topic *ast_cel_topic(void) struct ast_cel_general_config *ast_cel_get_config(void) { - RAII_VAR(struct cel_config *, mod_cfg, ao2_global_obj_ref(cel_configs), ao2_cleanup); + RAII_AO2_S_GLOBAL(struct cel_config *, mod_cfg, cel_configs); if (!mod_cfg || !mod_cfg->general) { return NULL; @@ -1726,7 +1726,7 @@ int ast_cel_backend_unregister(const char *name) int ast_cel_backend_register(const char *name, ast_cel_backend_cb backend_callback) { - RAII_VAR(struct ao2_container *, backends, ao2_global_obj_ref(cel_backends), ao2_cleanup); + RAII_AO2_S_GLOBAL(struct ao2_container *, backends, cel_backends); struct cel_backend *backend; if (!backends || ast_strlen_zero(name) || !backend_callback) { diff --git a/main/channel.c b/main/channel.c index b5492999a8..0303c739cb 100644 --- a/main/channel.c +++ b/main/channel.c @@ -5487,8 +5487,8 @@ static int set_format(struct ast_channel *chan, struct ast_format_cap *cap_set, const struct set_format_access *access; struct ast_format *rawformat; struct ast_format *format; - RAII_VAR(struct ast_format *, best_set_fmt, NULL, ao2_cleanup); - RAII_VAR(struct ast_format *, best_native_fmt, NULL, ao2_cleanup); + RAII_AO2_S(struct ast_format *, best_set_fmt, NULL); + RAII_AO2_S(struct ast_format *, best_native_fmt, NULL); int res; if (!direction) { @@ -5499,7 +5499,7 @@ static int set_format(struct ast_channel *chan, struct ast_format_cap *cap_set, access = &set_format_access_write; } - best_set_fmt = ast_format_cap_get_best_by_type(cap_set, AST_MEDIA_TYPE_AUDIO); + ast_s_format_cap_get_best_by_type(&best_set_fmt, cap_set, AST_MEDIA_TYPE_AUDIO); if (!best_set_fmt) { /* * Not setting any audio formats? @@ -6153,8 +6153,8 @@ static struct ast_channel *request_channel(const char *type, struct ast_format_c } else if (chan->tech->requester) { struct ast_format_cap *tmp_converted_cap = NULL; struct ast_format_cap *tmp_cap; - RAII_VAR(struct ast_format *, tmp_fmt, NULL, ao2_cleanup); - RAII_VAR(struct ast_format *, best_audio_fmt, NULL, ao2_cleanup); + RAII_AO2_S(struct ast_format *, tmp_fmt, NULL); + RAII_AO2_S(struct ast_format *, best_audio_fmt, NULL); struct ast_format_cap *joint_cap; if (!request_cap && topology) { @@ -6163,14 +6163,14 @@ static struct ast_channel *request_channel(const char *type, struct ast_format_c } /* find the best audio format to use */ - tmp_cap = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT); + ast_s_format_cap_alloc(&tmp_cap, AST_FORMAT_CAP_FLAG_DEFAULT); if (tmp_cap) { ast_format_cap_append_from_cap(tmp_cap, request_cap, AST_MEDIA_TYPE_AUDIO); /* We have audio - is it possible to connect the various calls to each other? (Avoid this check for calls without audio, like text+video calls) */ res = ast_translator_best_choice(tmp_cap, chan->tech->capabilities, &tmp_fmt, &best_audio_fmt); - ao2_ref(tmp_cap, -1); + ao2_s_cleanup(&tmp_cap); if (res < 0) { struct ast_str *tech_codecs = ast_str_alloca(AST_FORMAT_CAP_NAMES_LEN); struct ast_str *request_codecs = ast_str_alloca(AST_FORMAT_CAP_NAMES_LEN); @@ -6189,7 +6189,7 @@ static struct ast_channel *request_channel(const char *type, struct ast_format_c * to signal to the initiator which one of their codecs that was offered is * the one that was selected, particularly in a chain of Local channels. */ - joint_cap = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT); + ast_s_format_cap_alloc(&joint_cap, AST_FORMAT_CAP_FLAG_DEFAULT); if (!joint_cap) { ao2_cleanup(tmp_converted_cap); return NULL; @@ -6200,7 +6200,7 @@ static struct ast_channel *request_channel(const char *type, struct ast_format_c ao2_cleanup(tmp_converted_cap); c = chan->tech->requester(type, joint_cap, assignedids, requestor, addr, cause); - ao2_ref(joint_cap, -1); + ao2_s_cleanup(&joint_cap); } if (!c) { @@ -6502,8 +6502,8 @@ static int ast_channel_make_compatible_helper(struct ast_channel *from, struct a { struct ast_format_cap *src_cap; struct ast_format_cap *dst_cap; - RAII_VAR(struct ast_format *, best_src_fmt, NULL, ao2_cleanup); - RAII_VAR(struct ast_format *, best_dst_fmt, NULL, ao2_cleanup); + RAII_AO2_S(struct ast_format *, best_src_fmt, NULL); + RAII_AO2_S(struct ast_format *, best_dst_fmt, NULL); int no_path; /* @@ -6560,7 +6560,7 @@ static int ast_channel_make_compatible_helper(struct ast_channel *from, struct a ast_format_get_sample_rate(best_src_fmt) : ast_format_get_sample_rate(best_dst_fmt); /* pick the best signed linear format based upon what preserves the sample rate the best. */ - ao2_replace(best_src_fmt, ast_format_cache_get_slin_by_rate(best_sample_rate)); + ao2_s_replace(&best_src_fmt, ast_format_cache_get_slin_by_rate(best_sample_rate)); } } diff --git a/main/channel_internal_api.c b/main/channel_internal_api.c index 235dd0bf5d..3f14022274 100644 --- a/main/channel_internal_api.c +++ b/main/channel_internal_api.c @@ -650,7 +650,7 @@ void ast_channel_nativeformats_set(struct ast_channel *chan, { ast_assert(chan != NULL); - ao2_replace(chan->nativeformats, value); + ao2_s_replace(&chan->nativeformats, value); /* If chan->stream_topology is NULL, the channel is being destroyed * and topology is destroyed. @@ -788,23 +788,23 @@ void ast_channel_state_set(struct ast_channel *chan, enum ast_channel_state valu } void ast_channel_set_oldwriteformat(struct ast_channel *chan, struct ast_format *format) { - ao2_replace(chan->oldwriteformat, format); + ao2_s_replace(&chan->oldwriteformat, format); } void ast_channel_set_rawreadformat(struct ast_channel *chan, struct ast_format *format) { - ao2_replace(chan->rawreadformat, format); + ao2_s_replace(&chan->rawreadformat, format); } void ast_channel_set_rawwriteformat(struct ast_channel *chan, struct ast_format *format) { - ao2_replace(chan->rawwriteformat, format); + ao2_s_replace(&chan->rawwriteformat, format); } void ast_channel_set_readformat(struct ast_channel *chan, struct ast_format *format) { - ao2_replace(chan->readformat, format); + ao2_s_replace(&chan->readformat, format); } void ast_channel_set_writeformat(struct ast_channel *chan, struct ast_format *format) { - ao2_replace(chan->writeformat, format); + ao2_s_replace(&chan->writeformat, format); } struct ast_format *ast_channel_oldwriteformat(struct ast_channel *chan) { diff --git a/main/codec.c b/main/codec.c index d6de072e7d..f9dfd57ce8 100644 --- a/main/codec.c +++ b/main/codec.c @@ -291,15 +291,15 @@ int __ast_codec_register_with_format(struct ast_codec *codec, const char *format } } - codec_new = ao2_find(codecs, codec, OBJ_SEARCH_OBJECT | OBJ_NOLOCK); + codec_new = ao2_find_full(codecs, codec, OBJ_SEARCH_OBJECT | OBJ_NOLOCK, "", &codec_new); if (codec_new) { ast_log(LOG_ERROR, "A codec with name '%s' of type '%s' and sample rate '%u' is already registered\n", codec->name, ast_codec_media_type2str(codec->type), codec->sample_rate); - ao2_ref(codec_new, -1); + ao2_s_cleanup(&codec_new); return -1; } - codec_new = ao2_t_alloc_options(sizeof(*codec_new), codec_dtor, + ao2_s_alloc(&codec_new, sizeof(*codec_new), codec_dtor, AO2_ALLOC_OPT_LOCK_NOLOCK, S_OR(codec->description, "")); if (!codec_new) { ast_log(LOG_ERROR, "Could not allocate a codec with name '%s' of type '%s' and sample rate '%u'\n", @@ -318,12 +318,13 @@ int __ast_codec_register_with_format(struct ast_codec *codec, const char *format ast_verb(2, "Registered '%s' codec '%s' at sample rate '%u' with id '%u'\n", ast_codec_media_type2str(codec->type), codec->name, codec->sample_rate, codec_new->external.id); - ao2_ref(codec_new, -1); + ao2_s_cleanup(&codec_new); return 0; } -struct ast_codec *ast_codec_get(const char *name, enum ast_media_type type, unsigned int sample_rate) +struct ast_codec *__ast_codec_get(const char *name, enum ast_media_type type, + unsigned int sample_rate, void *debugstorage) { struct ast_codec codec = { .name = name, @@ -331,12 +332,12 @@ struct ast_codec *ast_codec_get(const char *name, enum ast_media_type type, unsi .sample_rate = sample_rate, }; - return ao2_find(codecs, &codec, OBJ_SEARCH_OBJECT); + return ao2_find_full(codecs, &codec, OBJ_SEARCH_OBJECT, NULL, debugstorage); } -struct ast_codec *ast_codec_get_by_id(int id) +struct ast_codec *__ast_codec_get_by_id(int id, void *debugstorage) { - return ao2_callback(codecs, 0, codec_id_cmp, &id); + return ao2_callback_full(codecs, 0, codec_id_cmp, &id, NULL, debugstorage); } int ast_codec_get_max(void) diff --git a/main/codec_builtin.c b/main/codec_builtin.c index 25aa51384b..df5ea977d6 100644 --- a/main/codec_builtin.c +++ b/main/codec_builtin.c @@ -907,28 +907,30 @@ static struct ast_codec silk24 = { #define CODEC_REGISTER_AND_CACHE(codec) \ ({ \ int __res_ ## __LINE__ = 0; \ - struct ast_format *__fmt_ ## __LINE__; \ + struct ast_format *__fmt_ ## __LINE__ = NULL; \ struct ast_codec *__codec_ ## __LINE__; \ res |= __ast_codec_register_with_format(&(codec), (codec).name, NULL); \ - __codec_ ## __LINE__ = ast_codec_get((codec).name, (codec).type, (codec).sample_rate); \ - __fmt_ ## __LINE__ = __codec_ ## __LINE__ ? ast_format_create(__codec_ ## __LINE__) : NULL; \ + ast_s_codec_get(&__codec_ ## __LINE__, (codec).name, (codec).type, (codec).sample_rate); \ + if (__codec_ ## __LINE__) { \ + ast_s_format_create(&__fmt_ ## __LINE__, __codec_ ## __LINE__); \ + } \ res |= ast_format_cache_set(__fmt_ ## __LINE__); \ - ao2_ref(__fmt_ ## __LINE__, -1); \ - ao2_ref(__codec_ ## __LINE__, -1); \ + ao2_s_cleanup(&__fmt_ ## __LINE__); \ + ao2_s_cleanup(&__codec_ ## __LINE__); \ __res_ ## __LINE__; \ }) #define CODEC_REGISTER_AND_CACHE_NAMED(fmt_name, codec) \ ({ \ int __res_ ## __LINE__ = 0; \ - struct ast_format *__fmt_ ## __LINE__; \ + struct ast_format *__fmt_ ## __LINE__ = NULL; \ struct ast_codec *__codec_ ## __LINE__; \ res |= __ast_codec_register_with_format(&(codec), fmt_name, NULL); \ - __codec_ ## __LINE__ = ast_codec_get((codec).name, (codec).type, (codec).sample_rate); \ - __fmt_ ## __LINE__ = ast_format_create_named((fmt_name), __codec_ ## __LINE__); \ + ast_s_codec_get(&__codec_ ## __LINE__, (codec).name, (codec).type, (codec).sample_rate); \ + ast_s_format_create_named(&__fmt_ ## __LINE__, (fmt_name), __codec_ ## __LINE__); \ res |= ast_format_cache_set(__fmt_ ## __LINE__); \ - ao2_ref(__fmt_ ## __LINE__, -1); \ - ao2_ref(__codec_ ## __LINE__, -1); \ + ao2_s_cleanup(&__fmt_ ## __LINE__); \ + ao2_s_cleanup(&__codec_ ## __LINE__); \ __res_ ## __LINE__; \ }) diff --git a/main/format.c b/main/format.c index 5ba9ffe91d..94cd779266 100644 --- a/main/format.c +++ b/main/format.c @@ -151,21 +151,22 @@ static void format_destroy(void *obj) format->interface->format_destroy(format); } - ao2_cleanup(format->codec); + ao2_s_cleanup(&format->codec); } -struct ast_format *ast_format_create_named(const char *format_name, struct ast_codec *codec) +struct ast_format *__ast_format_create_named(const char *format_name, + struct ast_codec *codec, void *debugstorage) { struct ast_format *format; struct format_interface *format_interface; - format = ao2_t_alloc_options(sizeof(*format), format_destroy, - AO2_ALLOC_OPT_LOCK_NOLOCK, S_OR(codec->description, "")); + format = ao2_alloc_full(sizeof(*format), format_destroy, + AO2_ALLOC_OPT_LOCK_NOLOCK, S_OR(codec->description, ""), debugstorage); if (!format) { return NULL; } format->name = format_name; - format->codec = ao2_bump(codec); + ao2_s_set(&format->codec, codec); format->channel_count = 1; format_interface = ao2_find(interfaces, codec->name, OBJ_SEARCH_KEY); @@ -177,25 +178,25 @@ struct ast_format *ast_format_create_named(const char *format_name, struct ast_c return format; } -struct ast_format *ast_format_clone(const struct ast_format *format) +struct ast_format *__ast_format_clone(const struct ast_format *format, void *debugstorage) { - struct ast_format *cloned = ast_format_create_named(format->name, format->codec); + struct ast_format *cloned = __ast_format_create_named(format->name, format->codec, debugstorage); if (!cloned) { return NULL; } if (cloned->interface && cloned->interface->format_clone(format, cloned)) { - ao2_ref(cloned, -1); + ao2_ref_full(cloned, -1, "", debugstorage); return NULL; } return cloned; } -struct ast_format *ast_format_create(struct ast_codec *codec) +struct ast_format *__ast_format_create(struct ast_codec *codec, void *debugstorage) { - return ast_format_create_named(codec->name, codec); + return __ast_format_create_named(codec->name, codec, debugstorage); } enum ast_format_cmp_res ast_format_cmp(const struct ast_format *format1, const struct ast_format *format2) @@ -321,9 +322,9 @@ void ast_format_generate_sdp_fmtp(const struct ast_format *format, unsigned int interface->format_generate_sdp_fmtp(format, payload, str); } -struct ast_codec *ast_format_get_codec(const struct ast_format *format) +struct ast_codec *__ast_format_get_codec(const struct ast_format *format, void *debugstorage) { - return ao2_bump(format->codec); + return ao2_bump_full(format->codec, "", debugstorage); } unsigned int ast_format_get_codec_id(const struct ast_format *format) diff --git a/main/format_cache.c b/main/format_cache.c index db0d9b91ee..3157e598c6 100644 --- a/main/format_cache.c +++ b/main/format_cache.c @@ -313,52 +313,52 @@ static void format_cache_shutdown(void) ao2_cleanup(formats); formats = NULL; - ao2_replace(ast_format_g723, NULL); - ao2_replace(ast_format_ulaw, NULL); - ao2_replace(ast_format_alaw, NULL); - ao2_replace(ast_format_gsm, NULL); - ao2_replace(ast_format_g726, NULL); - ao2_replace(ast_format_g726_aal2, NULL); - ao2_replace(ast_format_adpcm, NULL); - ao2_replace(ast_format_slin, NULL); - ao2_replace(ast_format_slin12, NULL); - ao2_replace(ast_format_slin16, NULL); - ao2_replace(ast_format_slin24, NULL); - ao2_replace(ast_format_slin32, NULL); - ao2_replace(ast_format_slin44, NULL); - ao2_replace(ast_format_slin48, NULL); - ao2_replace(ast_format_slin96, NULL); - ao2_replace(ast_format_slin192, NULL); - ao2_replace(ast_format_lpc10, NULL); - ao2_replace(ast_format_g729, NULL); - ao2_replace(ast_format_speex, NULL); - ao2_replace(ast_format_speex16, NULL); - ao2_replace(ast_format_speex32, NULL); - ao2_replace(ast_format_ilbc, NULL); - ao2_replace(ast_format_g722, NULL); - ao2_replace(ast_format_siren7, NULL); - ao2_replace(ast_format_siren14, NULL); - ao2_replace(ast_format_testlaw, NULL); - ao2_replace(ast_format_g719, NULL); - ao2_replace(ast_format_opus, NULL); - ao2_replace(ast_format_codec2, NULL); - ao2_replace(ast_format_jpeg, NULL); - ao2_replace(ast_format_png, NULL); - ao2_replace(ast_format_h261, NULL); - ao2_replace(ast_format_h263, NULL); - ao2_replace(ast_format_h263p, NULL); - ao2_replace(ast_format_h264, NULL); - ao2_replace(ast_format_mp4, NULL); - ao2_replace(ast_format_vp8, NULL); - ao2_replace(ast_format_vp9, NULL); - ao2_replace(ast_format_t140_red, NULL); - ao2_replace(ast_format_t140, NULL); - ao2_replace(ast_format_t38, NULL); - ao2_replace(ast_format_none, NULL); - ao2_replace(ast_format_silk8, NULL); - ao2_replace(ast_format_silk12, NULL); - ao2_replace(ast_format_silk16, NULL); - ao2_replace(ast_format_silk24, NULL); + ao2_s_replace(&ast_format_g723, NULL); + ao2_s_replace(&ast_format_ulaw, NULL); + ao2_s_replace(&ast_format_alaw, NULL); + ao2_s_replace(&ast_format_gsm, NULL); + ao2_s_replace(&ast_format_g726, NULL); + ao2_s_replace(&ast_format_g726_aal2, NULL); + ao2_s_replace(&ast_format_adpcm, NULL); + ao2_s_replace(&ast_format_slin, NULL); + ao2_s_replace(&ast_format_slin12, NULL); + ao2_s_replace(&ast_format_slin16, NULL); + ao2_s_replace(&ast_format_slin24, NULL); + ao2_s_replace(&ast_format_slin32, NULL); + ao2_s_replace(&ast_format_slin44, NULL); + ao2_s_replace(&ast_format_slin48, NULL); + ao2_s_replace(&ast_format_slin96, NULL); + ao2_s_replace(&ast_format_slin192, NULL); + ao2_s_replace(&ast_format_lpc10, NULL); + ao2_s_replace(&ast_format_g729, NULL); + ao2_s_replace(&ast_format_speex, NULL); + ao2_s_replace(&ast_format_speex16, NULL); + ao2_s_replace(&ast_format_speex32, NULL); + ao2_s_replace(&ast_format_ilbc, NULL); + ao2_s_replace(&ast_format_g722, NULL); + ao2_s_replace(&ast_format_siren7, NULL); + ao2_s_replace(&ast_format_siren14, NULL); + ao2_s_replace(&ast_format_testlaw, NULL); + ao2_s_replace(&ast_format_g719, NULL); + ao2_s_replace(&ast_format_opus, NULL); + ao2_s_replace(&ast_format_codec2, NULL); + ao2_s_replace(&ast_format_jpeg, NULL); + ao2_s_replace(&ast_format_png, NULL); + ao2_s_replace(&ast_format_h261, NULL); + ao2_s_replace(&ast_format_h263, NULL); + ao2_s_replace(&ast_format_h263p, NULL); + ao2_s_replace(&ast_format_h264, NULL); + ao2_s_replace(&ast_format_mp4, NULL); + ao2_s_replace(&ast_format_vp8, NULL); + ao2_s_replace(&ast_format_vp9, NULL); + ao2_s_replace(&ast_format_t140_red, NULL); + ao2_s_replace(&ast_format_t140, NULL); + ao2_s_replace(&ast_format_t38, NULL); + ao2_s_replace(&ast_format_none, NULL); + ao2_s_replace(&ast_format_silk8, NULL); + ao2_s_replace(&ast_format_silk12, NULL); + ao2_s_replace(&ast_format_silk16, NULL); + ao2_s_replace(&ast_format_silk24, NULL); } int ast_format_cache_init(void) @@ -377,97 +377,97 @@ int ast_format_cache_init(void) static void set_cached_format(const char *name, struct ast_format *format) { if (!strcmp(name, "codec2")) { - ao2_replace(ast_format_codec2, format); + ao2_s_replace(&ast_format_codec2, format); } else if (!strcmp(name, "g723")) { - ao2_replace(ast_format_g723, format); + ao2_s_replace(&ast_format_g723, format); } else if (!strcmp(name, "ulaw")) { - ao2_replace(ast_format_ulaw, format); + ao2_s_replace(&ast_format_ulaw, format); } else if (!strcmp(name, "alaw")) { - ao2_replace(ast_format_alaw, format); + ao2_s_replace(&ast_format_alaw, format); } else if (!strcmp(name, "gsm")) { - ao2_replace(ast_format_gsm, format); + ao2_s_replace(&ast_format_gsm, format); } else if (!strcmp(name, "g726")) { - ao2_replace(ast_format_g726, format); + ao2_s_replace(&ast_format_g726, format); } else if (!strcmp(name, "g726aal2")) { - ao2_replace(ast_format_g726_aal2, format); + ao2_s_replace(&ast_format_g726_aal2, format); } else if (!strcmp(name, "adpcm")) { - ao2_replace(ast_format_adpcm, format); + ao2_s_replace(&ast_format_adpcm, format); } else if (!strcmp(name, "slin")) { - ao2_replace(ast_format_slin, format); + ao2_s_replace(&ast_format_slin, format); } else if (!strcmp(name, "slin12")) { - ao2_replace(ast_format_slin12, format); + ao2_s_replace(&ast_format_slin12, format); } else if (!strcmp(name, "slin16")) { - ao2_replace(ast_format_slin16, format); + ao2_s_replace(&ast_format_slin16, format); } else if (!strcmp(name, "slin24")) { - ao2_replace(ast_format_slin24, format); + ao2_s_replace(&ast_format_slin24, format); } else if (!strcmp(name, "slin32")) { - ao2_replace(ast_format_slin32, format); + ao2_s_replace(&ast_format_slin32, format); } else if (!strcmp(name, "slin44")) { - ao2_replace(ast_format_slin44, format); + ao2_s_replace(&ast_format_slin44, format); } else if (!strcmp(name, "slin48")) { - ao2_replace(ast_format_slin48, format); + ao2_s_replace(&ast_format_slin48, format); } else if (!strcmp(name, "slin96")) { - ao2_replace(ast_format_slin96, format); + ao2_s_replace(&ast_format_slin96, format); } else if (!strcmp(name, "slin192")) { - ao2_replace(ast_format_slin192, format); + ao2_s_replace(&ast_format_slin192, format); } else if (!strcmp(name, "lpc10")) { - ao2_replace(ast_format_lpc10, format); + ao2_s_replace(&ast_format_lpc10, format); } else if (!strcmp(name, "g729")) { - ao2_replace(ast_format_g729, format); + ao2_s_replace(&ast_format_g729, format); } else if (!strcmp(name, "speex")) { - ao2_replace(ast_format_speex, format); + ao2_s_replace(&ast_format_speex, format); } else if (!strcmp(name, "speex16")) { - ao2_replace(ast_format_speex16, format); + ao2_s_replace(&ast_format_speex16, format); } else if (!strcmp(name, "speex32")) { - ao2_replace(ast_format_speex32, format); + ao2_s_replace(&ast_format_speex32, format); } else if (!strcmp(name, "ilbc")) { - ao2_replace(ast_format_ilbc, format); + ao2_s_replace(&ast_format_ilbc, format); } else if (!strcmp(name, "g722")) { - ao2_replace(ast_format_g722, format); + ao2_s_replace(&ast_format_g722, format); } else if (!strcmp(name, "siren7")) { - ao2_replace(ast_format_siren7, format); + ao2_s_replace(&ast_format_siren7, format); } else if (!strcmp(name, "siren14")) { - ao2_replace(ast_format_siren14, format); + ao2_s_replace(&ast_format_siren14, format); } else if (!strcmp(name, "testlaw")) { - ao2_replace(ast_format_testlaw, format); + ao2_s_replace(&ast_format_testlaw, format); } else if (!strcmp(name, "g719")) { - ao2_replace(ast_format_g719, format); + ao2_s_replace(&ast_format_g719, format); } else if (!strcmp(name, "opus")) { - ao2_replace(ast_format_opus, format); + ao2_s_replace(&ast_format_opus, format); } else if (!strcmp(name, "jpeg")) { - ao2_replace(ast_format_jpeg, format); + ao2_s_replace(&ast_format_jpeg, format); } else if (!strcmp(name, "png")) { - ao2_replace(ast_format_png, format); + ao2_s_replace(&ast_format_png, format); } else if (!strcmp(name, "h261")) { - ao2_replace(ast_format_h261, format); + ao2_s_replace(&ast_format_h261, format); } else if (!strcmp(name, "h263")) { - ao2_replace(ast_format_h263, format); + ao2_s_replace(&ast_format_h263, format); } else if (!strcmp(name, "h263p")) { - ao2_replace(ast_format_h263p, format); + ao2_s_replace(&ast_format_h263p, format); } else if (!strcmp(name, "h264")) { - ao2_replace(ast_format_h264, format); + ao2_s_replace(&ast_format_h264, format); } else if (!strcmp(name, "mpeg4")) { - ao2_replace(ast_format_mp4, format); + ao2_s_replace(&ast_format_mp4, format); } else if (!strcmp(name, "vp8")) { - ao2_replace(ast_format_vp8, format); + ao2_s_replace(&ast_format_vp8, format); } else if (!strcmp(name, "vp9")) { - ao2_replace(ast_format_vp9, format); + ao2_s_replace(&ast_format_vp9, format); } else if (!strcmp(name, "red")) { - ao2_replace(ast_format_t140_red, format); + ao2_s_replace(&ast_format_t140_red, format); } else if (!strcmp(name, "t140")) { - ao2_replace(ast_format_t140, format); + ao2_s_replace(&ast_format_t140, format); } else if (!strcmp(name, "t38")) { - ao2_replace(ast_format_t38, format); + ao2_s_replace(&ast_format_t38, format); } else if (!strcmp(name, "none")) { - ao2_replace(ast_format_none, format); + ao2_s_replace(&ast_format_none, format); } else if (!strcmp(name, "silk8")) { - ao2_replace(ast_format_silk8, format); + ao2_s_replace(&ast_format_silk8, format); } else if (!strcmp(name, "silk12")) { - ao2_replace(ast_format_silk12, format); + ao2_s_replace(&ast_format_silk12, format); } else if (!strcmp(name, "silk16")) { - ao2_replace(ast_format_silk16, format); + ao2_s_replace(&ast_format_silk16, format); } else if (!strcmp(name, "silk24")) { - ao2_replace(ast_format_silk24, format); + ao2_s_replace(&ast_format_silk24, format); } } @@ -500,13 +500,14 @@ int ast_format_cache_set(struct ast_format *format) } struct ast_format *__ast_format_cache_get(const char *name, - const char *tag, const char *file, int line, const char *func) + const char *tag, const char *file, int line, const char *func, void *debugstorage) { if (ast_strlen_zero(name)) { return NULL; } - return __ao2_find(formats, name, OBJ_SEARCH_KEY, tag, file, line, func); + return __ao2_find_full(formats, name, OBJ_SEARCH_KEY, + tag ?: __PRETTY_FUNCTION__, file, line, func, debugstorage); } struct ast_format *ast_format_cache_get_slin_by_rate(unsigned int rate) diff --git a/main/format_cap.c b/main/format_cap.c index 5630ab33d1..d0bbdd78b3 100644 --- a/main/format_cap.c +++ b/main/format_cap.c @@ -77,7 +77,7 @@ static void format_cap_destroy(void *obj) struct format_cap_framed *framed; while ((framed = AST_LIST_REMOVE_HEAD(list, entry))) { - ao2_ref(framed, -1); + ao2_ref_full(framed, -1, "", &cap->formats); } } AST_VECTOR_FREE(&cap->formats); @@ -86,7 +86,7 @@ static void format_cap_destroy(void *obj) struct format_cap_framed *framed = AST_VECTOR_GET(&cap->preference_order, idx); /* This will always be non-null, unlike formats */ - ao2_ref(framed, -1); + ao2_ref_full(framed, -1, "", &cap->preference_order); } AST_VECTOR_FREE(&cap->preference_order); } @@ -115,18 +115,18 @@ static inline int format_cap_init(struct ast_format_cap *cap, enum ast_format_ca } struct ast_format_cap *__ast_format_cap_alloc(enum ast_format_cap_flags flags, - const char *tag, const char *file, int line, const char *func) + const char *tag, const char *file, int line, const char *func, void *debugstorage) { struct ast_format_cap *cap; cap = __ao2_alloc_full(sizeof(*cap), format_cap_destroy, AO2_ALLOC_OPT_LOCK_NOLOCK, - tag, file, line, func, NULL); + tag ?: "ast_format_cap_alloc", file, line, func, debugstorage); if (!cap) { return NULL; } if (format_cap_init(cap, flags)) { - ao2_ref(cap, -1); + ao2_ref_full(cap, -1, "format_cap_init: Failed", debugstorage); return NULL; } @@ -143,7 +143,7 @@ static void format_cap_framed_destroy(void *obj) { struct format_cap_framed *framed = obj; - ao2_cleanup(framed->format); + ao2_s_cleanup(&framed->format); } static inline int format_cap_framed_init(struct format_cap_framed *framed, struct ast_format_cap *cap, struct ast_format *format, unsigned int framing) @@ -154,20 +154,20 @@ static inline int format_cap_framed_init(struct format_cap_framed *framed, struc if (ast_format_get_codec_id(format) >= AST_VECTOR_SIZE(&cap->formats)) { if (AST_VECTOR_REPLACE(&cap->formats, ast_format_get_codec_id(format), format_cap_framed_list_empty)) { - ao2_ref(framed, -1); + ao2_ref_full(framed, -1, "", &cap->formats); return -1; } } list = AST_VECTOR_GET_ADDR(&cap->formats, ast_format_get_codec_id(format)); - /* This takes the allocation reference */ if (AST_VECTOR_APPEND(&cap->preference_order, framed)) { - ao2_ref(framed, -1); + ao2_ref_full(framed, -1, "", &cap->formats); return -1; } + ao2_ref_full(framed, +1, "", &cap->preference_order); /* Order doesn't matter for formats, so insert at the head for performance reasons */ - ao2_ref(framed, +1); + /* This takes the allocation reference */ AST_LIST_INSERT_HEAD(list, framed, entry); cap->framing = MIN(cap->framing, framing ? framing : ast_format_get_default_ms(format)); @@ -202,12 +202,13 @@ int __ast_format_cap_append(struct ast_format_cap *cap, struct ast_format *forma return 0; } - framed = ao2_alloc_options(sizeof(*framed), format_cap_framed_destroy, AO2_ALLOC_OPT_LOCK_NOLOCK); + framed = ao2_alloc_full(sizeof(*framed), format_cap_framed_destroy, + AO2_ALLOC_OPT_LOCK_NOLOCK, "", &cap->formats); if (!framed) { return -1; } - __ao2_ref(format, +1, tag, file, line, func); + __ao2_ref_full(format, +1, tag ?: "ast_format_cap_append", file, line, func, &framed->format); framed->format = format; return format_cap_framed_init(framed, cap, format, framing); @@ -218,37 +219,38 @@ int ast_format_cap_append_by_type(struct ast_format_cap *cap, enum ast_media_typ int id; for (id = 1; id < ast_codec_get_max(); ++id) { - struct ast_codec *codec = ast_codec_get_by_id(id); + struct ast_codec *codec; struct ast_codec *codec2 = NULL; struct ast_format *format; int res; + ast_s_codec_get_by_id(&codec, id); if (!codec) { continue; } if ((type != AST_MEDIA_TYPE_UNKNOWN) && codec->type != type) { - ao2_ref(codec, -1); + ao2_s_cleanup(&codec); continue; } - format = ast_format_cache_get(codec->name); + ast_s_format_cache_get(&format, codec->name); if (format == ast_format_none) { - ao2_ref(format, -1); - ao2_ref(codec, -1); + ao2_s_cleanup(&format); + ao2_s_cleanup(&codec); continue; } if (format) { - codec2 = ast_format_get_codec(format); + ast_s_format_get_codec(&codec2, format); } if (codec != codec2) { - ao2_cleanup(format); - format = ast_format_create(codec); + ao2_s_cleanup(&format); + ast_s_format_create(&format, codec); } - ao2_cleanup(codec2); - ao2_ref(codec, -1); + ao2_s_cleanup(&codec2); + ao2_s_cleanup(&codec); if (!format) { return -1; @@ -256,7 +258,7 @@ int ast_format_cap_append_by_type(struct ast_format_cap *cap, enum ast_media_typ /* Use the global framing or default framing of the codec */ res = ast_format_cap_append(cap, format, 0); - ao2_ref(format, -1); + ao2_s_cleanup(&format); if (res) { return -1; @@ -294,8 +296,7 @@ static int format_cap_replace(struct ast_format_cap *cap, struct ast_format *for framed = AST_VECTOR_GET(&cap->preference_order, i); if (ast_format_get_codec_id(format) == ast_format_get_codec_id(framed->format)) { - ao2_t_replace(framed->format, format, "replacing with new format"); - framed->framing = framing; + ao2_s_replace(&framed->format, format); return 0; } } @@ -365,7 +366,8 @@ int ast_format_cap_update_by_allow_disallow(struct ast_format_cap *cap, const ch } all = strcasecmp(this, "all") ? 0 : 1; - if (!all && !(format = ast_format_cache_get(this))) { + + if (!all && !ast_s_format_cache_get(&format, this)) { ast_log(LOG_WARNING, "Cannot %s unknown format '%s'\n", iter_allowing ? "allow" : "disallow", this); res = -1; continue; @@ -387,7 +389,7 @@ int ast_format_cap_update_by_allow_disallow(struct ast_format_cap *cap, const ch } } - ao2_cleanup(format); + ao2_s_cleanup(&format); } return res; } @@ -397,7 +399,8 @@ 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(const struct ast_format_cap *cap, int position) +struct ast_format *__ast_format_cap_get_format(const struct ast_format_cap *cap, + int position, void *debugstorage) { struct format_cap_framed *framed; @@ -410,23 +413,24 @@ struct ast_format *ast_format_cap_get_format(const struct ast_format_cap *cap, i framed = AST_VECTOR_GET(&cap->preference_order, position); ast_assert(framed->format != ast_format_none); - ao2_ref(framed->format, +1); + ao2_ref_full(framed->format, +1, "", debugstorage); return framed->format; } -struct ast_format *ast_format_cap_get_best_by_type(const struct ast_format_cap *cap, enum ast_media_type type) +struct ast_format *__ast_format_cap_get_best_by_type(const struct ast_format_cap *cap, + enum ast_media_type type, void *debugstorage) { int i; if (type == AST_MEDIA_TYPE_UNKNOWN) { - return ast_format_cap_get_format(cap, 0); + return __ast_format_cap_get_format(cap, 0, debugstorage); } for (i = 0; i < AST_VECTOR_SIZE(&cap->preference_order); i++) { struct format_cap_framed *framed = AST_VECTOR_GET(&cap->preference_order, i); if (ast_format_get_type(framed->format) == type) { - ao2_ref(framed->format, +1); + ao2_ref_full(framed->format, +1, "", debugstorage); ast_assert(framed->format != ast_format_none); return framed->format; } diff --git a/main/frame.c b/main/frame.c index 383571f65d..70375495f4 100644 --- a/main/frame.c +++ b/main/frame.c @@ -132,7 +132,7 @@ static void __frame_free(struct ast_frame *fr, int cache) if (fr->frametype == AST_FRAME_VOICE || fr->frametype == AST_FRAME_VIDEO || fr->frametype == AST_FRAME_IMAGE) { - ao2_cleanup(fr->subclass.format); + ao2_s_cleanup(&fr->subclass.format); } AST_LIST_INSERT_HEAD(&frames->list, fr, frame_list); @@ -154,7 +154,7 @@ static void __frame_free(struct ast_frame *fr, int cache) if (fr->frametype == AST_FRAME_VOICE || fr->frametype == AST_FRAME_VIDEO || fr->frametype == AST_FRAME_IMAGE) { - ao2_cleanup(fr->subclass.format); + ao2_s_cleanup(&fr->subclass.format); } ast_free(fr); @@ -212,7 +212,7 @@ struct ast_frame *ast_frisolate(struct ast_frame *fr) out->subclass = fr->subclass; if ((fr->frametype == AST_FRAME_VOICE) || (fr->frametype == AST_FRAME_VIDEO) || (fr->frametype == AST_FRAME_IMAGE)) { - ao2_bump(out->subclass.format); + ao2_s_set(&out->subclass.format, fr->subclass.format); } out->datalen = fr->datalen; out->samples = fr->samples; @@ -342,7 +342,7 @@ struct ast_frame *ast_frdup(const struct ast_frame *f) out->subclass = f->subclass; if ((f->frametype == AST_FRAME_VOICE) || (f->frametype == AST_FRAME_VIDEO) || (f->frametype == AST_FRAME_IMAGE)) { - ao2_bump(out->subclass.format); + ao2_s_init(&out->subclass.format); } out->datalen = f->datalen; out->samples = f->samples; diff --git a/main/rtp_engine.c b/main/rtp_engine.c index 3d507745d3..afa43ae9bd 100644 --- a/main/rtp_engine.c +++ b/main/rtp_engine.c @@ -3123,7 +3123,7 @@ void ast_rtp_dtls_cfg_free(struct ast_rtp_dtls_cfg *dtls_cfg) */ static void rtp_engine_mime_type_cleanup(int i) { - ao2_cleanup(ast_rtp_mime_types[i].payload_type.format); + ao2_s_cleanup(&ast_rtp_mime_types[i].payload_type.format); memset(&ast_rtp_mime_types[i], 0, sizeof(struct ast_rtp_mime_type)); } @@ -3143,7 +3143,7 @@ static void set_next_mime_type(struct ast_format *format, int rtp_code, const ch memset(&ast_rtp_mime_types[x], 0, sizeof(struct ast_rtp_mime_type)); if (format) { ast_rtp_mime_types[x].payload_type.asterisk_format = 1; - ast_rtp_mime_types[x].payload_type.format = ao2_bump(format); + ao2_s_set(&ast_rtp_mime_types[x].payload_type.format, format); } else { ast_rtp_mime_types[x].payload_type.rtp_code = rtp_code; } diff --git a/main/stasis_message.c b/main/stasis_message.c index 482dd01d40..e003df195b 100644 --- a/main/stasis_message.c +++ b/main/stasis_message.c @@ -109,8 +109,8 @@ struct stasis_message { static void stasis_message_dtor(void *obj) { struct stasis_message *message = obj; - ao2_cleanup(message->type); - ao2_cleanup(message->data); + ao2_s_cleanup(&message->type); + ao2_s_cleanup(&message->data); } struct stasis_message *stasis_message_create_full(struct stasis_message_type *type, void *data, const struct ast_eid *eid) @@ -127,10 +127,8 @@ struct stasis_message *stasis_message_create_full(struct stasis_message_type *ty } message->timestamp = ast_tvnow(); - ao2_ref(type, +1); - message->type = type; - ao2_ref(data, +1); - message->data = data; + ao2_s_set(&message->type, type); + ao2_s_set(&message->data, data); if (eid) { message->eid_ptr = &message->eid; message->eid = *eid; diff --git a/main/threadpool.c b/main/threadpool.c index e3d0e40fd3..be7e23d8f1 100644 --- a/main/threadpool.c +++ b/main/threadpool.c @@ -370,7 +370,7 @@ static int threadpool_execute(struct ast_threadpool *pool) static void threadpool_destructor(void *obj) { struct ast_threadpool *pool = obj; - ao2_cleanup(pool->listener); + ao2_s_cleanup(&pool->listener); } /* @@ -913,8 +913,7 @@ struct ast_threadpool *ast_threadpool_create(const char *name, pool->tps = tps; if (listener) { - ao2_ref(listener, +1); - pool->listener = listener; + ao2_s_set(&pool->listener, listener); } ast_threadpool_set_size(pool, pool->options.initial_size); ao2_ref(pool, +1); @@ -1291,10 +1290,8 @@ static void serializer_dtor(void *obj) { struct serializer *ser = obj; - ao2_cleanup(ser->pool); - ser->pool = NULL; - ao2_cleanup(ser->shutdown_group); - ser->shutdown_group = NULL; + ao2_s_cleanup(&ser->pool); + ao2_s_cleanup(&ser->shutdown_group); } static struct serializer *serializer_create(struct ast_threadpool *pool, @@ -1306,9 +1303,8 @@ static struct serializer *serializer_create(struct ast_threadpool *pool, if (!ser) { return NULL; } - ao2_ref(pool, +1); - ser->pool = pool; - ser->shutdown_group = ao2_bump(shutdown_group); + ao2_s_set(&ser->pool, pool); + ao2_s_set(&ser->shutdown_group, shutdown_group); return ser; } diff --git a/main/translate.c b/main/translate.c index 26f9c9beeb..33b2dab702 100644 --- a/main/translate.c +++ b/main/translate.c @@ -295,11 +295,8 @@ static void destroy(struct ast_trans_pvt *pvt) if (t->destroy) { t->destroy(pvt); } - ao2_cleanup(pvt->f.subclass.format); - if (pvt->explicit_dst) { - ao2_ref(pvt->explicit_dst, -1); - pvt->explicit_dst = NULL; - } + ao2_s_cleanup(&pvt->f.subclass.format); + ao2_s_cleanup(&pvt->explicit_dst); ast_free(pvt); ast_module_unref(t->module); } @@ -339,7 +336,7 @@ static struct ast_trans_pvt *newpvt(struct ast_translator *t, struct ast_format * result of the SDP negotiation. For example with the Opus Codec, the format * knows whether both parties want to do forward-error correction (FEC). */ - pvt->explicit_dst = ao2_bump(explicit_dst); + ao2_s_set(&pvt->explicit_dst, explicit_dst); ast_module_ref(t->module); @@ -364,22 +361,24 @@ static struct ast_trans_pvt *newpvt(struct ast_translator *t, struct ast_format * C) create one. */ if (!pvt->f.subclass.format) { - pvt->f.subclass.format = ao2_bump(pvt->explicit_dst); + ao2_s_set(&pvt->f.subclass.format, pvt->explicit_dst); if (!pvt->f.subclass.format && !ast_strlen_zero(pvt->t->format)) { - pvt->f.subclass.format = ast_format_cache_get(pvt->t->format); + ast_s_format_cache_get(&pvt->f.subclass.format, pvt->t->format); } if (!pvt->f.subclass.format) { - struct ast_codec *codec = ast_codec_get(t->dst_codec.name, + struct ast_codec *codec; + + ast_s_codec_get(&codec, t->dst_codec.name, t->dst_codec.type, t->dst_codec.sample_rate); if (!codec) { ast_log(LOG_ERROR, "Unable to get destination codec\n"); destroy(pvt); return NULL; } - pvt->f.subclass.format = ast_format_create(codec); - ao2_ref(codec, -1); + ast_s_format_create(&pvt->f.subclass.format, codec); + ao2_s_cleanup(&codec); } if (!pvt->f.subclass.format) { @@ -1212,17 +1211,17 @@ int __ast_register_translator(struct ast_translator *t, struct ast_module *mod) { struct ast_translator *u; char tmp[80]; - RAII_VAR(struct ast_codec *, src_codec, NULL, ao2_cleanup); - RAII_VAR(struct ast_codec *, dst_codec, NULL, ao2_cleanup); + RAII_AO2_S(struct ast_codec *, src_codec, NULL); + RAII_AO2_S(struct ast_codec *, dst_codec, NULL); - src_codec = ast_codec_get(t->src_codec.name, t->src_codec.type, t->src_codec.sample_rate); + ast_s_codec_get(&src_codec, t->src_codec.name, t->src_codec.type, t->src_codec.sample_rate); if (!src_codec) { ast_assert(0); ast_log(LOG_WARNING, "Failed to register translator: unknown source codec %s\n", t->src_codec.name); return -1; } - dst_codec = ast_codec_get(t->dst_codec.name, t->dst_codec.type, t->dst_codec.sample_rate); + ast_s_codec_get(&dst_codec, t->dst_codec.name, t->dst_codec.type, t->dst_codec.sample_rate); if (!dst_codec) { ast_log(LOG_WARNING, "Failed to register translator: unknown destination codec %s\n", t->dst_codec.name); return -1; @@ -1383,8 +1382,8 @@ int ast_translator_best_choice(struct ast_format_cap *dst_cap, struct ast_format *fmt; struct ast_format *dst; struct ast_format *src; - RAII_VAR(struct ast_format *, best, NULL, ao2_cleanup); - RAII_VAR(struct ast_format *, bestdst, NULL, ao2_cleanup); + RAII_AO2_S(struct ast_format *, best, NULL); + RAII_AO2_S(struct ast_format *, bestdst, NULL); struct ast_format_cap *joint_cap; int i; int j; @@ -1394,64 +1393,68 @@ int ast_translator_best_choice(struct ast_format_cap *dst_cap, return -1; } - joint_cap = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT); + ast_s_format_cap_alloc(&joint_cap, AST_FORMAT_CAP_FLAG_DEFAULT); if (!joint_cap) { return -1; } ast_format_cap_get_compatible(dst_cap, src_cap, joint_cap); - for (i = 0; i < ast_format_cap_count(joint_cap); ++i, ao2_cleanup(fmt)) { - fmt = ast_format_cap_get_format(joint_cap, i); + for (i = 0; i < ast_format_cap_count(joint_cap); ++i) { + ast_s_format_cap_get_format(&fmt, joint_cap, i); if (!fmt || ast_format_get_type(fmt) != AST_MEDIA_TYPE_AUDIO) { + ao2_s_cleanup(&fmt); continue; } if (!best || ast_format_get_sample_rate(best) < ast_format_get_sample_rate(fmt)) { - ao2_replace(best, fmt); + ao2_s_replace(&best, fmt); } + + ao2_s_cleanup(&fmt); } - ao2_ref(joint_cap, -1); + ao2_s_cleanup(&joint_cap); if (best) { - ao2_replace(*dst_fmt_out, best); - ao2_replace(*src_fmt_out, best); + ao2_s_replace(dst_fmt_out, best); + ao2_s_replace(src_fmt_out, best); return 0; } /* need to translate */ AST_RWLIST_RDLOCK(&translators); - for (i = 0; i < ast_format_cap_count(dst_cap); ++i, ao2_cleanup(dst)) { - dst = ast_format_cap_get_format(dst_cap, i); + for (i = 0; i < ast_format_cap_count(dst_cap); ++i) { + ast_s_format_cap_get_format(&dst, dst_cap, i); if (!dst || ast_format_get_type(dst) != AST_MEDIA_TYPE_AUDIO) { + ao2_s_cleanup(&dst); continue; } - for (j = 0; j < ast_format_cap_count(src_cap); ++j, ao2_cleanup(src)) { + for (j = 0; j < ast_format_cap_count(src_cap); ++j) { int x; int y; - src = ast_format_cap_get_format(src_cap, j); + ast_s_format_cap_get_format(&src, src_cap, j); if (!src || ast_format_get_type(src) != AST_MEDIA_TYPE_AUDIO) { - continue; + goto cleanup_src; } x = format2index(src); y = format2index(dst); if (x < 0 || y < 0) { - continue; + goto cleanup_src; } if (!matrix_get(x, y) || !(matrix_get(x, y)->step)) { - continue; + goto cleanup_src; } if (matrix_get(x, y)->table_cost < besttablecost || matrix_get(x, y)->multistep < beststeps) { /* better than what we have so far */ - ao2_replace(best, src); - ao2_replace(bestdst, dst); + ao2_s_replace(&best, src); + ao2_s_replace(&bestdst, dst); besttablecost = matrix_get(x, y)->table_cost; beststeps = matrix_get(x, y)->multistep; } else if (matrix_get(x, y)->table_cost == besttablecost @@ -1467,15 +1470,19 @@ int ast_translator_best_choice(struct ast_format_cap *dst_cap, beststeps = matrix_get(x, y)->multistep; } } +cleanup_src: + ao2_s_cleanup(&src) } + + ao2_s_cleanup(&dst); } AST_RWLIST_UNLOCK(&translators); if (!best) { return -1; } - ao2_replace(*dst_fmt_out, bestdst); - ao2_replace(*src_fmt_out, best); + ao2_s_replace(dst_fmt_out, bestdst); + ao2_s_replace(src_fmt_out, best); return 0; } -- 2.17.1