]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
FS-7285 allow eavesdrop to bridge only one leg
authorDave Olszewski <dolszewski@marchex.com>
Tue, 10 Feb 2015 02:03:56 +0000 (18:03 -0800)
committerDave Olszewski <dolszewski@marchex.com>
Sat, 14 Feb 2015 22:45:15 +0000 (14:45 -0800)
Add channel variables eavesdrop_bridge_aleg and eavesdrop_bridge_bleg,
and if one is set to true on the eavesdrop channel, bridge that leg from
the target.  If neither is specified, bridge both.

src/include/switch_types.h
src/mod/applications/mod_dptools/mod_dptools.c
src/switch_ivr_async.c

index 6cd4836846830cdecfbeb49c1bb72e101995ed37..e0d11ca9345ec7fbd47396de9ee829917b656d6d 100644 (file)
@@ -331,7 +331,9 @@ typedef enum {
        ED_MUX_READ = (1 << 0),
        ED_MUX_WRITE = (1 << 1),
        ED_DTMF = (1 << 2),
-       ED_COPY_DISPLAY = (1 << 3)
+       ED_COPY_DISPLAY = (1 << 3),
+       ED_BRIDGE_READ = (1 << 4),
+       ED_BRIDGE_WRITE = (1 << 5)
 } switch_eavesdrop_flag_enum_t;
 typedef uint32_t switch_eavesdrop_flag_t;
 
index fc515a50e0a9aeaec964487fa4ab33a76a58d440..d7eb90b41794fee83dd10c18f080de819e3a7c86 100644 (file)
@@ -818,11 +818,21 @@ SWITCH_STANDARD_APP(eavesdrop_function)
                switch_channel_t *channel = switch_core_session_get_channel(session);
                const char *require_group = switch_channel_get_variable(channel, "eavesdrop_require_group");
                const char *enable_dtmf = switch_channel_get_variable(channel, "eavesdrop_enable_dtmf");
+               const char *bridge_aleg = switch_channel_get_variable(channel, "eavesdrop_bridge_aleg");
+               const char *bridge_bleg = switch_channel_get_variable(channel, "eavesdrop_bridge_bleg");
 
                if (enable_dtmf) {
                        flags = switch_true(enable_dtmf) ? ED_DTMF : ED_NONE;
                }
 
+               /* Defaults to both, if neither is set */
+               if (switch_true(bridge_aleg)) {
+                       flags |= ED_BRIDGE_READ;
+               }
+               if (switch_true(bridge_bleg)) {
+                       flags |= ED_BRIDGE_WRITE;
+               }
+
                if (!strcasecmp((char *) data, "all")) {
                        switch_cache_db_handle_t *db = NULL;
                        char *errmsg = NULL;
index 0b58c11433b9980cf0ff7f057fdaf14ee47d24dc..2755d90a4bb5e16044b935a8e89b74fde5e751be 100644 (file)
@@ -1758,6 +1758,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_eavesdrop_session(switch_core_session
                char cid_buf[1024] = "";
                switch_caller_profile_t *cp = NULL;
                uint32_t sanity = 600;
+               switch_media_bug_flag_t read_flags = 0, write_flags = 0;
 
                if (!switch_channel_media_up(channel)) {
                        goto end;
@@ -1847,6 +1848,11 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_eavesdrop_session(switch_core_session
                write_frame.buflen = sizeof(buf);
                write_frame.rate = codec.implementation->actual_samples_per_second;
 
+               /* Make sure that at least one leg is bridged, default to both */
+               if (! (flags & (ED_BRIDGE_READ | ED_BRIDGE_WRITE))) {
+                       flags |= ED_BRIDGE_READ | ED_BRIDGE_WRITE;
+               }
+
                ep->eavesdropper = session;
                ep->flags = flags;
                switch_mutex_init(&ep->mutex, SWITCH_MUTEX_NESTED, switch_core_session_get_pool(tsession));
@@ -1862,10 +1868,16 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_eavesdrop_session(switch_core_session
                switch_buffer_add_mutex(ep->r_buffer, ep->r_mutex);
 
 
+               if (flags & ED_BRIDGE_READ) {
+                       read_flags = SMBF_READ_STREAM | SMBF_READ_REPLACE;
+               }
+               if (flags & ED_BRIDGE_WRITE) {
+                       write_flags = SMBF_WRITE_STREAM | SMBF_WRITE_REPLACE;
+               }
+
                if (switch_core_media_bug_add(tsession, "eavesdrop", uuid,
                                                                          eavesdrop_callback, ep, 0,
-                                                                         SMBF_READ_STREAM | SMBF_WRITE_STREAM | SMBF_READ_REPLACE | SMBF_WRITE_REPLACE | 
-                                                                         SMBF_READ_PING | SMBF_THREAD_LOCK | SMBF_NO_PAUSE,
+                                                                         read_flags | write_flags | SMBF_READ_PING | SMBF_THREAD_LOCK | SMBF_NO_PAUSE,
                                                                          &bug) != SWITCH_STATUS_SUCCESS) {
                        switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Cannot attach bug\n");
                        goto end;