~ubuntu-branches/debian/sid/kodi/sid

« back to all changes in this revision

Viewing changes to xbmc/pvr/addons/PVRClient.cpp

  • Committer: Package Import Robot
  • Author(s): Balint Reczey
  • Date: 2015-08-18 14:16:59 UTC
  • mfrom: (1.1.1)
  • Revision ID: package-import@ubuntu.com-20150818141659-4lgq2pksj7918osz
Tags: 15.1+dfsg1-1
* New upstream release 15.0
  See http://www.kodi.tv/kodi-15-0-isengard-one-release-to-rule-them-all/
* Depend on libav.*-dev provided by src:ffmpeg
* Recommend udisks2 instead of udisks.
  Udisks has been removed from unstable but support for udisks2 is not
  implemented yet.
* Ship patch helping Jessie backports
* Refresh patches
* Eliminate __DATE__ macros from source to make build more reproducible
* Build-depend on libsdl2.*-dev instead of libsdl.*-dev
* Build-depend on libgif-dev
* Drop obsoleted fix of installed header's include paths
* Refresh include file list included by kodi-addons-dev
* Build depend on libcec (>= 3)
* Build-depend on groovy2 instead of groovy
* Sort build dependencies
* Fix packaging repository URL
* Remove removed files from debian/copyright
* Fix filenames with spaces in debian/copyright
* Ship TexturePacker in kodi-addons-dev in /usr/lib/kodi
* Build depend on libcec-platform-dev
* Stop using embedded gnulib modules in rsxs screensaver (Closes: #795813)
* Add missing copyright paragraphs to d/copyright
* Stop marking files as excluded which are removed from upstream tarball
  already
* Bump standards version to 3.9.6
* New upstream release 15.1
  See http://kodi.tv/kodi-15-1-isengard-maintenance-release/
* Move TexturePacker to kodi-bin
* Stop building TexturePacker statically

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
 
21
21
#include "Application.h"
22
22
#include "PVRClient.h"
 
23
#include "dialogs/GUIDialogYesNo.h"
23
24
#include "pvr/PVRManager.h"
24
25
#include "pvr/addons/PVRClients.h"
25
26
#include "epg/Epg.h"
30
31
#include "settings/AdvancedSettings.h"
31
32
#include "settings/Settings.h"
32
33
#include "utils/log.h"
 
34
#include "utils/StringUtils.h"
 
35
 
 
36
#include <assert.h>
33
37
 
34
38
using namespace ADDON;
35
39
using namespace PVR;
39
43
 
40
44
CPVRClient::CPVRClient(const AddonProps& props) :
41
45
    CAddonDll<DllPVRClient, PVRClient, PVR_PROPERTIES>(props),
42
 
    m_apiVersion("0.0.0")
 
46
    m_apiVersion("0.0.0"),
 
47
    m_bAvahiServiceAdded(false)
43
48
{
44
49
  ResetProperties();
45
50
}
46
51
 
47
52
CPVRClient::CPVRClient(const cp_extension_t *ext) :
48
53
    CAddonDll<DllPVRClient, PVRClient, PVR_PROPERTIES>(ext),
49
 
    m_apiVersion("0.0.0")
 
54
    m_apiVersion("0.0.0"),
 
55
    m_bAvahiServiceAdded(false)
50
56
{
51
57
  ResetProperties();
 
58
 
 
59
  m_strAvahiType = CAddonMgr::Get().GetExtValue(ext->configuration, "@avahi_type");
 
60
  m_strAvahiIpSetting = CAddonMgr::Get().GetExtValue(ext->configuration, "@avahi_ip_setting");
 
61
  m_strAvahiPortSetting = CAddonMgr::Get().GetExtValue(ext->configuration, "@avahi_port_setting");
 
62
  m_bNeedsConfiguration = !(CAddonMgr::Get().GetExtValue(ext->configuration, "@needs_configuration") == "false");
52
63
}
53
64
 
54
65
CPVRClient::~CPVRClient(void)
55
66
{
 
67
  if (m_bAvahiServiceAdded)
 
68
    CZeroconfBrowser::GetInstance()->RemoveServiceType(m_strAvahiType);
56
69
  Destroy();
57
70
  SAFE_DELETE(m_pInfo);
58
71
}
60
73
void CPVRClient::OnDisabled()
61
74
{
62
75
  // restart the PVR manager if we're disabling a client
63
 
  if (CPVRManager::Get().IsStarted())
 
76
  if (CPVRManager::Get().IsStarted() && CPVRManager::Get().RestartManagerOnAddonDisabled())
64
77
    CPVRManager::Get().Start(true);
65
78
}
66
79
 
67
80
void CPVRClient::OnEnabled()
68
81
{
69
82
  // restart the PVR manager if we're enabling a client
70
 
  CPVRManager::Get().Start(true);
 
83
  if (CPVRManager::Get().RestartManagerOnAddonDisabled())
 
84
    CPVRManager::Get().Start(true);
71
85
}
72
86
 
73
87
AddonPtr CPVRClient::GetRunningInstance() const
81
95
  return CAddon::GetRunningInstance();
82
96
}
83
97
 
