[svn-commits] rmudgett: branch rmudgett/parking r330636 - /team/rmudgett/parking/main/

SVN commits to the Digium repositories svn-commits at lists.digium.com
Tue Aug 2 11:31:34 CDT 2011


Author: rmudgett
Date: Tue Aug  2 11:31:29 2011
New Revision: 330636

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=330636
Log:
Address autoservice concerns when playing courtesy tone for parking.

Modified:
    team/rmudgett/parking/main/features.c

Modified: team/rmudgett/parking/main/features.c
URL: http://svnview.digium.com/svn/asterisk/team/rmudgett/parking/main/features.c?view=diff&rev=330636&r1=330635&r2=330636
==============================================================================
--- team/rmudgett/parking/main/features.c (original)
+++ team/rmudgett/parking/main/features.c Tue Aug  2 11:31:29 2011
@@ -1734,34 +1734,75 @@
 }
 
 /*!
+ * \internal
+ * \brief Play file to specified channel.
+ *
+ * \param play_to Channel to play audiofile to.
+ * \param other Channel to put in autoservice while playing file.
+ * \param msg Descriptive name of message type being played.
+ * \param audiofile Audio file to play.
+ *
+ * \retval 0 on success.
+ * \retval -1 on error. (Couldn't play file, a channel hung up,...)
+ */
+static int play_message_on_chan(struct ast_channel *play_to, struct ast_channel *other, const char *msg, const char *audiofile)
+{
+	/* Put other channel in autoservice. */
+	if (ast_autoservice_start(other)) {
+		return -1;
+	}
+	ast_autoservice_ignore(other, AST_FRAME_DTMF_BEGIN);
+	ast_autoservice_ignore(other, AST_FRAME_DTMF_END);
+	if (ast_stream_and_wait(play_to, audiofile, "")) {
+		ast_log(LOG_WARNING, "Failed to play %s '%s'!\n", msg, audiofile);
+		ast_autoservice_stop(other);
+		return -1;
+	}
+	if (ast_autoservice_stop(other)) {
+		return -1;
+	}
+	return 0;
+}
+
+/*!
+ * \internal
+ * \brief Play file to specified channels.
+ *
+ * \param left Channel on left to play file.
+ * \param right Channel on right to play file.
+ * \param which Play file on indicated channels: which < 0 play left, which == 0 play both, which > 0 play right
+ * \param msg Descriptive name of message type being played.
+ * \param audiofile Audio file to play to channels.
+ * 
+ * \note Plays file to the indicated channels in turn so please
+ * don't use this for very long messages.
+ * 
+ * \retval 0 on success.
+ * \retval -1 on error. (Couldn't play file, channel hung up,...)
+ */
+static int play_message_to_chans(struct ast_channel *left, struct ast_channel *right, int which, const char *msg, const char *audiofile)
+{
+	/* First play the file to the left channel if requested. */
+	if (which <= 0 && play_message_on_chan(left, right, msg, audiofile)) {
+		return -1;
+	}
+
+	/* Then play the file to the right channel if requested. */
+	if (which >= 0 && play_message_on_chan(right, left, msg, audiofile)) {
+		return -1;
+	}
+
+	return 0;
+}
+
+/*!
  * \brief Play message to both caller and callee in bridged call, plays synchronously, autoservicing the
  * other channel during the message, so please don't use this for very long messages
  */
 static int play_message_in_bridged_call(struct ast_channel *caller_chan, struct ast_channel *callee_chan, const char *audiofile)
 {
-	/* First play for caller, put other channel on auto service */
-	if (ast_autoservice_start(callee_chan))
-		return -1;
-	ast_autoservice_ignore(callee_chan, AST_FRAME_DTMF_END);
-	if (ast_stream_and_wait(caller_chan, audiofile, "")) {
-		ast_log(LOG_WARNING, "Failed to play automon message!\n");
-		ast_autoservice_stop(callee_chan);
-		return -1;
-	}
-	if (ast_autoservice_stop(callee_chan))
-		return -1;
-	/* Then play for callee, put other channel on auto service */
-	if (ast_autoservice_start(caller_chan))
-		return -1;
-	ast_autoservice_ignore(caller_chan, AST_FRAME_DTMF_END);
-	if (ast_stream_and_wait(callee_chan, audiofile, "")) {
-		ast_log(LOG_WARNING, "Failed to play automon message !\n");
-		ast_autoservice_stop(caller_chan);
-		return -1;
-	}
-	if (ast_autoservice_stop(caller_chan))
-		return -1;
-	return(0);
+	return play_message_to_chans(caller_chan, callee_chan, 0, "automon message",
+		audiofile);
 }
 
 /*!
@@ -4751,30 +4792,23 @@
 
 		/* Play a courtesy to the source(s) configured to prefix the bridge connecting */
 		if (!ast_strlen_zero(courtesytone)) {
-			int error = 0;
-
-/* BUGBUG we should autoservice the channel not getting the courtesy tone. */
-			if (parkedplay == 0) {
-				error = ast_stream_and_wait(chan, courtesytone, "");
-			} else if (parkedplay == 1) {
-				error = ast_stream_and_wait(peer, courtesytone, "");
-			} else if (parkedplay == 2) {
-				if (!ast_streamfile(chan, courtesytone, chan->language)
-					&& !ast_streamfile(peer, courtesytone, peer->language)) {
-					/*! \todo XXX we would like to wait on both! */
-					res = ast_waitstream(chan, "");
-					if (res >= 0) {
-						res = ast_waitstream(peer, "");
-					}
-					if (res < 0) {
-						error = 1;
-					}
-				} else {
-					error = 1;
-				}
-			}
-			if (error) {
-				ast_log(LOG_WARNING, "Failed to play courtesy tone!\n");
+			static const char msg[] = "courtesy tone";
+
+			switch (parkedplay) {
+			case 0:/* Courtesy tone to pickup chan */
+				res = play_message_to_chans(chan, peer, -1, msg, courtesytone);
+				break;
+			case 1:/* Courtesy tone to parked chan */
+				res = play_message_to_chans(chan, peer, 1, msg, courtesytone);
+				break;
+			case 2:/* Courtesy tone to both chans */
+				res = play_message_to_chans(chan, peer, 0, msg, courtesytone);
+				break;
+			default:
+				res = 0;
+				break;
+			}
+			if (res) {
 				ast_hangup(peer);
 				parkinglot_unref(parkinglot);
 				return -1;




More information about the svn-commits mailing list