[svn-commits] dvossel: trunk r325931 - in /trunk: ./ apps/ apps/confbridge/ apps/confbridge...

SVN commits to the Digium repositories svn-commits at lists.digium.com
Thu Jun 30 15:33:26 CDT 2011


Author: dvossel
Date: Thu Jun 30 15:33:15 2011
New Revision: 325931

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=325931
Log:
Video support for ConfBridge.

Review: https://reviewboard.asterisk.org/r/1288/


Modified:
    trunk/CHANGES
    trunk/apps/app_confbridge.c
    trunk/apps/app_voicemail.c
    trunk/apps/confbridge/conf_config_parser.c
    trunk/apps/confbridge/include/confbridge.h
    trunk/bridges/bridge_softmix.c
    trunk/configs/confbridge.conf.sample
    trunk/include/asterisk/bridging.h
    trunk/include/asterisk/dsp.h
    trunk/main/bridging.c
    trunk/main/dsp.c

Modified: trunk/CHANGES
URL: http://svnview.digium.com/svn/asterisk/trunk/CHANGES?view=diff&rev=325931&r1=325930&r2=325931
==============================================================================
--- trunk/CHANGES (original)
+++ trunk/CHANGES Thu Jun 30 15:33:15 2011
@@ -82,6 +82,8 @@
  * CONFBRIDGE_INFO dialplan function capable of retreiving information 
    about a conference such as locked status and number of parties, admins,
    and marked users.
+ * Addition of video_mode option in confbridge.conf for adding video support
+   into a bridge profile.
 
 Dialplan Variables
 ------------------

Modified: trunk/apps/app_confbridge.c
URL: http://svnview.digium.com/svn/asterisk/trunk/apps/app_confbridge.c?view=diff&rev=325931&r1=325930&r2=325931
==============================================================================
--- trunk/apps/app_confbridge.c (original)
+++ trunk/apps/app_confbridge.c Thu Jun 30 15:33:15 2011
@@ -77,6 +77,11 @@
             <description>
                     <para>Enters the user into a specified conference bridge. The user can exit the conference by hangup or DTMF menu option.</para>
             </description>
+			<see-also>
+				<ref type="application">ConfBridge</ref>
+				<ref type="function">CONFBRIDGE</ref>
+				<ref type="function">CONFBRIDGE_INFO</ref>
+			</see-also>
     </application>
 	<function name="CONFBRIDGE" language="en_US">
 		<synopsis>
@@ -233,6 +238,19 @@
 		<description>
 		</description>
 	</manager>
+	<manager name="ConfbridgeSetSingleVideoSrc" language="en_US">
+		<synopsis>
+			Set a conference user as the single video source distributed to all other participants.
+		</synopsis>
+		<syntax>
+			<xi:include xpointer="xpointer(/docs/manager[@name='Login']/syntax/parameter[@name='ActionID'])" />
+			<parameter name="Conference" required="true" />
+			<parameter name="Channel" required="true" />
+		</syntax>
+		<description>
+		</description>
+	</manager>
+
 ***/
 
 /*!
@@ -614,6 +632,68 @@
 	return res;
 }
 
+static void handle_video_on_join(struct conference_bridge *conference_bridge, struct conference_bridge_user *conference_bridge_user)
+{
+	/* only automatically set video source for marked users */
+	if (!ast_test_flag(&conference_bridge_user->u_profile, USER_OPT_MARKEDUSER)) {
+		return;
+	}
+
+	if (ast_test_flag(&conference_bridge->b_profile, BRIDGE_OPT_VIDEO_SRC_FIRST_MARKED)) {
+		int set = 1;
+		struct conference_bridge_user *tmp_user = NULL;
+		ao2_lock(conference_bridge);
+		/* see if anyone is already the video src */
+		AST_LIST_TRAVERSE(&conference_bridge->users_list, tmp_user, list) {
+			if (tmp_user == conference_bridge_user) {
+				continue;
+			}
+			if (ast_bridge_is_video_src(conference_bridge->bridge, tmp_user->chan)) {
+				set = 0;
+				break;
+			}
+		}
+		ao2_unlock(conference_bridge);
+		if (set) {
+			ast_bridge_set_single_src_video_mode(conference_bridge->bridge, conference_bridge_user->chan);
+		}
+	} else if (ast_test_flag(&conference_bridge->b_profile, BRIDGE_OPT_VIDEO_SRC_LAST_MARKED)) {
+		/* we joined and are video capable, we override anyone else that may have already been the video feed */
+		ast_bridge_set_single_src_video_mode(conference_bridge->bridge, conference_bridge_user->chan);
+	}
+}
+
+static void handle_video_on_exit(struct conference_bridge *conference_bridge, struct conference_bridge_user *conference_bridge_user)
+{
+	struct conference_bridge_user *tmp_user = NULL;
+
+	/* if this isn't a video source, nothing to update */
+	if (!ast_bridge_is_video_src(conference_bridge->bridge, conference_bridge_user->chan)) {
+		return;
+	}
+
+	ast_bridge_remove_video_src(conference_bridge->bridge, conference_bridge_user->chan);
+
+	/* if the video_mode isn't set to automatically pick the video source, do nothing on exit. */
+	if (!ast_test_flag(&conference_bridge->b_profile, BRIDGE_OPT_VIDEO_SRC_FIRST_MARKED) &&
+		!ast_test_flag(&conference_bridge->b_profile, BRIDGE_OPT_VIDEO_SRC_LAST_MARKED)) {
+		return;
+	}
+
+	/* Make the next avaliable marked user the video src.  */
+	ao2_lock(conference_bridge);
+	AST_LIST_TRAVERSE(&conference_bridge->users_list, tmp_user, list) {
+		if (tmp_user == conference_bridge_user) {
+			continue;
+		}
+		if (ast_test_flag(&tmp_user->u_profile, USER_OPT_MARKEDUSER)) {
+			ast_bridge_set_single_src_video_mode(conference_bridge->bridge, tmp_user->chan);
+			break;
+		}
+	}
+	ao2_unlock(conference_bridge);
+}
+
 /*!
  * \brief Perform post-joining marked specific actions
  *
@@ -627,7 +707,8 @@
 	if (ast_test_flag(&conference_bridge_user->u_profile, USER_OPT_MARKEDUSER)) {
 		struct conference_bridge_user *other_conference_bridge_user = NULL;
 
-		/* If we are not the first marked user to join just bail out now */
+		/* If we are not the first user to join, then the users are already
+		 * in the conference so we do not need to update them. */
 		if (conference_bridge->markedusers >= 2) {
 			return 0;
 		}
