Asterisk - The Open Source Telephony Project  21.4.1
Data Structures | Macros | Typedefs | Enumerations | Functions
bridge_channel.h File Reference
#include "asterisk/bridge_features.h"
#include "asterisk/bridge_technology.h"

Go to the source code of this file.

Data Structures

struct  ast_bridge_channel
 Structure that contains information regarding a channel in a bridge. More...
 

Macros

#define ast_bridge_channel_lock(bridge_channel)   _ast_bridge_channel_lock(bridge_channel, __FILE__, __PRETTY_FUNCTION__, __LINE__, #bridge_channel)
 Lock the bridge_channel. More...
 
#define ast_bridge_channel_trylock(bridge_channel)   _ast_bridge_channel_trylock(bridge_channel, __FILE__, __PRETTY_FUNCTION__, __LINE__, #bridge_channel)
 Try locking the bridge_channel. More...
 
#define ast_bridge_channel_unlock(bridge_channel)   _ast_bridge_channel_unlock(bridge_channel, __FILE__, __PRETTY_FUNCTION__, __LINE__, #bridge_channel)
 Unlock the bridge_channel. More...
 

Typedefs

typedef void(* ast_bridge_custom_callback_fn) (struct ast_bridge_channel *bridge_channel, const void *payload, size_t payload_size)
 Custom callback run on a bridge channel. More...
 
typedef void(* ast_bridge_custom_play_fn) (struct ast_bridge_channel *bridge_channel, const char *playfile)
 Custom interpretation of the playfile name. More...
 

Enumerations

enum  ast_bridge_channel_custom_callback_option { AST_BRIDGE_CHANNEL_CB_OPTION_MEDIA = (1 << 0) }
 
enum  bridge_channel_state { BRIDGE_CHANNEL_STATE_WAIT = 0, BRIDGE_CHANNEL_STATE_END, BRIDGE_CHANNEL_STATE_END_NO_DISSOLVE }
 State information about a bridged channel. More...
 
enum  bridge_channel_thread_state { BRIDGE_CHANNEL_THREAD_IDLE, BRIDGE_CHANNEL_THREAD_SIMPLE, BRIDGE_CHANNEL_THREAD_FRAME }
 

Functions

static void _ast_bridge_channel_lock (struct ast_bridge_channel *bridge_channel, const char *file, const char *function, int line, const char *var)
 
static int _ast_bridge_channel_trylock (struct ast_bridge_channel *bridge_channel, const char *file, const char *function, int line, const char *var)
 
static void _ast_bridge_channel_unlock (struct ast_bridge_channel *bridge_channel, const char *file, const char *function, int line, const char *var)
 
void ast_bridge_channel_feature_digit (struct ast_bridge_channel *bridge_channel, int digit)
 Add a DTMF digit to the collected digits to match against DTMF features. More...
 
void ast_bridge_channel_feature_digit_add (struct ast_bridge_channel *bridge_channel, int digit)
 Add a DTMF digit to the collected digits. More...
 
struct ast_channelast_bridge_channel_get_chan (struct ast_bridge_channel *bridge_channel)
 Get a ref to the bridge_channel's ast_channel. More...
 
void ast_bridge_channel_kick (struct ast_bridge_channel *bridge_channel, int cause)
 Kick the channel out of the bridge. More...
 
void ast_bridge_channel_leave_bridge (struct ast_bridge_channel *bridge_channel, enum bridge_channel_state new_state, int cause)
 Set bridge channel state to leave bridge (if not leaving already). More...
 
void ast_bridge_channel_leave_bridge_nolock (struct ast_bridge_channel *bridge_channel, enum bridge_channel_state new_state, int cause)
 Set bridge channel state to leave bridge (if not leaving already). More...
 
void ast_bridge_channel_lock_bridge (struct ast_bridge_channel *bridge_channel)
 Lock the bridge associated with the bridge channel. More...
 
struct ast_bridgeast_bridge_channel_merge_inhibit (struct ast_bridge_channel *bridge_channel, int request)
 Adjust the bridge_channel's bridge merge inhibit request count. More...
 
int ast_bridge_channel_notify_talking (struct ast_bridge_channel *bridge_channel, int started_talking)
 Lets the bridging indicate when a bridge channel has stopped or started talking. More...
 
struct ast_bridge_channelast_bridge_channel_peer (struct ast_bridge_channel *bridge_channel)
 Get the peer bridge channel of a two party bridge. More...
 
void ast_bridge_channel_playfile (struct ast_bridge_channel *bridge_channel, ast_bridge_custom_play_fn custom_play, const char *playfile, const char *moh_class)
 Play a file on the bridge channel. More...
 
int ast_bridge_channel_queue_app (struct ast_bridge_channel *bridge_channel, const char *app_name, const char *app_args, const char *moh_class)
 Queue a bridge action run application frame onto the bridge channel. More...
 
int ast_bridge_channel_queue_callback (struct ast_bridge_channel *bridge_channel, enum ast_bridge_channel_custom_callback_option flags, ast_bridge_custom_callback_fn callback, const void *payload, size_t payload_size)
 Queue a bridge action custom callback frame onto the bridge channel. More...
 
int ast_bridge_channel_queue_control_data (struct ast_bridge_channel *bridge_channel, enum ast_control_frame_type control, const void *data, size_t datalen)
 Queue a control frame onto the bridge channel with data. More...
 
int ast_bridge_channel_queue_frame (struct ast_bridge_channel *bridge_channel, struct ast_frame *fr)
 Write a frame to the specified bridge_channel. More...
 
int ast_bridge_channel_queue_playfile (struct ast_bridge_channel *bridge_channel, ast_bridge_custom_play_fn custom_play, const char *playfile, const char *moh_class)
 Queue a bridge action play file frame onto the bridge channel. More...
 
int ast_bridge_channel_queue_playfile_sync (struct ast_bridge_channel *bridge_channel, ast_bridge_custom_play_fn custom_play, const char *playfile, const char *moh_class)
 Synchronously queue a bridge action play file frame onto the bridge channel. More...
 
void ast_bridge_channel_restore_formats (struct ast_bridge_channel *bridge_channel)
 Restore the formats of a bridge channel's channel to how they were before bridge_channel_internal_join. More...
 
void ast_bridge_channel_run_app (struct ast_bridge_channel *bridge_channel, const char *app_name, const char *app_args, const char *moh_class)
 Run an application on the bridge channel. More...
 
void ast_bridge_channel_stream_map (struct ast_bridge_channel *bridge_channel)
 Maps a channel's stream topology to and from the bridge. More...
 
void ast_bridge_channel_update_accountcodes (struct ast_bridge_channel *joining, struct ast_bridge_channel *leaving)
 
void ast_bridge_channel_update_linkedids (struct ast_bridge_channel *bridge_channel, struct ast_bridge_channel *swap)
 
int ast_bridge_channel_write_app (struct ast_bridge_channel *bridge_channel, const char *app_name, const char *app_args, const char *moh_class)
 Write a bridge action run application frame into the bridge. More...
 
int ast_bridge_channel_write_callback (struct ast_bridge_channel *bridge_channel, enum ast_bridge_channel_custom_callback_option flags, ast_bridge_custom_callback_fn callback, const void *payload, size_t payload_size)
 Write a bridge action custom callback frame into the bridge. More...
 
int ast_bridge_channel_write_control_data (struct ast_bridge_channel *bridge_channel, enum ast_control_frame_type control, const void *data, size_t datalen)
 Write a control frame into the bridge with data. More...
 
int ast_bridge_channel_write_hold (struct ast_bridge_channel *bridge_channel, const char *moh_class)
 Write a hold frame into the bridge. More...
 
int ast_bridge_channel_write_park (struct ast_bridge_channel *bridge_channel, const char *parkee_uuid, const char *parker_uuid, const char *app_data)
 Have a bridge channel park a channel in the bridge. More...
 
int ast_bridge_channel_write_playfile (struct ast_bridge_channel *bridge_channel, ast_bridge_custom_play_fn custom_play, const char *playfile, const char *moh_class)
 Write a bridge action play file frame into the bridge. More...
 
int ast_bridge_channel_write_unhold (struct ast_bridge_channel *bridge_channel)
 Write an unhold frame into the bridge. More...
 

