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.
int iax2_format_compatibility_bitfield2cap (uint64_t bitfield, struct ast_format_cap *cap)
 Convert a bitfield to a format capabilities structure.
uint64_t iax2_format_compatibility_cap2bitfield (const struct ast_format_cap *cap)
 Convert a format capabilities structure to a bitfield.


Detailed Description

Media Format Bitfield Compatibility API.

Author:
Joshua Colp <jcolp@digium.com>

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


Function Documentation

uint64_t iax2_format_compatibility_best ( uint64_t  formats  ) 

Pick the best format from the given bitfield formats.

Parameters:
formats The bitfield for the media formats
Return values:
non-zero Best format out of the given formats.
zero No 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 81 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().

00082 {
00083    /*
00084     * This just our opinion, expressed in code.  We are
00085     * asked to choose the best codec to use, given no
00086     * information.
00087     */
00088    static const uint64_t best[] = {
00089       /*! Okay, ulaw is used by all telephony equipment, so start with it */
00090       AST_FORMAT_ULAW,
00091       /*! Unless of course, you're a silly European, so then prefer ALAW */
00092       AST_FORMAT_ALAW,
00093       AST_FORMAT_G719,
00094       AST_FORMAT_SIREN14,
00095       AST_FORMAT_SIREN7,
00096       AST_FORMAT_TESTLAW,
00097       /*! G.722 is better then all below, but not as common as the above... so give ulaw and alaw priority */
00098       AST_FORMAT_G722,
00099       /*! Okay, well, signed linear is easy to translate into other stuff */
00100       AST_FORMAT_SLIN16,
00101       AST_FORMAT_SLIN,
00102       /*! G.726 is standard ADPCM, in RFC3551 packing order */
00103       AST_FORMAT_G726,
00104       /*! G.726 is standard ADPCM, in AAL2 packing order */
00105       AST_FORMAT_G726_AAL2,
00106       /*! ADPCM has great sound quality and is still pretty easy to translate */
00107       AST_FORMAT_ADPCM,
00108       /*! Okay, we're down to vocoders now, so pick GSM because it's small and easier to
00109           translate and sounds pretty good */
00110       AST_FORMAT_GSM,
00111       /*! iLBC is not too bad */
00112       AST_FORMAT_ILBC,
00113       /*! Speex is free, but computationally more expensive than GSM */
00114       AST_FORMAT_SPEEX16,
00115       AST_FORMAT_SPEEX,
00116       /*! Opus */
00117       AST_FORMAT_OPUS,
00118       /*! Ick, LPC10 sounds terrible, but at least we have code for it, if you're tacky enough
00119           to use it */
00120       AST_FORMAT_LPC10,
00121       /*! G.729a is faster than 723 and slightly less expensive */
00122       AST_FORMAT_G729,
00123       /*! Down to G.723.1 which is proprietary but at least designed for voice */
00124       AST_FORMAT_G723,
00125    };
00126    int idx;
00127 
00128    /* Find the first preferred codec in the format given */
00129    for (idx = 0; idx < ARRAY_LEN(best); ++idx) {
00130       if (formats & best[idx]) {
00131          return best[idx];
00132       }
00133    }
00134 
00135    return 0;
00136 }

int iax2_format_compatibility_bitfield2cap ( uint64_t  bitfield,
struct ast_format_cap cap 
)

Convert a bitfield to a format capabilities structure.

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

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

References ast_format_cap_append, ast_format_compatibility_bitfield2format(), and format.

Referenced by iax2_codec_choose(), iax2_data_add_codecs(), and iax2_getformatname_multiple().

00062 {
00063    int bit;
00064 
00065    for (bit = 0; bit < 64; ++bit) {
00066       uint64_t mask = (1ULL << bit);
00067 
00068       if (mask & bitfield) {
00069          struct ast_format *format;
00070 
00071          format = ast_format_compatibility_bitfield2format(mask);
00072          if (format && ast_format_cap_append(cap, format, 0)) {
00073             return -1;
00074          }
00075       }
00076    }
00077 
00078    return 0;
00079 }

uint64_t iax2_format_compatibility_cap2bitfield ( const struct ast_format_cap cap  ) 

Convert a format capabilities structure to a bitfield.

Parameters:
cap Capabilities structure containing formats
Return values:
non-zero success
zero no formats present or no formats supported

Definition at line 45 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().

00046 {
00047    uint64_t bitfield = 0;
00048    int x;
00049 
00050    for (x = 0; x < ast_format_cap_count(cap); x++) {
00051       struct ast_format *format = ast_format_cap_get_format(cap, x);
00052 
00053       bitfield |= ast_format_compatibility_format2bitfield(format);
00054 
00055       ao2_ref(format, -1);
00056    }
00057 
00058    return bitfield;
00059 }


Generated on Thu Apr 16 06:31:05 2015 for Asterisk - The Open Source Telephony Project by  doxygen 1.5.6