<html>
<head>
    <base href="https://wiki.asterisk.org/wiki">
            <link rel="stylesheet" href="/wiki/s/en/2176/25/9/_/styles/combined.css?spaceKey=AST&amp;forWysiwyg=true" type="text/css">
    </head>
<body style="background: white;" bgcolor="white" class="email-body">
<div id="pageContent">
<div id="notificationFormat">
<div class="wiki-content">
<div class="email">
    <h2><a href="https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Bridging+API">Asterisk 12 Bridging API</a></h2>
    <h4>Page  <b>added</b> by             <a href="https://wiki.asterisk.org/wiki/display/~mjordan">Matt Jordan</a>
    </h4>
         <br/>
    <div class="notificationGreySide">
         
<h1><a name="Asterisk12BridgingAPI-BridgingFramework"></a><span class="error">&#91;Bridging Framework|&#93;</span></h1>

<h2><a name="Asterisk12BridgingAPI-astbridgecapability"></a>ast_bridge_capability</h2>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Confluence; brush: java; gutter: false">/*! \brief Capabilities for a bridge technology */
enum ast_bridge_capability {
        /*! Bridge is only capable of mixing 2 channels */
        AST_BRIDGE_CAPABILITY_1TO1MIX = (1 &lt;&lt; 1),
        /*! Bridge is capable of mixing 2 or more channels */
        AST_BRIDGE_CAPABILITY_MULTIMIX = (1 &lt;&lt; 2),
        /*! Bridge should natively bridge two channels if possible */
        AST_BRIDGE_CAPABILITY_NATIVE = (1 &lt;&lt; 3),
        /*! Bridge should run using the multithreaded model */
        AST_BRIDGE_CAPABILITY_MULTITHREADED = (1 &lt;&lt; 4),
        /*! Bridge should run a central bridge thread */
        AST_BRIDGE_CAPABILITY_THREAD = (1 &lt;&lt; 5),
        /*! Bridge technology can do video mixing (or something along those lines) */
        AST_BRIDGE_CAPABILITY_VIDEO = (1 &lt;&lt; 6),
        /*! Bridge technology can optimize things based on who is talking */
        AST_BRIDGE_CAPABILITY_OPTIMIZE = (1 &lt;&lt; 7),
};</pre>
</div></div>

<h2><a name="Asterisk12BridgingAPI-astbridgechannelstateenum"></a>ast_bridge_channel_state enum</h2>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Confluence; brush: java; gutter: false">/*! \brief State information about a bridged channel */
enum ast_bridge_channel_state {
        /*! Waiting for a signal (Channel in the bridge) */
        AST_BRIDGE_CHANNEL_STATE_WAIT = 0,
        /*! Bridged channel has ended itself (it has hung up) */
        AST_BRIDGE_CHANNEL_STATE_END,
        /*! Bridged channel was forced out and should be hung up */
        AST_BRIDGE_CHANNEL_STATE_HANGUP,
        /*! Bridged channel was ast_bridge_depart() from the bridge without being hung up */
        AST_BRIDGE_CHANNEL_STATE_DEPART,
        /*! Bridged channel was ast_bridge_depart() from the bridge during AST_BRIDGE_CHANNEL_STATE_END */
        AST_BRIDGE_CHANNEL_STATE_DEPART_END,
};</pre>
</div></div>

<h2><a name="Asterisk12BridgingAPI-astbridgewriteresult"></a>ast_bridge_write_result</h2>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Confluence; brush: java; gutter: false">/*! \brief Return values for bridge technology write function */
enum ast_bridge_write_result {
        /*! Bridge technology wrote out frame fine */
        AST_BRIDGE_WRITE_SUCCESS = 0,
        /*! Bridge technology attempted to write out the frame but failed */
        AST_BRIDGE_WRITE_FAILED,
        /*! Bridge technology does not support writing out a frame of this type */
        AST_BRIDGE_WRITE_UNSUPPORTED,
};</pre>
</div></div>

<h2><a name="Asterisk12BridgingAPI-astbridgetechoptimizations"></a>ast_bridge_tech_optimizations</h2>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Confluence; brush: java; gutter: false">/*!
 * \brief Structure specific to bridge technologies capable of
 * performing talking optimizations.
 */
