asterisk/res/res_hep_rtcp.c

145 lines
3.5 KiB
C
Raw Normal View History

res_hep_rtcp: Add module that sends RTCP information to a Homer Server This patch adds a new module to Asterisk, res_hep_rtcp. The module subscribes to the RTCP topics in Stasis and receives RTCP information back from the message bus. It encodes into HEPv3 packets and sends the information to the res_hep module for transmission. Using this, someone with a Homer server can get live call quality monitoring for all RTP-based channels in their Asterisk 12+ systems. In addition, there were a few bugs in the RTP engine, res_rtp_asterisk, and chan_pjsip that were uncovered by the tests written for the Asterisk Test Suite. This patch fixes the following: 1) chan_pjsip failed to set its channel unique ids on its RTP instance on outbound calls. It now does this in the appropriate location, in the serialized call callback. 2) The rtp_engine was overflowing some values when packed into JSON. Specifically, some longs and unsigned ints can't be be packed into integer values, for obvious reasons. Since libjansson only supports integers, floats, strings, booleans, and objects, we print these values into strings. 3) res_rtp_asterisk had a few problems: (a) it would emit a source IP address of 0.0.0.0 if bound to that IP address. We now use ast_find_ourip to get a better IP address, and properly marshal the result into an ast_strdupa'd string. (b) Reports can be generated with no report bodies. In particular, this occurs when a sender is transmitting information to a receiver (who will send no RTP back to the sender). As such, the sender has no report body for what it received. We now properly handle this case, and the sender will emit SR reports with no body. Likewise, if we receive an RTCP packet with no report body, we will still generate the appropriate events. ASTERISK-24119 #close ........ Merged revisions 419823 from http://svn.asterisk.org/svn/asterisk/branches/12 git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@419825 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2014-07-31 11:57:51 +00:00
/*
* Asterisk -- An open source telephony toolkit.
*
* Copyright (C) 1999 - 2014, Digium, Inc.
*
* Matt Jordan <mjordan@digium.com>
*
* See http://www.asterisk.org for more information about
* the Asterisk project. Please do not directly contact
* any of the maintainers of this project for assistance;
* the project provides a web site, mailing lists and IRC
* channels for your use.
*
* This program is free software, distributed under the terms of
* the GNU General Public License Version 2. See the LICENSE file
* at the top of the source tree.
*/
/*!
* \file
* \brief RTCP logging with Homer
*
* \author Matt Jordan <mjordan@digium.com>
*
*/
/*** MODULEINFO
<depend>res_hep</depend>
<support_level>extended</support_level>
***/
#include "asterisk.h"
git migration: Refactor the ASTERISK_FILE_VERSION macro Git does not support the ability to replace a token with a version string during check-in. While it does have support for replacing a token on clone, this is somewhat sub-optimal: the token is replaced with the object hash, which is not particularly easy for human consumption. What's more, in practice, the source file version was often not terribly useful. Generally, when triaging bugs, the overall version of Asterisk is far more useful than an individual SVN version of a file. As a result, this patch removes Asterisk's support for showing source file versions. Specifically, it does the following: * Rename ASTERISK_FILE_VERSION macro to ASTERISK_REGISTER_FILE, and remove passing the version in with the macro. Other facilities than 'core show file version' make use of the file names, such as setting a debug level only on a specific file. As such, the act of registering source files with the Asterisk core still has use. The macro rename now reflects the new macro purpose. * main/asterisk: - Refactor the file_version structure to reflect that it no longer tracks a version field. - Remove the "core show file version" CLI command. Without the file version, it is no longer useful. - Remove the ast_file_version_find function. The file version is no longer tracked. - Rename ast_register_file_version/ast_unregister_file_version to ast_register_file/ast_unregister_file, respectively. * main/manager: Remove value from the Version key of the ModuleCheck Action. The actual key itself has not been removed, as doing so would absolutely constitute a backwards incompatible change. However, since the file version is no longer tracked, there is no need to attempt to include it in the Version key. * UPGRADE: Add notes for: - Modification to the ModuleCheck AMI Action - Removal of the "core show file version" CLI command Change-Id: I6cf0ff280e1668bf4957dc21f32a5ff43444a40e
2015-04-12 02:38:22 +00:00
ASTERISK_REGISTER_FILE()
res_hep_rtcp: Add module that sends RTCP information to a Homer Server This patch adds a new module to Asterisk, res_hep_rtcp. The module subscribes to the RTCP topics in Stasis and receives RTCP information back from the message bus. It encodes into HEPv3 packets and sends the information to the res_hep module for transmission. Using this, someone with a Homer server can get live call quality monitoring for all RTP-based channels in their Asterisk 12+ systems. In addition, there were a few bugs in the RTP engine, res_rtp_asterisk, and chan_pjsip that were uncovered by the tests written for the Asterisk Test Suite. This patch fixes the following: 1) chan_pjsip failed to set its channel unique ids on its RTP instance on outbound calls. It now does this in the appropriate location, in the serialized call callback. 2) The rtp_engine was overflowing some values when packed into JSON. Specifically, some longs and unsigned ints can't be be packed into integer values, for obvious reasons. Since libjansson only supports integers, floats, strings, booleans, and objects, we print these values into strings. 3) res_rtp_asterisk had a few problems: (a) it would emit a source IP address of 0.0.0.0 if bound to that IP address. We now use ast_find_ourip to get a better IP address, and properly marshal the result into an ast_strdupa'd string. (b) Reports can be generated with no report bodies. In particular, this occurs when a sender is transmitting information to a receiver (who will send no RTP back to the sender). As such, the sender has no report body for what it received. We now properly handle this case, and the sender will emit SR reports with no body. Likewise, if we receive an RTCP packet with no report body, we will still generate the appropriate events. ASTERISK-24119 #close ........ Merged revisions 419823 from http://svn.asterisk.org/svn/asterisk/branches/12 git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@419825 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2014-07-31 11:57:51 +00:00
#include "asterisk/res_hep.h"
#include "asterisk/module.h"
#include "asterisk/netsock2.h"
#include "asterisk/stasis.h"
#include "asterisk/rtp_engine.h"
#include "asterisk/json.h"
#include "asterisk/config.h"
static struct stasis_subscription *stasis_rtp_subscription;
static void rtcp_message_handler(struct stasis_message *message)
{
RAII_VAR(struct ast_json *, json_payload, NULL, ast_json_unref);
RAII_VAR(char *, payload, NULL, ast_json_free);
struct ast_json *json_blob;
struct ast_json *json_channel;
struct ast_json *json_rtcp;
struct hepv3_capture_info *capture_info;
struct ast_json *from;
struct ast_json *to;
struct timeval current_time = ast_tvnow();
json_payload = stasis_message_to_json(message, NULL);
if (!json_payload) {
return;
}
json_blob = ast_json_object_get(json_payload, "blob");
if (!json_blob) {
return;
}
json_channel = ast_json_object_get(json_payload, "channel");
if (!json_channel) {
return;
}
json_rtcp = ast_json_object_get(json_payload, "rtcp_report");
if (!json_rtcp) {
return;
}
from = ast_json_object_get(json_blob, "from");
to = ast_json_object_get(json_blob, "to");
if (!from || !to) {
return;
}
payload = ast_json_dump_string(json_rtcp);
if (ast_strlen_zero(payload)) {
return;
}
capture_info = hepv3_create_capture_info(payload, strlen(payload));
if (!capture_info) {
return;
}
ast_sockaddr_parse(&capture_info->src_addr, ast_json_string_get(from), PARSE_PORT_REQUIRE);
ast_sockaddr_parse(&capture_info->dst_addr, ast_json_string_get(to), PARSE_PORT_REQUIRE);
capture_info->uuid = ast_strdup(ast_json_string_get(ast_json_object_get(json_channel, "name")));
if (!capture_info->uuid) {
ao2_ref(capture_info, -1);
return;
}
capture_info->capture_time = current_time;
capture_info->capture_type = HEPV3_CAPTURE_TYPE_RTCP;
capture_info->zipped = 0;
hepv3_send_packet(capture_info);
}
static void rtp_topic_handler(void *data, struct stasis_subscription *sub, struct stasis_message *message)
{
struct stasis_message_type *message_type = stasis_message_type(message);
if ((message_type == ast_rtp_rtcp_sent_type()) ||
(message_type == ast_rtp_rtcp_received_type())) {
rtcp_message_handler(message);
}
}
static int load_module(void)
{
stasis_rtp_subscription = stasis_subscribe(ast_rtp_topic(),
rtp_topic_handler, NULL);
if (!stasis_rtp_subscription) {
return AST_MODULE_LOAD_FAILURE;
}
return AST_MODULE_LOAD_SUCCESS;
}
static int unload_module(void)
{
if (stasis_rtp_subscription) {
stasis_rtp_subscription = stasis_unsubscribe_and_join(stasis_rtp_subscription);
res_hep_rtcp: Add module that sends RTCP information to a Homer Server This patch adds a new module to Asterisk, res_hep_rtcp. The module subscribes to the RTCP topics in Stasis and receives RTCP information back from the message bus. It encodes into HEPv3 packets and sends the information to the res_hep module for transmission. Using this, someone with a Homer server can get live call quality monitoring for all RTP-based channels in their Asterisk 12+ systems. In addition, there were a few bugs in the RTP engine, res_rtp_asterisk, and chan_pjsip that were uncovered by the tests written for the Asterisk Test Suite. This patch fixes the following: 1) chan_pjsip failed to set its channel unique ids on its RTP instance on outbound calls. It now does this in the appropriate location, in the serialized call callback. 2) The rtp_engine was overflowing some values when packed into JSON. Specifically, some longs and unsigned ints can't be be packed into integer values, for obvious reasons. Since libjansson only supports integers, floats, strings, booleans, and objects, we print these values into strings. 3) res_rtp_asterisk had a few problems: (a) it would emit a source IP address of 0.0.0.0 if bound to that IP address. We now use ast_find_ourip to get a better IP address, and properly marshal the result into an ast_strdupa'd string. (b) Reports can be generated with no report bodies. In particular, this occurs when a sender is transmitting information to a receiver (who will send no RTP back to the sender). As such, the sender has no report body for what it received. We now properly handle this case, and the sender will emit SR reports with no body. Likewise, if we receive an RTCP packet with no report body, we will still generate the appropriate events. ASTERISK-24119 #close ........ Merged revisions 419823 from http://svn.asterisk.org/svn/asterisk/branches/12 git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@419825 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2014-07-31 11:57:51 +00:00
}
return 0;
}
AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_LOAD_ORDER, "RTCP HEPv3 Logger",
.load = load_module,
.unload = unload_module,
.load_pri = AST_MODPRI_DEFAULT,
);