浏览代码

libobs: Add obs_get_active_fps function

Allows getting the current active framerate that the core is rendering
with.  This takes in to account any rendering lag or stalls that may be
occurring.
jp9000 9 年之前
父节点
当前提交
95ce556051
共有 4 个文件被更改,包括 20 次插入0 次删除
  1. 1 0
      libobs/obs-internal.h
  2. 12 0
      libobs/obs-video.c
  3. 5 0
      libobs/obs.c
  4. 2 0
      libobs/obs.h

+ 1 - 0
libobs/obs-internal.h

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

+ 12 - 0
libobs/obs-video.c

@@ -573,6 +573,8 @@ void *obs_video_thread(void *param)
 {
 {
 	uint64_t last_time = 0;
 	uint64_t last_time = 0;
 	uint64_t interval = video_output_get_frame_time(obs->video.video);
 	uint64_t interval = video_output_get_frame_time(obs->video.video);
+	uint64_t fps_total_ns = 0;
+	uint32_t fps_total_frames = 0;
 
 
 	obs->video.video_time = os_gettime_ns();
 	obs->video.video_time = os_gettime_ns();
 
 
@@ -603,6 +605,16 @@ void *obs_video_thread(void *param)
 		profile_reenable_thread();
 		profile_reenable_thread();
 
 
 		video_sleep(&obs->video, &obs->video.video_time, interval);
 		video_sleep(&obs->video, &obs->video.video_time, interval);
+
+		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);
+			fps_total_ns = 0;
+			fps_total_frames = 0;
+		}
 	}
 	}
 
 
 	UNUSED_PARAMETER(param);
 	UNUSED_PARAMETER(param);

+ 5 - 0
libobs/obs.c

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

+ 2 - 0
libobs/obs.h

@@ -610,6 +610,8 @@ EXPORT void obs_view_render(obs_view_t *view);
 
 
 EXPORT uint64_t obs_get_video_frame_time(void);
 EXPORT uint64_t obs_get_video_frame_time(void);
 
 
+EXPORT double obs_get_active_fps(void);
+
 
 
 /* ------------------------------------------------------------------------- */
 /* ------------------------------------------------------------------------- */
 /* Display context */
 /* Display context */