summaryrefslogtreecommitdiff
path: root/codecs/codec_dahdi.c
diff options
context:
space:
mode:
authorDavid Vossel <dvossel@digium.com>2011-02-03 16:22:10 +0000
committerDavid Vossel <dvossel@digium.com>2011-02-03 16:22:10 +0000
commitc26c190711a1bbe3b5fff1a93facae333757c56e (patch)
tree00da0caa5a07b7b25729f089dbcafb08129fa9be /codecs/codec_dahdi.c
parent652fb64a01c7a8656697d07e606620ee0ced6929 (diff)
Asterisk media architecture conversion - no more format bitfields
This patch is the foundation of an entire new way of looking at media in Asterisk. The code present in this patch is everything required to complete phase1 of my Media Architecture proposal. For more information about this project visit the link below. https://wiki.asterisk.org/wiki/display/AST/Media+Architecture+Proposal The primary function of this patch is to convert all the usages of format bitfields in Asterisk to use the new format and format_cap APIs. Functionally no change in behavior should be present in this patch. Thanks to twilson and russell for all the time they spent reviewing these changes. Review: https://reviewboard.asterisk.org/r/1083/ git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@306010 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'codecs/codec_dahdi.c')
-rw-r--r--codecs/codec_dahdi.c55
1 files changed, 32 insertions, 23 deletions
diff --git a/codecs/codec_dahdi.c b/codecs/codec_dahdi.c
index 64b73cdc1..960a594f7 100644
--- a/codecs/codec_dahdi.c
+++ b/codecs/codec_dahdi.c
@@ -179,7 +179,7 @@ static int dahdi_encoder_framein(struct ast_trans_pvt *pvt, struct ast_frame *f)
{
struct codec_dahdi_pvt *dahdip = pvt->pvt;
- if (!f->subclass.codec) {
+ if (!f->subclass.format.id) {
/* We're just faking a return for calculation purposes. */
dahdip->fake = 2;
pvt->samples = f->samples;
@@ -227,7 +227,7 @@ static struct ast_frame *dahdi_encoder_frameout(struct ast_trans_pvt *pvt)
if (2 == dahdip->fake) {
dahdip->fake = 1;
pvt->f.frametype = AST_FRAME_VOICE;
- pvt->f.subclass.codec = 0;
+ ast_format_clear(&pvt->f.subclass.format);
pvt->f.samples = dahdip->required_samples;
pvt->f.data.ptr = NULL;
pvt->f.offset = 0;
@@ -255,7 +255,7 @@ static struct ast_frame *dahdi_encoder_frameout(struct ast_trans_pvt *pvt)
pvt->f.datalen = res;
pvt->f.samples = dahdip->required_samples;
pvt->f.frametype = AST_FRAME_VOICE;
- pvt->f.subclass.codec = 1 << (pvt->t->dstfmt);
+ 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;
@@ -274,7 +274,7 @@ static int dahdi_decoder_framein(struct ast_trans_pvt *pvt, struct ast_frame *f)
{
struct codec_dahdi_pvt *dahdip = pvt->pvt;
- if (!f->subclass.codec) {
+ if (!f->subclass.format.id) {
/* We're just faking a return for calculation purposes. */
dahdip->fake = 2;
pvt->samples = f->samples;
@@ -300,7 +300,7 @@ static struct ast_frame *dahdi_decoder_frameout(struct ast_trans_pvt *pvt)
if (2 == dahdip->fake) {
dahdip->fake = 1;
pvt->f.frametype = AST_FRAME_VOICE;
- pvt->f.subclass.codec = 0;
+ ast_format_clear(&pvt->f.subclass.format);
pvt->f.samples = dahdip->required_samples;
pvt->f.data.ptr = NULL;
pvt->f.offset = 0;
@@ -338,7 +338,7 @@ static struct ast_frame *dahdi_decoder_frameout(struct ast_trans_pvt *pvt)
}
pvt->datalen = 0;
pvt->f.frametype = AST_FRAME_VOICE;
- pvt->f.subclass.codec = 1 << (pvt->t->dstfmt);
+ 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;
@@ -371,7 +371,7 @@ static void dahdi_destroy(struct ast_trans_pvt *pvt)
close(dahdip->fd);
}
-static int dahdi_translate(struct ast_trans_pvt *pvt, int dest, int source)
+static int dahdi_translate(struct ast_trans_pvt *pvt, struct ast_format *dst_format, struct ast_format *src_format)
{
/* Request translation through zap if possible */
int fd;
@@ -385,10 +385,10 @@ static int dahdi_translate(struct ast_trans_pvt *pvt, int dest, int source)
return -1;
}
- dahdip->fmts.srcfmt = (1 << source);
- dahdip->fmts.dstfmt = (1 << dest);
+ 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 %d to %d.\n", source, dest);
+ ast_debug(1, "Opening transcoder channel from %s to %s.\n", ast_getformatname(src_format), ast_getformatname(dst_format));
retry:
if (ioctl(fd, DAHDI_TC_ALLOCATE, &dahdip->fmts)) {
@@ -401,14 +401,14 @@ retry:
* support for ULAW instead of signed linear and then
* we'll just convert from ulaw to signed linear in
* software. */
- if (AST_FORMAT_SLINEAR == dahdip->fmts.srcfmt) {
+ if (AST_FORMAT_SLINEAR == ast_format_id_from_old_bitfield(dahdip->fmts.srcfmt)) {
ast_debug(1, "Using soft_slin support on source\n");
dahdip->softslin = 1;
- dahdip->fmts.srcfmt = AST_FORMAT_ULAW;
- } else if (AST_FORMAT_SLINEAR == dahdip->fmts.dstfmt) {
+ 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)) {
ast_debug(1, "Using soft_slin support on destination\n");
dahdip->softslin = 1;
- dahdip->fmts.dstfmt = AST_FORMAT_ULAW;
+ dahdip->fmts.dstfmt = ast_format_id_to_old_bitfield(AST_FORMAT_ULAW);
}
tried_once = 1;
goto retry;
@@ -427,9 +427,9 @@ retry:
dahdip->fd = fd;
- dahdip->required_samples = ((dahdip->fmts.dstfmt|dahdip->fmts.srcfmt)&AST_FORMAT_G723_1) ? G723_SAMPLES : G729_SAMPLES;
+ dahdip->required_samples = ((dahdip->fmts.dstfmt|dahdip->fmts.srcfmt) & (ast_format_id_to_old_bitfield(AST_FORMAT_G723_1))) ? G723_SAMPLES : G729_SAMPLES;
- switch (dahdip->fmts.dstfmt) {
+ switch (ast_format_id_from_old_bitfield(dahdip->fmts.dstfmt)) {
case AST_FORMAT_G729A:
ast_atomic_fetchadd_int(&channels.encoders, +1);
break;
@@ -446,7 +446,9 @@ retry:
static int dahdi_new(struct ast_trans_pvt *pvt)
{
- return dahdi_translate(pvt, pvt->t->dstfmt, pvt->t->srcfmt);
+ return dahdi_translate(pvt,
+ &pvt->t->dst_format,
+ &pvt->t->src_format);
}
static struct ast_frame *fakesrc_sample(void)
@@ -463,7 +465,9 @@ static struct ast_frame *fakesrc_sample(void)
static int is_encoder(struct translator *zt)
{
- if (zt->t.srcfmt&(AST_FORMAT_ULAW|AST_FORMAT_ALAW|AST_FORMAT_SLINEAR)) {
+ 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)) {
return 1;
} else {
return 0;
@@ -474,15 +478,20 @@ static int register_translator(int dst, int src)
{
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((1 << src)), ast_getformatname((1 << dst)));
- zt->t.srcfmt = (1 << src);
- zt->t.dstfmt = (1 << dst);
+ 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);
zt->t.buf_size = BUFFER_SIZE;
if (is_encoder(zt)) {
zt->t.framein = dahdi_encoder_framein;
@@ -518,10 +527,10 @@ static void drop_translator(int dst, int src)
AST_LIST_LOCK(&translators);
AST_LIST_TRAVERSE_SAFE_BEGIN(&translators, cur, entry) {
- if (cur->t.srcfmt != src)
+ if (cur->t.src_format.id != ast_format_id_from_old_bitfield((1 << src)))
continue;
- if (cur->t.dstfmt != dst)
+ if (cur->t.dst_format.id != ast_format_id_from_old_bitfield((1 << dst)))
continue;
AST_LIST_REMOVE_CURRENT(entry);