struct ast_bridge_tech_optimizations {
        /*! The amount of time in ms that talking must be detected before
         *  the dsp determines that talking has occurred */
        unsigned int talking_threshold;
        /*! The amount of time in ms that silence must be detected before
         *  the dsp determines that talking has stopped */
        unsigned int silence_threshold;
        /*! Whether or not the bridging technology should drop audio
         *  detected as silence from the mix. */
        unsigned int drop_silence:1;
};</pre>
</div></div>

<h2><a name="Asterisk12BridgingAPI-astbridgechannel"></a>ast_bridge_channel</h2>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Confluence; brush: java; gutter: false">/*!
 * \brief Structure that contains information regarding a channel in a bridge
 */
struct ast_bridge_channel {
        /*! Condition, used if we want to wake up a thread waiting on the bridged channel */
        ast_cond_t cond;
        /*! Current bridged channel state */
        enum ast_bridge_channel_state state;
        /*! Asterisk channel participating in the bridge */
        struct ast_channel *chan;
        /*! Asterisk channel we are swapping with (if swapping) */
        struct ast_channel *swap;
        /*! Bridge this channel is participating in */
        struct ast_bridge *bridge;
        /*! Private information unique to the bridge technology */
        void *bridge_pvt;
        /*! Thread handling the bridged channel */
        pthread_t thread;
        /*! Additional file descriptors to look at */
        int fds[4];
        /*! Bit to indicate whether the channel is suspended from the bridge or not */
        unsigned int suspended:1;
        /*! TRUE if the imparted channel must wait for an explicit depart from the bridge to reclaim the channel. */
        unsigned int depart_wait:1;
        /*! Features structure for features that are specific to this channel */
        struct ast_bridge_features *features;
        /*! Technology optimization parameters used by bridging technologies capable of
         *  optimizing based upon talk detection. */
        struct ast_bridge_tech_optimizations tech_args;
        /*! Call ID associated with bridge channel */
        struct ast_callid *callid;
        /*! Linked list information */
        AST_LIST_ENTRY(ast_bridge_channel) entry;
        /*! Queue of actions to perform on the channel. */
        AST_LIST_HEAD_NOLOCK(, ast_frame) action_queue;
};</pre>
</div></div>

<h2><a name="Asterisk12BridgingAPI-astbridgeactiontypeenum"></a>ast_bridge_action_type enum</h2>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Confluence; brush: java; gutter: false">enum ast_bridge_action_type {
        /*! Bridged channel is to detect a feature hook */
        AST_BRIDGE_ACTION_FEATURE,
        /*! Bridged channel is to act on an interval hook */
        AST_BRIDGE_ACTION_INTERVAL,
        /*! Bridged channel is to send a DTMF stream out */
        AST_BRIDGE_ACTION_DTMF_STREAM,
        /*! Bridged channel is to indicate talking start */
        AST_BRIDGE_ACTION_TALKING_START,
        /*! Bridged channel is to indicate talking stop */
        AST_BRIDGE_ACTION_TALKING_STOP,
};</pre>
</div></div>

<h2><a name="Asterisk12BridgingAPI-astbridgevideomodetypeenum"></a>ast_bridge_video_mode_type enum</h2>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Confluence; brush: java; gutter: false">enum ast_bridge_video_mode_type {
        /*! Video is not allowed in the bridge */
        AST_BRIDGE_VIDEO_MODE_NONE = 0,
        /*! A single user is picked as the only distributed of video across the bridge */
        AST_BRIDGE_VIDEO_MODE_SINGLE_SRC,
        /*! A single user's video feed is distributed to all bridge channels, but
         *  that feed is automatically picked based on who is talking the most. */
        AST_BRIDGE_VIDEO_MODE_TALKER_SRC,
};</pre>
</div></div>

<h2><a name="Asterisk12BridgingAPI-astbridgevideosinglesrcdata"></a>ast_bridge_video_single_src_data</h2>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Confluence; brush: java; gutter: false">/*! This is used for both SINGLE_SRC mode to set what channel
 *  should be the current single video feed */
struct ast_bridge_video_single_src_data {
        /*! Only accept video coming from this channel */
        struct ast_channel *chan_vsrc;
};</pre>
</div></div>

<h2><a name="Asterisk12BridgingAPI-astbridgevideotalkersrcdata"></a>ast_bridge_video_talker_src_data</h2>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Confluence; brush: java; gutter: false">/*! This is used for both SINGLE_SRC_TALKER mode to set what channel
 *  should be the current single video feed */
