]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
skypopen: select only IDLE interfaces, destroy the codec after the audio threads...
authorGiovanni Maruzzelli <gmaruzz@gmail.com>
Thu, 28 Oct 2010 08:53:52 +0000 (03:53 -0500)
committerGiovanni Maruzzelli <gmaruzz@gmail.com>
Thu, 28 Oct 2010 18:27:01 +0000 (13:27 -0500)
src/mod/endpoints/mod_skypopen/mod_skypopen.c
src/mod/endpoints/mod_skypopen/skypopen_protocol.c

index fdb6d563927e14702ca9811c6a83c3aa5c734a89..bff63d72ef00c704ab2eea278b02b15293714800 100644 (file)
@@ -213,14 +213,14 @@ static switch_status_t skypopen_codec(private_t *tech_pvt, int sample_rate, int
        if (switch_core_codec_init
                (&tech_pvt->read_codec, "L16", NULL, sample_rate, codec_ms, 1,
                 SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE, NULL, NULL) != SWITCH_STATUS_SUCCESS) {
-               ERRORA("Can't load codec?\n", SKYPOPEN_P_LOG);
+               ERRORA("skypopen_codec: Can't load codec?\n", SKYPOPEN_P_LOG);
                return SWITCH_STATUS_FALSE;
        }
 
        if (switch_core_codec_init
                (&tech_pvt->write_codec, "L16", NULL, sample_rate, codec_ms, 1,
                 SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE, NULL, NULL) != SWITCH_STATUS_SUCCESS) {
-               ERRORA("Can't load codec?\n", SKYPOPEN_P_LOG);
+               ERRORA("skypopen_codec: Can't load codec?\n", SKYPOPEN_P_LOG);
                switch_core_codec_destroy(&tech_pvt->read_codec);
                return SWITCH_STATUS_FALSE;
        }
@@ -235,10 +235,11 @@ static switch_status_t skypopen_codec(private_t *tech_pvt, int sample_rate, int
                switch_core_session_set_write_codec(session, &tech_pvt->write_codec);
                switch_core_session_rwunlock(session);
        } else {
-               ERRORA("no session\n", SKYPOPEN_P_LOG);
+               ERRORA("skypopen_codec: no session\n", SKYPOPEN_P_LOG);
                return SWITCH_STATUS_FALSE;
        }
 
+       DEBUGA_SKYPE("codecs UP\n", SKYPOPEN_P_LOG);
        return SWITCH_STATUS_SUCCESS;
 
 }
@@ -255,11 +256,11 @@ switch_status_t skypopen_tech_init(private_t *tech_pvt, switch_core_session_t *s
        switch_core_session_set_private(session, tech_pvt);
        switch_copy_string(tech_pvt->session_uuid_str, switch_core_session_get_uuid(session), sizeof(tech_pvt->session_uuid_str));
        if (!strlen(tech_pvt->session_uuid_str)) {
-               ERRORA("no tech_pvt->session_uuid_str\n", SKYPOPEN_P_LOG);
+               ERRORA("skypopen_tech_init: no tech_pvt->session_uuid_str\n", SKYPOPEN_P_LOG);
                return SWITCH_STATUS_FALSE;
        }
        if (skypopen_codec(tech_pvt, SAMPLERATE_SKYPOPEN, 20) != SWITCH_STATUS_SUCCESS) {
-               ERRORA("skypopen_codec FAILED\n", SKYPOPEN_P_LOG);
+               ERRORA("skypopen_tech_init: skypopen_codec FAILED\n", SKYPOPEN_P_LOG);
                return SWITCH_STATUS_FALSE;
        }
 
@@ -485,29 +486,6 @@ static switch_status_t channel_on_destroy(switch_core_session_t *session)
                }
                switch_mutex_unlock(tech_pvt->flag_mutex);
 
