Asterisk - The Open Source Telephony Project  18.5.0
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 <[email protected]>
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 <[email protected]>
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"
34 #include "asterisk/core_unreal.h"
35 #include "include/confbridge.h"
36 
37 /* ------------------------------------------------------------------- */
38 
39 /*! ConfBridge announcer channel private. */
40 struct announce_pvt {
41  /*! Unreal channel driver base class values. */
43  /*! Conference bridge associated with this announcer. */
44  struct ast_bridge *bridge;
45 };
46 
47 static 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 
53 static 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 
70 static void announce_pvt_destructor(void *vdoomed)
71 {
72  struct announce_pvt *doomed = vdoomed;
73 
74  ao2_cleanup(doomed->bridge);
75  doomed->bridge = NULL;
76  ast_unreal_destructor(&doomed->base);
77 }
78 
79 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)
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 
103  chan = ast_unreal_new_channels(&pvt->base, conf_announce_get_tech(),
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  {
151  SCOPED_CHANNELLOCK(lock, ast);
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 }
static const char type[]
Definition: chan_ooh323.c:109
Main Channel structure associated with a channel.
const char *const type
Definition: channel.h:630
Asterisk main include file. File version handling, generic pbx functions.
Structure that contains features information.
void * ast_channel_tech_pvt(const struct ast_channel *chan)
#define OBJ_KEY
Definition: astobj2.h:1155
#define ast_set_flag(p, flag)
Definition: utils.h:70
static int timeout
Definition: cdr_mysql.c:86
int ast_unreal_sendhtml(struct ast_channel *ast, int subclass, const char *data, int datalen)
Definition: core_unreal.c:846
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:1111
#define AST_UNREAL_NO_OPTIMIZATION
Definition: core_unreal.h:108
Structure to pass both assignedid values to channel drivers.
Definition: channel.h:605
#define AST_UNREAL_CARETAKER_THREAD
Definition: core_unreal.h:107
#define ast_assert(a)
Definition: utils.h:695
#define ao2_unlock(a)
Definition: astobj2.h:730
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:1162
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:317
int ast_unreal_indicate(struct ast_channel *ast, int condition, const void *data, size_t datalen)
Definition: core_unreal.c:622
#define NULL
Definition: resample.c:96
const char * data
int ast_unreal_fixup(struct ast_channel *oldchan, struct ast_channel *newchan)
Definition: core_unreal.c:369
struct ast_flags feature_flags
int conf_announce_channel_push(struct ast_channel *ast)
Push the announcer channel into the conference.
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:1924
struct ast_unreal_pvt base
#define SCOPED_CHANNELLOCK(varname, chan)
scoped lock specialization for channels.
Definition: lock.h:617
General Asterisk PBX channel definitions.
#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:911
void ast_unreal_destructor(void *vdoomed)
struct ast_unreal_pvt destructor.
Definition: core_unreal.c:1099
ast_mutex_t lock
Definition: app_meetme.c:1091
#define ao2_ref(o, delta)
Definition: astobj2.h:464
struct ast_channel_tech * conf_announce_get_tech(void)
Get ConfBridge announce channel technology struct.
#define ao2_lock(a)
Definition: astobj2.h:718
int ast_unreal_setoption(struct ast_channel *chan, int option, void *data, int datalen)
Definition: core_unreal.c:97
struct ao2_container * conference_bridges
Container to hold all conference bridges in progress.
Channels with this particular technology are an implementation detail of Asterisk and should generall...
Definition: channel.h:972
Structure to describe a channel "technology", ie a channel driver See for examples: ...
Definition: channel.h:629
struct ast_bridge * bridge
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)
Structure that contains information about a bridge.
Definition: bridge.h:357
int ast_unreal_write(struct ast_channel *ast, struct ast_frame *f)
Definition: core_unreal.c:318
Format capabilities structure, holds formats + preference order + etc.
Definition: format_cap.c:54
int ast_unreal_digit_begin(struct ast_channel *ast, char digit)
Definition: core_unreal.c:779
The base pvt structure for local channel derivatives.
Definition: core_unreal.h:91
int ast_unreal_digit_end(struct ast_channel *ast, char digit, unsigned int duration)
Definition: core_unreal.c:801
void ast_hangup(struct ast_channel *chan)
Hang up a channel.
Definition: channel.c:2548
struct ast_frame * ast_unreal_read(struct ast_channel *ast)
Definition: core_unreal.c:313
The structure that represents a conference bridge.
Definition: confbridge.h:244
#define ao2_find(container, arg, flags)
Definition: astobj2.h:1756
struct ast_bridge_features * ast_bridge_features_new(void)
Allocate a new bridge features struct.
Definition: bridge.c:3750
static struct ast_channel_tech announce_tech
int ast_unreal_queryoption(struct ast_channel *ast, int option, void *data, int *datalen)
Definition: core_unreal.c:166
#define ao2_cleanup(obj)
Definition: astobj2.h:1958
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:401
int ast_answer(struct ast_channel *chan)
Answer a channel.
Definition: channel.c:2814
Bridging API.
static int announce_hangup(struct ast_channel *ast)
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
static int announce_call(struct ast_channel *chan, const char *addr, int timeout)
static void announce_pvt_destructor(void *vdoomed)
int ast_unreal_sendtext(struct ast_channel *ast, const char *text)
Definition: core_unreal.c:824
Unreal channel derivative framework.