4 * Copyright (C) 2005-2013 Team XBMC
7 * This Program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2, or (at your option)
12 * This Program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with XBMC; see the file COPYING. If not, see
19 * <http://www.gnu.org/licenses/>.
25 #include "utils/StdString.h"
27 #define DIFFRINGSIZE 120
29 class CPullupCorrection
34 void Flush(); //flush the saved pattern and the ringbuffer
36 double GetCorrection() { return m_ptscorrection; }
37 int GetPatternLength() { return m_patternlength; }
38 double GetFrameDuration() { return m_frameduration; }
39 bool HasFullBuffer() { return m_ringfill == DIFFRINGSIZE; }
42 double m_prevpts; //last pts added
43 double m_diffring[DIFFRINGSIZE]; //ringbuffer of differences between pts'
44 int m_ringpos; //position of last diff added to ringbuffer
45 int m_ringfill; //how many diffs we have in the ringbuffer
46 double GetDiff(int diffnr); //gets diffs from now to the past
48 void GetPattern(std::vector<double>& pattern); //gets the current pattern
49 void GetDifftypes(std::vector<double>& difftypes); //gets the difftypes from the ringbuffer
51 static bool MatchDiff(double diff1, double diff2); //checks if two diffs match by MAXERR
52 static bool MatchDifftype(int* diffs1, int* diffs2, int nrdiffs); //checks if the difftypes match
54 //builds a pattern of timestamps in the ringbuffer
55 void BuildPattern(std::vector<double>& pattern, int patternlength);
57 //checks if the current pattern matches with the saved m_pattern with offset m_patternpos
58 bool CheckPattern(std::vector<double>& pattern);
60 double CalcFrameDuration(); //calculates the frame duration from m_pattern
62 std::vector<double> m_pattern; //the last saved pattern
63 int m_patternpos; //the position of the pattern in the ringbuffer, moves one to the past each time a pts is added
64 double m_ptscorrection; //the correction needed for the last added pts
65 double m_trackingpts; //tracked pts for smoothing the timestamps
66 double m_frameduration; //frameduration exposed to dvdplayer, used for calculating the fps
67 bool m_haspattern; //for the log
68 int m_patternlength; //for the codec info
69 CStdString GetPatternStr(); //also for the log