-
Notifications
You must be signed in to change notification settings - Fork 0
/
PVRManager.h
607 lines (506 loc) · 18.8 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
597
598
599
600
601
602
603
604
605
606
607
#pragma once
/*
* Copyright (C) 2012 Team XBMC
* http://www.xbmc.org
*
* This Program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with XBMC; see the file COPYING. If not, see
* <http://www.gnu.org/licenses/>.
*
*/
#include "threads/Thread.h"
#include "utils/JobManager.h"
#include "threads/Event.h"
#include "addons/include/xbmc_pvr_types.h"
class CGUIDialogProgressBarHandle;
class CStopWatch;
namespace EPG
{
class CEpgContainer;
}
namespace PVR
{
class CPVRClients;
class CPVRChannel;
typedef boost::shared_ptr<PVR::CPVRChannel> CPVRChannelPtr;
class CPVRChannelGroupsContainer;
class CPVRChannelGroup;
class CPVRRecording;
class CPVRRecordings;
class CPVRTimers;
class CPVRGUIInfo;
class CPVRDatabase;
class CGUIWindowPVRCommon;
enum ManagerState
{
ManagerStateError = 0,
ManagerStateStopped,
ManagerStateStarting,
ManagerStateStopping,
ManagerStateInterrupted,
ManagerStateStarted
};
#define g_PVRManager CPVRManager::Get()
#define g_PVRChannelGroups g_PVRManager.ChannelGroups()
#define g_PVRTimers g_PVRManager.Timers()
#define g_PVRRecordings g_PVRManager.Recordings()
#define g_PVRClients g_PVRManager.Clients()
typedef boost::shared_ptr<PVR::CPVRChannelGroup> CPVRChannelGroupPtr;
class CPVRManager : private CThread
{
friend class CPVRClients;
private:
/*!
* @brief Create a new CPVRManager instance, which handles all PVR related operations in XBMC.
*/
CPVRManager(void);
public:
/*!
* @brief Stop the PVRManager and destroy all objects it created.
*/
virtual ~CPVRManager(void);
/*!
* @brief Get the instance of the PVRManager.
* @return The PVRManager instance.
*/
static CPVRManager &Get(void);
/*!
* @brief Get the channel groups container.
* @return The groups container.
*/
CPVRChannelGroupsContainer *ChannelGroups(void) const { return m_channelGroups; }
/*!
* @brief Get the recordings container.
* @return The recordings container.
*/
CPVRRecordings *Recordings(void) const { return m_recordings; }
/*!
* @brief Get the timers container.
* @return The timers container.
*/
CPVRTimers *Timers(void) const { return m_timers; }
/*!
* @brief Get the timers container.
* @return The timers container.
*/
CPVRClients *Clients(void) const { return m_addons; }
/*!
* @brief Start the PVRManager, which loads all PVR data and starts some threads to update the PVR data.
*/
void Start(void);
/*!
* @brief Stop the PVRManager and destroy all objects it created.
*/
void Stop(void);
/*!
* @brief Delete PVRManager's objects.
*/
void Cleanup(void);
public:
/*!
* @brief Get the TV database.
* @return The TV database.
*/
CPVRDatabase *GetTVDatabase(void) const { return m_database; }
/*!
* @brief Updates the recordings and the "now" and "next" timers.
*/
void UpdateRecordingsCache(void);
/*!
* @brief Get a GUIInfoManager character string.
* @param dwInfo The string to get.
* @return The requested string or an empty one if it wasn't found.
*/
bool TranslateCharInfo(DWORD dwInfo, CStdString &strValue) const;
/*!
* @brief Get a GUIInfoManager integer.
* @param dwInfo The integer to get.
* @return The requested integer or 0 if it wasn't found.
*/
int TranslateIntInfo(DWORD dwInfo) const;
/*!
* @brief Get a GUIInfoManager boolean.
* @param dwInfo The boolean to get.
* @return The requested boolean or false if it wasn't found.
*/
bool TranslateBoolInfo(DWORD dwInfo) const;
/*!
* @brief Show the player info.
* @param iTimeout Hide the player info after iTimeout seconds.
* @todo not really the right place for this :-)
*/
void ShowPlayerInfo(int iTimeout);
/*!
* @brief Reset the TV database to it's initial state and delete all the data inside.
* @param bShowProgress True to show a progress bar, false otherwise.
*/
void ResetDatabase(bool bShowProgress = true);
/*!
* @brief Delete all EPG data from the database and reload it from the clients.
*/
void ResetEPG(void);
/*!
* @brief Check if a TV channel, radio channel or recording is playing.
* @return True if it's playing, false otherwise.
*/
bool IsPlaying(void) const;
/*!
* @return True while the PVRManager is initialising.
*/
bool IsInitialising(void) const;
/*!
* @brief Return the channel that is currently playing.
* @param channel The channel or NULL if none is playing.
* @return True if a channel is playing, false otherwise.
*/
bool GetCurrentChannel(CPVRChannelPtr &channel) const;
/*!
* @brief Return the EPG for the channel that is currently playing.
* @param channel The EPG or NULL if no channel is playing.
* @return The amount of results that was added or -1 if none.
*/
int GetCurrentEpg(CFileItemList &results) const;
/*!
* @brief Check whether the PVRManager has fully started.
* @return True if started, false otherwise.
*/
bool IsStarted(void) const;
/*!
* @brief Reset the playing EPG tag.
*/
void ResetPlayingTag(void);
/*!
* @brief Switch to the given channel.
* @param channel The channel to switch to.
* @param bPreview True to show a preview, false otherwise.
* @return Trrue if the switch was successful, false otherwise.
*/
bool PerformChannelSwitch(const CPVRChannel &channel, bool bPreview);
/*!
* @brief Close an open PVR stream.
*/
void CloseStream(void);
/*!
* @brief Open a stream from the given channel.
* @param channel The channel to open.
* @return True if the stream was opened, false otherwise.
*/
bool OpenLiveStream(const CFileItem &channel);
/*!
* @brief Open a stream from the given recording.
* @param tag The recording to open.
* @return True if the stream was opened, false otherwise.
*/
bool OpenRecordedStream(const CPVRRecording &tag);
/*!
* @brief Start recording on a given channel if it is not already recording, stop if it is.
* @param channel the channel to start/stop recording.
* @return True if the recording was started or stopped successfully, false otherwise.
*/
bool ToggleRecordingOnChannel(unsigned int iChannelId);
/*!
* @brief Start or stop recording on the channel that is currently being played.
* @param bOnOff True to start recording, false to stop.
* @return True if the recording was started or stopped successfully, false otherwise.
*/
bool StartRecordingOnPlayingChannel(bool bOnOff);
/*!
* @brief Get the channel number of the previously selected channel.
* @return The requested channel number or -1 if it wasn't found.
*/
int GetPreviousChannel(void);
/*!
* @brief Check whether there are active timers.
* @return True if there are active timers, false otherwise.
*/
bool HasTimers(void) const;
/*!
* @brief Check whether there are active recordings.
* @return True if there are active recordings, false otherwise.
*/
bool IsRecording(void) const;
/*!
* @brief Check whether the pvr backend is idle.
* @return True if there are no active timers/recordings/wake-ups within the configured time span.
*/
bool IsIdle(void) const;
/*!
* @brief Set the current playing group, used to load the right channel.
* @param group The new group.
*/
void SetPlayingGroup(CPVRChannelGroupPtr 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.
*/
CPVRChannelGroupPtr GetPlayingGroup(bool bRadio = false);
/*!
* @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 save the current video settings.
*/
void TriggerSaveChannelSettings(void);
/*!
* @brief Update the channel that is currently active.
* @param item The new channel.
* @return True if it was updated correctly, false otherwise.
*/
bool UpdateItem(CFileItem& item);
/*!
* @brief Switch to a channel given it's channel number.
* @param iChannelNumber The channel number to switch to.
* @return True if the channel was switched, false otherwise.
*/
bool ChannelSwitch(unsigned int iChannelNumber);
/*!
* @brief Switch to the next channel in this group.
* @param iNewChannelNumber The new channel number after the switch.
* @param bPreview If true, don't do the actual switch but just update channel pointers.
* Used to display event info while doing "fast channel switching"
* @return True if the channel was switched, false otherwise.
*/
bool ChannelUp(unsigned int *iNewChannelNumber, bool bPreview = false) { return ChannelUpDown(iNewChannelNumber, bPreview, true); }
/*!
* @brief Switch to the previous channel in this group.
* @param iNewChannelNumber The new channel number after the switch.
* @param bPreview If true, don't do the actual switch but just update channel pointers.
* Used to display event info while doing "fast channel switching"
* @return True if the channel was switched, false otherwise.
*/
bool ChannelDown(unsigned int *iNewChannelNumber, bool bPreview = false) { return ChannelUpDown(iNewChannelNumber, bPreview, false); }
/*!
* @brief Get the total duration of the currently playing LiveTV item.
* @return The total duration in milliseconds or NULL if no channel is playing.
*/
int GetTotalTime(void) const;
/*!
* @brief Get the current position in milliseconds since the start of a LiveTV item.
* @return The position in milliseconds or NULL if no channel is playing.
*/
int GetStartTime(void) const;
/*!
* @brief Start playback on a channel.
* @param channel The channel to start to play.
* @param bPreview If true, open minimised.
* @return True if playback was started, false otherwise.
*/
bool StartPlayback(const CPVRChannel *channel, bool bPreview = false);
/*!
* @brief Update the current playing file in the guiinfomanager and application.
*/
void UpdateCurrentFile(void);
/*!
* @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 recording is playing.
* @return True if it's playing, false otherwise.
*/
bool IsPlayingRecording(void) const;
/*!
* @return True when a channel scan is currently running, false otherwise.
*/
bool IsRunningChannelScan(void) const;
/*!
* @brief Open a selection dialog and start a channel scan on the selected client.
*/
void StartChannelScan(void);
/*!
* @brief Try to find missing channel icons automatically
*/
void SearchMissingChannelIcons(void);
/*!
* @brief Persist the current channel settings in the database.
*/
void SaveCurrentChannelSettings(void);
/*!
* @brief Load the settings for the current channel from the database.
*/
void LoadCurrentChannelSettings(void);
/*!
* @brief Check if channel is parental locked. Ask for PIN if neccessary.
* @param channel The channel to open.
* @return True if channel is unlocked (by default or PIN unlocked), false otherwise.
*/
bool CheckParentalLock(const CPVRChannel &channel);
/*!
* @brief Check if parental lock is overriden at the given moment.
* @param channel The channel to open.
* @return True if parental lock is overriden, false otherwise.
*/
bool IsParentalLocked(const CPVRChannel &channel);
/*!
* @brief Open Numeric dialog to check for parental PIN.
* @param strTitle Override the title of the dialog if set.
* @return True if entered PIN was correct, false otherwise.
*/
bool CheckParentalPIN(const char *strTitle = NULL);
/*!
* @brief Executes "pvrpowermanagement.setwakeupcmd"
*/
bool SetWakeupCommand(void);
protected:
/*!
* @brief PVR update and control thread.
*/
virtual void Process(void);
private:
/*!
* @brief Load at least one client and load all other PVR data after loading the client.
* If some clients failed to load here, the pvrmanager will retry to load them every second.
* @return If at least one client and all pvr data was loaded, false otherwise.
*/
bool Load(void);
/*!
* @brief Update all recordings.
*/
void UpdateRecordings(void);
/*!
* @brief Update all timers.
*/
void UpdateTimers(void);
/*!
* @brief Update all channels.
*/
void UpdateChannels(void);
/*!
* @brief Update all channel groups and channels in them.
*/
void UpdateChannelGroups(void);
/*!
* @brief Reset all properties.
*/
void ResetProperties(void);
/*!
* @brief Called by ChannelUp() and ChannelDown() to perform a channel switch.
* @param iNewChannelNumber The new channel number after the switch.
* @param bPreview Preview window if true.
* @param bUp Go one channel up if true, one channel down if false.
* @return True if the switch was successful, false otherwise.
*/
bool ChannelUpDown(unsigned int *iNewChannelNumber, bool bPreview, bool bUp);
/*!
* @brief Stop the EPG and PVR threads but do not remove their data.
*/
void StopUpdateThreads(void);
/*!
* @brief Restart the EPG and PVR threads after they've been stopped by StopUpdateThreads()
*/
bool StartUpdateThreads(void);
/*!
* @brief Continue playback on the last channel if it was stored in the database.
* @return True if playback was continued, false otherwise.
*/
bool ContinueLastChannel(void);
/*!
* @brief Show or update the progress dialog.
* @param strText The current status.
* @param iProgress The current progress in %.
*/
void ShowProgressDialog(const CStdString &strText, int iProgress);
/*!
* @brief Hide the progress dialog if it's visible.
*/
void HideProgressDialog(void);
void ExecutePendingJobs(void);
bool IsJobPending(const char *strJobName) const;
ManagerState GetState(void) const;
void SetState(ManagerState state);
/** @name containers */
//@{
CPVRChannelGroupsContainer * m_channelGroups; /*!< pointer to the channel groups container */
CPVRRecordings * m_recordings; /*!< pointer to the recordings container */
CPVRTimers * m_timers; /*!< pointer to the timers container */
CPVRClients * m_addons; /*!< pointer to the pvr addon container */
CPVRGUIInfo * m_guiInfo; /*!< pointer to the guiinfo data */
//@}
CCriticalSection m_critSectionTriggers; /*!< critical section for triggered updates */
CEvent m_triggerEvent; /*!< triggers an update */
std::vector<CJob *> m_pendingUpdates; /*!< vector of pending pvr updates */
CFileItem * m_currentFile; /*!< the PVR file that is currently playing */
CPVRDatabase * m_database; /*!< the database for all PVR related data */
CCriticalSection m_critSection; /*!< critical section for all changes to this class, except for changes to triggers */
bool m_bFirstStart; /*!< true when the PVR manager was started first, false otherwise */
bool m_bIsSwitchingChannels; /*!< true while switching channels */
CGUIDialogProgressBarHandle * m_progressHandle; /*!< progress dialog that is displayed while the pvrmanager is loading */
CCriticalSection m_managerStateMutex;
ManagerState m_managerState;
CStopWatch *m_parentalTimer;
};
class CPVRRecordingsUpdateJob : public CJob
{
public:
CPVRRecordingsUpdateJob(void) {}
virtual ~CPVRRecordingsUpdateJob() {}
virtual const char *GetType() const { return "pvr-update-recordings"; }
virtual bool DoWork();
};
class CPVRTimersUpdateJob : public CJob
{
public:
CPVRTimersUpdateJob(void) {}
virtual ~CPVRTimersUpdateJob() {}
virtual const char *GetType() const { return "pvr-update-timers"; }
virtual bool DoWork();
};
class CPVRChannelsUpdateJob : public CJob
{
public:
CPVRChannelsUpdateJob(void) {}
virtual ~CPVRChannelsUpdateJob() {}
virtual const char *GetType() const { return "pvr-update-channels"; }
virtual bool DoWork();
};
class CPVRChannelGroupsUpdateJob : public CJob
{
public:
CPVRChannelGroupsUpdateJob(void) {}
virtual ~CPVRChannelGroupsUpdateJob() {}
virtual const char *GetType() const { return "pvr-update-channelgroups"; }
virtual bool DoWork();
};
class CPVRChannelSettingsSaveJob : public CJob
{
public:
CPVRChannelSettingsSaveJob(void) {}
virtual ~CPVRChannelSettingsSaveJob() {}
virtual const char *GetType() const { return "pvr-save-channelsettings"; }
virtual bool DoWork();
};
}