-
Notifications
You must be signed in to change notification settings - Fork 7
/
client.cpp
729 lines (642 loc) · 15.6 KB
/
client.cpp
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
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
#include "client.h"
#include "TeleBoy.h"
#include "kodi/xbmc_pvr_dll.h"
#include "kodi/libKODI_guilib.h"
#include <chrono>
#include <thread>
using namespace ADDON;
#ifdef TARGET_WINDOWS
#define snprintf _snprintf
#endif
#ifdef TARGET_ANDROID
#include "to_string.h"
#endif
ADDON_STATUS m_CurStatus = ADDON_STATUS_UNKNOWN;
TeleBoy *teleboy = NULL;
/* User adjustable settings are saved here.
* Default values are defined inside client.h
* and exported to the other source files.
*/
std::string g_strUserPath = "";
std::string g_strClientPath = "";
CHelper_libXBMC_addon *XBMC = NULL;
CHelper_libXBMC_pvr *PVR = NULL;
std::string teleboyUsername = "";
std::string teleboyPassword = "";
bool teleboyFavoritesOnly = false;
bool teleboyEnableDolby = true;
int runningRequests = 0;
extern "C"
{
void ADDON_ReadSettings(void)
{
char buffer[1024];
bool boolBuffer;
XBMC->Log(LOG_DEBUG, "Read settings");
if (XBMC->GetSetting("username", &buffer))
{
teleboyUsername = buffer;
}
if (XBMC->GetSetting("password", &buffer))
{
teleboyPassword = buffer;
}
if (XBMC->GetSetting("favoritesonly", &boolBuffer))
{
teleboyFavoritesOnly = boolBuffer;
}
if (XBMC->GetSetting("enableDolby", &boolBuffer))
{
teleboyEnableDolby = boolBuffer;
}
XBMC->Log(LOG_DEBUG, "End Readsettings");
}
ADDON_STATUS ADDON_Create(void *hdl, void *props)
{
if (!hdl || !props)
{
return ADDON_STATUS_UNKNOWN;
}
PVR_PROPERTIES *pvrprops = (PVR_PROPERTIES *) props;
XBMC = new CHelper_libXBMC_addon;
XBMC->RegisterMe(hdl);
if (!XBMC->RegisterMe(hdl))
{
SAFE_DELETE(XBMC);
return ADDON_STATUS_PERMANENT_FAILURE;
}
PVR = new CHelper_libXBMC_pvr;
if (!PVR->RegisterMe(hdl))
{
SAFE_DELETE(PVR);
SAFE_DELETE(XBMC);
return ADDON_STATUS_PERMANENT_FAILURE;
}
XBMC->Log(LOG_DEBUG, "%s - Creating the PVR Teleboy add-on", __FUNCTION__);
m_CurStatus = ADDON_STATUS_NEED_SETTINGS;
g_strClientPath = pvrprops->strClientPath;
g_strUserPath = pvrprops->strUserPath;
teleboyUsername = "";
teleboyPassword = "";
ADDON_ReadSettings();
if (teleboyUsername.empty() || teleboyPassword.empty()) {
XBMC->Log(LOG_INFO, "Username or password not set.");
XBMC->QueueNotification(QUEUE_WARNING, XBMC->GetLocalizedString(30100));
return m_CurStatus;
}
XBMC->Log(LOG_DEBUG, "Create Teleboy");
teleboy = new TeleBoy(teleboyFavoritesOnly, teleboyEnableDolby);
XBMC->Log(LOG_DEBUG, "Login Teleboy");
if (teleboy->Login(teleboyUsername, teleboyPassword)) {
XBMC->Log(LOG_DEBUG, "Login done");
m_CurStatus = ADDON_STATUS_OK;
} else {
XBMC->Log(LOG_ERROR, "Login failed");
XBMC->QueueNotification(QUEUE_ERROR, XBMC->GetLocalizedString(30101));
}
return m_CurStatus;
}
ADDON_STATUS ADDON_GetStatus()
{
return m_CurStatus;
}
void ADDON_Destroy()
{
TeleBoy *oldTeleboy = teleboy;
teleboy = nullptr;
int waitCount = 10;
while (runningRequests > 0 && waitCount > 0)
{
XBMC->Log(LOG_INFO, "Wait for %d requests to finish for %d seconds.", runningRequests, waitCount);
std::this_thread::sleep_for(std::chrono::seconds(1));
waitCount--;
}
SAFE_DELETE(oldTeleboy);
SAFE_DELETE(PVR);
SAFE_DELETE(XBMC);
m_CurStatus = ADDON_STATUS_UNKNOWN;
}
ADDON_STATUS ADDON_SetSetting(const char *settingName, const void *settingValue)
{
string name = settingName;
if (name == "username")
{
string username = (const char*) settingValue;
if (username != teleboyUsername)
{
teleboyUsername = username;
return ADDON_STATUS_NEED_RESTART;
}
}
if (name == "password")
{
string password = (const char*) settingValue;
if (password != teleboyPassword)
{
teleboyPassword = password;
return ADDON_STATUS_NEED_RESTART;
}
}
if (name == "favoritesonly")
{
bool favOnly = *(bool *) settingValue;
if (favOnly != teleboyFavoritesOnly)
{
teleboyFavoritesOnly = favOnly;
return ADDON_STATUS_NEED_RESTART;
}
}
return ADDON_STATUS_OK;
}
void ADDON_Stop()
{
}
/***********************************************************
* PVR Client AddOn specific public library functions
***********************************************************/
void OnSystemSleep()
{
}
void OnSystemWake()
{
}
void OnPowerSavingActivated()
{
}
void OnPowerSavingDeactivated()
{
}
PVR_ERROR GetAddonCapabilities(PVR_ADDON_CAPABILITIES* pCapabilities)
{
pCapabilities->bSupportsEPG = true;
pCapabilities->bSupportsTV = true;
pCapabilities->bSupportsRadio = false;
pCapabilities->bSupportsChannelGroups = false;
pCapabilities->bSupportsRecordingPlayCount = false;
pCapabilities->bSupportsLastPlayedPosition = false;
pCapabilities->bSupportsRecordingsRename = false;
pCapabilities->bSupportsRecordingsLifetimeChange = false;
pCapabilities->bSupportsDescrambleInfo = false;
pCapabilities->bSupportsEPGEdl = true;
pCapabilities->bSupportsRecordingEdl = true;
runningRequests++;
if (teleboy)
{
teleboy->GetAddonCapabilities(pCapabilities);
}
runningRequests--;
return PVR_ERROR_NO_ERROR;
}
const char *GetBackendName(void)
{
static const char *strBackendName = "Teleboy PVR Add-on";
return strBackendName;
}
const char *GetBackendVersion(void)
{
static std::string strBackendVersion = STR(IPTV_VERSION);
return strBackendVersion.c_str();
}
const char *GetConnectionString(void)
{
static std::string strConnectionString = "connected";
return strConnectionString.c_str();
}
const char *GetBackendHostname(void)
{
return "";
}
PVR_ERROR GetEPGForChannel(ADDON_HANDLE handle, int iChannelUid,
time_t iStart, time_t iEnd)
{
runningRequests++;
PVR_ERROR ret = PVR_ERROR_SERVER_ERROR;
if (teleboy)
{
teleboy->GetEPGForChannel(iChannelUid, iStart, iEnd);
ret = PVR_ERROR_NO_ERROR;
}
runningRequests--;
return ret;
}
int GetChannelsAmount(void)
{
int ret = 0;
runningRequests++;
if (teleboy)
ret = teleboy->GetChannelsAmount();
runningRequests--;
return ret;
}
PVR_ERROR GetChannels(ADDON_HANDLE handle, bool bRadio)
{
if (bRadio)
return PVR_ERROR_NO_ERROR;
PVR_ERROR ret = PVR_ERROR_NO_ERROR;
runningRequests++;
if (teleboy)
ret = teleboy->GetChannels(handle, bRadio);
runningRequests--;
return ret;
}
bool OpenLiveStream(const PVR_CHANNEL &channel)
{
return false;
}
void CloseLiveStream(void)
{
}
int GetCurrentClientChannel(void)
{
return -1;
}
bool SwitchChannel(const PVR_CHANNEL &channel)
{
CloseLiveStream();
return OpenLiveStream(channel);
}
PVR_ERROR GetStreamProperties(PVR_STREAM_PROPERTIES* pProperties)
{
return PVR_ERROR_NOT_IMPLEMENTED;
}
int GetChannelGroupsAmount(void)
{
return PVR_ERROR_NOT_IMPLEMENTED;
}
PVR_ERROR GetChannelGroups(ADDON_HANDLE handle, bool bRadio)
{
return PVR_ERROR_SERVER_ERROR;
}
PVR_ERROR GetChannelGroupMembers(ADDON_HANDLE handle,
const PVR_CHANNEL_GROUP &group)
{
return PVR_ERROR_SERVER_ERROR;
}
void setStreamProperty(PVR_NAMED_VALUE* properties, unsigned int* propertiesCount, std::string name, std::string value)
{
strncpy(properties[*propertiesCount].strName, name.c_str(), sizeof(properties[*propertiesCount].strName) - 1);
strncpy(properties[*propertiesCount].strValue, value.c_str(), sizeof(properties[*propertiesCount].strValue) - 1);
*propertiesCount = (*propertiesCount) + 1;
}
void setStreamProperties(PVR_NAMED_VALUE* properties, unsigned int* propertiesCount, std::string url)
{
setStreamProperty(properties, propertiesCount, PVR_STREAM_PROPERTY_STREAMURL, url);
setStreamProperty(properties, propertiesCount, PVR_STREAM_PROPERTY_INPUTSTREAM, "inputstream.adaptive");
setStreamProperty(properties, propertiesCount, "inputstream.adaptive.manifest_type", "mpd");
setStreamProperty(properties, propertiesCount, "inputstream.adaptive.manifest_update_parameter", "full");
setStreamProperty(properties, propertiesCount, PVR_STREAM_PROPERTY_MIMETYPE, "application/xml+dash");
}
PVR_ERROR GetChannelStreamProperties(const PVR_CHANNEL* channel,
PVR_NAMED_VALUE* properties, unsigned int* propertiesCount)
{
PVR_ERROR ret = PVR_ERROR_FAILED;
runningRequests++;
std::string strUrl = teleboy->GetChannelStreamUrl(channel->iUniqueId);
if (!strUrl.empty())
{
*propertiesCount = 0;
setStreamProperties(properties, propertiesCount, strUrl);
setStreamProperty(properties, propertiesCount, PVR_STREAM_PROPERTY_ISREALTIMESTREAM, "true");
ret = PVR_ERROR_NO_ERROR;
}
runningRequests--;
return ret;
}
PVR_ERROR GetRecordingStreamProperties(const PVR_RECORDING* recording,
PVR_NAMED_VALUE* properties, unsigned int* propertiesCount)
{
PVR_ERROR ret = PVR_ERROR_FAILED;
runningRequests++;
std::string strUrl = teleboy->GetRecordingStreamUrl(recording->strRecordingId);
if (!strUrl.empty())
{
*propertiesCount = 0;
setStreamProperties(properties, propertiesCount, strUrl);
ret = PVR_ERROR_NO_ERROR;
}
runningRequests--;
return ret;
}
/** Recording API **/
int GetRecordingsAmount(bool deleted)
{
return 0;
}
PVR_ERROR GetRecordings(ADDON_HANDLE handle, bool deleted)
{
if (deleted)
{
return PVR_ERROR_NO_ERROR;
}
PVR_ERROR ret = PVR_ERROR_SERVER_ERROR;
runningRequests++;
if (teleboy && m_CurStatus == ADDON_STATUS_OK)
{
teleboy->GetRecordings(handle, "ready");
ret = PVR_ERROR_NO_ERROR;
}
runningRequests--;
return ret;
}
int GetTimersAmount(void)
{
return 0;
}
PVR_ERROR GetTimers(ADDON_HANDLE handle)
{
PVR_ERROR ret = PVR_ERROR_SERVER_ERROR;
runningRequests++;
if (teleboy && m_CurStatus == ADDON_STATUS_OK)
{
teleboy->GetRecordings(handle, "planned");
ret = PVR_ERROR_NO_ERROR;
}
runningRequests--;
return ret;
}
PVR_ERROR AddTimer(const PVR_TIMER &timer)
{
if (timer.iEpgUid <= EPG_TAG_INVALID_UID)
{
return PVR_ERROR_REJECTED;
}
runningRequests++;
PVR_ERROR ret = PVR_ERROR_SERVER_ERROR;
if (teleboy)
{
ret = PVR_ERROR_REJECTED;
if (teleboy->Record(timer.iEpgUid))
{
PVR->TriggerTimerUpdate();
PVR->TriggerRecordingUpdate();
ret = PVR_ERROR_NO_ERROR;
}
}
runningRequests--;
return ret;
}
PVR_ERROR DeleteRecording(const PVR_RECORDING &recording)
{
PVR_ERROR ret = PVR_ERROR_SERVER_ERROR;
runningRequests++;
if (teleboy)
{
ret = PVR_ERROR_REJECTED;
if (teleboy->DeleteRecording(recording.strRecordingId))
{
ret = PVR_ERROR_NO_ERROR;
}
}
runningRequests--;
return ret;
}
PVR_ERROR DeleteTimer(const PVR_TIMER &timer, bool bForceDelete)
{
PVR_ERROR ret = PVR_ERROR_SERVER_ERROR;
runningRequests++;
if (teleboy)
{
ret = PVR_ERROR_REJECTED;
if (teleboy->DeleteRecording(to_string(timer.iClientIndex)))
{
PVR->TriggerTimerUpdate();
PVR->TriggerRecordingUpdate();
ret = PVR_ERROR_NO_ERROR;
}
}
runningRequests--;
return ret;
}
void addTimerType(PVR_TIMER_TYPE types[], int idx, int attributes)
{
types[idx].iId = idx + 1;
types[idx].iAttributes = attributes;
types[idx].iPrioritiesSize = 0;
types[idx].iLifetimesSize = 0;
types[idx].iPreventDuplicateEpisodesSize = 0;
types[idx].iRecordingGroupSize = 0;
types[idx].iMaxRecordingsSize = 0;
}
PVR_ERROR GetTimerTypes(PVR_TIMER_TYPE types[], int *size)
{
addTimerType(types, 0, PVR_TIMER_TYPE_ATTRIBUTE_NONE);
addTimerType(types, 1, PVR_TIMER_TYPE_IS_MANUAL);
*size = 2;
return PVR_ERROR_NO_ERROR;
}
PVR_ERROR IsEPGTagRecordable(const EPG_TAG* tag, bool* bIsRecordable)
{
PVR_ERROR ret = PVR_ERROR_FAILED;
runningRequests++;
if (teleboy)
{
*bIsRecordable = teleboy->IsRecordable(tag);
ret = PVR_ERROR_NO_ERROR;
}
runningRequests--;
return ret;
}
PVR_ERROR IsEPGTagPlayable(const EPG_TAG* tag, bool* bIsPlayable)
{
PVR_ERROR ret = PVR_ERROR_FAILED;
runningRequests++;
if (teleboy)
{
*bIsPlayable = teleboy->IsPlayable(tag);
ret = PVR_ERROR_NO_ERROR;
}
runningRequests--;
return ret;
}
PVR_ERROR GetEPGTagStreamProperties(const EPG_TAG* tag,
PVR_NAMED_VALUE* properties, unsigned int* iPropertiesCount)
{
PVR_ERROR ret = PVR_ERROR_FAILED;
runningRequests++;
std::string strUrl = teleboy->GetEpgTagUrl(tag);
if (!strUrl.empty())
{
*iPropertiesCount = 0;
setStreamProperties(properties, iPropertiesCount, strUrl);
ret = PVR_ERROR_NO_ERROR;
}
runningRequests--;
return ret;
}
PVR_ERROR GetEPGTagEdl(const EPG_TAG* epgTag, PVR_EDL_ENTRY edl[], int *size)
{
edl[0].start=0;
edl[0].end = 300000;
edl[0].type = PVR_EDL_TYPE_COMBREAK;
*size = 1;
return PVR_ERROR_NO_ERROR;
}
PVR_ERROR SetRecordingPlayCount(const PVR_RECORDING &recording, int count)
{
return PVR_ERROR_NOT_IMPLEMENTED;
}
PVR_ERROR SetRecordingLastPlayedPosition(const PVR_RECORDING &recording,
int lastplayedposition)
{
return PVR_ERROR_NOT_IMPLEMENTED;
}
int GetRecordingLastPlayedPosition(const PVR_RECORDING &recording)
{
return -1;
}
PVR_ERROR GetRecordingSize(const PVR_RECORDING* recording, int64_t* sizeInBytes)
{
return PVR_ERROR_NOT_IMPLEMENTED;
}
/** UNUSED API FUNCTIONS */
bool CanPauseStream(void)
{
return true;
}
PVR_ERROR OpenDialogChannelScan(void)
{
return PVR_ERROR_NOT_IMPLEMENTED;
}
PVR_ERROR CallMenuHook(const PVR_MENUHOOK &menuhook,
const PVR_MENUHOOK_DATA &item)
{
return PVR_ERROR_NOT_IMPLEMENTED;
}
PVR_ERROR DeleteChannel(const PVR_CHANNEL &channel)
{
return PVR_ERROR_NOT_IMPLEMENTED;
}
PVR_ERROR RenameChannel(const PVR_CHANNEL &channel)
{
return PVR_ERROR_NOT_IMPLEMENTED;
}
PVR_ERROR OpenDialogChannelSettings(const PVR_CHANNEL &channel)
{
return PVR_ERROR_NOT_IMPLEMENTED;
}
PVR_ERROR OpenDialogChannelAdd(const PVR_CHANNEL &channel)
{
return PVR_ERROR_NOT_IMPLEMENTED;
}
bool OpenRecordedStream(const PVR_RECORDING &recording)
{
return false;
}
void CloseRecordedStream(void)
{
}
int ReadRecordedStream(unsigned char *pBuffer, unsigned int iBufferSize)
{
return 0;
}
long long SeekRecordedStream(long long iPosition, int iWhence /* = SEEK_SET */)
{
return 0;
}
long long LengthRecordedStream(void)
{
return 0;
}
void DemuxReset(void)
{
}
void DemuxFlush(void)
{
}
int ReadLiveStream(unsigned char *pBuffer, unsigned int iBufferSize)
{
return 0;
}
long long SeekLiveStream(long long iPosition, int iWhence /* = SEEK_SET */)
{
return -1;
}
long long LengthLiveStream(void)
{
return -1;
}
PVR_ERROR RenameRecording(const PVR_RECORDING &recording)
{
return PVR_ERROR_NOT_IMPLEMENTED;
}
PVR_ERROR GetRecordingEdl(const PVR_RECORDING& recording, PVR_EDL_ENTRY edl[], int *size)
{
edl[0].start=0;
edl[0].end = 300000;
edl[0].type = PVR_EDL_TYPE_COMBREAK;
*size = 1;
return PVR_ERROR_NO_ERROR;
}
PVR_ERROR UpdateTimer(const PVR_TIMER &timer)
{
return PVR_ERROR_NOT_IMPLEMENTED;
}
void DemuxAbort(void)
{
}
DemuxPacket* DemuxRead(void)
{
return NULL;
}
void FillBuffer(bool mode)
{
}
unsigned int GetChannelSwitchDelay(void)
{
return 0;
}
bool IsRealTimeStream(void)
{
return true;
}
void PauseStream(bool bPaused)
{
}
bool CanSeekStream(void)
{
return true;
}
bool SeekTime(double, bool, double*)
{
return false;
}
void SetSpeed(int)
{
}
PVR_ERROR UndeleteRecording(const PVR_RECORDING& recording)
{
return PVR_ERROR_NOT_IMPLEMENTED;
}
PVR_ERROR DeleteAllRecordingsFromTrash()
{
return PVR_ERROR_NOT_IMPLEMENTED;
}
PVR_ERROR SetEPGTimeFrame(int)
{
return PVR_ERROR_NOT_IMPLEMENTED;
}
PVR_ERROR GetDescrambleInfo(PVR_DESCRAMBLE_INFO*)
{
return PVR_ERROR_NOT_IMPLEMENTED;
}
PVR_ERROR SetRecordingLifetime(const PVR_RECORDING*)
{
return PVR_ERROR_NOT_IMPLEMENTED;
}
PVR_ERROR GetStreamTimes(PVR_STREAM_TIMES *times)
{
return PVR_ERROR_NOT_IMPLEMENTED;
}
PVR_ERROR GetDriveSpace(long long *iTotal, long long *iUsed)
{
return PVR_ERROR_NOT_IMPLEMENTED;
}
PVR_ERROR SignalStatus(PVR_SIGNAL_STATUS &signalStatus)
{
return PVR_ERROR_NOT_IMPLEMENTED;
}
PVR_ERROR GetStreamReadChunkSize(int* chunksize)
{
return PVR_ERROR_NOT_IMPLEMENTED;
}
}