]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
misc changes
authorAnthony Minessale <anthony.minessale@gmail.com>
Thu, 6 Dec 2007 22:26:37 +0000 (22:26 +0000)
committerAnthony Minessale <anthony.minessale@gmail.com>
Thu, 6 Dec 2007 22:26:37 +0000 (22:26 +0000)
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@6550 d0543943-73ff-0310-b7d9-9358b9ac24b2

src/include/switch_apr.h
src/include/switch_types.h
src/mod/endpoints/mod_dingaling/mod_dingaling.c
src/mod/endpoints/mod_sofia/mod_sofia.c
src/mod/formats/mod_shout/mod_shout.c
src/switch_apr.c
src/switch_core_io.c
src/switch_ivr_bridge.c
src/switch_rtp.c
src/switch_utils.c

index b4a0d96184b17674804f87a30a3de7170d6047cd..e7e639b3d6563f9d996d468454b08620dfcdfff7 100644 (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);
 
index 784f9c6d65242e9b8fabb346e31e627b8fa87827..4d7f09f9517ce666e6618cc5d3866ddf7b4235a7 100644 (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;
 
 /*!
index 844a5c7bc1c182ec3c13c24a71968702677886a6..983ef7f0771350c6134c7a7ca43d9ad5227bb14a 100644 (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;
index e960207233078e7028d600206c243f333b05e7e4..92b9584996c50712afd311bdcf8bdcc41d7f3e55 100644 (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) {
index 643f44a2fbedac48a6d7e0d66db03fca721d3c1f..6863703a7fd0aa470054e77b15b719aa9f8e7ce9 100644 (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;
        }
@@ -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);
index 2f34e001f7dc51feb3a796f64baf86b5f0d5f657..e5beea84dd6c5e34ce210109a5ba5824d630f1dc 100644 (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);
 }
 
index f08a7f08114be1b5402ac970084f03ef6e4bc087..2ad20ed51bc6a2de457d5c148c95a0cfef55d0bc 100644 (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);
index fc29c5d19e3a0abd5e8f09ee6a34d5886246ddc1..9c952482234097bf562ea96f7caf31ed453cf683 100644 (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",
index fcc9599afb1c348c4de23631be2f051ea2c2b6ae..f5233726560eb0be402a7fe80e0970ded2c568c5 100644 (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];
 
@@ -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);
index 1db452ebbaae8f1f3ee440a8b13f17a17ec2764d..b8d7e7a9e261991c1770f252b8dc304232b7b0d4 100644 (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;
 }