[asterisk-commits] dvossel: branch dvossel/fixtheworld_phase2 r306072 - in /team/dvossel/fixthew...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Thu Feb 3 12:21:35 CST 2011
Author: dvossel
Date: Thu Feb 3 12:21:31 2011
New Revision: 306072
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=306072
Log:
Introduction of the global dynamic Asterisk format list.
The global format list is now dynamic which allows custom formats with
attributes to be made on the fly from a configuration file.
Modified:
team/dvossel/fixtheworld_phase2/channels/chan_gtalk.c
team/dvossel/fixtheworld_phase2/channels/chan_iax2.c
team/dvossel/fixtheworld_phase2/channels/iax2.h
team/dvossel/fixtheworld_phase2/include/asterisk/format.h
team/dvossel/fixtheworld_phase2/include/asterisk/format_cap.h
team/dvossel/fixtheworld_phase2/include/asterisk/frame.h
team/dvossel/fixtheworld_phase2/main/data.c
team/dvossel/fixtheworld_phase2/main/format.c
team/dvossel/fixtheworld_phase2/main/format_cap.c
team/dvossel/fixtheworld_phase2/main/format_pref.c
team/dvossel/fixtheworld_phase2/main/frame.c
team/dvossel/fixtheworld_phase2/main/translate.c
Modified: team/dvossel/fixtheworld_phase2/channels/chan_gtalk.c
URL: http://svnview.digium.com/svn/asterisk/team/dvossel/fixtheworld_phase2/channels/chan_gtalk.c?view=diff&rev=306072&r1=306071&r2=306072
==============================================================================
--- team/dvossel/fixtheworld_phase2/channels/chan_gtalk.c (original)
+++ team/dvossel/fixtheworld_phase2/channels/chan_gtalk.c Thu Feb 3 12:21:31 2011
@@ -285,7 +285,7 @@
static int add_codec_to_answer(const struct gtalk_pvt *p, struct ast_format *codec, iks *dcodecs)
{
int res = 0;
- char *format = ast_getformatname(codec);
+ const char *format = ast_getformatname(codec);
if (!strcasecmp("ulaw", format)) {
iks *payload_eg711u, *payload_pcmu;
Modified: team/dvossel/fixtheworld_phase2/channels/chan_iax2.c
URL: http://svnview.digium.com/svn/asterisk/team/dvossel/fixtheworld_phase2/channels/chan_iax2.c?view=diff&rev=306072&r1=306071&r2=306072
==============================================================================
--- team/dvossel/fixtheworld_phase2/channels/chan_iax2.c (original)
+++ team/dvossel/fixtheworld_phase2/channels/chan_iax2.c Thu Feb 3 12:21:31 2011
@@ -1668,7 +1668,7 @@
return ast_format_to_old_bitfield(&tmpfmt);
}
-char *iax2_getformatname(iax2_format format)
+const char *iax2_getformatname(iax2_format format)
{
struct ast_format tmpfmt;
if (!(ast_format_from_old_bitfield(&tmpfmt, format))) {
Modified: team/dvossel/fixtheworld_phase2/channels/iax2.h
URL: http://svnview.digium.com/svn/asterisk/team/dvossel/fixtheworld_phase2/channels/iax2.h?view=diff&rev=306072&r1=306071&r2=306072
==============================================================================
--- team/dvossel/fixtheworld_phase2/channels/iax2.h (original)
+++ team/dvossel/fixtheworld_phase2/channels/iax2.h Thu Feb 3 12:21:31 2011
@@ -218,7 +218,7 @@
typedef int64_t iax2_format;
/*!\brief iax2 wrapper function for ast_getformatname */
-char *iax2_getformatname(iax2_format format);
+const char *iax2_getformatname(iax2_format format);
/*! Full frames are always delivered reliably */
struct ast_iax2_full_hdr {
Modified: team/dvossel/fixtheworld_phase2/include/asterisk/format.h
URL: http://svnview.digium.com/svn/asterisk/team/dvossel/fixtheworld_phase2/include/asterisk/format.h?view=diff&rev=306072&r1=306071&r2=306072
==============================================================================
--- team/dvossel/fixtheworld_phase2/include/asterisk/format.h (original)
+++ team/dvossel/fixtheworld_phase2/include/asterisk/format.h Thu Feb 3 12:21:31 2011
@@ -26,8 +26,8 @@
#ifndef _AST_FORMAT_H_
#define _AST_FORMAT_H_
+#include "asterisk/astobj2.h"
#define AST_FORMAT_ATTR_SIZE 128
-
#define AST_FORMAT_INC 100000
/*! This is the value that ends a var list of format attribute
@@ -133,6 +133,22 @@
AST_FORMAT_CMP_SUBSET,
};
+/*! \brief Definition of supported media formats (codecs) */
+struct ast_format_list {
+ struct ast_format format; /*!< The unique format. */
+ const char *name; /*!< short name */
+ int samplespersecond; /*!< Number of samples per second (8000/16000) */
+ const char *desc; /*!< Description */
+ int fr_len; /*!< Single frame length in bytes */
+ int min_ms; /*!< Min value */
+ int max_ms; /*!< Max value */
+ int inc_ms; /*!< Increment */
+ int def_ms; /*!< Default value */
+ unsigned int flags; /*!< Smoother flags */
+ int cur_ms; /*!< Current value */
+ int custom_entry;
+};
+
/*! \brief A format must register an attribute interface if it requires the use of the format attributes void pointer */
struct ast_format_attr_interface {
/*! format type */
@@ -286,6 +302,30 @@
*/
enum ast_format_id ast_format_id_from_old_bitfield(uint64_t src);
+const struct ast_format_list *ast_format_list_get(size_t *size);
+const struct ast_format_list *ast_format_list_destroy(const struct ast_format_list *list);
+
+/*! \brief Get the name of a format
+ * \param format id of format
+ * \return A static string containing the name of the format or "unknown" if unknown.
+ */
+const char* ast_getformatname(struct ast_format *format);
+
+/*!
+ * \brief Gets a format from a name.
+ * \param name string of format
+ * \param format structure to return the format in.
+ * \return This returns the format pointer given to it on success and NULL on failure
+ */
+struct ast_format *ast_getformatbyname(const char *name, struct ast_format *format);
+
+/*!
+ * \brief Get a name from a format
+ * \param format to get name of
+ * \return This returns a static string identifying the format on success, 0 on error.
+ */
+const char *ast_codec2str(struct ast_format *format);
+
/*!
* \brief register ast_format_attr_interface with core.
*
Modified: team/dvossel/fixtheworld_phase2/include/asterisk/format_cap.h
URL: http://svnview.digium.com/svn/asterisk/team/dvossel/fixtheworld_phase2/include/asterisk/format_cap.h?view=diff&rev=306072&r1=306071&r2=306072
==============================================================================
--- team/dvossel/fixtheworld_phase2/include/asterisk/format_cap.h (original)
+++ team/dvossel/fixtheworld_phase2/include/asterisk/format_cap.h Thu Feb 3 12:21:31 2011
@@ -70,7 +70,7 @@
* what is placed in the ast_format_cap structure. The actual
* input format ptr is not stored.
*/
-void ast_format_cap_add(struct ast_format_cap *cap, struct ast_format *format);
+void ast_format_cap_add(struct ast_format_cap *cap, const struct ast_format *format);
/*!
* \brief Add all formats Asterisk knows about for a specific type to
@@ -270,4 +270,14 @@
*/
void ast_format_cap_from_old_bitfield(struct ast_format_cap *dst, uint64_t src);
+/*! \brief Get the names of a set of formats
+ * \param buf a buffer for the output string
+ * \param size size of buf (bytes)
+ * \param format the format (combined IDs of codecs)
+ * Prints a list of readable codec names corresponding to "format".
+ * ex: for format=AST_FORMAT_GSM|AST_FORMAT_SPEEX|AST_FORMAT_ILBC it will return "0x602 (GSM|SPEEX|ILBC)"
+ * \return The return value is buf.
+ */
+char* ast_getformatname_multiple(char *buf, size_t size, struct ast_format_cap *cap);
+
#endif /* _AST_FORMATCAP_H */
Modified: team/dvossel/fixtheworld_phase2/include/asterisk/frame.h
URL: http://svnview.digium.com/svn/asterisk/team/dvossel/fixtheworld_phase2/include/asterisk/frame.h?view=diff&rev=306072&r1=306071&r2=306072
==============================================================================
--- team/dvossel/fixtheworld_phase2/include/asterisk/frame.h (original)
+++ team/dvossel/fixtheworld_phase2/include/asterisk/frame.h Thu Feb 3 12:21:31 2011
@@ -426,23 +426,6 @@
uint8_t data[0];
};
-
-/*! \brief Definition of supported media formats (codecs) */
-struct ast_format_list {
- enum ast_format_id id; /*!< The format unique id */
- char *name; /*!< short name */
- int samplespersecond; /*!< Number of samples per second (8000/16000) */
- char *desc; /*!< Description */
- int fr_len; /*!< Single frame length in bytes */
- int min_ms; /*!< Min value */
- int max_ms; /*!< Max value */
- int inc_ms; /*!< Increment */
- int def_ms; /*!< Default value */
- unsigned int flags; /*!< Smoother flags */
- int cur_ms; /*!< Current value */
-};
-
-
/*! \brief Requests a frame to be allocated
*
* \param source
@@ -504,37 +487,6 @@
*/
int ast_parse_allow_disallow(struct ast_codec_pref *pref, struct ast_format_cap *cap, const char *list, int allowing);
-/*! \brief Get the name of a format
- * \param format id of format
- * \return A static string containing the name of the format or "unknown" if unknown.
- */
-char* ast_getformatname(struct ast_format *format);
-
-/*! \brief Get the names of a set of formats
- * \param buf a buffer for the output string
- * \param size size of buf (bytes)
- * \param format the format (combined IDs of codecs)
- * Prints a list of readable codec names corresponding to "format".
- * ex: for format=AST_FORMAT_GSM|AST_FORMAT_SPEEX|AST_FORMAT_ILBC it will return "0x602 (GSM|SPEEX|ILBC)"
- * \return The return value is buf.
- */
-char* ast_getformatname_multiple(char *buf, size_t size, struct ast_format_cap *cap);
-
-/*!
- * \brief Gets a format from a name.
- * \param name string of format
- * \param format structure to return the format in.
- * \return This returns the format pointer given to it on success and NULL on failure
- */
-struct ast_format *ast_getformatbyname(const char *name, struct ast_format *format);
-
-/*! \brief Get a name from a format
- * Gets a name from a format
- * \param format to get name of
- * \return This returns a static string identifying the format on success, 0 on error.
- */
-char *ast_codec2str(struct ast_format *format);
-
/*! \name AST_Smoother
*/
/*@{ */
@@ -581,8 +533,6 @@
#endif
/*@} Doxygen marker */
-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);
/*! \brief Returns the number of samples contained in the frame */
Modified: team/dvossel/fixtheworld_phase2/main/data.c
URL: http://svnview.digium.com/svn/asterisk/team/dvossel/fixtheworld_phase2/main/data.c?view=diff&rev=306072&r1=306071&r2=306072
==============================================================================
--- team/dvossel/fixtheworld_phase2/main/data.c (original)
+++ team/dvossel/fixtheworld_phase2/main/data.c Thu Feb 3 12:21:31 2011
@@ -3111,11 +3111,12 @@
if (!codecs) {
return -1;
}
- fmlist = ast_get_format_list(&fmlist_size);
+ fmlist = ast_format_list_get(&fmlist_size);
for (x = 0; x < fmlist_size; x++) {
- if (fmlist[x].id == format->id) {
+ if (ast_format_cmp(&fmlist[x].format, format) == AST_FORMAT_CMP_EQUAL) {
codec = ast_data_add_node(codecs, "codec");
if (!codec) {
+ ast_format_list_destroy(fmlist);
return -1;
}
ast_data_add_str(codec, "name", fmlist[x].name);
@@ -3124,6 +3125,7 @@
ast_data_add_int(codec, "frame_length", fmlist[x].fr_len);
}
}
+ ast_format_list_destroy(fmlist);
return 0;
}
@@ -3133,18 +3135,18 @@
struct ast_data *codecs, *codec;
size_t fmlist_size;
const struct ast_format_list *fmlist;
- struct ast_format tmp_fmt;
int x;
codecs = ast_data_add_node(root, node_name);
if (!codecs) {
return -1;
}
- fmlist = ast_get_format_list(&fmlist_size);
+ fmlist = ast_format_list_get(&fmlist_size);
for (x = 0; x < fmlist_size; x++) {
- if (ast_format_cap_iscompatible(cap, ast_format_set(&tmp_fmt, fmlist[x].id, 0))) {
+ if (ast_format_cap_iscompatible(cap, &fmlist[x].format)) {
codec = ast_data_add_node(codecs, "codec");
if (!codec) {
+ ast_format_list_destroy(fmlist);
return -1;
}
ast_data_add_str(codec, "name", fmlist[x].name);
@@ -3153,6 +3155,7 @@
ast_data_add_int(codec, "frame_length", fmlist[x].fr_len);
}
}
+ ast_format_list_destroy(fmlist);
return 0;
}
Modified: team/dvossel/fixtheworld_phase2/main/format.c
URL: http://svnview.digium.com/svn/asterisk/team/dvossel/fixtheworld_phase2/main/format.c?view=diff&rev=306072&r1=306071&r2=306072
==============================================================================
--- team/dvossel/fixtheworld_phase2/main/format.c (original)
+++ team/dvossel/fixtheworld_phase2/main/format.c Thu Feb 3 12:21:31 2011
@@ -4,6 +4,7 @@
* Copyright (C) 2010, Digium, Inc.
*
* David Vossel <dvossel at digium.com>
+ * Mark Spencer <markster at digium.com>
*
* See http://www.asterisk.org for more information about
* the Asterisk project. Please do not directly contact
@@ -21,6 +22,7 @@
* \brief Format API
*
* \author David Vossel <dvossel at digium.com>
+ * \author Mark Spencer <markster at digium.com>
*/
#include "asterisk.h"
@@ -32,6 +34,9 @@
#include "asterisk/format.h"
#include "asterisk/astobj2.h"
#include "asterisk/lock.h"
+#include "asterisk/frame.h"
+#include "asterisk/utils.h"
+#include "asterisk/cli.h"
/*! This is the container for all the format attribute interfaces.
* An ao2 container was chosen for fast lookup. */
@@ -50,6 +55,17 @@
* of the ao2 lock. */
ast_rwlock_t wraplock;
};
+
+/*! \brief Format List container, This container is never directly accessed outside
+ * of this file, and It only exists for building the format_list_array. */
+static struct ao2_container *format_list;
+/*! \brief Format List array is a read only array protected by a read write lock.
+ * This array may be used outside this file with the use of reference counting to
+ * guarantee safety for access by multiple threads. */
+static struct ast_format_list *format_list_array;
+static size_t format_list_array_len = 0;
+/*! \brief Locks the format list array so a reference can be taken safely. */
+static ast_rwlock_t format_list_array_lock;
static int interface_cmp_cb(void *obj, void *arg, int flags)
{
@@ -486,16 +502,405 @@
return 0;
}
+const char* ast_getformatname(struct ast_format *format)
+{
+ int x;
+ const char *ret = "unknown";
+ size_t f_len;
+ const struct ast_format_list *f_list = ast_format_list_get(&f_len);
+ for (x = 0; x < f_len; x++) {
+ if (ast_format_cmp(&f_list[x].format, format) == AST_FORMAT_CMP_EQUAL) {
+ ret = f_list[x].name;
+ break;
+ }
+ }
+ f_list = ast_format_list_destroy(f_list);
+ return ret;
+}
+
+char *ast_getformatname_multiple(char *buf, size_t size, struct ast_format_cap *cap)
+{
+ int x;
+ unsigned len;
+ char *start, *end = buf;
+ struct ast_format tmp_fmt;
+ size_t f_len;
+ const struct ast_format_list *f_list = ast_format_list_get(&f_len);
+
+ if (!size) {
+ f_list = ast_format_list_destroy(f_list);
+ return buf;
+ }
+ snprintf(end, size, "(");
+ len = strlen(end);
+ end += len;
+ size -= len;
+ start = end;
+ for (x = 0; x < f_len; x++) {
+ ast_format_copy(&tmp_fmt, &f_list[x].format);
+ if (ast_format_cap_iscompatible(cap, &tmp_fmt)) {
+ snprintf(end, size, "%s|", f_list[x].name);
+ len = strlen(end);
+ end += len;
+ size -= len;
+ }
+ }
+ if (start == end) {
+ ast_copy_string(start, "nothing)", size);
+ } else if (size > 1) {
+ *(end - 1) = ')';
+ }
+ f_list = ast_format_list_destroy(f_list);
+ return buf;
+}
+
+static struct ast_codec_alias_table {
+ char *alias;
+ char *realname;
+} ast_codec_alias_table[] = {
+ { "slinear", "slin"},
+ { "slinear16", "slin16"},
+ { "g723.1", "g723"},
+ { "g722.1", "siren7"},
+ { "g722.1c", "siren14"},
+};
+
+static const char *ast_expand_codec_alias(const char *in)
+{
+ int x;
+
+ for (x = 0; x < ARRAY_LEN(ast_codec_alias_table); x++) {
+ if (!strcmp(in,ast_codec_alias_table[x].alias))
+ return ast_codec_alias_table[x].realname;
+ }
+ return in;
+}
+
+struct ast_format *ast_getformatbyname(const char *name, struct ast_format *result)
+{
+ int x;
+ size_t f_len;
+ const struct ast_format_list *f_list = ast_format_list_get(&f_len);
+
+ for (x = 0; x < f_len; x++) {
+ if (!strcasecmp(f_list[x].name, name) ||
+ !strcasecmp(f_list[x].name, ast_expand_codec_alias(name))) {
+
+ ast_format_copy(result, &f_list[x].format);
+ f_list = ast_format_list_destroy(f_list);
+ return result;
+ }
+ }
+ f_list = ast_format_list_destroy(f_list);
+
+ return NULL;
+}
+
+const char *ast_codec2str(struct ast_format *format)
+{
+ int x;
+ const char *ret = "unknown";
+ size_t f_len;
+ const struct ast_format_list *f_list = ast_format_list_get(&f_len);
+
+ for (x = 0; x < f_len; x++) {
+ if (ast_format_cmp(&f_list[x].format, format) == AST_FORMAT_CMP_EQUAL) {
+ ret = f_list[x].desc;
+ break;
+ }
+ }
+ f_list = ast_format_list_destroy(f_list);
+ return ret;
+}
+
+
+static char *show_codecs(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
+{
+ int x, found=0;
+ size_t f_len;
+ const struct ast_format_list *f_list;
+
+ switch (cmd) {
+ case CLI_INIT:
+ e->command = "core show codecs [audio|video|image|text]";
+ e->usage =
+ "Usage: core show codecs [audio|video|image|text]\n"
+ " Displays codec mapping\n";
+ return NULL;
+ case CLI_GENERATE:
+ return NULL;
+ }
+
+ if ((a->argc < 3) || (a->argc > 4))
+ return CLI_SHOWUSAGE;
+
+ f_list = ast_format_list_get(&f_len);
+ if (!ast_opt_dont_warn)
+ ast_cli(a->fd, "Disclaimer: this command is for informational purposes only.\n"
+ "\tIt does not indicate anything about your configuration.\n");
+
+ ast_cli(a->fd, "%19s %8s %8s %s\n","ID","TYPE","NAME","DESCRIPTION");
+ ast_cli(a->fd, "-----------------------------------------------------------------------------------\n");
+
+ for (x = 0; x < f_len; x++) {
+ if (a->argc == 4) {
+ if (!strcasecmp(a->argv[3], "audio")) {
+ if (AST_FORMAT_GET_TYPE(f_list[x].format.id) != AST_FORMAT_TYPE_AUDIO) {
+ continue;
+ }
+ } else if (!strcasecmp(a->argv[3], "video")) {
+ if (AST_FORMAT_GET_TYPE(f_list[x].format.id) != AST_FORMAT_TYPE_VIDEO) {
+ continue;
+ }
+ } else if (!strcasecmp(a->argv[3], "image")) {
+ if (AST_FORMAT_GET_TYPE(f_list[x].format.id) != AST_FORMAT_TYPE_IMAGE) {
+ continue;
+ }
+ } else if (!strcasecmp(a->argv[3], "text")) {
+ if (AST_FORMAT_GET_TYPE(f_list[x].format.id) != AST_FORMAT_TYPE_TEXT) {
+ continue;
+ }
+ } else {
+ continue;
+ }
+ }
+
+ ast_cli(a->fd, "%19u %5s %8s (%s)\n",
+ f_list[x].format.id,
+ (AST_FORMAT_GET_TYPE(f_list[x].format.id) == AST_FORMAT_TYPE_AUDIO) ? "audio" :
+ (AST_FORMAT_GET_TYPE(f_list[x].format.id) == AST_FORMAT_TYPE_IMAGE) ? "image" :
+ (AST_FORMAT_GET_TYPE(f_list[x].format.id) == AST_FORMAT_TYPE_VIDEO) ? "video" :
+ (AST_FORMAT_GET_TYPE(f_list[x].format.id) == AST_FORMAT_TYPE_TEXT) ? "text" :
+ "(unk)",
+ f_list[x].name,
+ f_list[x].desc);
+ found = 1;
+ }
+
+ f_list = ast_format_list_destroy(f_list);
+ if (!found) {
+ return CLI_SHOWUSAGE;
+ } else {
+ return CLI_SUCCESS;
+ }
+}
+
+static char *show_codec_n(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
+{
+ enum ast_format_id format_id;
+ int x, found = 0;
+ int type_punned_codec;
+ size_t f_len;
+ const struct ast_format_list *f_list;
+
+ switch (cmd) {
+ case CLI_INIT:
+ e->command = "core show codec";
+ e->usage =
+ "Usage: core show codec <number>\n"
+ " Displays codec mapping\n";
+ return NULL;
+ case CLI_GENERATE:
+ return NULL;
+ }
+
+ if (a->argc != 4)
+ return CLI_SHOWUSAGE;
+
+ if (sscanf(a->argv[3], "%30d", &type_punned_codec) != 1) {
+ return CLI_SHOWUSAGE;
+ }
+ format_id = type_punned_codec;
+
+ f_list = ast_format_list_get(&f_len);
+ for (x = 0; x < f_len; x++) {
+ if (f_list[x].format.id == format_id) {
+ found = 1;
+ ast_cli(a->fd, "%11u %s\n", (unsigned int) format_id, f_list[x].desc);
+ break;
+ }
+ }
+
+ if (!found)
+ ast_cli(a->fd, "Codec %d not found\n", format_id);
+
+ f_list = ast_format_list_destroy(f_list);
+ return CLI_SUCCESS;
+}
+
+/* Builtin Asterisk CLI-commands for debugging */
+static struct ast_cli_entry my_clis[] = {
+ AST_CLI_DEFINE(show_codecs, "Displays a list of codecs"),
+ AST_CLI_DEFINE(show_codec_n, "Shows a specific codec"),
+};
+int init_framer(void)
+{
+ ast_cli_register_multiple(my_clis, ARRAY_LEN(my_clis));
+ return 0;
+}
+
+static int format_list_add(
+ const struct ast_format *format,
+ const char *name,
+ int samplespersecond,
+ const char *description,
+ int fr_len,
+ int min_ms,
+ int max_ms,
+ int inc_ms,
+ int def_ms,
+ unsigned int flags,
+ int cur_ms,
+ int custom_entry)
+{
+ struct ast_format_list *entry;
+ if (!(entry = ao2_alloc(sizeof(*entry), NULL))) {
+ return -1;
+ }
+ ast_format_copy(&entry->format, format);
+ entry->name = name;
+ entry->desc = description;
+ entry->samplespersecond = samplespersecond;
+ entry->fr_len = fr_len;
+ entry->min_ms = min_ms;
+ entry->max_ms = max_ms;
+ entry->inc_ms = inc_ms;
+ entry->def_ms = def_ms;
+ entry->flags = flags;
+ entry->cur_ms = cur_ms;
+ entry->custom_entry = custom_entry;
+
+ ao2_link(format_list, entry);
+ return 0;
+}
+
+static int list_cmp_cb(void *obj, void *arg, int flags)
+{
+ struct ast_format_list *entry1 = obj;
+ struct ast_format_list *entry2 = arg;
+
+ return (ast_format_cmp(&entry1->format, &entry2->format) == AST_FORMAT_CMP_EQUAL) ? CMP_MATCH | CMP_STOP : 0;
+}
+static int list_hash_cb(const void *obj, const int flags)
+{
+ return ao2_container_count(format_list);
+}
+
+const struct ast_format_list *ast_format_list_get(size_t *size)
+{
+ struct ast_format_list *list;
+ ast_rwlock_rdlock(&format_list_array_lock);
+ ao2_ref(format_list_array, 1);
+ list = format_list_array;
+ *size = format_list_array_len;
+ ast_rwlock_unlock(&format_list_array_lock);
+ return list;
+}
+const struct ast_format_list *ast_format_list_destroy(const struct ast_format_list *list)
+{
+ ao2_ref((void *) list, -1);
+ return NULL;
+}
+
+static int build_format_list_array(void)
+{
+ struct ast_format_list *tmp;
+ size_t arraysize = sizeof(struct ast_format_list) * ao2_container_count(format_list);
+ int i = 0;
+ struct ao2_iterator it;
+
+ ast_rwlock_wrlock(&format_list_array_lock);
+ tmp = format_list_array;
+ if (!(format_list_array = ao2_alloc(arraysize, NULL))) {
+ format_list_array = tmp;
+ ast_rwlock_unlock(&format_list_array_lock);
+ return -1;
+ }
+ format_list_array_len = ao2_container_count(format_list);
+ if (tmp) {
+ ao2_ref(tmp, -1);
+ }
+
+ it = ao2_iterator_init(format_list, 0);
+ while ((tmp = ao2_iterator_next(&it)) && (i < format_list_array_len)) {
+ memcpy(&format_list_array[i], tmp, sizeof(struct ast_format_list));
+ i++;
+ }
+ ao2_iterator_destroy(&it);
+
+ ast_rwlock_unlock(&format_list_array_lock);
+ return 0;
+}
+static int format_list_init(void)
+{
+ struct ast_format tmpfmt;
+ if (!(format_list = ao2_container_alloc(283, list_hash_cb, list_cmp_cb))) {
+ return -1;
+ }
+ /* initiate static entries XXX DO NOT CHANGE THIS ORDER! */
+ format_list_add(ast_format_set(&tmpfmt, AST_FORMAT_G723_1, 0), "g723", 8000, "G.723.1", 20, 30, 300, 30, 30, 0, 0, 0); /*!< G723.1 */
+ format_list_add(ast_format_set(&tmpfmt, AST_FORMAT_GSM, 0), "gsm", 8000, "GSM", 33, 20, 300, 20, 20, 0, 0, 0); /*!< codec_gsm.c */
+ format_list_add(ast_format_set(&tmpfmt, AST_FORMAT_ULAW, 0), "ulaw", 8000, "G.711 u-law", 80, 10, 150, 10, 20, 0, 0, 0); /*!< codec_ulaw.c */
+ format_list_add(ast_format_set(&tmpfmt, AST_FORMAT_ALAW, 0), "alaw", 8000, "G.711 A-law", 80, 10, 150, 10, 20, 0, 0, 0); /*!< codec_alaw.c */
+ format_list_add(ast_format_set(&tmpfmt, AST_FORMAT_G726, 0), "g726", 8000, "G.726 RFC3551", 40, 10, 300, 10, 20, 0, 0, 0); /*!< codec_g726.c */
+ format_list_add(ast_format_set(&tmpfmt, AST_FORMAT_ADPCM, 0), "adpcm" , 8000, "ADPCM", 40, 10, 300, 10, 20, 0, 0, 0); /*!< codec_adpcm.c */
+ format_list_add(ast_format_set(&tmpfmt, AST_FORMAT_SLINEAR, 0), "slin", 8000, "16 bit Signed Linear PCM", 160, 10, 70, 10, 20, AST_SMOOTHER_FLAG_BE, 0, 0); /*!< Signed linear */
+ format_list_add(ast_format_set(&tmpfmt, AST_FORMAT_LPC10, 0), "lpc10", 8000, "LPC10", 7, 20, 20, 20, 20, 0, 0, 0); /*!< codec_lpc10.c */
+ format_list_add(ast_format_set(&tmpfmt, AST_FORMAT_G729A, 0), "g729", 8000, "G.729A", 10, 10, 230, 10, 20, AST_SMOOTHER_FLAG_G729, 0, 0); /*!< Binary commercial distribution */
+ format_list_add(ast_format_set(&tmpfmt, AST_FORMAT_SPEEX, 0), "speex", 8000, "SpeeX", 10, 10, 60, 10, 20, 0, 0, 0); /*!< codec_speex.c */
+ format_list_add(ast_format_set(&tmpfmt, AST_FORMAT_SPEEX16, 0), "speex16", 16000, "SpeeX 16khz", 10, 10, 60, 10, 20, 0, 0, 0); /*!< codec_speex.c */
+ format_list_add(ast_format_set(&tmpfmt, AST_FORMAT_ILBC, 0), "ilbc", 8000, "iLBC", 50, 30, 30, 30, 30, 0, 0, 0); /*!< codec_ilbc.c */ /* inc=30ms - workaround */
+ format_list_add(ast_format_set(&tmpfmt, AST_FORMAT_G726_AAL2, 0), "g726aal2", 8000, "G.726 AAL2", 40, 10, 300, 10, 20, 0, 0, 0); /*!< codec_g726.c */
+ format_list_add(ast_format_set(&tmpfmt, AST_FORMAT_G722, 0), "g722", 16000, "G722", 80, 10, 150, 10, 20, 0, 0, 0); /*!< codec_g722.c */
+ format_list_add(ast_format_set(&tmpfmt, AST_FORMAT_SLINEAR16, 0), "slin16", 16000, "16 bit Signed Linear PCM (16kHz)", 320, 10, 70, 10, 20, AST_SMOOTHER_FLAG_BE, 0 ,0);/*!< Signed linear (16kHz) */
+ format_list_add(ast_format_set(&tmpfmt, AST_FORMAT_JPEG, 0), "jpeg", 0, "JPEG image", 0, 0, 0, 0 ,0 ,0 ,0, 0); /*!< See format_jpeg.c */
+ format_list_add(ast_format_set(&tmpfmt, AST_FORMAT_PNG, 0), "png", 0, "PNG image", 0, 0, 0, 0 ,0 ,0 ,0, 0); /*!< PNG Image format */
+ format_list_add(ast_format_set(&tmpfmt, AST_FORMAT_H261, 0), "h261", 0, "H.261 Video", 0, 0, 0, 0 ,0 ,0 ,0, 0); /*!< H.261 Video Passthrough */
+ format_list_add(ast_format_set(&tmpfmt, AST_FORMAT_H263, 0), "h263", 0, "H.263 Video", 0, 0, 0, 0 ,0 ,0 ,0, 0); /*!< H.263 Passthrough support, see format_h263.c */
+ format_list_add(ast_format_set(&tmpfmt, AST_FORMAT_H263_PLUS, 0), "h263p", 0, "H.263+ Video", 0, 0, 0,0 ,0 ,0, 0, 0); /*!< H.263plus passthrough support See format_h263.c */
+ format_list_add(ast_format_set(&tmpfmt, AST_FORMAT_H264, 0), "h264", 0, "H.264 Video", 0, 0, 0, 0 ,0 ,0, 0, 0); /*!< Passthrough support, see format_h263.c */
+ format_list_add(ast_format_set(&tmpfmt, AST_FORMAT_MP4_VIDEO, 0), "mpeg4", 0, "MPEG4 Video", 0, 0, 0, 0, 0 ,0, 0, 0); /*!< Passthrough support for MPEG4 */
+ format_list_add(ast_format_set(&tmpfmt, AST_FORMAT_T140RED, 0), "red", 1, "T.140 Realtime Text with redundancy", 0, 0, 0,0 ,0 ,0, 0, 0); /*!< Redundant T.140 Realtime Text */
+ format_list_add(ast_format_set(&tmpfmt, AST_FORMAT_T140, 0), "t140", 0, "Passthrough T.140 Realtime Text", 0, 0, 0, 0 ,0 ,0, 0, 0); /*!< Passthrough support for T.140 Realtime Text */
+ format_list_add(ast_format_set(&tmpfmt, AST_FORMAT_SIREN7, 0), "siren7", 16000, "ITU G.722.1 (Siren7, licensed from Polycom)", 80, 20, 80, 20, 20, 0, 0, 0); /*!< Binary commercial distribution */
+ format_list_add(ast_format_set(&tmpfmt, AST_FORMAT_SIREN14, 0), "siren14", 32000, "ITU G.722.1 Annex C, (Siren14, licensed from Polycom)", 120, 20, 80, 20, 20, 0, 0, 0); /*!< Binary commercial distribution */
+ format_list_add(ast_format_set(&tmpfmt, AST_FORMAT_TESTLAW, 0), "testlaw", 8000, "G.711 test-law", 80, 10, 150, 10, 20, 0, 0, 0); /*!< codec_ulaw.c */
+ format_list_add(ast_format_set(&tmpfmt, AST_FORMAT_G719, 0), "g719", 48000, "ITU G.719", 160, 20, 80, 20, 20, 0, 0, 0);
+
+ return 0;
+}
+
int ast_format_attr_init()
{
+ ast_cli_register_multiple(my_clis, ARRAY_LEN(my_clis));
if (ast_rwlock_init(&ilock)) {
return -1;
+ }
+ if (ast_rwlock_init(&format_list_array_lock)) {
+ return -1;
+ ast_rwlock_destroy(&ilock);
}
if (!(interfaces = ao2_container_alloc(283, interface_hash_cb, interface_cmp_cb))) {
ast_rwlock_destroy(&ilock);
- return -1;
- }
+ goto init_cleanup;
+ }
+ if (format_list_init()) {
+ goto init_cleanup;
+ }
+ if (build_format_list_array()) {
+ goto init_cleanup;
+ }
+
return 0;
+
+init_cleanup:
+ ast_rwlock_destroy(&ilock);
+ ast_rwlock_destroy(&format_list_array_lock);
+ if (interfaces) {
+ ao2_ref(interfaces, -1);
+ }
+ ao2_ref(format_list, -1);
+ return -1;
}
int ast_format_attr_reg_interface(const struct ast_format_attr_interface *interface)
Modified: team/dvossel/fixtheworld_phase2/main/format_cap.c
URL: http://svnview.digium.com/svn/asterisk/team/dvossel/fixtheworld_phase2/main/format_cap.c?view=diff&rev=306072&r1=306071&r2=306072
==============================================================================
--- team/dvossel/fixtheworld_phase2/main/format_cap.c (original)
+++ team/dvossel/fixtheworld_phase2/main/format_cap.c Thu Feb 3 12:21:31 2011
@@ -99,7 +99,7 @@
return NULL;
}
-void ast_format_cap_add(struct ast_format_cap *cap, struct ast_format *format)
+void ast_format_cap_add(struct ast_format_cap *cap, const struct ast_format *format)
{
struct ast_format *fnew;
@@ -122,26 +122,26 @@
{
int x;
size_t f_len = 0;
- struct ast_format tmp_fmt;
- const struct ast_format_list *f_list = ast_get_format_list(&f_len);
+ const struct ast_format_list *f_list = ast_format_list_get(&f_len);
for (x = 0; x < f_len; x++) {
- if (AST_FORMAT_GET_TYPE(f_list[x].id) == type) {
- ast_format_cap_add(cap, ast_format_set(&tmp_fmt, f_list[x].id, 0));
+ if (AST_FORMAT_GET_TYPE(f_list[x].format.id) == type) {
+ ast_format_cap_add(cap, &f_list[x].format);
}
}
+ ast_format_list_destroy(f_list);
}
void ast_format_cap_add_all(struct ast_format_cap *cap)
{
int x;
size_t f_len = 0;
- struct ast_format tmp_fmt;
- const struct ast_format_list *f_list = ast_get_format_list(&f_len);
+ const struct ast_format_list *f_list = ast_format_list_get(&f_len);
for (x = 0; x < f_len; x++) {
- ast_format_cap_add(cap, ast_format_set(&tmp_fmt, f_list[x].id, 0));
- }
+ ast_format_cap_add(cap, &f_list[x].format);
+ }
+ ast_format_list_destroy(f_list);
}
static int append_cb(void *obj, void *arg, int flag)
Modified: team/dvossel/fixtheworld_phase2/main/format_pref.c
URL: http://svnview.digium.com/svn/asterisk/team/dvossel/fixtheworld_phase2/main/format_pref.c?view=diff&rev=306072&r1=306071&r2=306072
==============================================================================
--- team/dvossel/fixtheworld_phase2/main/format_pref.c (original)
+++ team/dvossel/fixtheworld_phase2/main/format_pref.c Thu Feb 3 12:21:31 2011
@@ -34,7 +34,7 @@
void ast_codec_pref_convert(struct ast_codec_pref *pref, char *buf, size_t size, int right)
{
size_t f_len;
- const struct ast_format_list *f_list = ast_get_format_list(&f_len);
+ const const struct ast_format_list *f_list = ast_format_list_get(&f_len);
int x, differential = (int) 'A', mem;
char *from, *to;
@@ -57,9 +57,10 @@
}
to[x] = right ? (from[x] + differential) : (from[x] - differential);
if (!right && to[x] && (to[x] < f_len)) {
- ast_format_set(&pref->formats[x], f_list[to[x]-1].id , 0);
- }
- }
+ ast_format_copy(&pref->formats[x], &f_list[to[x]-1].format);
+ }
+ }
+ ast_format_list_destroy(f_list);
}
int ast_codec_pref_string(struct ast_codec_pref *pref, char *buf, size_t size)
@@ -67,7 +68,7 @@
int x;
struct ast_format format;
size_t total_len, slen;
- char *formatname;
+ const char *formatname;
memset(buf, 0, size);
total_len = size;
@@ -116,7 +117,7 @@
struct ast_codec_pref oldorder;
int x, y = 0;
size_t f_len = 0;
- const struct ast_format_list *f_list = ast_get_format_list(&f_len);
+ const const struct ast_format_list *f_list = ast_format_list_get(&f_len);
if (!pref->order[0])
return;
@@ -127,12 +128,13 @@
for (x = 0; x < f_len; x++) {
if (!oldorder.order[x])
break;
- if (f_list[oldorder.order[x]-1].id != format->id) {
+ if (ast_format_cmp(&f_list[oldorder.order[x]-1].format, format) == AST_FORMAT_CMP_NOT_EQUAL) {
pref->order[y] = oldorder.order[x];
ast_format_copy(&pref->formats[y], &oldorder.formats[x]);
pref->framing[y++] = oldorder.framing[x];
}
}
+ ast_format_list_destroy(f_list);
}
/*! \brief Append codec to list */
@@ -140,12 +142,12 @@
{
int x, newindex = 0;
size_t f_len = 0;
- const struct ast_format_list *f_list = ast_get_format_list(&f_len);
+ const struct ast_format_list *f_list = ast_format_list_get(&f_len);
ast_codec_pref_remove(pref, format);
for (x = 0; x < f_len; x++) {
- if (f_list[x].id == format->id) {
+ if (ast_format_cmp(&f_list[x].format, format) == AST_FORMAT_CMP_EQUAL) {
newindex = x + 1;
break;
}
@@ -161,6 +163,7 @@
}
}
+ ast_format_list_destroy(f_list);
return x;
}
@@ -169,18 +172,20 @@
{
int x, newindex = 0;
size_t f_len = 0;
- const struct ast_format_list *f_list = ast_get_format_list(&f_len);
+ const struct ast_format_list *f_list = ast_format_list_get(&f_len);
/* First step is to get the codecs "index number" */
for (x = 0; x < f_len; x++) {
- if (f_list[x].id == format->id) {
+ if (ast_format_cmp(&f_list[x].format, format) == AST_FORMAT_CMP_EQUAL) {
newindex = x + 1;
break;
}
}
/* Done if its unknown */
- if (!newindex)
+ if (!newindex) {
+ ast_format_list_destroy(f_list);
return;
+ }
/* Now find any existing occurrence, or the end */
for (x = 0; x < AST_CODEC_PREF_SIZE; x++) {
@@ -188,8 +193,10 @@
break;
}
- if (only_if_existing && !pref->order[x])
+ if (only_if_existing && !pref->order[x]) {
+ ast_format_list_destroy(f_list);
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) */
@@ -203,6 +210,7 @@
pref->order[0] = newindex;
pref->framing[0] = 0; /* ? */
ast_format_copy(&pref->formats[0], format);
+ ast_format_list_destroy(f_list);
}
/*! \brief Set packet size for codec */
@@ -210,17 +218,19 @@
{
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].id == format->id) {
+ const struct ast_format_list *f_list = ast_format_list_get(&f_len);
+
+ for (x = 0; x < f_len; x++) {
+ if (ast_format_cmp(&f_list[x].format, format) == AST_FORMAT_CMP_EQUAL) {
idx = x;
break;
}
}
- if (idx < 0)
+ if (idx < 0) {
+ ast_format_list_destroy(f_list);
return -1;
+ }
/* size validation */
if (!framems)
@@ -242,6 +252,7 @@
}
}
+ ast_format_list_destroy(f_list);
return x;
}
@@ -249,12 +260,12 @@
struct ast_format_list ast_codec_pref_getsize(struct ast_codec_pref *pref, struct ast_format *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].id == format->id) {
+ struct ast_format_list fmt = { { 0, }, };
+ size_t f_len = 0;
+ const struct ast_format_list *f_list = ast_format_list_get(&f_len);
+
+ for (x = 0; x < f_len; x++) {
+ if (ast_format_cmp(&f_list[x].format, format) == AST_FORMAT_CMP_EQUAL) {
fmt = f_list[x];
idx = x;
break;
@@ -282,7 +293,7 @@
framems = f_list[idx].max_ms;
fmt.cur_ms = framems;
-
+ ast_format_list_destroy(f_list);
return fmt;
}
@@ -292,8 +303,7 @@
int x, slot, found;
size_t f_len = 0;
struct ast_format tmp_fmt;
-
- const struct ast_format_list *f_list = ast_get_format_list(&f_len);
+ const struct ast_format_list *f_list = ast_format_list_get(&f_len);
ast_format_clear(result);
@@ -302,11 +312,12 @@
if (!slot)
break;
- if (ast_format_cap_iscompatible(cap, ast_format_set(&tmp_fmt, f_list[slot-1].id, 0))) {
+ if (ast_format_cap_iscompatible(cap, &f_list[slot-1].format)) {
found = 1; /*format is found and stored in tmp_fmt */
break;
}
}
+ ast_format_list_destroy(f_list);
if (found && (AST_FORMAT_GET_TYPE(tmp_fmt.id) == AST_FORMAT_TYPE_AUDIO)) {
ast_format_copy(result, &tmp_fmt);
return result;
Modified: team/dvossel/fixtheworld_phase2/main/frame.c
URL: http://svnview.digium.com/svn/asterisk/team/dvossel/fixtheworld_phase2/main/frame.c?view=diff&rev=306072&r1=306071&r2=306072
==============================================================================
--- team/dvossel/fixtheworld_phase2/main/frame.c (original)
+++ team/dvossel/fixtheworld_phase2/main/frame.c Thu Feb 3 12:21:31 2011
@@ -90,38 +90,6 @@
char framedata[SMOOTHER_SIZE + AST_FRIENDLY_OFFSET];
struct ast_frame *opt;
int len;
-};
-
-/*! \brief Definition of supported media formats (codecs) */
-static const struct ast_format_list AST_FORMAT_LIST[] = {
- { AST_FORMAT_G723_1 , "g723", 8000, "G.723.1", 20, 30, 300, 30, 30 }, /*!< G723.1 */
- { AST_FORMAT_GSM, "gsm", 8000, "GSM", 33, 20, 300, 20, 20 }, /*!< codec_gsm.c */
- { AST_FORMAT_ULAW, "ulaw", 8000, "G.711 u-law", 80, 10, 150, 10, 20 }, /*!< codec_ulaw.c */
- { AST_FORMAT_ALAW, "alaw", 8000, "G.711 A-law", 80, 10, 150, 10, 20 }, /*!< codec_alaw.c */
- { AST_FORMAT_G726, "g726", 8000, "G.726 RFC3551", 40, 10, 300, 10, 20 }, /*!< codec_g726.c */
- { AST_FORMAT_ADPCM, "adpcm" , 8000, "ADPCM", 40, 10, 300, 10, 20 }, /*!< codec_adpcm.c */
- { AST_FORMAT_SLINEAR, "slin", 8000, "16 bit Signed Linear PCM", 160, 10, 70, 10, 20, AST_SMOOTHER_FLAG_BE }, /*!< Signed linear */
- { AST_FORMAT_LPC10, "lpc10", 8000, "LPC10", 7, 20, 20, 20, 20 }, /*!< codec_lpc10.c */
- { AST_FORMAT_G729A, "g729", 8000, "G.729A", 10, 10, 230, 10, 20, AST_SMOOTHER_FLAG_G729 }, /*!< Binary commercial distribution */
- { AST_FORMAT_SPEEX, "speex", 8000, "SpeeX", 10, 10, 60, 10, 20 }, /*!< codec_speex.c */
- { AST_FORMAT_SPEEX16, "speex16", 16000, "SpeeX 16khz", 10, 10, 60, 10, 20 }, /*!< codec_speex.c */
- { AST_FORMAT_ILBC, "ilbc", 8000, "iLBC", 50, 30, 30, 30, 30 }, /*!< codec_ilbc.c */ /* inc=30ms - workaround */
- { AST_FORMAT_G726_AAL2, "g726aal2", 8000, "G.726 AAL2", 40, 10, 300, 10, 20 }, /*!< codec_g726.c */
- { AST_FORMAT_G722, "g722", 16000, "G722", 80, 10, 150, 10, 20 }, /*!< codec_g722.c */
- { AST_FORMAT_SLINEAR16, "slin16", 16000, "16 bit Signed Linear PCM (16kHz)", 320, 10, 70, 10, 20, AST_SMOOTHER_FLAG_BE }, /*!< Signed linear (16kHz) */
- { AST_FORMAT_JPEG, "jpeg", 0, "JPEG image"}, /*!< See format_jpeg.c */
- { AST_FORMAT_PNG, "png", 0, "PNG image"}, /*!< PNG Image format */
- { AST_FORMAT_H261, "h261", 0, "H.261 Video" }, /*!< H.261 Video Passthrough */
- { AST_FORMAT_H263, "h263", 0, "H.263 Video" }, /*!< H.263 Passthrough support, see format_h263.c */
- { AST_FORMAT_H263_PLUS, "h263p", 0, "H.263+ Video" }, /*!< H.263plus passthrough support See format_h263.c */
- { AST_FORMAT_H264, "h264", 0, "H.264 Video" }, /*!< Passthrough support, see format_h263.c */
- { AST_FORMAT_MP4_VIDEO, "mpeg4", 0, "MPEG4 Video" }, /*!< Passthrough support for MPEG4 */
- { AST_FORMAT_T140RED, "red", 1, "T.140 Realtime Text with redundancy"}, /*!< Redundant T.140 Realtime Text */
- { AST_FORMAT_T140, "t140", 0, "Passthrough T.140 Realtime Text" }, /*!< Passthrough support for T.140 Realtime Text */
- { AST_FORMAT_SIREN7, "siren7", 16000, "ITU G.722.1 (Siren7, licensed from Polycom)", 80, 20, 80, 20, 20 }, /*!< Binary commercial distribution */
- { AST_FORMAT_SIREN14, "siren14", 32000, "ITU G.722.1 Annex C, (Siren14, licensed from Polycom)", 120, 20, 80, 20, 20 }, /*!< Binary commercial distribution */
[... 321 lines stripped ...]
More information about the asterisk-commits
mailing list