Sat Apr 26 2014 22:02:50

Asterisk developer's documentation


format_cap.c File Reference

Format Capability API. More...

#include "asterisk.h"
#include "asterisk/_private.h"
#include "asterisk/format.h"
#include "asterisk/format_cap.h"
#include "asterisk/frame.h"
#include "asterisk/astobj2.h"
#include "asterisk/utils.h"
Include dependency graph for format_cap.c:

Go to the source code of this file.

Data Structures

struct  ast_format_cap
struct  byid_data
struct  find_joint_data
struct  multiple_by_id_data

Functions

static int append_cb (void *obj, void *arg, int flag)
void ast_format_cap_add (struct ast_format_cap *cap, const struct ast_format *format)
 Add format capability to capabilities structure.
void ast_format_cap_add_all (struct ast_format_cap *cap)
 Add all known formats to the capabilities structure using default format attribute.
void ast_format_cap_add_all_by_type (struct ast_format_cap *cap, enum ast_format_type type)
 Add all formats Asterisk knows about for a specific type to the capabilities structure. Formats with attributes are set, but their attributes are initilized to 0's. An attribute structure of 0's should indicate to the format attribute interface that the format has full capabilities.
struct ast_format_capast_format_cap_alloc (void)
 Allocate a new ast_format_cap structure with locking.
struct ast_format_capast_format_cap_alloc_nolock (void)
 Allocate a new ast_format_cap structure.
void ast_format_cap_append (struct ast_format_cap *dst, const struct ast_format_cap *src)
 Append the formats in src to dst.
int ast_format_cap_best_byid (const struct ast_format_cap *cap, enum ast_format_id id, struct ast_format *result)
 Finds the best quality audio format for a given format id and returns it in result.
void ast_format_cap_copy (struct ast_format_cap *dst, const struct ast_format_cap *src)
 Copy all items in src to dst.
void * ast_format_cap_destroy (struct ast_format_cap *cap)
 Destroy an ast_format_cap structure.
struct ast_format_capast_format_cap_dup (const struct ast_format_cap *cap)
 create a deep copy of an ast_format_cap structure
void ast_format_cap_from_old_bitfield (struct ast_format_cap *dst, uint64_t src)
 convert old bitfield format to ast_format_cap represenatation
int ast_format_cap_get_compatible_format (const struct ast_format_cap *cap, const struct ast_format *format, struct ast_format *result)
 Find if input ast_format is within the capabilities of the ast_format_cap object then return the compatible format from the capabilities structure in the result.
struct ast_format_capast_format_cap_get_type (const struct ast_format_cap *cap, enum ast_format_type ftype)
 Get all capabilities for a specific media type.
int ast_format_cap_has_joint (const struct ast_format_cap *cap1, const struct ast_format_cap *cap2)
 Find out if capability structures have any joint capabilities without returning those capabilities.
int ast_format_cap_has_type (const struct ast_format_cap *cap, enum ast_format_type type)
 Find out if the capabilities structure has any formats of a specific type.
int ast_format_cap_identical (const struct ast_format_cap *cap1, const struct ast_format_cap *cap2)
 is cap1 identical to cap2
int ast_format_cap_is_empty (const struct ast_format_cap *cap)
 determine if a capabilities structure is empty or not
int ast_format_cap_iscompatible (const struct ast_format_cap *cap, const struct ast_format *format)
 Find if ast_format is within the capabilities of the ast_format_cap object.
void ast_format_cap_iter_end (struct ast_format_cap *cap)
 Ends ast_format_cap iteration.
int ast_format_cap_iter_next (struct ast_format_cap *cap, struct ast_format *format)
 Next format in interation.
void ast_format_cap_iter_start (struct ast_format_cap *cap)
 Start iterating formats.
struct ast_format_capast_format_cap_joint (const struct ast_format_cap *cap1, const struct ast_format_cap *cap2)
 Get joint capability structure.
int ast_format_cap_joint_append (const struct ast_format_cap *cap1, const struct ast_format_cap *cap2, struct ast_format_cap *result)
 Get joint capability structure, append into result capabilities structure.
int ast_format_cap_joint_copy (const struct ast_format_cap *cap1, const struct ast_format_cap *cap2, struct ast_format_cap *result)
 Get joint capability structure, copy into result capabilities structure.
int ast_format_cap_remove (struct ast_format_cap *cap, struct ast_format *format)
 Remove format capability from capability structure.
void ast_format_cap_remove_all (struct ast_format_cap *cap)
 Remove all format capabilities from capability structure.
int ast_format_cap_remove_byid (struct ast_format_cap *cap, enum ast_format_id id)
 Remove all format capabilities from capability structure for a specific format id.
void ast_format_cap_remove_bytype (struct ast_format_cap *cap, enum ast_format_type type)
 Remove all formats matching a specific format type.
void ast_format_cap_set (struct ast_format_cap *cap, struct ast_format *format)
 Remove all previous formats and set a single new format.
