From b3ec0eac5fa1d38265b8ba830cd4fd6c8c4fae7b Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Thu, 29 Oct 2009 17:52:52 +0000 Subject: [PATCH] add uuid_debug_audio git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@15274 d0543943-73ff-0310-b7d9-9358b9ac24b2 --- src/include/switch_types.h | 3 +- .../applications/mod_commands/mod_commands.c | 11 ++--- src/mod/endpoints/mod_sofia/mod_sofia.c | 22 ++++++++-- src/switch_rtp.c | 41 ++++++++++++++++--- 4 files changed, 62 insertions(+), 15 deletions(-) diff --git a/src/include/switch_types.h b/src/include/switch_types.h index 07b9670be3..059e50a48b 100644 --- a/src/include/switch_types.h +++ b/src/include/switch_types.h @@ -514,7 +514,8 @@ typedef enum { SWITCH_ZRTP_FLAG_SECURE_RECV = (1 << 24), SWITCH_ZRTP_FLAG_SECURE_MITM_SEND = (1 << 25), SWITCH_ZRTP_FLAG_SECURE_MITM_RECV = (1 << 26), - SWITCH_RTP_FLAG_DEBUG_RTP = (1 << 27) + SWITCH_RTP_FLAG_DEBUG_RTP_READ = (1 << 27), + SWITCH_RTP_FLAG_DEBUG_RTP_WRITE = (1 << 28) } switch_rtp_flag_enum_t; typedef uint32_t switch_rtp_flag_t; diff --git a/src/mod/applications/mod_commands/mod_commands.c b/src/mod/applications/mod_commands/mod_commands.c index a319969d59..f8caf079b7 100644 --- a/src/mod/applications/mod_commands/mod_commands.c +++ b/src/mod/applications/mod_commands/mod_commands.c @@ -2106,10 +2106,10 @@ SWITCH_STANDARD_API(uuid_warning_function) } -#define DEBUG_AUDIO_SYNTAX " " +#define DEBUG_AUDIO_SYNTAX " " SWITCH_STANDARD_API(uuid_debug_audio_function) { - char *mycmd = NULL, *argv[2] = { 0 }; + char *mycmd = NULL, *argv[3] = { 0 }; int argc = 0; switch_status_t status = SWITCH_STATUS_FALSE; @@ -2117,14 +2117,15 @@ SWITCH_STANDARD_API(uuid_debug_audio_function) argc = switch_separate_string(mycmd, ' ', argv, (sizeof(argv) / sizeof(argv[0]))); } - if (zstr(cmd) || argc < 2 || zstr(argv[0]) || zstr(argv[1])) { + if (zstr(cmd) || argc < 3 || zstr(argv[0]) || zstr(argv[1]) || zstr(argv[2])) { stream->write_function(stream, "-USAGE: %s\n", DEBUG_AUDIO_SYNTAX); } else { switch_core_session_message_t msg = { 0 }; switch_core_session_t *lsession = NULL; - + msg.message_id = SWITCH_MESSAGE_INDICATE_DEBUG_AUDIO; - msg.string_arg = argv[1]; + msg.string_array_arg[0] = argv[1]; + msg.string_array_arg[1] = argv[2]; msg.from = __FILE__; if ((lsession = switch_core_session_locate(argv[0]))) { diff --git a/src/mod/endpoints/mod_sofia/mod_sofia.c b/src/mod/endpoints/mod_sofia/mod_sofia.c index 95f6c5c877..891f782193 100644 --- a/src/mod/endpoints/mod_sofia/mod_sofia.c +++ b/src/mod/endpoints/mod_sofia/mod_sofia.c @@ -1082,14 +1082,28 @@ static switch_status_t sofia_receive_message(switch_core_session_t *session, swi switch (msg->message_id) { case SWITCH_MESSAGE_INDICATE_DEBUG_AUDIO: { - if (switch_rtp_ready(tech_pvt->rtp_session)) { - if (switch_true(msg->string_arg)) { - switch_rtp_set_flag(tech_pvt->rtp_session, SWITCH_RTP_FLAG_DEBUG_RTP); + if (switch_rtp_ready(tech_pvt->rtp_session) && !zstr(msg->string_array_arg[0]) && !zstr(msg->string_array_arg[1])) { + int32_t flags = 0; + if (!strcasecmp(msg->string_array_arg[0], "read")) { + flags |= SWITCH_RTP_FLAG_DEBUG_RTP_READ; + } else if (!strcasecmp(msg->string_array_arg[0], "write")) { + flags |= SWITCH_RTP_FLAG_DEBUG_RTP_WRITE; + } else if (!strcasecmp(msg->string_array_arg[0], "both")) { + flags |= SWITCH_RTP_FLAG_DEBUG_RTP_READ | SWITCH_RTP_FLAG_DEBUG_RTP_WRITE; + } + + if (flags) { + if (switch_true(msg->string_array_arg[1])) { + switch_rtp_set_flag(tech_pvt->rtp_session, flags); + } else { + switch_rtp_clear_flag(tech_pvt->rtp_session, flags); + } } else { - switch_rtp_clear_flag(tech_pvt->rtp_session, SWITCH_RTP_FLAG_DEBUG_RTP); + switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Invalid Options\n"); } } } + status = SWITCH_STATUS_FALSE; goto end; case SWITCH_MESSAGE_INDICATE_TRANSCODING_NECESSARY: if (tech_pvt->rtp_session && switch_rtp_test_flag(tech_pvt->rtp_session, SWITCH_RTP_FLAG_PASS_RFC2833)) { diff --git a/src/switch_rtp.c b/src/switch_rtp.c index 1338672f24..631aaafab5 100644 --- a/src/switch_rtp.c +++ b/src/switch_rtp.c @@ -1679,10 +1679,10 @@ static void do_flush(switch_rtp_t *rtp_session) if (switch_rtp_ready(rtp_session)) { - if (switch_test_flag(rtp_session, SWITCH_RTP_FLAG_DEBUG_RTP)) { + if (switch_test_flag(rtp_session, SWITCH_RTP_FLAG_DEBUG_RTP_READ)) { switch_core_session_t *session = switch_core_memory_pool_get_data(rtp_session->pool, "__session"); if (!session) { - switch_clear_flag(rtp_session, SWITCH_RTP_FLAG_DEBUG_RTP); + switch_clear_flag(rtp_session, SWITCH_RTP_FLAG_DEBUG_RTP_READ); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "RTP HAS NO SESSION!\n"); } else { switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), @@ -1904,11 +1904,11 @@ static int rtp_common_read(switch_rtp_t *rtp_session, switch_payload_t *payload_ } - if (bytes && switch_test_flag(rtp_session, SWITCH_RTP_FLAG_DEBUG_RTP)) { + if (bytes && switch_test_flag(rtp_session, SWITCH_RTP_FLAG_DEBUG_RTP_READ)) { switch_core_session_t *session = switch_core_memory_pool_get_data(rtp_session->pool, "__session"); if (!session) { - switch_clear_flag(rtp_session, SWITCH_RTP_FLAG_DEBUG_RTP); + switch_clear_flag(rtp_session, SWITCH_RTP_FLAG_DEBUG_RTP_READ); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "RTP HAS NO SESSION!\n"); } else { const char *tx_host; @@ -1923,7 +1923,7 @@ static int rtp_common_read(switch_rtp_t *rtp_session, switch_payload_t *payload_ my_host = switch_get_addr(bufc, sizeof(bufc), rtp_session->local_addr); switch_log_printf(SWITCH_CHANNEL_SESSION_LOG_CLEAN(session), SWITCH_LOG_CONSOLE, - "%s b=%ld %s:%u %s:%u %s:%u pt=%d ts=%u m=%d\n", + "R %s b=%ld %s:%u %s:%u %s:%u pt=%d ts=%u m=%d\n", switch_channel_get_name(switch_core_session_get_channel(session)), (long)bytes, my_host, switch_sockaddr_get_port(rtp_session->local_addr), @@ -2748,6 +2748,37 @@ static int rtp_common_write(switch_rtp_t *rtp_session, #endif + if (switch_test_flag(rtp_session, SWITCH_RTP_FLAG_DEBUG_RTP_WRITE)) { + switch_core_session_t *session = switch_core_memory_pool_get_data(rtp_session->pool, "__session"); + + if (!session) { + switch_clear_flag(rtp_session, SWITCH_RTP_FLAG_DEBUG_RTP_WRITE); + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "RTP HAS NO SESSION!\n"); + } else { + const char *tx_host; + const char *old_host; + const char *my_host; + + char bufa[30], bufb[30], bufc[30]; + + + tx_host = switch_get_addr(bufa, sizeof(bufa), rtp_session->from_addr); + old_host = switch_get_addr(bufb, sizeof(bufb), rtp_session->remote_addr); + my_host = switch_get_addr(bufc, sizeof(bufc), rtp_session->local_addr); + + switch_log_printf(SWITCH_CHANNEL_SESSION_LOG_CLEAN(session), SWITCH_LOG_CONSOLE, + "W %s b=%ld %s:%u %s:%u %s:%u pt=%d ts=%u m=%d\n", + switch_channel_get_name(switch_core_session_get_channel(session)), + (long)bytes, + my_host, switch_sockaddr_get_port(rtp_session->local_addr), + old_host, rtp_session->remote_port, + tx_host, switch_sockaddr_get_port(rtp_session->from_addr), + send_msg->header.pt, ntohl(send_msg->header.ts), send_msg->header.m); + + } + } + + if (switch_socket_sendto(rtp_session->sock_output, rtp_session->remote_addr, 0, (void *) send_msg, &bytes) != SWITCH_STATUS_SUCCESS) { rtp_session->seq--; ret = -1;