aboutsummaryrefslogtreecommitdiffstats
path: root/include/asterisk/format.h
diff options
context:
space:
mode:
authordvossel <dvossel@f38db490-d61c-443f-a65b-d21fe96a405b>2011-02-22 23:04:49 +0000
committerdvossel <dvossel@f38db490-d61c-443f-a65b-d21fe96a405b>2011-02-22 23:04:49 +0000
commitf27e928f0588f5cbf85ac8202cef912efcc51a9c (patch)
treeb061487de973558358757bd1b6e457aaccf41638 /include/asterisk/format.h
parent70442b4e1767b35ed1699d27cfc24109c617f445 (diff)
Media Project Phase2: SILK 8khz-24khz, SLINEAR 8khz-192khz, SPEEX 32khz, hd audio ConfBridge, and other stuff
-Functional changes 1. Dynamic global format list build by codecs defined in codecs.conf 2. SILK 8khz, 12khz, 16khz, and 24khz with custom attributes defined in codecs.conf 3. Negotiation of SILK attributes in chan_sip. 4. SPEEX 32khz with translation 5. SLINEAR 8khz, 12khz, 24khz, 32khz, 44.1khz, 48khz, 96khz, 192khz with translation using codec_resample.c 6. Various changes to RTP code required to properly handle the dynamic format list and formats with attributes. 7. ConfBridge now dynamically jumps to the best possible sample rate. This allows for conferences to take advantage of HD audio (Which sounds awesome) 8. Audiohooks are no longer limited to 8khz audio, and most effects have been updated to take advantage of this such as Volume, DENOISE, PITCH_SHIFT. 9. codec_resample now uses its own code rather than depending on libresample. -Organizational changes Global format list is moved from frame.c to format.c Various format specific functions moved from frame.c to format.c Review: https://reviewboard.asterisk.org/r/1104/ git-svn-id: http://svn.digium.com/svn/asterisk/trunk@308582 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'include/asterisk/format.h')
-rw-r--r--include/asterisk/format.h162
1 files changed, 143 insertions, 19 deletions
diff --git a/include/asterisk/format.h b/include/asterisk/format.h
index 09212abc8..67e4178a2 100644
--- a/include/asterisk/format.h
+++ b/include/asterisk/format.h
@@ -26,8 +26,9 @@
#ifndef _AST_FORMAT_H_
#define _AST_FORMAT_H_
+#include "asterisk/astobj2.h"
+#include "asterisk/silk.h"
#define AST_FORMAT_ATTR_SIZE 128
-
#define AST_FORMAT_INC 100000
/*! This is the value that ends a var list of format attribute
@@ -55,32 +56,49 @@ enum ast_format_id {
AST_FORMAT_G726_AAL2 = 5 + AST_FORMAT_TYPE_AUDIO,
/*! ADPCM (IMA) */
AST_FORMAT_ADPCM = 6 + AST_FORMAT_TYPE_AUDIO,
- /*! Raw 16-bit Signed Linear (8000 Hz) PCM */
- AST_FORMAT_SLINEAR = 7 + AST_FORMAT_TYPE_AUDIO,
/*! LPC10, 180 samples/frame */
- AST_FORMAT_LPC10 = 8 + AST_FORMAT_TYPE_AUDIO,
+ AST_FORMAT_LPC10 = 7 + AST_FORMAT_TYPE_AUDIO,
/*! G.729A audio */
- AST_FORMAT_G729A = 9 + AST_FORMAT_TYPE_AUDIO,
+ AST_FORMAT_G729A = 8 + AST_FORMAT_TYPE_AUDIO,
/*! SpeeX Free Compression */
- AST_FORMAT_SPEEX = 10 + AST_FORMAT_TYPE_AUDIO,
+ AST_FORMAT_SPEEX = 9 + AST_FORMAT_TYPE_AUDIO,
/*! iLBC Free Compression */
- AST_FORMAT_ILBC = 11 + AST_FORMAT_TYPE_AUDIO,
+ AST_FORMAT_ILBC = 10 + AST_FORMAT_TYPE_AUDIO,
/*! ADPCM (G.726, 32kbps, RFC3551 codeword packing) */
- AST_FORMAT_G726 = 12 + AST_FORMAT_TYPE_AUDIO,
+ AST_FORMAT_G726 = 11 + AST_FORMAT_TYPE_AUDIO,
/*! G.722 */
- AST_FORMAT_G722 = 13 + AST_FORMAT_TYPE_AUDIO,
+ AST_FORMAT_G722 = 12 + AST_FORMAT_TYPE_AUDIO,
/*! G.722.1 (also known as Siren7, 32kbps assumed) */
- AST_FORMAT_SIREN7 = 14 + AST_FORMAT_TYPE_AUDIO,
+ AST_FORMAT_SIREN7 = 13 + AST_FORMAT_TYPE_AUDIO,
/*! G.722.1 Annex C (also known as Siren14, 48kbps assumed) */
- AST_FORMAT_SIREN14 = 15 + AST_FORMAT_TYPE_AUDIO,
- /*! Raw 16-bit Signed Linear (16000 Hz) PCM */
- AST_FORMAT_SLINEAR16 = 16 + AST_FORMAT_TYPE_AUDIO,
+ AST_FORMAT_SIREN14 = 14 + AST_FORMAT_TYPE_AUDIO,
/*! G.719 (64 kbps assumed) */
- AST_FORMAT_G719 = 17 + AST_FORMAT_TYPE_AUDIO,
+ AST_FORMAT_G719 = 15 + AST_FORMAT_TYPE_AUDIO,
/*! SpeeX Wideband (16kHz) Free Compression */
- AST_FORMAT_SPEEX16 = 18 + AST_FORMAT_TYPE_AUDIO,
+ AST_FORMAT_SPEEX16 = 16 + AST_FORMAT_TYPE_AUDIO,
/*! Raw mu-law data (G.711) */
- AST_FORMAT_TESTLAW = 19 + AST_FORMAT_TYPE_AUDIO,
+ AST_FORMAT_TESTLAW = 17 + AST_FORMAT_TYPE_AUDIO,
+ /*! SILK format */
+ AST_FORMAT_SILK = 18 + AST_FORMAT_TYPE_AUDIO,
+ /*! Raw 16-bit Signed Linear (8000 Hz) PCM */
+ AST_FORMAT_SLINEAR = 19 + AST_FORMAT_TYPE_AUDIO,
+ /*! Raw 16-bit Signed Linear (12000 Hz) PCM */
+ AST_FORMAT_SLINEAR12 = 20 + AST_FORMAT_TYPE_AUDIO,
+ /*! Raw 16-bit Signed Linear (16000 Hz) PCM */
+ AST_FORMAT_SLINEAR16 = 21 + AST_FORMAT_TYPE_AUDIO,
+ /*! Raw 16-bit Signed Linear (24000 Hz) PCM */
+ AST_FORMAT_SLINEAR24 = 22 + AST_FORMAT_TYPE_AUDIO,
+ /*! Raw 16-bit Signed Linear (32000 Hz) PCM */
+ AST_FORMAT_SLINEAR32 = 23 + AST_FORMAT_TYPE_AUDIO,
+ /*! Raw 16-bit Signed Linear (44100 Hz) PCM just because we can. */
+ AST_FORMAT_SLINEAR44 = 24 + AST_FORMAT_TYPE_AUDIO,
+ /*! Raw 16-bit Signed Linear (48000 Hz) PCM */
+ AST_FORMAT_SLINEAR48 = 25 + AST_FORMAT_TYPE_AUDIO,
+ /*! Raw 16-bit Signed Linear (96000 Hz) PCM */
+ AST_FORMAT_SLINEAR96 = 26 + AST_FORMAT_TYPE_AUDIO,
+ /*! Raw 16-bit Signed Linear (192000 Hz) PCM. maybe we're taking this too far. */
+ AST_FORMAT_SLINEAR192 = 27 + AST_FORMAT_TYPE_AUDIO,
+ AST_FORMAT_SPEEX32 = 28 + AST_FORMAT_TYPE_AUDIO,
/*! H.261 Video */
AST_FORMAT_H261 = 1 + AST_FORMAT_TYPE_VIDEO,
@@ -107,6 +125,7 @@ enum ast_format_id {
/*! Determine what type of media a ast_format_id is. */
#define AST_FORMAT_GET_TYPE(id) (((int) (id / AST_FORMAT_INC)) * AST_FORMAT_INC)
+
/*! \brief This structure contains the buffer used for format attributes */
struct ast_format_attr {
/*! The buffer formats can use to represent attributes */
@@ -133,6 +152,22 @@ enum ast_format_cmp_res {
AST_FORMAT_CMP_SUBSET,
};
+/*! \brief Definition of supported media formats (codecs) */
+struct ast_format_list {
+ struct ast_format format; /*!< The unique format. */
+ char name[64]; /*!< short name */
+ unsigned int samplespersecond; /*!< Number of samples per second (8000/16000) */
+ char desc[128]; /*!< 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 */
@@ -154,6 +189,34 @@ struct ast_format_attr_interface {
/*! \brief Set format capabilities from a list of key value pairs ending with AST_FORMAT_ATTR_END.
* \note This function does not need to call va_end of the va_list. */
void (* const format_attr_set)(struct ast_format_attr *format_attr, va_list ap);
+
+ /*!
+ * \brief Find out if format capabilities in va_list are in format.
+ * \note This function does not need to call va_end of the va_list.
+ *
+ * \note This function is optional. In many cases the format_attr_cmp
+ * function can be used to derive these results. If it is possible
+ * that some format attributes have no bearing on the equality of two formats, this
+ * function must exist.
+ *
+ * \retval 0 if all attributes exist
+ * \retval -1 if any of the attributes not present
+ */
+ int (* const format_attr_isset)(const struct ast_format_attr *format_attr, va_list ap);
+
+ /*
+ * \brief Return a value for a specific format key. Return that value in the void pointer.
+ *
+ * \note It is not expected that all key value pairs can be returned, but those that can should
+ * be documented as such.
+ *
+ * \note This function is optional if key value pairs are not allowed to be accessed. This
+ * will result in -1 always being returned.
+ *
+ * \retval 0 Success, value was found and copied into void pointer.
+ * \retval -1 failure, Value was either not found, or not allowed to be accessed.
+ */
+ int (* const format_attr_get_val)(const struct ast_format_attr *format_attr, int key, void *val);
};
/*!
@@ -218,7 +281,18 @@ void ast_format_clear(struct ast_format *format);
* \return 0, The format key value pairs are within the capabilities defined in this structure.
* \return -1, The format key value pairs are _NOT_ within the capabilities of this structure.
*/
-int ast_format_isset(struct ast_format *format, ... );
+int ast_format_isset(const struct ast_format *format, ... );
+
+/*!
+ * \brief Get a value from a format containing attributes.
+ * \note The key represents the format attribute to be retrieved, and the void pointer
+ * is to the structure that value will be stored in. It must be known what structure a
+ * key represents.
+ *
+ * \retval 0, success
+ * \retval -1, failure
+ */
+int ast_format_get_value(const struct ast_format *format, int key, void *value);
/*!
* \brief Compare ast_formats structures
@@ -287,6 +361,52 @@ struct ast_format *ast_format_from_old_bitfield(struct ast_format *dst, uint64_t
enum ast_format_id ast_format_id_from_old_bitfield(uint64_t src);
/*!
+ * \brief Retrieve the global format list in a read only array.
+ * \note ast_format_list_destroy must be called on every format
+ * list retrieved from this function.
+ */
+const struct ast_format_list *ast_format_list_get(size_t *size);
+
+/*!
+ * \brief Destroy an ast_format_list gotten from ast_format_list_get()
+ */
+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(const struct ast_format *format);
+
+/*! \brief Returns a string containing all formats pertaining to an format id.
+ * \param buf a buffer for the output string
+ * \param size size of buf (bytes)
+ * \param format id.
+ * \return The return value is buf.
+ */
+char* ast_getformatname_multiple_byid(char *buf, size_t size, enum ast_format_id id);
+
+/*!
+ * \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 Get the sample rate for a given format.
+ */
+int ast_format_rate(const struct ast_format *format);
+
+/*!
* \brief register ast_format_attr_interface with core.
*
* \retval 0 success
@@ -303,8 +423,12 @@ int ast_format_attr_reg_interface(const struct ast_format_attr_interface *interf
int ast_format_attr_unreg_interface(const struct ast_format_attr_interface *interface);
/*!
- * \brief Init the ast_format attribute interface register container.
+ * \brief Determine if a format is 16bit signed linear of any sample rate.
*/
-int ast_format_attr_init(void);
+int ast_format_is_slinear(const struct ast_format *format);
+/*!
+ * \brief Get the best slinear format id for a given sample rate
+ */
+enum ast_format_id ast_format_slin_by_rate(unsigned int rate);
#endif /* _AST_FORMAT_H */