Sat Apr 26 2014 22:01:58

Asterisk developer's documentation


bridging.c File Reference

Channel Bridging API. More...

#include "asterisk.h"
#include <signal.h>
#include "asterisk/logger.h"
#include "asterisk/channel.h"
#include "asterisk/options.h"
#include "asterisk/utils.h"
#include "asterisk/lock.h"
#include "asterisk/linkedlists.h"
#include "asterisk/bridging.h"
#include "asterisk/bridging_technology.h"
#include "asterisk/app.h"
#include "asterisk/file.h"
#include "asterisk/module.h"
#include "asterisk/astobj2.h"
#include "asterisk/test.h"
Include dependency graph for bridging.c:

Go to the source code of this file.

Data Structures

struct  bridge_technologies

Defines

#define BRIDGE_ARRAY_GROW   32
#define BRIDGE_ARRAY_START   128

Functions

int __ast_bridge_technology_register (struct ast_bridge_technology *technology, struct ast_module *module)
 Register a bridge technology for use.
void ast_bridge_change_state (struct ast_bridge_channel *bridge_channel, enum ast_bridge_channel_state new_state)
 Change the state of a bridged channel.
int ast_bridge_check (uint32_t capabilities)
 See if it is possible to create a bridge.
int ast_bridge_depart (struct ast_bridge *bridge, struct ast_channel *chan)
 Depart a channel from a bridge.
int ast_bridge_destroy (struct ast_bridge *bridge)
 Destroy a bridge.
int ast_bridge_dtmf_stream (struct ast_bridge *bridge, const char *dtmf, struct ast_channel *chan)
 Play a DTMF stream into a bridge, optionally not to a given channel.
int ast_bridge_features_cleanup (struct ast_bridge_features *features)
 Clean up the contents of a bridge features structure.
int ast_bridge_features_enable (struct ast_bridge_features *features, enum ast_bridge_builtin_feature feature, const char *dtmf, void *config)
 Enable a built in feature on a bridge features structure.
int ast_bridge_features_hook (struct ast_bridge_features *features, const char *dtmf, ast_bridge_features_hook_callback callback, void *hook_pvt, ast_bridge_features_hook_pvt_destructor destructor)
 Attach a custom hook to a bridge features structure.
int ast_bridge_features_init (struct ast_bridge_features *features)
 Initialize bridge features structure.
int ast_bridge_features_register (enum ast_bridge_builtin_feature feature, ast_bridge_features_hook_callback callback, const char *dtmf)
 Register a handler for a built in feature.
int ast_bridge_features_set_flag (struct ast_bridge_features *features, enum ast_bridge_feature_flags flag)
 Set a flag on a bridge features structure.
int ast_bridge_features_set_talk_detector (struct ast_bridge_features *features, ast_bridge_talking_indicate_callback talker_cb, ast_bridge_talking_indicate_destructor talker_destructor, void *pvt_data)
 Set a callback on the features structure to receive talking notifications on.
int ast_bridge_features_unregister (enum ast_bridge_builtin_feature feature)
 Unregister a handler for a built in feature.
void ast_bridge_handle_trip (struct ast_bridge *bridge, struct ast_bridge_channel *bridge_channel, struct ast_channel *chan, int outfd)
 Feed notification that a frame is waiting on a channel into the bridging core.
int ast_bridge_impart (struct ast_bridge *bridge, struct ast_channel *chan, struct ast_channel *swap, struct ast_bridge_features *features, int allow_hangup)
 Impart (non-blocking) a channel on a bridge.
int ast_bridge_is_video_src (struct ast_bridge *bridge, struct ast_channel *chan)
 Determine if a channel is a video src for the bridge.
enum ast_bridge_channel_state ast_bridge_join (struct ast_bridge *bridge, struct ast_channel *chan, struct ast_channel *swap, struct ast_bridge_features *features, struct ast_bridge_tech_optimizations *tech_args)
 Join (blocking) a channel to a bridge.
int ast_bridge_merge (struct ast_bridge *bridge0, struct ast_bridge *bridge1)
 Merge two bridges together.
struct ast_bridgeast_bridge_new (uint32_t capabilities, int flags)
 Create a new bridge.
void ast_bridge_notify_talking (struct ast_bridge *bridge, struct ast_bridge_channel *bridge_channel, int started_talking)
 Lets the bridging indicate when a bridge channel has stopped or started talking.
int ast_bridge_number_video_src (struct ast_bridge *bridge)
 Returns the number of video sources currently active in the bridge.
int ast_bridge_remove (struct ast_bridge *bridge, struct ast_channel *chan)
 Remove a channel from a bridge.
void ast_bridge_remove_video_src (struct ast_bridge *bridge, struct ast_channel *chan)
 remove a channel as a source of video for the bridge.
void ast_bridge_set_internal_sample_rate (struct ast_bridge *bridge, unsigned int sample_rate)
 Adjust the internal mixing sample rate of a bridge used during multimix mode.
void ast_bridge_set_mixing_interval (struct ast_bridge *bridge, unsigned int mixing_interval)
 Adjust the internal mixing interval of a bridge used during multimix mode.
void ast_bridge_set_single_src_video_mode (struct ast_bridge *bridge, struct ast_channel *video_src_chan)
 Set a bridge to feed a single video source to all participants.
void ast_bridge_set_talker_src_video_mode (struct ast_bridge *bridge)
 Set the bridge to pick the strongest talker supporting video as the single source video feed.
int ast_bridge_suspend (struct ast_bridge *bridge, struct ast_channel *chan)
 Suspend a channel temporarily from a bridge.
void ast_bridge_technology_suspend (struct ast_bridge_technology *technology)
 Suspend a bridge technology from consideration.
int ast_bridge_technology_unregister (struct ast_bridge_technology *technology)
 Unregister a bridge technology from use.
void ast_bridge_technology_unsuspend (struct ast_bridge_technology *technology)
 Unsuspend a bridge technology.
int ast_bridge_unsuspend (struct ast_bridge *bridge, struct ast_channel *chan)
 Unsuspend a channel from a bridge.
void ast_bridge_update_talker_src_video_mode (struct ast_bridge *bridge, struct ast_channel *chan, int talker_energy, int is_keyframe)
 Update information about talker energy for talker src video mode.
static void bridge_array_add (struct ast_bridge *bridge, struct ast_channel *chan)
 Helper function to add a channel to the bridge array.
static void bridge_array_remove (struct ast_bridge *bridge, struct ast_channel *chan)
 Helper function to remove a channel from the bridge array.
static struct ast_bridge_channelbridge_channel_alloc (struct ast_bridge *bridge)
static void bridge_channel_destroy (void *obj)
static void bridge_channel_dtmf_stream (struct ast_bridge *bridge, struct ast_bridge_channel *bridge_channel)
 Internal function that plays back DTMF on a bridge channel.
static void bridge_channel_feature (struct ast_bridge *bridge, struct ast_bridge_channel *bridge_channel)
 Internal function that executes a feature on a bridge channel.
static enum
ast_bridge_channel_state 
bridge_channel_join (struct ast_bridge_channel *bridge_channel)
 Join a channel to a bridge and handle anything the bridge may want us to do.
static enum
ast_bridge_channel_state 
bridge_channel_join_multithreaded (struct ast_bridge_channel *bridge_channel)
 Run in a multithreaded model. Each joined channel does writing/reading in their own thread. TODO: Improve.
static enum
ast_bridge_channel_state 
bridge_channel_join_singlethreaded (struct ast_bridge_channel *bridge_channel)
 Run in a singlethreaded model. Each joined channel yields itself to the main bridge thread. TODO: Improve.
static void bridge_channel_suspend (struct ast_bridge *bridge, struct ast_bridge_channel *bridge_channel)
 Internal function that suspends a channel from a bridge.
static void bridge_channel_talking (struct ast_bridge *bridge, struct ast_bridge_channel *bridge_channel)
static void * bridge_channel_thread (void *data)
 Thread responsible for imparted bridged channels.
static void bridge_channel_unsuspend (struct ast_bridge *bridge, struct ast_bridge_channel *bridge_channel)
 Internal function that unsuspends a channel from a bridge.
static void bridge_check_dissolve (struct ast_bridge *bridge, struct ast_bridge_channel *bridge_channel)
 Internal function to see whether a bridge should dissolve, and if so do it.
static int bridge_drop_control_frame (int subclass)
 Internal function used to determine whether a control frame should be dropped or not.
static struct ast_framebridge_handle_dtmf (struct ast_bridge *bridge, struct ast_bridge_channel *bridge_channel, struct ast_frame *frame)
 Internal function to handle DTMF from a channel.
static int bridge_make_compatible (struct ast_bridge *bridge, struct ast_bridge_channel *bridge_channel)
static void bridge_poke (struct ast_bridge *bridge)
 Helper function to poke the bridge thread.
static void * bridge_thread (void *data)
 Bridge thread function.
static void cleanup_video_mode (struct ast_bridge *bridge)
static void destroy_bridge (void *obj)
static struct
ast_bridge_technology
find_best_technology (uint32_t capabilities)
 Helper function used to find the "best" bridge technology given a specified capabilities.
static struct ast_bridge_channelfind_bridge_channel (struct ast_bridge *bridge, struct ast_channel *chan)
 Helper function to find a bridge channel given a channel.
static int generic_thread_loop (struct ast_bridge *bridge)
 Generic thread loop, TODO: Rethink this/improve it.
static int smart_bridge_operation (struct ast_bridge *bridge, struct ast_bridge_channel *bridge_channel, int count)
 Perform the smart bridge operation. Basically sees if a new bridge technology should be used instead of the current one.

Variables

static struct bridge_technologies bridge_technologies
static char builtin_features_dtmf [AST_BRIDGE_BUILTIN_END][MAXIMUM_DTMF_FEATURE_STRING]
static void * builtin_features_handlers [AST_BRIDGE_BUILTIN_END]

Detailed Description

Channel Bridging API.

Author:
Joshua Colp <jcolp@digium.com>

Definition in file bridging.c.


Define Documentation

#define BRIDGE_ARRAY_GROW   32

Definition at line 56 of file bridging.c.

Referenced by bridge_array_add().

#define BRIDGE_ARRAY_START   128

Definition at line 53 of file bridging.c.

Referenced by ast_bridge_new().


Function Documentation

int __ast_bridge_technology_register ( struct ast_bridge_technology technology,
struct ast_module mod 
)

Register a bridge technology for use.

Parameters:
technologyThe bridge technology to register
modThe module that is registering the bridge technology
Return values:
0on success
-1on failure

Example usage:

 ast_bridge_technology_register(&simple_bridge_tech);

This registers a bridge technology declared as the structure simple_bridge_tech with the bridging core and makes it available for use when creating bridges.

Definition at line 66 of file bridging.c.

References ast_log(), AST_RWLIST_INSERT_TAIL, AST_RWLIST_TRAVERSE, AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, ast_strlen_zero(), ast_verb, ast_bridge_technology::capabilities, LOG_WARNING, ast_bridge_technology::mod, ast_bridge_technology::name, and ast_bridge_technology::write.

{
   struct ast_bridge_technology *current = NULL;

   /* Perform a sanity check to make sure the bridge technology conforms to our needed requirements */
   if (ast_strlen_zero(technology->name) || !technology->capabilities || !technology->write) {
      ast_log(LOG_WARNING, "Bridge technology %s failed registration sanity check.\n", technology->name);
      return -1;
   }

   AST_RWLIST_WRLOCK(&bridge_technologies);

   /* Look for duplicate bridge technology already using this name, or already registered */
   AST_RWLIST_TRAVERSE(&bridge_technologies, current, entry) {
      if ((!strcasecmp(current->name, technology->name)) || (current == technology)) {
         ast_log(LOG_WARNING, "A bridge technology of %s already claims to exist in our world.\n", technology->name);
         AST_RWLIST_UNLOCK(&bridge_technologies);
         return -1;
      }
   }

   /* Copy module pointer so reference counting can keep the module from unloading */
   technology->mod = module;

   /* Insert our new bridge technology into the list and print out a pretty message */
   AST_RWLIST_INSERT_TAIL(&bridge_technologies, technology, entry);

   AST_RWLIST_UNLOCK(&bridge_technologies);

   ast_verb(2, "Registered bridge technology %s\n", technology->name);

   return 0;
}
void ast_bridge_change_state ( struct ast_bridge_channel bridge_channel,
enum ast_bridge_channel_state  new_state 
)

Change the state of a bridged channel.

Parameters:
bridge_channelChannel to change the state on
new_stateThe new state to place the channel into

Example usage:

This places the channel pointed to by bridge_channel into the state AST_BRIDGE_CHANNEL_STATE_WAIT.

Note:
This API call is only meant to be used in feature hook callbacks to make sure the channel either hangs up or returns to the bridge.

Definition at line 121 of file bridging.c.

References ao2_lock, ao2_unlock, ast_cond_signal, ast_bridge_channel::cond, ast_bridge_channel::state, and ast_bridge_channel::thread.

Referenced by ast_bridge_depart(), ast_bridge_destroy(), ast_bridge_dtmf_stream(), ast_bridge_handle_trip(), ast_bridge_notify_talking(), ast_bridge_remove(), attended_abort_transfer(), attended_threeway_transfer(), bridge_channel_dtmf_stream(), bridge_channel_feature(), bridge_channel_join(), bridge_channel_talking(), bridge_check_dissolve(), bridge_handle_dtmf(), feature_attended_transfer(), feature_blind_transfer(), and feature_hangup().

