Asterisk - The Open Source Telephony Project  18.5.0
Macros | Functions | Variables
format_cache.c File Reference

Media Format Cache API. More...

#include "asterisk.h"
#include "asterisk/logger.h"
#include "asterisk/format.h"
#include "asterisk/format_cache.h"
#include "asterisk/astobj2.h"
#include "asterisk/strings.h"
Include dependency graph for format_cache.c:

Go to the source code of this file.

Macros

#define CACHE_BUCKETS   53
 Number of buckets to use for the media format cache (should be prime for performance reasons) More...
 

Functions

struct ast_format__ast_format_cache_get (const char *name, const char *tag, const char *file, int line, const char *func)
 Retrieve a named format from the cache. More...
 
struct ast_formatast_format_cache_get_by_codec (const struct ast_codec *codec)
 Retrieve a format from the cache by its codec. More...
 
struct ast_formatast_format_cache_get_slin_by_rate (unsigned int rate)
 Retrieve the best signed linear format given a sample rate. More...
 
int ast_format_cache_init (void)
 Initialize format cache support within the core. More...
 
int ast_format_cache_is_slinear (struct ast_format *format)
 Determines if a format is one of the cached slin formats. More...
 
int ast_format_cache_set (struct ast_format *format)
 Set a named format cache entry. More...
 
static void format_cache_shutdown (void)
 Function called when the process is shutting down. More...
 
static int format_cmp_cb (void *obj, void *arg, int flags)
 
static int format_hash_cb (const void *obj, int flags)
 
static void set_cached_format (const char *name, struct ast_format *format)
 

Variables

struct ast_formatast_format_adpcm
 Built-in cached adpcm format. More...
 
struct ast_formatast_format_alaw
 Built-in cached alaw format. More...
 
struct ast_formatast_format_codec2
 Built-in cached codec2 format. More...
 
struct ast_formatast_format_g719
 Built-in cached g719 format. More...
 
struct ast_formatast_format_g722
 Built-in cached g722 format. More...
 
struct ast_formatast_format_g723
 Built-in cached g723.1 format. More...
 
struct ast_formatast_format_g726
 Built-in cached g726 format. More...
 
struct ast_formatast_format_g726_aal2
 Built-in cached g726-aal2 format. More...
 
struct ast_formatast_format_g729
 Built-in cached g729 format. More...
 
struct ast_formatast_format_gsm
 Built-in cached gsm format. More...
 
struct ast_formatast_format_h261
 Built-in cached h261 format. More...
 
struct ast_formatast_format_h263
 Built-in cached h263 format. More...
 
struct ast_formatast_format_h263p
 Built-in cached h263 plus format. More...
 
struct ast_formatast_format_h264
 Built-in cached h264 format. More...
 
struct ast_formatast_format_h265
 Built-in cached h265 format. More...
 
struct ast_formatast_format_ilbc
 Built-in cached ilbc format. More...
 
struct ast_formatast_format_jpeg
 Built-in cached jpeg format. More...
 
struct ast_formatast_format_lpc10
 Built-in cached ilbc format. More...
 
struct ast_formatast_format_mp4
 Built-in cached mp4 format. More...
 
struct ast_formatast_format_none
 Built-in "null" format. More...
 
struct ast_formatast_format_opus
 Built-in cached opus format. More...
 
struct ast_formatast_format_png
 Built-in cached png format. More...
 
struct ast_formatast_format_silk12
 
struct ast_formatast_format_silk16
 
struct ast_formatast_format_silk24
 
struct ast_formatast_format_silk8
 Built-in "silk" format. More...
 
struct ast_formatast_format_siren14
 Built-in cached siren14 format. More...
 
struct ast_formatast_format_siren7
 Built-in cached siren7 format. More...
 
struct ast_formatast_format_slin
 Built-in cached signed linear 8kHz format. More...
 
struct ast_formatast_format_slin12
 Built-in cached signed linear 12kHz format. More...
 
struct ast_formatast_format_slin16
 Built-in cached signed linear 16kHz format. More...
 
struct ast_formatast_format_slin192
 Built-in cached signed linear 192kHz format. More...
 
struct ast_formatast_format_slin24
 Built-in cached signed linear 24kHz format. More...
 
struct ast_formatast_format_slin32
 Built-in cached signed linear 32kHz format. More...
 
struct ast_formatast_format_slin44
 Built-in cached signed linear 44kHz format. More...
 
struct ast_formatast_format_slin48
 Built-in cached signed linear 48kHz format. More...
 
struct ast_formatast_format_slin96
 Built-in cached signed linear 96kHz format. More...
 
struct ast_formatast_format_speex
 Built-in cached speex format. More...
 
struct ast_formatast_format_speex16
 Built-in cached speex at 16kHz format. More...
 
struct ast_formatast_format_speex32
 Built-in cached speex at 32kHz format. More...
 
struct ast_formatast_format_t140
 Built-in cached t140 format. More...
 
struct ast_formatast_format_t140_red
 Built-in cached t140 red format. More...
 
struct ast_formatast_format_t38
 Built-in cached T.38 format. More...
 
struct ast_formatast_format_testlaw
 Built-in cached testlaw format. More...
 
struct ast_formatast_format_ulaw
 Built-in cached ulaw format. More...
 
struct ast_formatast_format_vp8
 Built-in cached vp8 format. More...
 
struct ast_formatast_format_vp9
 Built-in cached vp9 format. More...
 
static struct ao2_containerformats
 Cached formats. More...
 

Detailed Description

