Asterisk - The Open Source Telephony Project
21.4.1
|
Format Capabilities API. More...
#include "asterisk.h"
#include "asterisk/logger.h"
#include "asterisk/format.h"
#include "asterisk/format_cap.h"
#include "asterisk/format_cache.h"
#include "asterisk/codec.h"
#include "asterisk/astobj2.h"
#include "asterisk/strings.h"
#include "asterisk/vector.h"
#include "asterisk/linkedlists.h"
#include "asterisk/utils.h"
Go to the source code of this file.
Data Structures | |
struct | ast_format_cap |
Format capabilities structure, holds formats + preference order + etc. More... | |
struct | format_cap_framed |
Structure used for capability formats, adds framing. More... | |
struct | format_cap_framed_list |
Linked list for formats. More... | |
Macros | |
#define | FORMAT_CAP_FRAMED_ELEM_CLEANUP(elem) ao2_cleanup((elem)) |
format_cap_framed vector element cleanup. More... | |
#define | FORMAT_CAP_FRAMED_ELEM_CMP(elem, value) ((elem)->format == (value)) |
format_cap_framed comparator for AST_VECTOR_REMOVE_CMP_ORDERED() More... | |
Functions | |
struct ast_format_cap * | __ast_format_cap_alloc (enum ast_format_cap_flags flags, const char *tag, const char *file, int line, const char *func) |
int | __ast_format_cap_append (struct ast_format_cap *cap, struct ast_format *format, unsigned int framing, const char *tag, const char *file, int line, const char *func) |
static const char * | __ast_format_cap_get_names (const struct ast_format_cap *cap, struct ast_str **buf, int append) |
int | ast_format_cap_append_by_type (struct ast_format_cap *cap, enum ast_media_type type) |
Add all codecs Asterisk knows about for a specific type to the capabilities structure. More... | |
int | ast_format_cap_append_from_cap (struct ast_format_cap *dst, const struct ast_format_cap *src, enum ast_media_type type) |
Append the formats of provided type in src to dst. More... | |
const char * | ast_format_cap_append_names (const struct ast_format_cap *cap, struct ast_str **buf) |
Append the names of codecs of a set of formats to an ast_str buffer. More... | |
size_t | ast_format_cap_count (const struct ast_format_cap *cap) |
Get the number of formats present within the capabilities structure. More... | |
int | ast_format_cap_empty (const struct ast_format_cap *cap) |
Determine if a format cap has no formats in it. More... | |
struct ast_format * | ast_format_cap_get_best_by_type (const struct ast_format_cap *cap, enum ast_media_type type) |
Get the most preferred format for a particular media type. More... | |
int | ast_format_cap_get_compatible (const struct ast_format_cap *cap1, const struct ast_format_cap *cap2, struct ast_format_cap *result) |
Find the compatible formats between two capabilities structures. More... | |
struct ast_format * | ast_format_cap_get_compatible_format (const struct ast_format_cap *cap, const struct ast_format *format) |
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. More... | |
struct ast_format * | ast_format_cap_get_format (const struct ast_format_cap *cap, int position) |
Get the format at a specific index. More... | |
unsigned int | ast_format_cap_get_format_framing (const struct ast_format_cap *cap, const struct ast_format *format) |
Get the framing for a format. More... | |
unsigned int | ast_format_cap_get_framing (const struct ast_format_cap *cap) |
Get the global framing. More... | |
const char * | ast_format_cap_get_names (const struct ast_format_cap *cap, struct ast_str **buf) |
Get the names of codecs of a set of formats. More... | |
int | ast_format_cap_has_type (const struct ast_format_cap *cap, enum ast_media_type type) |
Find out if the capabilities structure has any formats of a specific type. More... | |
int | ast_format_cap_identical (const struct ast_format_cap *cap1, const struct ast_format_cap *cap2) |
Determine if two capabilities structures are identical. More... | |
int | ast_format_cap_iscompatible (const struct ast_format_cap *cap1, const struct ast_format_cap *cap2) |
Determine if any joint capabilities exist between two capabilities structures. More... | |
enum ast_format_cmp_res | ast_format_cap_iscompatible_format (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. More... | |
int | ast_format_cap_remove (struct ast_format_cap *cap, struct ast_format *format) |
Remove format capability from capability structure. More... | |
void | ast_format_cap_remove_by_type (struct ast_format_cap *cap, enum ast_media_type type) |
Remove all formats matching a specific format type. More... | |
void | ast_format_cap_replace_from_cap (struct ast_format_cap *dst, const struct ast_format_cap *src, enum ast_media_type type) |
Replace the formats of provided type in dst with equivalent formats from src. More... | |
void | ast_format_cap_set_framing (struct ast_format_cap *cap, unsigned int framing) |
Set the global framing. More... | |
int | ast_format_cap_update_by_allow_disallow (struct ast_format_cap *cap, const char *list, int allowing) |
Parse an "allow" or "deny" list and modify a format capabilities structure accordingly. More... | |
static void | format_cap_destroy (void *obj) |
Destructor for format capabilities structure. | |
static void | format_cap_framed_destroy (void *obj) |
Destructor for format capabilities framed structure. | |
static int | format_cap_framed_init (struct format_cap_framed *framed, struct ast_format_cap *cap, struct ast_format *format, unsigned int framing) |
static int | format_cap_init (struct ast_format_cap *cap, enum ast_format_cap_flags flags) |
Initialize values on an ast_format_cap. More... | |
static int | format_cap_replace (struct ast_format_cap *cap, struct ast_format *format, unsigned int framing) |
static int | format_in_format_cap (struct ast_format_cap *cap, struct ast_format *format) |
static int | internal_format_cap_identical (const struct ast_format_cap *cap1, const struct ast_format_cap *cap2) |
Variables | |
static const struct format_cap_framed_list | format_cap_framed_list_empty = AST_LIST_HEAD_NOLOCK_INIT_VALUE |
Dummy empty list for when we are inserting a new list. | |
Format Capabilities API.
Definition in file format_cap.c.
#define FORMAT_CAP_FRAMED_ELEM_CLEANUP | ( | elem | ) | ao2_cleanup((elem)) |
format_cap_framed vector element cleanup.
elem | Element to cleanup |
Definition at line 493 of file format_cap.c.
Referenced by ast_format_cap_remove(), and ast_format_cap_remove_by_type().
#define FORMAT_CAP_FRAMED_ELEM_CMP | ( | elem, | |
value | |||
) | ((elem)->format == (value)) |
format_cap_framed comparator for AST_VECTOR_REMOVE_CMP_ORDERED()
elem | Element to compare against |
value | Value to compare with the vector element. |
0 | if element does not match. |
Non-zero | if element matches. |
Definition at line 486 of file format_cap.c.
Referenced by ast_format_cap_remove(), and ast_format_cap_remove_by_type().
int ast_format_cap_append_by_type | ( | struct ast_format_cap * | cap, |
enum ast_media_type | type | ||
) |
Add all codecs Asterisk knows about for a specific type to the capabilities structure.
cap | The capabilities structure to add to. |
type | The type of formats to add. |
0 | success |
-1 | failure |
Definition at line 216 of file format_cap.c.
References ao2_ref, ast_codec_get_by_id(), ast_codec_get_max(), ast_format_cache_get_by_codec(), ast_format_cap_append, ast_format_create(), ast_format_get_codec(), ast_format_none, format_cap_framed::format, and ast_codec::type.
Referenced by ast_ari_channels_create(), ast_format_cap_update_by_allow_disallow(), ast_local_init(), begin_dial_prerun(), and load_module().
int ast_format_cap_append_from_cap | ( | struct ast_format_cap * | dst, |
const struct ast_format_cap * | src, | ||
enum ast_media_type | type | ||
) |
Append the formats of provided type in src to dst.
dst | The destination capabilities structure |
src | The source capabilities structure |
type | The type of formats to append. |
0 | success |
-1 | failure |
Definition at line 269 of file format_cap.c.
References ast_format_cap_append, ast_format_get_type(), AST_VECTOR_GET, AST_VECTOR_SIZE, format_cap_framed::format, format_cap_framed::framing, and ast_format_cap::preference_order.
Referenced by ast_media_get_format_cap(), ast_stream_clone(), ast_stream_create_resolved(), ast_stream_topology_create_from_format_cap(), ast_stream_topology_get_formats_by_type(), chan_pjsip_get_codec(), chan_pjsip_new(), chan_pjsip_read_stream(), chan_rtp_get_codec(), channel_do_masquerade(), create_outgoing_sdp_stream(), jingle_alloc(), jingle_call(), jingle_interpret_content(), jingle_new(), load_module(), and unistim_new().
const char* ast_format_cap_append_names | ( | const struct ast_format_cap * | cap, |
struct ast_str ** | buf | ||
) |
Append the names of codecs of a set of formats to an ast_str buffer.
cap | The capabilities structure containing the formats |
buf | A ast_str buffer to append the names of the formats to |
buf
Definition at line 739 of file format_cap.c.
Referenced by ast_stream_create_resolved(), and ast_stream_to_str().
size_t ast_format_cap_count | ( | const struct ast_format_cap * | cap | ) |
Get the number of formats present within the capabilities structure.
cap | The capabilities structure |
Definition at line 395 of file format_cap.c.
References AST_VECTOR_SIZE, and ast_format_cap::preference_order.
Referenced by add_format_information_cb(), ast_format_cap_empty(), ast_iax2_new(), ast_openvstream(), ast_rtp_instance_available_formats(), ast_rtp_lookup_mime_multiple2(), ast_stream_get_format_count(), ast_stream_topology_create_from_format_cap(), ast_stream_topology_equal(), ast_translate_available_formats(), ast_translator_best_choice(), begin_dial_prerun(), create_outgoing_sdp_stream(), iax2_codec_pref_string(), iax2_format_compatibility_cap2bitfield(), jingle_add_payloads_to_description(), jingle_interpret_description(), jingle_new(), and unistim_new().
int ast_format_cap_empty | ( | const struct ast_format_cap * | cap | ) |
Determine if a format cap has no formats in it.
cap | The format cap to check for emptiness |
1 | The format cap has zero formats or only ast_format_none |
0 | The format cap has at least one format |
Definition at line 744 of file format_cap.c.
References ast_format_cap_count(), ast_format_none, AST_VECTOR_GET, and ast_format_cap::preference_order.
Referenced by ast_stream_create_resolved(), ast_translator_best_choice(), and chan_pjsip_new().
struct ast_format* ast_format_cap_get_best_by_type | ( | const struct ast_format_cap * | cap, |
enum ast_media_type | type | ||
) |
Get the most preferred format for a particular media type.
cap | The capabilities structure |
type | The type of media to get |
non-NULL | the preferred format |
NULL | no media of type present |
Definition at line 417 of file format_cap.c.
References ao2_ref, ast_format_cap_get_format(), ast_format_get_type(), ast_format_none, AST_VECTOR_GET, AST_VECTOR_SIZE, format_cap_framed::format, and ast_format_cap::preference_order.
Referenced by chan_pjsip_new().
int ast_format_cap_get_compatible | ( | const struct ast_format_cap * | cap1, |
const struct ast_format_cap * | cap2, | ||
struct ast_format_cap * | result | ||
) |
Find the compatible formats between two capabilities structures.
cap1 | The first capabilities structure | |
cap2 | The second capabilities structure | |
[out] | result | The capabilities structure to place the results into |
0 | success |
-1 | failure |
Definition at line 628 of file format_cap.c.
References ao2_ref, ast_format_cap_append, ast_format_cap_get_compatible_format(), AST_VECTOR_GET, AST_VECTOR_SIZE, format_cap_framed::format, format_cap_framed::framing, and ast_format_cap::preference_order.
Referenced by ast_speech_new(), ast_stream_create_resolved(), ast_translator_best_choice(), create_outgoing_sdp_stream(), and jingle_interpret_description().
struct ast_format* ast_format_cap_get_compatible_format | ( | const struct ast_format_cap * | cap, |
const struct ast_format * | format | ||
) |
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.
non-NULL | if format is compatible |
NULL | if not compatible |
Definition at line 546 of file format_cap.c.
References ast_format_cmp(), AST_FORMAT_CMP_EQUAL, AST_FORMAT_CMP_NOT_EQUAL, ast_format_get_codec_id(), ast_format_joint(), AST_LIST_TRAVERSE, AST_VECTOR_GET_ADDR, AST_VECTOR_SIZE, format_cap_framed::format, and ast_format_cap::formats.
Referenced by ast_format_cap_get_compatible(), and ast_translate_available_formats().
struct ast_format* ast_format_cap_get_format | ( | const struct ast_format_cap * | cap, |
int | position | ||
) |
Get the format at a specific index.
cap | The capabilities structure |
position | The position to get |
non-NULL | success |
NULL | failure |
Definition at line 400 of file format_cap.c.
References ao2_ref, ast_format_none, AST_VECTOR_GET, AST_VECTOR_SIZE, format_cap_framed::format, and ast_format_cap::preference_order.
Referenced by add_format_information_cb(), ast_format_cap_get_best_by_type(), ast_iax2_new(), ast_openvstream(), ast_rtp_lookup_mime_multiple2(), ast_speech_new(), ast_stream_create_resolved(), ast_translate_available_formats(), ast_translator_best_choice(), ast_unreal_new_channels(), audiosocket_request(), chan_pjsip_new(), create_outgoing_sdp_stream(), iax2_codec_pref_string(), iax2_format_compatibility_cap2bitfield(), jingle_add_payloads_to_description(), jingle_interpret_content(), jingle_new(), and unistim_new().
unsigned int ast_format_cap_get_format_framing | ( | const struct ast_format_cap * | cap, |
const struct ast_format * | format | ||
) |
Get the framing for a format.
cap | The capabilities structure |
format | The format to retrieve |
Definition at line 443 of file format_cap.c.
References ast_format_cmp(), AST_FORMAT_CMP_EQUAL, AST_FORMAT_CMP_NOT_EQUAL, ast_format_get_codec_id(), ast_format_get_default_ms(), AST_LIST_TRAVERSE, AST_VECTOR_GET_ADDR, AST_VECTOR_SIZE, format_cap_framed::format, ast_format_cap::formats, format_cap_framed::framing, and ast_format_cap::framing.
unsigned int ast_format_cap_get_framing | ( | const struct ast_format_cap * | cap | ) |
Get the global framing.
cap | The capabilities structure. |
0 | if no formats are in the structure and no framing has been provided |
Definition at line 438 of file format_cap.c.
References ast_format_cap::framing.
Referenced by ast_stream_create_resolved(), ast_stream_topology_create_from_format_cap(), create_outgoing_sdp_stream(), jingle_enable_video(), and jingle_new().
const char* ast_format_cap_get_names | ( | const struct ast_format_cap * | cap, |
struct ast_str ** | buf | ||
) |
Get the names of codecs of a set of formats.
cap | The capabilities structure containing the formats |
buf | A ast_str buffer to populate with the names of the formats |
buf
Definition at line 734 of file format_cap.c.
Referenced by ast_streamfile(), ast_write_stream(), chan_pjsip_get_codec(), chan_pjsip_set_rtp_peer(), chan_rtp_get_codec(), compatible_formats_exist(), console_request(), handle_cli_core_show_channeltype(), handle_showchan(), jingle_write(), local_request_with_stream_topology(), and unistim_new().
int ast_format_cap_has_type | ( | const struct ast_format_cap * | cap, |
enum ast_media_type | type | ||
) |
Find out if the capabilities structure has any formats of a specific type.
1 | true |
0 | false, no formats of specific type. |
Definition at line 613 of file format_cap.c.
References ast_format_get_type(), AST_VECTOR_GET, AST_VECTOR_SIZE, format_cap_framed::format, and ast_format_cap::preference_order.
Referenced by ast_bridge_update_talker_src_video_mode(), ast_channel_make_compatible_helper(), ast_openstream_full(), ast_openvstream(), ast_sendtext_data(), ast_stream_topology_create_from_format_cap(), jingle_enable_video(), jingle_request(), and negotiate_incoming_sdp_stream().
int ast_format_cap_identical | ( | const struct ast_format_cap * | cap1, |
const struct ast_format_cap * | cap2 | ||
) |
Determine if two capabilities structures are identical.
cap1 | The first capabilities structure |
cap2 | The second capabilities structure |
0 | capabilities are not identical |
1 | capabilities are identical |
Definition at line 687 of file format_cap.c.
References AST_VECTOR_SIZE, and ast_format_cap::preference_order.
Referenced by ast_stream_topology_equal().
int ast_format_cap_iscompatible | ( | const struct ast_format_cap * | cap1, |
const struct ast_format_cap * | cap2 | ||
) |
Determine if any joint capabilities exist between two capabilities structures.
cap1 | The first capabilities structure |
cap2 | The second capabilities structure |
0 | no joint capabilities exist |
1 | joint capabilities exist |
Definition at line 653 of file format_cap.c.
References ast_format_cap_iscompatible_format(), AST_FORMAT_CMP_NOT_EQUAL, AST_VECTOR_GET, AST_VECTOR_SIZE, format_cap_framed::format, and ast_format_cap::preference_order.
Referenced by ast_openvstream(), ast_rtp_instance_early_bridge(), ast_rtp_instance_early_bridge_make_compatible(), compatible_formats_exist(), and console_request().
enum ast_format_cmp_res ast_format_cap_iscompatible_format | ( | 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.
Definition at line 581 of file format_cap.c.
References ast_format_cmp(), AST_FORMAT_CMP_EQUAL, AST_FORMAT_CMP_NOT_EQUAL, ast_format_get_codec_id(), AST_LIST_TRAVERSE, AST_VECTOR_GET_ADDR, AST_VECTOR_SIZE, format_cap_framed::format, and ast_format_cap::formats.
Referenced by ast_format_cap_iscompatible(), ast_speech_new(), chan_pjsip_indicate(), chan_pjsip_read_stream(), is_compatible_format(), jingle_read(), and jingle_write().
int ast_format_cap_remove | ( | struct ast_format_cap * | cap, |
struct ast_format * | format | ||
) |
Remove format capability from capability structure.
0 | remove was successful |
-1 | remove failed. Could not find format to remove |
Definition at line 495 of file format_cap.c.
References ast_format_get_codec_id(), AST_LIST_REMOVE_CURRENT, AST_LIST_TRAVERSE_SAFE_BEGIN, AST_LIST_TRAVERSE_SAFE_END, AST_VECTOR_GET_ADDR, AST_VECTOR_REMOVE_CMP_ORDERED, AST_VECTOR_SIZE, FORMAT_CAP_FRAMED_ELEM_CLEANUP, FORMAT_CAP_FRAMED_ELEM_CMP, ast_format_cap::formats, and ast_format_cap::preference_order.
Referenced by ast_format_cap_update_by_allow_disallow().
void ast_format_cap_remove_by_type | ( | struct ast_format_cap * | cap, |
enum ast_media_type | type | ||
) |
Remove all formats matching a specific format type.
cap | The capabilities structure |
type | The media type to remove formats of |
Definition at line 523 of file format_cap.c.
References ao2_ref, ast_format_get_type(), AST_LIST_REMOVE_CURRENT, AST_LIST_TRAVERSE_SAFE_BEGIN, AST_LIST_TRAVERSE_SAFE_END, AST_VECTOR_GET_ADDR, AST_VECTOR_REMOVE_CMP_ORDERED, AST_VECTOR_SIZE, format_cap_framed::format, FORMAT_CAP_FRAMED_ELEM_CLEANUP, FORMAT_CAP_FRAMED_ELEM_CMP, ast_format_cap::formats, and ast_format_cap::preference_order.
Referenced by ast_format_cap_update_by_allow_disallow(), ast_rtp_codecs_payload_formats(), ast_stream_create_resolved(), chan_pjsip_read_stream(), and jingle_interpret_description().
void ast_format_cap_replace_from_cap | ( | struct ast_format_cap * | dst, |
const struct ast_format_cap * | src, | ||
enum ast_media_type | type | ||
) |
Replace the formats of provided type in dst with equivalent formats from src.
dst | The destination capabilities structure |
src | The source capabilities structure |
type | The type of formats to replace. |
Definition at line 306 of file format_cap.c.
References ast_format_get_type(), AST_VECTOR_GET, AST_VECTOR_SIZE, format_cap_framed::format, format_cap_framed::framing, and ast_format_cap::preference_order.
void ast_format_cap_set_framing | ( | struct ast_format_cap * | cap, |
unsigned int | framing | ||
) |
Set the global framing.
cap | The capabilities structure. |
framing | The framing value (in milliseconds). |
ast_format_cap
structure may override this value, if the framing they require is less than the value set by this function. Definition at line 136 of file format_cap.c.
References format_cap_framed::framing, and ast_format_cap::framing.
Referenced by ast_rtp_codecs_payload_formats(), ast_stream_create_resolved(), and ast_stream_topology_create_from_format_cap().
int ast_format_cap_update_by_allow_disallow | ( | struct ast_format_cap * | cap, |
const char * | list, | ||
int | allowing | ||
) |
Parse an "allow" or "deny" list and modify a format capabilities structure accordingly.
cap | The capabilities structure to modify |
list | The list containing formats to append or remove |
allowing | If zero, start removing formats specified in the list. If non-zero, start appending formats specified in the list. |
0 | on success |
-1 | on failure |
Definition at line 320 of file format_cap.c.
References ast_debug, ast_format_cache_get, ast_format_cap_append, ast_format_cap_append_by_type(), ast_format_cap_remove(), ast_format_cap_remove_by_type(), ast_strdupa, and ast_strip().
Referenced by codec_handler_fn().
|
inlinestatic |
Initialize values on an ast_format_cap.
cap | ast_format_cap to initialize |
flags | Unused. |
0 | Success |
-1 | Failure |
Definition at line 102 of file format_cap.c.
References AST_VECTOR_INIT, ast_format_cap::formats, ast_format_cap::framing, and ast_format_cap::preference_order.