mirror of
https://github.com/signalwire/freeswitch.git
synced 2025-04-16 08:49:01 +00:00
improvements
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@1176 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
parent
026e8d39ca
commit
c3a77d23bb
@ -651,7 +651,7 @@ DoxyDefine(apr_status_t switch_socket_recvfrom(switch_sockaddr_t *from,
|
|||||||
apr_int32_t flags,
|
apr_int32_t flags,
|
||||||
char *buf,
|
char *buf,
|
||||||
apr_size_t *len);)
|
apr_size_t *len);)
|
||||||
#define switch_socket_recvfrom apr_socket_recvfrom
|
//#define switch_socket_recvfrom apr_socket_recvfrom
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Send a file from an open file descriptor to a socket, along with
|
* Send a file from an open file descriptor to a socket, along with
|
||||||
|
@ -156,6 +156,28 @@ SWITCH_DECLARE(void) switch_rtp_destroy(switch_rtp **rtp_session);
|
|||||||
*/
|
*/
|
||||||
SWITCH_DECLARE(switch_status) switch_rtp_activate_ice(switch_rtp *rtp_session, char *login, char *rlogin);
|
SWITCH_DECLARE(switch_status) switch_rtp_activate_ice(switch_rtp *rtp_session, char *login, char *rlogin);
|
||||||
|
|
||||||
|
/*!
|
||||||
|
\brief Set an RTP Flag
|
||||||
|
\param rtp_session the RTP session
|
||||||
|
\param flags the flags to set
|
||||||
|
*/
|
||||||
|
SWITCH_DECLARE(void) switch_rtp_set_flag(switch_rtp *rtp_session, switch_rtp_flag_t flags);
|
||||||
|
|
||||||
|
/*!
|
||||||
|
\brief Test an RTP Flag
|
||||||
|
\param rtp_session the RTP session
|
||||||
|
\param flags the flags to test
|
||||||
|
\return TRUE or FALSE
|
||||||
|
*/
|
||||||
|
SWITCH_DECLARE(uint8_t) switch_rtp_test_flag(switch_rtp *rtp_session, switch_rtp_flag_t flags);
|
||||||
|
|
||||||
|
/*!
|
||||||
|
\brief Clear an RTP Flag
|
||||||
|
\param rtp_session the RTP session
|
||||||
|
\param flags the flags to clear
|
||||||
|
*/
|
||||||
|
SWITCH_DECLARE(void) switch_rtp_clear_flag(switch_rtp *rtp_session, switch_rtp_flag_t flags);
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief Retrieve the socket from an existing RTP session
|
\brief Retrieve the socket from an existing RTP session
|
||||||
\param rtp_session the RTP session to retrieve the socket from
|
\param rtp_session the RTP session to retrieve the socket from
|
||||||
|
@ -102,13 +102,15 @@ SWITCH_DECLARE_DATA extern switch_directories SWITCH_GLOBAL_dirs;
|
|||||||
SWITCH_RTP_FLAG_IO - IO is ready
|
SWITCH_RTP_FLAG_IO - IO is ready
|
||||||
SWITCH_RTP_FLAG_USE_TIMER - Timeout Reads and replace with a CNG Frame
|
SWITCH_RTP_FLAG_USE_TIMER - Timeout Reads and replace with a CNG Frame
|
||||||
SWITCH_RTP_FLAG_SECURE - Secure RTP
|
SWITCH_RTP_FLAG_SECURE - Secure RTP
|
||||||
|
SWITCH_RTP_FLAG_AUTOADJ - Auto-Adjust the dest based on the source
|
||||||
</pre>
|
</pre>
|
||||||
*/
|
*/
|
||||||
typedef enum {
|
typedef enum {
|
||||||
SWITCH_RTP_FLAG_NOBLOCK = ( 1 << 0),
|
SWITCH_RTP_FLAG_NOBLOCK = ( 1 << 0),
|
||||||
SWITCH_RTP_FLAG_IO = (1 << 1),
|
SWITCH_RTP_FLAG_IO = (1 << 1),
|
||||||
SWITCH_RTP_FLAG_USE_TIMER = (1 << 2),
|
SWITCH_RTP_FLAG_USE_TIMER = (1 << 2),
|
||||||
SWITCH_RTP_FLAG_SECURE = (1 << 3)
|
SWITCH_RTP_FLAG_SECURE = (1 << 3),
|
||||||
|
SWITCH_RTP_FLAG_AUTOADJ = (1 << 4)
|
||||||
} switch_rtp_flag_t;
|
} switch_rtp_flag_t;
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@ -148,12 +150,16 @@ typedef enum {
|
|||||||
SWITCH_MESSAGE_REDIRECT_AUDIO - Indication to redirect audio to another location if possible
|
SWITCH_MESSAGE_REDIRECT_AUDIO - Indication to redirect audio to another location if possible
|
||||||
SWITCH_MESSAGE_TRANSMIT_TEXT - A text message
|
SWITCH_MESSAGE_TRANSMIT_TEXT - A text message
|
||||||
SWITCH_MESSAGE_INDICATE_PROGRESS - indicate progress
|
SWITCH_MESSAGE_INDICATE_PROGRESS - indicate progress
|
||||||
|
SWITCH_MESSAGE_INDICATE_BRIDGE - indicate a bridge starting
|
||||||
|
SWITCH_MESSAGE_INDICATE_UNBRIDGE - indicate a bridge ending
|
||||||
</pre>
|
</pre>
|
||||||
*/
|
*/
|
||||||
typedef enum {
|
typedef enum {
|
||||||
SWITCH_MESSAGE_REDIRECT_AUDIO,
|
SWITCH_MESSAGE_REDIRECT_AUDIO,
|
||||||
SWITCH_MESSAGE_TRANSMIT_TEXT,
|
SWITCH_MESSAGE_TRANSMIT_TEXT,
|
||||||
SWITCH_MESSAGE_INDICATE_PROGRESS
|
SWITCH_MESSAGE_INDICATE_PROGRESS,
|
||||||
|
SWITCH_MESSAGE_INDICATE_BRIDGE,
|
||||||
|
SWITCH_MESSAGE_INDICATE_UNBRIDGE
|
||||||
} switch_core_session_message_t;
|
} switch_core_session_message_t;
|
||||||
|
|
||||||
|
|
||||||
|
@ -65,6 +65,9 @@ extern "C" {
|
|||||||
!strcasecmp(expr, "true") ||\
|
!strcasecmp(expr, "true") ||\
|
||||||
atoi(expr))) ? SWITCH_TRUE : SWITCH_FALSE
|
atoi(expr))) ? SWITCH_TRUE : SWITCH_FALSE
|
||||||
|
|
||||||
|
|
||||||
|
SWITCH_DECLARE(switch_status) switch_socket_recvfrom(switch_sockaddr_t *from, switch_socket_t *sock, int32_t flags, char *buf, switch_size_t *len);
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief Return a printable name of a switch_priority_t
|
\brief Return a printable name of a switch_priority_t
|
||||||
\param priority the priority to get the name of
|
\param priority the priority to get the name of
|
||||||
|
@ -271,7 +271,7 @@ static int activate_rtp(struct private_object *tech_pvt)
|
|||||||
tech_pvt->codec_num,
|
tech_pvt->codec_num,
|
||||||
tech_pvt->read_codec.implementation->encoded_bytes_per_frame,
|
tech_pvt->read_codec.implementation->encoded_bytes_per_frame,
|
||||||
tech_pvt->read_codec.implementation->microseconds_per_frame,
|
tech_pvt->read_codec.implementation->microseconds_per_frame,
|
||||||
SWITCH_RTP_FLAG_USE_TIMER,
|
SWITCH_RTP_FLAG_USE_TIMER | SWITCH_RTP_FLAG_AUTOADJ,
|
||||||
NULL,
|
NULL,
|
||||||
&err, switch_core_session_get_pool(tech_pvt->session)))) {
|
&err, switch_core_session_get_pool(tech_pvt->session)))) {
|
||||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "RTP ERROR %s\n", err);
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "RTP ERROR %s\n", err);
|
||||||
@ -887,6 +887,37 @@ static switch_status channel_answer_channel(switch_core_session *session)
|
|||||||
return SWITCH_STATUS_SUCCESS;
|
return SWITCH_STATUS_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static switch_status channel_receive_message(switch_core_session *session, switch_core_session_message *msg)
|
||||||
|
{
|
||||||
|
switch_channel *channel;
|
||||||
|
struct private_object *tech_pvt;
|
||||||
|
|
||||||
|
channel = switch_core_session_get_channel(session);
|
||||||
|
assert(channel != NULL);
|
||||||
|
|
||||||
|
tech_pvt = switch_core_session_get_private(session);
|
||||||
|
assert(tech_pvt != NULL);
|
||||||
|
|
||||||
|
switch (msg->message_id) {
|
||||||
|
case SWITCH_MESSAGE_INDICATE_BRIDGE:
|
||||||
|
if (tech_pvt->rtp_session) {
|
||||||
|
switch_rtp_clear_flag(tech_pvt->rtp_session, SWITCH_RTP_FLAG_USE_TIMER);
|
||||||
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "De-activate timed RTP!\n");
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case SWITCH_MESSAGE_INDICATE_UNBRIDGE:
|
||||||
|
if (tech_pvt->rtp_session) {
|
||||||
|
switch_rtp_set_flag(tech_pvt->rtp_session, SWITCH_RTP_FLAG_USE_TIMER);
|
||||||
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Re-activate timed RTP!\n");
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return SWITCH_STATUS_SUCCESS;
|
||||||
|
}
|
||||||
static const switch_state_handler_table channel_event_handlers = {
|
static const switch_state_handler_table channel_event_handlers = {
|
||||||
/*.on_init */ channel_on_init,
|
/*.on_init */ channel_on_init,
|
||||||
/*.on_ring */ channel_on_ring,
|
/*.on_ring */ channel_on_ring,
|
||||||
@ -904,7 +935,8 @@ static const switch_io_routines channel_io_routines = {
|
|||||||
/*.kill_channel */ channel_kill_channel,
|
/*.kill_channel */ channel_kill_channel,
|
||||||
/*.waitfor_read */ channel_waitfor_read,
|
/*.waitfor_read */ channel_waitfor_read,
|
||||||
/*.waitfor_write */ channel_waitfor_write,
|
/*.waitfor_write */ channel_waitfor_write,
|
||||||
/*.send_dtmf */ channel_send_dtmf
|
/*.send_dtmf */ channel_send_dtmf,
|
||||||
|
/*.receive_message*/ channel_receive_message
|
||||||
};
|
};
|
||||||
|
|
||||||
static const switch_endpoint_interface channel_endpoint_interface = {
|
static const switch_endpoint_interface channel_endpoint_interface = {
|
||||||
|
@ -927,15 +927,28 @@ SWITCH_DECLARE(switch_status) switch_ivr_multi_threaded_bridge(switch_core_sessi
|
|||||||
|
|
||||||
if (switch_channel_test_flag(peer_channel, CF_ANSWERED) || switch_channel_test_flag(peer_channel, CF_EARLY_MEDIA)) {
|
if (switch_channel_test_flag(peer_channel, CF_ANSWERED) || switch_channel_test_flag(peer_channel, CF_EARLY_MEDIA)) {
|
||||||
switch_event *event;
|
switch_event *event;
|
||||||
|
switch_core_session_message msg = {0};
|
||||||
|
|
||||||
if (switch_event_create(&event, SWITCH_EVENT_CHANNEL_BRIDGE) == SWITCH_STATUS_SUCCESS) {
|
if (switch_event_create(&event, SWITCH_EVENT_CHANNEL_BRIDGE) == SWITCH_STATUS_SUCCESS) {
|
||||||
switch_channel_event_set_data(caller_channel, event);
|
switch_channel_event_set_data(caller_channel, event);
|
||||||
switch_event_fire(&event);
|
switch_event_fire(&event);
|
||||||
}
|
}
|
||||||
|
|
||||||
switch_core_session_launch_thread(session, audio_bridge_thread, (void *) &other_audio_thread);
|
msg.message_id = SWITCH_MESSAGE_INDICATE_BRIDGE;
|
||||||
|
msg.from = __FILE__;
|
||||||
|
msg.pointer_arg = session;
|
||||||
|
switch_core_session_receive_message(peer_session, &msg);
|
||||||
|
msg.pointer_arg = peer_session;
|
||||||
|
switch_core_session_receive_message(session, &msg);
|
||||||
|
|
||||||
|
switch_core_session_launch_thread(peer_session, audio_bridge_thread, (void *) &other_audio_thread);
|
||||||
audio_bridge_thread(NULL, (void *) &this_audio_thread);
|
audio_bridge_thread(NULL, (void *) &this_audio_thread);
|
||||||
|
|
||||||
|
msg.pointer_arg = NULL;
|
||||||
|
msg.message_id = SWITCH_MESSAGE_INDICATE_UNBRIDGE;
|
||||||
|
switch_core_session_receive_message(peer_session, &msg);
|
||||||
|
switch_core_session_receive_message(session, &msg);
|
||||||
|
|
||||||
if (switch_event_create(&event, SWITCH_EVENT_CHANNEL_UNBRIDGE) == SWITCH_STATUS_SUCCESS) {
|
if (switch_event_create(&event, SWITCH_EVENT_CHANNEL_UNBRIDGE) == SWITCH_STATUS_SUCCESS) {
|
||||||
switch_channel_event_set_data(caller_channel, event);
|
switch_channel_event_set_data(caller_channel, event);
|
||||||
switch_event_fire(&event);
|
switch_event_fire(&event);
|
||||||
|
@ -86,6 +86,7 @@ struct switch_rtp {
|
|||||||
switch_time_t last_read;
|
switch_time_t last_read;
|
||||||
switch_time_t next_read;
|
switch_time_t next_read;
|
||||||
uint32_t ms_per_packet;
|
uint32_t ms_per_packet;
|
||||||
|
uint32_t remote_port;
|
||||||
uint8_t stuncount;
|
uint8_t stuncount;
|
||||||
switch_buffer *packet_buffer;
|
switch_buffer *packet_buffer;
|
||||||
};
|
};
|
||||||
@ -168,6 +169,7 @@ static void handle_ice(switch_rtp *rtp_session, void *data, switch_size_t len)
|
|||||||
switch_sockaddr_ip_get(&remote_ip, rtp_session->from_addr);
|
switch_sockaddr_ip_get(&remote_ip, rtp_session->from_addr);
|
||||||
switch_stun_packet_attribute_add_binded_address(rpacket, remote_ip, rtp_session->from_addr->port);
|
switch_stun_packet_attribute_add_binded_address(rpacket, remote_ip, rtp_session->from_addr->port);
|
||||||
bytes = switch_stun_packet_length(rpacket);
|
bytes = switch_stun_packet_length(rpacket);
|
||||||
|
|
||||||
switch_socket_sendto(rtp_session->sock, rtp_session->from_addr, 0, (void*)rpacket, &bytes);
|
switch_socket_sendto(rtp_session->sock, rtp_session->from_addr, 0, (void*)rpacket, &bytes);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -239,6 +241,8 @@ SWITCH_DECLARE(switch_status) switch_rtp_set_remote_address(switch_rtp *rtp_sess
|
|||||||
return SWITCH_STATUS_FALSE;
|
return SWITCH_STATUS_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
rtp_session->remote_port = port;
|
||||||
|
|
||||||
return SWITCH_STATUS_SUCCESS;
|
return SWITCH_STATUS_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -462,17 +466,41 @@ SWITCH_DECLARE(void) switch_rtp_set_invald_handler(switch_rtp *rtp_session, swit
|
|||||||
rtp_session->invalid_handler = on_invalid;
|
rtp_session->invalid_handler = on_invalid;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SWITCH_DECLARE(void) switch_rtp_set_flag(switch_rtp *rtp_session, switch_rtp_flag_t flags)
|
||||||
|
{
|
||||||
|
|
||||||
|
switch_set_flag(rtp_session, flags);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
SWITCH_DECLARE(uint8_t) switch_rtp_test_flag(switch_rtp *rtp_session, switch_rtp_flag_t flags)
|
||||||
|
{
|
||||||
|
|
||||||
|
return (uint8_t) switch_test_flag(rtp_session, flags);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
SWITCH_DECLARE(void) switch_rtp_clear_flag(switch_rtp *rtp_session, switch_rtp_flag_t flags)
|
||||||
|
{
|
||||||
|
|
||||||
|
switch_clear_flag(rtp_session, flags);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
static int rtp_common_read(switch_rtp *rtp_session, void *data, int *payload_type, switch_frame_flag *flags)
|
static int rtp_common_read(switch_rtp *rtp_session, void *data, int *payload_type, switch_frame_flag *flags)
|
||||||
{
|
{
|
||||||
switch_size_t bytes;
|
switch_size_t bytes;
|
||||||
switch_status status;
|
switch_status status;
|
||||||
|
|
||||||
|
|
||||||
for(;;) {
|
for(;;) {
|
||||||
bytes = sizeof(rtp_msg_t);
|
bytes = sizeof(rtp_msg_t);
|
||||||
status = switch_socket_recvfrom(rtp_session->from_addr, rtp_session->sock, 0, (void *)&rtp_session->recv_msg, &bytes);
|
status = switch_socket_recvfrom(rtp_session->from_addr, rtp_session->sock, 0, (void *)&rtp_session->recv_msg, &bytes);
|
||||||
|
|
||||||
|
if (switch_test_flag(rtp_session, SWITCH_RTP_FLAG_AUTOADJ) && rtp_session->from_addr->port != rtp_session->remote_port) {
|
||||||
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Auto Changing port to %u\n", rtp_session->from_addr->port);
|
||||||
|
rtp_session->remote_addr->port = rtp_session->from_addr->port;
|
||||||
|
}
|
||||||
|
|
||||||
if (!switch_test_flag(rtp_session, SWITCH_RTP_FLAG_IO)) {
|
if (!switch_test_flag(rtp_session, SWITCH_RTP_FLAG_IO)) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -497,6 +525,7 @@ static int rtp_common_read(switch_rtp *rtp_session, void *data, int *payload_typ
|
|||||||
if (switch_test_flag(rtp_session, SWITCH_RTP_FLAG_USE_TIMER)) {
|
if (switch_test_flag(rtp_session, SWITCH_RTP_FLAG_USE_TIMER)) {
|
||||||
if ((switch_time_now() - rtp_session->next_read) > 1000) {
|
if ((switch_time_now() - rtp_session->next_read) > 1000) {
|
||||||
/* We're late! We're Late!*/
|
/* We're late! We're Late!*/
|
||||||
|
printf("late\n");
|
||||||
memset(&rtp_session->recv_msg, 0, SWITCH_RTP_CNG_PAYLOAD);
|
memset(&rtp_session->recv_msg, 0, SWITCH_RTP_CNG_PAYLOAD);
|
||||||
rtp_session->recv_msg.header.pt = SWITCH_RTP_CNG_PAYLOAD;
|
rtp_session->recv_msg.header.pt = SWITCH_RTP_CNG_PAYLOAD;
|
||||||
*flags |= SFF_CNG;
|
*flags |= SFF_CNG;
|
||||||
|
@ -34,6 +34,16 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
SWITCH_DECLARE(switch_status) switch_socket_recvfrom(switch_sockaddr_t *from, switch_socket_t *sock, int32_t flags, char *buf, switch_size_t *len)
|
||||||
|
{
|
||||||
|
switch_status status;
|
||||||
|
|
||||||
|
if ((status = apr_socket_recvfrom(from, sock, flags, buf, len)) == SWITCH_STATUS_SUCCESS) {
|
||||||
|
from->port = ntohs(from->sa.sin.sin_port);
|
||||||
|
}
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
SWITCH_DECLARE(char *) switch_priority_name(switch_priority_t priority)
|
SWITCH_DECLARE(char *) switch_priority_name(switch_priority_t priority)
|
||||||
{
|
{
|
||||||
switch(priority) { /*lol*/
|
switch(priority) { /*lol*/
|
||||||
|
Loading…
x
Reference in New Issue
Block a user