[svn-commits] branch north/bug_1082 - r8222 in /team/north/bug_1082: apps/ channels/

svn-commits at lists.digium.com svn-commits at lists.digium.com
Wed Jan 18 16:45:47 MST 2006


Author: north
Date: Wed Jan 18 17:45:46 2006
New Revision: 8222

URL: http://svn.digium.com/view/asterisk?rev=8222&view=rev
Log:
Took patch from bug 1082, changed it to set channel var from queues, and read same var from agent_call

Modified:
    team/north/bug_1082/apps/app_queue.c
    team/north/bug_1082/channels/chan_agent.c

Modified: team/north/bug_1082/apps/app_queue.c
URL: http://svn.digium.com/view/asterisk/team/north/bug_1082/apps/app_queue.c?rev=8222&r1=8221&r2=8222&view=diff
==============================================================================
--- team/north/bug_1082/apps/app_queue.c (original)
+++ team/north/bug_1082/apps/app_queue.c Wed Jan 18 17:45:46 2006
@@ -350,6 +350,7 @@
 	char sound_thanks[80];          /*!< Sound file: "Thank you for your patience." (def. queue-thankyou) */
 	char sound_reporthold[80];	/*!< Sound file: "Hold time" (def. queue-reporthold) */
 	char sound_periodicannounce[MAX_PERIODIC_ANNOUNCEMENTS][80];/* Sound files: Custom announce, no default */
+	char sound_ack[80];		/*!< Sound file: Per queue agent ack sound, no default */
 
 	int count;			/*!< How many entries */
 	int maxlen;			/*!< Max number of entries */
@@ -689,6 +690,8 @@
 		}
 	} else if (!strcasecmp(param, "periodic-announce-frequency")) {
 		q->periodicannouncefrequency = atoi(val);
+	} else if (!strcasecmp(param, "acksound")) {
+		ast_copy_string(q->sound_ack, val, sizeof(q->sound_ack));
 	} else if (!strcasecmp(param, "retry")) {
 		q->retry = atoi(val);
 		if (q->retry < 0)
@@ -1433,6 +1436,9 @@
 
 	/* Presense of ADSI CPE on outgoing channel follows ours */
 	tmp->chan->adsicpe = qe->chan->adsicpe;
+
+	/* Allows agent to play a per queue ack sound */
+	pbx_builtin_setvar_helper(tmp->chan, "QUEUEACKSOUND", qe->parent->sound_ack);
 
 	/* Place the call, but don't wait on the answer */
 	res = ast_call(tmp->chan, location, 0);

Modified: team/north/bug_1082/channels/chan_agent.c
URL: http://svn.digium.com/view/asterisk/team/north/bug_1082/channels/chan_agent.c?rev=8222&r1=8221&r2=8222&view=diff
==============================================================================
--- team/north/bug_1082/channels/chan_agent.c (original)
+++ team/north/bug_1082/channels/chan_agent.c Wed Jan 18 17:45:46 2006
@@ -54,6 +54,7 @@
 #include "asterisk/module.h"
 #include "asterisk/pbx.h"
 #include "asterisk/options.h"
+#include "asterisk/translate.h"
 #include "asterisk/lock.h"
 #include "asterisk/sched.h"
 #include "asterisk/io.h"
@@ -157,6 +158,8 @@
 static int autologoff;
 static int wrapuptime;
 static int ackcall;
+static char acksound[AST_MAX_BUF] = "";
+static int ackwait = 0;
 static int multiplelogin = 1;
 static int autologoffunavail = 0;
 
@@ -206,6 +209,8 @@
 	char loginchan[80];            /**< channel they logged in from */
 	char logincallerid[80];        /**< Caller ID they had when they logged in */
 	struct ast_channel *chan;      /**< Channel we use */
+	struct ast_trans_pvt *trans;
+	int framecount;
 	struct agent_pvt *next;        /**< Next Agent in the linked list. */
 };
 
