]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
add some sanity code to originate and conference
authorAnthony Minessale <anthony.minessale@gmail.com>
Wed, 25 Oct 2006 01:00:26 +0000 (01:00 +0000)
committerAnthony Minessale <anthony.minessale@gmail.com>
Wed, 25 Oct 2006 01:00:26 +0000 (01:00 +0000)
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@3189 d0543943-73ff-0310-b7d9-9358b9ac24b2

src/include/switch_resample.h
src/mod/applications/mod_conference/mod_conference.c
src/switch_ivr.c
src/switch_resample.c

index a61bba120ac35cfb25d1497c91cf4fbc7c600876..b02edf60d9decab57eaaed8d405e5787612878ad 100644 (file)
@@ -38,6 +38,7 @@
        way comes along some day. =D
        
 */
+#define switch_normalize_volume(x) if(x > 4) x = 4; if (x < -4) x = -4;
 
 #ifndef SWITCH_RESAMPLE_H
 #define SWITCH_RESAMPLE_H
@@ -154,6 +155,13 @@ SWITCH_DECLARE(int) switch_short_to_float(short *s, float *f, int len);
  */
 SWITCH_DECLARE(void) switch_swap_linear(int16_t *buf, int len);
 
+/*!
+  \brief Change the volume of a signed linear audio frame
+  \param data the audio data
+  \param samples the number of 2 byte samples
+  \param vol the volume factor -4 -> 4
+ */
+SWITCH_DECLARE(void) switch_change_sln_volume(int16_t *data, uint32_t samples, int32_t vol);
 ///\}
 
 SWITCH_END_EXTERN_C
index d804ba9556ae5c2af1417b5f749d5d4d15e0a37f..ef64144681dd064c4f5fd76c796bbf23b3835cf3 100644 (file)
@@ -31,7 +31,7 @@
  *
  */
 #include <switch.h>
-#define normalize_volume(x) if(x > 4) x = 4; if (x < -4) x = -4;
+
 static const char modname[] = "mod_conference";
 static const char global_app_name[] = "conference";
 static char *global_cf_name = "conference.conf";
@@ -229,7 +229,6 @@ static switch_status_t conference_member_play_file(conference_member_t *member,
 static switch_status_t conference_member_say(conference_obj_t *conference, conference_member_t *member, char *text, uint32_t leadin);
 static uint32_t conference_member_stop_file(conference_member_t *member, file_stop_t stop);
 static conference_obj_t *conference_new(char *name, switch_xml_t profile, switch_memory_pool_t *pool);
-static void switch_change_sln_volume(int16_t *data, uint32_t samples, int32_t vol);
 static switch_status_t chat_send(char *proto, char *from, char *to, char *subject, char *body, char *hint);
 static void launch_conference_record_thread(conference_obj_t *conference, char *path);
 
@@ -250,28 +249,6 @@ static uint32_t next_member_id(void)
        return id;
 }
 
