diff options
Diffstat (limited to 'channels/iax2/format_compatibility.c')
-rw-r--r-- | channels/iax2/format_compatibility.c | 73 |
1 files changed, 68 insertions, 5 deletions
diff --git a/channels/iax2/format_compatibility.c b/channels/iax2/format_compatibility.c index 8085c2c26..be7852c8f 100644 --- a/channels/iax2/format_compatibility.c +++ b/channels/iax2/format_compatibility.c @@ -38,6 +38,7 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$") #include "asterisk/format_compatibility.h" #include "asterisk/format_cache.h" #include "asterisk/format_cap.h" +#include "asterisk/utils.h" #include "include/format_compatibility.h" @@ -59,13 +60,75 @@ uint64_t iax2_format_compatibility_cap2bitfield(const struct ast_format_cap *cap int iax2_format_compatibility_bitfield2cap(uint64_t bitfield, struct ast_format_cap *cap) { - int x; + int bit; + + for (bit = 0; bit < 64; ++bit) { + uint64_t mask = (1ULL << bit); + + if (mask & bitfield) { + struct ast_format *format; + + format = ast_format_compatibility_bitfield2format(mask); + if (format && ast_format_cap_append(cap, format, 0)) { + return -1; + } + } + } - for (x = 0; x < 64; x++) { - uint64_t tmp = (1ULL << x); + return 0; +} + +uint64_t iax2_format_compatibility_best(uint64_t formats) +{ + /* + * This just our opinion, expressed in code. We are + * asked to choose the best codec to use, given no + * information. + */ + static const uint64_t best[] = { + /*! Okay, ulaw is used by all telephony equipment, so start with it */ + AST_FORMAT_ULAW, + /*! Unless of course, you're a silly European, so then prefer ALAW */ + AST_FORMAT_ALAW, + AST_FORMAT_G719, + AST_FORMAT_SIREN14, + AST_FORMAT_SIREN7, + AST_FORMAT_TESTLAW, + /*! G.722 is better then all below, but not as common as the above... so give ulaw and alaw priority */ + AST_FORMAT_G722, + /*! Okay, well, signed linear is easy to translate into other stuff */ + AST_FORMAT_SLIN16, + AST_FORMAT_SLIN, + /*! G.726 is standard ADPCM, in RFC3551 packing order */ + AST_FORMAT_G726, + /*! G.726 is standard ADPCM, in AAL2 packing order */ + AST_FORMAT_G726_AAL2, + /*! ADPCM has great sound quality and is still pretty easy to translate */ + AST_FORMAT_ADPCM, + /*! Okay, we're down to vocoders now, so pick GSM because it's small and easier to + translate and sounds pretty good */ + AST_FORMAT_GSM, + /*! iLBC is not too bad */ + AST_FORMAT_ILBC, + /*! Speex is free, but computationally more expensive than GSM */ + AST_FORMAT_SPEEX16, + AST_FORMAT_SPEEX, + /*! Opus */ + AST_FORMAT_OPUS, + /*! Ick, LPC10 sounds terrible, but at least we have code for it, if you're tacky enough + to use it */ + AST_FORMAT_LPC10, + /*! G.729a is faster than 723 and slightly less expensive */ + AST_FORMAT_G729, + /*! Down to G.723.1 which is proprietary but at least designed for voice */ + AST_FORMAT_G723, + }; + int idx; - if ((tmp & bitfield) && ast_format_cap_append(cap, ast_format_compatibility_bitfield2format(tmp), 0)) { - return -1; + /* Find the first preferred codec in the format given */ + for (idx = 0; idx < ARRAY_LEN(best); ++idx) { + if (formats & best[idx]) { + return best[idx]; } } |