ソースを参照

libobs: Add function to get average render time

Useful for real-time rendering statistics
jp9000 8 年 前
コミット
cb9a478821
4 ファイル変更18 行追加0 行削除
  1. 1 0
      libobs/obs-internal.h
  2. 11 0
      libobs/obs-video.c
  3. 5 0
      libobs/obs.c
  4. 1 0
      libobs/obs.h

+ 1 - 0
libobs/obs-internal.h

@@ -244,6 +244,7 @@ struct obs_core_video {
 	int                             cur_texture;
 
 	uint64_t                        video_time;
+	uint64_t                        video_avg_frame_time_ns;
 	double                          video_fps;
 	video_t                         *video;
 	pthread_t                       video_thread;

+ 11 - 0
libobs/obs-video.c

@@ -586,6 +586,7 @@ void *obs_video_thread(void *param)
 {
 	uint64_t last_time = 0;
 	uint64_t interval = video_output_get_frame_time(obs->video.video);
+	uint64_t frame_time_total_ns = 0;
 	uint64_t fps_total_ns = 0;
 	uint32_t fps_total_frames = 0;
 
@@ -599,6 +600,9 @@ void *obs_video_thread(void *param)
 	profile_register_root(video_thread_name, interval);
 
 	while (!video_output_stopped(obs->video.video)) {
+		uint64_t frame_start = os_gettime_ns();
+		uint64_t frame_time_ns;
+
 		profile_start(video_thread_name);
 
 		profile_start(tick_sources_name);
@@ -613,18 +617,25 @@ void *obs_video_thread(void *param)
 		output_frame();
 		profile_end(output_frame_name);
 
+		frame_time_ns = os_gettime_ns() - frame_start;
+
 		profile_end(video_thread_name);
 
 		profile_reenable_thread();
 
 		video_sleep(&obs->video, &obs->video.video_time, interval);
 
+		frame_time_total_ns += frame_time_ns;
 		fps_total_ns += (obs->video.video_time - last_time);
 		fps_total_frames++;
 
 		if (fps_total_ns >= 1000000000ULL) {
 			obs->video.video_fps = (double)fps_total_frames /
 				((double)fps_total_ns / 1000000000.0);
+			obs->video.video_avg_frame_time_ns =
+				frame_time_total_ns / (uint64_t)fps_total_frames;
+
+			frame_time_total_ns = 0;
 			fps_total_ns = 0;
 			fps_total_frames = 0;
 		}

+ 5 - 0
libobs/obs.c

@@ -1849,6 +1849,11 @@ double obs_get_active_fps(void)
 	return obs ? obs->video.video_fps : 0.0;
 }
 
+uint64_t obs_get_average_frame_time_ns(void)
+{
+	return obs ? obs->video.video_avg_frame_time_ns : 0;
+}
+
 enum obs_obj_type obs_obj_get_type(void *obj)
 {
 	struct obs_context_data *context = obj;

+ 1 - 0
libobs/obs.h

@@ -627,6 +627,7 @@ EXPORT void obs_view_render(obs_view_t *view);
 EXPORT uint64_t obs_get_video_frame_time(void);
 
 EXPORT double obs_get_active_fps(void);
+EXPORT uint64_t obs_get_average_frame_time_ns(void);
 
 
 /* ------------------------------------------------------------------------- */