{
   /* Change the state on the bridge channel */
   bridge_channel->state = new_state;

   /* Only poke the channel's thread if it is not us */
   if (!pthread_equal(pthread_self(), bridge_channel->thread)) {
      pthread_kill(bridge_channel->thread, SIGURG);
      ao2_lock(bridge_channel);
      ast_cond_signal(&bridge_channel->cond);
      ao2_unlock(bridge_channel);
   }

   return;
}
int ast_bridge_check ( uint32_t  capabilities)

See if it is possible to create a bridge.

Parameters:
capabilitiesThe capabilities that the bridge will use
Return values:
1if possible
0if not possible

Example usage:

This sees if it is possible to create a bridge capable of bridging two channels together.

Definition at line 521 of file bridging.c.

References ast_module_unref(), find_best_technology(), and ast_bridge_technology::mod.

{
   struct ast_bridge_technology *bridge_technology = NULL;

   if (!(bridge_technology = find_best_technology(capabilities))) {
      return 0;
   }

   ast_module_unref(bridge_technology->mod);

   return 1;
}
int ast_bridge_depart ( struct ast_bridge bridge,
struct ast_channel chan 
)

Depart a channel from a bridge.

Parameters:
bridgeBridge to depart from
chanChannel to depart
Return values:
0on success
-1on failure

Example usage:

 ast_bridge_depart(bridge, chan);

This removes the channel pointed to by the chan pointer from the bridge pointed to by the bridge pointer and gives control to the calling thread. This does not hang up the channel.

Note:
This API call can only be used on channels that were added to the bridge using the ast_bridge_impart API call.

Definition at line 1191 of file bridging.c.

References ao2_lock, ao2_unlock, ast_bridge_change_state(), AST_BRIDGE_CHANNEL_STATE_DEPART, find_bridge_channel(), ast_bridge_channel::thread, and thread.

Referenced by feature_attended_transfer(), and play_sound_helper().

{
   struct ast_bridge_channel *bridge_channel = NULL;
   pthread_t thread;

   ao2_lock(bridge);

   /* Try to find the channel that we want to depart */
   if (!(bridge_channel = find_bridge_channel(bridge, chan))) {
      ao2_unlock(bridge);
      return -1;
   }

   ast_bridge_change_state(bridge_channel, AST_BRIDGE_CHANNEL_STATE_DEPART);
   thread = bridge_channel->thread;

   ao2_unlock(bridge);

   pthread_join(thread, NULL);

   return 0;
}
int ast_bridge_destroy ( struct ast_bridge bridge)

Destroy a bridge.

Parameters:
bridgeBridge to destroy
Return values:
0on success
-1on failure

Example usage:

This destroys a bridge that was previously created using ast_bridge_new.

Definition at line 534 of file bridging.c.

References ao2_lock, ao2_ref, ao2_unlock, ast_bridge_change_state(), AST_BRIDGE_CHANNEL_STATE_END, ast_callid_unref, ast_debug, AST_LIST_TRAVERSE, AST_PTHREADT_NULL, bridge_poke(), ast_bridge::callid, ast_bridge::stop, ast_bridge::thread, and thread.

Referenced by ast_bridge_new(), destroy_conference_bridge(), and feature_attended_transfer().

{
   struct ast_bridge_channel *bridge_channel = NULL;

   ao2_lock(bridge);

   if (bridge->callid) {
      bridge->callid = ast_callid_unref(bridge->callid);
   }

   if (bridge->thread != AST_PTHREADT_NULL) {
      pthread_t thread = bridge->thread;
      bridge->stop = 1;
      bridge_poke(bridge);
      ao2_unlock(bridge);
      pthread_join(thread, NULL);
      ao2_lock(bridge);
   }

   ast_debug(1, "Telling all channels in bridge %p to end and leave the party\n", bridge);

   /* Drop every bridged channel, the last one will cause the bridge thread (if it exists) to exit */
   AST_LIST_TRAVERSE(&bridge->channels, bridge_channel, entry) {
      ast_bridge_change_state(bridge_channel, AST_BRIDGE_CHANNEL_STATE_END);
   }

   ao2_unlock(bridge);

   ao2_ref(bridge, -1);

   return 0;
}
int ast_bridge_dtmf_stream ( struct ast_bridge bridge,
const char *  dtmf,
struct ast_channel chan 
)

Play a DTMF stream into a bridge, optionally not to a given channel.

Parameters:
bridgeBridge to play stream into
dtmfDTMF to play
chanChannel to optionally not play to
Return values:
0on success
-1on failure

Example usage:

 ast_bridge_dtmf_stream(bridge, "0123456789", NULL);

This sends the DTMF digits '0123456789' to all channels in the bridge pointed to by the bridge pointer. Optionally a channel may be excluded by passing it's channel pointer using the chan parameter.

Definition at line 1482 of file bridging.c.

References ao2_lock, ao2_unlock, ast_bridge_change_state(), AST_BRIDGE_CHANNEL_STATE_DTMF, ast_copy_string(), AST_LIST_TRAVERSE, ast_bridge_channel::chan, and ast_bridge_channel::dtmf_stream_q.

Referenced by bridge_channel_feature().

{
   struct ast_bridge_channel *bridge_channel = NULL;

   ao2_lock(bridge);

   AST_LIST_TRAVERSE(&bridge->channels, bridge_channel, entry) {
      if (bridge_channel->chan == chan) {
         continue;
      }
      ast_copy_string(bridge_channel->dtmf_stream_q, dtmf, sizeof(bridge_channel->dtmf_stream_q));
      ast_bridge_change_state(bridge_channel, AST_BRIDGE_CHANNEL_STATE_DTMF);
   }

   ao2_unlock(bridge);

   return 0;
}

Clean up the contents of a bridge features structure.

Parameters:
featuresBridge features structure
Return values:
0on success
-1on failure

Example usage:

This cleans up the feature structure 'features'.

Note:
This MUST be called after the features structure is done being used or a memory leak may occur.

Definition at line 1463 of file bridging.c.

References ast_free, AST_LIST_REMOVE_HEAD, ast_bridge_features_hook::destructor, ast_bridge_features_hook::hook_pvt, ast_bridge_features::talker_destructor_cb, and ast_bridge_features::talker_pvt_data.

Referenced by confbridge_exec(), destroy_bridge(), and feature_attended_transfer().

{
   struct ast_bridge_features_hook *hook = NULL;

   /* This is relatively simple, hooks are kept as a list on the features structure so we just pop them off and free them */
   while ((hook = AST_LIST_REMOVE_HEAD(&features->hooks, entry))) {
      if (hook->destructor) {
         hook->destructor(hook->hook_pvt);
      }
      ast_free(hook);
   }
   if (features->talker_destructor_cb && features->talker_pvt_data) {
      features->talker_destructor_cb(features->talker_pvt_data);
      features->talker_pvt_data = NULL;
   }

   return 0;
}
int ast_bridge_features_enable ( struct ast_bridge_features features,
enum ast_bridge_builtin_feature  feature,
const char *  dtmf,
void *  config 
)

Enable a built in feature on a bridge features structure.

Parameters:
featuresBridge features structure
featureFeature to enable
dtmfOptionally the DTMF stream to trigger the feature, if not specified it will be the default
configConfiguration structure unique to the built in type
Return values:
0on success
-1on failure

Example usage:

This enables the attended transfer DTMF option using the default DTMF string. An alternate string may be provided using the dtmf parameter. Internally this is simply setting up a hook to a built in feature callback function.

Definition at line 1425 of file bridging.c.

References ast_bridge_features_hook(), ast_debug, and ast_strlen_zero().

Referenced by feature_attended_transfer().

{
   /* If no alternate DTMF stream was provided use the default one */
   if (ast_strlen_zero(dtmf)) {
      dtmf = builtin_features_dtmf[feature];
      /* If no DTMF is still available (ie: it has been disabled) then error out now */
      if (ast_strlen_zero(dtmf)) {
         ast_debug(1, "Failed to enable built in feature %d on %p, no DTMF string is available for it.\n", feature, features);
         return -1;
      }
   }

   if (!builtin_features_handlers[feature]) {
      return -1;
   }

   /* The rest is basically pretty easy. We create another hook using the built in feature's callback and DTMF, easy as pie. */
   return ast_bridge_features_hook(features, dtmf, builtin_features_handlers[feature], config, NULL);
}
int ast_bridge_features_hook ( struct ast_bridge_features features,
const char *  dtmf,
ast_bridge_features_hook_callback  callback,
void *  hook_pvt,
ast_bridge_features_hook_pvt_destructor  destructor 
)

Attach a custom hook to a bridge features structure.

Parameters:
featuresBridge features structure
dtmfDTMF string to be activated upon
callbackFunction to execute upon activation
hook_pvtUnique data
Optionaldestructor callback for hook_pvt data
Return values:
0on success
-1on failure

Example usage:

 struct ast_bridge_features features;
 ast_bridge_features_init(&features);
 ast_bridge_features_hook(&features, "#", pound_callback, NULL, NULL);

This makes the bridging core call pound_callback if a channel that has this feature structure inputs the DTMF string '#'. A pointer to useful data may be provided to the hook_pvt parameter.

Note:
It is important that the callback set the bridge channel state back to AST_BRIDGE_CHANNEL_STATE_WAIT or the bridge thread will not service the channel.

Definition at line 1388 of file bridging.c.

References ast_calloc, ast_copy_string(), AST_LIST_INSERT_TAIL, ast_bridge_features_hook::callback, ast_bridge_features_hook::destructor, ast_bridge_features_hook::dtmf, ast_bridge_features_hook::hook_pvt, and ast_bridge_features::usable.

Referenced by ast_bridge_features_enable(), and feature_attended_transfer().

{
   struct ast_bridge_features_hook *hook = NULL;

   /* Allocate new memory and setup it's various variables */
   if (!(hook = ast_calloc(1, sizeof(*hook)))) {
      return -1;
   }

   ast_copy_string(hook->dtmf, dtmf, sizeof(hook->dtmf));
   hook->callback = callback;
   hook->destructor = destructor;
   hook->hook_pvt = hook_pvt;

   /* Once done we add it onto the list. Now it will be picked up when DTMF is used */
   AST_LIST_INSERT_TAIL(&features->hooks, hook, entry);

   features->usable = 1;

   return 0;
}
int ast_bridge_features_init ( struct ast_bridge_features features)

Initialize bridge features structure.

Parameters:
featuresBridge featues structure
Return values:
0on success
-1on failure

Example usage:

 struct ast_bridge_features features;
 ast_bridge_features_init(&features);

This initializes the feature structure 'features' to have nothing enabled.

Note:
This MUST be called before enabling features or flags. Failure to do so may result in a crash.

Definition at line 1452 of file bridging.c.

References AST_LIST_HEAD_INIT_NOLOCK.

Referenced by confbridge_exec(), and feature_attended_transfer().

{
   /* Zero out the structure */
   memset(features, 0, sizeof(*features));

   /* Initialize the hooks list, just in case */
   AST_LIST_HEAD_INIT_NOLOCK(&features->hooks);

   return 0;
}
int ast_bridge_features_register ( enum ast_bridge_builtin_feature  feature,
ast_bridge_features_hook_callback  callback,
const char *  dtmf 
)

Register a handler for a built in feature.

Parameters:
featureThe feature that the handler will be responsible for
callbackThe callback function that will handle it
dtmfDefault DTMF string used to activate the feature
Return values:
0on success
-1on failure

Example usage:

 ast_bridge_features_register(AST_BRIDGE_BUILTIN_ATTENDED_TRANSFER, bridge_builtin_attended_transfer, "*1");

This registers the function bridge_builtin_attended_transfer as the function responsible for the built in attended transfer feature.

Definition at line 1362 of file bridging.c.

References ast_copy_string(), and ast_strlen_zero().

Referenced by load_module().

{
   if (builtin_features_handlers[feature]) {
      return -1;
   }

   if (!ast_strlen_zero(dtmf)) {
      ast_copy_string(builtin_features_dtmf[feature], dtmf, sizeof(builtin_features_dtmf[feature]));
   }

   builtin_features_handlers[feature] = callback;

   return 0;
}

Set a flag on a bridge features structure.

Parameters:
featuresBridge features structure
flagFlag to enable
Return values:
0on success
-1on failure

Example usage:

This sets the AST_BRIDGE_FLAG_DISSOLVE feature to be enabled on the features structure 'features'.

Definition at line 1445 of file bridging.c.

References ast_set_flag, ast_bridge_features::feature_flags, and ast_bridge_features::usable.

Referenced by feature_attended_transfer().

{
   ast_set_flag(&features->feature_flags, flag);
   features->usable = 1;
   return 0;
}
int ast_bridge_features_set_talk_detector ( struct ast_bridge_features features,
ast_bridge_talking_indicate_callback  talker_cb,
ast_bridge_talking_indicate_destructor  talker_destructor,
void *  pvt_data 
)

Set a callback on the features structure to receive talking notifications on.

