Skip to content

Commit

Permalink
merge props and cache
Browse files Browse the repository at this point in the history
  • Loading branch information
janbar committed Feb 27, 2024
1 parent fb64773 commit 836ab9f
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 95 deletions.
44 changes: 1 addition & 43 deletions src/cppmyth/MythProgramInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,12 @@ enum

MythProgramInfo::MythProgramInfo()
: m_proginfo()
, m_props()
, m_cache()
{
}

MythProgramInfo::MythProgramInfo(const Myth::ProgramPtr& proginfo)
: m_proginfo(proginfo)
, m_props(new Props())
, m_cache(new Cache())
{
}
Expand Down Expand Up @@ -127,46 +125,6 @@ bool MythProgramInfo::HasFanart() const
return false;
}

void MythProgramInfo::SetPropsVideoFrameRate(float fps)
{
m_props->videoFrameRate = fps;
}

float MythProgramInfo::GetPropsVideoFrameRate() const
{
return m_props->videoFrameRate;
}

void MythProgramInfo::SetPropsVideoAspec(float aspec)
{
m_props->videoAspec = aspec;
}

float MythProgramInfo::GetPropsVideoAspec() const
{
return m_props->videoAspec;
}

void MythProgramInfo::SetPropsSerie(bool flag)
{
m_props->serie = flag;
}

bool MythProgramInfo::GetPropsSerie() const
{
return m_props->serie;
}

void MythProgramInfo::SetPropsBookmark(int seconds)
{
m_props->bookmark = seconds;
}

int MythProgramInfo::GetPropsBookmark() const
{
return m_props->bookmark;
}

int32_t MythProgramInfo::Cache::get_flags(const MythProgramInfo& prog) const
{
m_flags |= FLAGS_INITIALIZED;
Expand Down Expand Up @@ -247,7 +205,7 @@ const std::string& MythProgramInfo::Cache::get_grouping_title(const MythProgramI
default:
buf.push_back(*it);
trim = 0;
}
}
}
m_groupingTitle.assign(buf.c_str(), buf.size() - trim);
return m_groupingTitle;
Expand Down
67 changes: 34 additions & 33 deletions src/cppmyth/MythProgramInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,52 +57,34 @@ class MythProgramInfo
int64_t FileSize() const { return m_proginfo->fileSize; }
bool IsDamaged(uint32_t schemaVersion) const;

/// Reset cache
void ResetCache() { m_cache.reset(new Cache()); }
/// Copy cache from other
void CopyCache(const MythProgramInfo &other) { m_cache = other.m_cache; }
/// Reset cached flags
void ResetFlags() { m_cache->ResetFlags(); }
// Custom flags

// About cache
bool IsVisible() const;
bool IsDeleted() const;
bool IsLiveTV() const;
bool HasCoverart() const;
bool HasFanart() const;

/// Reset custom properties
void ResetProps() { m_props.reset(new Props()); }
/// Copy reference of properties from other
void CopyProps(const MythProgramInfo &other) { m_props = other.m_props; }

void SetPropsVideoFrameRate(float fps);
float GetPropsVideoFrameRate() const;
void SetPropsVideoAspec(float aspec);
float GetPropsVideoAspec() const;
void SetPropsSerie(bool flag);
bool GetPropsSerie() const;
void SetPropsBookmark(int seconds);
int GetPropsBookmark() const;

const std::string& UID() const { return m_cache->GetUID(*this); }
const std::string& GroupingTitle() const { return m_cache->GetGroupingTitle(*this); }
float VideoFrameRate() const { return m_cache->GetVideoFrameRate(); }
float VideoAspec() const { return m_cache->GetVideoAspec(); }
bool Serie() const { return m_cache->GetSerie(); }
int Bookmark() const { return m_cache->GetBookmark(); }

void SetVideoFrameRate(float fps) { m_cache->SetVideoFrameRate(fps); }
void SetVideoAspec(float aspec) { m_cache->SetVideoAspec(aspec); }
void SetSerie(bool flag) { m_cache->SetSerie(flag); }
void SetBookmark(int seconds) { m_cache->SetBookmark(seconds); }

private:
Myth::ProgramPtr m_proginfo;

struct Props
{
Props()
: videoFrameRate(0)
, videoAspec(0)
, serie(false)
, bookmark(0)
{}
~Props() {}
float videoFrameRate;
float videoAspec;
bool serie; ///< true if program is serie else false
int bookmark; ///< last played position in seconds
};

MYTH_SHARED_PTR<Props> m_props;

friend class Cache;