Macro Definition Documentation

#define ast_bridge_channel_lock (   bridge_channel)    _ast_bridge_channel_lock(bridge_channel, __FILE__, __PRETTY_FUNCTION__, __LINE__, #bridge_channel)
#define ast_bridge_channel_trylock (   bridge_channel)    _ast_bridge_channel_trylock(bridge_channel, __FILE__, __PRETTY_FUNCTION__, __LINE__, #bridge_channel)

Try locking the bridge_channel.

Parameters
bridge_channelWhat to try locking
Return values
0on success.
non-zeroon error.

Definition at line 218 of file bridge_channel.h.

#define ast_bridge_channel_unlock (   bridge_channel)    _ast_bridge_channel_unlock(bridge_channel, __FILE__, __PRETTY_FUNCTION__, __LINE__, #bridge_channel)

Typedef Documentation

typedef void(* ast_bridge_custom_callback_fn) (struct ast_bridge_channel *bridge_channel, const void *payload, size_t payload_size)

Custom callback run on a bridge channel.

Parameters
bridge_channelWhich channel to operate on.
payloadData to pass to the callback. (NULL if none).
payload_sizeSize of the payload if payload is non-NULL. A number otherwise.
Note
The payload MUST NOT have any resources that need to be freed.

Definition at line 598 of file bridge_channel.h.

typedef void(* ast_bridge_custom_play_fn) (struct ast_bridge_channel *bridge_channel, const char *playfile)

Custom interpretation of the playfile name.

Parameters
bridge_channelWhich channel to play the file on
playfileSound filename to play.

Definition at line 514 of file bridge_channel.h.

Enumeration Type Documentation

Enumerator
AST_BRIDGE_CHANNEL_CB_OPTION_MEDIA 

The callback temporarily affects media. (Like a custom playfile.)

Definition at line 600 of file bridge_channel.h.

600  {
601  /*! The callback temporarily affects media. (Like a custom playfile.) */
603 };

State information about a bridged channel.

Enumerator
BRIDGE_CHANNEL_STATE_WAIT 

Waiting for a signal (Channel in the bridge)

BRIDGE_CHANNEL_STATE_END 

Bridged channel was forced out and should be hung up (Bridge may dissolve.)

BRIDGE_CHANNEL_STATE_END_NO_DISSOLVE 

Bridged channel was forced out. Don't dissolve the bridge regardless

Definition at line 60 of file bridge_channel.h.

60  {
61  /*! Waiting for a signal (Channel in the bridge) */
63  /*! Bridged channel was forced out and should be hung up (Bridge may dissolve.) */
65  /*! Bridged channel was forced out. Don't dissolve the bridge regardless */
67 };
Enumerator
BRIDGE_CHANNEL_THREAD_IDLE 

Bridge channel thread is idle/waiting.

BRIDGE_CHANNEL_THREAD_SIMPLE 

Bridge channel thread is writing a normal/simple frame.

BRIDGE_CHANNEL_THREAD_FRAME 

Bridge channel thread is processing a frame.

Definition at line 69 of file bridge_channel.h.

69  {
70  /*! Bridge channel thread is idle/waiting. */
72  /*! Bridge channel thread is writing a normal/simple frame. */
74  /*! Bridge channel thread is processing a frame. */
76 };

Function Documentation

void ast_bridge_channel_feature_digit ( struct ast_bridge_channel bridge_channel,
int  digit 
)

Add a DTMF digit to the collected digits to match against DTMF features.

Since
12.8.0
Parameters
bridge_channelChannel that received a DTMF digit.
digitDTMF digit to add to collected digits or 0 for timeout event.
Note
Neither the bridge nor the bridge_channel locks should be held when entering this function.
This is intended to be called by bridge hooks and the bridge channel thread.
This is intended to be called by non-DTMF bridge hooks and the bridge channel thread. Calling from a DTMF bridge hook can potentially cause unbounded recursion.

Definition at line 1695 of file bridge_channel.c.

References ao2_ref, ao2_unlink, ast_bridge_channel_kick(), ast_bridge_channel_lock_bridge(), ast_bridge_unlock, AST_CONTROL_SRCUPDATE, ast_debug, ast_indicate(), ast_samp2tv(), ast_test_suite_event_notify, ast_tvadd(), ast_tvnow(), ast_bridge_channel::bridge, ast_bridge_hook::callback, ast_bridge_channel::chan, ast_bridge_hook_dtmf_parms::code, ast_bridge_channel::collected, ast_bridge_hook_dtmf::dtmf, ast_bridge_channel::dtmf_hook_state, ast_bridge_features::dtmf_hooks, ast_bridge_features::dtmf_passthrough, ast_bridge_channel::features, ast_bridge_hook_dtmf::generic, ast_bridge_hook::hook_pvt, ast_bridge_channel::interdigit_timeout, OBJ_SEARCH_PARTIAL_KEY, and ast_bridge_channel::suspended.