@@ -664,7 +745,6 @@
 				other_conference_bridge_user->features.mute = 0;
 			}
 		}
-
 	} else {
 		/* If a marked user already exists in the conference bridge we can just bail out now */
 		if (conference_bridge->markedusers) {
@@ -858,6 +938,10 @@
 		ast_bridge_set_internal_sample_rate(conference_bridge->bridge, conference_bridge->b_profile.internal_sample_rate);
 		/* Set the internal mixing interval on the bridge from the bridge profile */
 		ast_bridge_set_mixing_interval(conference_bridge->bridge, conference_bridge->b_profile.mix_interval);
+
+		if (ast_test_flag(&conference_bridge->b_profile, BRIDGE_OPT_VIDEO_SRC_FOLLOW_TALKER)) {
+			ast_bridge_set_talker_src_video_mode(conference_bridge->bridge);
+		}
 
 		/* Setup lock for playback channel */
 		ast_mutex_init(&conference_bridge->playback_lock);
@@ -1370,6 +1454,8 @@
 		}
 	}
 
+	handle_video_on_join(conference_bridge, &conference_bridge_user);
+
 	/* Join our conference bridge for real */
 	send_join_event(conference_bridge_user.chan, conference_bridge->name);
 	ast_bridge_join(conference_bridge->bridge,
@@ -1378,6 +1464,9 @@
 		&conference_bridge_user.features,
 		&conference_bridge_user.tech_args);
 	send_leave_event(conference_bridge_user.chan, conference_bridge->name);
+
+
+	handle_video_on_exit(conference_bridge, &conference_bridge_user);
 
 	/* if this user has a intro, play it when leaving */
 	if (!quiet && !ast_strlen_zero(conference_bridge_user.name_rec_location)) {
@@ -1681,6 +1770,11 @@
 			break;
 		case MENU_ACTION_NOOP:
 			break;
+		case MENU_ACTION_SET_SINGLE_VIDEO_SRC:
+			ao2_lock(conference_bridge);
+			ast_bridge_set_single_src_video_mode(conference_bridge->bridge, bridge_channel->chan);
+			ao2_unlock(conference_bridge);
+			break;
 		}
 	}
 	return res;
@@ -2436,6 +2530,55 @@
 	return 0;
 }
 
+static int action_confbridgesetsinglevideosrc(struct mansession *s, const struct message *m)
+{
+	const char *conference = astman_get_header(m, "Conference");
+	const char *channel = astman_get_header(m, "Channel");
+	struct conference_bridge_user *participant = NULL;
+	struct conference_bridge *bridge = NULL;
+	struct conference_bridge tmp;
+
+	if (ast_strlen_zero(conference)) {
+		astman_send_error(s, m, "No Conference name provided.");
+		return 0;
+	}
+	if (ast_strlen_zero(channel)) {
+		astman_send_error(s, m, "No channel name provided.");
+		return 0;
+	}
+	if (!ao2_container_count(conference_bridges)) {
+		astman_send_error(s, m, "No active conferences.");
+		return 0;
+	}
+
+	ast_copy_string(tmp.name, conference, sizeof(tmp.name));
+	bridge = ao2_find(conference_bridges, &tmp, OBJ_POINTER);
+	if (!bridge) {
+		astman_send_error(s, m, "No Conference by that name found.");
+		return 0;
+	}
+
+	/* find channel and set as video src. */
+	ao2_lock(bridge);
+	AST_LIST_TRAVERSE(&bridge->users_list, participant, list) {
+		if (!strncmp(channel, participant->chan->name, strlen(channel))) {
+			ast_bridge_set_single_src_video_mode(bridge->bridge, participant->chan);
+			break;
+		}
+	}
+	ao2_unlock(bridge);
+	ao2_ref(bridge, -1);
+
+	/* do not access participant after bridge unlock.  We are just
+	 * using this check to see if it was found or not */
+	if (!participant) {
+		astman_send_error(s, m, "No channel by that name found in conference.");
+		return 0;
+	}
+	astman_send_ack(s, m, "Conference single video source set.");
+	return 0;
+}
+
 static int func_confbridge_info(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len)
 {
 	char *parse = NULL;
@@ -2567,6 +2710,7 @@
 	res |= ast_manager_register_xml("ConfbridgeLock", EVENT_FLAG_CALL, action_confbridgelock);
 	res |= ast_manager_register_xml("ConfbridgeStartRecord", EVENT_FLAG_CALL, action_confbridgestartrecord);
 	res |= ast_manager_register_xml("ConfbridgeStopRecord", EVENT_FLAG_CALL, action_confbridgestoprecord);
+	res |= ast_manager_register_xml("ConfbridgeSetSingleVideoSrc", EVENT_FLAG_CALL, action_confbridgesetsinglevideosrc);
 
 	conf_load_config(0);
 	return res;

Modified: trunk/apps/app_voicemail.c
URL: http://svnview.digium.com/svn/asterisk/trunk/apps/app_voicemail.c?view=diff&rev=325931&r1=325930&r2=325931
==============================================================================
--- trunk/apps/app_voicemail.c (original)
+++ trunk/apps/app_voicemail.c Thu Jun 30 15:33:15 2011
@@ -903,8 +903,6 @@
 static int is_valid_dtmf(const char *key);
 static void read_password_from_file(const char *secretfn, char *password, int passwordlen);
 static int write_password_to_file(const char *secretfn, const char *password);
-static const char *substitute_escapes(const char *value);
-static void free_user(struct ast_vm_user *vmu);
 
 struct ao2_container *inprocess_container;
 
@@ -996,8 +994,7 @@
  * - the dialcontext
  * - the exitcontext
  * - vmmaxsecs, vmmaxmsg, maxdeletedmsg
- * - volume gain
- * - emailsubject, emailbody set to NULL
+ * - volume gain.
  */
 static void populate_defaults(struct ast_vm_user *vmu)
 {
@@ -1048,10 +1045,6 @@
 		ast_copy_string(vmu->attachfmt, value, sizeof(vmu->attachfmt));
 	} else if (!strcasecmp(var, "serveremail")) {
 		ast_copy_string(vmu->serveremail, value, sizeof(vmu->serveremail));
-	} else if (!strcasecmp(var, "emailbody")) {
-		vmu->emailbody = ast_strdup(substitute_escapes(value));
-	} else if (!strcasecmp(var, "emailsubject")) {
-		vmu->emailsubject = ast_strdup(substitute_escapes(value));
 	} else if (!strcasecmp(var, "language")) {
 		ast_copy_string(vmu->language, value, sizeof(vmu->language));
 	} else if (!strcasecmp(var, "tz")) {
@@ -1389,7 +1382,7 @@
 			ast_variables_destroy(var);
 		} else { 
 			if (!ivm) 
-				free_user(retval);
+				ast_free(retval);
 			retval = NULL;
 		}	
 	} 