Media Format Cache API.

Author
Joshua Colp jcolp[email protected]@dig[email protected]ium.c[email protected]om

Definition in file format_cache.c.

Macro Definition Documentation

◆ CACHE_BUCKETS

#define CACHE_BUCKETS   53

Number of buckets to use for the media format cache (should be prime for performance reasons)

Definition at line 262 of file format_cache.c.

Referenced by ast_format_cache_init().

Function Documentation

◆ __ast_format_cache_get()

struct ast_format* __ast_format_cache_get ( const char *  name,
const char *  tag,
const char *  file,
int  line,
const char *  func 
)

Retrieve a named format from the cache.

Parameters
nameName of the cached format
Return values
non-NULLif found
NULLif not found
Note
The returned format has its reference count incremented. It must be dropped using ao2_ref or ao2_cleanup.

Definition at line 510 of file format_cache.c.

References __ao2_find(), ast_strlen_zero, NULL, and OBJ_SEARCH_KEY.

512 {
513  if (ast_strlen_zero(name)) {
514  return NULL;
515  }
516 
517  return __ao2_find(formats, name, OBJ_SEARCH_KEY, tag, file, line, func);
518 }
void * __ao2_find(struct ao2_container *c, const void *arg, enum search_flags flags, const char *tag, const char *file, int line, const char *func)
The arg parameter is a search key, but is not an object.
Definition: astobj2.h:1105
#define NULL
Definition: resample.c:96
#define ast_strlen_zero(foo)
Definition: strings.h:52
Definition: file.c:69
static const char name[]
Definition: cdr_mysql.c:74

◆ ast_format_cache_get_by_codec()

struct ast_format* ast_format_cache_get_by_codec ( const struct ast_codec codec)

Retrieve a format from the cache by its codec.

Parameters
codecThe codec to search by
Return values
non-NULLif found
NULLif not found
Note
The returned format has its reference count incremented. It must be dropped using ao2_ref or ao2_cleanup.

Definition at line 559 of file format_cache.c.

References ao2_cleanup, ao2_iterator_destroy(), ao2_iterator_init(), ao2_iterator_next, ao2_ref, ast_format_get_codec(), format, and NULL.

Referenced by ast_format_cap_append_by_type().

560 {
561  struct ast_format *format;
562  struct ao2_iterator it;
563 
564  for (it = ao2_iterator_init(formats, 0);
565  (format = ao2_iterator_next(&it));
566  ao2_ref(format, -1)) {
567  struct ast_codec *candidate = ast_format_get_codec(format);
568  if (codec == candidate) {
569  ao2_cleanup(candidate);
571  return format;
572  }
573  ao2_cleanup(candidate);
574  }
575 
577  return NULL;
578 }
struct ast_codec * ast_format_get_codec(const struct ast_format *format)
Get the codec associated with a format.
Definition: format.c:324
Definition of a media format.
Definition: format.c:43
void ao2_iterator_destroy(struct ao2_iterator *iter)
Destroy a container iterator.
#define NULL
Definition: resample.c:96
#define ao2_ref(o, delta)
Definition: astobj2.h:464
Definition: file.c:69
#define ao2_iterator_next(iter)
Definition: astobj2.h:1933
When we need to walk through a container, we use an ao2_iterator to keep track of the current positio...
Definition: astobj2.h:1841
#define ao2_cleanup(obj)
Definition: astobj2.h:1958
static snd_pcm_format_t format
Definition: chan_alsa.c:102
Represents a media codec within Asterisk.
Definition: codec.h:42
struct ao2_iterator ao2_iterator_init(struct ao2_container *c, int flags) attribute_warn_unused_result
Create an iterator for a container.

◆ ast_format_cache_get_slin_by_rate()

struct ast_format* ast_format_cache_get_slin_by_rate ( unsigned int  rate)

Retrieve the best signed linear format given a sample rate.

Parameters
rateThe sample rate

This is a convenience function that returns one of the global ast_format_slinxxx formats.

Returns
pointer to the signed linear format
Note
The returned format has NOT had its reference count incremented.

Definition at line 520 of file format_cache.c.

References ast_format_slin, ast_format_slin12, ast_format_slin16, ast_format_slin192, ast_format_slin24, ast_format_slin32, ast_format_slin44, ast_format_slin48, and ast_format_slin96.

Referenced by ast_channel_make_compatible_helper(), audiohook_list_translate_to_slin(), audiohook_read_frame_both(), audiohook_read_frame_helper(), audiohook_read_frame_single(), audiohook_set_internal_rate(), generate_interpolated_slin(), init_jack_data(), mixmonitor_thread(), mp3_exec(), resamp_new(), set_softmix_bridge_data(), snoop_determine_format(), softmix_bridge_unsuspend(), softmix_mixing_loop(), softmix_translate_helper_change_rate(), and softmix_translate_helper_init().

