]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
tweak
authorAnthony Minessale <anthony.minessale@gmail.com>
Wed, 24 Sep 2008 16:32:58 +0000 (16:32 +0000)
committerAnthony Minessale <anthony.minessale@gmail.com>
Wed, 24 Sep 2008 16:32:58 +0000 (16:32 +0000)
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@9635 d0543943-73ff-0310-b7d9-9358b9ac24b2

src/mod/endpoints/mod_loopback/mod_loopback.c

index bbc2129a8614c14c671f529f20c356db98ab0db9..8949f76d391439371e47db908b2550af3201c2cc 100644 (file)
@@ -48,7 +48,8 @@ static switch_memory_pool_t *module_pool = NULL;
 typedef enum {
        TFLAG_LINKED = (1 << 0),
        TFLAG_OUTBOUND = (1 << 1),
-       TFLAG_WRITE = (1 << 2)
+       TFLAG_WRITE = (1 << 2),
+       TFLAG_CNG = (1 << 3)
 } TFLAGS;
 
 struct private_object {
@@ -299,7 +300,9 @@ static switch_status_t channel_on_hangup(switch_core_session_t *session)
        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s CHANNEL HANGUP\n", switch_channel_get_name(channel));
 
        switch_clear_flag_locked(tech_pvt, TFLAG_LINKED);
-       switch_clear_flag_locked(tech_pvt->other_tech_pvt, TFLAG_LINKED);
+       if (tech_pvt->other_tech_pvt) {
+               switch_clear_flag_locked(tech_pvt->other_tech_pvt, TFLAG_LINKED);
+       }
        
        switch_channel_hangup(tech_pvt->other_channel, switch_channel_get_cause(channel));
        switch_core_session_rwunlock(tech_pvt->other_session);
@@ -319,8 +322,18 @@ static switch_status_t channel_kill_channel(switch_core_session_t *session, int
        assert(tech_pvt != NULL);
 
        switch (sig) {
+       case SWITCH_SIG_BREAK:
+               switch_set_flag_locked(tech_pvt, TFLAG_CNG);
+               if (tech_pvt->other_tech_pvt) {
+                       switch_set_flag_locked(tech_pvt->other_tech_pvt, TFLAG_CNG);
+               }
+               break;
        case SWITCH_SIG_KILL:
                switch_channel_hangup(channel, SWITCH_CAUSE_NORMAL_CLEARING);
+               switch_clear_flag_locked(tech_pvt, TFLAG_LINKED);
+               if (tech_pvt->other_tech_pvt) {
+                       switch_clear_flag_locked(tech_pvt->other_tech_pvt, TFLAG_LINKED);
+               }
                break;
        default:
                break;
@@ -398,15 +411,23 @@ static switch_status_t channel_read_frame(switch_core_session_t *session, switch
                goto end;
        }
 
-       while(!switch_test_flag(tech_pvt->other_tech_pvt, TFLAG_WRITE)) {
+       while(tech_pvt->other_tech_pvt && !switch_test_flag(tech_pvt->other_tech_pvt, TFLAG_WRITE)) {
                if (!switch_channel_ready(channel)) {
                        goto end;
                }
+               if (switch_test_flag(tech_pvt, TFLAG_CNG)) {
+                       *frame = &tech_pvt->cng_frame;
+                       status = SWITCH_STATUS_SUCCESS;
+                       switch_clear_flag_locked(tech_pvt, TFLAG_CNG);
+                       goto end;
+               }
                switch_yield(1000);
        }
        
-       *frame = &tech_pvt->other_tech_pvt->write_frame;
-       switch_clear_flag_locked(tech_pvt->other_tech_pvt, TFLAG_WRITE);
+       if (tech_pvt->other_tech_pvt && switch_test_flag(tech_pvt->other_tech_pvt, TFLAG_WRITE)) {
+               *frame = &tech_pvt->other_tech_pvt->write_frame;
+               switch_clear_flag_locked(tech_pvt->other_tech_pvt, TFLAG_WRITE);
+       }
        
        //printf("READ %s %d\n", switch_channel_get_name(channel), (*frame)->datalen);
        status = SWITCH_STATUS_SUCCESS;