diff options
Diffstat (limited to 'xbmc/utils/BitstreamStats.cpp')
| -rw-r--r-- | xbmc/utils/BitstreamStats.cpp | 70 |
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 | |||
| 13 | int64_t BitstreamStats::m_tmFreq; | ||
| 14 | |||
| 15 | BitstreamStats::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 | |||
| 29 | void BitstreamStats::AddSampleBytes(unsigned int nBytes) | ||
| 30 | { | ||
| 31 | AddSampleBits(nBytes*8); | ||
| 32 | } | ||
| 33 | |||
| 34 | void BitstreamStats::AddSampleBits(unsigned int nBits) | ||
| 35 | { | ||
| 36 | m_nBitCount += nBits; | ||
| 37 | if (m_nBitCount >= m_nEstimatedBitrate) | ||
| 38 | CalculateBitrate(); | ||
| 39 | } | ||
| 40 | |||
| 41 | void BitstreamStats::Start() | ||
| 42 | { | ||
| 43 | m_nBitCount = 0; | ||
| 44 | m_tmStart = CurrentHostCounter(); | ||
| 45 | } | ||
| 46 | |||
| 47 | void 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 | |||
