Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions src/include/switch_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -1706,6 +1706,7 @@ typedef enum {
CF_EARLY_MEDIA_SIP_UPDATE,
CF_DENOISED,
CF_REMOTE_RECOVERED,
CF_FORWARD_CNG_ONCE,
/* WARNING: DO NOT ADD ANY FLAGS BELOW THIS LINE */
/* IF YOU ADD NEW ONES CHECK IF THEY SHOULD PERSIST OR ZERO THEM IN switch_core_session.c switch_core_session_request_xml() */
CF_FLAG_MAX
Expand Down
8 changes: 8 additions & 0 deletions src/switch_core_io.c
Original file line number Diff line number Diff line change
Expand Up @@ -709,6 +709,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_read_frame(switch_core_sessi
switch_media_bug_t *bp;
switch_bool_t ok = SWITCH_TRUE;
int prune = 0;
int bp_cng = switch_test_flag(read_frame, SFF_CNG);
switch_thread_rwlock_rdlock(session->bug_rwlock);

for (bp = session->bugs; bp; bp = bp->next) {
Expand Down Expand Up @@ -744,6 +745,11 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_read_frame(switch_core_sessi
if ((ok = bp->callback(bp, bp->user_data, SWITCH_ABC_TYPE_READ_REPLACE)) == SWITCH_TRUE) {
read_frame = bp->read_replace_frame_out;
}

// Check if updated read_frame is a CNG
if (!bp_cng && switch_test_flag(read_frame, SFF_CNG)) {
flag |= SFF_CNG;
}
}
}

Expand Down Expand Up @@ -973,6 +979,8 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_read_frame(switch_core_sessi
} else {
if (flag & SFF_CNG) {
switch_set_flag((*frame), SFF_CNG);
} else {
switch_clear_flag((*frame), SFF_CNG);
}

if (session->bugs) {
Expand Down
36 changes: 36 additions & 0 deletions src/switch_ivr_bridge.c
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,9 @@ static void *audio_bridge_thread(switch_thread_t *thread, void *obj)
const char *banner_file = NULL;
int played_banner = 0, banner_counter = 0;
int pass_val = 0, last_pass_val = 0;
int sent_cng = 0, sent_cng_interval = 0;
switch_time_t last_sent_cng = 0;
const char *bridge_forward_cng_interval = NULL;

#ifdef SWITCH_VIDEO_IN_THREADS
struct vid_helper vh = { 0 };
Expand Down Expand Up @@ -593,6 +596,26 @@ static void *audio_bridge_thread(switch_thread_t *thread, void *obj)
max_continuous_silence_ms = 5000;
}
}

if (switch_channel_var_true(chan_a, "bridge_forward_cng_once")) {
#if DEBUG_RTP
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session_a), SWITCH_LOG_NOTICE, "Audio bridge thread: forward_cng %p\n", (void*)session_a);
#endif
switch_channel_set_flag(chan_b, CF_FORWARD_CNG_ONCE);
}

if ((bridge_forward_cng_interval = switch_channel_get_variable(chan_a, "bridge_forward_cng_interval"))) {
if (switch_true(bridge_forward_cng_interval)) {
sent_cng_interval = 5000;
} else {
if ((sent_cng_interval = atoi(bridge_forward_cng_interval)) < 0) {
sent_cng_interval = 0;
}
}
if (sent_cng_interval > 0) {
switch_channel_set_flag(chan_b, CF_FORWARD_CNG_ONCE);
}
}

if ((silence_var = switch_channel_get_variable(chan_a, "bridge_generate_comfort_noise"))) {
#if DEBUG_RTP
Expand Down Expand Up @@ -1116,6 +1139,17 @@ static void *audio_bridge_thread(switch_thread_t *thread, void *obj)
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session_a), SWITCH_LOG_NOTICE, "Audio bridge thread: skip write frame, reason: CF_ACCEPT_CNG %p %p -> %p\n", (void*)session_b, (void*)session_a, (void*)session_b);
#endif
continue;
} else if (switch_channel_test_flag(chan_b, CF_FORWARD_CNG_ONCE)) {
if (!sent_cng && !last_sent_cng) {
sent_cng = 1;
if (sent_cng_interval) {
last_sent_cng = switch_time_now();
}
} else if (sent_cng && last_sent_cng && ((switch_time_now() - last_sent_cng) / 1000) > sent_cng_interval) {
last_sent_cng = switch_time_now();
} else {
continue;
}
}
} else {
if (silence_threshold && is_silence_frame(read_frame, silence_threshold, &read_impl)) {
Expand All @@ -1127,6 +1161,8 @@ static void *audio_bridge_thread(switch_thread_t *thread, void *obj)
} else {
total_silence_frame_ms = 0;
}
sent_cng = 0;
last_sent_cng = 0;
}

if (switch_channel_test_flag(chan_a, CF_BRIDGE_NOWRITE)) {
Expand Down
Loading