521 {
522  if (rate >= 192000) {
523  return ast_format_slin192;
524  } else if (rate >= 96000) {
525  return ast_format_slin96;
526  } else if (rate >= 48000) {
527  return ast_format_slin48;
528  } else if (rate >= 44100) {
529  return ast_format_slin44;
530  } else if (rate >= 32000) {
531  return ast_format_slin32;
532  } else if (rate >= 24000) {
533  return ast_format_slin24;
534  } else if (rate >= 16000) {
535  return ast_format_slin16;
536  } else if (rate >= 12000) {
537  return ast_format_slin12;
538  }
539  return ast_format_slin;
540 }
struct ast_format * ast_format_slin192
Built-in cached signed linear 192kHz format.
Definition: format_cache.c:81
struct ast_format * ast_format_slin96
Built-in cached signed linear 96kHz format.
Definition: format_cache.c:76
struct ast_format * ast_format_slin32
Built-in cached signed linear 32kHz format.
Definition: format_cache.c:61
struct ast_format * ast_format_slin24
Built-in cached signed linear 24kHz format.
Definition: format_cache.c:56
struct ast_format * ast_format_slin48
Built-in cached signed linear 48kHz format.
Definition: format_cache.c:71
struct ast_format * ast_format_slin16
Built-in cached signed linear 16kHz format.
Definition: format_cache.c:51
struct ast_format * ast_format_slin
Built-in cached signed linear 8kHz format.
Definition: format_cache.c:41
struct ast_format * ast_format_slin44
Built-in cached signed linear 44kHz format.
Definition: format_cache.c:66
struct ast_format * ast_format_slin12
Built-in cached signed linear 12kHz format.
Definition: format_cache.c:46

◆ ast_format_cache_init()

int ast_format_cache_init ( void  )

Initialize format cache support within the core.

Return values
0success
-1failure

Definition at line 370 of file format_cache.c.

References AO2_ALLOC_OPT_LOCK_RWLOCK, ao2_container_alloc_hash, ast_register_cleanup(), CACHE_BUCKETS, format_cache_shutdown(), format_cmp_cb(), format_hash_cb(), and NULL.

Referenced by asterisk_daemon().

371 {
374  if (!formats) {
375  return -1;
376  }
377 
379 
380  return 0;
381 }
static void format_cache_shutdown(void)
Function called when the process is shutting down.
Definition: format_cache.c:316
#define NULL
Definition: resample.c:96
#define CACHE_BUCKETS
Number of buckets to use for the media format cache (should be prime for performance reasons) ...
Definition: format_cache.c:262
int ast_register_cleanup(void(*func)(void))
Register a function to be executed before Asterisk gracefully exits.
Definition: clicompat.c:19
#define ao2_container_alloc_hash(ao2_options, container_options, n_buckets, hash_fn, sort_fn, cmp_fn)
Definition: astobj2.h:1310
Definition: file.c:69
static int format_cmp_cb(void *obj, void *arg, int flags)
Definition: format_cache.c:286
static int format_hash_cb(const void *obj, int flags)
Definition: format_cache.c:267

◆ ast_format_cache_is_slinear()

int ast_format_cache_is_slinear ( struct ast_format format)

Determines if a format is one of the cached slin formats.

Parameters
formatThe format to check
Return values
0if the format is not an SLIN format
1if the format is an SLIN format

Definition at line 542 of file format_cache.c.

References ast_format_cmp(), and AST_FORMAT_CMP_EQUAL.

Referenced by __ast_read(), ast_channel_make_compatible_helper(), ast_dsp_call_progress(), ast_dsp_process(), ast_dsp_silence_noise_with_energy(), ast_frame_adjust_volume(), ast_frame_adjust_volume_float(), ast_rtp_interpret(), ast_slinfactory_init_with_format(), and ast_write_stream().

543 {
553  return 1;
554  }
555 
556  return 0;
557 }
struct ast_format * ast_format_slin192
Built-in cached signed linear 192kHz format.
Definition: format_cache.c:81
struct ast_format * ast_format_slin96
Built-in cached signed linear 96kHz format.
Definition: format_cache.c:76
struct ast_format * ast_format_slin32
Built-in cached signed linear 32kHz format.
Definition: format_cache.c:61
enum ast_format_cmp_res ast_format_cmp(const struct ast_format *format1, const struct ast_format *format2)
Compare two formats.
Definition: format.c:201
struct ast_format * ast_format_slin24
Built-in cached signed linear 24kHz format.
Definition: format_cache.c:56
struct ast_format * ast_format_slin48
Built-in cached signed linear 48kHz format.
Definition: format_cache.c:71
struct ast_format * ast_format_slin16
Built-in cached signed linear 16kHz format.
Definition: format_cache.c:51
struct ast_format * ast_format_slin
Built-in cached signed linear 8kHz format.
Definition: format_cache.c:41
struct ast_format * ast_format_slin44
Built-in cached signed linear 44kHz format.
Definition: format_cache.c:66
struct ast_format * ast_format_slin12
Built-in cached signed linear 12kHz format.
Definition: format_cache.c:46

◆ ast_format_cache_set()

int ast_format_cache_set ( struct ast_format format)

Set a named format cache entry.

Parameters
formatA pointer to the format to cache
Return values
0success
-1failure

Definition at line 482 of file format_cache.c.

References ao2_cleanup, ao2_find, ao2_link_flags, ao2_unlink_flags, ast_assert, ast_format_get_name(), ast_strlen_zero, ast_verb, lock, NULL, OBJ_NOLOCK, OBJ_SEARCH_KEY, SCOPED_AO2WRLOCK, and set_cached_format().

Referenced by AST_TEST_DEFINE().

