misc changes

git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@6550 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
Anthony Minessale 2007-12-06 22:26:37 +00:00
parent 5526800e90
commit 836f55ba33
10 changed files with 80 additions and 15 deletions

View File

@ -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);

View File

@ -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;
/*!

View File

@ -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;

View File

@ -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) {

View File

@ -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;
}
@ -1053,7 +1056,8 @@ void do_telecast(switch_stream_handle_t *stream)
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,9 +1077,14 @@ 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);
goto end;

View File

@ -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);
}

View File

@ -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);

View File

@ -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",

View File

@ -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];
@ -254,7 +254,7 @@ 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);

View File

@ -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;
}