-
-
Notifications
You must be signed in to change notification settings - Fork 6.3k
/
PVRManager.h
596 lines (495 loc) · 17.2 KB
/
PVRManager.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
/*
* Copyright (C) 2012-2018 Team Kodi
* This file is part of Kodi - https://kodi.tv
*
* SPDX-License-Identifier: GPL-2.0-or-later
* See LICENSES/README.md for more information.
*/
#pragma once
#include "addons/kodi-addon-dev-kit/include/kodi/xbmc_pvr_types.h"
#include "interfaces/IAnnouncer.h"
#include "pvr/PVRActionListener.h"
#include "pvr/PVRSettings.h"
#include "pvr/epg/EpgContainer.h"
#include "threads/CriticalSection.h"
#include "threads/Event.h"
#include "threads/Thread.h"
#include "utils/EventStream.h"
#include <memory>
#include <string>
#include <vector>
class CFileItem;
class CJob;
class CStopWatch;
namespace PVR
{
class CPVRChannel;
class CPVRChannelGroup;
class CPVRChannelGroupsContainer;
class CPVRClient;
class CPVRClients;
class CPVRDatabase;
class CPVRGUIActions;
class CPVRGUIInfo;
class CPVRGUIProgressHandler;
class CPVRRecording;
class CPVRRecordings;
class CPVRTimers;
enum class PVREvent
{
// PVR Manager states
ManagerError = 0,
ManagerStopped,
ManagerStarting,
ManagerStopping,
ManagerInterrupted,
ManagerStarted,
// Channel events
ChannelPlaybackStopped,
// Channel group events
ChannelGroup,
ChannelGroupInvalidated,
ChannelGroupsInvalidated,
ChannelGroupsLoaded,
// Recording events
RecordingsInvalidated,
// Timer events
AnnounceReminder,
Timers,
TimersInvalidated,
// EPG events
Epg,
EpgActiveItem,
EpgContainer,
EpgItemUpdate,
EpgUpdatePending,
// Item events
CurrentItem,
};
class CPVRManagerJobQueue
{
public:
CPVRManagerJobQueue();
void Start();
void Stop();
void Clear();
void AppendJob(CJob * job);
void ExecutePendingJobs();
bool WaitForJobs(unsigned int milliSeconds);
private:
CCriticalSection m_critSection;
CEvent m_triggerEvent;
std::vector<CJob *> m_pendingUpdates;
bool m_bStopped = true;
};
class CPVRManager : private CThread, public ANNOUNCEMENT::IAnnouncer
{
public:
/*!
* @brief Create a new CPVRManager instance, which handles all PVR related operations in XBMC.
*/
CPVRManager(void);
/*!
* @brief Stop the PVRManager and destroy all objects it created.
*/
~CPVRManager(void) override;
void Announce(ANNOUNCEMENT::AnnouncementFlag flag, const char* sender, const char* message, const CVariant& data) override;
/*!
* @brief Get the channel groups container.
* @return The groups container.
*/
std::shared_ptr<CPVRChannelGroupsContainer> ChannelGroups(void) const;
/*!
* @brief Get the recordings container.
* @return The recordings container.
*/
std::shared_ptr<CPVRRecordings> Recordings(void) const;
/*!
* @brief Get the timers container.
* @return The timers container.
*/
std::shared_ptr<CPVRTimers> Timers(void) const;
/*!
* @brief Get the timers container.
* @return The timers container.
*/
std::shared_ptr<CPVRClients> Clients(void) const;
/*!
* @brief Get the instance of a client that matches the given item.
* @param item The item containing a PVR recording, a PVR channel, a PVR timer or a PVR EPG event.
* @return the requested client on success, nullptr otherwise.
*/
std::shared_ptr<CPVRClient> GetClient(const CFileItem& item) const;
/*!
* @brief Get the instance of a client that matches the given id.
* @param iClientId The id of a PVR client.
* @return the requested client on success, nullptr otherwise.
*/
std::shared_ptr<CPVRClient> GetClient(int iClientId) const;
/*!
* @brief Get access to the pvr gui actions.
* @return The gui actions.
*/
std::shared_ptr<CPVRGUIActions> GUIActions(void) const;
/*!
* @brief Get access to the epg container.
* @return The epg container.
*/
CPVREpgContainer& EpgContainer();
/*!
* @brief Init PVRManager.
*/
void Init(void);
/*!
* @brief Start the PVRManager, which loads all PVR data and starts some threads to update the PVR data.
*/
void Start();
/*!
* @brief Stop PVRManager.
*/
void Stop(void);
/*!
* @brief Stop PVRManager, unload data.
*/
void Unload();
/*!
* @brief Deinit PVRManager, unload data, unload addons.
*/
void Deinit();
/*!
* @brief Propagate event on system sleep
*/
void OnSleep();
/*!
* @brief Propagate event on system wake
*/
void OnWake();
/*!
* @brief Get the TV database.
* @return The TV database.
*/
std::shared_ptr<CPVRDatabase> GetTVDatabase(void) const;
/*!
* @brief Check if a TV channel, radio channel or recording is playing.
* @return True if it's playing, false otherwise.
*/
bool IsPlaying(void) const;
/*!
* @brief Check if the given channel is playing.
* @param channel The channel to check.
* @return True if it's playing, false otherwise.
*/
bool IsPlayingChannel(const std::shared_ptr<CPVRChannel>& channel) const;
/*!
* @brief Check if the given recording is playing.
* @param recording The recording to check.
* @return True if it's playing, false otherwise.
*/
bool IsPlayingRecording(const std::shared_ptr<CPVRRecording>& recording) const;
/*!
* @brief Check if the given epg tag is playing.
* @param epgTag The tag to check.
* @return True if it's playing, false otherwise.
*/
bool IsPlayingEpgTag(const std::shared_ptr<CPVREpgInfoTag>& epgTag) const;
/*!
* @return True while the PVRManager is initialising.
*/
inline bool IsInitialising(void) const
{
return GetState() == ManagerStateStarting;
}
/*!
* @brief Check whether the PVRManager has fully started.
* @return True if started, false otherwise.
*/
inline bool IsStarted(void) const
{
return GetState() == ManagerStateStarted;
}
/*!
* @brief Check whether the PVRManager is stopping
* @return True while the PVRManager is stopping.
*/
inline bool IsStopping(void) const
{
return GetState() == ManagerStateStopping;
}
/*!
* @brief Check whether the PVRManager has been stopped.
* @return True if stopped, false otherwise.
*/
inline bool IsStopped(void) const
{
return GetState() == ManagerStateStopped;
}
/*!
* @brief Check whether playing channel matches given uids.
* @param iClientID The client id.
* @param iUniqueChannelID The channel uid.
* @return True on match, false if there is no match or no channel is playing.
*/
bool IsPlayingChannel(int iClientID, int iUniqueChannelID) const;
/*!
* @brief Return the channel that is currently playing.
* @return The channel or NULL if none is playing.
*/
std::shared_ptr<CPVRChannel> GetPlayingChannel(void) const;
/*!
* @brief Return the recording that is currently playing.
* @return The recording or NULL if none is playing.
*/
std::shared_ptr<CPVRRecording> GetPlayingRecording(void) const;
/*!
* @brief Return the epg tag that is currently playing.
* @return The tag or NULL if none is playing.
*/
std::shared_ptr<CPVREpgInfoTag> GetPlayingEpgTag(void) const;
/*!
* @brief Get the name of the playing client, if there is one.
* @return The name of the client or an empty string if nothing is playing.
*/
std::string GetPlayingClientName(void) const;
/*!
* @brief Get the ID of the playing client, if there is one.
* @return The ID or -1 if no client is playing.
*/
int GetPlayingClientID(void) const;
/*!
* @brief Check whether there is an active recording on the currenlyt playing channel.
* @return True if there is a playing channel and there is an active recording on that channel, false otherwise.
*/
bool IsRecordingOnPlayingChannel(void) const;
/*!
* @brief Check if an active recording is playing.
* @return True if an in-progress (active) recording is playing, false otherwise.
*/
bool IsPlayingActiveRecording() const;
/*!
* @brief Check whether the currently playing channel can be recorded.
* @return True if there is a playing channel that can be recorded, false otherwise.
*/
bool CanRecordOnPlayingChannel(void) const;
/*!
* @brief Check whether EPG tags for channels have been created.
* @return True if EPG tags have been created, false otherwise.
*/
bool EpgsCreated(void) const;
/*!
* @brief Inform PVR manager that playback of an item just started.
* @param item The item that started to play.
*/
void OnPlaybackStarted(const std::shared_ptr<CFileItem> item);
/*!
* @brief Inform PVR manager that playback of an item was stopped due to user interaction.
* @param item The item that stopped to play.
*/
void OnPlaybackStopped(const std::shared_ptr<CFileItem> item);
/*!
* @brief Inform PVR manager that playback of an item has stopped without user interaction.
* @param item The item that ended to play.
*/
void OnPlaybackEnded(const std::shared_ptr<CFileItem> item);
/*!
* @brief Check whether there are active recordings.
* @return True if there are active recordings, false otherwise.
*/
bool IsRecording(void) const;
/*!
* @brief Set the current playing group, used to load the right channel.
* @param group The new group.
*/
void SetPlayingGroup(const std::shared_ptr<CPVRChannelGroup>& group);
/*!
* @brief Get the current playing group, used to load the right channel.
* @param bRadio True to get the current radio group, false to get the current TV group.
* @return The current group or the group containing all channels if it's not set.
*/
std::shared_ptr<CPVRChannelGroup> GetPlayingGroup(bool bRadio = false) const;
/*!
* @brief Let the background thread create epg tags for all channels.
*/
void TriggerEpgsCreate(void);
/*!
* @brief Let the background thread update the recordings list.
*/
void TriggerRecordingsUpdate(void);
/*!
* @brief Let the background thread update the timer list.
*/
void TriggerTimersUpdate(void);
/*!
* @brief Let the background thread update the channel list.
*/
void TriggerChannelsUpdate(void);
/*!
* @brief Let the background thread update the channel groups list.
*/
void TriggerChannelGroupsUpdate(void);
/*!
* @brief Let the background thread search for all missing channel icons.
*/
void TriggerSearchMissingChannelIcons(void);
/*!
* @brief Let the background thread search for missing channel icons for channels contained in the given group.
* @param group The channel group.
*/
void TriggerSearchMissingChannelIcons(const std::shared_ptr<CPVRChannelGroup>& group);
/*!
* @brief Check whether names are still correct after the language settings changed.
*/
void LocalizationChanged(void);
/*!
* @brief Check if a TV channel is playing.
* @return True if it's playing, false otherwise.
*/
bool IsPlayingTV(void) const;
/*!
* @brief Check if a radio channel is playing.
* @return True if it's playing, false otherwise.
*/
bool IsPlayingRadio(void) const;
/*!
* @brief Check if a an encrypted TV or radio channel is playing.
* @return True if it's playing, false otherwise.
*/
bool IsPlayingEncryptedChannel(void) const;
/*!
* @brief Check if a recording is playing.
* @return True if it's playing, false otherwise.
*/
bool IsPlayingRecording(void) const;
/*!
* @brief Check if an epg tag is playing.
* @return True if it's playing, false otherwise.
*/
bool IsPlayingEpgTag(void) const;
/*!
* @brief Check if parental lock is overridden at the given moment.
* @param channel The channel to check.
* @return True if parental lock is overridden, false otherwise.
*/
bool IsParentalLocked(const std::shared_ptr<CPVRChannel>& channel) const;
/*!
* @brief Check if parental lock is overridden at the given moment.
* @param epgTag The epg tag to check.
* @return True if parental lock is overridden, false otherwise.
*/
bool IsParentalLocked(const std::shared_ptr<CPVREpgInfoTag>& epgTag) const;
/*!
* @brief Restart the parental timer.
*/
void RestartParentalTimer();
/*!
* @brief Create EPG tags for all channels in internal channel groups
* @return True if EPG tags where created successfully, false otherwise
*/
bool CreateChannelEpgs(void);
/*!
* @brief Signal a connection change of a client
*/
void ConnectionStateChange(CPVRClient* client, std::string connectString, PVR_CONNECTION_STATE state, std::string message);
/*!
* @brief Query the events available for CEventStream
*/
CEventStream<PVREvent>& Events() { return m_events; }
/*!
* @brief Publish an event
* @param state the event
*/
void PublishEvent(PVREvent state);
protected:
/*!
* @brief PVR update and control thread.
*/
void Process(void) override;
private:
/*!
* @brief Updates the last watched timestamps of the channel and group which are currently playing.
* @param channel The channel which is updated
* @param time The last watched time to set
*/
void UpdateLastWatched(const std::shared_ptr<CPVRChannel>& channel, const CDateTime& time);
/*!
* @brief Set the playing group to the first group the channel is in if the given channel is not part of the current playing group
* @param channel The channel
*/
void SetPlayingGroup(const std::shared_ptr<CPVRChannel>& channel);
/*!
* @brief Executes "pvrpowermanagement.setwakeupcmd"
*/
bool SetWakeupCommand(void);
/*!
* @brief Load at least one client and load all other PVR data (channelgroups, timers, recordings) after loading the client.
* @param progressHandler The progress handler to use for showing the different load stages.
* @return If at least one client and all pvr data was loaded, false otherwise.
*/
bool LoadComponents(CPVRGUIProgressHandler* progressHandler);
/*!
* @brief Unload all PVR data (recordings, timers, channelgroups).
*/
void UnloadComponents();
/*!
* @brief Reset all properties.
*/
void ResetProperties(void);
/*!
* @brief Destroy PVRManager's objects.
*/
void Clear(void);
/*!
* @brief Continue playback on the last played channel.
*/
void TriggerPlayChannelOnStartup(void);
enum ManagerState
{
ManagerStateError = 0,
ManagerStateStopped,
ManagerStateStarting,
ManagerStateStopping,
ManagerStateInterrupted,
ManagerStateStarted
};
/*!
* @brief Get the current state of the PVR manager.
* @return the state.
*/
ManagerState GetState(void) const;
/*!
* @brief Set the current state of the PVR manager.
* @param state the new state.
*/
void SetState(ManagerState state);
bool IsCurrentlyParentalLocked(const std::shared_ptr<CPVRChannel>& channel, bool bGenerallyLocked) const;
/** @name containers */
//@{
std::shared_ptr<CPVRChannelGroupsContainer> m_channelGroups; /*!< pointer to the channel groups container */
std::shared_ptr<CPVRRecordings> m_recordings; /*!< pointer to the recordings container */
std::shared_ptr<CPVRTimers> m_timers; /*!< pointer to the timers container */
std::shared_ptr<CPVRClients> m_addons; /*!< pointer to the pvr addon container */
std::unique_ptr<CPVRGUIInfo> m_guiInfo; /*!< pointer to the guiinfo data */
std::shared_ptr<CPVRGUIActions> m_guiActions; /*!< pointer to the pvr gui actions */
CPVREpgContainer m_epgContainer; /*!< the epg container */
//@}
CPVRManagerJobQueue m_pendingUpdates; /*!< vector of pending pvr updates */
std::shared_ptr<CPVRDatabase> m_database; /*!< the database for all PVR related data */
mutable CCriticalSection m_critSection; /*!< critical section for all changes to this class, except for changes to triggers */
bool m_bFirstStart = true; /*!< true when the PVR manager was started first, false otherwise */
bool m_bEpgsCreated = false; /*!< true if epg data for channels has been created */
mutable CCriticalSection m_managerStateMutex;
ManagerState m_managerState = ManagerStateStopped;
std::unique_ptr<CStopWatch> m_parentalTimer;
CCriticalSection m_startStopMutex; // mutex for protecting pvr manager's start/restart/stop sequence */
CEventSource<PVREvent> m_events;
CPVRActionListener m_actionListener;
CPVRSettings m_settings;
std::shared_ptr<CPVRChannel> m_playingChannel;
std::shared_ptr<CPVRRecording> m_playingRecording;
std::shared_ptr<CPVREpgInfoTag> m_playingEpgTag;
std::string m_strPlayingClientName;
int m_playingClientId = -1;
int m_iplayingChannelUniqueID = -1;
class CLastWatchedUpdateTimer;
std::unique_ptr<CLastWatchedUpdateTimer> m_lastWatchedUpdateTimer;
};
}