@@ -10644,9 +10637,7 @@
 		"envelope=yes|moveheard=yes|sayduration=yes|saydurationm=5|forcename=yes|"
 		"forcegreetings=yes|callback=somecontext|dialout=somecontext2|"
 		"exitcontext=somecontext3|minsecs=10|maxsecs=100|nextaftercmd=yes|"
-		"backupdeleted=50|volgain=1.3|passwordlocation=spooldir|emailbody="
-		"Dear ${VM_NAME}:\n\n\tYou were just left a ${VM_DUR} long message|emailsubject="
-		"[PBX]: New message ${VM_MSGNUM} in mailbox ${VM_MAILBOX}";
+		"backupdeleted=50|volgain=1.3|passwordlocation=spooldir";
 #ifdef IMAP_STORAGE
 	static const char option_string2[] = "imapuser=imapuser|imappassword=imappasswd|"
 		"imapfolder=INBOX|imapvmshareid=6000";
@@ -10668,7 +10659,6 @@
 		return AST_TEST_NOT_RUN;
 	}
 	ast_set_flag(vmu, VM_ALLOCED);
-	populate_defaults(vmu);
 
 	apply_options(vmu, options_string);
 
@@ -10682,14 +10672,6 @@
 	}
 	if (strcasecmp(vmu->serveremail, "someguy at digium.com")) {
 		ast_test_status_update(test, "Parse failure for serveremail option\n");
-		res = 1;
-	}
-	if (!vmu->emailsubject || strcasecmp(vmu->emailsubject, "[PBX]: New message ${VM_MSGNUM} in mailbox ${VM_MAILBOX}")) {
-		ast_test_status_update(test, "Parse failure for emailsubject option\n");
-		res = 1;
-	}
-	if (!vmu->emailbody || strcasecmp(vmu->emailbody, "Dear ${VM_NAME}:\n\n\tYou were just left a ${VM_DUR} long message")) {
-		ast_test_status_update(test, "Parse failure for emailbody option\n");
 		res = 1;
 	}
 	if (strcasecmp(vmu->zonetag, "central")) {

Modified: trunk/apps/confbridge/conf_config_parser.c
URL: http://svnview.digium.com/svn/asterisk/trunk/apps/confbridge/conf_config_parser.c?view=diff&rev=325931&r1=325930&r2=325931
==============================================================================
--- trunk/apps/confbridge/conf_config_parser.c (original)
+++ trunk/apps/confbridge/conf_config_parser.c Thu Jun 30 15:33:15 2011
@@ -284,6 +284,14 @@
 		}
 	} else if (!strcasecmp(name, "record_conference")) {
 		ast_set2_flag(b_profile, ast_true(value), BRIDGE_OPT_RECORD_CONFERENCE);
+	} else if (!strcasecmp(name, "video_mode")) {
+		if (!strcasecmp(value, "first_marked")) {
+			ast_set_flag(b_profile, BRIDGE_OPT_VIDEO_SRC_FIRST_MARKED);
+		} else if (!strcasecmp(value, "last_marked")) {
+			ast_set_flag(b_profile, BRIDGE_OPT_VIDEO_SRC_LAST_MARKED);
+		} else if (!strcasecmp(value, "follow_talker")) {
+			ast_set_flag(b_profile, BRIDGE_OPT_VIDEO_SRC_FOLLOW_TALKER);
+		}
 	} else if (!strcasecmp(name, "max_members")) {
 		if (sscanf(value, "%30u", &b_profile->max_members) != 1) {
 			return -1;
@@ -534,6 +542,7 @@
 	case MENU_ACTION_ADMIN_TOGGLE_LOCK:
 	case MENU_ACTION_ADMIN_KICK_LAST:
 	case MENU_ACTION_LEAVE:
+	case MENU_ACTION_SET_SINGLE_VIDEO_SRC:
 		break;
 	case MENU_ACTION_PLAYBACK:
 	case MENU_ACTION_PLAYBACK_AND_CONTINUE:
@@ -649,6 +658,8 @@
 			res |= add_action_to_menu_entry(menu_entry, MENU_ACTION_ADMIN_KICK_LAST, NULL);
 		} else if (!strcasecmp(action, "leave_conference")) {
 			res |= add_action_to_menu_entry(menu_entry, MENU_ACTION_LEAVE, NULL);
+		} else if (!strcasecmp(action, "set_as_single_video_src")) {
+			res |= add_action_to_menu_entry(menu_entry, MENU_ACTION_SET_SINGLE_VIDEO_SRC, NULL);
 		} else if (!strncasecmp(action, "dialplan_exec(", 14)) {
 			ast_copy_string(buf, action, sizeof(buf));
 			action_args = buf;
@@ -983,6 +994,16 @@
 		ast_cli(a->fd,"Max Members:          No Limit\n");
 	}
 
+	if (b_profile.flags & BRIDGE_OPT_VIDEO_SRC_LAST_MARKED) {
+		ast_cli(a->fd, "Video Mode:           last_marked\n");
+	} else if (b_profile.flags & BRIDGE_OPT_VIDEO_SRC_FIRST_MARKED) {
+		ast_cli(a->fd, "Video Mode:           first_marked\n");
+	} else if (b_profile.flags & BRIDGE_OPT_VIDEO_SRC_FOLLOW_TALKER) {
+		ast_cli(a->fd, "Video Mode:           follow_talker\n");
+	} else {
+		ast_cli(a->fd, "Video Mode:           no video\n");
+	}
+
 	ast_cli(a->fd,"sound_join:           %s\n", conf_get_sound(CONF_SOUND_JOIN, b_profile.sounds));
 	ast_cli(a->fd,"sound_leave:          %s\n", conf_get_sound(CONF_SOUND_LEAVE, b_profile.sounds));
 	ast_cli(a->fd,"sound_only_person:    %s\n", conf_get_sound(CONF_SOUND_ONLY_PERSON, b_profile.sounds));
@@ -1142,6 +1163,9 @@
 			case MENU_ACTION_LEAVE:
 				ast_cli(a->fd, "leave_conference");
 				break;
+			case MENU_ACTION_SET_SINGLE_VIDEO_SRC:
+				ast_cli(a->fd, "set_as_single_video_src");
+				break;
 			}
 			action_num++;
 		}