struct ast_bridge_video_talker_src_data {
        /*! Only accept video coming from this channel */
        struct ast_channel *chan_vsrc;
        int average_talking_energy;

        /*! Current talker see's this person */
        struct ast_channel *chan_old_vsrc;
};</pre>
</div></div>

<h2><a name="Asterisk12BridgingAPI-astbridgevideomode"></a>ast_bridge_video_mode</h2>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Confluence; brush: java; gutter: false">struct ast_bridge_video_mode {
        enum ast_bridge_video_mode_type mode;
        /* Add data for all the video modes here. */
        union {
                struct ast_bridge_video_single_src_data single_src_data;
                struct ast_bridge_video_talker_src_data talker_src_data;
        } mode_data;
};</pre>
</div></div>

<h2><a name="Asterisk12BridgingAPI-astbridge"></a>ast_bridge</h2>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Confluence; brush: java; gutter: false">/*!
 * \brief Structure that contains information about a bridge
 */
struct ast_bridge {
        /*! Condition, used if we want to wake up the bridge thread. */
        ast_cond_t cond;
        /*! Number of channels participating in the bridge */
        int num;
        /*! The video mode this bridge is using */
        struct ast_bridge_video_mode video_mode;
        /*! The internal sample rate this bridge is mixed at when multiple channels are being mixed.
         *  If this value is 0, the bridge technology may auto adjust the internal mixing rate. */
        unsigned int internal_sample_rate;
        /*! The mixing interval indicates how quickly the bridges internal mixing should occur
         * for bridge technologies that mix audio. When set to 0, the bridge tech must choose a
         * default interval for itself. */
        unsigned int internal_mixing_interval;
        /*! Bit to indicate that the bridge thread is waiting on channels in the bridge array */
        unsigned int waiting:1;
        /*! Bit to indicate the bridge thread should stop */
        unsigned int stop:1;
        /*! Bit to indicate the bridge thread should refresh itself */
        unsigned int refresh:1;
        /*! Bridge flags to tweak behavior */
        struct ast_flags feature_flags;
        /*! Bridge technology that is handling the bridge */
        struct ast_bridge_technology *technology;
        /*! Private information unique to the bridge technology */
        void *bridge_pvt;
        /*! Thread running the bridge */
        pthread_t thread;
        /*! Enabled features information */
        struct ast_bridge_features features;
        /*! Array of channels that the bridge thread is currently handling */
        struct ast_channel **array;
        /*! Number of channels in the above array */
        size_t array_num;
        /*! Number of channels the array can handle */
        size_t array_size;
        /*! Call ID associated with the bridge */
        struct ast_callid *callid;
        /*! Linked list of channels participating in the bridge */
        AST_LIST_HEAD_NOLOCK(, ast_bridge_channel) channels;
        /*! Linked list of channels removed from the bridge and waiting to be departed. */
        AST_LIST_HEAD_NOLOCK(, ast_bridge_channel) depart_wait;
};</pre>
</div></div>

<h2><a name="Asterisk12BridgingAPI-astbridgenew"></a>ast_bridge_new</h2>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Confluence; brush: java; gutter: false">/*!
 * \brief Create a new bridge
 *
 * \param capabilities The capabilities that we require to be used on the bridge
 * \param flags Flags that will alter the behavior of the bridge
 *
 * \retval a pointer to a new bridge on success
 * \retval NULL on failure
 *
 * Example usage:
 *
 * \code
 * struct ast_bridge *bridge;
 * bridge = ast_bridge_new(AST_BRIDGE_CAPABILITY_1TO1MIX, AST_BRIDGE_FLAG_DISSOLVE_HANGUP);
 * \endcode
 *
 * This creates a simple two party bridge that will be destroyed once one of
 * the channels hangs up.
 */
struct ast_bridge *ast_bridge_new(uint32_t capabilities, int flags);</pre>
</div></div>

<h2><a name="Asterisk12BridgingAPI-astbridgelock"></a>ast_bridge_lock</h2>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Confluence; brush: java; gutter: false">/*!
 * \brief Lock the bridge.
 *
 * \param bridge Bridge to lock
 *
 * \return Nothing
 */
