Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENGDESK-37297: Support for setting position in media bug list #358

Open
wants to merge 5 commits into
base: telnyx/telephony/development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions src/include/switch_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,9 @@ typedef enum {
ED_BRIDGE_WRITE = (1 << 5),
ED_TAP_READ = (1 << 6),
ED_TAP_WRITE = (1 << 7),
ED_STEREO = (1 << 8)
ED_STEREO = (1 << 8),
ED_BUG_TOP = (1 << 9),
ED_BUG_BOTTOM = (1 << 10)
} switch_eavesdrop_flag_enum_t;
typedef uint32_t switch_eavesdrop_flag_t;

Expand Down Expand Up @@ -1965,9 +1967,10 @@ typedef enum {
SMBF_READ_VIDEO_PATCH = (1 << 24),
SMBF_READ_TEXT_STREAM = (1 << 25),
SMBF_FIRST = (1 << 26),
SMBF_PAUSE = (1 << 27),
SMBF_STEREO_NO_DOWN_MIX = (1 << 28),
SMBF_REAL_STEREO = (1 << 29)
SMBF_LAST = (1 << 27),
SMBF_PAUSE = (1 << 28),
SMBF_STEREO_NO_DOWN_MIX = (1 << 29),
SMBF_REAL_STEREO = (1 << 30)
} switch_media_bug_flag_enum_t;
typedef uint32_t switch_media_bug_flag_t;

Expand Down
25 changes: 24 additions & 1 deletion src/mod/applications/mod_dptools/mod_dptools.c
Original file line number Diff line number Diff line change
Expand Up @@ -934,6 +934,8 @@ SWITCH_STANDARD_APP(eavesdrop_function)
const char *bridge_bleg = switch_channel_get_variable(channel, "eavesdrop_bridge_bleg");
const char *whisper_aleg = switch_channel_get_variable(channel, "eavesdrop_whisper_aleg");
const char *whisper_bleg = switch_channel_get_variable(channel, "eavesdrop_whisper_bleg");
const char *bug_top = switch_channel_get_variable(channel, "eavesdrop_bug_top");
const char *bug_bottom = switch_channel_get_variable(channel, "eavesdrop_bug_bottom");

