Debian Codegraph @

xbmc/pvr/channels/PVRChannel.h

raw
1 /*
2 * Copyright (C) 2012-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 "addons/kodi-dev-kit/include/kodi/c-api/addon-instance/pvr/pvr_channels.h"
12 #include "addons/kodi-dev-kit/include/kodi/c-api/addon-instance/pvr/pvr_providers.h"
13 #include "pvr/PVRCachedImage.h"
14 #include "pvr/channels/PVRChannelNumber.h"
15 #include "threads/CriticalSection.h"
16 #include "utils/ISerializable.h"
17 #include "utils/ISortable.h"
18
19 #include <memory>
20 #include <string>
21 #include <utility>
22 #include <vector>
23
24 class CDateTime;
25
26 namespace PVR
27 {
28 enum class PVREvent;
29
30 class CPVRProvider;
31 class CPVREpg;
32 class CPVREpgInfoTag;
33 class CPVRRadioRDSInfoTag;
34
35 class CPVRChannel : public ISerializable, public ISortable
36 {
37 friend class CPVRDatabase;
38
39 public:
40 static const std::string IMAGE_OWNER_PATTERN;
41
42 explicit CPVRChannel(bool bRadio);
43 CPVRChannel(bool bRadio, const std::string& iconPath);
44 CPVRChannel(const PVR_CHANNEL& channel, unsigned int iClientId);
45
46 virtual ~CPVRChannel();
47
48 bool operator==(const CPVRChannel& right) const;
49 bool operator!=(const CPVRChannel& right) const;
50
51 /*!
52 * @brief Copy over data to the given PVR_CHANNEL instance.
53 * @param channel The channel instance to fill.
54 */
55 void FillAddonData(PVR_CHANNEL& channel) const;
56
57 void Serialize(CVariant& value) const override;
58
59 /*! @name Kodi related channel methods
60 */
61 //@{
62
63 /*!
64 * @brief Delete this channel from the database.
65 * @return True if it was deleted successfully, false otherwise.
66 */
67 bool QueueDelete();
68
69 /*!
70 * @brief Update this channel tag with the data of the given channel tag.
71 * @param channel The new channel data.
72 * @return True if something changed, false otherwise.
73 */
74 bool UpdateFromClient(const std::shared_ptr<const CPVRChannel>& channel);
75
76 /*!
77 * @brief Persists the changes in the database.
78 * @return True if the changes were saved successfully, false otherwise.
79 */
80 bool Persist();
81
82 /*!
83 * @return The identifier given to this channel by the TV database.
84 */
85 int ChannelID() const;
86
87 /*!
88 * @return True when not persisted yet, false otherwise.
89 */
90 bool IsNew() const;
91
92 /*!
93 * @brief Set the identifier for this channel.
94 * @param iDatabaseId The new channel ID
95 * @return True if the something changed, false otherwise.
96 */
97 bool SetChannelID(int iDatabaseId);
98
99 /*!
100 * @return True if this channel is a radio channel, false if not.
101 */
102 bool IsRadio() const { return m_bIsRadio; }
103
104 /*!
105 * @return True if this channel is hidden. False if not.
106 */
107 bool IsHidden() const;
108
109 /*!
110 * @brief Set to true to hide this channel. Set to false to unhide it.
111 *
112 * Set to true to hide this channel. Set to false to unhide it.
113 * The EPG of hidden channels won't be updated.
114 * @param bIsHidden The new setting.
115 * @param bIsUserSetIcon true if user changed the hidden flag via GUI, false otherwise.
116 * @return True if the something changed, false otherwise.
117 */
118 bool SetHidden(bool bIsHidden, bool bIsUserSetHidden = false);
119
120 /*!
121 * @return True if this channel is locked. False if not.
122 */
123 bool IsLocked() const;
124
125 /*!
126 * @brief Set to true to lock this channel. Set to false to unlock it.
127 *
128 * Set to true to lock this channel. Set to false to unlock it.
129 * Locked channels need can only be viewed if parental PIN entered.
130 * @param bIsLocked The new setting.
131 * @return True if the something changed, false otherwise.
132 */
133 bool SetLocked(bool bIsLocked);
134
135 /*!
136 * @brief Obtain the Radio RDS data for this channel, if available.
137 * @return The Radio RDS data or nullptr.
138 */
139 std::shared_ptr<CPVRRadioRDSInfoTag> GetRadioRDSInfoTag() const;
140
141 /*!
142 * @brief Set the Radio RDS data for the channel.
143 * @param tag The RDS data.
144 */
145 void SetRadioRDSInfoTag(const std::shared_ptr<CPVRRadioRDSInfoTag>& tag);
146
147 /*!
148 * @return True if this channel has archive support, false otherwise
149 */
150 bool HasArchive() const;
151
152 /*!
153 * @brief Set the archive support flag for this channel.
154 * @param bHasArchive True to set the flag, false to reset.
155 * @return True if the flag was changed, false otherwise.
156 */
157 bool SetArchive(bool bHasArchive);
158
159 /*!
160 * @return The path to the icon for this channel as given by the client.
161 */
162 std::string ClientIconPath() const;
163
164 /*!
165 * @return The path to the icon for this channel.
166 */
167 std::string IconPath() const;
168
169 /*!
170 * @return True if this user changed icon via GUI. False if not.
171 */
172 bool IsUserSetIcon() const;
173
174 /*!
175 * @return whether the user has changed the channel name through the GUI
176 */
177 bool IsUserSetName() const;
178
179 /*!
180 * @return True if user changed the hidden flag via GUI, False if not
181 */
182 bool IsUserSetHidden() const;
183
184 /*!
185 * @return the id of the channel group the channel was watched from the last time; -1 if unknown.
186 */
187 int LastWatchedGroupId() const;
188
189 /*!
190 * @brief Set the path to the icon for this channel.
191 * @param strIconPath The new path.
192 * @param bIsUserSetIcon true if user changed the icon via GUI, false otherwise.
193 * @return True if the something changed, false otherwise.
194 */
195 bool SetIconPath(const std::string& strIconPath, bool bIsUserSetIcon = false);
196
197 /*!
198 * @return The name for this channel used by XBMC.
199 */
200 std::string ChannelName() const;
201
202 /*!
203 * @brief Set the name for this channel used by XBMC.
204 * @param strChannelName The new channel name.
205 * @param bIsUserSetName whether the change was triggered by the user directly
206 * @return True if the something changed, false otherwise.
207 */
208 bool SetChannelName(const std::string& strChannelName, bool bIsUserSetName = false);
209
210 /*!
211 * @return Time channel has been watched last.
212 */
213 time_t LastWatched() const;
214
215 /*!
216 * @brief Set the last time the channel has been watched and the channel group used to watch.
217 * @param lastWatched The new last watched time value.
218 * @param groupId the id of the group used to watch the channel.
219 * @return True if the something changed, false otherwise.
220 */
221 bool SetLastWatched(time_t lastWatched, int groupId);
222
223 /*!
224 * @brief Check whether this channel has unpersisted data changes.
225 * @return True if this channel has changes to persist, false otherwise
226 */
227 bool IsChanged() const;
228
229 /*!
230 * @brief reset changed flag after persist
231 */
232 void Persisted();
233 //@}
234
235 /*! @name Client related channel methods
236 */
237 //@{
238
239 /*!
240 * @brief A unique identifier for this channel.
241 *
242 * A unique identifier for this channel.
243 * It can be used to find the same channel on different providers
244 *
245 * @return The Unique ID.
246 */
247 int UniqueID() const;
248
249 /*!
250 * @return The identifier of the client that serves this channel.
251 */
252 int ClientID() const;
253
254 /*!
255 * @brief Set the identifier of the client that serves this channel.
256 * @param iClientId The new ID.
257 * @return True if the something changed, false otherwise.
258 */
259 bool SetClientID(int iClientId);
260
261 /*!
262 * Get the channel number on the client.
263 * @return The channel number on the client.
264 */
265 const CPVRChannelNumber& ClientChannelNumber() const;
266
267 /*!
268 * @return The name of this channel on the client.
269 */
270 std::string ClientChannelName() const;
271
272 /*!
273 * @brief The stream input mime type
274 *
275 * The stream input type
276 * If it is empty, ffmpeg will try to scan the stream to find the right input format.
277 * See https://www.iana.org/assignments/media-types/media-types.xhtml for a
278 * list of the input formats.
279 *
280 * @return The stream input type
281 */
282 std::string MimeType() const;
283
284 // ISortable implementation
285 void ToSortable(SortItem& sortable, Field field) const override;
286
287 /*!
288 * @return Storage id for this channel in CPVRChannelGroup
289 */
290 std::pair<int, int> StorageId() const { return std::make_pair(m_iClientId, m_iUniqueId); }
291
292 /*!
293 * @brief Return true if this channel is encrypted.
294 *
295 * Return true if this channel is encrypted. Does not inform whether XBMC can play the file.
296 * Decryption should be done by the client.
297 *
298 * @return Return true if this channel is encrypted.
299 */
300 bool IsEncrypted() const;
301
302 /*!
303 * @brief Return the encryption system ID for this channel. 0 for FTA.
304 *
305 * Return the encryption system ID for this channel. 0 for FTA.
306 * The values are documented on: http://www.dvb.org/index.php?id=174.
307 *
308 * @return Return the encryption system ID for this channel.
309 */
310 int EncryptionSystem() const;
311
312 /*!
313 * @return A friendly name for the used encryption system.
314 */
315 std::string EncryptionName() const;
316 //@}
317
318 /*! @name EPG methods
319 */
320 //@{
321
322 /*!
323 * @return The ID of the EPG table to use for this channel or -1 if it isn't set.
324 */
325 int EpgID() const;
326
327 /*!
328 * @brief Create the EPG for this channel, if it does not yet exist
329 * @return true if a new epg was created, false otherwise.
330 */
331 bool CreateEPG();
332
333 /*!
334 * @brief Get the EPG table for this channel.
335 * @return The EPG for this channel.
336 */
337 std::shared_ptr<CPVREpg> GetEPG() const;
338
339 /*!
340 * @brief Get the EPG tags for this channel.
341 * @return The tags.
342 */
343 std::vector<std::shared_ptr<CPVREpgInfoTag>> GetEpgTags() const;
344
345 /*!
346 * @brief Get all EPG tags for the given time frame, including "gap" tags.
347 * @param timelineStart Start of time line.
348 * @param timelineEnd End of time line.
349 * @param minEventEnd The minimum end time of the events to return.
350 * @param maxEventStart The maximum start time of the events to return.
351 * @return The matching tags.
352 */
353 std::vector<std::shared_ptr<CPVREpgInfoTag>> GetEPGTimeline(const CDateTime& timelineStart,
354 const CDateTime& timelineEnd,
355 const CDateTime& minEventEnd,
356 const CDateTime& maxEventStart) const;
357
358 /*!
359 * @brief Create a "gap" EPG tag.
360 * @param start Start of gap.
361 * @param end End of gap.
362 * @return The tag.
363 */
364 std::shared_ptr<CPVREpgInfoTag> CreateEPGGapTag(const CDateTime& start,
365 const CDateTime& end) const;
366
367 /*!
368 * @brief Get the EPG tag that is now active on this channel.
369 *
370 * Get the EPG tag that is now active on this channel.
371 * Will return an empty tag if there is none.
372 *
373 * @return The EPG tag that is now active.
374 */
375 std::shared_ptr<CPVREpgInfoTag> GetEPGNow() const;
376
377 /*!
378 * @brief Get the EPG tag that was previously active on this channel.
379 *
380 * Get the EPG tag that was previously active on this channel.
381 * Will return an empty tag if there is none.
382 *
383 * @return The EPG tag that was previously active.
384 */
385 std::shared_ptr<CPVREpgInfoTag> GetEPGPrevious() const;
386
387 /*!
388 * @brief Get the EPG tag that will be next active on this channel.
389 *
390 * Get the EPG tag that will be next active on this channel.
391 * Will return an empty tag if there is none.
392 *
393 * @return The EPG tag that will be next active.
394 */
395 std::shared_ptr<CPVREpgInfoTag> GetEPGNext() const;
396
397 /*!
398 * @return Don't use an EPG for this channel if set to false.
399 */
400 bool EPGEnabled() const;
401
402 /*!
403 * @brief Set to true if an EPG should be used for this channel. Set to false otherwise.
404 * @param bEPGEnabled The new value.
405 * @return True if the something changed, false otherwise.
406 */
407 bool SetEPGEnabled(bool bEPGEnabled);
408
409 /*!
410 * @brief Get the name of the scraper to be used for this channel.
411 *
412 * Get the name of the scraper to be used for this channel.
413 * The default is 'client', which means the EPG should be loaded from the backend.
414 *
415 * @return The name of the scraper to be used for this channel.
416 */
417 std::string EPGScraper() const;
418
419 /*!
420 * @brief Set the name of the scraper to be used for this channel.
421 *
422 * Set the name of the scraper to be used for this channel.
423 * Set to "client" to load the EPG from the backend
424 *
425 * @param strScraper The new scraper name.
426 * @return True if the something changed, false otherwise.
427 */
428 bool SetEPGScraper(const std::string& strScraper);
429
430 bool CanRecord() const;
431
432 static std::string GetEncryptionName(int iCaid);
433
434 /*!
435 * @brief Get the client order for this channel
436 * @return iOrder The order for this channel
437 */
438 int ClientOrder() const { return m_iClientOrder; }
439
440 /*!
441 * @brief Get the client provider Uid for this channel
442 * @return m_iClientProviderUid The provider Uid for this channel
443 */
444 int ClientProviderUid() const { return m_iClientProviderUid; }
445
446 /*!
447 * @brief CEventStream callback for PVR events.
448 * @param event The event.
449 */
450 void Notify(const PVREvent& event);
451
452 /*!
453 * @brief Lock the instance. No other thread gets access to this channel until Unlock was called.
454 */
455 void Lock() { m_critSection.lock(); }
456
457 /*!
458 * @brief Unlock the instance. Other threads may get access to this channel again.
459 */
460 void Unlock() { m_critSection.unlock(); }
461
462 /*!
463 * @brief Get the default provider of this channel. The default
464 * provider represents the PVR add-on itself.
465 * @return The default provider of this channel
466 */
467 std::shared_ptr<CPVRProvider> GetDefaultProvider() const;
468
469 /*!
470 * @brief Whether or not this channel has a provider set by the client.
471 * @return True if a provider was set by the client, false otherwise.
472 */
473 bool HasClientProvider() const;
474
475 /*!
476 * @brief Get the provider of this channel. This may be the default provider or a
477 * custom provider set by the client. If @ref "HasClientProvider()" returns true
478 * the provider will be custom from the client, otherwise the default provider.
479 * @return The provider of this channel
480 */
481 std::shared_ptr<CPVRProvider> GetProvider() const;
482
483 //@}
484 private:
485 CPVRChannel() = delete;
486 CPVRChannel(const CPVRChannel& tag) = delete;
487 CPVRChannel& operator=(const CPVRChannel& channel) = delete;
488
489 /*!
490 * @brief Update the encryption name after SetEncryptionSystem() has been called.
491 */
492 void UpdateEncryptionName();
493
494 /*!
495 * @brief Reset the EPG instance pointer.
496 */
497 void ResetEPG();
498
499 /*!
500 * @brief Set the client provider Uid for this channel
501 * @param iClientProviderUid The provider Uid for this channel
502 * @return True if the something changed, false otherwise.
503 */
504 bool SetClientProviderUid(int iClientProviderUid);
505
506 /*! @name Kodi related channel data
507 */
508 //@{
509 int m_iChannelId = -1; /*!< the identifier given to this channel by the TV database */
510 bool m_bIsRadio = false; /*!< true if this channel is a radio channel, false if not */
511 bool m_bIsHidden = false; /*!< true if this channel is hidden, false if not */
512 bool m_bIsUserSetName = false; /*!< true if user set the channel name via GUI, false if not */
513 bool m_bIsUserSetIcon = false; /*!< true if user set the icon via GUI, false if not */
514 bool m_bIsUserSetHidden = false; /*!< true if user set the hidden flag via GUI, false if not */
515 bool m_bIsLocked = false; /*!< true if channel is locked, false if not */
516 CPVRCachedImage m_iconPath; /*!< the path to the icon for this channel */
517 std::string m_strChannelName; /*!< the name for this channel used by Kodi */
518 time_t m_iLastWatched = 0; /*!< last time channel has been watched */
519 bool m_bChanged =
520 false; /*!< true if anything in this entry was changed that needs to be persisted */
521 std::shared_ptr<CPVRRadioRDSInfoTag>
522 m_rdsTag; /*! < the radio rds data, if available for the channel. */
523 bool m_bHasArchive = false; /*!< true if this channel supports archive */
524 //@}
525
526 /*! @name EPG related channel data
527 */
528 //@{
529 int m_iEpgId = -1; /*!< the id of the EPG for this channel */
530 bool m_bEPGEnabled = false; /*!< don't use an EPG for this channel if set to false */
531 std::string m_strEPGScraper =
532 "client"; /*!< the name of the scraper to be used for this channel */
533 std::shared_ptr<CPVREpg> m_epg;
534 //@}
535
536 /*! @name Client related channel data
537 */
538 //@{
539 int m_iUniqueId = -1; /*!< the unique identifier for this channel */
540 int m_iClientId = -1; /*!< the identifier of the client that serves this channel */
541 CPVRChannelNumber m_clientChannelNumber; /*!< the channel number on the client */
542 std::string m_strClientChannelName; /*!< the name of this channel on the client */
543 std::string
544 m_strMimeType; /*!< the stream input type based mime type, see @ref https://www.iana.org/assignments/media-types/media-types.xhtml#video */
545 int m_iClientEncryptionSystem =
546 -1; /*!< the encryption system used by this channel. 0 for FreeToAir, -1 for unknown */
547 std::string
548 m_strClientEncryptionName; /*!< the name of the encryption system used by this channel */
549 int m_iClientOrder = 0; /*!< the order from this channels group member */
550 int m_iClientProviderUid =
551 PVR_PROVIDER_INVALID_UID; /*!< the unique id for this provider from the client */
552 int m_lastWatchedGroupId{
553 -1}; /*!< the id of the channel group the channel was watched from the last time */
554 //@}
555
556 mutable CCriticalSection m_critSection;
557 };
558 } // namespace PVR