-               if (switch_core_codec_ready(&tech_pvt->read_codec)) {
-                       switch_core_codec_destroy(&tech_pvt->read_codec);
-               }
-
-               if (switch_core_codec_ready(&tech_pvt->write_codec)) {
-                       switch_core_codec_destroy(&tech_pvt->write_codec);
-               }
-
-               if (tech_pvt->timer_read.timer_interface && tech_pvt->timer_read.timer_interface->timer_next) {
-                       switch_core_timer_destroy(&tech_pvt->timer_read);
-               }
-
-               if (tech_pvt->timer_write.timer_interface && tech_pvt->timer_write.timer_interface->timer_next) {
-                       switch_core_timer_destroy(&tech_pvt->timer_write);
-               }
-
-               if (tech_pvt->read_buffer) {
-                       switch_buffer_destroy(&tech_pvt->read_buffer);
-               }
-               if (tech_pvt->write_buffer) {
-                       switch_buffer_destroy(&tech_pvt->write_buffer);
-               }
-
                DEBUGA_SKYPE("audio tcp threads to DIE\n", SKYPOPEN_P_LOG);
                conta=0;
                while(tech_pvt->tcp_srv_thread){
@@ -530,6 +508,30 @@ static switch_status_t channel_on_destroy(switch_core_session_t *session)
                }
                DEBUGA_SKYPE("audio tcp cli thread DEAD %d\n", SKYPOPEN_P_LOG, conta);
 
+
+               if (switch_core_codec_ready(&tech_pvt->read_codec)) {
+                       switch_core_codec_destroy(&tech_pvt->read_codec);
+               }
+
+               if (switch_core_codec_ready(&tech_pvt->write_codec)) {
+                       switch_core_codec_destroy(&tech_pvt->write_codec);
+               }
+
+               DEBUGA_SKYPE("codecs DOWN\n", SKYPOPEN_P_LOG);
+               if (tech_pvt->timer_read.timer_interface && tech_pvt->timer_read.timer_interface->timer_next) {
+                       switch_core_timer_destroy(&tech_pvt->timer_read);
+               }
+
+               if (tech_pvt->timer_write.timer_interface && tech_pvt->timer_write.timer_interface->timer_next) {
+                       switch_core_timer_destroy(&tech_pvt->timer_write);
+               }
+
+               if (tech_pvt->read_buffer) {
+                       switch_buffer_destroy(&tech_pvt->read_buffer);
+               }
+               if (tech_pvt->write_buffer) {
+                       switch_buffer_destroy(&tech_pvt->write_buffer);
+               }
                //DEBUGA_SKYPE("debugging_hangup 13\n", SKYPOPEN_P_LOG);
                switch_mutex_lock(tech_pvt->mutex_thread_audio_cli);
                //DEBUGA_SKYPE("debugging_hangup cli lock\n", SKYPOPEN_P_LOG);
@@ -2423,9 +2425,9 @@ private_t *find_available_skypopen_interface_rr(private_t *tech_pvt_calling)
                        tech_pvt = &globals.SKYPOPEN_INTERFACES[interface_id];
                        skype_state = tech_pvt->interface_state;
                        //DEBUGA_SKYPE("skype interface: %d, name: %s, state: %d\n", SKYPOPEN_P_LOG, interface_id, globals.SKYPOPEN_INTERFACES[interface_id].name, skype_state);
