summaryrefslogtreecommitdiff
path: root/main/bridge.c
diff options
context:
space:
mode:
authorKinsey Moore <kmoore@digium.com>2014-06-26 12:43:47 +0000
committerKinsey Moore <kmoore@digium.com>2014-06-26 12:43:47 +0000
commite977b7936b02bcd33a35bf7c4e5b51f496f727e5 (patch)
tree02c6fd7d4127021f3e20f783e350da4d78123bbd /main/bridge.c
parent22e62ac6f640f6442968e5ab9146d3a7fe496f95 (diff)
Bridging: Allow channels to define bridging hooks
This patch allows the current owner of a channel to define various feature hooks to be made available once the channel has entered a bridge. This includes any hooks that are setup on the ast_bridge_features struct such as DTMF hooks, bridge event hooks (join, leave, etc.), and interval hooks. Review: https://reviewboard.asterisk.org/r/3649/ git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@417361 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'main/bridge.c')
-rw-r--r--main/bridge.c58
1 files changed, 58 insertions, 0 deletions
diff --git a/main/bridge.c b/main/bridge.c
index 35287e278..41053eb8a 100644
--- a/main/bridge.c
+++ b/main/bridge.c
@@ -3327,6 +3327,64 @@ static int bridge_dtmf_hook_sort(const void *obj_left, const void *obj_right, in
return cmp;
}
+/*! \brief Callback for merging hook ao2_containers */
+static int merge_container_cb(void *obj, void *data, int flags)
+{
+ ao2_link(data, obj);
+ return 0;
+}
+
+/*! \brief Wrapper for interval hooks that calls into the wrapped hook */
+static int interval_wrapper_cb(struct ast_bridge_channel *bridge_channel, void *obj)
+{
+ struct ast_bridge_hook_timer *hook = obj;
+
+ return hook->generic.callback(bridge_channel, hook->generic.hook_pvt);
+}
+
+/*! \brief Destructor for the hook wrapper */
+static void interval_wrapper_pvt_dtor(void *obj)
+{
+ ao2_cleanup(obj);
+}
+
+/*! \brief Wrap the provided interval hook and add it to features */
+static void wrap_hook(struct ast_bridge_features *features, struct ast_bridge_hook_timer *hook)
+{
+ /* Break out of the current wrapper if it exists to avoid multiple layers */
+ if (hook->generic.callback == interval_wrapper_cb) {
+ hook = hook->generic.hook_pvt;
+ }
+
+ ast_bridge_interval_hook(features, hook->timer.flags, hook->timer.interval,
+ interval_wrapper_cb, ao2_bump(hook), interval_wrapper_pvt_dtor,
+ hook->generic.remove_flags.flags);
+}
+
+void ast_bridge_features_merge(struct ast_bridge_features *into, const struct ast_bridge_features *from)
+{
+ struct ast_bridge_hook_timer *hook;
+ int idx;
+
+ /* Merge hook containers */
+ ao2_callback(from->dtmf_hooks, 0, merge_container_cb, into->dtmf_hooks);
+ ao2_callback(from->other_hooks, 0, merge_container_cb, into->other_hooks);
+
+ /* Merge hook heaps */
+ ast_heap_wrlock(from->interval_hooks);
+ for (idx = 1; (hook = ast_heap_peek(from->interval_hooks, idx)); idx++) {
+ wrap_hook(into, hook);
+ }
+ ast_heap_unlock(from->interval_hooks);
+
+ /* Merge feature flags */
+ into->feature_flags.flags |= from->feature_flags.flags;
+ into->usable |= from->usable;
+
+ into->mute |= from->mute;
+ into->dtmf_passthrough |= from->dtmf_passthrough;
+}
+
/* XXX ASTERISK-21271 make ast_bridge_features_init() static when make ast_bridge_join() requires features to be allocated. */
int ast_bridge_features_init(struct ast_bridge_features *features)
{