1696 {
1697  struct ast_bridge_features *features = bridge_channel->features;
1698  struct ast_bridge_hook_dtmf *hook = NULL;
1699  size_t dtmf_len;
1700 
1701  struct sanity_check_of_dtmf_size {
1702  char check[1 / (ARRAY_LEN(bridge_channel->dtmf_hook_state.collected) == ARRAY_LEN(hook->dtmf.code))];
1703  };
1704 
1705  dtmf_len = strlen(bridge_channel->dtmf_hook_state.collected);
1706  if (!dtmf_len && !digit) {
1707  /* Nothing to do */
1708  return;
1709  }
1710 
1711  if (digit) {
1712  dtmf_len = bridge_channel_feature_digit_add(bridge_channel, digit, dtmf_len);
1713  }
1714 
1715  while (digit) {
1716  /* See if a DTMF feature hook matches or can match */
1717  hook = ao2_find(features->dtmf_hooks, bridge_channel->dtmf_hook_state.collected,
1719  if (!hook) {
1720  ast_debug(1, "No DTMF feature hooks on %p(%s) match '%s'\n",
1721  bridge_channel, ast_channel_name(bridge_channel->chan),
1722  bridge_channel->dtmf_hook_state.collected);
1723  break;
1724  } else if (dtmf_len != strlen(hook->dtmf.code)) {
1725  unsigned int digit_timeout;
1726  /* Need more digits to match */
1727  ao2_ref(hook, -1);
1728  digit_timeout = bridge_channel_feature_digit_timeout(bridge_channel);
1729  bridge_channel->dtmf_hook_state.interdigit_timeout =
1730  ast_tvadd(ast_tvnow(), ast_samp2tv(digit_timeout, 1000));
1731  return;
1732  } else {
1733  int remove_me;
1734  int already_suspended;
1735 
1736  ast_debug(1, "DTMF feature hook %p matched DTMF string '%s' on %p(%s)\n",
1737  hook, bridge_channel->dtmf_hook_state.collected, bridge_channel,
1738  ast_channel_name(bridge_channel->chan));
1739 
1740  /*
1741  * Clear the collected digits before executing the hook
1742  * in case the hook starts another sequence.
1743  */
1744  bridge_channel->dtmf_hook_state.collected[0] = '\0';
1745 
1746  ast_bridge_channel_lock_bridge(bridge_channel);
1747  already_suspended = bridge_channel->suspended;
1748  if (!already_suspended) {
1749  bridge_channel_internal_suspend_nolock(bridge_channel);
1750  }
1751  ast_bridge_unlock(bridge_channel->bridge);
1752  ast_indicate(bridge_channel->chan, AST_CONTROL_SRCUPDATE);
1753 
1754  /* Execute the matched hook on this channel. */
1755  remove_me = hook->generic.callback(bridge_channel, hook->generic.hook_pvt);
1756  if (remove_me) {
1757  ast_debug(1, "DTMF hook %p is being removed from %p(%s)\n",
1758  hook, bridge_channel, ast_channel_name(bridge_channel->chan));
1759  ao2_unlink(features->dtmf_hooks, hook);
1760  }
1761  testsuite_notify_feature_success(bridge_channel->chan, hook->dtmf.code);
1762  ao2_ref(hook, -1);
1763 
1764  ast_indicate(bridge_channel->chan, AST_CONTROL_SRCUPDATE);
1765  if (!already_suspended) {
1766  bridge_channel_unsuspend(bridge_channel);
1767  }
1768 
1769  /*
1770  * If we are handing the channel off to an external hook for
1771  * ownership, we are not guaranteed what kind of state it will
1772  * come back in. If the channel hungup, we need to detect that
1773  * here if the hook did not already change the state.
1774  */
1775  if (bridge_channel->chan && ast_check_hangup_locked(bridge_channel->chan)) {
1776  ast_bridge_channel_kick(bridge_channel, 0);
1777  bridge_channel->dtmf_hook_state.collected[0] = '\0';
1778  return;
1779  }
1780 
1781  /* if there is dtmf that has been collected then loop back through,
1782  but set digit to -1 so it doesn't try to do an add since the dtmf
1783  is already in the buffer */
1784  dtmf_len = strlen(bridge_channel->dtmf_hook_state.collected);
1785  if (!dtmf_len) {
1786  return;
1787  }
1788  }
1789  }
1790 
1791  if (!digit) {
1792  ast_debug(1, "DTMF feature string collection on %p(%s) timed out\n",
1793  bridge_channel, ast_channel_name(bridge_channel->chan));
1794  }
1795 
1796  /* Timeout or DTMF digit didn't allow a match with any hooks. */
1797  if (features->dtmf_passthrough) {
1798  /* Stream the collected DTMF to the other channels. */
1799  bridge_channel_write_dtmf_stream(bridge_channel,
1800  bridge_channel->dtmf_hook_state.collected);
1801  }
1802  bridge_channel->dtmf_hook_state.collected[0] = '\0';
1803 
1804  ast_test_suite_event_notify("FEATURE_DETECTION", "Result: fail");
1805 }
struct ast_bridge_channel::@193 dtmf_hook_state
struct ast_bridge_features * features
Structure that contains features information.
int ast_indicate(struct ast_channel *chan, int condition)
Indicates condition of channel.
Definition: channel.c:4277
unsigned int suspended
struct ao2_container * dtmf_hooks
struct timeval ast_tvnow(void)
Returns current timeval. Meant to replace calls to gettimeofday().
Definition: time.h:159
char collected[MAXIMUM_DTMF_FEATURE_STRING]
struct ast_bridge * bridge
Bridge this channel is participating in.
The arg parameter is a partial search key similar to OBJ_SEARCH_KEY.
Definition: astobj2.h:1116
void ast_bridge_channel_kick(struct ast_bridge_channel *bridge_channel, int cause)
Kick the channel out of the bridge.
#define ao2_ref(o, delta)
Reference/unreference an object and return the old refcount.
Definition: astobj2.h:459
struct timeval ast_samp2tv(unsigned int _nsamp, unsigned int _rate)
Returns a timeval corresponding to the duration of n samples at rate r. Useful to convert samples to ...
Definition: time.h:282
struct ast_bridge_hook_dtmf_parms dtmf
#define ast_debug(level,...)
Log a DEBUG message.
struct timeval interdigit_timeout
#define ast_test_suite_event_notify(s, f,...)
Definition: test.h:189
unsigned int dtmf_passthrough
#define ao2_unlink(container, obj)
Remove an object from a container.
Definition: astobj2.h:1578
ast_bridge_hook_callback callback
struct timeval ast_tvadd(struct timeval a, struct timeval b)
Returns the sum of two timevals a + b.
Definition: extconf.c:2282
#define ast_bridge_unlock(bridge)
Unlock the bridge.
Definition: bridge.h:481
struct ast_bridge_hook generic
struct ast_channel * chan
void ast_bridge_channel_lock_bridge(struct ast_bridge_channel *bridge_channel)
Lock the bridge associated with the bridge channel.
char code[MAXIMUM_DTMF_FEATURE_STRING]
void ast_bridge_channel_feature_digit_add ( struct ast_bridge_channel bridge_channel,
int  digit 
)

Add a DTMF digit to the collected digits.

Since
13.3.0
Parameters
bridge_channelChannel that received a DTMF digit.
digitDTMF digit to add to collected digits
Note
Neither the bridge nor the bridge_channel locks should be held when entering this function.
This is can only be called from within DTMF bridge hooks.

Definition at line 1687 of file bridge_channel.c.

References ast_bridge_channel::collected, and ast_bridge_channel::dtmf_hook_state.

Referenced by play_file().

1688 {
1689  if (digit) {
1690  bridge_channel_feature_digit_add(
1691  bridge_channel, digit, strlen(bridge_channel->dtmf_hook_state.collected));
1692  }
1693 }
struct ast_bridge_channel::@193 dtmf_hook_state
char collected[MAXIMUM_DTMF_FEATURE_STRING]
struct ast_channel* ast_bridge_channel_get_chan ( struct ast_bridge_channel bridge_channel)

Get a ref to the bridge_channel's ast_channel.

Parameters
bridge_channelThe bridge channel
Note
The returned channel NEEDS to be unref'd once you are done with it. In general, this function is best used when accessing the bridge_channel chan from outside of a bridging thread.
Return values
ref'dast_channel on success
NULLotherwise

Definition at line 212 of file bridge_channel.c.

References ao2_bump, and ast_bridge_channel::chan.

Referenced by ast_bridge_channel_write_unhold().

213 {
214  struct ast_channel *chan;
215 
216  ao2_lock(bridge_channel);
217  chan = ao2_bump(bridge_channel->chan);
218  ao2_unlock(bridge_channel);
219 
220  return chan;
221 }
Main Channel structure associated with a channel.
#define ao2_bump(obj)
Bump refcount on an AO2 object by one, returning the object.
Definition: astobj2.h:480
struct ast_channel * chan
void ast_bridge_channel_kick ( struct ast_bridge_channel bridge_channel,
int  cause 
)

Kick the channel out of the bridge.

Since
12.0.0
Parameters
bridge_channelWhich channel is being kicked or hungup.
causeCause of channel being kicked. If cause <= 0 then use cause on channel if cause still <= 0 use AST_CAUSE_NORMAL_CLEARING.
Note
This is intended to be called by bridge hooks and the bridge channel thread.

Definition at line 592 of file bridge_channel.c.

References ao2_iterator_destroy(), ao2_iterator_init(), ao2_ref, ao2_unlink, ast_bridge_channel_leave_bridge(), ast_bridge_channel_lock, ast_bridge_channel_unlock, ast_debug, BRIDGE_CHANNEL_STATE_END, BRIDGE_CHANNEL_STATE_WAIT, ast_bridge_hook::callback, ast_bridge_channel::chan, ast_bridge_channel::features, ast_bridge_hook::hook_pvt, ast_bridge_features::other_hooks, ast_bridge_channel::state, and ast_bridge_hook::type.

Referenced by ast_bridge_channel_feature_digit(), and ast_bridge_channel_run_app().

593 {
594  struct ast_bridge_features *features = bridge_channel->features;
595  struct ast_bridge_hook *hook;
596  struct ao2_iterator iter;
597 
598  ast_bridge_channel_lock(bridge_channel);
599  if (bridge_channel->state == BRIDGE_CHANNEL_STATE_WAIT) {
600  channel_set_cause(bridge_channel->chan, cause);
601  cause = 0;
602  }
603  ast_bridge_channel_unlock(bridge_channel);
604 
605  /* Run any hangup hooks. */
606  iter = ao2_iterator_init(features->other_hooks, 0);
607  for (; (hook = ao2_iterator_next(&iter)); ao2_ref(hook, -1)) {
608  int remove_me;
609 
610  if (hook->type != AST_BRIDGE_HOOK_TYPE_HANGUP) {
611  continue;
612  }
613  remove_me = hook->callback(bridge_channel, hook->hook_pvt);
614  if (remove_me) {
615  ast_debug(1, "Hangup hook %p is being removed from %p(%s)\n",
616  hook, bridge_channel, ast_channel_name(bridge_channel->chan));
617  ao2_unlink(features->other_hooks, hook);
618  }
619  }
620  ao2_iterator_destroy(&iter);
621 
622  /* Default hangup action. */
624 }
struct ast_bridge_features * features
Structure that contains features information.
void ast_bridge_channel_leave_bridge(struct ast_bridge_channel *bridge_channel, enum bridge_channel_state new_state, int cause)
Set bridge channel state to leave bridge (if not leaving already).
enum bridge_channel_state state
void ao2_iterator_destroy(struct ao2_iterator *iter)
Destroy a container iterator.
#define ast_bridge_channel_lock(bridge_channel)
Lock the bridge_channel.
enum ast_bridge_hook_type type
#define ao2_ref(o, delta)
Reference/unreference an object and return the old refcount.
Definition: astobj2.h:459
#define ast_debug(level,...)
Log a DEBUG message.
#define ast_bridge_channel_unlock(bridge_channel)
Unlock the bridge_channel.
#define ao2_unlink(container, obj)
Remove an object from a container.
Definition: astobj2.h:1578
ast_bridge_hook_callback callback
struct ast_channel * chan
When we need to walk through a container, we use an ao2_iterator to keep track of the current positio...
Definition: astobj2.h:1821
struct ao2_container * other_hooks
struct ao2_iterator ao2_iterator_init(struct ao2_container *c, int flags) attribute_warn_unused_result
Create an iterator for a container.
Structure that is the essence of a feature hook.
void ast_bridge_channel_leave_bridge ( struct ast_bridge_channel bridge_channel,
enum bridge_channel_state  new_state,
int  cause 
)

Set bridge channel state to leave bridge (if not leaving already).

Parameters
bridge_channelChannel to change the state on
new_stateThe new state to place the channel into
causeCause of channel leaving bridge. If cause <= 0 then use cause on channel if cause still <= 0 use AST_CAUSE_NORMAL_CLEARING.

Example usage:

1 ast_bridge_channel_leave_bridge(bridge_channel, BRIDGE_CHANNEL_STATE_END, AST_CAUSE_NORMAL_CLEARING);

This places the channel pointed to by bridge_channel into the state BRIDGE_CHANNEL_STATE_END if it was BRIDGE_CHANNEL_STATE_WAIT before.

Definition at line 315 of file bridge_channel.c.

References ast_bridge_channel_leave_bridge_nolock(), ast_bridge_channel_lock, and ast_bridge_channel_unlock.

Referenced by ast_bridge_channel_kick(), ast_bridge_depart(), ast_bridge_remove(), bridge_agent_hold_push(), feature_hangup(), and say_parking_space().

316 {
317  ast_bridge_channel_lock(bridge_channel);
318  ast_bridge_channel_leave_bridge_nolock(bridge_channel, new_state, cause);
319  ast_bridge_channel_unlock(bridge_channel);
320 }
#define ast_bridge_channel_lock(bridge_channel)
Lock the bridge_channel.
void ast_bridge_channel_leave_bridge_nolock(struct ast_bridge_channel *bridge_channel, enum bridge_channel_state new_state, int cause)
Set bridge channel state to leave bridge (if not leaving already).
#define ast_bridge_channel_unlock(bridge_channel)
Unlock the bridge_channel.
void ast_bridge_channel_leave_bridge_nolock ( struct ast_bridge_channel bridge_channel,
enum bridge_channel_state  new_state,
int  cause 
)

Set bridge channel state to leave bridge (if not leaving already).

Parameters
bridge_channelChannel to change the state on
new_stateThe new state to place the channel into
causeCause of channel leaving bridge. If cause <= 0 then use cause on channel if cause still <= 0 use AST_CAUSE_NORMAL_CLEARING.

Example usage:

1 ast_bridge_channel_leave_bridge(bridge_channel, BRIDGE_CHANNEL_STATE_END, AST_CAUSE_NORMAL_CLEARING);

This places the channel pointed to by bridge_channel into the state BRIDGE_CHANNEL_STATE_END if it was BRIDGE_CHANNEL_STATE_WAIT before.

Definition at line 293 of file bridge_channel.c.

References ast_bridge_vars_set(), ast_debug, BRIDGE_CHANNEL_STATE_WAIT, ast_bridge_channel::chan, and ast_bridge_channel::state.

Referenced by ast_bridge_channel_leave_bridge().

294 {
295  if (bridge_channel->state != BRIDGE_CHANNEL_STATE_WAIT) {
296  return;
297  }
298 
299  ast_debug(1, "Setting %p(%s) state from:%u to:%u\n",
300  bridge_channel, ast_channel_name(bridge_channel->chan), bridge_channel->state,
301  new_state);
302 
303  channel_set_cause(bridge_channel->chan, cause);
304 
305  ast_channel_lock(bridge_channel->chan);
306  ast_bridge_vars_set(bridge_channel->chan, NULL, NULL);
307  ast_channel_unlock(bridge_channel->chan);
308 
309  /* Change the state on the bridge channel */
310  bridge_channel->state = new_state;
311 
312  bridge_channel_poke(bridge_channel);
313 }
void ast_bridge_vars_set(struct ast_channel *chan, const char *name, const char *pvtid)
Sets BRIDGECHANNEL and BRIDGEPVTCALLID for a channel.
Definition: bridge.c:1212
enum bridge_channel_state state
#define ast_debug(level,...)
Log a DEBUG message.
struct ast_channel * chan
void ast_bridge_channel_lock_bridge ( struct ast_bridge_channel bridge_channel)

Lock the bridge associated with the bridge channel.

Since
12.0.0
Parameters
bridge_channelChannel that wants to lock the bridge.

This is an upstream lock operation. The defined locking order is bridge then bridge_channel.

Note
On entry, neither the bridge nor bridge_channel is locked.
The bridge_channel->bridge pointer changes because of a bridge-merge/channel-move operation between bridges.

Definition at line 223 of file bridge_channel.c.

References ao2_ref, ast_bridge_channel_lock, ast_bridge_channel_unlock, ast_bridge_lock, ast_bridge_unlock, and ast_bridge_channel::bridge.

Referenced by ast_bridge_channel_feature_digit(), ast_bridge_channel_merge_inhibit(), ast_bridge_notify_masquerade(), and check_binaural_position_change().

224 {
225  struct ast_bridge *bridge;
226 
227  for (;;) {
228  /* Safely get the bridge pointer */
229  ast_bridge_channel_lock(bridge_channel);
230  bridge = bridge_channel->bridge;
231  ao2_ref(bridge, +1);
232  ast_bridge_channel_unlock(bridge_channel);
233 
234  /* Lock the bridge and see if it is still the bridge we need to lock. */
235  ast_bridge_lock(bridge);
236  if (bridge == bridge_channel->bridge) {
237  ao2_ref(bridge, -1);
238  return;
239  }
240  ast_bridge_unlock(bridge);
241  ao2_ref(bridge, -1);
242  }
243 }
struct ast_bridge * bridge
Bridge this channel is participating in.
#define ast_bridge_channel_lock(bridge_channel)
Lock the bridge_channel.
#define ao2_ref(o, delta)
Reference/unreference an object and return the old refcount.
Definition: astobj2.h:459
#define ast_bridge_channel_unlock(bridge_channel)
Unlock the bridge_channel.
Structure that contains information about a bridge.
Definition: bridge.h:349
#define ast_bridge_unlock(bridge)
Unlock the bridge.
Definition: bridge.h:481
#define ast_bridge_lock(bridge)
Lock the bridge.
Definition: bridge.h:470
struct ast_bridge* ast_bridge_channel_merge_inhibit ( struct ast_bridge_channel bridge_channel,
int  request 
)

Adjust the bridge_channel's bridge merge inhibit request count.

Since
12.0.0
Parameters
bridge_channelWhat to operate on.
requestInhibit request increment. (Positive to add requests. Negative to remove requests.)
Note
This API call is meant for internal bridging operations.
Return values
bridgeadjusted merge inhibit with reference count.

Definition at line 370 of file bridge_channel.c.

References ao2_ref, ast_bridge_channel_lock_bridge(), ast_bridge_unlock, and ast_bridge_channel::bridge.

Referenced by feature_attended_transfer().

371 {
372  struct ast_bridge *bridge;
373 
374  ast_bridge_channel_lock_bridge(bridge_channel);
375  bridge = bridge_channel->bridge;
376  ao2_ref(bridge, +1);
377  bridge_merge_inhibit_nolock(bridge, request);
378  ast_bridge_unlock(bridge);
379  return bridge;
380 }
struct ast_bridge * bridge
Bridge this channel is participating in.
#define ao2_ref(o, delta)
Reference/unreference an object and return the old refcount.
Definition: astobj2.h:459
Structure that contains information about a bridge.
Definition: bridge.h:349
#define ast_bridge_unlock(bridge)
Unlock the bridge.
Definition: bridge.h:481
void ast_bridge_channel_lock_bridge(struct ast_bridge_channel *bridge_channel)
Lock the bridge associated with the bridge channel.
int ast_bridge_channel_notify_talking ( 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
bridge_channelThe bridge channel that has either started or stopped talking.
started_talkingset to 1 when this indicates the channel has started talking set to 0 when this indicates the channel has stopped talking.
Return values
0on success.
-1on error.

Definition at line 245 of file bridge_channel.c.

References ast_bridge_channel_queue_frame(), AST_FRAME_BRIDGE_ACTION, BRIDGE_CHANNEL_ACTION_TALKING_START, BRIDGE_CHANNEL_ACTION_TALKING_STOP, and ast_frame::frametype.

246 {
247  struct ast_frame action = {
249  .subclass.integer = started_talking
251  };
252 
253  return ast_bridge_channel_queue_frame(bridge_channel, &action);
254 }
int ast_bridge_channel_queue_frame(struct ast_bridge_channel *bridge_channel, struct ast_frame *fr)
Write a frame to the specified bridge_channel.
Data structure associated with a single frame of data.
enum ast_frame_type frametype
struct ast_bridge_channel* ast_bridge_channel_peer ( struct ast_bridge_channel bridge_channel)

Get the peer bridge channel of a two party bridge.

Since
12.0.0
Parameters
bridge_channelWhat to get the peer of.
Note
On entry, bridge_channel->bridge is already locked.
This is an internal bridge function.
Return values
peeron success.
NULLno peer channel.

Definition at line 322 of file bridge_channel.c.

References AST_LIST_TRAVERSE, ast_bridge_channel::bridge, ast_bridge::channels, ast_bridge_channel::in_bridge, and ast_bridge::num_channels.

323 {
324  struct ast_bridge *bridge = bridge_channel->bridge;
325  struct ast_bridge_channel *other = NULL;
326 
327  if (bridge_channel->in_bridge && bridge->num_channels == 2) {
328  AST_LIST_TRAVERSE(&bridge->channels, other, entry) {
329  if (other != bridge_channel) {
330  break;
331  }
332  }
333  }
334 
335  return other;
336 }
struct ast_bridge * bridge
Bridge this channel is participating in.
Structure that contains information about a bridge.
Definition: bridge.h:349
#define AST_LIST_TRAVERSE(head, var, field)
Loops over (traverses) the entries in a list.
Definition: linkedlists.h:491
unsigned int in_bridge
struct ast_bridge_channels_list channels
Definition: bridge.h:363
Structure that contains information regarding a channel in a bridge.
Definition: search.h:40
unsigned int num_channels
Definition: bridge.h:373
void ast_bridge_channel_playfile ( struct ast_bridge_channel bridge_channel,
ast_bridge_custom_play_fn  custom_play,
const char *  playfile,
const char *  moh_class 
)

Play a file on the bridge channel.

Since
12.0.0
Parameters
bridge_channelWhich channel to play the file on
custom_playCall this function to play the playfile. (NULL if normal sound file to play)
playfileSound filename to play.
moh_classMOH class to request bridge peers to hear while file is played. NULL if no MOH. Empty if default MOH class.
Note
This is intended to be called by bridge hooks.

Definition at line 1262 of file bridge_channel.c.

References ast_bridge_channel_write_hold(), ast_bridge_channel_write_unhold(), AST_DIGIT_NONE, AST_FLAG_MOH, ast_moh_start(), ast_strdupa, ast_stream_and_wait(), and ast_bridge_channel::chan.

1263 {
1264  if (moh_class) {
1265  ast_bridge_channel_write_hold(bridge_channel, moh_class);
1266  }
1267  if (custom_play) {
1268  custom_play(bridge_channel, playfile);
1269  } else {
1270  ast_stream_and_wait(bridge_channel->chan, playfile, AST_DIGIT_NONE);
1271  }
1272  if (moh_class) {
1273  ast_bridge_channel_write_unhold(bridge_channel);
1274  }
1275 
1276  /*
1277  * It may be necessary to resume music on hold after we finish
1278  * playing the announcment.
1279  */
1280  if (ast_test_flag(ast_channel_flags(bridge_channel->chan), AST_FLAG_MOH)) {
1281  const char *latest_musicclass;
1282 
1283  ast_channel_lock(bridge_channel->chan);
1284  latest_musicclass = ast_strdupa(ast_channel_latest_musicclass(bridge_channel->chan));
1285  ast_channel_unlock(bridge_channel->chan);
1286  ast_moh_start(bridge_channel->chan, latest_musicclass, NULL);
1287  }
1288 }
int ast_bridge_channel_write_unhold(struct ast_bridge_channel *bridge_channel)
Write an unhold frame into the bridge.
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition: astmm.h:298
#define AST_DIGIT_NONE
Definition: file.h:47
int ast_moh_start(struct ast_channel *chan, const char *mclass, const char *interpclass)
Turn on music on hold on a given channel.
Definition: channel.c:7766
int ast_stream_and_wait(struct ast_channel *chan, const char *file, const char *digits)
stream file until digit If the file name is non-empty, try to play it.
Definition: file.c:1878
struct ast_channel * chan
int ast_bridge_channel_write_hold(struct ast_bridge_channel *bridge_channel, const char *moh_class)
Write a hold frame into the bridge.
int ast_bridge_channel_queue_app ( struct ast_bridge_channel bridge_channel,
const char *  app_name,
const char *  app_args,
const char *  moh_class 
)

Queue a bridge action run application frame onto the bridge channel.

Since
12.0.0
Parameters
bridge_channelWhich channel to put the frame onto
app_nameDialplan application name.
app_argsArguments for the application. (NULL or empty for no arguments)
moh_classMOH class to request bridge peers to hear while application is running. NULL if no MOH. Empty if default MOH class.
Note
This is intended to be called by bridge hooks.
Return values
0on success.
-1on error.

Definition at line 1256 of file bridge_channel.c.

1257 {
1258  return payload_helper_app(bridge_channel_queue_action_data,
1259  bridge_channel, app_name, app_args, moh_class);
1260 }
const char * app_name(struct ast_app *app)
Definition: pbx_app.c:463
int ast_bridge_channel_queue_callback ( struct ast_bridge_channel bridge_channel,
enum ast_bridge_channel_custom_callback_option  flags,
ast_bridge_custom_callback_fn  callback,
const void *  payload,
size_t  payload_size 
)

Queue a bridge action custom callback frame onto the bridge channel.

Since
12.0.0
Parameters
bridge_channelWhich channel to put the frame onto.
flagsCustom callback option flags.
callbackCustom callback run on a bridge channel.
payloadData to pass to the callback. (NULL if none).
payload_sizeSize of the payload if payload is non-NULL. A number otherwise.
Note
The payload MUST NOT have any resources that need to be freed.
This is intended to be called by bridge hooks.
Return values
0on success.
-1on error.

Definition at line 1429 of file bridge_channel.c.

Referenced by ast_bridge_kick().

1432 {
1433  return payload_helper_cb(bridge_channel_queue_action_data,
1434  bridge_channel, flags, callback, payload, payload_size);
1435 }
int ast_bridge_channel_queue_control_data ( struct ast_bridge_channel bridge_channel,
enum ast_control_frame_type  control,
const void *  data,
size_t  datalen 
)

Queue a control frame onto the bridge channel with data.

Since
12.0.0
Parameters
bridge_channelWhich channel to queue the frame onto.
controlType of control frame.
dataFrame payload data to pass.
datalenFrame payload data length to pass.
Return values
0on success.
-1on error.

Definition at line 1104 of file bridge_channel.c.

References ast_bridge_channel_queue_frame(), AST_FRAME_CONTROL, ast_frame::datalen, and ast_frame::frametype.

1105 {
1106  struct ast_frame frame = {
1108  .subclass.integer = control,
1109  .datalen = datalen,
1110  .data.ptr = (void *) data,
1111  };
1112 
1113  return ast_bridge_channel_queue_frame(bridge_channel, &frame);
1114 }
int ast_bridge_channel_queue_frame(struct ast_bridge_channel *bridge_channel, struct ast_frame *fr)
Write a frame to the specified bridge_channel.
union ast_frame::@224 data
Data structure associated with a single frame of data.
enum ast_frame_type frametype
int ast_bridge_channel_queue_frame ( struct ast_bridge_channel bridge_channel,
struct ast_frame fr 
)

Write a frame to the specified bridge_channel.

Since
12.0.0
Parameters
bridge_channelChannel to queue the frame.
frFrame to write.
Return values
0on success.
-1on error.

Definition at line 1005 of file bridge_channel.c.

References ast_bridge_channel::alert_pipe, ast_alertpipe_write(), ast_bridge_channel_lock, ast_bridge_channel_unlock, AST_FRAME_DTMF_BEGIN, AST_FRAME_DTMF_END, AST_FRAME_IMAGE, AST_FRAME_NULL, AST_FRAME_RTCP, AST_FRAME_TEXT, AST_FRAME_TEXT_DATA, AST_FRAME_VIDEO, AST_FRAME_VOICE, ast_frdup, ast_is_deferrable_frame(), AST_LIST_INSERT_TAIL, ast_msg_data_get_attribute(), AST_VECTOR_GET, AST_VECTOR_SIZE, BRIDGE_CHANNEL_STATE_WAIT, ast_bridge_channel::chan, ast_frame::data, ast_frame::datalen, ast_bridge_channel::features, ast_frame::frametype, ast_bridge_channel::state, ast_frame::stream_num, ast_bridge_channel::suspended, ast_bridge_features::text_messaging, ast_bridge_channel::to_channel, and ast_bridge_channel::wr_queue.

Referenced by ast_bridge_channel_notify_talking(), ast_bridge_channel_queue_control_data(), ast_bridge_queue_everyone_else(), and softmix_mixing_loop().

1006 {
1007  struct ast_frame *dup;
1008 
1009  if (bridge_channel->suspended
1010  /* Also defer DTMF frames. */
1012  && fr->frametype != AST_FRAME_DTMF_END
1013  && !ast_is_deferrable_frame(fr)) {
1014  /* Drop non-deferable frames when suspended. */
1015  return 0;
1016  }
1017  if (fr->frametype == AST_FRAME_NULL) {
1018  /* "Accept" the frame and discard it. */
1019  return 0;
1020  }
1021 
1022  if ((fr->frametype == AST_FRAME_VOICE || fr->frametype == AST_FRAME_VIDEO ||
1024  fr->frametype == AST_FRAME_RTCP) && fr->stream_num > -1) {
1025  int num = -1;
1026 
1027  ast_bridge_channel_lock(bridge_channel);
1028  if (fr->stream_num < (int)AST_VECTOR_SIZE(&bridge_channel->stream_map.to_channel)) {
1029  num = AST_VECTOR_GET(&bridge_channel->stream_map.to_channel, fr->stream_num);
1030  }
1031  ast_bridge_channel_unlock(bridge_channel);
1032 
1033  if (num == -1) {
1034  /* We don't have a mapped stream so just discard this frame. */
1035  return 0;
1036  }
1037  }
1038 
1039  dup = ast_frdup(fr);
1040  if (!dup) {
1041  return -1;
1042  }
1043 
1044  ast_bridge_channel_lock(bridge_channel);
1045  if (bridge_channel->state != BRIDGE_CHANNEL_STATE_WAIT) {
1046  /* Drop frames on channels leaving the bridge. */
1047  ast_bridge_channel_unlock(bridge_channel);
1048  bridge_frame_free(dup);
1049  return 0;
1050  }
1051 
1052  if ((fr->frametype == AST_FRAME_TEXT || fr->frametype == AST_FRAME_TEXT_DATA) &&
1053  !bridge_channel->features->text_messaging) {
1054  /* This channel is not accepting text messages. */
1055  ast_bridge_channel_unlock(bridge_channel);
1056  bridge_frame_free(dup);
1057  return 0;
1058  }
1059 
1060  if (DEBUG_ATLEAST(1)) {
1061  if (fr->frametype == AST_FRAME_TEXT) {
1062  ast_log(LOG_DEBUG, "Queuing TEXT frame to '%s': %*.s\n", ast_channel_name(bridge_channel->chan),
1063  fr->datalen, (char *)fr->data.ptr);
1064  } else if (fr->frametype == AST_FRAME_TEXT_DATA) {
1065  struct ast_msg_data *msg = fr->data.ptr;
1066  ast_log(LOG_DEBUG, "Queueing TEXT_DATA frame from '%s' to '%s:%s': %s\n",
1067  ast_msg_data_get_attribute(msg, AST_MSG_DATA_ATTR_FROM),
1068  ast_msg_data_get_attribute(msg, AST_MSG_DATA_ATTR_TO),
1069  ast_channel_name(bridge_channel->chan),
1070  ast_msg_data_get_attribute(msg, AST_MSG_DATA_ATTR_BODY));
1071  }
1072  }
1073 
1074  AST_LIST_INSERT_TAIL(&bridge_channel->wr_queue, dup, frame_list);
1075  if (ast_alertpipe_write(bridge_channel->alert_pipe)) {
1076  ast_log(LOG_ERROR, "We couldn't write alert pipe for %p(%s)... something is VERY wrong\n",
1077  bridge_channel, ast_channel_name(bridge_channel->chan));
1078  }
1079  ast_bridge_channel_unlock(bridge_channel);
1080  return 0;
1081 }
#define ast_frdup(fr)
Copies a frame.
struct ast_bridge_features * features
enum bridge_channel_state state
unsigned int suspended
Structure used to transport a message through the frame core.
unsigned int text_messaging
#define ast_bridge_channel_lock(bridge_channel)
Lock the bridge_channel.
struct ast_bridge_channel::@190 wr_queue
#define ast_bridge_channel_unlock(bridge_channel)
Unlock the bridge_channel.
struct ast_vector_int to_channel
#define AST_LIST_INSERT_TAIL(head, elm, field)
Appends a list entry to the tail of a list.
Definition: linkedlists.h:731
const char * ast_msg_data_get_attribute(struct ast_msg_data *msg, enum ast_msg_data_attribute_type attribute_type)
Get attribute from ast_msg_data.
union ast_frame::@224 data
#define AST_VECTOR_GET(vec, idx)
Get an element from a vector.
Definition: vector.h:680
struct ast_channel * chan
ssize_t ast_alertpipe_write(int alert_pipe[2])
Write an event to an alert pipe.
Definition: alertpipe.c:120
int ast_is_deferrable_frame(const struct ast_frame *frame)
Should we keep this frame for later?
Definition: channel.c:1467
Data structure associated with a single frame of data.
enum ast_frame_type frametype
#define AST_VECTOR_SIZE(vec)
Get the number of elements in a vector.
Definition: vector.h:609
int ast_bridge_channel_queue_playfile ( struct ast_bridge_channel bridge_channel,
ast_bridge_custom_play_fn  custom_play,
const char *  playfile,
const char *  moh_class 
)

Queue a bridge action play file frame onto the bridge channel.

Since
12.0.0
Parameters
bridge_channelWhich channel to put the frame onto.
custom_playCall this function to play the playfile. (NULL if normal sound file to play)
playfileSound filename to play.
moh_classMOH class to request bridge peers to hear while file is played. NULL if no MOH. Empty if default MOH class.
Note
This is intended to be called by bridge hooks.
Return values
0on success.
-1on error.

Definition at line 1343 of file bridge_channel.c.

Referenced by ast_bridge_add_channel(), and play_sound().

1344 {
1345  return payload_helper_playfile(bridge_channel_queue_action_data,
1346  bridge_channel, custom_play, playfile, moh_class);
1347 }
int ast_bridge_channel_queue_playfile_sync ( struct ast_bridge_channel bridge_channel,
ast_bridge_custom_play_fn  custom_play,
const char *  playfile,
const char *  moh_class 
)

Synchronously queue a bridge action play file frame onto the bridge channel.

Since
12.2.0
Parameters
bridge_channelWhich channel to put the frame onto.
custom_playCall this function to play the playfile. (NULL if normal sound file to play)
playfileSound filename to play.
moh_classMOH class to request bridge peers to hear while file is played. NULL if no MOH. Empty if default MOH class.

This function will block until the queued frame has been destroyed. This will happen either if an error occurs or if the queued playback finishes.

Note
No locks may be held when calling this function.
Return values
0The playback was successfully queued.
-1The playback could not be queued.

Definition at line 1349 of file bridge_channel.c.

1351 {
1352  return payload_helper_playfile(bridge_channel_queue_action_data_sync,
1353  bridge_channel, custom_play, playfile, moh_class);
1354 }
void ast_bridge_channel_restore_formats ( struct ast_bridge_channel bridge_channel)

Restore the formats of a bridge channel's channel to how they were before bridge_channel_internal_join.

Since
12.0.0
Parameters
bridge_channelChannel to restore

Definition at line 338 of file bridge_channel.c.

References ast_debug, ast_format_cmp(), AST_FORMAT_CMP_NOT_EQUAL, ast_format_get_name(), ast_set_read_format(), ast_set_write_format(), ast_bridge_channel::chan, ast_bridge_channel::read_format, and ast_bridge_channel::write_format.

339 {
340  ast_assert(bridge_channel->read_format != NULL);
341  ast_assert(bridge_channel->write_format != NULL);
342 
343  ast_channel_lock(bridge_channel->chan);
344 
345  /* Restore original formats of the channel as they came in */
346  if (ast_format_cmp(ast_channel_readformat(bridge_channel->chan), bridge_channel->read_format) == AST_FORMAT_CMP_NOT_EQUAL) {
347  ast_debug(1, "Bridge is returning %p(%s) to read format %s\n",
348  bridge_channel, ast_channel_name(bridge_channel->chan),
349  ast_format_get_name(bridge_channel->read_format));
350  if (ast_set_read_format(bridge_channel->chan, bridge_channel->read_format)) {
351  ast_debug(1, "Bridge failed to return %p(%s) to read format %s\n",
352  bridge_channel, ast_channel_name(bridge_channel->chan),
353  ast_format_get_name(bridge_channel->read_format));
354  }
355  }
356  if (ast_format_cmp(ast_channel_writeformat(bridge_channel->chan), bridge_channel->write_format) == AST_FORMAT_CMP_NOT_EQUAL) {
357  ast_debug(1, "Bridge is returning %p(%s) to write format %s\n",
358  bridge_channel, ast_channel_name(bridge_channel->chan),
359  ast_format_get_name(bridge_channel->write_format));
360  if (ast_set_write_format(bridge_channel->chan, bridge_channel->write_format)) {
361  ast_debug(1, "Bridge failed to return %p(%s) to write format %s\n",
362  bridge_channel, ast_channel_name(bridge_channel->chan),
363  ast_format_get_name(bridge_channel->write_format));
364  }
365  }
366 
367  ast_channel_unlock(bridge_channel->chan);
368 }
const char * ast_format_get_name(const struct ast_format *format)
Get the name associated with a format.
Definition: format.c:334
enum ast_format_cmp_res ast_format_cmp(const struct ast_format *format1, const struct ast_format *format2)
Compare two formats.
Definition: format.c:201
int ast_set_read_format(struct ast_channel *chan, struct ast_format *format)
Sets read format on channel chan.
Definition: channel.c:5762
#define ast_debug(level,...)
Log a DEBUG message.
int ast_set_write_format(struct ast_channel *chan, struct ast_format *format)
Sets write format on channel chan.
Definition: channel.c:5803
struct ast_format * write_format
struct ast_format * read_format
struct ast_channel * chan
void ast_bridge_channel_run_app ( struct ast_bridge_channel bridge_channel,
const char *  app_name,
const char *  app_args,
const char *  moh_class 
)

Run an application on the bridge channel.

Since
12.0.0
Parameters
bridge_channelWhich channel to run the application on.
app_nameDialplan application name.
app_argsArguments for the application. (NULL tolerant)
moh_classMOH class to request bridge peers to hear while application is running. NULL if no MOH. Empty if default MOH class.
Note
This is intended to be called by bridge hooks.

Definition at line 1184 of file bridge_channel.c.

References ast_bridge_channel_kick(), ast_bridge_channel_write_hold(), ast_bridge_channel_write_unhold(), ast_bridge_channel::chan, and S_OR.

1185 {
1186  if (moh_class) {
1187  ast_bridge_channel_write_hold(bridge_channel, moh_class);
1188  }
1189  if (run_app_helper(bridge_channel->chan, app_name, S_OR(app_args, ""))) {
1190  /* Break the bridge if the app returns non-zero. */
1191  ast_bridge_channel_kick(bridge_channel, AST_CAUSE_NORMAL_CLEARING);
1192  }
1193  if (moh_class) {
1194  ast_bridge_channel_write_unhold(bridge_channel);
1195  }
1196 }
int ast_bridge_channel_write_unhold(struct ast_bridge_channel *bridge_channel)
Write an unhold frame into the bridge.
void ast_bridge_channel_kick(struct ast_bridge_channel *bridge_channel, int cause)
Kick the channel out of the bridge.
const char * app_name(struct ast_app *app)
Definition: pbx_app.c:463
struct ast_channel * chan
#define S_OR(a, b)
returns the equivalent of logic or for strings: first one if not empty, otherwise second one...
Definition: strings.h:80
int ast_bridge_channel_write_hold(struct ast_bridge_channel *bridge_channel, const char *moh_class)
Write a hold frame into the bridge.
void ast_bridge_channel_stream_map ( struct ast_bridge_channel bridge_channel)

Maps a channel's stream topology to and from the bridge.

Since
15.0.0

When a channel joins a bridge or its associated stream topology is updated, each stream in the topology needs to be mapped according to its media type to the bridge. Calling this method creates a mapping of each stream on the channel indexed to the bridge's supported media types and vice versa (i.e. bridge's media types indexed to channel streams).

The first channel to join the bridge creates the initial order for the bridge's media types (e.g. a one to one mapping is made). Subsequently added channels are mapped to that order adding more media types if/when the newly added channel has more streams and/or media types specified by the bridge.

Parameters
bridge_channelChannel to map
Note
The bridge_channel's bridge must be locked prior to calling this function.

Definition at line 3119 of file bridge_channel.c.

References ast_bridge_channel_lock, ast_bridge_channel_unlock, ast_channel_get_stream_topology(), ast_stream_topology_map(), ast_bridge_channel::bridge, ast_bridge_channel::chan, ast_bridge::media_types, ast_bridge_channel::to_bridge, and ast_bridge_channel::to_channel.

Referenced by softmix_bridge_stream_topology_changed().

3120 {
3121  ast_bridge_channel_lock(bridge_channel);
3122  ast_channel_lock(bridge_channel->chan);
3124  &bridge_channel->bridge->media_types, &bridge_channel->stream_map.to_bridge,
3125  &bridge_channel->stream_map.to_channel);
3126  ast_channel_unlock(bridge_channel->chan);
3127  ast_bridge_channel_unlock(bridge_channel);
3128 }
struct ast_stream_topology * ast_channel_get_stream_topology(const struct ast_channel *chan)
Retrieve the topology of streams on a channel.
struct ast_vector_int to_bridge
struct ast_bridge * bridge
Bridge this channel is participating in.
#define ast_bridge_channel_lock(bridge_channel)
Lock the bridge_channel.
#define ast_bridge_channel_unlock(bridge_channel)
Unlock the bridge_channel.
struct ast_vector_int to_channel
struct ast_channel * chan
struct ast_vector_int media_types
Definition: bridge.h:404
void ast_stream_topology_map(const struct ast_stream_topology *topology, struct ast_vector_int *types, struct ast_vector_int *v0, struct ast_vector_int *v1)
Map a given topology's streams to the given types.
Definition: stream.c:985
int ast_bridge_channel_write_app ( struct ast_bridge_channel bridge_channel,
const char *  app_name,
const char *  app_args,
const char *  moh_class 
)

