From 836f55ba33f121b9e39eeb5f1fa618df971a0a78 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Thu, 6 Dec 2007 22:26:37 +0000 Subject: [PATCH] misc changes git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@6550 d0543943-73ff-0310-b7d9-9358b9ac24b2 --- src/include/switch_apr.h | 2 +- src/include/switch_types.h | 6 ++- .../endpoints/mod_dingaling/mod_dingaling.c | 4 ++ src/mod/endpoints/mod_sofia/mod_sofia.c | 4 ++ src/mod/formats/mod_shout/mod_shout.c | 15 ++++++-- src/switch_apr.c | 5 ++- src/switch_core_io.c | 38 ++++++++++++++++++- src/switch_ivr_bridge.c | 4 ++ src/switch_rtp.c | 13 ++++--- src/switch_utils.c | 4 +- 10 files changed, 80 insertions(+), 15 deletions(-) diff --git a/src/include/switch_apr.h b/src/include/switch_apr.h index b4a0d96184..e7e639b3d6 100644 --- a/src/include/switch_apr.h +++ b/src/include/switch_apr.h @@ -964,7 +964,7 @@ SWITCH_DECLARE(switch_status_t) switch_socket_accept(switch_socket_t ** new_sock SWITCH_DECLARE(switch_status_t) switch_socket_connect(switch_socket_t * sock, switch_sockaddr_t * sa); SWITCH_DECLARE(uint16_t) switch_sockaddr_get_port(switch_sockaddr_t * sa); -SWITCH_DECLARE(char *) switch_get_addr(char *buf, switch_size_t len, switch_sockaddr_t * in); +SWITCH_DECLARE(const char *) switch_get_addr(char *buf, switch_size_t len, switch_sockaddr_t * in); SWITCH_DECLARE(int32_t) switch_sockaddr_get_family(switch_sockaddr_t * sa); SWITCH_DECLARE(switch_status_t) switch_sockaddr_ip_get(char **addr, switch_sockaddr_t * sa); diff --git a/src/include/switch_types.h b/src/include/switch_types.h index 784f9c6d65..4d7f09f951 100644 --- a/src/include/switch_types.h +++ b/src/include/switch_types.h @@ -239,6 +239,7 @@ typedef enum { SWITCH_ABC_TYPE_WRITE, SWITCH_ABC_TYPE_WRITE_REPLACE, SWITCH_ABC_TYPE_READ_REPLACE, + SWITCH_ABC_TYPE_READ_PING, SWITCH_ABC_TYPE_CLOSE } switch_abc_type_t; @@ -806,8 +807,9 @@ typedef enum { SMBF_WRITE_STREAM = (1 << 1), SMBF_WRITE_REPLACE = (1 << 2), SMBF_READ_REPLACE = (1 << 3), - SMBF_STEREO = (1 << 4), - SMBF_RECORD_ANSWER_REQ = (1 << 5) + SMBF_READ_PING = (1 << 4), + SMBF_STEREO = (1 << 5), + SMBF_RECORD_ANSWER_REQ = (1 << 6) } switch_media_bug_flag_t; /*! diff --git a/src/mod/endpoints/mod_dingaling/mod_dingaling.c b/src/mod/endpoints/mod_dingaling/mod_dingaling.c index 844a5c7bc1..983ef7f077 100644 --- a/src/mod/endpoints/mod_dingaling/mod_dingaling.c +++ b/src/mod/endpoints/mod_dingaling/mod_dingaling.c @@ -1525,18 +1525,22 @@ static switch_status_t channel_receive_message(switch_core_session_t *session, s channel_answer_channel(session); break; case SWITCH_MESSAGE_INDICATE_BRIDGE: + /* if (tech_pvt->rtp_session && switch_test_flag(tech_pvt->profile, TFLAG_TIMER)) { 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"); //switch_rtp_set_flag(tech_pvt->rtp_session, SWITCH_RTP_FLAG_TIMER_RECLOCK); } + */ break; case SWITCH_MESSAGE_INDICATE_UNBRIDGE: + /* if (tech_pvt->rtp_session && switch_test_flag(tech_pvt->profile, TFLAG_TIMER)) { 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"); //switch_rtp_clear_flag(tech_pvt->rtp_session, SWITCH_RTP_FLAG_TIMER_RECLOCK); } + */ break; default: break; diff --git a/src/mod/endpoints/mod_sofia/mod_sofia.c b/src/mod/endpoints/mod_sofia/mod_sofia.c index e960207233..92b9584996 100644 --- a/src/mod/endpoints/mod_sofia/mod_sofia.c +++ b/src/mod/endpoints/mod_sofia/mod_sofia.c @@ -805,16 +805,20 @@ static switch_status_t sofia_receive_message(switch_core_session_t *session, swi return SWITCH_STATUS_FALSE; } } + /* if (tech_pvt->rtp_session && switch_test_flag(tech_pvt, TFLAG_TIMER)) { 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_test_flag(tech_pvt, TFLAG_TIMER)) { 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; case SWITCH_MESSAGE_INDICATE_REDIRECT: if (msg->string_arg) { diff --git a/src/mod/formats/mod_shout/mod_shout.c b/src/mod/formats/mod_shout/mod_shout.c index 643f44a2fb..6863703a7f 100644 --- a/src/mod/formats/mod_shout/mod_shout.c +++ b/src/mod/formats/mod_shout/mod_shout.c @@ -932,7 +932,7 @@ static switch_bool_t telecast_callback(switch_media_bug_t *bug, void *user_data, break; case SWITCH_ABC_TYPE_CLOSE: break; - case SWITCH_ABC_TYPE_WRITE: + case SWITCH_ABC_TYPE_READ_PING: if (buffer) { if (switch_core_media_bug_read(bug, &frame) == SWITCH_STATUS_SUCCESS) { switch_buffer_lock(buffer); @@ -943,7 +943,10 @@ static switch_bool_t telecast_callback(switch_media_bug_t *bug, void *user_data, return SWITCH_FALSE; } break; + case SWITCH_ABC_TYPE_READ: + case SWITCH_ABC_TYPE_WRITE: + default: break; } @@ -1052,8 +1055,9 @@ void do_telecast(switch_stream_handle_t *stream) switch_mutex_init(&mutex, SWITCH_MUTEX_NESTED, switch_core_session_get_pool(tsession)); switch_buffer_create_dynamic(&buffer, 1024, 2048, 0); switch_buffer_add_mutex(buffer, mutex); - - if (switch_core_media_bug_add(tsession, telecast_callback, buffer, 0, SMBF_READ_STREAM | SMBF_WRITE_STREAM, &bug) != SWITCH_STATUS_SUCCESS) { + + if (switch_core_media_bug_add(tsession, telecast_callback, buffer, 0, + SMBF_READ_STREAM | SMBF_WRITE_STREAM | SMBF_READ_PING, &bug) != SWITCH_STATUS_SUCCESS) { goto end; } @@ -1073,8 +1077,13 @@ void do_telecast(switch_stream_handle_t *stream) bytes = switch_buffer_read(buffer, buf, sizeof(buf)); switch_buffer_unlock(buffer); } else { + if (!bytes) { + switch_yield(1000); + continue; + } memset(buf, 0, bytes); } + if ((rlen = lame_encode_buffer(gfp, (void *)buf, NULL, bytes / 2, mp3buf, sizeof(mp3buf))) < 0) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "MP3 encode error %d!\n", rlen); diff --git a/src/switch_apr.c b/src/switch_apr.c index 2f34e001f7..e5beea84dd 100644 --- a/src/switch_apr.c +++ b/src/switch_apr.c @@ -646,8 +646,11 @@ SWITCH_DECLARE(switch_status_t) switch_mcast_join(switch_socket_t * sock, switch /* socket functions */ -SWITCH_DECLARE(char *) switch_get_addr(char *buf, switch_size_t len, switch_sockaddr_t * in) +SWITCH_DECLARE(const char *) switch_get_addr(char *buf, switch_size_t len, switch_sockaddr_t * in) { + if (!in) { + return ""; + } return get_addr(buf, len, &in->sa.sin.sin_addr); } diff --git a/src/switch_core_io.c b/src/switch_core_io.c index f08a7f0811..2ad20ed51b 100644 --- a/src/switch_core_io.c +++ b/src/switch_core_io.c @@ -131,6 +131,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_read_frame(switch_core_sessi assert(session != NULL); assert(*frame != NULL); + if (switch_test_flag(*frame, SFF_CNG)) { status = SWITCH_STATUS_SUCCESS; goto done; @@ -367,6 +368,40 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_read_frame(switch_core_sessi if (flag & SFF_CNG) { switch_set_flag((*frame), SFF_CNG); } + if (session->bugs) { + switch_media_bug_t *bp, *dp, *last = NULL; + switch_bool_t ok = SWITCH_TRUE; + switch_thread_rwlock_rdlock(session->bug_rwlock); + for (bp = session->bugs; bp; bp = bp->next) { + if (bp->ready && switch_test_flag(bp, SMBF_READ_PING)) { + switch_mutex_lock(bp->read_mutex); + if (bp->callback) { + if (bp->callback(bp, bp->user_data, SWITCH_ABC_TYPE_READ_PING) == SWITCH_FALSE || (bp->stop_time && bp->stop_time <= time(NULL))) { + ok = SWITCH_FALSE; + } + } + switch_mutex_unlock(bp->read_mutex); + } + + if (ok == SWITCH_FALSE) { + bp->ready = 0; + if (last) { + last->next = bp->next; + } else { + session->bugs = bp->next; + } + dp = bp; + bp = last; + switch_core_media_bug_close(&dp); + if (!bp) { + break; + } + continue; + } + last = bp; + } + switch_thread_rwlock_unlock(session->bug_rwlock); + } } return status; @@ -512,7 +547,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_write_frame(switch_core_sess write_frame->rate = session->write_resampler->to_rate; } - if (do_bugs) { + if (!do_bugs) { do_write = 1; write_frame = frame; goto done; @@ -528,6 +563,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_write_frame(switch_core_sess continue; } if (switch_test_flag(bp, SMBF_WRITE_STREAM)) { + switch_mutex_lock(bp->write_mutex); switch_buffer_write(bp->raw_write_buffer, write_frame->data, write_frame->datalen); switch_mutex_unlock(bp->write_mutex); diff --git a/src/switch_ivr_bridge.c b/src/switch_ivr_bridge.c index fc29c5d19e..9c95248223 100644 --- a/src/switch_ivr_bridge.c +++ b/src/switch_ivr_bridge.c @@ -168,6 +168,10 @@ static void *audio_bridge_thread(switch_thread_t * thread, void *obj) status = switch_core_session_read_frame(session_a, &read_frame, -1, stream_id); if (SWITCH_READ_ACCEPTABLE(status)) { + if (switch_test_flag(read_frame, SFF_CNG)) { + continue; + } + if (status != SWITCH_STATUS_BREAK && !switch_channel_test_flag(chan_a, CF_HOLD)) { if (switch_core_session_write_frame(session_b, read_frame, -1, stream_id) != SWITCH_STATUS_SUCCESS) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "write: %s Bad Frame....[%u] Bubye!\n", diff --git a/src/switch_rtp.c b/src/switch_rtp.c index fcc9599afb..f523372656 100644 --- a/src/switch_rtp.c +++ b/src/switch_rtp.c @@ -242,7 +242,7 @@ static void handle_ice(switch_rtp_t *rtp_session, void *data, switch_size_t len) if ((packet->header.type == SWITCH_STUN_BINDING_REQUEST) && !strcmp(rtp_session->user_ice, username)) { uint8_t buf[512]; switch_stun_packet_t *rpacket; - char *remote_ip; + const char *remote_ip; switch_size_t bytes; char ipbuf[25]; @@ -253,8 +253,8 @@ static void handle_ice(switch_rtp_t *rtp_session, void *data, switch_size_t len) remote_ip = switch_get_addr(ipbuf, sizeof(ipbuf), rtp_session->from_addr); - - switch_stun_packet_attribute_add_binded_address(rpacket, remote_ip, switch_sockaddr_get_port(rtp_session->from_addr)); + + switch_stun_packet_attribute_add_binded_address(rpacket, (char *)remote_ip, switch_sockaddr_get_port(rtp_session->from_addr)); bytes = switch_stun_packet_length(rpacket); switch_socket_sendto(rtp_session->sock, rtp_session->from_addr, 0, (void *) rpacket, &bytes); } @@ -424,7 +424,8 @@ SWITCH_DECLARE(switch_status_t) switch_rtp_set_remote_address(switch_rtp_t *rtp_ { *err = "Success"; - if (switch_sockaddr_info_get(&rtp_session->remote_addr, host, SWITCH_UNSPEC, port, 0, rtp_session->pool) != SWITCH_STATUS_SUCCESS) { + if (switch_sockaddr_info_get(&rtp_session->remote_addr, host, SWITCH_UNSPEC, port, 0, rtp_session->pool) + != SWITCH_STATUS_SUCCESS || !rtp_session->remote_addr) { *err = "Remote Address Error!"; return SWITCH_STATUS_FALSE; } @@ -1005,8 +1006,8 @@ static int rtp_common_read(switch_rtp_t *rtp_session, switch_payload_t *payload_ if (bytes && switch_test_flag(rtp_session, SWITCH_RTP_FLAG_AUTOADJ) && switch_sockaddr_get_port(rtp_session->from_addr)) { - char *tx_host; - char *old_host; + const char *tx_host; + const char *old_host; char bufa[30], bufb[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); diff --git a/src/switch_utils.c b/src/switch_utils.c index 1db452ebba..b8d7e7a9e2 100644 --- a/src/switch_utils.c +++ b/src/switch_utils.c @@ -899,7 +899,9 @@ SWITCH_DECLARE(char *) get_addr(char *buf, switch_size_t len, struct in_addr *in { assert(buf); *buf = '\0'; - inet_ntop(AF_INET, in, buf, len); + if (in) { + inet_ntop(AF_INET, in, buf, len); + } return buf; }