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 "threads/CriticalSection.h"
12 
13 #include <atomic>
14 #include <string>
15 #include <vector>
16 
17 namespace EDL
18 {
19   struct Cut;
20 }
21 
22 class CDataCacheCore
23 {
24 public:
25   CDataCacheCore();
26   virtual ~CDataCacheCore();
27   static CDataCacheCore& GetInstance();
28   void Reset();
29   bool HasAVInfoChanges();
30   void SignalVideoInfoChange();
31   void SignalAudioInfoChange();
32   void SignalSubtitleInfoChange();
33 
34   // player video info
35   void SetVideoDecoderName(std::string name, bool isHw);
36   std::string GetVideoDecoderName();
37   bool IsVideoHwDecoder();
38   void SetVideoDeintMethod(std::string method);
39   std::string GetVideoDeintMethod();
40   void SetVideoPixelFormat(std::string pixFormat);
41   std::string GetVideoPixelFormat();
42   void SetVideoStereoMode(std::string mode);
43   std::string GetVideoStereoMode();
44   void SetVideoDimensions(int width, int height);
45   int GetVideoWidth();
46   int GetVideoHeight();
47   void SetVideoFps(float fps);
48   float GetVideoFps();
49   void SetVideoDAR(float dar);
50   float GetVideoDAR();
51 
52   // player audio info
53   void SetAudioDecoderName(std::string name);
54   std::string GetAudioDecoderName();
55   void SetAudioChannels(std::string channels);
56   std::string GetAudioChannels();
57   void SetAudioSampleRate(int sampleRate);
58   int GetAudioSampleRate();
59   void SetAudioBitsPerSample(int bitsPerSample);
60   int GetAudioBitsPerSample();
61 
62   // content info
63   void SetCutList(const std::vector<EDL::Cut>& cutList);
64   std::vector<EDL::Cut> GetCutList() const;
65   void SetChapters(const std::vector<std::pair<std::string, int64_t>>& chapters);
66   std::vector<std::pair<std::string, int64_t>> GetChapters() const;
67 
68   // render info
69   void SetRenderClockSync(bool enabled);
70   bool IsRenderClockSync();
71 
72   // player states
73   void SetStateSeeking(bool active);
74   bool IsSeeking();
75   void SetSpeed(float tempo, float speed);
76   float GetSpeed();
77   float GetTempo();
78   void SetFrameAdvance(bool fa);
79   bool IsFrameAdvance();
80   bool IsPlayerStateChanged();
81   void SetGuiRender(bool gui);
82   bool GetGuiRender();
83   void SetVideoRender(bool video);
84   bool GetVideoRender();
85   void SetPlayTimes(time_t start, int64_t current, int64_t min, int64_t max);
86   void GetPlayTimes(time_t &start, int64_t &current, int64_t &min, int64_t &max);
87 
88   /*!
89    * \brief Get the start time
90    *
91    * For a typical video this will be zero. For live TV, this is a reference time
92    * in units of time_t (UTC) from which time elapsed starts. Ideally this would
93    * be the start of the tv show but can be any other time as well.
94    */
95   time_t GetStartTime();
96 
97   /*!
98    * \brief Get the current time of playback
99    *
100    * This is the time elapsed, in ms, since the start time.
101    */
102   int64_t GetPlayTime();
103 
104   /*!
105    * \brief Get the current percentage of playback if a playback buffer is available.
106    *
107    *  If there is no playback buffer, percentage will be 0.
108    */
109   float GetPlayPercentage();
110 
111   /*!
112    * \brief Get the minumum time
113    *
114    * This will be zero for a typical video. With timeshift, this is the time,
115    * in ms, that the player can go back. This can be before the start time.
116    */
117   int64_t GetMinTime();
118 
119   /*!
120    * \brief Get the maximum time
121    *
122    * This is the maximun time, in ms, that the player can skip forward. For a
123    * typical video, this will be the total length. For live TV without
124    * timeshift this is zero, and for live TV with timeshift this will be the
125    * buffer ahead.
126    */
127   int64_t GetMaxTime();
128 
129 protected:
130   std::atomic_bool m_hasAVInfoChanges;
131 
132   CCriticalSection m_videoPlayerSection;
133   struct SPlayerVideoInfo
134   {
135     std::string decoderName;
136     bool isHwDecoder;
137     std::string deintMethod;
138     std::string pixFormat;
139     std::string stereoMode;
140     int width;
141     int height;
142     float fps;
143     float dar;
144   } m_playerVideoInfo;
145 
146   CCriticalSection m_audioPlayerSection;
147   struct SPlayerAudioInfo
148   {
149     std::string decoderName;
150     std::string channels;
151     int sampleRate;
152     int bitsPerSample;
153   } m_playerAudioInfo;
154 
155   mutable CCriticalSection m_contentSection;
156   struct SContentInfo
157   {
158     std::vector<EDL::Cut> m_cutList;
159     std::vector<std::pair<std::string, int64_t>> m_chapters; // name and position for chapters
160   } m_contentInfo;
161 
162   CCriticalSection m_renderSection;
163   struct SRenderInfo
164   {
165     bool m_isClockSync;
166   } m_renderInfo;
167 
168   CCriticalSection m_stateSection;
169   bool m_playerStateChanged = false;
170   struct SStateInfo
171   {
172     bool m_stateSeeking;
173     bool m_renderGuiLayer;
174     bool m_renderVideoLayer;
175     float m_tempo;
176     float m_speed;
177     bool m_frameAdvance;
178   } m_stateInfo;
179 
180   struct STimeInfo
181   {
182     time_t m_startTime;
183     int64_t m_time;
184     int64_t m_timeMax;
185     int64_t m_timeMin;
186   } m_timeInfo = {};
187 };
188