Skip to content

Commit

Permalink
Merge pull request #38 from AllStarLink/add_1055_iax2_patch
Browse files Browse the repository at this point in the history
Add "Missing voice format on incoming IAX2 channel" patch
  • Loading branch information
Allan-N authored Jan 16, 2025
2 parents 47beb8f + 9becf4f commit 8e72889
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
53 changes: 53 additions & 0 deletions debian/patches/chan_iax2_unknown_format.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
diff --git a/channels/chan_iax2.c b/channels/chan_iax2.c
index a99e789de57..3ebed93a772 100644
--- a/channels/chan_iax2.c
+++ b/channels/chan_iax2.c
@@ -786,7 +786,8 @@ struct chan_iax2_pvt {
unsigned short peercallno;
/*! Negotiated format, this is only used to remember what format was
chosen for an unauthenticated call so that the channel can get
- created later using the right format */
+ created later using the right format. We also use it for
+ authenticated calls to check the format from __get_from_jb. */
iax2_format chosenformat;
/*! Peer selected format */
iax2_format peerformat;
@@ -4205,10 +4206,24 @@ static void __get_from_jb(const void *p)
* 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) {
+ /* As a last resort, we can use pvt->chosenformat.
+ * This is set when we receive a call (either authenticated or unauthenticated),
+ * so even if we haven't received any voice frames yet, we can still use the
+ * right format.
+ *
+ * If we have to do this, in most cases, we aren't even processing voice frames
+ * anyways, it's likely a non-voice frame. In that case, the format doesn't
+ * really matter so much, because we could just pass 20 to jb_get instead
+ * of calling ast_format_get_default_ms. However, until jb_get returns,
+ * we don't actually know what kind of frame it is for sure, so use
+ * the right format just to be safe. */
+ voicefmt = ast_format_compatibility_bitfield2format(pvt->chosenformat);
+ }
}
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));
+ /* This should never happen, since we should always be able to have an acceptable format to use. */
+ ast_log(LOG_ERROR, "No voice, peer, or chosen 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));
@@ -11557,6 +11572,11 @@ static int socket_process_helper(struct iax2_thread *thread)
VERBOSE_PREFIX_4,
using_prefs);

+ /* Unlike unauthenticated calls, we don't need to store
+ * the chosen format for channel creation.
+ * However, this is helpful for __get_from_jb. */
+ iaxs[fr->callno]->chosenformat = format;
+
ast_set_flag(&iaxs[fr->callno]->state, IAX_STATE_STARTED);
c = ast_iax2_new(fr->callno, AST_STATE_RING, format,
&iaxs[fr->callno]->rprefs, NULL, NULL, 1);
1 change: 1 addition & 0 deletions debian/patches/series
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ config_c_fix_tryinclude.patch
config_c_fix_whitespace.patch
sounds_ulaw_default
enable_custom_sounddir.patch
chan_iax2_unknown_format.patch

0 comments on commit 8e72889

Please sign in to comment.