[asterisk-commits] dvossel: branch dvossel/shortbus r325811 - in /team/dvossel/shortbus: apps/ a...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Thu Jun 30 11:16:07 CDT 2011


Author: dvossel
Date: Thu Jun 30 11:16:03 2011
New Revision: 325811

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=325811
Log:
follow_talker confbridge video_mode option

Modified:
    team/dvossel/shortbus/apps/app_confbridge.c
    team/dvossel/shortbus/apps/confbridge/conf_config_parser.c
    team/dvossel/shortbus/apps/confbridge/include/confbridge.h
    team/dvossel/shortbus/bridges/bridge_softmix.c
    team/dvossel/shortbus/configs/confbridge.conf.sample
    team/dvossel/shortbus/include/asterisk/bridging.h
    team/dvossel/shortbus/include/asterisk/dsp.h
    team/dvossel/shortbus/main/bridging.c
    team/dvossel/shortbus/main/dsp.c

Modified: team/dvossel/shortbus/apps/app_confbridge.c
URL: http://svnview.digium.com/svn/asterisk/team/dvossel/shortbus/apps/app_confbridge.c?view=diff&rev=325811&r1=325810&r2=325811
==============================================================================
--- team/dvossel/shortbus/apps/app_confbridge.c (original)
+++ team/dvossel/shortbus/apps/app_confbridge.c Thu Jun 30 11:16:03 2011
@@ -667,6 +667,8 @@
 		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)) {
@@ -931,6 +933,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);

Modified: team/dvossel/shortbus/apps/confbridge/conf_config_parser.c
URL: http://svnview.digium.com/svn/asterisk/team/dvossel/shortbus/apps/confbridge/conf_config_parser.c?view=diff&rev=325811&r1=325810&r2=325811
==============================================================================
--- team/dvossel/shortbus/apps/confbridge/conf_config_parser.c (original)
+++ team/dvossel/shortbus/apps/confbridge/conf_config_parser.c Thu Jun 30 11:16:03 2011
@@ -289,6 +289,8 @@
 			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) {
@@ -996,6 +998,8 @@
 		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");
 	}

Modified: team/dvossel/shortbus/apps/confbridge/include/confbridge.h
URL: http://svnview.digium.com/svn/asterisk/team/dvossel/shortbus/apps/confbridge/include/confbridge.h?view=diff&rev=325811&r1=325810&r2=325811
==============================================================================
--- team/dvossel/shortbus/apps/confbridge/include/confbridge.h (original)
+++ team/dvossel/shortbus/apps/confbridge/include/confbridge.h Thu Jun 30 11:16:03 2011
@@ -63,6 +63,7 @@
 	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 {

Modified: team/dvossel/shortbus/bridges/bridge_softmix.c
URL: http://svnview.digium.com/svn/asterisk/team/dvossel/shortbus/bridges/bridge_softmix.c?view=diff&rev=325811&r1=325810&r2=325811
==============================================================================
--- team/dvossel/shortbus/bridges/bridge_softmix.c (original)
+++ team/dvossel/shortbus/bridges/bridge_softmix.c Thu Jun 30 11:16:03 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 {
@@ -436,6 +452,7 @@
 	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;
@@ -459,6 +476,10 @@
 		case AST_BRIDGE_VIDEO_MODE_NONE:
 			break;
 		case AST_BRIDGE_VIDEO_MODE_SINGLE_SRC:
+		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);
 			}
@@ -469,8 +490,20 @@
 
 	/* 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;

Modified: team/dvossel/shortbus/configs/confbridge.conf.sample
URL: http://svnview.digium.com/svn/asterisk/team/dvossel/shortbus/configs/confbridge.conf.sample?view=diff&rev=325811&r1=325810&r2=325811
==============================================================================
--- team/dvossel/shortbus/configs/confbridge.conf.sample (original)
+++ team/dvossel/shortbus/configs/confbridge.conf.sample Thu Jun 30 11:16:03 2011
@@ -168,13 +168,15 @@
                         ; larger amounts of delay into the bridge.  Valid values here are 10, 20, 40,
                         ; or 80.  By default 20ms is used.
 
-;video_mode = first_marked ; Sets how confbridge handles video distribution to the conference participants.
+;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.

Modified: team/dvossel/shortbus/include/asterisk/bridging.h
URL: http://svnview.digium.com/svn/asterisk/team/dvossel/shortbus/include/asterisk/bridging.h?view=diff&rev=325811&r1=325810&r2=325811
==============================================================================
--- team/dvossel/shortbus/include/asterisk/bridging.h (original)
+++ team/dvossel/shortbus/include/asterisk/bridging.h Thu Jun 30 11:16:03 2011
@@ -172,15 +172,24 @@
 	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,
-	/* Future modes
-	AST_BRIDGE_VIDEO_MODE_TALKER_ONLY, // Strongest talker's video feed is distributed
-	AST_BRIDGE_VIDEO_MODE_MIXED, //  users are mixed into a single frame
-	*/
-};
-
+	/*! 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 {
@@ -188,6 +197,7 @@
 	/* 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;
 };
 
@@ -507,10 +517,25 @@
 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: team/dvossel/shortbus/include/asterisk/dsp.h
URL: http://svnview.digium.com/svn/asterisk/team/dvossel/shortbus/include/asterisk/dsp.h?view=diff&rev=325811&r1=325810&r2=325811
==============================================================================
--- team/dvossel/shortbus/include/asterisk/dsp.h (original)
+++ team/dvossel/shortbus/include/asterisk/dsp.h Thu Jun 30 11:16:03 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: team/dvossel/shortbus/main/bridging.c
URL: http://svnview.digium.com/svn/asterisk/team/dvossel/shortbus/main/bridging.c?view=diff&rev=325811&r1=325810&r2=325811
==============================================================================
--- team/dvossel/shortbus/main/bridging.c (original)
+++ team/dvossel/shortbus/main/bridging.c Thu Jun 30 11:16:03 2011
@@ -1485,6 +1485,10 @@
 			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));
 }
@@ -1496,6 +1500,44 @@
 	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);
 }
 
@@ -1512,7 +1554,36 @@
 			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: team/dvossel/shortbus/main/dsp.c
URL: http://svnview.digium.com/svn/asterisk/team/dvossel/shortbus/main/dsp.c?view=diff&rev=325811&r1=325810&r2=325811
==============================================================================
--- team/dvossel/shortbus/main/dsp.c (original)
+++ team/dvossel/shortbus/main/dsp.c Thu Jun 30 11:16:03 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 asterisk-commits mailing list