| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
#include "asterisk.h" |
| 31 |
|
| 32 |
#include "asterisk/logger.h" |
| 33 |
#include "asterisk/astobj2.h" |
| 34 |
#include "asterisk/codec.h" |
| 35 |
#include "asterisk/format.h" |
| 36 |
#include "asterisk/format_compatibility.h" |
| 37 |
#include "asterisk/format_cache.h" |
| 38 |
#include "asterisk/format_cap.h" |
| 39 |
#include "asterisk/utils.h" |
| 40 |
|
| 41 |
#include "include/format_compatibility.h" |
| 42 |
|
| 43 |
uint64_t iax2_format_compatibility_cap2bitfield(const struct ast_format_cap *cap) |
| 44 |
{ |
| 45 |
uint64_t bitfield = 0; |
| 46 |
int x; |
| 47 |
|
| 48 |
for (x = 0; x < ast_format_cap_count(cap); x++) { |
| 49 |
struct ast_format *format = ast_format_cap_get_format(cap, x); |
| 50 |
|
| 51 |
bitfield |= ast_format_compatibility_format2bitfield(format); |
| 52 |
|
| 53 |
ao2_ref(format, -1); |
| 54 |
} |
| 55 |
|
| 56 |
return bitfield; |
| 57 |
} |
| 58 |
|
| 59 |
int iax2_format_compatibility_bitfield2cap(uint64_t bitfield, struct ast_format_cap *cap) |
| 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 |
|
| 69 |
format = ast_format_compatibility_bitfield2format(mask); |
| 70 |
if (format && ast_format_cap_append(cap, format, 0)) { |
| 71 |
return -1; |
| 72 |
} |
| 73 |
} |
| 74 |
} |
| 75 |
|
| 76 |
return 0; |
| 77 |
} |
| 78 |
|
| 79 |
uint64_t iax2_format_compatibility_best(uint64_t formats) |
| 80 |
{ |
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
static const uint64_t best[] = { |
| 87 |
|
| 88 |
AST_FORMAT_ULAW, |
| 89 |
|
| 90 |
AST_FORMAT_ALAW, |
| 91 |
AST_FORMAT_G719, |
| 92 |
AST_FORMAT_SIREN14, |
| 93 |
AST_FORMAT_SIREN7, |
| 94 |
|
| 95 |
AST_FORMAT_G722, |
| 96 |
|
| 97 |
AST_FORMAT_SLIN16, |
| 98 |
AST_FORMAT_SLIN, |
| 99 |
|
| 100 |
AST_FORMAT_G726, |
| 101 |
|
| 102 |
AST_FORMAT_G726_AAL2, |
| 103 |
|
| 104 |
AST_FORMAT_ADPCM, |
| 105 |
|
| 106 |
|
| 107 |
AST_FORMAT_GSM, |
| 108 |
|
| 109 |
AST_FORMAT_ILBC, |
| 110 |
|
| 111 |
AST_FORMAT_SPEEX16, |
| 112 |
AST_FORMAT_SPEEX, |
| 113 |
|
| 114 |
AST_FORMAT_OPUS, |
| 115 |
|
| 116 |
|
| 117 |
AST_FORMAT_LPC10, |
| 118 |
|
| 119 |
AST_FORMAT_G729, |
| 120 |
|
| 121 |
AST_FORMAT_G723, |
| 122 |
}; |
| 123 |
int idx; |
| 124 |
|
| 125 |
|
| 126 |
for (idx = 0; idx < ARRAY_LEN(best); ++idx) { |
| 127 |
if (formats & best[idx]) { |
| 128 |
return best[idx]; |
| 129 |
} |
| 130 |
} |
| 131 |
|
| 132 |
return 0; |
| 133 |
} |