Asterisk - The Open Source Telephony Project  18.5.0
conf_chan_record.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 recorder 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/format_cache.h"
35 #include "include/confbridge.h"
36 
37 /* ------------------------------------------------------------------- */
38 
39 static unsigned int name_sequence = 0;
40 
41 static int rec_call(struct ast_channel *chan, const char *addr, int timeout)
42 {
43  /* Make sure anyone calling ast_call() for this channel driver is going to fail. */
44  return -1;
45 }
46 
47 static struct ast_frame *rec_read(struct ast_channel *ast)
48 {
49  return &ast_null_frame;
50 }
51 
52 static int rec_write(struct ast_channel *ast, struct ast_frame *f)
53 {
54  return 0;
55 }
56 
57 static struct ast_channel *rec_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)
58 {
59  struct ast_channel *chan;
60  const char *conf_name = data;
61  RAII_VAR(struct ast_format_cap *, capabilities, NULL, ao2_cleanup);
62  int generated_seqno = ast_atomic_fetchadd_int((int *) &name_sequence, +1);
63 
65  if (!capabilities) {
66  return NULL;
67  }
69 
71  "CBRec/%s-%08x",
72  conf_name, (unsigned) generated_seqno);
73  if (!chan) {
74  return NULL;
75  }
76  if (ast_channel_add_bridge_role(chan, "recorder")) {
77  ast_channel_unlock(chan);
78  ast_channel_release(chan);
79  return NULL;
80  }
81 
83  ast_channel_nativeformats_set(chan, capabilities);
88  ast_channel_unlock(chan);
89  return chan;
90 }
91 
92 static struct ast_channel_tech record_tech = {
93  .type = "CBRec",
94  .description = "Conference Bridge Recording Channel",
95  .requester = rec_request,
96  .call = rec_call,
97  .read = rec_read,
98  .write = rec_write,
99  .properties = AST_CHAN_TP_INTERNAL,
100 };
101 
103 {
104  return &record_tech;
105 }
static struct ast_channel_tech record_tech
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.
void ast_channel_set_writeformat(struct ast_channel *chan, struct ast_format *format)
struct ast_channel * ast_channel_release(struct ast_channel *chan)
Unlink and release reference to a channel.
Definition: channel.c:1584
void ast_channel_set_rawwriteformat(struct ast_channel *chan, struct ast_format *format)
static int timeout
Definition: cdr_mysql.c:86
Structure to pass both assignedid values to channel drivers.
Definition: channel.h:605
int ast_format_cap_append_by_type(struct ast_format_cap *cap, enum ast_media_type type)
Add all codecs Asterisk knows about for a specific type to the capabilities structure.
Definition: format_cap.c:216
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
#define NULL
Definition: resample.c:96
const char * data
int ast_atomic_fetchadd_int(volatile int *p, int v)
Atomically add v to *p and return the previous value of *p.
Definition: lock.h:755
struct ast_channel_tech * conf_record_get_tech(void)
Get ConfBridge record channel technology struct.
void ast_channel_tech_set(struct ast_channel *chan, const struct ast_channel_tech *value)
void ast_channel_set_rawreadformat(struct ast_channel *chan, struct ast_format *format)
static unsigned int name_sequence
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_channel_nativeformats_set(struct ast_channel *chan, struct ast_format_cap *value)
void ast_channel_set_readformat(struct ast_channel *chan, struct ast_format *format)
Channels with this particular technology are an implementation detail of Asterisk and should generall...
Definition: channel.h:972
#define ast_format_cap_alloc(flags)
Definition: format_cap.h:52
Structure to describe a channel "technology", ie a channel driver See for examples: ...
Definition: channel.h:629
static int rec_call(struct ast_channel *chan, const char *addr, int timeout)
Format capabilities structure, holds formats + preference order + etc.
Definition: format_cap.c:54
static struct ast_channel * rec_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 struct ast_frame * rec_read(struct ast_channel *ast)
#define ast_channel_unlock(chan)
Definition: channel.h:2946
struct ast_frame ast_null_frame
Definition: main/frame.c:79
static int rec_write(struct ast_channel *ast, struct ast_frame *f)
#define ao2_cleanup(obj)
Definition: astobj2.h:1958
Data structure associated with a single frame of data.
Bridging API.
#define ast_channel_alloc(needqueue, state, cid_num, cid_name, acctcode, exten, context, assignedids, requestor, amaflag,...)
Create a channel structure.
Definition: channel.h:1259
struct ast_format * ast_format_slin
Built-in cached signed linear 8kHz format.
Definition: format_cache.c:41
Media Format Cache API.