483 {
485  struct ast_format *old_format;
486 
487  ast_assert(format != NULL);
488 
489  if (ast_strlen_zero(ast_format_get_name(format))) {
490  return -1;
491  }
492 
494  if (old_format) {
495  ao2_unlink_flags(formats, old_format, OBJ_NOLOCK);
496  }
498 
499  set_cached_format(ast_format_get_name(format), format);
500 
501  ast_verb(2, "%s cached format with name '%s'\n",
502  old_format ? "Updated" : "Created",
503  ast_format_get_name(format));
504 
505  ao2_cleanup(old_format);
506 
507  return 0;
508 }
The arg parameter is a search key, but is not an object.
Definition: astobj2.h:1105
Assume that the ao2_container is already locked.
Definition: astobj2.h:1067
Definition of a media format.
Definition: format.c:43
#define ast_assert(a)
Definition: utils.h:695
#define ao2_link_flags(container, obj, flags)
Definition: astobj2.h:1572
const char * ast_format_get_name(const struct ast_format *format)
Get the name associated with a format.
Definition: format.c:334
#define NULL
Definition: resample.c:96
#define ast_verb(level,...)
Definition: logger.h:463
#define SCOPED_AO2WRLOCK(varname, obj)
scoped lock specialization for ao2 write locks.
Definition: lock.h:612
#define ast_strlen_zero(foo)
Definition: strings.h:52
ast_mutex_t lock
Definition: app_meetme.c:1091
static void set_cached_format(const char *name, struct ast_format *format)
Definition: format_cache.c:383
Definition: file.c:69
#define ao2_find(container, arg, flags)
Definition: astobj2.h:1756
#define ao2_cleanup(obj)
Definition: astobj2.h:1958
#define ao2_unlink_flags(container, obj, flags)
Definition: astobj2.h:1622

◆ format_cache_shutdown()

static void format_cache_shutdown ( void  )
static

Function called when the process is shutting down.

Definition at line 316 of file format_cache.c.

References ao2_cleanup, ao2_replace, and NULL.

Referenced by ast_format_cache_init().

317 {
319  formats = NULL;
320 
368 }
struct ast_format * ast_format_slin192
Built-in cached signed linear 192kHz format.
Definition: format_cache.c:81
struct ast_format * ast_format_ulaw
Built-in cached ulaw format.
Definition: format_cache.c:86
struct ast_format * ast_format_ilbc
Built-in cached ilbc format.
Definition: format_cache.c:126
struct ast_format * ast_format_mp4
Built-in cached mp4 format.
Definition: format_cache.c:191
struct ast_format * ast_format_t140
Built-in cached t140 format.
Definition: format_cache.c:236
struct ast_format * ast_format_g722
Built-in cached g722 format.
Definition: format_cache.c:111
struct ast_format * ast_format_h265
Built-in cached h265 format.
Definition: format_cache.c:186
struct ast_format * ast_format_slin96
Built-in cached signed linear 96kHz format.
Definition: format_cache.c:76
struct ast_format * ast_format_t140_red
Built-in cached t140 red format.
Definition: format_cache.c:241
struct ast_format * ast_format_h261
Built-in cached h261 format.
Definition: format_cache.c:166
struct ast_format * ast_format_vp9
Built-in cached vp9 format.
Definition: format_cache.c:201
struct ast_format * ast_format_jpeg
Built-in cached jpeg format.
Definition: format_cache.c:206
struct ast_format * ast_format_slin32
Built-in cached signed linear 32kHz format.
Definition: format_cache.c:61
struct ast_format * ast_format_none
Built-in "null" format.
Definition: format_cache.c:251
struct ast_format * ast_format_g729
Built-in cached g729 format.
Definition: format_cache.c:156
#define NULL
Definition: resample.c:96
struct ast_format * ast_format_opus
Built-in cached opus format.
Definition: format_cache.c:226
struct ast_format * ast_format_h263
Built-in cached h263 format.
Definition: format_cache.c:171
struct ast_format * ast_format_gsm
Built-in cached gsm format.
Definition: format_cache.c:101
struct ast_format * ast_format_h263p
Built-in cached h263 plus format.
Definition: format_cache.c:176
struct ast_format * ast_format_adpcm
Built-in cached adpcm format.
Definition: format_cache.c:106
struct ast_format * ast_format_testlaw
Built-in cached testlaw format.
Definition: format_cache.c:96
struct ast_format * ast_format_siren14
Built-in cached siren14 format.
Definition: format_cache.c:216
struct ast_format * ast_format_h264
Built-in cached h264 format.
Definition: format_cache.c:181
struct ast_format * ast_format_silk12
Definition: format_cache.c:257
struct ast_format * ast_format_silk8
Built-in "silk" format.
Definition: format_cache.c:256
Definition: file.c:69
struct ast_format * ast_format_speex16
Built-in cached speex at 16kHz format.
Definition: format_cache.c:141
struct ast_format * ast_format_png
Built-in cached png format.
Definition: format_cache.c:211
struct ast_format * ast_format_slin24
Built-in cached signed linear 24kHz format.
Definition: format_cache.c:56
struct ast_format * ast_format_slin48
Built-in cached signed linear 48kHz format.
Definition: format_cache.c:71
struct ast_format * ast_format_alaw
Built-in cached alaw format.
Definition: format_cache.c:91
struct ast_format * ast_format_speex32
Built-in cached speex at 32kHz format.
Definition: format_cache.c:146
#define ao2_replace(dst, src)
Definition: astobj2.h:517
struct ast_format * ast_format_lpc10
Built-in cached ilbc format.
Definition: format_cache.c:131
#define ao2_cleanup(obj)
Definition: astobj2.h:1958
struct ast_format * ast_format_silk16
Definition: format_cache.c:258
struct ast_format * ast_format_t38
Built-in cached T.38 format.
Definition: format_cache.c:246
struct ast_format * ast_format_g726_aal2
Built-in cached g726-aal2 format.
Definition: format_cache.c:121
struct ast_format * ast_format_siren7
Built-in cached siren7 format.
Definition: format_cache.c:221
struct ast_format * ast_format_speex
Built-in cached speex format.
Definition: format_cache.c:136
struct ast_format * ast_format_slin16
Built-in cached signed linear 16kHz format.
Definition: format_cache.c:51
struct ast_format * ast_format_g723
Built-in cached g723.1 format.
Definition: format_cache.c:151
struct ast_format * ast_format_codec2
Built-in cached codec2 format.
Definition: format_cache.c:231
struct ast_format * ast_format_g719
Built-in cached g719 format.
Definition: format_cache.c:161
struct ast_format * ast_format_slin
Built-in cached signed linear 8kHz format.
Definition: format_cache.c:41
struct ast_format * ast_format_vp8
Built-in cached vp8 format.
Definition: format_cache.c:196
struct ast_format * ast_format_g726
Built-in cached g726 format.
Definition: format_cache.c:116
struct ast_format * ast_format_silk24
Definition: format_cache.c:259
struct ast_format * ast_format_slin44
Built-in cached signed linear 44kHz format.
Definition: format_cache.c:66
struct ast_format * ast_format_slin12
Built-in cached signed linear 12kHz format.
Definition: format_cache.c:46

