42 #define CODEC_BUCKETS 53
73 int __ast_codec_register_with_format(
struct ast_codec *codec,
const char *format_name,
78 static
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);
90 if (right->
type != AST_MEDIA_TYPE_UNKNOWN) {
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)) {
137 return CLI_SHOWUSAGE;
140 if (!ast_opt_dont_warn) {
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");
151 for (; (codec = ao2_iterator_next(&i));
ao2_ref(codec, -1)) {
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";
215 return CLI_SHOWUSAGE;
218 if (sscanf(a->argv[3],
"%30d", &type_punned_codec) != 1) {
219 return CLI_SHOWUSAGE;
224 ast_cli(a->fd,
"Codec %d not found\n", type_punned_codec);
238 AST_CLI_DEFINE(show_codecs,
"Displays a list of registered codecs"),
239 AST_CLI_DEFINE(show_codec,
"Shows a specific codec"),
253 ast_codec_hash_fn, NULL, codec_cmp);
264 static void codec_dtor(
void *obj)
275 return __ast_codec_register_with_format(codec, NULL, mod);
278 int __ast_codec_register_with_format(
struct ast_codec *codec,
const char *format_name,
struct ast_module *
mod)
284 if (codec->
type == AST_MEDIA_TYPE_UNKNOWN) {
285 ast_log(LOG_ERROR,
"A media type must be specified for codec '%s'\n", codec->
name);
287 }
else if (codec->
type == AST_MEDIA_TYPE_AUDIO) {
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",
351 case AST_MEDIA_TYPE_AUDIO:
353 case AST_MEDIA_TYPE_VIDEO:
355 case AST_MEDIA_TYPE_IMAGE:
357 case AST_MEDIA_TYPE_TEXT:
366 if (!strcasecmp(media_type_str,
"audio")) {
367 return AST_MEDIA_TYPE_AUDIO;
368 }
else if (!strcasecmp(media_type_str,
"video")) {
369 return AST_MEDIA_TYPE_VIDEO;
370 }
else if (!strcasecmp(media_type_str,
"image")) {
371 return AST_MEDIA_TYPE_IMAGE;
372 }
else if (!strcasecmp(media_type_str,
"text")) {
373 return AST_MEDIA_TYPE_TEXT;
375 return AST_MEDIA_TYPE_UNKNOWN;
382 unsigned int samples = 0;
394 if ((
int) samples < 0) {
395 ast_log(LOG_WARNING,
"Codec %s returned invalid number of samples.\n",
400 ast_log(LOG_WARNING,
"Unable to calculate samples for codec %s\n",
const char * name
Name for this codec.
Asterisk main include file. File version handling, generic pbx functions.
AO2_STRING_FIELD_HASH_FN(transport_monitor, key)
Hashing function for struct transport_monitor.
const char * ast_codec_media_type2str(enum ast_media_type type)
Conversion function to take a media type and turn it into a string.
String manipulation functions.
int ast_cli_unregister_multiple(struct ast_cli_entry *e, int len)
Unregister multiple commands.
The arg parameter is a search key, but is not an object.
unsigned int id
Internal unique identifier for this codec, set at registration time (starts at 1) ...
descriptor for a cli entry.
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.
#define ao2_callback(c, flags, cb_fn, arg)
ao2_callback() is a generic function that applies cb_fn() to all objects in a container, as described below.
struct ast_codec external
Public codec structure. Must remain first.
Assume that the ao2_container is already locked.
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 ...
#define ast_cli_register_multiple(e, len)
Register multiple commands.
void ao2_iterator_destroy(struct ao2_iterator *iter)
Destroy a container iterator.
#define ao2_link_flags(container, obj, flags)
Add an object to a container.
struct ast_codec * ast_codec_get_by_id(int id)
Retrieve a codec given the unique identifier.
#define ao2_t_alloc_options(data_size, destructor_fn, options, debug_msg)
Allocate and initialize an object.
struct ast_module * mod
The module that registered this codec.
#define SCOPED_AO2WRLOCK(varname, obj)
scoped lock specialization for ao2 write locks.
struct ast_frame_subclass subclass
unsigned int ast_codec_samples_count(struct ast_frame *frame)
Get the number of samples contained within a frame.
static int codec_id_cmp(void *obj, void *arg, int flags)
Callback function for getting a codec based on unique identifier.
The arg parameter is a partial search key similar to OBJ_SEARCH_KEY.
int ast_register_cleanup(void(*func)(void))
Register a function to be executed before Asterisk gracefully exits.
static struct ao2_container * codecs
Registered codecs.
#define ao2_ref(o, delta)
Reference/unreference an object and return the old refcount.
Asterisk internal frame definitions.
unsigned int quality
Format quality, on scale from 0 to 150 (100 is ulaw, the reference). This allows better format to be ...
int ast_codec_get_max(void)
Retrieve the current maximum identifier for codec iteration.
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_init(void)
Initialize codec support within the core.
#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.
const char * description
Brief description.
static void codec_shutdown(void)
Function called when the process is shutting down.
#define ast_module_shutdown_ref(mod)
Prevent unload of the module before shutdown.
int(* get_length)(unsigned int samples)
Retrieve the length of media from number of samples.
static int codec_id
Current identifier value for newly registered codec.
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.
Support for logging to various files, console and syslog Configuration in file logger.conf.
const char * format_name
A format name for a default sane format using this codec.
unsigned int sample_rate
Sample rate (number of samples carried in a second)
#define ast_module_unref(mod)
Release a reference to the module.
#define CODEC_BUCKETS
Number of buckets to use for codecs (should be prime for performance reasons)
Assume that the ao2_container is already locked.
The arg parameter is an object of the same type.
When we need to walk through a container, we use an ao2_iterator to keep track of the current positio...
Standard Command Line Interface.
#define S_OR(a, b)
returns the equivalent of logic or for strings: first one if not empty, otherwise second one...
int(* samples_count)(struct ast_frame *frame)
Retrieve the number of samples in a frame.
Data structure associated with a single frame of data.
enum ast_media_type type
Type of media this codec contains.
ast_media_type
Types of media.
enum ast_frame_type frametype
Search option field mask.
struct ast_format * format
Asterisk module definitions.
Represents a media codec within Asterisk.
struct ao2_iterator ao2_iterator_init(struct ao2_container *c, int flags) attribute_warn_unused_result
Create an iterator for a container.