Cache string values of formats on ast_format_cap() to save processing.

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
........

Merged revisions 400356 from http://svn.asterisk.org/svn/asterisk/branches/12


git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@400363 65c4cc65-6c06-0410-ace0-fbb531ad65f3
changes/97/197/1
Mark Michelson 12 years ago
parent c977f73e13
commit ee21eee7e0

@ -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);

@ -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));

@ -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;
}

@ -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) {

@ -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) {

@ -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);

@ -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);

@ -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);

@ -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));

@ -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));

@ -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;
}

@ -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));

@ -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));

@ -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;
}

@ -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);

@ -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);

@ -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));

@ -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));

@ -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);

@ -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;
}

@ -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);

@ -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);

@ -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));

@ -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;
}

@ -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;
}

@ -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);

@ -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;
}

@ -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;
}

@ -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;
}

@ -29,32 +29,27 @@
/*! 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.

@ -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;

@ -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;

@ -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;

@ -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);

@ -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;
}

@ -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 */

@ -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;
}

@ -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;

@ -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;
}

@ -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) {

@ -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;

@ -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;
}

@ -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;

@ -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));

@ -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));

@ -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;
}

@ -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;
}

@ -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);

@ -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;
}

@ -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);

@ -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");

Loading…
Cancel
Save