2 * Asterisk -- An open source telephony toolkit.
4 * Copyright (C) 1999 - 2014, Digium, Inc.
6 * Matt Jordan <mjordan@digium.com>
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.
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.
21 * \brief RTCP logging with Homer
23 * \author Matt Jordan <mjordan@digium.com>
28 <depend>res_hep</depend>
29 <support_level>extended</support_level>
34 ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
38 #include "asterisk/res_hep.h"
39 #include "asterisk/module.h"
40 #include "asterisk/netsock2.h"
41 #include "asterisk/stasis.h"
42 #include "asterisk/rtp_engine.h"
43 #include "asterisk/json.h"
44 #include "asterisk/config.h"
46 static struct stasis_subscription *stasis_rtp_subscription;
48 static void rtcp_message_handler(struct stasis_message *message)
51 RAII_VAR(struct ast_json *, json_payload, NULL, ast_json_unref);
52 RAII_VAR(char *, payload, NULL, ast_json_free);
53 struct ast_json *json_blob;
54 struct ast_json *json_channel;
55 struct ast_json *json_rtcp;
56 struct hepv3_capture_info *capture_info;
57 struct ast_json *from;
59 struct timeval current_time = ast_tvnow();
61 json_payload = stasis_message_to_json(message, NULL);
66 json_blob = ast_json_object_get(json_payload, "blob");
71 json_channel = ast_json_object_get(json_payload, "channel");
76 json_rtcp = ast_json_object_get(json_payload, "rtcp_report");
81 from = ast_json_object_get(json_blob, "from");
82 to = ast_json_object_get(json_blob, "to");
87 payload = ast_json_dump_string(json_rtcp);
88 if (ast_strlen_zero(payload)) {
92 capture_info = hepv3_create_capture_info(payload, strlen(payload));
96 ast_sockaddr_parse(&capture_info->src_addr, ast_json_string_get(from), PARSE_PORT_REQUIRE);
97 ast_sockaddr_parse(&capture_info->dst_addr, ast_json_string_get(to), PARSE_PORT_REQUIRE);
99 capture_info->uuid = ast_strdup(ast_json_string_get(ast_json_object_get(json_channel, "name")));
100 if (!capture_info->uuid) {
101 ao2_ref(capture_info, -1);
104 capture_info->capture_time = current_time;
105 capture_info->capture_type = HEPV3_CAPTURE_TYPE_RTCP;
106 capture_info->zipped = 0;
108 hepv3_send_packet(capture_info);
111 static void rtp_topic_handler(void *data, struct stasis_subscription *sub, struct stasis_message *message)
113 struct stasis_message_type *message_type = stasis_message_type(message);
115 if ((message_type == ast_rtp_rtcp_sent_type()) ||
116 (message_type == ast_rtp_rtcp_received_type())) {
117 rtcp_message_handler(message);
121 static int load_module(void)
124 stasis_rtp_subscription = stasis_subscribe(ast_rtp_topic(),
125 rtp_topic_handler, NULL);
126 if (!stasis_rtp_subscription) {
127 return AST_MODULE_LOAD_FAILURE;
130 return AST_MODULE_LOAD_SUCCESS;
133 static int unload_module(void)
135 if (stasis_rtp_subscription) {
136 stasis_rtp_subscription = stasis_unsubscribe(stasis_rtp_subscription);
142 AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_LOAD_ORDER, "RTCP HEPv3 Logger",
144 .unload = unload_module,
145 .load_pri = AST_MODPRI_DEFAULT,