]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
gsmopen: cleaning write-read frame
authorGiovanni Maruzzelli <gmaruzz@gmail.com>
Tue, 10 Apr 2012 11:18:49 +0000 (13:18 +0200)
committerGiovanni Maruzzelli <gmaruzz@gmail.com>
Tue, 10 Apr 2012 11:18:49 +0000 (13:18 +0200)
src/mod/endpoints/mod_gsmopen/mod_gsmopen.cpp

index e1afc59e9677327e0a481e89d2339010a0833e5d..62aeba9a13dde73d87b30b9539bf2a694a86d4c1 100644 (file)
@@ -712,12 +712,12 @@ static switch_status_t channel_read_frame(switch_core_session_t *session, switch
 
        switch_core_timer_next(&tech_pvt->timer_read);
 
-       if (tech_pvt->no_sound == 1) {
+       if (tech_pvt->no_sound) {
                goto cng;
        }
-//  if ((samples = tech_pvt->serialPort_serial_audio->Read((char *) tech_pvt->read_frame.data, 320)) >0)
+       samples = tech_pvt->serialPort_serial_audio->Read(buffer2, 640);
 
-       if ((samples = tech_pvt->serialPort_serial_audio->Read(buffer2, 640)) >= 320) {
+       if (samples >= 320) {
                tech_pvt->buffer2_full = 0;
 
                if (samples >= 640) {
@@ -726,20 +726,7 @@ static switch_status_t channel_read_frame(switch_core_session_t *session, switch
                        tech_pvt->buffer2_full = 1;
                }
                samples = 320;
-
                memcpy(tech_pvt->read_frame.data, buffer2, 320);
-               tech_pvt->read_frame.datalen = samples;
-               tech_pvt->read_frame.samples = samples / 2;
-
-               tech_pvt->read_frame.timestamp = tech_pvt->timer_read.samplecount;
-
-               *frame = &tech_pvt->read_frame;
-
-               //if ((samples2 = tech_pvt->serialPort_serial_audio->Read((char *) tech_pvt->read_frame.data, 320)) >0){
-               //  WARNINGA("samples2=%d\n", GSMOPEN_P_LOG, samples2);
-               //}
-               //status = SWITCH_STATUS_SUCCESS;
-               switch_set_flag(tech_pvt, TFLAG_VOICE);
        } else {
                DEBUGA_GSMOPEN("MINGA samples=%d\n", GSMOPEN_P_LOG, samples);
                if (tech_pvt->buffer2_full) {
@@ -747,35 +734,24 @@ static switch_status_t channel_read_frame(switch_core_session_t *session, switch
                        tech_pvt->buffer2_full = 0;
                        samples = 320;
                        DEBUGA_GSMOPEN("samples=%d FROM BUFFER\n", GSMOPEN_P_LOG, samples);
+               }
 
-                       tech_pvt->read_frame.datalen = samples;
-                       tech_pvt->read_frame.samples = samples / 2;
+       }
 
-                       tech_pvt->read_frame.timestamp = tech_pvt->timer_read.samplecount;
+       tech_pvt->read_frame.datalen = samples;
+       tech_pvt->read_frame.samples = samples / 2;
+       tech_pvt->read_frame.timestamp = tech_pvt->timer_read.samplecount;
 
-                       *frame = &tech_pvt->read_frame;
+       *frame = &tech_pvt->read_frame;
 
-                       //if ((samples2 = tech_pvt->serialPort_serial_audio->Read((char *) tech_pvt->read_frame.data, 320)) >0){
-                       //  WARNINGA("samples2=%d\n", GSMOPEN_P_LOG, samples2);
-                       //}
-                       //status = SWITCH_STATUS_SUCCESS;
-                       switch_set_flag(tech_pvt, TFLAG_VOICE);
-               }
+       switch_set_flag(tech_pvt, TFLAG_VOICE);
 
-       }
-       //WARNINGA("samples=%d\n", GSMOPEN_P_LOG, samples);
        if (samples != 320) {
                DEBUGA_GSMOPEN("samples=%d\n", GSMOPEN_P_LOG, samples);
                goto cng;
        }
-//DEBUGA_GSMOPEN("samples=%d tech_pvt->read_frame.timestamp=%d\n", GSMOPEN_P_LOG, samples, tech_pvt->read_frame.timestamp);
-
-//usleep(17000);
-//usleep(17000);
 
        memset(digit_str, 0, sizeof(digit_str));
-       //teletone_dtmf_detect(&tech_pvt->dtmf_detect, (int16_t *) tech_pvt->read_frame.data, tech_pvt->read_frame.samples);
-       //teletone_dtmf_get(&tech_pvt->dtmf_detect, digit_str, sizeof(digit_str));
        dtmf_rx(&tech_pvt->dtmf_state, (int16_t *) tech_pvt->read_frame.data, tech_pvt->read_frame.samples);
        dtmf_rx_get(&tech_pvt->dtmf_state, digit_str, sizeof(digit_str));
 
@@ -875,17 +851,14 @@ static switch_status_t channel_write_frame(switch_core_session_t *session, switc
 #endif
 
        //switch_core_timer_next(&tech_pvt->timer_write);
-       //sent = frame->datalen;
-
-       //ERRORA("PLAY \n", GSMOPEN_P_LOG);
-
        gsmopen_sound_boost(frame->data, frame->samples, tech_pvt->playback_boost);
-       sent = tech_pvt->serialPort_serial_audio->Write((char *) frame->data, (int) (frame->datalen));
+       if(!tech_pvt->no_sound){
+               sent = tech_pvt->serialPort_serial_audio->Write((char *) frame->data, (int) (frame->datalen));
 
-       if (sent && sent != frame->datalen && sent != -1) {
-               DEBUGA_GSMOPEN("sent %d\n", GSMOPEN_P_LOG, sent);
+               if (sent && sent != frame->datalen && sent != -1) {
+                       DEBUGA_GSMOPEN("sent %d\n", GSMOPEN_P_LOG, sent);
+               }
        }
-       //NOTICA("sent=%d\n", GSMOPEN_P_LOG, sent);
        return SWITCH_STATUS_SUCCESS;
 }