Parameters:
featuresBridge features structure
talker_cb,Callbackfunction to execute when talking events occur in the bridge core.
pvt_dataOptional unique data that will be passed with the talking events.
Optionaldestructor callback for pvt data.
Return values:
0,success
-1,failure

Definition at line 1414 of file bridging.c.

References ast_bridge_features::talker_cb, ast_bridge_features::talker_destructor_cb, and ast_bridge_features::talker_pvt_data.

Referenced by confbridge_exec().

{
   features->talker_cb = talker_cb;
   features->talker_destructor_cb = talker_destructor;
   features->talker_pvt_data = pvt_data;
   return 0;
}

Unregister a handler for a built in feature.

Parameters:
featureThe feature to unregister
Return values:
0on success
-1on failure

Example usage:

 ast_bridge_features_unregister(AST_BRIDGE_BUILTIN_ATTENDED_TRANSFER);

This unregisters the function that is handling the built in attended transfer feature.

Definition at line 1377 of file bridging.c.

{
   if (!builtin_features_handlers[feature]) {
      return -1;
   }

   builtin_features_handlers[feature] = NULL;

   return 0;
}
void ast_bridge_handle_trip ( struct ast_bridge bridge,
struct ast_bridge_channel bridge_channel,
struct ast_channel chan,
int  outfd 
)

Feed notification that a frame is waiting on a channel into the bridging core.

Parameters:
bridgeThe bridge that the notification should influence
bridge_channelBridge channel the notification was received on (if known)
chanChannel the notification was received on (if known)
outfdFile descriptor that the notification was received on (if known)

Example usage:

 ast_bridge_handle_trip(bridge, NULL, chan, -1);

This tells the bridging core that a frame has been received on the channel pointed to by chan and that it should be read and handled.

Note:
This should only be used by bridging technologies.

Definition at line 285 of file bridging.c.

References ast_bridge_change_state(), AST_BRIDGE_CHANNEL_STATE_END, AST_CONTROL_HANGUP, ast_debug, AST_FRAME_CONTROL, AST_FRAME_DTMF_BEGIN, AST_FRAME_DTMF_END, ast_frfree, ast_read(), ast_read_noaudio(), bridge_drop_control_frame(), bridge_handle_dtmf(), ast_bridge_features::dtmf_passthrough, ast_bridge_technology::fd, ast_bridge_channel::features, ast_bridge::features, find_bridge_channel(), ast_frame::frametype, ast_frame_subclass::integer, ast_bridge_features::mute, ast_bridge_technology::poke, ast_frame::subclass, ast_bridge::technology, and ast_bridge_technology::write.

Referenced by bridge_channel_join_multithreaded(), generic_thread_loop(), and multiplexed_thread_function().

{
   /* If no bridge channel has been provided and the actual channel has been provided find it */
   if (chan && !bridge_channel) {
      bridge_channel = find_bridge_channel(bridge, chan);
   }

   /* If a bridge channel with actual channel is present read a frame and handle it */
   if (chan && bridge_channel) {
      struct ast_frame *frame = (((bridge->features.mute) || (bridge_channel->features && bridge_channel->features->mute)) ? ast_read_noaudio(chan) : ast_read(chan));

      /* This is pretty simple... see if they hung up */
      if (!frame || (frame->frametype == AST_FRAME_CONTROL && frame->subclass.integer == AST_CONTROL_HANGUP)) {
         /* Signal the thread that is handling the bridged channel that it should be ended */
         ast_bridge_change_state(bridge_channel, AST_BRIDGE_CHANNEL_STATE_END);
      } else if (frame->frametype == AST_FRAME_CONTROL && bridge_drop_control_frame(frame->subclass.integer)) {
         ast_debug(1, "Dropping control frame from bridge channel %p\n", bridge_channel);
      } else if (frame->frametype == AST_FRAME_DTMF_BEGIN || frame->frametype == AST_FRAME_DTMF_END) {
         int dtmf_passthrough = bridge_channel->features ?
            bridge_channel->features->dtmf_passthrough :
            bridge->features.dtmf_passthrough;

         if (frame->frametype == AST_FRAME_DTMF_BEGIN) {
            frame = bridge_handle_dtmf(bridge, bridge_channel, frame);
         }

         if (frame && dtmf_passthrough) {
            bridge->technology->write(bridge, bridge_channel, frame);
         }
      } else {
         /* Simply write the frame out to the bridge technology if it still exists */
         bridge->technology->write(bridge, bridge_channel, frame);
      }

      if (frame) {
         ast_frfree(frame);
      }
      return;
   }

   /* If a file descriptor actually tripped pass it off to the bridge technology */
   if (outfd > -1 && bridge->technology->fd) {
      bridge->technology->fd(bridge, bridge_channel, outfd);
      return;
   }

   /* If all else fails just poke the bridge */
   if (bridge->technology->poke && bridge_channel) {
      bridge->technology->poke(bridge, bridge_channel);
      return;
   }

   return;
}
int ast_bridge_impart ( struct ast_bridge bridge,
struct ast_channel chan,
struct ast_channel swap,
struct ast_bridge_features features,
int  allow_hangup 
)

Impart (non-blocking) a channel on a bridge.

Parameters:
bridgeBridge to impart on
chanChannel to impart
swapChannel to swap out if swapping
featuresBridge features structure
allow_hangupIndicates if the bridge thread should manage hanging up of the channel or not.
Return values:
0on success
-1on failure

Example usage:

 ast_bridge_impart(bridge, chan, NULL, NULL, 0);

This adds a channel pointed to by the chan pointer to the bridge pointed to by the bridge pointer. This function will return immediately and will not wait until the channel is no longer part of the bridge.

If this channel will be replacing another channel the other channel can be specified in the swap parameter. The other channel will be thrown out of the bridge in an atomic fashion.

If channel specific features are enabled a pointer to the features structure can be specified in the features parameter.

Definition at line 1166 of file bridging.c.

References ast_bridge_channel::allow_impart_hangup, ao2_ref, ast_pthread_create, ast_read_threadstorage_callid(), bridge_channel_alloc(), bridge_channel_thread(), ast_bridge_channel::callid, ast_bridge_channel::chan, ast_bridge_channel::features, ast_bridge_channel::swap, and ast_bridge_channel::thread.

Referenced by bridge_call(), feature_attended_transfer(), feature_blind_transfer(), and play_sound_helper().

{
   struct ast_bridge_channel *bridge_channel = bridge_channel_alloc(bridge);

   /* Try to allocate a structure for the bridge channel */
   if (!(bridge_channel)) {
      return -1;
   }

   /* Setup various parameters */
   bridge_channel->chan = chan;
   bridge_channel->swap = swap;
   bridge_channel->features = features;
   bridge_channel->allow_impart_hangup = allow_hangup;
   bridge_channel->callid = ast_read_threadstorage_callid();

   /* Actually create the thread that will handle the channel */
   if (ast_pthread_create(&bridge_channel->thread, NULL, bridge_channel_thread, bridge_channel)) {
      ao2_ref(bridge_channel, -1);
      return -1;
   }

   return 0;
}
int ast_bridge_is_video_src ( struct ast_bridge bridge,
struct ast_channel chan 
)

Determine if a channel is a video src for the bridge.

Return values:
0Not a current video source of the bridge.
None0, is a video source of the bridge, The number returned represents the priority this video stream has on the bridge where 1 is the highest priority.

Definition at line 1621 of file bridging.c.

References ao2_lock, ao2_unlock, AST_BRIDGE_VIDEO_MODE_NONE, AST_BRIDGE_VIDEO_MODE_SINGLE_SRC, AST_BRIDGE_VIDEO_MODE_TALKER_SRC, ast_bridge_video_talker_src_data::chan_old_vsrc, ast_bridge_video_single_src_data::chan_vsrc, ast_bridge_video_talker_src_data::chan_vsrc, ast_bridge_video_mode::mode, ast_bridge_video_mode::mode_data, ast_bridge_video_mode::single_src_data, ast_bridge_video_mode::talker_src_data, and ast_bridge::video_mode.

Referenced by handle_video_on_exit(), handle_video_on_join(), softmix_bridge_write(), and softmix_pass_video_top_priority().

{
   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;
      } else if (bridge->video_mode.mode_data.talker_src_data.chan_old_vsrc == chan) {
         res = 2;
      }

   }
   ao2_unlock(bridge);
   return res;
}
enum ast_bridge_channel_state ast_bridge_join ( struct ast_bridge bridge,
struct ast_channel chan,
struct ast_channel swap,
struct ast_bridge_features features,
struct ast_bridge_tech_optimizations tech_args 
)

Join (blocking) a channel to a bridge.

Parameters:
bridgeBridge to join
chanChannel to join
swapChannel to swap out if swapping
featuresBridge features structure
(Optional)Bridging tech optimization parameters for this channel.
Return values:
statethat channel exited the bridge with

Example usage:

 ast_bridge_join(bridge, chan, NULL, NULL);

This adds a channel pointed to by the chan pointer to the bridge pointed to by the bridge pointer. This function will not return until the channel has been removed from the bridge, swapped out for another channel, or has hung up.

If this channel will be replacing another channel the other channel can be specified in the swap parameter. The other channel will be thrown out of the bridge in an atomic fashion.

If channel specific features are enabled a pointer to the features structure can be specified in the features parameter.

Definition at line 1102 of file bridging.c.

References ao2_lock, ao2_ref, ao2_unlock, AST_BRIDGE_CHANNEL_STATE_HANGUP, bridge_channel_alloc(), bridge_channel_join(), ast_bridge_channel::chan, ast_bridge_channel::features, state, ast_bridge_channel::swap, and ast_bridge_channel::tech_args.

Referenced by confbridge_exec(), feature_attended_transfer(), and record_thread().

{
   struct ast_bridge_channel *bridge_channel = bridge_channel_alloc(bridge);
   enum ast_bridge_channel_state state = AST_BRIDGE_CHANNEL_STATE_HANGUP;

   if (!bridge_channel) {
      return state;
   }
   if (tech_args) {
      memcpy(&bridge_channel->tech_args, tech_args, sizeof(bridge_channel->tech_args));
   }

   /* Initialize various other elements of the bridge channel structure that we can't do above */
   bridge_channel->chan = chan;
   bridge_channel->swap = swap;
   bridge_channel->features = features;

   state = bridge_channel_join(bridge_channel);

   /* Cleanup all the data in the bridge channel after it leaves the bridge. */
   ao2_lock(bridge_channel);
   bridge_channel->chan = NULL;
   bridge_channel->swap = NULL;
   bridge_channel->features = NULL;
   ao2_unlock(bridge_channel);

   ao2_ref(bridge_channel, -1);

   return state;
}
int ast_bridge_merge ( struct ast_bridge bridge0,
struct ast_bridge bridge1 
)

Merge two bridges together.

Parameters:
bridge0First bridge
bridge1Second bridge
Return values:
0on success
-1on failure

Example usage:

 ast_bridge_merge(bridge0, bridge1);

This merges the bridge pointed to by bridge1 with the bridge pointed to by bridge0. In reality all of the channels in bridge1 are simply moved to bridge0.

Note:
The second bridge specified is not destroyed when this operation is completed.

Definition at line 1233 of file bridging.c.

References ao2_lock, ao2_ref, ao2_unlock, AST_BRIDGE_CAPABILITY_MULTIMIX, AST_BRIDGE_FLAG_SMART, ast_cond_signal, ast_debug, AST_LIST_INSERT_TAIL, AST_LIST_REMOVE_HEAD, AST_PTHREADT_STOP, ast_test_flag, ast_bridge_channel::bridge, bridge_array_add(), bridge_array_remove(), bridge_make_compatible(), ast_bridge_technology::capabilities, ast_bridge_channel::chan, ast_bridge_channel::cond, ast_bridge::feature_flags, ast_bridge_technology::join, ast_bridge_technology::leave, ast_bridge_technology::name, ast_bridge::num, smart_bridge_operation(), ast_bridge::technology, ast_bridge_channel::thread, and ast_bridge::thread.

