[asterisk-commits] rmudgett: trunk r392514 - in /trunk: bridges/ include/asterisk/ main/
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Fri Jun 21 17:39:29 CDT 2013
Author: rmudgett
Date: Fri Jun 21 17:39:27 2013
New Revision: 392514
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=392514
Log:
Extract a useful routine from the softmix bridge technology.
* Extract a useful routine from the softmix bridge technology for other
technologies. Make other technologies use it if they can.
* Made native and 1-1 bridges write to all parties if the bridge channel
writing the frame into the bridge is NULL. Softmix will also do the same
for frame types that make sense.
* Tweak the bridge write routine return value meaning and adjust the
bridge technologies to match.
Modified:
trunk/bridges/bridge_holding.c
trunk/bridges/bridge_native_rtp.c
trunk/bridges/bridge_simple.c
trunk/bridges/bridge_softmix.c
trunk/include/asterisk/bridging.h
trunk/include/asterisk/bridging_technology.h
trunk/main/bridging.c
Modified: trunk/bridges/bridge_holding.c
URL: http://svnview.digium.com/svn/asterisk/trunk/bridges/bridge_holding.c?view=diff&rev=392514&r1=392513&r2=392514
==============================================================================
--- trunk/bridges/bridge_holding.c (original)
+++ trunk/bridges/bridge_holding.c Fri Jun 21 17:39:27 2013
@@ -255,27 +255,25 @@
static int holding_bridge_write(struct ast_bridge *bridge, struct ast_bridge_channel *bridge_channel, struct ast_frame *frame)
{
- struct ast_bridge_channel *cur;
- struct holding_channel *hc = bridge_channel->tech_pvt;
+ struct holding_channel *hc = bridge_channel ? bridge_channel->tech_pvt : NULL;
/* If there is no tech_pvt, then the channel failed to allocate one when it joined and is borked. Don't listen to him. */
if (!hc) {
- return -1;
+ /* "Accept" the frame and discard it. */
+ return 0;
}
/* If we aren't an announcer, we never have any business writing anything. */
if (!ast_test_flag(&hc->holding_roles, HOLDING_ROLE_ANNOUNCER)) {
- return -1;
- }
-
- /* Ok, so we are the announcer and there are one or more people available to receive our writes. Let's do it. */
- AST_LIST_TRAVERSE(&bridge->channels, cur, entry) {
- if (bridge_channel == cur || !cur->tech_pvt) {
- continue;
- }
-
- ast_bridge_channel_queue_frame(cur, frame);
- }
+ /* "Accept" the frame and discard it. */
+ return 0;
+ }
+
+ /*
+ * Ok, so we are the announcer. Write the frame to all other
+ * channels if any.
+ */
+ ast_bridge_queue_everyone_else(bridge, bridge_channel, frame);
return 0;
}
Modified: trunk/bridges/bridge_native_rtp.c
URL: http://svnview.digium.com/svn/asterisk/trunk/bridges/bridge_native_rtp.c?view=diff&rev=392514&r1=392513&r2=392514
==============================================================================
--- trunk/bridges/bridge_native_rtp.c (original)
+++ trunk/bridges/bridge_native_rtp.c Fri Jun 21 17:39:27 2013
@@ -389,16 +389,7 @@
static int native_rtp_bridge_write(struct ast_bridge *bridge, struct ast_bridge_channel *bridge_channel, struct ast_frame *frame)
{
- struct ast_bridge_channel *other = ast_bridge_channel_peer(bridge_channel);
-
- if (!other) {
- return -1;
- }
-
- /* The bridging core takes care of freeing the passed in frame. */
- ast_bridge_channel_queue_frame(other, frame);
-
- return 0;
+ return ast_bridge_queue_everyone_else(bridge, bridge_channel, frame);
}
static struct ast_bridge_technology native_rtp_bridge = {
Modified: trunk/bridges/bridge_simple.c
URL: http://svnview.digium.com/svn/asterisk/trunk/bridges/bridge_simple.c?view=diff&rev=392514&r1=392513&r2=392514
==============================================================================
--- trunk/bridges/bridge_simple.c (original)
+++ trunk/bridges/bridge_simple.c Fri Jun 21 17:39:27 2013
@@ -68,18 +68,7 @@
static int simple_bridge_write(struct ast_bridge *bridge, struct ast_bridge_channel *bridge_channel, struct ast_frame *frame)
{
- struct ast_bridge_channel *other;
-
- /* Find the channel we actually want to write to */
- other = ast_bridge_channel_peer(bridge_channel);
- if (!other) {
- return -1;
- }
-
- /* The bridging core takes care of freeing the passed in frame. */
- ast_bridge_channel_queue_frame(other, frame);
-
- return 0;
+ return ast_bridge_queue_everyone_else(bridge, bridge_channel, frame);
}
static struct ast_bridge_technology simple_bridge = {
Modified: trunk/bridges/bridge_softmix.c
URL: http://svnview.digium.com/svn/asterisk/trunk/bridges/bridge_softmix.c?view=diff&rev=392514&r1=392513&r2=392514
==============================================================================
--- trunk/bridges/bridge_softmix.c (original)
+++ trunk/bridges/bridge_softmix.c Fri Jun 21 17:39:27 2013
@@ -445,29 +445,6 @@
ast_free(sc);
}
-/*!
- * \internal
- * \brief Pass the given frame to everyone else.
- * \since 12.0.0
- *
- * \param bridge What bridge to distribute frame.
- * \param bridge_channel Channel to optionally not pass frame to. (NULL to pass to everyone)
- * \param frame Frame to pass.
- *
- * \return Nothing
- */
-static void softmix_pass_everyone_else(struct ast_bridge *bridge, struct ast_bridge_channel *bridge_channel, struct ast_frame *frame)
-{
- struct ast_bridge_channel *cur;
-
- AST_LIST_TRAVERSE(&bridge->channels, cur, entry) {
- if (cur == bridge_channel) {
- continue;
- }
- ast_bridge_channel_queue_frame(cur, frame);
- }
-}
-
static void softmix_pass_video_top_priority(struct ast_bridge *bridge, struct ast_frame *frame)
{
struct ast_bridge_channel *cur;
@@ -507,7 +484,7 @@
video_src_priority = ast_bridge_is_video_src(bridge, bridge_channel->chan);
if (video_src_priority == 1) {
/* Pass to me and everyone else. */
- softmix_pass_everyone_else(bridge, NULL, frame);
+ ast_bridge_queue_everyone_else(bridge, NULL, frame);
}
break;
case AST_BRIDGE_VIDEO_MODE_TALKER_SRC:
@@ -522,7 +499,7 @@
int num_src = ast_bridge_number_video_src(bridge);
int echo = num_src > 1 ? 0 : 1;
- softmix_pass_everyone_else(bridge, echo ? NULL : bridge_channel, frame);
+ ast_bridge_queue_everyone_else(bridge, echo ? NULL : bridge_channel, frame);
} else if (video_src_priority == 2) {
softmix_pass_video_top_priority(bridge, frame);
}
@@ -612,12 +589,14 @@
* \param bridge_channel Which channel is writing the frame.
* \param frame What is being written.
*
- * \return Nothing
- */
-static void softmix_bridge_write_control(struct ast_bridge *bridge, struct ast_bridge_channel *bridge_channel, struct ast_frame *frame)
+ * \retval 0 Frame accepted into the bridge.
+ * \retval -1 Frame needs to be deferred.
+ */
+static int softmix_bridge_write_control(struct ast_bridge *bridge, struct ast_bridge_channel *bridge_channel, struct ast_frame *frame)
{
/* BUGBUG need to look at channel roles to determine what to do with control frame. */
/*! \todo BUGBUG softmix_bridge_write_control() not written */
+ return 0;
}
/*!
@@ -629,8 +608,8 @@
* \param bridge_channel Which channel is writing the frame.
* \param frame What is being written.
*
- * \retval 0 on success
- * \retval -1 on failure
+ * \retval 0 Frame accepted into the bridge.
+ * \retval -1 Frame needs to be deferred.
*
* \note On entry, bridge is already locked.
*/
@@ -638,30 +617,35 @@
{
int res = 0;
- if (!bridge->tech_pvt || !bridge_channel->tech_pvt) {
- return -1;
+ if (!bridge->tech_pvt || (bridge_channel && !bridge_channel->tech_pvt)) {
+ /* "Accept" the frame and discard it. */
+ return 0;
}
switch (frame->frametype) {
case AST_FRAME_DTMF_BEGIN:
case AST_FRAME_DTMF_END:
- softmix_pass_everyone_else(bridge, bridge_channel, frame);
+ res = ast_bridge_queue_everyone_else(bridge, bridge_channel, frame);
break;
case AST_FRAME_VOICE:
- softmix_bridge_write_voice(bridge, bridge_channel, frame);
+ if (bridge_channel) {
+ softmix_bridge_write_voice(bridge, bridge_channel, frame);
+ }
break;
case AST_FRAME_VIDEO:
- softmix_bridge_write_video(bridge, bridge_channel, frame);
+ if (bridge_channel) {
+ softmix_bridge_write_video(bridge, bridge_channel, frame);
+ }
break;
case AST_FRAME_CONTROL:
- softmix_bridge_write_control(bridge, bridge_channel, frame);
+ res = softmix_bridge_write_control(bridge, bridge_channel, frame);
break;
case AST_FRAME_BRIDGE_ACTION:
- softmix_pass_everyone_else(bridge, bridge_channel, frame);
+ res = ast_bridge_queue_everyone_else(bridge, bridge_channel, frame);
break;
default:
ast_debug(3, "Frame type %d unsupported\n", frame->frametype);
- res = -1;
+ /* "Accept" the frame and discard it. */
break;
}
Modified: trunk/include/asterisk/bridging.h
URL: http://svnview.digium.com/svn/asterisk/trunk/include/asterisk/bridging.h?view=diff&rev=392514&r1=392513&r2=392514
==============================================================================
--- trunk/include/asterisk/bridging.h (original)
+++ trunk/include/asterisk/bridging.h Fri Jun 21 17:39:27 2013
@@ -1065,6 +1065,22 @@
void ast_bridge_update_accountcodes(struct ast_bridge *bridge, struct ast_bridge_channel *bridge_channel, struct ast_bridge_channel *swap);
/*!
+ * \brief Queue the given frame to everyone else.
+ * \since 12.0.0
+ *
+ * \param bridge What bridge to distribute frame.
+ * \param bridge_channel Channel to optionally not pass frame to. (NULL to pass to everyone)
+ * \param frame Frame to pass.
+ *
+ * \note This is intended to be called by bridge hooks and
+ * bridge technologies.
+ *
+ * \retval 0 Frame written to at least one channel.
+ * \retval -1 Frame written to no channels.
+ */
+int ast_bridge_queue_everyone_else(struct ast_bridge *bridge, struct ast_bridge_channel *bridge_channel, struct ast_frame *frame);
+
+/*!
* \brief Write a frame to the specified bridge_channel.
* \since 12.0.0
*
Modified: trunk/include/asterisk/bridging_technology.h
URL: http://svnview.digium.com/svn/asterisk/trunk/include/asterisk/bridging_technology.h?view=diff&rev=392514&r1=392513&r2=392514
==============================================================================
--- trunk/include/asterisk/bridging_technology.h (original)
+++ trunk/include/asterisk/bridging_technology.h Fri Jun 21 17:39:27 2013
@@ -124,8 +124,10 @@
/*!
* \brief Write a frame into the bridging technology instance for a bridge.
*
- * \retval 0 on success
- * \retval -1 on failure
+ * \note The bridge must be tolerant of bridge_channel being NULL.
+ *
+ * \retval 0 Frame accepted into the bridge.
+ * \retval -1 Frame needs to be deferred.
*
* \note On entry, bridge is already locked.
*/
Modified: trunk/main/bridging.c
URL: http://svnview.digium.com/svn/asterisk/trunk/main/bridging.c?view=diff&rev=392514&r1=392513&r2=392514
==============================================================================
--- trunk/main/bridging.c (original)
+++ trunk/main/bridging.c Fri Jun 21 17:39:27 2013
@@ -419,6 +419,22 @@
};
return ast_bridge_channel_queue_frame(bridge_channel, &frame);
+}
+
+int ast_bridge_queue_everyone_else(struct ast_bridge *bridge, struct ast_bridge_channel *bridge_channel, struct ast_frame *frame)
+{
+ struct ast_bridge_channel *cur;
+ int not_written = -1;
+
+ AST_LIST_TRAVERSE(&bridge->channels, cur, entry) {
+ if (cur == bridge_channel) {
+ continue;
+ }
+ if (!ast_bridge_channel_queue_frame(cur, frame)) {
+ not_written = 0;
+ }
+ }
+ return not_written;
}
void ast_bridge_channel_restore_formats(struct ast_bridge_channel *bridge_channel)
More information about the asterisk-commits
mailing list