Skip to content

Commit

Permalink
Merge pull request xbmc#25928 from ksooo/pvr-cleanup-parental-rating-…
Browse files Browse the repository at this point in the history
…icon-texture-cache

[PVR] Add support for automatic texture cache cleanup for parantal ra…
  • Loading branch information
ksooo authored Nov 4, 2024
2 parents 11817c2 + 5f9b296 commit 3f4c967
Show file tree
Hide file tree
Showing 9 changed files with 91 additions and 32 deletions.
4 changes: 2 additions & 2 deletions xbmc/pvr/addons/PVRClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ class CAddonRecording : public PVR_RECORDING
m_firstAired(recording.FirstAired().IsValid() ? recording.FirstAired().GetAsW3CDate() : ""),
m_providerName(recording.ProviderName()),
m_parentalRatingCode(recording.GetParentalRatingCode()),
m_parentalRatingIcon(recording.GetParentalRatingIcon()),
m_parentalRatingIcon(recording.ClientParentalRatingIconPath()),
m_parentalRatingSource(recording.GetParentalRatingSource())
{
// zero-init base struct members
Expand Down Expand Up @@ -309,7 +309,7 @@ class CAddonEpgTag : public EPG_TAG
m_genreDescription(tag.GenreDescription()),
m_firstAired(GetFirstAired(tag)),
m_parentalRatingCode(tag.ParentalRatingCode()),
m_parentalRatingIcon(tag.ParentalRatingIcon()),
m_parentalRatingIcon(tag.ClientParentalRatingIconPath()),
m_parentalRatingSource(tag.ParentalRatingSource())
{
// zero-init base struct members
Expand Down
4 changes: 3 additions & 1 deletion xbmc/pvr/epg/Epg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,9 @@ void CPVREpg::RemovedFromContainer()

int CPVREpg::CleanupCachedImages(const std::shared_ptr<const CPVREpgDatabase>& database)
{
const std::vector<std::string> urlsToCheck = database->GetAllIconPaths(EpgID());
std::vector<std::string> urlsToCheck;
database->GetAllIconPaths(EpgID(), urlsToCheck);
database->GetAllParentalRatingIconPaths(EpgID(), urlsToCheck);
const std::string owner = StringUtils::Format(CPVREpgInfoTag::IMAGE_OWNER_PATTERN, EpgID());

return CPVRCachedImages::Cleanup({{owner, ""}}, urlsToCheck);
Expand Down
43 changes: 34 additions & 9 deletions xbmc/pvr/epg/EpgDatabase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,8 @@ std::shared_ptr<CPVREpgInfoTag> CPVREpgDatabase::CreateEpgTag(
if (!pDS->eof())
{
std::shared_ptr<CPVREpgInfoTag> newTag(
new CPVREpgInfoTag(m_pDS->fv("idEpg").get_asInt(), m_pDS->fv("sIconPath").get_asString()));
new CPVREpgInfoTag(m_pDS->fv("idEpg").get_asInt(), m_pDS->fv("sIconPath").get_asString(),
m_pDS->fv("sParentalRatingIcon").get_asString()));

time_t iStartTime;
iStartTime = static_cast<time_t>(m_pDS->fv("iStartTime").get_asInt());
Expand Down Expand Up @@ -481,7 +482,6 @@ std::shared_ptr<CPVREpgInfoTag> CPVREpgDatabase::CreateEpgTag(
newTag->m_iFlags = m_pDS->fv("iFlags").get_asInt();
newTag->m_strSeriesLink = m_pDS->fv("sSeriesLink").get_asString();
newTag->m_parentalRatingCode = m_pDS->fv("sParentalRatingCode").get_asString();
newTag->m_parentalRatingIcon = m_pDS->fv("sParentalRatingIcon").get_asString();
newTag->m_parentalRatingSource = m_pDS->fv("sParentalRatingSource").get_asString();
newTag->m_iGenreType = m_pDS->fv("iGenreType").get_asInt();
newTag->m_iGenreSubType = m_pDS->fv("iGenreSubType").get_asInt();
Expand Down Expand Up @@ -1121,7 +1121,7 @@ std::vector<std::shared_ptr<CPVREpgInfoTag>> CPVREpgDatabase::GetAllEpgTags(int
return {};
}

std::vector<std::string> CPVREpgDatabase::GetAllIconPaths(int iEpgID) const
bool CPVREpgDatabase::GetAllIconPaths(int iEpgID, std::vector<std::string>& paths) const
{
std::unique_lock<CCriticalSection> lock(m_critSection);
const std::string strQuery =
Expand All @@ -1130,21 +1130,46 @@ std::vector<std::string> CPVREpgDatabase::GetAllIconPaths(int iEpgID) const
{
try
{
std::vector<std::string> paths;
while (!m_pDS->eof())
{
paths.emplace_back(m_pDS->fv("sIconPath").get_asString());
m_pDS->next();
}
m_pDS->close();
return paths;
return true;
}
catch (...)
{
CLog::LogF(LOGERROR, "Could not load tags for EPG ({})", iEpgID);
CLog::LogF(LOGERROR, "Could not load icon paths for EPG ({})", iEpgID);
}
}
return {};
return false;
}

bool CPVREpgDatabase::GetAllParentalRatingIconPaths(int iEpgID,
std::vector<std::string>& paths) const
{
std::unique_lock<CCriticalSection> lock(m_critSection);
const std::string strQuery =
PrepareSQL("SELECT sParentalRatingIcon FROM epgtags WHERE idEpg = %u;", iEpgID);
if (ResultQuery(strQuery))
{
try
{
while (!m_pDS->eof())
{
paths.emplace_back(m_pDS->fv("sParentalRatingIcon").get_asString());
m_pDS->next();
}
m_pDS->close();
return true;
}
catch (...)
{
CLog::LogF(LOGERROR, "Could not load parental rating icon paths for EPG ({})", iEpgID);
}
}
return false;
}

bool CPVREpgDatabase::GetLastEpgScanTime(int iEpgId, CDateTime* lastScan) const
Expand Down Expand Up @@ -1301,7 +1326,7 @@ bool CPVREpgDatabase::QueuePersistQuery(const CPVREpgInfoTag& tag)
tag.GenreDescription().c_str(), sFirstAired.c_str(), tag.ParentalRating(), tag.StarRating(),
tag.SeriesNumber(), tag.EpisodeNumber(), tag.EpisodePart(), tag.EpisodeName().c_str(),
tag.Flags(), tag.SeriesLink().c_str(), tag.ParentalRatingCode().c_str(),
tag.UniqueBroadcastID(), tag.ParentalRatingIcon().c_str(),
tag.UniqueBroadcastID(), tag.ClientParentalRatingIconPath().c_str(),
tag.ParentalRatingSource().c_str(), tag.TitleExtraInfo().c_str());
}
else
Expand All @@ -1324,7 +1349,7 @@ bool CPVREpgDatabase::QueuePersistQuery(const CPVREpgInfoTag& tag)
tag.GenreDescription().c_str(), sFirstAired.c_str(), tag.ParentalRating(), tag.StarRating(),
tag.SeriesNumber(), tag.EpisodeNumber(), tag.EpisodePart(), tag.EpisodeName().c_str(),
tag.Flags(), tag.SeriesLink().c_str(), tag.ParentalRatingCode().c_str(),
tag.UniqueBroadcastID(), iBroadcastId, tag.ParentalRatingIcon().c_str(),
tag.UniqueBroadcastID(), iBroadcastId, tag.ClientParentalRatingIconPath().c_str(),
tag.ParentalRatingSource().c_str(), tag.TitleExtraInfo().c_str());
}

Expand Down
13 changes: 11 additions & 2 deletions xbmc/pvr/epg/EpgDatabase.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,18 @@ namespace PVR
/*!
* @brief Get all icon paths for a given EPG id.
* @param iEpgID The ID of the EPG.
* @return The entries.
* @param path The paths returned.
* @return True on success, false otherwise.
*/
bool GetAllIconPaths(int iEpgID, std::vector<std::string>& paths) const;

/*!
* @brief Get all parental rating icon paths for a given EPG id.
* @param iEpgID The ID of the EPG.
* @param path The paths returned.
* @return True on success, false otherwise.
*/
std::vector<std::string> GetAllIconPaths(int iEpgID) const;
bool GetAllParentalRatingIconPaths(int iEpgID, std::vector<std::string>& paths) const;

/*!
* @brief Check whether this EPG has any tags.
Expand Down
16 changes: 10 additions & 6 deletions xbmc/pvr/epg/EpgInfoTag.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,11 @@ using namespace PVR;

const std::string CPVREpgInfoTag::IMAGE_OWNER_PATTERN = "epgtag_{}";

CPVREpgInfoTag::CPVREpgInfoTag(int iEpgID, const std::string& iconPath)
: m_iUniqueBroadcastID(EPG_TAG_INVALID_UID),
CPVREpgInfoTag::CPVREpgInfoTag(int iEpgID,
const std::string& iconPath,
const std::string& parentalRatingIconPath)
: m_parentalRatingIcon(parentalRatingIconPath, StringUtils::Format(IMAGE_OWNER_PATTERN, iEpgID)),
m_iUniqueBroadcastID(EPG_TAG_INVALID_UID),
m_iconPath(iconPath, StringUtils::Format(IMAGE_OWNER_PATTERN, iEpgID)),
m_iFlags(EPG_TAG_FLAG_UNDEFINED),
m_channelData(new CPVREpgChannelData),
Expand All @@ -46,7 +49,8 @@ CPVREpgInfoTag::CPVREpgInfoTag(const std::shared_ptr<CPVREpgChannelData>& channe
const CDateTime& start,
const CDateTime& end,
bool bIsGapTag)
: m_iUniqueBroadcastID(EPG_TAG_INVALID_UID),
: m_parentalRatingIcon(StringUtils::Format(IMAGE_OWNER_PATTERN, iEpgID)),
m_iUniqueBroadcastID(EPG_TAG_INVALID_UID),
m_iconPath(StringUtils::Format(IMAGE_OWNER_PATTERN, iEpgID)),
m_iFlags(EPG_TAG_FLAG_UNDEFINED),
m_bIsGapTag(bIsGapTag),
Expand All @@ -70,6 +74,8 @@ CPVREpgInfoTag::CPVREpgInfoTag(const EPG_TAG& data,
: m_iGenreType(data.iGenreType),
m_iGenreSubType(data.iGenreSubType),
m_parentalRating(data.iParentalRating),
m_parentalRatingIcon(data.strParentalRatingIcon ? data.strParentalRatingIcon : "",
StringUtils::Format(IMAGE_OWNER_PATTERN, iEpgID)),
m_iStarRating(data.iStarRating),
m_iSeriesNumber(data.iSeriesNumber),
m_iEpisodeNumber(data.iEpisodeNumber),
Expand Down Expand Up @@ -134,8 +140,6 @@ CPVREpgInfoTag::CPVREpgInfoTag(const EPG_TAG& data,
m_strSeriesLink = data.strSeriesLink;
if (data.strParentalRatingCode)
m_parentalRatingCode = data.strParentalRatingCode;
if (data.strParentalRatingIcon)
m_parentalRatingIcon = data.strParentalRatingIcon;
if (data.strParentalRatingSource)
m_parentalRatingSource = data.strParentalRatingSource;
}
Expand Down Expand Up @@ -176,7 +180,7 @@ void CPVREpgInfoTag::Serialize(CVariant& value) const
value["channeluid"] = m_channelData->UniqueClientChannelId();
value["parentalrating"] = m_parentalRating;
value["parentalratingcode"] = m_parentalRatingCode;
value["parentalratingicon"] = m_parentalRatingIcon;
value["parentalratingicon"] = ClientParentalRatingIconPath();
value["parentalratingsource"] = m_parentalRatingSource;
value["rating"] = m_iStarRating;
value["title"] = m_strTitle;
Expand Down
14 changes: 11 additions & 3 deletions xbmc/pvr/epg/EpgInfoTag.h
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,13 @@ class CPVREpgInfoTag final : public ISerializable,
* @brief Get the parental rating icon path of this event.
* @return Path to the parental rating icon.
*/
const std::string& ParentalRatingIcon() const { return m_parentalRatingIcon; }
const std::string& ParentalRatingIcon() const { return m_parentalRatingIcon.GetLocalImage(); }

/*!
* @brief Get the parental rating icon path of this event as given by the client.
* @return The path to the icon
*/
std::string ClientParentalRatingIconPath() const { return m_parentalRatingIcon.GetClientImage(); }

/*!
* @brief Get the parental rating source of this event.
Expand Down Expand Up @@ -485,7 +491,9 @@ class CPVREpgInfoTag final : public ISerializable,
static const std::string DeTokenize(const std::vector<std::string>& tokens);

private:
CPVREpgInfoTag(int iEpgID, const std::string& iconPath);
CPVREpgInfoTag(int iEpgID,
const std::string& iconPath,
const std::string& parentalRatingIconPath);

CPVREpgInfoTag() = delete;
CPVREpgInfoTag(const CPVREpgInfoTag& tag) = delete;
Expand All @@ -503,7 +511,7 @@ class CPVREpgInfoTag final : public ISerializable,
std::string m_strGenreDescription; /*!< genre description */
unsigned int m_parentalRating = 0; /*!< parental rating */
std::string m_parentalRatingCode; /*!< Parental rating code */
std::string m_parentalRatingIcon; /*!< parental rating icon path */
CPVRCachedImage m_parentalRatingIcon; /*!< parental rating icon path */
std::string m_parentalRatingSource; /*!< parental rating source */
int m_iStarRating = 0; /*!< star rating */
int m_iSeriesNumber = -1; /*!< series number */
Expand Down
14 changes: 7 additions & 7 deletions xbmc/pvr/recordings/PVRRecording.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ const std::string CPVRRecording::IMAGE_OWNER_PATTERN = "pvrrecording";
CPVRRecording::CPVRRecording()
: m_iconPath(IMAGE_OWNER_PATTERN),
m_thumbnailPath(IMAGE_OWNER_PATTERN),
m_fanartPath(IMAGE_OWNER_PATTERN)
m_fanartPath(IMAGE_OWNER_PATTERN),
m_parentalRatingIcon(IMAGE_OWNER_PATTERN)
{
Reset();
}
Expand All @@ -78,7 +79,9 @@ CPVRRecording::CPVRRecording(const PVR_RECORDING& recording, unsigned int iClien
: m_iconPath(recording.strIconPath ? recording.strIconPath : "", IMAGE_OWNER_PATTERN),
m_thumbnailPath(recording.strThumbnailPath ? recording.strThumbnailPath : "",
IMAGE_OWNER_PATTERN),
m_fanartPath(recording.strFanartPath ? recording.strFanartPath : "", IMAGE_OWNER_PATTERN)
m_fanartPath(recording.strFanartPath ? recording.strFanartPath : "", IMAGE_OWNER_PATTERN),
m_parentalRatingIcon(recording.strParentalRatingIcon ? recording.strParentalRatingIcon : "",
IMAGE_OWNER_PATTERN)
{
Reset();

Expand Down Expand Up @@ -132,8 +135,6 @@ CPVRRecording::CPVRRecording(const PVR_RECORDING& recording, unsigned int iClien
m_parentalRating = recording.iParentalRating;
if (recording.strParentalRatingCode)
m_parentalRatingCode = recording.strParentalRatingCode;
if (recording.strParentalRatingIcon)
m_parentalRatingIcon = recording.strParentalRatingIcon;
if (recording.strParentalRatingSource)
m_parentalRatingSource = recording.strParentalRatingSource;

Expand Down Expand Up @@ -222,7 +223,7 @@ void CPVRRecording::Serialize(CVariant& value) const
value["genre"] = m_genre;
value["parentalrating"] = m_parentalRating;
value["parentalratingcode"] = m_parentalRatingCode;
value["parentalratingicon"] = m_parentalRatingIcon;
value["parentalratingicon"] = ClientParentalRatingIconPath();
value["parentalratingsource"] = m_parentalRatingSource;
value["episodepart"] = m_episodePartNumber;
value["titleextrainfo"] = m_titleExtraInfo;
Expand Down Expand Up @@ -279,7 +280,6 @@ void CPVRRecording::Reset()

m_parentalRating = 0;
m_parentalRatingCode.clear();
m_parentalRatingIcon.clear();
m_parentalRatingSource.clear();
m_titleExtraInfo.clear();

Expand Down Expand Up @@ -755,7 +755,7 @@ const std::string& CPVRRecording::GetParentalRatingCode() const
const std::string& CPVRRecording::GetParentalRatingIcon() const
{
std::unique_lock<CCriticalSection> lock(m_critSection);
return m_parentalRatingIcon;
return m_parentalRatingIcon.GetLocalImage();
}

const std::string& CPVRRecording::GetParentalRatingSource() const
Expand Down
11 changes: 10 additions & 1 deletion xbmc/pvr/recordings/PVRRecording.h
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,15 @@ class CPVRRecording final : public CVideoInfoTag
*/
const std::string& ClientFanartPath() const { return m_fanartPath.GetClientImage(); }

/*!
* @brief Return the parental rating icon path as given by the client.
* @return The path.
*/
const std::string& ClientParentalRatingIconPath() const
{
return m_parentalRatingIcon.GetClientImage();
}

/*!
* @brief Return the icon path used by Kodi.
* @return The path.
Expand Down Expand Up @@ -578,7 +587,7 @@ class CPVRRecording final : public CVideoInfoTag
PVR_PROVIDER_INVALID_UID; /*!< provider uid associated with this recording on the client */
unsigned int m_parentalRating{0}; /*!< parental rating */
std::string m_parentalRatingCode; /*!< Parental rating code */
std::string m_parentalRatingIcon; /*!< parental rating icon path */
CPVRCachedImage m_parentalRatingIcon; /*!< parental rating icon path */
std::string m_parentalRatingSource; /*!< parental rating source */
int m_episodePartNumber{PVR_RECORDING_INVALID_SERIES_EPISODE}; /*!< episode part number */
std::string m_titleExtraInfo; /*!< title extra info */
Expand Down
4 changes: 3 additions & 1 deletion xbmc/pvr/recordings/PVRRecordings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -391,12 +391,14 @@ int CPVRRecordings::CleanupCachedImages()
urlsToCheck.emplace_back(recording.second->ClientIconPath());
urlsToCheck.emplace_back(recording.second->ClientThumbnailPath());
urlsToCheck.emplace_back(recording.second->ClientFanartPath());
urlsToCheck.emplace_back(recording.second->ClientParentalRatingIconPath());
urlsToCheck.emplace_back(recording.second->m_strFileNameAndPath);
}
}

static const std::vector<PVRImagePattern> urlPatterns = {
{CPVRRecording::IMAGE_OWNER_PATTERN, ""}, // client-supplied icon, thumbnail, fanart
{CPVRRecording::IMAGE_OWNER_PATTERN,
""}, // client-supplied icon, thumbnail, fanart, parental rating icon
{"video", "pvr://recordings/"}, // kodi-generated video thumbnail
};
return CPVRCachedImages::Cleanup(urlPatterns, urlsToCheck);
Expand Down

0 comments on commit 3f4c967

Please sign in to comment.