summaryrefslogtreecommitdiffstats
path: root/xbmc/utils/BitstreamStats.cpp
diff options
context:
space:
mode:
authormanuel <manuel@mausz.at>2020-10-19 00:52:24 +0200
committermanuel <manuel@mausz.at>2020-10-19 00:52:24 +0200
commitbe933ef2241d79558f91796cc5b3a161f72ebf9c (patch)
treefe3ab2f130e20c99001f2d7a81d610c78c96a3f4 /xbmc/utils/BitstreamStats.cpp
parent5f8335c1e49ce108ef3481863833c98efa00411b (diff)
downloadkodi-pvr-build-be933ef2241d79558f91796cc5b3a161f72ebf9c.tar.gz
kodi-pvr-build-be933ef2241d79558f91796cc5b3a161f72ebf9c.tar.bz2
kodi-pvr-build-be933ef2241d79558f91796cc5b3a161f72ebf9c.zip
sync with upstream
Diffstat (limited to 'xbmc/utils/BitstreamStats.cpp')
-rw-r--r--xbmc/utils/BitstreamStats.cpp70
1 files changed, 70 insertions, 0 deletions
diff --git a/xbmc/utils/BitstreamStats.cpp b/xbmc/utils/BitstreamStats.cpp
new file mode 100644
index 0000000..a35a757
--- /dev/null
+++ b/xbmc/utils/BitstreamStats.cpp
@@ -0,0 +1,70 @@
1/*
2 * Copyright (C) 2005-2018 Team Kodi
3 * This file is part of Kodi - https://kodi.tv
4 *
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 * See LICENSES/README.md for more information.
7 */
8
9#include "BitstreamStats.h"
10
11#include "utils/TimeUtils.h"
12
13int64_t BitstreamStats::m_tmFreq;
14
15BitstreamStats::BitstreamStats(unsigned int nEstimatedBitrate)
16{
17 m_dBitrate = 0.0;
18 m_dMaxBitrate = 0.0;
19 m_dMinBitrate = -1.0;
20
21 m_nBitCount = 0;
22 m_nEstimatedBitrate = nEstimatedBitrate;
23 m_tmStart = 0LL;
24
25 if (m_tmFreq == 0LL)
26 m_tmFreq = CurrentHostFrequency();
27}
28
29void BitstreamStats::AddSampleBytes(unsigned int nBytes)
30{
31 AddSampleBits(nBytes*8);
32}
33
34void BitstreamStats::AddSampleBits(unsigned int nBits)
35{
36 m_nBitCount += nBits;
37 if (m_nBitCount >= m_nEstimatedBitrate)
38 CalculateBitrate();
39}
40
41void BitstreamStats::Start()
42{
43 m_nBitCount = 0;
44 m_tmStart = CurrentHostCounter();
45}
46
47void BitstreamStats::CalculateBitrate()
48{
49 int64_t tmNow;
50 tmNow = CurrentHostCounter();
51
52 double elapsed = (double)(tmNow - m_tmStart) / (double)m_tmFreq;
53 // only update once every 2 seconds
54 if (elapsed >= 2)
55 {
56 m_dBitrate = (double)m_nBitCount / elapsed;
57
58 if (m_dBitrate > m_dMaxBitrate)
59 m_dMaxBitrate = m_dBitrate;
60
61 if (m_dBitrate < m_dMinBitrate || m_dMinBitrate == -1)
62 m_dMinBitrate = m_dBitrate;
63
64 Start();
65 }
66}
67
68
69
70