int CPVRChannelGroup::GetEPGAll(CFileItemList &results, bool bIncludeChannelsWithoutEPG /* = false */) const { int iInitialSize = results.Size(); CEpgInfoTagPtr epgTag; CPVRChannelPtr channel; CSingleLock lock(m_critSection); for (PVR_CHANNEL_GROUP_SORTED_MEMBERS::const_iterator it = m_sortedMembers.begin(); it != m_sortedMembers.end(); ++it) { channel = (*it).channel; if (!channel->IsHidden()) { int iAdded = 0; CEpgPtr epg = channel->GetEPG(); if (epg) { // XXX channel pointers aren't set in some occasions. this works around the issue, but is not very nice epg->SetChannel(channel); iAdded = epg->Get(results); } if (bIncludeChannelsWithoutEPG && iAdded == 0) { // Add dummy EPG tag associated with this channel epgTag = CEpgInfoTag::CreateDefaultTag(); epgTag->SetPVRChannel(channel); results.Add(CFileItemPtr(new CFileItem(epgTag))); } } } return results.Size() - iInitialSize; }
CDateTime CPVRChannelGroup::GetEPGDate(EpgDateType epgDateType) const { CDateTime date; CEpgPtr epg; CPVRChannelPtr channel; CSingleLock lock(m_critSection); for (PVR_CHANNEL_GROUP_MEMBERS::const_iterator it = m_members.begin(); it != m_members.end(); ++it) { channel = it->second.channel; if (!channel->IsHidden() && (epg = channel->GetEPG())) { CDateTime epgDate; switch (epgDateType) { case EPG_FIRST_DATE: epgDate = epg->GetFirstDate(); if (epgDate.IsValid() && (!date.IsValid() || epgDate < date)) date = epgDate; break; case EPG_LAST_DATE: epgDate = epg->GetLastDate(); if (epgDate.IsValid() && (!date.IsValid() || epgDate > date)) date = epgDate; break; } } } return date; }
void CPVRTimers::UpdateEpgEvent(CPVRTimerInfoTagPtr timer) { CSingleLock lock(timer->m_critSection); /* already got an epg event set */ if (timer->m_epgTag) return; /* try to get the channel */ CPVRChannelPtr channel = g_PVRChannelGroups->GetByUniqueID(timer->m_iClientChannelUid, timer->m_iClientId); if (!channel) return; /* try to get the EPG table */ CEpg *epg = channel->GetEPG(); if (!epg) return; /* try to set the timer on the epg tag that matches with a 2 minute margin */ CEpgInfoTagPtr epgTag = epg->GetTagBetween(timer->StartAsUTC() - CDateTimeSpan(0, 0, 2, 0), timer->EndAsUTC() + CDateTimeSpan(0, 0, 2, 0)); if (!epgTag) epgTag = epg->GetTagAround(timer->StartAsUTC()); if (epgTag) { timer->m_epgTag = epgTag; timer->m_genre = epgTag->Genre(); timer->m_iGenreType = epgTag->GenreType(); timer->m_iGenreSubType = epgTag->GenreSubType(); epgTag->SetTimer(timer); } }
int CPVRChannelGroup::GetEPGNowOrNext(CFileItemList &results, bool bGetNext) const { int iInitialSize = results.Size(); CEpgInfoTagPtr epgNext; CPVRChannelPtr channel; CSingleLock lock(m_critSection); for (PVR_CHANNEL_GROUP_SORTED_MEMBERS::const_iterator it = m_sortedMembers.begin(); it != m_sortedMembers.end(); ++it) { channel = (*it).channel; CEpgPtr epg = channel->GetEPG(); if (epg && !channel->IsHidden()) { epgNext = bGetNext ? epg->GetTagNext() : epg->GetTagNow(); if (epgNext) { CFileItemPtr entry(new CFileItem(epgNext)); entry->SetLabel2(epgNext->StartAsLocalTime().GetAsLocalizedTime("", false)); entry->SetPath(channel->Path()); entry->SetArt("thumb", channel->IconPath()); results.Add(entry); } } } return results.Size() - iInitialSize; }
int CPVRChannelGroup::GetEPGNext(CFileItemList &results) { int iInitialSize = results.Size(); CSingleLock lock(m_critSection); for (unsigned int iChannelPtr = 0; iChannelPtr < m_members.size(); iChannelPtr++) { CPVRChannelPtr channel = m_members.at(iChannelPtr).channel; CEpg *epg = channel->GetEPG(); if (!epg || !epg->HasValidEntries() || m_members.at(iChannelPtr).channel->IsHidden()) continue; CEpgInfoTag epgNow; if (!epg->InfoTagNext(epgNow)) continue; CFileItemPtr entry(new CFileItem(epgNow)); entry->SetLabel2(epgNow.StartAsLocalTime().GetAsLocalizedTime("", false)); entry->SetPath(channel->Path()); entry->SetArt("thumb", channel->IconPath()); results.Add(entry); } return results.Size() - iInitialSize; }
void CGUIWindowPVRChannelsBase::UpdateEpg(const CFileItemPtr &item) { const CPVRChannelPtr channel(item->GetPVRChannelInfoTag()); if (!CGUIDialogYesNo::ShowAndGetInput(CVariant{19251}, // "Update guide information" CVariant{19252}, // "Schedule guide update for this channel?" CVariant{""}, CVariant{channel->ChannelName()})) return; const CPVREpgPtr epg = channel->GetEPG(); if (epg) { epg->ForceUpdate(); const std::string strMessage = StringUtils::Format("%s: '%s'", g_localizeStrings.Get(19253).c_str(), // "Guide update scheduled for channel" channel->ChannelName().c_str()); CGUIDialogKaiToast::QueueNotification(CGUIDialogKaiToast::Info, g_localizeStrings.Get(19166), // "PVR information" strMessage); } else { const std::string strMessage = StringUtils::Format("%s: '%s'", g_localizeStrings.Get(19254).c_str(), // "Guide update failed for channel" channel->ChannelName().c_str()); CGUIDialogKaiToast::QueueNotification(CGUIDialogKaiToast::Error, g_localizeStrings.Get(19166), // "PVR information" strMessage); } }
CEpgInfoTagPtr CEpgContainer::GetTagById(const CPVRChannelPtr &channel, unsigned int iBroadcastId) const { CEpgInfoTagPtr retval; if (iBroadcastId == EPG_TAG_INVALID_UID) return retval; if (channel) { const CEpgPtr epg(channel->GetEPG()); if (epg) retval = epg->GetTagByBroadcastId(iBroadcastId); } else { for (const auto &epgEntry : m_epgs) { retval = epgEntry.second->GetTagByBroadcastId(iBroadcastId); if (retval) break; } } return retval; }
int CPVRManager::GetCurrentEpg(CFileItemList &results) const { int iReturn = -1; CPVRChannelPtr channel; if (m_addons->GetPlayingChannel(channel)) iReturn = channel->GetEPG(results); else CLog::Log(LOGDEBUG,"PVRManager - %s - no current channel set", __FUNCTION__); return iReturn; }
CEpgInfoTagPtr CEpgContainer::GetTagById(const CPVRChannelPtr &channel, unsigned int iBroadcastId) const { CEpgInfoTagPtr retval; if (!channel || iBroadcastId == EPG_TAG_INVALID_UID) return retval; const CEpgPtr epg(channel->GetEPG()); if (epg) retval = epg->GetTagByBroadcastId(iBroadcastId); return retval; }
int CPVRChannelGroup::GetEPGAll(CFileItemList &results) const { int iInitialSize = results.Size(); CEpg* epg; CPVRChannelPtr channel; CSingleLock lock(m_critSection); for (PVR_CHANNEL_GROUP_SORTED_MEMBERS::const_iterator it = m_sortedMembers.begin(); it != m_sortedMembers.end(); ++it) { channel = (*it).channel; if (!channel->IsHidden() && (epg = channel->GetEPG()) != NULL) { // XXX channel pointers aren't set in some occasions. this works around the issue, but is not very nice epg->SetChannel(channel); epg->Get(results); } } return results.Size() - iInitialSize; }
void CAddonCallbacksPVR::UpdateEpgEvent(const EpgEventStateChange &ch, bool bQueued) { const CPVRChannelPtr channel(g_PVRChannelGroups->GetByUniqueID(ch.iUniqueChannelId, ch.iClientId)); if (channel) { const CEpgPtr epg(channel->GetEPG()); if (epg) { if (!epg->UpdateEntry(ch.event, ch.state)) CLog::Log(LOGERROR, "PVR - %s - epg update failed for %sevent change (%d)", __FUNCTION__, bQueued ? "queued " : "", ch.event->UniqueBroadcastID()); } else { CLog::Log(LOGERROR, "PVR - %s - channel '%s' does not have an EPG! Unable to deliver %sevent change (%d)!", __FUNCTION__, channel->ChannelName().c_str(), bQueued ? "queued " : "", ch.event->UniqueBroadcastID()); } } else CLog::Log(LOGERROR, "PVR - %s - invalid channel (%d)! Unable to deliver %sevent change (%d)!", __FUNCTION__, ch.iUniqueChannelId, bQueued ? "queued " : "", ch.event->UniqueBroadcastID()); }
std::vector<std::shared_ptr<CPVREpgInfoTag>> CPVRChannelGroup::GetEPGAll(bool bIncludeChannelsWithoutEPG /* = false */) const { std::vector<std::shared_ptr<CPVREpgInfoTag>> tags; CPVREpgInfoTagPtr epgTag; CPVRChannelPtr channel; CSingleLock lock(m_critSection); for (PVR_CHANNEL_GROUP_SORTED_MEMBERS::const_iterator it = m_sortedMembers.begin(); it != m_sortedMembers.end(); ++it) { channel = (*it).channel; if (!channel->IsHidden()) { bool bEmpty = false; CPVREpgPtr epg = channel->GetEPG(); if (epg) { const std::vector<std::shared_ptr<CPVREpgInfoTag>> epgTags = epg->GetTags(); bEmpty = epgTags.empty(); if (!bEmpty) tags.insert(tags.end(), epgTags.begin(), epgTags.end()); } if (bIncludeChannelsWithoutEPG && bEmpty) { // Add dummy EPG tag associated with this channel if (epg) epgTag = std::make_shared<CPVREpgInfoTag>(epg->GetChannelData(), epg->EpgID()); else epgTag = std::make_shared<CPVREpgInfoTag>(std::make_shared<CPVREpgChannelData>(*channel), -1); tags.emplace_back(epgTag); } } } return tags; }
void CAddonCallbacksPVR::PVRTriggerEpgUpdate(void *addonData, unsigned int iChannelUid) { // get the client CPVRClient *client = GetPVRClient(addonData); if (!client) { CLog::Log(LOGERROR, "PVR - %s - invalid handler data", __FUNCTION__); return; } // get the channel CPVRChannelPtr channel = g_PVRChannelGroups->GetByUniqueID(iChannelUid, client->GetID()); CEpg* epg(NULL); // get the EPG for the channel if (!channel || (epg = channel->GetEPG()) == NULL) { CLog::Log(LOGERROR, "PVR - %s - invalid channel or channel doesn't have an EPG", __FUNCTION__); return; } // force an update epg->ForceUpdate(); }
JSONRPC_STATUS CPVROperations::GetBroadcasts(const std::string &method, ITransportLayer *transport, IClient *client, const CVariant ¶meterObject, CVariant &result) { if (!g_PVRManager.IsStarted()) return FailedToExecute; CPVRChannelGroupsContainer *channelGroupContainer = g_PVRManager.ChannelGroups(); if (channelGroupContainer == NULL) return FailedToExecute; CPVRChannelPtr channel = channelGroupContainer->GetChannelById((int)parameterObject["channelid"].asInteger()); if (channel == NULL) return InvalidParams; CEpg *channelEpg = channel->GetEPG(); if (channelEpg == NULL) return InternalError; CFileItemList programFull; channelEpg->Get(programFull); HandleFileItemList("broadcastid", false, "broadcasts", programFull, parameterObject, result, programFull.Size(), true); return OK; }
void CEpgContainer::Process(void) { time_t iNow(0), iLastSave(0); bool bUpdateEpg(true); bool bHasPendingUpdates(false); while (!m_bStop && !g_application.m_bStop) { CDateTime::GetCurrentDateTime().GetAsUTCDateTime().GetAsTime(iNow); { CSingleLock lock(m_critSection); bUpdateEpg = (iNow >= m_iNextEpgUpdate); } /* update the EPG */ if (!InterruptUpdate() && bUpdateEpg && g_PVRManager.EpgsCreated() && UpdateEPG()) m_bIsInitialising = false; /* clean up old entries */ if (!m_bStop && iNow >= m_iLastEpgCleanup + g_advancedSettings.m_iEpgCleanupInterval) RemoveOldEntries(); /* check for pending manual EPG updates */ while (!m_bStop) { SUpdateRequest request; { CSingleLock lock(m_updateRequestsLock); if (m_updateRequests.empty()) break; request = m_updateRequests.front(); m_updateRequests.pop_front(); } // get the channel CPVRChannelPtr channel = g_PVRChannelGroups->GetByUniqueID(request.channelID, request.clientID); CEpgPtr epg; // get the EPG for the channel if (!channel || !(epg = channel->GetEPG())) { CLog::Log(LOGERROR, "PVR - %s - invalid channel or channel doesn't have an EPG", __FUNCTION__); continue; } // force an update epg->ForceUpdate(); } if (!m_bStop) { { CSingleLock lock(m_critSection); bHasPendingUpdates = (m_pendingUpdates > 0); } if (bHasPendingUpdates) UpdateEPG(true); } /* check for updated active tag */ if (!m_bStop) CheckPlayingEvents(); /* check for changes that need to be saved every 60 seconds */ if (iNow - iLastSave > 60) { PersistAll(); iLastSave = iNow; } Sleep(1000); } }