]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
Cache string values of formats on ast_format_cap() to save processing.
authorMark Michelson <mmichelson@digium.com>
Wed, 2 Oct 2013 22:34:05 +0000 (22:34 +0000)
committerMark Michelson <mmichelson@digium.com>
Wed, 2 Oct 2013 22:34:05 +0000 (22:34 +0000)
Channel snapshots have string representations of the channel's native formats.
Prior to this change, the format strings were re-created on ever channel snapshot
creation. Since channel native formats rarely change, this was very wasteful.
Now, string representations of formats may optionally be stored on the ast_format_cap
for cases where string representations may be requested frequently. When formats
are altered, the string cache is marked as invalid. When strings are requested, the
cache validity is checked. If the cache is valid, then the cached strings are copied.
If the cache is invalid, then the string cache is rebuilt and copied, and the cache
is marked as being valid again.

Review: https://reviewboard.asterisk.org/r/2879

git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/12@400356 65c4cc65-6c06-0410-ace0-fbb531ad65f3

51 files changed:
addons/chan_mobile.c
addons/chan_ooh323.c
apps/app_confbridge.c
apps/app_meetme.c
apps/app_originate.c
bridges/bridge_holding.c
bridges/bridge_native_rtp.c
bridges/bridge_simple.c
bridges/bridge_softmix.c
channels/chan_alsa.c
channels/chan_bridge_media.c
channels/chan_console.c
channels/chan_dahdi.c
channels/chan_gtalk.c
channels/chan_h323.c
channels/chan_iax2.c
channels/chan_jingle.c
channels/chan_mgcp.c
channels/chan_misdn.c
channels/chan_motif.c
channels/chan_multicast_rtp.c
channels/chan_nbs.c
channels/chan_oss.c
channels/chan_phone.c
channels/chan_pjsip.c
channels/chan_sip.c
channels/chan_skinny.c
channels/chan_unistim.c
channels/dahdi/bridge_native_dahdi.c
include/asterisk/format_cap.h
main/bridge_basic.c
main/ccss.c
main/channel.c
main/core_local.c
main/dial.c
main/file.c
main/format_cap.c
main/manager.c
main/media_index.c
main/rtp_engine.c
pbx/pbx_spool.c
res/ari/resource_bridges.c
res/parking/parking_applications.c
res/res_agi.c
res/res_clioriginate.c
res/res_pjsip/pjsip_configuration.c
res/res_pjsip_sdp_rtp.c
res/res_pjsip_session.c
res/res_stasis.c
tests/test_config.c
tests/test_format_api.c

index f5d5b4e1a96422db8549b0cfe7b1dd4775ad1bcc..2cf7c7dbdd49906c7bc4d0cae846cc77f7a705d1 100644 (file)
@@ -4705,7 +4705,7 @@ static int load_module(void)
 
        int dev_id, s;
 
-       if (!(mbl_tech.capabilities = ast_format_cap_alloc())) {
+       if (!(mbl_tech.capabilities = ast_format_cap_alloc(0))) {
                return AST_MODULE_LOAD_DECLINE;
        }
        ast_format_set(&prefformat, DEVICE_FRAME_FORMAT, 0);
index 303b06857a4cfb4dce5bab22e8f1843c08e0f9e7..f374a216bce16673d0bbe0a476592bdb162376d3 100644 (file)
@@ -521,7 +521,7 @@ static struct ooh323_pvt *ooh323_alloc(int callref, char *callToken)
                ast_log(LOG_ERROR, "Couldn't allocate private ooh323 structure\n");
                return NULL;
        }
