kodi
DataCacheCore.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 "EdlEdit.h"
12 #include "threads/CriticalSection.h"
13 
14 #include <atomic>
15 #include <chrono>
16 #include <string>
17 #include <vector>
18 
20 {
21 public:
23  virtual ~CDataCacheCore();
24  static CDataCacheCore& GetInstance();
25  void Reset();
26  bool HasAVInfoChanges();
27  void SignalVideoInfoChange();
28  void SignalAudioInfoChange();
29  void SignalSubtitleInfoChange();
30 
31  // player video info
32  void SetVideoDecoderName(std::string name, bool isHw);
33  std::string GetVideoDecoderName();
34  bool IsVideoHwDecoder();
35  void SetVideoDeintMethod(std::string method);
36  std::string GetVideoDeintMethod();
37  void SetVideoPixelFormat(std::string pixFormat);
38  std::string GetVideoPixelFormat();
39  void SetVideoStereoMode(std::string mode);
40  std::string GetVideoStereoMode();
41  void SetVideoDimensions(int width, int height);
42  int GetVideoWidth();
43  int GetVideoHeight();
44  void SetVideoFps(float fps);
45  float GetVideoFps();
46  void SetVideoDAR(float dar);
47  float GetVideoDAR();
48 
53  void SetVideoInterlaced(bool isInterlaced);
54 
59  bool IsVideoInterlaced();
60 
61  // player audio info
62  void SetAudioDecoderName(std::string name);
63  std::string GetAudioDecoderName();
64  void SetAudioChannels(std::string channels);
65  std::string GetAudioChannels();
66  void SetAudioSampleRate(int sampleRate);
67  int GetAudioSampleRate();
68  void SetAudioBitsPerSample(int bitsPerSample);
69  int GetAudioBitsPerSample();
70 
71  // content info
72 
77  void SetEditList(const std::vector<EDL::Edit>& editList);
78 
83  const std::vector<EDL::Edit>& GetEditList() const;
84 
89  void SetCuts(const std::vector<int64_t>& cuts);
90 
95  const std::vector<int64_t>& GetCuts() const;
96 
101  void SetSceneMarkers(const std::vector<int64_t>& sceneMarkers);
102 
107  const std::vector<int64_t>& GetSceneMarkers() const;
108 
109  void SetChapters(const std::vector<std::pair<std::string, int64_t>>& chapters);
110 
115  const std::vector<std::pair<std::string, int64_t>>& GetChapters() const;
116 
117  // render info
118  void SetRenderClockSync(bool enabled);
119  bool IsRenderClockSync();
120 
121  // player states
126  void SeekFinished(int64_t offset);
127 
128  void SetStateSeeking(bool active);
129  bool IsSeeking();
130 
136  bool HasPerformedSeek(int64_t lastSecondInterval) const;
137 
142  int64_t GetSeekOffSet() const;
143 
144  void SetSpeed(float tempo, float speed);
145  float GetSpeed();
146  float GetTempo();
147  void SetFrameAdvance(bool fa);
148  bool IsFrameAdvance();
149  bool IsPlayerStateChanged();
150  void SetGuiRender(bool gui);
151  bool GetGuiRender();
152  void SetVideoRender(bool video);
153  bool GetVideoRender();
154  void SetPlayTimes(time_t start, int64_t current, int64_t min, int64_t max);
155  void GetPlayTimes(time_t &start, int64_t &current, int64_t &min, int64_t &max);
156 
164  time_t GetStartTime();
165 
171  int64_t GetPlayTime();
172 
178  float GetPlayPercentage();
179 
186  int64_t GetMinTime();
187 
196  int64_t GetMaxTime();
197 
198 protected:
199  std::atomic_bool m_hasAVInfoChanges = false;
200 
201  CCriticalSection m_videoPlayerSection;
203  {
204  std::string decoderName;
205  bool isHwDecoder;
206  std::string deintMethod;
207  std::string pixFormat;
208  std::string stereoMode;
209  int width;
210  int height;
211  float fps;
212  float dar;
213  bool m_isInterlaced;
214  } m_playerVideoInfo;
215 
216  CCriticalSection m_audioPlayerSection;
218  {
219  std::string decoderName;
220  std::string channels;
221  int sampleRate;
222  int bitsPerSample;
223  } m_playerAudioInfo;
224 
225  mutable CCriticalSection m_contentSection;
227  {
228  public:
233  void SetEditList(const std::vector<EDL::Edit>& editList) { m_editList = editList; }
234 
239  const std::vector<EDL::Edit>& GetEditList() const { return m_editList; }
240 
245  void SetCuts(const std::vector<int64_t>& cuts) { m_cuts = cuts; }
246 
251  const std::vector<int64_t>& GetCuts() const { return m_cuts; }
252 
257  void SetSceneMarkers(const std::vector<int64_t>& sceneMarkers)
258  {
259  m_sceneMarkers = sceneMarkers;
260  }
261 
266  const std::vector<int64_t>& GetSceneMarkers() const { return m_sceneMarkers; }
267 
272  void SetChapters(const std::vector<std::pair<std::string, int64_t>>& chapters)
273  {
274  m_chapters = chapters;
275  }
276 
281  const std::vector<std::pair<std::string, int64_t>>& GetChapters() const { return m_chapters; }
282 
286  void Reset()
287  {
288  m_editList.clear();
289  m_chapters.clear();
290  m_cuts.clear();
291  m_sceneMarkers.clear();
292  }
293 
294  private:
296  std::vector<EDL::Edit> m_editList;
298  std::vector<std::pair<std::string, int64_t>> m_chapters;
300  std::vector<int64_t> m_cuts;
302  std::vector<int64_t> m_sceneMarkers;
303  } m_contentInfo;
304 
305  CCriticalSection m_renderSection;
306  struct SRenderInfo
307  {
308  bool m_isClockSync;
309  } m_renderInfo;
310 
311  mutable CCriticalSection m_stateSection;
312  bool m_playerStateChanged = false;
313  struct SStateInfo
314  {
315  bool m_stateSeeking{false};
316  bool m_renderGuiLayer{false};
317  bool m_renderVideoLayer{false};
318  float m_tempo{1.0f};
319  float m_speed{1.0f};
320  bool m_frameAdvance{false};
322  std::chrono::time_point<std::chrono::system_clock> m_lastSeekTime{
323  std::chrono::time_point<std::chrono::system_clock>{}};
325  int64_t m_lastSeekOffset{0};
326  } m_stateInfo;
327 
328  struct STimeInfo
329  {
330  time_t m_startTime;
331  int64_t m_time;
332  int64_t m_timeMax;
333  int64_t m_timeMin;
334  } m_timeInfo = {};
335 };
void SetVideoInterlaced(bool isInterlaced)
Set if the video is interlaced in cache.
Definition: DataCacheCore.cpp:197
void SetSceneMarkers(const std::vector< int64_t > &sceneMarkers)
Set the list of scene markers in cache.
Definition: DataCacheCore.cpp:290
void Reset()
Reset the content cache to the original values (all empty)
Definition: DataCacheCore.h:286
void SetChapters(const std::vector< std::pair< std::string, int64_t >> &chapters)
Save the chapter list in cache.
Definition: DataCacheCore.h:272
void SetEditList(const std::vector< EDL::Edit > &editList)
Set the EDL edit list to cache.
Definition: DataCacheCore.cpp:266
const std::vector< EDL::Edit > & GetEditList() const
Get the EDL edit list in cache.
Definition: DataCacheCore.h:239
Definition: DataCacheCore.h:217
float GetPlayPercentage()
Get the current percentage of playback if a playback buffer is available.
Definition: DataCacheCore.cpp:487
const std::vector< int64_t > & GetCuts() const
Get the list of cut markers from cache.
Definition: DataCacheCore.cpp:284
time_t GetStartTime()
Get the start time.
Definition: DataCacheCore.cpp:463
Definition: DataCacheCore.h:19
const std::vector< int64_t > & GetSceneMarkers() const
Get the list of scene markers markers from cache.
Definition: DataCacheCore.cpp:296
void SetEditList(const std::vector< EDL::Edit > &editList)
Set the EDL edit list in cache.
Definition: DataCacheCore.h:233
void SetSceneMarkers(const std::vector< int64_t > &sceneMarkers)
Save the list of scene markers in cache.
Definition: DataCacheCore.h:257
const std::vector< std::pair< std::string, int64_t > > & GetChapters() const
Get the list of chapters in cache.
Definition: DataCacheCore.h:281
void SeekFinished(int64_t offset)
Notifies the cache core that a seek operation has finished.
Definition: DataCacheCore.cpp:329
const std::vector< int64_t > & GetSceneMarkers() const
Get the list of scene markers in cache.
Definition: DataCacheCore.h:266
Definition: DataCacheCore.h:202
bool HasPerformedSeek(int64_t lastSecondInterval) const
Checks if a seek has been performed in the last provided seconds interval.
Definition: DataCacheCore.cpp:342
Definition: DataCacheCore.h:313
void SetCuts(const std::vector< int64_t > &cuts)
Set the list of cut markers in cache.
Definition: DataCacheCore.cpp:278
const std::vector< std::pair< std::string, int64_t > > & GetChapters() const
Get the chapter list in cache.
Definition: DataCacheCore.cpp:308
bool IsVideoInterlaced()
Check if the video is interlaced from cache.
Definition: DataCacheCore.cpp:203
int64_t GetSeekOffSet() const
Gets the last seek offset.
Definition: DataCacheCore.cpp:336
Definition: DataCacheCore.h:306
Definition: DataCacheCore.h:328
void SetCuts(const std::vector< int64_t > &cuts)
Save the list of cut markers in cache.
Definition: DataCacheCore.h:245
int64_t GetMaxTime()
Get the maximum time.
Definition: DataCacheCore.cpp:481
int64_t GetMinTime()
Get the minimum time.
Definition: DataCacheCore.cpp:475
const std::vector< int64_t > & GetCuts() const
Get the list of cut markers in cache.
Definition: DataCacheCore.h:251
Definition: DataCacheCore.h:226
int64_t GetPlayTime()
Get the current time of playback.
Definition: DataCacheCore.cpp:469
const std::vector< EDL::Edit > & GetEditList() const
Get the EDL edit list in cache.
Definition: DataCacheCore.cpp:272