From 069da397f5b9e7adb10c2c9d8d03f83d195dae37 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hunyadv=C3=A1ri=20P=C3=A9ter?= Date: Tue, 20 Mar 2018 09:20:37 +0100 Subject: [PATCH] Improve recording transfer Use the same method everywhere Move the bug without stopping and starting the recording over It was broken in some circumstances and also some settings were lost FS-8900 --resolve --- src/include/switch_core.h | 1 - .../applications/mod_commands/mod_commands.c | 2 +- src/mod/endpoints/mod_loopback/mod_loopback.c | 4 +- src/mod/endpoints/mod_sofia/sofia.c | 20 ++++---- src/mod/endpoints/mod_verto/mod_verto.c | 6 +-- src/switch_channel.c | 2 +- src/switch_core_media_bug.c | 47 ------------------- src/switch_ivr_originate.c | 4 +- 8 files changed, 19 insertions(+), 67 deletions(-) diff --git a/src/include/switch_core.h b/src/include/switch_core.h index a07ea36a1e..b92bba4dfb 100644 --- a/src/include/switch_core.h +++ b/src/include/switch_core.h @@ -409,7 +409,6 @@ SWITCH_DECLARE(switch_status_t) switch_core_media_bug_remove_all_function(_In_ s #define switch_core_media_bug_remove_all(_s) switch_core_media_bug_remove_all_function(_s, NULL) SWITCH_DECLARE(switch_status_t) switch_core_media_bug_enumerate(switch_core_session_t *session, switch_stream_handle_t *stream); -SWITCH_DECLARE(switch_status_t) switch_core_media_bug_transfer_recordings(switch_core_session_t *orig_session, switch_core_session_t *new_session); SWITCH_DECLARE(switch_status_t) switch_core_media_bug_transfer_callback(switch_core_session_t *orig_session, switch_core_session_t *new_session, switch_media_bug_callback_t callback, void * (*user_data_dup_func) (switch_core_session_t *, void *)); diff --git a/src/mod/applications/mod_commands/mod_commands.c b/src/mod/applications/mod_commands/mod_commands.c index ea1b5161cf..670f5f2a37 100644 --- a/src/mod/applications/mod_commands/mod_commands.c +++ b/src/mod/applications/mod_commands/mod_commands.c @@ -2930,7 +2930,7 @@ SWITCH_STANDARD_API(transfer_function) tsession = other_session; other_session = NULL; if (switch_true(switch_channel_get_variable(channel, "recording_follow_transfer"))) { - switch_core_media_bug_transfer_recordings(tmp, tsession); + switch_ivr_transfer_recordings(tmp, tsession); } switch_core_session_rwunlock(tmp); } diff --git a/src/mod/endpoints/mod_loopback/mod_loopback.c b/src/mod/endpoints/mod_loopback/mod_loopback.c index e22ec9cc84..8360a5655b 100644 --- a/src/mod/endpoints/mod_loopback/mod_loopback.c +++ b/src/mod/endpoints/mod_loopback/mod_loopback.c @@ -866,12 +866,12 @@ static switch_status_t channel_write_frame(switch_core_session_t *session, switc if (br_a) { ch_a = switch_core_session_get_channel(br_a); - switch_core_media_bug_transfer_recordings(session, br_a); + switch_ivr_transfer_recordings(session, br_a); } if (br_b) { ch_b = switch_core_session_get_channel(br_b); - switch_core_media_bug_transfer_recordings(tech_pvt->other_session, br_b); + switch_ivr_transfer_recordings(tech_pvt->other_session, br_b); } if (ch_a && ch_b && switch_channel_test_flag(ch_a, CF_BRIDGED) && switch_channel_test_flag(ch_b, CF_BRIDGED)) { diff --git a/src/mod/endpoints/mod_sofia/sofia.c b/src/mod/endpoints/mod_sofia/sofia.c index 54f3e6802a..d0d1b7d975 100644 --- a/src/mod/endpoints/mod_sofia/sofia.c +++ b/src/mod/endpoints/mod_sofia/sofia.c @@ -6748,7 +6748,7 @@ static void sofia_handle_sip_r_invite(switch_core_session_t *session, int status p_contact->m_url->url_user, sip_redirect_dialplan, sip_redirect_context); if (switch_true(switch_channel_get_variable(channel, "recording_follow_transfer"))) { - switch_core_media_bug_transfer_recordings(session, a_session); + switch_ivr_transfer_recordings(session, a_session); } switch_ivr_session_transfer(a_session, p_contact->m_url->url_user, sip_redirect_dialplan, sip_redirect_context); @@ -6765,7 +6765,7 @@ static void sofia_handle_sip_r_invite(switch_core_session_t *session, int status p_contact->m_url->url_user); if (switch_true(switch_channel_get_variable(channel, "recording_follow_transfer"))) { - switch_core_media_bug_transfer_recordings(session, a_session); + switch_ivr_transfer_recordings(session, a_session); } switch_ivr_session_transfer(a_session, p_contact->m_url->url_user, NULL, NULL); @@ -7738,7 +7738,7 @@ static void sofia_handle_sip_i_state(switch_core_session_t *session, int status, if (switch_true(switch_channel_get_variable(channel, "recording_follow_transfer")) && (tmp = switch_core_session_locate(br_a))) { - switch_core_media_bug_transfer_recordings(session, tmp); + switch_ivr_transfer_recordings(session, tmp); switch_core_session_rwunlock(tmp); } @@ -8543,7 +8543,7 @@ void *SWITCH_THREAD_FUNC nightmare_xfer_thread_run(switch_thread_t *thread, void if (switch_channel_up(channel_a)) { if (switch_true(switch_channel_get_variable(channel_a, "recording_follow_transfer"))) { - switch_core_media_bug_transfer_recordings(session, a_session); + switch_ivr_transfer_recordings(session, a_session); } @@ -8931,12 +8931,12 @@ void sofia_handle_sip_i_refer(nua_t *nua, sofia_profile_t *profile, nua_handle_t switch_ivr_session_transfer(a_session, "park", "inline", NULL); } if (switch_true(switch_channel_get_variable(channel_a, "recording_follow_transfer"))) { - switch_core_media_bug_transfer_recordings(session, a_session); + switch_ivr_transfer_recordings(session, a_session); } if (switch_true(switch_channel_get_variable(channel_b, "recording_follow_transfer")) && (tmpsess = switch_core_session_locate(br_a))) { switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_NOTICE, "Early transfer detected with no media, moving recording bug to other leg\n"); - switch_core_media_bug_transfer_recordings(b_session, tmpsess); + switch_ivr_transfer_recordings(b_session, tmpsess); switch_core_session_rwunlock(tmpsess); } @@ -8997,14 +8997,14 @@ void sofia_handle_sip_i_refer(nua_t *nua, sofia_profile_t *profile, nua_handle_t if (switch_true(switch_channel_get_variable(channel_a, "recording_follow_transfer")) && (tmp = switch_core_session_locate(br_a))) { switch_channel_set_variable(switch_core_session_get_channel(tmp), "transfer_disposition", "bridge"); - switch_core_media_bug_transfer_recordings(session, tmp); + switch_ivr_transfer_recordings(session, tmp); switch_core_session_rwunlock(tmp); } if (switch_true(switch_channel_get_variable(channel_b, "recording_follow_transfer")) && (tmp = switch_core_session_locate(br_b))) { - switch_core_media_bug_transfer_recordings(b_session, tmp); + switch_ivr_transfer_recordings(b_session, tmp); switch_core_session_rwunlock(tmp); } @@ -9093,7 +9093,7 @@ void sofia_handle_sip_i_refer(nua_t *nua, sofia_profile_t *profile, nua_handle_t if (switch_true(switch_channel_get_variable(hup_channel, "recording_follow_transfer"))) { - switch_core_media_bug_transfer_recordings(hup_session, t_session); + switch_ivr_transfer_recordings(hup_session, t_session); } if(sofia_test_pflag(profile, PFLAG_FIRE_TRANFER_EVENTS)) { @@ -9348,7 +9348,7 @@ void sofia_handle_sip_i_refer(nua_t *nua, sofia_profile_t *profile, nua_handle_t } if (switch_true(switch_channel_get_variable(channel, "recording_follow_transfer"))) { - switch_core_media_bug_transfer_recordings(session, b_session); + switch_ivr_transfer_recordings(session, b_session); } switch_channel_set_variable(channel, SWITCH_ENDPOINT_DISPOSITION_VARIABLE, "BLIND_TRANSFER"); diff --git a/src/mod/endpoints/mod_verto/mod_verto.c b/src/mod/endpoints/mod_verto/mod_verto.c index 7a8b6e23b1..5f72e31f8b 100644 --- a/src/mod/endpoints/mod_verto/mod_verto.c +++ b/src/mod/endpoints/mod_verto/mod_verto.c @@ -3051,14 +3051,14 @@ static switch_bool_t attended_transfer(switch_core_session_t *session, switch_co if (switch_true(switch_channel_get_variable(tech_pvt->channel, "recording_follow_transfer")) && (tmp = switch_core_session_locate(br_a))) { switch_channel_set_variable(switch_core_session_get_channel(tmp), "transfer_disposition", "bridge"); - switch_core_media_bug_transfer_recordings(session, tmp); + switch_ivr_transfer_recordings(session, tmp); switch_core_session_rwunlock(tmp); } if (switch_true(switch_channel_get_variable(b_tech_pvt->channel, "recording_follow_transfer")) && (tmp = switch_core_session_locate(br_b))) { - switch_core_media_bug_transfer_recordings(b_session, tmp); + switch_ivr_transfer_recordings(b_session, tmp); switch_core_session_rwunlock(tmp); } @@ -3104,7 +3104,7 @@ static switch_bool_t attended_transfer(switch_core_session_t *session, switch_co ext = switch_channel_get_variable(hup_channel, "destination_number"); if (switch_true(switch_channel_get_variable(hup_channel, "recording_follow_transfer"))) { - switch_core_media_bug_transfer_recordings(hup_session, t_session); + switch_ivr_transfer_recordings(hup_session, t_session); } if (idest) { diff --git a/src/switch_channel.c b/src/switch_channel.c index 09fefa1f2a..684c4014ec 100644 --- a/src/switch_channel.c +++ b/src/switch_channel.c @@ -863,7 +863,7 @@ SWITCH_DECLARE(void) switch_channel_mark_hold(switch_channel_t *channel, switch_ if (switch_true(switch_channel_get_variable(channel, "flip_record_on_hold"))) { switch_core_session_t *other_session; if (switch_core_session_get_partner(channel->session, &other_session) == SWITCH_STATUS_SUCCESS) { - switch_core_media_bug_transfer_recordings(channel->session, other_session); + switch_ivr_transfer_recordings(channel->session, other_session); switch_core_session_rwunlock(other_session); } } diff --git a/src/switch_core_media_bug.c b/src/switch_core_media_bug.c index 962a9cb564..49ed61cd61 100644 --- a/src/switch_core_media_bug.c +++ b/src/switch_core_media_bug.c @@ -1012,53 +1012,6 @@ SWITCH_DECLARE(switch_status_t) switch_core_media_bug_flush_all(switch_core_sess return SWITCH_STATUS_FALSE; } -SWITCH_DECLARE(switch_status_t) switch_core_media_bug_transfer_recordings(switch_core_session_t *orig_session, switch_core_session_t *new_session) -{ - switch_media_bug_t *bp; - char *list[100] = { 0 }; - int stop_times[100] = { 0 }; - int i = 0, x = 0; - - if (orig_session->bugs) { - switch_channel_t *new_channel = switch_core_session_get_channel(new_session); - switch_channel_t *orig_channel = switch_core_session_get_channel(orig_session); - const char *save_append = switch_channel_get_variable(new_channel, "record_append"); - const char *save_stereo = switch_channel_get_variable(new_channel, "record_stereo"); - const char *orig_stereo = switch_channel_get_variable(orig_channel, "record_stereo"); - const char *new_stereo = orig_stereo; - - switch_thread_rwlock_wrlock(orig_session->bug_rwlock); - switch_channel_set_variable(new_channel, "RECORD_MIN_SEC", "0"); - switch_channel_set_variable(new_channel, "record_append", "true"); - switch_channel_set_variable(new_channel, "record_stereo", new_stereo); - - for (bp = orig_session->bugs; bp; bp = bp->next) { - if (!strcmp(bp->function, "session_record")) { - list[x] = switch_core_session_strdup(new_session, bp->target); - if (bp->stop_time > 0) { - stop_times[x] = (int)(bp->stop_time - switch_epoch_time_now(NULL)); - } - x++; - } - } - - switch_thread_rwlock_unlock(orig_session->bug_rwlock); - - for(i = 0; i < x; i++) { - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(orig_session), SWITCH_LOG_DEBUG, "Transfering %s from %s to %s\n", list[i], - switch_core_session_get_name(orig_session), switch_core_session_get_name(new_session)); - switch_ivr_stop_record_session(orig_session, list[i]); - switch_ivr_record_session(new_session, list[i], stop_times[i], NULL); - } - - switch_channel_set_variable(new_channel, "record_append", save_append); - switch_channel_set_variable(new_channel, "record_stereo", save_stereo); - - } - - return x ? SWITCH_STATUS_SUCCESS : SWITCH_STATUS_FALSE; -} - SWITCH_DECLARE(switch_status_t) switch_core_media_bug_transfer_callback(switch_core_session_t *orig_session, switch_core_session_t *new_session, switch_media_bug_callback_t callback, void * (*user_data_dup_func) (switch_core_session_t *, void *)) diff --git a/src/switch_ivr_originate.c b/src/switch_ivr_originate.c index 3794ba73b4..ba5c7aafbe 100644 --- a/src/switch_ivr_originate.c +++ b/src/switch_ivr_originate.c @@ -3610,11 +3610,11 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_originate(switch_core_session_t *sess switch_channel_set_variable(holding_channel, SWITCH_HANGUP_AFTER_BRIDGE_VARIABLE, "true"); if (caller_channel && switch_true(switch_channel_get_variable(caller_channel, "recording_follow_transfer"))) { - switch_core_media_bug_transfer_recordings(session, originate_status[i].peer_session); + switch_ivr_transfer_recordings(session, originate_status[i].peer_session); } if (switch_true(switch_channel_get_variable(holding_channel, "recording_follow_transfer"))) { - switch_core_media_bug_transfer_recordings(holding_session, originate_status[i].peer_session); + switch_ivr_transfer_recordings(holding_session, originate_status[i].peer_session); } switch_core_session_rwunlock(holding_session);