-static void switch_change_sln_volume(int16_t *data, uint32_t samples, int32_t vol)
-{
-       int16_t *p = data;
-       uint32_t x = 0;
-       int32_t v = vol * 10;
-       double mult = (((double)abs(v)) / 100) * 2;
-       int32_t b;
-
-       if (v > 0) {
-               mult += (.2 * abs(v));
-               mult = 4;
-       } else {
-               mult -= 1;
-       }
-
-       for (x = 0; x < samples; x++) {
-               b = (int32_t)((double)p[x] * mult);
-               switch_normalize_to_16bit(b);
-               p[x] = (int16_t) b;
-       }
-}
-
 /* if other_member has a relationship with member, produce it */
 static conference_relationship_t *member_get_relationship(conference_member_t *member, conference_member_t *other_member)
 {
@@ -920,7 +897,7 @@ static void conference_loop(conference_member_t *member)
                                case '3':
                                        switch_mutex_lock(member->flag_mutex);
                                        member->volume_out_level++;
-                                       normalize_volume(member->volume_out_level);
+                                       switch_normalize_volume(member->volume_out_level);
                                        switch_mutex_unlock(member->flag_mutex);
                                        snprintf(msg, sizeof(msg), "Volume level %d", member->volume_out_level);
                                        conference_member_say(member->conference, member, msg, 0);
@@ -935,7 +912,7 @@ static void conference_loop(conference_member_t *member)
                                case '1':
                                        switch_mutex_lock(member->flag_mutex);
                                        member->volume_out_level--;
-                                       normalize_volume(member->volume_out_level);
+                                       switch_normalize_volume(member->volume_out_level);
                                        switch_mutex_unlock(member->flag_mutex);
                                        snprintf(msg, sizeof(msg), "Volume level %d", member->volume_out_level);
                                        conference_member_say(member->conference, member, msg, 0);
@@ -943,7 +920,7 @@ static void conference_loop(conference_member_t *member)
                                case '6':
                                        switch_mutex_lock(member->flag_mutex);
                                        member->volume_in_level++;
-                                       normalize_volume(member->volume_in_level);
+                                       switch_normalize_volume(member->volume_in_level);
                                        switch_mutex_unlock(member->flag_mutex);
                                        snprintf(msg, sizeof(msg), "Gain level %d", member->volume_in_level);
                                        conference_member_say(member->conference, member, msg, 0);
@@ -958,7 +935,7 @@ static void conference_loop(conference_member_t *member)
                                case '4':
                                        switch_mutex_lock(member->flag_mutex);
                                        member->volume_in_level--;
-                                       normalize_volume(member->volume_in_level);
+                                       switch_normalize_volume(member->volume_in_level);
                                        switch_mutex_unlock(member->flag_mutex);
                                        snprintf(msg, sizeof(msg), "Gain level %d", member->volume_in_level);
                                        conference_member_say(member->conference, member, msg, 0);
@@ -1756,7 +1733,7 @@ static int conference_function_volume_in_member(conference_obj_t *conference, co
                if (data) {
                        switch_mutex_lock(member->flag_mutex);
                        member->volume_in_level = atoi((char *)data);
-                       normalize_volume(member->volume_in_level);
+                       switch_normalize_volume(member->volume_in_level);
                        switch_mutex_unlock(member->flag_mutex);
                }
 
@@ -1792,7 +1769,7 @@ static int conference_function_volume_out_member(conference_obj_t *conference, c
                if (data) {
                        switch_mutex_lock(member->flag_mutex);
                        member->volume_out_level = atoi((char *)data);
-                       normalize_volume(member->volume_out_level);
+                       switch_normalize_volume(member->volume_out_level);
                        switch_mutex_unlock(member->flag_mutex);
                }
 
@@ -2458,6 +2435,17 @@ static switch_status_t conference_outcall(conference_obj_t *conference,
        char appdata[512];
        switch_call_cause_t cause = SWITCH_CAUSE_NORMAL_CLEARING;
 
+
+       if (switch_thread_rwlock_tryrdlock(conference->rwlock) != SWITCH_STATUS_SUCCESS) {
+               switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Read Lock Fail\n");
+               return SWITCH_STATUS_FALSE;
+       }
+
+       if (session) {
+               caller_channel = switch_core_session_get_channel(session);
+       
+       }
+
        if (switch_ivr_originate(session,
                                                         &peer_session,
                                                         &cause,
@@ -2469,8 +2457,7 @@ static switch_status_t conference_outcall(conference_obj_t *conference,
                                                         NULL) != SWITCH_STATUS_SUCCESS) {
                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Cannot create outgoing channel, cause: %s\n",
                                  switch_channel_cause2str(cause));
-               if (session) {
-                       caller_channel = switch_core_session_get_channel(session);
+               if (caller_channel) {
                        switch_channel_hangup(caller_channel, cause);
                }
                goto done;
@@ -2480,6 +2467,15 @@ static switch_status_t conference_outcall(conference_obj_t *conference,
        peer_channel = switch_core_session_get_channel(peer_session);
        assert(peer_channel != NULL);
 
+       if (!switch_test_flag(conference, CFLAG_RUNNING)) {
+               switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Conference is gone now, nevermind..\n");
+               if (caller_channel) {
+                       switch_channel_hangup(caller_channel, SWITCH_CAUSE_NO_ROUTE_DESTINATION);
+               }
+               switch_channel_hangup(peer_channel, SWITCH_CAUSE_NO_ROUTE_DESTINATION);
+               goto done;
+       }
+
        if (caller_channel && switch_channel_test_flag(peer_channel, CF_ANSWERED)) {
                switch_channel_answer(caller_channel);
        }
@@ -2509,6 +2505,7 @@ static switch_status_t conference_outcall(conference_obj_t *conference,
        }
 
 done:
+       switch_thread_rwlock_unlock(conference->rwlock);
        return status;
 }
 
index 62995914960a2b1711e05efcf89447a844cbbac5..2a0f22c9365de3c29981a281148e1634b3ae8429 100644 (file)
@@ -1999,6 +1999,10 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_originate(switch_core_session_t *sess
                
                }
 
+               if (!switch_channel_ready(caller_channel)) {
+                       idx = -2;
+               }
+
                if (session && !switch_channel_test_flag(caller_channel, CF_NOMEDIA)) {
                        switch_core_session_reset(session);
                }
@@ -2062,10 +2066,21 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_originate(switch_core_session_t *sess
                                        break;
                                }
                        }
+
                        if (caller_channel) {
+                               if (idx == -2) {
+                                       *cause = switch_channel_get_cause(caller_channel);
+                               } 
                                switch_channel_set_variable(caller_channel, "originate_disposition", switch_channel_cause2str(*cause));
+                               
+                       }
+                       if (idx == -2) {
+                               switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Originate Cancelled by originator termination Cause: %d [%s]\n",
+                                                                 *cause, switch_channel_cause2str(*cause));
+                       } else {
+                               switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Originate Resulted in Error Cause: %d [%s]\n",
+                                                                 *cause, switch_channel_cause2str(*cause));
                        }
-                       switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Originate Resulted in Error Cause: %d [%s]\n", *cause, switch_channel_cause2str(*cause));
                }
 
                if (!pass && write_codec.implementation) {
index 39ab3c66f2ada0d19f0ec96011b7b743c998449e..e52ae20fab368fabf36224d024de484d5371c7f1 100644 (file)
@@ -182,3 +182,37 @@ SWITCH_DECLARE(void) switch_swap_linear(int16_t *buf, int len)
                buf[i] = ((buf[i] >> 8) & 0x00ff) | ((buf[i] << 8) & 0xff00);
        }
 }
+
+SWITCH_DECLARE(void) switch_change_sln_volume(int16_t *data, uint32_t samples, int32_t vol)
+{
+    double newrate = 0;
+    int div = 0;
+
+       switch_normalize_volume(vol);
+
+       if (vol > 0) {
+               vol++;
+       } else if (vol < 0) {
+               vol--;
+       }
+
+       newrate = vol * 1.3;
+
+       if (vol < 0) {
+               newrate *= -1;
+               div++;
+       }
+
+       if (newrate) {
+               int32_t tmp;
+               int x;
+               int16_t *fp = data;
+
+               for (x = 0; x < samples; x++) {
+                       tmp = (double) div ? fp[x] / newrate : fp[x] * newrate;
+                       switch_normalize_to_16bit(tmp);
+                       fp[x] = tmp;
+               }
+       }
+}
+