media formats: re-architect handling of media for performance improvements
[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 "asterisk/format_cache.h"
37 #include "include/confbridge.h"
38
39 /* ------------------------------------------------------------------- */
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
63         capabilities = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT);
64         if (!capabilities) {
65                 return NULL;
66         }
67         ast_format_cap_append_by_type(capabilities, AST_MEDIA_TYPE_UNKNOWN);
68
69         chan = ast_channel_alloc(1, AST_STATE_UP, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0,
70                 "CBRec/conf-%s-uid-%d",
71                 conf_name, (int) ast_random());
72         if (!chan) {
73                 return NULL;
74         }
75         if (ast_channel_add_bridge_role(chan, "recorder")) {
76                 ast_channel_unlock(chan);
77                 ast_channel_release(chan);
78                 return NULL;
79         }
80
81         ast_channel_tech_set(chan, conf_record_get_tech());
82         ast_channel_nativeformats_set(chan, capabilities);
83         ast_channel_set_writeformat(chan, ast_format_slin);
84         ast_channel_set_rawwriteformat(chan, ast_format_slin);
85         ast_channel_set_readformat(chan, ast_format_slin);
86         ast_channel_set_rawreadformat(chan, ast_format_slin);
87         ast_channel_unlock(chan);
88         return chan;
89 }
90
91 static struct ast_channel_tech record_tech = {
92         .type = "CBRec",
93         .description = "Conference Bridge Recording Channel",
94         .requester = rec_request,
95         .call = rec_call,
96         .read = rec_read,
97         .write = rec_write,
98         .properties = AST_CHAN_TP_INTERNAL,
99 };
100
101 struct ast_channel_tech *conf_record_get_tech(void)
102 {
103         return &record_tech;
104 }