[Asterisk-code-review] translate.c: Take sampling rate into account when checking codec's bu... (asterisk[master])

Friendly Automation asteriskteam at digium.com
Wed Apr 28 16:34:21 CDT 2021


Friendly Automation has submitted this change. ( https://gerrit.asterisk.org/c/asterisk/+/15801 )

Change subject: translate.c: Take sampling rate into account when checking codec's buffer size
......................................................................

translate.c: Take sampling rate into account when checking codec's buffer size

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
---
M main/translate.c
1 file changed, 7 insertions(+), 1 deletion(-)

Approvals:
  Joshua Colp: Looks good to me, but someone else must approve
  Kevin Harwell: Looks good to me, approved
  George Joseph: Looks good to me, but someone else must approve
  Friendly Automation: Approved for Submit



diff --git a/main/translate.c b/main/translate.c
index a9665ae..6604d14 100644
--- a/main/translate.c
+++ b/main/translate.c
@@ -408,12 +408,18 @@
 		}
 	}
 	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;
 		}

-- 
To view, visit https://gerrit.asterisk.org/c/asterisk/+/15801
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings

Gerrit-Project: asterisk
Gerrit-Branch: master
Gerrit-Change-Id: I9aebe2f8788e00321a7f5c47aa97c617f39e9055
Gerrit-Change-Number: 15801
Gerrit-PatchSet: 3
Gerrit-Owner: Jean Aunis - Prescom <jean.aunis at prescom.fr>
Gerrit-Reviewer: Friendly Automation
Gerrit-Reviewer: George Joseph <gjoseph at digium.com>
Gerrit-Reviewer: Joshua Colp <jcolp at sangoma.com>
Gerrit-Reviewer: Kevin Harwell <kharwell at digium.com>
Gerrit-CC: Sean Bright <sean at seanbright.com>
Gerrit-MessageType: merged
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20210428/02fbb9fa/attachment-0001.html>


More information about the asterisk-code-review mailing list