From c47fd8f774ddddff83695633f44a8fbd51f3c789 Mon Sep 17 00:00:00 2001 From: Gregory Nietsky Date: Thu, 22 Sep 2011 06:18:33 +0000 Subject: [PATCH] Its possible to loose audio on ast_write when the channel is not transcoded correctly. in the case of DAHDI the channel is hungup. This patch tries to "fix" the problem and make the channel compatiable and warn the user of this problem. Please note there is a underlying problem with codec negotion this does not fix the problem it does try to rectify it and prevent loss of service. Review: https://reviewboard.asterisk.org/r/1442/ (closes issue ASTERISK-17541) (closes issue ASTERISK-18063) (issue ASTERISK-14384) (issue ASTERISK-17502) (issue ASTERISK-18325) (issue ASTERISK-18422) git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/1.8@337430 65c4cc65-6c06-0410-ace0-fbb531ad65f3 --- main/channel.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/main/channel.c b/main/channel.c index 319fa6a8c4..8d82c02ee0 100644 --- a/main/channel.c +++ b/main/channel.c @@ -4894,10 +4894,25 @@ int ast_write(struct ast_channel *chan, struct ast_frame *fr) } /* If the frame is in the raw write format, then it's easy... just use the frame - otherwise we will have to translate */ - if (fr->subclass.codec == chan->rawwriteformat) + if (fr->subclass.codec == chan->rawwriteformat) { f = fr; - else + } else { + /* XXX Something is not right we are not compatible with this frame bad things can happen + * problems range from no/one-way audio to unexplained line hangups as a last resort try adjust the format + * ideally we do not want to do this and this indicates a deeper problem for now we log these events to + * eliminate user impact and help identify the problem areas + * JIRA issues related to this :- + * ASTERISK-14384, ASTERISK-17502, ASTERISK-17541, ASTERISK-18063, ASTERISK-18325, ASTERISK-18422*/ + if ((!(fr->subclass.codec & chan->nativeformats)) && (chan->writeformat != fr->subclass.codec)) { + char nf[512]; + ast_log(LOG_WARNING, "Codec mismatch on channel %s setting write format to %s from %s native formats %s\n", + chan->name, ast_getformatname(fr->subclass.codec), ast_getformatname(chan->writeformat), + ast_getformatname_multiple(nf, sizeof(nf), chan->nativeformats & AST_FORMAT_AUDIO_MASK)); + ast_set_write_format(chan, fr->subclass.codec); + } + f = (chan->writetrans) ? ast_translate(chan->writetrans, fr, 0) : fr; + } if (!f) { res = 0;