class Cache
Expand All @@ -112,12 +94,26 @@ class MythProgramInfo
: m_flags(0)
, m_UID()
, m_groupingTitle()
, m_videoFrameRate(0)
, m_videoAspec(0)
, m_serie(false)
, m_bookmark(0)
{}
~Cache() {}
void ResetFlags() { m_flags = 0; }
int32_t GetFlags(const MythProgramInfo& prog) const { return (m_flags == 0 ? get_flags(prog) : m_flags); }
const std::string& GetUID(const MythProgramInfo& prog) const { return (m_UID.empty() ? get_uid(prog) : m_UID); }
const std::string& GetGroupingTitle(const MythProgramInfo& prog) const { return (m_groupingTitle.empty() ? get_grouping_title(prog) : m_groupingTitle); }

float GetVideoFrameRate() const { return m_videoFrameRate; }
float GetVideoAspec() const { return m_videoAspec; }
bool GetSerie() const { return m_serie; }
int GetBookmark() const { return m_bookmark; }
void SetVideoFrameRate(float fps) { m_videoFrameRate = fps; }
void SetVideoAspec(float aspec) { m_videoAspec = aspec; }
void SetSerie(bool flag) { m_serie = flag; }
void SetBookmark(int seconds) { m_bookmark = seconds; }

private:
mutable int32_t m_flags;
mutable std::string m_UID;
Expand All @@ -126,6 +122,11 @@ class MythProgramInfo
int32_t get_flags(const MythProgramInfo& prog) const;
const std::string& get_uid(const MythProgramInfo& prog) const;
const std::string& get_grouping_title(const MythProgramInfo& prog) const;

float m_videoFrameRate;
float m_videoAspec;
bool m_serie; ///< true if program is serie else false
int m_bookmark; ///< last played position in seconds
};