◆ format_cmp_cb()

static int format_cmp_cb ( void *  obj,
void *  arg,
int  flags 
)
static

Definition at line 286 of file format_cache.c.

References ast_assert, ast_format_get_name(), CMP_MATCH, OBJ_SEARCH_KEY, OBJ_SEARCH_MASK, OBJ_SEARCH_OBJECT, and OBJ_SEARCH_PARTIAL_KEY.

Referenced by ast_format_cache_init().

287 {
288  const struct ast_format *left = obj;
289  const struct ast_format *right = arg;
290  const char *right_key = arg;
291  int cmp;
292 
293  switch (flags & OBJ_SEARCH_MASK) {
294  case OBJ_SEARCH_OBJECT:
295  right_key = ast_format_get_name(right);
296  /* Fall through */
297  case OBJ_SEARCH_KEY:
298  cmp = strcasecmp(ast_format_get_name(left), right_key);
299  break;
301  cmp = strncasecmp(ast_format_get_name(left), right_key, strlen(right_key));
302  break;
303  default:
304  ast_assert(0);
305  cmp = 0;
306  break;
307  }
308  if (cmp) {
309  return 0;
310  }
311 
312  return CMP_MATCH;
313 }
The arg parameter is a search key, but is not an object.
Definition: astobj2.h:1105
Definition of a media format.
Definition: format.c:43
#define ast_assert(a)
Definition: utils.h:695
const char * ast_format_get_name(const struct ast_format *format)
Get the name associated with a format.
Definition: format.c:334
The arg parameter is a partial search key similar to OBJ_SEARCH_KEY.
Definition: astobj2.h:1120
The arg parameter is an object of the same type.
Definition: astobj2.h:1091
Search option field mask.
Definition: astobj2.h:1076

◆ format_hash_cb()

static int format_hash_cb ( const void *  obj,
int  flags 
)
static

Definition at line 267 of file format_cache.c.

References ast_assert, ast_format_get_name(), ast_str_case_hash(), format, OBJ_SEARCH_KEY, OBJ_SEARCH_MASK, and OBJ_SEARCH_OBJECT.

Referenced by ast_format_cache_init().

268 {
269  const struct ast_format *format;
270  const char *key;
271 
272  switch (flags & OBJ_SEARCH_MASK) {
273  case OBJ_SEARCH_KEY:
274  key = obj;
275  return ast_str_case_hash(key);
276  case OBJ_SEARCH_OBJECT:
277  format = obj;
278  return ast_str_case_hash(ast_format_get_name(format));
279  default:
280  /* Hash can only work on something with a full key. */
281  ast_assert(0);
282  return 0;
283  }
284 }
The arg parameter is a search key, but is not an object.
Definition: astobj2.h:1105
Definition of a media format.
Definition: format.c:43
#define ast_assert(a)
Definition: utils.h:695
const char * ast_format_get_name(const struct ast_format *format)
Get the name associated with a format.
Definition: format.c:334
The arg parameter is an object of the same type.
Definition: astobj2.h:1091
Search option field mask.
Definition: astobj2.h:1076
static snd_pcm_format_t format
Definition: chan_alsa.c:102
static force_inline int attribute_pure ast_str_case_hash(const char *str)
Compute a hash value on a case-insensitive string.
Definition: strings.h:1250

◆ set_cached_format()

static void set_cached_format ( const char *  name,
struct ast_format format 
)
static

Definition at line 383 of file format_cache.c.

References ao2_replace.

Referenced by ast_format_cache_set().

