mirror of
https://github.com/asterisk/asterisk.git
synced 2025-09-19 11:42:27 +00:00
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: https://origsvn.digium.com/svn/asterisk/trunk@98024 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
@@ -287,12 +287,12 @@ struct ast_trans_pvt *ast_translator_build_path(int dest, int source)
|
|||||||
return head;
|
return head;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int is16kHz(int format)
|
static inline int format_rate(int format)
|
||||||
{
|
{
|
||||||
if (format == AST_FORMAT_G722 || format == AST_FORMAT_SLINEAR16)
|
if (format == AST_FORMAT_G722 || format == AST_FORMAT_SLINEAR16)
|
||||||
return 1;
|
return 16000;
|
||||||
|
|
||||||
return 0;
|
return 8000;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*! \brief do the actual translation */
|
/*! \brief do the actual translation */
|
||||||
@@ -313,11 +313,6 @@ struct ast_frame *ast_translate(struct ast_trans_pvt *path, struct ast_frame *f,
|
|||||||
|
|
||||||
/* XXX hmmm... check this below */
|
/* XXX hmmm... check this below */
|
||||||
if (!ast_tvzero(f->delivery)) {
|
if (!ast_tvzero(f->delivery)) {
|
||||||
int in_rate = 8000;
|
|
||||||
|
|
||||||
if (is16kHz(f->subclass))
|
|
||||||
in_rate = 16000;
|
|
||||||
|
|
||||||
if (!ast_tvzero(path->nextin)) {
|
if (!ast_tvzero(path->nextin)) {
|
||||||
/* Make sure this is in line with what we were expecting */
|
/* Make sure this is in line with what we were expecting */
|
||||||
if (!ast_tveq(path->nextin, f->delivery)) {
|
if (!ast_tveq(path->nextin, f->delivery)) {
|
||||||
@@ -336,7 +331,7 @@ struct ast_frame *ast_translate(struct ast_trans_pvt *path, struct ast_frame *f,
|
|||||||
path->nextout = f->delivery;
|
path->nextout = f->delivery;
|
||||||
}
|
}
|
||||||
/* Predict next incoming sample */
|
/* 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;
|
delivery = f->delivery;
|
||||||
for ( ; out && p ; p = p->next) {
|
for ( ; out && p ; p = p->next) {
|
||||||
@@ -349,11 +344,6 @@ struct ast_frame *ast_translate(struct ast_trans_pvt *path, struct ast_frame *f,
|
|||||||
return NULL;
|
return NULL;
|
||||||
/* we have a frame, play with times */
|
/* we have a frame, play with times */
|
||||||
if (!ast_tvzero(delivery)) {
|
if (!ast_tvzero(delivery)) {
|
||||||
int out_rate = 8000;
|
|
||||||
|
|
||||||
if (is16kHz(out->subclass))
|
|
||||||
out_rate = 16000;
|
|
||||||
|
|
||||||
/* Regenerate prediction after a discontinuity */
|
/* Regenerate prediction after a discontinuity */
|
||||||
if (ast_tvzero(path->nextout))
|
if (ast_tvzero(path->nextout))
|
||||||
path->nextout = ast_tvnow();
|
path->nextout = ast_tvnow();
|
||||||
@@ -363,7 +353,7 @@ struct ast_frame *ast_translate(struct ast_trans_pvt *path, struct ast_frame *f,
|
|||||||
|
|
||||||
/* Predict next outgoing timestamp from samples in this
|
/* Predict next outgoing timestamp from samples in this
|
||||||
frame. */
|
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 {
|
} else {
|
||||||
out->delivery = ast_tv(0, 0);
|
out->delivery = ast_tv(0, 0);
|
||||||
out->has_timing_info = has_timing_info;
|
out->has_timing_info = has_timing_info;
|
||||||
@@ -387,10 +377,7 @@ static void calc_cost(struct ast_translator *t, int seconds)
|
|||||||
struct rusage start;
|
struct rusage start;
|
||||||
struct rusage end;
|
struct rusage end;
|
||||||
int cost;
|
int cost;
|
||||||
int out_rate = 8000;
|
int out_rate = format_rate(t->dstfmt);
|
||||||
|
|
||||||
if (is16kHz(t->dstfmt))
|
|
||||||
out_rate = 16000;
|
|
||||||
|
|
||||||
if (!seconds)
|
if (!seconds)
|
||||||
seconds = 1;
|
seconds = 1;
|
||||||
|
Reference in New Issue
Block a user