Asterisk EAGI: Difference between revisions

From voipsupport
Jump to navigation Jump to search
 
(14 intermediate revisions by the same user not shown)
Line 1: Line 1:
==FreePBX Patch needed to be able to use EAGI==
==FreePBX Patch needed to be able to use EAGI==
File: /var/www/html/admin/libraries/extensions.class.php


<pre>--- extensions.class.original.php 2016-06-18 19:23:14.009320154 +0200
<pre>--- extensions.class.original.php 2016-06-18 19:23:14.009320154 +0200
Line 17: Line 19:


==PHPAGI patch to the version distributed in FreePBX to be able to open EAGI audio stream==
==PHPAGI patch to the version distributed in FreePBX to be able to open EAGI audio stream==
File: /var/lib/asterisk/agi-bin/phpagi.php


<pre>--- phpagi.dist.php 2016-06-19 09:07:55.475372158 +0200
<pre>--- phpagi.dist.php 2016-06-19 09:07:55.475372158 +0200
Line 40: Line 44:
Note: '''slin48''' not sln48
Note: '''slin48''' not sln48


 
===Patch===
Patch:


<pre>
<pre>
Line 65: Line 68:
+ pbx_retrieve_variable(chan, "EAGI_AUDIO_FORMAT", &ret, tempstr, sizeof(tempstr), NULL);
+ pbx_retrieve_variable(chan, "EAGI_AUDIO_FORMAT", &ret, tempstr, sizeof(tempstr), NULL);
+ ast_verb(3, "EAGI_AUDIO_FORMAT = %s\n", tempstr);
+ ast_verb(3, "EAGI_AUDIO_FORMAT = %s\n", tempstr);
+ requested_format = __ast_format_cache_get(tempstr);
+ requested_format = ast_format_cache_get(tempstr);
+ if (requested_format == NULL) {
+ if (requested_format == NULL) {
+ requested_format = ast_format_slin;
+ requested_format = ast_format_slin;
Line 79: Line 82:
</pre>
</pre>


Values for the format are:
===Formats===
* g723
* ulaw
* ulaw
* alaw
* alaw
Line 97: Line 99:
* slin192
* slin192
* lpc10
* lpc10
* g729
* speex
* speex
* speex16
* speex16
Line 103: Line 104:
* ilbc
* ilbc
* g722
* g722
* siren7
* siren14
* testlaw
* testlaw
===Formats that may require licences or additional software===
* g719
* g719
* opus
* opus
* h261
* siren7
* h263
* siren14
* h263p
* g729
* h264
* mpeg4
* vp8
* red
* t140
These are the ones I found in the source file, but I have only test slin, slin48 and gsm. Some may not be audio formats: I removed the two image formats, but maybe I did not get all of the inappropriate ones.

Latest revision as of 12:03, 23 July 2016

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

File: /var/lib/asterisk/agi-bin/phpagi.php

--- 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