#define ast_bridge_lock(bridge)        _ast_bridge_lock(bridge, __FILE__, __PRETTY_FUNCTION__, __LINE__, #bridge)
static inline void _ast_bridge_lock(struct ast_bridge *bridge, const char *file, const char *function, int line, const char *var)
{
        __ao2_lock(bridge, AO2_LOCK_REQ_MUTEX, file, function, line, var);
}</pre>
</div></div>

<h2><a name="Asterisk12BridgingAPI-astbridgeunlock"></a>ast_bridge_unlock</h2>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Confluence; brush: java; gutter: false">/*!
 * \brief Unlock the bridge.
 *
 * \param bridge Bridge to unlock
 *
 * \return Nothing
 */
#define ast_bridge_unlock(bridge)        _ast_bridge_unlock(bridge, __FILE__, __PRETTY_FUNCTION__, __LINE__, #bridge)
static inline void _ast_bridge_unlock(struct ast_bridge *bridge, const char *file, const char *function, int line, const char *var)
{
        __ao2_unlock(bridge, file, function, line, var);
}</pre>
</div></div>

<h2><a name="Asterisk12BridgingAPI-astbridgecheck"></a>ast_bridge_check</h2>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Confluence; brush: java; gutter: false">/*!
 * \brief See if it is possible to create a bridge
 *
 * \param capabilities The capabilities that the bridge will use
 *
 * \retval 1 if possible
 * \retval 0 if not possible
 *
 * Example usage:
 *
 * \code
 * int possible = ast_bridge_check(AST_BRIDGE_CAPABILITY_1TO1MIX);
 * \endcode
 *
 * This sees if it is possible to create a bridge capable of bridging two channels
 * together.
 */
int ast_bridge_check(uint32_t capabilities);</pre>
</div></div>

<h2><a name="Asterisk12BridgingAPI-astbridgedestroy"></a>ast_bridge_destroy</h2>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Confluence; brush: java; gutter: false">/*!
 * \brief Destroy a bridge
 *
 * \param bridge Bridge to destroy
 *
 * \retval 0 on success
 * \retval -1 on failure
 *
 * Example usage:
 *
 * \code
 * ast_bridge_destroy(bridge);
 * \endcode
 *
 * This destroys a bridge that was previously created using ast_bridge_new.
 */
int ast_bridge_destroy(struct ast_bridge *bridge);</pre>
</div></div>

<h2><a name="Asterisk12BridgingAPI-astbridgejoin"></a>ast_bridge_join</h2>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Confluence; brush: java; gutter: false">/*!
 * \brief Join (blocking) a channel to a bridge
 *
 * \param bridge Bridge to join
 * \param chan Channel to join
 * \param swap Channel to swap out if swapping
 * \param features Bridge features structure
 * \param tech_args Optional Bridging tech optimization parameters for this channel.
 *
 * \retval state that channel exited the bridge with
 *
 * Example usage:
 *
 * \code
 * ast_bridge_join(bridge, chan, NULL, NULL);
 * \endcode
 *
 * 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.
 */
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);</pre>
</div></div>

<h2><a name="Asterisk12BridgingAPI-astbridgeimpart"></a>ast_bridge_impart</h2>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Confluence; brush: java; gutter: false">/*!
 * \brief Impart (non-blocking) a channel onto a bridge
 *
 * \param bridge Bridge to impart on
 * \param chan Channel to impart
 * \param swap Channel to swap out if swapping.  NULL if not swapping.
 * \param features Bridge features structure. Must be NULL or obtained by ast_bridge_features_new().
 * \param independent TRUE if caller does not want to reclaim the channel using ast_bridge_depart().
 *
 * \retval 0 on success
 * \retval -1 on failure
 *
 * Example usage:
 *
 * \code
 * ast_bridge_impart(bridge, chan, NULL, NULL, 0);
 * \endcode
 *
 * \details
 * 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.
 *
 * \note If you impart a channel as not independent you MUST
 * ast_bridge_depart() the channel.  The bridge channel thread
 * is created join-able.  The implication is that the channel is
 * special and is not intended to be moved to another bridge.
 *
 * \note If you impart a channel as independent you must not
 * ast_bridge_depart() the channel.  The bridge channel thread
 * is created non-join-able.  The channel must be treated as if
 * it were placed into the bridge by ast_bridge_join().
 * Channels placed into a bridge by ast_bridge_join() are
 * removed by a third party using ast_bridge_remove().
 */
