提交 70d73caf authored 作者: Anthony Minessale's avatar Anthony Minessale 提交者: Brian West

FSRTP-14

上级 9a74958b
......@@ -116,6 +116,7 @@
#include "switch_utils.h"
#include "switch_caller.h"
#include "switch_frame.h"
#include "switch_rtcp_frame.h"
#include "switch_module_interfaces.h"
#include "switch_channel.h"
#include "switch_buffer.h"
......
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
* Copyright (C) 2005-2009, Anthony Minessale II <anthm@freeswitch.org>
*
* Version: MPL 1.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
*
* The Initial Developer of the Original Code is
* Anthony Minessale II <anthm@freeswitch.org>
* Portions created by the Initial Developer are Copyright (C)
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Sherwin Sim
*
*
* switch_rtcp_frame.h -- RTCP Frame Structure
*
*/
/*! \file switch_rtcp_frame.h
\brief RTCP Frame Structure
*/
#ifndef SWITCH_RTCP_FRAME_H
#define SWITCH_RTCP_FRAME_H
#include <switch.h>
SWITCH_BEGIN_EXTERN_C
/*! \brief An abstraction of a rtcp frame */
struct switch_rtcp_frame {
uint16_t report_count;
uint16_t packet_type;
uint32_t ssrc;
uint32_t ntp_msw;
uint32_t ntp_lsw;
uint32_t timestamp;
uint32_t packet_count;
uint32_t octect_count;
};
SWITCH_END_EXTERN_C
#endif
/* For Emacs:
* Local Variables:
* mode:c
* indent-tabs-mode:t
* tab-width:4
* c-basic-offset:4
* End:
* For VIM:
* vim:set softtabstop=4 shiftwidth=4 tabstop=4:
*/
......@@ -41,6 +41,7 @@
SWITCH_BEGIN_EXTERN_C
#define SWITCH_RTP_MAX_BUF_LEN 16384
#define SWITCH_RTCP_MAX_BUF_LEN 16384
#define SWITCH_RTP_MAX_CRYPTO_LEN 64
#define SWITCH_RTP_KEY_LEN 30
#define SWITCH_RTP_CRYPTO_KEY_32 "AES_CM_128_HMAC_SHA1_32"
......@@ -213,6 +214,13 @@ SWITCH_DECLARE(void) switch_rtp_destroy(switch_rtp_t **rtp_session);
*/
SWITCH_DECLARE(switch_status_t) switch_rtp_activate_ice(switch_rtp_t *rtp_session, char *login, char *rlogin);
/*!
\brief Activate sending RTCP Sender Reports (SR's)
\param send_rate interval in milliseconds to send at
\return SWITCH_STATUS_SUCCESS
*/
SWITCH_DECLARE(switch_status_t) switch_rtp_activate_rtcp(switch_rtp_t *rtp_session, int send_rate);
/*!
\brief Acvite a jitter buffer on an RTP session
\param rtp_session the rtp session
......@@ -347,6 +355,15 @@ SWITCH_DECLARE(switch_status_t) switch_rtp_zerocopy_read(switch_rtp_t *rtp_sessi
*/
SWITCH_DECLARE(switch_status_t) switch_rtp_zerocopy_read_frame(switch_rtp_t *rtp_session, switch_frame_t *frame, switch_io_flag_t io_flags);
/*!
\brief Read RTCP data from a given RTP session without copying
\param rtp_session the RTP session to read from
\param frame an RTCP frame to populate with information
\return the number of bytes read
*/
SWITCH_DECLARE(switch_status_t) switch_rtcp_zerocopy_read_frame(switch_rtp_t *rtp_session, switch_rtcp_frame_t *frame);
SWITCH_DECLARE(void) rtp_flush_read_buffer(switch_rtp_t *rtp_session, switch_rtp_flush_t flush);
/*!
......
......@@ -534,7 +534,8 @@ typedef enum {
SWITCH_ZRTP_FLAG_SECURE_MITM_RECV = (1 << 26),
SWITCH_RTP_FLAG_DEBUG_RTP_READ = (1 << 27),
SWITCH_RTP_FLAG_DEBUG_RTP_WRITE = (1 << 28),
SWITCH_RTP_FLAG_VIDEO = (1 << 29)
SWITCH_RTP_FLAG_VIDEO = (1 << 29),
SWITCH_RTP_FLAG_ENABLE_RTCP = (1 << 30)
} switch_rtp_flag_enum_t;
typedef uint32_t switch_rtp_flag_t;
......@@ -607,6 +608,35 @@ typedef struct {
#pragma pack(pop, r1)
#endif
#ifdef _MSC_VER
#pragma pack(push, r1, 1)
#endif
#if SWITCH_BYTE_ORDER == __BIG_ENDIAN
typedef struct {
unsigned version:2; /* protocol version */
unsigned p:1; /* padding flag */
unsigned count:5; /* number of reception report blocks */
unsigned type:8; /* packet type */
unsigned length:16; /* length in 32-bit words - 1 */
} switch_rtcp_hdr_t;
#else /* BIG_ENDIAN */
typedef struct {
unsigned count:5; /* number of reception report blocks */
unsigned p:1; /* padding flag */
unsigned version:2; /* protocol version */
unsigned type:8; /* packet type */
unsigned length:16; /* length in 32-bit words - 1 */
} switch_rtcp_hdr_t;
#endif
#ifdef _MSC_VER
#pragma pack(pop, r1)
#endif
/*!
\enum switch_priority_t
\brief Priority Indication
......@@ -1352,6 +1382,7 @@ typedef enum {
SWITCH_EVENT_SERVER_DISCONNECTED,
SWITCH_EVENT_SEND_INFO,
SWITCH_EVENT_RECV_INFO,
SWITCH_EVENT_RECV_RTCP_MESSAGE,
SWITCH_EVENT_CALL_SECURE,
SWITCH_EVENT_NAT,
SWITCH_EVENT_RECORD_START,
......@@ -1472,6 +1503,7 @@ typedef uint16_t switch_port_t;
typedef uint8_t switch_payload_t;
typedef struct switch_app_log switch_app_log_t;
typedef struct switch_rtp switch_rtp_t;
typedef struct switch_rtcp switch_rtcp_t;
typedef struct switch_core_session_message switch_core_session_message_t;
typedef struct switch_event_header switch_event_header_t;
typedef struct switch_event switch_event_t;
......@@ -1479,6 +1511,7 @@ typedef struct switch_event_subclass switch_event_subclass_t;
typedef struct switch_event_node switch_event_node_t;
typedef struct switch_loadable_module switch_loadable_module_t;
typedef struct switch_frame switch_frame_t;
typedef struct switch_rtcp_frame switch_rtcp_frame_t;
typedef struct switch_channel switch_channel_t;
typedef struct switch_file_handle switch_file_handle_t;
typedef struct switch_core_session switch_core_session_t;
......
......@@ -802,6 +802,7 @@ static switch_status_t sofia_read_frame(switch_core_session_t *session, switch_f
switch_channel_t *channel = switch_core_session_get_channel(session);
int payload = 0;
uint32_t sanity = 1000;
switch_rtcp_frame_t rtcp_frame;
switch_assert(tech_pvt != NULL);
......@@ -859,6 +860,50 @@ static switch_status_t sofia_read_frame(switch_core_session_t *session, switch_f
}
return status;
}
/* Try to read an RTCP frame, if successful raise an event */
if (switch_rtcp_zerocopy_read_frame(tech_pvt->rtp_session, &rtcp_frame) == SWITCH_STATUS_SUCCESS) {
switch_event_t *event;
if (switch_event_create(&event, SWITCH_EVENT_RECV_RTCP_MESSAGE) == SWITCH_STATUS_SUCCESS) {
char buf[30];
char* uuid = switch_core_session_get_uuid(session);
if (uuid) {
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Unique-ID", switch_core_session_get_uuid(session));
}
snprintf(buf, sizeof(buf), "%.8x", rtcp_frame.ssrc);
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "SSRC", buf);
snprintf(buf, sizeof(buf), "%u", rtcp_frame.ntp_msw);
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "NTP-Most-Significant-Word", buf);
snprintf(buf, sizeof(buf), "%u", rtcp_frame.ntp_lsw);
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "NTP-Least-Significant-Word", buf);
snprintf(buf, sizeof(buf), "%u", rtcp_frame.timestamp);
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "RTP-Timestamp", buf);
snprintf(buf, sizeof(buf), "%u", rtcp_frame.packet_count);
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Sender-Packet-Count", buf);
snprintf(buf, sizeof(buf), "%u", rtcp_frame.octect_count);
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Octect-Packet-Count", buf);
snprintf(buf, sizeof(buf), "%lu", tech_pvt->read_frame.timestamp);
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Last-RTP-Timestamp", buf);
snprintf(buf, sizeof(buf), "%u", tech_pvt->read_frame.rate);
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "RTP-Rate", buf);
snprintf(buf, sizeof(buf), "%lu", switch_time_now());
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Capture-Time", buf);
switch_event_fire(&event);
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG10, "Dispatched RTCP event\n");
}
}
/* Fast PASS! */
if (switch_test_flag((&tech_pvt->read_frame), SFF_PROXY_PACKET)) {
......
......@@ -466,6 +466,7 @@ struct sofia_profile {
char *record_path;
char *presence_hosts;
char *challenge_realm;
char *rtcp_interval_msec;
sofia_cid_type_t cid_type;
sofia_dtmf_t dtmf_type;
int auto_restart;
......
......@@ -2459,6 +2459,8 @@ switch_status_t reconfig_sofia(sofia_profile_t *profile)
profile->hold_music = switch_core_strdup(profile->pool, val);
} else if (!strcasecmp(var, "outbound-proxy")) {
profile->outbound_proxy = switch_core_strdup(profile->pool, val);
} else if (!strcasecmp(var, "rtcp-interval-msec")) {
profile->rtcp_interval_msec = switch_core_strdup(profile->pool, val);
} else if (!strcasecmp(var, "session-timeout")) {
int v_session_timeout = atoi(val);
if (v_session_timeout >= 0) {
......@@ -2996,6 +2998,8 @@ switch_status_t config_sofia(int reload, char *profile_name)
profile->hold_music = switch_core_strdup(profile->pool, val);
} else if (!strcasecmp(var, "outbound-proxy")) {
profile->outbound_proxy = switch_core_strdup(profile->pool, val);
} else if (!strcasecmp(var, "rtcp-interval-msec")) {
profile->rtcp_interval_msec = switch_core_strdup(profile->pool, val);
} else if (!strcasecmp(var, "session-timeout")) {
int v_session_timeout = atoi(val);
if (v_session_timeout >= 0) {
......
......@@ -2725,6 +2725,15 @@ switch_status_t sofia_glue_activate_rtp(private_object_t *tech_pvt, switch_rtp_f
switch_rtp_activate_stun_ping(tech_pvt->rtp_session, tech_pvt->stun_ip, tech_pvt->stun_port, stun_ping,
(tech_pvt->stun_flags & STUN_FLAG_FUNNY) ? 1 : 0);
}
if ((val = switch_channel_get_variable(tech_pvt->channel, "rtcp_interval_msec")) || (val = tech_pvt->profile->rtcp_interval_msec)) {
int interval = atoi(val);
if (interval < 100 || interval > 5000) {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(tech_pvt->session), SWITCH_LOG_ERROR, "Invalid rtcp interval spec [%d] must be between 100 and 5000\n", interval);
} else {
switch_rtp_activate_rtcp(tech_pvt->rtp_session, interval);
}
}
if ((val = switch_channel_get_variable(tech_pvt->channel, "jitterbuffer_msec"))) {
int len = atoi(val);
......
......@@ -180,6 +180,7 @@ static char *EVENT_NAMES[] = {
"SERVER_DISCONNECTED",
"SEND_INFO",
"RECV_INFO",
"RECV_RTCP_MESSAGE",
"CALL_SECURE",
"NAT",
"RECORD_START",
......
差异被折叠。
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论