FS-11436 RTP timestamp field incorrectly calculated based on fps

This commit is contained in:
Sergey Khripchenko 2018-10-04 09:37:49 -07:00 committed by Andrey Volk
parent 8534a4b86a
commit be7c5331f6
7 changed files with 26 additions and 34 deletions

View 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 {

View 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;

View 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]);
}

View 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]) {

View File

@ -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;

View 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;

View 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;