int ast_bridge_impart(struct ast_bridge *bridge, struct ast_channel *chan, struct ast_channel *swap, struct ast_bridge_features *features, int independent);</pre>
</div></div>

<h2><a name="Asterisk12BridgingAPI-astbridgedepart"></a>ast_bridge_depart</h2>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Confluence; brush: java; gutter: false">/*!
 * \brief Depart a channel from a bridge
 *
 * \param bridge Bridge to depart from
 * \param chan Channel to depart
 *
 * \retval 0 on success
 * \retval -1 on failure
 *
 * Example usage:
 *
 * \code
 * ast_bridge_depart(bridge, chan);
 * \endcode
 *
 * 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 with the independent flag FALSE.
 */
int ast_bridge_depart(struct ast_bridge *bridge, struct ast_channel *chan);</pre>
</div></div>

<h2><a name="Asterisk12BridgingAPI-astbridgeremove"></a>ast_bridge_remove</h2>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Confluence; brush: java; gutter: false">/*!
 * \brief Remove a channel from a bridge
 *
 * \param bridge Bridge that the channel is to be removed from
 * \param chan Channel to remove
 *
 * \retval 0 on success
 * \retval -1 on failure
 *
 * Example usage:
 *
 * \code
 * ast_bridge_remove(bridge, chan);
 * \endcode
 *
 * 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.
 */
int ast_bridge_remove(struct ast_bridge *bridge, struct ast_channel *chan);</pre>
</div></div>

<h2><a name="Asterisk12BridgingAPI-astbridgemerge"></a>ast_bridge_merge</h2>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Confluence; brush: java; gutter: false">/*!
 * \brief Merge two bridges together
 *
 * \param bridge0 First bridge
 * \param bridge1 Second bridge
 *
 * \retval 0 on success
 * \retval -1 on failure
 *
 * Example usage:
 *
 * \code
 * ast_bridge_merge(bridge0, bridge1);
 * \endcode
 *
 * 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.
 */
int ast_bridge_merge(struct ast_bridge *bridge0, struct ast_bridge *bridge1);</pre>
</div></div>

<h2><a name="Asterisk12BridgingAPI-astbridgesuspend"></a>ast_bridge_suspend</h2>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Confluence; brush: java; gutter: false">/*!
 * \brief Suspend a channel temporarily from a bridge
 *
 * \param bridge Bridge to suspend the channel from
 * \param chan Channel to suspend
 *
 * \retval 0 on success
 * \retval -1 on failure
 *
 * Example usage:
 *
 * \code
 * ast_bridge_suspend(bridge, chan);
 * \endcode
 *
 * 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.
 */
int ast_bridge_suspend(struct ast_bridge *bridge, struct ast_channel *chan);</pre>
</div></div>

<h2><a name="Asterisk12BridgingAPI-astbridgeunsuspend"></a>ast_bridge_unsuspend</h2>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Confluence; brush: java; gutter: false">/*!
 * \brief Unsuspend a channel from a bridge
 *
 * \param bridge Bridge to unsuspend the channel from
 * \param chan Channel to unsuspend
 *
 * \retval 0 on success
 * \retval -1 on failure
 *
 * Example usage:
 *
 * \code
 * ast_bridge_unsuspend(bridge, chan);
 * \endcode
 *
 * 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.
 */
int ast_bridge_unsuspend(struct ast_bridge *bridge, struct ast_channel *chan);</pre>
</div></div>

<h2><a name="Asterisk12BridgingAPI-astbridgechangestate"></a>ast_bridge_change_state</h2>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Confluence; brush: java; gutter: false">/*!
 * \brief Change the state of a bridged channel
 *
 * \param bridge_channel Channel to change the state on
 * \param new_state The new state to place the channel into
 *
 * Example usage:
 *
 * \code
 * ast_bridge_change_state(bridge_channel, AST_BRIDGE_CHANNEL_STATE_HANGUP);
 * \endcode
 *
 * This places the channel pointed to by bridge_channel into the state
 * AST_BRIDGE_CHANNEL_STATE_HANGUP.
 *
 * \note This API call is only meant to be used in feature hook callbacks to
 *       request the channel exit the bridge.
 */