Write a bridge action run application frame into the bridge.

Since
12.0.0
Parameters
bridge_channelWhich channel is putting the frame into the bridge
app_nameDialplan application name.
app_argsArguments for the application. (NULL or empty for no arguments)
moh_classMOH class to request bridge peers to hear while application is running. NULL if no MOH. Empty if default MOH class.
Note
This is intended to be called by bridge hooks.
Return values
0on success.
-1on error.

Definition at line 1250 of file bridge_channel.c.

1251 {
1252  return payload_helper_app(bridge_channel_write_action_data,
1253  bridge_channel, app_name, app_args, moh_class);
1254 }
const char * app_name(struct ast_app *app)
Definition: pbx_app.c:463
int ast_bridge_channel_write_callback ( struct ast_bridge_channel bridge_channel,
enum ast_bridge_channel_custom_callback_option  flags,
ast_bridge_custom_callback_fn  callback,
const void *  payload,
size_t  payload_size 
)

Write a bridge action custom callback frame into the bridge.

Since
12.0.0
Parameters
bridge_channelWhich channel is putting the frame into the bridge
flagsCustom callback option flags.
callbackCustom callback run on a bridge channel.
payloadData to pass to the callback. (NULL if none).
payload_sizeSize of the payload if payload is non-NULL. A number otherwise.
Note
The payload MUST NOT have any resources that need to be freed.
This is intended to be called by bridge hooks.
Return values
0on success.
-1on error.

