From be7c5331f6acb285835037374243f71db075a945 Mon Sep 17 00:00:00 2001 From: Sergey Khripchenko Date: Thu, 4 Oct 2018 09:37:49 -0700 Subject: [PATCH] FS-11436 RTP timestamp field incorrectly calculated based on fps --- src/include/switch_types.h | 5 ++++ src/include/switch_utils.h | 9 +++++++ .../mod_conference/conference_api.c | 2 +- .../mod_conference/conference_video.c | 4 +-- .../mod_conference/mod_conference.h | 9 +------ src/switch_core_media.c | 27 +++++-------------- src/switch_core_media_bug.c | 4 ++- 7 files changed, 26 insertions(+), 34 deletions(-) diff --git a/src/include/switch_types.h b/src/include/switch_types.h index 06fc25e4b3..1f6f673b9d 100644 --- a/src/include/switch_types.h +++ b/src/include/switch_types.h @@ -1620,6 +1620,11 @@ typedef struct switch_vid_params_s { uint32_t d_height; } switch_vid_params_t; +typedef struct switch_fps_s { + float fps; + int ms; + int samples; +} switch_fps_t; typedef enum { diff --git a/src/include/switch_utils.h b/src/include/switch_utils.h index 9c4b418edc..54536361db 100644 --- a/src/include/switch_utils.h +++ b/src/include/switch_utils.h @@ -1072,6 +1072,15 @@ static inline int32_t switch_calc_bitrate(int w, int h, int quality, double fps) } +static inline void switch_calc_fps(switch_fps_t *fpsP, float fps, int samplerate) +{ + fpsP->fps = fps; + fpsP->ms = (int)(1000 / fps); + fpsP->samples = (int)(samplerate / fps); + return; +} +#define switch_calc_video_fps(fpsP, fps) switch_calc_fps(fpsP, fps, 90000) + static inline int32_t switch_parse_bandwidth_string(const char *bwv) { float bw = 0; diff --git a/src/mod/applications/mod_conference/conference_api.c b/src/mod/applications/mod_conference/conference_api.c index ac219f4927..ec1640795c 100644 --- a/src/mod/applications/mod_conference/conference_api.c +++ b/src/mod/applications/mod_conference/conference_api.c @@ -1910,7 +1910,7 @@ switch_status_t conference_api_sub_vid_fps(conference_obj_t *conference, switch_ fps = (float)atof(argv[2]); if (conference_video_set_fps(conference, fps)) { - stream->write_function(stream, "+OK FPS set to [%s]\n", argv[2]); + stream->write_function(stream, "+OK FPS set to [%0.2f]\n", conference->video_fps.fps); } else { stream->write_function(stream, "-ERR Invalid FPS [%s]\n", argv[2]); } diff --git a/src/mod/applications/mod_conference/conference_video.c b/src/mod/applications/mod_conference/conference_video.c index 71fb0889d5..4ff4220fd1 100644 --- a/src/mod/applications/mod_conference/conference_video.c +++ b/src/mod/applications/mod_conference/conference_video.c @@ -49,9 +49,7 @@ int conference_video_set_fps(conference_obj_t *conference, float fps) return 0; } - conference->video_fps.fps = fps; - conference->video_fps.ms = (int) 1000 / fps; - conference->video_fps.samples = (int) 90000 / conference->video_fps.ms; + switch_calc_video_fps(&conference->video_fps, fps); for (j = 0; j <= conference->canvas_count; j++) { if (conference->canvases[j]) { diff --git a/src/mod/applications/mod_conference/mod_conference.h b/src/mod/applications/mod_conference/mod_conference.h index ccded3bfb5..16d959061d 100644 --- a/src/mod/applications/mod_conference/mod_conference.h +++ b/src/mod/applications/mod_conference/mod_conference.h @@ -119,13 +119,6 @@ /* STRUCTS */ -struct conference_fps { - float fps; - int ms; - int samples; -}; - - typedef enum { CONF_SILENT_REQ = (1 << 0), CONF_SILENT_DONE = (1 << 1) @@ -749,7 +742,7 @@ typedef struct conference_obj { switch_mutex_t *canvas_mutex; switch_hash_t *layout_hash; switch_hash_t *layout_group_hash; - struct conference_fps video_fps; + switch_fps_t video_fps; int recording_members; uint32_t video_floor_packets; video_layout_t *new_personal_vlayout; diff --git a/src/switch_core_media.c b/src/switch_core_media.c index f34613870f..c33acaff4d 100644 --- a/src/switch_core_media.c +++ b/src/switch_core_media.c @@ -6661,21 +6661,6 @@ SWITCH_DECLARE(void) switch_core_session_write_blank_video(switch_core_session_t } -typedef struct core_fps_s { - float fps; - int ms; - int samples; -} core_fps_t; - -static int video_get_fps(core_fps_t *fpsP, float fps) -{ - fpsP->fps = fps; - fpsP->ms = (int) 1000 / fps; - fpsP->samples = (int) 90000 / fpsP->ms; - - return 0; -} - static void *SWITCH_THREAD_FUNC video_write_thread(switch_thread_t *thread, void *obj) { switch_core_session_t *session = (switch_core_session_t *) obj; @@ -6688,7 +6673,7 @@ static void *SWITCH_THREAD_FUNC video_write_thread(switch_thread_t *thread, void int fps; switch_video_read_flag_t read_flags = SVR_BLOCK; switch_core_session_t *b_session = NULL; - core_fps_t fps_data = { 0 }; + switch_fps_t fps_data = { 0 }; switch_image_t *last_frame = NULL; if (switch_core_session_read_lock(session) != SWITCH_STATUS_SUCCESS) { @@ -6732,8 +6717,8 @@ static void *SWITCH_THREAD_FUNC video_write_thread(switch_thread_t *thread, void } - video_get_fps(&fps_data, fps); - switch_core_timer_init(&timer, "soft", (int)(1000 / fps) , fps_data.samples, switch_core_session_get_pool(session)); + switch_calc_video_fps(&fps_data, fps); + switch_core_timer_init(&timer, "soft", fps_data.ms, fps_data.samples, switch_core_session_get_pool(session)); while (smh->video_write_thread_running > 0 && switch_channel_up_nosig(session->channel) && smh->video_write_fh && switch_test_flag(smh->video_write_fh, SWITCH_FILE_OPEN)) { @@ -6744,8 +6729,8 @@ static void *SWITCH_THREAD_FUNC video_write_thread(switch_thread_t *thread, void //if (smh->video_write_fh && smh->video_write_fh->mm.source_fps && smh->video_write_fh->mm.source_fps != fps) { // switch_core_timer_destroy(&timer); - // video_get_fps(&fps_data, fps); - // switch_core_timer_init(&timer, "soft", (int)(1000 / fps) , fps_data.samples, switch_core_session_get_pool(session)); + // switch_calc_video_fps(&fps_data, fps); + // switch_core_timer_init(&timer, "soft", fps_data.ms, fps_data.samples, switch_core_session_get_pool(session)); //} if (smh->video_write_fh && !switch_test_flag(smh->video_write_fh, SWITCH_FILE_FLAG_VIDEO_EOF)) { @@ -6779,7 +6764,7 @@ static void *SWITCH_THREAD_FUNC video_write_thread(switch_thread_t *thread, void switch_img_fill(last_frame, 0, 0, last_frame->d_w, last_frame->d_h, &bgcolor); fr.img = last_frame; - for (x = 0; x < fps / 2; x++) { + for (x = 0; x < fps_data.fps / 2; x++) { switch_core_timer_next(&timer); fr.timestamp = timer.samplecount; fr.flags = SFF_USE_VIDEO_TIMESTAMP|SFF_RAW_RTP|SFF_RAW_RTP_PARSE_FRAME; diff --git a/src/switch_core_media_bug.c b/src/switch_core_media_bug.c index 80b6cfc600..29f7837de4 100644 --- a/src/switch_core_media_bug.c +++ b/src/switch_core_media_bug.c @@ -603,6 +603,7 @@ static void *SWITCH_THREAD_FUNC video_bug_thread(switch_thread_t *thread, void * int vw = 1280; int vh = 720; int last_w = 0, last_h = 0, other_last_w = 0, other_last_h = 0; + switch_fps_t fps_data = { 0 }; switch_rgb_color_t color = { 0 }; switch_color_set_rgb(&color, "#000000"); @@ -634,7 +635,8 @@ static void *SWITCH_THREAD_FUNC video_bug_thread(switch_thread_t *thread, void * if (mm.vw) vw = mm.vw; if (mm.vh) vh = mm.vh; - switch_core_timer_init(&timer, "soft", 1000 / fps, (90000 / (1000 / fps)), NULL); + switch_calc_video_fps(&fps_data, fps); + switch_core_timer_init(&timer, "soft", fps_data.ms, fps_data.samples, NULL); while (bug->ready) { switch_status_t status;