void ast_bridge_change_state(struct ast_bridge_channel *bridge_channel, enum ast_bridge_channel_state new_state);</pre>
</div></div>


<h2><a name="Asterisk12BridgingAPI-astbridgesetinternalsamplerate"></a>ast_bridge_set_internal_sample_rate</h2>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Confluence; brush: java; gutter: false">/*!
 * \brief Adjust the internal mixing sample rate of a bridge
 * used during multimix mode.
 *
 * \param bridge Channel to change the sample rate on.
 * \param sample_rate 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.
 *
 */
void ast_bridge_set_internal_sample_rate(struct ast_bridge *bridge, unsigned int sample_rate);</pre>
</div></div>

<h2><a name="Asterisk12BridgingAPI-astbridgesetmixinginterval"></a>ast_bridge_set_mixing_interval</h2>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Confluence; brush: java; gutter: false">/*!
 * \brief Adjust the internal mixing interval of a bridge used
 * during multimix mode.
 *
 * \param bridge Channel to change the sample rate on.
 * \param mixing_interval the sample rate to change to.  If 0 is set
 * the bridge tech is free to choose any mixing interval it uses by default.
 */
void ast_bridge_set_mixing_interval(struct ast_bridge *bridge, unsigned int mixing_interval);</pre>
</div></div>

<h2><a name="Asterisk12BridgingAPI-astbridgesetsinglesrcvideomode"></a>ast_bridge_set_single_src_video_mode</h2>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Confluence; brush: java; gutter: false">/*!
 * \brief Set a bridge to feed a single video source to all participants.
 */
void ast_bridge_set_single_src_video_mode(struct ast_bridge *bridge, struct ast_channel *video_src_chan);</pre>
</div></div>

<h2><a name="Asterisk12BridgingAPI-astbridgesettalkersrcvideomode"></a>ast_bridge_set_talker_src_video_mode</h2>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Confluence; brush: java; gutter: false">/*!
 * \brief Set the bridge to pick the strongest talker supporting
 * video as the single source video feed
 */
void ast_bridge_set_talker_src_video_mode(struct ast_bridge *bridge);</pre>
</div></div>

<h2><a name="Asterisk12BridgingAPI-astbridgeupdatetalkersrcvideomode"></a>ast_bridge_update_talker_src_video_mode</h2>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Confluence; brush: java; gutter: false">/*!
 * \brief Update information about talker energy for talker src video mode.
 */
void ast_bridge_update_talker_src_video_mode(struct ast_bridge *bridge, struct ast_channel *chan, int talker_energy, int is_keyfame);</pre>
</div></div>

<h2><a name="Asterisk12BridgingAPI-astbridgenumbervideosrc"></a>ast_bridge_number_video_src</h2>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Confluence; brush: java; gutter: false">/*!
 * \brief Returns the number of video sources currently active in the bridge
 */
int ast_bridge_number_video_src(struct ast_bridge *bridge);</pre>
</div></div>

<h2><a name="Asterisk12BridgingAPI-astbridgeisvideosrc"></a>ast_bridge_is_video_src</h2>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Confluence; brush: java; gutter: false">/*!
 * \brief Determine if a channel is a video src for the bridge
 *
 * \retval 0 Not a current video source of the bridge.
 * \retval None 0, 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.
 */
int ast_bridge_is_video_src(struct ast_bridge *bridge, struct ast_channel *chan);</pre>
</div></div>

<h2><a name="Asterisk12BridgingAPI-astbridgeremovevideosrc"></a>ast_bridge_remove_video_src</h2>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Confluence; brush: java; gutter: false">/*!
 * \brief remove a channel as a source of video for the bridge.
 */
void ast_bridge_remove_video_src(struct ast_bridge *bridge, struct ast_channel *chan);</pre>
</div></div>

<h1><a name="Asterisk12BridgingAPI-BridgingTechnologies"></a><a href="http://svn.asterisk.org/svn/asterisk/team/group/bridge_construction/include/asterisk/bridging_technology.h" class="external-link" rel="nofollow">Bridging Technologies</a></h1>

<p>This header file defines the APIs that bridging technologies must implement and function calls provided specifically to bridging technologies.</p>

<h2><a name="Asterisk12BridgingAPI-astbridgepreference"></a>ast_bridge_preference</h2>

