Merge pull request #5101 from FernetMenta/ffmpeg-threads
[vuplus_xbmc] / xbmc / cores / dvdplayer / DVDTSCorrection.h
1 #pragma once
2
3 /*
4  *      Copyright (C) 2005-2013 Team XBMC
5  *      http://xbmc.org
6  *
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)
10  *  any later version.
11  *
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.
16  *
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/>.
20  *
21  */
22
23 #include <vector>
24
25 #include "utils/StdString.h"
26
27 #define DIFFRINGSIZE 120
28
29 class CPullupCorrection
30 {
31   public:
32     CPullupCorrection();
33     void   Add(double pts);
34     void   Flush(); //flush the saved pattern and the ringbuffer
35
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; }
40
41   private:
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
47
48     void GetPattern(std::vector<double>& pattern);     //gets the current pattern
49     void GetDifftypes(std::vector<double>& difftypes); //gets the difftypes from the ringbuffer
50
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
53
54     //builds a pattern of timestamps in the ringbuffer
55     void BuildPattern(std::vector<double>& pattern, int patternlength);
56
57     //checks if the current pattern matches with the saved m_pattern with offset m_patternpos
58     bool CheckPattern(std::vector<double>& pattern);
59
60     double CalcFrameDuration(); //calculates the frame duration from m_pattern
61
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
70 };