uint64_t ast_format_cap_to_old_bitfield (const struct ast_format_cap *cap)
 ast_format_cap to old bitfield format represenatation
char * ast_getformatname_multiple (char *buf, size_t size, struct ast_format_cap *cap)
 Get the names of a set of formats.
 ASTERISK_FILE_VERSION (__FILE__,"$Revision: 369013 $")
static struct ast_format_capcap_alloc_helper (int nolock)
static int cmp_cb (void *obj, void *arg, int flags)
static int copy_cb (void *obj, void *arg, int flag)
static int find_best_byid_cb (void *obj, void *arg, int flag)
static int find_exact_cb (void *obj, void *arg, int flag)
static int find_joint_cb (void *obj, void *arg, int flag)
static int hash_cb (const void *obj, const int flags)
static int joint_copy_helper (const struct ast_format_cap *cap1, const struct ast_format_cap *cap2, struct ast_format_cap *result, int append)
static int multiple_by_id_cb (void *obj, void *arg, int flag)
static int multiple_by_type_cb (void *obj, void *arg, int flag)

Detailed Description

Format Capability API.

Author:
David Vossel <dvossel@digium.com>

Definition in file format_cap.c.


Function Documentation

static int append_cb ( void *  obj,
void *  arg,
int  flag 
) [static]

Definition at line 150 of file format_cap.c.

References ast_format_cap_add(), ast_format_cap_iscompatible(), and format.

Referenced by ast_format_cap_append().

{
   struct ast_format_cap *result = (struct ast_format_cap *) arg;
   struct ast_format *format = (struct ast_format *) obj;

   if (!ast_format_cap_iscompatible(result, format)) {
      ast_format_cap_add(result, format);
   }

   return 0;
}
void ast_format_cap_add ( struct ast_format_cap cap,
const struct ast_format format 
)

Add format capability to capabilities structure.

Note:
A copy of the input format is made and that copy is what is placed in the ast_format_cap structure. The actual input format ptr is not stored.

Definition at line 109 of file format_cap.c.

References ao2_alloc, ao2_link, ao2_ref, ast_format_copy(), ast_format_cap::formats, and ast_format::id.

Referenced by action_originate(), add_sdp(), agent_new(), alloc_playback_chan(), alsa_new(), append_cb(), ast_format_cap_add_all(), ast_format_cap_add_all_by_type(), ast_format_cap_from_old_bitfield(), ast_format_cap_get_type(), ast_format_cap_set(), ast_parse_allow_disallow(), ast_request(), ast_set_read_format(), ast_set_read_format_by_id(), ast_set_write_format(), ast_set_write_format_by_id(), ast_translate_available_formats(), bridge_request(), build_conf(), cb_events(), conf_run(), conf_start_record(), console_new(), copy_cb(), dahdi_new(), feature_request_and_dial(), filehelper(), find_joint_cb(), generic_recall(), gtalk_invite(), gtalk_new(), gtalk_rtp_read(), handle_capabilities_res_message(), handle_speechcreate(), jingle_accept_call(), jingle_new(), jingle_read(), jingle_rtp_read(), load_module(), misdn_new(), multicast_rtp_request(), nbs_new(), new_outgoing(), orig_app(), orig_exten(), originate_exec(), oss_new(), parkandannounce_exec(), phone_new(), reload_config(), rtp_payload_type_add_ast(), sip_new(), sip_rtp_read(), and sip_set_default_format_capabilities().

{
   struct ast_format *fnew;

   if (!format || !format->id) {
      return;
   }
   if (!(fnew = ao2_alloc(sizeof(struct ast_format), NULL))) {
      return;
   }
   ast_format_copy(fnew, format);
   ao2_link(cap->formats, fnew);
   ao2_ref(fnew, -1);
}
void ast_format_cap_add_all ( struct ast_format_cap cap)

Add all known formats to the capabilities structure using default format attribute.

Definition at line 138 of file format_cap.c.

References ast_format_cap_add(), ast_format_list_destroy(), ast_format_list_get(), and format.

Referenced by ast_parse_allow_disallow(), load_module(), and rec_request().

{
   int x;
   size_t f_len = 0;
   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);
   }
   ast_format_list_destroy(f_list);
}
void ast_format_cap_add_all_by_type ( struct ast_format_cap cap,
enum ast_format_type  type 
)

Add all formats Asterisk knows about for a specific type to the capabilities structure. Formats with attributes are set, but their attributes are initilized to 0's. An attribute structure of 0's should indicate to the format attribute interface that the format has full capabilities.

Note:
A copy of the input format is made and that copy is what is placed in the ast_format_cap structure. The actual input format ptr is not stored.

Definition at line 124 of file format_cap.c.

References ast_format_cap_add(), AST_FORMAT_GET_TYPE, ast_format_list_destroy(), ast_format_list_get(), and format.

Referenced by begin_dial_channel(), and load_module().