84
 
bool CPVRClient::OnPreInstall()
 
98
void CPVRClient::OnPreInstall()
85
99
{
86
100
  // stop the pvr manager, so running pvr add-ons are stopped and closed
87
101
  PVR::CPVRManager::Get().Stop();
88
 
  return false;
89
102
}
90
103
 
91
 
void CPVRClient::OnPostInstall(bool restart, bool update)
 
104
void CPVRClient::OnPostInstall(bool update, bool modal)
92
105
{
93
106
  // (re)start the pvr manager
94
107
  PVR::CPVRManager::Get().Start(true);
132
145
  m_strConnectionString   = DEFAULT_INFO_STRING_VALUE;
133
146
  m_strFriendlyName       = DEFAULT_INFO_STRING_VALUE;
134
147
  m_strBackendName        = DEFAULT_INFO_STRING_VALUE;
 
148
  m_strBackendHostname.clear();
135
149
  m_bIsPlayingTV          = false;
136
150
  m_bIsPlayingRecording   = false;
137
151
  memset(&m_addonCapabilities, 0, sizeof(m_addonCapabilities));
138
 
  ResetQualityData(m_qualityInfo);
139
152
  m_apiVersion = AddonVersion("0.0.0");
140
153
}
141
154
 
142
155
ADDON_STATUS CPVRClient::Create(int iClientId)
143
156
{
144
157
  ADDON_STATUS status(ADDON_STATUS_UNKNOWN);
145
 
  if (iClientId <= PVR_INVALID_CLIENT_ID || iClientId == PVR_VIRTUAL_CLIENT_ID)
 
158
  if (iClientId <= PVR_INVALID_CLIENT_ID)
146
159
    return status;
147
160
 
148
161
  /* ensure that a previous instance is destroyed */
246
259
  addonRecording.iLifetime           = xbmcRecording.m_iLifetime;
247
260
  addonRecording.iPlayCount          = xbmcRecording.m_playCount;
248
261
  addonRecording.iLastPlayedPosition = (int)xbmcRecording.m_resumePoint.timeInSeconds;
 
262
  addonRecording.bIsDeleted          = xbmcRecording.IsDeleted();
249
263
  strncpy(addonRecording.strDirectory, xbmcRecording.m_strDirectory.c_str(), sizeof(addonRecording.strDirectory) - 1);
250
264
  strncpy(addonRecording.strStreamURL, xbmcRecording.m_strStreamURL.c_str(), sizeof(addonRecording.strStreamURL) - 1);
251
265
  strncpy(addonRecording.strIconPath, xbmcRecording.m_strIconPath.c_str(), sizeof(addonRecording.strIconPath) - 1);
294
308
 * @param xbmcChannel The channel on XBMC's side.
295
309
 * @param addonChannel The channel on the addon's side.
296
310
 */
297
 
void CPVRClient::WriteClientChannelInfo(const CPVRChannel &xbmcChannel, PVR_CHANNEL &addonChannel)
 
311
void CPVRClient::WriteClientChannelInfo(const CPVRChannelPtr &xbmcChannel, PVR_CHANNEL &addonChannel)
298
312
{
 
313
  assert(xbmcChannel.get());
 
314
 
299
315
  memset(&addonChannel, 0, sizeof(addonChannel));
300
316
 
301
 
  addonChannel.iUniqueId         = xbmcChannel.UniqueID();
302
 
  addonChannel.iChannelNumber    = xbmcChannel.ClientChannelNumber();
303
 
  addonChannel.iSubChannelNumber = xbmcChannel.ClientSubChannelNumber();
304
 
  strncpy(addonChannel.strChannelName, xbmcChannel.ClientChannelName().c_str(), sizeof(addonChannel.strChannelName) - 1);
305
 
  strncpy(addonChannel.strIconPath, xbmcChannel.IconPath().c_str(), sizeof(addonChannel.strIconPath) - 1);
306
 
  addonChannel.iEncryptionSystem = xbmcChannel.EncryptionSystem();
307
 
  addonChannel.bIsRadio          = xbmcChannel.IsRadio();
308
 
  addonChannel.bIsHidden         = xbmcChannel.IsHidden();
309
 
  strncpy(addonChannel.strInputFormat, xbmcChannel.InputFormat().c_str(), sizeof(addonChannel.strInputFormat) - 1);
310
 
  strncpy(addonChannel.strStreamURL, xbmcChannel.StreamURL().c_str(), sizeof(addonChannel.strStreamURL) - 1);
 
317
  addonChannel.iUniqueId         = xbmcChannel->UniqueID();
 
318
  addonChannel.iChannelNumber    = xbmcChannel->ClientChannelNumber();
 
319
  addonChannel.iSubChannelNumber = xbmcChannel->ClientSubChannelNumber();
 
320
  strncpy(addonChannel.strChannelName, xbmcChannel->ClientChannelName().c_str(), sizeof(addonChannel.strChannelName) - 1);
 
321
  strncpy(addonChannel.strIconPath, xbmcChannel->IconPath().c_str(), sizeof(addonChannel.strIconPath) - 1);
 
322
  addonChannel.iEncryptionSystem = xbmcChannel->EncryptionSystem();
 
323
  addonChannel.bIsRadio          = xbmcChannel->IsRadio();
 
324
  addonChannel.bIsHidden         = xbmcChannel->IsHidden();
 
325
  strncpy(addonChannel.strInputFormat, xbmcChannel->InputFormat().c_str(), sizeof(addonChannel.strInputFormat) - 1);
 
326
  strncpy(addonChannel.strStreamURL, xbmcChannel->StreamURL().c_str(), sizeof(addonChannel.strStreamURL) - 1);
311
327
}
312
328
 
313
329
bool CPVRClient::IsCompatibleAPIVersion(const ADDON::AddonVersion &minVersion, const ADDON::AddonVersion &version)
319
335
 
320
336
bool CPVRClient::IsCompatibleGUIAPIVersion(const ADDON::AddonVersion &minVersion, const ADDON::AddonVersion &version)
321
337
{
322
 
  AddonVersion myMinVersion = AddonVersion(XBMC_GUI_MIN_API_VERSION);
323
 
  AddonVersion myVersion = AddonVersion(XBMC_GUI_API_VERSION);
 
338
  AddonVersion myMinVersion = AddonVersion(KODI_GUILIB_MIN_API_VERSION);
 
339
  AddonVersion myVersion = AddonVersion(KODI_GUILIB_API_VERSION);
324
340
  return (version >= myMinVersion && minVersion <= myVersion);
325
341
}
326
342
 
339
355
 
340
356
  /* check the GUI API version */
341
357
  AddonVersion guiVersion = AddonVersion("0.0.0");
342
 
  minVersion = AddonVersion(XBMC_GUI_MIN_API_VERSION);
 
358
  minVersion = AddonVersion(KODI_GUILIB_MIN_API_VERSION);
343
359
  try { guiVersion = AddonVersion(m_pStruct->GetGUIAPIVersion()); }
344
360
  catch (std::exception &e) { LogException(e, "GetGUIAPIVersion()"); return false;  }
345
361
 
354
370
 
355
371
bool CPVRClient::GetAddonProperties(void)
356
372
{
357
 
  std::string strBackendName, strConnectionString, strFriendlyName, strBackendVersion;
 
373
  std::string strBackendName, strConnectionString, strFriendlyName, strBackendVersion, strBackendHostname;
358
374
  PVR_ADDON_CAPABILITIES addonCapabilities;
359
375
 
360
376
  /* get the capabilities */
385
401
  try { strBackendVersion = m_pStruct->GetBackendVersion(); }
386
402
  catch (std::exception &e) { LogException(e, "GetBackendVersion()"); return false;  }
387
403
 
 
404
  /* backend hostname */
 
405
  try { strBackendHostname = m_pStruct->GetBackendHostname(); }
 
406
  catch (std::exception &e) { LogException(e, "GetBackendHostname()"); return false; }
 
407
 
388
408
  /* update the members */
389
409
  m_strBackendName      = strBackendName;
390
410
  m_strConnectionString = strConnectionString;
391
411
  m_strFriendlyName     = strFriendlyName;
392
412
  m_strBackendVersion   = strBackendVersion;
393
413
  m_addonCapabilities   = addonCapabilities;
 
414
  m_strBackendHostname  = strBackendHostname;
394
415
 
395
416
  return true;
396
417
}
411
432
  return m_strBackendVersion;
412
433
}
413
434
 
 
435
const std::string& CPVRClient::GetBackendHostname(void) const
 
