]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
translate.c: Take sampling rate into account when checking codec's buffer size
authorJean Aunis <jean.aunis@prescom.fr>
Wed, 21 Apr 2021 11:42:32 +0000 (13:42 +0200)
committerJean Aunis - Prescom <jean.aunis@prescom.fr>
Wed, 28 Apr 2021 06:16:07 +0000 (01:16 -0500)
Up/down sampling changes the number of samples produced by a translation.
This must be taken into account when checking the codec's buffer size.

ASTERISK-29328

Change-Id: I9aebe2f8788e00321a7f5c47aa97c617f39e9055

main/translate.c

index a9665ae348cee990630cd348d660955bef6af7f0..6604d14ff42491d48a9cbb1bd296fe726a2ef1ee 100644 (file)
@@ -408,12 +408,18 @@ static int framein(struct ast_trans_pvt *pvt, struct ast_frame *f)
                }
        }
        if (pvt->t->buffer_samples) {   /* do not pass empty frames to callback */
+               int src_srate = pvt->t->src_codec.sample_rate;
+               int dst_srate = pvt->t->dst_codec.sample_rate;
+
+               ast_assert(src_srate > 0);
+
                if (f->datalen == 0) { /* perform native PLC if available */
                        /* If the codec has native PLC, then do that */
                        if (!pvt->t->native_plc)
                                return 0;
                }
-               if (pvt->samples + f->samples > pvt->t->buffer_samples) {
+
+               if (pvt->samples + (f->samples * dst_srate / src_srate) > pvt->t->buffer_samples) {
                        ast_log(LOG_WARNING, "Out of buffer space\n");
                        return -1;
                }