]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
translate: generic plc not filled in after translation
authorKevin Harwell <kharwell@digium.com>
Wed, 18 Apr 2018 20:59:38 +0000 (15:59 -0500)
committerKevin Harwell <kharwell@digium.com>
Tue, 24 Apr 2018 20:54:17 +0000 (14:54 -0600)
If during translation a codec could not handle a given frame the translation
core would return NULL, thus not passing along the "missing" frame. Due to this
there was no frame to apply generic plc to, thus rendering it useless.

This patch makes it so the translation core produces an interpolated slin frame
in the cases where an attempt was made to translate to slin, but failed. This
interpolated frame is then passed along and can be used by the generic plc
algorithms to fill in the frame.

ASTERISK-27814 #close

Change-Id: I133d084da87adef913bf2ecc9c9240e3eaf4f40a

formats/format_sln.c
main/translate.c

index 6ad8c386e9350fe60b46cb8b730f56729bfeccc1..80d34840023cdca632950488002dba1fa8707af9 100644 (file)
@@ -54,6 +54,12 @@ static struct ast_frame *generic_read(struct ast_filestream *s, int *whennext, u
 static int slinear_write(struct ast_filestream *fs, struct ast_frame *f)
 {
        int res;
+
+       /* Don't try to write an interpolated frame */
+       if (f->datalen == 0) {
+               return 0;
+       }
+
        if ((res = fwrite(f->data.ptr, 1, f->datalen, fs->f)) != f->datalen) {
                        ast_log(LOG_WARNING, "Bad write (%d/%d): %s\n", res, f->datalen, strerror(errno));
                        return -1;
index 396c5522e18f64f8a24a1facbf360e6c2a03ef96..26f9c9beebba518d3aa1c905bfecc2c6921e98bd 100644 (file)
@@ -524,6 +524,34 @@ struct ast_trans_pvt *ast_translator_build_path(struct ast_format *dst, struct a
        return head;
 }
 
+static struct ast_frame *generate_interpolated_slin(struct ast_trans_pvt *p, struct ast_frame *f)
+{
+       struct ast_frame res = { AST_FRAME_VOICE };
+
+       /*
+        * If we've gotten here then we should have an interpolated frame that was not handled
+        * by the translation codec. So create an interpolated frame in the appropriate format
+        * that was going to be written. This frame might be handled later by other resources.
+        * For instance, generic plc.
+        *
+        * Note, generic plc is currently only available for the format type 'slin' (8KHz only -
+        * The generic plc code appears to have been based around that). Generic plc is filled
+        * in later on frame write.
+        */
+       if (!ast_opt_generic_plc || f->datalen != 0 ||
+               ast_format_cmp(p->explicit_dst, ast_format_slin) == AST_FORMAT_CMP_NOT_EQUAL) {
+               return NULL;
+       }
+
+       res.subclass.format = ast_format_cache_get_slin_by_rate(8000); /* ref bumped on dup */
+       res.samples = f->samples;
+       res.datalen = 0;
+       res.data.ptr = NULL;
+       res.offset = AST_FRIENDLY_OFFSET;
+
+       return ast_frdup(&res);
+}
+
 /*! \brief do the actual translation */
 struct ast_frame *ast_translate(struct ast_trans_pvt *path, struct ast_frame *f, int consume)
 {
@@ -586,6 +614,11 @@ struct ast_frame *ast_translate(struct ast_trans_pvt *path, struct ast_frame *f,
                }
                out = p->t->frameout(p);
        }
+
+       if (!out) {
+               out = generate_interpolated_slin(path, f);
+       }
+
        if (out) {
                /* we have a frame, play with times */
                if (!ast_tvzero(delivery)) {