From 726163aa29a9a9f7b4bbd64bf0a2110229ac2f89 Mon Sep 17 00:00:00 2001 From: jp9000 Date: Mon, 25 Jan 2016 03:58:51 -0800 Subject: [PATCH] libobs: Report lost frame count due to rendering lag This has been missing for a bit too long, and should make it easier/faster to diagnose issues users might be having. --- libobs/obs-internal.h | 4 ++++ libobs/obs-output.c | 45 ++++++++++++++++++++++++++++++------------- libobs/obs-video.c | 3 +++ 3 files changed, 39 insertions(+), 13 deletions(-) diff --git a/libobs/obs-internal.h b/libobs/obs-internal.h index 2b0be22f0..6a1ccf4c2 100644 --- a/libobs/obs-internal.h +++ b/libobs/obs-internal.h @@ -242,6 +242,8 @@ struct obs_core_video { uint64_t video_time; video_t *video; pthread_t video_thread; + uint32_t total_frames; + uint32_t lagged_frames; bool thread_initialized; bool gpu_conversion; @@ -631,6 +633,8 @@ struct obs_output { os_event_t *reconnect_stop_event; volatile bool reconnect_thread_active; + uint32_t starting_drawn_count; + uint32_t starting_lagged_count; uint32_t starting_frame_count; uint32_t starting_skipped_frame_count; diff --git a/libobs/obs-output.c b/libobs/obs-output.c index 1c69a6a24..d8a6a980a 100644 --- a/libobs/obs-output.c +++ b/libobs/obs-output.c @@ -190,6 +190,8 @@ bool obs_output_actual_start(obs_output_t *output) video_output_get_total_frames(output->video); output->starting_skipped_frame_count = video_output_get_skipped_frames(output->video); + output->starting_drawn_count = obs->video.total_frames; + output->starting_lagged_count = obs->video.lagged_frames; } if (output->delay_restart_refs) @@ -222,35 +224,52 @@ bool obs_output_start(obs_output_t *output) static void log_frame_info(struct obs_output *output) { + struct obs_core_video *video = &obs->video; + uint32_t video_frames = video_output_get_total_frames(output->video); uint32_t video_skipped = video_output_get_skipped_frames(output->video); uint32_t total = video_frames - output->starting_frame_count; uint32_t skipped = video_skipped - output->starting_skipped_frame_count; + uint32_t drawn = video->total_frames - output->starting_drawn_count; + uint32_t lagged = video->lagged_frames - output->starting_lagged_count; + int dropped = obs_output_get_frames_dropped(output); - double percentage_skipped = (double)skipped / (double)total * 100.0; + double percentage_skipped = 0.0f; + double percentage_lagged = 0.0f; + double percentage_dropped = 0.0f; + + if (total) { + percentage_skipped = (double)skipped / (double)total * 100.0; + percentage_dropped = (double)dropped / (double)total * 100.0; + } + if (drawn) + percentage_lagged = (double)lagged / (double)drawn * 100.0; blog(LOG_INFO, "Output '%s': stopping", output->context.name); - blog(LOG_INFO, "Output '%s': Total frames: %"PRIu32, + blog(LOG_INFO, "Output '%s': Total encoded frames: %"PRIu32, output->context.name, total); + blog(LOG_INFO, "Output '%s': Total drawn frames: %"PRIu32, + output->context.name, drawn); - if (total) - blog(LOG_INFO, "Output '%s': Number of skipped frames: " - "%"PRIu32" (%g%%)", + if (total && skipped) + blog(LOG_INFO, "Output '%s': Number of skipped frames due " + "to encoding lag: %"PRIu32" (%0.1f%%)", output->context.name, skipped, percentage_skipped); - - if (dropped) { - double percentage_dropped; - percentage_dropped = (double)dropped / (double)total * 100.0; - - blog(LOG_INFO, "Output '%s': Number of dropped frames: " - "%d (%g%%)", + if (drawn && lagged) + blog(LOG_INFO, "Output '%s': Number of lagged frames due " + "to rendering lag/stalls: %"PRIu32" (%0.1f%%)", + output->context.name, + lagged, percentage_lagged); + if (total && dropped) + blog(LOG_INFO, "Output '%s': Number of dropped frames due " + "to insufficient bandwidth/connection stalls: " + "%d (%0.1f%%)", output->context.name, dropped, percentage_dropped); - } } void obs_output_actual_stop(obs_output_t *output, bool force) diff --git a/libobs/obs-video.c b/libobs/obs-video.c index 3ed7a77cc..61e8715d2 100644 --- a/libobs/obs-video.c +++ b/libobs/obs-video.c @@ -528,6 +528,9 @@ static inline void video_sleep(struct obs_core_video *video, *p_time = cur_time + interval_ns * count; } + video->total_frames += count; + video->lagged_frames += count - 1; + vframe_info.timestamp = cur_time; vframe_info.count = count; circlebuf_push_back(&video->vframe_info_buffer, &vframe_info,