-                       if ((tech_pvt_calling ? strcmp(tech_pvt->skype_user, tech_pvt_calling->skype_user) : 1)
-                               && (SKYPOPEN_STATE_DOWN == skype_state || 0 == skype_state) && (tech_pvt->skype_callflow == CALLFLOW_STATUS_FINISHED
-                                                                                                                                                               || 0 == tech_pvt->skype_callflow)) {
+                       if ((tech_pvt_calling ? strcmp(tech_pvt->skype_user, tech_pvt_calling->skype_user) : 1) 
+                               //&& (SKYPOPEN_STATE_DOWN == skype_state || 0 == skype_state) && (tech_pvt->skype_callflow == CALLFLOW_STATUS_FINISHED || 0 == tech_pvt->skype_callflow)) {}
+                               && (SKYPOPEN_STATE_IDLE == skype_state)) {
                                DEBUGA_SKYPE("returning as available skype interface name: %s, state: %d callflow: %d\n", SKYPOPEN_P_LOG, tech_pvt->name, skype_state,
                                                         tech_pvt->skype_callflow);
                                if (tech_pvt_calling == NULL) {
@@ -2883,8 +2885,9 @@ int skypopen_transfer(private_t *tech_pvt)
                if (strlen(globals.SKYPOPEN_INTERFACES[i].name)) {
 
                        giovatech = &globals.SKYPOPEN_INTERFACES[i];
-                       /* let's look for a DOWN one */
-                       if ((giovatech->interface_state == SKYPOPEN_STATE_DOWN || giovatech->interface_state == 0) && (!strcmp(giovatech->skype_user, tech_pvt->skype_user))) { //XXX 1.0sec - can have a max of 1 call coming from the same skypename to the same skypename each 1.0 seconds
+                       /* let's look for a IDLE one */
+                       //if ((giovatech->interface_state == SKYPOPEN_STATE_DOWN || giovatech->interface_state == 0) && (!strcmp(giovatech->skype_user, tech_pvt->skype_user))) {}      //XXX 1.0sec - can have a max of 1 call coming from the same skypename to the same skypename each 1.0 seconds
+                       if ((giovatech->interface_state == SKYPOPEN_STATE_IDLE) && (!strcmp(giovatech->skype_user, tech_pvt->skype_user))) {    //XXX 1.0sec - can have a max of 1 call coming from the same skypename to the same skypename each 1.0 seconds
                                found = 1;
                                DEBUGA_SKYPE
                                        ("FOUND  (name=%s, giovatech->interface_state=%d == SKYPOPEN_STATE_DOWN) && (giovatech->skype_user=%s == tech_pvt->skype_user=%s) && (giovatech->callid_number=%s == value=%s)\n",
@@ -2975,7 +2978,7 @@ int skypopen_transfer(private_t *tech_pvt)
                        sprintf(msg_to_skype, "ALTER CALL %s TRANSFER %s", id, available_skypopen_interface->skype_user);
                        skypopen_signaling_write(tech_pvt, msg_to_skype);
                        if (tech_pvt->interface_state == SKYPOPEN_STATE_SELECTED) {
-                               tech_pvt->interface_state = SKYPOPEN_STATE_IDLE;        //we marked it SKYPOPEN_STATE_SELECTED just in case it has to make an outbound call
+                               //FIXME why this? tech_pvt->interface_state = SKYPOPEN_STATE_IDLE;      //we marked it SKYPOPEN_STATE_SELECTED just in case it has to make an outbound call
                        }
                } else {
                        /* no skypopen interfaces idle, do nothing */
index 871cc781550ad360b1a8e66ae6361d872aee0224..97e5e80aa85b12ba3a8611d98f7b1478ac2e80f9 100644 (file)
@@ -217,7 +217,7 @@ int skypopen_signaling_read(private_t *tech_pvt)
                                                ("Skype got ERROR: |||%s|||, we are trying to use this interface to make or receive a call, but another call is half-active on this interface. Let's the previous one to continue.\n",
                                                 SKYPOPEN_P_LOG, message);
                                } else if (!strncasecmp(message, "ERROR 99 CALL", 12)) {
-                                       WARNINGA("Skype got ERROR: |||%s|||, another call is active on this interface\n\n\n", SKYPOPEN_P_LOG, message);
+                                       DEBUGA_SKYPE("Skype got ERROR: |||%s|||, another call is active on this interface\n\n\n", SKYPOPEN_P_LOG, message);
                                        tech_pvt->interface_state = SKYPOPEN_STATE_ERROR_DOUBLE_CALL;
                                } else if (!strncasecmp(message, "ERROR 592 ALTER CALL", 19)) {
                                        NOTICA("Skype got ERROR about TRANSFERRING, no problem: |||%s|||\n", SKYPOPEN_P_LOG, message);
@@ -250,7 +250,7 @@ int skypopen_signaling_read(private_t *tech_pvt)
                                        return CALLFLOW_INCOMING_HANGUP;
                                } else if (!strncasecmp(message, "ERROR 589 ALTER CALL", 19)) {
                                        char msg_to_skype[256];
-                                       WARNINGA("Skype client was not able to correctly manage tcp audio sockets, probably got a local or remote hangup: |||%s|||\n", SKYPOPEN_P_LOG, message);
+                                       DEBUGA_SKYPE("Skype client was not able to correctly manage tcp audio sockets, probably got a local or remote hangup: |||%s|||\n", SKYPOPEN_P_LOG, message);
                                        if(strlen(tech_pvt->skype_call_id)){
                                        sprintf(msg_to_skype, "ALTER CALL %s HANGUP", tech_pvt->skype_call_id);
                                        skypopen_signaling_write(tech_pvt, msg_to_skype);
@@ -619,7 +619,7 @@ int skypopen_signaling_read(private_t *tech_pvt)
                                                                skypopen_strncpy(tech_pvt->skype_call_id, id, sizeof(tech_pvt->skype_call_id) - 1);
                                                                DEBUGA_SKYPE("Our remote party in skype_call %s is RINGING\n", SKYPOPEN_P_LOG, id);
                                                                if (remote_party_is_ringing(tech_pvt) != SWITCH_STATUS_SUCCESS) {
-                                                                       WARNINGA("We are getting the RINGING from a call we probably canceled, trying to get out hanging up call id: %s.\n",
+                                                                       DEBUGA_SKYPE("We are getting the RINGING from a call we probably canceled, trying to get out hanging up call id: %s.\n",
                                                                                         SKYPOPEN_P_LOG, id);
                                                                        sprintf(msg_to_skype, "ALTER CALL %s END HANGUP", id);
                                                                        skypopen_signaling_write(tech_pvt, msg_to_skype);
@@ -629,9 +629,10 @@ int skypopen_signaling_read(private_t *tech_pvt)
                                                                        // CLOUDTREE (Thomas Hazel)
                                                                        tech_pvt->ringing_state = SKYPOPEN_RINGING_INIT;
                                                                        tech_pvt->skype_callflow = CALLFLOW_CALL_IDLE;
-                                                                       tech_pvt->interface_state = SKYPOPEN_STATE_IDLE;
-                                                                       WARNINGA("we're back to IDLE\n", SKYPOPEN_P_LOG);
-                                                                       skypopen_sleep(10000);
+                                                                       tech_pvt->interface_state = SKYPOPEN_STATE_DOWN;
+                                                                       DEBUGA_SKYPE("we're now DOWN\n", SKYPOPEN_P_LOG);
+                                                                       return CALLFLOW_INCOMING_HANGUP;
+                                                                       //skypopen_sleep(10000);
 
                                                                }
                                                        } else {
@@ -769,7 +770,7 @@ int skypopen_signaling_read(private_t *tech_pvt)
 
                                        } else if (!strcasecmp(value, "LOCALHOLD")) {
                                                char msg_to_skype[256];
-                                               WARNINGA("skype_call: %s is now LOCALHOLD, let's hangup\n", SKYPOPEN_P_LOG, id);
+                                               DEBUGA_SKYPE("skype_call: %s is now LOCALHOLD, let's hangup\n", SKYPOPEN_P_LOG, id);
                                                sprintf(msg_to_skype, "ALTER CALL %s HANGUP", id);
                                                skypopen_signaling_write(tech_pvt, msg_to_skype);
                                        } else if (!strcasecmp(value, "REMOTEHOLD")) {