Asterisk - The Open Source Telephony Project
18.5.0
|
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 |
Number of buckets to use for codecs (should be prime for performance reasons)
Definition at line 42 of file codec.c.
Referenced by ast_codec_init().
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 272 of file codec.c.
References __ast_codec_register_with_format(), and NULL.
int __ast_codec_register_with_format | ( | struct ast_codec * | codec, |
const char * | format_name, | ||
struct ast_module * | mod | ||
) |
Definition at line 277 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, 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 407 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 326 of file codec.c.
References ao2_find, ast_codec::name, 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 337 of file codec.c.
References ao2_callback, and codec_id_cmp().
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 342 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 249 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_cmp(), codec_shutdown(), 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 347 of file codec.c.
References AST_MEDIA_TYPE_AUDIO, AST_MEDIA_TYPE_IMAGE, AST_MEDIA_TYPE_TEXT, and AST_MEDIA_TYPE_VIDEO.
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(), stream_echo_write_error(), and validate_stream().
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 378 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 363 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 263 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 189 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 242 of file codec.c.
References ao2_cleanup, ARRAY_LEN, ast_cli_unregister_multiple(), and NULL.
Referenced by ast_codec_init().
|
static |
Definition at line 197 of file codec.c.
References ao2_callback, ao2_ref, ast_cli_args::argc, ast_cli_args::argv, ast_cli(), CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, codec_id_cmp(), ast_cli_entry::command, ast_codec::description, internal_ast_codec::external, ast_cli_args::fd, 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 ao2_iterator_destroy(), AO2_ITERATOR_DONTLOCK, ao2_iterator_init(), ao2_iterator_next, ao2_rdlock, ao2_ref, ao2_unlock, ast_cli_args::argc, ast_cli_args::argv, 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, ast_cli_entry::command, ast_codec::description, internal_ast_codec::external, ast_cli_args::fd, internal_ast_codec::format_name, ast_codec::id, ast_codec::name, NULL, S_OR, ast_codec::type, and ast_cli_entry::usage.
|
static |
|
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 action_originate(), ast_rtp_read(), codec_prefs_to_str(), handle_capabilities_res_message(), and process_sdp().