[asterisk-commits] rmudgett: branch group/media_formats-reviewed-trunk r418782 - in /team/group/...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Wed Jul 16 12:58:30 CDT 2014
Author: rmudgett
Date: Wed Jul 16 12:58:23 2014
New Revision: 418782
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=418782
Log:
codec_dahdi: Fix type mismatches and other badness.
* Fixed the BUGBUG issues.
* Fixed bitfield type mismatches. 3 != (1 << 3)
Review: https://reviewboard.asterisk.org/r/3803/
Modified:
team/group/media_formats-reviewed-trunk/codecs/codec_dahdi.c
team/group/media_formats-reviewed-trunk/include/asterisk/format_compatibility.h
team/group/media_formats-reviewed-trunk/main/format_compatibility.c
Modified: team/group/media_formats-reviewed-trunk/codecs/codec_dahdi.c
URL: http://svnview.digium.com/svn/asterisk/team/group/media_formats-reviewed-trunk/codecs/codec_dahdi.c?view=diff&rev=418782&r1=418781&r2=418782
==============================================================================
--- team/group/media_formats-reviewed-trunk/codecs/codec_dahdi.c (original)
+++ team/group/media_formats-reviewed-trunk/codecs/codec_dahdi.c Wed Jul 16 12:58:23 2014
@@ -59,17 +59,29 @@
#define G729_SAMPLES 160
#define ULAW_SAMPLES 160
+/* Defines from DAHDI. */
#ifndef DAHDI_FORMAT_MAX_AUDIO
+/*! G.723.1 compression */
#define DAHDI_FORMAT_G723_1 (1 << 0)
+/*! GSM compression */
#define DAHDI_FORMAT_GSM (1 << 1)
+/*! Raw mu-law data (G.711) */
#define DAHDI_FORMAT_ULAW (1 << 2)
+/*! Raw A-law data (G.711) */
#define DAHDI_FORMAT_ALAW (1 << 3)
+/*! ADPCM (G.726, 32kbps) */
#define DAHDI_FORMAT_G726 (1 << 4)
+/*! ADPCM (IMA) */
#define DAHDI_FORMAT_ADPCM (1 << 5)
+/*! Raw 16-bit Signed Linear (8000 Hz) PCM */
#define DAHDI_FORMAT_SLINEAR (1 << 6)
+/*! LPC10, 180 samples/frame */
#define DAHDI_FORMAT_LPC10 (1 << 7)
+/*! G.729A audio */
#define DAHDI_FORMAT_G729A (1 << 8)
+/*! SpeeX Free Compression */
#define DAHDI_FORMAT_SPEEX (1 << 9)
+/*! iLBC Free Compression */
#define DAHDI_FORMAT_ILBC (1 << 10)
#endif
@@ -79,68 +91,232 @@
int decoders;
} channels;
-/*
- * Good grief, this array is large and sparse! array[1 << 10], something like 80k
- *
- * BUGBUG Type mismatch: The users of the array only give a 0-31 index value not a (1 << (0-31)) index value.
+#if defined(NOT_NEEDED)
+/*!
+ * \internal
+ * \brief Convert DAHDI format bitfield to old Asterisk format bitfield.
+ * \since 13.0.0
+ *
+ * \param dahdi Bitfield from DAHDI to convert.
+ *
+ * \note They should be the same values but they don't have to be.
+ *
+ * \return Old Asterisk bitfield equivalent.
*/
-static struct ast_codec codecs[] = {
- [DAHDI_FORMAT_G723_1] = {
+static uint64_t bitfield_dahdi2ast(unsigned dahdi)
+{
+ uint64_t ast;
+
+ switch (dahdi) {
+ case DAHDI_FORMAT_G723_1:
+ ast = AST_FORMAT_G723;
+ break;
+ case DAHDI_FORMAT_GSM:
+ ast = AST_FORMAT_GSM;
+ break;
+ case DAHDI_FORMAT_ULAW:
+ ast = AST_FORMAT_ULAW;
+ break;
+ case DAHDI_FORMAT_ALAW:
+ ast = AST_FORMAT_ALAW;
+ break;
+ case DAHDI_FORMAT_G726:
+ ast = AST_FORMAT_G726_AAL2;
+ break;
+ case DAHDI_FORMAT_ADPCM:
+ ast = AST_FORMAT_ADPCM;
+ break;
+ case DAHDI_FORMAT_SLINEAR:
+ ast = AST_FORMAT_SLIN;
+ break;
+ case DAHDI_FORMAT_LPC10:
+ ast = AST_FORMAT_LPC10;
+ break;
+ case DAHDI_FORMAT_G729A:
+ ast = AST_FORMAT_G729;
+ break;
+ case DAHDI_FORMAT_SPEEX:
+ ast = AST_FORMAT_SPEEX;
+ break;
+ case DAHDI_FORMAT_ILBC:
+ ast = AST_FORMAT_ILBC;
+ break;
+ default:
+ ast = 0;
+ break;
+ }
+
+ return ast;
+}
+#endif /* defined(NOT_NEEDED) */
+
+/*!
+ * \internal
+ * \brief Convert old Asterisk format bitfield to DAHDI format bitfield.
+ * \since 13.0.0
+ *
+ * \param ast Old Asterisk bitfield to convert.
+ *
+ * \note They should be the same values but they don't have to be.
+ *
+ * \return DAHDI bitfield equivalent.
+ */
+static unsigned bitfield_ast2dahdi(uint64_t ast)
+{
+ unsigned dahdi;
+
+ switch (ast) {
+ case AST_FORMAT_G723:
+ dahdi = DAHDI_FORMAT_G723_1;
+ break;
+ case AST_FORMAT_GSM:
+ dahdi = DAHDI_FORMAT_GSM;
+ break;
+ case AST_FORMAT_ULAW:
+ dahdi = DAHDI_FORMAT_ULAW;
+ break;
+ case AST_FORMAT_ALAW:
+ dahdi = DAHDI_FORMAT_ALAW;
+ break;
+ case AST_FORMAT_G726_AAL2:
+ dahdi = DAHDI_FORMAT_G726;
+ break;
+ case AST_FORMAT_ADPCM:
+ dahdi = DAHDI_FORMAT_ADPCM;
+ break;
+ case AST_FORMAT_SLIN:
+ dahdi = DAHDI_FORMAT_SLINEAR;
+ break;
+ case AST_FORMAT_LPC10:
+ dahdi = DAHDI_FORMAT_LPC10;
+ break;
+ case AST_FORMAT_G729:
+ dahdi = DAHDI_FORMAT_G729A;
+ break;
+ case AST_FORMAT_SPEEX:
+ dahdi = DAHDI_FORMAT_SPEEX;
+ break;
+ case AST_FORMAT_ILBC:
+ dahdi = DAHDI_FORMAT_ILBC;
+ break;
+ default:
+ dahdi = 0;
+ break;
+ }
+
+ return dahdi;
+}
+
+/*!
+ * \internal
+ * \brief Get the DAHDI codec by index.
+ * \since 13.0.0
+ *
+ * \param idx Codex index (0-31).
+ *
+ * \return Specified codec if exists otherwise NULL.
+ */
+static const struct ast_codec *get_dahdi_codec(unsigned idx)
+{
+ const struct ast_codec *codec;
+
+ static const struct ast_codec dahdi_g723_1 = {
.name = "g723",
.type = AST_MEDIA_TYPE_AUDIO,
.sample_rate = 8000,
- },
- [DAHDI_FORMAT_GSM] = {
+ };
+ static const struct ast_codec dahdi_gsm = {
.name = "gsm",
.type = AST_MEDIA_TYPE_AUDIO,
.sample_rate = 8000,
- },
- [DAHDI_FORMAT_ULAW] = {
+ };
+ static const struct ast_codec dahdi_ulaw = {
.name = "ulaw",
.type = AST_MEDIA_TYPE_AUDIO,
.sample_rate = 8000,
- },
- [DAHDI_FORMAT_ALAW] = {
+ };
+ static const struct ast_codec dahdi_alaw = {
.name = "alaw",
.type = AST_MEDIA_TYPE_AUDIO,
.sample_rate = 8000,
- },
- [DAHDI_FORMAT_G726] = {
+ };
+ static const struct ast_codec dahdi_g726 = {
.name = "g726",
.type = AST_MEDIA_TYPE_AUDIO,
.sample_rate = 8000,
- },
- [DAHDI_FORMAT_ADPCM] = {
+ };
+ static const struct ast_codec dahdi_adpcm = {
.name = "adpcm",
.type = AST_MEDIA_TYPE_AUDIO,
.sample_rate = 8000,
- },
- [DAHDI_FORMAT_SLINEAR] = {
+ };
+ static const struct ast_codec dahdi_slinear = {
.name = "slin",
.type = AST_MEDIA_TYPE_AUDIO,
.sample_rate = 8000,
- },
- [DAHDI_FORMAT_LPC10] = {
+ };
+ static const struct ast_codec dahdi_lpc10 = {
.name = "lpc10",
.type = AST_MEDIA_TYPE_AUDIO,
.sample_rate = 8000,
- },
- [DAHDI_FORMAT_G729A] = {
+ };
+ static const struct ast_codec dahdi_g729a = {
.name = "g729",
.type = AST_MEDIA_TYPE_AUDIO,
.sample_rate = 8000,
- },
- [DAHDI_FORMAT_SPEEX] = {
+ };
+ static const struct ast_codec dahdi_speex = {
.name = "speex",
.type = AST_MEDIA_TYPE_AUDIO,
.sample_rate = 8000,
- },
- [DAHDI_FORMAT_ILBC] = {
+ };
+ static const struct ast_codec dahdi_ilbc = {
.name = "ilbc",
.type = AST_MEDIA_TYPE_AUDIO,
.sample_rate = 8000,
- },
-};
+ };
+
+ switch (1UL << idx) {
+ case DAHDI_FORMAT_G723_1:
+ codec = &dahdi_g723_1;
+ break;
+ case DAHDI_FORMAT_GSM:
+ codec = &dahdi_gsm;
+ break;
+ case DAHDI_FORMAT_ULAW:
+ codec = &dahdi_ulaw;
+ break;
+ case DAHDI_FORMAT_ALAW:
+ codec = &dahdi_alaw;
+ break;
+ case DAHDI_FORMAT_G726:
+ codec = &dahdi_g726;
+ break;
+ case DAHDI_FORMAT_ADPCM:
+ codec = &dahdi_adpcm;
+ break;
+ case DAHDI_FORMAT_SLINEAR:
+ codec = &dahdi_slinear;
+ break;
+ case DAHDI_FORMAT_LPC10:
+ codec = &dahdi_lpc10;
+ break;
+ case DAHDI_FORMAT_G729A:
+ codec = &dahdi_g729a;
+ break;
+ case DAHDI_FORMAT_SPEEX:
+ codec = &dahdi_speex;
+ break;
+ case DAHDI_FORMAT_ILBC:
+ codec = &dahdi_ilbc;
+ break;
+ default:
+ codec = NULL;
+ break;
+ }
+
+ return codec;
+}
static char *handle_cli_transcoder_show(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a);
@@ -309,20 +485,16 @@
int res;
if (2 == dahdip->fake) {
+ struct ast_frame frm = {
+ .frametype = AST_FRAME_VOICE,
+ .samples = dahdip->required_samples,
+ .src = pvt->t->name,
+ };
+
dahdip->fake = 1;
-/* BUGBUG need to setup a new static frame to prevent destroying the translators normal static frame. */
- pvt->f.frametype = AST_FRAME_VOICE;
- ao2_cleanup(pvt->f.subclass.format);
- pvt->f.subclass.format = NULL;
- pvt->f.samples = dahdip->required_samples;
- pvt->f.data.ptr = NULL;
- pvt->f.offset = 0;
- pvt->f.datalen = 0;
- pvt->f.mallocd = 0;
pvt->samples = 0;
- return ast_frisolate(&pvt->f);
-
+ return ast_frisolate(&frm);
} else if (1 == dahdip->fake) {
dahdip->fake = 0;
return NULL;
@@ -387,18 +559,16 @@
struct codec_dahdi_pvt *dahdip = pvt->pvt;
if (2 == dahdip->fake) {
+ struct ast_frame frm = {
+ .frametype = AST_FRAME_VOICE,
+ .samples = dahdip->required_samples,
+ .src = pvt->t->name,
+ };
+
dahdip->fake = 1;
-/* BUGBUG need to setup a new static frame to prevent destroying the translators normal static frame. */
- pvt->f.frametype = AST_FRAME_VOICE;
- ao2_cleanup(pvt->f.subclass.format);
- pvt->f.subclass.format = NULL;
- pvt->f.samples = dahdip->required_samples;
- pvt->f.data.ptr = NULL;
- pvt->f.offset = 0;
- pvt->f.datalen = 0;
- pvt->f.mallocd = 0;
pvt->samples = 0;
- return ast_frisolate(&pvt->f);
+
+ return ast_frisolate(&frm);
} else if (1 == dahdip->fake) {
pvt->samples = 0;
dahdip->fake = 0;
@@ -509,8 +679,8 @@
return -1;
}
- dahdip->fmts.srcfmt = ast_format_compatibility_codec2bitfield(src_codec);
- dahdip->fmts.dstfmt = ast_format_compatibility_codec2bitfield(dst_codec);
+ dahdip->fmts.srcfmt = bitfield_ast2dahdi(ast_format_compatibility_codec2bitfield(src_codec));
+ dahdip->fmts.dstfmt = bitfield_ast2dahdi(ast_format_compatibility_codec2bitfield(dst_codec));
ast_assert(pvt->f.subclass.format == NULL);
pvt->f.subclass.format = ao2_bump(dahdi_format_to_cached(dahdip->fmts.dstfmt));
@@ -601,19 +771,28 @@
}
}
-static int register_translator(int dst, int src)
-{
+static int register_translator(unsigned dst, unsigned src)
+{
+ const struct ast_codec *dst_codec;
+ const struct ast_codec *src_codec;
struct translator *zt;
int res;
+ dst_codec = get_dahdi_codec(dst);
+ src_codec = get_dahdi_codec(src);
+ if (!dst_codec || !src_codec) {
+ return -1;
+ }
+
if (!(zt = ast_calloc(1, sizeof(*zt)))) {
return -1;
}
- snprintf((char *) (zt->t.name), sizeof(zt->t.name), "zap%sto%s",
- codecs[src].name, codecs[dst].name);
- memcpy(&zt->t.src_codec, &codecs[src], sizeof(struct ast_codec));
- memcpy(&zt->t.dst_codec, &codecs[dst], sizeof(struct ast_codec));
+ snprintf(zt->t.name, sizeof(zt->t.name), "dahdi_%s_to_%s",
+ src_codec->name, dst_codec->name);
+
+ memcpy(&zt->t.src_codec, src_codec, sizeof(*src_codec));
+ memcpy(&zt->t.dst_codec, dst_codec, sizeof(*dst_codec));
zt->t.buf_size = BUFFER_SIZE;
if (is_encoder(zt)) {
zt->t.framein = dahdi_encoder_framein;
@@ -643,17 +822,20 @@
return res;
}
-static void drop_translator(int dst, int src)
+static void drop_translator(unsigned dst, unsigned src)
{
struct translator *cur;
AST_LIST_LOCK(&translators);
AST_LIST_TRAVERSE_SAFE_BEGIN(&translators, cur, entry) {
- if (ast_format_compatibility_codec2bitfield(cur->t.core_src_codec) != src)
+ if (bitfield_ast2dahdi(ast_format_compatibility_codec2bitfield(cur->t.core_src_codec))
+ != (1U << src)) {
continue;
-
- if (ast_format_compatibility_codec2bitfield(cur->t.core_dst_codec) != dst)
+ }
+ if (bitfield_ast2dahdi(ast_format_compatibility_codec2bitfield(cur->t.core_dst_codec))
+ != (1U << dst)) {
continue;
+ }
AST_LIST_REMOVE_CURRENT(entry);
ast_unregister_translator(&cur->t);
@@ -764,7 +946,6 @@
static int load_module(void)
{
- ast_ulaw_init();
find_transcoders();
ast_cli_register_multiple(cli, ARRAY_LEN(cli));
return AST_MODULE_LOAD_SUCCESS;
Modified: team/group/media_formats-reviewed-trunk/include/asterisk/format_compatibility.h
URL: http://svnview.digium.com/svn/asterisk/team/group/media_formats-reviewed-trunk/include/asterisk/format_compatibility.h?view=diff&rev=418782&r1=418781&r2=418782
==============================================================================
--- team/group/media_formats-reviewed-trunk/include/asterisk/format_compatibility.h (original)
+++ team/group/media_formats-reviewed-trunk/include/asterisk/format_compatibility.h Wed Jul 16 12:58:23 2014
@@ -29,6 +29,72 @@
struct ast_format;
struct ast_codec;
struct ast_format_cap;
+
+/*
+ * Legacy bitfields for specific formats
+ */
+
+/*! G.723.1 compression */
+#define AST_FORMAT_G723 (1ULL << 0)
+/*! GSM compression */
+#define AST_FORMAT_GSM (1ULL << 1)
+/*! Raw mu-law data (G.711) */
+#define AST_FORMAT_ULAW (1ULL << 2)
+/*! Raw A-law data (G.711) */
+#define AST_FORMAT_ALAW (1ULL << 3)
+/*! ADPCM (G.726, 32kbps, AAL2 codeword packing) */
+#define AST_FORMAT_G726_AAL2 (1ULL << 4)
+/*! ADPCM (IMA) */
+#define AST_FORMAT_ADPCM (1ULL << 5)
+/*! Raw 16-bit Signed Linear (8000 Hz) PCM */
+#define AST_FORMAT_SLIN (1ULL << 6)
+/*! LPC10, 180 samples/frame */
+#define AST_FORMAT_LPC10 (1ULL << 7)
+/*! G.729A audio */
+#define AST_FORMAT_G729 (1ULL << 8)
+/*! SpeeX Free Compression */
+#define AST_FORMAT_SPEEX (1ULL << 9)
+/*! iLBC Free Compression */
+#define AST_FORMAT_ILBC (1ULL << 10)
+/*! ADPCM (G.726, 32kbps, RFC3551 codeword packing) */
+#define AST_FORMAT_G726 (1ULL << 11)
+/*! G.722 */
+#define AST_FORMAT_G722 (1ULL << 12)
+/*! G.722.1 (also known as Siren7, 32kbps assumed) */
+#define AST_FORMAT_SIREN7 (1ULL << 13)
+/*! G.722.1 Annex C (also known as Siren14, 48kbps assumed) */
+#define AST_FORMAT_SIREN14 (1ULL << 14)
+/*! Raw 16-bit Signed Linear (16000 Hz) PCM */
+#define AST_FORMAT_SLIN16 (1ULL << 15)
+/*! G.719 (64 kbps assumed) */
+#define AST_FORMAT_G719 (1ULL << 32)
+/*! SpeeX Wideband (16kHz) Free Compression */
+#define AST_FORMAT_SPEEX16 (1ULL << 33)
+/*! Opus audio (8kHz, 16kHz, 24kHz, 48Khz) */
+#define AST_FORMAT_OPUS (1ULL << 34)
+/*! Raw testing-law data (G.711) */
+#define AST_FORMAT_TESTLAW (1ULL << 47)
+/*! H.261 Video */
+#define AST_FORMAT_H261 (1ULL << 18)
+/*! H.263 Video */
+#define AST_FORMAT_H263 (1ULL << 19)
+/*! H.263+ Video */
+#define AST_FORMAT_H263P (1ULL << 20)
+/*! H.264 Video */
+#define AST_FORMAT_H264 (1ULL << 21)
+/*! MPEG4 Video */
+#define AST_FORMAT_MP4 (1ULL << 22)
+/*! VP8 Video */
+#define AST_FORMAT_VP8 (1ULL << 23)
+/*! JPEG Images */
+#define AST_FORMAT_JPEG (1ULL << 16)
+/*! PNG Images */
+#define AST_FORMAT_PNG (1ULL << 17)
+/*! T.140 RED Text format RFC 4103 */
+#define AST_FORMAT_T140_RED (1ULL << 26)
+/*! T.140 Text format - ITU T.140, RFC 4103 */
+#define AST_FORMAT_T140 (1ULL << 27)
+
#define AST_CODEC_PREF_SIZE 64
struct ast_codec_pref {
Modified: team/group/media_formats-reviewed-trunk/main/format_compatibility.c
URL: http://svnview.digium.com/svn/asterisk/team/group/media_formats-reviewed-trunk/main/format_compatibility.c?view=diff&rev=418782&r1=418781&r2=418782
==============================================================================
--- team/group/media_formats-reviewed-trunk/main/format_compatibility.c (original)
+++ team/group/media_formats-reviewed-trunk/main/format_compatibility.c Wed Jul 16 12:58:23 2014
@@ -38,38 +38,6 @@
#include "asterisk/format_compatibility.h"
#include "asterisk/format_cache.h"
#include "asterisk/format_cap.h"
-
-/*! \brief Legacy bitfields for specific formats */
-#define AST_FORMAT_G723 (1ULL << 0)
-#define AST_FORMAT_GSM (1ULL << 1)
-#define AST_FORMAT_ULAW (1ULL << 2)
-#define AST_FORMAT_ALAW (1ULL << 3)
-#define AST_FORMAT_G726_AAL2 (1ULL << 4)
-#define AST_FORMAT_ADPCM (1ULL << 5)
-#define AST_FORMAT_SLIN (1ULL << 6)
-#define AST_FORMAT_LPC10 (1ULL << 7)
-#define AST_FORMAT_G729 (1ULL << 8)
-#define AST_FORMAT_SPEEX (1ULL << 9)
-#define AST_FORMAT_ILBC (1ULL << 10)
-#define AST_FORMAT_G726 (1ULL << 11)
-#define AST_FORMAT_G722 (1ULL << 12)
-#define AST_FORMAT_SIREN7 (1ULL << 13)
-#define AST_FORMAT_SIREN14 (1ULL << 14)
-#define AST_FORMAT_SLIN16 (1ULL << 15)
-#define AST_FORMAT_G719 (1ULL << 32)
-#define AST_FORMAT_SPEEX16 (1ULL << 33)
-#define AST_FORMAT_OPUS (1ULL << 34)
-#define AST_FORMAT_TESTLAW (1ULL << 47)
-#define AST_FORMAT_H261 (1ULL << 18)
-#define AST_FORMAT_H263 (1ULL << 19)
-#define AST_FORMAT_H263P (1ULL << 20)
-#define AST_FORMAT_H264 (1ULL << 21)
-#define AST_FORMAT_MP4 (1ULL << 22)
-#define AST_FORMAT_VP8 (1ULL << 23)
-#define AST_FORMAT_JPEG (1ULL << 16)
-#define AST_FORMAT_PNG (1ULL << 17)
-#define AST_FORMAT_T140_RED (1ULL << 26)
-#define AST_FORMAT_T140 (1ULL << 27)
uint64_t ast_format_compatibility_format2bitfield(const struct ast_format *format)
{
More information about the asterisk-commits
mailing list