[Asterisk-code-review] res agi: Set audio format of EAGI audio via new EAGI AUDIO F... (asterisk[master])

John Fawcett asteriskteam at digium.com
Sat Jul 23 13:55:13 CDT 2016


John Fawcett has uploaded a new change for review.

  https://gerrit.asterisk.org/3325

Change subject: res_agi: Set audio format of EAGI audio via new EAGI_AUDIO_FORMAT variable
......................................................................

res_agi: Set audio format of EAGI audio via new EAGI_AUDIO_FORMAT variable

Introduces a new variable EAGI_AUDIO_FORMAT that sets the audio format output
by EAGI on file descriptor 3 to be set to a specified format, for example
Set(EAGI_AUDIO_FORMAT=slin48). If the variable is not set then the default
format is slin, as in the existing code.

ASTERISK-26124

Change-Id: I188815b0cb47b7979139151c4e5211412fd69924
---
M CHANGES
M res/res_agi.c
2 files changed, 22 insertions(+), 3 deletions(-)


  git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/25/3325/1

diff --git a/CHANGES b/CHANGES
index 31b521c..18b587e 100644
--- a/CHANGES
+++ b/CHANGES
@@ -2830,6 +2830,11 @@
    whether it specifies the case of uppercase, lowercase, or all letters to
    provide functionality similar to SayAlphaCase.
 
+ * The audio format output on file descriptor 3 when using EAGI can now be
+   set by using the EAGI_AUDIO_FORMAT variable in the dialplan prior to calling
+   the EAGI script, for example: Set(EAGI_AUDIO_FORMAT=slin48). If the variable
+   is not set then the format defaults to the existing behaviour (slin).
+
 res_ari (Asterisk RESTful Interface) (and others)
 ------------------
  * The Asterisk RESTful Interface (ARI) provides a mechanism to expose and
diff --git a/res/res_agi.c b/res/res_agi.c
index e8249e2..b88ccc4 100644
--- a/res/res_agi.c
+++ b/res/res_agi.c
@@ -890,7 +890,7 @@
 		</syntax>
 		<description>
 			<para>Using 'EAGI' provides enhanced AGI, with incoming audio available out of band
-			on file descriptor 3.</para>
+			on file descriptor 3. The audio format may be set by using the variable EAGI_AUDIO_FORMAT prior to calling EAGI, for example Set(EAGI_AUDIO_FORMAT=slin48). If the variable is not set then the default audio format is 8kHz mono slin.</para>
 			<xi:include xpointer="xpointer(/docs/application[@name='AGI']/description/para)" />
 			<xi:include xpointer="xpointer(/docs/application[@name='AGI']/description/variablelist)" />
 		</description>
@@ -4232,14 +4232,28 @@
 {
 	int res;
 	struct ast_format *readformat;
+	struct ast_format *requested_format;
+	char *ret;
+	char tempstr[1024] = "";
 
 	if (ast_check_hangup(chan)) {
 		ast_log(LOG_ERROR, "EAGI cannot be run on a dead/hungup channel, please use AGI.\n");
 		return 0;
 	}
 	readformat = ao2_bump(ast_channel_readformat(chan));
-	if (ast_set_read_format(chan, ast_format_slin)) {
-		ast_log(LOG_WARNING, "Unable to set channel '%s' to linear mode\n", ast_channel_name(chan));
+
+	// set format according to EAGI_AUDIO_FORMAT variable else use slin
+	pbx_retrieve_variable(chan, "EAGI_AUDIO_FORMAT", &ret, tempstr, sizeof(tempstr), NULL);
+	ast_verb(3, "EAGI_AUDIO_FORMAT = %s\n", tempstr);
+	requested_format = ast_format_cache_get(tempstr);
+	if (requested_format == NULL) {
+		requested_format = ast_format_slin;
+		ast_verb(3, "Setting EAGI audio format to default slin\n");
+	} else  {
+		ast_verb(3, "Setting EAGI audio format to requested %s\n",tempstr);
+	}
+	if (ast_set_read_format(chan, requested_format)) {
+		ast_log(LOG_WARNING, "Unable to set channel '%s' to requested mode\n", ast_channel_name(chan));
 		ao2_ref(readformat, -1);
 		return -1;
 	}

-- 
To view, visit https://gerrit.asterisk.org/3325
To unsubscribe, visit https://gerrit.asterisk.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I188815b0cb47b7979139151c4e5211412fd69924
Gerrit-PatchSet: 1
Gerrit-Project: asterisk
Gerrit-Branch: master
Gerrit-Owner: John Fawcett <john at voipsupport.it>



More information about the asterisk-code-review mailing list