]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
FS-11436 RTP timestamp field incorrectly calculated based on fps
authorSergey Khripchenko <shripchenko@intermedia.net>
Thu, 4 Oct 2018 16:37:49 +0000 (09:37 -0700)
committerAndrey Volk <andywolk@gmail.com>
Tue, 16 Jul 2019 16:26:24 +0000 (20:26 +0400)
src/include/switch_types.h
src/include/switch_utils.h
src/mod/applications/mod_conference/conference_api.c
src/mod/applications/mod_conference/conference_video.c
src/mod/applications/mod_conference/mod_conference.h
src/switch_core_media.c
src/switch_core_media_bug.c

index 06fc25e4b39192bdbcb9a233af967e8c9600485f..1f6f673b9db02b94bdafe68f1c4c11a977c9644b 100644 (file)
@@ -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 {
index 9c4b418edc7198d491e13d2f012ab288a6bb64d8..54536361db9a9bd37f2b93cf33a0e415e8fbe96c 100644 (file)
@@ -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;
index ac219f4927507c17151618febeae7737b52657c6..ec1640795ce6e337c9caae8598404c6e073b528f 100644 (file)
@@ -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]);
        }
index 71fb0889d5c7c590741d7dcbe5d58cb8473ee4ce..4ff4220fd1e4bf6a9124a08b8ddc75fb3ed78f84 100644 (file)
@@ -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]) {
index ccded3bfb547fce3c327e5a6da801fb7b922a869..16d959061d4f806efd1fc3f35fe6be13ba8a9543 100644 (file)
 
 /* 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;
index f34613870fda9939169925a38eb749796f582696..c33acaff4d6be1311f11f4664d72b7df6f03a6af 100644 (file)
@@ -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;
index 80b6cfc6002ee860df8707473c206a27943b28fd..29f7837de40f03e9bea9660853d7b8f9a766289c 100644 (file)
@@ -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;