diff --git a/include/asterisk/frame.h b/include/asterisk/frame.h index 012f7a9529..3206f860f8 100644 --- a/include/asterisk/frame.h +++ b/include/asterisk/frame.h @@ -611,6 +611,17 @@ int ast_frame_adjust_volume(struct ast_frame *f, int adjustment); */ int ast_frame_slinear_sum(struct ast_frame *f1, struct ast_frame *f2); +/*! + * \brief Get the sample rate for a given format. + */ +static force_inline int ast_format_rate(int format) +{ + if (format == AST_FORMAT_G722 || format == AST_FORMAT_SLINEAR16) + return 16000; + + return 8000; +} + #if defined(__cplusplus) || defined(c_plusplus) } #endif diff --git a/main/rtp.c b/main/rtp.c index 9777a5183a..5be0586c6e 100644 --- a/main/rtp.c +++ b/main/rtp.c @@ -1612,7 +1612,7 @@ struct ast_frame *ast_rtp_read(struct ast_rtp *rtp) /* Add timing data to let ast_generic_bridge() put the frame into a jitterbuf */ ast_set_flag(&rtp->f, AST_FRFLAG_HAS_TIMING_INFO); rtp->f.ts = timestamp / 8; - rtp->f.len = rtp->f.samples / 8; + rtp->f.len = rtp->f.samples / ( (ast_format_rate(rtp->f.subclass) == 16000) ? 16 : 8 ); } else if(rtp->f.subclass & AST_FORMAT_VIDEO_MASK) { /* Video -- samples is # of samples vs. 90000 */ if (!rtp->lastividtimestamp) diff --git a/main/translate.c b/main/translate.c index 83a93a4d25..be10b11b23 100644 --- a/main/translate.c +++ b/main/translate.c @@ -298,14 +298,6 @@ struct ast_trans_pvt *ast_translator_build_path(int dest, int source) return head; } -static inline int format_rate(int format) -{ - if (format == AST_FORMAT_G722 || format == AST_FORMAT_SLINEAR16) - return 16000; - - return 8000; -} - /*! \brief do the actual translation */ struct ast_frame *ast_translate(struct ast_trans_pvt *path, struct ast_frame *f, int consume) { @@ -342,7 +334,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, format_rate(f->subclass))); + path->nextin = ast_tvadd(path->nextin, ast_samp2tv(f->samples, ast_format_rate(f->subclass))); } delivery = f->delivery; for ( ; out && p ; p = p->next) { @@ -366,7 +358,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, format_rate(out->subclass))); + path->nextout = ast_tvadd(path->nextout, ast_samp2tv(out->samples, ast_format_rate(out->subclass))); } else { out->delivery = ast_tv(0, 0); ast_set2_flag(out, has_timing_info, AST_FRFLAG_HAS_TIMING_INFO); @@ -390,7 +382,7 @@ static void calc_cost(struct ast_translator *t, int seconds) struct rusage start; struct rusage end; int cost; - int out_rate = format_rate(t->dstfmt); + int out_rate = ast_format_rate(t->dstfmt); if (!seconds) seconds = 1;