Debian Codegraph @

xbmc/pvr/channels/PVRChannel.cpp

raw
1 /*
2 * Copyright (C) 2012-2018 Team Kodi
3 * This file is part of Kodi - https://kodi.tv
4 *
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 * See LICENSES/README.md for more information.
7 */
8
9 #include "PVRChannel.h"
10
11 #include "ServiceBroker.h"
12 #include "XBDateTime.h"
13 #include "guilib/LocalizeStrings.h"
14 #include "pvr/PVRDatabase.h"
15 #include "pvr/PVRManager.h"
16 #include "pvr/addons/PVRClient.h"
17 #include "pvr/epg/Epg.h"
18 #include "pvr/epg/EpgChannelData.h"
19 #include "pvr/epg/EpgContainer.h"
20 #include "pvr/epg/EpgInfoTag.h"
21 #include "pvr/providers/PVRProviders.h"
22 #include "utils/StringUtils.h"
23 #include "utils/Variant.h"
24 #include "utils/log.h"
25
26 #include <memory>
27 #include <mutex>
28 #include <string>
29
30 using namespace PVR;
31
32 const std::string CPVRChannel::IMAGE_OWNER_PATTERN = "pvrchannel_{}";
33
34 bool CPVRChannel::operator==(const CPVRChannel& right) const
35 {
36 return (m_bIsRadio == right.m_bIsRadio && m_iUniqueId == right.m_iUniqueId &&
37 m_iClientId == right.m_iClientId);
38 }
39
40 bool CPVRChannel::operator!=(const CPVRChannel& right) const
41 {
42 return !(*this == right);
43 }
44
45 CPVRChannel::CPVRChannel(bool bRadio)
46 : m_bIsRadio(bRadio),
47 m_iconPath("", StringUtils::Format(IMAGE_OWNER_PATTERN, bRadio ? "radio" : "tv"))
48 {
49 UpdateEncryptionName();
50 }
51
52 CPVRChannel::CPVRChannel(bool bRadio, const std::string& iconPath)
53 : m_bIsRadio(bRadio),
54 m_iconPath(iconPath, StringUtils::Format(IMAGE_OWNER_PATTERN, bRadio ? "radio" : "tv"))
55 {
56 UpdateEncryptionName();
57 }
58
59 CPVRChannel::CPVRChannel(const PVR_CHANNEL& channel, unsigned int iClientId)
60 : m_bIsRadio(channel.bIsRadio),
61 m_bIsHidden(channel.bIsHidden),
62 m_iconPath(channel.strIconPath,
63 StringUtils::Format(IMAGE_OWNER_PATTERN, channel.bIsRadio ? "radio" : "tv")),
64 m_strChannelName(channel.strChannelName),
65 m_bHasArchive(channel.bHasArchive),
66 m_bEPGEnabled(!channel.bIsHidden),
67 m_iUniqueId(channel.iUniqueId),
68 m_iClientId(iClientId),
69 m_clientChannelNumber(channel.iChannelNumber, channel.iSubChannelNumber),
70 m_strClientChannelName(channel.strChannelName),
71 m_strMimeType(channel.strMimeType),
72 m_iClientEncryptionSystem(channel.iEncryptionSystem),
73 m_iClientOrder(channel.iOrder),
74 m_iClientProviderUid(channel.iClientProviderUid)
75 {
76 if (m_strChannelName.empty())
77 m_strChannelName = StringUtils::Format("{} {}", g_localizeStrings.Get(19029), m_iUniqueId);
78
79 UpdateEncryptionName();
80 }
81
82 CPVRChannel::~CPVRChannel()
83 {
84 ResetEPG();
85 }
86
87 void CPVRChannel::FillAddonData(PVR_CHANNEL& channel) const
88 {
89 channel = {};
90 channel.iUniqueId = UniqueID();
91 channel.iChannelNumber = ClientChannelNumber().GetChannelNumber();
92 channel.iSubChannelNumber = ClientChannelNumber().GetSubChannelNumber();
93 strncpy(channel.strChannelName, ClientChannelName().c_str(), sizeof(channel.strChannelName) - 1);
94 strncpy(channel.strIconPath, ClientIconPath().c_str(), sizeof(channel.strIconPath) - 1);
95 channel.iEncryptionSystem = EncryptionSystem();
96 channel.bIsRadio = IsRadio();
97 channel.bIsHidden = IsHidden();
98 strncpy(channel.strMimeType, MimeType().c_str(), sizeof(channel.strMimeType) - 1);
99 channel.iClientProviderUid = ClientProviderUid();
100 channel.bHasArchive = HasArchive();
101 }
102
103 void CPVRChannel::Serialize(CVariant& value) const
104 {
105 value["channelid"] = m_iChannelId;
106 value["channeltype"] = m_bIsRadio ? "radio" : "tv";
107 value["hidden"] = m_bIsHidden;
108 value["locked"] = m_bIsLocked;
109 value["icon"] = ClientIconPath();
110 value["channel"] = m_strChannelName;
111 value["uniqueid"] = m_iUniqueId;
112 CDateTime lastPlayed(m_iLastWatched);
113 value["lastplayed"] = lastPlayed.IsValid() ? lastPlayed.GetAsDBDate() : "";
114
115 std::shared_ptr<CPVREpgInfoTag> epg = GetEPGNow();
116 if (epg)
117 {
118 // add the properties of the current EPG item to the main object
119 epg->Serialize(value);
120 // and add an extra sub-object with only the current EPG details
121 epg->Serialize(value["broadcastnow"]);
122 }
123
124 epg = GetEPGNext();
125 if (epg)
126 epg->Serialize(value["broadcastnext"]);
127
128 value["hasarchive"] = m_bHasArchive;
129 value["clientid"] = m_iClientId;
130 }
131
132 bool CPVRChannel::QueueDelete()
133 {
134 bool bReturn = false;
135 const std::shared_ptr<CPVRDatabase> database = CServiceBroker::GetPVRManager().GetTVDatabase();
136 if (!database)
137 return bReturn;
138
139 const std::shared_ptr<const CPVREpg> epg = GetEPG();
140 if (epg)
141 ResetEPG();
142
143 bReturn = database->QueueDeleteQuery(*this);
144 return bReturn;
145 }
146
147 std::shared_ptr<CPVREpg> CPVRChannel::GetEPG() const
148 {
149 const_cast<CPVRChannel*>(this)->CreateEPG();
150
151 std::unique_lock<CCriticalSection> lock(m_critSection);
152 if (!m_bIsHidden && m_bEPGEnabled)
153 return m_epg;
154
155 return {};
156 }
157
158 bool CPVRChannel::CreateEPG()
159 {
160 std::unique_lock<CCriticalSection> lock(m_critSection);
161 if (!m_epg)
162 {
163 m_epg = CServiceBroker::GetPVRManager().EpgContainer().CreateChannelEpg(
164 m_iEpgId, m_strEPGScraper, std::make_shared<CPVREpgChannelData>(*this));
165 if (m_epg)
166 {
167 CLog::LogFC(LOGDEBUG, LOGPVR, "Created EPG for {} channel '{}'", IsRadio() ? "radio" : "TV",
168 m_strChannelName);
169
170 if (m_epg->EpgID() != m_iEpgId)
171 {
172 m_iEpgId = m_epg->EpgID();
173 m_bChanged = true;
174 }
175
176 // Subscribe for EPG delete event
177 m_epg->Events().Subscribe(this, &CPVRChannel::Notify);
178 return true;
179 }
180 }
181 return false;
182 }
183
184 void CPVRChannel::Notify(const PVREvent& event)
185 {
186 if (event == PVREvent::EpgDeleted)
187 {
188 ResetEPG();
189 }
190 }
191
192 void CPVRChannel::ResetEPG()
193 {
194 std::shared_ptr<CPVREpg> epgToUnsubscribe;
195 {
196 std::unique_lock<CCriticalSection> lock(m_critSection);
197 if (m_epg)
198 {
199 epgToUnsubscribe = m_epg;
200 m_epg.reset();
201 }
202 }
203
204 if (epgToUnsubscribe)
205 epgToUnsubscribe->Events().Unsubscribe(this);
206 }
207
208 bool CPVRChannel::UpdateFromClient(const std::shared_ptr<const CPVRChannel>& channel)
209 {
210 std::unique_lock<CCriticalSection> lock(m_critSection);
211
212 SetClientID(channel->ClientID());
213 SetArchive(channel->HasArchive());
214 SetClientProviderUid(channel->ClientProviderUid());
215
216 m_clientChannelNumber = channel->m_clientChannelNumber;
217 m_strMimeType = channel->MimeType();
218 m_iClientEncryptionSystem = channel->EncryptionSystem();
219 m_strClientChannelName = channel->ClientChannelName();
220
221 UpdateEncryptionName();
222
223 // only update the channel name, icon, and hidden flag if the user hasn't changed them manually
224 if (m_strChannelName.empty() || !IsUserSetName())
225 SetChannelName(channel->ClientChannelName());
226 if (IconPath().empty() || !IsUserSetIcon())
227 SetIconPath(channel->ClientIconPath());
228 if (!IsUserSetHidden())
229 SetHidden(channel->IsHidden());
230
231 return m_bChanged;
232 }
233
234 bool CPVRChannel::Persist()
235 {
236 {
237 // not changed
238 std::unique_lock<CCriticalSection> lock(m_critSection);
239 if (!m_bChanged && m_iChannelId > 0)
240 return true;
241 }
242
243 const std::shared_ptr<CPVRDatabase> database = CServiceBroker::GetPVRManager().GetTVDatabase();
244 if (database)
245 {
246 CLog::LogFC(LOGDEBUG, LOGPVR, "Persisting channel '{}'", m_strChannelName);
247
248 bool bReturn = database->Persist(*this, true);
249
250 std::unique_lock<CCriticalSection> lock(m_critSection);
251 m_bChanged = !bReturn;
252 return bReturn;
253 }
254
255 return false;
256 }
257
258 bool CPVRChannel::SetChannelID(int iChannelId)
259 {
260 std::unique_lock<CCriticalSection> lock(m_critSection);
261 if (m_iChannelId != iChannelId)
262 {
263 m_iChannelId = iChannelId;
264
265 const std::shared_ptr<const CPVREpg> epg = GetEPG();
266 if (epg)
267 epg->GetChannelData()->SetChannelId(m_iChannelId);
268
269 m_bChanged = true;
270 return true;
271 }
272
273 return false;
274 }
275
276 bool CPVRChannel::SetHidden(bool bIsHidden, bool bIsUserSetHidden /*= false*/)
277 {
278 std::unique_lock<CCriticalSection> lock(m_critSection);
279
280 if (m_bIsHidden != bIsHidden || m_bIsUserSetHidden != bIsUserSetHidden)
281 {
282 m_bIsHidden = bIsHidden;
283 m_bIsUserSetHidden = bIsUserSetHidden;
284
285 if (m_epg)
286 m_epg->GetChannelData()->SetHidden(m_bIsHidden);
287
288 m_bChanged = true;
289 return true;
290 }
291
292 return false;
293 }
294
295 bool CPVRChannel::SetLocked(bool bIsLocked)
296 {
297 std::unique_lock<CCriticalSection> lock(m_critSection);
298
299 if (m_bIsLocked != bIsLocked)
300 {
301 m_bIsLocked = bIsLocked;
302
303 const std::shared_ptr<const CPVREpg> epg = GetEPG();
304 if (epg)
305 epg->GetChannelData()->SetLocked(m_bIsLocked);
306
307 m_bChanged = true;
308 return true;
309 }
310
311 return false;
312 }
313
314 std::shared_ptr<CPVRRadioRDSInfoTag> CPVRChannel::GetRadioRDSInfoTag() const
315 {
316 std::unique_lock<CCriticalSection> lock(m_critSection);
317 return m_rdsTag;
318 }
319
320 void CPVRChannel::SetRadioRDSInfoTag(const std::shared_ptr<CPVRRadioRDSInfoTag>& tag)
321 {
322 std::unique_lock<CCriticalSection> lock(m_critSection);
323 m_rdsTag = tag;
324 }
325
326 bool CPVRChannel::HasArchive() const
327 {
328 std::unique_lock<CCriticalSection> lock(m_critSection);
329 return m_bHasArchive;
330 }
331
332 bool CPVRChannel::SetArchive(bool bHasArchive)
333 {
334 std::unique_lock<CCriticalSection> lock(m_critSection);
335
336 if (m_bHasArchive != bHasArchive)
337 {
338 m_bHasArchive = bHasArchive;
339 m_bChanged = true;
340 return true;
341 }
342
343 return false;
344 }
345
346 bool CPVRChannel::SetIconPath(const std::string& strIconPath, bool bIsUserSetIcon /* = false */)
347 {
348 if (StringUtils::StartsWith(strIconPath, "image://"))
349 {
350 CLog::LogF(LOGERROR, "Not allowed to call this method with an image URL");
351 return false;
352 }
353
354 std::unique_lock<CCriticalSection> lock(m_critSection);
355 if (ClientIconPath() == strIconPath)
356 return false;
357
358 m_iconPath.SetClientImage(strIconPath);
359
360 const std::shared_ptr<const CPVREpg> epg = GetEPG();
361 if (epg)
362 epg->GetChannelData()->SetChannelIconPath(strIconPath);
363
364 m_bChanged = true;
365 m_bIsUserSetIcon = bIsUserSetIcon && !IconPath().empty();
366 return true;
367 }
368
369 bool CPVRChannel::SetChannelName(const std::string& strChannelName, bool bIsUserSetName /*= false*/)
370 {
371 std::string strName(strChannelName);
372
373 if (strName.empty())
374 strName = StringUtils::Format(g_localizeStrings.Get(19085),
375 m_clientChannelNumber.FormattedChannelNumber());
376
377 std::unique_lock<CCriticalSection> lock(m_critSection);
378 if (m_strChannelName != strName || m_bIsUserSetName != bIsUserSetName)
379 {
380 m_strChannelName = strName;
381 m_bIsUserSetName = bIsUserSetName;
382
383 const std::shared_ptr<const CPVREpg> epg = GetEPG();
384 if (epg)
385 epg->GetChannelData()->SetChannelName(m_strChannelName);
386
387 m_bChanged = true;
388 return true;
389 }
390
391 return false;
392 }
393
394 bool CPVRChannel::SetLastWatched(time_t lastWatched, int groupId)
395 {
396 {
397 std::unique_lock<CCriticalSection> lock(m_critSection);
398 m_iLastWatched = lastWatched;
399 m_lastWatchedGroupId = groupId;
400 }
401
402 const std::shared_ptr<CPVRDatabase> database = CServiceBroker::GetPVRManager().GetTVDatabase();
403 if (database)
404 return database->UpdateLastWatched(*this, groupId);
405
406 return false;
407 }
408
409 /********** Client related channel methods **********/
410
411 bool CPVRChannel::SetClientID(int iClientId)
412 {
413 std::unique_lock<CCriticalSection> lock(m_critSection);
414
415 if (m_iClientId != iClientId)
416 {
417 m_iClientId = iClientId;
418 m_bChanged = true;
419 return true;
420 }
421
422 return false;
423 }
424
425 std::string CPVRChannel::GetEncryptionName(int iCaid)
426 {
427 // http://www.dvb.org/index.php?id=174
428 // http://en.wikipedia.org/wiki/Conditional_access_system
429 std::string strName(g_localizeStrings.Get(13205)); /* Unknown */
430
431 if (iCaid == 0x0000)
432 strName = g_localizeStrings.Get(19013); /* Free To Air */
433 else if (iCaid >= 0x0001 && iCaid <= 0x009F)
434 strName = g_localizeStrings.Get(19014); /* Fixed */
435 else if (iCaid >= 0x00A0 && iCaid <= 0x00A1)
436 strName = g_localizeStrings.Get(338); /* Analog */
437 else if (iCaid >= 0x00A2 && iCaid <= 0x00FF)
438 strName = g_localizeStrings.Get(19014); /* Fixed */
439 else if (iCaid >= 0x0100 && iCaid <= 0x01FF)
440 strName = "SECA Mediaguard";
441 else if (iCaid == 0x0464)
442 strName = "EuroDec";
443 else if (iCaid >= 0x0500 && iCaid <= 0x05FF)
444 strName = "Viaccess";
445 else if (iCaid >= 0x0600 && iCaid <= 0x06FF)
446 strName = "Irdeto";
447 else if (iCaid >= 0x0900 && iCaid <= 0x09FF)
448 strName = "NDS Videoguard";
449 else if (iCaid >= 0x0B00 && iCaid <= 0x0BFF)
450 strName = "Conax";
451 else if (iCaid >= 0x0D00 && iCaid <= 0x0DFF)
452 strName = "CryptoWorks";
453 else if (iCaid >= 0x0E00 && iCaid <= 0x0EFF)
454 strName = "PowerVu";
455 else if (iCaid == 0x1000)
456 strName = "RAS";
457 else if (iCaid >= 0x1200 && iCaid <= 0x12FF)
458 strName = "NagraVision";
459 else if (iCaid >= 0x1700 && iCaid <= 0x17FF)
460 strName = "BetaCrypt";
461 else if (iCaid >= 0x1800 && iCaid <= 0x18FF)
462 strName = "NagraVision";
463 else if (iCaid == 0x22F0)
464 strName = "Codicrypt";
465 else if (iCaid == 0x2600)
466 strName = "BISS";
467 else if (iCaid == 0x4347)
468 strName = "CryptOn";
469 else if (iCaid == 0x4800)
470 strName = "Accessgate";
471 else if (iCaid == 0x4900)
472 strName = "China Crypt";
473 else if (iCaid == 0x4A10)
474 strName = "EasyCas";
475 else if (iCaid == 0x4A20)
476 strName = "AlphaCrypt";
477 else if (iCaid == 0x4A70)
478 strName = "DreamCrypt";
479 else if (iCaid == 0x4A60)
480 strName = "SkyCrypt";
481 else if (iCaid == 0x4A61)
482 strName = "Neotioncrypt";
483 else if (iCaid == 0x4A62)
484 strName = "SkyCrypt";
485 else if (iCaid == 0x4A63)
486 strName = "Neotion SHL";
487 else if (iCaid >= 0x4A64 && iCaid <= 0x4A6F)
488 strName = "SkyCrypt";
489 else if (iCaid == 0x4A80)
490 strName = "ThalesCrypt";
491 else if (iCaid == 0x4AA1)
492 strName = "KeyFly";
493 else if (iCaid == 0x4ABF)
494 strName = "DG-Crypt";
495 else if (iCaid >= 0x4AD0 && iCaid <= 0x4AD1)
496 strName = "X-Crypt";
497 else if (iCaid == 0x4AD4)
498 strName = "OmniCrypt";
499 else if (iCaid == 0x4AE0)
500 strName = "RossCrypt";
501 else if (iCaid == 0x5500)
502 strName = "Z-Crypt";
503 else if (iCaid == 0x5501)
504 strName = "Griffin";
505 else if (iCaid == 0x5601)
506 strName = "Verimatrix";
507
508 if (iCaid >= 0)
509 strName += StringUtils::Format(" ({:04X})", iCaid);
510
511 return strName;
512 }
513
514 void CPVRChannel::UpdateEncryptionName()
515 {
516 std::unique_lock<CCriticalSection> lock(m_critSection);
517 m_strClientEncryptionName = GetEncryptionName(m_iClientEncryptionSystem);
518 }
519
520 bool CPVRChannel::SetClientProviderUid(int iClientProviderUid)
521 {
522 std::unique_lock<CCriticalSection> lock(m_critSection);
523
524 if (m_iClientProviderUid != iClientProviderUid)
525 {
526 m_iClientProviderUid = iClientProviderUid;
527 m_bChanged = true;
528 return true;
529 }
530
531 return false;
532 }
533
534 /********** EPG methods **********/
535
536 std::vector<std::shared_ptr<CPVREpgInfoTag>> CPVRChannel::GetEpgTags() const
537 {
538 const std::shared_ptr<const CPVREpg> epg = GetEPG();
539 if (!epg)
540 {
541 CLog::LogFC(LOGDEBUG, LOGPVR, "Cannot get EPG for channel '{}'", m_strChannelName);
542 return {};
543 }
544
545 return epg->GetTags();
546 }
547
548 std::vector<std::shared_ptr<CPVREpgInfoTag>> CPVRChannel::GetEPGTimeline(
549 const CDateTime& timelineStart,
550 const CDateTime& timelineEnd,
551 const CDateTime& minEventEnd,
552 const CDateTime& maxEventStart) const
553 {
554 const std::shared_ptr<const CPVREpg> epg = GetEPG();
555 if (epg)
556 {
557 return epg->GetTimeline(timelineStart, timelineEnd, minEventEnd, maxEventStart);
558 }
559 else
560 {
561 // return single gap tag spanning whole timeline
562 return std::vector<std::shared_ptr<CPVREpgInfoTag>>{
563 CreateEPGGapTag(timelineStart, timelineEnd)};
564 }
565 }
566
567 std::shared_ptr<CPVREpgInfoTag> CPVRChannel::CreateEPGGapTag(const CDateTime& start,
568 const CDateTime& end) const
569 {
570 const std::shared_ptr<const CPVREpg> epg = GetEPG();
571 if (epg)
572 return std::make_shared<CPVREpgInfoTag>(epg->GetChannelData(), epg->EpgID(), start, end, true);
573 else
574 return std::make_shared<CPVREpgInfoTag>(std::make_shared<CPVREpgChannelData>(*this), -1, start,
575 end, true);
576 }
577
578 std::shared_ptr<CPVREpgInfoTag> CPVRChannel::GetEPGNow() const
579 {
580 std::shared_ptr<CPVREpgInfoTag> tag;
581 const std::shared_ptr<const CPVREpg> epg = GetEPG();
582 if (epg)
583 tag = epg->GetTagNow();
584
585 return tag;
586 }
587
588 std::shared_ptr<CPVREpgInfoTag> CPVRChannel::GetEPGNext() const
589 {
590 std::shared_ptr<CPVREpgInfoTag> tag;
591 const std::shared_ptr<const CPVREpg> epg = GetEPG();
592 if (epg)
593 tag = epg->GetTagNext();
594
595 return tag;
596 }
597
598 std::shared_ptr<CPVREpgInfoTag> CPVRChannel::GetEPGPrevious() const
599 {
600 std::shared_ptr<CPVREpgInfoTag> tag;
601 const std::shared_ptr<const CPVREpg> epg = GetEPG();
602 if (epg)
603 tag = epg->GetTagPrevious();
604
605 return tag;
606 }
607
608 bool CPVRChannel::SetEPGEnabled(bool bEPGEnabled)
609 {
610 std::unique_lock<CCriticalSection> lock(m_critSection);
611
612 if (m_bEPGEnabled != bEPGEnabled)
613 {
614 m_bEPGEnabled = bEPGEnabled;
615
616 if (m_epg)
617 {
618 m_epg->GetChannelData()->SetEPGEnabled(m_bEPGEnabled);
619
620 if (m_bEPGEnabled)
621 m_epg->ForceUpdate();
622 else
623 m_epg->Clear();
624 }
625
626 m_bChanged = true;
627 return true;
628 }
629
630 return false;
631 }
632
633 bool CPVRChannel::SetEPGScraper(const std::string& strScraper)
634 {
635 std::unique_lock<CCriticalSection> lock(m_critSection);
636
637 if (m_strEPGScraper != strScraper)
638 {
639 bool bCleanEPG = !m_strEPGScraper.empty() || strScraper.empty();
640
641 m_strEPGScraper = strScraper;
642
643 if (bCleanEPG && m_epg)
644 m_epg->Clear();
645
646 m_bChanged = true;
647 return true;
648 }
649
650 return false;
651 }
652
653 void CPVRChannel::ToSortable(SortItem& sortable, Field field) const
654 {
655 std::unique_lock<CCriticalSection> lock(m_critSection);
656 if (field == FieldChannelName)
657 sortable[FieldChannelName] = m_strChannelName;
658 else if (field == FieldLastPlayed)
659 {
660 const CDateTime lastWatched(m_iLastWatched);
661 sortable[FieldLastPlayed] =
662 lastWatched.IsValid() ? lastWatched.GetAsDBDateTime() : StringUtils::Empty;
663 }
664 else if (field == FieldProvider)
665 sortable[FieldProvider] = StringUtils::Format("{} {}", m_iClientId, m_iClientProviderUid);
666 }
667
668 int CPVRChannel::ChannelID() const
669 {
670 std::unique_lock<CCriticalSection> lock(m_critSection);
671 return m_iChannelId;
672 }
673
674 bool CPVRChannel::IsNew() const
675 {
676 std::unique_lock<CCriticalSection> lock(m_critSection);
677 return m_iChannelId <= 0;
678 }
679
680 bool CPVRChannel::IsHidden() const
681 {
682 std::unique_lock<CCriticalSection> lock(m_critSection);
683 return m_bIsHidden;
684 }
685
686 bool CPVRChannel::IsLocked() const
687 {
688 std::unique_lock<CCriticalSection> lock(m_critSection);
689 return m_bIsLocked;
690 }
691
692 std::string CPVRChannel::ClientIconPath() const
693 {
694 std::unique_lock<CCriticalSection> lock(m_critSection);
695 return m_iconPath.GetClientImage();
696 }
697
698 std::string CPVRChannel::IconPath() const
699 {
700 std::unique_lock<CCriticalSection> lock(m_critSection);
701 return m_iconPath.GetLocalImage();
702 }
703
704 bool CPVRChannel::IsUserSetIcon() const
705 {
706 std::unique_lock<CCriticalSection> lock(m_critSection);
707 return m_bIsUserSetIcon;
708 }
709
710 bool CPVRChannel::IsUserSetName() const
711 {
712 std::unique_lock<CCriticalSection> lock(m_critSection);
713 return m_bIsUserSetName;
714 }
715
716 bool CPVRChannel::IsUserSetHidden() const
717 {
718 std::unique_lock<CCriticalSection> lock(m_critSection);
719 return m_bIsUserSetHidden;
720 }
721
722 int CPVRChannel::LastWatchedGroupId() const
723 {
724 std::unique_lock<CCriticalSection> lock(m_critSection);
725 return m_lastWatchedGroupId;
726 }
727
728 std::string CPVRChannel::ChannelName() const
729 {
730 std::unique_lock<CCriticalSection> lock(m_critSection);
731 return m_strChannelName;
732 }
733
734 time_t CPVRChannel::LastWatched() const
735 {
736 std::unique_lock<CCriticalSection> lock(m_critSection);
737 return m_iLastWatched;
738 }
739
740 bool CPVRChannel::IsChanged() const
741 {
742 std::unique_lock<CCriticalSection> lock(m_critSection);
743 return m_bChanged;
744 }
745
746 void CPVRChannel::Persisted()
747 {
748 std::unique_lock<CCriticalSection> lock(m_critSection);
749 m_bChanged = false;
750 }
751
752 int CPVRChannel::UniqueID() const
753 {
754 return m_iUniqueId;
755 }
756
757 int CPVRChannel::ClientID() const
758 {
759 std::unique_lock<CCriticalSection> lock(m_critSection);
760 return m_iClientId;
761 }
762
763 const CPVRChannelNumber& CPVRChannel::ClientChannelNumber() const
764 {
765 std::unique_lock<CCriticalSection> lock(m_critSection);
766 return m_clientChannelNumber;
767 }
768
769 std::string CPVRChannel::ClientChannelName() const
770 {
771 std::unique_lock<CCriticalSection> lock(m_critSection);
772 return m_strClientChannelName;
773 }
774
775 std::string CPVRChannel::MimeType() const
776 {
777 std::unique_lock<CCriticalSection> lock(m_critSection);
778 return m_strMimeType;
779 }
780
781 bool CPVRChannel::IsEncrypted() const
782 {
783 std::unique_lock<CCriticalSection> lock(m_critSection);
784 return m_iClientEncryptionSystem > 0;
785 }
786
787 int CPVRChannel::EncryptionSystem() const
788 {
789 std::unique_lock<CCriticalSection> lock(m_critSection);
790 return m_iClientEncryptionSystem;
791 }
792
793 std::string CPVRChannel::EncryptionName() const
794 {
795 std::unique_lock<CCriticalSection> lock(m_critSection);
796 return m_strClientEncryptionName;
797 }
798
799 int CPVRChannel::EpgID() const
800 {
801 std::unique_lock<CCriticalSection> lock(m_critSection);
802 return m_iEpgId;
803 }
804
805 bool CPVRChannel::EPGEnabled() const
806 {
807 std::unique_lock<CCriticalSection> lock(m_critSection);
808 return m_bEPGEnabled;
809 }
810
811 std::string CPVRChannel::EPGScraper() const
812 {
813 std::unique_lock<CCriticalSection> lock(m_critSection);
814 return m_strEPGScraper;
815 }
816
817 bool CPVRChannel::CanRecord() const
818 {
819 const std::shared_ptr<const CPVRClient> client =
820 CServiceBroker::GetPVRManager().GetClient(m_iClientId);
821 return client && client->GetClientCapabilities().SupportsRecordings() &&
822 client->GetClientCapabilities().SupportsTimers();
823 }
824
825 std::shared_ptr<CPVRProvider> CPVRChannel::GetDefaultProvider() const
826 {
827 return CServiceBroker::GetPVRManager().Providers()->GetByClient(m_iClientId,
828 PVR_PROVIDER_INVALID_UID);
829 }
830
831 bool CPVRChannel::HasClientProvider() const
832 {
833 std::unique_lock<CCriticalSection> lock(m_critSection);
834 return m_iClientProviderUid != PVR_PROVIDER_INVALID_UID;
835 }
836
837 std::shared_ptr<CPVRProvider> CPVRChannel::GetProvider() const
838 {
839 auto provider =
840 CServiceBroker::GetPVRManager().Providers()->GetByClient(m_iClientId, m_iClientProviderUid);
841
842 if (!provider)
843 provider = GetDefaultProvider();
844
845 return provider;
846 }