]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
skypiax: lot of changes and tweakings about timing
authorGiovanni Maruzzelli <gmaruzz@gmail.com>
Sun, 14 Feb 2010 02:36:46 +0000 (02:36 +0000)
committerGiovanni Maruzzelli <gmaruzz@gmail.com>
Sun, 14 Feb 2010 02:36:46 +0000 (02:36 +0000)
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@16638 d0543943-73ff-0310-b7d9-9358b9ac24b2

src/mod/endpoints/mod_skypiax/alsa/dummy.c
src/mod/endpoints/mod_skypiax/configs/copy [new file with mode: 0644]
src/mod/endpoints/mod_skypiax/configs/create [new file with mode: 0644]
src/mod/endpoints/mod_skypiax/mod_skypiax.c
src/mod/endpoints/mod_skypiax/skypiax_protocol.c

index 51b9228b7b8e89f0e3aef61612b32558609d561f..df36e1141ea54a75695afacafcc5607a96a560ef 100644 (file)
@@ -336,8 +336,8 @@ static void snd_card_dummy_pcm_timer_function(unsigned long data)
                        printk("giova: timer_func %d %d NULL: continue\n", __LINE__, i);
                        continue;
                }
-               if (in_irq())
-                       printk("giova: timer_func %d %d we are in HARDWARE IRQ\n", __LINE__, i);
+               //if (in_irq())
+                       //printk("giova: timer_func %d %d we are in HARDWARE IRQ\n", __LINE__, i);
                //if(in_softirq())
                //printk("giova: timer_func %d %d we are in SOFT IRQ\n", __LINE__, i);
 //printk("giova: timer_func %d %d\n", __LINE__, i);
