| 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 |
//! \file vp_frametracker.cpp |
| 24 |
//! \brief vp frame tracker. |
| 25 |
//! \details vp frame tracker. |
| 26 |
//! |
| 27 |
#include "vp_frametracker.h" |
| 28 |
using namespace vp; |
| 29 |
|
| 30 |
VpFrameTracker::VpFrameTracker() : m_numberOfFrames(0), m_startTimeQueue({}), m_isEnabled(false) |
| 31 |
{ |
| 32 |
} |
| 33 |
|
| 34 |
MOS_STATUS VpFrameTracker::UpdateFPS() |
| 35 |
{ |
| 36 |
if (m_isEnabled) |
| 37 |
{ |
| 38 |
m_numberOfFrames++; |
| 39 |
if (m_numberOfFrames > FRAME_TRACING_BEGIN) |
| 40 |
{ |
| 41 |
if (m_startTimeQueue.size() <= FRAME_TRACING_PERIOD) |
| 42 |
{ |
| 43 |
m_startTimeQueue.push_back(Clock::now()); |
| 44 |
} |
| 45 |
else |
| 46 |
{ |
| 47 |
m_startTimeQueue.pop_front(); |
| 48 |
m_startTimeQueue.push_back(Clock::now()); |
| 49 |
m_numberOfFrames = MAX_FRAME_TRACING; |
| 50 |
} |
| 51 |
} |
| 52 |
} |
| 53 |
return MOS_STATUS_SUCCESS; |
| 54 |
} |
| 55 |
|
| 56 |
bool VpFrameTracker::Is60Fps() |
| 57 |
{ |
| 58 |
// Only be calculated with isEnabled flag has been set |
| 59 |
// Skip first FRAME_TRACING_BEGIN frames to avoid noise |
| 60 |
// Calculate the FPS during FRAME_TRACING_PERIOD |
| 61 |
// If the FPS is greater than FPS60_THRESHOLD, return true |
| 62 |
m_isEnabled = true; |
| 63 |
bool res = false; |
| 64 |
|
| 65 |
if (m_numberOfFrames >= MAX_FRAME_TRACING) |
| 66 |
{ |
| 67 |
double currFPS = GetFPS(); |
| 68 |
if (currFPS > FPS60_THRESHOLD) |
| 69 |
{ |
| 70 |
res = true; |
| 71 |
} |
| 72 |
else |
| 73 |
{ |
| 74 |
res = false; |
| 75 |
} |
| 76 |
} |
| 77 |
return res; |
| 78 |
} |