Merge pull request #5101 from FernetMenta/ffmpeg-threads
[vuplus_xbmc] / xbmc / cores / dvdplayer / DVDPlayerVideo.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 "threads/Thread.h"
24 #include "DVDMessageQueue.h"
25 #include "DVDDemuxers/DVDDemuxUtils.h"
26 #include "DVDCodecs/Video/DVDVideoCodec.h"
27 #include "DVDClock.h"
28 #include "DVDOverlayContainer.h"
29 #include "DVDTSCorrection.h"
30 #ifdef HAS_VIDEO_PLAYBACK
31 #include "cores/VideoRenderers/RenderManager.h"
32 #endif
33
34 class CDemuxStreamVideo;
35 class CDVDOverlayCodecCC;
36
37 #define VIDEO_PICTURE_QUEUE_SIZE 1
38
39 class CDVDPlayerVideo : public CThread
40 {
41 public:
42   CDVDPlayerVideo( CDVDClock* pClock
43                  , CDVDOverlayContainer* pOverlayContainer
44                  , CDVDMessageQueue& parent);
45   virtual ~CDVDPlayerVideo();
46
47   bool OpenStream(CDVDStreamInfo &hint);
48   void OpenStream(CDVDStreamInfo &hint, CDVDVideoCodec* codec);
49   void CloseStream(bool bWaitForBuffers);
50
51   void StepFrame();
52   void Flush();
53
54   // waits until all available data has been rendered
55   // just waiting for packetqueue should be enough for video
56   void WaitForBuffers()                             { m_messageQueue.WaitUntilEmpty(); }
57   bool AcceptsData() const                          { return !m_messageQueue.IsFull(); }
58   bool HasData() const                              { return m_messageQueue.GetDataSize() > 0; }
59   int  GetLevel();
60   bool IsInited() const                             { return m_messageQueue.IsInited(); }
61   void SendMessage(CDVDMsg* pMsg, int priority = 0) { m_messageQueue.Put(pMsg, priority); }
62
63   void EnableSubtitle(bool bEnable)                 { m_bRenderSubs = bEnable; }
64   bool IsSubtitleEnabled()                          { return m_bRenderSubs; }
65
66   void EnableFullscreen(bool bEnable)               { m_bAllowFullscreen = bEnable; }
67
68 #ifdef HAS_VIDEO_PLAYBACK
69   void GetVideoRect(CRect& SrcRect, CRect& DestRect)  { g_renderManager.GetVideoRect(SrcRect, DestRect); }
70   float GetAspectRatio()                            { return g_renderManager.GetAspectRatio(); }
71 #endif
72
73   double GetDelay()                                { return m_iVideoDelay; }
74   void SetDelay(double delay)                      { m_iVideoDelay = delay; }
75
76   double GetSubtitleDelay()                                { return m_iSubtitleDelay; }
77   void SetSubtitleDelay(double delay)                      { m_iSubtitleDelay = delay; }
78
79   bool IsStalled()                                  { return m_stalled; }
80   int GetNrOfDroppedFrames()                        { return m_iDroppedFrames; }
81
82   bool InitializedOutputDevice();
83
84   double GetCurrentPts()                           { return m_iCurrentPts; }
85   int    GetPullupCorrection()                     { return m_pullupCorrection.GetPatternLength(); }
86
87   double GetOutputDelay(); /* returns the expected delay, from that a packet is put in queue */
88   std::string GetPlayerInfo();
89   int GetVideoBitrate();
90   std::string GetStereoMode();
91
92   void SetSpeed(int iSpeed);
93
94   // classes
95   CDVDOverlayContainer* m_pOverlayContainer;
96
97   CDVDClock* m_pClock;
98
99 protected:
100   virtual void OnStartup();
101   virtual void OnExit();
102   virtual void Process();
103
104 #define EOS_ABORT 1
105 #define EOS_DROPPED 2
106 #define EOS_VERYLATE 4
107
108   void AutoCrop(DVDVideoPicture* pPicture);
109   void AutoCrop(DVDVideoPicture *pPicture, RECT &crop);
110   CRect m_crop;
111
112   int OutputPicture(const DVDVideoPicture* src, double pts);
113 #ifdef HAS_VIDEO_PLAYBACK
114   void ProcessOverlays(DVDVideoPicture* pSource, double pts);
115 #endif
116   void ProcessVideoUserData(DVDVideoUserData* pVideoUserData, double pts);
117
118   CDVDMessageQueue m_messageQueue;
119   CDVDMessageQueue& m_messageParent;
120
121   double m_iCurrentPts; // last pts displayed
122   double m_iVideoDelay;
123   double m_iSubtitleDelay;
124   double m_FlipTimeStamp; // time stamp of last flippage. used to play at a forced framerate
125
126   int m_iLateFrames;
127   int m_iDroppedFrames;
128   int m_iDroppedRequest;
129
130   void   ResetFrameRateCalc();
131   void   CalcFrameRate();
132
133   double m_fFrameRate;       //framerate of the video currently playing
134   bool   m_bCalcFrameRate;  //if we should calculate the framerate from the timestamps
135   double m_fStableFrameRate; //place to store calculated framerates
136   int    m_iFrameRateCount;  //how many calculated framerates we stored in m_fStableFrameRate
137   bool   m_bAllowDrop;       //we can't drop frames until we've calculated the framerate
138   int    m_iFrameRateErr;    //how many frames we couldn't calculate the framerate, we give up after a while
139   int    m_iFrameRateLength; //how many seconds we should measure the framerate
140                              //this is increased exponentially from CDVDPlayerVideo::CalcFrameRate()
141
142   bool   m_bFpsInvalid;      // needed to ignore fps (e.g. dvd stills)
143
144   struct SOutputConfiguration
145   {
146     unsigned int width;
147     unsigned int height;
148     unsigned int dwidth;
149     unsigned int dheight;
150     unsigned int color_format;
151     unsigned int extended_format;
152     unsigned int color_matrix : 4;
153     unsigned int color_range  : 1;
154     unsigned int chroma_position;
155     unsigned int color_primaries;
156     unsigned int color_transfer;
157     unsigned int stereo_flags;
158     double       framerate;
159   } m_output; //holds currently configured output
160
161   bool m_bAllowFullscreen;
162   bool m_bRenderSubs;
163
164   float m_fForcedAspectRatio;
165
166   int m_iNrOfPicturesNotToSkip;
167   int m_speed;
168
169   bool m_stalled;
170   bool m_started;
171   std::string m_codecname;
172
173   BitstreamStats m_videoStats;
174
175   // classes
176   CDVDStreamInfo m_hints;
177   CDVDVideoCodec* m_pVideoCodec;
178   CDVDOverlayCodecCC* m_pOverlayCodecCC;
179
180   DVDVideoPicture* m_pTempOverlayPicture;
181
182   CPullupCorrection m_pullupCorrection;
183
184   std::list<DVDMessageListItem> m_packets;
185 };
186