384 {
385  if (!strcmp(name, "codec2")) {
387  } else if (!strcmp(name, "g723")) {
388  ao2_replace(ast_format_g723, format);
389  } else if (!strcmp(name, "ulaw")) {
390  ao2_replace(ast_format_ulaw, format);
391  } else if (!strcmp(name, "alaw")) {
392  ao2_replace(ast_format_alaw, format);
393  } else if (!strcmp(name, "gsm")) {
394  ao2_replace(ast_format_gsm, format);
395  } else if (!strcmp(name, "g726")) {
396  ao2_replace(ast_format_g726, format);
397  } else if (!strcmp(name, "g726aal2")) {
399  } else if (!strcmp(name, "adpcm")) {
400  ao2_replace(ast_format_adpcm, format);
401  } else if (!strcmp(name, "slin")) {
402  ao2_replace(ast_format_slin, format);
403  } else if (!strcmp(name, "slin12")) {
405  } else if (!strcmp(name, "slin16")) {
407  } else if (!strcmp(name, "slin24")) {
409  } else if (!strcmp(name, "slin32")) {
411  } else if (!strcmp(name, "slin44")) {
413  } else if (!strcmp(name, "slin48")) {
415  } else if (!strcmp(name, "slin96")) {
417  } else if (!strcmp(name, "slin192")) {
419  } else if (!strcmp(name, "lpc10")) {
420  ao2_replace(ast_format_lpc10, format);
421  } else if (!strcmp(name, "g729")) {
422  ao2_replace(ast_format_g729, format);
423  } else if (!strcmp(name, "speex")) {
424  ao2_replace(ast_format_speex, format);
425  } else if (!strcmp(name, "speex16")) {
427  } else if (!strcmp(name, "speex32")) {
429  } else if (!strcmp(name, "ilbc")) {
430  ao2_replace(ast_format_ilbc, format);
431  } else if (!strcmp(name, "g722")) {
432  ao2_replace(ast_format_g722, format);
433  } else if (!strcmp(name, "siren7")) {
435  } else if (!strcmp(name, "siren14")) {
437  } else if (!strcmp(name, "testlaw")) {
439  } else if (!strcmp(name, "g719")) {
440  ao2_replace(ast_format_g719, format);
441  } else if (!strcmp(name, "opus")) {
442  ao2_replace(ast_format_opus, format);
443  } else if (!strcmp(name, "jpeg")) {
444  ao2_replace(ast_format_jpeg, format);
445  } else if (!strcmp(name, "png")) {
446  ao2_replace(ast_format_png, format);
447  } else if (!strcmp(name, "h261")) {
448  ao2_replace(ast_format_h261, format);
449  } else if (!strcmp(name, "h263")) {
450  ao2_replace(ast_format_h263, format);
451  } else if (!strcmp(name, "h263p")) {
452  ao2_replace(ast_format_h263p, format);
453  } else if (!strcmp(name, "h264")) {
454  ao2_replace(ast_format_h264, format);
455  } else if (!strcmp(name, "h265")) {
456  ao2_replace(ast_format_h265, format);
457  } else if (!strcmp(name, "mpeg4")) {
458  ao2_replace(ast_format_mp4, format);
459  } else if (!strcmp(name, "vp8")) {
460  ao2_replace(ast_format_vp8, format);
461  } else if (!strcmp(name, "vp9")) {
462  ao2_replace(ast_format_vp9, format);
463  } else if (!strcmp(name, "red")) {
465  } else if (!strcmp(name, "t140")) {
466  ao2_replace(ast_format_t140, format);
467  } else if (!strcmp(name, "t38")) {
468  ao2_replace(ast_format_t38, format);
469  } else if (!strcmp(name, "none")) {
470  ao2_replace(ast_format_none, format);
471  } else if (!strcmp(name, "silk8")) {
472  ao2_replace(ast_format_silk8, format);
473  } else if (!strcmp(name, "silk12")) {
475  } else if (!strcmp(name, "silk16")) {
477  } else if (!strcmp(name, "silk24")) {
479  }
480 }
struct ast_format * ast_format_slin192
Built-in cached signed linear 192kHz format.
Definition: format_cache.c:81
struct ast_format * ast_format_ulaw
Built-in cached ulaw format.
Definition: format_cache.c:86
struct ast_format * ast_format_ilbc
Built-in cached ilbc format.
Definition: format_cache.c:126
struct ast_format * ast_format_mp4
Built-in cached mp4 format.
Definition: format_cache.c:191
struct ast_format * ast_format_t140
Built-in cached t140 format.
Definition: format_cache.c:236
struct ast_format * ast_format_g722
Built-in cached g722 format.
Definition: format_cache.c:111
struct ast_format * ast_format_h265
Built-in cached h265 format.
Definition: format_cache.c:186
struct ast_format * ast_format_slin96
Built-in cached signed linear 96kHz format.
Definition: format_cache.c:76
struct ast_format * ast_format_t140_red
Built-in cached t140 red format.
Definition: format_cache.c:241
struct ast_format * ast_format_h261
Built-in cached h261 format.
Definition: format_cache.c:166
struct ast_format * ast_format_vp9
Built-in cached vp9 format.
Definition: format_cache.c:201
struct ast_format * ast_format_jpeg
Built-in cached jpeg format.
Definition: format_cache.c:206
struct ast_format * ast_format_slin32
Built-in cached signed linear 32kHz format.
Definition: format_cache.c:61
struct ast_format * ast_format_none
Built-in "null" format.
Definition: format_cache.c:251
struct ast_format * ast_format_g729
Built-in cached g729 format.
Definition: format_cache.c:156
struct ast_format * ast_format_opus
Built-in cached opus format.
Definition: format_cache.c:226
struct ast_format * ast_format_h263
Built-in cached h263 format.
Definition: format_cache.c:171
struct ast_format * ast_format_gsm
Built-in cached gsm format.
Definition: format_cache.c:101
struct ast_format * ast_format_h263p
Built-in cached h263 plus format.
Definition: format_cache.c:176
struct ast_format * ast_format_adpcm
Built-in cached adpcm format.
Definition: format_cache.c:106
struct ast_format * ast_format_testlaw
Built-in cached testlaw format.
Definition: format_cache.c:96
struct ast_format * ast_format_siren14
Built-in cached siren14 format.
Definition: format_cache.c:216
struct ast_format * ast_format_h264
Built-in cached h264 format.
Definition: format_cache.c:181
struct ast_format * ast_format_silk12
Definition: format_cache.c:257
struct ast_format * ast_format_silk8
Built-in "silk" format.
Definition: format_cache.c:256
struct ast_format * ast_format_speex16
Built-in cached speex at 16kHz format.
Definition: format_cache.c:141
struct ast_format * ast_format_png
Built-in cached png format.
Definition: format_cache.c:211
static const char name[]
Definition: cdr_mysql.c:74
struct ast_format * ast_format_slin24
Built-in cached signed linear 24kHz format.
Definition: format_cache.c:56
struct ast_format * ast_format_slin48
Built-in cached signed linear 48kHz format.
Definition: format_cache.c:71
struct ast_format * ast_format_alaw
Built-in cached alaw format.
Definition: format_cache.c:91
struct ast_format * ast_format_speex32
Built-in cached speex at 32kHz format.
Definition: format_cache.c:146
#define ao2_replace(dst, src)
Definition: astobj2.h:517
struct ast_format * ast_format_lpc10
Built-in cached ilbc format.
Definition: format_cache.c:131
struct ast_format * ast_format_silk16
Definition: format_cache.c:258
struct ast_format * ast_format_t38
Built-in cached T.38 format.
Definition: format_cache.c:246
struct ast_format * ast_format_g726_aal2
Built-in cached g726-aal2 format.
Definition: format_cache.c:121
struct ast_format * ast_format_siren7
Built-in cached siren7 format.
Definition: format_cache.c:221
struct ast_format * ast_format_speex
Built-in cached speex format.
Definition: format_cache.c:136
struct ast_format * ast_format_slin16
Built-in cached signed linear 16kHz format.
Definition: format_cache.c:51
struct ast_format * ast_format_g723
Built-in cached g723.1 format.
Definition: format_cache.c:151
struct ast_format * ast_format_codec2
Built-in cached codec2 format.
Definition: format_cache.c:231
struct ast_format * ast_format_g719
Built-in cached g719 format.
Definition: format_cache.c:161
struct ast_format * ast_format_slin
Built-in cached signed linear 8kHz format.
Definition: format_cache.c:41
struct ast_format * ast_format_vp8
Built-in cached vp8 format.
Definition: format_cache.c:196
struct ast_format * ast_format_g726
Built-in cached g726 format.
Definition: format_cache.c:116
struct ast_format * ast_format_silk24
Definition: format_cache.c:259
struct ast_format * ast_format_slin44
Built-in cached signed linear 44kHz format.
Definition: format_cache.c:66
struct ast_format * ast_format_slin12
Built-in cached signed linear 12kHz format.
Definition: format_cache.c:46