Modified: trunk/apps/confbridge/include/confbridge.h
URL: http://svnview.digium.com/svn/asterisk/trunk/apps/confbridge/include/confbridge.h?view=diff&rev=325931&r1=325930&r2=325931
==============================================================================
--- trunk/apps/confbridge/include/confbridge.h (original)
+++ trunk/apps/confbridge/include/confbridge.h Thu Jun 30 15:33:15 2011
@@ -61,6 +61,9 @@
 
 enum bridge_profile_flags {
 	BRIDGE_OPT_RECORD_CONFERENCE = (1 << 0), /*!< Set if the conference should be recorded */
+	BRIDGE_OPT_VIDEO_SRC_LAST_MARKED = (1 << 1), /*!< Set if conference should feed video of last marked user to all participants. */
+	BRIDGE_OPT_VIDEO_SRC_FIRST_MARKED = (1 << 2), /*!< Set if conference should feed video of first marked user to all participants. */
+	BRIDGE_OPT_VIDEO_SRC_FOLLOW_TALKER = (1 << 3), /*!< Set if conference set the video feed to follow the loudest talker.  */
 };
 
 enum conf_menu_action_id {
@@ -78,6 +81,7 @@
 	MENU_ACTION_ADMIN_KICK_LAST,
 	MENU_ACTION_LEAVE,
 	MENU_ACTION_NOOP,
+	MENU_ACTION_SET_SINGLE_VIDEO_SRC,
 };
 
 /*! The conference menu action contains both

Modified: trunk/bridges/bridge_softmix.c
URL: http://svnview.digium.com/svn/asterisk/trunk/bridges/bridge_softmix.c?view=diff&rev=325931&r1=325930&r2=325931
==============================================================================
--- trunk/bridges/bridge_softmix.c (original)
+++ trunk/bridges/bridge_softmix.c Thu Jun 30 15:33:15 2011
@@ -69,6 +69,20 @@
  * mixed out its own write audio stream because it is not talking. */
 #define DEFAULT_SOFTMIX_SILENCE_THRESHOLD 2500
 #define DEFAULT_SOFTMIX_TALKING_THRESHOLD 160