Definition at line 1421 of file bridge_channel.c.

1424 {
1425  return payload_helper_cb(bridge_channel_write_action_data,
1426  bridge_channel, flags, callback, payload, payload_size);
1427 }
int ast_bridge_channel_write_control_data ( struct ast_bridge_channel bridge_channel,
enum ast_control_frame_type  control,
const void *  data,
size_t  datalen 
)

Write a control frame into the bridge with data.

Since
12.0.0
Parameters
bridge_channelWhich channel is putting the frame into the bridge.
controlType of control frame.
dataFrame payload data to pass.
datalenFrame payload data length to pass.
Return values
0on success.
-1on error.

Definition at line 1116 of file bridge_channel.c.

References AST_FRAME_CONTROL, ast_frame::datalen, and ast_frame::frametype.

Referenced by ast_bridge_channel_write_hold(), ast_bridge_channel_write_unhold(), and ringing().

1117 {
1118  struct ast_frame frame = {
1120  .subclass.integer = control,
1121  .datalen = datalen,
1122  .data.ptr = (void *) data,
1123  };
1124 
1125  return bridge_channel_write_frame(bridge_channel, &frame);
1126 }
union ast_frame::@224 data
Data structure associated with a single frame of data.
enum ast_frame_type frametype
int ast_bridge_channel_write_hold ( struct ast_bridge_channel bridge_channel,
const char *  moh_class 
)