436
{
 
437
  return m_strBackendHostname;
 
438
}
 
439
 
414
440
const std::string& CPVRClient::GetConnectionString(void) const
415
441
{
416
442
  return m_strConnectionString;
444
470
  if (!m_addonCapabilities.bSupportsChannelScan)
445
471
    return PVR_ERROR_NOT_IMPLEMENTED;
446
472
 
447
 
  try { return m_pStruct->DialogChannelScan(); }
 
473
  try { return m_pStruct->OpenDialogChannelScan(); }
448
474
  catch (std::exception &e) { LogException(e, __FUNCTION__); }
449
475
 
450
476
  return PVR_ERROR_UNKNOWN;
451
477
}
452
478
 
 
479
PVR_ERROR CPVRClient::OpenDialogChannelAdd(const CPVRChannelPtr &channel)
 
480
{
 
481
  if (!m_bReadyToUse)
 
482
    return PVR_ERROR_REJECTED;
 
483
 
 
484
  if (!m_addonCapabilities.bSupportsChannelSettings)
 
485
    return PVR_ERROR_NOT_IMPLEMENTED;
 
486
 
 
487
  PVR_ERROR retVal(PVR_ERROR_UNKNOWN);
 
488
  try
 
489
  {
 
490
    PVR_CHANNEL addonChannel;
 
491
    WriteClientChannelInfo(channel, addonChannel);
 
492
 
 
493
    retVal = m_pStruct->OpenDialogChannelAdd(addonChannel);
 
494
    LogError(retVal, __FUNCTION__);
 
495
  }
 
496
  catch (std::exception &e)
 
497
  {
 
498
    LogException(e, __FUNCTION__);
 
499
  }
 
500
 
 
501
  return retVal;
 
502
}
 
