Skip to content

Commit

Permalink
Merge pull request #676 from ksooo/misc-cleanup-and-fixes
Browse files Browse the repository at this point in the history
Misc cleanup and fixes
  • Loading branch information
ksooo authored Aug 21, 2024
2 parents c0c097a + c2bb7cd commit 2674084
Show file tree
Hide file tree
Showing 14 changed files with 99 additions and 82 deletions.
2 changes: 1 addition & 1 deletion pvr.hts/addon.xml.in
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<addon
id="pvr.hts"
version="22.1.0"
version="22.2.0"
name="Tvheadend HTSP Client"
provider-name="Adam Sutton, Sam Stenvall, Lars Op den Kamp, Kai Sommerfeld">
<requires>@ADDON_DEPENDS@</requires>
Expand Down
4 changes: 4 additions & 0 deletions pvr.hts/changelog.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
v22.2.0
- Add support for TVH Parental Rating fields
- Misc cleanup and smaller fixes

v22.1.0
- PVR Add-on API v9.0.0

Expand Down
127 changes: 69 additions & 58 deletions src/Tvheadend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ CTvheadend::CTvheadend(const kodi::addon::IInstanceInfo& instance)
m_playingLiveStream(false),
m_playingRecording(nullptr)
{
m_dmx.reserve(m_settings->GetTotalTuners());
for (int i = 0; i < 1 || i < m_settings->GetTotalTuners(); i++)
{
m_dmx.emplace_back(new HTSPDemuxer(m_settings, *this, *m_conn));
Expand Down Expand Up @@ -206,10 +207,10 @@ void CTvheadend::QueryAvailableProfiles(std::unique_lock<std::recursive_mutex>&
if (str)
profile.SetComment(str);

Logger::Log(LogLevel::LEVEL_INFO, " Name: %s, Comment: %s",
profile.GetName().c_str(), profile.GetComment().c_str());
Logger::Log(LogLevel::LEVEL_INFO, " Name: %s, Comment: %s", profile.GetName().c_str(),
profile.GetComment().c_str());

m_profiles.emplace_back(profile);
m_profiles.emplace_back(std::move(profile));
}

htsmsg_destroy(m);
Expand All @@ -218,9 +219,8 @@ void CTvheadend::QueryAvailableProfiles(std::unique_lock<std::recursive_mutex>&
bool CTvheadend::HasStreamingProfile(const std::string& streamingProfile) const
{
return std::find_if(m_profiles.cbegin(), m_profiles.cend(),
[&streamingProfile](const Profile& profile) {
return profile.GetName() == streamingProfile;
}) != m_profiles.cend();
[&streamingProfile](const Profile& profile)
{ return profile.GetName() == streamingProfile; }) != m_profiles.cend();
}

/* **************************************************************************
Expand All @@ -246,6 +246,7 @@ PVR_ERROR CTvheadend::GetChannelGroups(bool radio, kodi::addon::PVRChannelGroups
{
std::lock_guard<std::recursive_mutex> lock(m_mutex);

tags.reserve(m_tags.size());
for (const auto& entry : m_tags)
{
/* Does group contain channels of the requested type? */
Expand All @@ -260,14 +261,14 @@ PVR_ERROR CTvheadend::GetChannelGroups(bool radio, kodi::addon::PVRChannelGroups
tag.SetIsRadio(radio);
tag.SetPosition(entry.second.GetIndex());

tags.emplace_back(tag);
tags.emplace_back(std::move(tag));
}
}

for (const auto& tag : tags)
{
/* Callback. */
results.Add(tag);
results.Add(std::move(tag));
}

return PVR_ERROR_NO_ERROR;
Expand All @@ -284,13 +285,13 @@ PVR_ERROR CTvheadend::GetChannelGroupMembers(const kodi::addon::PVRChannelGroup&
std::lock_guard<std::recursive_mutex> lock(m_mutex);

// Find the tag
const auto it = std::find_if(m_tags.cbegin(), m_tags.cend(), [group](const TagMapEntry& tag) {
return tag.second.GetName() == group.GetGroupName();
});
const auto it = std::find_if(m_tags.cbegin(), m_tags.cend(), [&group](const TagMapEntry& tag)
{ return tag.second.GetName() == group.GetGroupName(); });

if (it != m_tags.cend())
{
// Find all channels in this group that are of the correct type
gms.reserve(it->second.GetChannels().size());
for (const auto& channelId : it->second.GetChannels())
{
auto cit = m_channels.find(channelId);
Expand All @@ -304,7 +305,7 @@ PVR_ERROR CTvheadend::GetChannelGroupMembers(const kodi::addon::PVRChannelGroup&
gm.SetChannelNumber(cit->second.GetNum());
gm.SetSubChannelNumber(cit->second.GetNumMinor());

gms.emplace_back(gm);
gms.emplace_back(std::move(gm));
}
}
}
Expand All @@ -313,7 +314,7 @@ PVR_ERROR CTvheadend::GetChannelGroupMembers(const kodi::addon::PVRChannelGroup&
for (const auto& gm : gms)
{
/* Callback. */
results.Add(gm);
results.Add(std::move(gm));
}

return PVR_ERROR_NO_ERROR;
Expand Down Expand Up @@ -342,6 +343,7 @@ PVR_ERROR CTvheadend::GetChannels(bool radio, kodi::addon::PVRChannelsResultSet&
{
std::lock_guard<std::recursive_mutex> lock(m_mutex);

channels.reserve(m_channels.size());
for (const auto& entry : m_channels)
{
const auto& channel = entry.second;
Expand All @@ -359,22 +361,23 @@ PVR_ERROR CTvheadend::GetChannels(bool radio, kodi::addon::PVRChannelsResultSet&
chn.SetChannelName(channel.GetName());
chn.SetIconPath(channel.GetIcon());

channels.emplace_back(chn);
channels.emplace_back(std::move(chn));
}
}

for (const auto& channel : channels)
{
/* Callback. */
results.Add(channel);
results.Add(std::move(channel));
}

return PVR_ERROR_NO_ERROR;
}

PVR_ERROR CTvheadend::GetChannelStreamProperties(const kodi::addon::PVRChannel& channel,
PVR_SOURCE source,
std::vector<kodi::addon::PVRStreamProperty>& properties)
PVR_ERROR CTvheadend::GetChannelStreamProperties(
const kodi::addon::PVRChannel& channel,
PVR_SOURCE source,
std::vector<kodi::addon::PVRStreamProperty>& properties)
{
if (!m_settings->GetStreamingHTTP())
return PVR_ERROR_NO_ERROR;
Expand Down Expand Up @@ -476,6 +479,7 @@ PVR_ERROR CTvheadend::GetRecordings(bool deleted, kodi::addon::PVRRecordingsResu
std::lock_guard<std::recursive_mutex> lock(m_mutex);
char buf[128];

recs.reserve(m_recordings.size());
for (const auto& entry : m_recordings)
{
const auto& recording = entry.second;
Expand Down Expand Up @@ -604,14 +608,14 @@ PVR_ERROR CTvheadend::GetRecordings(bool deleted, kodi::addon::PVRRecordingsResu
/* parental age rating source*/
rec.SetParentalRatingSource(recording.GetRatingSource());

recs.emplace_back(rec);
recs.emplace_back(std::move(rec));
}
}

for (const auto& rec : recs)
{
/* Callback. */
results.Add(rec);
results.Add(std::move(rec));
}

return PVR_ERROR_NO_ERROR;
Expand Down Expand Up @@ -684,7 +688,7 @@ PVR_ERROR CTvheadend::GetRecordingEdl(const kodi::addon::PVRRecording& rec,
entry.SetType(PVR_EDL_TYPE_COMBREAK);
break;
}
edl.emplace_back(entry);
edl.emplace_back(std::move(entry));

Logger::Log(LogLevel::LEVEL_DEBUG, "edl start:%d end:%d action:%d", start, end, type);
}
Expand Down Expand Up @@ -1092,12 +1096,11 @@ bool CTvheadend::CreateTimer(const Recording& tvhTmr, kodi::addon::PVRTimer& tmr
tmr.SetGenreType(0); // not supported by tvh?
tmr.SetGenreSubType(0); // not supported by tvh?
tmr.SetFullTextEpgSearch(false); // n/a for one-shot timers
tmr.SetParentClientIndex(
tmr.GetTimerType() == TIMER_ONCE_CREATED_BY_TIMEREC
? m_timeRecordings.GetTimerIntIdFromStringId(tvhTmr.GetTimerecId())
: tmr.GetTimerType() == TIMER_ONCE_CREATED_BY_AUTOREC
? m_autoRecordings.GetTimerIntIdFromStringId(tvhTmr.GetAutorecId())
: 0);
tmr.SetParentClientIndex(tmr.GetTimerType() == TIMER_ONCE_CREATED_BY_TIMEREC
? m_timeRecordings.GetTimerIntIdFromStringId(tvhTmr.GetTimerecId())
: tmr.GetTimerType() == TIMER_ONCE_CREATED_BY_AUTOREC
? m_autoRecordings.GetTimerIntIdFromStringId(tvhTmr.GetAutorecId())
: 0);
return true;
}

Expand All @@ -1111,6 +1114,7 @@ PVR_ERROR CTvheadend::GetTimers(kodi::addon::PVRTimersResultSet& results)
std::lock_guard<std::recursive_mutex> lock(m_mutex);

/* One-shot timers */
timers.reserve(m_recordings.size());
for (const auto& entry : m_recordings)
{
const auto& recording = entry.second;
Expand All @@ -1121,7 +1125,7 @@ PVR_ERROR CTvheadend::GetTimers(kodi::addon::PVRTimersResultSet& results)
/* Setup entry */
kodi::addon::PVRTimer tmr;
if (CreateTimer(recording, tmr))
timers.emplace_back(tmr);
timers.emplace_back(std::move(tmr));
}

/* Time-based repeating timers */
Expand All @@ -1134,7 +1138,7 @@ PVR_ERROR CTvheadend::GetTimers(kodi::addon::PVRTimersResultSet& results)
for (const auto& timer : timers)
{
/* Callback. */
results.Add(timer);
results.Add(std::move(timer));
}

return PVR_ERROR_NO_ERROR;
Expand Down Expand Up @@ -1401,7 +1405,7 @@ void CTvheadend::TransferEvent(kodi::addon::PVREPGTagsResultSet& results, const
CreateEvent(event, tag);

/* Transfer event to Kodi */
results.Add(tag);
results.Add(std::move(tag));
}

PVR_ERROR CTvheadend::GetEPGForChannel(int channelUid,
Expand Down Expand Up @@ -1889,7 +1893,7 @@ void CTvheadend::PushEpgEventUpdate(const Event& epg, EPG_EVENT_STATE state)
SHTSPEvent event = SHTSPEvent(HTSP_EVENT_EPG_UPDATE, epg, state);

if (std::find(m_events.begin(), m_events.end(), event) == m_events.end())
m_events.emplace_back(event);
m_events.emplace_back(std::move(event));
}

void CTvheadend::SyncInitCompleted()
Expand Down Expand Up @@ -2004,30 +2008,36 @@ void CTvheadend::SyncEpgCompleted()

/* Schedules */
std::vector<std::pair<uint32_t, uint32_t>> deletedEvents;
utilities::erase_if(m_schedules, [&](const ScheduleMapEntry& entry) {
if (entry.second.IsDirty())
{
// all events are dirty too!
for (auto& evt : entry.second.GetEvents())
deletedEvents.emplace_back(std::make_pair(evt.second.GetId() /* event uid */,
entry.second.GetId() /* channel uid */));
return true;
}
return false;
});
utilities::erase_if(m_schedules,
[&](const ScheduleMapEntry& entry)
{
if (entry.second.IsDirty())
{
// all events are dirty too!
for (auto& evt : entry.second.GetEvents())
deletedEvents.emplace_back(
std::make_pair(evt.second.GetId() /* event uid */,
entry.second.GetId() /* channel uid */));
return true;
}
return false;
});

/* Events */
for (auto& entry : m_schedules)
{
utilities::erase_if(entry.second.GetEvents(), [&](const EventUidsMapEntry& mapEntry) {
if (mapEntry.second.IsDirty())
{
deletedEvents.emplace_back(std::make_pair(mapEntry.second.GetId() /* event uid */,
entry.second.GetId() /* channel uid */));
return true;
}
return false;
});
utilities::erase_if(entry.second.GetEvents(),
[&](const EventUidsMapEntry& mapEntry)
{
if (mapEntry.second.IsDirty())
{
deletedEvents.emplace_back(
std::make_pair(mapEntry.second.GetId() /* event uid */,
entry.second.GetId() /* channel uid */));
return true;
}
return false;
});
}

for (auto& entry : deletedEvents)
Expand Down Expand Up @@ -2552,7 +2562,7 @@ void CTvheadend::ParseRecordingAddOrUpdate(htsmsg_t* msg, bool bAdd)
str = htsmsg_get_str(msg, "ratingLabel");
if (str)
rec.SetRatingLabel(str);

str = htsmsg_get_str(msg, "ratingIcon");
if (str)
rec.SetRatingIcon(GetImageURL(str));
Expand Down Expand Up @@ -2638,8 +2648,8 @@ void CTvheadend::ParseRecordingAddOrUpdate(htsmsg_t* msg, bool bAdd)
{
const std::string error = rec.GetError().empty() ? "n/a" : rec.GetError();

Logger::Log(LogLevel::LEVEL_DEBUG, "recording id:%d, state:%s, title:%s, error:%s",
rec.GetId(), state, rec.GetTitle().c_str(), error.c_str());
Logger::Log(LogLevel::LEVEL_DEBUG, "recording id:%d, state:%s, title:%s, error:%s", rec.GetId(),
state, rec.GetTitle().c_str(), error.c_str());

if (m_asyncState.GetState() > ASYNC_DVR)
{
Expand Down Expand Up @@ -2745,14 +2755,14 @@ bool CTvheadend::ParseEvent(htsmsg_t* msg, bool bAdd, Event& evt)
if (!htsmsg_get_u32(msg, "ageRating", &u32))
evt.SetAge(u32);

str = htsmsg_get_str(msg, "ratingLabel"); // HTSP v36 required
str = htsmsg_get_str(msg, "ratingLabel"); // HTSP v36 required
if (str)
evt.SetRatingLabel(str);

str = htsmsg_get_str(msg, "ratingIcon"); // HTSP v36 required
str = htsmsg_get_str(msg, "ratingIcon"); // HTSP v36 required
if (str)
evt.SetRatingIcon(GetImageURL(str));

str = htsmsg_get_str(msg, "ratingAuthority");
if (str)
{
Expand Down Expand Up @@ -3143,7 +3153,8 @@ PVR_ERROR CTvheadend::GetStreamTimes(kodi::addon::PVRStreamTimes& times)
{
if (m_playingRecording->GetFilesStart() > 0)
{
times.SetPTSEnd((std::time(nullptr) - m_playingRecording->GetFilesStart()) * STREAM_TIME_BASE);
times.SetPTSEnd((std::time(nullptr) - m_playingRecording->GetFilesStart()) *
STREAM_TIME_BASE);
}
else
{
Expand Down
7 changes: 4 additions & 3 deletions src/Tvheadend.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,10 @@ class ATTR_DLL_LOCAL CTvheadend : public kodi::addon::CInstancePVRClient,

PVR_ERROR GetChannelsAmount(int& amount) override;
PVR_ERROR GetChannels(bool radio, kodi::addon::PVRChannelsResultSet& results) override;
PVR_ERROR GetChannelStreamProperties(const kodi::addon::PVRChannel& channel,
PVR_SOURCE source,
std::vector<kodi::addon::PVRStreamProperty>& properties) override;
PVR_ERROR GetChannelStreamProperties(
const kodi::addon::PVRChannel& channel,
PVR_SOURCE source,
std::vector<kodi::addon::PVRStreamProperty>& properties) override;

PVR_ERROR GetRecordingsAmount(bool deleted, int& amount) override;
PVR_ERROR GetRecordings(bool deleted, kodi::addon::PVRRecordingsResultSet& results) override;
Expand Down
4 changes: 3 additions & 1 deletion src/tvheadend/AutoRecordings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ int AutoRecordings::GetAutorecTimerCount() const

void AutoRecordings::GetAutorecTimers(std::vector<kodi::addon::PVRTimer>& timers)
{
timers.reserve(timers.size() + m_autoRecordings.size());

for (const auto& rec : m_autoRecordings)
{
/* Setup entry */
Expand Down Expand Up @@ -103,7 +105,7 @@ void AutoRecordings::GetAutorecTimers(std::vector<kodi::addon::PVRTimer>& timers
tmr.SetFullTextEpgSearch(rec.second.GetFulltext());
tmr.SetParentClientIndex(0);

timers.emplace_back(tmr);
timers.emplace_back(std::move(tmr));
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/tvheadend/ChannelTuningPredictor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ ChannelPair ChannelTuningPredictor::MakeChannelPair(const entity::Channel& chann

ChannelPairIterator ChannelTuningPredictor::GetIterator(uint32_t channelId) const
{
return std::find_if(
m_channels.cbegin(), m_channels.cend(),
[channelId](const ChannelPair& channel) { return channel.first == channelId; });
return std::find_if(m_channels.cbegin(), m_channels.cend(),
[channelId](const ChannelPair& channel)
{ return channel.first == channelId; });
}

uint32_t ChannelTuningPredictor::PredictNextChannelId(uint32_t tuningFrom, uint32_t tuningTo) const
Expand Down
Loading

0 comments on commit 2674084

Please sign in to comment.