46 static int differential = (int)
'A';
51 for (x = 0; x < ARRAY_LEN(pref->
order) && x < size; ++x) {
52 if (!pref->
order[x]) {
56 buf[x] = pref->
order[x] + differential;
61 for (x = 0; x < ARRAY_LEN(pref->
order) && x < size; ++x) {
66 pref->
order[x] = buf[x] - differential;
70 if (x < ARRAY_LEN(pref->
order)) {
79 if (0 <= idx && idx < ARRAY_LEN(pref->
order) && pref->
order[idx]) {
80 uint64_t pref_bitfield;
95 for (idx = 0; idx < ARRAY_LEN(pref->
order); ++idx) {
96 uint64_t pref_bitfield;
100 if (!pref_bitfield) {
114 uint64_t best_bitfield;
121 for (idx = 0; bitfield && idx < ARRAY_LEN(prefs->
order); ++idx) {
123 if (!best_bitfield) {
127 if (best_bitfield & bitfield) {
134 bitfield &= ~best_bitfield;
142 if (!best_bitfield) {
149 ast_assert(format != NULL);
156 bitfield &= ~best_bitfield;
163 for (bit = 0; bit < 64; ++bit) {
164 uint64_t mask = (1ULL << bit);
166 if (mask & bitfield) {
194 strcpy(buf,
"(...)");
200 total_len = size - 3;
212 name_len = strlen(name);
231 sprintf(cur,
"%s%s", x ?
"|" :
"", name);
233 total_len -= name_len;
243 return size - total_len;
246 static void codec_pref_remove_index(
struct iax2_codec_pref *pref,
int codec_pref_index)
250 idx = codec_pref_index;
251 if (idx == ARRAY_LEN(pref->
order) - 1) {
253 pref->
order[idx] = 0;
258 for (; idx < ARRAY_LEN(pref->
order); ++idx) {
261 if (!pref->
order[idx]) {
272 if (!pref->
order[0]) {
276 for (x = 0; x < ARRAY_LEN(pref->
order); ++x) {
277 if (!pref->
order[x]) {
281 if (pref->
order[x] == format_index) {
282 codec_pref_remove_index(pref, x);
292 if (!pref->
order[0]) {
300 for (idx = ARRAY_LEN(pref->
order); idx--;) {
301 uint64_t pref_bitfield;
304 if (!pref_bitfield) {
309 if (!(pref_bitfield & bitfield)) {
310 codec_pref_remove_index(pref, idx);
369 if (order_value < 1 || ARRAY_LEN(iax2_supported_formats) < order_value) {
373 return iax2_supported_formats[order_value - 1];
381 for (idx = 0; idx < ARRAY_LEN(iax2_supported_formats); ++idx) {
382 if (iax2_supported_formats[idx] == bitfield) {
399 static void iax2_codec_pref_append_bitfield(
struct iax2_codec_pref *pref, uint64_t bitfield,
unsigned int framing)
411 for (x = 0; x < ARRAY_LEN(pref->
order); ++x) {
412 if (!pref->
order[x]) {
413 pref->
order[x] = format_index;
429 iax2_codec_pref_append_bitfield(pref, bitfield, framing);
433 int only_if_existing)
449 for (x = 0; x < ARRAY_LEN(pref->
order); ++x) {
450 if (!pref->
order[x] || pref->
order[x] == format_index)
458 ast_assert(x < ARRAY_LEN(pref->
order));
461 if (ARRAY_LEN(pref->
order) <= x) {
462 x = ARRAY_LEN(pref->
order) - 1;
465 if (only_if_existing && !pref->
order[x]) {
477 pref->
order[0] = format_index;
484 uint64_t working_bitfield;
485 uint64_t best_bitfield;
489 memset(pref, 0,
sizeof(*pref));
491 working_bitfield = bitfield;
494 while (working_bitfield) {
496 if (!best_bitfield) {
502 working_bitfield &= ~best_bitfield;
506 ast_assert(format != NULL);
508 iax2_codec_pref_append_bitfield(pref, best_bitfield, 0);
512 if (working_bitfield) {
513 for (bit = 0; bit < 64; ++bit) {
514 uint64_t mask = (1ULL << bit);
516 if (mask & working_bitfield) {
524 iax2_codec_pref_append_bitfield(pref, mask, 0);
Asterisk main include file. File version handling, generic pbx functions.
uint64_t iax2_codec_pref_from_bitfield(struct iax2_codec_pref *pref, uint64_t bitfield)
Create codec preference list from the given bitfield formats.
static const uint64_t iax2_supported_formats[]
Formats supported by IAX2.
void iax2_codec_pref_remove_missing(struct iax2_codec_pref *pref, uint64_t bitfield)
Removes format from the pref list that aren't in the bitfield.
void iax2_codec_pref_prepend(struct iax2_codec_pref *pref, struct ast_format *format, unsigned int framing, int only_if_existing)
Prepend an audio codec to a preference list, removing it first if it was already there.
int iax2_codec_pref_best_bitfield2cap(uint64_t bitfield, struct iax2_codec_pref *prefs, struct ast_format_cap *cap)
Convert a bitfield to a format capabilities structure in the "best" order.
uint64_t iax2_codec_pref_order_value_to_format_bitfield(int order_value)
Convert an iax2_codec_pref order value into a format bitfield.
int iax2_codec_pref_to_cap(struct iax2_codec_pref *pref, struct ast_format_cap *cap)
Convert a preference structure to a capabilities structure.
#define ao2_ref(o, delta)
Reference/unreference an object and return the old refcount.
int iax2_codec_pref_string(struct iax2_codec_pref *pref, char *buf, size_t size)
Dump audio codec preference list into a string.
void iax2_codec_pref_append(struct iax2_codec_pref *pref, struct ast_format *format, unsigned int framing)
Append a audio codec to a preference list, removing it first if it was already there.
unsigned int framing[IAX2_CODEC_PREF_SIZE]
int iax2_codec_pref_format_bitfield_to_order_value(uint64_t bitfield)
Convert a format bitfield into an iax2_codec_pref order value.
Support for logging to various files, console and syslog Configuration in file logger.conf.
char order[IAX2_CODEC_PREF_SIZE]
Media Format Bitfield Compatibility API.
void iax2_codec_pref_convert(struct iax2_codec_pref *pref, char *buf, size_t size, int right)
Shift an audio codec preference list up or down 65 bytes so that it becomes an ASCII string...
struct ast_format * iax2_codec_pref_index(struct iax2_codec_pref *pref, int idx, struct ast_format **result)
Codec located at a particular place in the preference index.
static void codec_pref_remove(struct iax2_codec_pref *pref, int format_index)
Remove codec from pref list.