{
   int x;
   size_t f_len = 0;
   const struct ast_format_list *f_list = ast_format_list_get(&f_len);

   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);
      }
   }
   ast_format_list_destroy(f_list);
}
struct ast_format_cap* ast_format_cap_alloc ( void  ) [read]

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.
Return values:
ast_format_capobject on success.
NULLon failure.

Definition at line 94 of file format_cap.c.

References cap_alloc_helper().

Referenced by __ast_channel_alloc_ap(), ast_format_cap_dup(), handle_capabilities_res_message(), and load_module().

{
   return cap_alloc_helper(0);
}
struct ast_format_cap* ast_format_cap_alloc_nolock ( void  ) [read]

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.
Return values:
ast_format_capobject on success.
NULLon failure.

Definition at line 89 of file format_cap.c.

References cap_alloc_helper().

Referenced by action_originate(), add_sdp(), alloc_playback_chan(), ast_format_cap_dup(), ast_format_cap_get_type(), ast_format_cap_joint(), ast_openstream_full(), ast_openvstream(), ast_rtp_instance_bridge(), ast_rtp_instance_early_bridge(), ast_rtp_instance_early_bridge_make_compatible(), ast_set_read_format(), ast_set_read_format_by_id(), ast_set_write_format(), ast_set_write_format_by_id(), begin_dial_channel(), build_conf(), build_gateway(), build_peer(), cb_events(), conf_run(), conf_start_record(), feature_request_and_dial(), generic_recall(), gtalk_alloc(), gtalk_invite(), gtalk_load_config(), h323_parse_allow_disallow(), handle_speechcreate(), iax2_best_codec(), iax2_codec_choose(), iax2_data_add_codecs(), iax2_getformatname_multiple(), iax2_parse_allow_disallow(), jingle_accept_call(), jingle_alloc(), jingle_endpoint_alloc(), jingle_load_config(), new_outgoing(), orig_app(), orig_exten(), originate_exec(), parkandannounce_exec(), process_sdp(), setup_rtp_connection(), sip_alloc(), skinny_device_alloc(), skinny_line_alloc(), temp_peer(), and unistim_line_alloc().

{
   return cap_alloc_helper(1);
}
void ast_format_cap_append ( struct ast_format_cap dst,
const struct ast_format_cap src 
)

Append the formats in src to dst.

Definition at line 162 of file format_cap.c.

References ao2_callback, append_cb(), ast_format_cap::formats, and OBJ_NODATA.

Referenced by process_sdp(), remote_bridge_loop(), sip_get_codec(), and sip_request_call().

int ast_format_cap_best_byid ( const struct ast_format_cap cap,
enum  ast_format_id,
struct ast_format result 
)

Finds the best quality audio format for a given format id and returns it in result.

Return values:
1format found and set to result structure.
0no format found, result structure is cleared.

Definition at line 345 of file format_cap.c.

References ao2_callback, ast_format_clear(), find_best_byid_cb(), ast_format_cap::formats, ast_format::id, byid_data::id, id, OBJ_MULTIPLE, OBJ_NODATA, and byid_data::result.

Referenced by ast_best_codec().

{
   struct byid_data data;
   data.result = result;
   data.id = id;

   ast_format_clear(result);
   ao2_callback(cap->formats,
      OBJ_MULTIPLE | OBJ_NODATA,
      find_best_byid_cb,
      &data);
   return result->id ? 1 : 0;
}
void* ast_format_cap_destroy ( struct ast_format_cap cap)

Destroy an ast_format_cap structure.

Returns:
NULL

Definition at line 99 of file format_cap.c.

References ao2_ref, ast_free, and ast_format_cap::formats.

Referenced by __sip_destroy(), __unload_module(), action_originate(), add_sdp(), alloc_playback_chan(), ast_channel_bridge(), ast_channel_destructor(), ast_format_cap_get_type(), ast_format_cap_joint(), ast_generic_bridge(), ast_openstream_full(), ast_openvstream(), ast_request(), ast_rtp_instance_bridge(), ast_rtp_instance_early_bridge(), ast_rtp_instance_early_bridge_make_compatible(), ast_set_read_format(), ast_set_read_format_by_id(), ast_set_write_format(), ast_set_write_format_by_id(), ast_speech_new(), ast_translator_best_choice(), begin_dial_channel(), build_conf(), cb_events(), check_peer_ok(), conf_run(), conf_start_record(), destroy_endpoint(), destroy_fast_originate_helper(), feature_request_and_dial(), free_outgoing(), func_channel_read(), generic_recall(), gtalk_alloc(), gtalk_free_pvt(), gtalk_invite(), gtalk_member_destroy(), h323_parse_allow_disallow(), handle_capabilities_res_message(), handle_speechcreate(), iax2_best_codec(), iax2_codec_choose(), iax2_data_add_codecs(), iax2_getformatname_multiple(), iax2_parse_allow_disallow(), iax2_request(), jingle_accept_call(), jingle_alloc(), jingle_endpoint_destructor(), jingle_free_pvt(), jingle_member_destroy(), jingle_session_destructor(), load_module(), local_pvt_destructor(), orig_app(), orig_exten(), originate_exec(), parkandannounce_exec(), process_sdp(), remote_bridge_loop(), setup_rtp_connection(), sip_alloc(), sip_destroy_peer(), skinny_device_alloc(), skinny_device_destroy(), skinny_line_alloc(), skinny_line_destroy(), socket_process_helper(), unistim_line_destroy(), and unload_module().

