[Asterisk-code-review] translate: generic plc not filled in after translation (asterisk[certified/13.18])

Jenkins2 asteriskteam at digium.com
Thu May 3 10:19:17 CDT 2018


Jenkins2 has submitted this change and it was merged. ( https://gerrit.asterisk.org/8823 )

Change subject: translate: generic plc not filled in after translation
......................................................................

translate: generic plc not filled in after translation

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
---
M formats/format_sln.c
M main/translate.c
2 files changed, 39 insertions(+), 0 deletions(-)

Approvals:
  Joshua Colp: Looks good to me, but someone else must approve
  Benjamin Keith Ford: Looks good to me, but someone else must approve
  George Joseph: Looks good to me, approved
  Jenkins2: Approved for Submit



diff --git a/formats/format_sln.c b/formats/format_sln.c
index b81046c..01fbb6d 100644
--- a/formats/format_sln.c
+++ b/formats/format_sln.c
@@ -56,6 +56,12 @@
 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;
diff --git a/main/translate.c b/main/translate.c
index e1a7d9f..c21b3cc 100644
--- a/main/translate.c
+++ b/main/translate.c
@@ -527,6 +527,34 @@
 	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)
 {
@@ -578,6 +606,11 @@
 		}
 		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)) {

-- 
To view, visit https://gerrit.asterisk.org/8823
To unsubscribe, visit https://gerrit.asterisk.org/settings

Gerrit-Project: asterisk
Gerrit-Branch: certified/13.18
Gerrit-MessageType: merged
Gerrit-Change-Id: I133d084da87adef913bf2ecc9c9240e3eaf4f40a
Gerrit-Change-Number: 8823
Gerrit-PatchSet: 2
Gerrit-Owner: Kevin Harwell <kharwell at digium.com>
Gerrit-Reviewer: Benjamin Keith Ford <bford at digium.com>
Gerrit-Reviewer: George Joseph <gjoseph at digium.com>
Gerrit-Reviewer: Jenkins2
Gerrit-Reviewer: Joshua Colp <jcolp at digium.com>
Gerrit-Reviewer: Kevin Harwell <kharwell at digium.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20180503/52e0cfc6/attachment.html>


More information about the asterisk-code-review mailing list