if (enable_dtmf) {
flags = switch_true(enable_dtmf) ? ED_DTMF : ED_NONE;
Expand All @@ -953,6 +955,14 @@ SWITCH_STANDARD_APP(eavesdrop_function)
if (switch_true(bridge_bleg)) {
flags |= ED_BRIDGE_WRITE;
}
if (switch_true(bug_top)) {
flags &= ED_BUG_BOTTOM;
flags |= ED_BUG_TOP;
}
if (switch_true(bug_bottom)) {
flags &= ED_BUG_TOP;
flags |= ED_BUG_BOTTOM;
}

if (!strcasecmp((char *) data, "all")) {
switch_cache_db_handle_t *db = NULL;
Expand Down Expand Up @@ -1036,7 +1046,20 @@ SWITCH_STANDARD_APP(three_way_function)
if (zstr(data)) {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Usage: %s\n", threeway_SYNTAX);
} else {
switch_ivr_eavesdrop_session(session, data, NULL, ED_MUX_READ | ED_MUX_WRITE);
switch_channel_t *channel = switch_core_session_get_channel(session);
const char *bug_top = switch_channel_get_variable(channel, "eavesdrop_bug_top");
const char *bug_bottom = switch_channel_get_variable(channel, "eavesdrop_bug_bottom");
switch_eavesdrop_flag_t flags = ED_MUX_READ | ED_MUX_WRITE;

if (switch_true(bug_top)) {
flags &= ED_BUG_BOTTOM;
flags |= ED_BUG_TOP;
}
if (switch_true(bug_bottom)) {
flags &= ED_BUG_TOP;
flags |= ED_BUG_BOTTOM;
}
switch_ivr_eavesdrop_session(session, data, NULL, flags);
}
}

Expand Down
28 changes: 10 additions & 18 deletions src/switch_core_media_bug.c
Original file line number Diff line number Diff line change
Expand Up @@ -817,11 +817,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_media_bug_add(switch_core_session_t
switch_media_bug_t *bug, *bp;
switch_size_t bytes;
switch_event_t *event;
#if 0
int tap_only = 1, punt = 0, added = 0;
#else
int tap_only = 1, punt = 0;
#endif

const char *p;

Expand Down Expand Up @@ -994,7 +990,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_media_bug_add(switch_core_session_t

switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Attaching BUG to %s\n", switch_channel_get_name(session->channel));
switch_thread_rwlock_wrlock(session->bug_rwlock);
#if 0

if (!session->bugs) {
session->bugs = bug;
added = 1;
Expand All @@ -1011,21 +1007,17 @@ SWITCH_DECLARE(switch_status_t) switch_core_media_bug_add(switch_core_session_t
tap_only = 0;
}

if (!added && !bp->next) {
bp->next = bug;
break;
}
}
#else
bug->next = session->bugs;
session->bugs = bug;

for(bp = session->bugs; bp; bp = bp->next) {
if (bp->ready && !switch_test_flag(bp, SMBF_TAP_NATIVE_READ) && !switch_test_flag(bp, SMBF_TAP_NATIVE_WRITE)) {
tap_only = 0;
if (!added) {
if (switch_test_flag(bp, SMBF_LAST) && !switch_test_flag(bug, SMBF_LAST)){
bug->next = bp;
bp = bug;
break;
} else if (!bp->next) {
bp->next = bug;
break;
}
}
}
#endif

switch_thread_rwlock_unlock(session->bug_rwlock);
*new_bug = bug;
Expand Down
26 changes: 22 additions & 4 deletions src/switch_ivr_async.c
Original file line number Diff line number Diff line change
Expand Up @@ -1108,9 +1108,15 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_displace_session(switch_core_session_
}

if (flags && strchr(flags, 'f')) {
bug_flags &= SMBF_LAST;
bug_flags |= SMBF_FIRST;
}

if (flags && strchr(flags, 'b')) {
bug_flags &= SMBF_FIRST;
bug_flags |= SMBF_LAST;
}

if (flags && strchr(flags, 'r')) {
if (strchr(flags, 'w')) { // r&w mode, both sides can hear the same file
int len = dh->fh.samplerate / 10 * 2 * dh->fh.channels; // init with 100ms
Expand Down Expand Up @@ -2389,7 +2395,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, stereo_flag = 0;
switch_media_bug_flag_t read_flags = 0, write_flags = 0, stereo_flag = 0, pos_flag = 0;
const char *vval;
int buf_size = 0;
int channels;
Expand Down Expand Up @@ -2567,8 +2573,10 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_eavesdrop_session(switch_core_session
read_flags = 0;
}

if (flags & ED_STEREO) {
stereo_flag = SMBF_STEREO;
if (flags & ED_BUG_TOP) {
pos_flag = SMBF_FIRST;
} else if (flags & ED_BUG_BOTTOM) {
pos_flag = SMBF_LAST;
}

if (switch_channel_test_flag(session->channel, CF_VIDEO) && switch_channel_test_flag(tsession->channel, CF_VIDEO)) {
Expand Down Expand Up @@ -2598,7 +2606,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_eavesdrop_session(switch_core_session

if (switch_core_media_bug_add(tsession, "eavesdrop", uuid,
eavesdrop_callback, ep, 0,
read_flags | write_flags | SMBF_READ_PING | SMBF_THREAD_LOCK | SMBF_NO_PAUSE | stereo_flag,
read_flags | write_flags | SMBF_READ_PING | SMBF_THREAD_LOCK | SMBF_NO_PAUSE | stereo_flag | pos_flag,
&bug) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Cannot attach bug\n");
goto end;
Expand Down Expand Up @@ -3115,6 +3123,16 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_record_session_event(switch_core_sess
flags |= SMBF_READ_STREAM;
}

if (recording_var_true(channel, vars, "RECORD_BUG_TOP")) {
flags &= SMBF_LAST;
flags |= SMBF_FIRST;
}

if (recording_var_true(channel, vars, "RECORD_BUG_BOTTOM")) {
flags &= SMBF_FIRST;
flags |= SMBF_LAST;
}

if (channels == 1) { /* if leg is already stereo this feature is not available */
if (recording_var_true(channel, vars, "RECORD_STEREO")) {
flags |= SMBF_STEREO;
Expand Down