Asterisk - The Open Source Telephony Project GIT-master-d856a3e
|
Codecs API. More...
#include "asterisk.h"
#include "asterisk/logger.h"
#include "asterisk/codec.h"
#include "asterisk/format.h"
#include "asterisk/frame.h"
#include "asterisk/astobj2.h"
#include "asterisk/strings.h"
#include "asterisk/module.h"
#include "asterisk/cli.h"
Go to the source code of this file.
Data Structures | |
struct | internal_ast_codec |
Macros | |
#define | CODEC_BUCKETS 53 |
Number of buckets to use for codecs (should be prime for performance reasons) More... | |
Functions | |
int | __ast_codec_register (struct ast_codec *codec, struct ast_module *mod) |
This function is used to register a codec with the Asterisk core. Registering allows it to be passed through in frames and configured in channel drivers. More... | |
int | __ast_codec_register_with_format (struct ast_codec *codec, const char *format_name, struct ast_module *mod) |
unsigned int | ast_codec_determine_length (const struct ast_codec *codec, unsigned int samples) |
Get the length of media (in milliseconds) given a number of samples. More... | |
struct ast_codec * | ast_codec_get (const char *name, enum ast_media_type type, unsigned int sample_rate) |
Retrieve a codec given a name, type, and sample rate. More... | |
struct ast_codec * | ast_codec_get_by_id (int id) |
Retrieve a codec given the unique identifier. More... | |
int | ast_codec_get_max (void) |
Retrieve the current maximum identifier for codec iteration. More... | |
int | ast_codec_init (void) |
Initialize codec support within the core. More... | |
const char * | ast_codec_media_type2str (enum ast_media_type type) |
Conversion function to take a media type and turn it into a string. More... | |
unsigned int | ast_codec_samples_count (struct ast_frame *frame) |
Get the number of samples contained within a frame. More... | |
enum ast_media_type | ast_media_type_from_str (const char *media_type_str) |
Conversion function to take a media string and convert it to a media type. More... | |
static int | codec_cmp (void *obj, void *arg, int flags) |
static void | codec_dtor (void *obj) |
static int | codec_id_cmp (void *obj, void *arg, int flags) |
Callback function for getting a codec based on unique identifier. More... | |
static void | codec_shutdown (void) |
Function called when the process is shutting down. More... | |
static char * | show_codec (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
static char * | show_codecs (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
Variables | |
static struct ast_cli_entry | codec_cli [] |
static int | codec_id = 1 |
Current identifier value for newly registered codec. More... | |
static struct ao2_container * | codecs |
Registered codecs. More... | |
Codecs API.
Definition in file codec.c.
#define CODEC_BUCKETS 53 |
int __ast_codec_register | ( | struct ast_codec * | codec, |
struct ast_module * | mod | ||
) |
This function is used to register a codec with the Asterisk core. Registering allows it to be passed through in frames and configured in channel drivers.
codec | to register |
mod | the module this codec is provided by |
0 | success |
-1 | failure |
Definition at line 273 of file codec.c.
References __ast_codec_register_with_format(), ast_codec::mod, and NULL.
int __ast_codec_register_with_format | ( | struct ast_codec * | codec, |
const char * | format_name, | ||
struct ast_module * | mod | ||
) |
Definition at line 278 of file codec.c.
References AO2_ALLOC_OPT_LOCK_NOLOCK, ao2_find, ao2_link_flags, ao2_ref, ao2_t_alloc_options, ast_codec_media_type2str(), ast_log, AST_MEDIA_TYPE_AUDIO, AST_MEDIA_TYPE_UNKNOWN, ast_module_shutdown_ref, ast_verb, codec_dtor(), codec_id, codecs, ast_codec::description, internal_ast_codec::external, internal_ast_codec::format_name, ast_codec::id, lock, LOG_ERROR, ast_codec::name, OBJ_NOLOCK, OBJ_SEARCH_OBJECT, S_OR, ast_codec::sample_rate, SCOPED_AO2WRLOCK, and ast_codec::type.
Referenced by __ast_codec_register().
unsigned int ast_codec_determine_length | ( | const struct ast_codec * | codec, |
unsigned int | samples | ||
) |
Get the length of media (in milliseconds) given a number of samples.
codec | The codec itself |
samples | The number of samples |
length | of media (in milliseconds) |
Definition at line 408 of file codec.c.
References ast_codec::get_length.
Referenced by ast_format_determine_length().
struct ast_codec * ast_codec_get | ( | const char * | name, |
enum ast_media_type | type, | ||
unsigned int | sample_rate | ||
) |
Retrieve a codec given a name, type, and sample rate.
name | The name of the codec |
type | The type of the codec |
sample_rate | Optional sample rate, may not be applicable for some types |
non-NULL | success |
NULL | failure |
Definition at line 327 of file codec.c.
References ao2_find, codecs, name, ast_codec::name, OBJ_SEARCH_OBJECT, ast_codec::sample_rate, and type.
Referenced by __ast_register_translator(), AST_TEST_DEFINE(), handle_show_translation_path(), and newpvt().
struct ast_codec * ast_codec_get_by_id | ( | int | id | ) |
Retrieve a codec given the unique identifier.
id | The unique identifier |
non-NULL | success |
NULL | failure |
Definition at line 338 of file codec.c.
References ao2_callback, codec_id_cmp(), and codecs.
Referenced by ast_format_cap_append_by_type(), AST_TEST_DEFINE(), complete_trans_path_choice(), handle_show_translation_path(), handle_show_translation_table(), and index2codec().
int ast_codec_get_max | ( | void | ) |
Retrieve the current maximum identifier for codec iteration.
Definition at line 343 of file codec.c.
References codec_id.
Referenced by ast_format_cap_append_by_type(), and AST_TEST_DEFINE().
int ast_codec_init | ( | void | ) |
Initialize codec support within the core.
0 | success |
-1 | failure |
Definition at line 250 of file codec.c.
References AO2_ALLOC_OPT_LOCK_RWLOCK, ao2_container_alloc_hash, ARRAY_LEN, ast_cli_register_multiple, ast_register_cleanup(), CODEC_BUCKETS, codec_cli, codec_cmp(), codec_shutdown(), codecs, and NULL.
Referenced by asterisk_daemon().
const char * ast_codec_media_type2str | ( | enum ast_media_type | type | ) |
Conversion function to take a media type and turn it into a string.
type | The media type |
string | representation of the media type |
Definition at line 348 of file codec.c.
References AST_MEDIA_TYPE_AUDIO, AST_MEDIA_TYPE_IMAGE, AST_MEDIA_TYPE_TEXT, AST_MEDIA_TYPE_VIDEO, and type.
Referenced by __ast_codec_register_with_format(), add_msid_to_stream(), add_sdp_streams(), ast_rtp_engine_load_format(), ast_rtp_interpret(), ast_rtp_read(), ast_sip_create_joint_call_cap(), ast_sip_session_media_state_add(), ast_stream_create_resolved(), ast_stream_to_str(), ast_stream_topology_append_stream(), ast_stream_topology_create_from_format_cap(), ast_stream_topology_set_stream(), AST_TEST_DEFINE(), chan_pjsip_write_stream(), check_stream_positions(), create_outgoing_sdp_stream(), handle_incoming_sdp(), handle_negotiated_sdp_session_media(), handle_showchan(), is_media_state_valid(), log_caps(), negotiate_incoming_sdp_stream(), rtp_check_timeout(), sdp_requires_deferral(), set_caps(), set_incoming_call_offer_cap(), show_codecs(), stream_echo_exec(), and stream_echo_write_error().
unsigned int ast_codec_samples_count | ( | struct ast_frame * | frame | ) |
Get the number of samples contained within a frame.
frame | The frame itself |
number | of samples in the frame |
Definition at line 379 of file codec.c.
References ao2_ref, ast_format_get_codec(), ast_format_get_name(), AST_FRAME_IMAGE, AST_FRAME_VIDEO, AST_FRAME_VOICE, ast_log, ast_frame_subclass::format, ast_frame::frametype, LOG_WARNING, ast_codec::samples_count, and ast_frame::subclass.
Referenced by ast_rtp_interpret(), dahdi_encoder_frameout(), isAnsweringMachine(), moh_generate(), ogg_speex_read(), schedule_delivery(), socket_process_helper(), and socket_process_meta().
enum ast_media_type ast_media_type_from_str | ( | const char * | media_type_str | ) |
Conversion function to take a media string and convert it to a media type.
media_type_str | The media type string |
The | ast_media_type that corresponds to the string |
Definition at line 364 of file codec.c.
References AST_MEDIA_TYPE_AUDIO, AST_MEDIA_TYPE_IMAGE, AST_MEDIA_TYPE_TEXT, AST_MEDIA_TYPE_UNKNOWN, and AST_MEDIA_TYPE_VIDEO.
Referenced by handle_incoming_sdp(), sdp_requires_deferral(), and stream_echo_exec().
|
static |
Definition at line 78 of file codec.c.
References ast_assert, AST_MEDIA_TYPE_UNKNOWN, CMP_MATCH, ast_codec::name, OBJ_SEARCH_KEY, OBJ_SEARCH_MASK, OBJ_SEARCH_OBJECT, OBJ_SEARCH_PARTIAL_KEY, ast_codec::sample_rate, and ast_codec::type.
Referenced by ast_codec_init().
|
static |
Definition at line 264 of file codec.c.
References ast_module_unref, and ast_codec::mod.
Referenced by __ast_codec_register_with_format().
|
static |
Callback function for getting a codec based on unique identifier.
Definition at line 190 of file codec.c.
References CMP_MATCH, CMP_STOP, and ast_codec::id.
Referenced by ast_codec_get_by_id(), and show_codec().
|
static |
Function called when the process is shutting down.
Definition at line 243 of file codec.c.
References ao2_cleanup, ARRAY_LEN, ast_cli_unregister_multiple(), codec_cli, codecs, and NULL.
Referenced by ast_codec_init().
|
static |
Definition at line 198 of file codec.c.
References a, ao2_callback, ao2_ref, ast_cli(), CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, codec_id_cmp(), codecs, ast_cli_entry::command, ast_codec::description, internal_ast_codec::external, internal_ast_codec::format_name, ast_codec::id, NULL, S_OR, and ast_cli_entry::usage.
|
static |
Definition at line 120 of file codec.c.
References a, ao2_iterator_destroy(), AO2_ITERATOR_DONTLOCK, ao2_iterator_init(), ao2_iterator_next, ao2_rdlock, ao2_ref, ao2_unlock, ast_cli(), ast_codec_media_type2str(), AST_MEDIA_TYPE_AUDIO, AST_MEDIA_TYPE_IMAGE, AST_MEDIA_TYPE_TEXT, AST_MEDIA_TYPE_VIDEO, ast_opt_dont_warn, CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, codecs, ast_cli_entry::command, ast_codec::description, internal_ast_codec::external, internal_ast_codec::format_name, ast_codec::id, ast_codec::name, NULL, ast_codec::quality, S_OR, ast_codec::type, and ast_cli_entry::usage.
|
static |
Definition at line 237 of file codec.c.
Referenced by ast_codec_init(), and codec_shutdown().
|
static |
Current identifier value for newly registered codec.
Definition at line 45 of file codec.c.
Referenced by __ast_codec_register_with_format(), and ast_codec_get_max().
|
static |
Registered codecs.
Definition at line 48 of file codec.c.
Referenced by __ast_codec_register_with_format(), action_originate(), ast_codec_get(), ast_codec_get_by_id(), ast_codec_init(), ast_rtp_codecs_find_payload_code(), ast_rtp_codecs_get_framing(), ast_rtp_codecs_get_payload(), ast_rtp_codecs_get_payload_format(), ast_rtp_codecs_get_preferred_dtmf_format_pt(), ast_rtp_codecs_get_preferred_dtmf_format_rate(), ast_rtp_codecs_get_preferred_format(), ast_rtp_codecs_get_stream_type(), ast_rtp_codecs_payload_code(), ast_rtp_codecs_payload_code_sample_rate(), ast_rtp_codecs_payload_code_tx(), ast_rtp_codecs_payload_code_tx_sample_rate(), ast_rtp_codecs_payload_formats(), ast_rtp_codecs_payload_replace_format(), ast_rtp_codecs_payload_set_rx(), ast_rtp_codecs_payload_set_rx_sample_rate(), ast_rtp_codecs_payloads_clear(), ast_rtp_codecs_payloads_destroy(), ast_rtp_codecs_payloads_initialize(), ast_rtp_codecs_payloads_set_m_type(), ast_rtp_codecs_payloads_set_rtpmap_type(), ast_rtp_codecs_payloads_set_rtpmap_type_rate(), ast_rtp_codecs_payloads_unset(), ast_rtp_codecs_set_framing(), ast_rtp_codecs_set_preferred_dtmf_format(), ast_rtp_codecs_set_preferred_format(), ast_rtp_payload_mapping_tx_is_present(), ast_rtp_read(), codec_prefs_to_str(), codec_shutdown(), find_unused_payload(), find_unused_payload_in_range(), get_codecs(), jingle_interpret_description(), load_module(), payload_mapping_rx_clear_primary(), payload_mapping_tx_is_present(), rtp_codecs_assign_payload_code_rx(), rtp_codecs_find_non_primary_dynamic_rx(), rtp_codecs_payload_replace_rx(), rtp_codecs_payload_set_rx(), set_caps(), set_incoming_call_offer_cap(), show_codec(), and show_codecs().