503
 
 
504
PVR_ERROR CPVRClient::OpenDialogChannelSettings(const CPVRChannelPtr &channel)
 
505
{
 
506
  if (!m_bReadyToUse)
 
507
    return PVR_ERROR_REJECTED;
 
508
 
 
509
  if (!m_addonCapabilities.bSupportsChannelSettings)
 
510
    return PVR_ERROR_NOT_IMPLEMENTED;
 
511
 
 
512
  PVR_ERROR retVal(PVR_ERROR_UNKNOWN);
 
513
  try
 
514
  {
 
515
    PVR_CHANNEL addonChannel;
 
516
    WriteClientChannelInfo(channel, addonChannel);
 
517
 
 
518
    retVal = m_pStruct->OpenDialogChannelSettings(addonChannel);
 
519
    LogError(retVal, __FUNCTION__);
 
520
  }
 
521
  catch (std::exception &e)
 
522
  {
 
523
    LogException(e, __FUNCTION__);
 
524
  }
 
525
 
 
526
  return retVal;
 
527
}
 
528
 
 
529
PVR_ERROR CPVRClient::DeleteChannel(const CPVRChannelPtr &channel)
 
530
{
 
531
  if (!m_bReadyToUse)
 
532
    return PVR_ERROR_REJECTED;
 
533
 
 
534
  if (!m_addonCapabilities.bSupportsChannelSettings)
 
535
    return PVR_ERROR_NOT_IMPLEMENTED;
 
536
 
 
537
  PVR_ERROR retVal(PVR_ERROR_UNKNOWN);
 
538
  try
 
539
  {
 
540
    PVR_CHANNEL addonChannel;
 
541
    WriteClientChannelInfo(channel, addonChannel);
 
542
 
 
543
    retVal = m_pStruct->DeleteChannel(addonChannel);
 
544
    LogError(retVal, __FUNCTION__);
 
545
  }
 
546
  catch (std::exception &e)
 
547
  {
 
548
    LogException(e, __FUNCTION__);
 
549
  }
 
550
 
 
551
  return retVal;
 
552
}
 
553
 
 
554
PVR_ERROR CPVRClient::RenameChannel(const CPVRChannelPtr &channel)
 
555
{
 
556
  if (!m_bReadyToUse)
 
557
    return PVR_ERROR_REJECTED;
 
558
 
 
559
  if (!m_addonCapabilities.bSupportsChannelSettings)
 
560
    return PVR_ERROR_NOT_IMPLEMENTED;
 
561
 
 
562
  PVR_ERROR retVal(PVR_ERROR_UNKNOWN);
 
563
  try
 
564
  {
 
565
    PVR_CHANNEL addonChannel;
 
566
    WriteClientChannelInfo(channel, addonChannel);
 
567
 
 
568
    retVal = m_pStruct->RenameChannel(addonChannel);
 
569
    LogError(retVal, __FUNCTION__);
 
570
  }
 
571
  catch (std::exception &e)
 
572
  {
 
573
    LogException(e, __FUNCTION__);
 
574
  }
 
575
 
 
576
  return retVal;
 
577
}
 
578
 
