| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 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 |
|
| 40 |
struct announce_pvt { |
| 41 |
|
| 42 |
struct ast_unreal_pvt base; |
| 43 |
|
| 44 |
struct ast_bridge *bridge; |
| 45 |
}; |
| 46 |
|
| 47 |
static int announce_call(struct ast_channel *chan, const char *addr, int timeout) |
| 48 |
{ |
| 49 |
|
| 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 |
|
| 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 |
|
| 93 |
pvt = (struct announce_pvt *) ast_unreal_alloc(sizeof(*pvt), announce_pvt_destructor, |
| 94 |
cap); |
| 95 |
if (!pvt) { |
| 96 |
return NULL; |
| 97 |
} |
| 98 |
ast_set_flag(&pvt->base, AST_UNREAL_NO_OPTIMIZATION); |
| 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 |
|
| 117 |
static struct ast_channel_tech announce_tech = { |
| 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 |
|
| 139 |
struct ast_channel_tech *conf_announce_get_tech(void) |
| 140 |
{ |
| 141 |
return &announce_tech; |
| 142 |
} |
| 143 |
|
| 144 |
int conf_announce_channel_push(struct ast_channel *ast) |
| 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 |
} |
| 168 |
ast_set_flag(&features->feature_flags, AST_BRIDGE_CHANNEL_FLAG_IMMOVABLE); |
| 169 |
|
| 170 |
|
| 171 |
if (ast_bridge_impart(p->bridge, chan, NULL, features, |
| 172 |
AST_BRIDGE_IMPART_CHAN_INDEPENDENT)) { |
| 173 |
return -1; |
| 174 |
} |
| 175 |
ao2_lock(p); |
| 176 |
ast_set_flag(&p->base, AST_UNREAL_CARETAKER_THREAD); |
| 177 |
ao2_unlock(p); |
| 178 |
return 0; |
| 179 |
} |