]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
skypiax: restored a previous wrong commit
authorGiovanni Maruzzelli <gmaruzz@gmail.com>
Sat, 13 Feb 2010 16:54:24 +0000 (16:54 +0000)
committerGiovanni Maruzzelli <gmaruzz@gmail.com>
Sat, 13 Feb 2010 16:54:24 +0000 (16:54 +0000)
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@16633 d0543943-73ff-0310-b7d9-9358b9ac24b2

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

index 9071cd47630faeec01115f445a5296c3c5326dda..a293a56673fc681c463d9302a2092100a966b1bf 100644 (file)
 
 #include "skypiax.h"
 #define MDL_CHAT_PROTO "skype"
-#define TIMERS_ON
-#ifdef TIMERS_ON
 #define TIMER_WRITE
-#else
-#undef TIMER_WRITE
-#endif
 
 #ifdef WIN32
 /***************/
@@ -263,7 +258,6 @@ switch_status_t skypiax_tech_init(private_t * tech_pvt, switch_core_session_t *s
                return SWITCH_STATUS_FALSE;
        }
 
-#ifdef TIMERS_ON
        if (switch_core_timer_init(&tech_pvt->timer_read, "soft", 20, tech_pvt->read_codec.implementation->samples_per_packet, skypiax_module_pool) !=
                SWITCH_STATUS_SUCCESS) {
                ERRORA("setup timer failed\n", SKYPIAX_P_LOG);
@@ -271,7 +265,6 @@ switch_status_t skypiax_tech_init(private_t * tech_pvt, switch_core_session_t *s
        }
 
        switch_core_timer_sync(&tech_pvt->timer_read);
-#endif// TIMERS_ON
 
 #ifdef TIMER_WRITE
        if (switch_core_timer_init(&tech_pvt->timer_write, "soft", 20, tech_pvt->write_codec.implementation->samples_per_packet, skypiax_module_pool) !=
@@ -489,9 +482,7 @@ static switch_status_t channel_on_destroy(switch_core_session_t *session)
                        switch_core_codec_destroy(&tech_pvt->write_codec);
                }
 
-#ifdef TIMERS_ON
                switch_core_timer_destroy(&tech_pvt->timer_read);
-#endif// TIMERS_ON
 #ifdef TIMER_WRITE
 
                switch_core_timer_destroy(&tech_pvt->timer_write);
@@ -684,7 +675,6 @@ static switch_status_t channel_read_frame(switch_core_session_t *session, switch
        switch_channel_t *channel = NULL;
        private_t *tech_pvt = NULL;
        switch_byte_t *data;
-//unsigned int len;
 
        channel = switch_core_session_get_channel(session);
        switch_assert(channel != NULL);
@@ -703,14 +693,7 @@ static switch_status_t channel_read_frame(switch_core_session_t *session, switch
 
        //switch_core_timer_next(&tech_pvt->timer_read);
 
-                                               if (tech_pvt->skype_callflow != CALLFLOW_STATUS_REMOTEHOLD) {
-                                                       tech_pvt->read_frame.datalen = recv(tech_pvt->readfd, (char *) tech_pvt->read_frame.data, 320, 0);      //seems that Skype only sends 320 bytes at time
-                                               } else {
-                                                       tech_pvt->read_frame.datalen = 0;
-                                               }
-
-       //if (!skypiax_audio_read(tech_pvt)) {
-       if (!tech_pvt->read_frame.datalen) {
+       if (!skypiax_audio_read(tech_pvt)) {
 
                ERRORA("skypiax_audio_read ERROR\n", SKYPIAX_P_LOG);
 
@@ -736,9 +719,7 @@ static switch_status_t channel_read_frame(switch_core_session_t *session, switch
                                DEBUGA_SKYPE("CHANNEL READ CONTINUE\n", SKYPIAX_P_LOG);
                                continue;
                        }
-#ifdef TIMERS_ON
                        switch_core_timer_check(&tech_pvt->timer_read, SWITCH_TRUE);
-#endif// TIMERS_ON
                        *frame = &tech_pvt->read_frame;
 #if SWITCH_BYTE_ORDER == __BIG_ENDIAN
                        if (switch_test_flag(tech_pvt, TFLAG_LINEAR)) {
@@ -771,7 +752,7 @@ static switch_status_t channel_write_frame(switch_core_session_t *session, switc
 {
        switch_channel_t *channel = NULL;
        private_t *tech_pvt = NULL;
-       unsigned int sent=0;
+       unsigned int sent;
 
        channel = switch_core_session_get_channel(session);
        switch_assert(channel != NULL);
@@ -790,50 +771,25 @@ static switch_status_t channel_write_frame(switch_core_session_t *session, switc
        }
 #endif
 
-#if 0
        sent = frame->datalen;
 #ifdef WIN32
        //switch_file_write(tech_pvt->audiopipe_cli[1], frame->data, &sent);
 #else /* WIN32 */
        //sent = write(tech_pvt->audiopipe_cli[1], frame->data, sent);
 #endif /* WIN32 */
-       //if (tech_pvt->flag_audio_cli == 0) {
+       if (tech_pvt->flag_audio_cli == 1) {
+               switch_sleep(1000);             //1 millisec
+       }
+       if (tech_pvt->flag_audio_cli == 0) {
 #ifdef TIMER_WRITE
                switch_core_timer_next(&tech_pvt->timer_write);
 #endif // TIMER_WRITE
 
-       //while (tech_pvt->flag_audio_cli == 1) {
-               //switch_sleep(1000);           //10 millisec
-                                               //WARNINGA("write now is 1\n", SKYPIAX_P_LOG);
-       //}
-       switch_mutex_lock(tech_pvt->flag_audio_cli_mutex);
                memcpy(tech_pvt->audiobuf_cli, frame->data, frame->datalen);
                tech_pvt->flag_audio_cli = 1;
-       switch_mutex_unlock(tech_pvt->flag_audio_cli_mutex);
-       //}
+       }
        //NOTICA("write \n", SKYPIAX_P_LOG);
-#endif //0
 
-#ifdef TIMER_WRITE
-/* NONBLOCKING ? */
-               switch_core_timer_next(&tech_pvt->timer_write);
-               //switch_core_timer_check(&tech_pvt->timer_write, SWITCH_TRUE);
-#endif // TIMER_WRITE
-       /* send the 16khz frame to the Skype client waiting for incoming audio to be sent to the remote party */
-                                                               if (tech_pvt->skype_callflow != CALLFLOW_STATUS_REMOTEHOLD) {
-                                                                       sent = send(tech_pvt->writefd, (char *) frame->data, frame->datalen, 0);
-                                                                       if (sent == -1) {
-                                                                               ERRORA("EXIT? sent=%d\n", SKYPIAX_P_LOG, sent);
-                                                                       } else if (sent != frame->datalen) {
-                                                                               ERRORA("sent=%d\n", SKYPIAX_P_LOG, sent);
-                                                                       }
-                                                               }
-
-
-#ifdef TIMER_WRITE
-/* BLOCKING ? */
-               //switch_core_timer_check(&tech_pvt->timer_write, SWITCH_TRUE);
-#endif // TIMER_WRITE
        if (sent != frame->datalen && sent != -1) {
                DEBUGA_SKYPE("CLI PIPE write %d\n", SKYPIAX_P_LOG, sent);
        }
@@ -874,9 +830,7 @@ static switch_status_t channel_receive_message(switch_core_session_t *session, s
                {
                        DEBUGA_SKYPE("MSG_ID=%d, TO BE ANSWERED!\n", SKYPIAX_P_LOG, msg->message_id);
 
-#ifdef TIMERS_ON
                        switch_core_timer_sync(&tech_pvt->timer_read);
-#endif// TIMERS_ON
 #ifdef TIMER_WRITE
                        switch_core_timer_sync(&tech_pvt->timer_write);
 #endif // TIMER_WRITE
@@ -887,9 +841,7 @@ static switch_status_t channel_receive_message(switch_core_session_t *session, s
 
                DEBUGA_SKYPE("%s CHANNEL got SWITCH_MESSAGE_INDICATE_AUDIO_SYNC\n", SKYPIAX_P_LOG, switch_channel_get_name(channel));
 
-#ifdef TIMERS_ON
                switch_core_timer_sync(&tech_pvt->timer_read);
-#endif// TIMERS_ON
 #ifdef TIMER_WRITE
                switch_core_timer_sync(&tech_pvt->timer_write);
 #endif // TIMER_WRITE
@@ -897,9 +849,7 @@ static switch_status_t channel_receive_message(switch_core_session_t *session, s
        default:
                {
 
-#ifdef TIMERS_ON
                        switch_core_timer_sync(&tech_pvt->timer_read);
-#endif// TIMERS_ON
 #ifdef TIMER_WRITE
 
                        switch_core_timer_sync(&tech_pvt->timer_write);
@@ -1444,8 +1394,6 @@ static switch_status_t load_config(int reload_type)
 
                                skypiax_audio_init(&globals.SKYPIAX_INTERFACES[interface_id]);
 
-       switch_mutex_init(&globals.SKYPIAX_INTERFACES[interface_id].flag_audio_srv_mutex, SWITCH_MUTEX_NESTED, skypiax_module_pool);
-       switch_mutex_init(&globals.SKYPIAX_INTERFACES[interface_id].flag_audio_cli_mutex, SWITCH_MUTEX_NESTED, skypiax_module_pool);
                                NOTICA
                                        ("WAITING roughly 10 seconds to find a running Skype client and connect to its SKYPE API for interface_id=%d\n",
                                         SKYPIAX_P_LOG, interface_id);
index 8ebafa31e93b80cca539acfc0850de35bd914eac..7ac71489f3574d48fda353b01015a2e56bcb3cee 100644 (file)
@@ -29,7 +29,6 @@
  * Further Contributors:
  *
  *
- *
  * mod_skypiax.c -- Skype compatible Endpoint Module
  *
  */
@@ -192,8 +191,6 @@ struct private_object {
        switch_caller_profile_t *caller_profile;
        switch_mutex_t *mutex;
        switch_mutex_t *flag_mutex;
-       switch_mutex_t *flag_audio_cli_mutex;
-       switch_mutex_t *flag_audio_srv_mutex;
 
        char interface_id[80];
        char name[80];
@@ -281,8 +278,6 @@ struct private_object {
        uint32_t report_incoming_chatmessages;
        switch_timer_t timer_read;
        switch_timer_t timer_write;
-unsigned int writefd;
-unsigned int readfd;
 };
 
 typedef struct private_object private_t;
index dcf11d489cf422dac64d5be3568d00b2ce92b6d3..1482b0f5fb310d85e582de2e46cc92b5ae43d124 100644 (file)
@@ -55,9 +55,8 @@ int skypiax_socket_create_and_bind(private_t * tech_pvt, unsigned short *which_p
                start_port = *which_port;
 
        my_addr.sin_port = htons(start_port);
-/* NONBLOCKING ? */
        //fcntl(s, F_SETFL, O_NONBLOCK);
-
+       //tech_pvt->tcp_cli_port = start_port;
        *which_port = start_port;
        while (bind(s, (struct sockaddr *) &my_addr, sizeof(struct sockaddr)) < 0) {
                DEBUGA_SKYPE("*which_port=%d, tech_pvt->tcp_cli_port=%d, tech_pvt->tcp_srv_port=%d\n", SKYPIAX_P_LOG, *which_port, tech_pvt->tcp_cli_port,
@@ -119,7 +118,6 @@ int skypiax_socket_create_and_bind(private_t * tech_pvt, unsigned short *which_p
        size = sizeof(int);
        setsockopt(s, SOL_SOCKET, SO_SNDBUF, (char *) &sockbufsize, size);
 
-
        sockbufsize = 0;
        size = sizeof(int);
        getsockopt(s, SOL_SOCKET, SO_SNDBUF, (char *) &sockbufsize, &size);
@@ -724,22 +722,22 @@ void *skypiax_do_tcp_srv_thread_func(void *obj)
        private_t *tech_pvt = obj;
        int s;
        unsigned int len;
-       //unsigned int i;
-       //unsigned int a;
+       unsigned int i;
+       unsigned int a;
 #if defined(WIN32) && !defined(__CYGWIN__)
        int sin_size;
 #else /* WIN32 */
        unsigned int sin_size;
 #endif /* WIN32 */
        unsigned int fd;
-       //short srv_in[SAMPLES_PER_FRAME];
-       //short srv_out[SAMPLES_PER_FRAME / 2];
+       short srv_in[SAMPLES_PER_FRAME];
+       short srv_out[SAMPLES_PER_FRAME / 2];
        //struct sockaddr_in my_addr;
        struct sockaddr_in remote_addr;
        //int exit = 0;
        unsigned int kill_cli_size;
        short kill_cli_buff[SAMPLES_PER_FRAME];
-       //short totalbuf[SAMPLES_PER_FRAME];
+       short totalbuf[SAMPLES_PER_FRAME];
        int sockbufsize = 0;
        unsigned int size = sizeof(int);
 
@@ -799,13 +797,6 @@ void *skypiax_do_tcp_srv_thread_func(void *obj)
                                                   || tech_pvt->skype_callflow == CALLFLOW_STATUS_EARLYMEDIA
                                                   || tech_pvt->skype_callflow == CALLFLOW_STATUS_REMOTEHOLD || tech_pvt->skype_callflow == SKYPIAX_STATE_UP)) {
 
-                                       tech_pvt->readfd = fd;
-                                               //WARNINGA("read HERE\n", SKYPIAX_P_LOG);
-                                               skypiax_sleep(100000);
-
-
-#ifdef NOLOOP
-
                                        unsigned int fdselect;
                                        int rt;
                                        fd_set fs;
@@ -875,16 +866,13 @@ void *skypiax_do_tcp_srv_thread_func(void *obj)
 
 
                                                                howmany = SAMPLES_PER_FRAME * sizeof(short);
-                                                               //while (tech_pvt->flag_audio_srv == 1) {
-                                                                       //switch_sleep(1000);   //10 millisec
-                                               //WARNINGA("read now is 1\n", SKYPIAX_P_LOG);
-                                                               //}
-                                                               //if (tech_pvt->flag_audio_srv == 0) {
-       //switch_mutex_lock(tech_pvt->flag_audio_srv_mutex);
+                                                               if (tech_pvt->flag_audio_srv == 1) {
+                                                                       switch_sleep(1000);     //1 millisec
+                                                               }
+                                                               if (tech_pvt->flag_audio_srv == 0) {
                                                                        memcpy(tech_pvt->audiobuf_srv, totalbuf, SAMPLES_PER_FRAME * sizeof(short));
                                                                        tech_pvt->flag_audio_srv = 1;
-       //switch_mutex_unlock(tech_pvt->flag_audio_srv_mutex);
-                                                               //}
+                                                               }
                                                                //NOTICA("read \n", SKYPIAX_P_LOG);
                                                                if (howmany != SAMPLES_PER_FRAME * sizeof(short)) {
                                                                        ERRORA("howmany is %d, but was expected to be %d\n", SKYPIAX_P_LOG,
@@ -906,7 +894,6 @@ void *skypiax_do_tcp_srv_thread_func(void *obj)
                                                skypiax_sleep(10000);
                                        }
 
-#endif// NOLOOP
                                }
 
                                /* let's send some frame in the pipes, so both tcp_cli and tcp_srv will have an occasion to die */
@@ -931,7 +918,6 @@ void *skypiax_do_tcp_srv_thread_func(void *obj)
                                skypiax_sleep(2000);
                                DEBUGA_SKYPE("Skype incoming audio GONE\n", SKYPIAX_P_LOG);
                                skypiax_close_socket(fd);
-                               break;
                        }
                }
        }
@@ -948,15 +934,13 @@ void *skypiax_do_tcp_cli_thread_func(void *obj)
        int s;
        //struct sockaddr_in my_addr;
        struct sockaddr_in remote_addr;
-#ifdef NOVARS
        unsigned int got;
        unsigned int len;
        unsigned int i;
        unsigned int a;
+       unsigned int fd;
        short cli_out[SAMPLES_PER_FRAME * 2];
        short cli_in[SAMPLES_PER_FRAME];
-#endif// NOVARS
-       unsigned int fd;
 #ifdef WIN32
        int sin_size;
 #else
@@ -1025,19 +1009,10 @@ void *skypiax_do_tcp_cli_thread_func(void *obj)
 
                                if (!(running && tech_pvt->running))
                                        break;
-
-
-
-
                                while (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)) {
-                                       tech_pvt->writefd = fd;
-                                               //NOTICA("write HERE\n", SKYPIAX_P_LOG);
-                                               skypiax_sleep(100000);
-#if 0
-#ifdef NOVARS
                                        unsigned int fdselect;
                                        int rt;
                                        fd_set fs;
@@ -1064,46 +1039,32 @@ void *skypiax_do_tcp_cli_thread_func(void *obj)
                                        fdselect = fd;
                                        FD_SET(fdselect, &fs);
 
-#endif// NOVARS
-#if 0
-                                       rt = select(fdselect + 1, NULL, &fs, NULL, NULL);
+                                       //FIXME rt = select(fdselect + 1, NULL, &fs, NULL, &to);
                                        while (tech_pvt->flag_audio_cli == 0) {
 #ifdef WIN32
                                                skypiax_sleep(100);     //0.1 millisec
 #else
-                                               skypiax_sleep(1000);    //10 millisec
+                                               skypiax_sleep(1000);    //1 millisec
 #endif //WIN32
-                                               NOTICA("write now is 0\n", SKYPIAX_P_LOG);
+                                               //WARNINGA("write now is 0\n", SKYPIAX_P_LOG);
                                        }
                                        //ERRORA("write is now 1\n", SKYPIAX_P_LOG);
 
                                        rt = 1;
-#endif //0
-                                       //rt = select(fdselect + 1, NULL, &fs, NULL, NULL);
 
-#ifdef NOLOOP
                                        if (rt > 0) {
                                                int counter;
-#if 0
-                                       while (tech_pvt->flag_audio_cli == 0) {
-#ifdef WIN32
-                                               skypiax_sleep(100);     //0.1 millisec
-#else
-                                               skypiax_sleep(10000);   //10 millisec
-#endif //WIN32
-                                               WARNINGA("write now is 0\n", SKYPIAX_P_LOG);
-                                       }
-#endif //0
-       
+
                                                /* until we drained the pipe to empty */
+                                               //for (counter = 0; counter < 10; counter++) {
                                                for (counter = 0; counter < 1; counter++) {
                                                        /* read from the pipe the audio frame we are supposed to send out */
                                                        //got = skypiax_pipe_read(tech_pvt->audiopipe_cli[0], cli_in, SAMPLES_PER_FRAME * sizeof(short));
 
 
                                                        got = SAMPLES_PER_FRAME * sizeof(short);
-       switch_mutex_lock(tech_pvt->flag_audio_cli_mutex);
                                                        memcpy(cli_in, tech_pvt->audiobuf_cli, SAMPLES_PER_FRAME * sizeof(short));
+                                                       tech_pvt->flag_audio_cli = 0;
 
 
 
@@ -1139,7 +1100,6 @@ void *skypiax_do_tcp_cli_thread_func(void *obj)
                                                                /* send the 16khz frame to the Skype client waiting for incoming audio to be sent to the remote party */
                                                                if (tech_pvt->skype_callflow != CALLFLOW_STATUS_REMOTEHOLD) {
                                                                        len = send(fd, (char *) cli_out, got, 0);
-                                                       tech_pvt->flag_audio_cli = 0;
                                                                        //skypiax_sleep(5000);  //5 msec
 
                                                                        if (len == -1) {
@@ -1151,7 +1111,6 @@ void *skypiax_do_tcp_cli_thread_func(void *obj)
                                                                        }
                                                                }
 
-       switch_mutex_unlock(tech_pvt->flag_audio_cli_mutex);
                                                        } else {
 
                                                                WARNINGA("got is %d, but was expected to be %d\n", SKYPIAX_P_LOG, got, (int) (SAMPLES_PER_FRAME * sizeof(short)));
@@ -1174,12 +1133,9 @@ void *skypiax_do_tcp_cli_thread_func(void *obj)
                                                skypiax_sleep(1000);
                                        }
 
-#endif// NOLOOP
-#endif// 0
                                }
                                DEBUGA_SKYPE("Skype outbound audio GONE\n", SKYPIAX_P_LOG);
                                skypiax_close_socket(fd);
-                               break;
                        }
                }
        }
@@ -1194,24 +1150,20 @@ int skypiax_audio_read(private_t * tech_pvt)
 {
        unsigned int samples;
 
-#if 0
        while (tech_pvt->flag_audio_srv == 0) {
 #ifdef WIN32
                skypiax_sleep(100);             //0.1 millisec
 #else
-               skypiax_sleep(1000);    //10 millisec
+               skypiax_sleep(1000);    //1 millisec
 #endif //WIN32
 
-               WARNINGA("read now is 0\n", SKYPIAX_P_LOG);
+               //WARNINGA("read now is 0\n", SKYPIAX_P_LOG);
        }
-#endif //0
        //ERRORA("read is now 1\n", SKYPIAX_P_LOG);
        //samples = skypiax_pipe_read(tech_pvt->audiopipe_srv[0], tech_pvt->read_frame.data, SAMPLES_PER_FRAME * sizeof(short));
        samples = SAMPLES_PER_FRAME * sizeof(short);
-       //switch_mutex_lock(tech_pvt->flag_audio_srv_mutex);
        memcpy(tech_pvt->read_frame.data, tech_pvt->audiobuf_srv, SAMPLES_PER_FRAME * sizeof(short));
        tech_pvt->flag_audio_srv = 0;
-       //switch_mutex_unlock(tech_pvt->flag_audio_srv_mutex);
 
        if (samples != SAMPLES_PER_FRAME * sizeof(short)) {
                if (samples)