[asterisk-commits] file: branch group/media_formats r407955 - in /team/group/media_formats: code...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Tue Feb 11 08:43:35 CST 2014
Author: file
Date: Tue Feb 11 08:43:30 2014
New Revision: 407955
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=407955
Log:
Move codec_dahdi over to using core codecs.
Internally codec_dahdi uses the old bitfields with some translation to/from
the new codecs + formats.
Modified:
team/group/media_formats/codecs/codec_dahdi.c
team/group/media_formats/include/asterisk/format_cache.h
Modified: team/group/media_formats/codecs/codec_dahdi.c
URL: http://svnview.digium.com/svn/asterisk/team/group/media_formats/codecs/codec_dahdi.c?view=diff&rev=407955&r1=407954&r2=407955
==============================================================================
--- team/group/media_formats/codecs/codec_dahdi.c (original)
+++ team/group/media_formats/codecs/codec_dahdi.c Tue Feb 11 08:43:30 2014
@@ -78,6 +78,64 @@
int decoders;
} channels;
+static struct ast_codec codecs[] = {
+ [DAHDI_FORMAT_G723_1] = {
+ .name = "g723",
+ .type = AST_MEDIA_TYPE_AUDIO,
+ .sample_rate = 8000,
+ },
+ [DAHDI_FORMAT_GSM] = {
+ .name = "gsm",
+ .type = AST_MEDIA_TYPE_AUDIO,
+ .sample_rate = 8000,
+ },
+ [DAHDI_FORMAT_ULAW] = {
+ .name = "ulaw",
+ .type = AST_MEDIA_TYPE_AUDIO,
+ .sample_rate = 8000,
+ },
+ [DAHDI_FORMAT_ALAW] = {
+ .name = "alaw",
+ .type = AST_MEDIA_TYPE_AUDIO,
+ .sample_rate = 8000,
+ },
+ [DAHDI_FORMAT_G726] = {
+ .name = "g726",
+ .type = AST_MEDIA_TYPE_AUDIO,
+ .sample_rate = 8000,
+ },
+ [DAHDI_FORMAT_ADPCM] = {
+ .name = "adpcm",
+ .type = AST_MEDIA_TYPE_AUDIO,
+ .sample_rate = 8000,
+ },
+ [DAHDI_FORMAT_SLINEAR] = {
+ .name = "slin",
+ .type = AST_MEDIA_TYPE_AUDIO,
+ .sample_rate = 8000,
+ },
+ [DAHDI_FORMAT_LPC10] = {
+ .name = "lpc10",
+ .type = AST_MEDIA_TYPE_AUDIO,
+ .sample_rate = 8000,
+ },
+ [DAHDI_FORMAT_G729A] = {
+ .name = "g729",
+ .type = AST_MEDIA_TYPE_AUDIO,
+ .sample_rate = 8000,
+ },
+ [DAHDI_FORMAT_SPEEX] = {
+ .name = "speex",
+ .type = AST_MEDIA_TYPE_AUDIO,
+ .sample_rate = 8000,
+ },
+ [DAHDI_FORMAT_ILBC] = {
+ .name = "ilbc",
+ .type = AST_MEDIA_TYPE_AUDIO,
+ .sample_rate = 8000,
+ },
+};
+
static char *handle_cli_transcoder_show(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a);
static struct ast_cli_entry cli[] = {
@@ -190,7 +248,7 @@
{
struct codec_dahdi_pvt *dahdip = pvt->pvt;
- if (!f->subclass.format.id) {
+ if (!f->subclass.format) {
/* We're just faking a return for calculation purposes. */
dahdip->fake = 2;
pvt->samples = f->samples;
@@ -247,7 +305,8 @@
if (2 == dahdip->fake) {
dahdip->fake = 1;
pvt->f.frametype = AST_FRAME_VOICE;
- ast_format_clear(&pvt->f.subclass.format);
+ 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;
@@ -277,13 +336,7 @@
}
} else {
pvt->f.datalen = res;
- pvt->f.frametype = AST_FRAME_VOICE;
- ast_format_copy(&pvt->f.subclass.format, &pvt->t->dst_format);
- pvt->f.mallocd = 0;
- pvt->f.offset = AST_FRIENDLY_OFFSET;
- pvt->f.src = pvt->t->name;
- pvt->f.data.ptr = pvt->outbuf.c;
- pvt->f.samples = ast_codec_get_samples(&pvt->f);
+ pvt->f.samples = ast_codec_samples_count(&pvt->f);
dahdip->samples_written_to_hardware =
(dahdip->samples_written_to_hardware >= pvt->f.samples) ?
@@ -302,7 +355,7 @@
{
struct codec_dahdi_pvt *dahdip = pvt->pvt;
- if (!f->subclass.format.id) {
+ if (!f->subclass.format) {
/* We're just faking a return for calculation purposes. */
dahdip->fake = 2;
pvt->samples = f->samples;
@@ -329,7 +382,8 @@
if (2 == dahdip->fake) {
dahdip->fake = 1;
pvt->f.frametype = AST_FRAME_VOICE;
- ast_format_clear(&pvt->f.subclass.format);
+ 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;
@@ -370,12 +424,6 @@
pvt->f.datalen = res;
}
pvt->datalen = 0;
- pvt->f.frametype = AST_FRAME_VOICE;
- ast_format_copy(&pvt->f.subclass.format, &pvt->t->dst_format);
- pvt->f.mallocd = 0;
- pvt->f.offset = AST_FRIENDLY_OFFSET;
- pvt->f.src = pvt->t->name;
- pvt->f.data.ptr = pvt->outbuf.c;
pvt->f.samples = res;
pvt->samples = 0;
dahdip->samples_written_to_hardware =
@@ -394,9 +442,9 @@
{
struct codec_dahdi_pvt *dahdip = pvt->pvt;
- switch (ast_format_id_from_old_bitfield(dahdip->fmts.dstfmt)) {
- case AST_FORMAT_G729A:
- case AST_FORMAT_G723_1:
+ switch (dahdip->fmts.dstfmt) {
+ case DAHDI_FORMAT_G729A:
+ case DAHDI_FORMAT_G723_1:
ast_atomic_fetchadd_int(&channels.encoders, -1);
break;
default:
@@ -404,10 +452,43 @@
break;
}
+ ao2_cleanup(pvt->f.subclass.format);
+
close(dahdip->fd);
}
-static int dahdi_translate(struct ast_trans_pvt *pvt, struct ast_format *dst_format, struct ast_format *src_format)
+static struct ast_format *dahdi_format_to_cached(int format)
+{
+ switch (format) {
+ case DAHDI_FORMAT_G723_1:
+ return ast_format_g723;
+ case DAHDI_FORMAT_GSM:
+ return ast_format_gsm;
+ case DAHDI_FORMAT_ULAW:
+ return ast_format_ulaw;
+ case DAHDI_FORMAT_ALAW:
+ return ast_format_alaw;
+ case DAHDI_FORMAT_G726:
+ return ast_format_g726;
+ case DAHDI_FORMAT_ADPCM:
+ return ast_format_adpcm;
+ case DAHDI_FORMAT_SLINEAR:
+ return ast_format_slin;
+ case DAHDI_FORMAT_LPC10:
+ return ast_format_lpc10;
+ case DAHDI_FORMAT_G729A:
+ return ast_format_g729;
+ case DAHDI_FORMAT_SPEEX:
+ return ast_format_speex;
+ case DAHDI_FORMAT_ILBC:
+ return ast_format_ilbc;
+ }
+
+ /* This will never be reached */
+ return NULL;
+}
+
+static int dahdi_translate(struct ast_trans_pvt *pvt, struct ast_codec *dst_codec, struct ast_codec *src_codec)
{
/* Request translation through zap if possible */
int fd;
@@ -421,10 +502,17 @@
return -1;
}
- dahdip->fmts.srcfmt = ast_format_to_old_bitfield(src_format);
- dahdip->fmts.dstfmt = ast_format_to_old_bitfield(dst_format);
-
- ast_debug(1, "Opening transcoder channel from %s to %s.\n", ast_getformatname(src_format), ast_getformatname(dst_format));
+ dahdip->fmts.srcfmt = src_codec->original_id;
+ dahdip->fmts.dstfmt = dst_codec->original_id;
+
+ pvt->f.frametype = AST_FRAME_VOICE;
+ pvt->f.subclass.format = ast_format_copy(dahdi_format_to_cached(dst_codec->original_id));
+ pvt->f.mallocd = 0;
+ pvt->f.offset = AST_FRIENDLY_OFFSET;
+ pvt->f.src = pvt->t->name;
+ pvt->f.data.ptr = pvt->outbuf.c;
+
+ ast_debug(1, "Opening transcoder channel from %s to %s.\n", src_codec->name, dst_codec->name);
retry:
if (ioctl(fd, DAHDI_TC_ALLOCATE, &dahdip->fmts)) {
@@ -437,14 +525,14 @@
* support for ULAW instead of signed linear and then
* we'll just convert from ulaw to signed linear in
* software. */
- if (AST_FORMAT_SLINEAR == ast_format_id_from_old_bitfield(dahdip->fmts.srcfmt)) {
+ if (dahdip->fmts.srcfmt == DAHDI_FORMAT_SLINEAR) {
ast_debug(1, "Using soft_slin support on source\n");
dahdip->softslin = 1;
- dahdip->fmts.srcfmt = ast_format_id_to_old_bitfield(AST_FORMAT_ULAW);
- } else if (AST_FORMAT_SLINEAR == ast_format_id_from_old_bitfield(dahdip->fmts.dstfmt)) {
+ dahdip->fmts.srcfmt = DAHDI_FORMAT_ULAW;
+ } else if (dahdip->fmts.dstfmt == DAHDI_FORMAT_SLINEAR) {
ast_debug(1, "Using soft_slin support on destination\n");
dahdip->softslin = 1;
- dahdip->fmts.dstfmt = ast_format_id_to_old_bitfield(AST_FORMAT_ULAW);
+ dahdip->fmts.dstfmt = DAHDI_FORMAT_ULAW;
}
tried_once = 1;
goto retry;
@@ -463,13 +551,13 @@
dahdip->fd = fd;
- dahdip->required_samples = ((dahdip->fmts.dstfmt|dahdip->fmts.srcfmt) & (ast_format_id_to_old_bitfield(AST_FORMAT_G723_1))) ? G723_SAMPLES : G729_SAMPLES;
-
- switch (ast_format_id_from_old_bitfield(dahdip->fmts.dstfmt)) {
- case AST_FORMAT_G729A:
+ dahdip->required_samples = ((dahdip->fmts.dstfmt|dahdip->fmts.srcfmt) & (DAHDI_FORMAT_G723_1)) ? G723_SAMPLES : G729_SAMPLES;
+
+ switch (dahdip->fmts.dstfmt) {
+ case DAHDI_FORMAT_G729A:
ast_atomic_fetchadd_int(&channels.encoders, +1);
break;
- case AST_FORMAT_G723_1:
+ case DAHDI_FORMAT_G723_1:
ast_atomic_fetchadd_int(&channels.encoders, +1);
break;
default:
@@ -483,8 +571,8 @@
static int dahdi_new(struct ast_trans_pvt *pvt)
{
return dahdi_translate(pvt,
- &pvt->t->dst_format,
- &pvt->t->src_format);
+ pvt->t->core_dst_codec,
+ pvt->t->core_src_codec);
}
static struct ast_frame *fakesrc_sample(void)
@@ -501,9 +589,9 @@
static int is_encoder(struct translator *zt)
{
- if ((zt->t.src_format.id == AST_FORMAT_ULAW) ||
- (zt->t.src_format.id == AST_FORMAT_ALAW) ||
- (zt->t.src_format.id == AST_FORMAT_SLINEAR)) {
+ if ((zt->t.core_src_codec->original_id == DAHDI_FORMAT_ULAW) ||
+ (zt->t.core_src_codec->original_id == DAHDI_FORMAT_ALAW) ||
+ (zt->t.core_src_codec->original_id == DAHDI_FORMAT_SLINEAR)) {
return 1;
} else {
return 0;
@@ -514,20 +602,15 @@
{
struct translator *zt;
int res;
- struct ast_format dst_format;
- struct ast_format src_format;
-
- ast_format_from_old_bitfield(&dst_format, (1 << dst));
- ast_format_from_old_bitfield(&src_format, (1 << src));
if (!(zt = ast_calloc(1, sizeof(*zt)))) {
return -1;
}
snprintf((char *) (zt->t.name), sizeof(zt->t.name), "zap%sto%s",
- ast_getformatname(&src_format), ast_getformatname(&dst_format));
- ast_format_copy(&zt->t.src_format, &src_format);
- ast_format_copy(&zt->t.dst_format, &dst_format);
+ 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));
zt->t.buf_size = BUFFER_SIZE;
if (is_encoder(zt)) {
zt->t.framein = dahdi_encoder_framein;
@@ -563,10 +646,10 @@
AST_LIST_LOCK(&translators);
AST_LIST_TRAVERSE_SAFE_BEGIN(&translators, cur, entry) {
- if (cur->t.src_format.id != ast_format_id_from_old_bitfield((1 << src)))
+ if (cur->t.core_src_codec->original_id != src)
continue;
- if (cur->t.dst_format.id != ast_format_id_from_old_bitfield((1 << dst)))
+ if (cur->t.core_dst_codec->original_id != dst)
continue;
AST_LIST_REMOVE_CURRENT(entry);
Modified: team/group/media_formats/include/asterisk/format_cache.h
URL: http://svnview.digium.com/svn/asterisk/team/group/media_formats/include/asterisk/format_cache.h?view=diff&rev=407955&r1=407954&r2=407955
==============================================================================
--- team/group/media_formats/include/asterisk/format_cache.h (original)
+++ team/group/media_formats/include/asterisk/format_cache.h Tue Feb 11 08:43:30 2014
@@ -124,6 +124,16 @@
extern struct ast_format *ast_format_speex16;
/*!
+ * \brief Built-in cached g723.1 format.
+ */
+extern struct ast_format *ast_format_g723;
+
+/*!
+ * \brief Built-in cached g729 format.
+ */
+extern struct ast_format *ast_format_g729;
+
+/*!
* \brief Initialize format cache support within the core.
*
* \retval 0 success
More information about the asterisk-commits
mailing list