Write a hold frame into the bridge.

Since
12.0.0
Parameters
bridge_channelWhich channel is putting the hold into the bridge.
moh_classThe suggested music class for the other end to use.
Return values
0on success.
-1on error.

Definition at line 1128 of file bridge_channel.c.

References ast_bridge_channel_write_control_data(), ast_channel_hold_type(), ast_channel_publish_cached_blob(), AST_CONTROL_HOLD, ast_json_pack(), ast_json_unref(), and ast_bridge_channel::chan.

Referenced by ast_bridge_channel_playfile(), ast_bridge_channel_run_app(), feature_attended_transfer(), feature_blind_transfer(), and hold().

1129 {
1130  struct ast_json *blob;
1131  int res;
1132  size_t datalen;
1133 
1134  if (!ast_strlen_zero(moh_class)) {
1135  datalen = strlen(moh_class) + 1;
1136 
1137  blob = ast_json_pack("{s: s}",
1138  "musicclass", moh_class);
1139  } else {
1140  moh_class = NULL;
1141  datalen = 0;
1142  blob = NULL;
1143  }
1144 
1146 
1148  moh_class, datalen);
1149 
1150  ast_json_unref(blob);
1151  return res;
1152 }
struct stasis_message_type * ast_channel_hold_type(void)
Message type for when a channel is placed on hold.
struct ast_json * ast_json_pack(char const *format,...)
Helper for creating complex JSON values.
Definition: json.c:612
void ast_json_unref(struct ast_json *value)
Decrease refcount on value. If refcount reaches zero, value is freed.
Definition: json.c:73
void ast_channel_publish_cached_blob(struct ast_channel *chan, struct stasis_message_type *type, struct ast_json *blob)
Publish a channel blob message using the latest snapshot from the cache.
int ast_bridge_channel_write_control_data(struct ast_bridge_channel *bridge_channel, enum ast_control_frame_type control, const void *data, size_t datalen)
Write a control frame into the bridge with data.
struct ast_channel * chan
Abstract JSON element (object, array, string, int, ...).
int ast_bridge_channel_write_park ( struct ast_bridge_channel bridge_channel,
const char *  parkee_uuid,
const char *  parker_uuid,
const char *  app_data 
)