@@ -501,6 +506,14 @@
 			/* Note that we don't hangup if it's not a callback because Asterisk will do it
 			   for us when the PBX instance that called login finishes */
 			if (!ast_strlen_zero(p->loginchan)) {
+				if(p && p->chan && p->chan->stream) {
+					ast_closestream(p->chan->stream);
+					p->chan->stream = NULL;
+				}
+				if(p && p->trans) {
+					ast_translator_free_path(p->trans);
+					p->trans = NULL;
+				}
 				if (p->chan)
 					ast_log(LOG_DEBUG, "Bridge on '%s' being cleared (2)\n", p->chan->name);
 
@@ -529,6 +542,7 @@
  				if (p->ackcall) {
  					if (option_verbose > 2)
  						ast_verbose(VERBOSE_PREFIX_3 "%s answered, waiting for '#' to acknowledge\n", p->chan->name);
+					p->framecount = 1;
  					/* Don't pass answer along */
  					ast_frfree(f);
  					f = &null_frame;
@@ -543,6 +557,14 @@
  			break;
  		case AST_FRAME_DTMF:
  			if (!p->acknowledged && (f->subclass == '#')) {
+				if(p && p->chan && p->chan->stream) {
+					ast_closestream(p->chan->stream);
+					p->chan->stream = NULL;
+				}
+				if(p && p->trans) {
+					ast_translator_free_path(p->trans);
+					p->trans = NULL;
+				}
  				if (option_verbose > 2)
  					ast_verbose(VERBOSE_PREFIX_3 "%s acknowledged\n", p->chan->name);
  				p->acknowledged = 1;
@@ -664,6 +686,7 @@
 static int agent_call(struct ast_channel *ast, char *dest, int timeout)
 {
 	struct agent_pvt *p = ast->tech_pvt;
+	struct ast_frame *f2 = NULL;
 	int res = -1;
 	int newstate=0;
 	ast_mutex_lock(&p->lock);
@@ -735,6 +758,57 @@
 		}
 		res = 0;
 	}
+
+	/* Turn this code into poor man's generator since we are reading frames at the perfect speed 
+	   just open a stream and pass along the frames from the file while we are waiting for 
+	   the agent to press # or the timeout to occur.
+	*/
+	if(p && ! p->acknowledged) {
+		/* We don't want to rely on queues being loaded,
+		   so we'll just use a channel variable that gets set from queues.
+		*/
+		char *oldacksound = NULL;
+		if (!ast_strlen_zero(acksound))
+			oldacksound = ast_strdupa(acksound);
+		if (!ast_strlen_zero(pbx_builtin_getvar_helper(ast, "QUEUEACKSOUND")))
+			strncpy(acksound, pbx_builtin_getvar_helper(ast, "QUEUEACKSOUND"), AST_MAX_BUF);
+
+		if(p->chan && !ast_strlen_zero(acksound) && p->framecount++ > ackwait &&
+		   ! p->trans && (ast_openstream(p->chan,acksound, p->chan->language))) {
+			if((f2 = ast_readframe(p->chan->stream))) {
+				if(p->chan->readformat && p->chan->readformat != f2->subclass) 
+					p->trans = ast_translator_build_path(p->chan->readformat, f2->subclass);
+			}
+		}
+		ast_copy_string(acksound, oldacksound, sizeof(acksound));
+
+		if(p->framecount > ackwait && p->chan && p->chan->stream) {
+			if(!f2) {
+				if(!(f2 = ast_readframe(p->chan->stream))) {
+					/* Reset the stream and the ackwait and play the file again if the time comes. */
+					if(p->chan && p->chan->stream) {
+						ast_closestream(p->chan->stream);
+						p->chan->stream = NULL;
+					}
+					if(p->trans) {
+						ast_translator_free_path(p->trans);
+						p->trans = NULL;
+					}
+					p->framecount = 0;
+				}
+			}
+			if(f2) {
+				if(p->trans && f2->subclass != p->chan->readformat)
+					f2 = ast_translate(p->trans, f2, 1);
+				if(f2) {
+					ast_write(p->chan, f2);
+					ast_frfree(f2);
+					f2 = NULL;
+				}
+			}
+		}
+	}
+
 	CLEANUP(ast,p);
 	ast_mutex_unlock(&p->lock);
 	if (newstate)
@@ -765,6 +839,15 @@
 	ast->tech_pvt = NULL;
 	p->app_sleep_cond = 1;
 	p->acknowledged = 0;
+
+	if(p && p->chan && p->chan->stream) {
+		ast_stopstream(p->chan);
+		p->chan->stream = NULL;
+	}
+	if(p && p->trans) {
+		ast_translator_free_path(p->trans);
+		p->trans = NULL;
+	}
 
 	/* if they really are hung up then set start to 0 so the test
 	 * later if we're called on an already downed channel
@@ -991,6 +1074,8 @@
 		 * can safely use signals for this purpose. The pselect() needs to be
 		 * implemented in the kernel for this.
 		 */
+		p->trans = NULL;
+		p->framecount = 0;
 		p->app_sleep_cond = 0;
 		if( ast_mutex_trylock(&p->app_lock) )
 		{
@@ -1076,6 +1161,10 @@
 		/* Create the interface list */
 		if (!strcasecmp(v->name, "agent")) {
 			add_agent(v->value, 0);
+		} else if (!strcasecmp(v->name, "acksound")) {
+			strncpy(acksound,v->value,AST_MAX_BUF);
+		} else if (!strcasecmp(v->name, "ackwait")) {
+			ackwait = atoi(v->value);
 		} else if (!strcasecmp(v->name, "group")) {
 			group = ast_get_group(v->value);
 		} else if (!strcasecmp(v->name, "autologoff")) {



More information about the svn-commits mailing list