Asterisk - The Open Source Telephony Project  18.5.0
Functions
channels/iax2/include/format_compatibility.h File Reference

Media Format Bitfield Compatibility API. More...

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

uint64_t iax2_format_compatibility_best (uint64_t formats)
 Pick the best format from the given bitfield formats. More...
 
int iax2_format_compatibility_bitfield2cap (uint64_t bitfield, struct ast_format_cap *cap)
 Convert a bitfield to a format capabilities structure. More...
 
uint64_t iax2_format_compatibility_cap2bitfield (const struct ast_format_cap *cap)
 Convert a format capabilities structure to a bitfield. More...
 

Detailed Description

Media Format Bitfield Compatibility API.

Author
Joshua Colp jcolp.nosp@m.@dig.nosp@m.ium.c.nosp@m.om

Definition in file channels/iax2/include/format_compatibility.h.

Function Documentation

◆ iax2_format_compatibility_best()

uint64_t iax2_format_compatibility_best ( uint64_t  formats)

Pick the best format from the given bitfield formats.

Parameters
formatsThe bitfield for the media formats
Return values
non-zeroBest format out of the given formats.
zeroNo formats present or no formats considered best.

Okay, ulaw is used by all telephony equipment, so start with it

Unless of course, you're a silly European, so then prefer ALAW

G.722 is better then all below, but not as common as the above... so give ulaw and alaw priority

Okay, well, signed linear is easy to translate into other stuff

G.726 is standard ADPCM, in RFC3551 packing order

G.726 is standard ADPCM, in AAL2 packing order

ADPCM has great sound quality and is still pretty easy to translate

Okay, we're down to vocoders now, so pick GSM because it's small and easier to translate and sounds pretty good

iLBC is not too bad

Speex is free, but computationally more expensive than GSM

Opus

Ick, LPC10 sounds terrible, but at least we have code for it, if you're tacky enough to use it

G.729a is faster than 723 and slightly less expensive

Down to G.723.1 which is proprietary but at least designed for voice

Definition at line 79 of file channels/iax2/format_compatibility.c.

References ARRAY_LEN, AST_FORMAT_ADPCM, AST_FORMAT_ALAW, AST_FORMAT_G719, AST_FORMAT_G722, AST_FORMAT_G723, AST_FORMAT_G726, AST_FORMAT_G726_AAL2, AST_FORMAT_G729, AST_FORMAT_GSM, AST_FORMAT_ILBC, AST_FORMAT_LPC10, AST_FORMAT_OPUS, AST_FORMAT_SIREN14, AST_FORMAT_SIREN7, AST_FORMAT_SLIN, AST_FORMAT_SLIN16, AST_FORMAT_SPEEX, AST_FORMAT_SPEEX16, AST_FORMAT_TESTLAW, and AST_FORMAT_ULAW.

Referenced by iax2_codec_pref_best_bitfield2cap(), iax2_codec_pref_from_bitfield(), and socket_process_helper().

80 {
81  /*
82  * This just our opinion, expressed in code. We are
83  * asked to choose the best codec to use, given no
84  * information.
85  */
86  static const uint64_t best[] = {
87  /*! Okay, ulaw is used by all telephony equipment, so start with it */
89  /*! Unless of course, you're a silly European, so then prefer ALAW */
95  /*! G.722 is better then all below, but not as common as the above... so give ulaw and alaw priority */
97  /*! Okay, well, signed linear is easy to translate into other stuff */
100  /*! G.726 is standard ADPCM, in RFC3551 packing order */
102  /*! G.726 is standard ADPCM, in AAL2 packing order */
104  /*! ADPCM has great sound quality and is still pretty easy to translate */
106  /*! Okay, we're down to vocoders now, so pick GSM because it's small and easier to
107  translate and sounds pretty good */
109  /*! iLBC is not too bad */
111  /*! Speex is free, but computationally more expensive than GSM */
114  /*! Opus */
116  /*! Ick, LPC10 sounds terrible, but at least we have code for it, if you're tacky enough
117  to use it */
119  /*! G.729a is faster than 723 and slightly less expensive */
121  /*! Down to G.723.1 which is proprietary but at least designed for voice */
123  };
124  int idx;
125 
126  /* Find the first preferred codec in the format given */
127  for (idx = 0; idx < ARRAY_LEN(best); ++idx) {
128  if (formats & best[idx]) {
129  return best[idx];
130  }
131  }
132 
133  return 0;
134 }
#define ARRAY_LEN(a)
Definition: isdn_lib.c:42
Definition: file.c:69

◆ iax2_format_compatibility_bitfield2cap()

int iax2_format_compatibility_bitfield2cap ( uint64_t  bitfield,
struct ast_format_cap cap 
)

Convert a bitfield to a format capabilities structure.

Parameters
bitfieldThe bitfield for the media formats
capCapabilities structure to place formats into
Return values
0on success.
-1on error.
Note
If failure occurs the capabilities structure may contain a partial set of formats

Definition at line 59 of file channels/iax2/format_compatibility.c.

References ast_format_cap_append, ast_format_compatibility_bitfield2format(), and format.

Referenced by iax2_codec_choose(), and iax2_getformatname_multiple().

60 {
61  int bit;
62 
63  for (bit = 0; bit < 64; ++bit) {
64  uint64_t mask = (1ULL << bit);
65 
66  if (mask & bitfield) {
67  struct ast_format *format;
68 
70  if (format && ast_format_cap_append(cap, format, 0)) {
71  return -1;
72  }
73  }
74  }
75 
76  return 0;
77 }
struct ast_format * ast_format_compatibility_bitfield2format(uint64_t bitfield)
Convert a bitfield to its respective format structure.
Definition of a media format.
Definition: format.c:43
#define ast_format_cap_append(cap, format, framing)
Definition: format_cap.h:103
static snd_pcm_format_t format
Definition: chan_alsa.c:102

◆ iax2_format_compatibility_cap2bitfield()

uint64_t iax2_format_compatibility_cap2bitfield ( const struct ast_format_cap cap)

Convert a format capabilities structure to a bitfield.

Parameters
capCapabilities structure containing formats
Return values
non-zerosuccess
zerono formats present or no formats supported

Definition at line 43 of file channels/iax2/format_compatibility.c.

References ao2_ref, ast_format_cap_count(), ast_format_cap_get_format(), ast_format_compatibility_format2bitfield(), and format.

Referenced by iax2_call(), iax2_parse_allow_disallow(), and socket_process_helper().

44 {
45  uint64_t bitfield = 0;
46  int x;
47 
48  for (x = 0; x < ast_format_cap_count(cap); x++) {
50 
51  bitfield |= ast_format_compatibility_format2bitfield(format);
52 
53  ao2_ref(format, -1);
54  }
55 
56  return bitfield;
57 }
uint64_t ast_format_compatibility_format2bitfield(const struct ast_format *format)
Convert a format structure to its respective bitfield.
Definition of a media format.
Definition: format.c:43
size_t ast_format_cap_count(const struct ast_format_cap *cap)
Get the number of formats present within the capabilities structure.
Definition: format_cap.c:395
#define ao2_ref(o, delta)
Definition: astobj2.h:464
struct ast_format * ast_format_cap_get_format(const struct ast_format_cap *cap, int position)
Get the format at a specific index.
Definition: format_cap.c:400
static snd_pcm_format_t format
Definition: chan_alsa.c:102