Asterisk - The Open Source Telephony Project
21.4.1
|
Media Format API. More...
#include "asterisk.h"
#include "asterisk/logger.h"
#include "asterisk/codec.h"
#include "asterisk/format.h"
#include "asterisk/astobj2.h"
#include "asterisk/strings.h"
#include "asterisk/module.h"
Go to the source code of this file.
Data Structures | |
struct | ast_format |
Definition of a media format. More... | |
struct | format_interface |
Structure used when registering a format interface. More... | |
Macros | |
#define | FORMAT_INTERFACE_BUCKETS 53 |
Number of buckets to use for format interfaces (should be prime for performance reasons) | |
Functions | |
int | __ast_format_interface_register (const char *codec, const struct ast_format_interface *interface, struct ast_module *mod) |
Register a format interface for use with the provided codec. More... | |
const void * | ast_format_attribute_get (const struct ast_format *format, const char *name) |
struct ast_format * | ast_format_attribute_set (const struct ast_format *format, const char *name, const char *value) |
Set an attribute on a format to a specific value. More... | |
int | ast_format_can_be_smoothed (const struct ast_format *format) |
Get whether or not the format can be smoothed. More... | |
struct ast_format * | ast_format_clone (const struct ast_format *format) |
Clone an existing media format so it can be modified. More... | |
enum ast_format_cmp_res | ast_format_cmp (const struct ast_format *format1, const struct ast_format *format2) |
Compare two formats. More... | |
struct ast_format * | ast_format_create (struct ast_codec *codec) |
Create a new media format. More... | |
struct ast_format * | ast_format_create_named (const char *format_name, struct ast_codec *codec) |
Create a new media format with a specific name. More... | |
unsigned int | ast_format_determine_length (const struct ast_format *format, unsigned int samples) |
Get the length (in milliseconds) for the format with a given number of samples. More... | |
void | ast_format_generate_sdp_fmtp (const struct ast_format *format, unsigned int payload, struct ast_str **str) |
This function is used to produce an fmtp SDP line for an Asterisk format. The attributes present on the Asterisk format are translated into the SDP equivalent. More... | |
void * | ast_format_get_attribute_data (const struct ast_format *format) |
Get the attribute data on a format. More... | |
unsigned int | ast_format_get_channel_count (const struct ast_format *format) |
Get the channel count on a format. More... | |
struct ast_codec * | ast_format_get_codec (const struct ast_format *format) |
Get the codec associated with a format. More... | |
unsigned int | ast_format_get_codec_id (const struct ast_format *format) |
Get the codec identifier associated with a format. More... | |
const char * | ast_format_get_codec_name (const struct ast_format *format) |
Get the codec name associated with a format. More... | |
unsigned int | ast_format_get_default_ms (const struct ast_format *format) |
Get the default framing size (in milliseconds) for a format. More... | |
unsigned int | ast_format_get_maximum_ms (const struct ast_format *format) |
Get the maximum amount of media carried in this format. More... | |
unsigned int | ast_format_get_minimum_bytes (const struct ast_format *format) |
Get the minimum number of bytes expected in a frame for this format. More... | |
unsigned int | ast_format_get_minimum_ms (const struct ast_format *format) |
Get the minimum amount of media carried in this format. More... | |
const char * | ast_format_get_name (const struct ast_format *format) |
Get the name associated with a format. More... | |
unsigned int | ast_format_get_sample_rate (const struct ast_format *format) |
Get the sample rate of a media format. More... | |
int | ast_format_get_smoother_flags (const struct ast_format *format) |
Get smoother flags for this format. More... | |
enum ast_media_type | ast_format_get_type (const struct ast_format *format) |
Get the media type of a format. More... | |
int | ast_format_init (void) |
Initialize media format support. More... | |
struct ast_format * | ast_format_joint (const struct ast_format *format1, const struct ast_format *format2) |
Get a common joint capability between two formats. More... | |
struct ast_format * | ast_format_parse_sdp_fmtp (const struct ast_format *format, const char *attributes) |
This function is used to have a media format aware module parse and interpret SDP attribute information. Once interpreted this information is stored on the format itself using Asterisk format attributes. More... | |
void | ast_format_set_attribute_data (struct ast_format *format, void *attribute_data) |
Set the attribute data on a format. More... | |
void | ast_format_set_channel_count (struct ast_format *format, unsigned int channel_count) |
Set the channel count on a format. More... | |
static void | format_destroy (void *obj) |
Destructor for media formats. | |
static void | format_shutdown (void) |
Function called when the process is shutting down. | |
Variables | |
static struct ao2_container * | interfaces |
Container for registered format interfaces. | |
Media Format API.
Definition in file format.c.
int __ast_format_interface_register | ( | const char * | codec, |
const struct ast_format_interface * | interface, | ||
struct ast_module * | mod | ||
) |
Register a format interface for use with the provided codec.
codec | The name of codec the interface is applicable to |
interface | A pointer to the interface implementation |
mod | The module this format interface is provided by |
0 | success |
-1 | failure |
Definition at line 90 of file format.c.
References AO2_ALLOC_OPT_LOCK_NOLOCK, ao2_link_flags, ao2_ref, ast_module_shutdown_ref, format_interface::codec, ast_format_interface::format_clone, ast_format_interface::format_destroy, format_interface::interface, lock, OBJ_NOLOCK, OBJ_SEARCH_KEY, and SCOPED_AO2WRLOCK.
const void* ast_format_attribute_get | ( | const struct ast_format * | format, |
const char * | name | ||
) |
format | The format to retrieve the attribute from |
name | Attribute name |
non-NULL | the attribute value |
NULL | the attribute does not exist or is unset |
Definition at line 267 of file format.c.
References ao2_ref, ast_format::codec, ast_codec::name, and OBJ_SEARCH_KEY.
struct ast_format* ast_format_attribute_set | ( | const struct ast_format * | format, |
const char * | name, | ||
const char * | value | ||
) |
Set an attribute on a format to a specific value.
format | The format to set the attribute on |
name | Attribute name |
value | Attribute value |
non-NULL | success |
NULL | failure |
Definition at line 248 of file format.c.
References ao2_bump, ao2_ref, and OBJ_SEARCH_KEY.
int ast_format_can_be_smoothed | ( | const struct ast_format * | format | ) |
Get whether or not the format can be smoothed.
format | The media format |
0 | the format cannot be smoothed |
1 | the format can be smoothed |
Definition at line 344 of file format.c.
References ast_format::codec, and ast_codec::smooth.
Referenced by ast_rtp_write(), and multicast_rtp_write().
struct ast_format* ast_format_clone | ( | const struct ast_format * | format | ) |
Clone an existing media format so it can be modified.
format | The existing media format |
non-NULL | success |
NULL | failure |
Definition at line 180 of file format.c.
References ao2_ref, ast_format_create_named(), ast_format::codec, ast_format_interface::format_clone, ast_format::interface, and ast_format::name.
Referenced by test_core_format_attribute_set(), test_core_format_get_joint(), and test_core_format_parse_sdp_fmtp().
enum ast_format_cmp_res ast_format_cmp | ( | const struct ast_format * | format1, |
const struct ast_format * | format2 | ||
) |
Compare two formats.
Definition at line 201 of file format.c.
References AST_FORMAT_CMP_EQUAL, AST_FORMAT_CMP_NOT_EQUAL, and ast_format::codec.
Referenced by __ast_read(), alarmreceiver_exec(), ast_bridge_channel_restore_formats(), ast_channel_make_compatible_helper(), ast_dsp_process(), ast_format_cache_is_slinear(), ast_format_cap_get_compatible_format(), ast_format_cap_get_format_framing(), ast_format_cap_iscompatible_format(), ast_format_compatibility_format2bitfield(), ast_format_joint(), ast_frame_slinear_sum(), ast_read_image(), ast_rtp_codecs_payload_code_sample_rate(), ast_rtp_codecs_payload_code_tx_sample_rate(), ast_rtp_codecs_payloads_set_rtpmap_type_rate(), ast_rtp_codecs_payloads_unset(), ast_rtp_engine_unload_format(), ast_rtp_get_rate(), ast_rtp_lookup_mime_subtype2(), ast_rtp_lookup_sample_rate2(), ast_rtp_write(), ast_set_read_format_path(), ast_set_write_format_path(), ast_slinfactory_feed(), ast_write_stream(), ast_writestream(), bridge_p2p_rtp_write(), chan_pjsip_read_stream(), fax_detect_framehook(), fax_gateway_framehook(), generic_fax_exec(), jingle_add_payloads_to_description(), make_silence(), rtp_raw_write(), and spandsp_fax_gateway_process().
struct ast_format* ast_format_create | ( | struct ast_codec * | codec | ) |
Create a new media format.
codec | The codec to use |
non-NULL | success |
NULL | failure |
Definition at line 196 of file format.c.
References ast_format_create_named(), and ast_codec::name.
Referenced by ast_format_cap_append_by_type(), and newpvt().
struct ast_format* ast_format_create_named | ( | const char * | format_name, |
struct ast_codec * | codec | ||
) |
Create a new media format with a specific name.
format_name | The name to use for the format |
codec | The codec to use |
codec
cannot be explicitly used for the name of the format. This is the case for codecs with multiple sample ratesnon-NULL | success |
NULL | failure |
Definition at line 157 of file format.c.
References AO2_ALLOC_OPT_LOCK_NOLOCK, ao2_bump, ao2_ref, ao2_t_alloc_options, ast_format::channel_count, ast_format::codec, ast_codec::description, format_destroy(), ast_format::interface, format_interface::interface, ast_format::name, ast_codec::name, OBJ_SEARCH_KEY, and S_OR.
Referenced by ast_format_clone(), and ast_format_create().
unsigned int ast_format_determine_length | ( | const struct ast_format * | format, |
unsigned int | samples | ||
) |
Get the length (in milliseconds) for the format with a given number of samples.
format | The media format |
samples | The number of samples |
Definition at line 384 of file format.c.
References ast_codec_determine_length(), and ast_format::codec.
void ast_format_generate_sdp_fmtp | ( | const struct ast_format * | format, |
unsigned int | payload, | ||
struct ast_str ** | str | ||
) |
This function is used to produce an fmtp SDP line for an Asterisk format. The attributes present on the Asterisk format are translated into the SDP equivalent.
format | to generate an fmtp line for |
payload | numerical payload for the fmtp line |
str | structure that the fmtp line will be appended to |
Definition at line 305 of file format.c.
References ao2_ref, ast_format::codec, ast_codec::name, and OBJ_SEARCH_KEY.
void* ast_format_get_attribute_data | ( | const struct ast_format * | format | ) |
Get the attribute data on a format.
format | The media format |
Definition at line 125 of file format.c.
References ast_format::attribute_data.
Referenced by ilbctolin_framein(), lintoilbc_frameout(), test_core_format_attribute_get(), test_core_format_attribute_set(), test_core_format_clone(), test_core_format_cmp(), test_core_format_destroy(), test_core_format_generate_sdp_fmtp(), test_core_format_get_joint(), and test_core_format_parse_sdp_fmtp().
unsigned int ast_format_get_channel_count | ( | const struct ast_format * | format | ) |
Get the channel count on a format.
format | The media format |
Definition at line 135 of file format.c.
References ast_format::channel_count.
Referenced by softmix_bridge_join().
struct ast_codec* ast_format_get_codec | ( | const struct ast_format * | format | ) |
Get the codec associated with a format.
format | The media format |
Definition at line 324 of file format.c.
References ao2_bump, and ast_format::codec.
Referenced by ast_codec_samples_count(), ast_format_cache_get_by_codec(), ast_format_cap_append_by_type(), and ast_translator_best_choice().
unsigned int ast_format_get_codec_id | ( | const struct ast_format * | format | ) |
Get the codec identifier associated with a format.
format | The media format |
Definition at line 329 of file format.c.
References ast_format::codec, and ast_codec::id.
Referenced by ast_format_cap_get_compatible_format(), ast_format_cap_get_format_framing(), ast_format_cap_iscompatible_format(), ast_format_cap_remove(), ast_format_compatibility_codec2bitfield(), and ast_slinfactory_feed().
const char* ast_format_get_codec_name | ( | const struct ast_format * | format | ) |
Get the codec name associated with a format.
format | The media format |
Definition at line 339 of file format.c.
References ast_format::codec, and ast_codec::name.
Referenced by ast_rtp_engine_load_format().
unsigned int ast_format_get_default_ms | ( | const struct ast_format * | format | ) |
Get the default framing size (in milliseconds) for a format.
format | The media format |
Definition at line 359 of file format.c.
References ast_format::codec, and ast_codec::default_ms.
Referenced by ast_format_cap_get_format_framing(), ast_rtp_write(), and multicast_rtp_write().
unsigned int ast_format_get_maximum_ms | ( | const struct ast_format * | format | ) |
Get the maximum amount of media carried in this format.
format | The media format |
Definition at line 369 of file format.c.
References ast_format::codec, and ast_codec::maximum_ms.
Referenced by create_outgoing_sdp_stream().
unsigned int ast_format_get_minimum_bytes | ( | const struct ast_format * | format | ) |
Get the minimum number of bytes expected in a frame for this format.
format | The media format |
Definition at line 374 of file format.c.
References ast_format::codec, and ast_codec::minimum_bytes.
Referenced by ast_rtp_write(), and multicast_rtp_write().
unsigned int ast_format_get_minimum_ms | ( | const struct ast_format * | format | ) |
Get the minimum amount of media carried in this format.
format | The media format |
Definition at line 364 of file format.c.
References ast_format::codec, and ast_codec::minimum_ms.
Referenced by ast_rtp_write(), and multicast_rtp_write().
const char* ast_format_get_name | ( | const struct ast_format * | format | ) |
Get the name associated with a format.
format | The media format |
Definition at line 334 of file format.c.
References ast_format::name.
Referenced by __ast_play_and_record(), add_format_information_cb(), agent_login_exec(), ast_bridge_channel_restore_formats(), ast_channel_make_compatible_helper(), ast_codec_samples_count(), ast_dsp_call_progress(), ast_dsp_process(), ast_format_cache_set(), ast_frame_subclass2str(), ast_openvstream(), ast_rtp_write(), ast_set_read_format_path(), ast_set_write_format_path(), ast_slinfactory_feed(), ast_stopstream(), ast_streamfile(), ast_translator_best_choice(), ast_translator_build_path(), ast_write_stream(), ast_writestream(), bridge_p2p_rtp_write(), chan_pjsip_read_stream(), channel_do_masquerade(), create_outgoing_sdp_stream(), handle_showchan(), iax2_codec_pref_string(), iax2_getformatname(), jingle_read(), jingle_write(), multicast_rtp_write(), and unistim_new().
unsigned int ast_format_get_sample_rate | ( | const struct ast_format * | format | ) |
Get the sample rate of a media format.
format | The media format |
Definition at line 379 of file format.c.
References ast_format::codec, and ast_codec::sample_rate.
Referenced by ast_channel_make_compatible_helper(), ast_ratestream(), ast_rtp_dtmf_begin(), ast_rtp_engine_load_format(), ast_rtp_get_rate(), ast_translate(), ast_translator_best_choice(), ast_translator_build_path(), ogg_speex_open(), schedule_delivery(), snoop_determine_format(), stasis_app_control_snoop(), and waitstream_core().
int ast_format_get_smoother_flags | ( | const struct ast_format * | format | ) |
Get smoother flags for this format.
format | The media format |
Definition at line 349 of file format.c.
References ast_format::codec, and ast_codec::smoother_flags.
Referenced by ast_rtp_write(), and multicast_rtp_write().
enum ast_media_type ast_format_get_type | ( | const struct ast_format * | format | ) |
Get the media type of a format.
format | The media format |
Definition at line 354 of file format.c.
References ast_format::codec, and ast_codec::type.
Referenced by __ast_read(), ast_ari_recordings_get_stored_file(), ast_format_cap_append_from_cap(), ast_format_cap_get_best_by_type(), ast_format_cap_has_type(), ast_format_cap_remove_by_type(), ast_format_cap_replace_from_cap(), ast_openvstream(), ast_playstream(), ast_rtp_codecs_get_stream_type(), ast_rtp_engine_load_format(), ast_translator_best_choice(), ast_translator_build_path(), ast_write_stream(), ast_writestream(), create_outgoing_sdp_stream(), and jingle_add_payloads_to_description().
int ast_format_init | ( | void | ) |
Initialize media format support.
0 | success |
-1 | failure |
Definition at line 77 of file format.c.
References AO2_ALLOC_OPT_LOCK_RWLOCK, ao2_container_alloc_hash, ast_register_cleanup(), FORMAT_INTERFACE_BUCKETS, and format_shutdown().
struct ast_format* ast_format_joint | ( | const struct ast_format * | format1, |
const struct ast_format * | format2 | ||
) |
Get a common joint capability between two formats.
non-NULL | if joint capability exists |
NULL | if no joint capability exists |
Definition at line 226 of file format.c.
References ao2_bump, ast_format_cmp(), AST_FORMAT_CMP_EQUAL, ast_format::attribute_data, and ast_format::codec.
Referenced by ast_format_cap_get_compatible_format().
struct ast_format* ast_format_parse_sdp_fmtp | ( | const struct ast_format * | format, |
const char * | attributes | ||
) |
This function is used to have a media format aware module parse and interpret SDP attribute information. Once interpreted this information is stored on the format itself using Asterisk format attributes.
format | to set |
attributes | string containing the fmtp line from the SDP |
non-NULL | success, attribute values were valid |
NULL | failure, values were not acceptable |
Definition at line 286 of file format.c.
References ao2_bump, ao2_ref, ast_format::codec, ast_codec::name, and OBJ_SEARCH_KEY.
Referenced by ast_rtp_codecs_payloads_set_rtpmap_type_rate().
void ast_format_set_attribute_data | ( | struct ast_format * | format, |
void * | attribute_data | ||
) |
Set the attribute data on a format.
format | The media format |
attribute_data | The attribute data |
Definition at line 130 of file format.c.
References ast_format::attribute_data.
Referenced by test_core_format_clone().
void ast_format_set_channel_count | ( | struct ast_format * | format, |
unsigned int | channel_count | ||
) |
Set the channel count on a format.
format | The media format |
channel_count | The number of audio channels used |
Definition at line 140 of file format.c.
References ast_format::channel_count.