<p>An enumeration that specifies for a registered bridging technology the preference the Bridging Framework should assign when picking between technologies with equivalent capabilities.</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Confluence; brush: java; gutter: false">/*! \brief Preference for choosing the bridge technology */
enum ast_bridge_preference {
        /*! Bridge technology should have high precedence over other bridge technologies */
        AST_BRIDGE_PREFERENCE_HIGH = 0,
        /*! Bridge technology is decent, not the best but should still be considered over low */
        AST_BRIDGE_PREFERENCE_MEDIUM,
        /*! Bridge technology is low, it should not be considered unless it is absolutely needed */
        AST_BRIDGE_PREFERENCE_LOW,
};</pre>
</div></div>

<h2><a name="Asterisk12BridgingAPI-astbridgetechnology"></a>ast_bridge_technology</h2>

<p>The interface that defines a bridging technology.</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Confluence; brush: java; gutter: false">/*!
 * \brief Structure that is the essence of a bridge technology
 */
struct ast_bridge_technology {
        /*! Unique name to this bridge technology */
        const char *name;
        /*! The capabilities that this bridge technology is capable of.  This has nothing to do with
         * format capabilities. */
        uint32_t capabilities;
        /*! Preference level that should be used when determining whether to use this bridge technology or not */
        enum ast_bridge_preference preference;
        /*! Callback for when a bridge is being created */
        int (*create)(struct ast_bridge *bridge);
        /*! Callback for when a bridge is being destroyed */
        int (*destroy)(struct ast_bridge *bridge);
        /*! Callback for when a channel is being added to a bridge */
        int (*join)(struct ast_bridge *bridge, struct ast_bridge_channel *bridge_channel);
        /*! Callback for when a channel is leaving a bridge */
        int (*leave)(struct ast_bridge *bridge, struct ast_bridge_channel *bridge_channel);
        /*! Callback for when a channel is suspended from the bridge */
        void (*suspend)(struct ast_bridge *bridge, struct ast_bridge_channel *bridge_channel);
        /*! Callback for when a channel is unsuspended from the bridge */
        void (*unsuspend)(struct ast_bridge *bridge, struct ast_bridge_channel *bridge_channel);
        /*! Callback to see if a channel is compatible with the bridging technology */
        int (*compatible)(struct ast_bridge_channel *bridge_channel);
        /*! Callback for writing a frame into the bridging technology */
        enum ast_bridge_write_result (*write)(struct ast_bridge *bridge, struct ast_bridge_channel *bridged_channel, struct ast_frame *frame);
        /*! Callback for when a file descriptor trips */
        int (*fd)(struct ast_bridge *bridge, struct ast_bridge_channel *bridge_channel, int fd);
        /*! Callback for replacement thread function */
        int (*thread)(struct ast_bridge *bridge);
        /*! Callback for poking a bridge thread */
        int (*poke)(struct ast_bridge *bridge, struct ast_bridge_channel *bridge_channel);
        /*! Formats that the bridge technology supports */
        struct ast_format_cap *format_capabilities;
        /*! Bit to indicate whether the bridge technology is currently suspended or not */
        unsigned int suspended:1;
        /*! Module this bridge technology belongs to. Is used for reference counting when creating/destroying a bridge. */
        struct ast_module *mod;
        /*! Linked list information */
        AST_RWLIST_ENTRY(ast_bridge_technology) entry;
};</pre>
</div></div>

<h2><a name="Asterisk12BridgingAPI-APIFunctionsforBridgingTechnologies"></a>API Functions for Bridging Technologies</h2>

<h3><a name="Asterisk12BridgingAPI-Registration"></a>Registration</h3>

<p>Bridging technologies must register themselves with the Bridging Framework.</p>

<h4><a name="Asterisk12BridgingAPI-astbridgetechnologyregister"></a>ast_bridge_technology_register</h4>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Confluence; brush: java; gutter: false">/*!
 * \brief Register a bridge technology for use
 *
 * \param technology The bridge technology to register
 * \param mod The module that is registering the bridge technology
 *
 * \retval 0 on success
 * \retval -1 on failure
 *
 * Example usage:
 *
 * \code
 * ast_bridge_technology_register(&amp;simple_bridge_tech);
 * \endcode
 *
 * 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.
 */
int __ast_bridge_technology_register(struct ast_bridge_technology *technology, struct ast_module *mod);