-       if (!(pvt->cap = ast_format_cap_alloc_nolock())) {
+       if (!(pvt->cap = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_NOLOCK))) {
                ast_free(pvt);
                ast_log(LOG_ERROR, "Couldn't allocate private ooh323 structure\n");
                return NULL;
@@ -2304,7 +2304,7 @@ static struct ooh323_user *build_user(const char *name, struct ast_variable *v)
        user = ast_calloc(1,sizeof(struct ooh323_user));
        if (user) {
                memset(user, 0, sizeof(struct ooh323_user));
-               if (!(user->cap = ast_format_cap_alloc())) {
+               if (!(user->cap = ast_format_cap_alloc(0))) {
                        ast_free(user);
                        return NULL;
                }
@@ -2452,7 +2452,7 @@ static struct ooh323_peer *build_peer(const char *name, struct ast_variable *v,
        peer = ast_calloc(1, sizeof(*peer));
        if (peer) {
                memset(peer, 0, sizeof(struct ooh323_peer));
-               if (!(peer->cap = ast_format_cap_alloc())) {
+               if (!(peer->cap = ast_format_cap_alloc(0))) {
                        ast_free(peer);
                        return NULL;
                }
@@ -3677,10 +3677,10 @@ static int load_module(void)
                .onModeChanged = onModeChanged,
                .onMediaChanged = (cb_OnMediaChanged) setup_rtp_remote,
        };
-       if (!(gCap = ast_format_cap_alloc())) {
+       if (!(gCap = ast_format_cap_alloc(0))) {
                return 1; 
        }
-       if (!(ooh323_tech.capabilities = ast_format_cap_alloc())) {
+       if (!(ooh323_tech.capabilities = ast_format_cap_alloc(0))) {
                return 1;
        }
        ast_format_cap_add(gCap, ast_format_set(&tmpfmt, AST_FORMAT_ULAW, 0));
index d9db7ab5b6c9066fbd49e3be4db7b9579fcc8cbd..47cfa0b8bab0a35510bf4fae8ed42ee5caf2e0bb 100644 (file)
@@ -662,7 +662,7 @@ static int conf_start_record(struct confbridge_conference *conference)
                return -1;
        }
 
-       cap = ast_format_cap_alloc_nolock();
+       cap = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_NOLOCK);
        if (!cap) {
                return -1;
        }
@@ -1327,7 +1327,7 @@ static int alloc_playback_chan(struct confbridge_conference *conference)
        struct ast_format_cap *cap;
        struct ast_format format;
 
-       cap = ast_format_cap_alloc_nolock();
+       cap = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_NOLOCK);
        if (!cap) {
                return -1;
        }
@@ -3094,7 +3094,7 @@ static void unregister_channel_tech(struct ast_channel_tech *tech)
  */
 static int register_channel_tech(struct ast_channel_tech *tech)
 {
-       tech->capabilities = ast_format_cap_alloc();
+       tech->capabilities = ast_format_cap_alloc(0);
        if (!tech->capabilities) {
                return -1;
        }
index cd6a4f72c66aea44bf59804b48a0004e18d0ace0..ffd55e70dffdb8b9cd94417f9d80923ed56f33ad 100644 (file)
@@ -1611,7 +1611,7 @@ static struct ast_conference *build_conf(const char *confno, const char *pin,
        struct ast_conference *cnf;
        struct dahdi_confinfo dahdic = { 0, };
        int confno_int = 0;
-       struct ast_format_cap *cap_slin = ast_format_cap_alloc_nolock();
+       struct ast_format_cap *cap_slin = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_NOLOCK);
        struct ast_format tmp_fmt;
 
        AST_LIST_LOCK(&confs);
@@ -3216,7 +3216,7 @@ static int conf_run(struct ast_channel *chan, struct ast_conference *conf, struc
        int setusercount = 0;
        int confsilence = 0, totalsilence = 0;
        char *mailbox, *context;
-       struct ast_format_cap *cap_slin = ast_format_cap_alloc_nolock();
+       struct ast_format_cap *cap_slin = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_NOLOCK);
        struct ast_format tmpfmt;
 
        if (!cap_slin) {
index 8eb8ba329c73856f51705a83ecf57ff459e8d0fb..f924921d438dcc0f29e2dfd3889c119cf368c570 100644 (file)
@@ -113,7 +113,7 @@ static int originate_exec(struct ast_channel *chan, const char *data)
        unsigned int timeout = 30;
        static const char default_exten[] = "s";
        struct ast_format tmpfmt;
-       struct ast_format_cap *cap_slin = ast_format_cap_alloc_nolock();
+       struct ast_format_cap *cap_slin = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_NOLOCK);
 
        ast_autoservice_start(chan);
        if (!cap_slin) {
index 9d0ba721a1a832212faa34bc4ab6fda505c12954..5eeb4708da3322e86ff02e9ef68c0f6f73b48908 100644 (file)
@@ -433,7 +433,7 @@ static int unload_module(void)
 
 static int load_module(void)
 {
-       if (!(holding_bridge.format_capabilities = ast_format_cap_alloc())) {
+       if (!(holding_bridge.format_capabilities = ast_format_cap_alloc(0))) {
                return AST_MODULE_LOAD_DECLINE;
        }
        ast_format_cap_add_all_by_type(holding_bridge.format_capabilities, AST_FORMAT_TYPE_AUDIO);
index c8bf880b6f29ea2727d4be1a57d16b77db70cf66..7775d41ec18316fa32146187ec8b3615b060e375 100644 (file)
@@ -124,8 +124,8 @@ static int native_rtp_bridge_start(struct ast_bridge *bridge, struct ast_channel
        RAII_VAR(struct ast_rtp_instance *, vinstance1, NULL, ao2_cleanup);
        RAII_VAR(struct ast_rtp_instance *, tinstance0, NULL, ao2_cleanup);
        RAII_VAR(struct ast_rtp_instance *, tinstance1, NULL, ao2_cleanup);
-       RAII_VAR(struct ast_format_cap *, cap0, ast_format_cap_alloc_nolock(), ast_format_cap_destroy);
-       RAII_VAR(struct ast_format_cap *, cap1, ast_format_cap_alloc_nolock(), ast_format_cap_destroy);
+       RAII_VAR(struct ast_format_cap *, cap0, ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_NOLOCK), ast_format_cap_destroy);
+       RAII_VAR(struct ast_format_cap *, cap1, ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_NOLOCK), ast_format_cap_destroy);
 
        if (c0 == c1) {
                return 0;
@@ -279,8 +279,8 @@ static int native_rtp_bridge_compatible(struct ast_bridge *bridge)
        RAII_VAR(struct ast_rtp_instance *, instance1, NULL, ao2_cleanup);
        RAII_VAR(struct ast_rtp_instance *, vinstance0, NULL, ao2_cleanup);
        RAII_VAR(struct ast_rtp_instance *, vinstance1, NULL, ao2_cleanup);
-       RAII_VAR(struct ast_format_cap *, cap0, ast_format_cap_alloc_nolock(), ast_format_cap_destroy);
-       RAII_VAR(struct ast_format_cap *, cap1, ast_format_cap_alloc_nolock(), ast_format_cap_destroy);
+       RAII_VAR(struct ast_format_cap *, cap0, ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_NOLOCK), ast_format_cap_destroy);
+       RAII_VAR(struct ast_format_cap *, cap1, ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_NOLOCK), ast_format_cap_destroy);
        int read_ptime0, read_ptime1, write_ptime0, write_ptime1;
 
        /* We require two channels before even considering native bridging */
@@ -448,7 +448,7 @@ static int unload_module(void)
 
 static int load_module(void)
 {
-       if (!(native_rtp_bridge.format_capabilities = ast_format_cap_alloc())) {
+       if (!(native_rtp_bridge.format_capabilities = ast_format_cap_alloc(0))) {
                return AST_MODULE_LOAD_DECLINE;
        }
        ast_format_cap_add_all_by_type(native_rtp_bridge.format_capabilities, AST_FORMAT_TYPE_AUDIO);
index 78ac7a4ae2c5f97a0ccb57254ce34d1fdd9426a6..4a03dbe10a8d798a562d6c9ed8fc4704d7152654 100644 (file)
@@ -82,7 +82,7 @@ static int unload_module(void)
 
 static int load_module(void)
 {
-       if (!(simple_bridge.format_capabilities = ast_format_cap_alloc())) {
+       if (!(simple_bridge.format_capabilities = ast_format_cap_alloc(0))) {
                return AST_MODULE_LOAD_DECLINE;
        }
        ast_format_cap_add_all_by_type(simple_bridge.format_capabilities, AST_FORMAT_TYPE_AUDIO);
index c6cde396d659b216b1a8433759a1d0123c9359b3..b7cce866ceed1ae0aea7e334abef26b2d60ca19a 100644 (file)
@@ -1137,7 +1137,7 @@ static int unload_module(void)
 static int load_module(void)
 {
        struct ast_format tmp;
-       if (!(softmix_bridge.format_capabilities = ast_format_cap_alloc())) {
+       if (!(softmix_bridge.format_capabilities = ast_format_cap_alloc(0))) {
                return AST_MODULE_LOAD_DECLINE;
        }
        ast_format_cap_add(softmix_bridge.format_capabilities, ast_format_set(&tmp, AST_FORMAT_SLINEAR, 0));
index f1720ba8cea2563b0af69aa4f10a5d58ce29b450..60bbacbb86e06ad0c01de250a5397fd9e4b65930 100644 (file)
@@ -960,7 +960,7 @@ static int load_module(void)
        struct ast_flags config_flags = { 0 };
        struct ast_format tmpfmt;
 
-       if (!(alsa_tech.capabilities = ast_format_cap_alloc())) {
+       if (!(alsa_tech.capabilities = ast_format_cap_alloc(0))) {
                return AST_MODULE_LOAD_DECLINE;
        }
        ast_format_cap_add(alsa_tech.capabilities, ast_format_set(&tmpfmt, AST_FORMAT_SLINEAR, 0));
index 663578033eb6cacb5087dd745a78a837e892c2ca..7aaca6671552cecc01e0b92cb60e5f6b918dcb3e 100644 (file)
@@ -182,12 +182,12 @@ static int unload_module(void)
 
 static int load_module(void)
 {
-       announce_tech.capabilities = ast_format_cap_alloc();
+       announce_tech.capabilities = ast_format_cap_alloc(0);
        if (!announce_tech.capabilities) {
                return AST_MODULE_LOAD_DECLINE;
        }
 
-       record_tech.capabilities = ast_format_cap_alloc();
+       record_tech.capabilities = ast_format_cap_alloc(0);
        if (!record_tech.capabilities) {
                return AST_MODULE_LOAD_DECLINE;
        }
index 76571d20989cbafad259f56010f89669e2a0d119..922c53b426125aa1b9355ad60cf2283e928e6508 100644 (file)
@@ -1497,7 +1497,7 @@ static int load_module(void)
        struct ast_format tmpfmt;
        PaError res;
 
-       if (!(console_tech.capabilities = ast_format_cap_alloc())) {
+       if (!(console_tech.capabilities = ast_format_cap_alloc(0))) {
                return AST_MODULE_LOAD_DECLINE;
        }
        ast_format_cap_add(console_tech.capabilities, ast_format_set(&tmpfmt, AST_FORMAT_SLINEAR16, 0));
index 65a9758f2632e568d8ef5118b2c3d308c0ccf1a1..e52969b5dbb0bcaeee859a4cec687bc5baf657b0 100644 (file)
@@ -18550,7 +18550,7 @@ static int load_module(void)
                return AST_MODULE_LOAD_FAILURE;
        }
 
-       if (!(dahdi_tech.capabilities = ast_format_cap_alloc())) {
+       if (!(dahdi_tech.capabilities = ast_format_cap_alloc(0))) {
                return AST_MODULE_LOAD_FAILURE;
        }
        ast_format_cap_add(dahdi_tech.capabilities, ast_format_set(&tmpfmt, AST_FORMAT_SLINEAR, 0));
index a44ca57f46f78a313048732f88812278b5f68686..d6a09494197c08036ba4115d71369b7635849296 100644 (file)
@@ -436,7 +436,7 @@ static int gtalk_invite(struct gtalk_pvt *p, char *to, char *from, char *sid, in
        iks_insert_attrib(dcodecs, "xmlns", GOOGLE_AUDIO_NS);
        iks_insert_attrib(dcodecs, "xml:lang", "en");
 
-       if (!(alreadysent = ast_format_cap_alloc_nolock())) {
+       if (!(alreadysent = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_NOLOCK))) {
                return 0;
        }
        for (x = 0; x < AST_CODEC_PREF_SIZE; x++) {
@@ -1063,9 +1063,9 @@ static struct gtalk_pvt *gtalk_alloc(struct gtalk *client, const char *us, const
        if (!(tmp = ast_calloc(1, sizeof(*tmp)))) {
                return NULL;
        }
-       tmp->cap = ast_format_cap_alloc_nolock();
-       tmp->jointcap = ast_format_cap_alloc_nolock();
-       tmp->peercap = ast_format_cap_alloc_nolock();
+       tmp->cap = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_NOLOCK);
+       tmp->jointcap = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_NOLOCK);
+       tmp->peercap = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_NOLOCK);
        if (!tmp->jointcap || !tmp->peercap || !tmp->cap) {
                tmp->cap = ast_format_cap_destroy(tmp->cap);
                tmp->jointcap = ast_format_cap_destroy(tmp->jointcap);
@@ -2256,7 +2256,7 @@ static int gtalk_load_config(void)
                        member = ast_calloc(1, sizeof(*member));
                        ASTOBJ_INIT(member);
                        ASTOBJ_WRLOCK(member);
-                       member->cap = ast_format_cap_alloc_nolock();
+                       member->cap = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_NOLOCK);
                        if (!strcasecmp(cat, "guest")) {
                                ast_copy_string(member->name, "guest", sizeof(member->name));
                                ast_copy_string(member->user, "guest", sizeof(member->user));
@@ -2336,10 +2336,10 @@ static int load_module(void)
        char *jabber_loaded = ast_module_helper("", "res_jabber.so", 0, 0, 0, 0);
        struct ast_format tmpfmt;
 
-       if (!(gtalk_tech.capabilities = ast_format_cap_alloc())) {
+       if (!(gtalk_tech.capabilities = ast_format_cap_alloc(0))) {
                return AST_MODULE_LOAD_DECLINE;
        }
-       if (!(global_capability = ast_format_cap_alloc())) {
+       if (!(global_capability = ast_format_cap_alloc(0))) {
                return AST_MODULE_LOAD_DECLINE;
        }
 
index dd23b7f597150243f7f493613c4ece70ef1de7dc..22dba3c18307b65a5ed78f282271cfc570ab647a 100644 (file)
@@ -1313,7 +1313,7 @@ static struct oh323_alias *realtime_alias(const char *alias)
 static int h323_parse_allow_disallow(struct ast_codec_pref *pref, h323_format *formats, const char *list, int allowing)
 {
        int res;
-       struct ast_format_cap *cap = ast_format_cap_alloc_nolock();
+       struct ast_format_cap *cap = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_NOLOCK);
        if (!cap) {
                return 1;
        }
@@ -2093,7 +2093,7 @@ static void setup_rtp_connection(unsigned call_reference, const char *remoteIp,
        /* Don't try to lock the channel if nothing changed */
        if (nativeformats_changed || pvt->options.progress_audio || (rtp_change != NEED_NONE)) {
                if (pvt->owner && !ast_channel_trylock(pvt->owner)) {
-                       struct ast_format_cap *pvt_native = ast_format_cap_alloc_nolock();
+                       struct ast_format_cap *pvt_native = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_NOLOCK);
                        ast_format_cap_from_old_bitfield(pvt_native, pvt->nativeformats);
 
                        /* Re-build translation path only if native format(s) has been changed */
@@ -3336,7 +3336,7 @@ static enum ast_module_load_result load_module(void)
 {
        int res;
 
-       if (!(oh323_tech.capabilities = ast_format_cap_alloc())) {
+       if (!(oh323_tech.capabilities = ast_format_cap_alloc(0))) {
                return AST_MODULE_LOAD_FAILURE;
        }
        ast_format_cap_add_all_by_type(oh323_tech.capabilities, AST_FORMAT_TYPE_AUDIO);
index 551c2046dc9f7cb5a0e513cd7713e990602debc0..77fd442773092d1389ee631573b9e72f94533b72 100644 (file)
@@ -1717,7 +1717,7 @@ static iax2_format iax2_codec_choose(struct ast_codec_pref *pref, iax2_format fo
        struct ast_format_cap *cap;
        struct ast_format tmpfmt;
        iax2_format format = 0;
-       if ((cap = ast_format_cap_alloc_nolock())) {
+       if ((cap = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_NOLOCK))) {
                ast_format_clear(&tmpfmt);
                ast_format_cap_from_old_bitfield(cap, formats);
                ast_codec_choose(pref, cap, find_best, &tmpfmt);
@@ -1730,7 +1730,7 @@ static iax2_format iax2_codec_choose(struct ast_codec_pref *pref, iax2_format fo
 
 static iax2_format iax2_best_codec(iax2_format formats)
 {
-       struct ast_format_cap *cap = ast_format_cap_alloc_nolock();
+       struct ast_format_cap *cap = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_NOLOCK);
        struct ast_format tmpfmt;
        if (!cap) {
                return 0;
@@ -1755,7 +1755,7 @@ const char *iax2_getformatname(iax2_format format)
 
 static char *iax2_getformatname_multiple(char *codec_buf, size_t len, iax2_format format)
 {
-       struct ast_format_cap *cap = ast_format_cap_alloc_nolock();
+       struct ast_format_cap *cap = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_NOLOCK);
 
        if (!cap) {
                return "(Nothing)";
@@ -1770,7 +1770,7 @@ static char *iax2_getformatname_multiple(char *codec_buf, size_t len, iax2_forma
 static int iax2_parse_allow_disallow(struct ast_codec_pref *pref, iax2_format *formats, const char *list, int allowing)
 {
        int res;
-       struct ast_format_cap *cap = ast_format_cap_alloc_nolock();
+       struct ast_format_cap *cap = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_NOLOCK);
        if (!cap) {
                return 1;
        }
@@ -1786,7 +1786,7 @@ static int iax2_parse_allow_disallow(struct ast_codec_pref *pref, iax2_format *f
 static int iax2_data_add_codecs(struct ast_data *root, const char *node_name, iax2_format formats)
 {
        int res;
-       struct ast_format_cap *cap = ast_format_cap_alloc_nolock();
+       struct ast_format_cap *cap = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_NOLOCK);
        if (!cap) {
                return -1;
        }
@@ -14624,7 +14624,7 @@ static int load_module(void)
        int x = 0;
        struct iax2_registry *reg = NULL;
 
-       if (!(iax2_tech.capabilities = ast_format_cap_alloc())) {
+       if (!(iax2_tech.capabilities = ast_format_cap_alloc(0))) {
                return AST_MODULE_LOAD_FAILURE;
        }
        ast_format_cap_add_all(iax2_tech.capabilities);
index a8cab623830d9787ec98aad3ee2c32ec14d67a65..56c15b193f6f14cf4d359f4fa9163f6786933098 100644 (file)
@@ -322,7 +322,7 @@ static int jingle_accept_call(struct jingle *client, struct jingle_pvt *p)
        iks *iq, *jingle, *dcodecs, *payload_red, *payload_audio, *payload_cn;
        int x;
        struct ast_format pref_codec;
-       struct ast_format_cap *alreadysent = ast_format_cap_alloc_nolock();
+       struct ast_format_cap *alreadysent = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_NOLOCK);
 
        if (p->initiator || !alreadysent)
                return 1;
@@ -798,9 +798,9 @@ static struct jingle_pvt *jingle_alloc(struct jingle *client, const char *from,
                return NULL;
        }
 
-       tmp->cap = ast_format_cap_alloc_nolock();
-       tmp->jointcap = ast_format_cap_alloc_nolock();
-       tmp->peercap = ast_format_cap_alloc_nolock();
+       tmp->cap = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_NOLOCK);
+       tmp->jointcap = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_NOLOCK);
+       tmp->peercap = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_NOLOCK);
        if (!tmp->cap || !tmp->jointcap || !tmp->peercap) {
                tmp->cap = ast_format_cap_destroy(tmp->cap);
                tmp->jointcap = ast_format_cap_destroy(tmp->jointcap);
@@ -1897,7 +1897,7 @@ static int jingle_load_config(void)
                        member = ast_calloc(1, sizeof(*member));
                        ASTOBJ_INIT(member);
                        ASTOBJ_WRLOCK(member);
-                       member->cap = ast_format_cap_alloc_nolock();
+                       member->cap = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_NOLOCK);
                        if (!strcasecmp(cat, "guest")) {
                                ast_copy_string(member->name, "guest", sizeof(member->name));
                                ast_copy_string(member->user, "guest", sizeof(member->user));
@@ -1981,12 +1981,12 @@ static int load_module(void)
 
        char *jabber_loaded = ast_module_helper("", "res_jabber.so", 0, 0, 0, 0);
 
-       if (!(jingle_tech.capabilities = ast_format_cap_alloc())) {
+       if (!(jingle_tech.capabilities = ast_format_cap_alloc(0))) {
                return AST_MODULE_LOAD_DECLINE;
        }
 
        ast_format_cap_add_all_by_type(jingle_tech.capabilities, AST_FORMAT_TYPE_AUDIO);
-       if (!(global_capability = ast_format_cap_alloc())) {
+       if (!(global_capability = ast_format_cap_alloc(0))) {
                return AST_MODULE_LOAD_DECLINE;
        }
        ast_format_cap_add(global_capability, ast_format_set(&tmpfmt, AST_FORMAT_ULAW, 0));
index 7c91200882cace4b10f17d1a98b2dcecf20c2d86..a659a2aab445eb4cd9ab6778d615e20bc86cdabc 100644 (file)
@@ -2039,7 +2039,7 @@ static int process_sdp(struct mgcp_subchannel *sub, struct mgcp_request *req)
        }
 
        /* Now gather all of the codecs that were asked for: */
-       if (!(peercap = ast_format_cap_alloc_nolock())) {
+       if (!(peercap = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_NOLOCK))) {
                return -1;
        }
        ast_rtp_codecs_payload_formats(ast_rtp_instance_get_codecs(sub->rtp), peercap, &peerNonCodecCapability);
@@ -4172,7 +4172,7 @@ static struct mgcp_gateway *build_gateway(char *cat, struct ast_variable *v)
                                        ast_mutex_init(&e->lock);
                                        ast_mutex_init(&e->rqnt_queue_lock);
                                        ast_mutex_init(&e->cmd_queue_lock);
-                                       e->cap = ast_format_cap_alloc_nolock();
+                                       e->cap = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_NOLOCK);
                                        ast_copy_string(e->name, v->value, sizeof(e->name));
                                        e->needaudit = 1;
                                }
@@ -4288,7 +4288,7 @@ static struct mgcp_gateway *build_gateway(char *cat, struct ast_variable *v)
                                        ast_mutex_init(&e->lock);
                                        ast_mutex_init(&e->rqnt_queue_lock);
                                        ast_mutex_init(&e->cmd_queue_lock);
-                                       e->cap = ast_format_cap_alloc_nolock();
+                                       e->cap = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_NOLOCK);
                                        ast_copy_string(e->name, v->value, sizeof(e->name));
                                        e->needaudit = 1;
                                }
@@ -4829,10 +4829,10 @@ static int load_module(void)
 {
        struct ast_format tmpfmt;
 
-       if (!(global_capability = ast_format_cap_alloc())) {
+       if (!(global_capability = ast_format_cap_alloc(0))) {
                return AST_MODULE_LOAD_FAILURE;
        }
-       if (!(mgcp_tech.capabilities = ast_format_cap_alloc())) {
+       if (!(mgcp_tech.capabilities = ast_format_cap_alloc(0))) {
                return AST_MODULE_LOAD_FAILURE;
        }
        ast_format_cap_add(global_capability, ast_format_set(&tmpfmt, AST_FORMAT_ULAW, 0));
index 29274e743a4daf3ca94643519a358d3ca63e59cc..38197c6381e63f4c7464dd9453aed02f23f15c94 100644 (file)
@@ -10193,7 +10193,7 @@ cb_events(enum event_e event, struct misdn_bchannel *bc, void *user_data)
                ch->addr = bc->addr;
 
                {
-                       struct ast_format_cap *cap = ast_format_cap_alloc_nolock();
+                       struct ast_format_cap *cap = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_NOLOCK);
                        struct ast_format tmpfmt;
                        if (!(cap)) {
                                return RESPONSE_ERR;
@@ -11298,7 +11298,7 @@ static int load_module(void)
        };
 
 
-       if (!(misdn_tech.capabilities = ast_format_cap_alloc())) {
+       if (!(misdn_tech.capabilities = ast_format_cap_alloc(0))) {
                return AST_MODULE_LOAD_DECLINE;
        }
        ast_format_set(&prefformat, AST_FORMAT_ALAW, 0);
index e13c66c6feaf15e5c7f95105f29696662c7502a6..1e7ee3cce67c58a37e53dcebcb606be04698ffaa 100644 (file)
@@ -519,7 +519,7 @@ static void *jingle_endpoint_alloc(const char *cat)
 
        ast_string_field_set(endpoint, name, cat);
 
-       endpoint->cap = ast_format_cap_alloc_nolock();
+       endpoint->cap = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_NOLOCK);
        endpoint->transport = JINGLE_TRANSPORT_ICE_UDP;
 
        return endpoint;
@@ -741,9 +741,9 @@ static struct jingle_session *jingle_alloc(struct jingle_endpoint *endpoint, con
        session->connection = endpoint->connection;
        session->transport = endpoint->transport;
 
-       if (!(session->cap = ast_format_cap_alloc_nolock()) ||
-           !(session->jointcap = ast_format_cap_alloc_nolock()) ||
-           !(session->peercap = ast_format_cap_alloc_nolock()) ||
+       if (!(session->cap = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_NOLOCK)) ||
+           !(session->jointcap = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_NOLOCK)) ||
+           !(session->peercap = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_NOLOCK)) ||
            !session->callid) {
                ao2_ref(session, -1);
                return NULL;
@@ -2707,7 +2707,7 @@ static int custom_transport_handler(const struct aco_option *opt, struct ast_var
  */
 static int load_module(void)
 {
-       if (!(jingle_tech.capabilities = ast_format_cap_alloc())) {
+       if (!(jingle_tech.capabilities = ast_format_cap_alloc(0))) {
                return AST_MODULE_LOAD_DECLINE;
        }
 
index 4629829698ee3f754782513dfa24229767da9696..1b9e4d31f26a88e6300df9da4216dffaf603f7fc 100644 (file)
@@ -176,7 +176,7 @@ failure:
 /*! \brief Function called when our module is loaded */
 static int load_module(void)
 {
-       if (!(multicast_rtp_tech.capabilities = ast_format_cap_alloc())) {
+       if (!(multicast_rtp_tech.capabilities = ast_format_cap_alloc(0))) {
                return AST_MODULE_LOAD_DECLINE;
        }
        ast_format_cap_add_all(multicast_rtp_tech.capabilities);
index e6384872ee1e48440d8f164a79572355ab117941..1d8c59d4e1d819c0c9e95030b4355aa84023cb38 100644 (file)
@@ -281,7 +281,7 @@ static int unload_module(void)
 static int load_module(void)
 {
        ast_format_set(&prefformat, AST_FORMAT_SLINEAR, 0);
-       if (!(nbs_tech.capabilities = ast_format_cap_alloc())) {
+       if (!(nbs_tech.capabilities = ast_format_cap_alloc(0))) {
                return AST_MODULE_LOAD_FAILURE;
        }
        ast_format_cap_add(nbs_tech.capabilities, &prefformat);
index f8e67e59e800a1180842a899596882781936b40d..5ae18f362e8ae9b8c67fe84a44a782a7e70d321b 100644 (file)
@@ -1479,7 +1479,7 @@ static int load_module(void)
                return AST_MODULE_LOAD_FAILURE;
        }
 
-       if (!(oss_tech.capabilities = ast_format_cap_alloc())) {
+       if (!(oss_tech.capabilities = ast_format_cap_alloc(0))) {
                return AST_MODULE_LOAD_FAILURE;
        }
        ast_format_cap_add(oss_tech.capabilities, ast_format_set(&tmpfmt, AST_FORMAT_SLINEAR, 0));
index 71a498a8585bb931ccc4b9ec1557a02129db9ff3..c1a24b8b1b95dffcc01eab349eabc4ed8403bb4d 100644 (file)
@@ -1376,7 +1376,7 @@ static int load_module(void)
        struct ast_flags config_flags = { 0 };
        struct ast_format tmpfmt;
 
-       if (!(phone_tech.capabilities = ast_format_cap_alloc())) {
+       if (!(phone_tech.capabilities = ast_format_cap_alloc(0))) {
                return AST_MODULE_LOAD_DECLINE;
        }
        ast_format_cap_add(phone_tech.capabilities, ast_format_set(&tmpfmt, AST_FORMAT_G723_1, 0));
@@ -1384,11 +1384,11 @@ static int load_module(void)
        ast_format_cap_add(phone_tech.capabilities, ast_format_set(&tmpfmt, AST_FORMAT_ULAW, 0));
        ast_format_cap_add(phone_tech.capabilities, ast_format_set(&tmpfmt, AST_FORMAT_G729A, 0));
 
-       if (!(prefcap = ast_format_cap_alloc())) {
+       if (!(prefcap = ast_format_cap_alloc(0))) {
                return AST_MODULE_LOAD_DECLINE;
        }
        ast_format_cap_copy(prefcap, phone_tech.capabilities);
-       if (!(phone_tech_fxs.capabilities = ast_format_cap_alloc())) {
+       if (!(phone_tech_fxs.capabilities = ast_format_cap_alloc(0))) {
                return AST_MODULE_LOAD_DECLINE;
        }
 
index e505751c3a1cd557ab6331b42f376950150191a8..6ceece4fcc889c2c11899e14952178fc8d95d013 100644 (file)
@@ -2065,7 +2065,7 @@ static int chan_pjsip_incoming_ack(struct ast_sip_session *session, struct pjsip
  */
 static int load_module(void)
 {
-       if (!(chan_pjsip_tech.capabilities = ast_format_cap_alloc())) {
+       if (!(chan_pjsip_tech.capabilities = ast_format_cap_alloc(0))) {
                return AST_MODULE_LOAD_DECLINE;
        }
 
index 497fb6e616350f64756c7e8b821239d9b29911ad..00a2a16cbb18859d2da7ffed3d03b81d3f278b64 100644 (file)
@@ -8814,11 +8814,11 @@ struct sip_pvt *sip_alloc(ast_string_field callid, struct ast_sockaddr *addr,
                sip_pvt_callid_set(p, logger_callid);
        }
 
-       p->caps = ast_format_cap_alloc_nolock();
-       p->jointcaps = ast_format_cap_alloc_nolock();
-       p->peercaps = ast_format_cap_alloc_nolock();
-       p->redircaps = ast_format_cap_alloc_nolock();
-       p->prefcaps = ast_format_cap_alloc_nolock();
+       p->caps = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_NOLOCK);
+       p->jointcaps = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_NOLOCK);
+       p->peercaps = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_NOLOCK);
+       p->redircaps = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_NOLOCK);
+       p->prefcaps = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_NOLOCK);
 
        if (!p->caps|| !p->jointcaps || !p->peercaps || !p->redircaps) {
                p->caps = ast_format_cap_destroy(p->caps);
@@ -10052,15 +10052,15 @@ static int process_sdp(struct sip_pvt *p, struct sip_request *req, int t38action
        int udptlportno = -1;                   /*!< UDPTL image destination port number */
 
        /* Peer capability is the capability in the SDP, non codec is RFC2833 DTMF (101) */
-       struct ast_format_cap *peercapability = ast_format_cap_alloc_nolock();
-       struct ast_format_cap *vpeercapability = ast_format_cap_alloc_nolock();
-       struct ast_format_cap *tpeercapability = ast_format_cap_alloc_nolock();
+       struct ast_format_cap *peercapability = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_NOLOCK);
+       struct ast_format_cap *vpeercapability = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_NOLOCK);
+       struct ast_format_cap *tpeercapability = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_NOLOCK);
 
        int peernoncodeccapability = 0, vpeernoncodeccapability = 0, tpeernoncodeccapability = 0;
 
        struct ast_rtp_codecs newaudiortp = { 0, }, newvideortp = { 0, }, newtextrtp = { 0, };
-       struct ast_format_cap *newjointcapability = ast_format_cap_alloc_nolock(); /* Negotiated capability */
-       struct ast_format_cap *newpeercapability = ast_format_cap_alloc_nolock();
+       struct ast_format_cap *newjointcapability = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_NOLOCK); /* Negotiated capability */
+       struct ast_format_cap *newpeercapability = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_NOLOCK);
        int newnoncodeccapability;
 
        const char *codecs;
@@ -13136,8 +13136,8 @@ static char *crypto_get_attrib(struct ast_sdp_srtp *srtp, int dtls_enabled, int
 */
 static enum sip_result add_sdp(struct sip_request *resp, struct sip_pvt *p, int oldsdp, int add_audio, int add_t38)
 {
-       struct ast_format_cap *alreadysent = ast_format_cap_alloc_nolock();
-       struct ast_format_cap *tmpcap = ast_format_cap_alloc_nolock();
+       struct ast_format_cap *alreadysent = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_NOLOCK);
+       struct ast_format_cap *tmpcap = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_NOLOCK);
        int res = AST_SUCCESS;
        int doing_directmedia = FALSE;
        struct ast_sockaddr addr = { {0,} };
@@ -30358,7 +30358,7 @@ static struct sip_peer *temp_peer(const char *name)
                return NULL;
        }
 
-       if (!(peer->caps = ast_format_cap_alloc_nolock())) {
+       if (!(peer->caps = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_NOLOCK))) {
                ao2_t_ref(peer, -1, "failed to allocate format capabilities, drop peer");
                return NULL;
        }
@@ -30467,7 +30467,7 @@ static struct sip_peer *build_peer(const char *name, struct ast_variable *v, str
                if (!(peer->endpoint = ast_endpoint_create("SIP", name))) {
                        return NULL;
                }
-               if (!(peer->caps = ast_format_cap_alloc_nolock())) {
+               if (!(peer->caps = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_NOLOCK))) {
                        ao2_t_ref(peer, -1, "failed to allocate format capabilities, drop peer");
                        return NULL;
                }
@@ -34351,7 +34351,7 @@ static int load_module(void)
                return AST_MODULE_LOAD_FAILURE;
        }
 
-       if (!(sip_tech.capabilities = ast_format_cap_alloc())) {
+       if (!(sip_tech.capabilities = ast_format_cap_alloc(0))) {
                return AST_MODULE_LOAD_FAILURE;
        }
 
@@ -34373,7 +34373,7 @@ static int load_module(void)
                return AST_MODULE_LOAD_FAILURE;
        }
 
-       if (!(sip_cfg.caps = ast_format_cap_alloc())) {
+       if (!(sip_cfg.caps = ast_format_cap_alloc(0))) {
                return AST_MODULE_LOAD_FAILURE;
        }
        ast_format_cap_add_all_by_type(sip_tech.capabilities, AST_FORMAT_TYPE_AUDIO);
index 496de18667eefdb86bbfca62cb334947728cf22a..a65862ff3caaf70e40a9dc08d980facc40cbf97e 100644 (file)
@@ -1677,8 +1677,8 @@ static struct skinny_line *skinny_line_alloc(void)
                return NULL;
        }
 
-       l->cap = ast_format_cap_alloc_nolock();
-       l->confcap = ast_format_cap_alloc_nolock();
+       l->cap = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_NOLOCK);
+       l->confcap = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_NOLOCK);
        if (!l->cap || !l->confcap) {
                l->cap = ast_format_cap_destroy(l->cap);
                l->confcap = ast_format_cap_destroy(l->confcap);
@@ -1704,8 +1704,8 @@ static struct skinny_device *skinny_device_alloc(const char *dname)
                return NULL;
        }
 
-       d->cap = ast_format_cap_alloc_nolock();
-       d->confcap = ast_format_cap_alloc_nolock();
+       d->cap = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_NOLOCK);
+       d->confcap = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_NOLOCK);
        d->endpoint = ast_endpoint_create("Skinny", dname);
        if (!d->cap || !d->confcap || !d->endpoint) {
                d->cap = ast_format_cap_destroy(d->cap);
@@ -6643,7 +6643,7 @@ static int handle_capabilities_res_message(struct skinny_req *req, struct skinny
        struct skinny_device *d = s->device;
        struct skinny_line *l;
        uint32_t count = 0;
-       struct ast_format_cap *codecs = ast_format_cap_alloc();
+       struct ast_format_cap *codecs = ast_format_cap_alloc(0);
        int i;
 
        if (!codecs) {
@@ -8635,10 +8635,10 @@ static int load_module(void)
 {
        int res = 0;
        struct ast_format tmpfmt;
-       if (!(default_cap = ast_format_cap_alloc())) {
+       if (!(default_cap = ast_format_cap_alloc(0))) {
                return AST_MODULE_LOAD_DECLINE;
        }
-       if (!(skinny_tech.capabilities = ast_format_cap_alloc())) {
+       if (!(skinny_tech.capabilities = ast_format_cap_alloc(0))) {
                return AST_MODULE_LOAD_DECLINE;
        }
 
index 5238679880b9c88b7bc5556f424985c8f52029c4..547cd7c2f6e23aeaa654fd13073a09e1643ea214 100644 (file)
@@ -1836,7 +1836,7 @@ static struct unistim_line *unistim_line_alloc(void)
                return NULL;
        }
 
-       if (!(l->cap = ast_format_cap_alloc_nolock())) {
+       if (!(l->cap = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_NOLOCK))) {
                ast_free(l);
                return NULL;
        }
@@ -6853,10 +6853,10 @@ int load_module(void)
 {
        int res;
        struct ast_format tmpfmt;
-       if (!(global_cap = ast_format_cap_alloc())) {
+       if (!(global_cap = ast_format_cap_alloc(0))) {
                goto buff_failed;
        }
-       if (!(unistim_tech.capabilities = ast_format_cap_alloc())) {
+       if (!(unistim_tech.capabilities = ast_format_cap_alloc(0))) {
                goto buff_failed;
        }
 
index 13e1a84ddfae3713340088fa43c53c318536db22..7505eca3ef572f7ba52ed331bde1a61abfb7dbf0 100644 (file)
@@ -911,7 +911,7 @@ int dahdi_native_load(struct ast_module *mod, const struct ast_channel_tech *tec
 
        dahdi_tech = tech;
 
-       native_bridge.format_capabilities = ast_format_cap_alloc();
+       native_bridge.format_capabilities = ast_format_cap_alloc(0);
        if (!native_bridge.format_capabilities) {
                return -1;
        }
index b34f1d3ca7e8325d7d7c434afab2e664676d76ae..aa4eb3bfd6242208b74c3c24ef76df00fbc706d6 100644 (file)
 /*! Capabilities are represented by an opaque structure statically defined in format_capability.c */
 struct ast_format_cap;
 
-/*!
- * \brief Allocate a new ast_format_cap structure.
- *
- * \note Allocation of this object assumes locking
- * is already occuring and that the point of contention
- * is above this capabilities structure.  For example,
- * a tech_pvt object referencing a capabilities structure
- * can use this function as long as it always holds the
- * tech_pvt lock while accessing its capabilities.
- *
- * \retval ast_format_cap object on success.
- * \retval NULL on failure.
- */
-struct ast_format_cap *ast_format_cap_alloc_nolock(void);
+enum ast_format_cap_flags {
+       /*!
+        * The ast_format_cap will be allocated with no lock.
+        * Useful if there is a separate lock used to protect the structure
+        */
+       AST_FORMAT_CAP_FLAG_NOLOCK = (1 << 0),
+       /*!
+        * String representations of the formats are cached on the structure.
+        * Useful if string representation is frequently requested of the structure.
+        */
+       AST_FORMAT_CAP_FLAG_CACHE_STRINGS = (1 << 1),
+};
 
 /*!
- * \brief Allocate a new ast_format_cap structure with locking
- *
- * \note If no other form of locking is taking place, use this function.
- * This function makes most sense for globally accessible capabilities structures
- * that have no other means of locking.
+ * \brief Allocate a new ast_format_cap structure
  *
+ * \param flags Modifiers of struct behavior.
  * \retval ast_format_cap object on success.
  * \retval NULL on failure.
  */
-struct ast_format_cap *ast_format_cap_alloc(void);
+struct ast_format_cap *ast_format_cap_alloc(enum ast_format_cap_flags flags);
 
 /*!
  * \brief Destroy an ast_format_cap structure.
index 942a3ce25915bdd58765b6e4eaada6ce51de3f6f..76dfb289367133a0d367cbadb20559959bea5f33 100644 (file)
@@ -2218,7 +2218,7 @@ static void recall_callback(struct ast_dial *dial)
 
 static int recalling_enter(struct attended_transfer_properties *props)
 {
-       RAII_VAR(struct ast_format_cap *, cap, ast_format_cap_alloc_nolock(), ast_format_cap_destroy);
+       RAII_VAR(struct ast_format_cap *, cap, ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_NOLOCK), ast_format_cap_destroy);
        struct ast_format fmt;
 
        if (!cap) {
@@ -2346,7 +2346,7 @@ static int attach_framehook(struct attended_transfer_properties *props, struct a
 
 static int retransfer_enter(struct attended_transfer_properties *props)
 {
-       RAII_VAR(struct ast_format_cap *, cap, ast_format_cap_alloc_nolock(), ast_format_cap_destroy);
+       RAII_VAR(struct ast_format_cap *, cap, ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_NOLOCK), ast_format_cap_destroy);
        struct ast_format fmt;
        char destination[AST_MAX_EXTENSION + AST_MAX_CONTEXT + 2];
        int cause;
index 3068c6ffac9f5e09d9097737f112e4471c6f400c..fadc6e36f77bbad18ac069b7777a781e074aacc9 100644 (file)
@@ -2815,7 +2815,7 @@ static void *generic_recall(void *data)
        const char *callback_sub = ast_get_cc_callback_sub(agent->cc_params);
        unsigned int recall_timer = ast_get_cc_recall_timer(agent->cc_params) * 1000;
        struct ast_format tmp_fmt;
-       struct ast_format_cap *tmp_cap = ast_format_cap_alloc_nolock();
+       struct ast_format_cap *tmp_cap = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_NOLOCK);
 
        if (!tmp_cap) {
                return NULL;
index 36528f5df82cfc693b7e6f450c6c7f66bfb06fad..e6025c0628baa4fddba44f7ac45d2e54267f3d70 100644 (file)
@@ -879,7 +879,7 @@ __ast_channel_alloc_ap(int needqueue, int state, const char *cid_num, const char
 
        ast_channel_stage_snapshot(tmp);
 
-       if (!(nativeformats = ast_format_cap_alloc())) {
+       if (!(nativeformats = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_CACHE_STRINGS))) {
                ao2_ref(tmp, -1);
                /* format capabilities structure allocation failure */
                return NULL;
@@ -5401,7 +5401,7 @@ static int set_format(struct ast_channel *chan,
 
 int ast_set_read_format(struct ast_channel *chan, struct ast_format *format)
 {
-       struct ast_format_cap *cap = ast_format_cap_alloc_nolock();
+       struct ast_format_cap *cap = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_NOLOCK);
        int res;
 
        if (!cap) {
@@ -5422,7 +5422,7 @@ int ast_set_read_format(struct ast_channel *chan, struct ast_format *format)
 
 int ast_set_read_format_by_id(struct ast_channel *chan, enum ast_format_id id)
 {
-       struct ast_format_cap *cap = ast_format_cap_alloc_nolock();
+       struct ast_format_cap *cap = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_NOLOCK);
        struct ast_format tmp_format;
        int res;
 
@@ -5454,7 +5454,7 @@ int ast_set_read_format_from_cap(struct ast_channel *chan, struct ast_format_cap
 
 int ast_set_write_format(struct ast_channel *chan, struct ast_format *format)
 {
-       struct ast_format_cap *cap = ast_format_cap_alloc_nolock();
+       struct ast_format_cap *cap = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_NOLOCK);
        int res;
 
        if (!cap) {
@@ -5475,7 +5475,7 @@ int ast_set_write_format(struct ast_channel *chan, struct ast_format *format)
 
 int ast_set_write_format_by_id(struct ast_channel *chan, enum ast_format_id id)
 {
-       struct ast_format_cap *cap = ast_format_cap_alloc_nolock();
+       struct ast_format_cap *cap = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_NOLOCK);
        struct ast_format tmp_format;
        int res;
 
index d4ec06d9fb18cfa291982eacb1095857921499d5..4a047032ce4f91db42fbc6c69a81a0c6bcc24268 100644 (file)
@@ -1018,7 +1018,7 @@ int ast_local_init(void)
                return -1;
        }
 
-       if (!(local_tech.capabilities = ast_format_cap_alloc())) {
+       if (!(local_tech.capabilities = ast_format_cap_alloc(0))) {
                return -1;
        }
        ast_format_cap_add_all(local_tech.capabilities);
index 6d796e2b9ded7a905577da7fc5ab4a31fc55908e..8cc6f9c89431e0851a360e3e2dc52519cd0d2466 100644 (file)
@@ -273,7 +273,7 @@ static int begin_dial_prerun(struct ast_dial_channel *channel, struct ast_channe
        } else if (chan) {
                cap_request = ast_channel_nativeformats(chan);
        } else {
-               cap_all_audio = ast_format_cap_alloc_nolock();
+               cap_all_audio = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_NOLOCK);
                ast_format_cap_add_all_by_type(cap_all_audio, AST_FORMAT_TYPE_AUDIO);
                cap_request = cap_all_audio;
        }
index b24cdeeb320900d335fb49a3c3343f269d63ae9c..ffdbf1821d54c9331f26474893a4eb73b6630440 100644 (file)
@@ -749,7 +749,7 @@ struct ast_filestream *ast_openstream_full(struct ast_channel *chan, const char
        buflen = strlen(preflang) + strlen(filename) + 4;
        buf = ast_alloca(buflen);
 
-       if (!(file_fmt_cap = ast_format_cap_alloc_nolock())) {
+       if (!(file_fmt_cap = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_NOLOCK))) {
                return NULL;
        }
        if (!fileexists_core(filename, NULL, preflang, buf, buflen, file_fmt_cap) ||
@@ -797,7 +797,7 @@ struct ast_filestream *ast_openvstream(struct ast_channel *chan, const char *fil
        if (!ast_format_cap_has_type(ast_channel_nativeformats(chan), AST_FORMAT_TYPE_VIDEO)) {
                return NULL;
        }
-       if (!(tmp_cap = ast_format_cap_alloc_nolock())) {
+       if (!(tmp_cap = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_NOLOCK))) {
                return NULL;
        }
        /* Video is supported, so see what video formats exist for this file */
index 5fc110812739c40e1210f7a07590569882927507..96c2fa3aaf4c1c110311b9874b9769e6e3aba8ee 100644 (file)
@@ -38,13 +38,16 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$");
 #include "asterisk/astobj2.h"
 #include "asterisk/utils.h"
 
+#define FORMAT_STR_BUFSIZE 256
 
 struct ast_format_cap {
        /* The capabilities structure is just an ao2 container of ast_formats */
        struct ao2_container *formats;
        struct ao2_iterator it;
        /*! TRUE if the formats container created without a lock. */
-       int nolock;
+       struct ast_flags flags;
+       unsigned int string_cache_valid;
+       char format_strs[0];
 };
 
 /*! format exists within capabilities structure if it is identical to
@@ -67,17 +70,27 @@ static int hash_cb(const void *obj, const int flags)
        return format->id;
 }
 
-static struct ast_format_cap *cap_alloc_helper(int nolock)
+struct ast_format_cap *ast_format_cap_alloc(enum ast_format_cap_flags flags)
 {
-       struct ast_format_cap *cap = ast_calloc(1, sizeof(*cap));
+       struct ast_format_cap *cap;
+       unsigned int alloc_size;
+       
+       alloc_size = sizeof(*cap);
+       if (flags & AST_FORMAT_CAP_FLAG_CACHE_STRINGS) {
+               alloc_size += FORMAT_STR_BUFSIZE;
+       }
 
+       cap = ast_calloc(1, alloc_size);
        if (!cap) {
                return NULL;
        }
-       cap->nolock = nolock;
+
+       ast_set_flag(&cap->flags, flags);
        cap->formats = ao2_container_alloc_options(
-               nolock ? AO2_ALLOC_OPT_LOCK_NOLOCK : AO2_ALLOC_OPT_LOCK_MUTEX,
-               283, hash_cb, cmp_cb);
+               (flags & AST_FORMAT_CAP_FLAG_NOLOCK) ?
+               AO2_ALLOC_OPT_LOCK_NOLOCK :
+               AO2_ALLOC_OPT_LOCK_MUTEX,
+               11, hash_cb, cmp_cb);
        if (!cap->formats) {
                ast_free(cap);
                return NULL;
@@ -86,16 +99,6 @@ static struct ast_format_cap *cap_alloc_helper(int nolock)
        return cap;
 }
 
-struct ast_format_cap *ast_format_cap_alloc_nolock(void)
-{
-       return cap_alloc_helper(1);
-}
-
-struct ast_format_cap *ast_format_cap_alloc(void)
-{
-       return cap_alloc_helper(0);
-}
-
 void *ast_format_cap_destroy(struct ast_format_cap *cap)
 {
        if (!cap) {
@@ -106,7 +109,7 @@ void *ast_format_cap_destroy(struct ast_format_cap *cap)
        return NULL;
 }
 
-void ast_format_cap_add(struct ast_format_cap *cap, const struct ast_format *format)
+static void format_cap_add(struct ast_format_cap *cap, const struct ast_format *format)
 {
        struct ast_format *fnew;
 
@@ -118,9 +121,16 @@ void ast_format_cap_add(struct ast_format_cap *cap, const struct ast_format *for
        }
        ast_format_copy(fnew, format);
        ao2_link(cap->formats, fnew);
+
        ao2_ref(fnew, -1);
 }
 
+void ast_format_cap_add(struct ast_format_cap *cap, const struct ast_format *format)
+{
+       format_cap_add(cap, format);
+       cap->string_cache_valid = 0;
+}
+
 void ast_format_cap_add_all_by_type(struct ast_format_cap *cap, enum ast_format_type type)
 {
        int x;
@@ -129,9 +139,10 @@ void ast_format_cap_add_all_by_type(struct ast_format_cap *cap, enum ast_format_
 
        for (x = 0; x < f_len; x++) {
                if (AST_FORMAT_GET_TYPE(f_list[x].format.id) == type) {
-                       ast_format_cap_add(cap, &f_list[x].format);
+                       format_cap_add(cap, &f_list[x].format);
                }
        }
+       cap->string_cache_valid = 0;
        ast_format_list_destroy(f_list);
 }
 
@@ -142,8 +153,9 @@ void ast_format_cap_add_all(struct ast_format_cap *cap)
        const struct ast_format_list *f_list = ast_format_list_get(&f_len);
 
        for (x = 0; x < f_len; x++) {
-               ast_format_cap_add(cap, &f_list[x].format);
+               format_cap_add(cap, &f_list[x].format);
        }
+       cap->string_cache_valid = 0;
        ast_format_list_destroy(f_list);
 }
 
@@ -153,7 +165,7 @@ static int append_cb(void *obj, void *arg, int flag)
        struct ast_format *format = (struct ast_format *) obj;
 
        if (!ast_format_cap_iscompatible(result, format)) {
-               ast_format_cap_add(result, format);
+               format_cap_add(result, format);
        }
 
        return 0;
@@ -162,6 +174,7 @@ static int append_cb(void *obj, void *arg, int flag)
 void ast_format_cap_append(struct ast_format_cap *dst, const struct ast_format_cap *src)
 {
        ao2_callback(src->formats, OBJ_NODATA, append_cb, dst);
+       dst->string_cache_valid = 0;
 }
 
 static int copy_cb(void *obj, void *arg, int flag)
@@ -169,28 +182,32 @@ static int copy_cb(void *obj, void *arg, int flag)
        struct ast_format_cap *result = (struct ast_format_cap *) arg;
        struct ast_format *format = (struct ast_format *) obj;
 
-       ast_format_cap_add(result, format);
+       format_cap_add(result, format);
        return 0;
 }
 
+static void format_cap_remove_all(struct ast_format_cap *cap)
+{
+       ao2_callback(cap->formats, OBJ_NODATA | OBJ_MULTIPLE | OBJ_UNLINK, NULL, NULL);
+}
+
 void ast_format_cap_copy(struct ast_format_cap *dst, const struct ast_format_cap *src)
 {
-       ast_format_cap_remove_all(dst);
+       format_cap_remove_all(dst);
        ao2_callback(src->formats, OBJ_NODATA, copy_cb, dst);
+       dst->string_cache_valid = 0;
 }
 
 struct ast_format_cap *ast_format_cap_dup(const struct ast_format_cap *cap)
 {
        struct ast_format_cap *dst;
-       if (cap->nolock) {
-               dst = ast_format_cap_alloc_nolock();
-       } else {
-               dst = ast_format_cap_alloc();
-       }
+
+       dst = ast_format_cap_alloc(ast_test_flag(&cap->flags, AST_FLAGS_ALL));
        if (!dst) {
                return NULL;
        }
        ao2_callback(cap->formats, OBJ_NODATA, copy_cb, dst);
+       dst->string_cache_valid = 0;
        return dst;
 }
 
@@ -217,6 +234,7 @@ int ast_format_cap_remove(struct ast_format_cap *cap, struct ast_format *format)
        fremove = ao2_callback(cap->formats, OBJ_POINTER | OBJ_UNLINK, find_exact_cb, format);
        if (fremove) {
                ao2_ref(fremove, -1);
+               cap->string_cache_valid = 0;
                return 0;
        }
 
@@ -259,6 +277,7 @@ int ast_format_cap_remove_byid(struct ast_format_cap *cap, enum ast_format_id id
 
        /* match_found will be set if at least one item was removed */
        if (data.match_found) {
+               cap->string_cache_valid = 0;
                return 0;
        }
 
@@ -278,17 +297,20 @@ void ast_format_cap_remove_bytype(struct ast_format_cap *cap, enum ast_format_ty
                OBJ_UNLINK | OBJ_NODATA | OBJ_MULTIPLE,
                multiple_by_type_cb,
                &type);
+       cap->string_cache_valid = 0;
 }
 
 void ast_format_cap_remove_all(struct ast_format_cap *cap)
 {
-       ao2_callback(cap->formats, OBJ_NODATA | OBJ_MULTIPLE | OBJ_UNLINK, NULL, NULL);
+       format_cap_remove_all(cap);
+       cap->string_cache_valid = 0;
 }
 
 void ast_format_cap_set(struct ast_format_cap *cap, struct ast_format *format)
 {
-       ast_format_cap_remove_all(cap);
-       ast_format_cap_add(cap, format);
+       format_cap_remove_all(cap);
+       format_cap_add(cap, format);
+       cap->string_cache_valid = 0;
 }
 
 int ast_format_cap_get_compatible_format(const struct ast_format_cap *cap, const struct ast_format *format, struct ast_format *result)
@@ -434,7 +456,7 @@ int ast_format_cap_identical(const struct ast_format_cap *cap1, const struct ast
 struct ast_format_cap *ast_format_cap_joint(const struct ast_format_cap *cap1, const struct ast_format_cap *cap2)
 {
        struct ao2_iterator it;
-       struct ast_format_cap *result = ast_format_cap_alloc_nolock();
+       struct ast_format_cap *result = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_NOLOCK);
        struct ast_format *tmp;
        struct find_joint_data data = {
                .joint_found = 0,
@@ -472,7 +494,7 @@ static int joint_copy_helper(const struct ast_format_cap *cap1, const struct ast
                .joint_found = 0,
        };
        if (!append) {
-               ast_format_cap_remove_all(result);
+               format_cap_remove_all(result);
        }
        it = ao2_iterator_init(cap1->formats, 0);
        while ((tmp = ao2_iterator_next(&it))) {
@@ -485,6 +507,8 @@ static int joint_copy_helper(const struct ast_format_cap *cap1, const struct ast
        }
        ao2_iterator_destroy(&it);
 
+       result->string_cache_valid = 0;
+
        return ao2_container_count(result->formats) ? 1 : 0;
 }
 
@@ -501,7 +525,7 @@ int ast_format_cap_joint_copy(const struct ast_format_cap *cap1, const struct as
 struct ast_format_cap *ast_format_cap_get_type(const struct ast_format_cap *cap, enum ast_format_type ftype)
 {
        struct ao2_iterator it;
-       struct ast_format_cap *result = ast_format_cap_alloc_nolock();
+       struct ast_format_cap *result = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_NOLOCK);
        struct ast_format *tmp;
 
        if (!result) {
@@ -575,7 +599,7 @@ int ast_format_cap_iter_next(struct ast_format_cap *cap, struct ast_format *form
        return 0;
 }
 
-char *ast_getformatname_multiple(char *buf, size_t size, struct ast_format_cap *cap)
+static char *getformatname_multiple(char *buf, size_t size, struct ast_format_cap *cap)
 {
        int x;
        unsigned len;
@@ -611,6 +635,20 @@ char *ast_getformatname_multiple(char *buf, size_t size, struct ast_format_cap *
        return buf;
 }
 
+char *ast_getformatname_multiple(char *buf, size_t size, struct ast_format_cap *cap)
+{
+       if (ast_test_flag(&cap->flags, AST_FORMAT_CAP_FLAG_CACHE_STRINGS)) {
+               if (!cap->string_cache_valid) {
+                       getformatname_multiple(cap->format_strs, FORMAT_STR_BUFSIZE, cap);
+                       cap->string_cache_valid = 1;
+               }
+               ast_copy_string(buf, cap->format_strs, size);
+               return buf;
+       }
+
+       return getformatname_multiple(buf, size, cap);
+}
+
 uint64_t ast_format_cap_to_old_bitfield(const struct ast_format_cap *cap)
 {
        uint64_t res = 0;
@@ -632,11 +670,12 @@ void ast_format_cap_from_old_bitfield(struct ast_format_cap *dst, uint64_t src)
        int x;
        struct ast_format tmp_format = { 0, };
 
-       ast_format_cap_remove_all(dst);
+       format_cap_remove_all(dst);
        for (x = 0; x < 64; x++) {
                tmp = (1ULL << x);
                if (tmp & src) {
-                       ast_format_cap_add(dst, ast_format_from_old_bitfield(&tmp_format, tmp));
+                       format_cap_add(dst, ast_format_from_old_bitfield(&tmp_format, tmp));
                }
        }
+       dst->string_cache_valid = 0;
 }
index f06b7dbca1eca7bb243afb3a6eb6e49c422bc81d..f3e883407fe9f6ee6cb62bff8c419ef95079a618 100644 (file)
@@ -4683,7 +4683,7 @@ static int action_originate(struct mansession *s, const struct message *m)
        int reason = 0;
        char tmp[256];
        char tmp2[256];
-       struct ast_format_cap *cap = ast_format_cap_alloc_nolock();
+       struct ast_format_cap *cap = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_NOLOCK);
        struct ast_format tmp_fmt;
        pthread_t th;
        int bridge_early = 0;
index 605cee927b45ceac32d7d29e90f102a3d73605e8..64fbbbddbe661aa8071768c2be566b9d894bf647 100644 (file)
@@ -67,7 +67,7 @@ static struct media_variant *media_variant_alloc(const char *variant_str)
                return NULL;
        }
 
-       variant->formats = ast_format_cap_alloc();
+       variant->formats = ast_format_cap_alloc(0);
        if (!variant->formats) {
                return NULL;
        }
index c7e35979522beba03c40f9dc62ffe85a2cdc70bb..54e1e45e3875758134fa69217c0462687749f737 100644 (file)
@@ -1081,8 +1081,8 @@ void ast_rtp_instance_early_bridge_make_compatible(struct ast_channel *c0, struc
        struct ast_rtp_glue *glue0, *glue1;
        enum ast_rtp_glue_result audio_glue0_res = AST_RTP_GLUE_RESULT_FORBID, video_glue0_res = AST_RTP_GLUE_RESULT_FORBID;
        enum ast_rtp_glue_result audio_glue1_res = AST_RTP_GLUE_RESULT_FORBID, video_glue1_res = AST_RTP_GLUE_RESULT_FORBID;
-       struct ast_format_cap *cap0 = ast_format_cap_alloc_nolock();
-       struct ast_format_cap *cap1 = ast_format_cap_alloc_nolock();
+       struct ast_format_cap *cap0 = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_NOLOCK);
+       struct ast_format_cap *cap1 = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_NOLOCK);
 
        /* Lock both channels so we can look for the glue that binds them together */
        ast_channel_lock_both(c0, c1);
@@ -1167,8 +1167,8 @@ int ast_rtp_instance_early_bridge(struct ast_channel *c0, struct ast_channel *c1
        struct ast_rtp_glue *glue0, *glue1;
        enum ast_rtp_glue_result audio_glue0_res = AST_RTP_GLUE_RESULT_FORBID, video_glue0_res = AST_RTP_GLUE_RESULT_FORBID;
        enum ast_rtp_glue_result audio_glue1_res = AST_RTP_GLUE_RESULT_FORBID, video_glue1_res = AST_RTP_GLUE_RESULT_FORBID;
-       struct ast_format_cap *cap0 = ast_format_cap_alloc_nolock();
-       struct ast_format_cap *cap1 = ast_format_cap_alloc_nolock();
+       struct ast_format_cap *cap0 = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_NOLOCK);
+       struct ast_format_cap *cap1 = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_NOLOCK);
 
        /* If there is no second channel just immediately bail out, we are of no use in that scenario */
        if (!c1 || !cap1 || !cap0) {
index 79ef7166fdb34c5d8b41a08358c7c3e9cd79f2b2..31d883c94ec0923c63dd2b0d868abfffdebb6ca5 100644 (file)
@@ -144,7 +144,7 @@ static struct outgoing *new_outgoing(const char *fn)
                return NULL;
        }
 
-       o->capabilities = ast_format_cap_alloc_nolock();
+       o->capabilities = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_NOLOCK);
        if (!o->capabilities) {
                free_outgoing(o);
                return NULL;
index ef7767f71cc7128b648efaa7bbcab90f27117e0e..77d5660ca7154e451d85383ca81f34601d460593 100644 (file)
@@ -276,7 +276,7 @@ static struct ast_channel *prepare_bridge_media_channel(const char *type)
        RAII_VAR(struct ast_format_cap *, cap, NULL, ast_format_cap_destroy);
        struct ast_format format;
 
-       cap = ast_format_cap_alloc_nolock();
+       cap = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_NOLOCK);
        if (!cap) {
                return NULL;
        }
index 7bd89226625c86f432b98dc4c8e216d0e88d9f36..2d481e42126b4f39a4db92ee417f4d07b2b13b11 100644 (file)
@@ -687,7 +687,7 @@ static void announce_to_dial(char *dial_string, char *announce_string, int parki
        struct ast_channel *dchan;
        struct outgoing_helper oh = { 0, };
        int outstate;
-       struct ast_format_cap *cap_slin = ast_format_cap_alloc_nolock();
+       struct ast_format_cap *cap_slin = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_NOLOCK);
        char buf[13];
        char *dial_tech;
        char *cur_announce;
index 84dcbebe9c5d3bbcc587f0a878df828183ad324f..e69a24cc1be4cc34a1aaf8a731d28b8e4f571cd9 100644 (file)
@@ -3025,7 +3025,7 @@ static int handle_speechcreate(struct ast_channel *chan, AGI *agi, int argc, con
                return RESULT_SUCCESS;
        }
 
-       if (!(cap = ast_format_cap_alloc_nolock())) {
+       if (!(cap = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_NOLOCK))) {
                return RESULT_FAILURE;
        }
        ast_format_cap_add(cap, ast_format_set(&tmpfmt, AST_FORMAT_SLINEAR, 0));
index 42030d798558575199ac26e66bfb03bf6030179c..0d639c77d23da9be83195269d45ed2996eced6ac 100644 (file)
@@ -70,7 +70,7 @@ static char *orig_app(int fd, const char *chan, const char *app, const char *app
                return CLI_SHOWUSAGE;
        }
 
-       if (!(cap = ast_format_cap_alloc_nolock())) {
+       if (!(cap = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_NOLOCK))) {
                return CLI_FAILURE;
        }
        ast_format_cap_add(cap, ast_format_set(&tmpfmt, AST_FORMAT_SLINEAR, 0));
@@ -115,7 +115,7 @@ static char *orig_exten(int fd, const char *chan, const char *data)
                exten = "s";
        if (ast_strlen_zero(context))
                context = "default";
-       if (!(cap = ast_format_cap_alloc_nolock())) {
+       if (!(cap = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_NOLOCK))) {
                return CLI_FAILURE;
        }
        ast_format_cap_add(cap, ast_format_set(&tmpfmt, AST_FORMAT_SLINEAR, 0));
index c0a6acc4ab0d7765574a2b2a5520ddab5e568828..151ab101643190cee30d989ac57cdd1027a5cc95 100644 (file)
@@ -832,7 +832,7 @@ void *ast_sip_endpoint_alloc(const char *name)
                ao2_cleanup(endpoint);
                return NULL;
        }
-       if (!(endpoint->media.codecs = ast_format_cap_alloc_nolock())) {
+       if (!(endpoint->media.codecs = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_NOLOCK))) {
                ao2_cleanup(endpoint);
                return NULL;
        }
index 4b086211452a08d1f05dfdecb80a52d05d85b02e..1d811a15b90472a0a2874dee55657610ddc6af3b 100644 (file)
@@ -205,8 +205,8 @@ static int set_caps(struct ast_sip_session *session, struct ast_sip_session_medi
        int direct_media_enabled = !ast_sockaddr_isnull(&session_media->direct_media_addr) &&
                !ast_format_cap_is_empty(session->direct_media_cap);
 
-       if (!(caps = ast_format_cap_alloc_nolock()) ||
-           !(peer = ast_format_cap_alloc_nolock())) {
+       if (!(caps = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_NOLOCK)) ||
+           !(peer = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_NOLOCK))) {
                ast_log(LOG_ERROR, "Failed to allocate %s capabilities\n", session_media->stream_type);
                return -1;
        }
@@ -910,7 +910,7 @@ static int create_outgoing_sdp_stream(struct ast_sip_session *session, struct as
        /* Add ICE attributes and candidates */
        add_ice_to_stream(session, session_media, pool, media);
 
-       if (!(caps = ast_format_cap_alloc_nolock())) {
+       if (!(caps = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_NOLOCK))) {
                ast_log(LOG_ERROR, "Failed to allocate %s capabilities\n", session_media->stream_type);
                return -1;
        }
index 9cb85dcf0d13d4b114e57fd595f696a19c133056..07ccd0ce2ee2b5b06b41e7c0acf91b6ee30d8d69 100644 (file)
@@ -1123,7 +1123,7 @@ struct ast_sip_session *ast_sip_session_alloc(struct ast_sip_endpoint *endpoint,
        ao2_ref(endpoint, +1);
        session->endpoint = endpoint;
        session->inv_session = inv_session;
-       session->req_caps = ast_format_cap_alloc_nolock();
+       session->req_caps = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_NOLOCK);
 
        if (endpoint->dtmf == AST_SIP_DTMF_INBAND) {
                dsp_features |= DSP_FEATURE_DIGIT_DETECT;
@@ -1151,7 +1151,7 @@ struct ast_sip_session *ast_sip_session_alloc(struct ast_sip_endpoint *endpoint,
                        iter->session_begin(session);
                }
        }
-       session->direct_media_cap = ast_format_cap_alloc_nolock();
+       session->direct_media_cap = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_NOLOCK);
        AST_LIST_HEAD_INIT_NOLOCK(&session->delayed_requests);
        ast_party_id_init(&session->id);
        ao2_ref(session, +1);
index ab2bf5c8690714a1e21fe9299017d8812f12be89..197022e725754f5ea851913f22d5badca29b1e2a 100644 (file)
@@ -321,7 +321,7 @@ static struct ast_channel *prepare_bridge_moh_channel(void)
        RAII_VAR(struct ast_format_cap *, cap, NULL, ast_format_cap_destroy);
        struct ast_format format;
 
-       cap = ast_format_cap_alloc_nolock();
+       cap = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_NOLOCK);
        if (!cap) {
                return NULL;
        }
index 6b1a8e420cdb375729a6f52df89a8f0475b0146f..f9e9a6f4874c377ba9651140dc6b3dea93c41178 100644 (file)
@@ -671,7 +671,7 @@ static void *test_item_alloc(const char *cat)
                ao2_ref(item, -1);
                return NULL;
        }
-       if (!(item->codeccapopt = ast_format_cap_alloc())) {
+       if (!(item->codeccapopt = ast_format_cap_alloc(0))) {
                ao2_ref(item, -1);
                return NULL;
        }
@@ -855,10 +855,10 @@ AST_TEST_DEFINE(config_options_test)
        ast_sockaddr_parse(&acl_allow, "1.2.3.4", PARSE_PORT_FORBID);
        ast_sockaddr_parse(&acl_fail, "1.1.1.1", PARSE_PORT_FORBID);
 
-       defaults.codeccapopt = ast_format_cap_alloc();
+       defaults.codeccapopt = ast_format_cap_alloc(0);
        ast_parse_allow_disallow(&defaults.codecprefopt, defaults.codeccapopt, CODEC_DEFAULT, 1);
 
-       configs.codeccapopt = ast_format_cap_alloc();
+       configs.codeccapopt = ast_format_cap_alloc(0);
        ast_parse_allow_disallow(&configs.codecprefopt, configs.codeccapopt, CODEC_CONFIG, 1);
 
        ast_string_field_init(&defaults, 128);
index c429e08954c56ca93201b32f5751bf1f561064d9..6cc3495700a474f5fdc4acd22bf2d3e55c0e5bca 100644 (file)
@@ -622,8 +622,8 @@ AST_TEST_DEFINE(container_test1_nolock)
                break;
        }
 
-       cap1 = ast_format_cap_alloc_nolock();
-       cap2 = ast_format_cap_alloc_nolock();
+       cap1 = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_NOLOCK);
+       cap2 = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_NOLOCK);
 
        if (!cap1 || !cap2) {
                ast_test_status_update(test, "cap alloc failed.\n");
@@ -654,8 +654,8 @@ AST_TEST_DEFINE(container_test1_withlock)
                break;
        }
 
-       cap1 = ast_format_cap_alloc();
-       cap2 = ast_format_cap_alloc();
+       cap1 = ast_format_cap_alloc(0);
+       cap2 = ast_format_cap_alloc(0);
 
        if (!cap1 || !cap2) {
                ast_test_status_update(test, "cap alloc failed.\n");
@@ -710,7 +710,7 @@ AST_TEST_DEFINE(container_test2_no_locking)
                break;
        }
 
-       cap = ast_format_cap_alloc_nolock();
+       cap = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_NOLOCK);
        if (!cap) {
                ast_test_status_update(test, "alloc failed\n");
                return AST_TEST_FAIL;
@@ -737,7 +737,7 @@ AST_TEST_DEFINE(container_test2_with_locking)
                break;
        }
 
-       cap = ast_format_cap_alloc();
+       cap = ast_format_cap_alloc(0);
        if (!cap) {
                ast_test_status_update(test, "alloc failed\n");
                return AST_TEST_FAIL;
@@ -756,13 +756,13 @@ static int container_test3_helper(int nolocking, struct ast_test *test)
 
        for (x = 0; x < 2000; x++) {
                if (nolocking) {
-                       cap1 = ast_format_cap_alloc_nolock();
-                       cap2 = ast_format_cap_alloc_nolock();
-                       joint = ast_format_cap_alloc_nolock();
+                       cap1 = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_NOLOCK);
+                       cap2 = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_NOLOCK);
+                       joint = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_NOLOCK);
                } else {
-                       cap1 = ast_format_cap_alloc();
-                       cap2 = ast_format_cap_alloc();
-                       joint = ast_format_cap_alloc();
+                       cap1 = ast_format_cap_alloc(0);
+                       cap2 = ast_format_cap_alloc(0);
+                       joint = ast_format_cap_alloc(0);
                }
                if (!cap1 || !cap2 || !joint) {
                        ast_test_status_update(test, "cap alloc fail\n");