MYTH_SHARED_PTR<Cache> m_cache;
Expand Down
37 changes: 18 additions & 19 deletions src/pvrclient-mythtv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -505,10 +505,9 @@ void PVRClientMythTV::HandleRecordingListChange(const Myth::EventMessage& msg)
kodi::Log(ADDON_LOG_DEBUG, "%s: Update recording: %s", __FUNCTION__, prog.UID().c_str());
if (m_control->RefreshRecordedArtwork(*(msg.program)) && CMythSettings::GetExtraDebug())
kodi::Log(ADDON_LOG_DEBUG, "%s: artwork found for %s", __FUNCTION__, prog.UID().c_str());
// Reset to recalculate flags
// share cache, but reset flags
prog.CopyCache(it->second);
prog.ResetFlags();
// Keep props
prog.CopyProps(it->second);
// Keep original air date
prog.GetPtr()->airdate = it->second.Airdate();
// Update recording
Expand Down Expand Up @@ -961,10 +960,10 @@ PVR_ERROR PVRClientMythTV::GetRecordings(kodi::addon::PVRRecordingsResultSet& re
{
if (found->second)
{
found->second->second.SetPropsSerie(true);
found->second->second.SetSerie(true);
found->second = NULL;
}
it->second.SetPropsSerie(true);
it->second.SetSerie(true);
}
else
titles.insert(std::make_pair(title, &(*it)));
Expand All @@ -989,7 +988,7 @@ PVR_ERROR PVRClientMythTV::GetRecordings(kodi::addon::PVRRecordingsResultSet& re
if (CMythSettings::GetUseBackendBookmarks() && it->second.HasBookmark())
{
// put the known value or something differ from zero to show the right symbol on the GUI
int bookmark = it->second.GetPropsBookmark();
int bookmark = it->second.Bookmark();
tag.SetLastPlayedPosition(bookmark > 0 ? bookmark : 1);
}

Expand Down Expand Up @@ -1035,7 +1034,7 @@ PVR_ERROR PVRClientMythTV::GetRecordings(kodi::addon::PVRRecordingsResultSet& re
std::string strDirectory;
if (!CMythSettings::GetRootDefaultGroup() || it->second.RecordingGroup().compare("Default") != 0)
strDirectory.append(it->second.RecordingGroup());
if (CMythSettings::GetGroupRecordings() == GROUP_RECORDINGS_ALWAYS || (CMythSettings::GetGroupRecordings() == GROUP_RECORDINGS_ONLY_FOR_SERIES && it->second.GetPropsSerie()))
if (CMythSettings::GetGroupRecordings() == GROUP_RECORDINGS_ALWAYS || (CMythSettings::GetGroupRecordings() == GROUP_RECORDINGS_ONLY_FOR_SERIES && it->second.Serie()))
strDirectory.append("/").append(it->second.GroupingTitle());
tag.SetDirectory(strDirectory);

Expand Down Expand Up @@ -1075,7 +1074,7 @@ PVR_ERROR PVRClientMythTV::GetRecordings(kodi::addon::PVRRecordingsResultSet& re
tag.SetPlotOutline("");
tag.SetSizeInBytes(it->second.FileSize());
unsigned int flags = PVR_RECORDING_FLAG_UNDEFINED;
if (it->second.GetPropsSerie())
if (it->second.Serie())
flags |= PVR_RECORDING_FLAG_IS_SERIES;
tag.SetFlags(flags);

Expand Down Expand Up @@ -1198,7 +1197,7 @@ PVR_ERROR PVRClientMythTV::GetDeletedRecordings(kodi::addon::PVRRecordingsResult
tag.SetPlotOutline("");
tag.SetSizeInBytes(it->second.FileSize());
unsigned int flags = PVR_RECORDING_FLAG_UNDEFINED;
if (it->second.GetPropsSerie())
if (it->second.Serie())
flags |= PVR_RECORDING_FLAG_IS_SERIES;
tag.SetFlags(flags);

Expand All @@ -1224,8 +1223,8 @@ void PVRClientMythTV::ForceUpdateRecording(ProgramInfoMap::iterator it)
MythProgramInfo prog(m_control->GetRecorded(it->second.ChannelID(), it->second.RecordingStartTime()));
if (!prog.IsNull())
{
// Copy props
prog.CopyProps(it->second);
// share cache
prog.CopyCache(it->second);
// Update recording
it->second = prog;
++m_recordingChangePinCount;
Expand Down Expand Up @@ -1411,7 +1410,7 @@ PVR_ERROR PVRClientMythTV::SetRecordingLastPlayedPosition(const kodi::addon::PVR
// Write the bookmark
if (m_control->SetSavedBookmark(*prog, 2, duration))
{
it->second.SetPropsBookmark(lastplayedposition);
it->second.SetBookmark(lastplayedposition);
kodi::Log(ADDON_LOG_INFO, "%s: Setting Bookmark successful: %d", __FUNCTION__, lastplayedposition);
return PVR_ERROR_NO_ERROR;
}
Expand All @@ -1435,7 +1434,7 @@ PVR_ERROR PVRClientMythTV::GetRecordingLastPlayedPosition(const kodi::addon::PVR
if (it->second.HasBookmark())
{
// return the known value from properties
position = it->second.GetPropsBookmark();
position = it->second.Bookmark();
if (position > 0)
{
kodi::Log(ADDON_LOG_DEBUG, "%s: %d", __FUNCTION__, position);
Expand All @@ -1449,7 +1448,7 @@ PVR_ERROR PVRClientMythTV::GetRecordingLastPlayedPosition(const kodi::addon::PVR
if (duration > 0)
{
position = (int)(duration / 1000);
it->second.SetPropsBookmark(position);
it->second.SetBookmark(position);
kodi::Log(ADDON_LOG_INFO, "%s: Fetching from backend: %d", __FUNCTION__, position);
return PVR_ERROR_NO_ERROR;
}
Expand Down Expand Up @@ -1492,7 +1491,7 @@ PVR_ERROR PVRClientMythTV::GetRecordingEdl(const kodi::addon::PVRRecording& reco
{
unit = 0; // marks are based on framecount
// Check required props else return
rate = prog.GetPropsVideoFrameRate();
rate = prog.VideoFrameRate();
kodi::Log(ADDON_LOG_DEBUG, "%s: AV props: Frame Rate = %.3f", __FUNCTION__, rate);
if (rate <= 0)
return PVR_ERROR_NO_ERROR;
Expand Down Expand Up @@ -2833,8 +2832,8 @@ PVR_ERROR PVRClientMythTV::CallRecordingMenuHook(const kodi::addon::PVRMenuhook&
items[10].append("[/COLOR]");

items[11].append("FrameRate : [COLOR white]");
if (pinfo.GetPropsVideoFrameRate() > 0.0)
items[11].append(std::to_string(pinfo.GetPropsVideoFrameRate()));
if (pinfo.VideoFrameRate() > 0.0)
items[11].append(std::to_string(pinfo.VideoFrameRate()));
items[11].append("[/COLOR]");

kodi::gui::dialogs::Select::Show(item.GetTitle(), items);
Expand Down Expand Up @@ -2941,10 +2940,10 @@ void PVRClientMythTV::FillRecordingAVInfo(MythProgramInfo& programInfo, Myth::St
default:
fps = (float)(mInfo.stream_info.fps_rate) / mInfo.stream_info.fps_scale;
}
programInfo.SetPropsVideoFrameRate(fps);
programInfo.SetVideoFrameRate(fps);
}
// Set video aspec
programInfo.SetPropsVideoAspec(mInfo.stream_info.aspect);
programInfo.SetVideoAspec(mInfo.stream_info.aspect);
}
}

Expand Down

0 comments on commit 836ab9f

Please sign in to comment.