From dc4c38dab52c928c5f50f9be3d649613e298625e Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Tue, 5 May 2015 13:27:52 -0500 Subject: [PATCH] FS-7499 FS-7508 FS-7501 some more general improvements for initial call setup --- src/include/switch_rtp.h | 1 + src/include/switch_vidderbuffer.h | 1 + src/mod/codecs/mod_vpx/mod_vpx.c | 2 +- src/switch_channel.c | 12 ++++++++++-- src/switch_core_media.c | 30 ++++++++++++++++++++---------- src/switch_rtp.c | 20 ++++++++++++++++++-- src/switch_vidderbuffer.c | 18 ++++++++++++++++++ 7 files changed, 69 insertions(+), 15 deletions(-) diff --git a/src/include/switch_rtp.h b/src/include/switch_rtp.h index 53e26c5a87..dcb09549ee 100644 --- a/src/include/switch_rtp.h +++ b/src/include/switch_rtp.h @@ -328,6 +328,7 @@ SWITCH_DECLARE(switch_status_t) switch_rtp_activate_rtcp(switch_rtp_t *rtp_sessi SWITCH_DECLARE(switch_timer_t *) switch_rtp_get_media_timer(switch_rtp_t *rtp_session); SWITCH_DECLARE(switch_status_t) switch_rtp_set_video_buffer_size(switch_rtp_t *rtp_session, uint32_t frames); +SWITCH_DECLARE(uint32_t) switch_rtp_get_video_buffer_size(switch_rtp_t *rtp_session); /*! \brief Acvite a jitter buffer on an RTP session diff --git a/src/include/switch_vidderbuffer.h b/src/include/switch_vidderbuffer.h index 132a7bf177..73942daa03 100644 --- a/src/include/switch_vidderbuffer.h +++ b/src/include/switch_vidderbuffer.h @@ -41,6 +41,7 @@ typedef enum { SWITCH_BEGIN_EXTERN_C SWITCH_DECLARE(switch_status_t) switch_vb_create(switch_vb_t **vbp, uint32_t min_frame_len, uint32_t max_frame_len, switch_memory_pool_t *pool); SWITCH_DECLARE(switch_status_t) switch_vb_set_frames(switch_vb_t *vb, uint32_t min_frame_len, uint32_t max_frame_len); +SWITCH_DECLARE(switch_status_t) switch_vb_get_frames(switch_vb_t *vb, uint32_t *min_frame_len, uint32_t *max_frame_len); SWITCH_DECLARE(switch_status_t) switch_vb_destroy(switch_vb_t **vbp); SWITCH_DECLARE(void) switch_vb_reset(switch_vb_t *vb); SWITCH_DECLARE(void) switch_vb_debug_level(switch_vb_t *vb, uint8_t level); diff --git a/src/mod/codecs/mod_vpx/mod_vpx.c b/src/mod/codecs/mod_vpx/mod_vpx.c index 1d25acd45e..e6eeb052f7 100644 --- a/src/mod/codecs/mod_vpx/mod_vpx.c +++ b/src/mod/codecs/mod_vpx/mod_vpx.c @@ -772,7 +772,7 @@ static switch_status_t switch_vpx_decode(switch_codec_t *codec, switch_frame_t * if (context->is_vp9) { is_keyframe = IS_VP9_KEY_FRAME(*(unsigned char *)frame->data); } else { // vp8 - is_keyframe = (*(unsigned char *)frame->data & 0x10) || IS_VP8_KEY_FRAME((uint8_t *)frame->data); + is_keyframe = IS_VP8_KEY_FRAME((uint8_t *)frame->data); } // if (is_keyframe) switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "got key %d\n", is_keyframe); diff --git a/src/switch_channel.c b/src/switch_channel.c index 60b3b62b35..302d4fdbbc 100644 --- a/src/switch_channel.c +++ b/src/switch_channel.c @@ -1785,7 +1785,8 @@ SWITCH_DECLARE(char *) switch_channel_get_cap_string(switch_channel_t *channel) SWITCH_DECLARE(void) switch_channel_set_flag_value(switch_channel_t *channel, switch_channel_flag_t flag, uint32_t value) { int HELD = 0; - + int just_set = 0; + switch_assert(channel); switch_assert(channel->flag_mutex); @@ -1793,9 +1794,16 @@ SWITCH_DECLARE(void) switch_channel_set_flag_value(switch_channel_t *channel, sw if (flag == CF_LEG_HOLDING && !channel->flags[flag] && channel->flags[CF_ANSWERED]) { HELD = 1; } - channel->flags[flag] = value; + if (channel->flags[flag] != value) { + just_set = 1; + channel->flags[flag] = value; + } switch_mutex_unlock(channel->flag_mutex); + if (flag == CF_VIDEO_READY && just_set) { + switch_core_session_request_video_refresh(channel->session); + } + if (flag == CF_ORIGINATOR && switch_channel_test_flag(channel, CF_ANSWERED) && switch_channel_up_nosig(channel)) { switch_channel_set_callstate(channel, CCS_RING_WAIT); } diff --git a/src/switch_core_media.c b/src/switch_core_media.c index 85a379e2b7..0fbda36c1b 100644 --- a/src/switch_core_media.c +++ b/src/switch_core_media.c @@ -1947,8 +1947,11 @@ static void check_jb_sync(switch_core_session_t *session) jb_sync_msec = tmp; } } - // TBD IMPROVE get_fps func - fps = 15; //switch_core_media_get_video_fps(session); + if (smh->vid_frames < 10) { + fps = 15; + } else { + fps = switch_core_media_get_video_fps(session); + } if (!fps) return; @@ -1959,13 +1962,20 @@ static void check_jb_sync(switch_core_session_t *session) frames = fps / (1000 / jb_sync_msec); } - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), - SWITCH_LOG_DEBUG, "%s Sync Audio and Video Jitterbuffer to %dms %u Video Frames FPS %u\n", - switch_channel_get_name(session->channel), - jb_sync_msec, frames, fps); - - switch_rtp_set_video_buffer_size(v_engine->rtp_session, frames); - check_jb(session, NULL, jb_sync_msec, jb_sync_msec); + if (frames == switch_rtp_get_video_buffer_size(v_engine->rtp_session)) { + switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), + SWITCH_LOG_DEBUG1, "%s Audio and Video Jitterbuffer settings not changed %dms %u Video Frames FPS %u\n", + switch_channel_get_name(session->channel), + jb_sync_msec, frames, fps); + } else { + switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), + SWITCH_LOG_INFO, "%s Sync Audio and Video Jitterbuffer to %dms %u Video Frames FPS %u\n", + switch_channel_get_name(session->channel), + jb_sync_msec, frames, fps); + + switch_rtp_set_video_buffer_size(v_engine->rtp_session, frames); + check_jb(session, NULL, jb_sync_msec, jb_sync_msec); + } } @@ -2088,7 +2098,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_media_read_frame(switch_core_session } smh->vid_frames++; - if (smh->vid_frames == 45) { + if (smh->vid_frames == 1 || ((smh->vid_frames % 300) == 0)) { check_jb_sync(session); } } diff --git a/src/switch_rtp.c b/src/switch_rtp.c index 874ddf06e5..24cf12ef52 100644 --- a/src/switch_rtp.c +++ b/src/switch_rtp.c @@ -3855,6 +3855,17 @@ static void jb_logger(const char *file, const char *func, int line, int level, c va_end(ap); } +SWITCH_DECLARE(uint32_t) switch_rtp_get_video_buffer_size(switch_rtp_t *rtp_session) +{ + uint32_t frames = 0; + + if (rtp_session->vb) { + switch_vb_get_frames(rtp_session->vb, &frames, NULL); + } + + return frames; +} + SWITCH_DECLARE(switch_status_t) switch_rtp_set_video_buffer_size(switch_rtp_t *rtp_session, uint32_t frames) { if (!switch_rtp_ready(rtp_session)) { @@ -5415,7 +5426,9 @@ static switch_status_t process_rtcp_report(switch_rtp_t *rtp_session, rtcp_msg_t if (msg->header.type == RTCP_PT_PSFB && (extp->header.fmt == RTCP_PSFB_FIR || extp->header.fmt == RTCP_PSFB_PLI)) { switch_core_media_gen_key_frame(rtp_session->session); - //switch_channel_set_flag(switch_core_session_get_channel(rtp_session->session), CF_VIDEO_REFRESH_REQ); + if (rtp_session->vbw) { + switch_vb_reset(rtp_session->vbw); + } } if (msg->header.type == RTCP_PT_RTPFB && extp->header.fmt == RTCP_RTPFB_NACK) { @@ -5423,11 +5436,14 @@ static switch_status_t process_rtcp_report(switch_rtp_t *rtp_session, rtcp_msg_t int i; switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(rtp_session->session), SWITCH_LOG_DEBUG1, "Got NACK count %d\n", ntohs(extp->header.length) - 2); - switch_core_media_gen_key_frame(rtp_session->session); + + for (i = 0; i < ntohs(extp->header.length) - 2; i++) { handle_nack(rtp_session, *nack); nack++; } + + switch_core_media_gen_key_frame(rtp_session->session); } } else diff --git a/src/switch_vidderbuffer.c b/src/switch_vidderbuffer.c index 8878229098..8bc6d26150 100644 --- a/src/switch_vidderbuffer.c +++ b/src/switch_vidderbuffer.c @@ -412,6 +412,24 @@ SWITCH_DECLARE(void) switch_vb_reset(switch_vb_t *vb) switch_mutex_unlock(vb->mutex); } +SWITCH_DECLARE(switch_status_t) switch_vb_get_frames(switch_vb_t *vb, uint32_t *min_frame_len, uint32_t *max_frame_len) +{ + + switch_mutex_lock(vb->mutex); + + if (min_frame_len) { + *min_frame_len = vb->min_frame_len; + } + + if (max_frame_len) { + *max_frame_len = vb->max_frame_len; + } + + switch_mutex_unlock(vb->mutex); + + return SWITCH_STATUS_SUCCESS; +} + SWITCH_DECLARE(switch_status_t) switch_vb_set_frames(switch_vb_t *vb, uint32_t min_frame_len, uint32_t max_frame_len) { switch_mutex_lock(vb->mutex);