[asterisk-commits] dvossel: branch dvossel/fixtheworld_phase1_step3 r300161 - in /team/dvossel/f...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Mon Jan 3 21:01:35 UTC 2011
Author: dvossel
Date: Mon Jan 3 15:01:31 2011
New Revision: 300161
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=300161
Log:
Splits the format pref API out of frame.c into its own file
Added:
team/dvossel/fixtheworld_phase1_step3/include/asterisk/format_pref.h (with props)
team/dvossel/fixtheworld_phase1_step3/main/format_pref.c (with props)
Modified:
team/dvossel/fixtheworld_phase1_step3/include/asterisk/frame.h
team/dvossel/fixtheworld_phase1_step3/main/frame.c
Added: team/dvossel/fixtheworld_phase1_step3/include/asterisk/format_pref.h
URL: http://svnview.digium.com/svn/asterisk/team/dvossel/fixtheworld_phase1_step3/include/asterisk/format_pref.h?view=auto&rev=300161
==============================================================================
--- team/dvossel/fixtheworld_phase1_step3/include/asterisk/format_pref.h (added)
+++ team/dvossel/fixtheworld_phase1_step3/include/asterisk/format_pref.h Mon Jan 3 15:01:31 2011
@@ -1,0 +1,97 @@
+/*
+ * Asterisk -- An open source telephony toolkit.
+ *
+ * Copyright (C) 2010, Digium, Inc.
+ *
+ * Mark Spencer <markster at digium.com>
+ *
+ * See http://www.asterisk.org for more information about
+ * the Asterisk project. Please do not directly contact
+ * any of the maintainers of this project for assistance;
+ * the project provides a web site, mailing lists and IRC
+ * channels for your use.
+ *
+ * This program is free software, distributed under the terms of
+ * the GNU General Public License Version 2. See the LICENSE file
+ * at the top of the source tree.
+ */
+
+/*!
+ * \file
+ * \brief Format Preference API
+ */
+
+#ifndef _AST_FORMATPREF_H_
+#define _AST_FORMATPREF_H_
+
+#include "asterisk/frame_defs.h"
+struct ast_codec_pref {
+ char order[sizeof(format_t) * 8];
+ char framing[sizeof(format_t) * 8];
+};
+
+/*! \page AudioCodecPref Audio Codec Preferences
+
+ In order to negotiate audio codecs in the order they are configured
+ in \<channel\>.conf for a device, we set up codec preference lists
+ in addition to the codec capabilities setting. The capabilities
+ setting is a bitmask of audio and video codecs with no internal
+ order. This will reflect the offer given to the other side, where
+ the prefered codecs will be added to the top of the list in the
+ order indicated by the "allow" lines in the device configuration.
+
+ Video codecs are not included in the preference lists since they
+ can't be transcoded and we just have to pick whatever is supported
+*/
+
+/*!
+ *\brief Initialize an audio codec preference to "no preference".
+ * \arg \ref AudioCodecPref
+*/
+void ast_codec_pref_init(struct ast_codec_pref *pref);
+
+/*!
+ * \brief Codec located at a particular place in the preference index.
+ * \arg \ref AudioCodecPref
+*/
+format_t ast_codec_pref_index(struct ast_codec_pref *pref, int index);
+
+/*! \brief Remove audio a codec from a preference list */
+void ast_codec_pref_remove(struct ast_codec_pref *pref, format_t format);
+
+/*! \brief Append a audio codec to a preference list, removing it first if it was already there
+*/
+int ast_codec_pref_append(struct ast_codec_pref *pref, format_t format);
+
+/*! \brief Prepend an audio codec to a preference list, removing it first if it was already there
+*/
+void ast_codec_pref_prepend(struct ast_codec_pref *pref, format_t format, int only_if_existing);
+
+/*! \brief Select the best audio format according to preference list from supplied options.
+ If "find_best" is non-zero then if nothing is found, the "Best" format of
+ the format list is selected, otherwise 0 is returned. */
+format_t ast_codec_choose(struct ast_codec_pref *pref, format_t formats, int find_best);
+
+/*! \brief Set packet size for codec
+*/
+int ast_codec_pref_setsize(struct ast_codec_pref *pref, format_t format, int framems);
+
+/*! \brief Get packet size for codec
+*/
+struct ast_format_list ast_codec_pref_getsize(struct ast_codec_pref *pref, format_t format);
+
+/*! \brief Dump audio codec preference list into a string */
+int ast_codec_pref_string(struct ast_codec_pref *pref, char *buf, size_t size);
+
+/*! \brief Shift an audio codec preference list up or down 65 bytes so that it becomes an ASCII string
+ * \note Due to a misunderstanding in how codec preferences are stored, this
+ * list starts at 'B', not 'A'. For backwards compatibility reasons, this
+ * cannot change.
+ * \param pref A codec preference list structure
+ * \param buf A string denoting codec preference, appropriate for use in line transmission
+ * \param size Size of \a buf
+ * \param right Boolean: if 0, convert from \a buf to \a pref; if 1, convert from \a pref to \a buf.
+ */
+void ast_codec_pref_convert(struct ast_codec_pref *pref, char *buf, size_t size, int right);
+
+#endif /* _AST_FORMATPREF_H */
Propchange: team/dvossel/fixtheworld_phase1_step3/include/asterisk/format_pref.h
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: team/dvossel/fixtheworld_phase1_step3/include/asterisk/format_pref.h
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Propchange: team/dvossel/fixtheworld_phase1_step3/include/asterisk/format_pref.h
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: team/dvossel/fixtheworld_phase1_step3/include/asterisk/frame.h
URL: http://svnview.digium.com/svn/asterisk/team/dvossel/fixtheworld_phase1_step3/include/asterisk/frame.h?view=diff&rev=300161&r1=300160&r2=300161
==============================================================================
--- team/dvossel/fixtheworld_phase1_step3/include/asterisk/frame.h (original)
+++ team/dvossel/fixtheworld_phase1_step3/include/asterisk/frame.h Mon Jan 3 15:01:31 2011
@@ -32,13 +32,9 @@
#include <sys/time.h>
#include "asterisk/frame_defs.h"
+#include "asterisk/format_pref.h"
#include "asterisk/endian.h"
#include "asterisk/linkedlists.h"
-
-struct ast_codec_pref {
- char order[sizeof(format_t) * 8];
- char framing[sizeof(format_t) * 8];
-};
/*!
* \page Def_Frame AST Multimedia and signalling frames
@@ -573,6 +569,12 @@
#define ast_frame_byteswap_be(fr) do { ; } while(0)
#endif
+/*! \brief Parse an "allow" or "deny" line in a channel or device configuration
+ and update the capabilities mask and pref if provided.
+ Video codecs are not added to codec preference lists, since we can not transcode
+ \return Returns number of errors encountered during parsing
+ */
+int ast_parse_allow_disallow(struct ast_codec_pref *pref, format_t *mask, const char *list, int allowing);
/*! \brief Get the name of a format
* \param format id of format
@@ -653,77 +655,6 @@
const struct ast_format_list *ast_get_format_list_index(int index);
const struct ast_format_list *ast_get_format_list(size_t *size);
void ast_frame_dump(const char *name, struct ast_frame *f, char *prefix);
-
-/*! \page AudioCodecPref Audio Codec Preferences
-
- In order to negotiate audio codecs in the order they are configured
- in \<channel\>.conf for a device, we set up codec preference lists
- in addition to the codec capabilities setting. The capabilities
- setting is a bitmask of audio and video codecs with no internal
- order. This will reflect the offer given to the other side, where
- the prefered codecs will be added to the top of the list in the
- order indicated by the "allow" lines in the device configuration.
-
- Video codecs are not included in the preference lists since they
- can't be transcoded and we just have to pick whatever is supported
-*/
-
-/*!
- *\brief Initialize an audio codec preference to "no preference".
- * \arg \ref AudioCodecPref
-*/
-void ast_codec_pref_init(struct ast_codec_pref *pref);
-
-/*!
- * \brief Codec located at a particular place in the preference index.
- * \arg \ref AudioCodecPref
-*/
-format_t ast_codec_pref_index(struct ast_codec_pref *pref, int index);
-
-/*! \brief Remove audio a codec from a preference list */
-void ast_codec_pref_remove(struct ast_codec_pref *pref, format_t format);
-
-/*! \brief Append a audio codec to a preference list, removing it first if it was already there
-*/
-int ast_codec_pref_append(struct ast_codec_pref *pref, format_t format);
-
-/*! \brief Prepend an audio codec to a preference list, removing it first if it was already there
-*/
-void ast_codec_pref_prepend(struct ast_codec_pref *pref, format_t format, int only_if_existing);
-
-/*! \brief Select the best audio format according to preference list from supplied options.
- If "find_best" is non-zero then if nothing is found, the "Best" format of
- the format list is selected, otherwise 0 is returned. */
-format_t ast_codec_choose(struct ast_codec_pref *pref, format_t formats, int find_best);
-
-/*! \brief Set packet size for codec
-*/
-int ast_codec_pref_setsize(struct ast_codec_pref *pref, format_t format, int framems);
-
-/*! \brief Get packet size for codec
-*/
-struct ast_format_list ast_codec_pref_getsize(struct ast_codec_pref *pref, format_t format);
-
-/*! \brief Parse an "allow" or "deny" line in a channel or device configuration
- and update the capabilities mask and pref if provided.
- Video codecs are not added to codec preference lists, since we can not transcode
- \return Returns number of errors encountered during parsing
- */
-int ast_parse_allow_disallow(struct ast_codec_pref *pref, format_t *mask, const char *list, int allowing);
-
-/*! \brief Dump audio codec preference list into a string */
-int ast_codec_pref_string(struct ast_codec_pref *pref, char *buf, size_t size);
-
-/*! \brief Shift an audio codec preference list up or down 65 bytes so that it becomes an ASCII string
- * \note Due to a misunderstanding in how codec preferences are stored, this
- * list starts at 'B', not 'A'. For backwards compatibility reasons, this
- * cannot change.
- * \param pref A codec preference list structure
- * \param buf A string denoting codec preference, appropriate for use in line transmission
- * \param size Size of \a buf
- * \param right Boolean: if 0, convert from \a buf to \a pref; if 1, convert from \a pref to \a buf.
- */
-void ast_codec_pref_convert(struct ast_codec_pref *pref, char *buf, size_t size, int right);
/*! \brief Returns the number of samples contained in the frame */
int ast_codec_get_samples(struct ast_frame *f);
Added: team/dvossel/fixtheworld_phase1_step3/main/format_pref.c
URL: http://svnview.digium.com/svn/asterisk/team/dvossel/fixtheworld_phase1_step3/main/format_pref.c?view=auto&rev=300161
==============================================================================
--- team/dvossel/fixtheworld_phase1_step3/main/format_pref.c (added)
+++ team/dvossel/fixtheworld_phase1_step3/main/format_pref.c Mon Jan 3 15:01:31 2011
@@ -1,0 +1,309 @@
+/*
+ * Asterisk -- An open source telephony toolkit.
+ *
+ * Copyright (C) 2010, Digium, Inc.
+ *
+ * Mark Spencer <markster at digium.com>
+ *
+ * See http://www.asterisk.org for more information about
+ * the Asterisk project. Please do not directly contact
+ * any of the maintainers of this project for assistance;
+ * the project provides a web site, mailing lists and IRC
+ * channels for your use.
+ *
+ * This program is free software, distributed under the terms of
+ * the GNU General Public License Version 2. See the LICENSE file
+ * at the top of the source tree.
+ */
+
+/*!
+ * \file
+ * \brief Format Preference API
+ */
+
+#include "asterisk.h"
+
+ASTERISK_FILE_VERSION(__FILE__, "$Revision$");
+
+#include "asterisk/_private.h"
+#include "asterisk/version.h"
+#include "asterisk/format.h"
+#include "asterisk/frame.h"
+#include "asterisk/channel.h"
+#include "asterisk/utils.h"
+
+void ast_codec_pref_convert(struct ast_codec_pref *pref, char *buf, size_t size, int right)
+{
+ int x, differential = (int) 'A', mem;
+ char *from, *to;
+
+ if (right) {
+ from = pref->order;
+ to = buf;
+ mem = size;
+ } else {
+ to = pref->order;
+ from = buf;
+ mem = sizeof(format_t) * 8;
+ }
+
+ memset(to, 0, mem);
+ for (x = 0; x < sizeof(format_t) * 8; x++) {
+ if (!from[x])
+ break;
+ to[x] = right ? (from[x] + differential) : (from[x] - differential);
+ }
+}
+
+int ast_codec_pref_string(struct ast_codec_pref *pref, char *buf, size_t size)
+{
+ int x;
+ format_t codec;
+ size_t total_len, slen;
+ char *formatname;
+
+ memset(buf, 0, size);
+ total_len = size;
+ buf[0] = '(';
+ total_len--;
+ for (x = 0; x < sizeof(format_t) * 8; x++) {
+ if (total_len <= 0)
+ break;
+ if (!(codec = ast_codec_pref_index(pref,x)))
+ break;
+ if ((formatname = ast_getformatname(codec))) {
+ slen = strlen(formatname);
+ if (slen > total_len)
+ break;
+ strncat(buf, formatname, total_len - 1); /* safe */
+ total_len -= slen;
+ }
+ if (total_len && x < sizeof(format_t) * 8 - 1 && ast_codec_pref_index(pref, x + 1)) {
+ strncat(buf, "|", total_len - 1); /* safe */
+ total_len--;
+ }
+ }
+ if (total_len) {
+ strncat(buf, ")", total_len - 1); /* safe */
+ total_len--;
+ }
+
+ return size - total_len;
+}
+
+format_t ast_codec_pref_index(struct ast_codec_pref *pref, int idx)
+{
+ int slot = 0;
+ size_t f_len = 0;
+ const struct ast_format_list *f_list = ast_get_format_list(&f_len);
+
+ if ((idx >= 0) && (idx < sizeof(pref->order))) {
+ slot = pref->order[idx];
+ }
+
+ return slot ? f_list[slot - 1].bits : 0;
+}
+
+/*! \brief Remove codec from pref list */
+void ast_codec_pref_remove(struct ast_codec_pref *pref, format_t format)
+{
+ struct ast_codec_pref oldorder;
+ int x, y = 0;
+ int slot;
+ int size;
+ size_t f_len = 0;
+ const struct ast_format_list *f_list = ast_get_format_list(&f_len);
+
+ if (!pref->order[0])
+ return;
+
+ memcpy(&oldorder, pref, sizeof(oldorder));
+ memset(pref, 0, sizeof(*pref));
+
+ for (x = 0; x < f_len; x++) {
+ slot = oldorder.order[x];
+ size = oldorder.framing[x];
+ if (! slot)
+ break;
+ if (f_list[slot-1].bits != format) {
+ pref->order[y] = slot;
+ pref->framing[y++] = size;
+ }
+ }
+}
+
+/*! \brief Append codec to list */
+int ast_codec_pref_append(struct ast_codec_pref *pref, format_t format)
+{
+ int x, newindex = 0;
+ size_t f_len = 0;
+ const struct ast_format_list *f_list = ast_get_format_list(&f_len);
+
+ ast_codec_pref_remove(pref, format);
+
+ for (x = 0; x < f_len; x++) {
+ if (f_list[x].bits == format) {
+ newindex = x + 1;
+ break;
+ }
+ }
+
+ if (newindex) {
+ for (x = 0; x < f_len; x++) {
+ if (!pref->order[x]) {
+ pref->order[x] = newindex;
+ break;
+ }
+ }
+ }
+
+ return x;
+}
+
+/*! \brief Prepend codec to list */
+void ast_codec_pref_prepend(struct ast_codec_pref *pref, format_t format, int only_if_existing)
+{
+ int x, newindex = 0;
+ size_t f_len = 0;
+ const struct ast_format_list *f_list = ast_get_format_list(&f_len);
+
+ /* First step is to get the codecs "index number" */
+ for (x = 0; x < f_len; x++) {
+ if (f_list[x].bits == format) {
+ newindex = x + 1;
+ break;
+ }
+ }
+ /* Done if its unknown */
+ if (!newindex)
+ return;
+
+ /* Now find any existing occurrence, or the end */
+ for (x = 0; x < sizeof(format_t) * 8; x++) {
+ if (!pref->order[x] || pref->order[x] == newindex)
+ break;
+ }
+
+ if (only_if_existing && !pref->order[x])
+ return;
+
+ /* Move down to make space to insert - either all the way to the end,
+ or as far as the existing location (which will be overwritten) */
+ for (; x > 0; x--) {
+ pref->order[x] = pref->order[x - 1];
+ pref->framing[x] = pref->framing[x - 1];
+ }
+
+ /* And insert the new entry */
+ pref->order[0] = newindex;
+ pref->framing[0] = 0; /* ? */
+}
+
+/*! \brief Set packet size for codec */
+int ast_codec_pref_setsize(struct ast_codec_pref *pref, format_t format, int framems)
+{
+ int x, idx = -1;
+ size_t f_len = 0;
+ const struct ast_format_list *f_list = ast_get_format_list(&f_len);
+
+ for (x = 0; x < f_len; x++) {
+ if (f_list[x].bits == format) {
+ idx = x;
+ break;
+ }
+ }
+
+ if (idx < 0)
+ return -1;
+
+ /* size validation */
+ if (!framems)
+ framems = f_list[idx].def_ms;
+
+ if (f_list[idx].inc_ms && framems % f_list[idx].inc_ms) /* avoid division by zero */
+ framems -= framems % f_list[idx].inc_ms;
+
+ if (framems < f_list[idx].min_ms)
+ framems = f_list[idx].min_ms;
+
+ if (framems > f_list[idx].max_ms)
+ framems = f_list[idx].max_ms;
+
+ for (x = 0; x < f_len; x++) {
+ if (pref->order[x] == (idx + 1)) {
+ pref->framing[x] = framems;
+ break;
+ }
+ }
+
+ return x;
+}
+
+/*! \brief Get packet size for codec */
+struct ast_format_list ast_codec_pref_getsize(struct ast_codec_pref *pref, format_t format)
+{
+ int x, idx = -1, framems = 0;
+ struct ast_format_list fmt = { 0, };
+ size_t f_len = 0;
+ const struct ast_format_list *f_list = ast_get_format_list(&f_len);
+
+ for (x = 0; x < f_len; x++) {
+ if (f_list[x].bits == format) {
+ fmt = f_list[x];
+ idx = x;
+ break;
+ }
+ }
+
+ for (x = 0; x < f_len; x++) {
+ if (pref->order[x] == (idx + 1)) {
+ framems = pref->framing[x];
+ break;
+ }
+ }
+
+ /* size validation */
+ if (!framems)
+ framems = f_list[idx].def_ms;
+
+ if (f_list[idx].inc_ms && framems % f_list[idx].inc_ms) /* avoid division by zero */
+ framems -= framems % f_list[idx].inc_ms;
+
+ if (framems < f_list[idx].min_ms)
+ framems = f_list[idx].min_ms;
+
+ if (framems > f_list[idx].max_ms)
+ framems = f_list[idx].max_ms;
+
+ fmt.cur_ms = framems;
+
+ return fmt;
+}
+
+/*! \brief Pick a codec */
+format_t ast_codec_choose(struct ast_codec_pref *pref, format_t formats, int find_best)
+{
+ int x, slot;
+ format_t ret = 0;
+ size_t f_len = 0;
+ const struct ast_format_list *f_list = ast_get_format_list(&f_len);
+
+ for (x = 0; x < f_len; x++) {
+ slot = pref->order[x];
+
+ if (!slot)
+ break;
+ if (formats & f_list[slot-1].bits) {
+ ret = f_list[slot-1].bits;
+ break;
+ }
+ }
+ if (ret & AST_FORMAT_AUDIO_MASK)
+ return ret;
+
+ ast_debug(4, "Could not find preferred codec - %s\n", find_best ? "Going for the best codec" : "Returning zero codec");
+
+ return find_best ? ast_best_codec(formats) : 0;
+}
+
+
Propchange: team/dvossel/fixtheworld_phase1_step3/main/format_pref.c
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: team/dvossel/fixtheworld_phase1_step3/main/format_pref.c
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Propchange: team/dvossel/fixtheworld_phase1_step3/main/format_pref.c
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: team/dvossel/fixtheworld_phase1_step3/main/frame.c
URL: http://svnview.digium.com/svn/asterisk/team/dvossel/fixtheworld_phase1_step3/main/frame.c?view=diff&rev=300161&r1=300160&r2=300161
==============================================================================
--- team/dvossel/fixtheworld_phase1_step3/main/frame.c (original)
+++ team/dvossel/fixtheworld_phase1_step3/main/frame.c Mon Jan 3 15:01:31 2011
@@ -984,266 +984,6 @@
return 0;
}
-void ast_codec_pref_convert(struct ast_codec_pref *pref, char *buf, size_t size, int right)
-{
- int x, differential = (int) 'A', mem;
- char *from, *to;
-
- if (right) {
- from = pref->order;
- to = buf;
- mem = size;
- } else {
- to = pref->order;
- from = buf;
- mem = sizeof(format_t) * 8;
- }
-
- memset(to, 0, mem);
- for (x = 0; x < sizeof(format_t) * 8; x++) {
- if (!from[x])
- break;
- to[x] = right ? (from[x] + differential) : (from[x] - differential);
- }
-}
-
-int ast_codec_pref_string(struct ast_codec_pref *pref, char *buf, size_t size)
-{
- int x;
- format_t codec;
- size_t total_len, slen;
- char *formatname;
-
- memset(buf, 0, size);
- total_len = size;
- buf[0] = '(';
- total_len--;
- for (x = 0; x < sizeof(format_t) * 8; x++) {
- if (total_len <= 0)
- break;
- if (!(codec = ast_codec_pref_index(pref,x)))
- break;
- if ((formatname = ast_getformatname(codec))) {
- slen = strlen(formatname);
- if (slen > total_len)
- break;
- strncat(buf, formatname, total_len - 1); /* safe */
- total_len -= slen;
- }
- if (total_len && x < sizeof(format_t) * 8 - 1 && ast_codec_pref_index(pref, x + 1)) {
- strncat(buf, "|", total_len - 1); /* safe */
- total_len--;
- }
- }
- if (total_len) {
- strncat(buf, ")", total_len - 1); /* safe */
- total_len--;
- }
-
- return size - total_len;
-}
-
-format_t ast_codec_pref_index(struct ast_codec_pref *pref, int idx)
-{
- int slot = 0;
-
- if ((idx >= 0) && (idx < sizeof(pref->order))) {
- slot = pref->order[idx];
- }
-
- return slot ? AST_FORMAT_LIST[slot - 1].bits : 0;
-}
-
-/*! \brief Remove codec from pref list */
-void ast_codec_pref_remove(struct ast_codec_pref *pref, format_t format)
-{
- struct ast_codec_pref oldorder;
- int x, y = 0;
- int slot;
- int size;
-
- if (!pref->order[0])
- return;
-
- memcpy(&oldorder, pref, sizeof(oldorder));
- memset(pref, 0, sizeof(*pref));
-
- for (x = 0; x < ARRAY_LEN(AST_FORMAT_LIST); x++) {
- slot = oldorder.order[x];
- size = oldorder.framing[x];
- if (! slot)
- break;
- if (AST_FORMAT_LIST[slot-1].bits != format) {
- pref->order[y] = slot;
- pref->framing[y++] = size;
- }
- }
-}
-
-/*! \brief Append codec to list */
-int ast_codec_pref_append(struct ast_codec_pref *pref, format_t format)
-{
- int x, newindex = 0;
-
- ast_codec_pref_remove(pref, format);
-
- for (x = 0; x < ARRAY_LEN(AST_FORMAT_LIST); x++) {
- if (AST_FORMAT_LIST[x].bits == format) {
- newindex = x + 1;
- break;
- }
- }
-
- if (newindex) {
- for (x = 0; x < ARRAY_LEN(AST_FORMAT_LIST); x++) {
- if (!pref->order[x]) {
- pref->order[x] = newindex;
- break;
- }
- }
- }
-
- return x;
-}
-
-/*! \brief Prepend codec to list */
-void ast_codec_pref_prepend(struct ast_codec_pref *pref, format_t format, int only_if_existing)
-{
- int x, newindex = 0;
-
- /* First step is to get the codecs "index number" */
- for (x = 0; x < ARRAY_LEN(AST_FORMAT_LIST); x++) {
- if (AST_FORMAT_LIST[x].bits == format) {
- newindex = x + 1;
- break;
- }
- }
- /* Done if its unknown */
- if (!newindex)
- return;
-
- /* Now find any existing occurrence, or the end */
- for (x = 0; x < sizeof(format_t) * 8; x++) {
- if (!pref->order[x] || pref->order[x] == newindex)
- break;
- }
-
- if (only_if_existing && !pref->order[x])
- return;
-
- /* Move down to make space to insert - either all the way to the end,
- or as far as the existing location (which will be overwritten) */
- for (; x > 0; x--) {
- pref->order[x] = pref->order[x - 1];
- pref->framing[x] = pref->framing[x - 1];
- }
-
- /* And insert the new entry */
- pref->order[0] = newindex;
- pref->framing[0] = 0; /* ? */
-}
-
-/*! \brief Set packet size for codec */
-int ast_codec_pref_setsize(struct ast_codec_pref *pref, format_t format, int framems)
-{
- int x, idx = -1;
-
- for (x = 0; x < ARRAY_LEN(AST_FORMAT_LIST); x++) {
- if (AST_FORMAT_LIST[x].bits == format) {
- idx = x;
- break;
- }
- }
-
- if (idx < 0)
- return -1;
-
- /* size validation */
- if (!framems)
- framems = AST_FORMAT_LIST[idx].def_ms;
-
- if (AST_FORMAT_LIST[idx].inc_ms && framems % AST_FORMAT_LIST[idx].inc_ms) /* avoid division by zero */
- framems -= framems % AST_FORMAT_LIST[idx].inc_ms;
-
- if (framems < AST_FORMAT_LIST[idx].min_ms)
- framems = AST_FORMAT_LIST[idx].min_ms;
-
- if (framems > AST_FORMAT_LIST[idx].max_ms)
- framems = AST_FORMAT_LIST[idx].max_ms;
-
- for (x = 0; x < ARRAY_LEN(AST_FORMAT_LIST); x++) {
- if (pref->order[x] == (idx + 1)) {
- pref->framing[x] = framems;
- break;
- }
- }
-
- return x;
-}
-
-/*! \brief Get packet size for codec */
-struct ast_format_list ast_codec_pref_getsize(struct ast_codec_pref *pref, format_t format)
-{
- int x, idx = -1, framems = 0;
- struct ast_format_list fmt = { 0, };
-
- for (x = 0; x < ARRAY_LEN(AST_FORMAT_LIST); x++) {
- if (AST_FORMAT_LIST[x].bits == format) {
- fmt = AST_FORMAT_LIST[x];
- idx = x;
- break;
- }
- }
-
- for (x = 0; x < ARRAY_LEN(AST_FORMAT_LIST); x++) {
- if (pref->order[x] == (idx + 1)) {
- framems = pref->framing[x];
- break;
- }
- }
-
- /* size validation */
- if (!framems)
- framems = AST_FORMAT_LIST[idx].def_ms;
-
- if (AST_FORMAT_LIST[idx].inc_ms && framems % AST_FORMAT_LIST[idx].inc_ms) /* avoid division by zero */
- framems -= framems % AST_FORMAT_LIST[idx].inc_ms;
-
- if (framems < AST_FORMAT_LIST[idx].min_ms)
- framems = AST_FORMAT_LIST[idx].min_ms;
-
- if (framems > AST_FORMAT_LIST[idx].max_ms)
- framems = AST_FORMAT_LIST[idx].max_ms;
-
- fmt.cur_ms = framems;
-
- return fmt;
-}
-
-/*! \brief Pick a codec */
-format_t ast_codec_choose(struct ast_codec_pref *pref, format_t formats, int find_best)
-{
- int x, slot;
- format_t ret = 0;
-
- for (x = 0; x < ARRAY_LEN(AST_FORMAT_LIST); x++) {
- slot = pref->order[x];
-
- if (!slot)
- break;
- if (formats & AST_FORMAT_LIST[slot-1].bits) {
- ret = AST_FORMAT_LIST[slot-1].bits;
- break;
- }
- }
- if (ret & AST_FORMAT_AUDIO_MASK)
- return ret;
-
- ast_debug(4, "Could not find preferred codec - %s\n", find_best ? "Going for the best codec" : "Returning zero codec");
-
- return find_best ? ast_best_codec(formats) : 0;
-}
-
int ast_parse_allow_disallow(struct ast_codec_pref *pref, format_t *mask, const char *list, int allowing)
{
int errors = 0, framems = 0;
More information about the asterisk-commits
mailing list