Variable Documentation

◆ ast_format_adpcm

struct ast_format* ast_format_adpcm

◆ ast_format_alaw

struct ast_format* ast_format_alaw

◆ ast_format_codec2

struct ast_format* ast_format_codec2

Built-in cached codec2 format.

Built-in cached Codec 2 format.

Definition at line 231 of file format_cache.c.

Referenced by codec2_sample(), load_module(), and unload_module().

◆ ast_format_g719

struct ast_format* ast_format_g719

◆ ast_format_g722

struct ast_format* ast_format_g722

◆ ast_format_g723

struct ast_format* ast_format_g723

◆ ast_format_g726

struct ast_format* ast_format_g726

◆ ast_format_g726_aal2

struct ast_format* ast_format_g726_aal2

◆ ast_format_g729

struct ast_format* ast_format_g729

◆ ast_format_gsm

struct ast_format* ast_format_gsm

◆ ast_format_h261

struct ast_format* ast_format_h261

◆ ast_format_h263

struct ast_format* ast_format_h263

◆ ast_format_h263p

struct ast_format* ast_format_h263p

◆ ast_format_h264

struct ast_format* ast_format_h264

◆ ast_format_h265

struct ast_format* ast_format_h265

Built-in cached h265 format.

Definition at line 186 of file format_cache.c.

Referenced by ast_rtp_engine_init(), and chan_pjsip_indicate().

◆ ast_format_ilbc

struct ast_format* ast_format_ilbc

◆ ast_format_jpeg

struct ast_format* ast_format_jpeg

◆ ast_format_lpc10

struct ast_format* ast_format_lpc10

◆ ast_format_mp4

struct ast_format* ast_format_mp4

◆ ast_format_none

struct ast_format* ast_format_none

◆ ast_format_opus

struct ast_format* ast_format_opus

◆ ast_format_png

struct ast_format* ast_format_png

◆ ast_format_silk12

struct ast_format* ast_format_silk12

Definition at line 257 of file format_cache.c.

◆ ast_format_silk16

struct ast_format* ast_format_silk16

Definition at line 258 of file format_cache.c.

◆ ast_format_silk24

struct ast_format* ast_format_silk24

Definition at line 259 of file format_cache.c.

◆ ast_format_silk8

struct ast_format* ast_format_silk8

Built-in "silk" format.

Built-in SILK format.

Definition at line 256 of file format_cache.c.

◆ ast_format_siren14

struct ast_format* ast_format_siren14

◆ ast_format_siren7

struct ast_format* ast_format_siren7

◆ ast_format_slin

struct ast_format* ast_format_slin

Built-in cached signed linear 8kHz format.

