| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
#ifndef __VP_FRAMETRACKER_H__ |
| 28 |
#define __VP_FRAMETRACKER_H__ |
| 29 |
#include <chrono> |
| 30 |
#include <stack> |
| 31 |
#include "mos_defs.h" |
| 32 |
#include "vp_utils.h" |
| 33 |
|
| 34 |
namespace vp |
| 35 |
{ |
| 36 |
using Clock = std::chrono::high_resolution_clock; |
| 37 |
using TimePoint = Clock::time_point; |
| 38 |
|
| 39 |
#define FRAME_TRACING_BEGIN 2 //Skip first 2 frames. Tuning the value can change skipped frame |
| 40 |
#define FRAME_TRACING_PERIOD 5 //Calbrate FPS with 5 frames, can enlarge/decrease calculation window |
| 41 |
#define MAX_FRAME_TRACING (FRAME_TRACING_BEGIN + FRAME_TRACING_PERIOD + 1) |
| 42 |
#define FPS60_THRESHOLD 33 // 60FPS threshold. Can tune this value according to different senario |
| 43 |
|
| 44 |
class VpFrameTracker |
| 45 |
{ |
| 46 |
public: |
| 47 |
VpFrameTracker(); |
| 48 |
|
| 49 |
virtual ~VpFrameTracker() |
| 50 |
{ |
| 51 |
m_startTimeQueue.clear(); |
| 52 |
}; |
| 53 |
|
| 54 |
virtual MOS_STATUS UpdateFPS(); |
| 55 |
|
| 56 |
virtual bool Is60Fps(); |
| 57 |
|
| 58 |
double GetFPS() |
| 59 |
{ |
| 60 |
std::chrono::duration<double> elapsed = m_startTimeQueue.back() - m_startTimeQueue.front(); |
| 61 |
|
| 62 |
if (m_startTimeQueue.size() != (FRAME_TRACING_PERIOD + 1)) |
| 63 |
{ |
| 64 |
VP_RENDER_ASSERTMESSAGE("Frame tracker queue size is not correct!"); |
| 65 |
VP_RENDER_ASSERT(m_startTimeQueue.size() == (FRAME_TRACING_PERIOD + 1)); |
| 66 |
} |
| 67 |
|
| 68 |
return ((1.0 / elapsed.count()) * FRAME_TRACING_PERIOD); |
| 69 |
} |
| 70 |
|
| 71 |
protected: |
| 72 |
|
| 73 |
int m_numberOfFrames; |
| 74 |
std::deque<TimePoint> m_startTimeQueue; |
| 75 |
bool m_isEnabled = false; |
| 76 |
|
| 77 |
MEDIA_CLASS_DEFINE_END(vp__VpFrameTracker) |
| 78 |
}; |
| 79 |
|
| 80 |
} |
| 81 |
#endif |