mirror of
https://github.com/signalwire/freeswitch.git
synced 2025-03-14 04:54:49 +00:00
FS-11436 more granularly calculate 'samples' and modify requested 'fsp' accordingly
+ review all places where it used and reflect that 'fps' is (float)
This commit is contained in:
parent
be7c5331f6
commit
c546154d67
@ -1074,9 +1074,13 @@ 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)
|
static inline void switch_calc_fps(switch_fps_t *fpsP, float fps, int samplerate)
|
||||||
{
|
{
|
||||||
fpsP->fps = fps;
|
/*
|
||||||
fpsP->ms = (int)(1000 / fps);
|
implicit/truncf() - leave us with equal-or-smaller ms and thus equal-or-bigger fps, which is better for quality (than roundf()).
|
||||||
fpsP->samples = (int)(samplerate / fps);
|
also equal-or-bigger fps is better for things like (int)fps
|
||||||
|
*/
|
||||||
|
fpsP->ms = (int)(1000.0f / fps);
|
||||||
|
fpsP->fps = 1000.0f / fpsP->ms;
|
||||||
|
fpsP->samples = (int)(samplerate / 1000 * fpsP->ms); // samplerate 99.99% is a factor of 1000, so we safe here with integer div by 1000
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
#define switch_calc_video_fps(fpsP, fps) switch_calc_fps(fpsP, fps, 90000)
|
#define switch_calc_video_fps(fpsP, fps) switch_calc_fps(fpsP, fps, 90000)
|
||||||
|
@ -2797,12 +2797,12 @@ void conference_video_pop_next_image(conference_member_t *member, switch_image_t
|
|||||||
member->blanks++;
|
member->blanks++;
|
||||||
|
|
||||||
|
|
||||||
if (member->blanks == member->conference->video_fps.fps || (member->blanks % (int)(member->conference->video_fps.fps * 10)) == 0) {
|
if (member->blanks == (int)member->conference->video_fps.fps || (member->blanks % (int)(member->conference->video_fps.fps * 10)) == 0) {
|
||||||
switch_core_session_request_video_refresh(member->session);
|
switch_core_session_request_video_refresh(member->session);
|
||||||
member->good_img = 0;
|
member->good_img = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (member->blanks == member->conference->video_fps.fps * 5) {
|
if (member->blanks == (int)(member->conference->video_fps.fps * 5)) {
|
||||||
member->blackouts++;
|
member->blackouts++;
|
||||||
conference_video_check_avatar(member, SWITCH_TRUE);
|
conference_video_check_avatar(member, SWITCH_TRUE);
|
||||||
conference_video_clear_managed_kps(member);
|
conference_video_clear_managed_kps(member);
|
||||||
@ -2973,12 +2973,12 @@ void conference_video_check_auto_bitrate(conference_member_t *member, mcu_layer_
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ((kps_in = switch_calc_bitrate(vid_params.width, vid_params.height,
|
if ((kps_in = switch_calc_bitrate(vid_params.width, vid_params.height,
|
||||||
member->conference->video_quality, (int)(member->conference->video_fps.fps))) < 512) {
|
member->conference->video_quality, member->conference->video_fps.fps)) < 512) {
|
||||||
kps_in = 512;
|
kps_in = 512;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (layer) {
|
if (layer) {
|
||||||
kps = switch_calc_bitrate(screen_w, screen_h, member->conference->video_quality, (int)(member->conference->video_fps.fps));
|
kps = switch_calc_bitrate(screen_w, screen_h, member->conference->video_quality, member->conference->video_fps.fps);
|
||||||
} else {
|
} else {
|
||||||
kps = kps_in;
|
kps = kps_in;
|
||||||
}
|
}
|
||||||
@ -3701,7 +3701,7 @@ void *SWITCH_THREAD_FUNC conference_video_muxing_thread_run(switch_thread_t *thr
|
|||||||
if (imember->channel && !switch_channel_test_flag(imember->channel, CF_VIDEO_BITRATE_UNMANAGABLE) &&
|
if (imember->channel && !switch_channel_test_flag(imember->channel, CF_VIDEO_BITRATE_UNMANAGABLE) &&
|
||||||
conference_utils_test_flag(conference, CFLAG_MANAGE_INBOUND_VIDEO_BITRATE)) {
|
conference_utils_test_flag(conference, CFLAG_MANAGE_INBOUND_VIDEO_BITRATE)) {
|
||||||
switch_core_media_get_vid_params(imember->session, &vid_params);
|
switch_core_media_get_vid_params(imember->session, &vid_params);
|
||||||
kps = switch_calc_bitrate(vid_params.width, vid_params.height, conference->video_quality, (int)(imember->conference->video_fps.fps));
|
kps = switch_calc_bitrate(vid_params.width, vid_params.height, conference->video_quality, imember->conference->video_fps.fps);
|
||||||
conference_video_set_incoming_bitrate(imember, kps, SWITCH_TRUE);
|
conference_video_set_incoming_bitrate(imember, kps, SWITCH_TRUE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -4273,7 +4273,7 @@ void pop_conference_video_next_canvas_image(mcu_canvas_t *canvas, switch_image_t
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
size = switch_queue_size(canvas->video_queue);
|
size = switch_queue_size(canvas->video_queue);
|
||||||
} while(size > canvas->conference->video_fps.fps / 2);
|
} while(size > (int)(canvas->conference->video_fps.fps / 2));
|
||||||
|
|
||||||
*imgP = img;
|
*imgP = img;
|
||||||
}
|
}
|
||||||
@ -4993,7 +4993,7 @@ switch_status_t conference_video_thread_callback(switch_core_session_t *session,
|
|||||||
if (frame->img && (((member->video_layer_id > -1) && canvas_id > -1) || member->canvas) &&
|
if (frame->img && (((member->video_layer_id > -1) && canvas_id > -1) || member->canvas) &&
|
||||||
conference_utils_member_test_flag(member, MFLAG_CAN_BE_SEEN) &&
|
conference_utils_member_test_flag(member, MFLAG_CAN_BE_SEEN) &&
|
||||||
!conference_utils_member_test_flag(member, MFLAG_HOLD) &&
|
!conference_utils_member_test_flag(member, MFLAG_HOLD) &&
|
||||||
switch_queue_size(member->video_queue) < member->conference->video_fps.fps &&
|
switch_queue_size(member->video_queue) < (int)member->conference->video_fps.fps &&
|
||||||
!member->conference->canvases[canvas_id]->playing_video_file) {
|
!member->conference->canvases[canvas_id]->playing_video_file) {
|
||||||
|
|
||||||
if (conference_utils_member_test_flag(member, MFLAG_FLIP_VIDEO) ||
|
if (conference_utils_member_test_flag(member, MFLAG_FLIP_VIDEO) ||
|
||||||
|
@ -6670,10 +6670,10 @@ static void *SWITCH_THREAD_FUNC video_write_thread(switch_thread_t *thread, void
|
|||||||
switch_rtp_engine_t *v_engine;
|
switch_rtp_engine_t *v_engine;
|
||||||
int buflen = SWITCH_RTP_MAX_BUF_LEN;
|
int buflen = SWITCH_RTP_MAX_BUF_LEN;
|
||||||
switch_timer_t timer = { 0 };
|
switch_timer_t timer = { 0 };
|
||||||
int fps;
|
|
||||||
switch_video_read_flag_t read_flags = SVR_BLOCK;
|
switch_video_read_flag_t read_flags = SVR_BLOCK;
|
||||||
switch_core_session_t *b_session = NULL;
|
switch_core_session_t *b_session = NULL;
|
||||||
switch_fps_t fps_data = { 0 };
|
switch_fps_t fps_data = { 0 };
|
||||||
|
float fps;
|
||||||
switch_image_t *last_frame = NULL;
|
switch_image_t *last_frame = NULL;
|
||||||
|
|
||||||
if (switch_core_session_read_lock(session) != SWITCH_STATUS_SUCCESS) {
|
if (switch_core_session_read_lock(session) != SWITCH_STATUS_SUCCESS) {
|
||||||
@ -6707,17 +6707,14 @@ 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) {
|
if (smh->video_write_fh && smh->video_write_fh->mm.source_fps) {
|
||||||
fps = (int) smh->video_write_fh->mm.source_fps;
|
fps = smh->video_write_fh->mm.source_fps;
|
||||||
} else {
|
} else if (video_globals.fps) {
|
||||||
fps = video_globals.fps;
|
fps = video_globals.fps;
|
||||||
}
|
} else {
|
||||||
|
|
||||||
if (!fps) {
|
|
||||||
fps = 15;
|
fps = 15;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
switch_calc_video_fps(&fps_data, fps);
|
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));
|
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 &&
|
while (smh->video_write_thread_running > 0 &&
|
||||||
@ -6764,7 +6761,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);
|
switch_img_fill(last_frame, 0, 0, last_frame->d_w, last_frame->d_h, &bgcolor);
|
||||||
fr.img = last_frame;
|
fr.img = last_frame;
|
||||||
|
|
||||||
for (x = 0; x < fps_data.fps / 2; x++) {
|
for (x = 0; x < (int)(fps_data.fps / 2); x++) {
|
||||||
switch_core_timer_next(&timer);
|
switch_core_timer_next(&timer);
|
||||||
fr.timestamp = timer.samplecount;
|
fr.timestamp = timer.samplecount;
|
||||||
fr.flags = SFF_USE_VIDEO_TIMESTAMP|SFF_RAW_RTP|SFF_RAW_RTP_PARSE_FRAME;
|
fr.flags = SFF_USE_VIDEO_TIMESTAMP|SFF_RAW_RTP|SFF_RAW_RTP_PARSE_FRAME;
|
||||||
|
@ -599,11 +599,11 @@ static void *SWITCH_THREAD_FUNC video_bug_thread(switch_thread_t *thread, void *
|
|||||||
switch_frame_t frame = { 0 };
|
switch_frame_t frame = { 0 };
|
||||||
switch_timer_t timer = { 0 };
|
switch_timer_t timer = { 0 };
|
||||||
switch_mm_t mm = { 0 };
|
switch_mm_t mm = { 0 };
|
||||||
int fps = 15;
|
|
||||||
int vw = 1280;
|
int vw = 1280;
|
||||||
int vh = 720;
|
int vh = 720;
|
||||||
int last_w = 0, last_h = 0, other_last_w = 0, other_last_h = 0;
|
int last_w = 0, last_h = 0, other_last_w = 0, other_last_h = 0;
|
||||||
switch_fps_t fps_data = { 0 };
|
switch_fps_t fps_data = { 0 };
|
||||||
|
float fps;
|
||||||
switch_rgb_color_t color = { 0 };
|
switch_rgb_color_t color = { 0 };
|
||||||
switch_color_set_rgb(&color, "#000000");
|
switch_color_set_rgb(&color, "#000000");
|
||||||
|
|
||||||
@ -628,14 +628,16 @@ static void *SWITCH_THREAD_FUNC video_bug_thread(switch_thread_t *thread, void *
|
|||||||
|
|
||||||
switch_core_media_bug_get_media_params(bug, &mm);
|
switch_core_media_bug_get_media_params(bug, &mm);
|
||||||
|
|
||||||
if (mm.fps) {
|
|
||||||
fps = (int) mm.fps;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mm.vw) vw = mm.vw;
|
if (mm.vw) vw = mm.vw;
|
||||||
if (mm.vh) vh = mm.vh;
|
if (mm.vh) vh = mm.vh;
|
||||||
|
|
||||||
|
if (mm.fps) {
|
||||||
|
fps = mm.fps;
|
||||||
|
} else {
|
||||||
|
fps = 15;
|
||||||
|
}
|
||||||
switch_calc_video_fps(&fps_data, fps);
|
switch_calc_video_fps(&fps_data, fps);
|
||||||
|
|
||||||
switch_core_timer_init(&timer, "soft", fps_data.ms, fps_data.samples, NULL);
|
switch_core_timer_init(&timer, "soft", fps_data.ms, fps_data.samples, NULL);
|
||||||
|
|
||||||
while (bug->ready) {
|
while (bug->ready) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user