{
   struct ast_bridge_channel *bridge_channel = NULL;

   ao2_lock(bridge0);
   ao2_lock(bridge1);

   /* If the first bridge currently has 2 channels and is not capable of becoming a multimixing bridge we can not merge */
   if ((bridge0->num + bridge1->num) > 2 && (!(bridge0->technology->capabilities & AST_BRIDGE_CAPABILITY_MULTIMIX) && !ast_test_flag(&bridge0->feature_flags, AST_BRIDGE_FLAG_SMART))) {
      ao2_unlock(bridge1);
      ao2_unlock(bridge0);
      ast_debug(1, "Can't merge bridge %p into bridge %p, multimix is needed and it could not be acquired.\n", bridge1, bridge0);
      return -1;
   }

   ast_debug(1, "Merging channels from bridge %p into bridge %p\n", bridge1, bridge0);

   /* Perform smart bridge operation on bridge we are merging into so it can change bridge technology if needed */
   if (smart_bridge_operation(bridge0, NULL, bridge0->num + bridge1->num)) {
      ao2_unlock(bridge1);
      ao2_unlock(bridge0);
      ast_debug(1, "Can't merge bridge %p into bridge %p, tried to perform smart bridge operation and failed.\n", bridge1, bridge0);
      return -1;
   }

   /* If a thread is currently executing on bridge1 tell it to stop */
   if (bridge1->thread) {
      ast_debug(1, "Telling bridge thread on bridge %p to stop as it is being merged into %p\n", bridge1, bridge0);
      bridge1->thread = AST_PTHREADT_STOP;
   }

   /* Move channels from bridge1 over to bridge0 */
   while ((bridge_channel = AST_LIST_REMOVE_HEAD(&bridge1->channels, entry))) {
      /* Tell the technology handling bridge1 that the bridge channel is leaving */
      if (bridge1->technology->leave) {
         ast_debug(1, "Giving bridge technology %s notification that %p is leaving bridge %p\n", bridge1->technology->name, bridge_channel, bridge1);
         if (bridge1->technology->leave(bridge1, bridge_channel)) {
            ast_debug(1, "Bridge technology %s failed to allow %p to leave bridge %p\n", bridge1->technology->name, bridge_channel, bridge1);
         }
      }

      /* Drop channel count and reference count on the bridge they are leaving */
      bridge1->num--;
      ao2_ref(bridge1, -1);

      bridge_array_remove(bridge1, bridge_channel->chan);

      /* Now add them into the bridge they are joining, increase channel count, and bump up reference count */
      bridge_channel->bridge = bridge0;
      AST_LIST_INSERT_TAIL(&bridge0->channels, bridge_channel, entry);
      bridge0->num++;
      ao2_ref(bridge0, +1);

      bridge_array_add(bridge0, bridge_channel->chan);

      /* Make the channel compatible with the new bridge it is joining or else formats would go amuck */
      bridge_make_compatible(bridge0, bridge_channel);

      /* Tell the technology handling bridge0 that the bridge channel is joining */
      if (bridge0->technology->join) {
         ast_debug(1, "Giving bridge technology %s notification that %p is joining bridge %p\n", bridge0->technology->name, bridge_channel, bridge0);
         if (bridge0->technology->join(bridge0, bridge_channel)) {
            ast_debug(1, "Bridge technology %s failed to join %p to bridge %p\n", bridge0->technology->name, bridge_channel, bridge0);
         }
      }

      /* Poke the bridge channel, this will cause it to wake up and execute the proper threading model for the new bridge it is in */
      pthread_kill(bridge_channel->thread, SIGURG);
      ao2_lock(bridge_channel);
      ast_cond_signal(&bridge_channel->cond);
      ao2_unlock(bridge_channel);
   }

   ast_debug(1, "Merged channels from bridge %p into bridge %p\n", bridge1, bridge0);

   ao2_unlock(bridge1);
   ao2_unlock(bridge0);

   return 0;
}
struct ast_bridge* ast_bridge_new ( uint32_t  capabilities,
int  flags 
) [read]

Create a new bridge.

Parameters:
capabilitiesThe capabilities that we require to be used on the bridge
flagsFlags that will alter the behavior of the bridge
Return values:
apointer to a new bridge on success
NULLon failure

Example usage:

This creates a simple two party bridge that will be destroyed once one of the channels hangs up.

Definition at line 469 of file bridging.c.

References ao2_alloc, ao2_ref, ast_bridge::array, ast_bridge::array_size, AST_BRIDGE_CAPABILITY_1TO1MIX, AST_BRIDGE_CAPABILITY_MULTIMIX, ast_bridge_destroy(), AST_BRIDGE_FLAG_SMART, ast_bridge_new(), ast_calloc, ast_debug, AST_PTHREADT_NULL, ast_set_flag, BRIDGE_ARRAY_START, ast_bridge_technology::create, destroy_bridge(), ast_bridge::feature_flags, find_best_technology(), ast_bridge_technology::name, ast_bridge::technology, and ast_bridge::thread.

Referenced by ast_bridge_new(), feature_attended_transfer(), and join_conference_bridge().

{
   struct ast_bridge *bridge = NULL;
   struct ast_bridge_technology *bridge_technology = NULL;

   /* If we need to be a smart bridge see if we can move between 1to1 and multimix bridges */
   if (flags & AST_BRIDGE_FLAG_SMART) {
      struct ast_bridge *other_bridge;

      if (!(other_bridge = ast_bridge_new((capabilities & AST_BRIDGE_CAPABILITY_1TO1MIX) ? AST_BRIDGE_CAPABILITY_MULTIMIX : AST_BRIDGE_CAPABILITY_1TO1MIX, 0))) {
         return NULL;
      }

      ast_bridge_destroy(other_bridge);
   }

   /* If capabilities were provided use our helper function to find the "best" bridge technology, otherwise we can
    * just look for the most basic capability needed, single 1to1 mixing. */
   bridge_technology = (capabilities ? find_best_technology(capabilities) : find_best_technology(AST_BRIDGE_CAPABILITY_1TO1MIX));

   /* If no bridge technology was found we can't possibly do bridging so fail creation of the bridge */
   if (!bridge_technology) {
      return NULL;
   }

   /* We have everything we need to create this bridge... so allocate the memory, link things together, and fire her up! */
   if (!(bridge = ao2_alloc(sizeof(*bridge), destroy_bridge))) {
      return NULL;
   }

   bridge->technology = bridge_technology;
   bridge->thread = AST_PTHREADT_NULL;

   /* Create an array of pointers for the channels that will be joining us */
   bridge->array = ast_calloc(BRIDGE_ARRAY_START, sizeof(struct ast_channel*));
   bridge->array_size = BRIDGE_ARRAY_START;

   ast_set_flag(&bridge->feature_flags, flags);

   /* Pass off the bridge to the technology to manipulate if needed */
   if (bridge->technology->create) {
      ast_debug(1, "Giving bridge technology %s the bridge structure %p to setup\n", bridge->technology->name, bridge);
      if (bridge->technology->create(bridge)) {
         ast_debug(1, "Bridge technology %s failed to setup bridge structure %p\n", bridge->technology->name, bridge);
         ao2_ref(bridge, -1);
         bridge = NULL;
      }
   }

   return bridge;
}
void ast_bridge_notify_talking ( struct ast_bridge bridge,
struct ast_bridge_channel bridge_channel,
int  started_talking 
)

Lets the bridging indicate when a bridge channel has stopped or started talking.

Note:
All DSP functionality on the bridge has been pushed down to the lowest possible layer, which in this case is the specific bridging technology being used. Since it is necessary for the knowledge of which channels are talking to make its way up to the application, this function has been created to allow the bridging technology to communicate that information with the bridging core.
Parameters:
bridgeThe bridge that the channel is a part of.
bridge_channelThe bridge channel that has either started or stopped talking.
started_talking,setto 1 when this indicates the channel has started talking, set to 0 when this indicates the channel has stopped talking.

Definition at line 276 of file bridging.c.

References ast_bridge_change_state(), AST_BRIDGE_CHANNEL_STATE_START_TALKING, and AST_BRIDGE_CHANNEL_STATE_STOP_TALKING.

Referenced by softmix_bridge_write().

int ast_bridge_remove ( struct ast_bridge bridge,
struct ast_channel chan 
)

Remove a channel from a bridge.

Parameters:
bridgeBridge that the channel is to be removed from
chanChannel to remove
Return values:
0on success
-1on failure

Example usage:

 ast_bridge_remove(bridge, chan);

This removes the channel pointed to by the chan pointer from the bridge pointed to by the bridge pointer and requests that it be hung up. Control over the channel will NOT be given to the calling thread.

Note:
This API call can be used on channels that were added to the bridge using both ast_bridge_join and ast_bridge_impart.

Definition at line 1214 of file bridging.c.

References ao2_lock, ao2_unlock, ast_bridge_change_state(), AST_BRIDGE_CHANNEL_STATE_HANGUP, and find_bridge_channel().

Referenced by action_kick_last(), conf_stop_record(), execute_menu_entry(), and kick_conference_participant().

{
   struct ast_bridge_channel *bridge_channel = NULL;

   ao2_lock(bridge);

   /* Try to find the channel that we want to remove */
   if (!(bridge_channel = find_bridge_channel(bridge, chan))) {
      ao2_unlock(bridge);
      return -1;
   }

   ast_bridge_change_state(bridge_channel, AST_BRIDGE_CHANNEL_STATE_HANGUP);

   ao2_unlock(bridge);

   return 0;
}
void ast_bridge_remove_video_src ( struct ast_bridge bridge,
struct ast_channel chan 
)

remove a channel as a source of video for the bridge.

Definition at line 1646 of file bridging.c.

References ao2_lock, ao2_unlock, AST_BRIDGE_VIDEO_MODE_NONE, AST_BRIDGE_VIDEO_MODE_SINGLE_SRC, AST_BRIDGE_VIDEO_MODE_TALKER_SRC, ast_channel_unref, ast_bridge_video_talker_src_data::average_talking_energy, ast_bridge_video_talker_src_data::chan_old_vsrc, ast_bridge_video_single_src_data::chan_vsrc, ast_bridge_video_talker_src_data::chan_vsrc, ast_bridge_video_mode::mode, ast_bridge_video_mode::mode_data, ast_bridge_video_mode::single_src_data, ast_bridge_video_mode::talker_src_data, and ast_bridge::video_mode.

Referenced by handle_video_on_exit().

void ast_bridge_set_internal_sample_rate ( struct ast_bridge bridge,
unsigned int  sample_rate 
)

Adjust the internal mixing sample rate of a bridge used during multimix mode.

Parameters:
bridge_channelChannel to change the sample rate on.
samplerate, the sample rate to change to. If a value of 0 is passed here, the bridge will be free to pick what ever sample rate it chooses.

Definition at line 1508 of file bridging.c.

References ao2_lock, ao2_unlock, and ast_bridge::internal_sample_rate.

Referenced by join_conference_bridge().

{

   ao2_lock(bridge);
   bridge->internal_sample_rate = sample_rate;
   ao2_unlock(bridge);
}
void ast_bridge_set_mixing_interval ( struct ast_bridge bridge,
unsigned int  mixing_interval 
)

Adjust the internal mixing interval of a bridge used during multimix mode.

Parameters:
bridge_channelChannel to change the sample rate on.
mixing_interval,thesample rate to change to. If 0 is set the bridge tech is free to choose any mixing interval it uses by default.

Definition at line 1501 of file bridging.c.

References ao2_lock, ao2_unlock, and ast_bridge::internal_mixing_interval.

Referenced by join_conference_bridge().

{
   ao2_lock(bridge);
   bridge->internal_mixing_interval = mixing_interval;
   ao2_unlock(bridge);
}

Set the bridge to pick the strongest talker supporting video as the single source video feed.

Definition at line 1548 of file bridging.c.

References ao2_lock, ao2_unlock, AST_BRIDGE_VIDEO_MODE_TALKER_SRC, ast_test_suite_event_notify, cleanup_video_mode(), ast_bridge_video_mode::mode, and ast_bridge::video_mode.

Referenced by handle_video_on_exit(), and join_conference_bridge().

{
   ao2_lock(bridge);
   cleanup_video_mode(bridge);
   bridge->video_mode.mode = AST_BRIDGE_VIDEO_MODE_TALKER_SRC;
   ast_test_suite_event_notify("BRIDGE_VIDEO_MODE", "Message: video mode set to talker source\r\nVideo Mode: %d", bridge->video_mode.mode);
   ao2_unlock(bridge);
}
int ast_bridge_suspend ( struct ast_bridge bridge,
struct ast_channel chan 
)

Suspend a channel temporarily from a bridge.

Parameters:
bridgeBridge to suspend the channel from
chanChannel to suspend
Return values:
0on success
-1on failure

Example usage:

This suspends the channel pointed to by chan from the bridge pointed to by bridge temporarily. Control of the channel is given to the calling thread. This differs from ast_bridge_depart as the channel will not be removed from the bridge.

Note:
This API call can be used on channels that were added to the bridge using both ast_bridge_join and ast_bridge_impart.

Definition at line 1314 of file bridging.c.

References ao2_lock, ao2_unlock, bridge_channel_suspend(), and find_bridge_channel().

Referenced by conf_moh_start(), and conf_moh_stop().

{
   struct ast_bridge_channel *bridge_channel;

   ao2_lock(bridge);

   if (!(bridge_channel = find_bridge_channel(bridge, chan))) {
      ao2_unlock(bridge);
      return -1;
   }

   bridge_channel_suspend(bridge, bridge_channel);

   ao2_unlock(bridge);

   return 0;
}

Suspend a bridge technology from consideration.

Parameters:
technologyThe bridge technology to suspend

Example usage:

 ast_bridge_technology_suspend(&simple_bridge_tech);

This suspends the bridge technology simple_bridge_tech from being considered when creating a new bridge. Existing bridges using the bridge technology are not affected.

Definition at line 1350 of file bridging.c.

References ast_bridge_technology::suspended.

{
   technology->suspended = 1;
   return;
}

Unregister a bridge technology from use.

Parameters:
technologyThe bridge technology to unregister
Return values:
0on success
-1on failure

Example usage:

 ast_bridge_technology_unregister(&simple_bridge_tech);

This unregisters a bridge technlogy declared as the structure simple_bridge_tech with the bridging core. It will no longer be considered when creating a new bridge.

Definition at line 100 of file bridging.c.

References AST_RWLIST_REMOVE_CURRENT, AST_RWLIST_TRAVERSE_SAFE_BEGIN, AST_RWLIST_TRAVERSE_SAFE_END, AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, ast_verb, and ast_bridge_technology::name.