@@ -364,8 +364,8 @@ static snd_pcm_uframes_t snd_card_dummy_pcm_pointer(struct snd_pcm_substream *su
        struct snd_dummy_pcm *dpcm = runtime->private_data;
 
 //printk("giova: pointer %d %p\n", __LINE__, dpcm);
-       //return bytes_to_frames(runtime, dpcm->pcm_buf_pos / dpcm->pcm_hz);
-       return (dpcm->pcm_buf_pos / dpcm->pcm_hz) / 2;
+       return bytes_to_frames(runtime, dpcm->pcm_buf_pos / dpcm->pcm_hz);
+       //return (dpcm->pcm_buf_pos / dpcm->pcm_hz) / 2;
 }
 
 static struct snd_pcm_hardware snd_card_dummy_playback = {
diff --git a/src/mod/endpoints/mod_skypiax/configs/copy b/src/mod/endpoints/mod_skypiax/configs/copy
new file mode 100644 (file)
index 0000000..f004a26
--- /dev/null
@@ -0,0 +1,39 @@
+cp -a skypiax101/* skypiax102/
+cp -a skypiax101/* skypiax103/
+cp -a skypiax101/* skypiax104/
+cp -a skypiax101/* skypiax105/
+cp -a skypiax101/* skypiax106/
+cp -a skypiax101/* skypiax107/
+cp -a skypiax101/* skypiax108/
+cp -a skypiax101/* skypiax109/
+cp -a skypiax101/* skypiax110/
+cp -a skypiax101/* skypiax111/
+cp -a skypiax101/* skypiax112/
+cp -a skypiax101/* skypiax113/
+cp -a skypiax101/* skypiax114/
+cp -a skypiax101/* skypiax115/
+cp -a skypiax101/* skypiax116/
+cp -a skypiax101/* skypiax117/
+cp -a skypiax101/* skypiax118/
+cp -a skypiax101/* skypiax119/
+cp -a skypiax101/* skypiax120/
+cp -a skypiax101/* skypiax121/
+cp -a skypiax101/* skypiax122/
+cp -a skypiax101/* skypiax123/
+cp -a skypiax101/* skypiax124/
+cp -a skypiax101/* skypiax125/
+cp -a skypiax101/* skypiax126/
+cp -a skypiax101/* skypiax127/
+cp -a skypiax101/* skypiax128/
+cp -a skypiax101/* skypiax129/
+cp -a skypiax101/* skypiax130/
+cp -a skypiax101/* skypiax131/
+cp -a skypiax101/* skypiax132/
+cp -a skypiax101/* skypiax133/
+cp -a skypiax101/* skypiax134/
+cp -a skypiax101/* skypiax135/
+cp -a skypiax101/* skypiax136/
+cp -a skypiax101/* skypiax137/
+cp -a skypiax101/* skypiax138/
+cp -a skypiax101/* skypiax139/
+cp -a skypiax101/* skypiax140/
diff --git a/src/mod/endpoints/mod_skypiax/configs/create b/src/mod/endpoints/mod_skypiax/configs/create
new file mode 100644 (file)
index 0000000..84a8af1
--- /dev/null
@@ -0,0 +1,40 @@
+mkdir skypiax101
+mkdir skypiax102
+mkdir skypiax103
+mkdir skypiax104
+mkdir skypiax105
+mkdir skypiax106
+mkdir skypiax107
+mkdir skypiax108
+mkdir skypiax109
+mkdir skypiax110
+mkdir skypiax111
+mkdir skypiax112
+mkdir skypiax113
+mkdir skypiax114
+mkdir skypiax115
+mkdir skypiax116
+mkdir skypiax117
+mkdir skypiax118
+mkdir skypiax119
+mkdir skypiax120
+mkdir skypiax121
+mkdir skypiax122
+mkdir skypiax123
+mkdir skypiax124
+mkdir skypiax125
+mkdir skypiax126
+mkdir skypiax127
+mkdir skypiax128
+mkdir skypiax129
+mkdir skypiax130
+mkdir skypiax131
+mkdir skypiax132
+mkdir skypiax133
+mkdir skypiax134
+mkdir skypiax135
+mkdir skypiax136
+mkdir skypiax137
+mkdir skypiax138
+mkdir skypiax139
+mkdir skypiax140
index a293a56673fc681c463d9302a2092100a966b1bf..f2a6481a76d8c44bd5b0e95855e5864cda7bc2c7 100644 (file)
@@ -719,7 +719,6 @@ static switch_status_t channel_read_frame(switch_core_session_t *session, switch
                                DEBUGA_SKYPE("CHANNEL READ CONTINUE\n", SKYPIAX_P_LOG);
                                continue;
                        }
-                       switch_core_timer_check(&tech_pvt->timer_read, SWITCH_TRUE);
                        *frame = &tech_pvt->read_frame;
 #if SWITCH_BYTE_ORDER == __BIG_ENDIAN
                        if (switch_test_flag(tech_pvt, TFLAG_LINEAR)) {
@@ -1393,6 +1392,7 @@ static switch_status_t load_config(int reload_type)
                                switch_sleep(100000);
 
                                skypiax_audio_init(&globals.SKYPIAX_INTERFACES[interface_id]);
+                               switch_mutex_init(&globals.SKYPIAX_INTERFACES[interface_id].mutex_audio_srv, 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",
@@ -1740,7 +1740,7 @@ int dtmf_received(private_t * tech_pvt, char *value)
 
        if (channel) {
 
-               if (!switch_channel_test_flag(channel, CF_BRIDGED)) {
+               //if (!switch_channel_test_flag(channel, CF_BRIDGED)) {
 
                        switch_dtmf_t dtmf = { (char) value[0], switch_core_default_dtmf_duration(0) };
                        DEBUGA_SKYPE("received DTMF %c on channel %s\n", SKYPIAX_P_LOG, dtmf.digit, switch_channel_get_name(channel));
@@ -1749,10 +1749,10 @@ int dtmf_received(private_t * tech_pvt, char *value)
                        switch_channel_queue_dtmf(channel, &dtmf);
                        switch_set_flag(tech_pvt, TFLAG_DTMF);
                        switch_mutex_unlock(tech_pvt->flag_mutex);
-               } else {
-                       NOTICA
-                               ("received a DTMF on channel %s, but we're BRIDGED, so let's NOT relay it out of band\n", SKYPIAX_P_LOG, switch_channel_get_name(channel));
-               }
+               //} else {
+                       //NOTICA
+                               //("received a DTMF on channel %s, but we're BRIDGED, so let's NOT relay it out of band\n", SKYPIAX_P_LOG, switch_channel_get_name(channel));
+               //}
        } else {
                WARNINGA("received %c DTMF, but no channel?\n", SKYPIAX_P_LOG, value[0]);
        }
index 1482b0f5fb310d85e582de2e46cc92b5ae43d124..c825b767b7d46ab165dbe6bff080a2618f5afc91 100644 (file)
@@ -813,11 +813,14 @@ void *skypiax_do_tcp_srv_thread_func(void *obj)
                                        to.tv_usec = 60000;     //60 msec
                                        to.tv_sec = 0;
 
+                                        if (tech_pvt->timer_read.timer_interface && tech_pvt->timer_read.timer_interface->timer_next) {
+       switch_core_timer_next(&tech_pvt->timer_read);
+                                        }
                                        rt = select(fdselect + 1, &fs, NULL, NULL, &to);
                                        if (rt > 0) {
 
                                                if (tech_pvt->skype_callflow != CALLFLOW_STATUS_REMOTEHOLD) {
-                                                       len = recv(fd, (char *) srv_in, 320, 0);        //seems that Skype only sends 320 bytes at time
+                                                       len = recv(fd, (char *) srv_in, 640, 0);        //seems that Skype only sends 320 bytes at time
                                                } else {
                                                        len = 0;
                                                }
@@ -825,6 +828,7 @@ void *skypiax_do_tcp_srv_thread_func(void *obj)
                                                if (len == 320) {
                                                        unsigned int howmany;
 
+                                                               //DEBUGA_SKYPE("320!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n", SKYPIAX_P_LOG);
                                                        if (samplerate_skypiax == 8000) {
                                                                /* we're downsampling from 16khz to 8khz, srv_out will contain each other sample from srv_in */
                                                                a = 0;
@@ -869,10 +873,12 @@ void *skypiax_do_tcp_srv_thread_func(void *obj)
                                                                if (tech_pvt->flag_audio_srv == 1) {
                                                                        switch_sleep(1000);     //1 millisec
                                                                }
-                                                               if (tech_pvt->flag_audio_srv == 0) {
+                                                               //if (tech_pvt->flag_audio_srv == 0) {
+                       switch_mutex_lock(tech_pvt->mutex_audio_srv);
                                                                        memcpy(tech_pvt->audiobuf_srv, totalbuf, SAMPLES_PER_FRAME * sizeof(short));
                                                                        tech_pvt->flag_audio_srv = 1;
-                                                               }
+                       switch_mutex_unlock(tech_pvt->mutex_audio_srv);
+                                                               //}
                                                                //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,
@@ -882,10 +888,19 @@ void *skypiax_do_tcp_srv_thread_func(void *obj)
                                                                tech_pvt->audiobuf_is_loaded = 0;
                                                        }
 
