Skip to content

Commit

Permalink
Merge pull request #15707 from ksooo/pvr-component-deps
Browse files Browse the repository at this point in the history
[PVR] Rework PVR component inter-dependencies
  • Loading branch information
ksooo committed Mar 14, 2019
2 parents e6de2d8 + ec1ecb1 commit d68bd9b
Show file tree
Hide file tree
Showing 64 changed files with 1,703 additions and 1,703 deletions.
186 changes: 93 additions & 93 deletions addons/resource.language.en_gb/resources/strings.po

Large diffs are not rendered by default.

36 changes: 30 additions & 6 deletions xbmc/FileItem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
#include "CueDocument.h"
#include "video/VideoDatabase.h"
#include "music/MusicDatabase.h"
#include "pvr/PVRManager.h"
#include "pvr/channels/PVRChannelGroupsContainer.h"
#include "pvr/channels/PVRChannel.h"
#include "pvr/epg/Epg.h"
#include "pvr/recordings/PVRRecording.h"
Expand Down Expand Up @@ -112,6 +114,20 @@ CFileItem::CFileItem(const CVideoInfoTag& movie)
SetFromVideoInfoTag(movie);
}

namespace
{
std::string GetEpgTagTitle(const std::shared_ptr<CPVREpgInfoTag>& epgTag)
{
if (CServiceBroker::GetPVRManager().IsParentalLocked(epgTag))
return g_localizeStrings.Get(19266); // Parental locked
else if (epgTag->Title().empty() &&
!CServiceBroker::GetSettingsComponent()->GetSettings()->GetBool(CSettings::SETTING_EPG_HIDENOINFOAVAILABLE))
return g_localizeStrings.Get(19055); // no information available
else
return epgTag->Title();
}
} // unnamed namespace

void CFileItem::FillMusicInfoTag(const CPVRChannelPtr& channel, const CPVREpgInfoTagPtr& tag)
{
if (channel && channel->IsRadio() && !HasMusicInfoTag())
Expand All @@ -120,7 +136,7 @@ void CFileItem::FillMusicInfoTag(const CPVRChannelPtr& channel, const CPVREpgInf

if (tag)
{
musictag->SetTitle(tag->Title());
musictag->SetTitle(GetEpgTagTitle(tag));
musictag->SetGenre(tag->Genre());
musictag->SetDuration(tag->GetDuration());
}
Expand All @@ -144,15 +160,23 @@ CFileItem::CFileItem(const CPVREpgInfoTagPtr& tag)
m_bIsFolder = false;
m_epgInfoTag = tag;
m_strPath = tag->Path();
SetLabel(tag->Title());
SetLabel(GetEpgTagTitle(tag));
m_dateTime = tag->StartAsLocalTime();

if (!tag->Icon().empty())
SetIconImage(tag->Icon());
else if (tag->HasChannel() && !tag->Channel()->IconPath().empty())
SetIconImage(tag->Channel()->IconPath());
else
{
const std::shared_ptr<CPVRChannel> channel = CServiceBroker::GetPVRManager().ChannelGroups()->GetChannelForEpgTag(tag);
if (channel)
{
if (!channel->IconPath().empty())
SetIconImage(channel->IconPath());

FillMusicInfoTag(channel, tag);
}
}

FillMusicInfoTag(tag->Channel(), tag);
FillInMimeType(false);
}

Expand Down Expand Up @@ -3597,7 +3621,7 @@ CFileItem CFileItem::GetItemToPlay() const
{
if (HasEPGInfoTag())
{
const CPVRChannelPtr channel(GetEPGInfoTag()->Channel());
const std::shared_ptr<CPVRChannel> channel = CServiceBroker::GetPVRManager().ChannelGroups()->GetChannelForEpgTag(GetEPGInfoTag());
if (channel)
return CFileItem(channel);
}
Expand Down
40 changes: 28 additions & 12 deletions xbmc/addons/PVRClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ extern "C" {
#include "pvr/channels/PVRChannelGroupInternal.h"
#include "pvr/channels/PVRChannelGroupsContainer.h"
#include "pvr/epg/Epg.h"
#include "pvr/epg/EpgChannelData.h"
#include "pvr/epg/EpgContainer.h"
#include "pvr/epg/EpgInfoTag.h"
#include "pvr/recordings/PVRRecordings.h"
Expand Down Expand Up @@ -609,11 +610,25 @@ PVR_ERROR CPVRClient::RenameChannel(const CPVRChannelPtr &channel)
}, m_clientCapabilities.SupportsChannelSettings());
}