Have a bridge channel park a channel in the bridge.

Since
12.0.0
Parameters
bridge_channelBridge channel performing the parking
parkee_uuidUnique id of the channel we want to park
parker_uuidUnique id of the channel parking the call
app_datastring indicating data used for park application (NULL allowed)
Note
This is intended to be called by bridge hooks.
Return values
0on success.
-1on error.

Definition at line 1492 of file bridge_channel.c.

1493 {
1494  return payload_helper_park(bridge_channel_write_action_data,
1495  bridge_channel, parkee_uuid, parker_uuid, app_data);
1496 }
int ast_bridge_channel_write_playfile ( struct ast_bridge_channel bridge_channel,
ast_bridge_custom_play_fn  custom_play,
const char *  playfile,
const char *  moh_class 
)

Write a bridge action play file frame into the bridge.

Since
12.0.0
Parameters
bridge_channelWhich channel is putting the frame into the bridge
custom_playCall this function to play the playfile. (NULL if normal sound file to play)
playfileSound filename to play.
moh_classMOH class to request bridge peers to hear while file is played. NULL if no MOH. Empty if default MOH class.
Note
This is intended to be called by bridge hooks.
Return values
0on success.
-1on error.

Definition at line 1337 of file bridge_channel.c.

Referenced by ast_bridge_transfer_attended().