{
   if (!cap) {
      return NULL;
   }
   ao2_ref(cap->formats, -1);
   ast_free(cap);
   return NULL;
}
struct ast_format_cap* ast_format_cap_dup ( const struct ast_format_cap src) [read]

create a deep copy of an ast_format_cap structure

Return values:
capon success
NULLon failure

Definition at line 182 of file format_cap.c.

References ao2_callback, ast_format_cap_alloc(), ast_format_cap_alloc_nolock(), copy_cb(), ast_format_cap::formats, ast_format_cap::nolock, and OBJ_NODATA.

Referenced by ast_channel_bridge(), ast_generic_bridge(), ast_request(), local_alloc(), remote_bridge_loop(), and socket_process_helper().

{
   struct ast_format_cap *dst;
   if (cap->nolock) {
      dst = ast_format_cap_alloc_nolock();
   } else {
      dst = ast_format_cap_alloc();
   }
   if (!dst) {
      return NULL;
   }
   ao2_callback(cap->formats, OBJ_NODATA, copy_cb, dst);
   return dst;
}
void ast_format_cap_from_old_bitfield ( struct ast_format_cap dst,
uint64_t  src 
)

convert old bitfield format to ast_format_cap represenatation

Note:
This is only to be used for IAX2 compatibility

Definition at line 629 of file format_cap.c.

References ast_format_cap_add(), ast_format_cap_remove_all(), and ast_format_from_old_bitfield().

Referenced by __oh323_new(), __oh323_update_info(), ast_iax2_new(), h323_parse_allow_disallow(), iax2_best_codec(), iax2_codec_choose(), iax2_data_add_codecs(), iax2_getformatname_multiple(), iax2_parse_allow_disallow(), setup_rtp_connection(), and socket_process_helper().

{
   uint64_t tmp = 0;
   int x;
   struct ast_format tmp_format = { 0, };

   ast_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));
      }
   }
}
int ast_format_cap_get_compatible_format ( const struct ast_format_cap cap,
const struct ast_format format,
struct ast_format result 
)

Find if input ast_format is within the capabilities of the ast_format_cap object then return the compatible format from the capabilities structure in the result.

Return values:
1format is compatible with formats held in ast_format_cap object.
0format is not compatible with any formats in ast_format_cap object.

Definition at line 294 of file format_cap.c.

References ao2_find, ao2_ref, ast_format_clear(), ast_format_copy(), f, ast_format_cap::formats, and OBJ_POINTER.

Referenced by add_sdp(), ast_codec_choose(), and ast_translate_available_formats().

{
   struct ast_format *f;
   struct ast_format_cap *tmp_cap = (struct ast_format_cap *) cap;

   f = ao2_find(tmp_cap->formats, format, OBJ_POINTER);
   if (f) {
      ast_format_copy(result, f);
      ao2_ref(f, -1);
      return 1;
   }
   ast_format_clear(result);
   return 0;
}
struct ast_format_cap* ast_format_cap_get_type ( const struct ast_format_cap cap,
enum ast_format_type  ftype 
) [read]

Get all capabilities for a specific media type.

Return values:
!NULLsuccess, new capabilities structure with _NO_ locking enabled on the new structure.
NULLfailure

Definition at line 501 of file format_cap.c.

References ao2_container_count(), ao2_iterator_destroy(), ao2_iterator_init(), ao2_iterator_next, ao2_ref, ast_format_cap_add(), ast_format_cap_alloc_nolock(), ast_format_cap_destroy(), AST_FORMAT_GET_TYPE, ast_format_cap::formats, and ast_format::id.

Referenced by ast_request(), and func_channel_read().

{
   struct ao2_iterator it;
   struct ast_format_cap *result = ast_format_cap_alloc_nolock();
   struct ast_format *tmp;

   if (!result) {
      return NULL;
   }

   /* for each format in cap1, see if that format is
    * compatible with cap2. If so copy it to the result */
   it = ao2_iterator_init(cap->formats, 0);
   while ((tmp = ao2_iterator_next(&it))) {
      if (AST_FORMAT_GET_TYPE(tmp->id) == ftype) {
         /* copy format */
         ast_format_cap_add(result, tmp);
      }
      ao2_ref(tmp, -1);
   }
   ao2_iterator_destroy(&it);

   if (ao2_container_count(result->formats)) {
      return result;
   }
   result = ast_format_cap_destroy(result);

   return NULL;
}
int ast_format_cap_has_joint ( const struct ast_format_cap cap1,
const struct ast_format_cap cap2 
)

