xbmc
PTSTracker.h
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 #pragma once
10 
11 #include <string>
12 #include <vector>
13 
14 #define DIFFRINGSIZE 120
15 #define VFR_DETECTION_THRESHOLD 3
16 #define VFR_PATTERN_THRESHOLD 2
17 
19 {
20  public:
21  CPtsTracker();
22  void Add(double pts);
23  void Flush(); //flush the saved pattern and the ringbuffer
24  void ResetVFRDetection(void);
25 
26  int GetPatternLength() { return m_patternlength; }
27  double GetFrameDuration() { return m_frameduration; }
28  double GetMaxFrameDuration(void) { return m_maxframeduration; }
29  double GetMinFrameDuration(void) { return m_minframeduration; }
30  bool HasFullBuffer() { return m_ringfill == DIFFRINGSIZE; }
31  bool VFRDetection(void) { return ((m_VFRCounter >= VFR_DETECTION_THRESHOLD) && (m_patternCounter >= VFR_PATTERN_THRESHOLD)); }
32 
33  private:
34  double m_prevpts; //last pts added
35  double m_diffring[DIFFRINGSIZE]; //ringbuffer of differences between pts'
36  int m_ringpos; //position of last diff added to ringbuffer
37  int m_ringfill; //how many diffs we have in the ringbuffer
38  double GetDiff(int diffnr); //gets diffs from now to the past
39 
40  void GetPattern(std::vector<double>& pattern); //gets the current pattern
41 
42  static bool MatchDiff(double diff1, double diff2); //checks if two diffs match by MAXERR
43  static bool MatchDifftype(int diffs1[], int diffs2[], int nrdiffs); //checks if the difftypes match
44 
45  //checks if the current pattern matches with the saved m_pattern with offset m_patternpos
46  bool CheckPattern(std::vector<double>& pattern);
47 
48  double CalcFrameDuration(); //calculates the frame duration from m_pattern
49 
50  std::vector<double> m_pattern, m_lastPattern; //the last saved pattern
51  double m_frameduration; //frameduration exposed to VideoPlayer, used for calculating the fps
52  double m_maxframeduration; //Max value detected for frame duration (for VFR files case)
53  double m_minframeduration; //Min value detected for frame duration (for VFR files case)
54  bool m_haspattern; //for the log and detecting VFR files case
55  int m_patternlength; //for the codec info
56  int m_VFRCounter; //retry counter for VFR detection
57  int m_patternCounter;
58  std::string GetPatternStr(); //also for the log
59 };
Definition: PTSTracker.h:18