+                                               } else if (len == 640) {
+
+                                                               if (tech_pvt->flag_audio_srv == 1) {
+                                                                       switch_sleep(1000);     //1 millisec
+                                                               }
+                       switch_mutex_lock(tech_pvt->mutex_audio_srv);
+                                                                       memcpy(tech_pvt->audiobuf_srv, srv_in, SAMPLES_PER_FRAME * sizeof(short));
+                                                                       tech_pvt->flag_audio_srv = 1;
+                       switch_mutex_unlock(tech_pvt->mutex_audio_srv);
                                                } else if (len == 0) {
                                                        skypiax_sleep(1000);
                                                } else {
-                                                       DEBUGA_SKYPE("len=%d, expected 320\n", SKYPIAX_P_LOG, len);
+                                                       ERRORA("len=%d, expected 640\n", SKYPIAX_P_LOG, len);
                                                }
 
                                        } else {
@@ -1017,6 +1032,10 @@ void *skypiax_do_tcp_cli_thread_func(void *obj)
                                        int rt;
                                        fd_set fs;
                                        struct timeval to;
+                                       int waitin;
+                                       int big_waitin=40;
+                                       int lil_waitin=20;
+                                       int big_waited;
 
                                        if (!(running && tech_pvt->running))
                                                break;
@@ -1040,15 +1059,36 @@ void *skypiax_do_tcp_cli_thread_func(void *obj)
                                        FD_SET(fdselect, &fs);
 
                                        //FIXME rt = select(fdselect + 1, NULL, &fs, NULL, &to);
+                                       waitin=0;
+                                       big_waited=0;
                                        while (tech_pvt->flag_audio_cli == 0) {
 #ifdef WIN32
                                                skypiax_sleep(100);     //0.1 millisec
 #else
                                                skypiax_sleep(1000);    //1 millisec
 #endif //WIN32
-                                               //WARNINGA("write now is 0\n", SKYPIAX_P_LOG);
+                                               waitin++;
+                                               if(big_waited == 1 && waitin==lil_waitin && tech_pvt->flag_audio_cli == 0){
+                                                       memset(cli_out, 255, SAMPLES_PER_FRAME * sizeof(short));
+                                                       send(fd, (char *) cli_out, SAMPLES_PER_FRAME * sizeof(short), 0);
+                                                       //WARNINGA("write buffer filled at %d\n", SKYPIAX_P_LOG, waitin);
+                                                       waitin=0;
+                                                       continue;
+                                               }
+                                               if(big_waited == 0 && waitin==big_waitin && tech_pvt->flag_audio_cli == 0){
+                                                       memset(cli_out, 255, SAMPLES_PER_FRAME * sizeof(short));
+                                                       send(fd, (char *) cli_out, SAMPLES_PER_FRAME * sizeof(short), 0);
+                                                       send(fd, (char *) cli_out, SAMPLES_PER_FRAME * sizeof(short), 0);
+                                                       //DEBUGA_SKYPE("write buffer filled at %d\n", SKYPIAX_P_LOG, waitin);
+                                                       waitin=0;
+                                                       big_waited=1;
+                                                       continue;
+                                               }
+
+                                       }
+                                       if(waitin > 21){
+                                               //DEBUGA_SKYPE("waitin is now %d\n", SKYPIAX_P_LOG, waitin);
                                        }
-                                       //ERRORA("write is now 1\n", SKYPIAX_P_LOG);
 
                                        rt = 1;
 
@@ -1149,22 +1189,29 @@ void *skypiax_do_tcp_cli_thread_func(void *obj)
 int skypiax_audio_read(private_t * tech_pvt)
 {
        unsigned int samples;
+       int waitin;
 
+       waitin=0;
        while (tech_pvt->flag_audio_srv == 0) {
 #ifdef WIN32
                skypiax_sleep(100);             //0.1 millisec
 #else
                skypiax_sleep(1000);    //1 millisec
 #endif //WIN32
+               waitin++;
 
                //WARNINGA("read now is 0\n", SKYPIAX_P_LOG);
        }
-       //ERRORA("read is now 1\n", SKYPIAX_P_LOG);
+       if(waitin > 21){
+               //DEBUGA_SKYPE("read is now %d\n", SKYPIAX_P_LOG, waitin);
+       }
        //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->mutex_audio_srv);
        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->mutex_audio_srv);
 
+       samples = SAMPLES_PER_FRAME * sizeof(short);
        if (samples != SAMPLES_PER_FRAME * sizeof(short)) {
                if (samples)
                        WARNINGA("read samples=%u expected=%u\n", SKYPIAX_P_LOG, samples, (int) (SAMPLES_PER_FRAME * sizeof(short)));