From 3c1be980d877a43752aaeac84ad2c7e23d7f1221 Mon Sep 17 00:00:00 2001 From: Kai Sommerfeld Date: Sun, 6 Oct 2019 12:42:23 +0200 Subject: [PATCH] Code cleanup: Apply Kodi clang-format ruleset. --- lib/libhts/htsmsg.h | 1 + pvr.hts/addon.xml.in | 2 +- pvr.hts/changelog.txt | 3 + src/Tvheadend.cpp | 1205 ++++++++++----------- src/Tvheadend.h | 190 ++-- src/client.cpp | 730 +++++-------- src/client.h | 6 +- src/tvheadend/AutoRecordings.cpp | 162 +-- src/tvheadend/AutoRecordings.h | 29 +- src/tvheadend/ChannelTuningPredictor.cpp | 22 +- src/tvheadend/ChannelTuningPredictor.h | 132 +-- src/tvheadend/HTSPConnection.cpp | 192 ++-- src/tvheadend/HTSPConnection.h | 32 +- src/tvheadend/HTSPDemuxer.cpp | 229 ++-- src/tvheadend/HTSPDemuxer.h | 61 +- src/tvheadend/HTSPMessage.h | 12 +- src/tvheadend/HTSPTypes.h | 103 +- src/tvheadend/HTSPVFS.cpp | 101 +- src/tvheadend/HTSPVFS.h | 14 +- src/tvheadend/IHTSPConnectionListener.h | 5 +- src/tvheadend/Profile.h | 43 +- src/tvheadend/Settings.cpp | 79 +- src/tvheadend/Settings.h | 253 ++--- src/tvheadend/Subscription.cpp | 71 +- src/tvheadend/Subscription.h | 166 +-- src/tvheadend/TimeRecordings.cpp | 138 +-- src/tvheadend/TimeRecordings.h | 29 +- src/tvheadend/entity/AutoRecording.cpp | 22 +- src/tvheadend/entity/AutoRecording.h | 71 +- src/tvheadend/entity/Channel.h | 121 +-- src/tvheadend/entity/Entity.h | 58 +- src/tvheadend/entity/Event.cpp | 10 +- src/tvheadend/entity/Event.h | 302 +++--- src/tvheadend/entity/Recording.h | 439 ++++---- src/tvheadend/entity/RecordingBase.cpp | 52 +- src/tvheadend/entity/RecordingBase.h | 124 +-- src/tvheadend/entity/Schedule.cpp | 2 +- src/tvheadend/entity/Schedule.h | 45 +- src/tvheadend/entity/Tag.cpp | 14 +- src/tvheadend/entity/Tag.h | 66 +- src/tvheadend/entity/TimeRecording.cpp | 14 +- src/tvheadend/entity/TimeRecording.h | 51 +- src/tvheadend/status/DescrambleInfo.cpp | 20 +- src/tvheadend/status/DescrambleInfo.h | 80 +- src/tvheadend/status/Quality.h | 62 +- src/tvheadend/status/QueueStatus.h | 54 +- src/tvheadend/status/SourceInfo.h | 52 +- src/tvheadend/status/TimeshiftStatus.h | 54 +- src/tvheadend/utilities/AsyncState.cpp | 13 +- src/tvheadend/utilities/AsyncState.h | 70 +- src/tvheadend/utilities/LifetimeMapper.h | 54 +- src/tvheadend/utilities/LocalizedString.h | 56 +- src/tvheadend/utilities/Logger.cpp | 11 +- src/tvheadend/utilities/Logger.h | 70 +- src/tvheadend/utilities/Utilities.h | 30 +- src/tvheadend/xbmc_codec_descriptor.hpp | 8 +- 56 files changed, 2906 insertions(+), 3129 deletions(-) diff --git a/lib/libhts/htsmsg.h b/lib/libhts/htsmsg.h index 7f45d9f2..ecd89353 100644 --- a/lib/libhts/htsmsg.h +++ b/lib/libhts/htsmsg.h @@ -21,6 +21,7 @@ #define HTSMSG_H_ #include +#include #include "htsq.h" #define HTSMSG_ERR_FIELD_NOT_FOUND -1 diff --git a/pvr.hts/addon.xml.in b/pvr.hts/addon.xml.in index e4837186..5788e82f 100644 --- a/pvr.hts/addon.xml.in +++ b/pvr.hts/addon.xml.in @@ -1,7 +1,7 @@ @ADDON_DEPENDS@ diff --git a/pvr.hts/changelog.txt b/pvr.hts/changelog.txt index ba134d3d..e3f74282 100644 --- a/pvr.hts/changelog.txt +++ b/pvr.hts/changelog.txt @@ -1,3 +1,6 @@ +5.2.1 +- Code cleanup: Apply Kodi clang-format ruleset. + 5.2.0 - Update: Recompile for 6.1.0 PVR Addon API compatibility diff --git a/src/Tvheadend.cpp b/src/Tvheadend.cpp index 2ea14aa3..4b6ca5e4 100644 --- a/src/Tvheadend.cpp +++ b/src/Tvheadend.cpp @@ -21,10 +21,6 @@ #include "Tvheadend.h" -#include -#include -#include - #include "tvheadend/HTSPConnection.h" #include "tvheadend/HTSPDemuxer.h" #include "tvheadend/HTSPMessage.h" @@ -35,17 +31,27 @@ #include "tvheadend/utilities/Logger.h" #include "tvheadend/utilities/Utilities.h" +#include +#include +#include + using namespace ADDON; using namespace P8PLATFORM; using namespace tvheadend; using namespace tvheadend::entity; using namespace tvheadend::utilities; -CTvheadend::CTvheadend(PVR_PROPERTIES *pvrProps) - : m_conn(new HTSPConnection(*this)), m_streamchange(false), m_vfs(new HTSPVFS(*m_conn)), - m_queue((size_t)-1), m_asyncState(Settings::GetInstance().GetResponseTimeout()), - m_timeRecordings(*m_conn), m_autoRecordings(*m_conn), m_epgMaxDays(pvrProps->iEpgMaxDays), - m_playingLiveStream(false), m_playingRecording(nullptr) +CTvheadend::CTvheadend(PVR_PROPERTIES* pvrProps) + : m_conn(new HTSPConnection(*this)), + m_streamchange(false), + m_vfs(new HTSPVFS(*m_conn)), + m_queue((size_t)-1), + m_asyncState(Settings::GetInstance().GetResponseTimeout()), + m_timeRecordings(*m_conn), + m_autoRecordings(*m_conn), + m_epgMaxDays(pvrProps->iEpgMaxDays), + m_playingLiveStream(false), + m_playingRecording(nullptr) { for (int i = 0; i < 1 || i < Settings::GetInstance().GetTotalTuners(); i++) { @@ -56,22 +62,22 @@ CTvheadend::CTvheadend(PVR_PROPERTIES *pvrProps) CTvheadend::~CTvheadend() { - for (auto *dmx : m_dmx) + for (auto* dmx : m_dmx) delete dmx; delete m_conn; delete m_vfs; } -void CTvheadend::Start ( void ) +void CTvheadend::Start(void) { CreateThread(); m_conn->Start(); } -void CTvheadend::Stop ( void ) +void CTvheadend::Stop(void) { - for (auto *dmx : m_dmx) + for (auto* dmx : m_dmx) dmx->Close(); m_conn->Stop(); @@ -82,12 +88,12 @@ void CTvheadend::Stop ( void ) * Miscellaneous * *************************************************************************/ -PVR_ERROR CTvheadend::GetDriveSpace ( long long *total, long long *used ) +PVR_ERROR CTvheadend::GetDriveSpace(long long* total, long long* used) { int64_t s64; CLockObject lock(m_conn->Mutex()); - htsmsg_t *m = htsmsg_create_map(); + htsmsg_t* m = htsmsg_create_map(); m = m_conn->SendAndWait("getDiskSpace", m); if (m == NULL) return PVR_ERROR_SERVER_ERROR; @@ -98,18 +104,19 @@ PVR_ERROR CTvheadend::GetDriveSpace ( long long *total, long long *used ) if (htsmsg_get_s64(m, "freediskspace", &s64)) goto error; - *used = *total - (s64 / 1024); + *used = *total - (s64 / 1024); htsmsg_destroy(m); return PVR_ERROR_NO_ERROR; error: htsmsg_destroy(m); - Logger::Log(LogLevel::LEVEL_ERROR, "malformed getDiskSpace response: 'totaldiskspace'/'freediskspace' missing"); + Logger::Log(LogLevel::LEVEL_ERROR, + "malformed getDiskSpace response: 'totaldiskspace'/'freediskspace' missing"); return PVR_ERROR_SERVER_ERROR; } -std::string CTvheadend::GetImageURL ( const char *str ) +std::string CTvheadend::GetImageURL(const char* str) { if (*str != '/') { @@ -127,7 +134,7 @@ std::string CTvheadend::GetImageURL ( const char *str ) void CTvheadend::QueryAvailableProfiles() { /* Build message */ - htsmsg_t *m = htsmsg_create_map(); + htsmsg_t* m = htsmsg_create_map(); /* Send */ { @@ -139,8 +146,8 @@ void CTvheadend::QueryAvailableProfiles() if (m == nullptr) return; - htsmsg_t *l; - htsmsg_field_t *f; + htsmsg_t* l; + htsmsg_field_t* f; if ((l = htsmsg_get_list(m, "profiles")) == NULL) { @@ -152,7 +159,7 @@ void CTvheadend::QueryAvailableProfiles() /* Process */ HTSMSG_FOREACH(f, l) { - const char *str; + const char* str; Profile profile; if ((str = htsmsg_get_str(&f->hmf_msg, "uuid")) != NULL) @@ -163,7 +170,7 @@ void CTvheadend::QueryAvailableProfiles() profile.SetComment(str); Logger::Log(LogLevel::LEVEL_DEBUG, "profile name: %s, comment: %s added", - profile.GetName().c_str(), profile.GetComment().c_str()); + profile.GetName().c_str(), profile.GetComment().c_str()); m_profiles.emplace_back(profile); } @@ -171,51 +178,47 @@ void CTvheadend::QueryAvailableProfiles() htsmsg_destroy(m); } -bool CTvheadend::HasStreamingProfile(const std::string &streamingProfile) const +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(); + return std::find_if(m_profiles.cbegin(), m_profiles.cend(), + [&streamingProfile](const Profile& profile) { + return profile.GetName() == streamingProfile; + }) != m_profiles.cend(); } /* ************************************************************************** * Tags * *************************************************************************/ -int CTvheadend::GetTagCount ( void ) +int CTvheadend::GetTagCount(void) { if (!m_asyncState.WaitForState(ASYNC_DVR)) return 0; - + CLockObject lock(m_mutex); return m_tags.size(); } -PVR_ERROR CTvheadend::GetTags ( ADDON_HANDLE handle, bool bRadio ) +PVR_ERROR CTvheadend::GetTags(ADDON_HANDLE handle, bool bRadio) { if (!m_asyncState.WaitForState(ASYNC_DVR)) return PVR_ERROR_FAILED; - + std::vector tags; { CLockObject lock(m_mutex); - for (const auto &entry : m_tags) + for (const auto& entry : m_tags) { /* Does group contain channels of the requested type? */ /* Note: tvheadend groups can contain both radio and tv channels. */ /* Thus, one tvheadend group can 'map' to two Kodi groups. */ - if (!entry.second.ContainsChannelType(bRadio ? CHANNEL_TYPE_RADIO : CHANNEL_TYPE_TV, GetChannels())) + if (!entry.second.ContainsChannelType(bRadio ? CHANNEL_TYPE_RADIO : CHANNEL_TYPE_TV, + GetChannels())) continue; - PVR_CHANNEL_GROUP tag = { 0 }; - strncpy(tag.strGroupName, entry.second.GetName().c_str(), - sizeof(tag.strGroupName) - 1); + PVR_CHANNEL_GROUP tag = {0}; + strncpy(tag.strGroupName, entry.second.GetName().c_str(), sizeof(tag.strGroupName) - 1); tag.bIsRadio = bRadio; tag.iPosition = entry.second.GetIndex(); tags.emplace_back(tag); @@ -228,42 +231,36 @@ PVR_ERROR CTvheadend::GetTags ( ADDON_HANDLE handle, bool bRadio ) /* Callback. */ PVR->TransferChannelGroup(handle, &(*it)); } - + return PVR_ERROR_NO_ERROR; } -PVR_ERROR CTvheadend::GetTagMembers - ( ADDON_HANDLE handle, const PVR_CHANNEL_GROUP &group ) +PVR_ERROR CTvheadend::GetTagMembers(ADDON_HANDLE handle, const PVR_CHANNEL_GROUP& group) { if (!m_asyncState.WaitForState(ASYNC_DVR)) return PVR_ERROR_FAILED; - + std::vector gms; { CLockObject lock(m_mutex); // Find the tag - const auto it = std::find_if( - m_tags.cbegin(), - m_tags.cend(), - [group](const TagMapEntry &tag) - { + const auto it = std::find_if(m_tags.cbegin(), m_tags.cend(), [group](const TagMapEntry& tag) { return tag.second.GetName() == group.strGroupName; }); if (it != m_tags.cend()) { // Find all channels in this group that are of the correct type - for (const auto &channelId : it->second.GetChannels()) + for (const auto& channelId : it->second.GetChannels()) { auto cit = m_channels.find(channelId); - if (cit != m_channels.cend() && cit->second.GetType() == (group.bIsRadio ? - CHANNEL_TYPE_RADIO : CHANNEL_TYPE_TV)) + if (cit != m_channels.cend() && + cit->second.GetType() == (group.bIsRadio ? CHANNEL_TYPE_RADIO : CHANNEL_TYPE_TV)) { - PVR_CHANNEL_GROUP_MEMBER gm = { 0 }; - strncpy( - gm.strGroupName, group.strGroupName, sizeof(gm.strGroupName) - 1); + PVR_CHANNEL_GROUP_MEMBER gm = {0}; + strncpy(gm.strGroupName, group.strGroupName, sizeof(gm.strGroupName) - 1); gm.iChannelUniqueId = cit->second.GetId(); gm.iChannelNumber = cit->second.GetNum(); gm.iSubChannelNumber = cit->second.GetNumMinor(); @@ -287,43 +284,41 @@ PVR_ERROR CTvheadend::GetTagMembers * Channels * *************************************************************************/ -int CTvheadend::GetChannelCount ( void ) +int CTvheadend::GetChannelCount(void) { if (!m_asyncState.WaitForState(ASYNC_DVR)) return 0; - + CLockObject lock(m_mutex); return m_channels.size(); } -PVR_ERROR CTvheadend::GetChannels ( ADDON_HANDLE handle, bool radio ) +PVR_ERROR CTvheadend::GetChannels(ADDON_HANDLE handle, bool radio) { if (!m_asyncState.WaitForState(ASYNC_DVR)) return PVR_ERROR_FAILED; - + std::vector channels; { CLockObject lock(m_mutex); - - for (const auto &entry : m_channels) + + for (const auto& entry : m_channels) { - const auto &channel = entry.second; + const auto& channel = entry.second; if (channel.GetType() != (radio ? CHANNEL_TYPE_RADIO : CHANNEL_TYPE_TV)) continue; - PVR_CHANNEL chn = { 0 }; + PVR_CHANNEL chn = {0}; - chn.iUniqueId = channel.GetId(); - chn.bIsRadio = radio; - chn.iChannelNumber = channel.GetNum(); + chn.iUniqueId = channel.GetId(); + chn.bIsRadio = radio; + chn.iChannelNumber = channel.GetNum(); chn.iSubChannelNumber = channel.GetNumMinor(); chn.iEncryptionSystem = channel.GetCaid(); - chn.bIsHidden = false; - strncpy(chn.strChannelName, channel.GetName().c_str(), - sizeof(chn.strChannelName) - 1); - strncpy(chn.strIconPath, channel.GetIcon().c_str(), - sizeof(chn.strIconPath) - 1); + chn.bIsHidden = false; + strncpy(chn.strChannelName, channel.GetName().c_str(), sizeof(chn.strChannelName) - 1); + strncpy(chn.strIconPath, channel.GetIcon().c_str(), sizeof(chn.strIconPath) - 1); channels.emplace_back(chn); } } @@ -342,33 +337,34 @@ PVR_ERROR CTvheadend::GetChannels ( ADDON_HANDLE handle, bool radio ) * Recordings * *************************************************************************/ -PVR_ERROR CTvheadend::SendDvrDelete ( uint32_t id, const char *method ) +PVR_ERROR CTvheadend::SendDvrDelete(uint32_t id, const char* method) { uint32_t u32; CLockObject lock(m_conn->Mutex()); /* Build message */ - htsmsg_t *m = htsmsg_create_map(); + htsmsg_t* m = htsmsg_create_map(); htsmsg_add_u32(m, "id", id); /* Send and wait a bit longer than usual */ - if ((m = m_conn->SendAndWait(method, m, - std::max(30000, Settings::GetInstance().GetResponseTimeout()))) == NULL) + if ((m = m_conn->SendAndWait( + method, m, std::max(30000, Settings::GetInstance().GetResponseTimeout()))) == NULL) return PVR_ERROR_SERVER_ERROR; /* Check for error */ if (htsmsg_get_u32(m, "success", &u32)) { - Logger::Log(LogLevel::LEVEL_ERROR, "malformed deleteDvrEntry/cancelDvrEntry response: 'success' missing"); + Logger::Log(LogLevel::LEVEL_ERROR, + "malformed deleteDvrEntry/cancelDvrEntry response: 'success' missing"); u32 = PVR_ERROR_FAILED; } htsmsg_destroy(m); - return u32 > 0 ? PVR_ERROR_NO_ERROR : PVR_ERROR_FAILED; + return u32 > 0 ? PVR_ERROR_NO_ERROR : PVR_ERROR_FAILED; } -PVR_ERROR CTvheadend::SendDvrUpdate( htsmsg_t* m ) +PVR_ERROR CTvheadend::SendDvrUpdate(htsmsg_t* m) { uint32_t u32; @@ -389,51 +385,45 @@ PVR_ERROR CTvheadend::SendDvrUpdate( htsmsg_t* m ) } htsmsg_destroy(m); - return u32 > 0 ? PVR_ERROR_NO_ERROR : PVR_ERROR_FAILED; + return u32 > 0 ? PVR_ERROR_NO_ERROR : PVR_ERROR_FAILED; } -int CTvheadend::GetRecordingCount ( void ) +int CTvheadend::GetRecordingCount(void) { if (!m_asyncState.WaitForState(ASYNC_EPG)) return 0; CLockObject lock(m_mutex); - return std::count_if( - m_recordings.cbegin(), - m_recordings.cend(), - [](const RecordingMapEntry &entry) - { - return entry.second.IsRecording(); - }); + return std::count_if(m_recordings.cbegin(), m_recordings.cend(), + [](const RecordingMapEntry& entry) { return entry.second.IsRecording(); }); } -PVR_ERROR CTvheadend::GetRecordings ( ADDON_HANDLE handle ) +PVR_ERROR CTvheadend::GetRecordings(ADDON_HANDLE handle) { if (!m_asyncState.WaitForState(ASYNC_EPG)) return PVR_ERROR_FAILED; - + std::vector recs; { CLockObject lock(m_mutex); Channels::const_iterator cit; char buf[128]; - for (const auto &entry : m_recordings) + for (const auto& entry : m_recordings) { - const auto &recording = entry.second; + const auto& recording = entry.second; if (!recording.IsRecording()) continue; /* Setup entry */ - PVR_RECORDING rec = { 0 }; + PVR_RECORDING rec = {0}; /* Channel icon */ if ((cit = m_channels.find(recording.GetChannel())) != m_channels.end()) { - strncpy(rec.strIconPath, cit->second.GetIcon().c_str(), - sizeof(rec.strIconPath) - 1); + strncpy(rec.strIconPath, cit->second.GetIcon().c_str(), sizeof(rec.strIconPath) - 1); } /* Channel name */ @@ -441,12 +431,10 @@ PVR_ERROR CTvheadend::GetRecordings ( ADDON_HANDLE handle ) sizeof(rec.strChannelName) - 1); /* Thumbnail image */ - strncpy(rec.strThumbnailPath, recording.GetImage().c_str(), - sizeof(rec.strThumbnailPath) - 1); + strncpy(rec.strThumbnailPath, recording.GetImage().c_str(), sizeof(rec.strThumbnailPath) - 1); /* Fanart image */ - strncpy(rec.strFanartPath, recording.GetFanartImage().c_str(), - sizeof(rec.strFanartPath) - 1); + strncpy(rec.strFanartPath, recording.GetFanartImage().c_str(), sizeof(rec.strFanartPath) - 1); /* ID */ snprintf(buf, sizeof(buf), "%i", recording.GetId()); @@ -520,7 +508,8 @@ PVR_ERROR CTvheadend::GetRecordings ( ADDON_HANDLE handle ) rec.iEpgEventId = recording.GetEventId(); /* channel id */ - rec.iChannelUid = recording.GetChannel() > 0 ? recording.GetChannel() : PVR_CHANNEL_INVALID_UID; + rec.iChannelUid = + recording.GetChannel() > 0 ? recording.GetChannel() : PVR_CHANNEL_INVALID_UID; /* channel type */ switch (recording.GetChannelType()) @@ -551,15 +540,14 @@ PVR_ERROR CTvheadend::GetRecordings ( ADDON_HANDLE handle ) return PVR_ERROR_NO_ERROR; } -PVR_ERROR CTvheadend::GetRecordingEdl - ( const PVR_RECORDING &rec, PVR_EDL_ENTRY edl[], int *num ) +PVR_ERROR CTvheadend::GetRecordingEdl(const PVR_RECORDING& rec, PVR_EDL_ENTRY edl[], int* num) { - htsmsg_t *list; - htsmsg_field_t *f; + htsmsg_t* list; + htsmsg_field_t* f; int idx; - + /* Build request */ - htsmsg_t *m = htsmsg_create_map(); + htsmsg_t* m = htsmsg_create_map(); htsmsg_add_u32(m, "id", atoi(rec.strRecordingId)); Logger::Log(LogLevel::LEVEL_DEBUG, "dvr get cutpoints id=%s", rec.strRecordingId); @@ -567,7 +555,7 @@ PVR_ERROR CTvheadend::GetRecordingEdl /* Send and Wait */ { CLockObject lock(m_conn->Mutex()); - + if ((m = m_conn->SendAndWait("getDvrCutpoints", m)) == NULL) return PVR_ERROR_SERVER_ERROR; } @@ -588,23 +576,23 @@ PVR_ERROR CTvheadend::GetRecordingEdl if (f->hmf_type != HMF_MAP) continue; - + /* Full */ if (idx >= *num) break; /* Get fields */ - if (htsmsg_get_u32(&f->hmf_msg, "start", &start) || - htsmsg_get_u32(&f->hmf_msg, "end", &end) || - htsmsg_get_u32(&f->hmf_msg, "type", &type)) + if (htsmsg_get_u32(&f->hmf_msg, "start", &start) || htsmsg_get_u32(&f->hmf_msg, "end", &end) || + htsmsg_get_u32(&f->hmf_msg, "type", &type)) { - Logger::Log(LogLevel::LEVEL_ERROR, "malformed getDvrCutpoints response: invalid EDL entry, will ignore"); + Logger::Log(LogLevel::LEVEL_ERROR, + "malformed getDvrCutpoints response: invalid EDL entry, will ignore"); continue; } /* Build entry */ edl[idx].start = start; - edl[idx].end = end; + edl[idx].end = end; switch (type) { case DVR_ACTION_TYPE_CUT: @@ -625,88 +613,94 @@ PVR_ERROR CTvheadend::GetRecordingEdl Logger::Log(LogLevel::LEVEL_DEBUG, "edl start:%d end:%d action:%d", start, end, type); } - + *num = idx; htsmsg_destroy(m); return PVR_ERROR_NO_ERROR; } -PVR_ERROR CTvheadend::DeleteRecording ( const PVR_RECORDING &rec ) +PVR_ERROR CTvheadend::DeleteRecording(const PVR_RECORDING& rec) { return SendDvrDelete(atoi(rec.strRecordingId), "deleteDvrEntry"); } -PVR_ERROR CTvheadend::RenameRecording ( const PVR_RECORDING &rec ) +PVR_ERROR CTvheadend::RenameRecording(const PVR_RECORDING& rec) { if (m_conn->GetProtocol() < 28) return PVR_ERROR_NOT_IMPLEMENTED; /* Build message */ - htsmsg_t *m = htsmsg_create_map(); - htsmsg_add_u32(m, "id", atoi(rec.strRecordingId)); - htsmsg_add_str(m, "title", rec.strTitle); + htsmsg_t* m = htsmsg_create_map(); + htsmsg_add_u32(m, "id", atoi(rec.strRecordingId)); + htsmsg_add_str(m, "title", rec.strTitle); return SendDvrUpdate(m); } -PVR_ERROR CTvheadend::SetLifetime ( const PVR_RECORDING &rec ) +PVR_ERROR CTvheadend::SetLifetime(const PVR_RECORDING& rec) { if (m_conn->GetProtocol() < 28) return PVR_ERROR_NOT_IMPLEMENTED; - Logger::Log(LogLevel::LEVEL_DEBUG, "Setting lifetime to %i for recording %s", rec.iLifetime, rec.strRecordingId); + Logger::Log(LogLevel::LEVEL_DEBUG, "Setting lifetime to %i for recording %s", rec.iLifetime, + rec.strRecordingId); /* Build message */ - htsmsg_t *m = htsmsg_create_map(); + htsmsg_t* m = htsmsg_create_map(); htsmsg_add_u32(m, "id", atoi(rec.strRecordingId)); if (m_conn->GetProtocol() >= 25) htsmsg_add_u32(m, "removal", LifetimeMapper::KodiToTvh(rec.iLifetime)); // remove from disk else - htsmsg_add_u32(m, "retention", LifetimeMapper::KodiToTvh(rec.iLifetime)); // remove from tvh database + htsmsg_add_u32(m, "retention", + LifetimeMapper::KodiToTvh(rec.iLifetime)); // remove from tvh database return SendDvrUpdate(m); } -PVR_ERROR CTvheadend::SetPlayCount ( const PVR_RECORDING &rec, int playCount ) +PVR_ERROR CTvheadend::SetPlayCount(const PVR_RECORDING& rec, int playCount) { if (m_conn->GetProtocol() < 27 || !Settings::GetInstance().GetDvrPlayStatus()) return PVR_ERROR_NOT_IMPLEMENTED; - Logger::Log(LogLevel::LEVEL_DEBUG, "Setting play count to %i for recording %s", playCount, rec.strRecordingId); + Logger::Log(LogLevel::LEVEL_DEBUG, "Setting play count to %i for recording %s", playCount, + rec.strRecordingId); /* Build message */ - htsmsg_t *m = htsmsg_create_map(); - htsmsg_add_u32(m, "id", atoi(rec.strRecordingId)); + htsmsg_t* m = htsmsg_create_map(); + htsmsg_add_u32(m, "id", atoi(rec.strRecordingId)); htsmsg_add_u32(m, "playcount", playCount); return SendDvrUpdate(m); } -PVR_ERROR CTvheadend::SetPlayPosition ( const PVR_RECORDING &rec, int playPosition ) +PVR_ERROR CTvheadend::SetPlayPosition(const PVR_RECORDING& rec, int playPosition) { if (m_conn->GetProtocol() < 27 || !Settings::GetInstance().GetDvrPlayStatus()) return PVR_ERROR_NOT_IMPLEMENTED; - Logger::Log(LogLevel::LEVEL_DEBUG, "Setting play position to %i for recording %s", playPosition, rec.strRecordingId); + Logger::Log(LogLevel::LEVEL_DEBUG, "Setting play position to %i for recording %s", playPosition, + rec.strRecordingId); /* Build message */ - htsmsg_t *m = htsmsg_create_map(); - htsmsg_add_u32(m, "id", atoi(rec.strRecordingId)); - htsmsg_add_u32(m, "playposition", playPosition >= 0 ? playPosition : 0); // Kodi uses -1 when fully watched + htsmsg_t* m = htsmsg_create_map(); + htsmsg_add_u32(m, "id", atoi(rec.strRecordingId)); + htsmsg_add_u32(m, "playposition", + playPosition >= 0 ? playPosition : 0); // Kodi uses -1 when fully watched return SendDvrUpdate(m); } -int CTvheadend::GetPlayPosition ( const PVR_RECORDING &rec ) +int CTvheadend::GetPlayPosition(const PVR_RECORDING& rec) { if (m_conn->GetProtocol() < 27 || !Settings::GetInstance().GetDvrPlayStatus()) return -1; CLockObject lock(m_mutex); - const auto &it = m_recordings.find(atoi(rec.strRecordingId)); + const auto& it = m_recordings.find(atoi(rec.strRecordingId)); if (it != m_recordings.end() && it->second.IsRecording()) { - Logger::Log(LogLevel::LEVEL_DEBUG, "Getting play position %i for recording %s", it->second.GetPlayPosition(), rec.strTitle); + Logger::Log(LogLevel::LEVEL_DEBUG, "Getting play position %i for recording %s", + it->second.GetPlayPosition(), rec.strTitle); return it->second.GetPlayPosition(); } @@ -719,24 +713,24 @@ struct TimerType : PVR_TIMER_TYPE { TimerType(unsigned int id, unsigned int attributes, - const std::string &description, - const std::vector< std::pair > &priorityValues - = std::vector< std::pair >(), - const std::vector< std::pair > &lifetimeValues - = std::vector< std::pair >(), - const std::vector< std::pair > &dupEpisodesValues - = std::vector< std::pair >()) + const std::string& description, + const std::vector>& priorityValues = + std::vector>(), + const std::vector>& lifetimeValues = + std::vector>(), + const std::vector>& dupEpisodesValues = + std::vector>()) { memset(this, 0, sizeof(PVR_TIMER_TYPE)); - iId = id; - iAttributes = attributes; - iPrioritiesSize = priorityValues.size(); - iPrioritiesDefault = Settings::GetInstance().GetDvrPriority(); - iPreventDuplicateEpisodesSize = dupEpisodesValues.size(); + iId = id; + iAttributes = attributes; + iPrioritiesSize = priorityValues.size(); + iPrioritiesDefault = Settings::GetInstance().GetDvrPriority(); + iPreventDuplicateEpisodesSize = dupEpisodesValues.size(); iPreventDuplicateEpisodesDefault = Settings::GetInstance().GetDvrDupdetect(); - iLifetimesSize = lifetimeValues.size(); - iLifetimesDefault = LifetimeMapper::TvhToKodi(Settings::GetInstance().GetDvrLifetime()); + iLifetimesSize = lifetimeValues.size(); + iLifetimesDefault = LifetimeMapper::TvhToKodi(Settings::GetInstance().GetDvrLifetime()); strncpy(strDescription, description.c_str(), sizeof(strDescription) - 1); @@ -744,21 +738,24 @@ struct TimerType : PVR_TIMER_TYPE for (auto it = priorityValues.begin(); it != priorityValues.end(); ++it, ++i) { priorities[i].iValue = it->first; - strncpy(priorities[i].strDescription, it->second.c_str(), sizeof(priorities[i].strDescription) - 1); + strncpy(priorities[i].strDescription, it->second.c_str(), + sizeof(priorities[i].strDescription) - 1); } i = 0; for (auto it = dupEpisodesValues.begin(); it != dupEpisodesValues.end(); ++it, ++i) { preventDuplicateEpisodes[i].iValue = it->first; - strncpy(preventDuplicateEpisodes[i].strDescription, it->second.c_str(), sizeof(preventDuplicateEpisodes[i].strDescription) - 1); + strncpy(preventDuplicateEpisodes[i].strDescription, it->second.c_str(), + sizeof(preventDuplicateEpisodes[i].strDescription) - 1); } i = 0; for (auto it = lifetimeValues.begin(); it != lifetimeValues.end(); ++it, ++i) { lifetimes[i].iValue = it->first; - strncpy(lifetimes[i].strDescription, it->second.c_str(), sizeof(lifetimes[i].strDescription) - 1); + strncpy(lifetimes[i].strDescription, it->second.c_str(), + sizeof(lifetimes[i].strDescription) - 1); } } }; @@ -768,207 +765,200 @@ struct TimerType : PVR_TIMER_TYPE void CTvheadend::GetLivetimeValues(std::vector>& lifetimeValues) const { lifetimeValues = { - { LifetimeMapper::TvhToKodi(DVR_RET_1DAY), LocalizedString(30375).Get() }, - { LifetimeMapper::TvhToKodi(DVR_RET_3DAY), LocalizedString(30376).Get() }, - { LifetimeMapper::TvhToKodi(DVR_RET_5DAY), LocalizedString(30377).Get() }, - { LifetimeMapper::TvhToKodi(DVR_RET_1WEEK), LocalizedString(30378).Get() }, - { LifetimeMapper::TvhToKodi(DVR_RET_2WEEK), LocalizedString(30379).Get() }, - { LifetimeMapper::TvhToKodi(DVR_RET_3WEEK), LocalizedString(30380).Get() }, - { LifetimeMapper::TvhToKodi(DVR_RET_1MONTH), LocalizedString(30381).Get() }, - { LifetimeMapper::TvhToKodi(DVR_RET_2MONTH), LocalizedString(30382).Get() }, - { LifetimeMapper::TvhToKodi(DVR_RET_3MONTH), LocalizedString(30383).Get() }, - { LifetimeMapper::TvhToKodi(DVR_RET_6MONTH), LocalizedString(30384).Get() }, - { LifetimeMapper::TvhToKodi(DVR_RET_1YEAR), LocalizedString(30385).Get() }, - { LifetimeMapper::TvhToKodi(DVR_RET_2YEARS), LocalizedString(30386).Get() }, - { LifetimeMapper::TvhToKodi(DVR_RET_3YEARS), LocalizedString(30387).Get() }, + {LifetimeMapper::TvhToKodi(DVR_RET_1DAY), LocalizedString(30375).Get()}, + {LifetimeMapper::TvhToKodi(DVR_RET_3DAY), LocalizedString(30376).Get()}, + {LifetimeMapper::TvhToKodi(DVR_RET_5DAY), LocalizedString(30377).Get()}, + {LifetimeMapper::TvhToKodi(DVR_RET_1WEEK), LocalizedString(30378).Get()}, + {LifetimeMapper::TvhToKodi(DVR_RET_2WEEK), LocalizedString(30379).Get()}, + {LifetimeMapper::TvhToKodi(DVR_RET_3WEEK), LocalizedString(30380).Get()}, + {LifetimeMapper::TvhToKodi(DVR_RET_1MONTH), LocalizedString(30381).Get()}, + {LifetimeMapper::TvhToKodi(DVR_RET_2MONTH), LocalizedString(30382).Get()}, + {LifetimeMapper::TvhToKodi(DVR_RET_3MONTH), LocalizedString(30383).Get()}, + {LifetimeMapper::TvhToKodi(DVR_RET_6MONTH), LocalizedString(30384).Get()}, + {LifetimeMapper::TvhToKodi(DVR_RET_1YEAR), LocalizedString(30385).Get()}, + {LifetimeMapper::TvhToKodi(DVR_RET_2YEARS), LocalizedString(30386).Get()}, + {LifetimeMapper::TvhToKodi(DVR_RET_3YEARS), LocalizedString(30387).Get()}, }; if (m_conn->GetProtocol() >= 25) { - lifetimeValues.emplace_back(std::make_pair(LifetimeMapper::TvhToKodi(DVR_RET_SPACE), LocalizedString(30373).Get())); - lifetimeValues.emplace_back(std::make_pair(LifetimeMapper::TvhToKodi(DVR_RET_FOREVER), LocalizedString(30374).Get())); + lifetimeValues.emplace_back( + std::make_pair(LifetimeMapper::TvhToKodi(DVR_RET_SPACE), LocalizedString(30373).Get())); + lifetimeValues.emplace_back( + std::make_pair(LifetimeMapper::TvhToKodi(DVR_RET_FOREVER), LocalizedString(30374).Get())); } } -PVR_ERROR CTvheadend::GetTimerTypes ( PVR_TIMER_TYPE types[], int *size ) +PVR_ERROR CTvheadend::GetTimerTypes(PVR_TIMER_TYPE types[], int* size) { /* PVR_Timer.iPriority values and presentation.*/ - static std::vector< std::pair > priorityValues; + static std::vector> priorityValues; if (priorityValues.size() == 0) { priorityValues = { - { DVR_PRIO_DEFAULT, LocalizedString(30368).Get() }, - { DVR_PRIO_UNIMPORTANT, LocalizedString(30355).Get() }, - { DVR_PRIO_LOW, LocalizedString(30354).Get() }, - { DVR_PRIO_NORMAL, LocalizedString(30353).Get() }, - { DVR_PRIO_HIGH, LocalizedString(30352).Get() }, - { DVR_PRIO_IMPORTANT, LocalizedString(30351).Get() }, + {DVR_PRIO_DEFAULT, LocalizedString(30368).Get()}, + {DVR_PRIO_UNIMPORTANT, LocalizedString(30355).Get()}, + {DVR_PRIO_LOW, LocalizedString(30354).Get()}, + {DVR_PRIO_NORMAL, LocalizedString(30353).Get()}, + {DVR_PRIO_HIGH, LocalizedString(30352).Get()}, + {DVR_PRIO_IMPORTANT, LocalizedString(30351).Get()}, }; } /* PVR_Timer.iPreventDuplicateEpisodes values and presentation.*/ - std::vector< std::pair > deDupValues = - { - { DVR_AUTOREC_RECORD_ALL, LocalizedString(30356).Get() }, - { DVR_AUTOREC_RECORD_DIFFERENT_EPISODE_NUMBER, LocalizedString(30357).Get() }, - { DVR_AUTOREC_RECORD_DIFFERENT_SUBTITLE, LocalizedString(30358).Get() }, - { DVR_AUTOREC_RECORD_DIFFERENT_DESCRIPTION, LocalizedString(30359).Get() }, + std::vector> deDupValues = { + {DVR_AUTOREC_RECORD_ALL, LocalizedString(30356).Get()}, + {DVR_AUTOREC_RECORD_DIFFERENT_EPISODE_NUMBER, LocalizedString(30357).Get()}, + {DVR_AUTOREC_RECORD_DIFFERENT_SUBTITLE, LocalizedString(30358).Get()}, + {DVR_AUTOREC_RECORD_DIFFERENT_DESCRIPTION, LocalizedString(30359).Get()}, }; if (m_conn->GetProtocol() >= 27) - deDupValues.emplace_back(std::make_pair(DVR_AUTOREC_RECORD_ONCE_PER_MONTH, LocalizedString(30370).Get())); + deDupValues.emplace_back( + std::make_pair(DVR_AUTOREC_RECORD_ONCE_PER_MONTH, LocalizedString(30370).Get())); - deDupValues.emplace_back(std::make_pair(DVR_AUTOREC_RECORD_ONCE_PER_WEEK, LocalizedString(30360).Get())); - deDupValues.emplace_back(std::make_pair(DVR_AUTOREC_RECORD_ONCE_PER_DAY, LocalizedString(30361).Get())); + deDupValues.emplace_back( + std::make_pair(DVR_AUTOREC_RECORD_ONCE_PER_WEEK, LocalizedString(30360).Get())); + deDupValues.emplace_back( + std::make_pair(DVR_AUTOREC_RECORD_ONCE_PER_DAY, LocalizedString(30361).Get())); if (m_conn->GetProtocol() >= 26) { - deDupValues.emplace_back(std::make_pair(DVR_AUTOREC_LRECORD_DIFFERENT_EPISODE_NUMBER, LocalizedString(30362).Get())); - deDupValues.emplace_back(std::make_pair(DVR_AUTOREC_LRECORD_DIFFERENT_SUBTITLE, LocalizedString(30363).Get())); - deDupValues.emplace_back(std::make_pair(DVR_AUTOREC_LRECORD_DIFFERENT_TITLE, LocalizedString(30364).Get())); - deDupValues.emplace_back(std::make_pair(DVR_AUTOREC_LRECORD_DIFFERENT_DESCRIPTION, LocalizedString(30365).Get())); + deDupValues.emplace_back( + std::make_pair(DVR_AUTOREC_LRECORD_DIFFERENT_EPISODE_NUMBER, LocalizedString(30362).Get())); + deDupValues.emplace_back( + std::make_pair(DVR_AUTOREC_LRECORD_DIFFERENT_SUBTITLE, LocalizedString(30363).Get())); + deDupValues.emplace_back( + std::make_pair(DVR_AUTOREC_LRECORD_DIFFERENT_TITLE, LocalizedString(30364).Get())); + deDupValues.emplace_back( + std::make_pair(DVR_AUTOREC_LRECORD_DIFFERENT_DESCRIPTION, LocalizedString(30365).Get())); } if (m_conn->GetProtocol() >= 27) - deDupValues.emplace_back(std::make_pair(DVR_AUTOREC_LRECORD_ONCE_PER_MONTH, LocalizedString(30371).Get())); + deDupValues.emplace_back( + std::make_pair(DVR_AUTOREC_LRECORD_ONCE_PER_MONTH, LocalizedString(30371).Get())); if (m_conn->GetProtocol() >= 26) { - deDupValues.emplace_back(std::make_pair(DVR_AUTOREC_LRECORD_ONCE_PER_WEEK, LocalizedString(30366).Get())); - deDupValues.emplace_back(std::make_pair(DVR_AUTOREC_LRECORD_ONCE_PER_DAY, LocalizedString(30367).Get())); + deDupValues.emplace_back( + std::make_pair(DVR_AUTOREC_LRECORD_ONCE_PER_WEEK, LocalizedString(30366).Get())); + deDupValues.emplace_back( + std::make_pair(DVR_AUTOREC_LRECORD_ONCE_PER_DAY, LocalizedString(30367).Get())); } if (m_conn->GetProtocol() >= 31) - deDupValues.emplace_back(std::make_pair(DVR_AUTOREC_RECORD_UNIQUE, LocalizedString(30372).Get())); + deDupValues.emplace_back( + std::make_pair(DVR_AUTOREC_RECORD_UNIQUE, LocalizedString(30372).Get())); /* PVR_Timer.iLifetime values and presentation.*/ - std::vector< std::pair > lifetimeValues; + std::vector> lifetimeValues; GetLivetimeValues(lifetimeValues); - unsigned int TIMER_ONCE_MANUAL_ATTRIBS - = PVR_TIMER_TYPE_IS_MANUAL | - PVR_TIMER_TYPE_SUPPORTS_CHANNELS | - PVR_TIMER_TYPE_SUPPORTS_START_TIME | - PVR_TIMER_TYPE_SUPPORTS_END_TIME | - PVR_TIMER_TYPE_SUPPORTS_PRIORITY | - PVR_TIMER_TYPE_SUPPORTS_LIFETIME; + unsigned int TIMER_ONCE_MANUAL_ATTRIBS = + PVR_TIMER_TYPE_IS_MANUAL | PVR_TIMER_TYPE_SUPPORTS_CHANNELS | + PVR_TIMER_TYPE_SUPPORTS_START_TIME | PVR_TIMER_TYPE_SUPPORTS_END_TIME | + PVR_TIMER_TYPE_SUPPORTS_PRIORITY | PVR_TIMER_TYPE_SUPPORTS_LIFETIME; - unsigned int TIMER_ONCE_EPG_ATTRIBS - = PVR_TIMER_TYPE_SUPPORTS_CHANNELS | - PVR_TIMER_TYPE_SUPPORTS_START_TIME | - PVR_TIMER_TYPE_SUPPORTS_END_TIME | - PVR_TIMER_TYPE_REQUIRES_EPG_TAG_ON_CREATE | - PVR_TIMER_TYPE_SUPPORTS_START_END_MARGIN | - PVR_TIMER_TYPE_SUPPORTS_PRIORITY | + unsigned int TIMER_ONCE_EPG_ATTRIBS = + PVR_TIMER_TYPE_SUPPORTS_CHANNELS | PVR_TIMER_TYPE_SUPPORTS_START_TIME | + PVR_TIMER_TYPE_SUPPORTS_END_TIME | PVR_TIMER_TYPE_REQUIRES_EPG_TAG_ON_CREATE | + PVR_TIMER_TYPE_SUPPORTS_START_END_MARGIN | PVR_TIMER_TYPE_SUPPORTS_PRIORITY | PVR_TIMER_TYPE_SUPPORTS_LIFETIME; if (m_conn->GetProtocol() >= 23) { TIMER_ONCE_MANUAL_ATTRIBS |= PVR_TIMER_TYPE_SUPPORTS_ENABLE_DISABLE; - TIMER_ONCE_EPG_ATTRIBS |= PVR_TIMER_TYPE_SUPPORTS_ENABLE_DISABLE; + TIMER_ONCE_EPG_ATTRIBS |= PVR_TIMER_TYPE_SUPPORTS_ENABLE_DISABLE; } /* Timer types definition. */ - std::vector< std::unique_ptr > timerTypes; + std::vector> timerTypes; timerTypes.emplace_back( - /* One-shot manual (time and channel based) */ - std::unique_ptr(new TimerType( - /* Type id. */ - TIMER_ONCE_MANUAL, - /* Attributes. */ - TIMER_ONCE_MANUAL_ATTRIBS, - /* Let Kodi generate the description. */ - "", - /* Values definitions for priorities. */ - priorityValues, - /* Values definitions for lifetime. */ - lifetimeValues))); + /* One-shot manual (time and channel based) */ + std::unique_ptr(new TimerType( + /* Type id. */ + TIMER_ONCE_MANUAL, + /* Attributes. */ + TIMER_ONCE_MANUAL_ATTRIBS, + /* Let Kodi generate the description. */ + "", + /* Values definitions for priorities. */ + priorityValues, + /* Values definitions for lifetime. */ + lifetimeValues))); timerTypes.emplace_back( - /* One-shot epg based */ - std::unique_ptr(new TimerType( - /* Type id. */ - TIMER_ONCE_EPG, - /* Attributes. */ - TIMER_ONCE_EPG_ATTRIBS, - /* Let Kodi generate the description. */ - "", - /* Values definitions for priorities. */ - priorityValues, - /* Values definitions for lifetime. */ - lifetimeValues))); + /* One-shot epg based */ + std::unique_ptr(new TimerType( + /* Type id. */ + TIMER_ONCE_EPG, + /* Attributes. */ + TIMER_ONCE_EPG_ATTRIBS, + /* Let Kodi generate the description. */ + "", + /* Values definitions for priorities. */ + priorityValues, + /* Values definitions for lifetime. */ + lifetimeValues))); timerTypes.emplace_back( - /* Read-only one-shot for timers generated by timerec */ - std::unique_ptr(new TimerType( - /* Type id. */ - TIMER_ONCE_CREATED_BY_TIMEREC, - /* Attributes. */ - TIMER_ONCE_MANUAL_ATTRIBS | - PVR_TIMER_TYPE_IS_READONLY | - PVR_TIMER_TYPE_FORBIDS_NEW_INSTANCES, - /* Description. */ - LocalizedString(30350).Get(), // "One Time (Scheduled by timer rule)" - /* Values definitions for priorities. */ - priorityValues, - /* Values definitions for lifetime. */ - lifetimeValues))); + /* Read-only one-shot for timers generated by timerec */ + std::unique_ptr(new TimerType( + /* Type id. */ + TIMER_ONCE_CREATED_BY_TIMEREC, + /* Attributes. */ + TIMER_ONCE_MANUAL_ATTRIBS | PVR_TIMER_TYPE_IS_READONLY | + PVR_TIMER_TYPE_FORBIDS_NEW_INSTANCES, + /* Description. */ + LocalizedString(30350).Get(), // "One Time (Scheduled by timer rule)" + /* Values definitions for priorities. */ + priorityValues, + /* Values definitions for lifetime. */ + lifetimeValues))); timerTypes.emplace_back( - /* Read-only one-shot for timers generated by autorec */ - std::unique_ptr(new TimerType( - /* Type id. */ - TIMER_ONCE_CREATED_BY_AUTOREC, - /* Attributes. */ - TIMER_ONCE_EPG_ATTRIBS | - PVR_TIMER_TYPE_IS_READONLY | - PVR_TIMER_TYPE_FORBIDS_NEW_INSTANCES, - /* Description. */ - LocalizedString(30350).Get(), // "One Time (Scheduled by timer rule)" - /* Values definitions for priorities. */ - priorityValues, - /* Values definitions for lifetime. */ - lifetimeValues))); + /* Read-only one-shot for timers generated by autorec */ + std::unique_ptr(new TimerType( + /* Type id. */ + TIMER_ONCE_CREATED_BY_AUTOREC, + /* Attributes. */ + TIMER_ONCE_EPG_ATTRIBS | PVR_TIMER_TYPE_IS_READONLY | + PVR_TIMER_TYPE_FORBIDS_NEW_INSTANCES, + /* Description. */ + LocalizedString(30350).Get(), // "One Time (Scheduled by timer rule)" + /* Values definitions for priorities. */ + priorityValues, + /* Values definitions for lifetime. */ + lifetimeValues))); timerTypes.emplace_back( - /* Repeating manual (time and channel based) - timerec */ - std::unique_ptr(new TimerType( - /* Type id. */ - TIMER_REPEATING_MANUAL, - /* Attributes. */ - PVR_TIMER_TYPE_IS_MANUAL | - PVR_TIMER_TYPE_IS_REPEATING | - PVR_TIMER_TYPE_SUPPORTS_ENABLE_DISABLE | - PVR_TIMER_TYPE_SUPPORTS_CHANNELS | - PVR_TIMER_TYPE_SUPPORTS_START_TIME | - PVR_TIMER_TYPE_SUPPORTS_END_TIME | - PVR_TIMER_TYPE_SUPPORTS_WEEKDAYS | - PVR_TIMER_TYPE_SUPPORTS_PRIORITY | - PVR_TIMER_TYPE_SUPPORTS_LIFETIME | - PVR_TIMER_TYPE_SUPPORTS_RECORDING_FOLDERS, - /* Let Kodi generate the description. */ - "", - /* Values definitions for priorities. */ - priorityValues, - /* Values definitions for lifetime. */ - lifetimeValues))); + /* Repeating manual (time and channel based) - timerec */ + std::unique_ptr(new TimerType( + /* Type id. */ + TIMER_REPEATING_MANUAL, + /* Attributes. */ + PVR_TIMER_TYPE_IS_MANUAL | PVR_TIMER_TYPE_IS_REPEATING | + PVR_TIMER_TYPE_SUPPORTS_ENABLE_DISABLE | PVR_TIMER_TYPE_SUPPORTS_CHANNELS | + PVR_TIMER_TYPE_SUPPORTS_START_TIME | PVR_TIMER_TYPE_SUPPORTS_END_TIME | + PVR_TIMER_TYPE_SUPPORTS_WEEKDAYS | PVR_TIMER_TYPE_SUPPORTS_PRIORITY | + PVR_TIMER_TYPE_SUPPORTS_LIFETIME | PVR_TIMER_TYPE_SUPPORTS_RECORDING_FOLDERS, + /* Let Kodi generate the description. */ + "", + /* Values definitions for priorities. */ + priorityValues, + /* Values definitions for lifetime. */ + lifetimeValues))); if (m_conn->GetProtocol() >= 29) { - unsigned int TIMER_REPEATING_SERIESLINK_ATTRIBS - = PVR_TIMER_TYPE_IS_REPEATING | - PVR_TIMER_TYPE_SUPPORTS_ENABLE_DISABLE | - PVR_TIMER_TYPE_SUPPORTS_CHANNELS | - PVR_TIMER_TYPE_SUPPORTS_START_TIME | - PVR_TIMER_TYPE_SUPPORTS_START_ANYTIME | - PVR_TIMER_TYPE_SUPPORTS_WEEKDAYS | - PVR_TIMER_TYPE_SUPPORTS_START_END_MARGIN | - PVR_TIMER_TYPE_SUPPORTS_PRIORITY | - PVR_TIMER_TYPE_SUPPORTS_LIFETIME | - PVR_TIMER_TYPE_SUPPORTS_RECORDING_FOLDERS | - PVR_TIMER_TYPE_SUPPORTS_ANY_CHANNEL | - PVR_TIMER_TYPE_REQUIRES_EPG_SERIESLINK_ON_CREATE; + unsigned int TIMER_REPEATING_SERIESLINK_ATTRIBS = + PVR_TIMER_TYPE_IS_REPEATING | PVR_TIMER_TYPE_SUPPORTS_ENABLE_DISABLE | + PVR_TIMER_TYPE_SUPPORTS_CHANNELS | PVR_TIMER_TYPE_SUPPORTS_START_TIME | + PVR_TIMER_TYPE_SUPPORTS_START_ANYTIME | PVR_TIMER_TYPE_SUPPORTS_WEEKDAYS | + PVR_TIMER_TYPE_SUPPORTS_START_END_MARGIN | PVR_TIMER_TYPE_SUPPORTS_PRIORITY | + PVR_TIMER_TYPE_SUPPORTS_LIFETIME | PVR_TIMER_TYPE_SUPPORTS_RECORDING_FOLDERS | + PVR_TIMER_TYPE_SUPPORTS_ANY_CHANNEL | PVR_TIMER_TYPE_REQUIRES_EPG_SERIESLINK_ON_CREATE; if (!Settings::GetInstance().GetAutorecApproxTime()) { @@ -978,33 +968,27 @@ PVR_ERROR CTvheadend::GetTimerTypes ( PVR_TIMER_TYPE types[], int *size ) } timerTypes.emplace_back( - /* Repeating epg based - series link autorec */ - std::unique_ptr(new TimerType( - /* Type id. */ - TIMER_REPEATING_SERIESLINK, - /* Attributes. */ - TIMER_REPEATING_SERIESLINK_ATTRIBS, - /* Description. */ - LocalizedString(30369).Get(), // "Timer rule (series link)" - /* Values definitions for priorities. */ - priorityValues, - /* Values definitions for lifetime. */ - lifetimeValues))); - } - - unsigned int TIMER_REPEATING_EPG_ATTRIBS - = PVR_TIMER_TYPE_IS_REPEATING | - PVR_TIMER_TYPE_SUPPORTS_ENABLE_DISABLE | - PVR_TIMER_TYPE_SUPPORTS_TITLE_EPG_MATCH | - PVR_TIMER_TYPE_SUPPORTS_CHANNELS | - PVR_TIMER_TYPE_SUPPORTS_START_TIME | - PVR_TIMER_TYPE_SUPPORTS_START_ANYTIME | - PVR_TIMER_TYPE_SUPPORTS_WEEKDAYS | - PVR_TIMER_TYPE_SUPPORTS_START_END_MARGIN | - PVR_TIMER_TYPE_SUPPORTS_PRIORITY | - PVR_TIMER_TYPE_SUPPORTS_LIFETIME | - PVR_TIMER_TYPE_SUPPORTS_RECORDING_FOLDERS | - PVR_TIMER_TYPE_SUPPORTS_ANY_CHANNEL; + /* Repeating epg based - series link autorec */ + std::unique_ptr(new TimerType( + /* Type id. */ + TIMER_REPEATING_SERIESLINK, + /* Attributes. */ + TIMER_REPEATING_SERIESLINK_ATTRIBS, + /* Description. */ + LocalizedString(30369).Get(), // "Timer rule (series link)" + /* Values definitions for priorities. */ + priorityValues, + /* Values definitions for lifetime. */ + lifetimeValues))); + } + + unsigned int TIMER_REPEATING_EPG_ATTRIBS = + PVR_TIMER_TYPE_IS_REPEATING | PVR_TIMER_TYPE_SUPPORTS_ENABLE_DISABLE | + PVR_TIMER_TYPE_SUPPORTS_TITLE_EPG_MATCH | PVR_TIMER_TYPE_SUPPORTS_CHANNELS | + PVR_TIMER_TYPE_SUPPORTS_START_TIME | PVR_TIMER_TYPE_SUPPORTS_START_ANYTIME | + PVR_TIMER_TYPE_SUPPORTS_WEEKDAYS | PVR_TIMER_TYPE_SUPPORTS_START_END_MARGIN | + PVR_TIMER_TYPE_SUPPORTS_PRIORITY | PVR_TIMER_TYPE_SUPPORTS_LIFETIME | + PVR_TIMER_TYPE_SUPPORTS_RECORDING_FOLDERS | PVR_TIMER_TYPE_SUPPORTS_ANY_CHANNEL; if (m_conn->GetProtocol() >= 20) { @@ -1020,20 +1004,20 @@ PVR_ERROR CTvheadend::GetTimerTypes ( PVR_TIMER_TYPE types[], int *size ) } timerTypes.emplace_back( - /* Repeating epg based - autorec */ - std::unique_ptr(new TimerType( - /* Type id. */ - TIMER_REPEATING_EPG, - /* Attributes. */ - TIMER_REPEATING_EPG_ATTRIBS, - /* Let Kodi generate the description. */ - "", - /* Values definitions for priorities. */ - priorityValues, - /* Values definitions for lifetime. */ - lifetimeValues, - /* Values definitions for prevent duplicate episodes. */ - deDupValues))); + /* Repeating epg based - autorec */ + std::unique_ptr(new TimerType( + /* Type id. */ + TIMER_REPEATING_EPG, + /* Attributes. */ + TIMER_REPEATING_EPG_ATTRIBS, + /* Let Kodi generate the description. */ + "", + /* Values definitions for priorities. */ + priorityValues, + /* Values definitions for lifetime. */ + lifetimeValues, + /* Values definitions for prevent duplicate episodes. */ + deDupValues))); /* Copy data to target array. */ int i = 0; @@ -1044,21 +1028,17 @@ PVR_ERROR CTvheadend::GetTimerTypes ( PVR_TIMER_TYPE types[], int *size ) return PVR_ERROR_NO_ERROR; } -int CTvheadend::GetTimerCount ( void ) +int CTvheadend::GetTimerCount(void) { if (!m_asyncState.WaitForState(ASYNC_EPG)) return 0; - + CLockObject lock(m_mutex); // Normal timers - int timerCount = std::count_if( - m_recordings.cbegin(), - m_recordings.cend(), - [](const RecordingMapEntry &entry) - { - return entry.second.IsTimer(); - }); + int timerCount = + std::count_if(m_recordings.cbegin(), m_recordings.cend(), + [](const RecordingMapEntry& entry) { return entry.second.IsTimer(); }); // Repeating timers timerCount += m_timeRecordings.GetTimerecTimerCount(); @@ -1067,65 +1047,61 @@ int CTvheadend::GetTimerCount ( void ) return timerCount; } -bool CTvheadend::CreateTimer ( const Recording &tvhTmr, PVR_TIMER &tmr ) +bool CTvheadend::CreateTimer(const Recording& tvhTmr, PVR_TIMER& tmr) { - tmr = { 0 }; + tmr = {0}; - tmr.iClientIndex = tvhTmr.GetId(); - tmr.iClientChannelUid = (tvhTmr.GetChannel() > 0) ? tvhTmr.GetChannel() : PVR_CHANNEL_INVALID_UID; - tmr.startTime = static_cast(tvhTmr.GetStart()); - tmr.endTime = static_cast(tvhTmr.GetStop()); - strncpy(tmr.strTitle, - tvhTmr.GetTitle().c_str(), sizeof(tmr.strTitle) - 1); - strncpy(tmr.strEpgSearchString, - "", sizeof(tmr.strEpgSearchString) - 1); // n/a for one-shot timers - strncpy(tmr.strDirectory, - "", sizeof(tmr.strDirectory) - 1); // n/a for one-shot timers - strncpy(tmr.strSummary, - tvhTmr.GetDescription().c_str(), sizeof(tmr.strSummary) - 1); + tmr.iClientIndex = tvhTmr.GetId(); + tmr.iClientChannelUid = (tvhTmr.GetChannel() > 0) ? tvhTmr.GetChannel() : PVR_CHANNEL_INVALID_UID; + tmr.startTime = static_cast(tvhTmr.GetStart()); + tmr.endTime = static_cast(tvhTmr.GetStop()); + strncpy(tmr.strTitle, tvhTmr.GetTitle().c_str(), sizeof(tmr.strTitle) - 1); + strncpy(tmr.strEpgSearchString, "", + sizeof(tmr.strEpgSearchString) - 1); // n/a for one-shot timers + strncpy(tmr.strDirectory, "", sizeof(tmr.strDirectory) - 1); // n/a for one-shot timers + strncpy(tmr.strSummary, tvhTmr.GetDescription().c_str(), sizeof(tmr.strSummary) - 1); if (m_conn->GetProtocol() >= 23) - tmr.state = !tvhTmr.IsEnabled() - ? PVR_TIMER_STATE_DISABLED - : tvhTmr.GetState(); + tmr.state = !tvhTmr.IsEnabled() ? PVR_TIMER_STATE_DISABLED : tvhTmr.GetState(); else - tmr.state = tvhTmr.GetState(); - - tmr.iPriority = tvhTmr.GetPriority(); - tmr.iLifetime = tvhTmr.GetLifetime(); - tmr.iTimerType = tvhTmr.GetTimerType(); - tmr.iMaxRecordings = 0; // not supported by tvh - tmr.iRecordingGroup = 0; // not supported by tvh - tmr.iPreventDuplicateEpisodes = 0; // n/a for one-shot timers - tmr.firstDay = 0; // not supported by tvh - tmr.iWeekdays = PVR_WEEKDAY_NONE; // n/a for one-shot timers - tmr.iEpgUid = (tvhTmr.GetEventId() > 0) ? tvhTmr.GetEventId() : PVR_TIMER_NO_EPG_UID; - tmr.iMarginStart = static_cast(tvhTmr.GetStartExtra()); - tmr.iMarginEnd = static_cast(tvhTmr.GetStopExtra()); - tmr.iGenreType = 0; // not supported by tvh? - tmr.iGenreSubType = 0; // not supported by tvh? - tmr.bFullTextEpgSearch = false; // n/a for one-shot timers - tmr.iParentClientIndex = tmr.iTimerType == TIMER_ONCE_CREATED_BY_TIMEREC - ? m_timeRecordings.GetTimerIntIdFromStringId(tvhTmr.GetTimerecId()) - : tmr.iTimerType == TIMER_ONCE_CREATED_BY_AUTOREC - ? m_autoRecordings.GetTimerIntIdFromStringId(tvhTmr.GetAutorecId()) - : 0; + tmr.state = tvhTmr.GetState(); + + tmr.iPriority = tvhTmr.GetPriority(); + tmr.iLifetime = tvhTmr.GetLifetime(); + tmr.iTimerType = tvhTmr.GetTimerType(); + tmr.iMaxRecordings = 0; // not supported by tvh + tmr.iRecordingGroup = 0; // not supported by tvh + tmr.iPreventDuplicateEpisodes = 0; // n/a for one-shot timers + tmr.firstDay = 0; // not supported by tvh + tmr.iWeekdays = PVR_WEEKDAY_NONE; // n/a for one-shot timers + tmr.iEpgUid = (tvhTmr.GetEventId() > 0) ? tvhTmr.GetEventId() : PVR_TIMER_NO_EPG_UID; + tmr.iMarginStart = static_cast(tvhTmr.GetStartExtra()); + tmr.iMarginEnd = static_cast(tvhTmr.GetStopExtra()); + tmr.iGenreType = 0; // not supported by tvh? + tmr.iGenreSubType = 0; // not supported by tvh? + tmr.bFullTextEpgSearch = false; // n/a for one-shot timers + tmr.iParentClientIndex = + tmr.iTimerType == TIMER_ONCE_CREATED_BY_TIMEREC + ? m_timeRecordings.GetTimerIntIdFromStringId(tvhTmr.GetTimerecId()) + : tmr.iTimerType == TIMER_ONCE_CREATED_BY_AUTOREC + ? m_autoRecordings.GetTimerIntIdFromStringId(tvhTmr.GetAutorecId()) + : 0; return true; } -PVR_ERROR CTvheadend::GetTimers ( ADDON_HANDLE handle ) +PVR_ERROR CTvheadend::GetTimers(ADDON_HANDLE handle) { if (!m_asyncState.WaitForState(ASYNC_EPG)) return PVR_ERROR_FAILED; - + std::vector timers; { CLockObject lock(m_mutex); /* One-shot timers */ - for (const auto &entry : m_recordings) + for (const auto& entry : m_recordings) { - const auto &recording = entry.second; + const auto& recording = entry.second; if (!recording.IsTimer()) continue; @@ -1153,28 +1129,27 @@ PVR_ERROR CTvheadend::GetTimers ( ADDON_HANDLE handle ) return PVR_ERROR_NO_ERROR; } -PVR_ERROR CTvheadend::AddTimer ( const PVR_TIMER &timer ) +PVR_ERROR CTvheadend::AddTimer(const PVR_TIMER& timer) { - if ((timer.iTimerType == TIMER_ONCE_MANUAL) || - (timer.iTimerType == TIMER_ONCE_EPG)) + if ((timer.iTimerType == TIMER_ONCE_MANUAL) || (timer.iTimerType == TIMER_ONCE_EPG)) { /* one shot timer */ uint32_t u32; /* Build message */ - htsmsg_t *m = htsmsg_create_map(); + htsmsg_t* m = htsmsg_create_map(); int64_t start = timer.startTime; if (timer.iEpgUid > PVR_TIMER_NO_EPG_UID && timer.iTimerType == TIMER_ONCE_EPG && start != 0) { /* EPG-based timer */ - htsmsg_add_u32(m, "eventId", timer.iEpgUid); + htsmsg_add_u32(m, "eventId", timer.iEpgUid); } else { /* manual timer */ - htsmsg_add_str(m, "title", timer.strTitle); + htsmsg_add_str(m, "title", timer.strTitle); if (start == 0) { @@ -1182,24 +1157,25 @@ PVR_ERROR CTvheadend::AddTimer ( const PVR_TIMER &timer ) start = time(NULL); } - htsmsg_add_s64(m, "start", start); - htsmsg_add_s64(m, "stop", timer.endTime); - htsmsg_add_u32(m, "channelId", timer.iClientChannelUid); - htsmsg_add_str(m, "description", timer.strSummary); + htsmsg_add_s64(m, "start", start); + htsmsg_add_s64(m, "stop", timer.endTime); + htsmsg_add_u32(m, "channelId", timer.iClientChannelUid); + htsmsg_add_str(m, "description", timer.strSummary); } if (m_conn->GetProtocol() >= 23) - htsmsg_add_u32(m, "enabled", timer.state == PVR_TIMER_STATE_DISABLED ? 0 : 1); + htsmsg_add_u32(m, "enabled", timer.state == PVR_TIMER_STATE_DISABLED ? 0 : 1); htsmsg_add_s64(m, "startExtra", timer.iMarginStart); - htsmsg_add_s64(m, "stopExtra", timer.iMarginEnd); + htsmsg_add_s64(m, "stopExtra", timer.iMarginEnd); if (m_conn->GetProtocol() >= 25) - htsmsg_add_u32(m, "removal", LifetimeMapper::KodiToTvh(timer.iLifetime)); // remove from disk + htsmsg_add_u32(m, "removal", LifetimeMapper::KodiToTvh(timer.iLifetime)); // remove from disk else - htsmsg_add_u32(m, "retention", LifetimeMapper::KodiToTvh(timer.iLifetime)); // remove from tvh database + htsmsg_add_u32(m, "retention", + LifetimeMapper::KodiToTvh(timer.iLifetime)); // remove from tvh database - htsmsg_add_u32(m, "priority", timer.iPriority); + htsmsg_add_u32(m, "priority", timer.iPriority); /* Send and Wait */ { @@ -1218,7 +1194,7 @@ PVR_ERROR CTvheadend::AddTimer ( const PVR_TIMER &timer ) } htsmsg_destroy(m); - return u32 > 0 ? PVR_ERROR_NO_ERROR : PVR_ERROR_FAILED; + return u32 > 0 ? PVR_ERROR_NO_ERROR : PVR_ERROR_FAILED; } else if (timer.iTimerType == TIMER_REPEATING_MANUAL) { @@ -1239,10 +1215,9 @@ PVR_ERROR CTvheadend::AddTimer ( const PVR_TIMER &timer ) } } -PVR_ERROR CTvheadend::DeleteTimer(const PVR_TIMER &timer, bool) +PVR_ERROR CTvheadend::DeleteTimer(const PVR_TIMER& timer, bool) { - if ((timer.iTimerType == TIMER_ONCE_MANUAL) || - (timer.iTimerType == TIMER_ONCE_EPG)) + if ((timer.iTimerType == TIMER_ONCE_MANUAL) || (timer.iTimerType == TIMER_ONCE_EPG)) { /* one shot timer */ return SendDvrDelete(timer.iClientIndex, "cancelDvrEntry"); @@ -1264,7 +1239,7 @@ PVR_ERROR CTvheadend::DeleteTimer(const PVR_TIMER &timer, bool) /* Read-only timer created by autorec or timerec */ CLockObject lock(m_mutex); - const auto &it = m_recordings.find(timer.iClientIndex); + const auto& it = m_recordings.find(timer.iClientIndex); if (it != m_recordings.end() && it->second.IsRecording()) { /* This is actually a request to cancel an active recording. */ @@ -1284,16 +1259,15 @@ PVR_ERROR CTvheadend::DeleteTimer(const PVR_TIMER &timer, bool) } } -PVR_ERROR CTvheadend::UpdateTimer ( const PVR_TIMER &timer ) +PVR_ERROR CTvheadend::UpdateTimer(const PVR_TIMER& timer) { - if ((timer.iTimerType == TIMER_ONCE_MANUAL) || - (timer.iTimerType == TIMER_ONCE_EPG)) + if ((timer.iTimerType == TIMER_ONCE_MANUAL) || (timer.iTimerType == TIMER_ONCE_EPG)) { /* one shot timer */ /* Build message */ - htsmsg_t *m = htsmsg_create_map(); - htsmsg_add_u32(m, "id", timer.iClientIndex); + htsmsg_t* m = htsmsg_create_map(); + htsmsg_add_u32(m, "id", timer.iClientIndex); if (m_conn->GetProtocol() >= 22) { @@ -1304,7 +1278,7 @@ PVR_ERROR CTvheadend::UpdateTimer ( const PVR_TIMER &timer ) { CLockObject lock(m_mutex); - const auto &it = m_recordings.find(timer.iClientIndex); + const auto& it = m_recordings.find(timer.iClientIndex); if (it == m_recordings.end()) { Logger::Log(LogLevel::LEVEL_ERROR, "cannot find the timer to update"); @@ -1313,15 +1287,17 @@ PVR_ERROR CTvheadend::UpdateTimer ( const PVR_TIMER &timer ) if (it->second.GetChannel() != static_cast(timer.iClientChannelUid)) { - Logger::Log(LogLevel::LEVEL_ERROR, "updating channels of one-shot timers not supported by HTSP v%d", m_conn->GetProtocol()); + Logger::Log(LogLevel::LEVEL_ERROR, + "updating channels of one-shot timers not supported by HTSP v%d", + m_conn->GetProtocol()); return PVR_ERROR_NOT_IMPLEMENTED; } } - htsmsg_add_str(m, "title", timer.strTitle); + htsmsg_add_str(m, "title", timer.strTitle); if (m_conn->GetProtocol() >= 23) - htsmsg_add_u32(m, "enabled", timer.state == PVR_TIMER_STATE_DISABLED ? 0 : 1); + htsmsg_add_u32(m, "enabled", timer.state == PVR_TIMER_STATE_DISABLED ? 0 : 1); int64_t start = timer.startTime; if (start == 0) @@ -1330,18 +1306,19 @@ PVR_ERROR CTvheadend::UpdateTimer ( const PVR_TIMER &timer ) start = time(NULL); } - htsmsg_add_s64(m, "start", start); - htsmsg_add_s64(m, "stop", timer.endTime); - htsmsg_add_str(m, "description", timer.strSummary); - htsmsg_add_s64(m, "startExtra", timer.iMarginStart); - htsmsg_add_s64(m, "stopExtra", timer.iMarginEnd); + htsmsg_add_s64(m, "start", start); + htsmsg_add_s64(m, "stop", timer.endTime); + htsmsg_add_str(m, "description", timer.strSummary); + htsmsg_add_s64(m, "startExtra", timer.iMarginStart); + htsmsg_add_s64(m, "stopExtra", timer.iMarginEnd); if (m_conn->GetProtocol() >= 25) - htsmsg_add_u32(m, "removal", LifetimeMapper::KodiToTvh(timer.iLifetime)); // remove from disk + htsmsg_add_u32(m, "removal", LifetimeMapper::KodiToTvh(timer.iLifetime)); // remove from disk else - htsmsg_add_u32(m, "retention", LifetimeMapper::KodiToTvh(timer.iLifetime)); // remove from tvh database + htsmsg_add_u32(m, "retention", + LifetimeMapper::KodiToTvh(timer.iLifetime)); // remove from tvh database - htsmsg_add_u32(m, "priority", timer.iPriority); + htsmsg_add_u32(m, "priority", timer.iPriority); return SendDvrUpdate(m); } @@ -1364,13 +1341,13 @@ PVR_ERROR CTvheadend::UpdateTimer ( const PVR_TIMER &timer ) /* Read-only timer created by autorec or timerec */ CLockObject lock(m_mutex); - const auto &it = m_recordings.find(timer.iClientIndex); + const auto& it = m_recordings.find(timer.iClientIndex); if (it != m_recordings.end() && (it->second.IsEnabled() == (timer.state == PVR_TIMER_STATE_DISABLED))) { /* This is actually a request to enable/disable a timer. */ - htsmsg_t *m = htsmsg_create_map(); - htsmsg_add_u32(m, "id", timer.iClientIndex); + htsmsg_t* m = htsmsg_create_map(); + htsmsg_add_u32(m, "id", timer.iClientIndex); htsmsg_add_u32(m, "enabled", timer.state == PVR_TIMER_STATE_DISABLED ? 0 : 1); return SendDvrUpdate(m); } @@ -1391,26 +1368,25 @@ PVR_ERROR CTvheadend::UpdateTimer ( const PVR_TIMER &timer ) * EPG * *************************************************************************/ -void CTvheadend::CreateEvent - ( const Event &event, EPG_TAG &epg ) -{ - epg = { 0 }; - epg.iUniqueBroadcastId = event.GetId(); - epg.iUniqueChannelId = event.GetChannel(); - epg.strTitle = event.GetTitle().c_str(); - epg.startTime = event.GetStart(); - epg.endTime = event.GetStop(); - epg.strPlotOutline = event.GetSummary().c_str(); - epg.strPlot = event.GetDesc().c_str(); - epg.strOriginalTitle = NULL; /* not supported by tvh */ - epg.strCast = event.GetCast().c_str(); - epg.strDirector = event.GetDirectors().c_str(); - epg.strWriter = event.GetWriters().c_str(); - epg.iYear = event.GetYear(); - epg.strIMDBNumber = NULL; /* not supported by tvh */ - epg.strIconPath = event.GetImage().c_str(); - epg.iGenreType = event.GetGenreType(); - epg.iGenreSubType = event.GetGenreSubType(); +void CTvheadend::CreateEvent(const Event& event, EPG_TAG& epg) +{ + epg = {0}; + epg.iUniqueBroadcastId = event.GetId(); + epg.iUniqueChannelId = event.GetChannel(); + epg.strTitle = event.GetTitle().c_str(); + epg.startTime = event.GetStart(); + epg.endTime = event.GetStop(); + epg.strPlotOutline = event.GetSummary().c_str(); + epg.strPlot = event.GetDesc().c_str(); + epg.strOriginalTitle = NULL; /* not supported by tvh */ + epg.strCast = event.GetCast().c_str(); + epg.strDirector = event.GetDirectors().c_str(); + epg.strWriter = event.GetWriters().c_str(); + epg.iYear = event.GetYear(); + epg.strIMDBNumber = NULL; /* not supported by tvh */ + epg.strIconPath = event.GetImage().c_str(); + epg.iGenreType = event.GetGenreType(); + epg.iGenreSubType = event.GetGenreSubType(); if (epg.iGenreType == 0) { const std::string& categories = event.GetCategories(); @@ -1420,19 +1396,18 @@ void CTvheadend::CreateEvent epg.strGenreDescription = categories.c_str(); } } - epg.firstAired = event.GetAired(); - epg.iParentalRating = event.GetAge(); - epg.iStarRating = event.GetStars(); - epg.iSeriesNumber = event.GetSeason(); - epg.iEpisodeNumber = event.GetEpisode(); - epg.iEpisodePartNumber = event.GetPart(); - epg.strEpisodeName = event.GetSubtitle().c_str(); - epg.iFlags = EPG_TAG_FLAG_UNDEFINED; - epg.strSeriesLink = event.GetSeriesLink().c_str(); + epg.firstAired = event.GetAired(); + epg.iParentalRating = event.GetAge(); + epg.iStarRating = event.GetStars(); + epg.iSeriesNumber = event.GetSeason(); + epg.iEpisodeNumber = event.GetEpisode(); + epg.iEpisodePartNumber = event.GetPart(); + epg.strEpisodeName = event.GetSubtitle().c_str(); + epg.iFlags = EPG_TAG_FLAG_UNDEFINED; + epg.strSeriesLink = event.GetSeriesLink().c_str(); } -void CTvheadend::TransferEvent - ( const Event &event, EPG_EVENT_STATE state ) +void CTvheadend::TransferEvent(const Event& event, EPG_EVENT_STATE state) { /* Build */ EPG_TAG tag; @@ -1442,8 +1417,7 @@ void CTvheadend::TransferEvent PVR->EpgEventStateChange(&tag, state); } -void CTvheadend::TransferEvent - ( ADDON_HANDLE handle, const Event &event ) +void CTvheadend::TransferEvent(ADDON_HANDLE handle, const Event& event) { /* Build */ EPG_TAG tag; @@ -1453,18 +1427,20 @@ void CTvheadend::TransferEvent PVR->TransferEpgEntry(handle, &tag); } -PVR_ERROR CTvheadend::GetEPGForChannel - ( ADDON_HANDLE handle, int iChannelUid, time_t start, time_t end ) +PVR_ERROR CTvheadend::GetEPGForChannel(ADDON_HANDLE handle, + int iChannelUid, + time_t start, + time_t end) { - htsmsg_field_t *f; + htsmsg_field_t* f; Logger::Log(LogLevel::LEVEL_DEBUG, "get epg channel %d start %ld stop %ld", iChannelUid, - (long long)start, (long long)end); + (long long)start, (long long)end); /* Build message */ - htsmsg_t *msg = htsmsg_create_map(); + htsmsg_t* msg = htsmsg_create_map(); htsmsg_add_u32(msg, "channelId", iChannelUid); - htsmsg_add_s64(msg, "maxTime", end); + htsmsg_add_s64(msg, "maxTime", end); /* Send and Wait */ { @@ -1475,7 +1451,7 @@ PVR_ERROR CTvheadend::GetEPGForChannel } /* Process */ - htsmsg_t *l; + htsmsg_t* l; if (!(l = htsmsg_get_list(msg, "events"))) { @@ -1513,7 +1489,9 @@ PVR_ERROR CTvheadend::SetEPGTimeFrame(int iDays) if (Settings::GetInstance().GetAsyncEpg()) { - Logger::Log(LogLevel::LEVEL_TRACE, "reconnecting to synchronize epg data. epg max time: old = %d, new = %d", m_epgMaxDays, iDays); + Logger::Log(LogLevel::LEVEL_TRACE, + "reconnecting to synchronize epg data. epg max time: old = %d, new = %d", + m_epgMaxDays, iDays); m_conn->Disconnect(); // reconnect to synchronize epg data } } @@ -1524,17 +1502,17 @@ PVR_ERROR CTvheadend::SetEPGTimeFrame(int iDays) * Connection * *************************************************************************/ -void CTvheadend::Disconnected ( void ) +void CTvheadend::Disconnected(void) { m_asyncState.SetState(ASYNC_NONE); } -bool CTvheadend::Connected ( void ) +bool CTvheadend::Connected(void) { - htsmsg_t *msg; + htsmsg_t* msg; /* Rebuild state */ - for (auto *dmx : m_dmx) + for (auto* dmx : m_dmx) { dmx->Connected(); } @@ -1543,30 +1521,31 @@ bool CTvheadend::Connected ( void ) m_autoRecordings.Connected(); /* Flag all async fields in case they've been deleted */ - for (auto &entry : m_channels) + for (auto& entry : m_channels) entry.second.SetDirty(true); - for (auto &entry : m_tags) + for (auto& entry : m_tags) entry.second.SetDirty(true); - for (auto &entry : m_schedules) + for (auto& entry : m_schedules) entry.second.SetDirty(true); { CLockObject lock(m_mutex); - for (auto &entry : m_recordings) + for (auto& entry : m_recordings) entry.second.SetDirty(true); } /* Request Async data, first is channels */ m_asyncState.SetState(ASYNC_CHN); - + msg = htsmsg_create_map(); if (Settings::GetInstance().GetAsyncEpg()) { Logger::Log(LogLevel::LEVEL_INFO, "request async EPG (%ld)", (long)m_epgMaxDays); htsmsg_add_u32(msg, "epg", 1); if (m_epgMaxDays > EPG_TIMEFRAME_UNLIMITED) - htsmsg_add_s64(msg, "epgMaxTime", static_cast(time(NULL) + m_epgMaxDays * int64_t(24 * 60 *60))); + htsmsg_add_s64(msg, "epgMaxTime", + static_cast(time(NULL) + m_epgMaxDays * int64_t(24 * 60 * 60))); } else htsmsg_add_u32(msg, "epg", 0); @@ -1603,7 +1582,7 @@ int CTvheadend::GetProtocol() const return m_conn->GetProtocol(); } -bool CTvheadend::HasCapability(const std::string &capability) const +bool CTvheadend::HasCapability(const std::string& capability) const { return m_conn->HasCapability(capability); } @@ -1622,7 +1601,7 @@ void CTvheadend::OnWake() * VFS * *************************************************************************/ -bool CTvheadend::VfsOpen(const PVR_RECORDING &rec) +bool CTvheadend::VfsOpen(const PVR_RECORDING& rec) { bool ret = m_vfs->Open(rec); @@ -1630,7 +1609,7 @@ bool CTvheadend::VfsOpen(const PVR_RECORDING &rec) { CLockObject lock(m_mutex); - const auto &it = m_recordings.find(atoi(rec.strRecordingId)); + const auto& it = m_recordings.find(atoi(rec.strRecordingId)); if (it != m_recordings.end()) { m_playingRecording = &(it->second); @@ -1648,7 +1627,7 @@ void CTvheadend::VfsClose() m_playingRecording = nullptr; } -ssize_t CTvheadend::VfsRead(unsigned char *buf, unsigned int len) +ssize_t CTvheadend::VfsRead(unsigned char* buf, unsigned int len) { return m_vfs->Read(buf, len, VfsIsActiveRecording()); } @@ -1681,14 +1660,14 @@ bool CTvheadend::VfsIsRealTimeStream() * Message handling * *************************************************************************/ -bool CTvheadend::ProcessMessage ( const char *method, htsmsg_t *msg ) +bool CTvheadend::ProcessMessage(const char* method, htsmsg_t* msg) { uint32_t subId; if (!htsmsg_get_u32(msg, "subscriptionId", &subId)) { /* subscriptionId found - for a Demuxer */ - for (auto *dmx : m_dmx) + for (auto* dmx : m_dmx) { if (dmx->GetSubscriptionId() == subId) return dmx->ProcessMessage(method, msg); @@ -1709,7 +1688,7 @@ void CTvheadend::CloseExpiredSubscriptions() int closeDelay = Settings::GetInstance().GetPreTunerCloseDelay(); if (closeDelay > 0) { - for (auto *dmx : m_dmx) + for (auto* dmx : m_dmx) { // do not close the running subscription if it is currently paused if (m_playingLiveStream && dmx == m_dmx_active && dmx->IsPaused()) @@ -1718,7 +1697,8 @@ void CTvheadend::CloseExpiredSubscriptions() time_t lastUse = dmx->GetLastUse(); if (lastUse > 0 && lastUse + closeDelay < std::time(nullptr)) { - Logger::Log(LogLevel::LEVEL_TRACE, "closing expired subscription %u", dmx->GetSubscriptionId()); + Logger::Log(LogLevel::LEVEL_TRACE, "closing expired subscription %u", + dmx->GetSubscriptionId()); dmx->Close(); } } @@ -1726,10 +1706,10 @@ void CTvheadend::CloseExpiredSubscriptions() } } -void* CTvheadend::Process ( void ) +void* CTvheadend::Process(void) { HTSPMessage msg; - const char *method; + const char* method; while (!IsStopped()) { @@ -1831,7 +1811,7 @@ void* CTvheadend::Process ( void ) eventsCopy = m_events; m_events.clear(); } - + /* Manual delete rather than waiting */ msg.ClearMessage(); @@ -1889,7 +1869,7 @@ void CTvheadend::TriggerTimerUpdate() m_events.emplace_back(SHTSPEvent(HTSP_EVENT_REC_UPDATE)); } -void CTvheadend::PushEpgEventUpdate(const Event &epg, EPG_EVENT_STATE state) +void CTvheadend::PushEpgEventUpdate(const Event& epg, EPG_EVENT_STATE state) { SHTSPEvent event = SHTSPEvent(HTSP_EVENT_EPG_UPDATE, epg, state); @@ -1897,7 +1877,7 @@ void CTvheadend::PushEpgEventUpdate(const Event &epg, EPG_EVENT_STATE state) m_events.emplace_back(event); } -void CTvheadend::SyncCompleted ( void ) +void CTvheadend::SyncCompleted(void) { Logger::Log(LogLevel::LEVEL_INFO, "async updates initialised"); @@ -1915,45 +1895,39 @@ void CTvheadend::SyncCompleted ( void ) if (!streamingProfile.empty() && !HasStreamingProfile(streamingProfile)) { - XBMC->QueueNotification( - QUEUE_ERROR, - LocalizedString(30502).Get().c_str(), streamingProfile.c_str()); + XBMC->QueueNotification(QUEUE_ERROR, LocalizedString(30502).Get().c_str(), + streamingProfile.c_str()); } else { /* Tell each demuxer to use this profile from now on */ - for (auto *dmx : m_dmx) + for (auto* dmx : m_dmx) dmx->SetStreamingProfile(streamingProfile); } } -void CTvheadend::SyncChannelsCompleted ( void ) +void CTvheadend::SyncChannelsCompleted(void) { /* check state engine */ if (m_asyncState.GetState() != ASYNC_CHN) return; /* Tags */ - utilities::erase_if(m_tags, [](const TagMapEntry &entry) - { - return entry.second.IsDirty(); - }); + utilities::erase_if(m_tags, [](const TagMapEntry& entry) { return entry.second.IsDirty(); }); TriggerChannelGroupsUpdate(); /* Channels */ - utilities::erase_if(m_channels, [](const ChannelMapEntry &entry) - { - return entry.second.IsDirty(); - }); + utilities::erase_if(m_channels, + [](const ChannelMapEntry& entry) { return entry.second.IsDirty(); }); TriggerChannelUpdate(); - + /* Next */ m_asyncState.SetState(ASYNC_DVR); } -void CTvheadend::SyncDvrCompleted ( void ) +void CTvheadend::SyncDvrCompleted(void) { /* check state engine */ if (m_asyncState.GetState() != ASYNC_DVR) @@ -1966,14 +1940,12 @@ void CTvheadend::SyncDvrCompleted ( void ) // save id of currently playing recording, if any uint32_t id = m_playingRecording ? m_playingRecording->GetId() : 0; - utilities::erase_if(m_recordings, [](const RecordingMapEntry &entry) - { - return entry.second.IsDirty(); - }); + utilities::erase_if(m_recordings, + [](const RecordingMapEntry& entry) { return entry.second.IsDirty(); }); if (m_playingRecording) { - const auto &it = m_recordings.find(id); + const auto& it = m_recordings.find(id); if (it == m_recordings.end()) m_playingRecording = nullptr; } @@ -1992,7 +1964,7 @@ void CTvheadend::SyncDvrCompleted ( void ) m_asyncState.SetState(ASYNC_EPG); } -void CTvheadend::SyncEpgCompleted ( void ) +void CTvheadend::SyncEpgCompleted(void) { /* check state engine */ if (!Settings::GetInstance().GetAsyncEpg()) @@ -2006,15 +1978,14 @@ void CTvheadend::SyncEpgCompleted ( void ) return; /* Schedules */ - std::vector > deletedEvents; - utilities::erase_if(m_schedules, [&](const ScheduleMapEntry &entry) - { + std::vector> 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 */)); + for (auto& evt : entry.second.GetEvents()) + deletedEvents.emplace_back(std::make_pair(evt.second.GetId() /* event uid */, + entry.second.GetId() /* channel uid */)); return true; } @@ -2022,14 +1993,13 @@ void CTvheadend::SyncEpgCompleted ( void ) }); /* Events */ - for (auto &entry : m_schedules) + for (auto& entry : m_schedules) { - utilities::erase_if(entry.second.GetEvents(), [&](const EventUidsMapEntry &mapEntry) - { + 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 */)); + deletedEvents.emplace_back(std::make_pair(mapEntry.second.GetId() /* event uid */, + entry.second.GetId() /* channel uid */)); return true; } return false; @@ -2037,7 +2007,7 @@ void CTvheadend::SyncEpgCompleted ( void ) } Event evt; - for (auto &entry : deletedEvents) + for (auto& entry : deletedEvents) { /* Transfer event to Kodi (callback) */ evt.SetId(entry.first); @@ -2049,11 +2019,11 @@ void CTvheadend::SyncEpgCompleted ( void ) m_asyncState.SetState(ASYNC_DONE); } -void CTvheadend::ParseTagAddOrUpdate ( htsmsg_t *msg, bool bAdd ) +void CTvheadend::ParseTagAddOrUpdate(htsmsg_t* msg, bool bAdd) { uint32_t u32; - const char *str; - htsmsg_t *list; + const char* str; + htsmsg_t* list; /* Validate */ if (htsmsg_get_u32(msg, "tagId", &u32)) @@ -2063,9 +2033,9 @@ void CTvheadend::ParseTagAddOrUpdate ( htsmsg_t *msg, bool bAdd ) } /* Locate object */ - auto &existingTag = m_tags[u32]; + auto& existingTag = m_tags[u32]; existingTag.SetDirty(false); - + /* Create new object */ Tag tag; tag.SetId(u32); @@ -2090,10 +2060,11 @@ void CTvheadend::ParseTagAddOrUpdate ( htsmsg_t *msg, bool bAdd ) /* Members */ if ((list = htsmsg_get_list(msg, "members")) != NULL) { - htsmsg_field_t *f; + htsmsg_field_t* f; HTSMSG_FOREACH(f, list) { - if (f->hmf_type != HMF_S64) continue; + if (f->hmf_type != HMF_S64) + continue; tag.GetChannels().emplace_back((int)f->hmf_s64); } } @@ -2103,14 +2074,14 @@ void CTvheadend::ParseTagAddOrUpdate ( htsmsg_t *msg, bool bAdd ) { existingTag = tag; - Logger::Log(LogLevel::LEVEL_DEBUG, "tag updated id:%u, name:%s", - existingTag.GetId(), existingTag.GetName().c_str()); + Logger::Log(LogLevel::LEVEL_DEBUG, "tag updated id:%u, name:%s", existingTag.GetId(), + existingTag.GetName().c_str()); if (m_asyncState.GetState() > ASYNC_CHN) TriggerChannelGroupsUpdate(); } } -void CTvheadend::ParseTagDelete ( htsmsg_t *msg ) +void CTvheadend::ParseTagDelete(htsmsg_t* msg) { uint32_t u32; @@ -2121,17 +2092,17 @@ void CTvheadend::ParseTagDelete ( htsmsg_t *msg ) return; } Logger::Log(LogLevel::LEVEL_DEBUG, "delete tag %u", u32); - + /* Erase */ m_tags.erase(u32); TriggerChannelGroupsUpdate(); } -void CTvheadend::ParseChannelAddOrUpdate ( htsmsg_t *msg, bool bAdd ) +void CTvheadend::ParseChannelAddOrUpdate(htsmsg_t* msg, bool bAdd) { uint32_t u32; - const char *str; - htsmsg_t *list; + const char* str; + htsmsg_t* list; /* Validate */ if (htsmsg_get_u32(msg, "channelId", &u32)) @@ -2141,7 +2112,7 @@ void CTvheadend::ParseChannelAddOrUpdate ( htsmsg_t *msg, bool bAdd ) } /* Locate channel object */ - Channel &channel = m_channels[u32]; + Channel& channel = m_channels[u32]; Channel comparison = channel; channel.SetId(u32); channel.SetDirty(false); @@ -2169,7 +2140,7 @@ void CTvheadend::ParseChannelAddOrUpdate ( htsmsg_t *msg, bool bAdd ) } else if (!channel.GetNum()) channel.SetNum(GetNextUnnumberedChannelNumber()); - + /* ATSC subchannel number */ if (!htsmsg_get_u32(msg, "channelNumberMinor", &u32)) channel.SetNumMinor(u32); @@ -2181,8 +2152,8 @@ void CTvheadend::ParseChannelAddOrUpdate ( htsmsg_t *msg, bool bAdd ) /* Services */ if ((list = htsmsg_get_list(msg, "services")) != NULL) { - htsmsg_field_t *f; - uint32_t caid = 0; + htsmsg_field_t* f; + uint32_t caid = 0; HTSMSG_FOREACH(f, list) { if (f->hmf_type != HMF_MAP) @@ -2216,8 +2187,8 @@ void CTvheadend::ParseChannelAddOrUpdate ( htsmsg_t *msg, bool bAdd ) /* Update Kodi */ if (channel != comparison) { - Logger::Log(LogLevel::LEVEL_DEBUG, "channel %s id:%u, name:%s", - (bAdd ? "added" : "updated"), channel.GetId(), channel.GetName().c_str()); + Logger::Log(LogLevel::LEVEL_DEBUG, "channel %s id:%u, name:%s", (bAdd ? "added" : "updated"), + channel.GetId(), channel.GetName().c_str()); if (bAdd) m_channelTuningPredictor.AddChannel(channel); @@ -2229,7 +2200,7 @@ void CTvheadend::ParseChannelAddOrUpdate ( htsmsg_t *msg, bool bAdd ) } } -void CTvheadend::ParseChannelDelete ( htsmsg_t *msg ) +void CTvheadend::ParseChannelDelete(htsmsg_t* msg) { uint32_t u32; @@ -2240,17 +2211,18 @@ void CTvheadend::ParseChannelDelete ( htsmsg_t *msg ) return; } Logger::Log(LogLevel::LEVEL_DEBUG, "delete channel %u", u32); - + /* Erase */ m_channels.erase(u32); m_channelTuningPredictor.RemoveChannel(u32); TriggerChannelUpdate(); } -void CTvheadend::ParseRecordingAddOrUpdate ( htsmsg_t *msg, bool bAdd ) +void CTvheadend::ParseRecordingAddOrUpdate(htsmsg_t* msg, bool bAdd) { const char *state, *str; - uint32_t id, channel, eventId, retention, removal, priority, enabled, contentType, playCount, playPosition, season, episode, part; + uint32_t id, channel, eventId, retention, removal, priority, enabled, contentType, playCount, + playPosition, season, episode, part; int64_t start, stop, startExtra, stopExtra; /* Channels must be complete */ @@ -2266,12 +2238,11 @@ void CTvheadend::ParseRecordingAddOrUpdate ( htsmsg_t *msg, bool bAdd ) /* Ignore duplicates */ uint32_t dup = 0; if (Settings::GetInstance().GetIgnoreDuplicateSchedules() && - !htsmsg_get_u32(msg, "duplicate", &dup) && - dup == 1) + !htsmsg_get_u32(msg, "duplicate", &dup) && dup == 1) return; /* Get/create entry */ - Recording &rec = m_recordings[id]; + Recording& rec = m_recordings[id]; Recording comparison = rec; rec.SetId(id); rec.SetDirty(false); @@ -2345,9 +2316,11 @@ void CTvheadend::ParseRecordingAddOrUpdate ( htsmsg_t *msg, bool bAdd ) if (stream->hmf_type != HMF_MAP) continue; - if (!htsmsg_get_u32(&stream->hmf_msg, "audio_type", &u32)) // Only present for audio streams + if (!htsmsg_get_u32(&stream->hmf_msg, "audio_type", + &u32)) // Only present for audio streams hasAudio = true; - if (!htsmsg_get_u32(&stream->hmf_msg, "aspect_num", &u32)) // Only present for video streams + if (!htsmsg_get_u32(&stream->hmf_msg, "aspect_num", + &u32)) // Only present for video streams hasVideo = true; } } @@ -2366,8 +2339,8 @@ void CTvheadend::ParseRecordingAddOrUpdate ( htsmsg_t *msg, bool bAdd ) /* Channel type fallback (in case channel was deleted) */ if (needChannelType) - rec.SetChannelType(hasVideo ? CHANNEL_TYPE_TV : - (hasAudio ? CHANNEL_TYPE_RADIO : CHANNEL_TYPE_OTHER)); + rec.SetChannelType(hasVideo ? CHANNEL_TYPE_TV + : (hasAudio ? CHANNEL_TYPE_RADIO : CHANNEL_TYPE_OTHER)); } /* Channel name fallback (in case channel was deleted) */ @@ -2427,7 +2400,8 @@ void CTvheadend::ParseRecordingAddOrUpdate ( htsmsg_t *msg, bool bAdd ) rec.SetPriority(priority); break; default: - Logger::Log(LogLevel::LEVEL_ERROR, "malformed dvrEntryAdd/dvrEntryUpdate: unknown priority value %d", priority); + Logger::Log(LogLevel::LEVEL_ERROR, + "malformed dvrEntryAdd/dvrEntryUpdate: unknown priority value %d", priority); return; } } @@ -2440,7 +2414,7 @@ void CTvheadend::ParseRecordingAddOrUpdate ( htsmsg_t *msg, bool bAdd ) /* Parse state */ if ((state = htsmsg_get_str(msg, "state")) != NULL) { - if (strstr(state, "scheduled") != NULL) + if (strstr(state, "scheduled") != NULL) rec.SetState(PVR_TIMER_STATE_SCHEDULED); else if (strstr(state, "recording") != NULL) rec.SetState(PVR_TIMER_STATE_RECORDING); @@ -2483,8 +2457,10 @@ void CTvheadend::ParseRecordingAddOrUpdate ( htsmsg_t *msg, bool bAdd ) if ((str = htsmsg_get_str(msg, "fanartImage")) != NULL) rec.SetFanartImage(GetImageURL(str)); - if (m_conn->GetProtocol() >= 32) { - if (rec.GetDescription().empty() && !rec.GetSubtitle().empty()) { + if (m_conn->GetProtocol() >= 32) + { + if (rec.GetDescription().empty() && !rec.GetSubtitle().empty()) + { /* Due to changes in HTSP v32, if the description is empty, try to use the subtitle as the description. Clear the subtitle @@ -2507,7 +2483,7 @@ void CTvheadend::ParseRecordingAddOrUpdate ( htsmsg_t *msg, bool bAdd ) else rec.SetError(str); } - + /* A running recording will have an active subscription assigned to it */ if (rec.GetState() == PVR_TIMER_STATE_RECORDING) { @@ -2544,8 +2520,8 @@ void CTvheadend::ParseRecordingAddOrUpdate ( htsmsg_t *msg, bool bAdd ) std::string error = rec.GetError().empty() ? "none" : rec.GetError(); Logger::Log(LogLevel::LEVEL_DEBUG, "recording id:%d, state:%s, title:%s, desc:%s, error:%s", - rec.GetId(), state, rec.GetTitle().c_str(), rec.GetDescription().c_str(), - error.c_str()); + rec.GetId(), state, rec.GetTitle().c_str(), rec.GetDescription().c_str(), + error.c_str()); if (m_asyncState.GetState() > ASYNC_DVR) { @@ -2555,7 +2531,7 @@ void CTvheadend::ParseRecordingAddOrUpdate ( htsmsg_t *msg, bool bAdd ) } } -void CTvheadend::ParseRecordingDelete ( htsmsg_t *msg ) +void CTvheadend::ParseRecordingDelete(htsmsg_t* msg) { uint32_t u32; @@ -2566,7 +2542,7 @@ void CTvheadend::ParseRecordingDelete ( htsmsg_t *msg ) return; } Logger::Log(LogLevel::LEVEL_DEBUG, "delete recording %u", u32); - + /* Erase */ { CLockObject lock(m_mutex); @@ -2582,9 +2558,9 @@ void CTvheadend::ParseRecordingDelete ( htsmsg_t *msg ) TriggerRecordingUpdate(); } -bool CTvheadend::ParseEvent ( htsmsg_t *msg, bool bAdd, Event &evt ) +bool CTvheadend::ParseEvent(htsmsg_t* msg, bool bAdd, Event& evt) { - const char *str; + const char* str; uint32_t u32, id, channel; int64_t s64, start, stop; @@ -2655,8 +2631,10 @@ bool CTvheadend::ParseEvent ( htsmsg_t *msg, bool bAdd, Event &evt ) if (!htsmsg_get_u32(msg, "dvrId", &u32)) evt.SetRecordingId(u32); - if (m_conn->GetProtocol() >= 32) { - if (evt.GetDesc().empty()) { + if (m_conn->GetProtocol() >= 32) + { + if (evt.GetDesc().empty()) + { /* Due to changes in HTSP v32, if the description is empty, try to use the summary as the description. If the summary is empty, @@ -2665,31 +2643,33 @@ bool CTvheadend::ParseEvent ( htsmsg_t *msg, bool bAdd, Event &evt ) This was done by TVHeadend prior to HTSP v32. */ - if (!evt.GetSummary().empty()) { + if (!evt.GetSummary().empty()) + { evt.SetDesc(evt.GetSummary()); evt.SetSummary(""); } - else if (!evt.GetSubtitle().empty()) { + else if (!evt.GetSubtitle().empty()) + { evt.SetDesc(evt.GetSubtitle()); evt.SetSubtitle(""); } } } - - htsmsg_t *l; + + htsmsg_t* l; if ((l = htsmsg_get_map(msg, "credits")) != nullptr) { std::vector writers; std::vector directors; std::vector cast; - htsmsg_field_t *f; + htsmsg_field_t* f; HTSMSG_FOREACH(f, l) { if (f->hmf_name == nullptr) continue; - const char *str = htsmsg_field_get_string(f); + const char* str = htsmsg_field_get_string(f); if (str == nullptr) continue; @@ -2710,10 +2690,10 @@ bool CTvheadend::ParseEvent ( htsmsg_t *msg, bool bAdd, Event &evt ) { std::vector categories; - htsmsg_field_t *f; + htsmsg_field_t* f; HTSMSG_FOREACH(f, l) { - const char *str = f->hmf_str; + const char* str = f->hmf_str; if (str != nullptr) categories.emplace_back(str); } @@ -2724,7 +2704,7 @@ bool CTvheadend::ParseEvent ( htsmsg_t *msg, bool bAdd, Event &evt ) return true; } -void CTvheadend::ParseEventAddOrUpdate ( htsmsg_t *msg, bool bAdd ) +void CTvheadend::ParseEventAddOrUpdate(htsmsg_t* msg, bool bAdd) { Event evt; @@ -2733,12 +2713,12 @@ void CTvheadend::ParseEventAddOrUpdate ( htsmsg_t *msg, bool bAdd ) return; /* create/update schedule */ - Schedule &sched = m_schedules[evt.GetChannel()]; + Schedule& sched = m_schedules[evt.GetChannel()]; sched.SetId(evt.GetChannel()); sched.SetDirty(false); /* create/update event */ - EventUids &events = sched.GetEvents(); + EventUids& events = sched.GetEvents(); bool bUpdated(false); if (bAdd && m_asyncState.GetState() < ASYNC_DONE) @@ -2751,7 +2731,7 @@ void CTvheadend::ParseEventAddOrUpdate ( htsmsg_t *msg, bool bAdd ) { bUpdated = true; - Entity &ent = it->second; + Entity& ent = it->second; ent.SetId(evt.GetId()); ent.SetDirty(false); } @@ -2759,7 +2739,7 @@ void CTvheadend::ParseEventAddOrUpdate ( htsmsg_t *msg, bool bAdd ) if (!bUpdated) { - Entity &ent = events[evt.GetId()]; + Entity& ent = events[evt.GetId()]; ent.SetId(evt.GetId()); ent.SetDirty(false); } @@ -2772,7 +2752,7 @@ void CTvheadend::ParseEventAddOrUpdate ( htsmsg_t *msg, bool bAdd ) PushEpgEventUpdate(evt, (!bAdd || bUpdated) ? EPG_EVENT_UPDATED : EPG_EVENT_CREATED); } -void CTvheadend::ParseEventDelete ( htsmsg_t *msg ) +void CTvheadend::ParseEventDelete(htsmsg_t* msg) { uint32_t u32; @@ -2785,10 +2765,10 @@ void CTvheadend::ParseEventDelete ( htsmsg_t *msg ) Logger::Log(LogLevel::LEVEL_TRACE, "delete event %u", u32); /* Erase */ - for (auto &entry : m_schedules) + for (auto& entry : m_schedules) { - Schedule &schedule = entry.second; - EventUids &events = schedule.GetEvents(); + Schedule& schedule = entry.second; + EventUids& events = schedule.GetEvents(); // Find the event so we can get the channel number auto eit = events.find(u32); @@ -2814,11 +2794,11 @@ uint32_t CTvheadend::GetNextUnnumberedChannelNumber() return number++; } -void CTvheadend::TuneOnOldest( uint32_t channelId ) +void CTvheadend::TuneOnOldest(uint32_t channelId) { HTSPDemuxer* oldest = NULL; - for (auto *dmx : m_dmx) + for (auto* dmx : m_dmx) { if (dmx->GetChannelId() == channelId) { @@ -2833,26 +2813,27 @@ void CTvheadend::TuneOnOldest( uint32_t channelId ) if (oldest) { Logger::Log(LogLevel::LEVEL_TRACE, "pretuning channel %u on subscription %u", - m_channels[channelId].GetNum(), oldest->GetSubscriptionId()); + m_channels[channelId].GetNum(), oldest->GetSubscriptionId()); oldest->Open(channelId, SUBSCRIPTION_WEIGHT_PRETUNING); } } -void CTvheadend::PredictiveTune( uint32_t fromChannelId, uint32_t toChannelId ) +void CTvheadend::PredictiveTune(uint32_t fromChannelId, uint32_t toChannelId) { CLockObject lock(m_mutex); /* Consult the predictive tuning helper for which channel * should be predictably tuned next */ - uint32_t predictedChannelId = m_channelTuningPredictor.PredictNextChannelId(fromChannelId, toChannelId); + uint32_t predictedChannelId = + m_channelTuningPredictor.PredictNextChannelId(fromChannelId, toChannelId); if (predictedChannelId != predictivetune::CHANNEL_ID_NONE) TuneOnOldest(predictedChannelId); } -bool CTvheadend::DemuxOpen( const PVR_CHANNEL &chn ) +bool CTvheadend::DemuxOpen(const PVR_CHANNEL& chn) { - HTSPDemuxer *oldest; + HTSPDemuxer* oldest; uint32_t prevId; oldest = m_dmx[0]; @@ -2867,12 +2848,12 @@ bool CTvheadend::DemuxOpen( const PVR_CHANNEL &chn ) /* If we have a lingering subscription for the target channel * we reuse that subscription */ - for (auto *dmx : m_dmx) + for (auto* dmx : m_dmx) { if (dmx->GetChannelId() == chn.iUniqueId) { Logger::Log(LogLevel::LEVEL_TRACE, "retuning channel %u on subscription %u", - m_channels[chn.iUniqueId].GetNum(), dmx->GetSubscriptionId()); + m_channels[chn.iUniqueId].GetNum(), dmx->GetSubscriptionId()); if (dmx != m_dmx_active) { @@ -2899,7 +2880,7 @@ bool CTvheadend::DemuxOpen( const PVR_CHANNEL &chn ) /* If we don't have an existing subscription for the channel we create one * on the oldest demuxer */ Logger::Log(LogLevel::LEVEL_TRACE, "tuning channel %u on subscription %u", - m_channels[chn.iUniqueId].GetNum(), oldest->GetSubscriptionId()); + m_channels[chn.iUniqueId].GetNum(), oldest->GetSubscriptionId()); prevId = m_dmx_active->GetChannelId(); m_dmx_active->Weight(SUBSCRIPTION_WEIGHT_POSTTUNING); @@ -2912,9 +2893,9 @@ bool CTvheadend::DemuxOpen( const PVR_CHANNEL &chn ) return m_playingLiveStream; } -DemuxPacket* CTvheadend::DemuxRead ( void ) +DemuxPacket* CTvheadend::DemuxRead(void) { - DemuxPacket *pkt = NULL; + DemuxPacket* pkt = NULL; if (m_streamchange) { @@ -2928,7 +2909,7 @@ DemuxPacket* CTvheadend::DemuxRead ( void ) return pkt; } - for (auto *dmx : m_dmx) + for (auto* dmx : m_dmx) { if (dmx == m_dmx_active) pkt = dmx->Read(); @@ -2938,7 +2919,7 @@ DemuxPacket* CTvheadend::DemuxRead ( void ) return pkt; } -void CTvheadend::DemuxClose ( void ) +void CTvheadend::DemuxClose(void) { // If predictive tuning is active, demuxers will be closed automatically once they are expired. if (m_dmx.size() == 1) @@ -2947,44 +2928,44 @@ void CTvheadend::DemuxClose ( void ) m_playingLiveStream = false; } -void CTvheadend::DemuxFlush ( void ) +void CTvheadend::DemuxFlush(void) { m_dmx_active->Flush(); } -void CTvheadend::DemuxAbort ( void ) +void CTvheadend::DemuxAbort(void) { // If predictive tuning is active, demuxers will be closed/aborted automatically once they are expired. if (m_dmx.size() == 1) m_dmx_active->Abort(); } -bool CTvheadend::DemuxSeek ( double time, bool backward, double *startpts ) +bool CTvheadend::DemuxSeek(double time, bool backward, double* startpts) { return m_dmx_active->Seek(time, backward, startpts); } -void CTvheadend::DemuxSpeed ( int speed ) +void CTvheadend::DemuxSpeed(int speed) { m_dmx_active->Speed(speed); } -void CTvheadend::DemuxFillBuffer ( bool mode ) +void CTvheadend::DemuxFillBuffer(bool mode) { m_dmx_active->FillBuffer(mode); } -PVR_ERROR CTvheadend::DemuxCurrentStreams ( PVR_STREAM_PROPERTIES *streams ) +PVR_ERROR CTvheadend::DemuxCurrentStreams(PVR_STREAM_PROPERTIES* streams) { return m_dmx_active->CurrentStreams(streams); } -PVR_ERROR CTvheadend::DemuxCurrentSignal ( PVR_SIGNAL_STATUS &sig ) +PVR_ERROR CTvheadend::DemuxCurrentSignal(PVR_SIGNAL_STATUS& sig) { return m_dmx_active->CurrentSignal(sig); } -PVR_ERROR CTvheadend::DemuxCurrentDescramble( PVR_DESCRAMBLE_INFO *info) +PVR_ERROR CTvheadend::DemuxCurrentDescramble(PVR_DESCRAMBLE_INFO* info) { return m_dmx_active->CurrentDescrambleInfo(info); } @@ -2999,7 +2980,7 @@ bool CTvheadend::DemuxIsRealTimeStream() const return m_dmx_active->IsRealTimeStream(); } -PVR_ERROR CTvheadend::GetStreamTimes(PVR_STREAM_TIMES *times) +PVR_ERROR CTvheadend::GetStreamTimes(PVR_STREAM_TIMES* times) { if (m_playingLiveStream) { @@ -3023,15 +3004,17 @@ PVR_ERROR CTvheadend::GetStreamTimes(PVR_STREAM_TIMES *times) // Older tvh versions do not expose real recording start/stop time. // Remark: Following calculation does not always work. Returned end time might be to large, as the // recording might actually have started later than scheduled start time (server came up too late etc). - times->ptsEnd = (m_playingRecording->GetStartExtra() * 60 - + std::time(nullptr) - m_playingRecording->GetStart()) * DVD_TIME_BASE; + times->ptsEnd = (m_playingRecording->GetStartExtra() * 60 + std::time(nullptr) - + m_playingRecording->GetStart()) * + DVD_TIME_BASE; } } else { if (m_playingRecording->GetFilesStart() > 0 && m_playingRecording->GetFilesStop() > 0) { - times->ptsEnd = (m_playingRecording->GetFilesStop() - m_playingRecording->GetFilesStart()) * DVD_TIME_BASE; + times->ptsEnd = (m_playingRecording->GetFilesStop() - m_playingRecording->GetFilesStart()) * + DVD_TIME_BASE; } else { diff --git a/src/Tvheadend.h b/src/Tvheadend.h index 201c5596..e1f04162 100644 --- a/src/Tvheadend.h +++ b/src/Tvheadend.h @@ -21,18 +21,16 @@ * */ -extern "C" { -#include +extern "C" +{ #include "libhts/htsmsg.h" -} -#include -#include -#include +#include +} -#include "p8-platform/util/buffer.h" +#include "client.h" #include "p8-platform/threads/threads.h" - +#include "p8-platform/util/buffer.h" #include "tvheadend/AutoRecordings.h" #include "tvheadend/ChannelTuningPredictor.h" #include "tvheadend/HTSPMessage.h" @@ -44,7 +42,10 @@ extern "C" { #include "tvheadend/entity/Schedule.h" #include "tvheadend/entity/Tag.h" #include "tvheadend/utilities/AsyncState.h" -#include "client.h" + +#include +#include +#include #define UNNUMBERED_CHANNEL (10000) @@ -56,7 +57,7 @@ namespace tvheadend class HTSPConnection; class HTSPDemuxer; class HTSPVFS; -} +} // namespace tvheadend /* Typedefs */ typedef P8PLATFORM::SyncedBuffer HTSPMessageQueue; @@ -64,64 +65,57 @@ typedef P8PLATFORM::SyncedBuffer HTSPMessageQueue; /* * Root object for Tvheadend connection */ -class CTvheadend - : public P8PLATFORM::CThread, public tvheadend::IHTSPConnectionListener +class CTvheadend : public P8PLATFORM::CThread, public tvheadend::IHTSPConnectionListener { public: - CTvheadend(PVR_PROPERTIES *pvrProps); + CTvheadend(PVR_PROPERTIES* pvrProps); ~CTvheadend() override; - void Start ( void ); - void Stop ( void ); + void Start(void); + void Stop(void); // IHTSPConnectionListener implementation void Disconnected() override; bool Connected() override; - bool ProcessMessage(const char *method, htsmsg_t *msg) override; - - const tvheadend::entity::Channels& GetChannels () const - { - return m_channels; - } - - PVR_ERROR GetDriveSpace ( long long *total, long long *used ); - - int GetTagCount ( void ); - PVR_ERROR GetTags ( ADDON_HANDLE handle, bool bRadio ); - PVR_ERROR GetTagMembers ( ADDON_HANDLE handle, - const PVR_CHANNEL_GROUP &group ); - - int GetChannelCount ( void ); - PVR_ERROR GetChannels ( ADDON_HANDLE handle, bool radio ); - - int GetRecordingCount ( void ); - PVR_ERROR GetRecordings ( ADDON_HANDLE handle ); - PVR_ERROR GetRecordingEdl ( const PVR_RECORDING &rec, PVR_EDL_ENTRY edl[], - int *num ); - PVR_ERROR DeleteRecording ( const PVR_RECORDING &rec ); - PVR_ERROR RenameRecording ( const PVR_RECORDING &rec ); - PVR_ERROR SetLifetime (const PVR_RECORDING &rec); - PVR_ERROR SetPlayCount ( const PVR_RECORDING &rec, int playcount ); - PVR_ERROR SetPlayPosition ( const PVR_RECORDING &rec, int playposition ); - int GetPlayPosition ( const PVR_RECORDING &rec ); - PVR_ERROR GetTimerTypes ( PVR_TIMER_TYPE types[], int *size ); - int GetTimerCount ( void ); - PVR_ERROR GetTimers ( ADDON_HANDLE handle ); - PVR_ERROR AddTimer ( const PVR_TIMER &tmr ); - PVR_ERROR DeleteTimer ( const PVR_TIMER &tmr, bool force ); - PVR_ERROR UpdateTimer ( const PVR_TIMER &tmr ); - - PVR_ERROR GetEPGForChannel ( ADDON_HANDLE handle, int iChannelUid, - time_t start, time_t end ); - PVR_ERROR SetEPGTimeFrame ( int iDays ); + bool ProcessMessage(const char* method, htsmsg_t* msg) override; + + const tvheadend::entity::Channels& GetChannels() const { return m_channels; } + + PVR_ERROR GetDriveSpace(long long* total, long long* used); + + int GetTagCount(void); + PVR_ERROR GetTags(ADDON_HANDLE handle, bool bRadio); + PVR_ERROR GetTagMembers(ADDON_HANDLE handle, const PVR_CHANNEL_GROUP& group); + + int GetChannelCount(void); + PVR_ERROR GetChannels(ADDON_HANDLE handle, bool radio); + + int GetRecordingCount(void); + PVR_ERROR GetRecordings(ADDON_HANDLE handle); + PVR_ERROR GetRecordingEdl(const PVR_RECORDING& rec, PVR_EDL_ENTRY edl[], int* num); + PVR_ERROR DeleteRecording(const PVR_RECORDING& rec); + PVR_ERROR RenameRecording(const PVR_RECORDING& rec); + PVR_ERROR SetLifetime(const PVR_RECORDING& rec); + PVR_ERROR SetPlayCount(const PVR_RECORDING& rec, int playcount); + PVR_ERROR SetPlayPosition(const PVR_RECORDING& rec, int playposition); + int GetPlayPosition(const PVR_RECORDING& rec); + PVR_ERROR GetTimerTypes(PVR_TIMER_TYPE types[], int* size); + int GetTimerCount(void); + PVR_ERROR GetTimers(ADDON_HANDLE handle); + PVR_ERROR AddTimer(const PVR_TIMER& tmr); + PVR_ERROR DeleteTimer(const PVR_TIMER& tmr, bool force); + PVR_ERROR UpdateTimer(const PVR_TIMER& tmr); + + PVR_ERROR GetEPGForChannel(ADDON_HANDLE handle, int iChannelUid, time_t start, time_t end); + PVR_ERROR SetEPGTimeFrame(int iDays); void GetLivetimeValues(std::vector>& lifetimeValues) const; private: - bool CreateTimer ( const tvheadend::entity::Recording &tvhTmr, PVR_TIMER &tmr ); + bool CreateTimer(const tvheadend::entity::Recording& tvhTmr, PVR_TIMER& tmr); - uint32_t GetNextUnnumberedChannelNumber (); - std::string GetImageURL ( const char *str ); + uint32_t GetNextUnnumberedChannelNumber(); + std::string GetImageURL(const char* str); /** * Queries the server for available streaming profiles and populates @@ -133,18 +127,18 @@ class CTvheadend * @param streamingProfile the streaming profile to check for * @return whether the server supports the specified streaming profile */ - bool HasStreamingProfile(const std::string &streamingProfile) const; + bool HasStreamingProfile(const std::string& streamingProfile) const; /* * Predictive tuning */ - void PredictiveTune ( uint32_t fromChannelId, uint32_t toChannelId ); - void TuneOnOldest ( uint32_t channelId ); + void PredictiveTune(uint32_t fromChannelId, uint32_t toChannelId); + void TuneOnOldest(uint32_t channelId); /* * Message processing (CThread implementation) */ - void *Process() override; + void* Process() override; /* * Event handling @@ -153,42 +147,45 @@ class CTvheadend void TriggerChannelUpdate(); void TriggerRecordingUpdate(); void TriggerTimerUpdate(); - void PushEpgEventUpdate(const tvheadend::entity::Event &epg, EPG_EVENT_STATE state); + void PushEpgEventUpdate(const tvheadend::entity::Event& epg, EPG_EVENT_STATE state); /* * Epg Handling */ - void CreateEvent ( const tvheadend::entity::Event &event, EPG_TAG &epg ); - void TransferEvent ( const tvheadend::entity::Event &event, EPG_EVENT_STATE state ); - void TransferEvent ( ADDON_HANDLE handle, const tvheadend::entity::Event &event ); + void CreateEvent(const tvheadend::entity::Event& event, EPG_TAG& epg); + void TransferEvent(const tvheadend::entity::Event& event, EPG_EVENT_STATE state); + void TransferEvent(ADDON_HANDLE handle, const tvheadend::entity::Event& event); /* * Message sending */ - PVR_ERROR SendDvrDelete ( uint32_t id, const char *method ); - PVR_ERROR SendDvrUpdate ( htsmsg_t *m ); + PVR_ERROR SendDvrDelete(uint32_t id, const char* method); + PVR_ERROR SendDvrUpdate(htsmsg_t* m); /* * Channel/Tags/Recordings/Events */ - void SyncChannelsCompleted ( void ); - void SyncDvrCompleted ( void ); - void SyncEpgCompleted ( void ); - void SyncCompleted ( void ); - void ParseTagAddOrUpdate ( htsmsg_t *m, bool bAdd ); - void ParseTagDelete ( htsmsg_t *m ); - void ParseChannelAddOrUpdate ( htsmsg_t *m, bool bAdd ); - void ParseChannelDelete ( htsmsg_t *m ); - void ParseRecordingAddOrUpdate ( htsmsg_t *m, bool bAdd ); - void ParseRecordingDelete ( htsmsg_t *m ); - void ParseEventAddOrUpdate ( htsmsg_t *m, bool bAdd ); - void ParseEventDelete ( htsmsg_t *m ); - bool ParseEvent ( htsmsg_t *msg, bool bAdd, tvheadend::entity::Event &evt ); + void SyncChannelsCompleted(void); + void SyncDvrCompleted(void); + void SyncEpgCompleted(void); + void SyncCompleted(void); + void ParseTagAddOrUpdate(htsmsg_t* m, bool bAdd); + void ParseTagDelete(htsmsg_t* m); + void ParseChannelAddOrUpdate(htsmsg_t* m, bool bAdd); + void ParseChannelDelete(htsmsg_t* m); + void ParseRecordingAddOrUpdate(htsmsg_t* m, bool bAdd); + void ParseRecordingDelete(htsmsg_t* m); + void ParseEventAddOrUpdate(htsmsg_t* m, bool bAdd); + void ParseEventDelete(htsmsg_t* m); + bool ParseEvent(htsmsg_t* msg, bool bAdd, tvheadend::entity::Event& evt); /* * VFS */ - bool VfsIsActiveRecording() const { return m_playingRecording && m_playingRecording->GetState() == PVR_TIMER_STATE_RECORDING; } + bool VfsIsActiveRecording() const + { + return m_playingRecording && m_playingRecording->GetState() == PVR_TIMER_STATE_RECORDING; + } public: /* @@ -198,35 +195,35 @@ class CTvheadend std::string GetServerVersion() const; std::string GetServerString() const; int GetProtocol() const; - bool HasCapability(const std::string &capability) const; + bool HasCapability(const std::string& capability) const; void OnSleep(); void OnWake(); /* * Demuxer */ - bool DemuxOpen ( const PVR_CHANNEL &chn ); - void DemuxClose ( void ); - DemuxPacket *DemuxRead ( void ); - void DemuxFlush ( void ); - void DemuxAbort ( void ); - bool DemuxSeek ( double time, bool backward, double *startpts ); - void DemuxSpeed ( int speed ); - void DemuxFillBuffer ( bool mode ); - PVR_ERROR DemuxCurrentStreams ( PVR_STREAM_PROPERTIES *streams ); - PVR_ERROR DemuxCurrentSignal ( PVR_SIGNAL_STATUS &sig ); - PVR_ERROR DemuxCurrentDescramble( PVR_DESCRAMBLE_INFO *info); - bool DemuxIsTimeShifting() const; - bool DemuxIsRealTimeStream() const; + bool DemuxOpen(const PVR_CHANNEL& chn); + void DemuxClose(void); + DemuxPacket* DemuxRead(void); + void DemuxFlush(void); + void DemuxAbort(void); + bool DemuxSeek(double time, bool backward, double* startpts); + void DemuxSpeed(int speed); + void DemuxFillBuffer(bool mode); + PVR_ERROR DemuxCurrentStreams(PVR_STREAM_PROPERTIES* streams); + PVR_ERROR DemuxCurrentSignal(PVR_SIGNAL_STATUS& sig); + PVR_ERROR DemuxCurrentDescramble(PVR_DESCRAMBLE_INFO* info); + bool DemuxIsTimeShifting() const; + bool DemuxIsRealTimeStream() const; void CloseExpiredSubscriptions(); /* * VFS (pass-thru) */ - bool VfsOpen(const PVR_RECORDING &rec); + bool VfsOpen(const PVR_RECORDING& rec); void VfsClose(); - ssize_t VfsRead(unsigned char *buf, unsigned int len); + ssize_t VfsRead(unsigned char* buf, unsigned int len); long long VfsSeek(long long position, int whence); long long VfsSize(); void VfsPauseStream(bool paused); @@ -235,7 +232,7 @@ class CTvheadend /* * stream times (live streams and recordings) */ - PVR_ERROR GetStreamTimes(PVR_STREAM_TIMES *times); + PVR_ERROR GetStreamTimes(PVR_STREAM_TIMES* times); /** * The streaming profiles available on the server @@ -271,5 +268,4 @@ class CTvheadend bool m_playingLiveStream; tvheadend::entity::Recording* m_playingRecording; - }; diff --git a/src/client.cpp b/src/client.cpp index 36e3520c..55c86968 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -20,10 +20,11 @@ */ #include "client.h" -#include "kodi/xbmc_pvr_dll.h" + +#include "Tvheadend.h" #include "kodi/libKODI_guilib.h" +#include "kodi/xbmc_pvr_dll.h" #include "p8-platform/util/util.h" -#include "Tvheadend.h" #include "tvheadend/Settings.h" #include "tvheadend/utilities/Logger.h" @@ -45,561 +46,432 @@ ADDON_STATUS m_CurStatus = ADDON_STATUS_UNKNOWN; * Globals */ CMutex g_mutex; -CHelper_libXBMC_addon *XBMC = NULL; -CHelper_libXBMC_pvr *PVR = NULL; -PVR_MENUHOOK *menuHook = NULL; -CTvheadend *tvh = NULL; +CHelper_libXBMC_addon* XBMC = NULL; +CHelper_libXBMC_pvr* PVR = NULL; +PVR_MENUHOOK* menuHook = NULL; +CTvheadend* tvh = NULL; /* ************************************************************************** * ADDON setup * *************************************************************************/ -extern "C" { - -void ADDON_ReadSettings(void) +extern "C" { - Settings::GetInstance().ReadSettings(); -} -ADDON_STATUS ADDON_Create(void* hdl, void* props) -{ - if (!hdl || !props) - return m_CurStatus; + void ADDON_ReadSettings(void) { Settings::GetInstance().ReadSettings(); } - /* Instantiate helpers */ - XBMC = new CHelper_libXBMC_addon; - PVR = new CHelper_libXBMC_pvr; - - if (!XBMC->RegisterMe(hdl) || - !PVR->RegisterMe(hdl)) + ADDON_STATUS ADDON_Create(void* hdl, void* props) { - SAFE_DELETE(PVR); - SAFE_DELETE(XBMC); - m_CurStatus = ADDON_STATUS_PERMANENT_FAILURE; - return m_CurStatus; - } + if (!hdl || !props) + return m_CurStatus; - /* Configure the logger */ - Logger::GetInstance().SetImplementation([](LogLevel level, const char *message) - { - /* Convert the log level */ - addon_log_t addonLevel; + /* Instantiate helpers */ + XBMC = new CHelper_libXBMC_addon; + PVR = new CHelper_libXBMC_pvr; - switch (level) + if (!XBMC->RegisterMe(hdl) || !PVR->RegisterMe(hdl)) { - case LogLevel::LEVEL_ERROR: - addonLevel = addon_log_t::LOG_ERROR; - break; - case LogLevel::LEVEL_INFO: - addonLevel = addon_log_t::LOG_INFO; - break; - default: - addonLevel = addon_log_t::LOG_DEBUG; + SAFE_DELETE(PVR); + SAFE_DELETE(XBMC); + m_CurStatus = ADDON_STATUS_PERMANENT_FAILURE; + return m_CurStatus; } - /* Don't log trace messages unless told so */ - if (level == LogLevel::LEVEL_TRACE && !Settings::GetInstance().GetTraceDebug()) - return; + /* Configure the logger */ + Logger::GetInstance().SetImplementation([](LogLevel level, const char* message) { + /* Convert the log level */ + addon_log_t addonLevel; - XBMC->Log(addonLevel, "%s", message); - }); + switch (level) + { + case LogLevel::LEVEL_ERROR: + addonLevel = addon_log_t::LOG_ERROR; + break; + case LogLevel::LEVEL_INFO: + addonLevel = addon_log_t::LOG_INFO; + break; + default: + addonLevel = addon_log_t::LOG_DEBUG; + } - Logger::GetInstance().SetPrefix("pvr.hts"); + /* Don't log trace messages unless told so */ + if (level == LogLevel::LEVEL_TRACE && !Settings::GetInstance().GetTraceDebug()) + return; - Logger::Log(LogLevel::LEVEL_INFO, "starting PVR client"); + XBMC->Log(addonLevel, "%s", message); + }); - ADDON_ReadSettings(); + Logger::GetInstance().SetPrefix("pvr.hts"); - tvh = new CTvheadend(reinterpret_cast(props)); - tvh->Start(); + Logger::Log(LogLevel::LEVEL_INFO, "starting PVR client"); - m_CurStatus = ADDON_STATUS_OK; - return m_CurStatus; -} + ADDON_ReadSettings(); -ADDON_STATUS ADDON_GetStatus() -{ - CLockObject lock(g_mutex); - return m_CurStatus; -} + tvh = new CTvheadend(reinterpret_cast(props)); + tvh->Start(); -void ADDON_Destroy() -{ - CLockObject lock(g_mutex); - tvh->Stop(); - SAFE_DELETE(tvh); - SAFE_DELETE(PVR); - SAFE_DELETE(XBMC); - SAFE_DELETE(menuHook); - m_CurStatus = ADDON_STATUS_UNKNOWN; -} - -ADDON_STATUS ADDON_SetSetting - (const char *settingName, const void *settingValue) -{ - CLockObject lock(g_mutex); - m_CurStatus = Settings::GetInstance().SetSetting(settingName, settingValue); - return m_CurStatus; -} + m_CurStatus = ADDON_STATUS_OK; + return m_CurStatus; + } -void OnSystemSleep() -{ - tvh->OnSleep(); -} + ADDON_STATUS ADDON_GetStatus() + { + CLockObject lock(g_mutex); + return m_CurStatus; + } -void OnSystemWake() -{ - tvh->OnWake(); -} + void ADDON_Destroy() + { + CLockObject lock(g_mutex); + tvh->Stop(); + SAFE_DELETE(tvh); + SAFE_DELETE(PVR); + SAFE_DELETE(XBMC); + SAFE_DELETE(menuHook); + m_CurStatus = ADDON_STATUS_UNKNOWN; + } -void OnPowerSavingActivated() -{ -} + ADDON_STATUS ADDON_SetSetting(const char* settingName, const void* settingValue) + { + CLockObject lock(g_mutex); + m_CurStatus = Settings::GetInstance().SetSetting(settingName, settingValue); + return m_CurStatus; + } -void OnPowerSavingDeactivated() -{ -} + void OnSystemSleep() { tvh->OnSleep(); } -/* ************************************************************************** + void OnSystemWake() { tvh->OnWake(); } + + void OnPowerSavingActivated() {} + + void OnPowerSavingDeactivated() {} + + /* ************************************************************************** * Capabilities / Info * *************************************************************************/ -PVR_ERROR GetAddonCapabilities(PVR_ADDON_CAPABILITIES* pCapabilities) -{ - pCapabilities->bSupportsEPG = true; - pCapabilities->bSupportsTV = true; - pCapabilities->bSupportsRadio = true; - pCapabilities->bSupportsRecordings = true; - pCapabilities->bSupportsRecordingsUndelete = false; - pCapabilities->bSupportsTimers = true; - pCapabilities->bSupportsChannelGroups = true; - pCapabilities->bHandlesInputStream = true; - pCapabilities->bHandlesDemuxing = true; - pCapabilities->bSupportsRecordingEdl = true; - pCapabilities->bSupportsRecordingPlayCount = (tvh->GetProtocol() >= 27 && Settings::GetInstance().GetDvrPlayStatus()); - pCapabilities->bSupportsLastPlayedPosition = (tvh->GetProtocol() >= 27 && Settings::GetInstance().GetDvrPlayStatus()); - pCapabilities->bSupportsDescrambleInfo = true; - pCapabilities->bSupportsAsyncEPGTransfer = Settings::GetInstance().GetAsyncEpg(); - - if (tvh->GetProtocol() >= 28) - { - pCapabilities->bSupportsRecordingsRename = true; - - pCapabilities->bSupportsRecordingsLifetimeChange = true; - - /* PVR_RECORDING.iLifetime values and presentation.*/ - std::vector> lifetimeValues; - tvh->GetLivetimeValues(lifetimeValues); - - pCapabilities->iRecordingsLifetimesSize = lifetimeValues.size(); - - int i = 0; - for (auto it = lifetimeValues.cbegin(); it != lifetimeValues.cend(); ++it, ++i) + PVR_ERROR GetAddonCapabilities(PVR_ADDON_CAPABILITIES* pCapabilities) + { + pCapabilities->bSupportsEPG = true; + pCapabilities->bSupportsTV = true; + pCapabilities->bSupportsRadio = true; + pCapabilities->bSupportsRecordings = true; + pCapabilities->bSupportsRecordingsUndelete = false; + pCapabilities->bSupportsTimers = true; + pCapabilities->bSupportsChannelGroups = true; + pCapabilities->bHandlesInputStream = true; + pCapabilities->bHandlesDemuxing = true; + pCapabilities->bSupportsRecordingEdl = true; + pCapabilities->bSupportsRecordingPlayCount = + (tvh->GetProtocol() >= 27 && Settings::GetInstance().GetDvrPlayStatus()); + pCapabilities->bSupportsLastPlayedPosition = + (tvh->GetProtocol() >= 27 && Settings::GetInstance().GetDvrPlayStatus()); + pCapabilities->bSupportsDescrambleInfo = true; + pCapabilities->bSupportsAsyncEPGTransfer = Settings::GetInstance().GetAsyncEpg(); + + if (tvh->GetProtocol() >= 28) { - pCapabilities->recordingsLifetimeValues[i].iValue = it->first; - strncpy(pCapabilities->recordingsLifetimeValues[i].strDescription, - it->second.c_str(), - sizeof(pCapabilities->recordingsLifetimeValues[i].strDescription) - 1); + pCapabilities->bSupportsRecordingsRename = true; + + pCapabilities->bSupportsRecordingsLifetimeChange = true; + + /* PVR_RECORDING.iLifetime values and presentation.*/ + std::vector> lifetimeValues; + tvh->GetLivetimeValues(lifetimeValues); + + pCapabilities->iRecordingsLifetimesSize = lifetimeValues.size(); + + int i = 0; + for (auto it = lifetimeValues.cbegin(); it != lifetimeValues.cend(); ++it, ++i) + { + pCapabilities->recordingsLifetimeValues[i].iValue = it->first; + strncpy(pCapabilities->recordingsLifetimeValues[i].strDescription, it->second.c_str(), + sizeof(pCapabilities->recordingsLifetimeValues[i].strDescription) - 1); + } } + return PVR_ERROR_NO_ERROR; } - return PVR_ERROR_NO_ERROR; -} -const char *GetBackendName(void) -{ - static std::string serverName; + const char* GetBackendName(void) + { + static std::string serverName; - serverName = tvh->GetServerName(); - return serverName.c_str(); -} + serverName = tvh->GetServerName(); + return serverName.c_str(); + } -const char *GetBackendVersion(void) -{ - static std::string serverVersion; + const char* GetBackendVersion(void) + { + static std::string serverVersion; - serverVersion = tvh->GetServerVersion(); - return serverVersion.c_str(); -} + serverVersion = tvh->GetServerVersion(); + return serverVersion.c_str(); + } -const char *GetConnectionString(void) -{ - static std::string serverString; + const char* GetConnectionString(void) + { + static std::string serverString; - serverString = tvh->GetServerString(); - return serverString.c_str(); -} + serverString = tvh->GetServerString(); + return serverString.c_str(); + } -const char *GetBackendHostname(void) -{ - return Settings::GetInstance().GetConstCharHostname(); -} + const char* GetBackendHostname(void) { return Settings::GetInstance().GetConstCharHostname(); } -PVR_ERROR GetDriveSpace(long long *iTotal, long long *iUsed) -{ - return tvh->GetDriveSpace(iTotal, iUsed); -} + PVR_ERROR GetDriveSpace(long long* iTotal, long long* iUsed) + { + return tvh->GetDriveSpace(iTotal, iUsed); + } -/* ************************************************************************** + /* ************************************************************************** * GUI hooks * *************************************************************************/ -PVR_ERROR CallMenuHook(const PVR_MENUHOOK&, const PVR_MENUHOOK_DATA&) -{ - return PVR_ERROR_NO_ERROR; -} + PVR_ERROR CallMenuHook(const PVR_MENUHOOK&, const PVR_MENUHOOK_DATA&) + { + return PVR_ERROR_NO_ERROR; + } -/* ************************************************************************** + /* ************************************************************************** * Demuxer * *************************************************************************/ -PVR_ERROR GetStreamReadChunkSize(int* chunksize) -{ - if (!chunksize) - return PVR_ERROR_INVALID_PARAMETERS; + PVR_ERROR GetStreamReadChunkSize(int* chunksize) + { + if (!chunksize) + return PVR_ERROR_INVALID_PARAMETERS; - *chunksize = Settings::GetInstance().GetStreamReadChunkSize() * 1024; - return PVR_ERROR_NO_ERROR; -} + *chunksize = Settings::GetInstance().GetStreamReadChunkSize() * 1024; + return PVR_ERROR_NO_ERROR; + } -bool CanPauseStream(void) -{ - return tvh->HasCapability("timeshift"); -} + bool CanPauseStream(void) { return tvh->HasCapability("timeshift"); } -bool CanSeekStream(void) -{ - return tvh->HasCapability("timeshift"); -} + bool CanSeekStream(void) { return tvh->HasCapability("timeshift"); } -PVR_ERROR GetStreamTimes(PVR_STREAM_TIMES *times) -{ - if (!times) - return PVR_ERROR_INVALID_PARAMETERS; + PVR_ERROR GetStreamTimes(PVR_STREAM_TIMES* times) + { + if (!times) + return PVR_ERROR_INVALID_PARAMETERS; - return tvh->GetStreamTimes(times); -} + return tvh->GetStreamTimes(times); + } -bool IsTimeshifting(void) -{ - return tvh->DemuxIsTimeShifting(); -} + bool IsTimeshifting(void) { return tvh->DemuxIsTimeShifting(); } -bool IsRealTimeStream() -{ - if (tvh->m_playingRecording) - return tvh->VfsIsRealTimeStream(); - else - return tvh->DemuxIsRealTimeStream(); -} + bool IsRealTimeStream() + { + if (tvh->m_playingRecording) + return tvh->VfsIsRealTimeStream(); + else + return tvh->DemuxIsRealTimeStream(); + } -bool OpenLiveStream(const PVR_CHANNEL &channel) -{ - return tvh->DemuxOpen(channel); -} + bool OpenLiveStream(const PVR_CHANNEL& channel) { return tvh->DemuxOpen(channel); } -void CloseLiveStream(void) -{ - tvh->DemuxClose(); -} + void CloseLiveStream(void) { tvh->DemuxClose(); } -bool SeekTime(double time,bool backward,double *startpts) -{ - return tvh->DemuxSeek(time, backward, startpts); -} + bool SeekTime(double time, bool backward, double* startpts) + { + return tvh->DemuxSeek(time, backward, startpts); + } -void SetSpeed(int speed) -{ - tvh->DemuxSpeed(speed); -} + void SetSpeed(int speed) { tvh->DemuxSpeed(speed); } -void PauseStream(bool paused) -{ - if (tvh->m_playingRecording) - tvh->VfsPauseStream(paused); -} + void PauseStream(bool paused) + { + if (tvh->m_playingRecording) + tvh->VfsPauseStream(paused); + } -PVR_ERROR GetStreamProperties(PVR_STREAM_PROPERTIES* pProperties) -{ - return tvh->DemuxCurrentStreams(pProperties); -} + PVR_ERROR GetStreamProperties(PVR_STREAM_PROPERTIES* pProperties) + { + return tvh->DemuxCurrentStreams(pProperties); + } -void FillBuffer(bool mode) -{ - tvh->DemuxFillBuffer(mode); -} + void FillBuffer(bool mode) { tvh->DemuxFillBuffer(mode); } -PVR_ERROR SignalStatus(PVR_SIGNAL_STATUS &signalStatus) -{ - return tvh->DemuxCurrentSignal(signalStatus); -} + PVR_ERROR SignalStatus(PVR_SIGNAL_STATUS& signalStatus) + { + return tvh->DemuxCurrentSignal(signalStatus); + } -PVR_ERROR GetDescrambleInfo(PVR_DESCRAMBLE_INFO* descrambleInfo) -{ - if (!descrambleInfo) - return PVR_ERROR_INVALID_PARAMETERS; + PVR_ERROR GetDescrambleInfo(PVR_DESCRAMBLE_INFO* descrambleInfo) + { + if (!descrambleInfo) + return PVR_ERROR_INVALID_PARAMETERS; - return tvh->DemuxCurrentDescramble(descrambleInfo); -} + return tvh->DemuxCurrentDescramble(descrambleInfo); + } -DemuxPacket* DemuxRead(void) -{ - return tvh->DemuxRead(); -} + DemuxPacket* DemuxRead(void) { return tvh->DemuxRead(); } -void DemuxAbort(void) -{ - tvh->DemuxAbort(); -} + void DemuxAbort(void) { tvh->DemuxAbort(); } -void DemuxReset(void) -{ -} + void DemuxReset(void) {} -void DemuxFlush(void) -{ - tvh->DemuxFlush(); -} + void DemuxFlush(void) { tvh->DemuxFlush(); } -/* ************************************************************************** + /* ************************************************************************** * Channel Management * *************************************************************************/ -int GetChannelGroupsAmount(void) -{ - return tvh->GetTagCount(); -} + int GetChannelGroupsAmount(void) { return tvh->GetTagCount(); } -PVR_ERROR GetChannelGroups(ADDON_HANDLE handle, bool bRadio) -{ - return tvh->GetTags(handle, bRadio); -} + PVR_ERROR GetChannelGroups(ADDON_HANDLE handle, bool bRadio) + { + return tvh->GetTags(handle, bRadio); + } -PVR_ERROR GetChannelGroupMembers(ADDON_HANDLE handle, const PVR_CHANNEL_GROUP &group) -{ - return tvh->GetTagMembers(handle, group); -} + PVR_ERROR GetChannelGroupMembers(ADDON_HANDLE handle, const PVR_CHANNEL_GROUP& group) + { + return tvh->GetTagMembers(handle, group); + } -int GetChannelsAmount(void) -{ - return tvh->GetChannelCount(); -} + int GetChannelsAmount(void) { return tvh->GetChannelCount(); } -PVR_ERROR GetChannels(ADDON_HANDLE handle, bool bRadio) -{ - return tvh->GetChannels(handle, bRadio); -} + PVR_ERROR GetChannels(ADDON_HANDLE handle, bool bRadio) + { + return tvh->GetChannels(handle, bRadio); + } -/* ************************************************************************** + /* ************************************************************************** * EPG * *************************************************************************/ -PVR_ERROR GetEPGForChannel - (ADDON_HANDLE handle, int iChannelUid, time_t iStart, time_t iEnd) -{ - return tvh->GetEPGForChannel(handle, iChannelUid, iStart, iEnd); -} + PVR_ERROR GetEPGForChannel(ADDON_HANDLE handle, int iChannelUid, time_t iStart, time_t iEnd) + { + return tvh->GetEPGForChannel(handle, iChannelUid, iStart, iEnd); + } -PVR_ERROR SetEPGTimeFrame(int iDays) -{ - return tvh->SetEPGTimeFrame(iDays); -} + PVR_ERROR SetEPGTimeFrame(int iDays) { return tvh->SetEPGTimeFrame(iDays); } -/* ************************************************************************** + /* ************************************************************************** * Recording Management * *************************************************************************/ -int GetRecordingsAmount(bool deleted) -{ - return tvh->GetRecordingCount(); -} + int GetRecordingsAmount(bool deleted) { return tvh->GetRecordingCount(); } -PVR_ERROR GetRecordings(ADDON_HANDLE handle, bool deleted) -{ - return tvh->GetRecordings(handle); -} + PVR_ERROR GetRecordings(ADDON_HANDLE handle, bool deleted) { return tvh->GetRecordings(handle); } -PVR_ERROR GetRecordingEdl - (const PVR_RECORDING &rec, PVR_EDL_ENTRY edl[], int *num) -{ - return tvh->GetRecordingEdl(rec, edl, num); -} + PVR_ERROR GetRecordingEdl(const PVR_RECORDING& rec, PVR_EDL_ENTRY edl[], int* num) + { + return tvh->GetRecordingEdl(rec, edl, num); + } -PVR_ERROR DeleteRecording(const PVR_RECORDING &rec) -{ - return tvh->DeleteRecording(rec); -} + PVR_ERROR DeleteRecording(const PVR_RECORDING& rec) { return tvh->DeleteRecording(rec); } -PVR_ERROR RenameRecording(const PVR_RECORDING &rec) -{ - return tvh->RenameRecording(rec); -} + PVR_ERROR RenameRecording(const PVR_RECORDING& rec) { return tvh->RenameRecording(rec); } -PVR_ERROR UndeleteRecording(const PVR_RECORDING& recording) -{ - return PVR_ERROR_NOT_IMPLEMENTED; -} + PVR_ERROR UndeleteRecording(const PVR_RECORDING& recording) { return PVR_ERROR_NOT_IMPLEMENTED; } -PVR_ERROR DeleteAllRecordingsFromTrash() -{ - return PVR_ERROR_NOT_IMPLEMENTED; -} + PVR_ERROR DeleteAllRecordingsFromTrash() { return PVR_ERROR_NOT_IMPLEMENTED; } -PVR_ERROR SetRecordingLifetime(const PVR_RECORDING *recording) -{ - if (!recording) + PVR_ERROR SetRecordingLifetime(const PVR_RECORDING* recording) { - Logger::Log(LogLevel::LEVEL_ERROR, "recording must not be nullptr"); - return PVR_ERROR_INVALID_PARAMETERS; + if (!recording) + { + Logger::Log(LogLevel::LEVEL_ERROR, "recording must not be nullptr"); + return PVR_ERROR_INVALID_PARAMETERS; + } + return tvh->SetLifetime(*recording); } - return tvh->SetLifetime(*recording); -} -PVR_ERROR SetRecordingPlayCount(const PVR_RECORDING &recording, int count) -{ - return tvh->SetPlayCount(recording, count); -} + PVR_ERROR SetRecordingPlayCount(const PVR_RECORDING& recording, int count) + { + return tvh->SetPlayCount(recording, count); + } -PVR_ERROR SetRecordingLastPlayedPosition(const PVR_RECORDING &recording, int lastplayedposition) -{ - return tvh->SetPlayPosition(recording, lastplayedposition); -} + PVR_ERROR SetRecordingLastPlayedPosition(const PVR_RECORDING& recording, int lastplayedposition) + { + return tvh->SetPlayPosition(recording, lastplayedposition); + } -int GetRecordingLastPlayedPosition(const PVR_RECORDING &recording) -{ - return tvh->GetPlayPosition(recording); -} + int GetRecordingLastPlayedPosition(const PVR_RECORDING& recording) + { + return tvh->GetPlayPosition(recording); + } -PVR_ERROR GetTimerTypes(PVR_TIMER_TYPE types[], int *size) -{ - return tvh->GetTimerTypes(types, size); -} + PVR_ERROR GetTimerTypes(PVR_TIMER_TYPE types[], int* size) + { + return tvh->GetTimerTypes(types, size); + } -int GetTimersAmount(void) -{ - return tvh->GetTimerCount(); -} + int GetTimersAmount(void) { return tvh->GetTimerCount(); } -PVR_ERROR GetTimers(ADDON_HANDLE handle) -{ - return tvh->GetTimers(handle); -} + PVR_ERROR GetTimers(ADDON_HANDLE handle) { return tvh->GetTimers(handle); } -PVR_ERROR AddTimer(const PVR_TIMER &timer) -{ - return tvh->AddTimer(timer); -} + PVR_ERROR AddTimer(const PVR_TIMER& timer) { return tvh->AddTimer(timer); } -PVR_ERROR DeleteTimer(const PVR_TIMER &timer, bool bForceDelete) -{ - return tvh->DeleteTimer(timer, bForceDelete); -} + PVR_ERROR DeleteTimer(const PVR_TIMER& timer, bool bForceDelete) + { + return tvh->DeleteTimer(timer, bForceDelete); + } -PVR_ERROR UpdateTimer(const PVR_TIMER &timer) -{ - return tvh->UpdateTimer(timer); -} - -/* ************************************************************************** + PVR_ERROR UpdateTimer(const PVR_TIMER& timer) { return tvh->UpdateTimer(timer); } + + /* ************************************************************************** * Recording VFS * *************************************************************************/ -bool OpenRecordedStream(const PVR_RECORDING &recording) -{ - return tvh->VfsOpen(recording); -} + bool OpenRecordedStream(const PVR_RECORDING& recording) { return tvh->VfsOpen(recording); } -void CloseRecordedStream(void) -{ - tvh->VfsClose(); -} + void CloseRecordedStream(void) { tvh->VfsClose(); } -int ReadRecordedStream(unsigned char *pBuffer, unsigned int iBufferSize) -{ - return static_cast(tvh->VfsRead(pBuffer, iBufferSize)); -} + int ReadRecordedStream(unsigned char* pBuffer, unsigned int iBufferSize) + { + return static_cast(tvh->VfsRead(pBuffer, iBufferSize)); + } -long long SeekRecordedStream(long long iPosition, int iWhence /* = SEEK_SET */) -{ - return tvh->VfsSeek(iPosition, iWhence); -} + long long SeekRecordedStream(long long iPosition, int iWhence /* = SEEK_SET */) + { + return tvh->VfsSeek(iPosition, iWhence); + } -long long LengthRecordedStream(void) -{ - return tvh->VfsSize(); -} + long long LengthRecordedStream(void) { return tvh->VfsSize(); } -/* ************************************************************************** + /* ************************************************************************** * Unused Functions * *************************************************************************/ -PVR_ERROR OpenDialogChannelScan(void) -{ - return PVR_ERROR_NOT_IMPLEMENTED; -} + PVR_ERROR OpenDialogChannelScan(void) { return PVR_ERROR_NOT_IMPLEMENTED; } -PVR_ERROR DeleteChannel(const PVR_CHANNEL&) -{ - return PVR_ERROR_NOT_IMPLEMENTED; -} + PVR_ERROR DeleteChannel(const PVR_CHANNEL&) { return PVR_ERROR_NOT_IMPLEMENTED; } -PVR_ERROR RenameChannel(const PVR_CHANNEL&) -{ - return PVR_ERROR_NOT_IMPLEMENTED; -} + PVR_ERROR RenameChannel(const PVR_CHANNEL&) { return PVR_ERROR_NOT_IMPLEMENTED; } -PVR_ERROR OpenDialogChannelSettings(const PVR_CHANNEL&) -{ - return PVR_ERROR_NOT_IMPLEMENTED; -} + PVR_ERROR OpenDialogChannelSettings(const PVR_CHANNEL&) { return PVR_ERROR_NOT_IMPLEMENTED; } -PVR_ERROR OpenDialogChannelAdd(const PVR_CHANNEL&) -{ - return PVR_ERROR_NOT_IMPLEMENTED; -} + PVR_ERROR OpenDialogChannelAdd(const PVR_CHANNEL&) { return PVR_ERROR_NOT_IMPLEMENTED; } -int ReadLiveStream(unsigned char *, unsigned int) -{ - return 0; -} + int ReadLiveStream(unsigned char*, unsigned int) { return 0; } -long long SeekLiveStream(long long, int) -{ - return -1; -} + long long SeekLiveStream(long long, int) { return -1; } -long long LengthLiveStream(void) -{ - return -1; -} + long long LengthLiveStream(void) { return -1; } -PVR_ERROR GetChannelStreamProperties(const PVR_CHANNEL*, PVR_NAMED_VALUE*, unsigned int*) -{ - return PVR_ERROR_NOT_IMPLEMENTED; -} + PVR_ERROR GetChannelStreamProperties(const PVR_CHANNEL*, PVR_NAMED_VALUE*, unsigned int*) + { + return PVR_ERROR_NOT_IMPLEMENTED; + } -PVR_ERROR GetRecordingStreamProperties(const PVR_RECORDING*, PVR_NAMED_VALUE*, unsigned int*) -{ - return PVR_ERROR_NOT_IMPLEMENTED; -} + PVR_ERROR GetRecordingStreamProperties(const PVR_RECORDING*, PVR_NAMED_VALUE*, unsigned int*) + { + return PVR_ERROR_NOT_IMPLEMENTED; + } -PVR_ERROR IsEPGTagRecordable(const EPG_TAG*, bool*) -{ - return PVR_ERROR_NOT_IMPLEMENTED; -} + PVR_ERROR IsEPGTagRecordable(const EPG_TAG*, bool*) { return PVR_ERROR_NOT_IMPLEMENTED; } -PVR_ERROR IsEPGTagPlayable(const EPG_TAG*, bool*) -{ - return PVR_ERROR_NOT_IMPLEMENTED; -} + PVR_ERROR IsEPGTagPlayable(const EPG_TAG*, bool*) { return PVR_ERROR_NOT_IMPLEMENTED; } -PVR_ERROR GetEPGTagStreamProperties(const EPG_TAG*, PVR_NAMED_VALUE*, unsigned int*) -{ - return PVR_ERROR_NOT_IMPLEMENTED; -} + PVR_ERROR GetEPGTagStreamProperties(const EPG_TAG*, PVR_NAMED_VALUE*, unsigned int*) + { + return PVR_ERROR_NOT_IMPLEMENTED; + } -PVR_ERROR GetEPGTagEdl(const EPG_TAG* epgTag, PVR_EDL_ENTRY edl[], int *size) -{ - return PVR_ERROR_NOT_IMPLEMENTED; -} + PVR_ERROR GetEPGTagEdl(const EPG_TAG* epgTag, PVR_EDL_ENTRY edl[], int* size) + { + return PVR_ERROR_NOT_IMPLEMENTED; + } } /* extern "C" */ diff --git a/src/client.h b/src/client.h index 55245fde..808c2586 100644 --- a/src/client.h +++ b/src/client.h @@ -21,9 +21,9 @@ * */ -#include "p8-platform/os.h" #include "kodi/libXBMC_addon.h" #include "kodi/libXBMC_pvr.h" +#include "p8-platform/os.h" -extern ADDON::CHelper_libXBMC_addon* XBMC; -extern CHelper_libXBMC_pvr* PVR; +extern ADDON::CHelper_libXBMC_addon* XBMC; +extern CHelper_libXBMC_pvr* PVR; diff --git a/src/tvheadend/AutoRecordings.cpp b/src/tvheadend/AutoRecordings.cpp index acb9b9b7..cf85102a 100644 --- a/src/tvheadend/AutoRecordings.cpp +++ b/src/tvheadend/AutoRecordings.cpp @@ -24,17 +24,16 @@ #include "HTSPConnection.h" #include "Settings.h" #include "entity/Recording.h" -#include "utilities/Utilities.h" -#include "utilities/Logger.h" #include "utilities/LifetimeMapper.h" +#include "utilities/Logger.h" +#include "utilities/Utilities.h" using namespace P8PLATFORM; using namespace tvheadend; using namespace tvheadend::entity; using namespace tvheadend::utilities; -AutoRecordings::AutoRecordings(HTSPConnection &conn) : - m_conn(conn) +AutoRecordings::AutoRecordings(HTSPConnection& conn) : m_conn(conn) { } @@ -51,10 +50,8 @@ void AutoRecordings::Connected() void AutoRecordings::SyncDvrCompleted() { - utilities::erase_if(m_autoRecordings, [](const AutoRecordingMapEntry &entry) - { - return entry.second.IsDirty(); - }); + utilities::erase_if(m_autoRecordings, + [](const AutoRecordingMapEntry& entry) { return entry.second.IsDirty(); }); } int AutoRecordings::GetAutorecTimerCount() const @@ -62,17 +59,18 @@ int AutoRecordings::GetAutorecTimerCount() const return m_autoRecordings.size(); } -void AutoRecordings::GetAutorecTimers(std::vector &timers) +void AutoRecordings::GetAutorecTimers(std::vector& timers) { for (auto tit = m_autoRecordings.begin(); tit != m_autoRecordings.end(); ++tit) { /* Setup entry */ - PVR_TIMER tmr = { 0 }; + PVR_TIMER tmr = {0}; - tmr.iClientIndex = tit->second.GetId(); - tmr.iClientChannelUid = (tit->second.GetChannel() > 0) ? tit->second.GetChannel() : PVR_TIMER_ANY_CHANNEL; - tmr.startTime = tit->second.GetStart(); - tmr.endTime = tit->second.GetStop(); + tmr.iClientIndex = tit->second.GetId(); + tmr.iClientChannelUid = + (tit->second.GetChannel() > 0) ? tit->second.GetChannel() : PVR_TIMER_ANY_CHANNEL; + tmr.startTime = tit->second.GetStart(); + tmr.endTime = tit->second.GetStop(); if (tmr.startTime == 0) tmr.bStartAnyTime = true; if (tmr.endTime == 0) @@ -89,42 +87,34 @@ void AutoRecordings::GetAutorecTimers(std::vector &timers) } if (tit->second.GetName().empty()) // timers created on backend may not contain a name - strncpy(tmr.strTitle, - tit->second.GetTitle().c_str(), sizeof(tmr.strTitle) - 1); + strncpy(tmr.strTitle, tit->second.GetTitle().c_str(), sizeof(tmr.strTitle) - 1); else - strncpy(tmr.strTitle, - tit->second.GetName().c_str(), sizeof(tmr.strTitle) - 1); - strncpy(tmr.strEpgSearchString, - tit->second.GetTitle().c_str(), sizeof(tmr.strEpgSearchString) - 1); - strncpy(tmr.strDirectory, - tit->second.GetDirectory().c_str(), sizeof(tmr.strDirectory) - 1); - strncpy(tmr.strSummary, - "", sizeof(tmr.strSummary) - 1); // n/a for repeating timers - strncpy(tmr.strSeriesLink, - tit->second.GetSeriesLink().c_str(), sizeof(tmr.strSeriesLink) - 1); - tmr.state = tit->second.IsEnabled() - ? PVR_TIMER_STATE_SCHEDULED - : PVR_TIMER_STATE_DISABLED; - tmr.iTimerType = tit->second.GetSeriesLink().empty() - ? TIMER_REPEATING_EPG - : TIMER_REPEATING_SERIESLINK; - tmr.iPriority = tit->second.GetPriority(); - tmr.iLifetime = tit->second.GetLifetime(); - tmr.iMaxRecordings = 0; // not supported by tvh - tmr.iRecordingGroup = 0; // not supported by tvh + strncpy(tmr.strTitle, tit->second.GetName().c_str(), sizeof(tmr.strTitle) - 1); + strncpy(tmr.strEpgSearchString, tit->second.GetTitle().c_str(), + sizeof(tmr.strEpgSearchString) - 1); + strncpy(tmr.strDirectory, tit->second.GetDirectory().c_str(), sizeof(tmr.strDirectory) - 1); + strncpy(tmr.strSummary, "", sizeof(tmr.strSummary) - 1); // n/a for repeating timers + strncpy(tmr.strSeriesLink, tit->second.GetSeriesLink().c_str(), sizeof(tmr.strSeriesLink) - 1); + tmr.state = tit->second.IsEnabled() ? PVR_TIMER_STATE_SCHEDULED : PVR_TIMER_STATE_DISABLED; + tmr.iTimerType = + tit->second.GetSeriesLink().empty() ? TIMER_REPEATING_EPG : TIMER_REPEATING_SERIESLINK; + tmr.iPriority = tit->second.GetPriority(); + tmr.iLifetime = tit->second.GetLifetime(); + tmr.iMaxRecordings = 0; // not supported by tvh + tmr.iRecordingGroup = 0; // not supported by tvh if (m_conn.GetProtocol() >= 20) tmr.iPreventDuplicateEpisodes = tit->second.GetDupDetect(); else - tmr.iPreventDuplicateEpisodes = 0; // not supported by tvh - - tmr.firstDay = 0; // not supported by tvh - tmr.iWeekdays = tit->second.GetDaysOfWeek(); - tmr.iEpgUid = PVR_TIMER_NO_EPG_UID; // n/a for repeating timers - tmr.iMarginStart = static_cast(tit->second.GetMarginStart()); - tmr.iMarginEnd = static_cast(tit->second.GetMarginEnd()); - tmr.iGenreType = 0; // not supported by tvh? - tmr.iGenreSubType = 0; // not supported by tvh? + tmr.iPreventDuplicateEpisodes = 0; // not supported by tvh + + tmr.firstDay = 0; // not supported by tvh + tmr.iWeekdays = tit->second.GetDaysOfWeek(); + tmr.iEpgUid = PVR_TIMER_NO_EPG_UID; // n/a for repeating timers + tmr.iMarginStart = static_cast(tit->second.GetMarginStart()); + tmr.iMarginEnd = static_cast(tit->second.GetMarginEnd()); + tmr.iGenreType = 0; // not supported by tvh? + tmr.iGenreSubType = 0; // not supported by tvh? tmr.bFullTextEpgSearch = tit->second.GetFulltext(); tmr.iParentClientIndex = 0; @@ -132,14 +122,15 @@ void AutoRecordings::GetAutorecTimers(std::vector &timers) } } -const unsigned int AutoRecordings::GetTimerIntIdFromStringId(const std::string &strId) const +const unsigned int AutoRecordings::GetTimerIntIdFromStringId(const std::string& strId) const { for (auto tit = m_autoRecordings.begin(); tit != m_autoRecordings.end(); ++tit) { if (tit->second.GetStringId() == strId) return tit->second.GetId(); } - Logger::Log(LogLevel::LEVEL_ERROR, "Autorec: Unable to obtain int id for string id %s", strId.c_str()); + Logger::Log(LogLevel::LEVEL_ERROR, "Autorec: Unable to obtain int id for string id %s", + strId.c_str()); return 0; } @@ -148,19 +139,19 @@ const std::string AutoRecordings::GetTimerStringIdFromIntId(unsigned int intId) for (auto tit = m_autoRecordings.begin(); tit != m_autoRecordings.end(); ++tit) { if (tit->second.GetId() == intId) - return tit->second.GetStringId(); + return tit->second.GetStringId(); } Logger::Log(LogLevel::LEVEL_ERROR, "Autorec: Unable to obtain string id for int id %s", intId); return ""; } -PVR_ERROR AutoRecordings::SendAutorecAdd(const PVR_TIMER &timer) +PVR_ERROR AutoRecordings::SendAutorecAdd(const PVR_TIMER& timer) { return SendAutorecAddOrUpdate(timer, false); } -PVR_ERROR AutoRecordings::SendAutorecUpdate(const PVR_TIMER &timer) +PVR_ERROR AutoRecordings::SendAutorecUpdate(const PVR_TIMER& timer) { if (m_conn.GetProtocol() >= 25) return SendAutorecAddOrUpdate(timer, true); @@ -174,13 +165,13 @@ PVR_ERROR AutoRecordings::SendAutorecUpdate(const PVR_TIMER &timer) return error; } -PVR_ERROR AutoRecordings::SendAutorecAddOrUpdate(const PVR_TIMER &timer, bool update) +PVR_ERROR AutoRecordings::SendAutorecAddOrUpdate(const PVR_TIMER& timer, bool update) { uint32_t u32; const std::string method = update ? "updateAutorecEntry" : "addAutorecEntry"; /* Build message */ - htsmsg_t *m = htsmsg_create_map(); + htsmsg_t* m = htsmsg_create_map(); if (update) { @@ -191,44 +182,48 @@ PVR_ERROR AutoRecordings::SendAutorecAddOrUpdate(const PVR_TIMER &timer, bool up return PVR_ERROR_FAILED; } - htsmsg_add_str(m, "id", strId.c_str()); // Autorec DVR Entry ID (string! + htsmsg_add_str(m, "id", strId.c_str()); // Autorec DVR Entry ID (string! } - htsmsg_add_str(m, "name", timer.strTitle); + htsmsg_add_str(m, "name", timer.strTitle); /* epg search data match string (regexp) */ - htsmsg_add_str(m, "title", timer.strEpgSearchString); + htsmsg_add_str(m, "title", timer.strEpgSearchString); /* fulltext epg search: */ /* "title" not empty && !fulltext => match strEpgSearchString against episode title only */ /* "title" not empty && fulltext => match strEpgSearchString against episode title, episode */ /* subtitle, episode summary and episode description (HTSPv19) */ if (m_conn.GetProtocol() >= 20) - htsmsg_add_u32(m, "fulltext", timer.bFullTextEpgSearch ? 1 : 0); + htsmsg_add_u32(m, "fulltext", timer.bFullTextEpgSearch ? 1 : 0); htsmsg_add_s64(m, "startExtra", timer.iMarginStart); - htsmsg_add_s64(m, "stopExtra", timer.iMarginEnd); + htsmsg_add_s64(m, "stopExtra", timer.iMarginEnd); if (m_conn.GetProtocol() >= 25) { - htsmsg_add_u32(m, "removal", timer.iLifetime); // remove from disk - htsmsg_add_s64(m, "channelId", timer.iClientChannelUid); // channelId is signed for >= htspv25, -1 = any + htsmsg_add_u32(m, "removal", timer.iLifetime); // remove from disk + htsmsg_add_s64(m, "channelId", + timer.iClientChannelUid); // channelId is signed for >= htspv25, -1 = any } else { - htsmsg_add_u32(m, "retention", LifetimeMapper::KodiToTvh(timer.iLifetime)); // remove from tvh database + htsmsg_add_u32(m, "retention", + LifetimeMapper::KodiToTvh(timer.iLifetime)); // remove from tvh database if (timer.iClientChannelUid >= 0) - htsmsg_add_u32(m, "channelId", timer.iClientChannelUid); // channelId is unsigned for < htspv25, not sending = any + htsmsg_add_u32( + m, "channelId", + timer.iClientChannelUid); // channelId is unsigned for < htspv25, not sending = any } - htsmsg_add_u32(m, "daysOfWeek", timer.iWeekdays); + htsmsg_add_u32(m, "daysOfWeek", timer.iWeekdays); if (m_conn.GetProtocol() >= 20) htsmsg_add_u32(m, "dupDetect", timer.iPreventDuplicateEpisodes); - htsmsg_add_u32(m, "priority", timer.iPriority); - htsmsg_add_u32(m, "enabled", timer.state == PVR_TIMER_STATE_DISABLED ? 0 : 1); + htsmsg_add_u32(m, "priority", timer.iPriority); + htsmsg_add_u32(m, "enabled", timer.state == PVR_TIMER_STATE_DISABLED ? 0 : 1); /* Note: As a result of internal filename cleanup, for "directory" == "/", */ /* tvh would put recordings into a folder named "-". Not a big issue */ @@ -242,7 +237,7 @@ PVR_ERROR AutoRecordings::SendAutorecAddOrUpdate(const PVR_TIMER &timer, bool up /* */ /* bAutorecApproxTime disabled: => start time in kodi = begin of starting window in tvh */ /* => end time in kodi = end of starting window in tvh */ - const Settings &settings = Settings::GetInstance(); + const Settings& settings = Settings::GetInstance(); if (settings.GetAutorecApproxTime()) { @@ -250,9 +245,11 @@ PVR_ERROR AutoRecordings::SendAutorecAddOrUpdate(const PVR_TIMER &timer, bool up if (timer.startTime > 0 && !timer.bStartAnyTime) { time_t startTime = timer.startTime; - struct tm *tm_start = localtime(&startTime); - int32_t startWindowBegin = tm_start->tm_hour * 60 + tm_start->tm_min - settings.GetAutorecMaxDiff(); - int32_t startWindowEnd = tm_start->tm_hour * 60 + tm_start->tm_min + settings.GetAutorecMaxDiff(); + struct tm* tm_start = localtime(&startTime); + int32_t startWindowBegin = + tm_start->tm_hour * 60 + tm_start->tm_min - settings.GetAutorecMaxDiff(); + int32_t startWindowEnd = + tm_start->tm_hour * 60 + tm_start->tm_min + settings.GetAutorecMaxDiff(); /* Past midnight correction */ if (startWindowBegin < 0) @@ -270,21 +267,25 @@ PVR_ERROR AutoRecordings::SendAutorecAddOrUpdate(const PVR_TIMER &timer, bool up { /* Exact start time (minutes from midnight). */ time_t startTime = timer.startTime; - struct tm *tm_start = localtime(&startTime); + struct tm* tm_start = localtime(&startTime); htsmsg_add_s32(m, "start", tm_start->tm_hour * 60 + tm_start->tm_min); } else - htsmsg_add_s32(m, "start", 25 * 60); // -1 or not sending causes server to set start and startWindow to any time + htsmsg_add_s32( + m, "start", + 25 * 60); // -1 or not sending causes server to set start and startWindow to any time if (timer.endTime > 0 && !timer.bEndAnyTime) { /* Exact stop time (minutes from midnight). */ time_t endTime = timer.endTime; - struct tm *tm_stop = localtime(&endTime); + struct tm* tm_stop = localtime(&endTime); htsmsg_add_s32(m, "startWindow", tm_stop->tm_hour * 60 + tm_stop->tm_min); } else - htsmsg_add_s32(m, "startWindow", 25 * 60); // -1 or not sending causes server to set start and startWindow to any time + htsmsg_add_s32( + m, "startWindow", + 25 * 60); // -1 or not sending causes server to set start and startWindow to any time } /* series link */ @@ -311,7 +312,7 @@ PVR_ERROR AutoRecordings::SendAutorecAddOrUpdate(const PVR_TIMER &timer, bool up return u32 == 1 ? PVR_ERROR_NO_ERROR : PVR_ERROR_FAILED; } -PVR_ERROR AutoRecordings::SendAutorecDelete(const PVR_TIMER &timer) +PVR_ERROR AutoRecordings::SendAutorecDelete(const PVR_TIMER& timer) { uint32_t u32; @@ -319,7 +320,7 @@ PVR_ERROR AutoRecordings::SendAutorecDelete(const PVR_TIMER &timer) if (strId.empty()) return PVR_ERROR_FAILED; - htsmsg_t *m = htsmsg_create_map(); + htsmsg_t* m = htsmsg_create_map(); htsmsg_add_str(m, "id", strId.c_str()); // Autorec DVR Entry ID (string!) /* Send and Wait */ @@ -341,9 +342,9 @@ PVR_ERROR AutoRecordings::SendAutorecDelete(const PVR_TIMER &timer) return u32 == 1 ? PVR_ERROR_NO_ERROR : PVR_ERROR_FAILED; } -bool AutoRecordings::ParseAutorecAddOrUpdate(htsmsg_t *msg, bool bAdd) +bool AutoRecordings::ParseAutorecAddOrUpdate(htsmsg_t* msg, bool bAdd) { - const char *str; + const char* str; uint32_t u32; int32_t s32; int64_t s64; @@ -351,12 +352,13 @@ bool AutoRecordings::ParseAutorecAddOrUpdate(htsmsg_t *msg, bool bAdd) /* Validate/set mandatory fields */ if ((str = htsmsg_get_str(msg, "id")) == NULL) { - Logger::Log(LogLevel::LEVEL_ERROR, "malformed autorecEntryAdd/autorecEntryUpdate: 'id' missing"); + Logger::Log(LogLevel::LEVEL_ERROR, + "malformed autorecEntryAdd/autorecEntryUpdate: 'id' missing"); return false; } /* Locate/create entry */ - AutoRecording &rec = m_autoRecordings[std::string(str)]; + AutoRecording& rec = m_autoRecordings[std::string(str)]; rec.SetStringId(std::string(str)); rec.SetDirty(false); @@ -513,9 +515,9 @@ bool AutoRecordings::ParseAutorecAddOrUpdate(htsmsg_t *msg, bool bAdd) return true; } -bool AutoRecordings::ParseAutorecDelete(htsmsg_t *msg) +bool AutoRecordings::ParseAutorecDelete(htsmsg_t* msg) { - const char *id; + const char* id; /* Validate/set mandatory fields */ if ((id = htsmsg_get_str(msg, "id")) == NULL) diff --git a/src/tvheadend/AutoRecordings.h b/src/tvheadend/AutoRecordings.h index 7af603a4..c7f6e80b 100644 --- a/src/tvheadend/AutoRecordings.h +++ b/src/tvheadend/AutoRecordings.h @@ -25,12 +25,13 @@ extern "C" { -#include #include "libhts/htsmsg.h" + +#include } -#include "kodi/libXBMC_pvr.h" #include "entity/AutoRecording.h" +#include "kodi/libXBMC_pvr.h" namespace tvheadend { @@ -40,7 +41,7 @@ class HTSPConnection; class AutoRecordings { public: - AutoRecordings(HTSPConnection &conn); + AutoRecordings(HTSPConnection& conn); ~AutoRecordings(); /* state updates */ @@ -48,25 +49,25 @@ class AutoRecordings void SyncDvrCompleted(); /* data access */ - int GetAutorecTimerCount() const; - void GetAutorecTimers(std::vector &timers); - const unsigned int GetTimerIntIdFromStringId(const std::string &strId) const; + int GetAutorecTimerCount() const; + void GetAutorecTimers(std::vector& timers); + const unsigned int GetTimerIntIdFromStringId(const std::string& strId) const; /* client to server messages */ - PVR_ERROR SendAutorecAdd (const PVR_TIMER &timer); - PVR_ERROR SendAutorecUpdate(const PVR_TIMER &timer); - PVR_ERROR SendAutorecDelete(const PVR_TIMER &timer); + PVR_ERROR SendAutorecAdd(const PVR_TIMER& timer); + PVR_ERROR SendAutorecUpdate(const PVR_TIMER& timer); + PVR_ERROR SendAutorecDelete(const PVR_TIMER& timer); /* server to client messages */ - bool ParseAutorecAddOrUpdate(htsmsg_t *msg, bool bAdd); - bool ParseAutorecDelete(htsmsg_t *msg); + bool ParseAutorecAddOrUpdate(htsmsg_t* msg, bool bAdd); + bool ParseAutorecDelete(htsmsg_t* msg); private: const std::string GetTimerStringIdFromIntId(unsigned int intId) const; - PVR_ERROR SendAutorecAddOrUpdate(const PVR_TIMER &timer, bool update); + PVR_ERROR SendAutorecAddOrUpdate(const PVR_TIMER& timer, bool update); - HTSPConnection &m_conn; - tvheadend::entity::AutoRecordingsMap m_autoRecordings; + HTSPConnection& m_conn; + tvheadend::entity::AutoRecordingsMap m_autoRecordings; }; } // namespace tvheadend diff --git a/src/tvheadend/ChannelTuningPredictor.cpp b/src/tvheadend/ChannelTuningPredictor.cpp index b6a25dbc..fca32c3f 100644 --- a/src/tvheadend/ChannelTuningPredictor.cpp +++ b/src/tvheadend/ChannelTuningPredictor.cpp @@ -20,18 +20,19 @@ */ #include "ChannelTuningPredictor.h" + #include using namespace tvheadend; using namespace tvheadend::entity; using namespace tvheadend::predictivetune; -void ChannelTuningPredictor::AddChannel(const Channel &channel) +void ChannelTuningPredictor::AddChannel(const Channel& channel) { m_channels.insert(MakeChannelPair(channel)); } -void ChannelTuningPredictor::UpdateChannel(const Channel &oldChannel, const Channel &newChannel) +void ChannelTuningPredictor::UpdateChannel(const Channel& oldChannel, const Channel& newChannel) { m_channels.erase(MakeChannelPair(oldChannel)); m_channels.insert(MakeChannelPair(newChannel)); @@ -45,7 +46,7 @@ void ChannelTuningPredictor::RemoveChannel(uint32_t channelId) m_channels.erase(it); } -ChannelPair ChannelTuningPredictor::MakeChannelPair(const entity::Channel &channel) +ChannelPair ChannelTuningPredictor::MakeChannelPair(const entity::Channel& channel) { return ChannelPair(channel.GetId(), ChannelNumber(channel.GetNum(), channel.GetNumMinor())); } @@ -53,13 +54,8 @@ 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; - } - ); + 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 @@ -74,11 +70,13 @@ uint32_t ChannelTuningPredictor::PredictNextChannelId(uint32_t tuningFrom, uint3 * it will point at the channel we should tune to */ std::set::iterator predictedIt = m_channels.cend(); - if (fromIt == m_channels.cend() || std::next(fromIt, 1) == toIt || toIt->second == firstNum) { + if (fromIt == m_channels.cend() || std::next(fromIt, 1) == toIt || toIt->second == firstNum) + { /* Tuning up or if we're tuning the first channel */ predictedIt = ++toIt; } - else if (std::prev(fromIt, 1) == toIt) { + else if (std::prev(fromIt, 1) == toIt) + { /* Tuning down */ predictedIt = --toIt; } diff --git a/src/tvheadend/ChannelTuningPredictor.h b/src/tvheadend/ChannelTuningPredictor.h index 2014d0c2..24951504 100644 --- a/src/tvheadend/ChannelTuningPredictor.h +++ b/src/tvheadend/ChannelTuningPredictor.h @@ -22,126 +22,128 @@ */ #include "entity/Channel.h" + #include #include namespace tvheadend { - namespace predictivetune - { +namespace predictivetune +{ - /** +/** * Used to indicate that predictive tuning failed to determine which * channel to be tuned next */ - const uint32_t CHANNEL_ID_NONE = -1; +const uint32_t CHANNEL_ID_NONE = -1; - /** +/** * Defines a channel number */ - class ChannelNumber - { - public: - ChannelNumber() - : m_channelNumber(0), m_subchannelNumber(0) {} - - ChannelNumber(uint32_t channelNumber, uint32_t subchannelNumber) - : m_channelNumber(channelNumber), m_subchannelNumber(subchannelNumber) {} - - bool operator ==(const ChannelNumber &right) const - { - return (m_channelNumber == right.m_channelNumber && - m_subchannelNumber == right.m_subchannelNumber); - } - - bool operator <(const ChannelNumber &right) const - { - if (m_channelNumber == right.m_channelNumber) - return m_subchannelNumber < right.m_subchannelNumber; - - return m_channelNumber < right.m_channelNumber; - } - - private: - uint32_t m_channelNumber; - uint32_t m_subchannelNumber; - }; - - /** +class ChannelNumber +{ +public: + ChannelNumber() : m_channelNumber(0), m_subchannelNumber(0) {} + + ChannelNumber(uint32_t channelNumber, uint32_t subchannelNumber) + : m_channelNumber(channelNumber), m_subchannelNumber(subchannelNumber) + { + } + + bool operator==(const ChannelNumber& right) const + { + return (m_channelNumber == right.m_channelNumber && + m_subchannelNumber == right.m_subchannelNumber); + } + + bool operator<(const ChannelNumber& right) const + { + if (m_channelNumber == right.m_channelNumber) + return m_subchannelNumber < right.m_subchannelNumber; + + return m_channelNumber < right.m_channelNumber; + } + +private: + uint32_t m_channelNumber; + uint32_t m_subchannelNumber; +}; + +/** * Defines a single channel ID/number pair */ - typedef std::pair ChannelPair; - typedef std::set::const_iterator ChannelPairIterator; +typedef std::pair ChannelPair; +typedef std::set::const_iterator ChannelPairIterator; - /** +/** * Sorter for channel pairs */ - struct SortChannelPair - { - bool operator()(const ChannelPair &left, const ChannelPair &right) const - { - return left.second < right.second; - } - }; +struct SortChannelPair +{ + bool operator()(const ChannelPair& left, const ChannelPair& right) const + { + return left.second < right.second; } +}; +} // namespace predictivetune - /** +/** * This class holds a sorted set of channel "pairs" (ID -> number mapping) and * can be used to predict which channel ID should be tuned after a normal zap * is performed. */ - class ChannelTuningPredictor - { - public: - /** +class ChannelTuningPredictor +{ +public: + /** * Adds the specified channel * @param channel the channel */ - void AddChannel(const entity::Channel &channel); + void AddChannel(const entity::Channel& channel); - /** + /** * Swaps the old channel with the new channel * @param oldChannel the channel that should be updated * @param newChannel the new channel */ - void UpdateChannel(const entity::Channel &oldChannel, const entity::Channel &newChannel); + void UpdateChannel(const entity::Channel& oldChannel, const entity::Channel& newChannel); - /** + /** * Removes the channel with the specified channel ID * @param channelId the channel ID */ - void RemoveChannel(uint32_t channelId); + void RemoveChannel(uint32_t channelId); - /** + /** * Attempts to predict the channel ID that should be tuned * @param tuningFrom the channel number we are tuning away from * @param tuningTo the channel number we are tuning to * @return the predicted channel number that should be tuned in advance, or * CHANNEL_ID_NONE if nothing could be predicted */ - uint32_t PredictNextChannelId(uint32_t tuningFrom, uint32_t tuningTo) const; + uint32_t PredictNextChannelId(uint32_t tuningFrom, uint32_t tuningTo) const; - private: - /** +private: + /** * Constructs a channel pair from the specified channel number * @param channel the channel to construct a pair from */ - static predictivetune::ChannelPair MakeChannelPair(const entity::Channel &channel); + static predictivetune::ChannelPair MakeChannelPair(const entity::Channel& channel); - /** + /** * Returns an iterator positioned at the channel pair that matches the * specified channel ID. If no match is found, an end iterator is returned * @param channelId the channel ID * @return the iterator */ - predictivetune::ChannelPairIterator GetIterator(uint32_t channelId) const; + predictivetune::ChannelPairIterator GetIterator(uint32_t channelId) const; - /** + /** * Set of pairs which map channel IDs to channel numbers. A custsom comparator is * used to ensure that all inserted pairs are always sorted by the channel number. * This way we can get the next/previous channel by simply adjusting iterators. */ - std::set m_channels; - }; -} + std::set m_channels; +}; +} // namespace tvheadend diff --git a/src/tvheadend/HTSPConnection.cpp b/src/tvheadend/HTSPConnection.cpp index a79151a0..22aed232 100644 --- a/src/tvheadend/HTSPConnection.cpp +++ b/src/tvheadend/HTSPConnection.cpp @@ -27,27 +27,27 @@ extern "C" #include "libhts/sha1.h" } -#include "p8-platform/os.h" -#include "p8-platform/util/StringUtils.h" - #include "../client.h" #include "IHTSPConnectionListener.h" #include "Settings.h" +#include "p8-platform/os.h" +#include "p8-platform/util/StringUtils.h" #include "utilities/Logger.h" using namespace P8PLATFORM; using namespace tvheadend; using namespace tvheadend::utilities; -#define FAST_RECONNECT_ATTEMPTS (5) -#define FAST_RECONNECT_INTERVAL (500) // ms -#define SLOW_RECONNECT_INTERVAL (5000) // ms +#define FAST_RECONNECT_ATTEMPTS (5) +#define FAST_RECONNECT_INTERVAL (500) // ms +#define SLOW_RECONNECT_INTERVAL (5000) // ms -#define HTSP_MIN_SERVER_VERSION (19) // Server must support at least this htsp version -#define HTSP_CLIENT_VERSION (34) // Client uses HTSP features up to this version. If the respective - // addon feature requires htsp features introduced after - // HTSP_MIN_SERVER_VERSION this feature will only be available if the - // actual server HTSP version matches (runtime htsp version check). +#define HTSP_MIN_SERVER_VERSION (19) // Server must support at least this htsp version +#define HTSP_CLIENT_VERSION \ + (34) // Client uses HTSP features up to this version. If the respective \ + // addon feature requires htsp features introduced after \ + // HTSP_MIN_SERVER_VERSION this feature will only be available if the \ + // actual server HTSP version matches (runtime htsp version check). namespace tvheadend { @@ -58,10 +58,7 @@ namespace tvheadend class HTSPResponse { public: - HTSPResponse() - : m_flag(false), m_msg(nullptr) - { - } + HTSPResponse() : m_flag(false), m_msg(nullptr) {} ~HTSPResponse() { @@ -71,16 +68,16 @@ class HTSPResponse Set(nullptr); // ensure signal is sent } - htsmsg_t *Get(P8PLATFORM::CMutex &mutex, uint32_t timeout) + htsmsg_t* Get(P8PLATFORM::CMutex& mutex, uint32_t timeout) { m_cond.Wait(mutex, m_flag, timeout); - htsmsg_t *r = m_msg; - m_msg = NULL; - m_flag = false; + htsmsg_t* r = m_msg; + m_msg = NULL; + m_flag = false; return r; } - void Set(htsmsg_t *msg) + void Set(htsmsg_t* msg) { m_msg = msg; m_flag = true; @@ -90,7 +87,7 @@ class HTSPResponse private: P8PLATFORM::CCondition m_cond; bool m_flag; - htsmsg_t *m_msg; + htsmsg_t* m_msg; }; } // namespace tvheadend @@ -99,10 +96,19 @@ class HTSPResponse * HTSP Connection handler */ -HTSPConnection::HTSPConnection (IHTSPConnectionListener& connListener) - : m_connListener(connListener), m_socket(NULL), m_regThread(new HTSPRegister(this)), - m_ready(false), m_seq(0), m_serverName(""), m_serverVersion(""), m_htspVersion(0), - m_webRoot(""), m_challenge(NULL), m_challengeLen(0), m_suspended(false), +HTSPConnection::HTSPConnection(IHTSPConnectionListener& connListener) + : m_connListener(connListener), + m_socket(NULL), + m_regThread(new HTSPRegister(this)), + m_ready(false), + m_seq(0), + m_serverName(""), + m_serverVersion(""), + m_htspVersion(0), + m_webRoot(""), + m_challenge(NULL), + m_challengeLen(0), + m_suspended(false), m_state(PVR_CONNECTION_STATE_UNKNOWN) { } @@ -132,10 +138,10 @@ void HTSPConnection::Stop() * Info */ -std::string HTSPConnection::GetWebURL ( const char *fmt, ... ) const +std::string HTSPConnection::GetWebURL(const char* fmt, ...) const { va_list va; - const Settings &settings = Settings::GetInstance(); + const Settings& settings = Settings::GetInstance(); // Generate the authentication string (user:pass@) std::string auth = settings.GetUsername(); @@ -144,7 +150,8 @@ std::string HTSPConnection::GetWebURL ( const char *fmt, ... ) const if (!auth.empty()) auth += "@"; - std::string url = StringUtils::Format("http://%s%s:%d", auth.c_str(), settings.GetHostname().c_str(), settings.GetPortHTTP()); + std::string url = StringUtils::Format("http://%s%s:%d", auth.c_str(), + settings.GetHostname().c_str(), settings.GetPortHTTP()); CLockObject lock(m_mutex); va_start(va, fmt); @@ -155,7 +162,7 @@ std::string HTSPConnection::GetWebURL ( const char *fmt, ... ) const return url; } -bool HTSPConnection::WaitForConnection ( void ) +bool HTSPConnection::WaitForConnection(void) { if (!m_ready) { @@ -165,39 +172,39 @@ bool HTSPConnection::WaitForConnection ( void ) return m_ready; } -int HTSPConnection::GetProtocol ( void ) const +int HTSPConnection::GetProtocol(void) const { CLockObject lock(m_mutex); return m_htspVersion; } -std::string HTSPConnection::GetServerName ( void ) const +std::string HTSPConnection::GetServerName(void) const { CLockObject lock(m_mutex); return m_serverName; } -std::string HTSPConnection::GetServerVersion ( void ) const +std::string HTSPConnection::GetServerVersion(void) const { CLockObject lock(m_mutex); return StringUtils::Format("%s (HTSP v%d)", m_serverVersion.c_str(), m_htspVersion); } -std::string HTSPConnection::GetServerString ( void ) const +std::string HTSPConnection::GetServerString(void) const { - const Settings &settings = Settings::GetInstance(); + const Settings& settings = Settings::GetInstance(); CLockObject lock(m_mutex); return StringUtils::Format("%s:%d", settings.GetHostname().c_str(), settings.GetPortHTSP()); } -bool HTSPConnection::HasCapability(const std::string &capability) const +bool HTSPConnection::HasCapability(const std::string& capability) const { - return std::find(m_capabilities.begin(), m_capabilities.end(), capability) - != m_capabilities.end(); + return std::find(m_capabilities.begin(), m_capabilities.end(), capability) != + m_capabilities.end(); } -void HTSPConnection::OnSleep ( void ) +void HTSPConnection::OnSleep(void) { CLockObject lock(m_mutex); @@ -207,7 +214,7 @@ void HTSPConnection::OnSleep ( void ) m_suspended = true; } -void HTSPConnection::OnWake ( void ) +void HTSPConnection::OnWake(void) { CLockObject lock(m_mutex); @@ -217,7 +224,7 @@ void HTSPConnection::OnWake ( void ) m_suspended = false; } -void HTSPConnection::SetState ( PVR_CONNECTION_STATE state ) +void HTSPConnection::SetState(PVR_CONNECTION_STATE state) { PVR_CONNECTION_STATE prevState(PVR_CONNECTION_STATE_UNKNOWN); PVR_CONNECTION_STATE newState(PVR_CONNECTION_STATE_UNKNOWN); @@ -229,8 +236,8 @@ void HTSPConnection::SetState ( PVR_CONNECTION_STATE state ) if (m_state != state && !m_suspended) { prevState = m_state; - newState = state; - m_state = newState; + newState = state; + m_state = newState; Logger::Log(LogLevel::LEVEL_DEBUG, "connection state change (%d -> %d)", prevState, newState); } @@ -249,12 +256,13 @@ void HTSPConnection::SetState ( PVR_CONNECTION_STATE state ) /* * Close the connection */ -void HTSPConnection::Disconnect ( void ) +void HTSPConnection::Disconnect(void) { CLockObject lock(m_mutex); /* Close socket */ - if (m_socket) { + if (m_socket) + { m_socket->Shutdown(); m_socket->Close(); } @@ -268,15 +276,15 @@ void HTSPConnection::Disconnect ( void ) * * Return false if an error occurs and the connection should be terminated */ -bool HTSPConnection::ReadMessage ( void ) +bool HTSPConnection::ReadMessage(void) { - uint8_t *buf; - uint8_t lb[4]; - size_t len, cnt; - ssize_t r; + uint8_t* buf; + uint8_t lb[4]; + size_t len, cnt; + ssize_t r; uint32_t seq; - htsmsg_t *msg; - const char *method; + htsmsg_t* msg; + const char* method; /* Read 4 byte len */ len = m_socket->Read(&lb, sizeof(lb)); @@ -284,7 +292,7 @@ bool HTSPConnection::ReadMessage ( void ) return false; len = (lb[0] << 24) + (lb[1] << 16) + (lb[2] << 8) + lb[3]; - /* Read rest of packet */ + /* Read rest of packet */ buf = (uint8_t*)malloc(len); cnt = 0; while (cnt < len) @@ -293,10 +301,10 @@ bool HTSPConnection::ReadMessage ( void ) if (r < 0) { Logger::Log(LogLevel::LEVEL_ERROR, "failed to read packet (%s)", - m_socket->GetError().c_str()); + m_socket->GetError().c_str()); free(buf); return false; - } + } cnt += r; } @@ -341,11 +349,11 @@ bool HTSPConnection::ReadMessage ( void ) /* * Send message to server */ -bool HTSPConnection::SendMessage0 ( const char *method, htsmsg_t *msg ) +bool HTSPConnection::SendMessage0(const char* method, htsmsg_t* msg) { - int e; - void *buf; - size_t len; + int e; + void* buf; + size_t len; ssize_t c; uint32_t seq; @@ -370,8 +378,7 @@ bool HTSPConnection::SendMessage0 ( const char *method, htsmsg_t *msg ) free(buf); if (c != (ssize_t)len) { - Logger::Log(LogLevel::LEVEL_ERROR, "failed to write (%s)", - m_socket->GetError().c_str()); + Logger::Log(LogLevel::LEVEL_ERROR, "failed to write (%s)", m_socket->GetError().c_str()); if (!m_suspended) Disconnect(); return false; @@ -383,11 +390,11 @@ bool HTSPConnection::SendMessage0 ( const char *method, htsmsg_t *msg ) /* * Send a message and wait for response */ -htsmsg_t *HTSPConnection::SendAndWait0 ( const char *method, htsmsg_t *msg, int iResponseTimeout ) +htsmsg_t* HTSPConnection::SendAndWait0(const char* method, htsmsg_t* msg, int iResponseTimeout) { if (iResponseTimeout == -1) iResponseTimeout = Settings::GetInstance().GetResponseTimeout(); - + uint32_t seq; /* Add Sequence number */ @@ -427,7 +434,7 @@ htsmsg_t *HTSPConnection::SendAndWait0 ( const char *method, htsmsg_t *msg, int else { const char* strError; - if((strError = htsmsg_get_str(msg, "error")) != NULL) + if ((strError = htsmsg_get_str(msg, "error")) != NULL) { Logger::Log(LogLevel::LEVEL_ERROR, "Command %s failed: %s", method, strError); htsmsg_destroy(msg); @@ -441,72 +448,71 @@ htsmsg_t *HTSPConnection::SendAndWait0 ( const char *method, htsmsg_t *msg, int /* * Send and wait for response */ -htsmsg_t *HTSPConnection::SendAndWait ( const char *method, htsmsg_t *msg, int iResponseTimeout ) +htsmsg_t* HTSPConnection::SendAndWait(const char* method, htsmsg_t* msg, int iResponseTimeout) { if (iResponseTimeout == -1) iResponseTimeout = Settings::GetInstance().GetResponseTimeout(); - + if (!WaitForConnection()) return NULL; return SendAndWait0(method, msg, iResponseTimeout); } -bool HTSPConnection::SendHello ( void ) +bool HTSPConnection::SendHello(void) { /* Build message */ - htsmsg_t *msg = htsmsg_create_map(); + htsmsg_t* msg = htsmsg_create_map(); htsmsg_add_str(msg, "clientname", "Kodi Media Center"); htsmsg_add_u32(msg, "htspversion", HTSP_CLIENT_VERSION); /* Send and Wait */ if (!(msg = SendAndWait0("hello", msg))) return false; - + /* Process */ - const char *webroot; - const void *chal; + const char* webroot; + const void* chal; size_t chal_len; - htsmsg_t *cap; + htsmsg_t* cap; /* Basic Info */ webroot = htsmsg_get_str(msg, "webroot"); - m_serverName = htsmsg_get_str(msg, "servername"); + m_serverName = htsmsg_get_str(msg, "servername"); m_serverVersion = htsmsg_get_str(msg, "serverversion"); - m_htspVersion = htsmsg_get_u32_or_default(msg, "htspversion", 0); - m_webRoot = webroot ? webroot : ""; - Logger::Log(LogLevel::LEVEL_DEBUG, "connected to %s / %s (HTSPv%d)", - m_serverName.c_str(), m_serverVersion.c_str(), m_htspVersion); + m_htspVersion = htsmsg_get_u32_or_default(msg, "htspversion", 0); + m_webRoot = webroot ? webroot : ""; + Logger::Log(LogLevel::LEVEL_DEBUG, "connected to %s / %s (HTSPv%d)", m_serverName.c_str(), + m_serverVersion.c_str(), m_htspVersion); /* Capabilities */ if ((cap = htsmsg_get_list(msg, "servercapability"))) { - htsmsg_field_t *f; + htsmsg_field_t* f; HTSMSG_FOREACH(f, cap) { if (f->hmf_type == HMF_STR) m_capabilities.emplace_back(f->hmf_str); } } - + /* Authentication */ htsmsg_get_bin(msg, "challenge", &chal, &chal_len); if (chal && chal_len) { - m_challenge = malloc(chal_len); + m_challenge = malloc(chal_len); m_challengeLen = chal_len; memcpy(m_challenge, chal, chal_len); } htsmsg_destroy(msg); - + return true; } -bool HTSPConnection::SendAuth - ( const std::string &user, const std::string &pass ) +bool HTSPConnection::SendAuth(const std::string& user, const std::string& pass) { uint32_t u32; - htsmsg_t *msg = htsmsg_create_map(); + htsmsg_t* msg = htsmsg_create_map(); htsmsg_add_str(msg, "username", user.c_str()); /* Add Password */ @@ -556,7 +562,7 @@ bool HTSPConnection::SendAuth /** * Register the connection, hello+auth */ -void HTSPConnection::Register ( void ) +void HTSPConnection::Register(void) { std::string user = Settings::GetInstance().GetUsername(); std::string pass = Settings::GetInstance().GetPassword(); @@ -576,14 +582,17 @@ void HTSPConnection::Register ( void ) /* Check htsp server version against client minimum htsp version */ if (m_htspVersion < HTSP_MIN_SERVER_VERSION) { - Logger::Log(LogLevel::LEVEL_ERROR, "server htsp version (v%d) does not match minimum htsp version required by client (v%d)", m_htspVersion, HTSP_MIN_SERVER_VERSION); + Logger::Log( + LogLevel::LEVEL_ERROR, + "server htsp version (v%d) does not match minimum htsp version required by client (v%d)", + m_htspVersion, HTSP_MIN_SERVER_VERSION); SetState(PVR_CONNECTION_STATE_VERSION_MISMATCH); goto fail; } /* Send Auth */ Logger::Log(LogLevel::LEVEL_DEBUG, "sending auth"); - + if (!SendAuth(user, pass)) { SetState(PVR_CONNECTION_STATE_ACCESS_DENIED); @@ -614,11 +623,11 @@ void HTSPConnection::Register ( void ) /* * Main thread loop for connection and rx handling */ -void* HTSPConnection::Process ( void ) +void* HTSPConnection::Process(void) { static bool log = false; static unsigned int retryAttempt = 0; - const Settings &settings = Settings::GetInstance(); + const Settings& settings = Settings::GetInstance(); while (!IsStopped()) { @@ -636,9 +645,10 @@ void* HTSPConnection::Process ( void ) delete m_socket; m_connListener.Disconnected(); m_socket = new CTcpSocket(host.c_str(), port); - m_ready = false; - m_seq = 0; - if (m_challenge) { + m_ready = false; + m_seq = 0; + if (m_challenge) + { free(m_challenge); m_challenge = NULL; } diff --git a/src/tvheadend/HTSPConnection.h b/src/tvheadend/HTSPConnection.h index 0f685ba2..cc78309d 100644 --- a/src/tvheadend/HTSPConnection.h +++ b/src/tvheadend/HTSPConnection.h @@ -25,12 +25,12 @@ #include #include -extern "C" { +extern "C" +{ #include "libhts/htsmsg.h" } #include "kodi/libXBMC_pvr.h" - #include "p8-platform/sockets/tcp.h" #include "p8-platform/threads/mutex.h" #include "p8-platform/threads/threads.h" @@ -57,19 +57,19 @@ class HTSPConnection : public P8PLATFORM::CThread void Stop(); void Disconnect(); - bool SendMessage0(const char *method, htsmsg_t *m); - htsmsg_t *SendAndWait0(const char *method, htsmsg_t *m, int iResponseTimeout = -1); - htsmsg_t *SendAndWait(const char *method, htsmsg_t *m, int iResponseTimeout = -1); + bool SendMessage0(const char* method, htsmsg_t* m); + htsmsg_t* SendAndWait0(const char* method, htsmsg_t* m, int iResponseTimeout = -1); + htsmsg_t* SendAndWait(const char* method, htsmsg_t* m, int iResponseTimeout = -1); int GetProtocol() const; - std::string GetWebURL(const char *fmt, ...) const; + std::string GetWebURL(const char* fmt, ...) const; std::string GetServerName() const; std::string GetServerVersion() const; std::string GetServerString() const; - bool HasCapability(const std::string &capability) const; + bool HasCapability(const std::string& capability) const; inline P8PLATFORM::CMutex& Mutex() { return m_mutex; } @@ -83,7 +83,7 @@ class HTSPConnection : public P8PLATFORM::CThread void Register(); bool ReadMessage(); bool SendHello(); - bool SendAuth(const std::string &u, const std::string &p); + bool SendAuth(const std::string& u, const std::string& p); void SetState(PVR_CONNECTION_STATE state); bool WaitForConnection(); @@ -94,29 +94,23 @@ class HTSPConnection : public P8PLATFORM::CThread class HTSPRegister : public P8PLATFORM::CThread { public: - HTSPRegister(HTSPConnection *conn) - : m_conn(conn) - { - } + HTSPRegister(HTSPConnection* conn) : m_conn(conn) {} - ~HTSPRegister() override - { - StopThread(0); - } + ~HTSPRegister() override { StopThread(0); } private: // CThread implementation - void *Process() override + void* Process() override { m_conn->Register(); return nullptr; } - HTSPConnection *m_conn; + HTSPConnection* m_conn; }; IHTSPConnectionListener& m_connListener; - P8PLATFORM::CTcpSocket *m_socket; + P8PLATFORM::CTcpSocket* m_socket; mutable P8PLATFORM::CMutex m_mutex; HTSPRegister* m_regThread; P8PLATFORM::CCondition m_regCond; diff --git a/src/tvheadend/HTSPDemuxer.cpp b/src/tvheadend/HTSPDemuxer.cpp index 4431ae6e..75093228 100644 --- a/src/tvheadend/HTSPDemuxer.cpp +++ b/src/tvheadend/HTSPDemuxer.cpp @@ -43,20 +43,23 @@ using namespace P8PLATFORM; using namespace tvheadend; using namespace tvheadend::utilities; -HTSPDemuxer::HTSPDemuxer ( HTSPConnection &conn ) - : m_conn(conn), m_pktBuffer((size_t)-1), +HTSPDemuxer::HTSPDemuxer(HTSPConnection& conn) + : m_conn(conn), + m_pktBuffer((size_t)-1), m_seekTime(INVALID_SEEKTIME), m_seeking(false), - m_subscription(conn), m_lastUse(0), - m_startTime(0), m_rdsIdx(0) + m_subscription(conn), + m_lastUse(0), + m_startTime(0), + m_rdsIdx(0) { } -HTSPDemuxer::~HTSPDemuxer () +HTSPDemuxer::~HTSPDemuxer() { } -void HTSPDemuxer::Connected ( void ) +void HTSPDemuxer::Connected(void) { /* Re-subscribe */ if (m_subscription.IsActive()) @@ -73,7 +76,7 @@ void HTSPDemuxer::Connected ( void ) * Demuxer API * *************************************************************************/ -void HTSPDemuxer::Close0 ( void ) +void HTSPDemuxer::Close0(void) { /* Send unsubscribe */ if (m_subscription.IsActive()) @@ -84,7 +87,7 @@ void HTSPDemuxer::Close0 ( void ) Abort0(); } -void HTSPDemuxer::Abort0 ( void ) +void HTSPDemuxer::Abort0(void) { CLockObject lock(m_mutex); m_streams.clear(); @@ -94,7 +97,7 @@ void HTSPDemuxer::Abort0 ( void ) } -bool HTSPDemuxer::Open ( uint32_t channelId, enum eSubscriptionWeight weight ) +bool HTSPDemuxer::Open(uint32_t channelId, enum eSubscriptionWeight weight) { CLockObject lock(m_conn.Mutex()); Logger::Log(LogLevel::LEVEL_DEBUG, "demux open"); @@ -104,7 +107,7 @@ bool HTSPDemuxer::Open ( uint32_t channelId, enum eSubscriptionWeight weight ) /* Open new subscription */ m_subscription.SendSubscribe(channelId, weight); - + /* Reset status */ ResetStatus(); @@ -117,7 +120,7 @@ bool HTSPDemuxer::Open ( uint32_t channelId, enum eSubscriptionWeight weight ) return m_subscription.IsActive(); } -void HTSPDemuxer::Close ( void ) +void HTSPDemuxer::Close(void) { CLockObject lock(m_conn.Mutex()); Close0(); @@ -125,32 +128,33 @@ void HTSPDemuxer::Close ( void ) Logger::Log(LogLevel::LEVEL_DEBUG, "demux close"); } -DemuxPacket *HTSPDemuxer::Read ( void ) +DemuxPacket* HTSPDemuxer::Read(void) { - DemuxPacket *pkt = NULL; + DemuxPacket* pkt = NULL; m_lastUse.store(time(nullptr)); - if (m_pktBuffer.Pop(pkt, 100)) { - Logger::Log(LogLevel::LEVEL_TRACE, "demux read idx :%d pts %lf len %lld", - pkt->iStreamId, pkt->pts, (long long)pkt->iSize); + if (m_pktBuffer.Pop(pkt, 100)) + { + Logger::Log(LogLevel::LEVEL_TRACE, "demux read idx :%d pts %lf len %lld", pkt->iStreamId, + pkt->pts, (long long)pkt->iSize); return pkt; } Logger::Log(LogLevel::LEVEL_TRACE, "demux read nothing"); - + return PVR->AllocateDemuxPacket(0); } -void HTSPDemuxer::Flush ( void ) +void HTSPDemuxer::Flush(void) { - DemuxPacket *pkt; + DemuxPacket* pkt; Logger::Log(LogLevel::LEVEL_TRACE, "demux flush"); while (m_pktBuffer.Pop(pkt)) PVR->FreeDemuxPacket(pkt); } -void HTSPDemuxer::Trim ( void ) +void HTSPDemuxer::Trim(void) { - DemuxPacket *pkt; + DemuxPacket* pkt; Logger::Log(LogLevel::LEVEL_TRACE, "demux trim"); /* reduce used buffer space to what is needed for DVDPlayer to resume @@ -160,7 +164,7 @@ void HTSPDemuxer::Trim ( void ) PVR->FreeDemuxPacket(pkt); } -void HTSPDemuxer::Abort ( void ) +void HTSPDemuxer::Abort(void) { Logger::Log(LogLevel::LEVEL_TRACE, "demux abort"); CLockObject lock(m_conn.Mutex()); @@ -168,14 +172,15 @@ void HTSPDemuxer::Abort ( void ) ResetStatus(); } -bool HTSPDemuxer::Seek(double time, bool, double *startpts) +bool HTSPDemuxer::Seek(double time, bool, double* startpts) { if (!m_subscription.IsActive()) return false; m_seekTime = 0; m_seeking = true; - if (!m_subscription.SendSeek(time)) { + if (!m_subscription.SendSeek(time)) + { m_seeking = false; return false; } @@ -190,7 +195,7 @@ bool HTSPDemuxer::Seek(double time, bool, double *startpts) Flush(); /* try to resync */ return false; } - + m_seeking = false; if (m_seekTime == INVALID_SEEKTIME) return false; @@ -202,7 +207,7 @@ bool HTSPDemuxer::Seek(double time, bool, double *startpts) return true; } -void HTSPDemuxer::Speed ( int speed ) +void HTSPDemuxer::Speed(int speed) { CLockObject lock(m_conn.Mutex()); if (!m_subscription.IsActive()) @@ -219,7 +224,7 @@ void HTSPDemuxer::Speed ( int speed ) m_requestedSpeed = speed; } -void HTSPDemuxer::FillBuffer ( bool mode ) +void HTSPDemuxer::FillBuffer(bool mode) { CLockObject lock(m_conn.Mutex()); if (!m_subscription.IsActive()) @@ -235,14 +240,14 @@ void HTSPDemuxer::FillBuffer ( bool mode ) m_requestedSpeed = speed; } -void HTSPDemuxer::Weight ( enum eSubscriptionWeight weight ) +void HTSPDemuxer::Weight(enum eSubscriptionWeight weight) { if (!m_subscription.IsActive() || m_subscription.GetWeight() == static_cast(weight)) return; m_subscription.SendWeight(static_cast(weight)); } -PVR_ERROR HTSPDemuxer::CurrentStreams ( PVR_STREAM_PROPERTIES *props ) +PVR_ERROR HTSPDemuxer::CurrentStreams(PVR_STREAM_PROPERTIES* props) { CLockObject lock(m_mutex); @@ -255,36 +260,31 @@ PVR_ERROR HTSPDemuxer::CurrentStreams ( PVR_STREAM_PROPERTIES *props ) return PVR_ERROR_NO_ERROR; } -PVR_ERROR HTSPDemuxer::CurrentSignal ( PVR_SIGNAL_STATUS &sig ) +PVR_ERROR HTSPDemuxer::CurrentSignal(PVR_SIGNAL_STATUS& sig) { CLockObject lock(m_mutex); - - sig = { 0 }; - - strncpy(sig.strAdapterName, m_sourceInfo.si_adapter.c_str(), - sizeof(sig.strAdapterName) - 1); - strncpy(sig.strAdapterStatus, m_signalInfo.fe_status.c_str(), - sizeof(sig.strAdapterStatus) - 1); - strncpy(sig.strServiceName, m_sourceInfo.si_service.c_str(), - sizeof(sig.strServiceName) - 1); - strncpy(sig.strProviderName, m_sourceInfo.si_provider.c_str(), - sizeof(sig.strProviderName) - 1); - strncpy(sig.strMuxName, m_sourceInfo.si_mux.c_str(), - sizeof(sig.strMuxName) - 1); - - sig.iSNR = m_signalInfo.fe_snr; - sig.iSignal = m_signalInfo.fe_signal; - sig.iBER = m_signalInfo.fe_ber; - sig.iUNC = m_signalInfo.fe_unc; + + sig = {0}; + + strncpy(sig.strAdapterName, m_sourceInfo.si_adapter.c_str(), sizeof(sig.strAdapterName) - 1); + strncpy(sig.strAdapterStatus, m_signalInfo.fe_status.c_str(), sizeof(sig.strAdapterStatus) - 1); + strncpy(sig.strServiceName, m_sourceInfo.si_service.c_str(), sizeof(sig.strServiceName) - 1); + strncpy(sig.strProviderName, m_sourceInfo.si_provider.c_str(), sizeof(sig.strProviderName) - 1); + strncpy(sig.strMuxName, m_sourceInfo.si_mux.c_str(), sizeof(sig.strMuxName) - 1); + + sig.iSNR = m_signalInfo.fe_snr; + sig.iSignal = m_signalInfo.fe_signal; + sig.iBER = m_signalInfo.fe_ber; + sig.iUNC = m_signalInfo.fe_unc; return PVR_ERROR_NO_ERROR; } -PVR_ERROR HTSPDemuxer::CurrentDescrambleInfo ( PVR_DESCRAMBLE_INFO *info ) +PVR_ERROR HTSPDemuxer::CurrentDescrambleInfo(PVR_DESCRAMBLE_INFO* info) { CLockObject lock(m_mutex); - *info = { 0 }; + *info = {0}; info->iPid = m_descrambleInfo.GetPid(); info->iCaid = m_descrambleInfo.GetCaid(); @@ -292,7 +292,8 @@ PVR_ERROR HTSPDemuxer::CurrentDescrambleInfo ( PVR_DESCRAMBLE_INFO *info ) info->iEcmTime = m_descrambleInfo.GetEcmTime(); info->iHops = m_descrambleInfo.GetHops(); - strncpy(info->strCardSystem, m_descrambleInfo.GetCardSystem().c_str(), sizeof(info->strCardSystem) - 1); + strncpy(info->strCardSystem, m_descrambleInfo.GetCardSystem().c_str(), + sizeof(info->strCardSystem) - 1); strncpy(info->strReader, m_descrambleInfo.GetReader().c_str(), sizeof(info->strReader) - 1); strncpy(info->strFrom, m_descrambleInfo.GetFrom().c_str(), sizeof(info->strFrom) - 1); strncpy(info->strProtocol, m_descrambleInfo.GetProtocol().c_str(), sizeof(info->strProtocol) - 1); @@ -325,7 +326,7 @@ bool HTSPDemuxer::IsRealTimeStream() const return (m_timeshiftStatus.shift < 10000000); } -PVR_ERROR HTSPDemuxer::GetStreamTimes(PVR_STREAM_TIMES *times) const +PVR_ERROR HTSPDemuxer::GetStreamTimes(PVR_STREAM_TIMES* times) const { *times = {0}; @@ -365,7 +366,7 @@ bool HTSPDemuxer::IsPaused() const return false; } -void HTSPDemuxer::SetStreamingProfile(const std::string &profile) +void HTSPDemuxer::SetStreamingProfile(const std::string& profile) { m_subscription.SetProfile(profile); } @@ -387,7 +388,7 @@ void HTSPDemuxer::ResetStatus(bool resetStartTime /* = true */) * Parse incoming data * *************************************************************************/ -bool HTSPDemuxer::ProcessMessage ( const char *method, htsmsg_t *m ) +bool HTSPDemuxer::ProcessMessage(const char* method, htsmsg_t* m) { /* Subscription messages */ if (!strcmp("muxpkt", method)) @@ -464,20 +465,20 @@ void HTSPDemuxer::ProcessRDS(uint32_t idx, const void* bin, size_t binlen) pkt->iStreamId = rdsIdx; m_pktBuffer.Push(pkt); - delete [] rdsdata; + delete[] rdsdata; } } } -void HTSPDemuxer::ParseMuxPacket ( htsmsg_t *m ) +void HTSPDemuxer::ParseMuxPacket(htsmsg_t* m) { - uint32_t idx, u32; - int64_t s64; - const void *bin; - size_t binlen; - DemuxPacket *pkt; - char type = 0; - int ignore; + uint32_t idx, u32; + int64_t s64; + const void* bin; + size_t binlen; + DemuxPacket* pkt; + char type = 0; + int ignore; CLockObject lock(m_mutex); @@ -487,10 +488,9 @@ void HTSPDemuxer::ParseMuxPacket ( htsmsg_t *m ) Logger::Log(LogLevel::LEVEL_DEBUG, "Ignored mux packet due to channel switch"); return; } - + /* Validate fields */ - if (htsmsg_get_u32(m, "stream", &idx) || - htsmsg_get_bin(m, "payload", &bin, &binlen)) + if (htsmsg_get_u32(m, "stream", &idx) || htsmsg_get_bin(m, "payload", &bin, &binlen)) { Logger::Log(LogLevel::LEVEL_ERROR, "malformed muxpkt: 'stream'/'payload' missing"); return; @@ -512,23 +512,23 @@ void HTSPDemuxer::ParseMuxPacket ( htsmsg_t *m ) if (!(pkt = PVR->AllocateDemuxPacket(binlen))) return; memcpy(pkt->pData, bin, binlen); - pkt->iSize = binlen; + pkt->iSize = binlen; pkt->iStreamId = idx; /* Duration */ if (!htsmsg_get_u32(m, "duration", &u32)) pkt->duration = TVH_TO_DVD_TIME(u32); - + /* Timestamps */ if (!htsmsg_get_s64(m, "dts", &s64)) - pkt->dts = TVH_TO_DVD_TIME(s64); + pkt->dts = TVH_TO_DVD_TIME(s64); else - pkt->dts = DVD_NOPTS_VALUE; + pkt->dts = DVD_NOPTS_VALUE; if (!htsmsg_get_s64(m, "pts", &s64)) - pkt->pts = TVH_TO_DVD_TIME(s64); + pkt->pts = TVH_TO_DVD_TIME(s64); else - pkt->pts = DVD_NOPTS_VALUE; + pkt->pts = DVD_NOPTS_VALUE; /* Type (for debug only) */ if (!htsmsg_get_u32(m, "frametype", &u32)) @@ -538,9 +538,8 @@ void HTSPDemuxer::ParseMuxPacket ( htsmsg_t *m ) ignore = m_seeking; - Logger::Log(LogLevel::LEVEL_TRACE, "demux pkt idx %d:%d type %c pts %lf len %lld%s", - idx, pkt->iStreamId, type, pkt->pts, (long long)binlen, - ignore ? " IGNORE" : ""); + Logger::Log(LogLevel::LEVEL_TRACE, "demux pkt idx %d:%d type %c pts %lf len %lld%s", idx, + pkt->iStreamId, type, pkt->pts, (long long)binlen, ignore ? " IGNORE" : ""); /* Store */ if (!ignore) @@ -590,8 +589,9 @@ bool HTSPDemuxer::AddRDSStream(uint32_t audioIdx, uint32_t rdsIdx) } else { - Logger::Log(LogLevel::LEVEL_INFO, "Maximum stream limit reached ignoring id: %d, type rds, codec: %u", - rdsIdx, rdsStream.iCodecId); + Logger::Log(LogLevel::LEVEL_INFO, + "Maximum stream limit reached ignoring id: %d, type rds, codec: %u", rdsIdx, + rdsStream.iCodecId); return false; } } @@ -599,7 +599,7 @@ bool HTSPDemuxer::AddRDSStream(uint32_t audioIdx, uint32_t rdsIdx) return false; } -bool HTSPDemuxer::AddTVHStream(uint32_t idx, const char* type, htsmsg_field_t *f) +bool HTSPDemuxer::AddTVHStream(uint32_t idx, const char* type, htsmsg_field_t* f) { const CodecDescriptor codecDescriptor = CodecDescriptor::GetCodecByName(type); const xbmc_codec_t codec = codecDescriptor.Codec(); @@ -615,21 +615,19 @@ bool HTSPDemuxer::AddTVHStream(uint32_t idx, const char* type, htsmsg_field_t *f stream.iPID = idx; /* Subtitle ID */ - if ((stream.iCodecType == XBMC_CODEC_TYPE_SUBTITLE) && - !strcmp("DVBSUB", type)) + if ((stream.iCodecType == XBMC_CODEC_TYPE_SUBTITLE) && !strcmp("DVBSUB", type)) { uint32_t composition_id = 0, ancillary_id = 0; htsmsg_get_u32(&f->hmf_msg, "composition_id", &composition_id); - htsmsg_get_u32(&f->hmf_msg, "ancillary_id" , &ancillary_id); + htsmsg_get_u32(&f->hmf_msg, "ancillary_id", &ancillary_id); stream.iSubtitleInfo = (composition_id & 0xffff) | ((ancillary_id & 0xffff) << 16); } /* Language */ - if (stream.iCodecType == XBMC_CODEC_TYPE_SUBTITLE || - stream.iCodecType == XBMC_CODEC_TYPE_AUDIO || + if (stream.iCodecType == XBMC_CODEC_TYPE_SUBTITLE || stream.iCodecType == XBMC_CODEC_TYPE_AUDIO || stream.iCodecType == XBMC_CODEC_TYPE_RDS) { - const char *language; + const char* language; if ((language = htsmsg_get_str(&f->hmf_msg, "language")) != NULL) strncpy(stream.strLanguage, language, sizeof(stream.strLanguage) - 1); } @@ -651,7 +649,7 @@ bool HTSPDemuxer::AddTVHStream(uint32_t idx, const char* type, htsmsg_field_t *f /* Video */ if (stream.iCodecType == XBMC_CODEC_TYPE_VIDEO) { - stream.iWidth = htsmsg_get_u32_or_default(&f->hmf_msg, "width", 0); + stream.iWidth = htsmsg_get_u32_or_default(&f->hmf_msg, "width", 0); stream.iHeight = htsmsg_get_u32_or_default(&f->hmf_msg, "height", 0); /* Ignore this message if the stream details haven't been determined @@ -670,7 +668,7 @@ bool HTSPDemuxer::AddTVHStream(uint32_t idx, const char* type, htsmsg_field_t *f if ((duration = htsmsg_get_u32_or_default(&f->hmf_msg, "duration", 0)) > 0) { stream.iFPSScale = duration; - stream.iFPSRate = DVD_TIME_BASE; + stream.iFPSRate = DVD_TIME_BASE; } } @@ -683,13 +681,14 @@ bool HTSPDemuxer::AddTVHStream(uint32_t idx, const char* type, htsmsg_field_t *f } else { - Logger::Log(LogLevel::LEVEL_INFO, "Maximum stream limit reached ignoring id: %d, type %s, codec: %u", idx, type, + Logger::Log(LogLevel::LEVEL_INFO, + "Maximum stream limit reached ignoring id: %d, type %s, codec: %u", idx, type, stream.iCodecId); return false; } } -void HTSPDemuxer::ParseSubscriptionStart ( htsmsg_t *m ) +void HTSPDemuxer::ParseSubscriptionStart(htsmsg_t* m) { /* Validate */ htsmsg_t* l; @@ -715,7 +714,7 @@ void HTSPDemuxer::ParseSubscriptionStart ( htsmsg_t *m ) if (f->hmf_type != HMF_MAP) continue; - const char *type; + const char* type; if ((type = htsmsg_get_str(&f->hmf_msg, "type")) == NULL) continue; @@ -738,12 +737,13 @@ void HTSPDemuxer::ParseSubscriptionStart ( htsmsg_t *m ) ParseSourceInfo(htsmsg_get_map(m, "sourceinfo")); } -void HTSPDemuxer::ParseSourceInfo ( htsmsg_t *m ) +void HTSPDemuxer::ParseSourceInfo(htsmsg_t* m) { - const char *str; - + const char* str; + /* Ignore */ - if (!m) return; + if (!m) + return; Logger::Log(LogLevel::LEVEL_TRACE, "demux sourceInfo:"); @@ -765,12 +765,12 @@ void HTSPDemuxer::ParseSourceInfo ( htsmsg_t *m ) if ((str = htsmsg_get_str(m, "adapter")) != NULL) { Logger::Log(LogLevel::LEVEL_TRACE, " adapter : %s", str); - m_sourceInfo.si_adapter = str; + m_sourceInfo.si_adapter = str; } if ((str = htsmsg_get_str(m, "network")) != NULL) { Logger::Log(LogLevel::LEVEL_TRACE, " network : %s", str); - m_sourceInfo.si_network = str; + m_sourceInfo.si_network = str; } if ((str = htsmsg_get_str(m, "provider")) != NULL) { @@ -780,7 +780,7 @@ void HTSPDemuxer::ParseSourceInfo ( htsmsg_t *m ) if ((str = htsmsg_get_str(m, "service")) != NULL) { Logger::Log(LogLevel::LEVEL_TRACE, " service : %s", str); - m_sourceInfo.si_service = str; + m_sourceInfo.si_service = str; } } @@ -789,15 +789,18 @@ void HTSPDemuxer::ParseSubscriptionStop(htsmsg_t*) //CLockObject lock(m_mutex); } -void HTSPDemuxer::ParseSubscriptionSkip ( htsmsg_t *m ) +void HTSPDemuxer::ParseSubscriptionSkip(htsmsg_t* m) { int64_t s64; CLockObject lock(m_conn.Mutex()); - if (htsmsg_get_s64(m, "time", &s64)) { + if (htsmsg_get_s64(m, "time", &s64)) + { m_seekTime = INVALID_SEEKTIME; - } else { + } + else + { m_seekTime = s64 < 0 ? 1 : s64 + 1; /* it must not be zero! */ Flush(); /* flush old packets (with wrong pts) */ } @@ -805,7 +808,7 @@ void HTSPDemuxer::ParseSubscriptionSkip ( htsmsg_t *m ) m_seekCond.Broadcast(); } -void HTSPDemuxer::ParseSubscriptionSpeed ( htsmsg_t *m ) +void HTSPDemuxer::ParseSubscriptionSpeed(htsmsg_t* m) { int32_t s32; if (!htsmsg_get_s32(m, "speed", &s32)) @@ -816,14 +819,14 @@ void HTSPDemuxer::ParseSubscriptionSpeed ( htsmsg_t *m ) m_actualSpeed = s32 * 10; } -void HTSPDemuxer::ParseSubscriptionGrace ( htsmsg_t *m ) +void HTSPDemuxer::ParseSubscriptionGrace(htsmsg_t* m) { } -void HTSPDemuxer::ParseQueueStatus (htsmsg_t* m) +void HTSPDemuxer::ParseQueueStatus(htsmsg_t* m) { uint32_t u32; - std::map::const_iterator it; + std::map::const_iterator it; CLockObject lock(m_mutex); @@ -846,10 +849,10 @@ void HTSPDemuxer::ParseQueueStatus (htsmsg_t* m) Logger::Log(LogLevel::LEVEL_TRACE, " Bdrop %d", u32); } -void HTSPDemuxer::ParseSignalStatus ( htsmsg_t *m ) +void HTSPDemuxer::ParseSignalStatus(htsmsg_t* m) { uint32_t u32; - const char *str; + const char* str; CLockObject lock(m_mutex); @@ -870,17 +873,17 @@ void HTSPDemuxer::ParseSignalStatus ( htsmsg_t *m ) if (!htsmsg_get_u32(m, "feSNR", &u32)) { Logger::Log(LogLevel::LEVEL_TRACE, " snr : %d", u32); - m_signalInfo.fe_snr = u32; + m_signalInfo.fe_snr = u32; } if (!htsmsg_get_u32(m, "feBER", &u32)) { Logger::Log(LogLevel::LEVEL_TRACE, " ber : %d", u32); - m_signalInfo.fe_ber = u32; + m_signalInfo.fe_ber = u32; } if (!htsmsg_get_u32(m, "feUNC", &u32)) { Logger::Log(LogLevel::LEVEL_TRACE, " unc : %d", u32); - m_signalInfo.fe_unc = u32; + m_signalInfo.fe_unc = u32; } if (!htsmsg_get_u32(m, "feSignal", &u32)) { @@ -889,7 +892,7 @@ void HTSPDemuxer::ParseSignalStatus ( htsmsg_t *m ) } } -void HTSPDemuxer::ParseTimeshiftStatus ( htsmsg_t *m ) +void HTSPDemuxer::ParseTimeshiftStatus(htsmsg_t* m) { uint32_t u32; int64_t s64; @@ -928,16 +931,14 @@ void HTSPDemuxer::ParseTimeshiftStatus ( htsmsg_t *m ) } } -void HTSPDemuxer::ParseDescrambleInfo(htsmsg_t *m) +void HTSPDemuxer::ParseDescrambleInfo(htsmsg_t* m) { uint32_t pid = 0, caid = 0, provid = 0, ecmtime = 0, hops = 0; const char *cardsystem, *reader, *from, *protocol; /* Parse mandatory fields */ - if (htsmsg_get_u32(m, "pid", &pid) || - htsmsg_get_u32(m, "caid", &caid) || - htsmsg_get_u32(m, "provid", &provid) || - htsmsg_get_u32(m, "ecmtime", &ecmtime) || + if (htsmsg_get_u32(m, "pid", &pid) || htsmsg_get_u32(m, "caid", &caid) || + htsmsg_get_u32(m, "provid", &provid) || htsmsg_get_u32(m, "ecmtime", &ecmtime) || htsmsg_get_u32(m, "hops", &hops)) { Logger::Log(LogLevel::LEVEL_ERROR, "malformed descrambleInfo, mandatory parameters missing"); diff --git a/src/tvheadend/HTSPDemuxer.h b/src/tvheadend/HTSPDemuxer.h index 60c47f3e..9089b873 100644 --- a/src/tvheadend/HTSPDemuxer.h +++ b/src/tvheadend/HTSPDemuxer.h @@ -21,23 +21,21 @@ * */ -#include - #include #include #include +#include #include -extern "C" { +extern "C" +{ #include "libhts/htsmsg.h" } +#include "Subscription.h" #include "kodi/libXBMC_pvr.h" - #include "p8-platform/threads/mutex.h" #include "p8-platform/util/buffer.h" - -#include "Subscription.h" #include "status/DescrambleInfo.h" #include "status/Quality.h" #include "status/SourceInfo.h" @@ -54,30 +52,31 @@ class HTSPConnection; class HTSPDemuxer { public: - HTSPDemuxer(HTSPConnection &conn); + HTSPDemuxer(HTSPConnection& conn); ~HTSPDemuxer(); - bool ProcessMessage(const char *method, htsmsg_t *m); + bool ProcessMessage(const char* method, htsmsg_t* m); void Connected(); - bool Open(uint32_t channelId, tvheadend::eSubscriptionWeight weight = tvheadend::SUBSCRIPTION_WEIGHT_NORMAL); + bool Open(uint32_t channelId, + tvheadend::eSubscriptionWeight weight = tvheadend::SUBSCRIPTION_WEIGHT_NORMAL); void Close(); - DemuxPacket *Read(); + DemuxPacket* Read(); void Trim(); void Flush(); void Abort(); - bool Seek(double time, bool backwards, double *startpts); + bool Seek(double time, bool backwards, double* startpts); void Speed(int speed); void FillBuffer(bool mode); void Weight(tvheadend::eSubscriptionWeight weight); - PVR_ERROR CurrentStreams(PVR_STREAM_PROPERTIES *streams); - PVR_ERROR CurrentSignal(PVR_SIGNAL_STATUS &sig); - PVR_ERROR CurrentDescrambleInfo(PVR_DESCRAMBLE_INFO *info); + PVR_ERROR CurrentStreams(PVR_STREAM_PROPERTIES* streams); + PVR_ERROR CurrentSignal(PVR_SIGNAL_STATUS& sig); + PVR_ERROR CurrentDescrambleInfo(PVR_DESCRAMBLE_INFO* info); bool IsTimeShifting() const; bool IsRealTimeStream() const; - PVR_ERROR GetStreamTimes(PVR_STREAM_TIMES *times) const; + PVR_ERROR GetStreamTimes(PVR_STREAM_TIMES* times) const; uint32_t GetSubscriptionId() const; uint32_t GetChannelId() const; @@ -88,7 +87,7 @@ class HTSPDemuxer * Tells each demuxer to use the specified profile for new subscriptions * @param profile the profile to use */ - void SetStreamingProfile(const std::string &profile); + void SetStreamingProfile(const std::string& profile); private: void Close0(); @@ -100,27 +99,27 @@ class HTSPDemuxer */ void ResetStatus(bool resetStartTime = true); - void ParseMuxPacket(htsmsg_t *m); - void ParseSourceInfo(htsmsg_t *m); - void ParseSubscriptionStart(htsmsg_t *m); - void ParseSubscriptionStop(htsmsg_t *m); - void ParseSubscriptionSkip(htsmsg_t *m); - void ParseSubscriptionSpeed(htsmsg_t *m); - void ParseSubscriptionGrace(htsmsg_t *m); - void ParseQueueStatus(htsmsg_t *m); - void ParseSignalStatus(htsmsg_t *m); - void ParseTimeshiftStatus(htsmsg_t *m); - void ParseDescrambleInfo(htsmsg_t *m); - - bool AddTVHStream(uint32_t idx, const char* type, htsmsg_field_t *f); + void ParseMuxPacket(htsmsg_t* m); + void ParseSourceInfo(htsmsg_t* m); + void ParseSubscriptionStart(htsmsg_t* m); + void ParseSubscriptionStop(htsmsg_t* m); + void ParseSubscriptionSkip(htsmsg_t* m); + void ParseSubscriptionSpeed(htsmsg_t* m); + void ParseSubscriptionGrace(htsmsg_t* m); + void ParseQueueStatus(htsmsg_t* m); + void ParseSignalStatus(htsmsg_t* m); + void ParseTimeshiftStatus(htsmsg_t* m); + void ParseDescrambleInfo(htsmsg_t* m); + + bool AddTVHStream(uint32_t idx, const char* type, htsmsg_field_t* f); bool AddRDSStream(uint32_t audioIdx, uint32_t rdsIdx); void ProcessRDS(uint32_t idx, const void* bin, size_t binlen); mutable P8PLATFORM::CMutex m_mutex; - HTSPConnection &m_conn; + HTSPConnection& m_conn; P8PLATFORM::SyncedBuffer m_pktBuffer; std::vector m_streams; - std::map m_streamStat; + std::map m_streamStat; int64_t m_seekTime; P8PLATFORM::CCondition m_seekCond; bool m_seeking; diff --git a/src/tvheadend/HTSPMessage.h b/src/tvheadend/HTSPMessage.h index 2bffc017..5c6d92fa 100644 --- a/src/tvheadend/HTSPMessage.h +++ b/src/tvheadend/HTSPMessage.h @@ -21,7 +21,8 @@ * */ -extern "C" { +extern "C" +{ #include "libhts/htsmsg.h" } @@ -37,12 +38,11 @@ class HTSPMessage { public: HTSPMessage(const std::string& method = "", htsmsg_t* msg = nullptr) - : m_method(method), m_msg(msg) + : m_method(method), m_msg(msg) { } - HTSPMessage(const HTSPMessage& msg) - : m_method(msg.m_method), m_msg(msg.m_msg) + HTSPMessage(const HTSPMessage& msg) : m_method(msg.m_method), m_msg(msg.m_msg) { msg.m_msg = nullptr; } @@ -53,7 +53,7 @@ class HTSPMessage htsmsg_destroy(m_msg); } - HTSPMessage& operator=(const HTSPMessage &msg) + HTSPMessage& operator=(const HTSPMessage& msg) { if (this != &msg) { @@ -78,7 +78,7 @@ class HTSPMessage private: std::string m_method; - mutable htsmsg_t *m_msg; + mutable htsmsg_t* m_msg; }; } // namespace tvheadend diff --git a/src/tvheadend/HTSPTypes.h b/src/tvheadend/HTSPTypes.h index 3a2c6014..856874d6 100644 --- a/src/tvheadend/HTSPTypes.h +++ b/src/tvheadend/HTSPTypes.h @@ -21,38 +21,40 @@ * */ +#include "entity/Event.h" +#include "kodi/libXBMC_pvr.h" + #include #include #include #include #include -#include "kodi/libXBMC_pvr.h" - -#include "entity/Event.h" - namespace tvheadend { -typedef enum { - DVR_PRIO_IMPORTANT = 0, - DVR_PRIO_HIGH = 1, - DVR_PRIO_NORMAL = 2, - DVR_PRIO_LOW = 3, +typedef enum +{ + DVR_PRIO_IMPORTANT = 0, + DVR_PRIO_HIGH = 1, + DVR_PRIO_NORMAL = 2, + DVR_PRIO_LOW = 3, DVR_PRIO_UNIMPORTANT = 4, - DVR_PRIO_NOT_SET = 5, - DVR_PRIO_DEFAULT = 6 + DVR_PRIO_NOT_SET = 5, + DVR_PRIO_DEFAULT = 6 } dvr_prio_t; -typedef enum { +typedef enum +{ DVR_ACTION_TYPE_CUT, DVR_ACTION_TYPE_MUTE, DVR_ACTION_TYPE_SCENE, DVR_ACTION_TYPE_COMBREAK, - + } dvr_action_type_t; -typedef enum { +typedef enum +{ DVR_AUTOREC_RECORD_ALL = 0, DVR_AUTOREC_RECORD_UNIQUE = 14, // Unique episode in EPG/XMLTV DVR_AUTOREC_RECORD_DIFFERENT_EPISODE_NUMBER = 1, @@ -75,36 +77,42 @@ typedef enum { * retention = lifetime of the database entry * removal = lifetime of the actual recording on disk */ -typedef enum { - DVR_RET_DVRCONFIG = 0, // the server will use it's own default value - DVR_RET_1DAY = 1, // the server will delete the db entry or recording after 1 day - DVR_RET_3DAY = 3, // ... - DVR_RET_5DAY = 5, - DVR_RET_1WEEK = 7, - DVR_RET_2WEEK = 14, - DVR_RET_3WEEK = 21, - DVR_RET_1MONTH = 31, - DVR_RET_2MONTH = 62, - DVR_RET_3MONTH = 92, - DVR_RET_6MONTH = 183, - DVR_RET_1YEAR = 366, - DVR_RET_2YEARS = 731, - DVR_RET_3YEARS = 1096, - DVR_RET_SPACE = INT32_MAX-1, // the server may delete this recording if space for a new recording is needed (removal only) - DVR_RET_FOREVER = INT32_MAX // the server should never delete this recording or database entry, only the user can do this +typedef enum +{ + DVR_RET_DVRCONFIG = 0, // the server will use it's own default value + DVR_RET_1DAY = 1, // the server will delete the db entry or recording after 1 day + DVR_RET_3DAY = 3, // ... + DVR_RET_5DAY = 5, + DVR_RET_1WEEK = 7, + DVR_RET_2WEEK = 14, + DVR_RET_3WEEK = 21, + DVR_RET_1MONTH = 31, + DVR_RET_2MONTH = 62, + DVR_RET_3MONTH = 92, + DVR_RET_6MONTH = 183, + DVR_RET_1YEAR = 366, + DVR_RET_2YEARS = 731, + DVR_RET_3YEARS = 1096, + DVR_RET_SPACE = + INT32_MAX - + 1, // the server may delete this recording if space for a new recording is needed (removal only) + DVR_RET_FOREVER = + INT32_MAX // the server should never delete this recording or database entry, only the user can do this } dvr_retention_t; -typedef enum { +typedef enum +{ CHANNEL_TYPE_OTHER = 0, - CHANNEL_TYPE_TV = 1, + CHANNEL_TYPE_TV = 1, CHANNEL_TYPE_RADIO = 2 } channel_type_t; -typedef enum { +typedef enum +{ HTSP_DVR_PLAYCOUNT_RESET = 0, - HTSP_DVR_PLAYCOUNT_SET = 1, - HTSP_DVR_PLAYCOUNT_KEEP = INT32_MAX-1, - HTSP_DVR_PLAYCOUNT_INCR = INT32_MAX + HTSP_DVR_PLAYCOUNT_SET = 1, + HTSP_DVR_PLAYCOUNT_KEEP = INT32_MAX - 1, + HTSP_DVR_PLAYCOUNT_INCR = INT32_MAX } dvr_playcount_t; enum eHTSPEventType @@ -122,30 +130,21 @@ struct SHTSPEvent // params for HTSP_EVENT_EPG_UPDATE tvheadend::entity::Event m_epg; - EPG_EVENT_STATE m_state; + EPG_EVENT_STATE m_state; - SHTSPEvent (eHTSPEventType type = HTSP_EVENT_NONE) : - m_type(type), - m_state(EPG_EVENT_CREATED) - { - } + SHTSPEvent(eHTSPEventType type = HTSP_EVENT_NONE) : m_type(type), m_state(EPG_EVENT_CREATED) {} - SHTSPEvent (eHTSPEventType type, const tvheadend::entity::Event &epg, EPG_EVENT_STATE state) : - m_type(type), - m_epg(epg), - m_state(state) + SHTSPEvent(eHTSPEventType type, const tvheadend::entity::Event& epg, EPG_EVENT_STATE state) + : m_type(type), m_epg(epg), m_state(state) { } - bool operator==(const SHTSPEvent &right) const + bool operator==(const SHTSPEvent& right) const { return m_type == right.m_type && m_epg == right.m_epg && m_state && right.m_state; } - bool operator!=(const SHTSPEvent &right) const - { - return !(*this == right); - } + bool operator!=(const SHTSPEvent& right) const { return !(*this == right); } }; typedef std::vector SHTSPEventList; diff --git a/src/tvheadend/HTSPVFS.cpp b/src/tvheadend/HTSPVFS.cpp index 78c114bc..e9b3fa9e 100644 --- a/src/tvheadend/HTSPVFS.cpp +++ b/src/tvheadend/HTSPVFS.cpp @@ -24,17 +24,16 @@ extern "C" { #include "libhts/htsmsg_binary.h" } -#include -#include -#include - -#include "p8-platform/threads/mutex.h" -#include "p8-platform/util/StringUtils.h" - #include "HTSPConnection.h" #include "Settings.h" +#include "p8-platform/threads/mutex.h" +#include "p8-platform/util/StringUtils.h" #include "utilities/Logger.h" +#include +#include +#include + using namespace P8PLATFORM; using namespace tvheadend; using namespace tvheadend::utilities; @@ -42,17 +41,23 @@ using namespace tvheadend::utilities; /* * VFS handler */ -HTSPVFS::HTSPVFS ( HTSPConnection &conn ) - : m_conn(conn), m_path(""), m_fileId(0), m_offset(0), - m_eofOffsetSecs(-1), m_pauseTime(0), m_paused(false), m_isRealTimeStream(false) +HTSPVFS::HTSPVFS(HTSPConnection& conn) + : m_conn(conn), + m_path(""), + m_fileId(0), + m_offset(0), + m_eofOffsetSecs(-1), + m_pauseTime(0), + m_paused(false), + m_isRealTimeStream(false) { } -HTSPVFS::~HTSPVFS () +HTSPVFS::~HTSPVFS() { } -void HTSPVFS::Connected ( void ) +void HTSPVFS::Connected(void) { /* Re-open */ if (m_fileId != 0) @@ -70,7 +75,7 @@ void HTSPVFS::Connected ( void ) * VFS API * *************************************************************************/ -bool HTSPVFS::Open ( const PVR_RECORDING &rec ) +bool HTSPVFS::Open(const PVR_RECORDING& rec) { /* Close existing */ Close(); @@ -90,21 +95,21 @@ bool HTSPVFS::Open ( const PVR_RECORDING &rec ) return true; } -void HTSPVFS::Close ( void ) +void HTSPVFS::Close(void) { if (m_fileId != 0) SendFileClose(); m_offset = 0; m_fileId = 0; - m_path = ""; + m_path = ""; m_eofOffsetSecs = -1; m_pauseTime = 0; m_paused = false; m_isRealTimeStream = false; } -ssize_t HTSPVFS::Read ( unsigned char *buf, unsigned int len, bool inprogress ) +ssize_t HTSPVFS::Read(unsigned char* buf, unsigned int len, bool inprogress) { /* Not opened */ if (!m_fileId) @@ -130,7 +135,7 @@ ssize_t HTSPVFS::Read ( unsigned char *buf, unsigned int len, bool inprogress ) return read; } -long long HTSPVFS::Seek ( long long pos, int whence, bool inprogress ) +long long HTSPVFS::Seek(long long pos, int whence, bool inprogress) { if (m_fileId == 0) return -1; @@ -152,8 +157,10 @@ long long HTSPVFS::Seek ( long long pos, int whence, bool inprogress ) m_eofOffsetSecs = (fileSize - m_offset) > 0 ? (fileSize - m_offset) / bitrate : 0; /* only set m_isRealTimeStream within last 10 secs of an inprogress recording */ - m_isRealTimeStream = (m_eofOffsetSecs >=0 && m_eofOffsetSecs < 10); - Logger::Log(LogLevel::LEVEL_TRACE, "vfs seek inprogress recording m_eofOffsetSecs=%lld m_isRealTimeStream=%d", static_cast(m_eofOffsetSecs), m_isRealTimeStream); + m_isRealTimeStream = (m_eofOffsetSecs >= 0 && m_eofOffsetSecs < 10); + Logger::Log(LogLevel::LEVEL_TRACE, + "vfs seek inprogress recording m_eofOffsetSecs=%lld m_isRealTimeStream=%d", + static_cast(m_eofOffsetSecs), m_isRealTimeStream); /* if we've seeked whilst paused then update m_pauseTime this is so we correctly recalculate m_eofOffsetSecs when returning to normal playback */ @@ -164,17 +171,17 @@ long long HTSPVFS::Seek ( long long pos, int whence, bool inprogress ) return ret; } -long long HTSPVFS::Size ( void ) +long long HTSPVFS::Size(void) { int64_t ret = -1; - htsmsg_t *m; - + htsmsg_t* m; + /* Build */ m = htsmsg_create_map(); htsmsg_add_u32(m, "id", m_fileId); Logger::Log(LogLevel::LEVEL_TRACE, "vfs stat id=%d", m_fileId); - + /* Send */ { CLockObject lock(m_conn.Mutex()); @@ -195,7 +202,7 @@ long long HTSPVFS::Size ( void ) return ret; } -void HTSPVFS::PauseStream ( bool paused ) +void HTSPVFS::PauseStream(bool paused) { m_paused = paused; @@ -209,14 +216,16 @@ void HTSPVFS::PauseStream ( bool paused ) { /* correct m_eofOffsetSecs based on how long we've been paused */ m_eofOffsetSecs += (std::time(nullptr) - m_pauseTime); - m_isRealTimeStream = (m_eofOffsetSecs >=0 && m_eofOffsetSecs < 10); - Logger::Log(LogLevel::LEVEL_TRACE, "vfs unpause inprogress recording m_eofOffsetSecs=%lld m_isRealTimeStream=%d", static_cast(m_eofOffsetSecs), m_isRealTimeStream); + m_isRealTimeStream = (m_eofOffsetSecs >= 0 && m_eofOffsetSecs < 10); + Logger::Log(LogLevel::LEVEL_TRACE, + "vfs unpause inprogress recording m_eofOffsetSecs=%lld m_isRealTimeStream=%d", + static_cast(m_eofOffsetSecs), m_isRealTimeStream); } m_pauseTime = 0; } } -bool HTSPVFS::IsRealTimeStream ( void ) +bool HTSPVFS::IsRealTimeStream(void) { return m_isRealTimeStream; } @@ -225,9 +234,9 @@ bool HTSPVFS::IsRealTimeStream ( void ) * HTSP Messages * *************************************************************************/ -bool HTSPVFS::SendFileOpen ( bool force ) +bool HTSPVFS::SendFileOpen(bool force) { - htsmsg_t *m; + htsmsg_t* m; /* Build Message */ m = htsmsg_create_map(); @@ -261,9 +270,9 @@ bool HTSPVFS::SendFileOpen ( bool force ) return m_fileId > 0; } -void HTSPVFS::SendFileClose ( void ) +void HTSPVFS::SendFileClose(void) { - htsmsg_t *m; + htsmsg_t* m; /* Build */ m = htsmsg_create_map(); @@ -271,11 +280,12 @@ void HTSPVFS::SendFileClose ( void ) /* If setting set, we will increase play count with CTvheadend::SetPlayCount */ if (m_conn.GetProtocol() >= 27) - htsmsg_add_u32(m, "playcount", Settings::GetInstance().GetDvrPlayStatus() ? - HTSP_DVR_PLAYCOUNT_KEEP : HTSP_DVR_PLAYCOUNT_INCR); + htsmsg_add_u32(m, "playcount", + Settings::GetInstance().GetDvrPlayStatus() ? HTSP_DVR_PLAYCOUNT_KEEP + : HTSP_DVR_PLAYCOUNT_INCR); Logger::Log(LogLevel::LEVEL_DEBUG, "vfs close id=%d", m_fileId); - + /* Send */ { CLockObject lock(m_conn.Mutex()); @@ -286,22 +296,22 @@ void HTSPVFS::SendFileClose ( void ) htsmsg_destroy(m); } -long long HTSPVFS::SendFileSeek ( int64_t pos, int whence, bool force ) +long long HTSPVFS::SendFileSeek(int64_t pos, int whence, bool force) { - htsmsg_t *m; + htsmsg_t* m; int64_t ret = -1; /* Build Message */ m = htsmsg_create_map(); - htsmsg_add_u32(m, "id", m_fileId); + htsmsg_add_u32(m, "id", m_fileId); htsmsg_add_s64(m, "offset", pos); if (whence == SEEK_CUR) htsmsg_add_str(m, "whence", "SEEK_CUR"); else if (whence == SEEK_END) htsmsg_add_str(m, "whence", "SEEK_END"); - Logger::Log(LogLevel::LEVEL_TRACE, "vfs seek id=%d whence=%d pos=%lld", - m_fileId, whence, (long long)pos); + Logger::Log(LogLevel::LEVEL_TRACE, "vfs seek id=%d whence=%d pos=%lld", m_fileId, whence, + (long long)pos); /* Send */ { @@ -325,7 +335,7 @@ long long HTSPVFS::SendFileSeek ( int64_t pos, int whence, bool force ) ret = -1; Logger::Log(LogLevel::LEVEL_ERROR, "vfs fileSeek response: 'offset' missing'"); - /* Update */ + /* Update */ } else { @@ -339,10 +349,10 @@ long long HTSPVFS::SendFileSeek ( int64_t pos, int whence, bool force ) return ret; } -ssize_t HTSPVFS::SendFileRead(unsigned char *buf, unsigned int len) +ssize_t HTSPVFS::SendFileRead(unsigned char* buf, unsigned int len) { - htsmsg_t *m; - const void *buffer; + htsmsg_t* m; + const void* buffer; size_t read; /* Build */ @@ -350,8 +360,7 @@ ssize_t HTSPVFS::SendFileRead(unsigned char *buf, unsigned int len) htsmsg_add_u32(m, "id", m_fileId); htsmsg_add_s64(m, "size", len); - Logger::Log(LogLevel::LEVEL_TRACE, "vfs read id=%d size=%d", - m_fileId, len); + Logger::Log(LogLevel::LEVEL_TRACE, "vfs read id=%d size=%d", m_fileId, len); /* Send */ { @@ -370,7 +379,7 @@ ssize_t HTSPVFS::SendFileRead(unsigned char *buf, unsigned int len) { Logger::Log(LogLevel::LEVEL_ERROR, "malformed fileRead response: 'data' missing"); return -1; - /* Store */ + /* Store */ } else { diff --git a/src/tvheadend/HTSPVFS.h b/src/tvheadend/HTSPVFS.h index faab231c..b889d08d 100644 --- a/src/tvheadend/HTSPVFS.h +++ b/src/tvheadend/HTSPVFS.h @@ -21,10 +21,10 @@ * */ -#include - #include "p8-platform/os.h" +#include + struct PVR_RECORDING; namespace tvheadend @@ -38,14 +38,14 @@ class HTSPConnection; class HTSPVFS { public: - HTSPVFS(HTSPConnection &conn); + HTSPVFS(HTSPConnection& conn); ~HTSPVFS(); void Connected(); - bool Open(const PVR_RECORDING &rec); + bool Open(const PVR_RECORDING& rec); void Close(); - ssize_t Read(unsigned char *buf, unsigned int len, bool inprogress); + ssize_t Read(unsigned char* buf, unsigned int len, bool inprogress); long long Seek(long long pos, int whence, bool inprogress); long long Size(); void PauseStream(bool paused); @@ -54,10 +54,10 @@ class HTSPVFS private: bool SendFileOpen(bool force = false); void SendFileClose(); - ssize_t SendFileRead(unsigned char *buf, unsigned int len); + ssize_t SendFileRead(unsigned char* buf, unsigned int len); long long SendFileSeek(int64_t pos, int whence, bool force = false); - HTSPConnection &m_conn; + HTSPConnection& m_conn; std::string m_path; uint32_t m_fileId; int64_t m_offset; diff --git a/src/tvheadend/IHTSPConnectionListener.h b/src/tvheadend/IHTSPConnectionListener.h index ed4c72fc..1bebc9ef 100644 --- a/src/tvheadend/IHTSPConnectionListener.h +++ b/src/tvheadend/IHTSPConnectionListener.h @@ -21,7 +21,8 @@ * */ -extern "C" { +extern "C" +{ #include "libhts/htsmsg.h" } @@ -38,7 +39,7 @@ class IHTSPConnectionListener virtual void Disconnected() = 0; virtual bool Connected() = 0; - virtual bool ProcessMessage(const char *method, htsmsg_t *msg) = 0; + virtual bool ProcessMessage(const char* method, htsmsg_t* msg) = 0; }; } // namespace tvheadend diff --git a/src/tvheadend/Profile.h b/src/tvheadend/Profile.h index 0ef2ac49..d34664f6 100644 --- a/src/tvheadend/Profile.h +++ b/src/tvheadend/Profile.h @@ -27,40 +27,39 @@ namespace tvheadend { - class Profile; - typedef std::vector Profiles; +class Profile; +typedef std::vector Profiles; - /** +/** * Represents a single streaming profile */ - class Profile - { - public: - - std::string GetUuid() const { return m_uuid; } - void SetUuid(const std::string &uuid) { m_uuid = uuid; } +class Profile +{ +public: + std::string GetUuid() const { return m_uuid; } + void SetUuid(const std::string& uuid) { m_uuid = uuid; } - std::string GetName() const { return m_name; } - void SetName(const std::string &name) { m_name = name; } + std::string GetName() const { return m_name; } + void SetName(const std::string& name) { m_name = name; } - std::string GetComment() const { return m_comment; } - void SetComment(const std::string &comment) { m_comment = comment; } + std::string GetComment() const { return m_comment; } + void SetComment(const std::string& comment) { m_comment = comment; } - private: - /* +private: + /* * The profile UUID */ - std::string m_uuid; + std::string m_uuid; - /** + /** * The profile name */ - std::string m_name; + std::string m_name; - /** + /** * The profile comment */ - std::string m_comment; - }; + std::string m_comment; +}; -} +} // namespace tvheadend diff --git a/src/tvheadend/Settings.cpp b/src/tvheadend/Settings.cpp index 8d119c07..31930dbf 100644 --- a/src/tvheadend/Settings.cpp +++ b/src/tvheadend/Settings.cpp @@ -19,34 +19,37 @@ * */ +#include "Settings.h" + #include "../client.h" #include "utilities/Logger.h" -#include "Settings.h" using namespace tvheadend; using namespace tvheadend::utilities; -const std::string Settings::DEFAULT_HOST = "127.0.0.1"; -const int Settings::DEFAULT_HTTP_PORT = 9981; -const int Settings::DEFAULT_HTSP_PORT = 9982; -const std::string Settings::DEFAULT_USERNAME = ""; -const std::string Settings::DEFAULT_PASSWORD = ""; -const int Settings::DEFAULT_CONNECT_TIMEOUT = 10000; // millisecs -const int Settings::DEFAULT_RESPONSE_TIMEOUT = 5000; // millisecs -const bool Settings::DEFAULT_TRACE_DEBUG = false; -const bool Settings::DEFAULT_ASYNC_EPG = true; -const bool Settings::DEFAULT_PRETUNER_ENABLED = false; -const int Settings::DEFAULT_TOTAL_TUNERS = 1; // total tuners > 1 => predictive tuning active -const int Settings::DEFAULT_PRETUNER_CLOSEDELAY = 10; // secs -const int Settings::DEFAULT_AUTOREC_MAXDIFF = 15; // mins. Maximum difference between real and approximate start time for auto recordings -const int Settings::DEFAULT_APPROX_TIME = 0; // don't use an approximate start time, use a fixed time instead for auto recordings -const std::string Settings::DEFAULT_STREAMING_PROFILE = ""; -const int Settings::DEFAULT_DVR_PRIO = DVR_PRIO_NORMAL; -const int Settings::DEFAULT_DVR_LIFETIME = 8; // enum 8 = 3 months -const int Settings::DEFAULT_DVR_DUPDETECT = DVR_AUTOREC_RECORD_ALL; -const bool Settings::DEFAULT_DVR_PLAYSTATUS = true; -const int Settings::DEFAULT_STREAM_CHUNKSIZE = 64; // KB -const bool Settings::DEFAULT_DVR_IGNORE_DUPLICATE_SCHEDULES = true; +const std::string Settings::DEFAULT_HOST = "127.0.0.1"; +const int Settings::DEFAULT_HTTP_PORT = 9981; +const int Settings::DEFAULT_HTSP_PORT = 9982; +const std::string Settings::DEFAULT_USERNAME = ""; +const std::string Settings::DEFAULT_PASSWORD = ""; +const int Settings::DEFAULT_CONNECT_TIMEOUT = 10000; // millisecs +const int Settings::DEFAULT_RESPONSE_TIMEOUT = 5000; // millisecs +const bool Settings::DEFAULT_TRACE_DEBUG = false; +const bool Settings::DEFAULT_ASYNC_EPG = true; +const bool Settings::DEFAULT_PRETUNER_ENABLED = false; +const int Settings::DEFAULT_TOTAL_TUNERS = 1; // total tuners > 1 => predictive tuning active +const int Settings::DEFAULT_PRETUNER_CLOSEDELAY = 10; // secs +const int Settings::DEFAULT_AUTOREC_MAXDIFF = + 15; // mins. Maximum difference between real and approximate start time for auto recordings +const int Settings::DEFAULT_APPROX_TIME = + 0; // don't use an approximate start time, use a fixed time instead for auto recordings +const std::string Settings::DEFAULT_STREAMING_PROFILE = ""; +const int Settings::DEFAULT_DVR_PRIO = DVR_PRIO_NORMAL; +const int Settings::DEFAULT_DVR_LIFETIME = 8; // enum 8 = 3 months +const int Settings::DEFAULT_DVR_DUPDETECT = DVR_AUTOREC_RECORD_ALL; +const bool Settings::DEFAULT_DVR_PLAYSTATUS = true; +const int Settings::DEFAULT_STREAM_CHUNKSIZE = 64; // KB +const bool Settings::DEFAULT_DVR_IGNORE_DUPLICATE_SCHEDULES = true; void Settings::ReadSettings() { @@ -70,7 +73,8 @@ void Settings::ReadSettings() /* Predictive Tuning */ m_bPretunerEnabled = ReadBoolSetting("pretuner_enabled", DEFAULT_PRETUNER_ENABLED); SetTotalTuners(m_bPretunerEnabled ? ReadIntSetting("total_tuners", DEFAULT_TOTAL_TUNERS) : 1); - SetPreTunerCloseDelay(m_bPretunerEnabled ? ReadIntSetting("pretuner_closedelay", DEFAULT_PRETUNER_CLOSEDELAY) : 0); + SetPreTunerCloseDelay( + m_bPretunerEnabled ? ReadIntSetting("pretuner_closedelay", DEFAULT_PRETUNER_CLOSEDELAY) : 0); /* Auto recordings */ SetAutorecApproxTime(ReadIntSetting("autorec_approxtime", DEFAULT_APPROX_TIME)); @@ -91,10 +95,11 @@ void Settings::ReadSettings() SetStreamReadChunkSizeKB(ReadIntSetting("stream_readchunksize", DEFAULT_STREAM_CHUNKSIZE)); /* Scheduled recordings */ - SetIgnoreDuplicateSchedules(ReadBoolSetting("dvr_ignore_duplicates", DEFAULT_DVR_IGNORE_DUPLICATE_SCHEDULES)); + SetIgnoreDuplicateSchedules( + ReadBoolSetting("dvr_ignore_duplicates", DEFAULT_DVR_IGNORE_DUPLICATE_SCHEDULES)); } -ADDON_STATUS Settings::SetSetting(const std::string &key, const void *value) +ADDON_STATUS Settings::SetSetting(const std::string& key, const void* value) { /* Connection */ if (key == "host") @@ -109,17 +114,17 @@ ADDON_STATUS Settings::SetSetting(const std::string &key, const void *value) return SetStringSetting(GetPassword(), value); else if (key == "connect_timeout") { - if (GetConnectTimeout() == (*(reinterpret_cast(value)) * 1000)) + if (GetConnectTimeout() == (*(reinterpret_cast(value)) * 1000)) return ADDON_STATUS_OK; else return ADDON_STATUS_NEED_RESTART; } else if (key == "response_timeout") { - if (GetResponseTimeout() == (*(reinterpret_cast(value)) * 1000)) + if (GetResponseTimeout() == (*(reinterpret_cast(value)) * 1000)) return ADDON_STATUS_OK; else - return ADDON_STATUS_NEED_RESTART; + return ADDON_STATUS_NEED_RESTART; } /* Debug */ else if (key == "trace_debug") @@ -173,7 +178,7 @@ ADDON_STATUS Settings::SetSetting(const std::string &key, const void *value) } } -std::string Settings::ReadStringSetting(const std::string &key, const std::string &def) +std::string Settings::ReadStringSetting(const std::string& key, const std::string& def) { char value[1024]; if (XBMC->GetSetting(key.c_str(), value)) @@ -182,7 +187,7 @@ std::string Settings::ReadStringSetting(const std::string &key, const std::strin return def; } -int Settings::ReadIntSetting(const std::string &key, int def) +int Settings::ReadIntSetting(const std::string& key, int def) { int value; if (XBMC->GetSetting(key.c_str(), &value)) @@ -191,7 +196,7 @@ int Settings::ReadIntSetting(const std::string &key, int def) return def; } -bool Settings::ReadBoolSetting(const std::string &key, bool def) +bool Settings::ReadBoolSetting(const std::string& key, bool def) { bool value; if (XBMC->GetSetting(key.c_str(), &value)) @@ -200,25 +205,25 @@ bool Settings::ReadBoolSetting(const std::string &key, bool def) return def; } -ADDON_STATUS Settings::SetStringSetting(const std::string &oldValue, const void *newValue) +ADDON_STATUS Settings::SetStringSetting(const std::string& oldValue, const void* newValue) { - if (oldValue == std::string(reinterpret_cast(newValue))) + if (oldValue == std::string(reinterpret_cast(newValue))) return ADDON_STATUS_OK; return ADDON_STATUS_NEED_RESTART; } -ADDON_STATUS Settings::SetIntSetting(int oldValue, const void *newValue) +ADDON_STATUS Settings::SetIntSetting(int oldValue, const void* newValue) { - if (oldValue == *(reinterpret_cast(newValue))) + if (oldValue == *(reinterpret_cast(newValue))) return ADDON_STATUS_OK; return ADDON_STATUS_NEED_RESTART; } -ADDON_STATUS Settings::SetBoolSetting(bool oldValue, const void *newValue) +ADDON_STATUS Settings::SetBoolSetting(bool oldValue, const void* newValue) { - if (oldValue == *(reinterpret_cast(newValue))) + if (oldValue == *(reinterpret_cast(newValue))) return ADDON_STATUS_OK; return ADDON_STATUS_NEED_RESTART; diff --git a/src/tvheadend/Settings.h b/src/tvheadend/Settings.h index 30b14894..ee50f882 100644 --- a/src/tvheadend/Settings.h +++ b/src/tvheadend/Settings.h @@ -21,88 +21,91 @@ * */ -#include - #include "HTSPTypes.h" #include "kodi/xbmc_addon_types.h" -namespace tvheadend { +#include - /** +namespace tvheadend +{ + +/** * Represents the current addon settings */ - class Settings { - public: - - // Default values. - static const std::string DEFAULT_HOST; - static const int DEFAULT_HTTP_PORT; - static const int DEFAULT_HTSP_PORT; - static const std::string DEFAULT_USERNAME; - static const std::string DEFAULT_PASSWORD; - static const int DEFAULT_CONNECT_TIMEOUT; // millisecs - static const int DEFAULT_RESPONSE_TIMEOUT; // millisecs - static const bool DEFAULT_TRACE_DEBUG; - static const bool DEFAULT_ASYNC_EPG; - static const bool DEFAULT_PRETUNER_ENABLED; - static const int DEFAULT_TOTAL_TUNERS; - static const int DEFAULT_PRETUNER_CLOSEDELAY; // secs - static const int DEFAULT_AUTOREC_MAXDIFF; // mins. Maximum difference between real and approximate start time for auto recordings - static const int DEFAULT_APPROX_TIME; // 0..1 (0 = use a fixed start time, 1 = use an approximate start time for auto recordings) - static const std::string DEFAULT_STREAMING_PROFILE; - static const int DEFAULT_DVR_PRIO; // any dvr_prio_t numeric value - static const int DEFAULT_DVR_LIFETIME; // 0..14 (0 = 1 day, 14 = forever) - static const int DEFAULT_DVR_DUPDETECT; // 0..5 (0 = record all, 5 = limit to once a day) - static const bool DEFAULT_DVR_PLAYSTATUS; - static const int DEFAULT_STREAM_CHUNKSIZE; // KB - static const bool DEFAULT_DVR_IGNORE_DUPLICATE_SCHEDULES; - - /** +class Settings +{ +public: + // Default values. + static const std::string DEFAULT_HOST; + static const int DEFAULT_HTTP_PORT; + static const int DEFAULT_HTSP_PORT; + static const std::string DEFAULT_USERNAME; + static const std::string DEFAULT_PASSWORD; + static const int DEFAULT_CONNECT_TIMEOUT; // millisecs + static const int DEFAULT_RESPONSE_TIMEOUT; // millisecs + static const bool DEFAULT_TRACE_DEBUG; + static const bool DEFAULT_ASYNC_EPG; + static const bool DEFAULT_PRETUNER_ENABLED; + static const int DEFAULT_TOTAL_TUNERS; + static const int DEFAULT_PRETUNER_CLOSEDELAY; // secs + static const int + DEFAULT_AUTOREC_MAXDIFF; // mins. Maximum difference between real and approximate start time for auto recordings + static const int + DEFAULT_APPROX_TIME; // 0..1 (0 = use a fixed start time, 1 = use an approximate start time for auto recordings) + static const std::string DEFAULT_STREAMING_PROFILE; + static const int DEFAULT_DVR_PRIO; // any dvr_prio_t numeric value + static const int DEFAULT_DVR_LIFETIME; // 0..14 (0 = 1 day, 14 = forever) + static const int DEFAULT_DVR_DUPDETECT; // 0..5 (0 = record all, 5 = limit to once a day) + static const bool DEFAULT_DVR_PLAYSTATUS; + static const int DEFAULT_STREAM_CHUNKSIZE; // KB + static const bool DEFAULT_DVR_IGNORE_DUPLICATE_SCHEDULES; + + /** * Singleton getter for the instance */ - static Settings& GetInstance() - { - static Settings settings; - return settings; - } + static Settings& GetInstance() + { + static Settings settings; + return settings; + } - /** + /** * Read all settings defined in settings.xml */ - void ReadSettings(); + void ReadSettings(); - /** + /** * Set a value according to key definition in settings.xml */ - ADDON_STATUS SetSetting(const std::string &key, const void *value); + ADDON_STATUS SetSetting(const std::string& key, const void* value); - /** + /** * Getters for the settings values */ - std::string GetHostname() const { return m_strHostname; } - const char *GetConstCharHostname() const { return m_strHostname.c_str(); } - int GetPortHTSP() const { return m_iPortHTSP; } - int GetPortHTTP() const { return m_iPortHTTP; } - std::string GetUsername() const { return m_strUsername; } - std::string GetPassword() const { return m_strPassword; } - int GetConnectTimeout() const { return m_iConnectTimeout; } - int GetResponseTimeout() const { return m_iResponseTimeout; } - bool GetTraceDebug() const { return m_bTraceDebug; } - bool GetAsyncEpg() const { return m_bAsyncEpg; } - int GetTotalTuners() const { return m_iTotalTuners; } - int GetPreTunerCloseDelay() const { return m_iPreTunerCloseDelay; } - int GetAutorecApproxTime() const { return m_iAutorecApproxTime; } - int GetAutorecMaxDiff() const { return m_iAutorecMaxDiff; } - std::string GetStreamingProfile() const { return m_strStreamingProfile; } - int GetDvrPriority() const { return m_iDvrPriority; } - int GetDvrDupdetect() const { return m_iDvrDupdetect; } - int GetDvrLifetime(bool asEnum = false) const; - bool GetDvrPlayStatus() const { return m_bDvrPlayStatus; } - int GetStreamReadChunkSize() const { return m_iStreamReadChunkSizeKB; } - bool GetIgnoreDuplicateSchedules() const { return m_bIgnoreDuplicateSchedules; } - - private: - Settings() + std::string GetHostname() const { return m_strHostname; } + const char* GetConstCharHostname() const { return m_strHostname.c_str(); } + int GetPortHTSP() const { return m_iPortHTSP; } + int GetPortHTTP() const { return m_iPortHTTP; } + std::string GetUsername() const { return m_strUsername; } + std::string GetPassword() const { return m_strPassword; } + int GetConnectTimeout() const { return m_iConnectTimeout; } + int GetResponseTimeout() const { return m_iResponseTimeout; } + bool GetTraceDebug() const { return m_bTraceDebug; } + bool GetAsyncEpg() const { return m_bAsyncEpg; } + int GetTotalTuners() const { return m_iTotalTuners; } + int GetPreTunerCloseDelay() const { return m_iPreTunerCloseDelay; } + int GetAutorecApproxTime() const { return m_iAutorecApproxTime; } + int GetAutorecMaxDiff() const { return m_iAutorecMaxDiff; } + std::string GetStreamingProfile() const { return m_strStreamingProfile; } + int GetDvrPriority() const { return m_iDvrPriority; } + int GetDvrDupdetect() const { return m_iDvrDupdetect; } + int GetDvrLifetime(bool asEnum = false) const; + bool GetDvrPlayStatus() const { return m_bDvrPlayStatus; } + int GetStreamReadChunkSize() const { return m_iStreamReadChunkSizeKB; } + bool GetIgnoreDuplicateSchedules() const { return m_bIgnoreDuplicateSchedules; } + +private: + Settings() : m_strHostname(DEFAULT_HOST), m_iPortHTSP(DEFAULT_HTTP_PORT), m_iPortHTTP(DEFAULT_HTSP_PORT), @@ -123,68 +126,70 @@ namespace tvheadend { m_iDvrDupdetect(DEFAULT_DVR_DUPDETECT), m_bDvrPlayStatus(DEFAULT_DVR_PLAYSTATUS), m_iStreamReadChunkSizeKB(DEFAULT_STREAM_CHUNKSIZE), - m_bIgnoreDuplicateSchedules(DEFAULT_DVR_IGNORE_DUPLICATE_SCHEDULES) {} + m_bIgnoreDuplicateSchedules(DEFAULT_DVR_IGNORE_DUPLICATE_SCHEDULES) + { + } - Settings(Settings const &) = delete; - void operator=(Settings const &) = delete; + Settings(Settings const&) = delete; + void operator=(Settings const&) = delete; - /** + /** * Setters */ - void SetHostname(const std::string& value) { m_strHostname = value; } - void SetPortHTSP(int value) { m_iPortHTSP = value; } - void SetPortHTTP(int value) { m_iPortHTTP = value; } - void SetUsername(const std::string& value) { m_strUsername = value; } - void SetPassword(const std::string& value) { m_strPassword = value; } - void SetConnectTimeout(int value) { m_iConnectTimeout = value; } - void SetResponseTimeout(int value) { m_iResponseTimeout = value; } - void SetTraceDebug(bool value) { m_bTraceDebug = value; } - void SetAsyncEpg(bool value) { m_bAsyncEpg = value; } - void SetTotalTuners(int value) { m_iTotalTuners = value; } - void SetPreTunerCloseDelay(int value) { m_iPreTunerCloseDelay = value; } - void SetAutorecApproxTime(int value) { m_iAutorecApproxTime = value; } - void SetAutorecMaxDiff(int value) { m_iAutorecMaxDiff = value; } - void SetStreamingProfile(const std::string &value) { m_strStreamingProfile = value; } - void SetDvrPriority(int value) { m_iDvrPriority = value; } - void SetDvrLifetime(int value) { m_iDvrLifetime = value; } - void SetDvrDupdetect(int value) { m_iDvrDupdetect = value; } - void SetDvrPlayStatus(bool value) { m_bDvrPlayStatus = value; } - void SetStreamReadChunkSizeKB(int value) { m_iStreamReadChunkSizeKB = value; } - void SetIgnoreDuplicateSchedules(bool value) { m_bIgnoreDuplicateSchedules = value; } - - /** + void SetHostname(const std::string& value) { m_strHostname = value; } + void SetPortHTSP(int value) { m_iPortHTSP = value; } + void SetPortHTTP(int value) { m_iPortHTTP = value; } + void SetUsername(const std::string& value) { m_strUsername = value; } + void SetPassword(const std::string& value) { m_strPassword = value; } + void SetConnectTimeout(int value) { m_iConnectTimeout = value; } + void SetResponseTimeout(int value) { m_iResponseTimeout = value; } + void SetTraceDebug(bool value) { m_bTraceDebug = value; } + void SetAsyncEpg(bool value) { m_bAsyncEpg = value; } + void SetTotalTuners(int value) { m_iTotalTuners = value; } + void SetPreTunerCloseDelay(int value) { m_iPreTunerCloseDelay = value; } + void SetAutorecApproxTime(int value) { m_iAutorecApproxTime = value; } + void SetAutorecMaxDiff(int value) { m_iAutorecMaxDiff = value; } + void SetStreamingProfile(const std::string& value) { m_strStreamingProfile = value; } + void SetDvrPriority(int value) { m_iDvrPriority = value; } + void SetDvrLifetime(int value) { m_iDvrLifetime = value; } + void SetDvrDupdetect(int value) { m_iDvrDupdetect = value; } + void SetDvrPlayStatus(bool value) { m_bDvrPlayStatus = value; } + void SetStreamReadChunkSizeKB(int value) { m_iStreamReadChunkSizeKB = value; } + void SetIgnoreDuplicateSchedules(bool value) { m_bIgnoreDuplicateSchedules = value; } + + /** * Read/Set values according to definition in settings.xml */ - static std::string ReadStringSetting(const std::string &key, const std::string &def); - static int ReadIntSetting(const std::string &key, int def); - static bool ReadBoolSetting(const std::string &key, bool def); - - // @return ADDON_STATUS_OK if value has not changed, ADDON_STATUS_NEED_RESTART otherwise - static ADDON_STATUS SetStringSetting(const std::string &oldValue, const void *newValue); - static ADDON_STATUS SetIntSetting(int oldValue, const void *newValue); - static ADDON_STATUS SetBoolSetting(bool oldValue, const void *newValue); - - std::string m_strHostname; - int m_iPortHTSP; - int m_iPortHTTP; - std::string m_strUsername; - std::string m_strPassword; - int m_iConnectTimeout; - int m_iResponseTimeout; - bool m_bTraceDebug; - bool m_bAsyncEpg; - bool m_bPretunerEnabled; - int m_iTotalTuners; - int m_iPreTunerCloseDelay; - bool m_iAutorecApproxTime; - int m_iAutorecMaxDiff; - std::string m_strStreamingProfile; - int m_iDvrPriority; - int m_iDvrLifetime; - int m_iDvrDupdetect; - bool m_bDvrPlayStatus; - int m_iStreamReadChunkSizeKB; - bool m_bIgnoreDuplicateSchedules; - }; - -} + static std::string ReadStringSetting(const std::string& key, const std::string& def); + static int ReadIntSetting(const std::string& key, int def); + static bool ReadBoolSetting(const std::string& key, bool def); + + // @return ADDON_STATUS_OK if value has not changed, ADDON_STATUS_NEED_RESTART otherwise + static ADDON_STATUS SetStringSetting(const std::string& oldValue, const void* newValue); + static ADDON_STATUS SetIntSetting(int oldValue, const void* newValue); + static ADDON_STATUS SetBoolSetting(bool oldValue, const void* newValue); + + std::string m_strHostname; + int m_iPortHTSP; + int m_iPortHTTP; + std::string m_strUsername; + std::string m_strPassword; + int m_iConnectTimeout; + int m_iResponseTimeout; + bool m_bTraceDebug; + bool m_bAsyncEpg; + bool m_bPretunerEnabled; + int m_iTotalTuners; + int m_iPreTunerCloseDelay; + bool m_iAutorecApproxTime; + int m_iAutorecMaxDiff; + std::string m_strStreamingProfile; + int m_iDvrPriority; + int m_iDvrLifetime; + int m_iDvrDupdetect; + bool m_bDvrPlayStatus; + int m_iStreamReadChunkSizeKB; + bool m_bIgnoreDuplicateSchedules; +}; + +} // namespace tvheadend diff --git a/src/tvheadend/Subscription.cpp b/src/tvheadend/Subscription.cpp index 5e6c16e4..d1bf18c0 100644 --- a/src/tvheadend/Subscription.cpp +++ b/src/tvheadend/Subscription.cpp @@ -21,21 +21,21 @@ #include "Subscription.h" +#include "HTSPConnection.h" #include "utilities/LocalizedString.h" #include "utilities/Logger.h" -#include "HTSPConnection.h" using namespace P8PLATFORM; using namespace tvheadend; using namespace tvheadend::utilities; -Subscription::Subscription(HTSPConnection &conn) : - m_id(0), - m_channelId(0), - m_weight(SUBSCRIPTION_WEIGHT_NORMAL), - m_speed(1000), - m_state(SUBSCRIPTION_STOPPED), - m_conn(conn) +Subscription::Subscription(HTSPConnection& conn) + : m_id(0), + m_channelId(0), + m_weight(SUBSCRIPTION_WEIGHT_NORMAL), + m_speed(1000), + m_state(SUBSCRIPTION_STOPPED), + m_conn(conn) { } @@ -111,7 +111,7 @@ std::string Subscription::GetProfile() const return m_profile; } -void Subscription::SetProfile(const std::string &profile) +void Subscription::SetProfile(const std::string& profile) { CLockObject lock(m_mutex); m_profile = profile; @@ -129,19 +129,19 @@ void Subscription::SendSubscribe(uint32_t channelId, uint32_t weight, bool resta } /* Build message */ - htsmsg_t *m = htsmsg_create_map(); - htsmsg_add_s32(m, "channelId", GetChannelId()); - htsmsg_add_u32(m, "subscriptionId", GetId()); - htsmsg_add_u32(m, "weight", GetWeight()); + htsmsg_t* m = htsmsg_create_map(); + htsmsg_add_s32(m, "channelId", GetChannelId()); + htsmsg_add_u32(m, "subscriptionId", GetId()); + htsmsg_add_u32(m, "weight", GetWeight()); htsmsg_add_u32(m, "timeshiftPeriod", static_cast(~0)); - htsmsg_add_u32(m, "normts", 1); - htsmsg_add_u32(m, "queueDepth", PACKET_QUEUE_DEPTH); + htsmsg_add_u32(m, "normts", 1); + htsmsg_add_u32(m, "queueDepth", PACKET_QUEUE_DEPTH); /* Use the specified profile if it has been set */ if (!GetProfile().empty()) htsmsg_add_str(m, "profile", GetProfile().c_str()); - Logger::Log(LogLevel::LEVEL_DEBUG, "demux subscribe to %d", GetChannelId()); + Logger::Log(LogLevel::LEVEL_DEBUG, "demux subscribe to %d", GetChannelId()); /* Send and Wait for response */ if (restart) @@ -154,14 +154,16 @@ void Subscription::SendSubscribe(uint32_t channelId, uint32_t weight, bool resta htsmsg_destroy(m); SetState(SUBSCRIPTION_STARTING); - Logger::Log(LogLevel::LEVEL_DEBUG, "demux successfully subscribed to channel id %d, subscription id %d", GetChannelId(), GetId()); + Logger::Log(LogLevel::LEVEL_DEBUG, + "demux successfully subscribed to channel id %d, subscription id %d", GetChannelId(), + GetId()); } void Subscription::SendUnsubscribe(void) { /* Build message */ - htsmsg_t *m = htsmsg_create_map(); - htsmsg_add_u32(m, "subscriptionId", GetId()); + htsmsg_t* m = htsmsg_create_map(); + htsmsg_add_u32(m, "subscriptionId", GetId()); Logger::Log(LogLevel::LEVEL_DEBUG, "demux unsubscribe from %d", GetChannelId()); /* Mark subscription as inactive immediately in case this command fails */ @@ -172,17 +174,19 @@ void Subscription::SendUnsubscribe(void) return; htsmsg_destroy(m); - Logger::Log(LogLevel::LEVEL_DEBUG, "demux successfully unsubscribed from channel id %d, subscription id %d", GetChannelId(), GetId()); + Logger::Log(LogLevel::LEVEL_DEBUG, + "demux successfully unsubscribed from channel id %d, subscription id %d", + GetChannelId(), GetId()); } bool Subscription::SendSeek(double time) { /* Build message */ - htsmsg_t *m = htsmsg_create_map(); + htsmsg_t* m = htsmsg_create_map(); htsmsg_add_u32(m, "subscriptionId", GetId()); - htsmsg_add_s64(m, "time", static_cast(time * 1000LL)); - htsmsg_add_u32(m, "absolute", 1); - Logger::Log(LogLevel::LEVEL_DEBUG, "demux send seek %d", time); + htsmsg_add_s64(m, "time", static_cast(time * 1000LL)); + htsmsg_add_u32(m, "absolute", 1); + Logger::Log(LogLevel::LEVEL_DEBUG, "demux send seek %d", time); /* Send and Wait */ { @@ -205,10 +209,11 @@ void Subscription::SendSpeed(int32_t speed, bool restart) SetSpeed(speed); /* Build message */ - htsmsg_t *m = htsmsg_create_map(); + htsmsg_t* m = htsmsg_create_map(); htsmsg_add_u32(m, "subscriptionId", GetId()); - htsmsg_add_s32(m, "speed", GetSpeed() / 10); // Kodi uses values an order of magnitude larger than tvheadend - Logger::Log(LogLevel::LEVEL_DEBUG, "demux send speed %d", GetSpeed() / 10); + htsmsg_add_s32(m, "speed", + GetSpeed() / 10); // Kodi uses values an order of magnitude larger than tvheadend + Logger::Log(LogLevel::LEVEL_DEBUG, "demux send speed %d", GetSpeed() / 10); if (restart) m = m_conn.SendAndWait0("subscriptionSpeed", m); @@ -224,10 +229,10 @@ void Subscription::SendWeight(uint32_t weight) SetWeight(weight); /* Build message */ - htsmsg_t *m = htsmsg_create_map(); + htsmsg_t* m = htsmsg_create_map(); htsmsg_add_u32(m, "subscriptionId", GetId()); - htsmsg_add_s32(m, "weight", GetWeight()); - Logger::Log(LogLevel::LEVEL_DEBUG, "demux send weight %u", GetWeight()); + htsmsg_add_s32(m, "weight", GetWeight()); + Logger::Log(LogLevel::LEVEL_DEBUG, "demux send weight %u", GetWeight()); /* Send and Wait */ { @@ -238,7 +243,7 @@ void Subscription::SendWeight(uint32_t weight) htsmsg_destroy(m); } -void Subscription::ParseSubscriptionStatus ( htsmsg_t *m ) +void Subscription::ParseSubscriptionStatus(htsmsg_t* m) { /* Not for preTuning and postTuning subscriptions */ if (GetWeight() == static_cast(SUBSCRIPTION_WEIGHT_PRETUNING) || @@ -248,12 +253,12 @@ void Subscription::ParseSubscriptionStatus ( htsmsg_t *m ) return; } - const char *status = htsmsg_get_str(m, "status"); + const char* status = htsmsg_get_str(m, "status"); /* 'subscriptionErrors' was added in htsp v20, use 'status' for older backends */ if (m_conn.GetProtocol() >= 20) { - const char *error = htsmsg_get_str(m, "subscriptionError"); + const char* error = htsmsg_get_str(m, "subscriptionError"); /* This field is absent when everything is fine */ if (error != NULL) diff --git a/src/tvheadend/Subscription.h b/src/tvheadend/Subscription.h index 85b009df..b0bec683 100644 --- a/src/tvheadend/Subscription.h +++ b/src/tvheadend/Subscription.h @@ -21,9 +21,10 @@ * */ -#include #include "p8-platform/threads/mutex.h" +#include + extern "C" { #include "libhts/htsmsg.h" @@ -31,121 +32,122 @@ extern "C" namespace tvheadend { - class HTSPConnection; - - /* streaming uses a weight of 100 by default on the tvh side */ - /* lowest configurable streaming weight in tvh is 50 */ - /* predictive tuning should be lower to avoid conflicts */ - /* weight 0 means that tvh will use the weight of it's config */ - enum eSubscriptionWeight - { - SUBSCRIPTION_WEIGHT_NORMAL = 100, - SUBSCRIPTION_WEIGHT_PRETUNING = 40, - SUBSCRIPTION_WEIGHT_POSTTUNING = 30, - SUBSCRIPTION_WEIGHT_SERVERCONF = 0, - }; - - enum eSubsriptionState - { - SUBSCRIPTION_STOPPED = 0, /* subscription is stopped or not started yet */ - SUBSCRIPTION_STARTING = 1, /* subscription is starting */ - SUBSCRIPTION_RUNNING = 2, /* subscription is running normal */ - SUBSCRIPTION_NOFREEADAPTER = 3, /* subscription has no free adapter to use */ - SUBSCRIPTION_SCRAMBLED = 4, /* subscription is not running because the channel is scrambled */ - SUBSCRIPTION_NOSIGNAL = 5, /* subscription is not running because of a weak/no input signal */ - SUBSCRIPTION_TUNINGFAILED = 6, /* subscription could not be started because of a tuning error */ - SUBSCRIPTION_USERLIMIT = 7, /* userlimit is reached, so we could not start this subscription */ - SUBSCRIPTION_NOACCESS = 8, /* we have no rights to watch this channel */ - SUBSCRIPTION_UNKNOWN = 9, /* subscription state is unknown, also used for pretuning and posttuning subscriptions */ - SUBSCRIPTION_PREPOSTTUNING = 10, /* used for pre and posttuning subscriptions (we do not care what the actual state is) */ - }; - - static const int PACKET_QUEUE_DEPTH = 10000000; - - class Subscription - { - public: - Subscription(HTSPConnection &conn); - - bool IsActive() const; - uint32_t GetId() const; - uint32_t GetChannelId() const; - uint32_t GetWeight() const; - int32_t GetSpeed() const; - eSubsriptionState GetState() const; - std::string GetProfile() const; - - /** +class HTSPConnection; + +/* streaming uses a weight of 100 by default on the tvh side */ +/* lowest configurable streaming weight in tvh is 50 */ +/* predictive tuning should be lower to avoid conflicts */ +/* weight 0 means that tvh will use the weight of it's config */ +enum eSubscriptionWeight +{ + SUBSCRIPTION_WEIGHT_NORMAL = 100, + SUBSCRIPTION_WEIGHT_PRETUNING = 40, + SUBSCRIPTION_WEIGHT_POSTTUNING = 30, + SUBSCRIPTION_WEIGHT_SERVERCONF = 0, +}; + +enum eSubsriptionState +{ + SUBSCRIPTION_STOPPED = 0, /* subscription is stopped or not started yet */ + SUBSCRIPTION_STARTING = 1, /* subscription is starting */ + SUBSCRIPTION_RUNNING = 2, /* subscription is running normal */ + SUBSCRIPTION_NOFREEADAPTER = 3, /* subscription has no free adapter to use */ + SUBSCRIPTION_SCRAMBLED = 4, /* subscription is not running because the channel is scrambled */ + SUBSCRIPTION_NOSIGNAL = 5, /* subscription is not running because of a weak/no input signal */ + SUBSCRIPTION_TUNINGFAILED = 6, /* subscription could not be started because of a tuning error */ + SUBSCRIPTION_USERLIMIT = 7, /* userlimit is reached, so we could not start this subscription */ + SUBSCRIPTION_NOACCESS = 8, /* we have no rights to watch this channel */ + SUBSCRIPTION_UNKNOWN = + 9, /* subscription state is unknown, also used for pretuning and posttuning subscriptions */ + SUBSCRIPTION_PREPOSTTUNING = + 10, /* used for pre and posttuning subscriptions (we do not care what the actual state is) */ +}; + +static const int PACKET_QUEUE_DEPTH = 10000000; + +class Subscription +{ +public: + Subscription(HTSPConnection& conn); + + bool IsActive() const; + uint32_t GetId() const; + uint32_t GetChannelId() const; + uint32_t GetWeight() const; + int32_t GetSpeed() const; + eSubsriptionState GetState() const; + std::string GetProfile() const; + + /** * Subscribe to a channel on the backend * @param channelId the channel to subscribe to * @param weight the desired subscription weight * @param restart restart the current subscription (i.e. after lost connection), other parameters will be ignored */ - void SendSubscribe(uint32_t channelId, uint32_t weight, bool restart = false); + void SendSubscribe(uint32_t channelId, uint32_t weight, bool restart = false); - /** + /** * Unsubscribe from a channel on the backend */ - void SendUnsubscribe(); + void SendUnsubscribe(); - /** + /** * Send a seek to the backend * @param time timestamp to seek to * @return false if the command failed, true otherwise */ - bool SendSeek(double time); + bool SendSeek(double time); - /** + /** * Change the subscription speed on the backend * @param speed the desired speed of the subscription * @param restart resent the current subscription speed (i.e. after lost connection), other parameters will be ignored */ - void SendSpeed(int32_t speed, bool restart = false); + void SendSpeed(int32_t speed, bool restart = false); - /** + /** * Change the subscription weight on the backend * @param weight the desired subscription weight */ - void SendWeight(uint32_t weight); + void SendWeight(uint32_t weight); - /** + /** * Parse the subscription status out of the incoming htsp data * @param m message containing the status field */ - void ParseSubscriptionStatus(htsmsg_t *m); + void ParseSubscriptionStatus(htsmsg_t* m); - /** + /** * Use the specified profile for all new subscriptions * @param profile the profile */ - void SetProfile(const std::string &profile); + void SetProfile(const std::string& profile); - private: +private: + void SetId(uint32_t id); + void SetChannelId(uint32_t id); + void SetWeight(uint32_t weight); + void SetSpeed(int32_t speed); + void SetState(eSubsriptionState state); - void SetId(uint32_t id); - void SetChannelId(uint32_t id); - void SetWeight(uint32_t weight); - void SetSpeed(int32_t speed); - void SetState(eSubsriptionState state); - - /** + /** * Show a notification to the user depending on the subscription state */ - void ShowStateNotification(); + void ShowStateNotification(); - /** + /** * Get the next unique subscription Id */ - static uint32_t GetNextId(); - - uint32_t m_id; - uint32_t m_channelId; - uint32_t m_weight; - int32_t m_speed; - eSubsriptionState m_state; - std::string m_profile; - HTSPConnection &m_conn; - - mutable P8PLATFORM::CMutex m_mutex; - }; -} + static uint32_t GetNextId(); + + uint32_t m_id; + uint32_t m_channelId; + uint32_t m_weight; + int32_t m_speed; + eSubsriptionState m_state; + std::string m_profile; + HTSPConnection& m_conn; + + mutable P8PLATFORM::CMutex m_mutex; +}; +} // namespace tvheadend diff --git a/src/tvheadend/TimeRecordings.cpp b/src/tvheadend/TimeRecordings.cpp index aa55da34..aae5f5ff 100644 --- a/src/tvheadend/TimeRecordings.cpp +++ b/src/tvheadend/TimeRecordings.cpp @@ -23,17 +23,16 @@ #include "HTSPConnection.h" #include "entity/Recording.h" -#include "utilities/Utilities.h" -#include "utilities/Logger.h" #include "utilities/LifetimeMapper.h" +#include "utilities/Logger.h" +#include "utilities/Utilities.h" using namespace P8PLATFORM; using namespace tvheadend; using namespace tvheadend::entity; using namespace tvheadend::utilities; -TimeRecordings::TimeRecordings(HTSPConnection &conn) : - m_conn(conn) +TimeRecordings::TimeRecordings(HTSPConnection& conn) : m_conn(conn) { } @@ -50,10 +49,8 @@ void TimeRecordings::Connected() void TimeRecordings::SyncDvrCompleted() { - utilities::erase_if(m_timeRecordings, [](const TimeRecordingMapEntry &entry) - { - return entry.second.IsDirty(); - }); + utilities::erase_if(m_timeRecordings, + [](const TimeRecordingMapEntry& entry) { return entry.second.IsDirty(); }); } int TimeRecordings::GetTimerecTimerCount() const @@ -61,56 +58,54 @@ int TimeRecordings::GetTimerecTimerCount() const return m_timeRecordings.size(); } -void TimeRecordings::GetTimerecTimers(std::vector &timers) +void TimeRecordings::GetTimerecTimers(std::vector& timers) { for (auto tit = m_timeRecordings.begin(); tit != m_timeRecordings.end(); ++tit) { /* Setup entry */ - PVR_TIMER tmr = { 0 }; - - tmr.iClientIndex = tit->second.GetId(); - tmr.iClientChannelUid = (tit->second.GetChannel() > 0) ? tit->second.GetChannel() : PVR_TIMER_ANY_CHANNEL; - tmr.startTime = tit->second.GetStart(); - tmr.endTime = tit->second.GetStop(); - strncpy(tmr.strTitle, - tit->second.GetName().c_str(), sizeof(tmr.strTitle) - 1); - strncpy(tmr.strEpgSearchString, - "", sizeof(tmr.strEpgSearchString) - 1); // n/a for manual timers - strncpy(tmr.strDirectory, - tit->second.GetDirectory().c_str(), sizeof(tmr.strDirectory) - 1); + PVR_TIMER tmr = {0}; + + tmr.iClientIndex = tit->second.GetId(); + tmr.iClientChannelUid = + (tit->second.GetChannel() > 0) ? tit->second.GetChannel() : PVR_TIMER_ANY_CHANNEL; + tmr.startTime = tit->second.GetStart(); + tmr.endTime = tit->second.GetStop(); + strncpy(tmr.strTitle, tit->second.GetName().c_str(), sizeof(tmr.strTitle) - 1); + strncpy(tmr.strEpgSearchString, "", + sizeof(tmr.strEpgSearchString) - 1); // n/a for manual timers + strncpy(tmr.strDirectory, tit->second.GetDirectory().c_str(), sizeof(tmr.strDirectory) - 1); strncpy(tmr.strSummary, "", - sizeof(tmr.strSummary) - 1); // n/a for repeating timers - tmr.state = tit->second.IsEnabled() - ? PVR_TIMER_STATE_SCHEDULED - : PVR_TIMER_STATE_DISABLED; - tmr.iTimerType = TIMER_REPEATING_MANUAL; - tmr.iPriority = tit->second.GetPriority(); - tmr.iLifetime = tit->second.GetLifetime(); - tmr.iMaxRecordings = 0; // not supported by tvh - tmr.iRecordingGroup = 0; // not supported by tvh - tmr.iPreventDuplicateEpisodes = 0; // n/a for manual timers - tmr.firstDay = 0; // not supported by tvh - tmr.iWeekdays = tit->second.GetDaysOfWeek(); - tmr.iEpgUid = PVR_TIMER_NO_EPG_UID; // n/a for manual timers - tmr.iMarginStart = 0; // n/a for manual timers - tmr.iMarginEnd = 0; // n/a for manual timers - tmr.iGenreType = 0; // not supported by tvh? - tmr.iGenreSubType = 0; // not supported by tvh? - tmr.bFullTextEpgSearch = false; // n/a for manual timers + sizeof(tmr.strSummary) - 1); // n/a for repeating timers + tmr.state = tit->second.IsEnabled() ? PVR_TIMER_STATE_SCHEDULED : PVR_TIMER_STATE_DISABLED; + tmr.iTimerType = TIMER_REPEATING_MANUAL; + tmr.iPriority = tit->second.GetPriority(); + tmr.iLifetime = tit->second.GetLifetime(); + tmr.iMaxRecordings = 0; // not supported by tvh + tmr.iRecordingGroup = 0; // not supported by tvh + tmr.iPreventDuplicateEpisodes = 0; // n/a for manual timers + tmr.firstDay = 0; // not supported by tvh + tmr.iWeekdays = tit->second.GetDaysOfWeek(); + tmr.iEpgUid = PVR_TIMER_NO_EPG_UID; // n/a for manual timers + tmr.iMarginStart = 0; // n/a for manual timers + tmr.iMarginEnd = 0; // n/a for manual timers + tmr.iGenreType = 0; // not supported by tvh? + tmr.iGenreSubType = 0; // not supported by tvh? + tmr.bFullTextEpgSearch = false; // n/a for manual timers tmr.iParentClientIndex = 0; timers.emplace_back(tmr); } } -const unsigned int TimeRecordings::GetTimerIntIdFromStringId(const std::string &strId) const +const unsigned int TimeRecordings::GetTimerIntIdFromStringId(const std::string& strId) const { for (auto tit = m_timeRecordings.begin(); tit != m_timeRecordings.end(); ++tit) { if (tit->second.GetStringId() == strId) return tit->second.GetId(); } - Logger::Log(LogLevel::LEVEL_ERROR, "Timerec: Unable to obtain int id for string id %s", strId.c_str()); + Logger::Log(LogLevel::LEVEL_ERROR, "Timerec: Unable to obtain int id for string id %s", + strId.c_str()); return 0; } @@ -119,19 +114,19 @@ const std::string TimeRecordings::GetTimerStringIdFromIntId(unsigned int intId) for (auto tit = m_timeRecordings.begin(); tit != m_timeRecordings.end(); ++tit) { if (tit->second.GetId() == intId) - return tit->second.GetStringId(); + return tit->second.GetStringId(); } Logger::Log(LogLevel::LEVEL_ERROR, "Timerec: Unable to obtain string id for int id %s", intId); return ""; } -PVR_ERROR TimeRecordings::SendTimerecAdd(const PVR_TIMER &timer) +PVR_ERROR TimeRecordings::SendTimerecAdd(const PVR_TIMER& timer) { return SendTimerecAddOrUpdate(timer, false); } -PVR_ERROR TimeRecordings::SendTimerecUpdate(const PVR_TIMER &timer) +PVR_ERROR TimeRecordings::SendTimerecUpdate(const PVR_TIMER& timer) { if (m_conn.GetProtocol() >= 25) return SendTimerecAddOrUpdate(timer, true); @@ -145,13 +140,13 @@ PVR_ERROR TimeRecordings::SendTimerecUpdate(const PVR_TIMER &timer) return error; } -PVR_ERROR TimeRecordings::SendTimerecAddOrUpdate(const PVR_TIMER &timer, bool update) +PVR_ERROR TimeRecordings::SendTimerecAddOrUpdate(const PVR_TIMER& timer, bool update) { uint32_t u32; const std::string method = update ? "updateTimerecEntry" : "addTimerecEntry"; /* Build message */ - htsmsg_t *m = htsmsg_create_map(); + htsmsg_t* m = htsmsg_create_map(); if (update) { @@ -162,36 +157,40 @@ PVR_ERROR TimeRecordings::SendTimerecAddOrUpdate(const PVR_TIMER &timer, bool up return PVR_ERROR_FAILED; } - htsmsg_add_str(m, "id", strId.c_str()); // Autorec DVR Entry ID (string!) + htsmsg_add_str(m, "id", strId.c_str()); // Autorec DVR Entry ID (string!) } - char title[PVR_ADDON_NAME_STRING_LENGTH+6]; - const char *titleExt = "%F-%R"; // timerec title should contain the pattern (e.g. %F-%R) for the generated recording files. Scary... + char title[PVR_ADDON_NAME_STRING_LENGTH + 6]; + const char* titleExt = + "%F-%R"; // timerec title should contain the pattern (e.g. %F-%R) for the generated recording files. Scary... snprintf(title, sizeof(title), "%s-%s", timer.strTitle, titleExt); - htsmsg_add_str(m, "name", timer.strTitle); - htsmsg_add_str(m, "title", title); + htsmsg_add_str(m, "name", timer.strTitle); + htsmsg_add_str(m, "title", title); time_t startTime = timer.startTime; - struct tm *tm_start = localtime(&startTime); - htsmsg_add_u32(m, "start", tm_start->tm_hour * 60 + tm_start->tm_min); // start time in minutes from midnight + struct tm* tm_start = localtime(&startTime); + htsmsg_add_u32(m, "start", + tm_start->tm_hour * 60 + tm_start->tm_min); // start time in minutes from midnight time_t endTime = timer.endTime; - struct tm *tm_stop = localtime(&endTime); - htsmsg_add_u32(m, "stop", tm_stop->tm_hour * 60 + tm_stop->tm_min); // end time in minutes from midnight + struct tm* tm_stop = localtime(&endTime); + htsmsg_add_u32(m, "stop", + tm_stop->tm_hour * 60 + tm_stop->tm_min); // end time in minutes from midnight if (m_conn.GetProtocol() >= 25) { - htsmsg_add_u32(m, "removal", timer.iLifetime); // remove from disk - htsmsg_add_s64(m, "channelId", timer.iClientChannelUid); // channelId is signed for >= htspv25 + htsmsg_add_u32(m, "removal", timer.iLifetime); // remove from disk + htsmsg_add_s64(m, "channelId", timer.iClientChannelUid); // channelId is signed for >= htspv25 } else { - htsmsg_add_u32(m, "retention", LifetimeMapper::KodiToTvh(timer.iLifetime)); // remove from tvh database - htsmsg_add_u32(m, "channelId", timer.iClientChannelUid); // channelId is unsigned for < htspv25 + htsmsg_add_u32(m, "retention", + LifetimeMapper::KodiToTvh(timer.iLifetime)); // remove from tvh database + htsmsg_add_u32(m, "channelId", timer.iClientChannelUid); // channelId is unsigned for < htspv25 } htsmsg_add_u32(m, "daysOfWeek", timer.iWeekdays); - htsmsg_add_u32(m, "priority", timer.iPriority); - htsmsg_add_u32(m, "enabled", timer.state == PVR_TIMER_STATE_DISABLED ? 0 : 1); + htsmsg_add_u32(m, "priority", timer.iPriority); + htsmsg_add_u32(m, "enabled", timer.state == PVR_TIMER_STATE_DISABLED ? 0 : 1); /* Note: As a result of internal filename cleanup, for "directory" == "/", */ /* tvh would put recordings into a folder named "-". Not a big issue */ @@ -219,7 +218,7 @@ PVR_ERROR TimeRecordings::SendTimerecAddOrUpdate(const PVR_TIMER &timer, bool up return u32 == 1 ? PVR_ERROR_NO_ERROR : PVR_ERROR_FAILED; } -PVR_ERROR TimeRecordings::SendTimerecDelete(const PVR_TIMER &timer) +PVR_ERROR TimeRecordings::SendTimerecDelete(const PVR_TIMER& timer) { uint32_t u32; @@ -227,7 +226,7 @@ PVR_ERROR TimeRecordings::SendTimerecDelete(const PVR_TIMER &timer) if (strId.empty()) return PVR_ERROR_FAILED; - htsmsg_t *m = htsmsg_create_map(); + htsmsg_t* m = htsmsg_create_map(); htsmsg_add_str(m, "id", strId.c_str()); // Timerec DVR Entry ID (string!) /* Send and Wait */ @@ -249,21 +248,22 @@ PVR_ERROR TimeRecordings::SendTimerecDelete(const PVR_TIMER &timer) return u32 == 1 ? PVR_ERROR_NO_ERROR : PVR_ERROR_FAILED; } -bool TimeRecordings::ParseTimerecAddOrUpdate(htsmsg_t *msg, bool bAdd) +bool TimeRecordings::ParseTimerecAddOrUpdate(htsmsg_t* msg, bool bAdd) { - const char *str; + const char* str; uint32_t u32; int32_t s32; /* Validate/set mandatory fields */ if ((str = htsmsg_get_str(msg, "id")) == NULL) { - Logger::Log(LogLevel::LEVEL_ERROR, "malformed timerecEntryAdd/timerecEntryUpdate: 'id' missing"); + Logger::Log(LogLevel::LEVEL_ERROR, + "malformed timerecEntryAdd/timerecEntryUpdate: 'id' missing"); return false; } /* Locate/create entry */ - TimeRecording &rec = m_timeRecordings[std::string(str)]; + TimeRecording& rec = m_timeRecordings[std::string(str)]; rec.SetStringId(std::string(str)); rec.SetDirty(false); @@ -386,9 +386,9 @@ bool TimeRecordings::ParseTimerecAddOrUpdate(htsmsg_t *msg, bool bAdd) return true; } -bool TimeRecordings::ParseTimerecDelete(htsmsg_t *msg) +bool TimeRecordings::ParseTimerecDelete(htsmsg_t* msg) { - const char *id; + const char* id; /* Validate/set mandatory fields */ if ((id = htsmsg_get_str(msg, "id")) == NULL) diff --git a/src/tvheadend/TimeRecordings.h b/src/tvheadend/TimeRecordings.h index 495424b2..b1b7d5de 100644 --- a/src/tvheadend/TimeRecordings.h +++ b/src/tvheadend/TimeRecordings.h @@ -25,12 +25,13 @@ extern "C" { -#include #include "libhts/htsmsg.h" + +#include } -#include "kodi/libXBMC_pvr.h" #include "entity/TimeRecording.h" +#include "kodi/libXBMC_pvr.h" namespace tvheadend { @@ -40,7 +41,7 @@ class HTSPConnection; class TimeRecordings { public: - TimeRecordings(HTSPConnection &conn); + TimeRecordings(HTSPConnection& conn); ~TimeRecordings(); /* state updates */ @@ -48,25 +49,25 @@ class TimeRecordings void SyncDvrCompleted(); /* data access */ - int GetTimerecTimerCount() const; - void GetTimerecTimers(std::vector &timers); - const unsigned int GetTimerIntIdFromStringId(const std::string &strId) const; + int GetTimerecTimerCount() const; + void GetTimerecTimers(std::vector& timers); + const unsigned int GetTimerIntIdFromStringId(const std::string& strId) const; /* client to server messages */ - PVR_ERROR SendTimerecAdd (const PVR_TIMER &timer); - PVR_ERROR SendTimerecUpdate(const PVR_TIMER &timer); - PVR_ERROR SendTimerecDelete(const PVR_TIMER &timer); + PVR_ERROR SendTimerecAdd(const PVR_TIMER& timer); + PVR_ERROR SendTimerecUpdate(const PVR_TIMER& timer); + PVR_ERROR SendTimerecDelete(const PVR_TIMER& timer); /* server to client messages */ - bool ParseTimerecAddOrUpdate(htsmsg_t *msg, bool bAdd); - bool ParseTimerecDelete(htsmsg_t *msg); + bool ParseTimerecAddOrUpdate(htsmsg_t* msg, bool bAdd); + bool ParseTimerecDelete(htsmsg_t* msg); private: const std::string GetTimerStringIdFromIntId(unsigned int intId) const; - PVR_ERROR SendTimerecAddOrUpdate(const PVR_TIMER &timer, bool update); + PVR_ERROR SendTimerecAddOrUpdate(const PVR_TIMER& timer, bool update); - HTSPConnection &m_conn; - tvheadend::entity::TimeRecordingsMap m_timeRecordings; + HTSPConnection& m_conn; + tvheadend::entity::TimeRecordingsMap m_timeRecordings; }; } // namespace tvheadend diff --git a/src/tvheadend/entity/AutoRecording.cpp b/src/tvheadend/entity/AutoRecording.cpp index d3deed93..d37cac80 100644 --- a/src/tvheadend/entity/AutoRecording.cpp +++ b/src/tvheadend/entity/AutoRecording.cpp @@ -26,8 +26,8 @@ using namespace tvheadend; using namespace tvheadend::entity; -AutoRecording::AutoRecording(const std::string &id /*= ""*/) : - RecordingBase(id), +AutoRecording::AutoRecording(const std::string& id /*= ""*/) + : RecordingBase(id), m_startWindowBegin(0), m_startWindowEnd(0), m_startExtra(0), @@ -37,19 +37,15 @@ AutoRecording::AutoRecording(const std::string &id /*= ""*/) : { } -bool AutoRecording::operator==(const AutoRecording &right) +bool AutoRecording::operator==(const AutoRecording& right) { - return RecordingBase::operator==(right) && - m_startWindowBegin == right.m_startWindowBegin && - m_startWindowEnd == right.m_startWindowEnd && - m_startExtra == right.m_startExtra && - m_stopExtra == right.m_stopExtra && - m_dupDetect == right.m_dupDetect && - m_fulltext == right.m_fulltext && - m_seriesLink == right.m_seriesLink; + return RecordingBase::operator==(right) && m_startWindowBegin == right.m_startWindowBegin && + m_startWindowEnd == right.m_startWindowEnd && m_startExtra == right.m_startExtra && + m_stopExtra == right.m_stopExtra && m_dupDetect == right.m_dupDetect && + m_fulltext == right.m_fulltext && m_seriesLink == right.m_seriesLink; } -bool AutoRecording::operator!=(const AutoRecording &right) +bool AutoRecording::operator!=(const AutoRecording& right) { return !(*this == right); } @@ -156,7 +152,7 @@ const std::string& AutoRecording::GetSeriesLink() const return m_seriesLink; } -void AutoRecording::SetSeriesLink(const std::string &seriesLink) +void AutoRecording::SetSeriesLink(const std::string& seriesLink) { m_seriesLink = seriesLink; } diff --git a/src/tvheadend/entity/AutoRecording.h b/src/tvheadend/entity/AutoRecording.h index 68d97c6c..a12ed4e5 100644 --- a/src/tvheadend/entity/AutoRecording.h +++ b/src/tvheadend/entity/AutoRecording.h @@ -22,52 +22,53 @@ */ #include "RecordingBase.h" + #include namespace tvheadend { - namespace entity - { - class AutoRecording : public RecordingBase - { - public: - AutoRecording(const std::string &id = ""); +namespace entity +{ +class AutoRecording : public RecordingBase +{ +public: + AutoRecording(const std::string& id = ""); - bool operator==(const AutoRecording &right); - bool operator!=(const AutoRecording &right); + bool operator==(const AutoRecording& right); + bool operator!=(const AutoRecording& right); - time_t GetStart() const; - void SetStartWindowBegin(int32_t begin); + time_t GetStart() const; + void SetStartWindowBegin(int32_t begin); - time_t GetStop() const; - void SetStartWindowEnd(int32_t end); + time_t GetStop() const; + void SetStartWindowEnd(int32_t end); - int64_t GetMarginStart() const; - void SetMarginStart(int64_t startExtra); + int64_t GetMarginStart() const; + void SetMarginStart(int64_t startExtra); - int64_t GetMarginEnd() const; - void SetMarginEnd(int64_t stopExtra); + int64_t GetMarginEnd() const; + void SetMarginEnd(int64_t stopExtra); - uint32_t GetDupDetect() const; - void SetDupDetect(uint32_t dupDetect); + uint32_t GetDupDetect() const; + void SetDupDetect(uint32_t dupDetect); - bool GetFulltext() const; - void SetFulltext(uint32_t fulltext); + bool GetFulltext() const; + void SetFulltext(uint32_t fulltext); - const std::string& GetSeriesLink() const; - void SetSeriesLink(const std::string &seriesLink); + const std::string& GetSeriesLink() const; + void SetSeriesLink(const std::string& seriesLink); - private: - int32_t m_startWindowBegin; // Begin of the starting window (minutes from midnight). - int32_t m_startWindowEnd; // End of the starting window (minutes from midnight). - int64_t m_startExtra; // Extra start minutes (pre-time). - int64_t m_stopExtra; // Extra stop minutes (post-time). - uint32_t m_dupDetect; // duplicate episode detect (numeric values: see dvr_autorec_dedup_t). - uint32_t m_fulltext; // Fulltext epg search. - std::string m_seriesLink; // Series link. - }; +private: + int32_t m_startWindowBegin; // Begin of the starting window (minutes from midnight). + int32_t m_startWindowEnd; // End of the starting window (minutes from midnight). + int64_t m_startExtra; // Extra start minutes (pre-time). + int64_t m_stopExtra; // Extra stop minutes (post-time). + uint32_t m_dupDetect; // duplicate episode detect (numeric values: see dvr_autorec_dedup_t). + uint32_t m_fulltext; // Fulltext epg search. + std::string m_seriesLink; // Series link. +}; - typedef std::map AutoRecordingsMap; - typedef std::pair AutoRecordingMapEntry; - } -} +typedef std::map AutoRecordingsMap; +typedef std::pair AutoRecordingMapEntry; +} // namespace entity +} // namespace tvheadend diff --git a/src/tvheadend/entity/Channel.h b/src/tvheadend/entity/Channel.h index 338c09cc..86015285 100644 --- a/src/tvheadend/entity/Channel.h +++ b/src/tvheadend/entity/Channel.h @@ -21,81 +21,66 @@ * */ +#include "../HTSPTypes.h" +#include "Entity.h" + #include -#include #include -#include "Entity.h" -#include "../HTSPTypes.h" +#include namespace tvheadend { - namespace entity - { +namespace entity +{ - class Channel; - typedef std::pair ChannelMapEntry; - typedef std::map Channels; +class Channel; +typedef std::pair ChannelMapEntry; +typedef std::map Channels; - /** +/** * Represents a channel */ - class Channel : public Entity - { - public: - Channel() : - m_num(0), - m_numMinor(0), - m_type(CHANNEL_TYPE_OTHER), - m_caid(0) - { - } - - bool operator<(const Channel &right) const - { - return m_num < right.m_num; - } - - bool operator==(const Channel &other) const - { - return m_id == other.m_id && - m_num == other.m_num && - m_numMinor == other.m_numMinor && - m_type == other.m_type && - m_caid == other.m_caid && - m_name == other.m_name && - m_icon == other.m_icon; - } - - bool operator!=(const Channel &other) const - { - return !(*this == other); - } - - uint32_t GetNum() const { return m_num; } - void SetNum(uint32_t num) { m_num = num; } - - uint32_t GetNumMinor() const { return m_numMinor; } - void SetNumMinor(uint32_t numMinor) { m_numMinor = numMinor; } - - uint32_t GetType() const { return m_type; } - void SetType(uint32_t type) { m_type = type; } - - uint32_t GetCaid() const { return m_caid; } - void SetCaid(uint32_t caid) { m_caid = caid; } - - const std::string& GetName() const { return m_name; } - void SetName(const std::string &name) { m_name = name; } - - const std::string& GetIcon() const { return m_icon; } - void SetIcon(const std::string &icon) { m_icon = icon; } - - private: - uint32_t m_num; - uint32_t m_numMinor; - uint32_t m_type; - uint32_t m_caid; - std::string m_name; - std::string m_icon; - }; +class Channel : public Entity +{ +public: + Channel() : m_num(0), m_numMinor(0), m_type(CHANNEL_TYPE_OTHER), m_caid(0) {} + + bool operator<(const Channel& right) const { return m_num < right.m_num; } + + bool operator==(const Channel& other) const + { + return m_id == other.m_id && m_num == other.m_num && m_numMinor == other.m_numMinor && + m_type == other.m_type && m_caid == other.m_caid && m_name == other.m_name && + m_icon == other.m_icon; } -} + + bool operator!=(const Channel& other) const { return !(*this == other); } + + uint32_t GetNum() const { return m_num; } + void SetNum(uint32_t num) { m_num = num; } + + uint32_t GetNumMinor() const { return m_numMinor; } + void SetNumMinor(uint32_t numMinor) { m_numMinor = numMinor; } + + uint32_t GetType() const { return m_type; } + void SetType(uint32_t type) { m_type = type; } + + uint32_t GetCaid() const { return m_caid; } + void SetCaid(uint32_t caid) { m_caid = caid; } + + const std::string& GetName() const { return m_name; } + void SetName(const std::string& name) { m_name = name; } + + const std::string& GetIcon() const { return m_icon; } + void SetIcon(const std::string& icon) { m_icon = icon; } + +private: + uint32_t m_num; + uint32_t m_numMinor; + uint32_t m_type; + uint32_t m_caid; + std::string m_name; + std::string m_icon; +}; +} // namespace entity +} // namespace tvheadend diff --git a/src/tvheadend/entity/Entity.h b/src/tvheadend/entity/Entity.h index 7969e298..a9defd22 100644 --- a/src/tvheadend/entity/Entity.h +++ b/src/tvheadend/entity/Entity.h @@ -25,57 +25,45 @@ namespace tvheadend { - namespace entity - { +namespace entity +{ - /** +/** * Abstract entity. An entity can be dirty or clean and has a numeric ID. */ - class Entity - { - public: - Entity() : m_id(0), m_dirty(false) {}; - virtual ~Entity() = default; +class Entity +{ +public: + Entity() : m_id(0), m_dirty(false){}; + virtual ~Entity() = default; - /** + /** * @return if the entity is dirty */ - virtual bool IsDirty() const - { - return m_dirty; - } + virtual bool IsDirty() const { return m_dirty; } - /** + /** * Marks the entity as dirty or not * @param dirty */ - virtual void SetDirty(bool dirty) - { - m_dirty = dirty; - } + virtual void SetDirty(bool dirty) { m_dirty = dirty; } - /** + /** * @return the entity ID */ - uint32_t GetId() const - { - return m_id; - } + uint32_t GetId() const { return m_id; } - /** + /** * Sets the entity ID * @param id */ - void SetId(uint32_t id) - { - m_id = id; - } + void SetId(uint32_t id) { m_id = id; } - protected: - uint32_t m_id; +protected: + uint32_t m_id; - private: - bool m_dirty; - }; - } -} +private: + bool m_dirty; +}; +} // namespace entity +} // namespace tvheadend diff --git a/src/tvheadend/entity/Event.cpp b/src/tvheadend/entity/Event.cpp index db674100..baae363c 100644 --- a/src/tvheadend/entity/Event.cpp +++ b/src/tvheadend/entity/Event.cpp @@ -21,27 +21,27 @@ #include "Event.h" -#include "p8-platform/util/StringUtils.h" #include "kodi/xbmc_epg_types.h" +#include "p8-platform/util/StringUtils.h" using namespace tvheadend::entity; -void Event::SetWriters(const std::vector &writers) +void Event::SetWriters(const std::vector& writers) { m_writers = StringUtils::Join(writers, EPG_STRING_TOKEN_SEPARATOR); } -void Event::SetDirectors(const std::vector &directors) +void Event::SetDirectors(const std::vector& directors) { m_directors = StringUtils::Join(directors, EPG_STRING_TOKEN_SEPARATOR); } -void Event::SetCast(const std::vector &cast) +void Event::SetCast(const std::vector& cast) { m_cast = StringUtils::Join(cast, EPG_STRING_TOKEN_SEPARATOR); } -void Event::SetCategories(const std::vector &categories) +void Event::SetCategories(const std::vector& categories) { m_categories = StringUtils::Join(categories, EPG_STRING_TOKEN_SEPARATOR); } diff --git a/src/tvheadend/entity/Event.h b/src/tvheadend/entity/Event.h index ecf8f839..9b23d9cd 100644 --- a/src/tvheadend/entity/Event.h +++ b/src/tvheadend/entity/Event.h @@ -22,171 +22,155 @@ */ #include "Entity.h" -#include -#include + #include +#include #include +#include namespace tvheadend { - namespace entity - { - class Event; - typedef std::pair EventMapEntry; - typedef std::map Events; +namespace entity +{ +class Event; +typedef std::pair EventMapEntry; +typedef std::map Events; - /** +/** * Represents an event/programme */ - class Event : public Entity - { - public: - Event() : - m_next(0), - m_channel(0), - m_content(0), - m_start(0), - m_stop(0), - m_stars(0), - m_age(0), - m_aired(0), - m_season(0), - m_episode(0), - m_part(0), - m_recordingId(0), - m_year(0) - { - } - - bool operator==(const Event &other) const - { - return m_id == other.m_id && - m_next == other.m_next && - m_channel == other.m_channel && - m_content == other.m_content && - m_start == other.m_start && - m_stop == other.m_stop && - m_stars == other.m_stars && - m_age == other.m_age && - m_aired == other.m_aired && - m_season == other.m_season && - m_episode == other.m_episode && - m_part == other.m_part && - m_title == other.m_title && - m_subtitle == other.m_subtitle && - m_desc == other.m_desc && - m_summary == other.m_summary && - m_image == other.m_image && - m_recordingId == other.m_recordingId && - m_seriesLink == other.m_seriesLink && - m_year == other.m_year && - m_writers == other.m_writers && - m_directors == other.m_directors && - m_cast == other.m_cast && - m_categories == other.m_categories; - } - - bool operator!=(const Event &other) const - { - return !(*this == other); - } - - uint32_t GetNext() const { return m_next; } - void SetNext(uint32_t next) { m_next = next; } - - uint32_t GetChannel() const { return m_channel; } - void SetChannel(uint32_t channel) { m_channel = channel; } - - uint32_t GetContent() const { return m_content; } - void SetContent(uint32_t content) { m_content = content; } - uint32_t GetGenreType() const { return m_content & 0xF0; } - uint32_t GetGenreSubType() const { return m_content & 0x0F; } - - time_t GetStart() const { return m_start; } - void SetStart(time_t start) { m_start = start; } - - time_t GetStop() const { return m_stop; } - void SetStop(time_t stop) { m_stop = stop; } - - uint32_t GetStars() const { return m_stars; } - void SetStars(uint32_t stars) { m_stars = stars; } - - uint32_t GetAge() const { return m_age; } - void SetAge(uint32_t age) { m_age = age; } - - time_t GetAired() const { return m_aired; } - void SetAired(time_t aired) { m_aired = aired; } - - uint32_t GetSeason() const { return m_season; } - void SetSeason(uint32_t season) { m_season = season; } - - uint32_t GetEpisode() const { return m_episode; } - void SetEpisode(uint32_t episode) { m_episode = episode; } - - uint32_t GetPart() const { return m_part; } - void SetPart(uint32_t part) { m_part = part; } - - const std::string& GetTitle() const { return m_title; } - void SetTitle(const std::string &title) { m_title = title; } - - const std::string& GetSubtitle() const { return m_subtitle; } - void SetSubtitle(const std::string &subtitle) { m_subtitle = subtitle; } - - // TODO: Rename to GetDescription to match Recording - const std::string& GetDesc() const { return m_desc; } - void SetDesc(const std::string &desc) { m_desc = desc; } - - const std::string& GetSummary() const { return m_summary; } - void SetSummary(const std::string &summary) { m_summary = summary; } - - const std::string& GetImage() const { return m_image; } - void SetImage(const std::string &image) { m_image = image; } - - uint32_t GetRecordingId() const { return m_recordingId; } - void SetRecordingId(uint32_t recordingId) { m_recordingId = recordingId; } - - const std::string& GetSeriesLink() const { return m_seriesLink; } - void SetSeriesLink(const std::string &seriesLink) { m_seriesLink = seriesLink; } - - uint32_t GetYear() const { return m_year; } - void SetYear(uint32_t year) { m_year = year; } - - const std::string& GetWriters() const { return m_writers; } - void SetWriters(const std::vector &writers); - - const std::string& GetDirectors() const { return m_directors; } - void SetDirectors(const std::vector &directors); - - const std::string& GetCast() const { return m_cast; } - void SetCast(const std::vector &cast); - - const std::string& GetCategories() const { return m_categories; } - void SetCategories(const std::vector &categories); - - private: - uint32_t m_next; - uint32_t m_channel; - uint32_t m_content; - time_t m_start; - time_t m_stop; - uint32_t m_stars; /* 1 - 5 */ - uint32_t m_age; /* years */ - time_t m_aired; - uint32_t m_season; - uint32_t m_episode; - uint32_t m_part; - std::string m_title; - std::string m_subtitle; /* episode name */ - std::string m_desc; - std::string m_summary; - std::string m_image; - uint32_t m_recordingId; - std::string m_seriesLink; - uint32_t m_year; - std::string m_writers; - std::string m_directors; - std::string m_cast; - std::string m_categories; - }; +class Event : public Entity +{ +public: + Event() + : m_next(0), + m_channel(0), + m_content(0), + m_start(0), + m_stop(0), + m_stars(0), + m_age(0), + m_aired(0), + m_season(0), + m_episode(0), + m_part(0), + m_recordingId(0), + m_year(0) + { } -} + + bool operator==(const Event& other) const + { + return m_id == other.m_id && m_next == other.m_next && m_channel == other.m_channel && + m_content == other.m_content && m_start == other.m_start && m_stop == other.m_stop && + m_stars == other.m_stars && m_age == other.m_age && m_aired == other.m_aired && + m_season == other.m_season && m_episode == other.m_episode && m_part == other.m_part && + m_title == other.m_title && m_subtitle == other.m_subtitle && m_desc == other.m_desc && + m_summary == other.m_summary && m_image == other.m_image && + m_recordingId == other.m_recordingId && m_seriesLink == other.m_seriesLink && + m_year == other.m_year && m_writers == other.m_writers && + m_directors == other.m_directors && m_cast == other.m_cast && + m_categories == other.m_categories; + } + + bool operator!=(const Event& other) const { return !(*this == other); } + + uint32_t GetNext() const { return m_next; } + void SetNext(uint32_t next) { m_next = next; } + + uint32_t GetChannel() const { return m_channel; } + void SetChannel(uint32_t channel) { m_channel = channel; } + + uint32_t GetContent() const { return m_content; } + void SetContent(uint32_t content) { m_content = content; } + uint32_t GetGenreType() const { return m_content & 0xF0; } + uint32_t GetGenreSubType() const { return m_content & 0x0F; } + + time_t GetStart() const { return m_start; } + void SetStart(time_t start) { m_start = start; } + + time_t GetStop() const { return m_stop; } + void SetStop(time_t stop) { m_stop = stop; } + + uint32_t GetStars() const { return m_stars; } + void SetStars(uint32_t stars) { m_stars = stars; } + + uint32_t GetAge() const { return m_age; } + void SetAge(uint32_t age) { m_age = age; } + + time_t GetAired() const { return m_aired; } + void SetAired(time_t aired) { m_aired = aired; } + + uint32_t GetSeason() const { return m_season; } + void SetSeason(uint32_t season) { m_season = season; } + + uint32_t GetEpisode() const { return m_episode; } + void SetEpisode(uint32_t episode) { m_episode = episode; } + + uint32_t GetPart() const { return m_part; } + void SetPart(uint32_t part) { m_part = part; } + + const std::string& GetTitle() const { return m_title; } + void SetTitle(const std::string& title) { m_title = title; } + + const std::string& GetSubtitle() const { return m_subtitle; } + void SetSubtitle(const std::string& subtitle) { m_subtitle = subtitle; } + + // TODO: Rename to GetDescription to match Recording + const std::string& GetDesc() const { return m_desc; } + void SetDesc(const std::string& desc) { m_desc = desc; } + + const std::string& GetSummary() const { return m_summary; } + void SetSummary(const std::string& summary) { m_summary = summary; } + + const std::string& GetImage() const { return m_image; } + void SetImage(const std::string& image) { m_image = image; } + + uint32_t GetRecordingId() const { return m_recordingId; } + void SetRecordingId(uint32_t recordingId) { m_recordingId = recordingId; } + + const std::string& GetSeriesLink() const { return m_seriesLink; } + void SetSeriesLink(const std::string& seriesLink) { m_seriesLink = seriesLink; } + + uint32_t GetYear() const { return m_year; } + void SetYear(uint32_t year) { m_year = year; } + + const std::string& GetWriters() const { return m_writers; } + void SetWriters(const std::vector& writers); + + const std::string& GetDirectors() const { return m_directors; } + void SetDirectors(const std::vector& directors); + + const std::string& GetCast() const { return m_cast; } + void SetCast(const std::vector& cast); + + const std::string& GetCategories() const { return m_categories; } + void SetCategories(const std::vector& categories); + +private: + uint32_t m_next; + uint32_t m_channel; + uint32_t m_content; + time_t m_start; + time_t m_stop; + uint32_t m_stars; /* 1 - 5 */ + uint32_t m_age; /* years */ + time_t m_aired; + uint32_t m_season; + uint32_t m_episode; + uint32_t m_part; + std::string m_title; + std::string m_subtitle; /* episode name */ + std::string m_desc; + std::string m_summary; + std::string m_image; + uint32_t m_recordingId; + std::string m_seriesLink; + uint32_t m_year; + std::string m_writers; + std::string m_directors; + std::string m_cast; + std::string m_categories; +}; +} // namespace entity +} // namespace tvheadend diff --git a/src/tvheadend/entity/Recording.h b/src/tvheadend/entity/Recording.h index a5a9960c..7242f3bd 100644 --- a/src/tvheadend/entity/Recording.h +++ b/src/tvheadend/entity/Recording.h @@ -21,255 +21,234 @@ * */ +#include "../utilities/LifetimeMapper.h" +#include "Entity.h" +#include "kodi/xbmc_pvr_types.h" + #include #include #include -#include "kodi/xbmc_pvr_types.h" -#include "Entity.h" -#include "../utilities/LifetimeMapper.h" // Timer types -#define TIMER_ONCE_MANUAL (PVR_TIMER_TYPE_NONE + 1) -#define TIMER_ONCE_EPG (PVR_TIMER_TYPE_NONE + 2) +#define TIMER_ONCE_MANUAL (PVR_TIMER_TYPE_NONE + 1) +#define TIMER_ONCE_EPG (PVR_TIMER_TYPE_NONE + 2) #define TIMER_ONCE_CREATED_BY_TIMEREC (PVR_TIMER_TYPE_NONE + 3) #define TIMER_ONCE_CREATED_BY_AUTOREC (PVR_TIMER_TYPE_NONE + 4) -#define TIMER_REPEATING_MANUAL (PVR_TIMER_TYPE_NONE + 5) -#define TIMER_REPEATING_EPG (PVR_TIMER_TYPE_NONE + 6) -#define TIMER_REPEATING_SERIESLINK (PVR_TIMER_TYPE_NONE + 7) +#define TIMER_REPEATING_MANUAL (PVR_TIMER_TYPE_NONE + 5) +#define TIMER_REPEATING_EPG (PVR_TIMER_TYPE_NONE + 6) +#define TIMER_REPEATING_SERIESLINK (PVR_TIMER_TYPE_NONE + 7) namespace tvheadend { - namespace entity - { +namespace entity +{ - class Recording; - typedef std::pair RecordingMapEntry; - typedef std::map Recordings; +class Recording; +typedef std::pair RecordingMapEntry; +typedef std::map Recordings; - /** +/** * Represents a recording or a timer * TODO: Create separate classes for recordings and timers since a * recording obviously can't have a "timer type" */ - class Recording : public Entity - { - public: - Recording() : - m_enabled(0), - m_channel(0), - m_channelType(0), - m_eventId(0), - m_start(0), - m_stop(0), - m_startExtra(0), - m_stopExtra(0), - m_filesStart(0), - m_filesStop(0), - m_state(PVR_TIMER_STATE_ERROR), - m_lifetime(0), - m_priority(50), // Kodi default - "normal" - m_playCount(0), - m_playPosition(0), - m_contentType(0), - m_season(0), - m_episode(0), - m_part(0) - { - } - - bool operator==(const Recording &other) const - { - return m_id == other.m_id && - m_enabled == other.m_enabled && - m_channel == other.m_channel && - m_channelType == other.m_channelType && - m_channelName == other.m_channelName && - m_eventId == other.m_eventId && - m_start == other.m_start && - m_stop == other.m_stop && - m_startExtra == other.m_startExtra && - m_stopExtra == other.m_stopExtra && - m_filesStart == other.m_filesStart && - m_filesStop == other.m_filesStop && - m_title == other.m_title && - m_path == other.m_path && - m_description == other.m_description && - m_image == other.m_image && - m_fanartImage == other.m_fanartImage && - m_timerecId == other.m_timerecId && - m_autorecId == other.m_autorecId && - m_state == other.m_state && - m_error == other.m_error && - m_lifetime == other.m_lifetime && - m_priority == other.m_priority && - m_playCount == other.m_playCount && - m_playPosition == other.m_playPosition && - m_contentType == other.m_contentType && - m_season == other.m_season && - m_episode == other.m_episode && - m_part == other.m_part; - } - - bool operator!=(const Recording &other) const - { - return !(*this == other); - } - - bool IsRecording() const - { - return m_state == PVR_TIMER_STATE_COMPLETED || - m_state == PVR_TIMER_STATE_ABORTED || - m_state == PVR_TIMER_STATE_RECORDING || - m_state == PVR_TIMER_STATE_CONFLICT_NOK; - } - - bool IsTimer() const - { - return m_state == PVR_TIMER_STATE_SCHEDULED || - m_state == PVR_TIMER_STATE_RECORDING || - m_state == PVR_TIMER_STATE_CONFLICT_NOK; - } - - /** +class Recording : public Entity +{ +public: + Recording() + : m_enabled(0), + m_channel(0), + m_channelType(0), + m_eventId(0), + m_start(0), + m_stop(0), + m_startExtra(0), + m_stopExtra(0), + m_filesStart(0), + m_filesStop(0), + m_state(PVR_TIMER_STATE_ERROR), + m_lifetime(0), + m_priority(50), // Kodi default - "normal" + m_playCount(0), + m_playPosition(0), + m_contentType(0), + m_season(0), + m_episode(0), + m_part(0) + { + } + + bool operator==(const Recording& other) const + { + return m_id == other.m_id && m_enabled == other.m_enabled && m_channel == other.m_channel && + m_channelType == other.m_channelType && m_channelName == other.m_channelName && + m_eventId == other.m_eventId && m_start == other.m_start && m_stop == other.m_stop && + m_startExtra == other.m_startExtra && m_stopExtra == other.m_stopExtra && + m_filesStart == other.m_filesStart && m_filesStop == other.m_filesStop && + m_title == other.m_title && m_path == other.m_path && + m_description == other.m_description && m_image == other.m_image && + m_fanartImage == other.m_fanartImage && m_timerecId == other.m_timerecId && + m_autorecId == other.m_autorecId && m_state == other.m_state && + m_error == other.m_error && m_lifetime == other.m_lifetime && + m_priority == other.m_priority && m_playCount == other.m_playCount && + m_playPosition == other.m_playPosition && m_contentType == other.m_contentType && + m_season == other.m_season && m_episode == other.m_episode && m_part == other.m_part; + } + + bool operator!=(const Recording& other) const { return !(*this == other); } + + bool IsRecording() const + { + return m_state == PVR_TIMER_STATE_COMPLETED || m_state == PVR_TIMER_STATE_ABORTED || + m_state == PVR_TIMER_STATE_RECORDING || m_state == PVR_TIMER_STATE_CONFLICT_NOK; + } + + bool IsTimer() const + { + return m_state == PVR_TIMER_STATE_SCHEDULED || m_state == PVR_TIMER_STATE_RECORDING || + m_state == PVR_TIMER_STATE_CONFLICT_NOK; + } + + /** * @return the type of timer */ - unsigned int GetTimerType() const - { - if (!m_timerecId.empty()) - return TIMER_ONCE_CREATED_BY_TIMEREC; - else if (!m_autorecId.empty()) - return TIMER_ONCE_CREATED_BY_AUTOREC; - else if (m_eventId != 0) - return TIMER_ONCE_EPG; - else - return TIMER_ONCE_MANUAL; - } + unsigned int GetTimerType() const + { + if (!m_timerecId.empty()) + return TIMER_ONCE_CREATED_BY_TIMEREC; + else if (!m_autorecId.empty()) + return TIMER_ONCE_CREATED_BY_AUTOREC; + else if (m_eventId != 0) + return TIMER_ONCE_EPG; + else + return TIMER_ONCE_MANUAL; + } - bool IsEnabled() const { return m_enabled > 0; } - void SetEnabled(uint32_t enabled) { m_enabled = enabled; } + bool IsEnabled() const { return m_enabled > 0; } + void SetEnabled(uint32_t enabled) { m_enabled = enabled; } - uint32_t GetChannel() const { return m_channel; } - void SetChannel(uint32_t channel) { m_channel = channel; } + uint32_t GetChannel() const { return m_channel; } + void SetChannel(uint32_t channel) { m_channel = channel; } - uint32_t GetChannelType() const { return m_channelType; } - void SetChannelType(uint32_t channelType) { m_channelType = channelType; } + uint32_t GetChannelType() const { return m_channelType; } + void SetChannelType(uint32_t channelType) { m_channelType = channelType; } - const std::string& GetChannelName() const { return m_channelName; } - void SetChannelName(const std::string &channelName) { m_channelName = channelName; } - - uint32_t GetEventId() const { return m_eventId; } - void SetEventId(uint32_t eventId) { m_eventId = eventId; } - - // TODO: Change to time_t - int64_t GetStart() const { return m_start; } - void SetStart(int64_t start) { m_start = start; } - - // TODO: Change to time_t - int64_t GetStop() const { return m_stop; } - void SetStop(int64_t stop) { m_stop = stop; } - - // TODO: Change to time_t - int64_t GetStartExtra() const { return m_startExtra; } - void SetStartExtra(int64_t startExtra) { m_startExtra = startExtra; } - - // TODO: Change to time_t - int64_t GetStopExtra() const { return m_stopExtra; } - void SetStopExtra(int64_t stopExtra) { m_stopExtra = stopExtra; } - - int64_t GetFilesStart() const { return m_filesStart; } - void SetFilesStart(int64_t start) { m_filesStart = start; } - - int64_t GetFilesStop() const { return m_filesStop; } - void SetFilesStop(int64_t stop) { m_filesStop = stop; } - - const std::string& GetTitle() const { return m_title; } - void SetTitle(const std::string &title) { m_title = title; } - - const std::string& GetSubtitle() const { return m_subtitle; } - void SetSubtitle(const std::string &subtitle) { m_subtitle = subtitle; } - - const std::string& GetPath() const { return m_path; } - void SetPath(const std::string &path) { m_path = path; } - - const std::string& GetDescription() const { return m_description; } - void SetDescription(const std::string &description) { m_description = description; } - - const std::string& GetImage() const { return m_image; } - void SetImage(const std::string &image) { m_image = image; } - - const std::string& GetFanartImage() const { return m_fanartImage; } - void SetFanartImage(const std::string &image) { m_fanartImage = image; } - - const std::string& GetTimerecId() const { return m_timerecId; } - void SetTimerecId(const std::string &autorecId) { m_timerecId = autorecId; } - - const std::string& GetAutorecId() const { return m_autorecId; } - void SetAutorecId(const std::string &title) { m_autorecId = title; } - - PVR_TIMER_STATE GetState() const { return m_state; } - void SetState(const PVR_TIMER_STATE &state) { m_state = state; } - - const std::string& GetError() const { return m_error; } - void SetError(const std::string &error) { m_error = error; } - - int GetLifetime() const { return utilities::LifetimeMapper::TvhToKodi(m_lifetime); } - void SetLifetime(uint32_t lifetime) { m_lifetime = lifetime; } - - uint32_t GetPriority() const { return m_priority; } - void SetPriority(uint32_t priority) { m_priority = priority; } - - uint32_t GetPlayCount() const { return m_playCount; } - void SetPlayCount(uint32_t playCount) { m_playCount = playCount; } - - uint32_t GetPlayPosition() const { return m_playPosition; } - void SetPlayPosition(uint32_t playPosition) { m_playPosition = playPosition; } - - void SetContentType(uint32_t content) { m_contentType = content; } - uint32_t GetContentType() const { return m_contentType; } - // tvh returns only the major DVB category for recordings in the - // bottom four bits and no sub-category - uint32_t GetGenreType() const { return m_contentType * 0x10; } - uint32_t GetGenreSubType() const { return 0; } - - uint32_t GetSeason() const { return m_season; } - void SetSeason(uint32_t season) { m_season = season; } - - uint32_t GetEpisode() const { return m_episode; } - void SetEpisode(uint32_t episode) { m_episode = episode; } - - uint32_t GetPart() const { return m_part; } - void SetPart(uint32_t part) { m_part = part; } - - private: - uint32_t m_enabled; - uint32_t m_channel; - uint32_t m_channelType; - std::string m_channelName; - uint32_t m_eventId; - int64_t m_start; - int64_t m_stop; - int64_t m_startExtra; - int64_t m_stopExtra; - int64_t m_filesStart; - int64_t m_filesStop; - std::string m_title; - std::string m_subtitle; - std::string m_path; - std::string m_description; - std::string m_image; - std::string m_fanartImage; - std::string m_timerecId; - std::string m_autorecId; - PVR_TIMER_STATE m_state; - std::string m_error; - uint32_t m_lifetime; - uint32_t m_priority; - uint32_t m_playCount; - uint32_t m_playPosition; - uint32_t m_contentType; - uint32_t m_season; - uint32_t m_episode; - uint32_t m_part; - }; - } -} + const std::string& GetChannelName() const { return m_channelName; } + void SetChannelName(const std::string& channelName) { m_channelName = channelName; } + + uint32_t GetEventId() const { return m_eventId; } + void SetEventId(uint32_t eventId) { m_eventId = eventId; } + + // TODO: Change to time_t + int64_t GetStart() const { return m_start; } + void SetStart(int64_t start) { m_start = start; } + + // TODO: Change to time_t + int64_t GetStop() const { return m_stop; } + void SetStop(int64_t stop) { m_stop = stop; } + + // TODO: Change to time_t + int64_t GetStartExtra() const { return m_startExtra; } + void SetStartExtra(int64_t startExtra) { m_startExtra = startExtra; } + + // TODO: Change to time_t + int64_t GetStopExtra() const { return m_stopExtra; } + void SetStopExtra(int64_t stopExtra) { m_stopExtra = stopExtra; } + + int64_t GetFilesStart() const { return m_filesStart; } + void SetFilesStart(int64_t start) { m_filesStart = start; } + + int64_t GetFilesStop() const { return m_filesStop; } + void SetFilesStop(int64_t stop) { m_filesStop = stop; } + + const std::string& GetTitle() const { return m_title; } + void SetTitle(const std::string& title) { m_title = title; } + + const std::string& GetSubtitle() const { return m_subtitle; } + void SetSubtitle(const std::string& subtitle) { m_subtitle = subtitle; } + + const std::string& GetPath() const { return m_path; } + void SetPath(const std::string& path) { m_path = path; } + + const std::string& GetDescription() const { return m_description; } + void SetDescription(const std::string& description) { m_description = description; } + + const std::string& GetImage() const { return m_image; } + void SetImage(const std::string& image) { m_image = image; } + + const std::string& GetFanartImage() const { return m_fanartImage; } + void SetFanartImage(const std::string& image) { m_fanartImage = image; } + + const std::string& GetTimerecId() const { return m_timerecId; } + void SetTimerecId(const std::string& autorecId) { m_timerecId = autorecId; } + + const std::string& GetAutorecId() const { return m_autorecId; } + void SetAutorecId(const std::string& title) { m_autorecId = title; } + + PVR_TIMER_STATE GetState() const { return m_state; } + void SetState(const PVR_TIMER_STATE& state) { m_state = state; } + + const std::string& GetError() const { return m_error; } + void SetError(const std::string& error) { m_error = error; } + + int GetLifetime() const { return utilities::LifetimeMapper::TvhToKodi(m_lifetime); } + void SetLifetime(uint32_t lifetime) { m_lifetime = lifetime; } + + uint32_t GetPriority() const { return m_priority; } + void SetPriority(uint32_t priority) { m_priority = priority; } + + uint32_t GetPlayCount() const { return m_playCount; } + void SetPlayCount(uint32_t playCount) { m_playCount = playCount; } + + uint32_t GetPlayPosition() const { return m_playPosition; } + void SetPlayPosition(uint32_t playPosition) { m_playPosition = playPosition; } + + void SetContentType(uint32_t content) { m_contentType = content; } + uint32_t GetContentType() const { return m_contentType; } + // tvh returns only the major DVB category for recordings in the + // bottom four bits and no sub-category + uint32_t GetGenreType() const { return m_contentType * 0x10; } + uint32_t GetGenreSubType() const { return 0; } + + uint32_t GetSeason() const { return m_season; } + void SetSeason(uint32_t season) { m_season = season; } + + uint32_t GetEpisode() const { return m_episode; } + void SetEpisode(uint32_t episode) { m_episode = episode; } + + uint32_t GetPart() const { return m_part; } + void SetPart(uint32_t part) { m_part = part; } + +private: + uint32_t m_enabled; + uint32_t m_channel; + uint32_t m_channelType; + std::string m_channelName; + uint32_t m_eventId; + int64_t m_start; + int64_t m_stop; + int64_t m_startExtra; + int64_t m_stopExtra; + int64_t m_filesStart; + int64_t m_filesStop; + std::string m_title; + std::string m_subtitle; + std::string m_path; + std::string m_description; + std::string m_image; + std::string m_fanartImage; + std::string m_timerecId; + std::string m_autorecId; + PVR_TIMER_STATE m_state; + std::string m_error; + uint32_t m_lifetime; + uint32_t m_priority; + uint32_t m_playCount; + uint32_t m_playPosition; + uint32_t m_contentType; + uint32_t m_season; + uint32_t m_episode; + uint32_t m_part; +}; +} // namespace entity +} // namespace tvheadend diff --git a/src/tvheadend/entity/RecordingBase.cpp b/src/tvheadend/entity/RecordingBase.cpp index 561e9198..bd08e66e 100644 --- a/src/tvheadend/entity/RecordingBase.cpp +++ b/src/tvheadend/entity/RecordingBase.cpp @@ -19,41 +19,29 @@ * */ -#include - #include "RecordingBase.h" #include "../utilities/LifetimeMapper.h" +#include + using namespace tvheadend::entity; -RecordingBase::RecordingBase(const std::string &id /*= ""*/) : - m_sid(id), - m_enabled(0), - m_daysOfWeek(0), - m_lifetime(0), - m_priority(0), - m_channel(0) +RecordingBase::RecordingBase(const std::string& id /*= ""*/) + : m_sid(id), m_enabled(0), m_daysOfWeek(0), m_lifetime(0), m_priority(0), m_channel(0) { m_id = GetNextIntId(); } -bool RecordingBase::operator==(const RecordingBase &right) +bool RecordingBase::operator==(const RecordingBase& right) { - return m_id == right.m_id && - m_enabled == right.m_enabled && - m_daysOfWeek == right.m_daysOfWeek && - m_lifetime == right.m_lifetime && - m_priority == right.m_priority && - m_title == right.m_title && - m_name == right.m_name && - m_directory == right.m_directory && - m_owner == right.m_owner && - m_creator == right.m_creator && - m_channel == right.m_channel; + return m_id == right.m_id && m_enabled == right.m_enabled && m_daysOfWeek == right.m_daysOfWeek && + m_lifetime == right.m_lifetime && m_priority == right.m_priority && + m_title == right.m_title && m_name == right.m_name && m_directory == right.m_directory && + m_owner == right.m_owner && m_creator == right.m_creator && m_channel == right.m_channel; } -bool RecordingBase::operator!=(const RecordingBase &right) +bool RecordingBase::operator!=(const RecordingBase& right) { return !(*this == right); } @@ -63,7 +51,7 @@ std::string RecordingBase::GetStringId() const return m_sid; } -void RecordingBase::SetStringId(const std::string &id) +void RecordingBase::SetStringId(const std::string& id) { m_sid = id; } @@ -113,7 +101,7 @@ const std::string& RecordingBase::GetTitle() const return m_title; } -void RecordingBase::SetTitle(const std::string &title) +void RecordingBase::SetTitle(const std::string& title) { m_title = title; } @@ -123,7 +111,7 @@ const std::string& RecordingBase::GetName() const return m_name; } -void RecordingBase::SetName(const std::string &name) +void RecordingBase::SetName(const std::string& name) { m_name = name; } @@ -133,17 +121,17 @@ const std::string& RecordingBase::GetDirectory() const return m_directory; } -void RecordingBase::SetDirectory(const std::string &directory) +void RecordingBase::SetDirectory(const std::string& directory) { m_directory = directory; } -void RecordingBase::SetOwner(const std::string &owner) +void RecordingBase::SetOwner(const std::string& owner) { m_owner = owner; } -void RecordingBase::SetCreator(const std::string &creator) +void RecordingBase::SetCreator(const std::string& creator) { m_creator = creator; } @@ -165,11 +153,11 @@ time_t RecordingBase::LocaltimeToUTC(int32_t lctime) /* complete lctime with current year, month, day, ... */ time_t t = time(NULL); - struct tm *tm_time = localtime(&t); + struct tm* tm_time = localtime(&t); - tm_time->tm_hour = lctime / 60; - tm_time->tm_min = lctime % 60; - tm_time->tm_sec = 0; + tm_time->tm_hour = lctime / 60; + tm_time->tm_min = lctime % 60; + tm_time->tm_sec = 0; return mktime(tm_time); } diff --git a/src/tvheadend/entity/RecordingBase.h b/src/tvheadend/entity/RecordingBase.h index f5604a70..f05aab3e 100644 --- a/src/tvheadend/entity/RecordingBase.h +++ b/src/tvheadend/entity/RecordingBase.h @@ -22,69 +22,71 @@ */ #include "Entity.h" -#include + #include #include +#include namespace tvheadend { - namespace entity - { - class RecordingBase : public Entity - { - protected: - RecordingBase(const std::string &id = ""); - bool operator==(const RecordingBase &right); - bool operator!=(const RecordingBase &right); - - public: - std::string GetStringId() const; - void SetStringId(const std::string &id); - - bool IsEnabled() const; - void SetEnabled(uint32_t enabled); - - int GetDaysOfWeek() const; - void SetDaysOfWeek(uint32_t daysOfWeek); - - int GetLifetime() const; - void SetLifetime(uint32_t retention); - - uint32_t GetPriority() const; - void SetPriority(uint32_t priority); - - const std::string &GetTitle() const; - void SetTitle(const std::string &title); - - const std::string &GetName() const; - void SetName(const std::string &name); - - const std::string &GetDirectory() const; - void SetDirectory(const std::string &directory); - - void SetOwner(const std::string &owner); - void SetCreator(const std::string &creator); - - uint32_t GetChannel() const; - void SetChannel(uint32_t channel); - - protected: - static time_t LocaltimeToUTC(int32_t lctime); - - private: - static unsigned int GetNextIntId(); - - std::string m_sid; // ID (string!) of dvr[Time|Auto]recEntry. - uint32_t m_enabled; // If [time|auto]rec entry is enabled (activated). - uint32_t m_daysOfWeek; // Bitmask - Days of week (0x01 = Monday, 0x40 = Sunday, 0x7f = Whole Week, 0 = Not set). - uint32_t m_lifetime; // Lifetime (in days). - uint32_t m_priority; // Priority (0 = Important, 1 = High, 2 = Normal, 3 = Low, 4 = Unimportant). - std::string m_title; // Title (pattern) for the recording files. - std::string m_name; // Name. - std::string m_directory; // Directory for the recording files. - std::string m_owner; // Owner. - std::string m_creator; // Creator. - uint32_t m_channel; // Channel ID. - }; - } -} +namespace entity +{ +class RecordingBase : public Entity +{ +protected: + RecordingBase(const std::string& id = ""); + bool operator==(const RecordingBase& right); + bool operator!=(const RecordingBase& right); + +public: + std::string GetStringId() const; + void SetStringId(const std::string& id); + + bool IsEnabled() const; + void SetEnabled(uint32_t enabled); + + int GetDaysOfWeek() const; + void SetDaysOfWeek(uint32_t daysOfWeek); + + int GetLifetime() const; + void SetLifetime(uint32_t retention); + + uint32_t GetPriority() const; + void SetPriority(uint32_t priority); + + const std::string& GetTitle() const; + void SetTitle(const std::string& title); + + const std::string& GetName() const; + void SetName(const std::string& name); + + const std::string& GetDirectory() const; + void SetDirectory(const std::string& directory); + + void SetOwner(const std::string& owner); + void SetCreator(const std::string& creator); + + uint32_t GetChannel() const; + void SetChannel(uint32_t channel); + +protected: + static time_t LocaltimeToUTC(int32_t lctime); + +private: + static unsigned int GetNextIntId(); + + std::string m_sid; // ID (string!) of dvr[Time|Auto]recEntry. + uint32_t m_enabled; // If [time|auto]rec entry is enabled (activated). + uint32_t + m_daysOfWeek; // Bitmask - Days of week (0x01 = Monday, 0x40 = Sunday, 0x7f = Whole Week, 0 = Not set). + uint32_t m_lifetime; // Lifetime (in days). + uint32_t m_priority; // Priority (0 = Important, 1 = High, 2 = Normal, 3 = Low, 4 = Unimportant). + std::string m_title; // Title (pattern) for the recording files. + std::string m_name; // Name. + std::string m_directory; // Directory for the recording files. + std::string m_owner; // Owner. + std::string m_creator; // Creator. + uint32_t m_channel; // Channel ID. +}; +} // namespace entity +} // namespace tvheadend diff --git a/src/tvheadend/entity/Schedule.cpp b/src/tvheadend/entity/Schedule.cpp index 410068b4..500f41e6 100644 --- a/src/tvheadend/entity/Schedule.cpp +++ b/src/tvheadend/entity/Schedule.cpp @@ -30,7 +30,7 @@ void Schedule::SetDirty(bool dirty) if (dirty) { // Mark all events as dirty too - for (auto &entry : m_events) + for (auto& entry : m_events) entry.second.SetDirty(dirty); } } diff --git a/src/tvheadend/entity/Schedule.h b/src/tvheadend/entity/Schedule.h index b0023b80..5a10bda0 100644 --- a/src/tvheadend/entity/Schedule.h +++ b/src/tvheadend/entity/Schedule.h @@ -21,42 +21,43 @@ * */ +#include "Entity.h" + #include #include -#include "Entity.h" namespace tvheadend { - namespace entity - { - class Schedule; - typedef std::pair ScheduleMapEntry; - typedef std::map Schedules; +namespace entity +{ +class Schedule; +typedef std::pair ScheduleMapEntry; +typedef std::map Schedules; - typedef std::pair EventUidsMapEntry; - typedef std::map EventUids; +typedef std::pair EventUidsMapEntry; +typedef std::map EventUids; - /** +/** * Represents a schedule. A schedule has a channel and a bunch of events. * The schedule ID matches the channel it belongs to. */ - class Schedule : public Entity - { - public: - virtual void SetDirty(bool dirty); +class Schedule : public Entity +{ +public: + virtual void SetDirty(bool dirty); - /** + /** * @return read-write reference to the events in this schedule */ - EventUids& GetEvents(); + EventUids& GetEvents(); - /** + /** * @return read-only reference to the events in this schedule */ - const EventUids& GetEvents() const; + const EventUids& GetEvents() const; - private: - EventUids m_events; // event uids - }; - } -} +private: + EventUids m_events; // event uids +}; +} // namespace entity +} // namespace tvheadend diff --git a/src/tvheadend/entity/Tag.cpp b/src/tvheadend/entity/Tag.cpp index 0ad609f2..244073f6 100644 --- a/src/tvheadend/entity/Tag.cpp +++ b/src/tvheadend/entity/Tag.cpp @@ -24,21 +24,17 @@ using namespace tvheadend; using namespace tvheadend::entity; -Tag::Tag() : -m_index(0) +Tag::Tag() : m_index(0) { } -bool Tag::operator==(const Tag &right) +bool Tag::operator==(const Tag& right) { - return m_id == right.m_id && - m_index == right.m_index && - m_name == right.m_name && - m_icon == right.m_icon && - m_channels == right.m_channels; + return m_id == right.m_id && m_index == right.m_index && m_name == right.m_name && + m_icon == right.m_icon && m_channels == right.m_channels; } -bool Tag::operator!=(const Tag &right) +bool Tag::operator!=(const Tag& right) { return !(*this == right); } diff --git a/src/tvheadend/entity/Tag.h b/src/tvheadend/entity/Tag.h index f8415ba1..deebd0b1 100644 --- a/src/tvheadend/entity/Tag.h +++ b/src/tvheadend/entity/Tag.h @@ -21,52 +21,52 @@ * */ +#include "../HTSPTypes.h" +#include "Channel.h" +#include "Entity.h" + #include -#include #include +#include #include -#include "Entity.h" -#include "../HTSPTypes.h" -#include "Channel.h" namespace tvheadend { - namespace entity - { - class Tag; - typedef std::pair TagMapEntry; - typedef std::map Tags; +namespace entity +{ +class Tag; +typedef std::pair TagMapEntry; +typedef std::map Tags; - /** +/** * Represents a channel tag */ - class Tag : public Entity - { - public: - Tag(); - - bool operator==(const Tag &right); - bool operator!=(const Tag &right); +class Tag : public Entity +{ +public: + Tag(); - uint32_t GetIndex() const; - void SetIndex(uint32_t index); + bool operator==(const Tag& right); + bool operator!=(const Tag& right); - const std::string& GetName() const; - void SetName(const std::string& name); + uint32_t GetIndex() const; + void SetIndex(uint32_t index); - void SetIcon(const std::string& icon); + const std::string& GetName() const; + void SetName(const std::string& name); - const std::vector& GetChannels() const; - std::vector& GetChannels(); + void SetIcon(const std::string& icon); - bool ContainsChannelType(channel_type_t eType, const Channels& channels) const; + const std::vector& GetChannels() const; + std::vector& GetChannels(); - private: - uint32_t m_index; - std::string m_name; - std::string m_icon; - std::vector m_channels; - }; - } -} + bool ContainsChannelType(channel_type_t eType, const Channels& channels) const; +private: + uint32_t m_index; + std::string m_name; + std::string m_icon; + std::vector m_channels; +}; +} // namespace entity +} // namespace tvheadend diff --git a/src/tvheadend/entity/TimeRecording.cpp b/src/tvheadend/entity/TimeRecording.cpp index 60262167..a3b8f913 100644 --- a/src/tvheadend/entity/TimeRecording.cpp +++ b/src/tvheadend/entity/TimeRecording.cpp @@ -23,21 +23,17 @@ using namespace tvheadend::entity; -TimeRecording::TimeRecording(const std::string &id /*= ""*/) : - RecordingBase(id), - m_start(0), - m_stop(0) +TimeRecording::TimeRecording(const std::string& id /*= ""*/) + : RecordingBase(id), m_start(0), m_stop(0) { } -bool TimeRecording::operator==(const TimeRecording &right) +bool TimeRecording::operator==(const TimeRecording& right) { - return RecordingBase::operator==(right) && - m_start == right.m_start && - m_stop == right.m_stop; + return RecordingBase::operator==(right) && m_start == right.m_start && m_stop == right.m_stop; } -bool TimeRecording::operator!=(const TimeRecording &right) +bool TimeRecording::operator!=(const TimeRecording& right) { return !(*this == right); } diff --git a/src/tvheadend/entity/TimeRecording.h b/src/tvheadend/entity/TimeRecording.h index 78a760ee..85271bdf 100644 --- a/src/tvheadend/entity/TimeRecording.h +++ b/src/tvheadend/entity/TimeRecording.h @@ -22,32 +22,33 @@ */ #include "RecordingBase.h" + #include namespace tvheadend { - namespace entity - { - class TimeRecording : public RecordingBase - { - public: - TimeRecording(const std::string &id = ""); - - bool operator==(const TimeRecording &right); - bool operator!=(const TimeRecording &right); - - time_t GetStart() const; - void SetStart(int32_t start); - - time_t GetStop() const; - void SetStop(int32_t stop); - - private: - int32_t m_start; // Start time in minutes from midnight (up to 24*60). - int32_t m_stop; // Stop time in minutes from midnight (up to 24*60). - }; - - typedef std::map TimeRecordingsMap; - typedef std::pair TimeRecordingMapEntry; - } -} +namespace entity +{ +class TimeRecording : public RecordingBase +{ +public: + TimeRecording(const std::string& id = ""); + + bool operator==(const TimeRecording& right); + bool operator!=(const TimeRecording& right); + + time_t GetStart() const; + void SetStart(int32_t start); + + time_t GetStop() const; + void SetStop(int32_t stop); + +private: + int32_t m_start; // Start time in minutes from midnight (up to 24*60). + int32_t m_stop; // Stop time in minutes from midnight (up to 24*60). +}; + +typedef std::map TimeRecordingsMap; +typedef std::pair TimeRecordingMapEntry; +} // namespace entity +} // namespace tvheadend diff --git a/src/tvheadend/status/DescrambleInfo.cpp b/src/tvheadend/status/DescrambleInfo.cpp index ed76a4ec..5f2df3fd 100644 --- a/src/tvheadend/status/DescrambleInfo.cpp +++ b/src/tvheadend/status/DescrambleInfo.cpp @@ -26,17 +26,17 @@ using namespace tvheadend::status; DescrambleInfo::DescrambleInfo() -: m_pid(PVR_DESCRAMBLE_INFO_NOT_AVAILABLE), - m_caid(PVR_DESCRAMBLE_INFO_NOT_AVAILABLE), - m_provid(PVR_DESCRAMBLE_INFO_NOT_AVAILABLE), - m_ecmTime(PVR_DESCRAMBLE_INFO_NOT_AVAILABLE), - m_hops(PVR_DESCRAMBLE_INFO_NOT_AVAILABLE) + : m_pid(PVR_DESCRAMBLE_INFO_NOT_AVAILABLE), + m_caid(PVR_DESCRAMBLE_INFO_NOT_AVAILABLE), + m_provid(PVR_DESCRAMBLE_INFO_NOT_AVAILABLE), + m_ecmTime(PVR_DESCRAMBLE_INFO_NOT_AVAILABLE), + m_hops(PVR_DESCRAMBLE_INFO_NOT_AVAILABLE) { } void DescrambleInfo::Clear() { - m_pid = PVR_DESCRAMBLE_INFO_NOT_AVAILABLE; + m_pid = PVR_DESCRAMBLE_INFO_NOT_AVAILABLE; m_caid = PVR_DESCRAMBLE_INFO_NOT_AVAILABLE; m_provid = PVR_DESCRAMBLE_INFO_NOT_AVAILABLE; m_ecmTime = PVR_DESCRAMBLE_INFO_NOT_AVAILABLE; @@ -102,7 +102,7 @@ std::string DescrambleInfo::GetCardSystem() const return m_cardSystem; } -void DescrambleInfo::SetCardSystem(const std::string &cardSystem) +void DescrambleInfo::SetCardSystem(const std::string& cardSystem) { m_cardSystem = cardSystem; } @@ -112,7 +112,7 @@ std::string DescrambleInfo::GetReader() const return m_reader; } -void DescrambleInfo::SetReader(const std::string &reader) +void DescrambleInfo::SetReader(const std::string& reader) { m_reader = reader; } @@ -122,7 +122,7 @@ std::string DescrambleInfo::GetFrom() const return m_from; } -void DescrambleInfo::SetFrom(const std::string &from) +void DescrambleInfo::SetFrom(const std::string& from) { m_from = from; } @@ -132,7 +132,7 @@ std::string DescrambleInfo::GetProtocol() const return m_protocol; } -void DescrambleInfo::SetProtocol(const std::string &protocol) +void DescrambleInfo::SetProtocol(const std::string& protocol) { m_protocol = protocol; } diff --git a/src/tvheadend/status/DescrambleInfo.h b/src/tvheadend/status/DescrambleInfo.h index ed833cc2..39bd5d8f 100644 --- a/src/tvheadend/status/DescrambleInfo.h +++ b/src/tvheadend/status/DescrambleInfo.h @@ -26,58 +26,56 @@ namespace tvheadend { - namespace status - { +namespace status +{ - /** +/** * Contains information about the descrambler used */ - class DescrambleInfo - { - public: - - DescrambleInfo(); - void Clear(); - - int64_t GetPid() const; - void SetPid(uint32_t pid); +class DescrambleInfo +{ +public: + DescrambleInfo(); + void Clear(); - int64_t GetCaid() const; - void SetCaid(uint32_t caid); + int64_t GetPid() const; + void SetPid(uint32_t pid); - int64_t GetProvid() const; - void SetProvid(uint32_t provid); + int64_t GetCaid() const; + void SetCaid(uint32_t caid); - int64_t GetEcmTime() const; - void SetEcmTime(uint32_t ecmTime); + int64_t GetProvid() const; + void SetProvid(uint32_t provid); - int64_t GetHops() const; - void SetHops(uint32_t hops); + int64_t GetEcmTime() const; + void SetEcmTime(uint32_t ecmTime); - std::string GetCardSystem() const; - void SetCardSystem(const std::string &cardSystem); + int64_t GetHops() const; + void SetHops(uint32_t hops); - std::string GetReader() const; - void SetReader(const std::string &reader); + std::string GetCardSystem() const; + void SetCardSystem(const std::string& cardSystem); - std::string GetFrom() const; - void SetFrom(const std::string &from); + std::string GetReader() const; + void SetReader(const std::string& reader); - std::string GetProtocol() const; - void SetProtocol(const std::string &protocol); + std::string GetFrom() const; + void SetFrom(const std::string& from); - private: - int64_t m_pid; - int64_t m_caid; - int64_t m_provid; - int64_t m_ecmTime; - int64_t m_hops; - std::string m_cardSystem; - std::string m_reader; - std::string m_from; - std::string m_protocol; + std::string GetProtocol() const; + void SetProtocol(const std::string& protocol); - }; +private: + int64_t m_pid; + int64_t m_caid; + int64_t m_provid; + int64_t m_ecmTime; + int64_t m_hops; + std::string m_cardSystem; + std::string m_reader; + std::string m_from; + std::string m_protocol; +}; - } -} +} // namespace status +} // namespace tvheadend diff --git a/src/tvheadend/status/Quality.h b/src/tvheadend/status/Quality.h index 34899b4e..e05c898a 100644 --- a/src/tvheadend/status/Quality.h +++ b/src/tvheadend/status/Quality.h @@ -25,61 +25,55 @@ namespace tvheadend { - namespace status - { - /** +namespace status +{ +/** * Represents the current signal quality */ - struct Quality - { +struct Quality +{ - /** + /** * Frontend status */ - std::string fe_status; + std::string fe_status; - /** + /** * Signal to noise ratio */ - uint32_t fe_snr; + uint32_t fe_snr; - /** + /** * Signal status percentage */ - uint32_t fe_signal; + uint32_t fe_signal; - /** + /** * Bit error rate */ - uint32_t fe_ber; + uint32_t fe_ber; - /** + /** * Uncorrected blocks */ - uint32_t fe_unc; + uint32_t fe_unc; - /** + /** * Constructor */ - Quality() : - fe_snr(0), - fe_signal(0), - fe_ber(0), - fe_unc(0) - { - } + Quality() : fe_snr(0), fe_signal(0), fe_ber(0), fe_unc(0) {} - /** + /** * Clears the current status */ - void Clear() - { - fe_status.clear(); - fe_snr = 0; - fe_signal = 0; - fe_ber = 0; - fe_unc = 0; - } - }; + void Clear() + { + fe_status.clear(); + fe_snr = 0; + fe_signal = 0; + fe_ber = 0; + fe_unc = 0; } -} +}; +} // namespace status +} // namespace tvheadend diff --git a/src/tvheadend/status/QueueStatus.h b/src/tvheadend/status/QueueStatus.h index ac39535c..84d1fe91 100644 --- a/src/tvheadend/status/QueueStatus.h +++ b/src/tvheadend/status/QueueStatus.h @@ -21,55 +21,49 @@ * */ -namespace tvheadend { - namespace status { - /** +namespace tvheadend +{ +namespace status +{ +/** * Represents the current demuxer packet queue */ - struct QueueStatus - { - /** +struct QueueStatus +{ + /** * Number of data packets in queue */ - uint32_t packets; + uint32_t packets; - /** + /** * Number of bytes in queue. */ - uint32_t bytes; + uint32_t bytes; - /** + /** * Estimated delay of queue (in µs) */ - uint32_t delay; + uint32_t delay; - /** + /** * Number of B-frames dropped */ - uint32_t bdrops; + uint32_t bdrops; - /** + /** * Number of P-frames dropped */ - uint32_t pdrops; + uint32_t pdrops; - /** + /** * Number of I-frames dropped */ - uint32_t idrops; + uint32_t idrops; - /** + /** * Constructor */ - QueueStatus() : - packets(0), - bytes(0), - delay(0), - bdrops(0), - pdrops(0), - idrops(0) - { - } - }; - } -} + QueueStatus() : packets(0), bytes(0), delay(0), bdrops(0), pdrops(0), idrops(0) {} +}; +} // namespace status +} // namespace tvheadend diff --git a/src/tvheadend/status/SourceInfo.h b/src/tvheadend/status/SourceInfo.h index 611e757f..4ee3ca61 100644 --- a/src/tvheadend/status/SourceInfo.h +++ b/src/tvheadend/status/SourceInfo.h @@ -25,49 +25,49 @@ namespace tvheadend { - namespace status - { - /** +namespace status +{ +/** * Represents information about the current service */ - struct SourceInfo - { - /** +struct SourceInfo +{ + /** * The current adapter used */ - std::string si_adapter; + std::string si_adapter; - /** + /** * The network */ - std::string si_network; + std::string si_network; - /** + /** * The mux */ - std::string si_mux; + std::string si_mux; - /** + /** * The service provider */ - std::string si_provider; + std::string si_provider; - /** + /** * The service name */ - std::string si_service; + std::string si_service; - /** + /** * Clears the current status */ - void Clear() - { - si_adapter.clear(); - si_network.clear(); - si_mux.clear(); - si_provider.clear(); - si_service.clear(); - } - }; + void Clear() + { + si_adapter.clear(); + si_network.clear(); + si_mux.clear(); + si_provider.clear(); + si_service.clear(); } -} +}; +} // namespace status +} // namespace tvheadend diff --git a/src/tvheadend/status/TimeshiftStatus.h b/src/tvheadend/status/TimeshiftStatus.h index bd5d97e6..b1da26d5 100644 --- a/src/tvheadend/status/TimeshiftStatus.h +++ b/src/tvheadend/status/TimeshiftStatus.h @@ -23,52 +23,50 @@ namespace tvheadend { - namespace status - { - /** +namespace status +{ +/** * Represents the current timeshift status */ - struct TimeshiftStatus - { +struct TimeshiftStatus +{ - /** + /** * Whether the buffer is full or not */ - bool full; + bool full; - /** + /** * Current position relative to live */ - int64_t shift; + int64_t shift; - /** + /** * PTS of the first frame in the buffer */ - int64_t start; + int64_t start; - /** + /** * PTS of the last frame in the buffer */ - int64_t end; + int64_t end; - /** + /** * Constructor */ - TimeshiftStatus() - { - Clear(); - } + TimeshiftStatus() { Clear(); } - /** + /** * Clears the current status */ - void Clear() - { - full = false; - shift = 0; - start = 0;; - end = 0; - } - }; + void Clear() + { + full = false; + shift = 0; + start = 0; + ; + end = 0; } -} +}; +} // namespace status +} // namespace tvheadend diff --git a/src/tvheadend/utilities/AsyncState.cpp b/src/tvheadend/utilities/AsyncState.cpp index 1f4fdf30..4f8a66c1 100644 --- a/src/tvheadend/utilities/AsyncState.cpp +++ b/src/tvheadend/utilities/AsyncState.cpp @@ -24,14 +24,15 @@ using namespace tvheadend::utilities; using namespace P8PLATFORM; -struct Param { +struct Param +{ eAsyncState state; - AsyncState *self; + AsyncState* self; }; AsyncState::AsyncState(int timeout) { - m_state = ASYNC_NONE; + m_state = ASYNC_NONE; m_timeout = timeout; } @@ -48,9 +49,9 @@ void AsyncState::SetState(eAsyncState state) m_condition.Broadcast(); } -bool AsyncState::PredicateCallback ( void *p ) +bool AsyncState::PredicateCallback(void* p) { - Param *param = (Param*)p; + Param* param = (Param*)p; return param->self->m_state >= param->state; } @@ -58,7 +59,7 @@ bool AsyncState::WaitForState(eAsyncState state) { Param p; p.state = state; - p.self = this; + p.self = this; CLockObject lock(m_mutex); return m_condition.Wait(m_mutex, AsyncState::PredicateCallback, (void*)&p, m_timeout); diff --git a/src/tvheadend/utilities/AsyncState.h b/src/tvheadend/utilities/AsyncState.h index 045f471a..9bef9a52 100644 --- a/src/tvheadend/utilities/AsyncState.h +++ b/src/tvheadend/utilities/AsyncState.h @@ -23,61 +23,59 @@ #include "p8-platform/threads/mutex.h" -namespace tvheadend { - namespace utilities { +namespace tvheadend +{ +namespace utilities +{ - /** +/** * Represents the possible states */ - enum eAsyncState - { - ASYNC_NONE = 0, - ASYNC_CHN = 1, - ASYNC_DVR = 2, - ASYNC_EPG = 3, - ASYNC_DONE = 4 - }; +enum eAsyncState +{ + ASYNC_NONE = 0, + ASYNC_CHN = 1, + ASYNC_DVR = 2, + ASYNC_EPG = 3, + ASYNC_DONE = 4 +}; - /** +/** * State tracker for the initial sync process. This class is thread-safe. */ - class AsyncState - { - public: - AsyncState(int timeout); +class AsyncState +{ +public: + AsyncState(int timeout); - virtual ~AsyncState() - { - }; + virtual ~AsyncState(){}; - /** + /** * @return the current state */ - eAsyncState GetState(); + eAsyncState GetState(); - /** + /** * Changes the current state to "state" * @param state the new state */ - void SetState(eAsyncState state); + void SetState(eAsyncState state); - /** + /** * Waits for the current state to change into "state" or higher * before the timeout is reached * @param state the minimum state desired * @return whether the state changed or not */ - bool WaitForState(eAsyncState state); + bool WaitForState(eAsyncState state); - private: +private: + static bool PredicateCallback(void* param); - static bool PredicateCallback ( void *param ); - - eAsyncState m_state; - P8PLATFORM::CMutex m_mutex; - P8PLATFORM::CCondition m_condition; - int m_timeout; - - }; - } -} + eAsyncState m_state; + P8PLATFORM::CMutex m_mutex; + P8PLATFORM::CCondition m_condition; + int m_timeout; +}; +} // namespace utilities +} // namespace tvheadend diff --git a/src/tvheadend/utilities/LifetimeMapper.h b/src/tvheadend/utilities/LifetimeMapper.h index d678669d..41fafbb6 100644 --- a/src/tvheadend/utilities/LifetimeMapper.h +++ b/src/tvheadend/utilities/LifetimeMapper.h @@ -25,34 +25,34 @@ namespace tvheadend { - namespace utilities - { - /** +namespace utilities +{ +/** * Maps "lifetime" values from Kodi to Tvheadend and vica versa */ - class LifetimeMapper - { - public: - static int TvhToKodi(uint32_t tvhLifetime) - { - // pvr addon api: addon defined special values must be less than zero - if (tvhLifetime == DVR_RET_SPACE) - return -2; - else if (tvhLifetime == DVR_RET_FOREVER) - return -1; - else - return tvhLifetime; // lifetime in days - } +class LifetimeMapper +{ +public: + static int TvhToKodi(uint32_t tvhLifetime) + { + // pvr addon api: addon defined special values must be less than zero + if (tvhLifetime == DVR_RET_SPACE) + return -2; + else if (tvhLifetime == DVR_RET_FOREVER) + return -1; + else + return tvhLifetime; // lifetime in days + } - static uint32_t KodiToTvh(int kodiLifetime) - { - if (kodiLifetime == -2) - return DVR_RET_SPACE; - else if (kodiLifetime == -1) - return DVR_RET_FOREVER; - else - return kodiLifetime; // lifetime in days - } - }; + static uint32_t KodiToTvh(int kodiLifetime) + { + if (kodiLifetime == -2) + return DVR_RET_SPACE; + else if (kodiLifetime == -1) + return DVR_RET_FOREVER; + else + return kodiLifetime; // lifetime in days } -} +}; +} // namespace utilities +} // namespace tvheadend diff --git a/src/tvheadend/utilities/LocalizedString.h b/src/tvheadend/utilities/LocalizedString.h index 24dfe991..d7ff970f 100644 --- a/src/tvheadend/utilities/LocalizedString.h +++ b/src/tvheadend/utilities/LocalizedString.h @@ -21,41 +21,35 @@ * */ -#include - #include "../../client.h" +#include + namespace tvheadend { - namespace utilities - { - /** +namespace utilities +{ +/** * Encapsulates an localized string. */ - class LocalizedString - { - public: - explicit LocalizedString(int stringId) - : m_localizedString(XBMC->GetLocalizedString(stringId)) - { - } - - ~LocalizedString() - { - XBMC->FreeString(m_localizedString); - } - - std::string Get() const - { - return m_localizedString ? std::string(m_localizedString) : std::string(); - } - - private: - LocalizedString() = delete; - LocalizedString(const LocalizedString&) = delete; - LocalizedString &operator =(const LocalizedString&) = delete; - - char* m_localizedString; - }; +class LocalizedString +{ +public: + explicit LocalizedString(int stringId) : m_localizedString(XBMC->GetLocalizedString(stringId)) {} + + ~LocalizedString() { XBMC->FreeString(m_localizedString); } + + std::string Get() const + { + return m_localizedString ? std::string(m_localizedString) : std::string(); } -} + +private: + LocalizedString() = delete; + LocalizedString(const LocalizedString&) = delete; + LocalizedString& operator=(const LocalizedString&) = delete; + + char* m_localizedString; +}; +} // namespace utilities +} // namespace tvheadend diff --git a/src/tvheadend/utilities/Logger.cpp b/src/tvheadend/utilities/Logger.cpp index 835a14d0..9c04bbb0 100644 --- a/src/tvheadend/utilities/Logger.cpp +++ b/src/tvheadend/utilities/Logger.cpp @@ -28,21 +28,20 @@ using namespace tvheadend::utilities; Logger::Logger() { // Use an empty implementation by default - SetImplementation([](LogLevel level, const char *message) - { + SetImplementation([](LogLevel level, const char* message) { }); } -Logger &Logger::GetInstance() +Logger& Logger::GetInstance() { static Logger instance; return instance; } -void Logger::Log(LogLevel level, const char *message, ...) +void Logger::Log(LogLevel level, const char* message, ...) { - auto &logger = GetInstance(); + auto& logger = GetInstance(); std::string logMessage; @@ -66,7 +65,7 @@ void Logger::SetImplementation(LoggerImplementation implementation) m_implementation = implementation; } -void Logger::SetPrefix(const std::string &prefix) +void Logger::SetPrefix(const std::string& prefix) { m_prefix = prefix; } diff --git a/src/tvheadend/utilities/Logger.h b/src/tvheadend/utilities/Logger.h index 645405f7..ed982df4 100644 --- a/src/tvheadend/utilities/Logger.h +++ b/src/tvheadend/utilities/Logger.h @@ -21,77 +21,75 @@ * */ -#include #include +#include namespace tvheadend { - namespace utilities - { - /** +namespace utilities +{ +/** * Represents the log level */ - enum LogLevel - { - LEVEL_ERROR, - LEVEL_INFO, - LEVEL_DEBUG, - LEVEL_TRACE - }; +enum LogLevel +{ + LEVEL_ERROR, + LEVEL_INFO, + LEVEL_DEBUG, + LEVEL_TRACE +}; - /** +/** * Short-hand for a function that acts as the logger implementation */ - typedef std::function LoggerImplementation; +typedef std::function LoggerImplementation; - /** +/** * The logger class. It is a singleton that by default comes with no * underlying implementation. It is up to the user to supply a suitable * implementation as a lambda using SetImplementation(). */ - class Logger - { - public: - - /** +class Logger +{ +public: + /** * Returns the singleton instance * @return */ - static Logger &GetInstance(); + static Logger& GetInstance(); - /** + /** * Logs the specified message using the specified log level * @param level the log level * @param message the log message * @param ... parameters for the log message */ - static void Log(LogLevel level, const char *message, ...); + static void Log(LogLevel level, const char* message, ...); - /** + /** * Configures the logger to use the specified implementation * @param implementation lambda */ - void SetImplementation(LoggerImplementation implementation); + void SetImplementation(LoggerImplementation implementation); - /** + /** * Sets the prefix to use in log messages * @param prefix */ - void SetPrefix(const std::string &prefix); + void SetPrefix(const std::string& prefix); - private: - Logger(); +private: + Logger(); - /** + /** * The logger implementation */ - LoggerImplementation m_implementation; + LoggerImplementation m_implementation; - /** + /** * The log message prefix */ - std::string m_prefix; - - }; - } -} + std::string m_prefix; +}; +} // namespace utilities +} // namespace tvheadend diff --git a/src/tvheadend/utilities/Utilities.h b/src/tvheadend/utilities/Utilities.h index fed8100c..2368b318 100644 --- a/src/tvheadend/utilities/Utilities.h +++ b/src/tvheadend/utilities/Utilities.h @@ -23,23 +23,23 @@ namespace tvheadend { - namespace utilities - { +namespace utilities +{ - /** +/** * std::remove_if() for maps. Borrowed from: * http://stackoverflow.com/questions/800955/remove-if-equivalent-for-stdmap */ - template< typename ContainerT, typename PredicateT > - void erase_if(ContainerT& items, const PredicateT& predicate) - { - for (auto it = items.begin(); it != items.end();) - { - if (predicate(*it)) - it = items.erase(it); - else - ++it; - } - }; +template +void erase_if(ContainerT& items, const PredicateT& predicate) +{ + for (auto it = items.begin(); it != items.end();) + { + if (predicate(*it)) + it = items.erase(it); + else + ++it; } -} +}; +} // namespace utilities +} // namespace tvheadend diff --git a/src/tvheadend/xbmc_codec_descriptor.hpp b/src/tvheadend/xbmc_codec_descriptor.hpp index 4104359a..e0b02f69 100644 --- a/src/tvheadend/xbmc_codec_descriptor.hpp +++ b/src/tvheadend/xbmc_codec_descriptor.hpp @@ -31,13 +31,11 @@ class CodecDescriptor public: CodecDescriptor(void) { - m_codec.codec_id = XBMC_INVALID_CODEC_ID; + m_codec.codec_id = XBMC_INVALID_CODEC_ID; m_codec.codec_type = XBMC_CODEC_TYPE_UNKNOWN; } - CodecDescriptor(xbmc_codec_t codec, const char* name) : - m_codec(codec), - m_strName(name) {} + CodecDescriptor(xbmc_codec_t codec, const char* name) : m_codec(codec), m_strName(name) {} virtual ~CodecDescriptor(void) {} xbmc_codec_t Codec(void) const { return m_codec; } @@ -60,5 +58,5 @@ class CodecDescriptor private: xbmc_codec_t m_codec; - std::string m_strName; + std::string m_strName; };