-
-
Notifications
You must be signed in to change notification settings - Fork 6.2k
/
PVRClient.h
610 lines (512 loc) · 20.3 KB
/
PVRClient.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
608
609
610
#pragma once
/*
* Copyright (C) 2012-2013 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 "addons/Addon.h"
#include "addons/AddonDll.h"
#include "addons/DllPVRClient.h"
#include "pvr/channels/PVRChannel.h"
#include "pvr/recordings/PVRRecordings.h"
namespace EPG
{
class CEpg;
}
namespace PVR
{
class CPVRChannelGroup;
class CPVRChannelGroupInternal;
class CPVRChannelGroups;
class CPVRTimers;
class CPVRTimerInfoTag;
class CPVRRecordings;
class CPVREpgContainer;
class CPVRClient;
typedef std::vector<PVR_MENUHOOK> PVR_MENUHOOKS;
typedef boost::shared_ptr<CPVRClient> PVR_CLIENT;
#define PVR_INVALID_CLIENT_ID (-2)
#define PVR_VIRTUAL_CLIENT_ID (-1)
/*!
* Interface from XBMC to a PVR add-on.
*
* Also translates XBMC's C++ structures to the addon's C structures.
*/
class CPVRClient : public ADDON::CAddonDll<DllPVRClient, PVRClient, PVR_PROPERTIES>
{
public:
CPVRClient(const ADDON::AddonProps& props);
CPVRClient(const cp_extension_t *ext);
~CPVRClient(void);
/** @name PVR add-on methods */
//@{
/*!
* @brief Initialise the instance of this add-on.
* @param iClientId The ID of this add-on.
*/
ADDON_STATUS Create(int iClientId);
/*!
* @return True when the dll for this add-on was loaded, false otherwise (e.g. unresolved symbols)
*/
bool DllLoaded(void) const;
/*!
* @brief Destroy the instance of this add-on.
*/
void Destroy(void);
/*!
* @brief Destroy and recreate this add-on.
*/
void ReCreate(void);
/*!
* @return True if this instance is initialised, false otherwise.
*/
bool ReadyToUse(void) const;
/*!
* @return The ID of this instance.
*/
int GetID(void) const;
//@}
/** @name PVR server methods */
//@{
/*!
* @brief Query this add-on's capabilities.
* @return pCapabilities The add-on's capabilities.
*/
PVR_ADDON_CAPABILITIES GetAddonCapabilities(void) const;
/*!
* @brief Get the stream properties of the stream that's currently being read.
* @param pProperties The properties.
* @return PVR_ERROR_NO_ERROR if the properties have been fetched successfully.
*/
PVR_ERROR GetStreamProperties(PVR_STREAM_PROPERTIES *pProperties);
/*!
* @return The name reported by the backend.
*/
CStdString GetBackendName(void) const;
/*!
* @return The version string reported by the backend.
*/
CStdString GetBackendVersion(void) const;
/*!
* @return The connection string reported by the backend.
*/
CStdString GetConnectionString(void) const;
/*!
* @return A friendly name for this add-on that can be used in log messages.
*/
CStdString GetFriendlyName(void) const;
/*!
* @brief Get the disk space reported by the server.
* @param iTotal The total disk space.
* @param iUsed The used disk space.
* @return PVR_ERROR_NO_ERROR if the drive space has been fetched successfully.
*/
PVR_ERROR GetDriveSpace(long long *iTotal, long long *iUsed);
/*!
* @brief Start a channel scan on the server.
* @return PVR_ERROR_NO_ERROR if the channel scan has been started successfully.
*/
PVR_ERROR StartChannelScan(void);
/*!
* @return True if this add-on has menu hooks, false otherwise.
*/
bool HaveMenuHooks(PVR_MENUHOOK_CAT cat) const;
/*!
* @return The menu hooks for this add-on.
*/
PVR_MENUHOOKS *GetMenuHooks(void);
/*!
* @brief Call one of the menu hooks of this client.
* @param hook The hook to call.
*/
void CallMenuHook(const PVR_MENUHOOK &hook);
//@}
/** @name PVR EPG methods */
//@{
/*!
* @brief Request an EPG table for a channel from the client.
* @param channel The channel to get the EPG table for.
* @param epg The table to write the data to.
* @param start The start time to use.
* @param end The end time to use.
* @param bSaveInDb If true, tell the callback method to save any new entry in the database or not. see CAddonCallbacksPVR::PVRTransferEpgEntry()
* @return PVR_ERROR_NO_ERROR if the table has been fetched successfully.
*/
PVR_ERROR GetEPGForChannel(const CPVRChannel &channel, EPG::CEpg *epg, time_t start = 0, time_t end = 0, bool bSaveInDb = false);
//@}
/** @name PVR channel group methods */
//@{
/*!
* @return The total amount of channel groups on the server or -1 on error.
*/
int GetChannelGroupsAmount(void);
/*!
* @brief Request the list of all channel groups from the backend.
* @param groups The groups container to get the groups for.
* @return PVR_ERROR_NO_ERROR if the list has been fetched successfully.
*/
PVR_ERROR GetChannelGroups(CPVRChannelGroups *groups);
/*!
* @brief Request the list of all group members from the backend.
* @param groups The group to get the members for.
* @return PVR_ERROR_NO_ERROR if the list has been fetched successfully.
*/
PVR_ERROR GetChannelGroupMembers(CPVRChannelGroup *group);
//@}
/** @name PVR channel methods */
//@{
/*!
* @return The total amount of channels on the server or -1 on error.
*/
int GetChannelsAmount(void);
/*!
* @brief Request the list of all channels from the backend.
* @param channels The channel group to add the channels to.
* @param bRadio True to get the radio channels, false to get the TV channels.
* @return PVR_ERROR_NO_ERROR if the list has been fetched successfully.
*/
PVR_ERROR GetChannels(CPVRChannelGroup &channels, bool bRadio);
//@}
/** @name PVR recording methods */
//@{
/*!
* @return The total amount of channels on the server or -1 on error.
*/
int GetRecordingsAmount(void);
/*!
* @brief Request the list of all recordings from the backend.
* @param results The container to add the recordings to.
* @return PVR_ERROR_NO_ERROR if the list has been fetched successfully.
*/
PVR_ERROR GetRecordings(CPVRRecordings *results);
/*!
* @brief Delete a recording on the backend.
* @param recording The recording to delete.
* @return PVR_ERROR_NO_ERROR if the recording has been deleted successfully.
*/
PVR_ERROR DeleteRecording(const CPVRRecording &recording);
/*!
* @brief Rename a recording on the backend.
* @param recording The recording to rename.
* @return PVR_ERROR_NO_ERROR if the recording has been renamed successfully.
*/
PVR_ERROR RenameRecording(const CPVRRecording &recording);
/*!
* @brief Set the play count of a recording on the backend.
* @param recording The recording to set the play count.
* @param count Play count.
* @return PVR_ERROR_NO_ERROR if the recording's play count has been set successfully.
*/
PVR_ERROR SetRecordingPlayCount(const CPVRRecording &recording, int count);
/*!
* @brief Set the last watched position of a recording on the backend.
* @param recording The recording.
* @param position The last watched position in seconds
* @return PVR_ERROR_NO_ERROR if the position has been stored successfully.
*/
PVR_ERROR SetRecordingLastPlayedPosition(const CPVRRecording &recording, int lastplayedposition);
/*!
* @brief Retrieve the last watched position of a recording on the backend.
* @param recording The recording.
* @return The last watched position in seconds or -1 on error
*/
int GetRecordingLastPlayedPosition(const CPVRRecording &recording);
//@}
/** @name PVR timer methods */
//@{
/*!
* @return The total amount of timers on the backend or -1 on error.
*/
int GetTimersAmount(void);
/*!
* @brief Request the list of all timers from the backend.
* @param results The container to store the result in.
* @return PVR_ERROR_NO_ERROR if the list has been fetched successfully.
*/
PVR_ERROR GetTimers(CPVRTimers *results);
/*!
* @brief Add a timer on the backend.
* @param timer The timer to add.
* @return PVR_ERROR_NO_ERROR if the timer has been added successfully.
*/
PVR_ERROR AddTimer(const CPVRTimerInfoTag &timer);
/*!
* @brief Delete a timer on the backend.
* @param timer The timer to delete.
* @param bForce Set to true to delete a timer that is currently recording a program.
* @return PVR_ERROR_NO_ERROR if the timer has been deleted successfully.
*/
PVR_ERROR DeleteTimer(const CPVRTimerInfoTag &timer, bool bForce = false);
/*!
* @brief Rename a timer on the server.
* @param timer The timer to rename.
* @param strNewName The new name of the timer.
* @return PVR_ERROR_NO_ERROR if the timer has been renamed successfully.
*/
PVR_ERROR RenameTimer(const CPVRTimerInfoTag &timer, const CStdString &strNewName);
/*!
* @brief Update the timer information on the server.
* @param timer The timer to update.
* @return PVR_ERROR_NO_ERROR if the timer has been updated successfully.
*/
PVR_ERROR UpdateTimer(const CPVRTimerInfoTag &timer);
//@}
/** @name PVR live stream methods */
//@{
/*!
* @brief Open a live stream on the server.
* @param channel The channel to stream.
* @param bIsSwitchingChannel True when switching channels, false otherwise.
* @return True if the stream opened successfully, false otherwise.
*/
bool OpenStream(const CPVRChannel &channel, bool bIsSwitchingChannel);
/*!
* @brief Close an open live stream.
*/
void CloseStream(void);
/*!
* @brief Read from an open live stream.
* @param lpBuf The buffer to store the data in.
* @param uiBufSize The amount of bytes to read.
* @return The amount of bytes that were actually read from the stream.
*/
int ReadStream(void* lpBuf, int64_t uiBufSize);
/*!
* @brief Seek in a live stream on a backend that supports timeshifting.
* @param iFilePosition The position to seek to.
* @param iWhence ?
* @return The new position.
*/
int64_t SeekStream(int64_t iFilePosition, int iWhence = SEEK_SET);
/*!
* @return The position in the stream that's currently being read.
*/
int64_t GetStreamPosition(void);
/*!
* @return The total length of the stream that's currently being read.
*/
int64_t GetStreamLength(void);
/*!
* @brief (Un)Pause a stream
*/
void PauseStream(bool bPaused);
/*!
* @return The channel number on the server of the live stream that's currently being read.
*/
int GetCurrentClientChannel(void);
/*!
* @brief Switch to another channel. Only to be called when a live stream has already been opened.
* @param channel The channel to switch to.
* @return True if the switch was successful, false otherwise.
*/
bool SwitchChannel(const CPVRChannel &channel);
/*!
* @brief Get the signal quality of the stream that's currently open.
* @param qualityinfo The signal quality.
* @return True if the signal quality has been read successfully, false otherwise.
*/
bool SignalQuality(PVR_SIGNAL_STATUS &qualityinfo);
/*!
* @brief Get the stream URL for a channel from the server. Used by the MediaPortal add-on.
* @param channel The channel to get the stream URL for.
* @return The requested URL.
*/
CStdString GetLiveStreamURL(const CPVRChannel &channel);
/*!
* @brief Check whether PVR backend supports pausing the currently playing stream
*/
bool CanPauseStream(void) const;
/*!
* @brief Check whether PVR backend supports seeking for the currently playing stream
*/
bool CanSeekStream(void) const;
/*!
* Notify the pvr addon/demuxer that XBMC wishes to seek the stream by time
* @param time The absolute time since stream start
* @param backwards True to seek to keyframe BEFORE time, else AFTER
* @param startpts can be updated to point to where display should start
* @return True if the seek operation was possible
* @remarks Optional, and only used if addon has its own demuxer. Return False if this add-on won't provide this function.
*/
bool SeekTime(int time, bool backwards, double *startpts);
/*!
* Notify the pvr addon/demuxer that XBMC wishes to change playback speed
* @param speed The requested playback speed
* @remarks Optional, and only used if addon has its own demuxer.
*/
void SetSpeed(int speed);
//@}
/** @name PVR recording stream methods */
//@{
/*!
* @brief Open a recording on the server.
* @param recording The recording to open.
* @return True if the stream has been opened succesfully, false otherwise.
*/
bool OpenStream(const CPVRRecording &recording);
//@}
/** @name PVR demultiplexer methods */
//@{
/*!
* @brief Reset the demultiplexer in the add-on.
*/
void DemuxReset(void);
/*!
* @brief Abort the demultiplexer thread in the add-on.
*/
void DemuxAbort(void);
/*!
* @brief Flush all data that's currently in the demultiplexer buffer in the add-on.
*/
void DemuxFlush(void);
/*!
* @brief Read a packet from the demultiplexer.
* @return The packet.
*/
DemuxPacket *DemuxRead(void);
//@}
bool SupportsChannelGroups(void) const;
bool SupportsChannelScan(void) const;
bool SupportsEPG(void) const;
bool SupportsLastPlayedPosition(void) const;
bool SupportsRadio(void) const;
bool SupportsRecordings(void) const;
bool SupportsRecordingFolders(void) const;
bool SupportsRecordingPlayCount(void) const;
bool SupportsTimers(void) const;
bool SupportsTV(void) const;
bool HandlesDemuxing(void) const;
bool HandlesInputStream(void) const;
bool IsPlayingLiveStream(void) const;
bool IsPlayingLiveTV(void) const;
bool IsPlayingLiveRadio(void) const;
bool IsPlayingEncryptedChannel(void) const;
bool IsPlayingRecording(void) const;
bool IsPlaying(void) const;
bool GetPlayingChannel(CPVRChannelPtr &channel) const;
bool GetPlayingRecording(CPVRRecording &recording) const;
/*! @name Signal status methods */
//@{
/*!
* @brief Get the quality data for the live stream that is currently playing.
* @param status A copy of the quality data.
*/
void GetQualityData(PVR_SIGNAL_STATUS *status) const;
/*!
* @return The current signal quality level.
*/
int GetSignalLevel(void) const;
/*!
* @return The current signal/noise ratio.
*/
int GetSNR(void) const;
/*!
* @brief Update the signal status for the tv stream that's currently being read.
*/
void UpdateCharInfoSignalStatus(void);
//@}
static const char *ToString(const PVR_ERROR error);
private:
/*!
* @brief Checks whether the provided API version is compatible with XBMC
* @param minVersion The add-on's XBMC_PVR_MIN_API_VERSION version
* @param version The add-on's XBMC_PVR_API_VERSION version
* @return True when compatible, false otherwise
*/
static bool IsCompatibleAPIVersion(const ADDON::AddonVersion &minVersion, const ADDON::AddonVersion &version);
/*!
* @brief Checks whether the provided GUI API version is compatible with XBMC
* @param minVersion The add-on's XBMC_GUI_MIN_API_VERSION version
* @param version The add-on's XBMC_GUI_API_VERSION version
* @return True when compatible, false otherwise
*/
static bool IsCompatibleGUIAPIVersion(const ADDON::AddonVersion &minVersion, const ADDON::AddonVersion &version);
/*!
* @brief Request the API version from the add-on, and check if it's compatible
* @return True when compatible, false otherwise.
*/
bool CheckAPIVersion(void);
/*!
* @brief Reset the signal quality data to the initial values.
*/
void ResetQualityData(PVR_SIGNAL_STATUS &qualityInfo);
/*!
* @brief Resets all class members to their defaults. Called by the constructors.
*/
void ResetProperties(int iClientId = PVR_INVALID_CLIENT_ID);
bool GetAddonProperties(void);
/*!
* @brief Copy over group info from xbmcGroup to addonGroup.
* @param xbmcGroup The group on XBMC's side.
* @param addonGroup The group on the addon's side.
*/
static void WriteClientGroupInfo(const CPVRChannelGroup &xbmcGroup, PVR_CHANNEL_GROUP &addonGroup);
/*!
* @brief Copy over recording info from xbmcRecording to addonRecording.
* @param xbmcRecording The recording on XBMC's side.
* @param addonRecording The recording on the addon's side.
*/
static void WriteClientRecordingInfo(const CPVRRecording &xbmcRecording, PVR_RECORDING &addonRecording);
/*!
* @brief Copy over timer info from xbmcTimer to addonTimer.
* @param xbmcTimer The timer on XBMC's side.
* @param addonTimer The timer on the addon's side.
*/
static void WriteClientTimerInfo(const CPVRTimerInfoTag &xbmcTimer, PVR_TIMER &addonTimer);
/*!
* @brief Copy over channel info from xbmcChannel to addonClient.
* @param xbmcChannel The channel on XBMC's side.
* @param addonChannel The channel on the addon's side.
*/
static void WriteClientChannelInfo(const CPVRChannel &xbmcChannel, PVR_CHANNEL &addonChannel);
/*!
* @brief Whether a channel can be played by this add-on
* @param channel The channel to check.
* @return True when it can be played, false otherwise.
*/
bool CanPlayChannel(const CPVRChannel &channel) const;
bool LogError(const PVR_ERROR error, const char *strMethod) const;
void LogException(const std::exception &e, const char *strFunctionName) const;
bool m_bReadyToUse; /*!< true if this add-on is connected to the backend, false otherwise */
CStdString m_strHostName; /*!< the host name */
PVR_MENUHOOKS m_menuhooks; /*!< the menu hooks for this add-on */
int m_iClientId; /*!< database ID of the client */
/* cached data */
CStdString m_strBackendName; /*!< the cached backend version */
bool m_bGotBackendName; /*!< true if the backend name has already been fetched */
CStdString m_strBackendVersion; /*!< the cached backend version */
bool m_bGotBackendVersion; /*!< true if the backend version has already been fetched */
CStdString m_strConnectionString; /*!< the cached connection string */
bool m_bGotConnectionString; /*!< true if the connection string has already been fetched */
CStdString m_strFriendlyName; /*!< the cached friendly name */
bool m_bGotFriendlyName; /*!< true if the friendly name has already been fetched */
PVR_ADDON_CAPABILITIES m_addonCapabilities; /*!< the cached add-on capabilities */
bool m_bGotAddonCapabilities; /*!< true if the add-on capabilities have already been fetched */
PVR_SIGNAL_STATUS m_qualityInfo; /*!< stream quality information */
/* stored strings to make sure const char* members in PVR_PROPERTIES stay valid */
std::string m_strUserPath; /*!< @brief translated path to the user profile */
std::string m_strClientPath; /*!< @brief translated path to this add-on */
CCriticalSection m_critSection;
bool m_bIsPlayingTV;
CPVRChannelPtr m_playingChannel;
bool m_bIsPlayingRecording;
CPVRRecording m_playingRecording;
ADDON::AddonVersion m_apiVersion;
bool m_bCanPauseStream;
bool m_bCanSeekStream;
};
}