453
579
void CPVRClient::CallMenuHook(const PVR_MENUHOOK &hook, const CFileItem *item)
454
580
{
455
581
  if (!m_bReadyToUse)
469
595
      else if (item->IsPVRChannel())
470
596
      {
471
597
        hookData.cat = PVR_MENUHOOK_CHANNEL;
472
 
        WriteClientChannelInfo(*item->GetPVRChannelInfoTag(), hookData.data.channel);
 
598
        WriteClientChannelInfo(item->GetPVRChannelInfoTag(), hookData.data.channel);
473
599
      }
474
 
      else if (item->IsPVRRecording())
 
600
      else if (item->IsUsablePVRRecording())
475
601
      {
476
602
        hookData.cat = PVR_MENUHOOK_RECORDING;
477
603
        WriteClientRecordingInfo(*item->GetPVRRecordingInfoTag(), hookData.data.recording);
478
604
      }
 
605
      else if (item->IsDeletedPVRRecording())
 
606
      {
 
607
        hookData.cat = PVR_MENUHOOK_DELETED_RECORDING;
 
608
        WriteClientRecordingInfo(*item->GetPVRRecordingInfoTag(), hookData.data.recording);
 
609
      }
479
610
      else if (item->IsPVRTimer())
480
611
      {
481
612
        hookData.cat = PVR_MENUHOOK_TIMER;
488
619
  catch (std::exception &e) { LogException(e, __FUNCTION__); }
489
620
}
490
621
 
491
 
PVR_ERROR CPVRClient::GetEPGForChannel(const CPVRChannel &channel, CEpg *epg, time_t start /* = 0 */, time_t end /* = 0 */, bool bSaveInDb /* = false*/)
 
622
PVR_ERROR CPVRClient::GetEPGForChannel(const CPVRChannelPtr &channel, CEpg *epg, time_t start /* = 0 */, time_t end /* = 0 */, bool bSaveInDb /* = false*/)
492
623
{
493
624
  if (!m_bReadyToUse)
494
625
    return PVR_ERROR_REJECTED;
635
766
  return retVal;
636
767
}
637
768
 
638
 
int CPVRClient::GetRecordingsAmount(void)
 
769
int CPVRClient::GetRecordingsAmount(bool deleted)
639
770
{
640
771
  int iReturn(-EINVAL);
641
772
 
642
 
  if (m_addonCapabilities.bSupportsRecordings)
643
 
  {
644
 
    try { iReturn = m_pStruct->GetRecordingsAmount(); }
645
 
    catch (std::exception &e) { LogException(e, __FUNCTION__); }
 
773
  if (!m_addonCapabilities.bSupportsRecordings || (deleted && !m_addonCapabilities.bSupportsRecordingsUndelete))
 
774
    return iReturn;
 
775
 
 
776
  try
 
777
  {
 
778
    iReturn = m_pStruct->GetRecordingsAmount(deleted);
 
779
  }
 
780
  catch (std::exception &e)
 
781
  {
 
782
    LogException(e, __FUNCTION__);
646
783
  }
647
784
 
648
785
  return iReturn;
649
786
}
650
787
 
651
 
PVR_ERROR CPVRClient::GetRecordings(CPVRRecordings *results)
 
788
PVR_ERROR CPVRClient::GetRecordings(CPVRRecordings *results, bool deleted)
652
789
{
653
790
  if (!m_bReadyToUse)
654
791
    return PVR_ERROR_REJECTED;
655
792
 
656
 
  if (!m_addonCapabilities.bSupportsRecordings)
 
793
  if (!m_addonCapabilities.bSupportsRecordings || (deleted && !m_addonCapabilities.bSupportsRecordingsUndelete))
657
794
    return PVR_ERROR_NOT_IMPLEMENTED;
658
795
 
659
796
  PVR_ERROR retVal(PVR_ERROR_UNKNOWN);
662
799
    ADDON_HANDLE_STRUCT handle;
663
800
    handle.callerAddress = this;
664
801
    handle.dataAddress = (CPVRRecordings*) results;
665
 
    retVal = m_pStruct->GetRecordings(&handle);
 
802
    retVal = m_pStruct->GetRecordings(&handle, deleted);
666
803
 
667
804
    LogError(retVal, __FUNCTION__);
668
805
  }
700
837
  return retVal;
701
838
}
702
839
 
 
840
PVR_ERROR CPVRClient::UndeleteRecording(const CPVRRecording &recording)
 
841
{
 
842
  if (!m_bReadyToUse)
 
843
    return PVR_ERROR_REJECTED;
 
844
 
 
845
  if (!m_addonCapabilities.bSupportsRecordingsUndelete)
 
846
    return PVR_ERROR_NOT_IMPLEMENTED;
 
847
 
 
848
  PVR_ERROR retVal(PVR_ERROR_UNKNOWN);
 
849
  try
 
850
  {
 
851
    PVR_RECORDING tag;
 
852
    WriteClientRecordingInfo(recording, tag);
 
853
 
 
854
    retVal = m_pStruct->UndeleteRecording(tag);
 
855
 
 
856
    LogError(retVal, __FUNCTION__);
 
857
  }
 
858
  catch (std::exception &e)
 
859
  {
 
860
    LogException(e, __FUNCTION__);
 
861
  }
 
862
 
 
863
  return retVal;
 
864
}
 
865
 
 
866
PVR_ERROR CPVRClient::DeleteAllRecordingsFromTrash()
 
867
{
 
868
  if (!m_bReadyToUse)
 
869
    return PVR_ERROR_REJECTED;
 
870
 
 
871
  if (!m_addonCapabilities.bSupportsRecordingsUndelete)
 
872
    return PVR_ERROR_NOT_IMPLEMENTED;
 
873
 
 
874
  PVR_ERROR retVal(PVR_ERROR_UNKNOWN);
 
875
  try
 
876
  {
 
877
    retVal = m_pStruct->DeleteAllRecordingsFromTrash();
 
878
 
 
879
    LogError(retVal, __FUNCTION__);
 
880
  }
 
881
  catch (std::exception &e)
 
882
  {
 
883
    LogException(e, __FUNCTION__);
 
884
  }
 
885
 
 
886
  return retVal;
 
887
}
 
888
 
703
889
PVR_ERROR CPVRClient::RenameRecording(const CPVRRecording &recording)
704
890
{
705
891
  if (!m_bReadyToUse)
1061
1247
  return -EINVAL;
1062
1248
}
1063
1249
 
1064
 
bool CPVRClient::SwitchChannel(const CPVRChannel &channel)
 
1250
bool CPVRClient::SwitchChannel(const CPVRChannelPtr &channel)
1065
1251
{
1066
1252
  bool bSwitched(false);
1067
1253
 
1078
1264
 
1079
1265
  if (bSwitched)
1080
1266
  {
1081
 
    CPVRChannelPtr currentChannel = g_PVRChannelGroups->GetByUniqueID(channel.UniqueID(), channel.ClientID());
 
1267
    CPVRChannelPtr currentChannel(g_PVRChannelGroups->GetByUniqueID(channel->UniqueID(), channel->ClientID()));
1082
1268
    CSingleLock lock(m_critSection);
1083
 
    ResetQualityData(m_qualityInfo);
1084
1269
    m_playingChannel = currentChannel;
1085
1270
  }
1086
1271
 
1103
1288
  return false;
1104
1289
}
1105
1290
 
1106
 
std::string CPVRClient::GetLiveStreamURL(const CPVRChannel &channel)
 
1291
std::string CPVRClient::GetLiveStreamURL(const CPVRChannelPtr &channel)
1107
1292
{
1108
1293
  std::string strReturn;
1109
1294
 
1238
1423
  CLog::Log(LOGERROR, "PVR - exception '%s' caught while trying to call '%s' on add-on '%s'. Please contact the developer of this add-on: %s", e.what(), strFunctionName, GetFriendlyName().c_str(), Author().c_str());
1239
1424
}
1240
1425
 
1241
 
bool CPVRClient::CanPlayChannel(const CPVRChannel &channel) const
 
1426
bool CPVRClient::CanPlayChannel(const CPVRChannelPtr &channel) const
1242
1427
{
 
1428
  assert(channel.get());
 
1429
 
1243
1430
  return (m_bReadyToUse &&
1244
 
           ((m_addonCapabilities.bSupportsTV && !channel.IsRadio()) ||
1245
 
            (m_addonCapabilities.bSupportsRadio && channel.IsRadio())));
 
1431
           ((m_addonCapabilities.bSupportsTV && !channel->IsRadio()) ||
 
1432
            (m_addonCapabilities.bSupportsRadio && channel->IsRadio())));
1246
1433
}
1247
1434
 