Find out if capability structures have any joint capabilities without returning those capabilities.

Return values:
1true, has joint capabilities
0false, failure

Definition at line 388 of file format_cap.c.

References ao2_callback, ao2_iterator_destroy(), ao2_iterator_init(), ao2_iterator_next, ao2_ref, find_joint_cb(), find_joint_data::format, ast_format_cap::formats, find_joint_data::joint_found, OBJ_MULTIPLE, and OBJ_NODATA.

Referenced by ast_rtp_instance_bridge(), ast_rtp_instance_early_bridge(), ast_rtp_instance_early_bridge_make_compatible(), console_request(), mgcp_request(), phone_request(), and unistim_request().

{
   struct ao2_iterator it;
   struct ast_format *tmp;
   struct find_joint_data data = {
      .joint_found = 0,
      .joint_cap = NULL,
   };

   it = ao2_iterator_init(cap1->formats, 0);
   while ((tmp = ao2_iterator_next(&it))) {
      data.format = tmp;
      ao2_callback(cap2->formats,
         OBJ_MULTIPLE | OBJ_NODATA,
         find_joint_cb,
         &data);
      ao2_ref(tmp, -1);
   }
   ao2_iterator_destroy(&it);

   return data.joint_found ? 1 : 0;
}
int ast_format_cap_has_type ( const struct ast_format_cap cap,
enum ast_format_type  type 
)

Find out if the capabilities structure has any formats of a specific type.

Return values:
1true
0false, no formats of specific type.

Definition at line 532 of file format_cap.c.

References ao2_iterator_destroy(), ao2_iterator_init(), ao2_iterator_next, ao2_ref, AST_FORMAT_GET_TYPE, ast_format_cap::formats, and ast_format::id.

Referenced by add_sdp(), ast_bridge_update_talker_src_video_mode(), ast_channel_make_compatible_helper(), ast_openstream_full(), ast_openvstream(), ast_sendtext(), dialog_initialize_rtp(), jingle_enable_video(), jingle_request(), oh323_request(), process_sdp(), sip_call(), sip_new(), sip_request_call(), and skinny_request().

{
   struct ao2_iterator it;
   struct ast_format *tmp;

   it = ao2_iterator_init(cap->formats, 0);
   while ((tmp = ao2_iterator_next(&it))) {
      if (AST_FORMAT_GET_TYPE(tmp->id) == type) {
         ao2_ref(tmp, -1);
         ao2_iterator_destroy(&it);
         return 1;
      }
      ao2_ref(tmp, -1);
   }
   ao2_iterator_destroy(&it);

   return 0;
}
int ast_format_cap_identical ( const struct ast_format_cap cap1,
const struct ast_format_cap cap2 
)

is cap1 identical to cap2

retval 1 true, identical retval 0 false, not identical

Definition at line 411 of file format_cap.c.

References ao2_container_count(), ao2_iterator_destroy(), ao2_iterator_init(), ao2_iterator_next, ao2_ref, ast_format_cap_iscompatible(), and ast_format_cap::formats.

Referenced by ast_channel_bridge(), ast_generic_bridge(), iax2_bridge(), multiplexed_bridge_join(), remote_bridge_loop(), setup_rtp_connection(), simple_bridge_join(), and sip_set_rtp_peer().

{
   struct ao2_iterator it;
   struct ast_format *tmp;

   if (ao2_container_count(cap1->formats) != ao2_container_count(cap2->formats)) {
      return 0; /* if they are not the same size, they are not identical */
   }

   it = ao2_iterator_init(cap1->formats, 0);
   while ((tmp = ao2_iterator_next(&it))) {
      if (!ast_format_cap_iscompatible(cap2, tmp)) {
         ao2_ref(tmp, -1);
         ao2_iterator_destroy(&it);
         return 0;
      }
      ao2_ref(tmp, -1);
   }
   ao2_iterator_destroy(&it);

   return 1;
}
int ast_format_cap_is_empty ( const struct ast_format_cap cap)
void ast_format_cap_iter_end ( struct ast_format_cap cap)

Ends ast_format_cap iteration.

Note:
this must be call after every ast_format_cap_iter_start

Definition at line 558 of file format_cap.c.

References ao2_iterator_destroy(), ao2_unlock, ast_format_cap::formats, and ast_format_cap::it.

Referenced by add_sdp(), ast_openvstream(), ast_rtp_lookup_mime_multiple2(), ast_translate_available_formats(), ast_translator_best_choice(), create_addr(), gtalk_new(), jingle_new(), transmit_connect(), transmit_connect_with_sdp(), transmit_modify_request(), and transmit_modify_with_sdp().

{
   ao2_iterator_destroy(&cap->it);
   /* We can unconditionally unlock even if the container has no lock. */
   ao2_unlock(cap->formats);
}
int ast_format_cap_iter_next ( struct ast_format_cap cap,
struct ast_format format 
)

Next format in interation.

Here is how to use the ast_format_cap iterator.

