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

Jean Aunis - Prescom asteriskteam at digium.com
Wed Apr 21 06:47:13 CDT 2021


Jean Aunis - Prescom has uploaded this change for review. ( 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, 3 insertions(+), 1 deletion(-)



  git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/01/15801/1

diff --git a/main/translate.c b/main/translate.c
index a9665ae..f6eb734 100644
--- a/main/translate.c
+++ b/main/translate.c
@@ -408,12 +408,14 @@
 		}
 	}
 	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;
 		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: 1
Gerrit-Owner: Jean Aunis - Prescom <jean.aunis at prescom.fr>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20210421/f6bb6e77/attachment.html>


More information about the asterisk-code-review mailing list