+
+#define DEFAULT_ENERGY_HISTORY_LEN 150
+
+struct video_follow_talker_data {
+	/*! audio energy history */
+	int energy_history[DEFAULT_ENERGY_HISTORY_LEN];
+	/*! The current slot being used in the history buffer, this
+	 *  increments and wraps around */
+	int energy_history_cur_slot;
+	/*! The current energy sum used for averages. */
+	int energy_accum;
+	/*! The current energy average */
+	int energy_average;
+};
 
 /*! \brief Structure which contains per-channel mixing information */
 struct softmix_channel {
@@ -93,6 +107,8 @@
 	short final_buf[MAX_DATALEN];
 	/*! Buffer containing only the audio from the channel */
 	short our_buf[MAX_DATALEN];
+	/*! Data pertaining to talker mode for video conferencing */
+	struct video_follow_talker_data video_talker;
 };
 
 struct softmix_bridge_data {
@@ -419,12 +435,24 @@
 	}
 }
 
+static void softmix_pass_video(struct ast_bridge *bridge, struct ast_bridge_channel *bridge_channel, struct ast_frame *frame)
+{
+	struct ast_bridge_channel *tmp;
+	AST_LIST_TRAVERSE(&bridge->channels, tmp, entry) {
+		if (tmp->suspended) {
+			continue;
+		}
+		ast_write(tmp->chan, frame);
+	}
+}
+
 /*! \brief Function called when a channel writes a frame into the bridge */
 static enum ast_bridge_write_result softmix_bridge_write(struct ast_bridge *bridge, struct ast_bridge_channel *bridge_channel, struct ast_frame *frame)
 {
 	struct softmix_channel *sc = bridge_channel->bridge_pvt;
 	struct softmix_bridge_data *softmix_data = bridge->bridge_pvt;
 	int totalsilence = 0;
+	int cur_energy = 0;
 	int silence_threshold = bridge_channel->tech_args.silence_threshold ?
 		bridge_channel->tech_args.silence_threshold :
 		DEFAULT_SOFTMIX_SILENCE_THRESHOLD;
@@ -434,18 +462,52 @@
 	/* Only accept audio frames, all others are unsupported */
 	if (frame->frametype == AST_FRAME_DTMF_END || frame->frametype == AST_FRAME_DTMF_BEGIN) {
 		softmix_pass_dtmf(bridge, bridge_channel, frame);
-		goto no_audio;
-	} else if (frame->frametype != AST_FRAME_VOICE) {
+		goto bridge_write_cleanup;
+	} else if (frame->frametype != AST_FRAME_VOICE && frame->frametype != AST_FRAME_VIDEO) {
 		res = AST_BRIDGE_WRITE_UNSUPPORTED;
-		goto no_audio;
+		goto bridge_write_cleanup;
 	} else if (frame->datalen == 0) {
-		goto no_audio;
+		goto bridge_write_cleanup;
+	}
+
+	/* Determine if this video frame should be distributed or not */
+	if (frame->frametype == AST_FRAME_VIDEO) {
+		switch (bridge->video_mode.mode) {
+		case AST_BRIDGE_VIDEO_MODE_NONE:
+			break;
+		case AST_BRIDGE_VIDEO_MODE_SINGLE_SRC:
+			if (ast_bridge_is_video_src(bridge, bridge_channel->chan)) {
+				softmix_pass_video(bridge, bridge_channel, frame);
+			}
+			break;
+		case AST_BRIDGE_VIDEO_MODE_TALKER_SRC:
+			ast_mutex_lock(&sc->lock);
+			ast_bridge_update_talker_src_video_mode(bridge, bridge_channel->chan, sc->video_talker.energy_average, ast_format_get_video_mark(&frame->subclass.format));
+			ast_mutex_unlock(&sc->lock);
+			if (ast_bridge_is_video_src(bridge, bridge_channel->chan)) {
+				softmix_pass_video(bridge, bridge_channel, frame);
+			}
+			break;
+		}
+		goto bridge_write_cleanup;
 	}
 
 	/* If we made it here, we are going to write the frame into the conference */
 	ast_mutex_lock(&sc->lock);
-
-	ast_dsp_silence(sc->dsp, frame, &totalsilence);
+	ast_dsp_silence_with_energy(sc->dsp, frame, &totalsilence, &cur_energy);
+
+	if (bridge->video_mode.mode == AST_BRIDGE_VIDEO_MODE_TALKER_SRC) {
+		int cur_slot = sc->video_talker.energy_history_cur_slot;
+		sc->video_talker.energy_accum -= sc->video_talker.energy_history[cur_slot];
+		sc->video_talker.energy_accum += cur_energy;
+		sc->video_talker.energy_history[cur_slot] = cur_energy;
+		sc->video_talker.energy_average = sc->video_talker.energy_accum / DEFAULT_ENERGY_HISTORY_LEN;
+		sc->video_talker.energy_history_cur_slot++;
+		if (sc->video_talker.energy_history_cur_slot == DEFAULT_ENERGY_HISTORY_LEN) {
+			sc->video_talker.energy_history_cur_slot = 0; /* wrap around */
+		}
+	}
+
 	if (totalsilence < silence_threshold) {
 		if (!sc->talking) {
 			update_talking = 1;
@@ -487,7 +549,7 @@
 
 	return res;
 
-no_audio:
+bridge_write_cleanup:
 	/* Even though the frame is not being written into the conference because it is not audio,
 	 * we should use this opportunity to check to see if a frame is ready to be written out from
 	 * the conference to the channel. */
@@ -817,7 +879,7 @@
 
 static struct ast_bridge_technology softmix_bridge = {
 	.name = "softmix",
-	.capabilities = AST_BRIDGE_CAPABILITY_MULTIMIX | AST_BRIDGE_CAPABILITY_THREAD | AST_BRIDGE_CAPABILITY_MULTITHREADED | AST_BRIDGE_CAPABILITY_OPTIMIZE,
+	.capabilities = AST_BRIDGE_CAPABILITY_MULTIMIX | AST_BRIDGE_CAPABILITY_THREAD | AST_BRIDGE_CAPABILITY_MULTITHREADED | AST_BRIDGE_CAPABILITY_OPTIMIZE | AST_BRIDGE_CAPABILITY_VIDEO,
 	.preference = AST_BRIDGE_PREFERENCE_LOW,
 	.create = softmix_bridge_create,
 	.destroy = softmix_bridge_destroy,

Modified: trunk/configs/confbridge.conf.sample
URL: http://svnview.digium.com/svn/asterisk/trunk/configs/confbridge.conf.sample?view=diff&rev=325931&r1=325930&r2=325931
==============================================================================
--- trunk/configs/confbridge.conf.sample (original)
+++ trunk/configs/confbridge.conf.sample Thu Jun 30 15:33:15 2011
@@ -167,6 +167,26 @@
                         ; be chosen.  Using a larger mixing interval comes at the cost of introducing
                         ; larger amounts of delay into the bridge.  Valid values here are 10, 20, 40,
                         ; or 80.  By default 20ms is used.
+
+;video_mode = follow_talker ; Sets how confbridge handles video distribution to the conference participants.
+                           ; Note that participants wanting to view and be the source of a video feed
+                           ; _MUST_ be sharing the same video codec.
+                           ; --- MODES ---
+                           ; none: No video sources are set by default in the conference. It is still
+                           ;       possible for a user to be set as a video source via AMI or DTMF action
+                           ;       at any time.
+                           ;
+                           ; follow_talker: The video feed will follow whoever is talking and providing video.
+                           ;
+                           ; last_marked: The last marked user to join the conference with video capabilities
+                           ;              will be the single source of video distributed to all participants.
+                           ;              If multiple marked users are capable of video, the last one to join
+                           ;              is always the source, when that user leaves it goes to the one who
+                           ;              joined before them.
+                           ;
+                           ; first_marked: The first marked user to join the conference with video capabilities
+                           ;               is the single source of video distribution among all participants. If
+                           ;               that user leaves, the marked user to join after them becomes the source.
 
 ; All sounds in the conference are customizable using the bridge profile options below.
 ; Simply state the option followed by the filename or full path of the filename after
@@ -264,6 +284,8 @@
 ; admin_toggle_conference_lock ; This action allows an Admin to toggle locking and
                                ; unlocking the conference.  Non admins can not use
                                ; this action even if it is in their menu.
+; set_as_single_video_src   ; This action allows any user to set themselves as the
+                            ; single video source distributed to all participants.
 
 [sample_user_menu]
 type=menu

Modified: trunk/include/asterisk/bridging.h
URL: http://svnview.digium.com/svn/asterisk/trunk/include/asterisk/bridging.h?view=diff&rev=325931&r1=325930&r2=325931
==============================================================================
--- trunk/include/asterisk/bridging.h (original)
+++ trunk/include/asterisk/bridging.h Thu Jun 30 15:33:15 2011
@@ -167,12 +167,48 @@
 	AST_LIST_ENTRY(ast_bridge_channel) entry;
 };
 
+enum ast_bridge_video_mode_type {
+	/*! Video is not allowed in the bridge */
+	AST_BRIDGE_VIDEO_MODE_NONE = 0,
+	/*! A single user is picked as the only distributed of video across the bridge */
+	AST_BRIDGE_VIDEO_MODE_SINGLE_SRC,
+	/*! A single user's video feed is distributed to all bridge channels, but
+	 *  that feed is automatically picked based on who is talking the most. */
+	AST_BRIDGE_VIDEO_MODE_TALKER_SRC,
+};
+
+/*! This is used for both SINGLE_SRC mode to set what channel
+ *  should be the current single video feed */
+struct ast_bridge_video_single_src_data {
+	/*! Only accept video coming from this channel */
+	struct ast_channel *chan_vsrc;
+};
+
+/*! This is used for both SINGLE_SRC_TALKER mode to set what channel
+ *  should be the current single video feed */
+struct ast_bridge_video_talker_src_data {
+	/*! Only accept video coming from this channel */
+	struct ast_channel *chan_vsrc;
+	int average_talking_energy;
+};
+
+struct ast_bridge_video_mode {
+	enum ast_bridge_video_mode_type mode;
+	/* Add data for all the video modes here. */
+	union {
+		struct ast_bridge_video_single_src_data single_src_data;
+		struct ast_bridge_video_talker_src_data talker_src_data;
+	} mode_data;
+};
+
 /*!
  * \brief Structure that contains information about a bridge
  */
 struct ast_bridge {
 	/*! Number of channels participating in the bridge */
 	int num;
+	/*! The video mode this bridge is using */
+	struct ast_bridge_video_mode video_mode;
 	/*! The internal sample rate this bridge is mixed at when multiple channels are being mixed.
 	 *  If this value is 0, the bridge technology may auto adjust the internal mixing rate. */
 	unsigned int internal_sample_rate;
@@ -475,6 +511,31 @@
  */
 void ast_bridge_set_mixing_interval(struct ast_bridge *bridge, unsigned int mixing_interval);
 
+/*!
+ * \brief Set a bridge to feed a single video source to all participants.
+ */
+void ast_bridge_set_single_src_video_mode(struct ast_bridge *bridge, struct ast_channel *video_src_chan);
+
+/*!
+ * \brief Set the bridge to pick the strongest talker supporting
+ * video as the single source video feed
+ */
+void ast_bridge_set_talker_src_video_mode(struct ast_bridge *bridge);
+
+/*!
+ * \brief Update information about talker energy for talker src video mode.
+ */
+void ast_bridge_update_talker_src_video_mode(struct ast_bridge *bridge, struct ast_channel *chan, int talker_energy, int is_keyfame);
+
+/*!
+ * \brief Determine if a channel is a video src for the bridge
+ */
+int ast_bridge_is_video_src(struct ast_bridge *bridge, struct ast_channel *chan);
+
+/*!
+ * \brief remove a channel as a source of video for the bridge.
+ */
+void ast_bridge_remove_video_src(struct ast_bridge *bridge, struct ast_channel *chan);
 
 #if defined(__cplusplus) || defined(c_plusplus)
 }

Modified: trunk/include/asterisk/dsp.h
URL: http://svnview.digium.com/svn/asterisk/trunk/include/asterisk/dsp.h?view=diff&rev=325931&r1=325930&r2=325931
==============================================================================
--- trunk/include/asterisk/dsp.h (original)
+++ trunk/include/asterisk/dsp.h Thu Jun 30 15:33:15 2011
@@ -109,6 +109,11 @@
    number of seconds of silence  */
 int ast_dsp_silence(struct ast_dsp *dsp, struct ast_frame *f, int *totalsilence);
 
+/*! \brief Return non-zero if this is silence.  Updates "totalsilence" with the total
+   number of seconds of silence. Returns the average energy of the samples in the frame
+   in frames_energy variable. */
+int ast_dsp_silence_with_energy(struct ast_dsp *dsp, struct ast_frame *f, int *totalsilence, int *frames_energy);
+
 /*!
  * \brief Return non-zero if this is noise.  Updates "totalnoise" with the total
  * number of seconds of noise

Modified: trunk/main/bridging.c
URL: http://svnview.digium.com/svn/asterisk/trunk/main/bridging.c?view=diff&rev=325931&r1=325930&r2=325931
==============================================================================
--- trunk/main/bridging.c (original)
+++ trunk/main/bridging.c Thu Jun 30 15:33:15 2011
@@ -50,6 +50,8 @@
 /* Grow rate of bridge array of channels */
 #define BRIDGE_ARRAY_GROW 32
 
+static void cleanup_video_mode(struct ast_bridge *bridge);
+
 /*! Default DTMF keys for built in features */
 static char builtin_features_dtmf[AST_BRIDGE_BUILTIN_END][MAXIMUM_DTMF_FEATURE_STRING];
 
@@ -456,6 +458,8 @@
 
 	/* Drop the array of channels */
 	ast_free(bridge->array);
+
+	cleanup_video_mode(bridge);
 
 	return;
 }
@@ -1470,3 +1474,116 @@
 	bridge->internal_sample_rate = sample_rate;
 	ao2_unlock(bridge);
 }
+
+static void cleanup_video_mode(struct ast_bridge *bridge)
+{
+	switch (bridge->video_mode.mode) {
+	case AST_BRIDGE_VIDEO_MODE_NONE:
+		break;
+	case AST_BRIDGE_VIDEO_MODE_SINGLE_SRC:
+		if (bridge->video_mode.mode_data.single_src_data.chan_vsrc) {
+			ast_channel_unref(bridge->video_mode.mode_data.single_src_data.chan_vsrc);
+		}
+		break;
+	case AST_BRIDGE_VIDEO_MODE_TALKER_SRC:
+		if (bridge->video_mode.mode_data.talker_src_data.chan_vsrc) {
+			ast_channel_unref(bridge->video_mode.mode_data.talker_src_data.chan_vsrc);
+		}
+	}
+	memset(&bridge->video_mode, 0, sizeof(bridge->video_mode));
+}
+
+void ast_bridge_set_single_src_video_mode(struct ast_bridge *bridge, struct ast_channel *video_src_chan)
+{
+	ao2_lock(bridge);
+	cleanup_video_mode(bridge);
+	bridge->video_mode.mode = AST_BRIDGE_VIDEO_MODE_SINGLE_SRC;
+	bridge->video_mode.mode_data.single_src_data.chan_vsrc = ast_channel_ref(video_src_chan);
+	ast_indicate(video_src_chan, AST_CONTROL_VIDUPDATE);
+	ao2_unlock(bridge);
+}
+
+void ast_bridge_set_talker_src_video_mode(struct ast_bridge *bridge)
+{
+	ao2_lock(bridge);
+	cleanup_video_mode(bridge);
+	bridge->video_mode.mode = AST_BRIDGE_VIDEO_MODE_TALKER_SRC;
+	ao2_unlock(bridge);
+}
+
+void ast_bridge_update_talker_src_video_mode(struct ast_bridge *bridge, struct ast_channel *chan, int talker_energy, int is_keyframe)
+{
+	struct ast_bridge_video_talker_src_data *data;
+	/* If the channel doesn't support video, we don't care about it */
+	if (!ast_format_cap_has_type(chan->nativeformats, AST_FORMAT_TYPE_VIDEO)) {
+		return;
+	}
+
+	ao2_lock(bridge);
+	data = &bridge->video_mode.mode_data.talker_src_data;
+
+	if (data->chan_vsrc == chan) {
+		data->average_talking_energy = talker_energy;
+	} else if ((data->average_talking_energy < talker_energy) && is_keyframe) {
+		if (data->chan_vsrc) {
+			ast_channel_unref(data->chan_vsrc);
+		}
+		data->chan_vsrc = ast_channel_ref(chan);
+		data->average_talking_energy = talker_energy;
+		ast_indicate(chan, AST_CONTROL_VIDUPDATE);
+	} else if ((data->average_talking_energy < talker_energy) && !is_keyframe) {
+		ast_indicate(chan, AST_CONTROL_VIDUPDATE);
+	} else if (!data->chan_vsrc && is_keyframe) {
+		data->chan_vsrc = ast_channel_ref(chan);
+		data->average_talking_energy = talker_energy;
+		ast_indicate(chan, AST_CONTROL_VIDUPDATE);
+	}
+	ao2_unlock(bridge);
+}
+
+int ast_bridge_is_video_src(struct ast_bridge *bridge, struct ast_channel *chan)
+{
+	int res = 0;
+
+	ao2_lock(bridge);
+	switch (bridge->video_mode.mode) {
+	case AST_BRIDGE_VIDEO_MODE_NONE:
+		break;
+	case AST_BRIDGE_VIDEO_MODE_SINGLE_SRC:
+		if (bridge->video_mode.mode_data.single_src_data.chan_vsrc == chan) {
+			res = 1;
+		}
+		break;
+	case AST_BRIDGE_VIDEO_MODE_TALKER_SRC:
+		if (bridge->video_mode.mode_data.talker_src_data.chan_vsrc == chan) {
+			res = 1;
+		}
+	}
+	ao2_unlock(bridge);
+	return res;
+}
+
+void ast_bridge_remove_video_src(struct ast_bridge *bridge, struct ast_channel *chan)
+{
+	ao2_lock(bridge);
+	switch (bridge->video_mode.mode) {
+	case AST_BRIDGE_VIDEO_MODE_NONE:
+		break;
+	case AST_BRIDGE_VIDEO_MODE_SINGLE_SRC:
+		if (bridge->video_mode.mode_data.single_src_data.chan_vsrc == chan) {
+			if (bridge->video_mode.mode_data.single_src_data.chan_vsrc) {
+				ast_channel_unref(bridge->video_mode.mode_data.single_src_data.chan_vsrc);
+			}
+			bridge->video_mode.mode_data.single_src_data.chan_vsrc = NULL;
+		}
+		break;
+	case AST_BRIDGE_VIDEO_MODE_TALKER_SRC:
+		if (bridge->video_mode.mode_data.talker_src_data.chan_vsrc == chan) {
+			if (bridge->video_mode.mode_data.talker_src_data.chan_vsrc) {
+				ast_channel_unref(bridge->video_mode.mode_data.talker_src_data.chan_vsrc);
+			}
+			bridge->video_mode.mode_data.talker_src_data.chan_vsrc = NULL;
+		}
+	}
+	ao2_unlock(bridge);
+}

Modified: trunk/main/dsp.c
URL: http://svnview.digium.com/svn/asterisk/trunk/main/dsp.c?view=diff&rev=325931&r1=325930&r2=325931
==============================================================================
--- trunk/main/dsp.c (original)
+++ trunk/main/dsp.c Thu Jun 30 15:33:15 2011
@@ -1103,7 +1103,7 @@
 	return __ast_dsp_call_progress(dsp, inf->data.ptr, inf->datalen / 2);
 }
 
