xbmc
VideoPlayerVideo.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 "DVDClock.h"
12 #include "DVDCodecs/Video/DVDVideoCodec.h"
13 #include "DVDMessageQueue.h"
14 #include "DVDOverlayContainer.h"
15 #include "DVDStreamInfo.h"
16 #include "IVideoPlayer.h"
17 #include "PTSTracker.h"
18 #include "cores/VideoPlayer/VideoRenderers/RenderManager.h"
19 #include "threads/Thread.h"
20 #include "utils/BitstreamStats.h"
21 
22 #include <atomic>
23 
24 #define DROP_DROPPED 1
25 #define DROP_VERYLATE 2
26 #define DROP_BUFFER_LEVEL 4
27 
28 class CDemuxStreamVideo;
29 
31 {
32 public:
33  void Reset();
34  void AddOutputDropGain(double pts, int frames);
35  struct CGain
36  {
37  int frames;
38  double pts;
39  };
40  std::deque<CGain> m_gain;
41  int m_totalGain;
42  double m_lastPts;
43 };
44 
46 {
47 public:
49  ,CDVDOverlayContainer* pOverlayContainer
50  ,CDVDMessageQueue& parent
51  ,CRenderManager& renderManager,
52  CProcessInfo &processInfo);
53  ~CVideoPlayerVideo() override;
54 
55  bool OpenStream(CDVDStreamInfo hint) override;
56  void CloseStream(bool bWaitForBuffers) override;
57  void Flush(bool sync) override;
58  bool AcceptsData() const override;
59  bool HasData() const override;
60  bool IsInited() const override;
61  void SendMessage(std::shared_ptr<CDVDMsg> pMsg, int priority = 0) override;
62  void FlushMessages() override;
63 
64  void EnableSubtitle(bool bEnable) override { m_bRenderSubs = bEnable; }
65  bool IsSubtitleEnabled() override { return m_bRenderSubs; }
66  double GetSubtitleDelay() override { return m_iSubtitleDelay; }
67  void SetSubtitleDelay(double delay) override { m_iSubtitleDelay = delay; }
68  bool IsStalled() const override { return m_stalled; }
69  bool IsRewindStalled() const override { return m_rewindStalled; }
70  double GetCurrentPts() override;
71  double GetOutputDelay() override; /* returns the expected delay, from that a packet is put in queue */
72  std::string GetPlayerInfo() override;
73  int GetVideoBitrate() override;
74  void SetSpeed(int iSpeed) override;
75 
76  // classes
77  CDVDOverlayContainer* m_pOverlayContainer;
78  CDVDClock* m_pClock;
79 
80 protected:
81 
82  enum EOutputState
83  {
84  OUTPUT_NORMAL,
85  OUTPUT_ABORT,
86  OUTPUT_DROPPED,
87  OUTPUT_AGAIN
88  };
89 
90  void OnExit() override;
91  void Process() override;
92 
93  bool ProcessDecoderOutput(double &frametime, double &pts);
94  void SendMessageBack(const std::shared_ptr<CDVDMsg>& pMsg, int priority = 0);
95  MsgQueueReturnCode GetMessage(std::shared_ptr<CDVDMsg>& pMsg,
96  std::chrono::milliseconds timeout,
97  int& priority);
98 
99  EOutputState OutputPicture(const VideoPicture* src);
100  void ProcessOverlays(const VideoPicture* pSource, double pts);
101  void OpenStream(CDVDStreamInfo& hint, std::unique_ptr<CDVDVideoCodec> codec);
102 
103  void ResetFrameRateCalc();
104  void CalcFrameRate();
105  int CalcDropRequirement(double pts);
106 
107  double m_iSubtitleDelay;
108 
109  int m_iLateFrames;
110  int m_iDroppedFrames;
111  int m_iDroppedRequest;
112 
113  double m_fFrameRate; //framerate of the video currently playing
114  double m_fStableFrameRate; //place to store calculated framerates
115  int m_iFrameRateCount; //how many calculated framerates we stored in m_fStableFrameRate
116  bool m_bAllowDrop; //we can't drop frames until we've calculated the framerate
117  int m_iFrameRateErr; //how many frames we couldn't calculate the framerate, we give up after a while
118  int m_iFrameRateLength; //how many seconds we should measure the framerate
119  //this is increased exponentially from CVideoPlayerVideo::CalcFrameRate()
120 
121  bool m_bFpsInvalid; // needed to ignore fps (e.g. dvd stills)
122  bool m_bRenderSubs;
123  float m_fForcedAspectRatio;
124  int m_speed;
125  std::atomic_bool m_stalled = false;
126  std::atomic_bool m_rewindStalled;
127  bool m_paused;
128  IDVDStreamPlayer::ESyncState m_syncState;
129  std::atomic_bool m_bAbortOutput;
130 
131  BitstreamStats m_videoStats;
132 
133  CDVDMessageQueue m_messageQueue;
134  CDVDMessageQueue& m_messageParent;
135  CDVDStreamInfo m_hints;
136  std::unique_ptr<CDVDVideoCodec> m_pVideoCodec;
137  CPtsTracker m_ptsTracker;
138  std::list<DVDMessageListItem> m_packets;
139  CDroppingStats m_droppingStats;
140  CRenderManager& m_renderManager;
141  VideoPicture m_picture;
142 
143  EOutputState m_outputSate;
144 };
Definition: VideoPlayerVideo.h:35
Definition: DVDStreamInfo.h:23
Definition: Thread.h:44
Definition: VideoPlayerVideo.h:30
Definition: VideoPlayerVideo.h:45
Definition: DVDMessageQueue.h:48
Definition: IVideoPlayer.h:75
Definition: BitstreamStats.h:13
Definition: DVDDemux.h:124
Definition: PTSTracker.h:18
Definition: RenderManager.h:54
Definition: ProcessInfo.h:26
Definition: DVDClock.h:18
Definition: DVDVideoCodec.h:36
Definition: DVDOverlayContainer.h:19