Referenced by unload_module().

{
   struct ast_bridge_technology *current = NULL;

   AST_RWLIST_WRLOCK(&bridge_technologies);

   /* Ensure the bridge technology is registered before removing it */
   AST_RWLIST_TRAVERSE_SAFE_BEGIN(&bridge_technologies, current, entry) {
      if (current == technology) {
         AST_RWLIST_REMOVE_CURRENT(entry);
         ast_verb(2, "Unregistered bridge technology %s\n", technology->name);
         break;
      }
   }
   AST_RWLIST_TRAVERSE_SAFE_END;

   AST_RWLIST_UNLOCK(&bridge_technologies);

   return current ? 0 : -1;
}

Unsuspend a bridge technology.

Parameters:
technologyThe bridge technology to unsuspend

Example usage:

 ast_bridge_technology_unsuspend(&simple_bridge_tech);

This makes the bridge technology simple_bridge_tech considered when creating a new bridge again.

Definition at line 1356 of file bridging.c.

References ast_bridge_technology::suspended.

{
   technology->suspended = 0;
   return;
}
int ast_bridge_unsuspend ( struct ast_bridge bridge,
struct ast_channel chan 
)

Unsuspend a channel from a bridge.

Parameters:
bridgeBridge to unsuspend the channel from
chanChannel to unsuspend
Return values:
0on success
-1on failure

Example usage:

 ast_bridge_unsuspend(bridge, chan);

This unsuspends the channel pointed to by chan from the bridge pointed to by bridge. The bridge will go back to handling the channel once this function returns.

Note:
You must not mess with the channel once this function returns. Doing so may result in bad things happening.

Definition at line 1332 of file bridging.c.

References ao2_lock, ao2_unlock, bridge_channel_unsuspend(), and find_bridge_channel().

Referenced by conf_moh_start(), and conf_moh_stop().

{
   struct ast_bridge_channel *bridge_channel;

   ao2_lock(bridge);

   if (!(bridge_channel = find_bridge_channel(bridge, chan))) {
      ao2_unlock(bridge);
      return -1;
   }

   bridge_channel_unsuspend(bridge, bridge_channel);

   ao2_unlock(bridge);

   return 0;
}
void ast_bridge_update_talker_src_video_mode ( struct ast_bridge bridge,
struct ast_channel chan,
int  talker_energy,
int  is_keyframe 
)

Update information about talker energy for talker src video mode.

Definition at line 1557 of file bridging.c.

References ao2_lock, ao2_unlock, ast_channel_name(), ast_channel_nativeformats(), ast_channel_ref, ast_channel_unref, AST_CONTROL_VIDUPDATE, ast_format_cap_has_type(), AST_FORMAT_TYPE_VIDEO, ast_indicate(), ast_test_suite_event_notify, ast_bridge_video_talker_src_data::average_talking_energy, ast_bridge_video_talker_src_data::chan_old_vsrc, ast_bridge_video_talker_src_data::chan_vsrc, ast_bridge_video_mode::mode_data, ast_bridge_video_mode::talker_src_data, and ast_bridge::video_mode.

Referenced by softmix_bridge_write().

{
   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(ast_channel_nativeformats(chan), 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_old_vsrc) {
         ast_channel_unref(data->chan_old_vsrc);
      }
      if (data->chan_vsrc) {
         data->chan_old_vsrc = data->chan_vsrc;
         ast_indicate(data->chan_old_vsrc, AST_CONTROL_VIDUPDATE);
      }
      data->chan_vsrc = ast_channel_ref(chan);
      data->average_talking_energy = talker_energy;
      ast_test_suite_event_notify("BRIDGE_VIDEO_SRC", "Message: video source updated\r\nVideo Channel: %s", ast_channel_name(data->chan_vsrc));
      ast_indicate(data->chan_vsrc, 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_test_suite_event_notify("BRIDGE_VIDEO_SRC", "Message: video source updated\r\nVideo Channel: %s", ast_channel_name(data->chan_vsrc));
      ast_indicate(chan, AST_CONTROL_VIDUPDATE);
   } else if (!data->chan_old_vsrc && is_keyframe) {
      data->chan_old_vsrc = ast_channel_ref(chan);
      ast_indicate(chan, AST_CONTROL_VIDUPDATE);
   }
   ao2_unlock(bridge);
}
static void bridge_array_add ( struct ast_bridge bridge,
struct ast_channel chan 
) [static]

Helper function to add a channel to the bridge array.

Note:
This function assumes the bridge is locked.

Definition at line 152 of file bridging.c.

References ast_bridge::array, ast_bridge::array_num, ast_bridge::array_size, ast_channel_name(), ast_debug, ast_log(), ast_realloc, BRIDGE_ARRAY_GROW, bridge_poke(), LOG_ERROR, and ast_bridge::waiting.

Referenced by ast_bridge_merge(), bridge_channel_join(), and bridge_channel_unsuspend().

{
   /* We have to make sure the bridge thread is not using the bridge array before messing with it */
   while (bridge->waiting) {
      bridge_poke(bridge);
      sched_yield();
   }

   bridge->array[bridge->array_num++] = chan;

   ast_debug(1, "Added channel %s(%p) to bridge array on %p, new count is %d\n", ast_channel_name(chan), chan, bridge, (int)bridge->array_num);

   /* If the next addition of a channel will exceed our array size grow it out */
   if (bridge->array_num == bridge->array_size) {
      struct ast_channel **tmp;
      ast_debug(1, "Growing bridge array on %p from %d to %d\n", bridge, (int)bridge->array_size, (int)bridge->array_size + BRIDGE_ARRAY_GROW);
      if (!(tmp = ast_realloc(bridge->array, (bridge->array_size + BRIDGE_ARRAY_GROW) * sizeof(struct ast_channel *)))) {
         ast_log(LOG_ERROR, "Failed to allocate more space for another channel on bridge '%p', this is not going to end well\n", bridge);
         return;
      }
      bridge->array = tmp;
      bridge->array_size += BRIDGE_ARRAY_GROW;
   }

   return;
}
static void bridge_array_remove ( struct ast_bridge bridge,
struct ast_channel chan 
) [static]

Helper function to remove a channel from the bridge array.

Note:
This function assumes the bridge is locked.

Definition at line 183 of file bridging.c.

References ast_bridge::array, ast_bridge::array_num, ast_debug, bridge_poke(), and ast_bridge::waiting.

Referenced by ast_bridge_merge(), bridge_channel_join(), and bridge_channel_suspend().

{
   int i;

   /* We have to make sure the bridge thread is not using the bridge array before messing with it */
   while (bridge->waiting) {
      bridge_poke(bridge);
      sched_yield();
   }

   for (i = 0; i < bridge->array_num; i++) {
      if (bridge->array[i] == chan) {
         bridge->array[i] = (bridge->array[(bridge->array_num - 1)] != chan ? bridge->array[(bridge->array_num - 1)] : NULL);
         bridge->array[(bridge->array_num - 1)] = NULL;
         bridge->array_num--;
         ast_debug(1, "Removed channel %p from bridge array on %p, new count is %d\n", chan, bridge, (int)bridge->array_num);
         break;
      }
   }

   return;
}
static struct ast_bridge_channel* bridge_channel_alloc ( struct ast_bridge bridge) [static, read]

Definition at line 1088 of file bridging.c.

References ao2_alloc, ao2_ref, ast_cond_init, ast_bridge_channel::bridge, bridge_channel_destroy(), and ast_bridge_channel::cond.

Referenced by ast_bridge_impart(), and ast_bridge_join().

{
   struct ast_bridge_channel *bridge_channel = ao2_alloc(sizeof(struct ast_bridge_channel), bridge_channel_destroy);
   if (!(bridge_channel)) {
      return NULL;
   }
   ast_cond_init(&bridge_channel->cond, NULL);
   if (bridge) {
      bridge_channel->bridge = bridge;
      ao2_ref(bridge_channel->bridge, +1);
   }
   return bridge_channel;
}
static void bridge_channel_destroy ( void *  obj) [static]

Definition at line 1072 of file bridging.c.

References ao2_ref, ast_callid_unref, ast_cond_destroy, ast_bridge_channel::bridge, ast_bridge_channel::callid, and ast_bridge_channel::cond.

Referenced by bridge_channel_alloc().

{
   struct ast_bridge_channel *bridge_channel = obj;

   if (bridge_channel->callid) {
      bridge_channel->callid = ast_callid_unref(bridge_channel->callid);
   }

   if (bridge_channel->bridge) {
      ao2_ref(bridge_channel->bridge, -1);
      bridge_channel->bridge = NULL;
   }
   /* Destroy elements of the bridge channel structure and the bridge channel structure itself */
   ast_cond_destroy(&bridge_channel->cond);
}
static void bridge_channel_dtmf_stream ( struct ast_bridge bridge,
struct ast_bridge_channel bridge_channel 
) [static]

Internal function that plays back DTMF on a bridge channel.

Definition at line 914 of file bridging.c.

References ast_bridge_change_state(), AST_BRIDGE_CHANNEL_STATE_WAIT, ast_copy_string(), ast_debug, ast_dtmf_stream(), ast_bridge_channel::chan, and ast_bridge_channel::dtmf_stream_q.

Referenced by bridge_channel_join().

{
   char dtmf_q[8] = "";

   ast_copy_string(dtmf_q, bridge_channel->dtmf_stream_q, sizeof(dtmf_q));
   bridge_channel->dtmf_stream_q[0] = '\0';

   ast_debug(1, "Playing DTMF stream '%s' out to bridge channel %p\n", dtmf_q, bridge_channel);
   ast_dtmf_stream(bridge_channel->chan, NULL, dtmf_q, 250, 0);

   ast_bridge_change_state(bridge_channel, AST_BRIDGE_CHANNEL_STATE_WAIT);

   return;
}
static void bridge_channel_feature ( struct ast_bridge bridge,
struct ast_bridge_channel bridge_channel 
) [static]

Internal function that executes a feature on a bridge channel.

Note:
Neither the bridge nor the bridge_channel locks should be held when entering this function.

Definition at line 827 of file bridging.c.

References ast_bridge_change_state(), AST_BRIDGE_CHANNEL_STATE_END, AST_BRIDGE_CHANNEL_STATE_FEATURE, AST_BRIDGE_CHANNEL_STATE_WAIT, ast_bridge_dtmf_stream(), ast_channel_flags(), ast_check_hangup_locked(), ast_clear_flag, ast_debug, AST_FLAG_END_DTMF_ONLY, AST_LIST_TRAVERSE, ast_set_flag, ast_waitfordigit(), ast_bridge_features_hook::callback, ast_bridge_channel::chan, ast_bridge_features_hook::dtmf, ast_bridge_channel::features, ast_bridge::features, ast_bridge_features_hook::hook_pvt, MAXIMUM_DTMF_FEATURE_STRING, and ast_bridge_channel::state.

Referenced by bridge_channel_join().

{
   struct ast_bridge_features *features = (bridge_channel->features ? bridge_channel->features : &bridge->features);
   struct ast_bridge_features_hook *hook = NULL;
   char dtmf[MAXIMUM_DTMF_FEATURE_STRING] = "";
   int look_for_dtmf = 1, dtmf_len = 0;

   /* The channel is now under our control and we don't really want any begin frames to do our DTMF matching so disable 'em at the core level */
   ast_set_flag(ast_channel_flags(bridge_channel->chan), AST_FLAG_END_DTMF_ONLY);

   /* Wait for DTMF on the channel and put it into a buffer. If the buffer matches any feature hook execute the hook. */
   while (look_for_dtmf) {
      int res = ast_waitfordigit(bridge_channel->chan, 3000);

      /* If the above timed out simply exit */
      if (!res) {
         ast_debug(1, "DTMF feature string collection on bridge channel %p timed out\n", bridge_channel);
         break;
      } else if (res < 0) {
         ast_debug(1, "DTMF feature string collection failed on bridge channel %p for some reason\n", bridge_channel);
         break;
      }

      /* Add the above DTMF into the DTMF string so we can do our matching */
      dtmf[dtmf_len++] = res;

      ast_debug(1, "DTMF feature string on bridge channel %p is now '%s'\n", bridge_channel, dtmf);

      /* Assume that we do not want to look for DTMF any longer */
      look_for_dtmf = 0;

      /* See if a DTMF feature hook matches or can match */
      AST_LIST_TRAVERSE(&features->hooks, hook, entry) {
         /* If this hook matches just break out now */
         if (!strcmp(hook->dtmf, dtmf)) {
            ast_debug(1, "DTMF feature hook %p matched DTMF string '%s' on bridge channel %p\n", hook, dtmf, bridge_channel);
            look_for_dtmf = 0;
            break;
         } else if (!strncmp(hook->dtmf, dtmf, dtmf_len)) {
            ast_debug(1, "DTMF feature hook %p can match DTMF string '%s', it wants '%s', on bridge channel %p\n", hook, dtmf, hook->dtmf, bridge_channel);
            look_for_dtmf = 1;
         } else {
            ast_debug(1, "DTMF feature hook %p does not match DTMF string '%s', it wants '%s', on bridge channel %p\n", hook, dtmf, hook->dtmf, bridge_channel);
         }
      }

      /* If we have reached the maximum length of a DTMF feature string bail out */
      if (dtmf_len == MAXIMUM_DTMF_FEATURE_STRING) {
         break;
      }
   }

   /* Since we are done bringing DTMF in return to using both begin and end frames */
   ast_clear_flag(ast_channel_flags(bridge_channel->chan), AST_FLAG_END_DTMF_ONLY);

   /* If a hook was actually matched execute it on this channel, otherwise stream up the DTMF to the other channels */
   if (hook) {
      hook->callback(bridge, bridge_channel, hook->hook_pvt);
      /* If we are handing the channel off to an external hook for ownership,
       * we are not guaranteed what kind of state it will come back in.  If
       * the channel hungup, we need to detect that here. */
      if (bridge_channel->chan && ast_check_hangup_locked(bridge_channel->chan)) {
         ast_bridge_change_state(bridge_channel, AST_BRIDGE_CHANNEL_STATE_END);
      }
   } else {
      ast_bridge_dtmf_stream(bridge, dtmf, bridge_channel->chan);
   }

   /* if the channel is still in feature state, revert it back to wait state */
   if (bridge_channel->state == AST_BRIDGE_CHANNEL_STATE_FEATURE) {
      ast_bridge_change_state(bridge_channel, AST_BRIDGE_CHANNEL_STATE_WAIT);
   }

   return;
}
static enum ast_bridge_channel_state bridge_channel_join ( struct ast_bridge_channel bridge_channel) [static]

