Asterisk EAGI

From voipsupport
Jump to navigation Jump to search

FreePBX Patch needed to be able to use EAGI

File: /var/www/html/admin/libraries/extensions.class.php

--- extensions.class.original.php	2016-06-18 19:23:14.009320154 +0200
+++ extensions.class.php	2016-06-18 15:54:11.273444005 +0200
@@ -1251,6 +1251,11 @@
 		return "AGI(".$this->data.")";
 	}
 }
+class ext_eagi extends extension {
+	function output() {
+		return "EAGI(".$this->data.")";
+	}
+}
 class ext_deadagi extends extension {
 	function output() {
 		return "DeadAGI(".$this->data.")";

PHPAGI patch to the version distributed in FreePBX to be able to open EAGI audio stream

--- phpagi.dist.php	2016-06-19 09:07:55.475372158 +0200
+++ phpagi.php	2016-06-19 09:46:12.734317454 +0200
@@ -173,10 +173,10 @@
       // open audio if eagi detected
       if($this->request['agi_enhanced'] == '1.0')
       {
-        if(file_exists('/proc/' . getmypid() . '/fd/3'))
+	if (array_search('php',stream_get_wrappers())!==FALSE)
         {
           // this should work on linux
-          $this->audio = fopen('/proc/' . getmypid() . '/fd/3', 'r');
+          $this->audio = fopen('php://fd/' . AUDIO_FILENO, 'r');
         }
         elseif(file_exists('/dev/fd/3'))
         {

Asterisk patch to configure EAGI audio stream format

With this patch, use the following in the dialplan prior to calling an EAGI script. The following example shows how to set 48kHz LPCM single channel 16 bit signed audio:

set(EAGI_AUDIO_FORMAT=slin48)

Note: slin48 not sln48

Patch

--- res/res_agi.c.original	2016-06-19 17:39:06.554220638 +0200
+++ res/res_agi.c	2016-06-19 21:01:59.644230411 +0200
@@ -4194,14 +4194,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 sln
+	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;
 	}

Formats

  • ulaw
  • alaw
  • gsm
  • g726
  • g726aal2
  • adpcm
  • slin
  • slin12
  • slin16
  • slin24
  • slin32
  • slin44
  • slin48
  • slin96
  • slin192
  • lpc10
  • speex
  • speex16
  • speex32
  • ilbc
  • g722
  • testlaw

Formats that may require licences or additional software

  • g719
  • opus
  • siren7
  • siren14
  • g729