34de5af3b84d8bbd542507c6cff2f1d219dd8e23
[asterisk/asterisk.git] / apps / confbridge / conf_chan_record.c
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 recorder 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 ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
33
34 #include "asterisk/channel.h"
35 #include "asterisk/bridge.h"
36 #include "include/confbridge.h"
37
38 /* ------------------------------------------------------------------- */
39
40 static int rec_call(struct ast_channel *chan, const char *addr, int timeout)
41 {
42         /* Make sure anyone calling ast_call() for this channel driver is going to fail. */
43         return -1;
44 }
45
46 static struct ast_frame *rec_read(struct ast_channel *ast)
47 {
48         return &ast_null_frame;
49 }
50
51 static int rec_write(struct ast_channel *ast, struct ast_frame *f)
52 {
53         return 0;
54 }
55
56 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)
57 {
58         struct ast_channel *chan;
59         struct ast_format format;
60         const char *conf_name = data;
61
62         chan = ast_channel_alloc(1, AST_STATE_UP, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0,
63                 "CBRec/conf-%s-uid-%d",
64                 conf_name, (int) ast_random());
65         if (!chan) {
66                 return NULL;
67         }
68         if (ast_channel_add_bridge_role(chan, "recorder")) {
69                 ast_channel_unlock(chan);
70                 ast_channel_release(chan);
71                 return NULL;
72         }
73         ast_format_set(&format, AST_FORMAT_SLINEAR, 0);
74         ast_channel_tech_set(chan, conf_record_get_tech());
75         ast_format_cap_add_all(ast_channel_nativeformats(chan));
76         ast_format_copy(ast_channel_writeformat(chan), &format);
77         ast_format_copy(ast_channel_rawwriteformat(chan), &format);
78         ast_format_copy(ast_channel_readformat(chan), &format);
79         ast_format_copy(ast_channel_rawreadformat(chan), &format);
80         ast_channel_unlock(chan);
81         return chan;
82 }
83
84 static struct ast_channel_tech record_tech = {
85         .type = "CBRec",
86         .description = "Conference Bridge Recording Channel",
87         .requester = rec_request,
88         .call = rec_call,
89         .read = rec_read,
90         .write = rec_write,
91         .properties = AST_CHAN_TP_INTERNAL,
92 };
93
94 struct ast_channel_tech *conf_record_get_tech(void)
95 {
96         return &record_tech;
97 }