tests: add fps print and check condition for display
diff --git a/tests/test-device-manager.cpp b/tests/test-device-manager.cpp
index d0eaa99..fb44b2e 100644
--- a/tests/test-device-manager.cpp
+++ b/tests/test-device-manager.cpp
@@ -55,6 +55,7 @@
, _interval (1)
, _frame_count (0)
, _frame_save (0)
+ , _enable_display (false)
{
#if HAVE_LIBDRM
_display = DrmDisplay::instance();
@@ -75,6 +76,10 @@
_frame_save = frame_save;
}
+ void enable_display(bool value) {
+ _enable_display = value;
+ }
+
protected:
virtual void handle_message (SmartPtr<XCamMessage> &msg);
virtual void handle_buffer (SmartPtr<VideoBuffer> &buf);
@@ -91,6 +96,7 @@
uint32_t _frame_count;
uint32_t _frame_save;
SmartPtr<DrmDisplay> _display;
+ bool _enable_display;
};
void
@@ -102,7 +108,10 @@
void
MainDeviceManager::handle_buffer (SmartPtr<VideoBuffer> &buf)
{
- display_buf (buf);
+ FPS_CALCULATION (fps_buf, 30);
+
+ if (_enable_display)
+ display_buf (buf);
if (!_save_file)
return ;
@@ -324,6 +333,9 @@
}
}
+ if (need_display)
+ device_manager->enable_display (true);
+
if (!device.ptr ()) {
if (capture_mode == V4L2_CAPTURE_MODE_STILL)
device = new AtomispDevice (CAPTURE_DEVICE_STILL);
diff --git a/tests/test-poll-thread.cpp b/tests/test-poll-thread.cpp
index 808c592..98baf3f 100644
--- a/tests/test-poll-thread.cpp
+++ b/tests/test-poll-thread.cpp
@@ -123,8 +123,8 @@
// );
#if HAVE_LIBDRM
- if (!_drm_dev->has_frame_buffer (base))
- _drm_dev->render_setup_frame_buffer (base);
+ //if (!_drm_dev->has_frame_buffer (base))
+ _drm_dev->render_setup_frame_buffer (base);
_drm_dev->render_buffer (base);
#endif
diff --git a/tests/test_common.h b/tests/test_common.h
index 392bac2..8d7dc03 100644
--- a/tests/test_common.h
+++ b/tests/test_common.h
@@ -46,6 +46,34 @@
#define DEFAULT_CPF_FILE "/etc/atomisp/imx185.cpf"
#define DEFAULT_SAVE_FILE_NAME "capture_buffer"
+#define FPS_CALCULATION(objname, count) \
+ do{ \
+ static uint32_t num_frame = 0; \
+ static struct timeval last_sys_time; \
+ static struct timeval first_sys_time; \
+ static bool b_last_sys_time_init = false; \
+ if (!b_last_sys_time_init) { \
+ gettimeofday (&last_sys_time, NULL); \
+ gettimeofday (&first_sys_time, NULL); \
+ b_last_sys_time_init = true; \
+ } else { \
+ if ((num_frame%count)==0) { \
+ double total, current; \
+ struct timeval cur_sys_time; \
+ gettimeofday (&cur_sys_time, NULL); \
+ total = (cur_sys_time.tv_sec - first_sys_time.tv_sec)*1.0f + \
+ (cur_sys_time.tv_usec - first_sys_time.tv_usec)/1000000.0f; \
+ current = (cur_sys_time.tv_sec - last_sys_time.tv_sec)*1.0f + \
+ (cur_sys_time.tv_usec - last_sys_time.tv_usec)/1000000.0f; \
+ printf("%s Current fps: %.2f, Total avg fps: %.2f\n", \
+ #objname, ((float)(count))/current, (float)num_frame/total); \
+ last_sys_time = cur_sys_time; \
+ } \
+ } \
+ ++num_frame; \
+ }while(0)
+
+
#define PROFILING_START(name) \
static unsigned int name##_times = 0; \
static struct timeval name##_start_time; \
@@ -59,7 +87,7 @@
name##_sum_time += (name##_end_time.tv_sec - name##_start_time.tv_sec)*1000.0f + \
(name##_end_time.tv_usec - name##_start_time.tv_usec)/1000.0f; \
if (name##_times >= times_of_print) { \
- printf ("profiling %s, fps:%d duration:%.2fms\n", #name, name##_sum_time/name##_times); \
+ printf ("profiling %s, fps:%.2f duration:%.2fms\n", #name, (name##_times*1000.0f/name##_sum_time), name##_sum_time/name##_times); \
name##_times = 0; \
name##_sum_time = 0.0; \
}