From dcc16df90d568d471d5dccf10ab017a30ebcd09f Mon Sep 17 00:00:00 2001
From: Wenpeng Song <wenpeng.song@iopsys.eu>
Date: Tue, 26 Apr 2022 13:26:21 +0000
Subject: [PATCH] Fix a bug that two call progress tones are being played
 simultaneously

There are two ways to play tones, 1) by platform API; 2) by asterisk.
The ongoing tone will be stopped when a new tone is about to start
if both tones are played by platform API.
But if the current tone is played by platform API and the new tone is about
to be played by asterisk, the existing tone must be stopped explicitly.
---
 channels/chan_brcm.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/channels/chan_brcm.c b/channels/chan_brcm.c
index 6f9a2b369d..bca823c4ab 100644
--- a/channels/chan_brcm.c
+++ b/channels/chan_brcm.c
@@ -645,6 +645,9 @@ static int brcm_indicate(struct ast_channel *ast, int condition, const void *dat
 					break;
 				}
 				res = -1;
+		  case AST_CAUSE_NETWORK_OUT_OF_ORDER:
+			  brcm_stop_dialtone(sub->parent); // stop any dialtone exist if disconnection happened due to network/server
+			  break;
 		  default:
 			  ast_debug(1, "Don't know how to handle cause code %d\n", ast_cause);
 			  break;
@@ -1408,9 +1411,7 @@ static int brcm_signal_dialtone(struct brcm_pvt *p) {
 	ast_verbose("Setting dialtone to %s\n", dialtone_map[p->dialtone].str);	
 	switch (p->dialtone) {
 		case DIALTONE_OFF:
-			endpt_signal(p->line_id, "dial", "off", NULL);
-			endpt_signal(p->line_id, "stutter", "off", NULL);
-			endpt_signal(p->line_id, "unobtainable", "off", NULL);
+			endpt_signal(p->line_id, "dial", "off", NULL); // this will turn off any tones that is playing. Act as play dial-off.
 			break;
 		case DIALTONE_ON:
 			endpt_signal(p->line_id, "dial", "on", NULL);
-- 
GitLab