PVR_ERROR CPVRClient::GetEPGForChannel(const CPVRChannelPtr &channel, CPVREpg *epg, time_t start /* = 0 */, time_t end /* = 0 */, bool bSaveInDb /* = false*/)
PVR_ERROR CPVRClient::GetEPGForChannel(const std::shared_ptr<CPVREpgChannelData>& channelData,
CPVREpg* epg,
time_t start /* = 0 */,
time_t end /* = 0 */,
bool bSaveInDb /* = false */)
{
return DoAddonCall(__FUNCTION__, [this, channel, epg, start, end, bSaveInDb](const AddonInstance* addon) {
PVR_CHANNEL addonChannel;
WriteClientChannelInfo(channel, addonChannel);
return DoAddonCall(__FUNCTION__, [this, channelData, epg, start, end, bSaveInDb](const AddonInstance* addon) {

//! @todo PVR Addon API Change: Change GetEPGForChannel param from 'PVR_CHANNEL channel' to 'int iUniqueId'.
PVR_CHANNEL addonChannel = {0};

// mandatory
addonChannel.iUniqueId = channelData->UniqueClientChannelId();
addonChannel.bIsRadio = channelData->IsRadio();

// optional
strncpy(addonChannel.strChannelName, channelData->ChannelName().c_str(), sizeof(addonChannel.strChannelName) - 1);
strncpy(addonChannel.strIconPath, channelData->IconPath().c_str(), sizeof(addonChannel.strIconPath) - 1);
addonChannel.bIsHidden = channelData->IsHidden();

ADDON_HANDLE_STRUCT handle;
handle.callerAddress = this;
Expand Down Expand Up @@ -647,15 +662,15 @@ class CAddonEpgTag : public EPG_TAG
public:
CAddonEpgTag() = delete;
explicit CAddonEpgTag(const CConstPVREpgInfoTagPtr kodiTag) :
m_strTitle(kodiTag->Title(true)),
m_strPlotOutline(kodiTag->PlotOutline(true)),
m_strPlot(kodiTag->Plot(true)),
m_strOriginalTitle(kodiTag->OriginalTitle(true)),
m_strTitle(kodiTag->Title()),
m_strPlotOutline(kodiTag->PlotOutline()),
m_strPlot(kodiTag->Plot()),
m_strOriginalTitle(kodiTag->OriginalTitle()),
m_strCast(kodiTag->DeTokenize(kodiTag->Cast())),
m_strDirector(kodiTag->DeTokenize(kodiTag->Directors())),
m_strWriter(kodiTag->DeTokenize(kodiTag->Writers())),
m_strIMDBNumber(kodiTag->IMDBNumber()),
m_strEpisodeName(kodiTag->EpisodeName(true)),
m_strEpisodeName(kodiTag->EpisodeName()),
m_strIconPath(kodiTag->Icon()),
m_strSeriesLink(kodiTag->SeriesLink()),
m_strGenreDescription(kodiTag->GetGenresLabel())
Expand Down Expand Up @@ -1484,7 +1499,7 @@ void CPVRClient::cb_transfer_channel_group(void *kodiInstance, const ADDON_HANDL
}

/* transfer this entry to the groups container */
CPVRChannelGroup transferGroup(*group);
CPVRChannelGroup transferGroup(*group, kodiGroups->GetGroupAll());
kodiGroups->UpdateFromClient(transferGroup);
}

Expand Down Expand Up @@ -1664,7 +1679,6 @@ void CPVRClient::cb_trigger_channel_groups_update(void *kodiInstance)

void CPVRClient::cb_trigger_epg_update(void *kodiInstance, unsigned int iChannelUid)
{
// get the client
CPVRClient *client = static_cast<CPVRClient*>(kodiInstance);
if (!client)
{
Expand Down Expand Up @@ -1718,7 +1732,9 @@ void CPVRClient::cb_epg_event_state_change(void* kodiInstance, EPG_TAG* tag, EPG
return;
}

CServiceBroker::GetPVRManager().EpgContainer().UpdateFromClient(std::make_shared<CPVREpgInfoTag>(*tag, client->GetID()), newState);
// Note: channel data and epg id may not yet be available. Tag will be fully initialized later.
const std::shared_ptr<CPVREpgInfoTag> epgTag = std::make_shared<CPVREpgInfoTag>(*tag, client->GetID(), nullptr, -1);
CServiceBroker::GetPVRManager().EpgContainer().UpdateFromClient(epgTag, newState);
}

class CCodecIds
Expand Down
5 changes: 3 additions & 2 deletions xbmc/addons/PVRClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
namespace PVR
{
class CPVRChannelGroups;
class CPVREpgChannelData;
class CPVRTimersContainer;
class CPVRClientMenuHook;
class CPVRClientMenuHooks;
Expand Down Expand Up @@ -400,14 +401,14 @@ namespace PVR

/*!
* @brief Request an EPG table for a channel from the client.
* @param channel The channel to get the EPG table for.
* @param channelData The data for 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 CPVRChannelPtr &channel, CPVREpg *epg, time_t start = 0, time_t end = 0, bool bSaveInDb = false);
PVR_ERROR GetEPGForChannel(const std::shared_ptr<CPVREpgChannelData>& channelData, CPVREpg* epg, time_t start = 0, time_t end = 0, bool bSaveInDb = false);

/*!
* Tell the client the time frame to use when notifying epg events back to Kodi. The client might push epg events asynchronously
Expand Down
2 changes: 1 addition & 1 deletion xbmc/cores/VideoPlayer/Edl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,7 @@ bool CEdl::ReadPvr(const CFileItem &fileItem)
}
else if (fileItem.HasEPGInfoTag())
{
CLog::Log(LOGDEBUG, "%s - Reading Edl for EPG: %s", __FUNCTION__, fileItem.GetEPGInfoTag()->Title(true).c_str());
CLog::Log(LOGDEBUG, "%s - Reading Edl for EPG: %s", __FUNCTION__, fileItem.GetEPGInfoTag()->Title().c_str());
edl = fileItem.GetEPGInfoTag()->GetEdl();
}
else
Expand Down
25 changes: 17 additions & 8 deletions xbmc/interfaces/json-rpc/PVROperations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,12 @@ JSONRPC_STATUS CPVROperations::GetBroadcasts(const std::string &method, ITranspo
return InternalError;

CFileItemList programFull;
channelEpg->Get(programFull);

const std::vector<std::shared_ptr<CPVREpgInfoTag>> tags = channelEpg->GetTags();
for (const auto& tag : tags)
{
programFull.Add(std::make_shared<CFileItem>(tag));
}

HandleFileItemList("broadcastid", false, "broadcasts", programFull, parameterObject, result, programFull.Size(), true);

Expand All @@ -169,7 +174,8 @@ JSONRPC_STATUS CPVROperations::GetBroadcastDetails(const std::string &method, IT
if (!CServiceBroker::GetPVRManager().IsStarted())
return FailedToExecute;

const CPVREpgInfoTagPtr epgTag = CServiceBroker::GetPVRManager().EpgContainer().GetTagById(CPVRChannelPtr(), parameterObject["broadcastid"].asUnsignedInteger());
const std::shared_ptr<CPVREpgInfoTag> epgTag = CServiceBroker::GetPVRManager().EpgContainer().GetTagById(nullptr,
parameterObject["broadcastid"].asUnsignedInteger());

if (!epgTag)
return InvalidParams;
Expand Down Expand Up @@ -210,13 +216,14 @@ JSONRPC_STATUS CPVROperations::Record(const std::string &method, ITransportLayer
return FailedToExecute;

CVariant record = parameterObject["record"];
bool bIsRecording = CServiceBroker::GetPVRManager().Timers()->IsRecordingOnChannel(*pChannel);
bool toggle = true;
if (record.isBoolean() && record.asBoolean() == pChannel->IsRecording())
if (record.isBoolean() && record.asBoolean() == bIsRecording)
toggle = false;

if (toggle)
{
if (!CServiceBroker::GetPVRManager().GUIActions()->SetRecordingOnChannel(pChannel, !pChannel->IsRecording()))
if (!CServiceBroker::GetPVRManager().GUIActions()->SetRecordingOnChannel(pChannel, !bIsRecording))
return FailedToExecute;
}

Expand Down Expand Up @@ -321,12 +328,13 @@ JSONRPC_STATUS CPVROperations::AddTimer(const std::string &method, ITransportLay
if (!CServiceBroker::GetPVRManager().IsStarted())
return FailedToExecute;

const CPVREpgInfoTagPtr epgTag = CServiceBroker::GetPVRManager().EpgContainer().GetTagById(CPVRChannelPtr(), parameterObject["broadcastid"].asUnsignedInteger());
const std::shared_ptr<CPVREpgInfoTag> epgTag = CServiceBroker::GetPVRManager().EpgContainer().GetTagById(nullptr,
parameterObject["broadcastid"].asUnsignedInteger());

if (!epgTag)
return InvalidParams;

if (epgTag->HasTimer())
if (CServiceBroker::GetPVRManager().Timers()->GetTimerForEpgTag(epgTag))
return InvalidParams;

CPVRTimerInfoTagPtr newTimer = CPVRTimerInfoTag::CreateFromEpg(epgTag, parameterObject["timerrule"].asBoolean(false));
Expand Down Expand Up @@ -363,14 +371,15 @@ JSONRPC_STATUS CPVROperations::ToggleTimer(const std::string &method, ITransport
if (!CServiceBroker::GetPVRManager().IsStarted())
return FailedToExecute;

const CPVREpgInfoTagPtr epgTag = CServiceBroker::GetPVRManager().EpgContainer().GetTagById(CPVRChannelPtr(), parameterObject["broadcastid"].asUnsignedInteger());
const std::shared_ptr<CPVREpgInfoTag> epgTag = CServiceBroker::GetPVRManager().EpgContainer().GetTagById(nullptr,
parameterObject["broadcastid"].asUnsignedInteger());

if (!epgTag)
return InvalidParams;

bool timerrule = parameterObject["timerrule"].asBoolean(false);
bool sentOkay = false;
CPVRTimerInfoTagPtr timer(epgTag->Timer());
std::shared_ptr<CPVRTimerInfoTag> timer = CServiceBroker::GetPVRManager().Timers()->GetTimerForEpgTag(epgTag);
if (timer)
{
if (timerrule)
Expand Down
22 changes: 11 additions & 11 deletions xbmc/pvr/PVRContextMenus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@
#include "pvr/channels/PVRChannel.h"
#include "pvr/epg/EpgInfoTag.h"
#include "pvr/recordings/PVRRecording.h"
#include "pvr/recordings/PVRRecordings.h"
#include "pvr/recordings/PVRRecordingsPath.h"
#include "pvr/timers/PVRTimers.h"
#include "pvr/timers/PVRTimersPath.h"

namespace PVR
{
Expand Down Expand Up @@ -85,7 +87,7 @@ namespace PVR

const CPVREpgInfoTagPtr epg(item.GetEPGInfoTag());
if (epg)
timer = epg->Timer();
timer = CServiceBroker::GetPVRManager().Timers()->GetTimerForEpgTag(epg);

if (!timer)
timer = item.GetPVRTimerInfoTag();
Expand Down Expand Up @@ -115,12 +117,7 @@ namespace PVR

bool PlayRecording::IsVisible(const CFileItem &item) const
{
CPVRRecordingPtr recording;

const CPVREpgInfoTagPtr epg(item.GetEPGInfoTag());
if (epg)
recording = epg->Recording();

const std::shared_ptr<CPVRRecording> recording = CServiceBroker::GetPVRManager().Recordings()->GetRecordingForEpgTag(item.GetEPGInfoTag());
if (recording)
return !recording->IsDeleted();

Expand Down Expand Up @@ -220,10 +217,13 @@ namespace PVR

const CPVRChannelPtr channel = item.GetPVRChannelInfoTag();
if (channel)
return !channel->IsRecording() && client && client->GetClientCapabilities().SupportsTimers();
return client && client->GetClientCapabilities().SupportsTimers() &&
!CServiceBroker::GetPVRManager().Timers()->IsRecordingOnChannel(*channel);

const CPVREpgInfoTagPtr epg = item.GetEPGInfoTag();
if (epg && !epg->Timer() && epg->Channel() && epg->IsRecordable())
if (epg &&
!CServiceBroker::GetPVRManager().Timers()->GetTimerForEpgTag(epg) &&
epg->IsRecordable())
return client && client->GetClientCapabilities().SupportsTimers();

return false;
Expand All @@ -245,7 +245,7 @@ namespace PVR

const CPVRChannelPtr channel(item.GetPVRChannelInfoTag());
if (channel)
return channel->IsRecording();
return CServiceBroker::GetPVRManager().Timers()->IsRecordingOnChannel(*channel);

const CPVRTimerInfoTagPtr timer(GetTimerInfoTagFromItem(item));
if (timer && !URIUtils::PathEquals(item.GetPath(), CPVRTimersPath::PATH_ADDTIMER))
Expand Down Expand Up @@ -381,7 +381,7 @@ namespace PVR
bool AddTimerRule::IsVisible(const CFileItem &item) const
{
const CPVREpgInfoTagPtr epg = item.GetEPGInfoTag();
if (epg && epg->Channel() && !epg->Timer())
if (epg && !CServiceBroker::GetPVRManager().Timers()->GetTimerForEpgTag(epg))
{
const CPVRClientPtr client = CServiceBroker::GetPVRManager().GetClient(item);
return client && client->GetClientCapabilities().SupportsTimers();
Expand Down
2 changes: 1 addition & 1 deletion xbmc/pvr/PVRDatabase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,7 @@ bool CPVRDatabase::Get(CPVRChannelGroups &results)
{
while (!m_pDS->eof())
{
CPVRChannelGroup data(m_pDS->fv("bIsRadio").get_asBool(), m_pDS->fv("idGroup").get_asInt(), m_pDS->fv("sName").get_asString());
CPVRChannelGroup data(m_pDS->fv("bIsRadio").get_asBool(), m_pDS->fv("idGroup").get_asInt(), m_pDS->fv("sName").get_asString(), results.GetGroupAll());
data.SetGroupType(m_pDS->fv("iGroupType").get_asInt());
data.SetLastWatched(static_cast<time_t>(m_pDS->fv("iLastWatched").get_asInt()));
data.SetHidden(m_pDS->fv("bIsHidden").get_asBool());
Expand Down
Loading

0 comments on commit d68bd9b

Please sign in to comment.