1338 {
1339  return payload_helper_playfile(bridge_channel_write_action_data,
1340  bridge_channel, custom_play, playfile, moh_class);
1341 }
int ast_bridge_channel_write_unhold ( struct ast_bridge_channel bridge_channel)

Write an unhold frame into the bridge.

Since
12.0.0
Parameters
bridge_channelWhich channel is putting the hold into the bridge.
Return values
0on success.
-1on error.

Definition at line 1154 of file bridge_channel.c.

References ao2_ref, ast_bridge_channel_get_chan(), ast_bridge_channel_write_control_data(), ast_channel_publish_cached_blob(), ast_channel_unhold_type(), and AST_CONTROL_UNHOLD.

Referenced by ast_bridge_channel_playfile(), ast_bridge_channel_run_app(), ast_bridge_transfer_attended(), ast_bridge_transfer_blind(), feature_attended_transfer(), feature_blind_transfer(), and unhold().

1155 {
1156  struct ast_channel *chan = ast_bridge_channel_get_chan(bridge_channel);
1157 
1158  if (!chan) {
1159  return -1;
1160  }
1161 
1163  ao2_ref(chan, -1);
1164 
1165  return ast_bridge_channel_write_control_data(bridge_channel, AST_CONTROL_UNHOLD, NULL, 0);
1166 }
Main Channel structure associated with a channel.
struct stasis_message_type * ast_channel_unhold_type(void)
Message type for when a channel is removed from hold.
void ast_channel_publish_cached_blob(struct ast_channel *chan, struct stasis_message_type *type, struct ast_json *blob)
Publish a channel blob message using the latest snapshot from the cache.
struct ast_channel * ast_bridge_channel_get_chan(struct ast_bridge_channel *bridge_channel)
Get a ref to the bridge_channel's ast_channel.
int ast_bridge_channel_write_control_data(struct ast_bridge_channel *bridge_channel, enum ast_control_frame_type control, const void *data, size_t datalen)
Write a control frame into the bridge with data.
#define ao2_ref(o, delta)
Reference/unreference an object and return the old refcount.
Definition: astobj2.h:459