Merge pull request #24943 from foresto/prev-subtitle
[xbmc.git] / xbmc / application / ApplicationStackHelper.h
blobf35c5f7b73b775bc95d8ad65ef10999f2ef4a43e
1 /*
2 * Copyright (C) 2017-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 "application/IApplicationComponent.h"
12 #include "threads/CriticalSection.h"
14 #include <map>
15 #include <memory>
16 #include <optional>
17 #include <string>
19 class CFileItem;
20 class CFileItemList;
22 class CApplicationStackHelper : public IApplicationComponent
24 public:
25 CApplicationStackHelper(void);
26 ~CApplicationStackHelper() = default;
28 void Clear();
29 void OnPlayBackStarted(const CFileItem& item);
31 /*!
32 \brief Initialize stack
33 \param item the FileItem object that is the stack
35 bool InitializeStack(const CFileItem& item);
37 /*!
38 \brief Initialize stack times for each part, start & end, total time, and current part number if resume offset is specified.
39 \param item the FileItem object that is the stack
40 \returns the part offset if available, nullopt in case of errors
42 std::optional<int64_t> InitializeStackStartPartAndOffset(const CFileItem& item);
44 /*!
45 \brief returns the current part number
47 int GetCurrentPartNumber() const { return m_currentStackPosition; }
49 /*!
50 \brief Returns true if Application is currently playing an ISO stack
52 bool IsPlayingISOStack() const;
54 /*!
55 \brief Returns true if Application is currently playing a Regular (non-ISO) stack
57 bool IsPlayingRegularStack() const;
59 /*!
60 \brief returns true if there is a next part available
62 bool HasNextStackPartFileItem() const;
64 /*!
65 \brief sets the next stack part as the current and returns a reference to it
67 const CFileItem& SetNextStackPartCurrentFileItem()
69 return GetStackPartFileItem(++m_currentStackPosition);
72 /*!
73 \brief sets a given stack part as the current and returns a reference to it
74 \param partNumber the number of the part that needs to become the current one
76 const CFileItem& SetStackPartCurrentFileItem(int partNumber)
78 return GetStackPartFileItem(m_currentStackPosition = partNumber);
81 /*!
82 \brief Returns the FileItem currently playing back as part of a (non-ISO) stack playback
84 const CFileItem& GetCurrentStackPartFileItem() const
86 return GetStackPartFileItem(m_currentStackPosition);
89 /*!
90 \brief Returns the end time of a FileItem part of a (non-ISO) stack playback
91 \param partNumber the requested part number in the stack
93 uint64_t GetStackPartEndTimeMs(int partNumber) const;
95 /*!
96 \brief Returns the start time of a FileItem part of a (non-ISO) stack playback
97 \param partNumber the requested part number in the stack
99 uint64_t GetStackPartStartTimeMs(int partNumber) const { return (partNumber > 0) ? GetStackPartEndTimeMs(partNumber - 1) : 0; }
102 \brief Returns the start time of the current FileItem part of a (non-ISO) stack playback
104 uint64_t GetCurrentStackPartStartTimeMs() const { return GetStackPartStartTimeMs(m_currentStackPosition); }
107 \brief Returns the total time of a (non-ISO) stack playback
109 uint64_t GetStackTotalTimeMs() const;
112 \brief Returns the stack part number corresponding to the given timestamp in a (non-ISO) stack playback
113 \param msecs the requested timestamp in the stack (in milliseconds)
115 int GetStackPartNumberAtTimeMs(uint64_t msecs);
117 // Stack information registration methods
120 \brief Clear all entries in the item-stack map. To be called upon playback stopped.
122 void ClearAllRegisteredStackInformation();
125 \brief Returns a smart pointer to the stack CFileItem.
127 std::shared_ptr<const CFileItem> GetRegisteredStack(const CFileItem& item) const;
130 \brief Returns true if there is a registered stack for the given CFileItem part.
131 \param item the reference to the item that is part of a stack
133 bool HasRegisteredStack(const CFileItem& item) const;
136 \brief Stores a smart pointer to the stack CFileItem in the item-stack map.
137 \param item the reference to the item that is part of a stack
138 \param stackItem the smart pointer to the stack CFileItem
140 void SetRegisteredStack(const CFileItem& item, std::shared_ptr<CFileItem> stackItem);
143 \brief Returns the part number of the part in the parameter
144 \param item the reference to the item that is part of a stack
146 int GetRegisteredStackPartNumber(const CFileItem& item);
149 \brief Stores the part number in the item-stack map.
150 \param item the reference to the item that is part of a stack
151 \param partNumber the part number of the part in other parameter
153 void SetRegisteredStackPartNumber(const CFileItem& item, int partNumber);
156 \brief Returns the start time of the part in the parameter
157 \param item the reference to the item that is part of a stack
159 uint64_t GetRegisteredStackPartStartTimeMs(const CFileItem& item) const;
162 \brief Stores the part start time in the item-stack map.
163 \param item the reference to the item that is part of a stack
164 \param startTime the start time of the part in other parameter
166 void SetRegisteredStackPartStartTimeMs(const CFileItem& item, uint64_t startTimeMs);
169 \brief Returns the total time of the stack associated to the part in the parameter
170 \param item the reference to the item that is part of a stack
172 uint64_t GetRegisteredStackTotalTimeMs(const CFileItem& item) const;
175 \brief Stores the stack's total time associated to the part in the item-stack map.
176 \param item the reference to the item that is part of a stack
177 \param totalTime the total time of the stack
179 void SetRegisteredStackTotalTimeMs(const CFileItem& item, uint64_t totalTimeMs);
181 CCriticalSection m_critSection;
183 protected:
185 \brief Returns a FileItem part of a (non-ISO) stack playback
186 \param partNumber the requested part number in the stack
188 CFileItem& GetStackPartFileItem(int partNumber);
189 const CFileItem& GetStackPartFileItem(int partNumber) const;
191 class StackPartInformation
193 public:
194 StackPartInformation()
196 m_lStackPartNumber = 0;
197 m_lStackPartStartTimeMs = 0;
198 m_lStackTotalTimeMs = 0;
200 uint64_t m_lStackPartStartTimeMs;
201 uint64_t m_lStackTotalTimeMs;
202 int m_lStackPartNumber;
203 std::shared_ptr<CFileItem> m_pStack;
206 typedef std::shared_ptr<StackPartInformation> StackPartInformationPtr;
207 typedef std::map<std::string, StackPartInformationPtr> Stackmap;
208 Stackmap m_stackmap;
209 StackPartInformationPtr GetStackPartInformation(const std::string& key);
210 StackPartInformationPtr GetStackPartInformation(const std::string& key) const;
212 std::unique_ptr<CFileItemList> m_currentStack;
213 int m_currentStackPosition = 0;
214 bool m_currentStackIsDiscImageStack = false;