1248
1435
bool CPVRClient::SupportsChannelGroups(void) const
1255
1442
  return m_addonCapabilities.bSupportsChannelScan;
1256
1443
}
1257
1444
 
 
1445
bool CPVRClient::SupportsChannelSettings(void) const
 
1446
{
 
1447
  return m_addonCapabilities.bSupportsChannelSettings;
 
1448
}
 
1449
 
1258
1450
bool CPVRClient::SupportsEPG(void) const
1259
1451
{
1260
1452
  return m_addonCapabilities.bSupportsEPG;
1275
1467
  return m_addonCapabilities.bSupportsRecordings;
1276
1468
}
1277
1469
 
 
1470
bool CPVRClient::SupportsRecordingsUndelete(void) const
 
1471
{
 
1472
  return m_addonCapabilities.bSupportsRecordingsUndelete;
 
1473
}
 
1474
 
1278
1475
bool CPVRClient::SupportsRecordingFolders(void) const
1279
1476
{
1280
1477
  return m_addonCapabilities.bSupportsRecordingFolders;
1346
1543
         IsPlayingRecording();
1347
1544
}
1348
1545
 
1349
 
bool CPVRClient::GetPlayingChannel(CPVRChannelPtr &channel) const
 
1546
CPVRChannelPtr CPVRClient::GetPlayingChannel() const
1350
1547
{
1351
1548
  CSingleLock lock(m_critSection);
1352
1549
  if (m_bReadyToUse && m_bIsPlayingTV)
1353
 
  {
1354
 
    channel = m_playingChannel;
1355
 
    return true;
1356
 
  }
1357
 
  return false;
 
1550
    return m_playingChannel;
 
1551
 
 
1552
  return CPVRChannelPtr();
1358
1553
}
1359
1554
 
1360
 
bool CPVRClient::GetPlayingRecording(CPVRRecording &recording) const
 
1555
CPVRRecordingPtr CPVRClient::GetPlayingRecording(void) const
1361
1556
{
1362
1557
  CSingleLock lock(m_critSection);
1363
1558
  if (m_bReadyToUse && m_bIsPlayingRecording)
1364
 
  {
1365
 
    recording = m_playingRecording;
1366
 
    return true;
1367
 
  }
1368
 
  return false;
 
1559
    return m_playingRecording;
 
1560
 
 
1561
  return CPVRRecordingPtr();
1369
1562
}
1370
1563
 
