aboutsummaryrefslogtreecommitdiffstats
path: root/main/translate.c
diff options
context:
space:
mode:
authorrussell <russell@f38db490-d61c-443f-a65b-d21fe96a405b>2008-01-11 00:14:59 +0000
committerrussell <russell@f38db490-d61c-443f-a65b-d21fe96a405b>2008-01-11 00:14:59 +0000
commit9005a1169b0918fce0b6c2a93d45b617f06c82bb (patch)
tree49d1e766a7ff7ae5b29b7edf48adf20e78fb391a /main/translate.c
parent5850da7e803cbf49fba1bbd6a869e26e678b2576 (diff)
Simplify this code with a suggestion from Luigi on the asterisk-dev list.
Instead of using is16kHz(), implement a format_rate() function. git-svn-id: http://svn.digium.com/svn/asterisk/branches/1.4@98025 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'main/translate.c')
-rw-r--r--main/translate.c25
1 files changed, 6 insertions, 19 deletions
diff --git a/main/translate.c b/main/translate.c
index 05d002a7d..ba115ed62 100644
--- a/main/translate.c
+++ b/main/translate.c
@@ -294,12 +294,12 @@ struct ast_trans_pvt *ast_translator_build_path(int dest, int source)
return head;
}
-static inline int is16kHz(int format)
+static inline int format_rate(int format)
{
if (format == AST_FORMAT_G722)
- return 1;
+ return 16000;
- return 0;
+ return 8000;
}
/*! \brief do the actual translation */
@@ -320,11 +320,6 @@ struct ast_frame *ast_translate(struct ast_trans_pvt *path, struct ast_frame *f,
/* XXX hmmm... check this below */
if (!ast_tvzero(f->delivery)) {
- int in_rate = 8000;
-
- if (is16kHz(f->subclass))
- in_rate = 16000;
-
if (!ast_tvzero(path->nextin)) {
/* Make sure this is in line with what we were expecting */
if (!ast_tveq(path->nextin, f->delivery)) {
@@ -343,7 +338,7 @@ struct ast_frame *ast_translate(struct ast_trans_pvt *path, struct ast_frame *f,
path->nextout = f->delivery;
}
/* Predict next incoming sample */
- path->nextin = ast_tvadd(path->nextin, ast_samp2tv(f->samples, in_rate));
+ path->nextin = ast_tvadd(path->nextin, ast_samp2tv(f->samples, format_rate(f->subclass)));
}
delivery = f->delivery;
for ( ; out && p ; p = p->next) {
@@ -356,11 +351,6 @@ struct ast_frame *ast_translate(struct ast_trans_pvt *path, struct ast_frame *f,
return NULL;
/* we have a frame, play with times */
if (!ast_tvzero(delivery)) {
- int out_rate = 8000;
-
- if (is16kHz(out->subclass))
- out_rate = 16000;
-
/* Regenerate prediction after a discontinuity */
if (ast_tvzero(path->nextout))
path->nextout = ast_tvnow();
@@ -370,7 +360,7 @@ struct ast_frame *ast_translate(struct ast_trans_pvt *path, struct ast_frame *f,
/* Predict next outgoing timestamp from samples in this
frame. */
- path->nextout = ast_tvadd(path->nextout, ast_samp2tv(out->samples, out_rate));
+ path->nextout = ast_tvadd(path->nextout, ast_samp2tv(out->samples, format_rate(out->subclass)));
} else {
out->delivery = ast_tv(0, 0);
out->has_timing_info = has_timing_info;
@@ -393,10 +383,7 @@ static void calc_cost(struct ast_translator *t, int seconds)
struct ast_trans_pvt *pvt;
struct timeval start;
int cost;
- int out_rate = 8000;
-
- if (is16kHz(t->dstfmt))
- out_rate = 16000;
+ int out_rate = format_rate(t->dstfmt);
if (!seconds)
seconds = 1;