Debian Codegraph @

media_softlet/agnostic/common/vp/hal/packet/vp_frametracker.h

raw
1 /*
2 * Copyright (c) 2024, Intel Corporation
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included
12 * in all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 * OTHER DEALINGS IN THE SOFTWARE.
21 */
22
23 //!
24 //! \file vp_frametracker.h
25 //! \brief vp frame tracker.
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 } // namespace vp
81 #endif // !__VP_FRAMETRACKER_H__