/*! \brief See \ref __ast_bridge_technology_register() */
#define ast_bridge_technology_register(technology) __ast_bridge_technology_register(technology, ast_module_info-&gt;self)</pre>
</div></div>

<h4><a name="Asterisk12BridgingAPI-astbridgetechnologyunregister"></a>ast_bridge_technology_unregister</h4>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Confluence; brush: java; gutter: false">/*!
 * \brief Unregister a bridge technology from use
 *
 * \param technology The bridge technology to unregister
 *
 * \retval 0 on success
 * \retval -1 on failure
 *
 * Example usage:
 *
 * \code
 * ast_bridge_technology_unregister(&amp;simple_bridge_tech);
 * \endcode
 *
 * 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.
 */
int ast_bridge_technology_unregister(struct ast_bridge_technology *technology);</pre>
</div></div>

<h3><a name="Asterisk12BridgingAPI-BridgeFrameworkInteraction"></a>Bridge Framework Interaction</h3>

<p>Several functions are provided specifically to bridging technologies to notify the Bridging Framework that some action has taken place.</p>

<h4><a name="Asterisk12BridgingAPI-astbridgehandletrip"></a>ast_bridge_handle_trip</h4>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Confluence; brush: java; gutter: false">/*!
 * \brief Feed notification that a frame is waiting on a channel into the bridging core
 *
 * \param bridge The bridge that the notification should influence
 * \param bridge_channel Bridge channel the notification was received on (if known)
 * \param chan Channel the notification was received on (if known)
 * \param outfd File descriptor that the notification was received on (if known)
 *
 * Example usage:
 *
 * \code
 * ast_bridge_handle_trip(bridge, NULL, chan, -1);
 * \endcode
 *
 * 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.
 */
void ast_bridge_handle_trip(struct ast_bridge *bridge, struct ast_bridge_channel *bridge_channel, struct ast_channel *chan, int outfd);</pre>
</div></div>

<h4><a name="Asterisk12BridgingAPI-astbridgenotifytalking"></a>ast_bridge_notify_talking</h4>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Confluence; brush: java; gutter: false">/*!
 * \brief 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.
 *
 * \param bridge_channel The bridge channel that has either started or stopped talking.
 * \param started_talking set to 1 when this indicates the channel has started talking set to 0
 * when this indicates the channel has stopped talking.
 */
void ast_bridge_notify_talking(struct ast_bridge_channel *bridge_channel, int started_talking);</pre>
</div></div>

<h4><a name="Asterisk12BridgingAPI-astbridgetechnologysuspend"></a>ast_bridge_technology_suspend</h4>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Confluence; brush: java; gutter: false">/*!
 * \brief Suspend a bridge technology from consideration
 *
 * \param technology The bridge technology to suspend
 *
 * Example usage:
 *
 * \code
 * ast_bridge_technology_suspend(&amp;simple_bridge_tech);
 * \endcode
 *
 * 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.
 */
void ast_bridge_technology_suspend(struct ast_bridge_technology *technology);</pre>
</div></div>

<h4><a name="Asterisk12BridgingAPI-astbridgetechnologyunsuspend"></a>ast_bridge_technology_unsuspend</h4>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Confluence; brush: java; gutter: false">/*!
 * \brief Unsuspend a bridge technology
 *
 * \param technology The bridge technology to unsuspend
 *
 * Example usage:
 *
 * \code
 * ast_bridge_technology_unsuspend(&amp;simple_bridge_tech);
 * \endcode
 *
 * This makes the bridge technology simple_bridge_tech considered when
 * creating a new bridge again.
 */
void ast_bridge_technology_unsuspend(struct ast_bridge_technology *technology);</pre>
</div></div>
    </div>
    <div id="commentsSection" class="wiki-content pageSection">
       <div style="float: right;" class="grey">
                        <a href="https://wiki.asterisk.org/wiki/users/removespacenotification.action?spaceKey=AST">Stop watching space</a>
            <span style="padding: 0px 5px;">|</span>
                <a href="https://wiki.asterisk.org/wiki/users/editmyemailsettings.action">Change email notification preferences</a>
</div>
       <a href="https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Bridging+API">View Online</a>
              |
       <a href="https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Bridging+API?showComments=true&amp;showCommentArea=true#addcomment">Add Comment</a>
           </div>
</div>
</div>
</div>
</div>
</body>
</html>