Definition at line 41 of file format_cache.c.

Referenced by _moh_class_malloc(), action_originate(), alloc_playback_chan(), alsa_new(), alsa_read(), alsa_request(), announce_to_dial(), ast_audiosocket_receive_frame(), ast_channel_start_silence_generator(), ast_format_cache_get_slin_by_rate(), ast_format_compatibility_bitfield2format(), ast_format_compatibility_codec2bitfield(), ast_format_compatibility_format2bitfield(), ast_frame_slinear_sum(), ast_rtp_engine_init(), ast_slinfactory_init(), ast_speech_new(), ast_write_stream(), audiosocket_exec(), background_detect_exec(), build_conf(), chanspy_exec(), conf_run(), conf_start_record(), create_test_frame(), dahdi_format_to_cached(), dahdi_read(), dahdi_write(), dahdiscan_exec(), derive_format_from_cap(), dictate_exec(), do_notify(), do_waiting(), eagi_exec(), extenspy_exec(), fax_detect_framehook(), fax_gateway_framehook(), fax_generator_generate(), g722_sample(), generate_interpolated_slin(), generic_fax_exec(), generic_recall(), handle_participant_join(), handle_recordfile(), handle_speechcreate(), handle_speechrecognize(), holding_bridge_join(), iax_frame_wrap(), ices_exec(), isAnsweringMachine(), linear_alloc(), linear_generator(), load_module(), make_silence(), measurenoise(), meetme_menu_admin_extended(), moh_parse_options(), nbs_new(), nbs_request(), NBScat_exec(), new_outgoing(), ooh323_rtp_read(), orig_app(), orig_exten(), originate_exec(), oss_new(), oss_read(), oss_request(), participant_reaction_announcer_join(), phone_new(), phone_read(), phone_setup(), phone_write(), playtones_alloc(), playtones_generator(), prepare_bridge_media_channel(), prepare_bridge_moh_channel(), rec_request(), recalling_enter(), record_exec(), retransfer_enter(), send_waveform_to_channel(), set_read_to_slin(), silence_generator_generate(), slin8_sample(), sms_exec(), socket_process_helper(), spandsp_fax_gateway_process(), spandsp_fax_gw_t30_gen(), spandsp_fax_read(), spandsp_v21_detect(), spy_generate(), tonepair_alloc(), tonepair_generator(), and transmit_audio().

◆ ast_format_slin12

struct ast_format* ast_format_slin12

Built-in cached signed linear 12kHz format.

Definition at line 46 of file format_cache.c.

Referenced by ast_format_cache_get_slin_by_rate(), ast_rtp_engine_init(), and load_module().

◆ ast_format_slin16

struct ast_format* ast_format_slin16

◆ ast_format_slin192

struct ast_format* ast_format_slin192

Built-in cached signed linear 192kHz format.

Definition at line 81 of file format_cache.c.

Referenced by ast_format_cache_get_slin_by_rate(), ast_rtp_engine_init(), and load_module().

◆ ast_format_slin24

struct ast_format* ast_format_slin24

Built-in cached signed linear 24kHz format.

Definition at line 56 of file format_cache.c.

Referenced by ast_format_cache_get_slin_by_rate(), ast_rtp_engine_init(), and load_module().

◆ ast_format_slin32

struct ast_format* ast_format_slin32

Built-in cached signed linear 32kHz format.

Definition at line 61 of file format_cache.c.

Referenced by ast_format_cache_get_slin_by_rate(), ast_rtp_engine_init(), and load_module().

◆ ast_format_slin44

struct ast_format* ast_format_slin44

Built-in cached signed linear 44kHz format.

Definition at line 66 of file format_cache.c.

Referenced by ast_format_cache_get_slin_by_rate(), ast_rtp_engine_init(), and load_module().

◆ ast_format_slin48

struct ast_format* ast_format_slin48

Built-in cached signed linear 48kHz format.

Definition at line 71 of file format_cache.c.

Referenced by ast_format_cache_get_slin_by_rate(), ast_rtp_engine_init(), and load_module().

◆ ast_format_slin96

struct ast_format* ast_format_slin96

Built-in cached signed linear 96kHz format.

Definition at line 76 of file format_cache.c.

Referenced by ast_format_cache_get_slin_by_rate(), ast_rtp_engine_init(), and load_module().

◆ ast_format_speex

struct ast_format* ast_format_speex

◆ ast_format_speex16

struct ast_format* ast_format_speex16

◆ ast_format_speex32

struct ast_format* ast_format_speex32

Built-in cached speex at 32kHz format.

Definition at line 146 of file format_cache.c.

Referenced by ast_rtp_engine_init(), and load_module().

◆ ast_format_t140

struct ast_format* ast_format_t140

◆ ast_format_t140_red

struct ast_format* ast_format_t140_red

◆ ast_format_t38

struct ast_format* ast_format_t38

Built-in cached T.38 format.

Definition at line 246 of file format_cache.c.

Referenced by t38_create_media_state().

◆ ast_format_testlaw

struct ast_format* ast_format_testlaw

◆ ast_format_ulaw

struct ast_format* ast_format_ulaw

◆ ast_format_vp8

struct ast_format* ast_format_vp8

◆ ast_format_vp9

struct ast_format* ast_format_vp9

Built-in cached vp9 format.

Definition at line 201 of file format_cache.c.

Referenced by ast_rtp_engine_init(), and chan_pjsip_indicate().

◆ formats

struct ao2_container* formats
static

Cached formats.

Definition at line 265 of file format_cache.c.