-static int __ast_dsp_silence_noise(struct ast_dsp *dsp, short *s, int len, int *totalsilence, int *totalnoise)
+static int __ast_dsp_silence_noise(struct ast_dsp *dsp, short *s, int len, int *totalsilence, int *totalnoise, int *frames_energy)
 {
 	int accum;
 	int x;
@@ -1163,6 +1163,9 @@
 	if (totalnoise) {
 		*totalnoise = dsp->totalnoise;
 	}
+	if (frames_energy) {
+		*frames_energy = accum;
+	}
 	return res;
 }
 
@@ -1318,7 +1321,25 @@
 	}
 	s = f->data.ptr;
 	len = f->datalen/2;
-	return __ast_dsp_silence_noise(dsp, s, len, totalsilence, NULL);
+	return __ast_dsp_silence_noise(dsp, s, len, totalsilence, NULL, NULL);
+}
+
+int ast_dsp_silence_with_energy(struct ast_dsp *dsp, struct ast_frame *f, int *totalsilence, int *frames_energy)
+{
+	short *s;
+	int len;
+
+	if (f->frametype != AST_FRAME_VOICE) {
+		ast_log(LOG_WARNING, "Can't calculate silence on a non-voice frame\n");
+		return 0;
+	}
+	if (!ast_format_is_slinear(&f->subclass.format)) {
+		ast_log(LOG_WARNING, "Can only calculate silence on signed-linear frames :(\n");
+		return 0;
+	}
+	s = f->data.ptr;
+	len = f->datalen/2;
+	return __ast_dsp_silence_noise(dsp, s, len, totalsilence, NULL, frames_energy);
 }
 
 int ast_dsp_noise(struct ast_dsp *dsp, struct ast_frame *f, int *totalnoise)
@@ -1336,7 +1357,7 @@
        }
        s = f->data.ptr;
        len = f->datalen/2;
-       return __ast_dsp_silence_noise(dsp, s, len, NULL, totalnoise);
+       return __ast_dsp_silence_noise(dsp, s, len, NULL, totalnoise, NULL);
 }
 
 
@@ -1393,7 +1414,7 @@
 
 	/* Need to run the silence detection stuff for silence suppression and busy detection */
 	if ((dsp->features & DSP_FEATURE_SILENCE_SUPPRESS) || (dsp->features & DSP_FEATURE_BUSY_DETECT)) {
-		res = __ast_dsp_silence_noise(dsp, shortdata, len, &silence, NULL);
+		res = __ast_dsp_silence_noise(dsp, shortdata, len, &silence, NULL, NULL);
 	}
 
 	if ((dsp->features & DSP_FEATURE_SILENCE_SUPPRESS) && silence) {




More information about the svn-commits mailing list