Join a channel to a bridge and handle anything the bridge may want us to do.

Definition at line 930 of file bridging.c.

References ao2_lock, ao2_ref, ao2_unlock, AST_BRIDGE_CAPABILITY_MULTITHREADED, AST_BRIDGE_CAPABILITY_THREAD, ast_bridge_change_state(), AST_BRIDGE_CHANNEL_STATE_DTMF, AST_BRIDGE_CHANNEL_STATE_END, AST_BRIDGE_CHANNEL_STATE_FEATURE, AST_BRIDGE_CHANNEL_STATE_HANGUP, AST_BRIDGE_CHANNEL_STATE_START_TALKING, AST_BRIDGE_CHANNEL_STATE_STOP_TALKING, AST_BRIDGE_CHANNEL_STATE_WAIT, AST_BRIDGE_FLAG_SMART, ast_channel_internal_bridge_set(), ast_channel_readformat(), ast_channel_writeformat(), ast_debug, ast_format_cmp(), AST_FORMAT_CMP_NOT_EQUAL, ast_format_copy(), ast_getformatname(), AST_LIST_INSERT_TAIL, AST_LIST_REMOVE, ast_pthread_create, AST_PTHREADT_NULL, ast_read_threadstorage_callid(), ast_set_read_format(), ast_set_write_format(), ast_test_flag, ast_bridge_channel::bridge, bridge_array_add(), bridge_array_remove(), bridge_channel_dtmf_stream(), bridge_channel_feature(), bridge_channel_join_multithreaded(), bridge_channel_join_singlethreaded(), bridge_channel_suspend(), bridge_channel_talking(), bridge_channel_unsuspend(), bridge_check_dissolve(), bridge_make_compatible(), bridge_thread(), ast_bridge::callid, ast_bridge_technology::capabilities, ast_bridge_channel::chan, ast_bridge::feature_flags, find_bridge_channel(), ast_bridge_technology::join, ast_bridge_technology::leave, ast_bridge_technology::name, ast_bridge::num, smart_bridge_operation(), ast_bridge_channel::state, state, ast_bridge::stop, ast_bridge_channel::swap, ast_bridge::technology, ast_bridge_channel::thread, and ast_bridge::thread.

Referenced by ast_bridge_join(), and bridge_channel_thread().

{
   struct ast_format formats[2];
   enum ast_bridge_channel_state state;
   ast_format_copy(&formats[0], ast_channel_readformat(bridge_channel->chan));
   ast_format_copy(&formats[1], ast_channel_writeformat(bridge_channel->chan));

   /* Record the thread that will be the owner of us */
   bridge_channel->thread = pthread_self();

   ast_debug(1, "Joining bridge channel %p to bridge %p\n", bridge_channel, bridge_channel->bridge);

   ao2_lock(bridge_channel->bridge);

   if (!bridge_channel->bridge->callid) {
      bridge_channel->bridge->callid = ast_read_threadstorage_callid();
   }

   state = bridge_channel->state;

   /* Add channel into the bridge */
   AST_LIST_INSERT_TAIL(&bridge_channel->bridge->channels, bridge_channel, entry);
   bridge_channel->bridge->num++;

   bridge_array_add(bridge_channel->bridge, bridge_channel->chan);

   if (bridge_channel->swap) {
      struct ast_bridge_channel *bridge_channel2 = NULL;

      /* If we are performing a swap operation we do not need
       * to execute the smart bridge operation as the actual number
       * of channels involved will not have changed, we just need to
       * tell the other channel to leave */
      if ((bridge_channel2 = find_bridge_channel(bridge_channel->bridge, bridge_channel->swap))) {
         ast_debug(1, "Swapping bridge channel %p out from bridge %p so bridge channel %p can slip in\n", bridge_channel2, bridge_channel->bridge, bridge_channel);
         ast_bridge_change_state(bridge_channel2, AST_BRIDGE_CHANNEL_STATE_HANGUP);
      }

      bridge_channel->swap = NULL;
   } else if (ast_test_flag(&bridge_channel->bridge->feature_flags, AST_BRIDGE_FLAG_SMART)) {
      /* Perform the smart bridge operation, basically see if we need to move around between technologies */
      smart_bridge_operation(bridge_channel->bridge, bridge_channel, bridge_channel->bridge->num);
   }

   /* Make the channel compatible with the bridge */
   bridge_make_compatible(bridge_channel->bridge, bridge_channel);

   /* Tell the bridge technology we are joining so they set us up */
   if (bridge_channel->bridge->technology->join) {
      ast_debug(1, "Giving bridge technology %s notification that %p is joining bridge %p\n", bridge_channel->bridge->technology->name, bridge_channel, bridge_channel->bridge);
      if (bridge_channel->bridge->technology->join(bridge_channel->bridge, bridge_channel)) {
         ast_debug(1, "Bridge technology %s failed to join %p to bridge %p\n", bridge_channel->bridge->technology->name, bridge_channel, bridge_channel->bridge);
      }
   }

   /* Actually execute the respective threading model, and keep our bridge thread alive */
   while (bridge_channel->state == AST_BRIDGE_CHANNEL_STATE_WAIT) {
      /* Update bridge pointer on channel */
      ast_channel_internal_bridge_set(bridge_channel->chan, bridge_channel->bridge);
      /* If the technology requires a thread and one is not running, start it up */
      if (bridge_channel->bridge->thread == AST_PTHREADT_NULL && (bridge_channel->bridge->technology->capabilities & AST_BRIDGE_CAPABILITY_THREAD)) {
         bridge_channel->bridge->stop = 0;
         ast_debug(1, "Starting a bridge thread for bridge %p\n", bridge_channel->bridge);
         ao2_ref(bridge_channel->bridge, +1);
         if (ast_pthread_create(&bridge_channel->bridge->thread, NULL, bridge_thread, bridge_channel->bridge)) {
            ast_debug(1, "Failed to create a bridge thread for bridge %p, giving it another go.\n", bridge_channel->bridge);
            ao2_ref(bridge_channel->bridge, -1);
            continue;
         }
      }
      /* Execute the threading model */
      state = (bridge_channel->bridge->technology->capabilities & AST_BRIDGE_CAPABILITY_MULTITHREADED ? bridge_channel_join_multithreaded(bridge_channel) : bridge_channel_join_singlethreaded(bridge_channel));
      /* Depending on the above state see what we need to do */
      switch (state) {
      case AST_BRIDGE_CHANNEL_STATE_FEATURE:
         bridge_channel_suspend(bridge_channel->bridge, bridge_channel);
         ao2_unlock(bridge_channel->bridge);
         bridge_channel_feature(bridge_channel->bridge, bridge_channel);
         ao2_lock(bridge_channel->bridge);
         bridge_channel_unsuspend(bridge_channel->bridge, bridge_channel);
         break;
      case AST_BRIDGE_CHANNEL_STATE_DTMF:
         bridge_channel_suspend(bridge_channel->bridge, bridge_channel);
         bridge_channel_dtmf_stream(bridge_channel->bridge, bridge_channel);
         bridge_channel_unsuspend(bridge_channel->bridge, bridge_channel);
         break;
      case AST_BRIDGE_CHANNEL_STATE_START_TALKING:
      case AST_BRIDGE_CHANNEL_STATE_STOP_TALKING:
         ao2_unlock(bridge_channel->bridge);
         bridge_channel_talking(bridge_channel->bridge, bridge_channel);
         ao2_lock(bridge_channel->bridge);
         break;
      default:
         break;
      }
   }

   ast_channel_internal_bridge_set(bridge_channel->chan, NULL);

   /* See if we need to dissolve the bridge itself if they hung up */
   if (bridge_channel->state == AST_BRIDGE_CHANNEL_STATE_END) {
      bridge_check_dissolve(bridge_channel->bridge, bridge_channel);
   }

   /* Tell the bridge technology we are leaving so they tear us down */
   if (bridge_channel->bridge->technology->leave) {
      ast_debug(1, "Giving bridge technology %s notification that %p is leaving bridge %p\n", bridge_channel->bridge->technology->name, bridge_channel, bridge_channel->bridge);
      if (bridge_channel->bridge->technology->leave(bridge_channel->bridge, bridge_channel)) {
         ast_debug(1, "Bridge technology %s failed to leave %p from bridge %p\n", bridge_channel->bridge->technology->name, bridge_channel, bridge_channel->bridge);
      }
   }

   /* Remove channel from the bridge */
   bridge_channel->bridge->num--;
   AST_LIST_REMOVE(&bridge_channel->bridge->channels, bridge_channel, entry);

   bridge_array_remove(bridge_channel->bridge, bridge_channel->chan);

   /* Perform the smart bridge operation if needed since a channel has left */
   if (ast_test_flag(&bridge_channel->bridge->feature_flags, AST_BRIDGE_FLAG_SMART)) {
      smart_bridge_operation(bridge_channel->bridge, NULL, bridge_channel->bridge->num);
   }

   ao2_unlock(bridge_channel->bridge);

   /* Restore original formats of the channel as they came in */
   if (ast_format_cmp(ast_channel_readformat(bridge_channel->chan), &formats[0]) == AST_FORMAT_CMP_NOT_EQUAL) {
      ast_debug(1, "Bridge is returning %p to read format %s(%d)\n", bridge_channel, ast_getformatname(&formats[0]), formats[0].id);
      if (ast_set_read_format(bridge_channel->chan, &formats[0])) {
         ast_debug(1, "Bridge failed to return channel %p to read format %s(%d)\n", bridge_channel, ast_getformatname(&formats[0]), formats[0].id);
      }
   }
   if (ast_format_cmp(ast_channel_writeformat(bridge_channel->chan), &formats[1]) == AST_FORMAT_CMP_NOT_EQUAL) {
      ast_debug(1, "Bridge is returning %p to write format %s(%d)\n", bridge_channel, ast_getformatname(&formats[1]), formats[1].id);
      if (ast_set_write_format(bridge_channel->chan, &formats[1])) {
         ast_debug(1, "Bridge failed to return channel %p to write format %s(%d)\n", bridge_channel, ast_getformatname(&formats[1]), formats[1].id);
      }
   }

   return bridge_channel->state;
}
static enum ast_bridge_channel_state bridge_channel_join_multithreaded ( struct ast_bridge_channel bridge_channel) [static]

Run in a multithreaded model. Each joined channel does writing/reading in their own thread. TODO: Improve.

Definition at line 737 of file bridging.c.

References ao2_lock, ao2_object_get_lockaddr(), ao2_unlock, ast_bridge_handle_trip(), ast_cond_wait, ast_debug, ast_waitfor_nandfds(), ast_bridge_channel::bridge, ast_bridge_channel::chan, ast_bridge_channel::cond, ast_bridge_technology::fd, ast_bridge_channel::fds, ast_bridge_channel::state, ast_bridge_channel::suspended, and ast_bridge::technology.

Referenced by bridge_channel_join().

{
   int fds[4] = { -1, }, nfds = 0, i = 0, outfd = -1, ms = -1;
   struct ast_channel *chan = NULL;

   /* Add any file descriptors we may want to monitor */
   if (bridge_channel->bridge->technology->fd) {
      for (i = 0; i < 4; i ++) {
         if (bridge_channel->fds[i] >= 0) {
            fds[nfds++] = bridge_channel->fds[i];
         }
      }
   }

   ao2_unlock(bridge_channel->bridge);

   ao2_lock(bridge_channel);
   /* Wait for data to either come from the channel or us to be signalled */
   if (!bridge_channel->suspended) {
      ao2_unlock(bridge_channel);
      ast_debug(10, "Going into a multithreaded waitfor for bridge channel %p of bridge %p\n", bridge_channel, bridge_channel->bridge);
      chan = ast_waitfor_nandfds(&bridge_channel->chan, 1, fds, nfds, NULL, &outfd, &ms);
   } else {
      ast_debug(10, "Going into a multithreaded signal wait for bridge channel %p of bridge %p\n", bridge_channel, bridge_channel->bridge);
      ast_cond_wait(&bridge_channel->cond, ao2_object_get_lockaddr(bridge_channel));
      ao2_unlock(bridge_channel);
   }

   ao2_lock(bridge_channel->bridge);

   if (!bridge_channel->suspended) {
      ast_bridge_handle_trip(bridge_channel->bridge, bridge_channel, chan, outfd);
   }

   return bridge_channel->state;
}
static enum ast_bridge_channel_state bridge_channel_join_singlethreaded ( struct ast_bridge_channel bridge_channel) [static]

