]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
Fix a bug that I just noticed in the RTP code. The calculation for setting the
authorRussell Bryant <russell@russellbryant.com>
Wed, 5 Mar 2008 01:52:18 +0000 (01:52 +0000)
committerRussell Bryant <russell@russellbryant.com>
Wed, 5 Mar 2008 01:52:18 +0000 (01:52 +0000)
len field in an ast_frame of audio was wrong when G.722 is in use.  The len field
represents the number of ms of audio that the frame contains.  It would have
set the value to be twice what it should be.

git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/1.4@105932 65c4cc65-6c06-0410-ace0-fbb531ad65f3

include/asterisk/frame.h
main/rtp.c
main/translate.c

index fc3481136bb883ddf9d4c3cfd0d684ca9c118fc2..3f15430280084f4602c61350f8857d5c6c5e1398 100644 (file)
@@ -569,6 +569,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)
+               return 16000;
+
+       return 8000;
+}
+
 #if defined(__cplusplus) || defined(c_plusplus)
 }
 #endif
index cec29dc4af592acaeade008df1be51509c8fbde1..6578c400e49a96ca2bdec018ded2522138ed0c21 100644 (file)
@@ -1313,7 +1313,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 {
                /* Video -- samples is # of samples vs. 90000 */
                if (!rtp->lastividtimestamp)
index 0aa21df122f32dfe9644db34f5209e1e6a85874b..3f5466d1fa4207d4afadcda7ca9f488ffd32ca8b 100644 (file)
@@ -306,14 +306,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)
-               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)
 {
@@ -350,7 +342,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) {
@@ -374,7 +366,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);
@@ -397,7 +389,7 @@ static void calc_cost(struct ast_translator *t, int seconds)
        struct ast_trans_pvt *pvt;
        struct timeval start;
        int cost;
-       int out_rate = format_rate(t->dstfmt);
+       int out_rate = ast_format_rate(t->dstfmt);
 
        if (!seconds)
                seconds = 1;