1371
 
bool CPVRClient::OpenStream(const CPVRChannel &channel, bool bIsSwitchingChannel)
 
1564
bool CPVRClient::OpenStream(const CPVRChannelPtr &channel, bool bIsSwitchingChannel)
1372
1565
{
1373
1566
  bool bReturn(false);
1374
1567
  CloseStream();
1375
1568
 
1376
1569
  if(!CanPlayChannel(channel))
1377
1570
  {
1378
 
    CLog::Log(LOGDEBUG, "add-on '%s' can not play channel '%s'", GetFriendlyName().c_str(), channel.ChannelName().c_str());
 
1571
    CLog::Log(LOGDEBUG, "add-on '%s' can not play channel '%s'", GetFriendlyName().c_str(), channel->ChannelName().c_str());
1379
1572
  }
1380
 
  else if (!channel.StreamURL().empty())
 
1573
  else if (!channel->StreamURL().empty())
1381
1574
  {
1382
 
    CLog::Log(LOGDEBUG, "opening live stream on url '%s'", channel.StreamURL().c_str());
 
1575
    CLog::Log(LOGDEBUG, "opening live stream on url '%s'", channel->StreamURL().c_str());
1383
1576
    bReturn = true;
1384
1577
 
1385
1578
    // the Njoy N7 sometimes doesn't switch channels, but opens a stream to the previous channel
1395
1588
  }
1396
1589
  else
1397
1590
  {
1398
 
    CLog::Log(LOGDEBUG, "opening live stream for channel '%s'", channel.ChannelName().c_str());
 
1591
    CLog::Log(LOGDEBUG, "opening live stream for channel '%s'", channel->ChannelName().c_str());
1399
1592
    PVR_CHANNEL tag;
1400
1593
    WriteClientChannelInfo(channel, tag);
1401
1594
 
1408
1601
 
1409
1602
  if (bReturn)
1410
1603
  {
1411
 
    CPVRChannelPtr currentChannel = g_PVRChannelGroups->GetByUniqueID(channel.UniqueID(), channel.ClientID());
 
1604
    CPVRChannelPtr currentChannel(g_PVRChannelGroups->GetByUniqueID(channel->UniqueID(), channel->ClientID()));
1412
1605
    CSingleLock lock(m_critSection);
1413
1606
    m_playingChannel      = currentChannel;
1414
1607
    m_bIsPlayingTV        = true;
1418
1611
  return bReturn;
1419
1612
}
1420
1613
 
1421
 
bool CPVRClient::OpenStream(const CPVRRecording &recording)
 
1614
bool CPVRClient::OpenStream(const CPVRRecordingPtr &recording)
1422
1615
{
1423
1616
  bool bReturn(false);
1424
1617
  CloseStream();
1426
1619
  if (m_bReadyToUse && m_addonCapabilities.bSupportsRecordings)
1427
1620
  {
1428
1621
    PVR_RECORDING tag;
1429
 
    WriteClientRecordingInfo(recording, tag);
 
1622
    WriteClientRecordingInfo(*recording, tag);
1430
1623
 
1431
1624
    try
1432
1625
    {
1513
1706
  return bReturn;
1514
1707
}
1515
1708
 
1516
 
void CPVRClient::ResetQualityData(PVR_SIGNAL_STATUS &qualityInfo)
1517
 
{
1518
 
  memset(&qualityInfo, 0, sizeof(qualityInfo));
1519
 
  if (CSettings::Get().GetBool("pvrplayback.signalquality"))
1520
 
  {
1521
 
    strncpy(qualityInfo.strAdapterName, g_localizeStrings.Get(13205).c_str(), PVR_ADDON_NAME_STRING_LENGTH - 1);
1522
 
    strncpy(qualityInfo.strAdapterStatus, g_localizeStrings.Get(13205).c_str(), PVR_ADDON_NAME_STRING_LENGTH - 1);
1523
 
  }
1524
 
  else
1525
 
  {
1526
 
    strncpy(qualityInfo.strAdapterName, g_localizeStrings.Get(13106).c_str(), PVR_ADDON_NAME_STRING_LENGTH - 1);
1527
 
    strncpy(qualityInfo.strAdapterStatus, g_localizeStrings.Get(13106).c_str(), PVR_ADDON_NAME_STRING_LENGTH - 1);
1528
 
  }
1529
 
}
1530
 
 
1531
 
void CPVRClient::GetQualityData(PVR_SIGNAL_STATUS *status) const
1532
 
{
1533
 
  CSingleLock lock(m_critSection);
1534
 
  *status = m_qualityInfo;
1535
 
}
1536
 
 
1537
 
int CPVRClient::GetSignalLevel(void) const
1538
 
{
1539
 
  CSingleLock lock(m_critSection);
1540
 
  return (int) ((float) m_qualityInfo.iSignal / 0xFFFF * 100);
1541
 
}
1542
 
 
1543
 
int CPVRClient::GetSNR(void) const
1544
 
{
1545
 
  CSingleLock lock(m_critSection);
1546
 
  return (int) ((float) m_qualityInfo.iSNR / 0xFFFF * 100);
1547
 
}
1548
 
 
1549
 
void CPVRClient::UpdateCharInfoSignalStatus(void)
1550
 
{
1551
 
  PVR_SIGNAL_STATUS qualityInfo;
1552
 
  ResetQualityData(qualityInfo);
1553
 
 
1554
 
  if (CSettings::Get().GetBool("pvrplayback.signalquality"))
1555
 
    SignalQuality(qualityInfo);
1556
 
 
1557
 
  CSingleLock lock(m_critSection);
1558
 
  m_qualityInfo = qualityInfo;
1559
 
}
1560
 
 
1561
1709
time_t CPVRClient::GetPlayingTime(void) const
1562
1710
{
1563
1711
  time_t time = 0;
1604
1752
  }
1605
1753
  return time;
1606
1754
}
 
1755
 
 
1756
bool CPVRClient::CanAutoconfigure(void) const
 
1757
{
 
1758
  /** can only auto-configure when avahi details are provided in addon.xml */
 
1759
  return !m_strAvahiType.empty() &&
 
1760
      !m_strAvahiIpSetting.empty() &&
 
1761
      !m_strAvahiPortSetting.empty();
 
1762
}
 
1763
 
 
1764
bool CPVRClient::AutoconfigureRegisterType(void)
 
1765
{
 
1766
  if (!m_strAvahiType.empty())
 
1767
  {
 
1768
    // AddServiceType() returns false when already registered
 
1769
    m_bAvahiServiceAdded |= CZeroconfBrowser::GetInstance()->AddServiceType(m_strAvahiType);
 
1770
    return true;
 
1771
  }
 
1772
 
 
1773
  return false;
 
1774
}
 
1775
 
 
1776
bool CPVRClient::Autoconfigure(void)
 
1777
{
 
1778
  bool bReturn(false);
 
1779
 
 
1780
  if (!CanAutoconfigure())
 
1781
    return bReturn;
 
1782
 
 
1783
  std::string strHostPort;
 
1784
  std::vector<CZeroconfBrowser::ZeroconfService> found_services = CZeroconfBrowser::GetInstance()->GetFoundServices();
 
1785
  for(std::vector<CZeroconfBrowser::ZeroconfService>::iterator it = found_services.begin(); !bReturn && it != found_services.end(); ++it)
 
1786
  {
 
1787
    /** found the type that we are looking for */
 
1788
    if ((*it).GetType() == m_strAvahiType && std::find(m_rejectedAvahiHosts.begin(), m_rejectedAvahiHosts.end(), *it) == m_rejectedAvahiHosts.end())
 
1789
    {
 
1790
      /** try to resolve */
 
1791
      if(!CZeroconfBrowser::GetInstance()->ResolveService((*it)))
 
1792
      {
 
1793
        CLog::Log(LOGWARNING, "%s - %s service found but the host name couldn't be resolved", __FUNCTION__, (*it).GetName().c_str());
 
1794
      }
 
1795
      else
 
1796
      {
 
1797
        // %s service found at %s
 
1798
        std::string strLogLine(StringUtils::Format(g_localizeStrings.Get(19689).c_str(), (*it).GetName().c_str(), (*it).GetIP().c_str()));
 
1799
        CLog::Log(LOGDEBUG, "%s - %s", __FUNCTION__, strLogLine.c_str());
 
1800
 
 
1801
        if (!CGUIDialogYesNo::ShowAndGetInput(19688, // Scanning for PVR services
 
1802
                                              strLogLine,
 
1803
                                              19690, // Do you want to use this service?
 
1804
                                              ""))
 
1805
        {
 
1806
          CLog::Log(LOGDEBUG, "%s - %s service found but not enabled by the user", __FUNCTION__, (*it).GetName().c_str());
 
1807
          m_rejectedAvahiHosts.push_back(*it);
 
1808
        }
 
1809
        else
 
1810
        {
 
1811
          /** update the settings and return */
 
1812
          std::string strPort(StringUtils::Format("%d", (*it).GetPort()));
 
1813
          UpdateSetting(m_strAvahiIpSetting, (*it).GetIP());
 
1814
          UpdateSetting(m_strAvahiPortSetting, strPort);
 
1815
          SaveSettings();
 
1816
          CLog::Log(LOGNOTICE, "%s - auto-configured %s using host '%s' and port '%d'", __FUNCTION__, (*it).GetName().c_str(), (*it).GetIP().c_str(), (*it).GetPort());
 
1817
 
 
1818
          bReturn = true;
 
1819
        }
 
1820
      }
 
1821
    }
 
1822
  }
 
1823
 
 
1824
  return bReturn;
 
1825
}