1. call ast_format_cap_iter_start 2. call ast_format_cap_iter_next in a loop until it returns -1 3. call ast_format_cap_iter_end to terminate the iterator.

example:

ast_format_cap_iter_start(cap); while (!ast_format_cap_iter_next(cap, &format)) {

} ast_format_cap_iter_end(Cap);

Unless the container was alloced using no_lock, the container will be locked during the entire iteration until ast_format_cap_iter_end is called. XXX Remember this, and do not attempt to lock any containers within this iteration that will violate locking order.

Return values:
0on success, new format is copied into input format struct
-1,nomore formats are present.

Definition at line 565 of file format_cap.c.

References ao2_iterator_next, ao2_ref, ast_format_copy(), and ast_format_cap::it.

Referenced by add_sdp(), ast_openvstream(), ast_rtp_lookup_mime_multiple2(), ast_translate_available_formats(), ast_translator_best_choice(), create_addr(), gtalk_new(), jingle_new(), transmit_connect(), transmit_connect_with_sdp(), transmit_modify_request(), and transmit_modify_with_sdp().

{
   struct ast_format *tmp = ao2_iterator_next(&cap->it);

   if (!tmp) {
      return -1;
   }
   ast_format_copy(format, tmp);
   ao2_ref(tmp, -1);

   return 0;
}
struct ast_format_cap* ast_format_cap_joint ( const struct ast_format_cap cap1,
const struct ast_format_cap cap2 
) [read]

Get joint capability structure.

Note:
returns an ast_format_cap object containing the joint capabilities on success. This new capabilities structure is allocated with _NO_ locking enabled. If a joint structure requires locking, allocate it and use the ast_format_cap_joint_copy function to fill it with the joint capabilities.
Return values:
!NULLsuccess, joint capabilties structure with _NO_ locking enabled.
NULLfailure

Definition at line 434 of file format_cap.c.

References ao2_callback, ao2_container_count(), ao2_iterator_destroy(), ao2_iterator_init(), ao2_iterator_next, ao2_ref, ast_format_cap_alloc_nolock(), ast_format_cap_destroy(), find_joint_cb(), find_joint_data::format, ast_format_cap::formats, find_joint_data::joint_found, OBJ_MULTIPLE, and OBJ_NODATA.

Referenced by ast_speech_new(), ast_translator_best_choice(), check_peer_ok(), and iax2_request().

{
   struct ao2_iterator it;
   struct ast_format_cap *result = ast_format_cap_alloc_nolock();
   struct ast_format *tmp;
   struct find_joint_data data = {
      .joint_found = 0,
      .joint_cap = result,
   };
   if (!result) {
      return NULL;
   }

   it = ao2_iterator_init(cap1->formats, 0);
   while ((tmp = ao2_iterator_next(&it))) {
      data.format = tmp;
      ao2_callback(cap2->formats,
         OBJ_MULTIPLE | OBJ_NODATA,
         find_joint_cb,
         &data);
      ao2_ref(tmp, -1);
   }
   ao2_iterator_destroy(&it);

   if (ao2_container_count(result->formats)) {
      return result;
   }

   result = ast_format_cap_destroy(result);
   return NULL;
}
int ast_format_cap_joint_append ( const struct ast_format_cap cap1,
const struct ast_format_cap cap2,
struct ast_format_cap result 
)

Get joint capability structure, append into result capabilities structure.

Return values:
1,jointcapabilities exist
0,jointcapabilities do not exist

Definition at line 491 of file format_cap.c.

References joint_copy_helper().

Referenced by jingle_interpret_description(), and process_sdp().

{
   return joint_copy_helper(cap1, cap2, result, 1);
}
int ast_format_cap_joint_copy ( const struct ast_format_cap cap1,
const struct ast_format_cap cap2,
struct ast_format_cap result 
)

Get joint capability structure, copy into result capabilities structure.

Return values:
1,jointcapabilities exist
0,jointcapabilities do not exist

Definition at line 496 of file format_cap.c.

References joint_copy_helper().

Referenced by add_sdp(), gtalk_is_answered(), gtalk_newcall(), handle_capabilities_res_message(), process_sdp(), sip_request_call(), and skinny_register().

{
   return joint_copy_helper(cap1, cap2, result, 0);
}
int ast_format_cap_remove ( struct ast_format_cap cap,
struct ast_format format 
)

Remove format capability from capability structure.

format must match Exactly to format in ast_format_cap object in order to be removed.

Return values:
0,removewas successful
-1,removefailed. Could not find format to remove

Definition at line 213 of file format_cap.c.

References ao2_callback, ao2_ref, find_exact_cb(), ast_format_cap::formats, OBJ_POINTER, and OBJ_UNLINK.

Referenced by ast_parse_allow_disallow(), phone_new(), and reload_config().

