Asterisk - The Open Source Telephony Project GIT-master-7e7a603
conf_chan_announce.c
Go to the documentation of this file.
1/*
2 * Asterisk -- An open source telephony toolkit.
3 *
4 * Copyright (C) 2013 Digium, Inc.
5 *
6 * Richard Mudgett <rmudgett@digium.com>
7 *
8 * See http://www.asterisk.org for more information about
9 * the Asterisk project. Please do not directly contact
10 * any of the maintainers of this project for assistance;
11 * the project provides a web site, mailing lists and IRC
12 * channels for your use.
13 *
14 * This program is free software, distributed under the terms of
15 * the GNU General Public License Version 2. See the LICENSE file
16 * at the top of the source tree.
17 */
18
19/*!
20 * \file
21 * \brief ConfBridge announcer channel driver
22 *
23 * \author Richard Mudgett <rmudgett@digium.com>
24 *
25 * See Also:
26 * \arg \ref AstCREDITS
27 */
28
29
30#include "asterisk.h"
31
32#include "asterisk/channel.h"
33#include "asterisk/bridge.h"
35#include "include/confbridge.h"
36
37/* ------------------------------------------------------------------- */
38
39/*! ConfBridge announcer channel private. */
41 /*! Unreal channel driver base class values. */
43 /*! Conference bridge associated with this announcer. */
45};
46
47static int announce_call(struct ast_channel *chan, const char *addr, int timeout)
48{
49 /* Make sure anyone calling ast_call() for this channel driver is going to fail. */
50 return -1;
51}
52
53static int announce_hangup(struct ast_channel *ast)
54{
55 struct announce_pvt *p = ast_channel_tech_pvt(ast);
56 int res;
57
58 if (!p) {
59 return -1;
60 }
61
62 /* give the pvt a ref to fulfill calling requirements. */
63 ao2_ref(p, +1);
64 res = ast_unreal_hangup(&p->base, ast);
65 ao2_ref(p, -1);
66
67 return res;
68}
69
70static void announce_pvt_destructor(void *vdoomed)
71{
72 struct announce_pvt *doomed = vdoomed;
73
74 ao2_cleanup(doomed->bridge);
75 doomed->bridge = NULL;
77}
78
79static struct ast_channel *announce_request(const char *type, struct ast_format_cap *cap, const struct ast_assigned_ids *assignedids, const struct ast_channel *requestor, const char *data, int *cause)
80{
81 struct ast_channel *chan;
82 const char *conf_name = data;
83 RAII_VAR(struct confbridge_conference *, conference, NULL, ao2_cleanup);
84 RAII_VAR(struct announce_pvt *, pvt, NULL, ao2_cleanup);
85
86 conference = ao2_find(conference_bridges, conf_name, OBJ_KEY);
87 if (!conference) {
88 return NULL;
89 }
90 ast_assert(conference->bridge != NULL);
91
92 /* Allocate a new private structure and then Asterisk channels */
93 pvt = (struct announce_pvt *) ast_unreal_alloc(sizeof(*pvt), announce_pvt_destructor,
94 cap);
95 if (!pvt) {
96 return NULL;
97 }
99 ast_copy_string(pvt->base.name, conf_name, sizeof(pvt->base.name));
100 pvt->bridge = conference->bridge;
101 ao2_ref(pvt->bridge, +1);
102
104 AST_STATE_UP, AST_STATE_UP, NULL, NULL, assignedids, requestor, 0);
105 if (chan) {
106 ast_answer(pvt->base.owner);
107 ast_answer(pvt->base.chan);
108 if (ast_channel_add_bridge_role(pvt->base.chan, "announcer")) {
109 ast_hangup(chan);
110 chan = NULL;
111 }
112 }
113
114 return chan;
115}
116
118 .type = "CBAnn",
119 .description = "Conference Bridge Announcing Channel",
120 .requester = announce_request,
121 .call = announce_call,
122 .hangup = announce_hangup,
123
124 .send_digit_begin = ast_unreal_digit_begin,
125 .send_digit_end = ast_unreal_digit_end,
126 .read = ast_unreal_read,
127 .write = ast_unreal_write,
128 .write_video = ast_unreal_write,
129 .exception = ast_unreal_read,
130 .indicate = ast_unreal_indicate,
131 .fixup = ast_unreal_fixup,
132 .send_html = ast_unreal_sendhtml,
133 .send_text = ast_unreal_sendtext,
134 .queryoption = ast_unreal_queryoption,
135 .setoption = ast_unreal_setoption,
136 .properties = AST_CHAN_TP_INTERNAL,
137};
138
140{
141 return &announce_tech;
142}
143
145{
146 struct ast_bridge_features *features;
147 struct ast_channel *chan;
148 RAII_VAR(struct announce_pvt *, p, NULL, ao2_cleanup);
149
150 {
152
153 p = ast_channel_tech_pvt(ast);
154 if (!p) {
155 return -1;
156 }
157 ao2_ref(p, +1);
158 chan = p->base.chan;
159 if (!chan) {
160 return -1;
161 }
162 }
163
164 features = ast_bridge_features_new();
165 if (!features) {
166 return -1;
167 }
169
170 /* Impart the output channel into the bridge */
171 if (ast_bridge_impart(p->bridge, chan, NULL, features,
173 return -1;
174 }
175 ao2_lock(p);
177 ao2_unlock(p);
178 return 0;
179}
struct ao2_container * conference_bridges
Container to hold all conference bridges in progress.
ast_mutex_t lock
Definition: app_sla.c:331
Asterisk main include file. File version handling, generic pbx functions.
#define OBJ_KEY
Definition: astobj2.h:1151
#define ao2_cleanup(obj)
Definition: astobj2.h:1934
#define ao2_find(container, arg, flags)
Definition: astobj2.h:1736
#define ao2_unlock(a)
Definition: astobj2.h:729
#define ao2_lock(a)
Definition: astobj2.h:717
#define ao2_ref(o, delta)
Reference/unreference an object and return the old refcount.
Definition: astobj2.h:459
Bridging API.
int ast_bridge_impart(struct ast_bridge *bridge, struct ast_channel *chan, struct ast_channel *swap, struct ast_bridge_features *features, enum ast_bridge_impart_flags flags) attribute_warn_unused_result
Impart a channel to a bridge (non-blocking)
Definition: bridge.c:1878
@ AST_BRIDGE_IMPART_CHAN_INDEPENDENT
Definition: bridge.h:590
struct ast_bridge_features * ast_bridge_features_new(void)
Allocate a new bridge features struct.
Definition: bridge.c:3683
@ AST_BRIDGE_CHANNEL_FLAG_IMMOVABLE
int ast_channel_add_bridge_role(struct ast_channel *chan, const char *role_name)
Adds a bridge role to a channel.
Definition: bridge_roles.c:313
static const char type[]
Definition: chan_ooh323.c:109
General Asterisk PBX channel definitions.
@ AST_CHAN_TP_INTERNAL
Channels with this particular technology are an implementation detail of Asterisk and should generall...
Definition: channel.h:971
void * ast_channel_tech_pvt(const struct ast_channel *chan)
void ast_hangup(struct ast_channel *chan)
Hang up a channel.
Definition: channel.c:2541
int ast_answer(struct ast_channel *chan)
Answer a channel.
Definition: channel.c:2805
@ AST_STATE_UP
Definition: channelstate.h:42
struct ast_channel_tech * conf_announce_get_tech(void)
Get ConfBridge announce channel technology struct.
static int announce_hangup(struct ast_channel *ast)
static int announce_call(struct ast_channel *chan, const char *addr, int timeout)
static struct ast_channel_tech announce_tech
static struct ast_channel * announce_request(const char *type, struct ast_format_cap *cap, const struct ast_assigned_ids *assignedids, const struct ast_channel *requestor, const char *data, int *cause)
static void announce_pvt_destructor(void *vdoomed)
int conf_announce_channel_push(struct ast_channel *ast)
Push the announcer channel into the conference.
Unreal channel derivative framework.
int ast_unreal_digit_end(struct ast_channel *ast, char digit, unsigned int duration)
Definition: core_unreal.c:801
int ast_unreal_setoption(struct ast_channel *chan, int option, void *data, int datalen)
Definition: core_unreal.c:97
int ast_unreal_queryoption(struct ast_channel *ast, int option, void *data, int *datalen)
Definition: core_unreal.c:166
int ast_unreal_fixup(struct ast_channel *oldchan, struct ast_channel *newchan)
Definition: core_unreal.c:369
#define AST_UNREAL_NO_OPTIMIZATION
Definition: core_unreal.h:108
int ast_unreal_digit_begin(struct ast_channel *ast, char digit)
Definition: core_unreal.c:779
int ast_unreal_sendhtml(struct ast_channel *ast, int subclass, const char *data, int datalen)
Definition: core_unreal.c:846
void ast_unreal_destructor(void *vdoomed)
struct ast_unreal_pvt destructor.
Definition: core_unreal.c:1097
int ast_unreal_hangup(struct ast_unreal_pvt *p, struct ast_channel *ast)
Hangup one end (maybe both ends) of an unreal channel derivative.
Definition: core_unreal.c:1018
int ast_unreal_write(struct ast_channel *ast, struct ast_frame *f)
Definition: core_unreal.c:318
struct ast_unreal_pvt * ast_unreal_alloc(size_t size, ao2_destructor_fn destructor, struct ast_format_cap *cap)
Allocate the base unreal struct for a derivative.
Definition: core_unreal.c:1109
int ast_unreal_indicate(struct ast_channel *ast, int condition, const void *data, size_t datalen)
Definition: core_unreal.c:622
int ast_unreal_sendtext(struct ast_channel *ast, const char *text)
Definition: core_unreal.c:824
#define AST_UNREAL_CARETAKER_THREAD
Definition: core_unreal.h:107
struct ast_channel * ast_unreal_new_channels(struct ast_unreal_pvt *p, const struct ast_channel_tech *tech, int semi1_state, int semi2_state, const char *exten, const char *context, const struct ast_assigned_ids *assignedids, const struct ast_channel *requestor, ast_callid callid)
Create the semi1 and semi2 unreal channels.
Definition: core_unreal.c:1160
struct ast_frame * ast_unreal_read(struct ast_channel *ast)
Definition: core_unreal.c:313
#define SCOPED_CHANNELLOCK(varname, chan)
scoped lock specialization for channels.
Definition: lock.h:619
#define NULL
Definition: resample.c:96
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:425
struct ast_unreal_pvt base
struct ast_bridge * bridge
Structure to pass both assignedid values to channel drivers.
Definition: channel.h:604
Structure that contains features information.
struct ast_flags feature_flags
Structure that contains information about a bridge.
Definition: bridge.h:349
Structure to describe a channel "technology", ie a channel driver See for examples:
Definition: channel.h:628
const char *const type
Definition: channel.h:629
Main Channel structure associated with a channel.
const char * data
Format capabilities structure, holds formats + preference order + etc.
Definition: format_cap.c:54
The base pvt structure for local channel derivatives.
Definition: core_unreal.h:91
The structure that represents a conference bridge.
Definition: confbridge.h:246
#define RAII_VAR(vartype, varname, initval, dtor)
Declare a variable that will call a destructor function when it goes out of scope.
Definition: utils.h:941
#define ast_assert(a)
Definition: utils.h:739
#define ast_set_flag(p, flag)
Definition: utils.h:70