]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
skypiax: works well again on Virtual Machines
authorGiovanni Maruzzelli <gmaruzz@gmail.com>
Tue, 2 Mar 2010 20:35:49 +0000 (20:35 +0000)
committerGiovanni Maruzzelli <gmaruzz@gmail.com>
Tue, 2 Mar 2010 20:35:49 +0000 (20:35 +0000)
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@16867 d0543943-73ff-0310-b7d9-9358b9ac24b2

src/mod/endpoints/mod_skypiax/mod_skypiax.c
src/mod/endpoints/mod_skypiax/skypiax_protocol.c

index 05a1adbc17c82c9d59486775f57d17b0f1b40611..82ea09baa51940f1191e5e844bcf29e8bba1e49b 100644 (file)
@@ -652,6 +652,7 @@ static switch_status_t channel_read_frame(switch_core_session_t *session, switch
        unsigned int i;
        unsigned int a;
        size_t bytes_read = 0;
+       int try=0;
 
 
        channel = switch_core_session_get_channel(session);
@@ -680,18 +681,34 @@ static switch_status_t channel_read_frame(switch_core_session_t *session, switch
 
        switch_core_timer_next(&tech_pvt->timer_read);
 
-       switch_mutex_lock(tech_pvt->mutex_audio_srv);
-       if (switch_buffer_inuse(tech_pvt->read_buffer)) {
-               bytes_read = switch_buffer_read(tech_pvt->read_buffer, tech_pvt->read_frame.data, 640);
-               tech_pvt->read_frame.datalen = bytes_read;
-       }
-       switch_mutex_unlock(tech_pvt->mutex_audio_srv);
+read:
 
-       if (!bytes_read) {
-               //NOTICA("skypiax_audio_read Silence\n", SKYPIAX_P_LOG);
-               memset(tech_pvt->read_frame.data, 255, SAMPLES_PER_FRAME * sizeof(short));
-               tech_pvt->read_frame.datalen = SAMPLES_PER_FRAME * sizeof(short);
 
+       if (tech_pvt && tech_pvt->interface_state != SKYPIAX_STATE_DOWN
+                       && (tech_pvt->skype_callflow == CALLFLOW_STATUS_INPROGRESS
+                               || tech_pvt->skype_callflow == CALLFLOW_STATUS_EARLYMEDIA
+                               || tech_pvt->skype_callflow == CALLFLOW_STATUS_REMOTEHOLD || tech_pvt->skype_callflow == SKYPIAX_STATE_UP)) {
+               switch_mutex_lock(tech_pvt->mutex_audio_srv);
+               if (switch_buffer_inuse(tech_pvt->read_buffer)) {
+                       bytes_read = switch_buffer_read(tech_pvt->read_buffer, tech_pvt->read_frame.data, 640);
+                       tech_pvt->read_frame.datalen = bytes_read;
+               }
+               switch_mutex_unlock(tech_pvt->mutex_audio_srv);
+
+               try=0;
+               if (!bytes_read) {
+                       switch_sleep(1000);
+                       try++;
+                       if(try < 5)
+                               goto read;
+                       NOTICA("skypiax_audio_read Silence\n", SKYPIAX_P_LOG);
+                       memset(tech_pvt->read_frame.data, 255, SAMPLES_PER_FRAME * sizeof(short));
+                       tech_pvt->read_frame.datalen = 640;
+
+               }
+       } else {
+               memset(tech_pvt->read_frame.data, 255, SAMPLES_PER_FRAME * sizeof(short));
+               tech_pvt->read_frame.datalen = 640;
        }
 
        switch_set_flag(tech_pvt, TFLAG_VOICE);
@@ -805,8 +822,9 @@ static switch_status_t channel_write_frame(switch_core_session_t *session, switc
 
        switch_mutex_lock(tech_pvt->mutex_audio_cli);
        if (switch_buffer_freespace(tech_pvt->write_buffer) < frame->datalen) {
-               //WARNINGA("NO SPACE WRITE: %d\n", SKYPIAX_P_LOG, frame->datalen);
-               switch_buffer_toss(tech_pvt->write_buffer, frame->datalen);
+               WARNINGA("NO SPACE WRITE: %d\n", SKYPIAX_P_LOG, frame->datalen);
+               //switch_buffer_toss(tech_pvt->write_buffer, frame->datalen);
+               switch_buffer_zero(tech_pvt->write_buffer);
        }
        switch_buffer_write(tech_pvt->write_buffer, frame->data, frame->datalen);
        switch_mutex_unlock(tech_pvt->mutex_audio_cli);
@@ -1667,6 +1685,7 @@ SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_skypiax_shutdown)
 #ifdef WIN32
                                if (SendMessage(tech_pvt->SkypiaxHandles.win32_hInit_MainWindowHandle, WM_DESTROY, 0, 0) == FALSE) {    // let's the skypiax_api_thread_func die
                                        DEBUGA_SKYPE("got FALSE here, thread probably was already dead. GetLastError returned: %d\n", SKYPIAX_P_LOG, GetLastError());
+                                       tech_pvt->skypiax_api_thread=NULL;
                                }
 #else
                                if (tech_pvt->SkypiaxHandles.disp) {
index 893ec2cefa37600fc6a26778045d504478d03458..142eb4636614b0ac4e4e565c81964d62ddb6e773 100644 (file)
@@ -103,7 +103,7 @@ int skypiax_socket_create_and_bind(private_t * tech_pvt, unsigned short *which_p
        sockbufsize = SAMPLES_PER_FRAME * 8;
 #endif //WIN32
        size = sizeof(int);
-       //setsockopt(s, SOL_SOCKET, SO_RCVBUF, (char *) &sockbufsize, size);
+       setsockopt(s, SOL_SOCKET, SO_RCVBUF, (char *) &sockbufsize, size);
 
        sockbufsize = 0;
        size = sizeof(int);
@@ -120,7 +120,7 @@ int skypiax_socket_create_and_bind(private_t * tech_pvt, unsigned short *which_p
        sockbufsize = SAMPLES_PER_FRAME * 8;
 #endif //WIN32
        size = sizeof(int);
-       //setsockopt(s, SOL_SOCKET, SO_SNDBUF, (char *) &sockbufsize, size);
+       setsockopt(s, SOL_SOCKET, SO_SNDBUF, (char *) &sockbufsize, size);
 
        sockbufsize = 0;
        size = sizeof(int);
@@ -844,14 +844,14 @@ void *skypiax_do_tcp_srv_thread_func(void *obj)
                                                if (len > 0) {
                                                        switch_mutex_lock(tech_pvt->mutex_audio_srv);
                                                        if (switch_buffer_freespace(tech_pvt->read_buffer) < len) {
-                                                               //switch_buffer_zero(tech_pvt->read_buffer);
+                                                               switch_buffer_zero(tech_pvt->read_buffer);
                                                                nospace = 1;
-                                                               switch_buffer_toss(tech_pvt->read_buffer, len);
+                                                               //switch_buffer_toss(tech_pvt->read_buffer, len);
                                                        }
                                                        switch_buffer_write(tech_pvt->read_buffer, srv_in, len);
                                                        switch_mutex_unlock(tech_pvt->mutex_audio_srv);
                                                        if (nospace) {
-                                                               //WARNINGA("NO SPACE READ: there was no space for: %d\n", SKYPIAX_P_LOG, len);
+                                                               WARNINGA("NO SPACE READ: there was no space for: %d\n", SKYPIAX_P_LOG, len);
                                                        }
                                                } else if (len == 0) {
                                                        DEBUGA_SKYPE("CLOSED\n", SKYPIAX_P_LOG);
@@ -992,6 +992,7 @@ void *skypiax_do_tcp_cli_thread_func(void *obj)
                                                switch_mutex_unlock(tech_pvt->mutex_audio_cli);
 
                                                if (!bytes_to_write) {
+                                                       continue;
                                                        memset(cli_out, 255, sizeof(cli_out));
                                                        bytes_to_write = 640;
                                                        //NOTICA("WRITE Silence!\n", SKYPIAX_P_LOG);