[asterisk-commits] file: branch file/bridging r107291 - /team/file/bridging/apps/app_confbridge.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Mon Mar 10 20:08:45 CDT 2008


Author: file
Date: Mon Mar 10 20:08:44 2008
New Revision: 107291

URL: http://svn.digium.com/view/asterisk?view=rev&rev=107291
Log:
Switch to using ast_stream_and_wait and also add a function that plays an audio file into the conference bridge.

Modified:
    team/file/bridging/apps/app_confbridge.c

Modified: team/file/bridging/apps/app_confbridge.c
URL: http://svn.digium.com/view/asterisk/team/file/bridging/apps/app_confbridge.c?view=diff&rev=107291&r1=107290&r2=107291
==============================================================================
--- team/file/bridging/apps/app_confbridge.c (original)
+++ team/file/bridging/apps/app_confbridge.c Mon Mar 10 20:08:44 2008
@@ -120,9 +120,7 @@
 
 	/* When finding a conference bridge that already exists make sure it is locked or that we are an admin */
 	if (conference_bridge && conference_bridge->locked && !ast_test_flag(&conference_bridge_user->flags, OPTION_ADMIN)) {
-		if (!ast_streamfile(conference_bridge_user->chan, "conf-locked", conference_bridge_user->chan->language)) {
-			ast_waitstream(conference_bridge_user->chan, "");
-		}
+		ast_stream_and_wait(conference_bridge_user->chan, "conf-locked", "");
 		AST_LIST_UNLOCK(&conference_bridges);
 		return NULL;
 	}
@@ -164,9 +162,7 @@
 		if (!ast_test_flag(&conference_bridge_user->flags, OPTION_NOONLYPERSON)) {
 			/* Play back the "you are currently the only person in this conference" recording while not blocking, as that would be silly. */
 			AST_LIST_UNLOCK(&conference_bridges);
-			ast_streamfile(conference_bridge_user->chan, "conf-onlyperson", conference_bridge_user->chan->language);
-			ast_waitstream(conference_bridge_user->chan, AST_DIGIT_ANY);
-			ast_stopstream(conference_bridge_user->chan);
+			ast_stream_and_wait(conference_bridge_user->chan, "conf-onlyperson", "");
 			AST_LIST_LOCK(&conference_bridges);
 		}
 		/* We have to check again as the value may have changed while playing back the recording */
@@ -230,6 +226,42 @@
 }
 
 /*!
+ * \brief Play sound file into conference bridge
+ *
+ * \param conference_bridge The conference bridge to play sound file into
+ * \param filename Sound file to play
+ *
+ * \return Returns 0 on success, -1 on failure
+ */
+static int play_sound_file(struct conference_bridge *conference_bridge, const char *filename)
+{
+	int cause;
+	struct ast_channel *chan = NULL;
+
+	/* Request a channel that we will use to interface with the bridge */
+	if (!(chan = ast_request("Bridge", AST_FORMAT_SLINEAR, "", &cause))) {
+		return -1;
+	}
+
+	/* Before we actually dial into the bridge we need to say what bridge */
+	chan->bridge = conference_bridge->bridge;
+
+	/* Now actually dial. Once this is done we have a clear conduit into the bridge. */
+	if (ast_call(chan, "", 0)) {
+		ast_hangup(chan);
+		return -1;
+	}
+
+	/* Stream the file into the conference while waiting for it to finish */
+	ast_stream_and_wait(chan, filename, "");
+
+	/* Now that it is done drop the channel */
+	ast_hangup(chan);
+
+	return 0;
+}
+
+/*!
  * \brief DTMF Menu Callback
  *
  * \param bridge Bridge this is involving
@@ -256,15 +288,11 @@
 	if (digit == '1') {
 		/* 1 - Mute or unmute yourself */
 		conference_bridge_user->features.mute = (!conference_bridge_user->features.mute ? 1 : 0);
-		if (!(res = ast_streamfile(bridge_channel->chan, (conference_bridge_user->features.mute ? "conf-muted" : "conf-unmuted"), bridge_channel->chan->language))) {
-			ast_waitstream(bridge_channel->chan, "");
-		}
+		res = ast_stream_and_wait(bridge_channel->chan, (conference_bridge_user->features.mute ? "conf-muted" : "conf-unmuted"), "");
 	} else if (isadmin && digit == '2') {
 		/* 2 - Unlock or lock conference */
 		conference_bridge->locked = (!conference_bridge->locked ? 1 : 0);
-		if (!(res = ast_streamfile(bridge_channel->chan, (conference_bridge->locked ? "conf-lockednow" : "conf-unlockednow"), bridge_channel->chan->language))) {
-			ast_waitstream(bridge_channel->chan, "");
-		}
+		res = ast_stream_and_wait(bridge_channel->chan, (conference_bridge->locked ? "conf-lockednow" : "conf-unlockednow"), "");
 	} else if (isadmin && digit == '3') {
 		/* 3 - Eject last user */
 		struct conference_bridge_user *last_participant = NULL;
@@ -272,9 +300,7 @@
 		AST_LIST_LOCK(&conference_bridges);
 		if (((last_participant = AST_LIST_LAST(&conference_bridge->users_list)) == conference_bridge_user) || (ast_test_flag(&last_participant->flags, OPTION_ADMIN))) {
 			AST_LIST_UNLOCK(&conference_bridges);
-			if (!(res = ast_streamfile(bridge_channel->chan, "conf-errormenu", bridge_channel->chan->language))) {
-				ast_waitstream(bridge_channel->chan, "");
-			}
+			res = ast_stream_and_wait(bridge_channel->chan, "conf-errormenu", "");
 		} else {
 			last_participant->kicked = 1;
 			ast_bridge_remove(conference_bridge->bridge, last_participant->chan);
@@ -290,9 +316,7 @@
 		/* 9 - Increase talking volume */
 	} else {
 		/* No valid option was selected */
-		if (!(res = ast_streamfile(bridge_channel->chan, "conf-errormenu", bridge_channel->chan->language))) {
-			ast_waitstream(bridge_channel->chan, "");
-		}
+		res = ast_stream_and_wait(bridge_channel->chan, "conf-errormenu", "");
 	}
 
 	bridge_channel->state = AST_BRIDGE_CHANNEL_STATE_WAIT;
@@ -346,9 +370,23 @@
 		conference_bridge_user.features.mute = 1;
 	}
 
+	/* If there is 1 or more people already in the conference then play our join sound unless overridden */
+	if (conference_bridge->users >= 2) {
+		ast_autoservice_start(chan);
+		play_sound_file(conference_bridge, "beep");
+		ast_autoservice_stop(chan);
+	}
+
 	/* Join our conference bridge for real */
 	ast_bridge_join(conference_bridge->bridge, chan, NULL, &conference_bridge_user.features);
 
+	/* If there is 1 or more people (not including us) already in the conference then play our leave sound unless overridden */
+	if (conference_bridge->users >= 2) {
+		ast_autoservice_start(chan);
+		play_sound_file(conference_bridge, "beep");
+		ast_autoservice_stop(chan);
+	}
+
 	/* Easy as pie, depart this channel from the conference bridge */
 	leave_conference_bridge(conference_bridge, &conference_bridge_user);
 
@@ -357,9 +395,7 @@
 
 	/* If the user was kicked from the conference play back the audio prompt for it */
 	if (conference_bridge_user.kicked) {
-		if (!(res = ast_streamfile(chan, "conf-kicked", chan->language))) {
-			ast_waitstream(chan, "");
-		}
+		res = ast_stream_and_wait(chan, "conf-kicked", "");
 	}
 
 	return res;




More information about the asterisk-commits mailing list