{
   struct ast_format *fremove;

   fremove = ao2_callback(cap->formats, OBJ_POINTER | OBJ_UNLINK, find_exact_cb, format);
   if (fremove) {
      ao2_ref(fremove, -1);
      return 0;
   }

   return -1;
}
int ast_format_cap_remove_byid ( struct ast_format_cap cap,
enum ast_format_id  id 
)

Remove all format capabilities from capability structure for a specific format id.

This will remove _ALL_ formats matching the format id from the capabilities structure.

Return values:
0,removewas successful
-1,removefailed. Could not find formats to remove

Definition at line 245 of file format_cap.c.

References ao2_callback, format, multiple_by_id_data::format, ast_format_cap::formats, ast_format::id, id, multiple_by_id_data::match_found, multiple_by_id_cb(), OBJ_MULTIPLE, OBJ_NODATA, and OBJ_UNLINK.

Referenced by ast_translate_available_formats().

{
   struct ast_format format = {
      .id = id,
   };
   struct multiple_by_id_data data = {
      .format = &format,
      .match_found = 0,
   };

   ao2_callback(cap->formats,
      OBJ_NODATA | OBJ_MULTIPLE | OBJ_UNLINK,
      multiple_by_id_cb,
      &data);

   /* match_found will be set if at least one item was removed */
   if (data.match_found) {
      return 0;
   }

   return -1;
}
uint64_t ast_format_cap_to_old_bitfield ( const struct ast_format_cap cap)

ast_format_cap to old bitfield format represenatation

Note:
This is only to be used for IAX2 compatibility
Return values:
oldbitfield representation of ast_format_cap
0,ifno old bitfield capabilities are present in ast_format_cap

Definition at line 614 of file format_cap.c.

References ao2_iterator_destroy(), ao2_iterator_init(), ao2_iterator_next, ao2_ref, ast_format_to_old_bitfield(), and ast_format_cap::formats.

Referenced by __oh323_new(), __oh323_update_info(), h323_parse_allow_disallow(), iax2_call(), iax2_parse_allow_disallow(), and socket_process_helper().

{
   uint64_t res = 0;
   struct ao2_iterator it;
   struct ast_format *tmp;

   it = ao2_iterator_init(cap->formats, 0);
   while ((tmp = ao2_iterator_next(&it))) {
      res |= ast_format_to_old_bitfield(tmp);
      ao2_ref(tmp, -1);
   }
   ao2_iterator_destroy(&it);
   return res;
}
char* ast_getformatname_multiple ( char *  buf,
size_t  size,
struct ast_format_cap cap 
)

Get the names of a set of formats.

Parameters:
bufa buffer for the output string
sizesize of buf (bytes)
formatthe format (combined IDs of codecs) Prints a list of readable codec names corresponding to "format". ex: for format=AST_FORMAT_GSM|AST_FORMAT_SPEEX|AST_FORMAT_ILBC it will return "0x602 (GSM|SPEEX|ILBC)"
Returns:
The return value is buf.

Definition at line 578 of file format_cap.c.

References ast_copy_string(), ast_format_cap_iscompatible(), ast_format_copy(), ast_format_list_destroy(), ast_format_list_get(), format, len(), and name.

Referenced by __ast_read(), _sip_show_peer(), _skinny_show_device(), _skinny_show_line(), add_sdp(), alsa_request(), ast_best_codec(), ast_request(), ast_rtp_instance_bridge(), ast_streamfile(), ast_write(), bridge_make_compatible(), console_request(), func_channel_read(), function_sippeer(), gtalk_is_answered(), gtalk_newcall(), gtalk_show_settings(), gtalk_write(), handle_capabilities_res_message(), handle_cli_core_show_channeltype(), handle_showchan(), iax2_bridge(), iax2_getformatname_multiple(), iax2_request(), jingle_write(), mgcp_request(), mgcp_write(), nbs_request(), oh323_request(), oh323_write(), oss_request(), phone_request(), process_sdp(), remote_bridge_loop(), serialize_showchan(), set_format(), setup_rtp_connection(), show_channels_cb(), sip_new(), sip_request_call(), sip_show_channel(), sip_show_settings(), sip_write(), skinny_new(), skinny_request(), skinny_write(), socket_process_helper(), start_rtp(), unistim_new(), unistim_request(), unistim_rtp_read(), unistim_show_info(), and unistim_write().

{
   int x;
   unsigned len;
   char *start, *end = buf;
   struct ast_format tmp_fmt;
   size_t f_len;
   const struct ast_format_list *f_list = ast_format_list_get(&f_len);

   if (!size) {
      f_list = ast_format_list_destroy(f_list);
      return buf;
   }
   snprintf(end, size, "(");
   len = strlen(end);
   end += len;
   size -= len;
   start = end;
   for (x = 0; x < f_len; x++) {
      ast_format_copy(&tmp_fmt, &f_list[x].format);
      if (ast_format_cap_iscompatible(cap, &tmp_fmt)) {
         snprintf(end, size, "%s|", f_list[x].name);
         len = strlen(end);
         end += len;
         size -= len;
      }
   }
   if (start == end) {
      ast_copy_string(start, "nothing)", size);
   } else if (size > 1) {
      *(end - 1) = ')';
   }
   f_list = ast_format_list_destroy(f_list);
   return buf;
}
ASTERISK_FILE_VERSION ( __FILE__  ,
"$Revision: 369013 $"   
)
static struct ast_format_cap* cap_alloc_helper ( int  nolock) [static, read]
static int cmp_cb ( void *  obj,
void *  arg,
int  flags 
) [static]

