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/>.
23 #include "threads/Thread.h"
24 #include "DVDMessageQueue.h"
25 #include "DVDDemuxers/DVDDemuxUtils.h"
26 #include "DVDCodecs/Video/DVDVideoCodec.h"
28 #include "DVDOverlayContainer.h"
29 #include "DVDTSCorrection.h"
30 #ifdef HAS_VIDEO_PLAYBACK
31 #include "cores/VideoRenderers/RenderManager.h"
34 class CDemuxStreamVideo;
35 class CDVDOverlayCodecCC;
37 #define VIDEO_PICTURE_QUEUE_SIZE 1
39 class CDVDPlayerVideo : public CThread
42 CDVDPlayerVideo( CDVDClock* pClock
43 , CDVDOverlayContainer* pOverlayContainer
44 , CDVDMessageQueue& parent);
45 virtual ~CDVDPlayerVideo();
47 bool OpenStream(CDVDStreamInfo &hint);
48 void OpenStream(CDVDStreamInfo &hint, CDVDVideoCodec* codec);
49 void CloseStream(bool bWaitForBuffers);
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; }
60 bool IsInited() const { return m_messageQueue.IsInited(); }
61 void SendMessage(CDVDMsg* pMsg, int priority = 0) { m_messageQueue.Put(pMsg, priority); }
63 void EnableSubtitle(bool bEnable) { m_bRenderSubs = bEnable; }
64 bool IsSubtitleEnabled() { return m_bRenderSubs; }
66 void EnableFullscreen(bool bEnable) { m_bAllowFullscreen = bEnable; }
68 #ifdef HAS_VIDEO_PLAYBACK
69 void GetVideoRect(CRect& SrcRect, CRect& DestRect) { g_renderManager.GetVideoRect(SrcRect, DestRect); }
70 float GetAspectRatio() { return g_renderManager.GetAspectRatio(); }
73 double GetDelay() { return m_iVideoDelay; }
74 void SetDelay(double delay) { m_iVideoDelay = delay; }
76 double GetSubtitleDelay() { return m_iSubtitleDelay; }
77 void SetSubtitleDelay(double delay) { m_iSubtitleDelay = delay; }
79 bool IsStalled() { return m_stalled; }
80 int GetNrOfDroppedFrames() { return m_iDroppedFrames; }
82 bool InitializedOutputDevice();
84 double GetCurrentPts() { return m_iCurrentPts; }
85 int GetPullupCorrection() { return m_pullupCorrection.GetPatternLength(); }
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();
92 void SetSpeed(int iSpeed);
95 CDVDOverlayContainer* m_pOverlayContainer;
100 virtual void OnStartup();
101 virtual void OnExit();
102 virtual void Process();
105 #define EOS_DROPPED 2
106 #define EOS_VERYLATE 4
108 void AutoCrop(DVDVideoPicture* pPicture);
109 void AutoCrop(DVDVideoPicture *pPicture, RECT &crop);
112 int OutputPicture(const DVDVideoPicture* src, double pts);
113 #ifdef HAS_VIDEO_PLAYBACK
114 void ProcessOverlays(DVDVideoPicture* pSource, double pts);
116 void ProcessVideoUserData(DVDVideoUserData* pVideoUserData, double pts);
118 CDVDMessageQueue m_messageQueue;
119 CDVDMessageQueue& m_messageParent;
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
127 int m_iDroppedFrames;
128 int m_iDroppedRequest;
130 void ResetFrameRateCalc();
131 void CalcFrameRate();
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()
142 bool m_bFpsInvalid; // needed to ignore fps (e.g. dvd stills)
144 struct SOutputConfiguration
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;
159 } m_output; //holds currently configured output
161 bool m_bAllowFullscreen;
164 float m_fForcedAspectRatio;
166 int m_iNrOfPicturesNotToSkip;
171 std::string m_codecname;
173 BitstreamStats m_videoStats;
176 CDVDStreamInfo m_hints;
177 CDVDVideoCodec* m_pVideoCodec;
178 CDVDOverlayCodecCC* m_pOverlayCodecCC;
180 DVDVideoPicture* m_pTempOverlayPicture;
182 CPullupCorrection m_pullupCorrection;
184 std::list<DVDMessageListItem> m_packets;