git migration: Refactor the ASTERISK_FILE_VERSION macro
[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_REGISTER_FILE()
33
34 #include "asterisk/channel.h"
35 #include "asterisk/bridge.h"
36 #include "asterisk/format_cache.h"
37 #include "include/confbridge.h"
38
39 /* ------------------------------------------------------------------- */
40
41 static unsigned int name_sequence = 0;
42
43 static int rec_call(struct ast_channel *chan, const char *addr, int timeout)
44 {
45         /* Make sure anyone calling ast_call() for this channel driver is going to fail. */
46         return -1;
47 }
48
49 static struct ast_frame *rec_read(struct ast_channel *ast)
50 {
51         return &ast_null_frame;
52 }
53
54 static int rec_write(struct ast_channel *ast, struct ast_frame *f)
55 {
56         return 0;
57 }
58
59 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)
60 {
61         struct ast_channel *chan;
62         const char *conf_name = data;
63         RAII_VAR(struct ast_format_cap *, capabilities, NULL, ao2_cleanup);
64         int generated_seqno = ast_atomic_fetchadd_int((int *) &name_sequence, +1);
65
66         capabilities = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT);
67         if (!capabilities) {
68                 return NULL;
69         }
70         ast_format_cap_append_by_type(capabilities, AST_MEDIA_TYPE_UNKNOWN);
71
72         chan = ast_channel_alloc(1, AST_STATE_UP, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0,
73                 "CBRec/%s-%08x",
74                 conf_name, (unsigned) generated_seqno);
75         if (!chan) {
76                 return NULL;
77         }
78         if (ast_channel_add_bridge_role(chan, "recorder")) {
79                 ast_channel_unlock(chan);
80                 ast_channel_release(chan);
81                 return NULL;
82         }
83
84         ast_channel_tech_set(chan, conf_record_get_tech());
85         ast_channel_nativeformats_set(chan, capabilities);
86         ast_channel_set_writeformat(chan, ast_format_slin);
87         ast_channel_set_rawwriteformat(chan, ast_format_slin);
88         ast_channel_set_readformat(chan, ast_format_slin);
89         ast_channel_set_rawreadformat(chan, ast_format_slin);
90         ast_channel_unlock(chan);
91         return chan;
92 }
93
94 static struct ast_channel_tech record_tech = {
95         .type = "CBRec",
96         .description = "Conference Bridge Recording Channel",
97         .requester = rec_request,
98         .call = rec_call,
99         .read = rec_read,
100         .write = rec_write,
101         .properties = AST_CHAN_TP_INTERNAL,
102 };
103
104 struct ast_channel_tech *conf_record_get_tech(void)
105 {
106         return &record_tech;
107 }