format exists within capabilities structure if it is identical to another format, or if the format is a proper subset of another format.

Definition at line 52 of file format_cap.c.

References ast_format_cmp(), AST_FORMAT_CMP_EQUAL, AST_FORMAT_CMP_SUBSET, CMP_MATCH, and CMP_STOP.

Referenced by cap_alloc_helper().

{
   struct ast_format *format1 = arg;
   struct ast_format *format2 = obj;
   enum ast_format_cmp_res res = ast_format_cmp(format1, format2);

   return ((res == AST_FORMAT_CMP_EQUAL) ||
         (res == AST_FORMAT_CMP_SUBSET)) ?
            CMP_MATCH | CMP_STOP :
            0;
}
static int copy_cb ( void *  obj,
void *  arg,
int  flag 
) [static]

Definition at line 167 of file format_cap.c.

References ast_format_cap_add(), and format.

Referenced by ast_format_cap_copy(), and ast_format_cap_dup().

{
   struct ast_format_cap *result = (struct ast_format_cap *) arg;
   struct ast_format *format = (struct ast_format *) obj;

   ast_format_cap_add(result, format);
   return 0;
}
static int find_best_byid_cb ( void *  obj,
void *  arg,
int  flag 
) [static]

Definition at line 331 of file format_cap.c.

References ast_format_copy(), ast_format_rate(), format, ast_format::id, byid_data::id, and byid_data::result.

Referenced by ast_format_cap_best_byid().

{
   struct ast_format *format = obj;
   struct byid_data *data = arg;

   if (data->id != format->id) {
      return 0;
   }
   if (!data->result->id || (ast_format_rate(data->result) < ast_format_rate(format))) {
      ast_format_copy(data->result, format);
   }
   return 0;
}
static int find_exact_cb ( void *  obj,
void *  arg,
int  flag 
) [static]

Definition at line 205 of file format_cap.c.

References ast_format_cmp(), AST_FORMAT_CMP_EQUAL, and CMP_MATCH.

Referenced by ast_format_cap_remove().

{
   struct ast_format *format1 = (struct ast_format *) arg;
   struct ast_format *format2 = (struct ast_format *) obj;

   return (ast_format_cmp(format1, format2) == AST_FORMAT_CMP_EQUAL) ? CMP_MATCH : 0;
}
static int find_joint_cb ( void *  obj,
void *  arg,
int  flag 
) [static]

Definition at line 372 of file format_cap.c.

References ast_format_cap_add(), ast_format_joint(), format, find_joint_data::format, find_joint_data::joint_cap, and find_joint_data::joint_found.

Referenced by ast_format_cap_has_joint(), ast_format_cap_joint(), and joint_copy_helper().

{
   struct ast_format *format = obj;
   struct find_joint_data *data = arg;

   struct ast_format tmp = { 0, };
   if (!ast_format_joint(format, data->format, &tmp)) {
      if (data->joint_cap) {
         ast_format_cap_add(data->joint_cap, &tmp);
      }
      data->joint_found++;
   }

   return 0;
}
static int hash_cb ( const void *  obj,
const int  flags 
) [static]

Definition at line 64 of file format_cap.c.

References format, and ast_format::id.

Referenced by cap_alloc_helper().

{
   const struct ast_format *format = obj;
   return format->id;
}
static int joint_copy_helper ( const struct ast_format_cap cap1,
const struct ast_format_cap cap2,
struct ast_format_cap result,
int  append 
) [static]
static int multiple_by_id_cb ( void *  obj,
void *  arg,
int  flag 
) [static]

Definition at line 231 of file format_cap.c.

References CMP_MATCH, format, multiple_by_id_data::format, ast_format::id, and multiple_by_id_data::match_found.

Referenced by ast_format_cap_remove_byid().

{
   struct multiple_by_id_data *data = arg;
   struct ast_format *format = obj;
   int res;

   res = (format->id == data->format->id) ? CMP_MATCH : 0;
   if (res) {
      data->match_found = 1;
   }

   return res;
}
static int multiple_by_type_cb ( void *  obj,
void *  arg,
int  flag 
) [static]

Definition at line 268 of file format_cap.c.

References AST_FORMAT_GET_TYPE, CMP_MATCH, format, ast_format::id, and type.

Referenced by ast_format_cap_remove_bytype().

{
   int *type = arg;
   struct ast_format *format = obj;
   return ((AST_FORMAT_GET_TYPE(format->id)) == *type) ? CMP_MATCH : 0;
}