42#define CODEC_BUCKETS 53
78static
int codec_cmp(
void *obj,
void *arg,
int flags)
82 const char *right_key = arg;
87 right_key = right->
name;
88 cmp = strcmp(left->
name, right_key);
103 cmp = strcmp(left->
name, right_key);
106 cmp = strncmp(left->
name, right_key, strlen(right_key));
127 e->
command =
"core show codecs [audio|video|image|text]";
129 "Usage: core show codecs [audio|video|image|text]\n"
130 " Displays codec mapping\n";
136 if ((
a->argc < 3) || (
a->argc > 4)) {
141 ast_cli(
a->fd,
"Disclaimer: this command is for informational purposes only.\n"
142 "\tIt does not indicate anything about your configuration.\n");
145 ast_cli(
a->fd,
"%8s %-5s %-12s %-16s %7s %s\n",
"ID",
"TYPE",
"NAME",
"FORMAT",
"QUALITY",
"DESCRIPTION");
146 ast_cli(
a->fd,
"------------------------------------------------------------------------------------------------\n");
153 if (!strcasecmp(
a->argv[3],
"audio")) {
157 }
else if (!strcasecmp(
a->argv[3],
"video")) {
161 }
else if (!strcasecmp(
a->argv[3],
"image")) {
165 }
else if (!strcasecmp(
a->argv[3],
"text")) {
174 ast_cli(
a->fd,
"%8u %-5s %-12s %-16s %7d (%s)\n",
200 int type_punned_codec;
205 e->
command =
"core show codec";
207 "Usage: core show codec <number>\n"
208 " Displays codec mapping\n";
218 if (sscanf(
a->argv[3],
"%30d", &type_punned_codec) != 1) {
224 ast_cli(
a->fd,
"Codec %d not found\n", type_punned_codec);
289 ast_log(
LOG_ERROR,
"A sample rate must be specified for codec '%s' of type '%s'\n",
297 ast_log(
LOG_ERROR,
"A codec with name '%s' of type '%s' and sample rate '%u' is already registered\n",
306 ast_log(
LOG_ERROR,
"Could not allocate a codec with name '%s' of type '%s' and sample rate '%u'\n",
319 ast_verb(5,
"Registered '%s' codec '%s' at sample rate '%u' with id '%u'\n",
366 if (!strcasecmp(media_type_str,
"audio")) {
368 }
else if (!strcasecmp(media_type_str,
"video")) {
370 }
else if (!strcasecmp(media_type_str,
"image")) {
372 }
else if (!strcasecmp(media_type_str,
"text")) {
382 unsigned int samples = 0;
394 if ((
int) samples < 0) {
Asterisk main include file. File version handling, generic pbx functions.
int ast_register_cleanup(void(*func)(void))
Register a function to be executed before Asterisk gracefully exits.
#define ao2_iterator_next(iter)
@ AO2_ALLOC_OPT_LOCK_NOLOCK
@ AO2_ALLOC_OPT_LOCK_RWLOCK
#define ao2_callback(c, flags, cb_fn, arg)
ao2_callback() is a generic function that applies cb_fn() to all objects in a container,...
@ AO2_ITERATOR_DONTLOCK
Assume that the ao2_container is already locked.
#define ao2_link_flags(container, obj, flags)
Add an object to a container.
#define ao2_t_alloc_options(data_size, destructor_fn, options, debug_msg)
Allocate and initialize an object.
#define ao2_find(container, arg, flags)
struct ao2_iterator ao2_iterator_init(struct ao2_container *c, int flags) attribute_warn_unused_result
Create an iterator for a container.
#define ao2_ref(o, delta)
Reference/unreference an object and return the old refcount.
#define AO2_STRING_FIELD_HASH_FN(stype, field)
Creates a hash function for a structure string field.
void ao2_iterator_destroy(struct ao2_iterator *iter)
Destroy a container iterator.
@ OBJ_SEARCH_PARTIAL_KEY
The arg parameter is a partial search key similar to OBJ_SEARCH_KEY.
@ OBJ_SEARCH_OBJECT
The arg parameter is an object of the same type.
@ OBJ_NOLOCK
Assume that the ao2_container is already locked.
@ OBJ_SEARCH_MASK
Search option field mask.
@ OBJ_SEARCH_KEY
The arg parameter is a search key, but is not an object.
#define ao2_container_alloc_hash(ao2_options, container_options, n_buckets, hash_fn, sort_fn, cmp_fn)
Allocate and initialize a hash container with the desired number of buckets.
Standard Command Line Interface.
int ast_cli_unregister_multiple(struct ast_cli_entry *e, int len)
Unregister multiple commands.
#define AST_CLI_DEFINE(fn, txt,...)
void ast_cli(int fd, const char *fmt,...)
#define ast_cli_register_multiple(e, len)
Register multiple commands.
static void codec_shutdown(void)
Function called when the process is shutting down.
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.
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 ...
static int codec_id_cmp(void *obj, void *arg, int flags)
Callback function for getting a codec based on unique identifier.
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.
static int codec_id
Current identifier value for newly registered codec.
static struct ao2_container * codecs
Registered codecs.
static char * show_codec(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
int ast_codec_init(void)
Initialize codec support within the core.
int __ast_codec_register_with_format(struct ast_codec *codec, const char *format_name, struct ast_module *mod)
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.
#define CODEC_BUCKETS
Number of buckets to use for codecs (should be prime for performance reasons)
unsigned int ast_codec_samples_count(struct ast_frame *frame)
Get the number of samples contained within a frame.
struct ast_codec * ast_codec_get_by_id(int id)
Retrieve a codec given the unique identifier.
const char * ast_codec_media_type2str(enum ast_media_type type)
Conversion function to take a media type and turn it into a string.
static char * show_codecs(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
static int codec_cmp(void *obj, void *arg, int flags)
static void codec_dtor(void *obj)
int ast_codec_get_max(void)
Retrieve the current maximum identifier for codec iteration.
static struct ast_cli_entry codec_cli[]
ast_media_type
Types of media.
Asterisk internal frame definitions.
Support for logging to various files, console and syslog Configuration in file logger....
#define ast_verb(level,...)
#define SCOPED_AO2WRLOCK(varname, obj)
scoped lock specialization for ao2 write locks.
Asterisk module definitions.
#define ast_module_unref(mod)
Release a reference to the module.
#define ast_module_shutdown_ref(mod)
Prevent unload of the module before shutdown.
#define ast_opt_dont_warn
String manipulation functions.
#define S_OR(a, b)
returns the equivalent of logic or for strings: first one if not empty, otherwise second one.
When we need to walk through a container, we use an ao2_iterator to keep track of the current positio...
descriptor for a cli entry.
Represents a media codec within Asterisk.
unsigned int sample_rate
Sample rate (number of samples carried in a second)
int(* samples_count)(struct ast_frame *frame)
Retrieve the number of samples in a frame.
enum ast_media_type type
Type of media this codec contains.
int(* get_length)(unsigned int samples)
Retrieve the length of media from number of samples.
const char * description
Brief description.
unsigned int quality
Format quality, on scale from 0 to 150 (100 is ulaw, the reference). This allows better format to be ...
struct ast_module * mod
The module that registered this codec.
const char * name
Name for this codec.
unsigned int id
Internal unique identifier for this codec, set at registration time (starts at 1)
struct ast_format * format
Data structure associated with a single frame of data.
struct ast_frame_subclass subclass
enum ast_frame_type frametype
const char * format_name
A format name for a default sane format using this codec.
struct ast_codec external
Public codec structure. Must remain first.