[Asterisk-code-review] chan_iax2: Fix jitterbuffer regression prior to receiving audio. (asterisk[20])

N A asteriskteam at digium.com
Mon Feb 27 12:52:41 CST 2023


N A has uploaded this change for review. ( https://gerrit.asterisk.org/c/asterisk/+/19940 )


Change subject: chan_iax2: Fix jitterbuffer regression prior to receiving audio.
......................................................................

chan_iax2: Fix jitterbuffer regression prior to receiving audio.

ASTERISK_29392 (a security fix) introduced a regression by
not processing frames when we don't have an audio format.

Currently, chan_iax2 only calls jb_get to read frames from
the jitterbuffer when the voiceformat has been set on the pvt.
However, this only happens when we receive a voice frame, which
means that prior to receiving voice frames, other types of frames
get stalled completely in the jitterbuffer.

To fix this, we now fallback to using the format negotiated during
call setup until we've actually received a voice frame with a format.
This ensures we're always able to read from the jitterbuffer.

ASTERISK-30354 #close
ASTERISK-30162 #close

Change-Id: Ie4fd1e8e088a145ad89e0427c2100a530e964fe9
---
M channels/chan_iax2.c
1 file changed, 39 insertions(+), 3 deletions(-)



  git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/40/19940/1

diff --git a/channels/chan_iax2.c b/channels/chan_iax2.c
index ab6bd61..5b3caf0 100644
--- a/channels/chan_iax2.c
+++ b/channels/chan_iax2.c
@@ -4158,9 +4158,19 @@
 	now.tv_usec += 1000;
 
 	ms = ast_tvdiff_ms(now, pvt->rxcore);
-
-	voicefmt = ast_format_compatibility_bitfield2format(pvt->voiceformat);
-	if (voicefmt && ms >= (next = jb_next(pvt->jb))) {
+	if (ms >= (next = jb_next(pvt->jb))) {
+		voicefmt = ast_format_compatibility_bitfield2format(pvt->voiceformat);
+		if (!voicefmt) {
+			/* pvt->voiceformat won't be set if we haven't received any voice frames yet.
+			 * In this case, fall back to using the format negotiated during call setup,
+			 * so we don't stall the jitterbuffer completely. */
+			voicefmt = ast_format_compatibility_bitfield2format(pvt->peerformat);
+		}
+		if (!voicefmt) {
+			/* Really shouldn't happen, but if it does, should be looked into */
+			ast_log(LOG_WARNING, "No voice format and no peer format available on %s, backlogging frame\n", ast_channel_name(pvt->owner));
+			goto cleanup; /* Don't crash if there's no voice format */
+		}
 		ret = jb_get(pvt->jb, &frame, ms, ast_format_get_default_ms(voicefmt));
 		switch(ret) {
 		case JB_OK:
@@ -4202,6 +4212,7 @@
 			break;
 		}
 	}
+cleanup:
 	if (pvt)
 		update_jbsched(pvt);
 	ast_mutex_unlock(&iaxsl[callno]);

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

Gerrit-Project: asterisk
Gerrit-Branch: 20
Gerrit-Change-Id: Ie4fd1e8e088a145ad89e0427c2100a530e964fe9
Gerrit-Change-Number: 19940
Gerrit-PatchSet: 1
Gerrit-Owner: N A <asterisk at phreaknet.org>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20230227/119fe2e2/attachment-0001.html>


More information about the asterisk-code-review mailing list