[WASAPI] set stream audio category
[xbmc.git] / xbmc / cores / DataCacheCore.h
blob5a4b1509e9fffc1da7e50e6effa6c5fc977e93ff
1 /*
2 * Copyright (C) 2005-2018 Team Kodi
3 * This file is part of Kodi - https://kodi.tv
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 * See LICENSES/README.md for more information.
7 */
9 #pragma once
11 #include "EdlEdit.h"
12 #include "threads/CriticalSection.h"
14 #include <atomic>
15 #include <chrono>
16 #include <string>
17 #include <vector>
19 class CDataCacheCore
21 public:
22 CDataCacheCore();
23 virtual ~CDataCacheCore();
24 static CDataCacheCore& GetInstance();
25 void Reset();
26 bool HasAVInfoChanges();
27 void SignalVideoInfoChange();
28 void SignalAudioInfoChange();
29 void SignalSubtitleInfoChange();
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();
49 /*!
50 * @brief Set if the video is interlaced in cache.
51 * @param isInterlaced Set true when the video is interlaced
53 void SetVideoInterlaced(bool isInterlaced);
55 /*!
56 * @brief Check if the video is interlaced from cache
57 * @return True if interlaced, otherwise false
59 bool IsVideoInterlaced();
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();
71 // content info
73 /*!
74 * @brief Set the EDL edit list to cache.
75 * @param editList The vector of edits to fill.
77 void SetEditList(const std::vector<EDL::Edit>& editList);
79 /*!
80 * @brief Get the EDL edit list in cache.
81 * @return The EDL edits or an empty vector if no edits exist.
83 const std::vector<EDL::Edit>& GetEditList() const;
85 /*!
86 * @brief Set the list of cut markers in cache.
87 * @return The list of cuts or an empty list if no cuts exist
89 void SetCuts(const std::vector<std::chrono::milliseconds>& cuts);
91 /*!
92 * @brief Get the list of cut markers from cache.
93 * @return The list of cut markers or an empty vector if no cuts exist.
95 const std::vector<std::chrono::milliseconds>& GetCuts() const;
97 /*!
98 * @brief Set the list of scene markers in cache.
99 * @return The list of scene markers or an empty list if no scene markers exist
101 void SetSceneMarkers(const std::vector<std::chrono::milliseconds>& sceneMarkers);
104 * @brief Get the list of scene markers markers from cache.
105 * @return The list of scene markers or an empty vector if no scene exist.
107 const std::vector<std::chrono::milliseconds>& GetSceneMarkers() const;
109 void SetChapters(const std::vector<std::pair<std::string, int64_t>>& chapters);
112 * @brief Get the chapter list in cache.
113 * @return The list of chapters or an empty vector if no chapters exist.
115 const std::vector<std::pair<std::string, int64_t>>& GetChapters() const;
117 // render info
118 void SetRenderClockSync(bool enabled);
119 bool IsRenderClockSync();
121 // player states
123 * @brief Notifies the cache core that a seek operation has finished
124 * @param offset - the seek offset
126 void SeekFinished(int64_t offset);
128 void SetStateSeeking(bool active);
129 bool IsSeeking();
132 * @brief Checks if a seek has been performed in the last provided seconds interval
133 * @param lastSecondInterval - the last elapsed second interval to check for a seek operation
134 * @return true if a seek was performed in the lastSecondInterval, false otherwise
136 bool HasPerformedSeek(int64_t lastSecondInterval) const;
139 * @brief Gets the last seek offset
140 * @return the last seek offset
142 int64_t GetSeekOffSet() const;
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);
158 * \brief Get the start time
160 * For a typical video this will be zero. For live TV, this is a reference time
161 * in units of time_t (UTC) from which time elapsed starts. Ideally this would
162 * be the start of the tv show but can be any other time as well.
164 time_t GetStartTime();
167 * \brief Get the current time of playback
169 * This is the time elapsed, in ms, since the start time.
171 int64_t GetPlayTime();
174 * \brief Get the current percentage of playback if a playback buffer is available.
176 * If there is no playback buffer, percentage will be 0.
178 float GetPlayPercentage();
181 * \brief Get the minimum time
183 * This will be zero for a typical video. With timeshift, this is the time,
184 * in ms, that the player can go back. This can be before the start time.
186 int64_t GetMinTime();
189 * \brief Get the maximum time
191 * This is the maximum time, in ms, that the player can skip forward. For a
192 * typical video, this will be the total length. For live TV without
193 * timeshift this is zero, and for live TV with timeshift this will be the
194 * buffer ahead.
196 int64_t GetMaxTime();
198 protected:
199 std::atomic_bool m_hasAVInfoChanges = false;
201 CCriticalSection m_videoPlayerSection;
202 struct SPlayerVideoInfo
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;
216 CCriticalSection m_audioPlayerSection;
217 struct SPlayerAudioInfo
219 std::string decoderName;
220 std::string channels;
221 int sampleRate;
222 int bitsPerSample;
223 } m_playerAudioInfo;
225 mutable CCriticalSection m_contentSection;
226 struct SContentInfo
228 public:
230 * @brief Set the EDL edit list in cache.
231 * @param editList the list of edits to store in cache
233 void SetEditList(const std::vector<EDL::Edit>& editList) { m_editList = editList; }
236 * @brief Get the EDL edit list in cache.
237 * @return the list of edits in cache
239 const std::vector<EDL::Edit>& GetEditList() const { return m_editList; }
242 * @brief Save the list of cut markers in cache.
243 * @param cuts the list of cut markers to store in cache
245 void SetCuts(const std::vector<std::chrono::milliseconds>& cuts) { m_cuts = cuts; }
248 * @brief Get the list of cut markers in cache.
249 * @return the list of cut markers in cache
251 const std::vector<std::chrono::milliseconds>& GetCuts() const { return m_cuts; }
254 * @brief Save the list of scene markers in cache.
255 * @param sceneMarkers the list of scene markers to store in cache
257 void SetSceneMarkers(const std::vector<std::chrono::milliseconds>& sceneMarkers)
259 m_sceneMarkers = sceneMarkers;
263 * @brief Get the list of scene markers in cache.
264 * @return the list of scene markers in cache
266 const std::vector<std::chrono::milliseconds>& GetSceneMarkers() const { return m_sceneMarkers; }
269 * @brief Save the chapter list in cache.
270 * @param chapters the list of chapters to store in cache
272 void SetChapters(const std::vector<std::pair<std::string, int64_t>>& chapters)
274 m_chapters = chapters;
278 * @brief Get the list of chapters in cache.
279 * @return the list of chapters in cache
281 const std::vector<std::pair<std::string, int64_t>>& GetChapters() const { return m_chapters; }
284 * @brief Reset the content cache to the original values (all empty)
286 void Reset()
288 m_editList.clear();
289 m_chapters.clear();
290 m_cuts.clear();
291 m_sceneMarkers.clear();
294 private:
295 /*!< list of EDL edits */
296 std::vector<EDL::Edit> m_editList;
297 /*!< name and position for chapters */
298 std::vector<std::pair<std::string, int64_t>> m_chapters;
299 /*!< position for EDL cuts */
300 std::vector<std::chrono::milliseconds> m_cuts;
301 /*!< position for EDL scene markers */
302 std::vector<std::chrono::milliseconds> m_sceneMarkers;
303 } m_contentInfo;
305 CCriticalSection m_renderSection;
306 struct SRenderInfo
308 bool m_isClockSync;
309 } m_renderInfo{};
311 mutable CCriticalSection m_stateSection;
312 bool m_playerStateChanged = false;
313 struct SStateInfo
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};
321 /*! Time point of the last seek operation */
322 std::chrono::time_point<std::chrono::system_clock> m_lastSeekTime{
323 std::chrono::time_point<std::chrono::system_clock>{}};
324 /*! Last seek offset */
325 int64_t m_lastSeekOffset{0};
326 } m_stateInfo;
328 struct STimeInfo
330 time_t m_startTime;
331 int64_t m_time;
332 int64_t m_timeMax;
333 int64_t m_timeMin;
334 } m_timeInfo = {};