Run in a singlethreaded model. Each joined channel yields itself to the main bridge thread. TODO: Improve.

Definition at line 775 of file bridging.c.

References ao2_lock, ao2_object_get_lockaddr(), ao2_unlock, AST_BRIDGE_CHANNEL_STATE_WAIT, ast_cond_wait, ast_debug, ast_bridge_channel::bridge, ast_bridge_channel::cond, and ast_bridge_channel::state.

Referenced by bridge_channel_join().

{
   ao2_unlock(bridge_channel->bridge);
   ao2_lock(bridge_channel);
   if (bridge_channel->state == AST_BRIDGE_CHANNEL_STATE_WAIT) {
      ast_debug(1, "Going into a single threaded signal wait for bridge channel %p of bridge %p\n", bridge_channel, bridge_channel->bridge);
      ast_cond_wait(&bridge_channel->cond, ao2_object_get_lockaddr(bridge_channel));
   }
   ao2_unlock(bridge_channel);
   ao2_lock(bridge_channel->bridge);

   return bridge_channel->state;
}
static void bridge_channel_suspend ( struct ast_bridge bridge,
struct ast_bridge_channel bridge_channel 
) [static]

Internal function that suspends a channel from a bridge.

Definition at line 790 of file bridging.c.

References ao2_lock, ao2_unlock, bridge_array_remove(), ast_bridge_channel::chan, ast_bridge_technology::suspend, ast_bridge_channel::suspended, and ast_bridge::technology.

Referenced by ast_bridge_suspend(), and bridge_channel_join().

{
   ao2_lock(bridge_channel);
   bridge_channel->suspended = 1;
   bridge_array_remove(bridge, bridge_channel->chan);
   ao2_unlock(bridge_channel);

   if (bridge->technology->suspend) {
      bridge->technology->suspend(bridge, bridge_channel);
   }

   return;
}
static void bridge_channel_talking ( struct ast_bridge bridge,
struct ast_bridge_channel bridge_channel 
) [static]

Definition at line 903 of file bridging.c.

References ast_bridge_change_state(), AST_BRIDGE_CHANNEL_STATE_WAIT, ast_bridge_channel::features, ast_bridge::features, ast_bridge_features::talker_cb, and ast_bridge_features::talker_pvt_data.

Referenced by bridge_channel_join().

{
   struct ast_bridge_features *features = (bridge_channel->features ? bridge_channel->features : &bridge->features);

   if (features && features->talker_cb) {
      features->talker_cb(bridge, bridge_channel, features->talker_pvt_data);
   }
   ast_bridge_change_state(bridge_channel, AST_BRIDGE_CHANNEL_STATE_WAIT);
}
static void* bridge_channel_thread ( void *  data) [static]

Thread responsible for imparted bridged channels.

Definition at line 1138 of file bridging.c.

References ast_bridge_channel::allow_impart_hangup, ao2_lock, ao2_ref, ao2_unlock, AST_BRIDGE_CHANNEL_STATE_END, AST_BRIDGE_CHANNEL_STATE_HANGUP, ast_callid_threadassoc_add(), ast_hangup(), bridge_channel_join(), ast_bridge_channel::callid, ast_bridge_channel::chan, ast_bridge_channel::features, state, and ast_bridge_channel::swap.

Referenced by ast_bridge_impart().

{
   struct ast_bridge_channel *bridge_channel = data;
   enum ast_bridge_channel_state state;

   if (bridge_channel->callid) {
      ast_callid_threadassoc_add(bridge_channel->callid);
   }

   state = bridge_channel_join(bridge_channel);

   /* If no other thread is going to take the channel then hang it up, or else we would have to service it until something else came along */
   if (bridge_channel->allow_impart_hangup && (state == AST_BRIDGE_CHANNEL_STATE_END || state == AST_BRIDGE_CHANNEL_STATE_HANGUP)) {
      ast_hangup(bridge_channel->chan);
   }

   /* cleanup */
   ao2_lock(bridge_channel);
   bridge_channel->chan = NULL;
   bridge_channel->swap = NULL;
   bridge_channel->features = NULL;
   ao2_unlock(bridge_channel);

   ao2_ref(bridge_channel, -1);

   return NULL;
}
static void bridge_channel_unsuspend ( struct ast_bridge bridge,
struct ast_bridge_channel bridge_channel 
) [static]

Internal function that unsuspends a channel from a bridge.

Definition at line 805 of file bridging.c.

References ao2_lock, ao2_unlock, ast_cond_signal, bridge_array_add(), ast_bridge_channel::chan, ast_bridge_channel::cond, ast_bridge_channel::suspended, ast_bridge::technology, and ast_bridge_technology::unsuspend.

Referenced by ast_bridge_unsuspend(), and bridge_channel_join().

{
   ao2_lock(bridge_channel);
   bridge_channel->suspended = 0;
   bridge_array_add(bridge, bridge_channel->chan);
   ast_cond_signal(&bridge_channel->cond);
   ao2_unlock(bridge_channel);

   if (bridge->technology->unsuspend) {
      bridge->technology->unsuspend(bridge, bridge_channel);
   }



   return;
}
static void bridge_check_dissolve ( struct ast_bridge bridge,
struct ast_bridge_channel bridge_channel 
) [static]

Internal function to see whether a bridge should dissolve, and if so do it.

Definition at line 221 of file bridging.c.

References ast_bridge_change_state(), AST_BRIDGE_CHANNEL_STATE_DEPART, AST_BRIDGE_CHANNEL_STATE_END, AST_BRIDGE_CHANNEL_STATE_HANGUP, AST_BRIDGE_FLAG_DISSOLVE, ast_debug, AST_LIST_TRAVERSE, ast_test_flag, ast_bridge_features::feature_flags, ast_bridge::feature_flags, ast_bridge_channel::features, ast_bridge_channel::state, and ast_bridge_features::usable.

Referenced by bridge_channel_join().

{
   struct ast_bridge_channel *bridge_channel2 = NULL;

   if (!ast_test_flag(&bridge->feature_flags, AST_BRIDGE_FLAG_DISSOLVE) && (!bridge_channel->features || !bridge_channel->features->usable || !ast_test_flag(&bridge_channel->features->feature_flags, AST_BRIDGE_FLAG_DISSOLVE))) {
      return;
   }

   ast_debug(1, "Dissolving bridge %p\n", bridge);

   AST_LIST_TRAVERSE(&bridge->channels, bridge_channel2, entry) {
      if (bridge_channel2->state != AST_BRIDGE_CHANNEL_STATE_END && bridge_channel2->state != AST_BRIDGE_CHANNEL_STATE_DEPART) {
         ast_bridge_change_state(bridge_channel2, AST_BRIDGE_CHANNEL_STATE_HANGUP);
      }
   }

   return;
}
static int bridge_drop_control_frame ( int  subclass) [static]

Internal function used to determine whether a control frame should be dropped or not.

Definition at line 265 of file bridging.c.

References AST_CONTROL_ANSWER.

Referenced by ast_bridge_handle_trip().

{
   switch (subclass) {
   case AST_CONTROL_ANSWER:
   case -1:
      return 1;
   default:
      return 0;
   }
}
static struct ast_frame* bridge_handle_dtmf ( struct ast_bridge bridge,
struct ast_bridge_channel bridge_channel,
struct ast_frame frame 
) [static, read]

Internal function to handle DTMF from a channel.

Definition at line 241 of file bridging.c.

References ast_bridge_change_state(), AST_BRIDGE_CHANNEL_STATE_FEATURE, ast_frfree, AST_LIST_TRAVERSE, ast_bridge_features_hook::dtmf, ast_bridge_channel::features, ast_bridge::features, ast_frame_subclass::integer, ast_frame::subclass, and ast_bridge_features::usable.

Referenced by ast_bridge_handle_trip().

{
   struct ast_bridge_features *features = (bridge_channel->features ? bridge_channel->features : &bridge->features);
   struct ast_bridge_features_hook *hook = NULL;

   /* If the features structure we grabbed is not usable immediately return the frame */
   if (!features->usable) {
      return frame;
   }

   /* See if this DTMF matches the beginnings of any feature hooks, if so we switch to the feature state to either execute the feature or collect more DTMF */
   AST_LIST_TRAVERSE(&features->hooks, hook, entry) {
      if (hook->dtmf[0] == frame->subclass.integer) {
         ast_frfree(frame);
         frame = NULL;
         ast_bridge_change_state(bridge_channel, AST_BRIDGE_CHANNEL_STATE_FEATURE);
         break;
      }
   }

   return frame;
}
static int bridge_make_compatible ( struct ast_bridge bridge,
struct ast_bridge_channel bridge_channel 
) [static]

Definition at line 567 of file bridging.c.

References ast_best_codec(), ast_channel_name(), ast_channel_readformat(), ast_channel_writeformat(), ast_debug, ast_format_cap_iscompatible(), ast_format_copy(), ast_getformatname(), ast_getformatname_multiple(), ast_log(), ast_set_read_format(), ast_set_write_format(), ast_bridge_channel::chan, ast_bridge_technology::format_capabilities, LOG_WARNING, ast_bridge_technology::name, option_debug, and ast_bridge::technology.

Referenced by ast_bridge_merge(), bridge_channel_join(), and smart_bridge_operation().

{
   struct ast_format formats[2];
   ast_format_copy(&formats[0], ast_channel_readformat(bridge_channel->chan));
   ast_format_copy(&formats[1], ast_channel_writeformat(bridge_channel->chan));

   /* Are the formats currently in use something ths bridge can handle? */
   if (!ast_format_cap_iscompatible(bridge->technology->format_capabilities, ast_channel_readformat(bridge_channel->chan))) {
      struct ast_format best_format;
      ast_best_codec(bridge->technology->format_capabilities, &best_format);

      /* Read format is a no go... */
      if (option_debug) {
         char codec_buf[512];
         ast_debug(1, "Bridge technology %s wants to read any of formats %s but channel has %s\n", bridge->technology->name,
            ast_getformatname_multiple(codec_buf, sizeof(codec_buf), bridge->technology->format_capabilities),
            ast_getformatname(&formats[0]));
      }
      /* Switch read format to the best one chosen */
      if (ast_set_read_format(bridge_channel->chan, &best_format)) {
         ast_log(LOG_WARNING, "Failed to set channel %s to read format %s\n", ast_channel_name(bridge_channel->chan), ast_getformatname(&best_format));
         return -1;
      }
      ast_debug(1, "Bridge %p put channel %s into read format %s\n", bridge, ast_channel_name(bridge_channel->chan), ast_getformatname(&best_format));
   } else {
      ast_debug(1, "Bridge %p is happy that channel %s already has read format %s\n", bridge, ast_channel_name(bridge_channel->chan), ast_getformatname(&formats[0]));
   }

   if (!ast_format_cap_iscompatible(bridge->technology->format_capabilities, &formats[1])) {
      struct ast_format best_format;
      ast_best_codec(bridge->technology->format_capabilities, &best_format);

      /* Write format is a no go... */
      if (option_debug) {
         char codec_buf[512];
         ast_debug(1, "Bridge technology %s wants to write any of formats %s but channel has %s\n", bridge->technology->name,
            ast_getformatname_multiple(codec_buf, sizeof(codec_buf), bridge->technology->format_capabilities),
            ast_getformatname(&formats[1]));
      }
      /* Switch write format to the best one chosen */
      if (ast_set_write_format(bridge_channel->chan, &best_format)) {
         ast_log(LOG_WARNING, "Failed to set channel %s to write format %s\n", ast_channel_name(bridge_channel->chan), ast_getformatname(&best_format));
         return -1;
      }
      ast_debug(1, "Bridge %p put channel %s into write format %s\n", bridge, ast_channel_name(bridge_channel->chan), ast_getformatname(&best_format));
   } else {
      ast_debug(1, "Bridge %p is happy that channel %s already has write format %s\n", bridge, ast_channel_name(bridge_channel->chan), ast_getformatname(&formats[1]));
   }

   return 0;
}
static void bridge_poke ( struct ast_bridge bridge) [static]

Helper function to poke the bridge thread.

Definition at line 138 of file bridging.c.

References AST_PTHREADT_NULL, AST_PTHREADT_STOP, and ast_bridge::thread.

Referenced by ast_bridge_destroy(), bridge_array_add(), bridge_array_remove(), and smart_bridge_operation().

{
   /* Poke the thread just in case */
   if (bridge->thread != AST_PTHREADT_NULL && bridge->thread != AST_PTHREADT_STOP) {
      pthread_kill(bridge->thread, SIGURG);
   }

   return;
}
static void* bridge_thread ( void *  data) [static]

Bridge thread function.

Definition at line 369 of file bridging.c.

