From be2d60accf6c254027f74b98e8393af1f543c0ea Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Wed, 9 Nov 2016 13:04:56 -0600 Subject: [PATCH] FS-9719: Separate gen_ts_delta between audio and video and enable support to auto engage this feature for pass-thru video --- src/include/switch_types.h | 1 + src/switch_core_media.c | 32 +++++++++++++++++++++++++------- src/switch_rtp.c | 21 ++++++++++++++------- 3 files changed, 40 insertions(+), 14 deletions(-) diff --git a/src/include/switch_types.h b/src/include/switch_types.h index 576c614935..78f4f0d557 100644 --- a/src/include/switch_types.h +++ b/src/include/switch_types.h @@ -771,6 +771,7 @@ typedef enum { SWITCH_RTP_FLAG_NACK, SWITCH_RTP_FLAG_TMMBR, SWITCH_RTP_FLAG_GEN_TS_DELTA, + SWITCH_RTP_FLAG_GEN_TS_MANUAL, SWITCH_RTP_FLAG_DETECT_SSRC, SWITCH_RTP_FLAG_INVALID } switch_rtp_flag_t; diff --git a/src/switch_core_media.c b/src/switch_core_media.c index 7febd3afa9..703fdb5c1a 100644 --- a/src/switch_core_media.c +++ b/src/switch_core_media.c @@ -6607,10 +6607,6 @@ SWITCH_DECLARE(switch_status_t) switch_core_media_activate_rtp(switch_core_sessi flags[SWITCH_RTP_FLAG_BYTESWAP] = 0; } - if ((val = switch_channel_get_variable(session->channel, "rtp_gen_ts_delta")) && switch_true(val)) { - flags[SWITCH_RTP_FLAG_GEN_TS_DELTA] = 1; - } - if (a_engine->rtp_session && is_reinvite) { //const char *ip = switch_channel_get_variable(session->channel, SWITCH_LOCAL_MEDIA_IP_VARIABLE); //const char *port = switch_channel_get_variable(session->channel, SWITCH_LOCAL_MEDIA_PORT_VARIABLE); @@ -6699,6 +6695,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_media_activate_rtp(switch_core_sessi !((val = switch_channel_get_variable(session->channel, "disable_rtp_auto_adjust")) && switch_true(val))) { flags[SWITCH_RTP_FLAG_AUTOADJ]++; } + timer_name = NULL; switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, @@ -6721,6 +6718,12 @@ SWITCH_DECLARE(switch_status_t) switch_core_media_activate_rtp(switch_core_sessi } } + + if ((val = switch_channel_get_variable(session->channel, "rtp_gen_ts_delta_audio")) && switch_true(val)) { + flags[SWITCH_RTP_FLAG_GEN_TS_MANUAL] = 1; + flags[SWITCH_RTP_FLAG_GEN_TS_DELTA] = 1; + } + if (switch_channel_up(session->channel)) { switch_channel_set_variable(session->channel, "rtp_use_timer_name", timer_name); @@ -7121,6 +7124,11 @@ SWITCH_DECLARE(switch_status_t) switch_core_media_activate_rtp(switch_core_sessi flags[SWITCH_RTP_FLAG_AUTOADJ]++; } + if ((val = switch_channel_get_variable(session->channel, "rtp_gen_ts_delta_video")) && switch_true(val)) { + flags[SWITCH_RTP_FLAG_GEN_TS_MANUAL] = 1; + flags[SWITCH_RTP_FLAG_GEN_TS_DELTA] = 1; + } + if (switch_channel_test_flag(session->channel, CF_PROXY_MEDIA)) { flags[SWITCH_RTP_FLAG_PROXY_MEDIA]++; } @@ -11501,7 +11509,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_write_video_frame(switch_cor switch_image_t *dup_img = NULL, *img = frame->img; switch_status_t encode_status; switch_frame_t write_frame = {0}; - //switch_rtp_engine_t *v_engine; + switch_rtp_engine_t *v_engine; switch_assert(session); @@ -11535,7 +11543,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_write_video_frame(switch_cor return SWITCH_STATUS_SUCCESS; } - //v_engine = &smh->engines[SWITCH_MEDIA_TYPE_VIDEO]; + v_engine = &smh->engines[SWITCH_MEDIA_TYPE_VIDEO]; if (smh->write_mutex[SWITCH_MEDIA_TYPE_VIDEO] && switch_mutex_trylock(smh->write_mutex[SWITCH_MEDIA_TYPE_VIDEO]) != SWITCH_STATUS_SUCCESS) { /* return CNG, another thread is already writing */ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG1, "%s is already being written to for %s\n", @@ -11559,8 +11567,18 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_write_video_frame(switch_cor } if (!img) { - switch_status_t vstatus = switch_core_session_write_encoded_video_frame(session, frame, flags, stream_id); + switch_status_t vstatus; + + if (!switch_rtp_test_flag(v_engine->rtp_session, SWITCH_RTP_FLAG_GEN_TS_MANUAL)) { + switch_rtp_set_flag(v_engine->rtp_session, SWITCH_RTP_FLAG_GEN_TS_DELTA); + } + + vstatus = switch_core_session_write_encoded_video_frame(session, frame, flags, stream_id); switch_goto_status(vstatus, done); + } else { + if (!switch_rtp_test_flag(v_engine->rtp_session, SWITCH_RTP_FLAG_GEN_TS_MANUAL)) { + switch_rtp_clear_flag(v_engine->rtp_session, SWITCH_RTP_FLAG_GEN_TS_DELTA); + } } diff --git a/src/switch_rtp.c b/src/switch_rtp.c index 840411e817..318d077dfc 100644 --- a/src/switch_rtp.c +++ b/src/switch_rtp.c @@ -7578,17 +7578,24 @@ static int rtp_common_write(switch_rtp_t *rtp_session, if (ntohl(send_msg->header.ts) != rtp_session->ts_norm.last_frame) { - if (switch_rtp_test_flag(rtp_session, SWITCH_RTP_FLAG_GEN_TS_DELTA)) { - int32_t delta = (int32_t) (ntohl(send_msg->header.ts) - rtp_session->ts_norm.last_frame); + int32_t delta = (int32_t) (ntohl(send_msg->header.ts) - rtp_session->ts_norm.last_frame); - if (switch_rtp_test_flag(rtp_session, SWITCH_RTP_FLAG_VIDEO) && delta > 0 && delta < 90000) { - rtp_session->ts_norm.delta = delta; - } - + if (switch_rtp_test_flag(rtp_session, SWITCH_RTP_FLAG_VIDEO) && delta > 0 && delta < 90000) { + rtp_session->ts_norm.delta = delta; + } + + if (switch_rtp_test_flag(rtp_session, SWITCH_RTP_FLAG_GEN_TS_DELTA)) { rtp_session->ts_norm.ts += rtp_session->ts_norm.delta; } else { switch_core_timer_sync(&rtp_session->timer); - rtp_session->ts_norm.ts = rtp_session->timer.samplecount; + if (rtp_session->ts_norm.ts == rtp_session->timer.samplecount) { + rtp_session->ts_norm.ts = rtp_session->timer.samplecount + 1; + } else { + rtp_session->ts_norm.ts = rtp_session->timer.samplecount; + } + if (send_msg->header.m) { + rtp_session->ts_norm.last_frame++; + } } }