References ao2_lock, ao2_ref, ao2_unlock, ast_bridge::array_num, ast_callid_threadassoc_add(), ast_debug, AST_PTHREADT_NULL, ast_bridge::callid, generic_thread_loop(), ast_bridge::refresh, ast_bridge::stop, ast_bridge::technology, ast_bridge_technology::thread, and ast_bridge::thread.

Referenced by bridge_channel_join(), and smart_bridge_operation().

{
   struct ast_bridge *bridge = data;
   int res = 0;

   ao2_lock(bridge);

   if (bridge->callid) {
      ast_callid_threadassoc_add(bridge->callid);
   }

   ast_debug(1, "Started bridge thread for %p\n", bridge);

   /* Loop around until we are told to stop */
   while (!bridge->stop && bridge->array_num && !res) {
      /* In case the refresh bit was set simply set it back to off */
      bridge->refresh = 0;

      ast_debug(1, "Launching bridge thread function %p for bridge %p\n", (bridge->technology->thread ? bridge->technology->thread : &generic_thread_loop), bridge);

      /* Execute the appropriate thread function. If the technology does not provide one we use the generic one */
      res = (bridge->technology->thread ? bridge->technology->thread(bridge) : generic_thread_loop(bridge));
   }

   ast_debug(1, "Ending bridge thread for %p\n", bridge);

   /* Indicate the bridge thread is no longer active */
   bridge->thread = AST_PTHREADT_NULL;
   ao2_unlock(bridge);

   ao2_ref(bridge, -1);

   return NULL;
}
static void destroy_bridge ( void *  obj) [static]

Definition at line 439 of file bridging.c.

References ast_bridge::array, ast_bridge_features_cleanup(), ast_debug, ast_free, ast_module_unref(), cleanup_video_mode(), ast_bridge_technology::destroy, ast_bridge::features, ast_bridge_technology::mod, ast_bridge_technology::name, and ast_bridge::technology.

Referenced by ast_bridge_new().

{
   struct ast_bridge *bridge = obj;

   ast_debug(1, "Actually destroying bridge %p, nobody wants it anymore\n", bridge);

   /* Pass off the bridge to the technology to destroy if needed */
   if (bridge->technology->destroy) {
      ast_debug(1, "Giving bridge technology %s the bridge structure %p to destroy\n", bridge->technology->name, bridge);
      if (bridge->technology->destroy(bridge)) {
         ast_debug(1, "Bridge technology %s failed to destroy bridge structure %p... trying our best\n", bridge->technology->name, bridge);
      }
   }

   /* We are no longer using the bridge technology so decrement the module reference count on it */
   if (bridge->technology->mod) {
      ast_module_unref(bridge->technology->mod);
   }

   /* Last but not least clean up the features configuration */
   ast_bridge_features_cleanup(&bridge->features);

   /* Drop the array of channels */
   ast_free(bridge->array);

   cleanup_video_mode(bridge);

   return;
}
static struct ast_bridge_technology* find_best_technology ( uint32_t  capabilities) [static, read]

Helper function used to find the "best" bridge technology given a specified capabilities.

Definition at line 405 of file bridging.c.

References ast_debug, ast_module_ref(), AST_RWLIST_RDLOCK, AST_RWLIST_TRAVERSE, AST_RWLIST_UNLOCK, ast_bridge_technology::capabilities, ast_bridge_technology::name, ast_bridge_technology::preference, and ast_bridge_technology::suspended.

Referenced by ast_bridge_check(), ast_bridge_new(), and smart_bridge_operation().

{
   struct ast_bridge_technology *current = NULL, *best = NULL;

   AST_RWLIST_RDLOCK(&bridge_technologies);
   AST_RWLIST_TRAVERSE(&bridge_technologies, current, entry) {
      if (current->suspended) {
         ast_debug(1, "Bridge technology %s is suspended. Skipping.\n", current->name);
         continue;
      }
      if (!(current->capabilities & capabilities)) {
         ast_debug(1, "Bridge technology %s does not have the capabilities we need.\n", current->name);
         continue;
      }
      if (best && best->preference < current->preference) {
         ast_debug(1, "Bridge technology %s has preference %d while %s has preference %d. Skipping.\n", current->name, current->preference, best->name, best->preference);
         continue;
      }
      best = current;
   }

   if (best) {
      /* Increment it's module reference count if present so it does not get unloaded while in use */
      if (best->mod) {
         ast_module_ref(best->mod);
      }
      ast_debug(1, "Chose bridge technology %s\n", best->name);
   }

   AST_RWLIST_UNLOCK(&bridge_technologies);

   return best;
}
static struct ast_bridge_channel* find_bridge_channel ( struct ast_bridge bridge,
struct ast_channel chan 
) [static, read]

Helper function to find a bridge channel given a channel.

Definition at line 207 of file bridging.c.

References AST_LIST_TRAVERSE, and ast_bridge_channel::chan.

Referenced by ast_bridge_depart(), ast_bridge_handle_trip(), ast_bridge_remove(), ast_bridge_suspend(), ast_bridge_unsuspend(), and bridge_channel_join().

{
   struct ast_bridge_channel *bridge_channel = NULL;

   AST_LIST_TRAVERSE(&bridge->channels, bridge_channel, entry) {
      if (bridge_channel->chan == chan) {
         break;
      }
   }

   return bridge_channel;
}
static int generic_thread_loop ( struct ast_bridge bridge) [static]

Generic thread loop, TODO: Rethink this/improve it.

Definition at line 341 of file bridging.c.

References ao2_lock, ao2_unlock, ast_bridge::array, ast_bridge::array_num, ast_bridge_handle_trip(), ast_waitfor_n(), first, ast_bridge::refresh, ast_bridge::stop, and ast_bridge::waiting.

Referenced by bridge_thread().

{
   while (!bridge->stop && !bridge->refresh && bridge->array_num) {
      struct ast_channel *winner = NULL;
      int to = -1;

      /* Move channels around for priority reasons if we have more than one channel in our array */
      if (bridge->array_num > 1) {
         struct ast_channel *first = bridge->array[0];
         memmove(bridge->array, bridge->array + 1, sizeof(struct ast_channel *) * (bridge->array_num - 1));
         bridge->array[(bridge->array_num - 1)] = first;
      }

      /* Wait on the channels */
      bridge->waiting = 1;
      ao2_unlock(bridge);
      winner = ast_waitfor_n(bridge->array, (int)bridge->array_num, &to);
      bridge->waiting = 0;
      ao2_lock(bridge);

      /* Process whatever they did */
      ast_bridge_handle_trip(bridge, NULL, winner, -1);
   }

   return 0;
}
static int smart_bridge_operation ( struct ast_bridge bridge,
struct ast_bridge_channel bridge_channel,
int  count 
) [static]

Perform the smart bridge operation. Basically sees if a new bridge technology should be used instead of the current one.

Definition at line 620 of file bridging.c.

References ao2_lock, ao2_unlock, AST_BRIDGE_CAPABILITY_1TO1MIX, AST_BRIDGE_CAPABILITY_MULTIMIX, AST_BRIDGE_CAPABILITY_THREAD, ast_cond_signal, ast_debug, AST_LIST_TRAVERSE, ast_module_unref(), AST_PTHREADT_NULL, bridge_make_compatible(), bridge_poke(), ast_bridge::bridge_pvt, bridge_thread(), ast_bridge_technology::capabilities, ast_bridge_channel::cond, ast_bridge_technology::create, find_best_technology(), ast_bridge_technology::join, ast_bridge_technology::name, ast_bridge::refresh, ast_bridge::stop, ast_bridge::technology, ast_bridge_channel::thread, and ast_bridge::thread.

Referenced by ast_bridge_merge(), and bridge_channel_join().

{
   uint32_t new_capabilities = 0;
   struct ast_bridge_technology *new_technology = NULL, *old_technology = bridge->technology;
   struct ast_bridge temp_bridge = {
      .technology = bridge->technology,
      .bridge_pvt = bridge->bridge_pvt,
   };
   struct ast_bridge_channel *bridge_channel2 = NULL;

   /* Based on current feature determine whether we want to change bridge technologies or not */
   if (bridge->technology->capabilities & AST_BRIDGE_CAPABILITY_1TO1MIX) {
      if (count <= 2) {
         ast_debug(1, "Bridge %p channel count (%d) is within limits for bridge technology %s, not performing smart bridge operation.\n", bridge, count, bridge->technology->name);
         return 0;
      }
      new_capabilities = AST_BRIDGE_CAPABILITY_MULTIMIX;
   } else if (bridge->technology->capabilities & AST_BRIDGE_CAPABILITY_MULTIMIX) {
      if (count > 2) {
         ast_debug(1, "Bridge %p channel count (%d) is within limits for bridge technology %s, not performing smart bridge operation.\n", bridge, count, bridge->technology->name);
         return 0;
      }
      new_capabilities = AST_BRIDGE_CAPABILITY_1TO1MIX;
   }

   if (!new_capabilities) {
      ast_debug(1, "Bridge '%p' has no new capabilities, not performing smart bridge operation.\n", bridge);
      return 0;
   }

   /* Attempt to find a new bridge technology to satisfy the capabilities */
   if (!(new_technology = find_best_technology(new_capabilities))) {
      return -1;
   }

   ast_debug(1, "Performing smart bridge operation on bridge %p, moving from bridge technology %s to %s\n", bridge, old_technology->name, new_technology->name);

   /* If a thread is currently executing for the current technology tell it to stop */
   if (bridge->thread != AST_PTHREADT_NULL) {
      /* If the new bridge technology also needs a thread simply tell the bridge thread to refresh itself. This has the benefit of not incurring the cost/time of tearing down and bringing up a new thread. */
      if (new_technology->capabilities & AST_BRIDGE_CAPABILITY_THREAD) {
         ast_debug(1, "Telling current bridge thread for bridge %p to refresh\n", bridge);
         bridge->refresh = 1;
         bridge_poke(bridge);
      } else {
         pthread_t bridge_thread = bridge->thread;
         ast_debug(1, "Telling current bridge thread for bridge %p to stop\n", bridge);
         bridge->stop = 1;
         bridge_poke(bridge);
         ao2_unlock(bridge);
         pthread_join(bridge_thread, NULL);
         ao2_lock(bridge);
      }
   }

   /* Since we are soon going to pass this bridge to a new technology we need to NULL out the bridge_pvt pointer but don't worry as it still exists in temp_bridge, ditto for the old technology */
   bridge->bridge_pvt = NULL;
   bridge->technology = new_technology;

   /* Pass the bridge to the new bridge technology so it can set it up */
   if (new_technology->create) {
      ast_debug(1, "Giving bridge technology %s the bridge structure %p to setup\n", new_technology->name, bridge);
      if (new_technology->create(bridge)) {
         ast_debug(1, "Bridge technology %s failed to setup bridge structure %p\n", new_technology->name, bridge);
      }
   }

   /* Move existing channels over to the new technology, while taking them away from the old one */
   AST_LIST_TRAVERSE(&bridge->channels, bridge_channel2, entry) {
      /* Skip over channel that initiated the smart bridge operation */
      if (bridge_channel == bridge_channel2) {
         continue;
      }

      /* First we part them from the old technology */
      if (old_technology->leave) {
         ast_debug(1, "Giving bridge technology %s notification that %p is leaving bridge %p (really %p)\n", old_technology->name, bridge_channel2, &temp_bridge, bridge);
         if (old_technology->leave(&temp_bridge, bridge_channel2)) {
            ast_debug(1, "Bridge technology %s failed to allow %p (really %p) to leave bridge %p\n", old_technology->name, bridge_channel2, &temp_bridge, bridge);
         }
      }

      /* Second we make them compatible again with the bridge */
      bridge_make_compatible(bridge, bridge_channel2);

      /* Third we join them to the new technology */
      if (new_technology->join) {
         ast_debug(1, "Giving bridge technology %s notification that %p is joining bridge %p\n", new_technology->name, bridge_channel2, bridge);
         if (new_technology->join(bridge, bridge_channel2)) {
            ast_debug(1, "Bridge technology %s failed to join %p to bridge %p\n", new_technology->name, bridge_channel2, bridge);
         }
      }

      /* Fourth we tell them to wake up so they become aware that they above has happened */
      pthread_kill(bridge_channel2->thread, SIGURG);
      ao2_lock(bridge_channel2);
      ast_cond_signal(&bridge_channel2->cond);
      ao2_unlock(bridge_channel2);
   }

   /* Now that all the channels have been moved over we need to get rid of all the information the old technology may have left around */
   if (old_technology->destroy) {
      ast_debug(1, "Giving bridge technology %s the bridge structure %p (really %p) to destroy\n", old_technology->name, &temp_bridge, bridge);
      if (old_technology->destroy(&temp_bridge)) {
         ast_debug(1, "Bridge technology %s failed to destroy bridge structure %p (really %p)... some memory may have leaked\n", old_technology->name, &temp_bridge, bridge);
      }
   }

   /* Finally if the old technology has module referencing remove our reference, we are no longer going to use it */
   if (old_technology->mod) {
      ast_module_unref(old_technology->mod);
   }

   return 0;
}

Variable Documentation

Default DTMF keys for built in features

Definition at line 61 of file bridging.c.

Function handlers for the built in features

Definition at line 64 of file bridging.c.