From c22d22948c24538c7cd76d4b87a02aee43726c3e Mon Sep 17 00:00:00 2001 From: Kai Sommerfeld Date: Fri, 18 Oct 2019 09:35:14 +0200 Subject: [PATCH 01/10] code cleanup: fix indentation glitches introduced by automatic clang-format application. --- src/client.cpp | 584 +++++++++++----------- src/tvheadend/ChannelTuningPredictor.h | 84 ++-- src/tvheadend/HTSPVFS.cpp | 4 +- src/tvheadend/Profile.h | 18 +- src/tvheadend/Settings.h | 24 +- src/tvheadend/Subscription.h | 58 +-- src/tvheadend/entity/AutoRecording.h | 2 + src/tvheadend/entity/Channel.h | 4 +- src/tvheadend/entity/Entity.h | 25 +- src/tvheadend/entity/Event.h | 6 +- src/tvheadend/entity/Recording.h | 13 +- src/tvheadend/entity/RecordingBase.h | 2 + src/tvheadend/entity/Schedule.h | 16 +- src/tvheadend/entity/Tag.h | 6 +- src/tvheadend/entity/TimeRecording.h | 2 + src/tvheadend/status/DescrambleInfo.h | 4 +- src/tvheadend/status/Quality.h | 35 +- src/tvheadend/status/QueueStatus.h | 34 +- src/tvheadend/status/SourceInfo.h | 30 +- src/tvheadend/status/TimeshiftStatus.h | 30 +- src/tvheadend/utilities/AsyncState.h | 29 +- src/tvheadend/utilities/LifetimeMapper.h | 6 +- src/tvheadend/utilities/LocalizedString.h | 6 +- src/tvheadend/utilities/Logger.h | 54 +- src/tvheadend/utilities/Utilities.h | 7 +- 25 files changed, 557 insertions(+), 526 deletions(-) diff --git a/src/client.cpp b/src/client.cpp index 55c86968..73bdf631 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -58,420 +58,420 @@ CTvheadend* tvh = NULL; extern "C" { - void ADDON_ReadSettings(void) { Settings::GetInstance().ReadSettings(); } +void ADDON_ReadSettings(void) { Settings::GetInstance().ReadSettings(); } - ADDON_STATUS ADDON_Create(void* hdl, void* props) +ADDON_STATUS ADDON_Create(void* hdl, void* props) +{ + if (!hdl || !props) + return m_CurStatus; + + /* Instantiate helpers */ + XBMC = new CHelper_libXBMC_addon; + PVR = new CHelper_libXBMC_pvr; + + if (!XBMC->RegisterMe(hdl) || !PVR->RegisterMe(hdl)) { - if (!hdl || !props) - return m_CurStatus; + SAFE_DELETE(PVR); + SAFE_DELETE(XBMC); + m_CurStatus = ADDON_STATUS_PERMANENT_FAILURE; + return m_CurStatus; + } - /* Instantiate helpers */ - XBMC = new CHelper_libXBMC_addon; - PVR = new CHelper_libXBMC_pvr; + /* Configure the logger */ + Logger::GetInstance().SetImplementation([](LogLevel level, const char* message) { + /* Convert the log level */ + addon_log_t addonLevel; - if (!XBMC->RegisterMe(hdl) || !PVR->RegisterMe(hdl)) + switch (level) { - SAFE_DELETE(PVR); - SAFE_DELETE(XBMC); - m_CurStatus = ADDON_STATUS_PERMANENT_FAILURE; - return m_CurStatus; + 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; } - /* Configure the logger */ - Logger::GetInstance().SetImplementation([](LogLevel level, const char* message) { - /* Convert the log level */ - addon_log_t addonLevel; - - 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; - } + /* Don't log trace messages unless told so */ + if (level == LogLevel::LEVEL_TRACE && !Settings::GetInstance().GetTraceDebug()) + return; - /* Don't log trace messages unless told so */ - if (level == LogLevel::LEVEL_TRACE && !Settings::GetInstance().GetTraceDebug()) - return; + XBMC->Log(addonLevel, "%s", message); + }); - XBMC->Log(addonLevel, "%s", message); - }); + Logger::GetInstance().SetPrefix("pvr.hts"); - Logger::GetInstance().SetPrefix("pvr.hts"); + Logger::Log(LogLevel::LEVEL_INFO, "starting PVR client"); - Logger::Log(LogLevel::LEVEL_INFO, "starting PVR client"); + ADDON_ReadSettings(); - ADDON_ReadSettings(); + tvh = new CTvheadend(reinterpret_cast(props)); + tvh->Start(); - tvh = new CTvheadend(reinterpret_cast(props)); - tvh->Start(); + m_CurStatus = ADDON_STATUS_OK; + return m_CurStatus; +} - m_CurStatus = ADDON_STATUS_OK; - return m_CurStatus; - } - - ADDON_STATUS ADDON_GetStatus() - { - CLockObject lock(g_mutex); - return m_CurStatus; - } - - 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_GetStatus() +{ + CLockObject lock(g_mutex); + return m_CurStatus; +} - 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 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; +} - void OnSystemSleep() { tvh->OnSleep(); } +void OnSystemSleep() { tvh->OnSleep(); } - void OnSystemWake() { tvh->OnWake(); } +void OnSystemWake() { tvh->OnWake(); } - void OnPowerSavingActivated() {} +void OnPowerSavingActivated() {} - void OnPowerSavingDeactivated() {} +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) +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) { - 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); - } + 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) +PVR_ERROR SetRecordingLifetime(const PVR_RECORDING* recording) +{ + if (!recording) { - if (!recording) - { - Logger::Log(LogLevel::LEVEL_ERROR, "recording must not be nullptr"); - return PVR_ERROR_INVALID_PARAMETERS; - } - return tvh->SetLifetime(*recording); + Logger::Log(LogLevel::LEVEL_ERROR, "recording must not be nullptr"); + return PVR_ERROR_INVALID_PARAMETERS; } + 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/tvheadend/ChannelTuningPredictor.h b/src/tvheadend/ChannelTuningPredictor.h index 24951504..135cb1d3 100644 --- a/src/tvheadend/ChannelTuningPredictor.h +++ b/src/tvheadend/ChannelTuningPredictor.h @@ -28,19 +28,18 @@ namespace tvheadend { - namespace predictivetune { /** - * Used to indicate that predictive tuning failed to determine which - * channel to be tuned next - */ + * Used to indicate that predictive tuning failed to determine which + * channel to be tuned next + */ const uint32_t CHANNEL_ID_NONE = -1; /** - * Defines a channel number - */ + * Defines a channel number + */ class ChannelNumber { public: @@ -71,14 +70,14 @@ class ChannelNumber }; /** - * Defines a single channel ID/number pair - */ + * Defines a single channel ID/number pair + */ typedef std::pair ChannelPair; typedef std::set::const_iterator ChannelPairIterator; /** - * Sorter for channel pairs - */ + * Sorter for channel pairs + */ struct SortChannelPair { bool operator()(const ChannelPair& left, const ChannelPair& right) const @@ -89,61 +88,62 @@ struct SortChannelPair } // 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. - */ + * 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: /** - * Adds the specified channel - * @param channel the channel - */ + * Adds the specified channel + * @param channel the 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 - */ + * 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); /** - * Removes the channel with the specified channel ID - * @param channelId the channel ID - */ + * Removes the channel with the specified channel ID + * @param channelId the channel ID + */ 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 - */ + * 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; private: /** - * Constructs a channel pair from the specified channel number - * @param channel the channel to construct a pair from - */ + * 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); /** - * 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 - */ + * 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; /** - * 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. - */ + * 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; }; + } // namespace tvheadend diff --git a/src/tvheadend/HTSPVFS.cpp b/src/tvheadend/HTSPVFS.cpp index e9b3fa9e..905a460a 100644 --- a/src/tvheadend/HTSPVFS.cpp +++ b/src/tvheadend/HTSPVFS.cpp @@ -39,8 +39,8 @@ using namespace tvheadend; using namespace tvheadend::utilities; /* -* VFS handler -*/ + * VFS handler + */ HTSPVFS::HTSPVFS(HTSPConnection& conn) : m_conn(conn), m_path(""), diff --git a/src/tvheadend/Profile.h b/src/tvheadend/Profile.h index d34664f6..e8fab741 100644 --- a/src/tvheadend/Profile.h +++ b/src/tvheadend/Profile.h @@ -31,8 +31,8 @@ class Profile; typedef std::vector Profiles; /** - * Represents a single streaming profile - */ + * Represents a single streaming profile + */ class Profile { public: @@ -46,19 +46,19 @@ class Profile void SetComment(const std::string& comment) { m_comment = comment; } private: - /* - * The profile UUID - */ + /** + * The profile UUID + */ std::string m_uuid; /** - * The profile name - */ + * The profile name + */ std::string m_name; /** - * The profile comment - */ + * The profile comment + */ std::string m_comment; }; diff --git a/src/tvheadend/Settings.h b/src/tvheadend/Settings.h index ee50f882..49d00f8b 100644 --- a/src/tvheadend/Settings.h +++ b/src/tvheadend/Settings.h @@ -61,8 +61,8 @@ class Settings static const bool DEFAULT_DVR_IGNORE_DUPLICATE_SCHEDULES; /** - * Singleton getter for the instance - */ + * Singleton getter for the instance + */ static Settings& GetInstance() { static Settings settings; @@ -70,18 +70,18 @@ class Settings } /** - * Read all settings defined in settings.xml - */ + * Read all settings defined in settings.xml + */ void ReadSettings(); /** - * Set a value according to key definition in settings.xml - */ + * Set a value according to key definition in settings.xml + */ ADDON_STATUS SetSetting(const std::string& key, const void* value); /** - * Getters for the settings values - */ + * 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; } @@ -134,8 +134,8 @@ class Settings void operator=(Settings const&) = delete; /** - * Setters - */ + * Setters + */ void SetHostname(const std::string& value) { m_strHostname = value; } void SetPortHTSP(int value) { m_iPortHTSP = value; } void SetPortHTTP(int value) { m_iPortHTTP = value; } @@ -158,8 +158,8 @@ class Settings void SetIgnoreDuplicateSchedules(bool value) { m_bIgnoreDuplicateSchedules = value; } /** - * Read/Set values according to definition in settings.xml - */ + * 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); diff --git a/src/tvheadend/Subscription.h b/src/tvheadend/Subscription.h index b0bec683..4f048d05 100644 --- a/src/tvheadend/Subscription.h +++ b/src/tvheadend/Subscription.h @@ -32,6 +32,7 @@ extern "C" namespace tvheadend { + class HTSPConnection; /* streaming uses a weight of 100 by default on the tvh side */ @@ -79,48 +80,48 @@ class Subscription 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 - */ + * 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); /** - * Unsubscribe from a channel on the backend - */ + * Unsubscribe from a channel on the backend + */ void SendUnsubscribe(); /** - * Send a seek to the backend - * @param time timestamp to seek to - * @return false if the command failed, true otherwise - */ + * Send a seek to the backend + * @param time timestamp to seek to + * @return false if the command failed, true otherwise + */ 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 - */ + * 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); /** - * Change the subscription weight on the backend - * @param weight the desired subscription weight - */ + * Change the subscription weight on the backend + * @param weight the desired subscription weight + */ void SendWeight(uint32_t weight); /** - * Parse the subscription status out of the incoming htsp data - * @param m message containing the status field - */ + * Parse the subscription status out of the incoming htsp data + * @param m message containing the status field + */ void ParseSubscriptionStatus(htsmsg_t* m); /** - * Use the specified profile for all new subscriptions - * @param profile the profile - */ + * Use the specified profile for all new subscriptions + * @param profile the profile + */ void SetProfile(const std::string& profile); private: @@ -131,13 +132,13 @@ class Subscription void SetState(eSubsriptionState state); /** - * Show a notification to the user depending on the subscription state - */ + * Show a notification to the user depending on the subscription state + */ void ShowStateNotification(); /** - * Get the next unique subscription Id - */ + * Get the next unique subscription Id + */ static uint32_t GetNextId(); uint32_t m_id; @@ -150,4 +151,5 @@ class Subscription mutable P8PLATFORM::CMutex m_mutex; }; + } // namespace tvheadend diff --git a/src/tvheadend/entity/AutoRecording.h b/src/tvheadend/entity/AutoRecording.h index a12ed4e5..0caa973f 100644 --- a/src/tvheadend/entity/AutoRecording.h +++ b/src/tvheadend/entity/AutoRecording.h @@ -29,6 +29,7 @@ namespace tvheadend { namespace entity { + class AutoRecording : public RecordingBase { public: @@ -70,5 +71,6 @@ class AutoRecording : public RecordingBase 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 86015285..acbed3b8 100644 --- a/src/tvheadend/entity/Channel.h +++ b/src/tvheadend/entity/Channel.h @@ -38,8 +38,8 @@ typedef std::pair ChannelMapEntry; typedef std::map Channels; /** - * Represents a channel - */ + * Represents a channel + */ class Channel : public Entity { public: diff --git a/src/tvheadend/entity/Entity.h b/src/tvheadend/entity/Entity.h index a9defd22..e3e533db 100644 --- a/src/tvheadend/entity/Entity.h +++ b/src/tvheadend/entity/Entity.h @@ -29,8 +29,8 @@ namespace entity { /** - * Abstract entity. An entity can be dirty or clean and has a numeric ID. - */ + * Abstract entity. An entity can be dirty or clean and has a numeric ID. + */ class Entity { public: @@ -38,25 +38,25 @@ class Entity virtual ~Entity() = default; /** - * @return if the entity is dirty - */ + * @return if the entity is dirty + */ virtual bool IsDirty() const { return m_dirty; } /** - * Marks the entity as dirty or not - * @param dirty - */ + * Marks the entity as dirty or not + * @param dirty + */ virtual void SetDirty(bool dirty) { m_dirty = dirty; } /** - * @return the entity ID - */ + * @return the entity ID + */ uint32_t GetId() const { return m_id; } /** - * Sets the entity ID - * @param id - */ + * Sets the entity ID + * @param id + */ void SetId(uint32_t id) { m_id = id; } protected: @@ -65,5 +65,6 @@ class Entity private: bool m_dirty; }; + } // namespace entity } // namespace tvheadend diff --git a/src/tvheadend/entity/Event.h b/src/tvheadend/entity/Event.h index 9b23d9cd..218e1c53 100644 --- a/src/tvheadend/entity/Event.h +++ b/src/tvheadend/entity/Event.h @@ -32,13 +32,14 @@ namespace tvheadend { namespace entity { + class Event; typedef std::pair EventMapEntry; typedef std::map Events; /** - * Represents an event/programme - */ + * Represents an event/programme + */ class Event : public Entity { public: @@ -172,5 +173,6 @@ class Event : public Entity 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 7242f3bd..5917bf73 100644 --- a/src/tvheadend/entity/Recording.h +++ b/src/tvheadend/entity/Recording.h @@ -48,10 +48,10 @@ 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" - */ + * 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: @@ -110,8 +110,8 @@ class Recording : public Entity } /** - * @return the type of timer - */ + * @return the type of timer + */ unsigned int GetTimerType() const { if (!m_timerecId.empty()) @@ -250,5 +250,6 @@ class Recording : public Entity uint32_t m_episode; uint32_t m_part; }; + } // namespace entity } // namespace tvheadend diff --git a/src/tvheadend/entity/RecordingBase.h b/src/tvheadend/entity/RecordingBase.h index f05aab3e..8145cc17 100644 --- a/src/tvheadend/entity/RecordingBase.h +++ b/src/tvheadend/entity/RecordingBase.h @@ -31,6 +31,7 @@ namespace tvheadend { namespace entity { + class RecordingBase : public Entity { protected: @@ -88,5 +89,6 @@ class RecordingBase : public Entity std::string m_creator; // Creator. uint32_t m_channel; // Channel ID. }; + } // namespace entity } // namespace tvheadend diff --git a/src/tvheadend/entity/Schedule.h b/src/tvheadend/entity/Schedule.h index 5a10bda0..8f420436 100644 --- a/src/tvheadend/entity/Schedule.h +++ b/src/tvheadend/entity/Schedule.h @@ -30,6 +30,7 @@ namespace tvheadend { namespace entity { + class Schedule; typedef std::pair ScheduleMapEntry; typedef std::map Schedules; @@ -38,26 +39,27 @@ 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. - */ + * 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); /** - * @return read-write reference to the events in this schedule - */ + * @return read-write reference to the events in this schedule + */ EventUids& GetEvents(); /** - * @return read-only reference to the events in this schedule - */ + * @return read-only reference to the events in this schedule + */ const EventUids& GetEvents() const; private: EventUids m_events; // event uids }; + } // namespace entity } // namespace tvheadend diff --git a/src/tvheadend/entity/Tag.h b/src/tvheadend/entity/Tag.h index deebd0b1..63350b34 100644 --- a/src/tvheadend/entity/Tag.h +++ b/src/tvheadend/entity/Tag.h @@ -34,13 +34,14 @@ namespace tvheadend { namespace entity { + class Tag; typedef std::pair TagMapEntry; typedef std::map Tags; /** - * Represents a channel tag - */ + * Represents a channel tag + */ class Tag : public Entity { public: @@ -68,5 +69,6 @@ class Tag : public Entity std::string m_icon; std::vector m_channels; }; + } // namespace entity } // namespace tvheadend diff --git a/src/tvheadend/entity/TimeRecording.h b/src/tvheadend/entity/TimeRecording.h index 85271bdf..3ad9f6a8 100644 --- a/src/tvheadend/entity/TimeRecording.h +++ b/src/tvheadend/entity/TimeRecording.h @@ -29,6 +29,7 @@ namespace tvheadend { namespace entity { + class TimeRecording : public RecordingBase { public: @@ -50,5 +51,6 @@ class TimeRecording : public RecordingBase typedef std::map TimeRecordingsMap; typedef std::pair TimeRecordingMapEntry; + } // namespace entity } // namespace tvheadend diff --git a/src/tvheadend/status/DescrambleInfo.h b/src/tvheadend/status/DescrambleInfo.h index 39bd5d8f..d2221d39 100644 --- a/src/tvheadend/status/DescrambleInfo.h +++ b/src/tvheadend/status/DescrambleInfo.h @@ -30,8 +30,8 @@ namespace status { /** - * Contains information about the descrambler used - */ + * Contains information about the descrambler used + */ class DescrambleInfo { public: diff --git a/src/tvheadend/status/Quality.h b/src/tvheadend/status/Quality.h index e05c898a..df11e1c5 100644 --- a/src/tvheadend/status/Quality.h +++ b/src/tvheadend/status/Quality.h @@ -27,45 +27,45 @@ namespace tvheadend { namespace status { + /** - * Represents the current signal quality - */ + * Represents the current signal quality + */ struct Quality { - /** - * Frontend status - */ + * Frontend status + */ std::string fe_status; /** - * Signal to noise ratio - */ + * Signal to noise ratio + */ uint32_t fe_snr; /** - * Signal status percentage - */ + * Signal status percentage + */ uint32_t fe_signal; /** - * Bit error rate - */ + * Bit error rate + */ uint32_t fe_ber; /** - * Uncorrected blocks - */ + * Uncorrected blocks + */ uint32_t fe_unc; /** - * Constructor - */ + * Constructor + */ Quality() : fe_snr(0), fe_signal(0), fe_ber(0), fe_unc(0) {} /** - * Clears the current status - */ + * Clears the current status + */ void Clear() { fe_status.clear(); @@ -75,5 +75,6 @@ struct Quality fe_unc = 0; } }; + } // namespace status } // namespace tvheadend diff --git a/src/tvheadend/status/QueueStatus.h b/src/tvheadend/status/QueueStatus.h index 84d1fe91..e79af4a7 100644 --- a/src/tvheadend/status/QueueStatus.h +++ b/src/tvheadend/status/QueueStatus.h @@ -25,45 +25,47 @@ namespace tvheadend { namespace status { + /** - * Represents the current demuxer packet queue - */ + * Represents the current demuxer packet queue + */ struct QueueStatus { /** - * Number of data packets in queue - */ + * Number of data packets in queue + */ uint32_t packets; /** - * Number of bytes in queue. - */ + * Number of bytes in queue. + */ uint32_t bytes; /** - * Estimated delay of queue (in µs) - */ + * Estimated delay of queue (in µs) + */ uint32_t delay; /** - * Number of B-frames dropped - */ + * Number of B-frames dropped + */ uint32_t bdrops; /** - * Number of P-frames dropped - */ + * Number of P-frames dropped + */ uint32_t pdrops; /** - * Number of I-frames dropped - */ + * Number of I-frames dropped + */ uint32_t idrops; /** - * Constructor - */ + * Constructor + */ 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 4ee3ca61..e385473d 100644 --- a/src/tvheadend/status/SourceInfo.h +++ b/src/tvheadend/status/SourceInfo.h @@ -27,39 +27,40 @@ namespace tvheadend { namespace status { + /** - * Represents information about the current service - */ + * Represents information about the current service + */ struct SourceInfo { /** - * The current adapter used - */ + * The current adapter used + */ std::string si_adapter; /** - * The network - */ + * The network + */ std::string si_network; /** - * The mux - */ + * The mux + */ std::string si_mux; /** - * The service provider - */ + * The service provider + */ std::string si_provider; /** - * The service name - */ + * The service name + */ std::string si_service; /** - * Clears the current status - */ + * Clears the current status + */ void Clear() { si_adapter.clear(); @@ -69,5 +70,6 @@ struct SourceInfo si_service.clear(); } }; + } // namespace status } // namespace tvheadend diff --git a/src/tvheadend/status/TimeshiftStatus.h b/src/tvheadend/status/TimeshiftStatus.h index b1da26d5..520eb879 100644 --- a/src/tvheadend/status/TimeshiftStatus.h +++ b/src/tvheadend/status/TimeshiftStatus.h @@ -25,40 +25,41 @@ namespace tvheadend { namespace status { + /** - * Represents the current timeshift status - */ + * Represents the current timeshift status + */ struct TimeshiftStatus { /** - * Whether the buffer is full or not - */ + * Whether the buffer is full or not + */ bool full; /** - * Current position relative to live - */ + * Current position relative to live + */ int64_t shift; /** - * PTS of the first frame in the buffer - */ + * PTS of the first frame in the buffer + */ int64_t start; /** - * PTS of the last frame in the buffer - */ + * PTS of the last frame in the buffer + */ int64_t end; /** - * Constructor - */ + * Constructor + */ TimeshiftStatus() { Clear(); } /** - * Clears the current status - */ + * Clears the current status + */ void Clear() { full = false; @@ -68,5 +69,6 @@ struct TimeshiftStatus end = 0; } }; + } // namespace status } // namespace tvheadend diff --git a/src/tvheadend/utilities/AsyncState.h b/src/tvheadend/utilities/AsyncState.h index 9bef9a52..a849bd8b 100644 --- a/src/tvheadend/utilities/AsyncState.h +++ b/src/tvheadend/utilities/AsyncState.h @@ -29,8 +29,8 @@ namespace utilities { /** - * Represents the possible states - */ + * Represents the possible states + */ enum eAsyncState { ASYNC_NONE = 0, @@ -41,8 +41,8 @@ enum eAsyncState }; /** - * State tracker for the initial sync process. This class is thread-safe. - */ + * State tracker for the initial sync process. This class is thread-safe. + */ class AsyncState { public: @@ -51,22 +51,22 @@ class AsyncState virtual ~AsyncState(){}; /** - * @return the current state - */ + * @return the current state + */ eAsyncState GetState(); /** - * Changes the current state to "state" - * @param state the new state - */ + * Changes the current state to "state" + * @param state the new 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 - */ + * 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); private: @@ -77,5 +77,6 @@ class AsyncState 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 41fafbb6..7078e48f 100644 --- a/src/tvheadend/utilities/LifetimeMapper.h +++ b/src/tvheadend/utilities/LifetimeMapper.h @@ -27,9 +27,10 @@ namespace tvheadend { namespace utilities { + /** - * Maps "lifetime" values from Kodi to Tvheadend and vica versa - */ + * Maps "lifetime" values from Kodi to Tvheadend and vica versa + */ class LifetimeMapper { public: @@ -54,5 +55,6 @@ class LifetimeMapper return kodiLifetime; // lifetime in days } }; + } // namespace utilities } // namespace tvheadend diff --git a/src/tvheadend/utilities/LocalizedString.h b/src/tvheadend/utilities/LocalizedString.h index d7ff970f..22e26feb 100644 --- a/src/tvheadend/utilities/LocalizedString.h +++ b/src/tvheadend/utilities/LocalizedString.h @@ -29,9 +29,10 @@ namespace tvheadend { namespace utilities { + /** - * Encapsulates an localized string. - */ + * Encapsulates a localized string. + */ class LocalizedString { public: @@ -51,5 +52,6 @@ class LocalizedString char* m_localizedString; }; + } // namespace utilities } // namespace tvheadend diff --git a/src/tvheadend/utilities/Logger.h b/src/tvheadend/utilities/Logger.h index ed982df4..1b02d71e 100644 --- a/src/tvheadend/utilities/Logger.h +++ b/src/tvheadend/utilities/Logger.h @@ -28,9 +28,10 @@ namespace tvheadend { namespace utilities { + /** - * Represents the log level - */ + * Represents the log level + */ enum LogLevel { LEVEL_ERROR, @@ -40,56 +41,57 @@ enum LogLevel }; /** - * Short-hand for a function that acts as the logger implementation - */ + * Short-hand for a function that acts as the logger implementation + */ 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(). - */ + * 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: /** - * Returns the singleton instance - * @return - */ + * Returns the singleton instance + * @return + */ 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 - */ + * 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, ...); /** - * Configures the logger to use the specified implementation - * @param implementation lambda - */ + * Configures the logger to use the specified implementation + * @param implementation lambda + */ void SetImplementation(LoggerImplementation implementation); /** - * Sets the prefix to use in log messages - * @param prefix - */ + * Sets the prefix to use in log messages + * @param prefix + */ void SetPrefix(const std::string& prefix); private: Logger(); /** - * The logger implementation - */ + * The logger implementation + */ LoggerImplementation m_implementation; /** - * The log message prefix - */ + * The log message prefix + */ std::string m_prefix; }; + } // namespace utilities } // namespace tvheadend diff --git a/src/tvheadend/utilities/Utilities.h b/src/tvheadend/utilities/Utilities.h index 2368b318..04580983 100644 --- a/src/tvheadend/utilities/Utilities.h +++ b/src/tvheadend/utilities/Utilities.h @@ -27,9 +27,9 @@ namespace utilities { /** - * std::remove_if() for maps. Borrowed from: - * http://stackoverflow.com/questions/800955/remove-if-equivalent-for-stdmap - */ + * std::remove_if() for maps. Borrowed from: + * http://stackoverflow.com/questions/800955/remove-if-equivalent-for-stdmap + */ template void erase_if(ContainerT& items, const PredicateT& predicate) { @@ -41,5 +41,6 @@ void erase_if(ContainerT& items, const PredicateT& predicate) ++it; } }; + } // namespace utilities } // namespace tvheadend From adab46a90958cf0d939c08d89ff1855d87368bac Mon Sep 17 00:00:00 2001 From: Kai Sommerfeld Date: Fri, 18 Oct 2019 09:44:26 +0200 Subject: [PATCH 02/10] code cleanup: '(void)' -> '()'. --- src/Tvheadend.cpp | 34 ++++++++++----------- src/Tvheadend.h | 28 ++++++++--------- src/client.cpp | 40 ++++++++++++------------- src/tvheadend/HTSPConnection.cpp | 24 +++++++-------- src/tvheadend/HTSPDemuxer.cpp | 16 +++++----- src/tvheadend/HTSPVFS.cpp | 10 +++---- src/tvheadend/Subscription.cpp | 4 +-- src/tvheadend/xbmc_codec_descriptor.hpp | 6 ++-- 8 files changed, 81 insertions(+), 81 deletions(-) diff --git a/src/Tvheadend.cpp b/src/Tvheadend.cpp index 4b6ca5e4..dd8cce30 100644 --- a/src/Tvheadend.cpp +++ b/src/Tvheadend.cpp @@ -69,13 +69,13 @@ CTvheadend::~CTvheadend() delete m_vfs; } -void CTvheadend::Start(void) +void CTvheadend::Start() { CreateThread(); m_conn->Start(); } -void CTvheadend::Stop(void) +void CTvheadend::Stop() { for (auto* dmx : m_dmx) dmx->Close(); @@ -190,7 +190,7 @@ bool CTvheadend::HasStreamingProfile(const std::string& streamingProfile) const * Tags * *************************************************************************/ -int CTvheadend::GetTagCount(void) +int CTvheadend::GetTagCount() { if (!m_asyncState.WaitForState(ASYNC_DVR)) return 0; @@ -284,7 +284,7 @@ PVR_ERROR CTvheadend::GetTagMembers(ADDON_HANDLE handle, const PVR_CHANNEL_GROUP * Channels * *************************************************************************/ -int CTvheadend::GetChannelCount(void) +int CTvheadend::GetChannelCount() { if (!m_asyncState.WaitForState(ASYNC_DVR)) return 0; @@ -388,7 +388,7 @@ PVR_ERROR CTvheadend::SendDvrUpdate(htsmsg_t* m) return u32 > 0 ? PVR_ERROR_NO_ERROR : PVR_ERROR_FAILED; } -int CTvheadend::GetRecordingCount(void) +int CTvheadend::GetRecordingCount() { if (!m_asyncState.WaitForState(ASYNC_EPG)) return 0; @@ -1028,7 +1028,7 @@ PVR_ERROR CTvheadend::GetTimerTypes(PVR_TIMER_TYPE types[], int* size) return PVR_ERROR_NO_ERROR; } -int CTvheadend::GetTimerCount(void) +int CTvheadend::GetTimerCount() { if (!m_asyncState.WaitForState(ASYNC_EPG)) return 0; @@ -1502,12 +1502,12 @@ PVR_ERROR CTvheadend::SetEPGTimeFrame(int iDays) * Connection * *************************************************************************/ -void CTvheadend::Disconnected(void) +void CTvheadend::Disconnected() { m_asyncState.SetState(ASYNC_NONE); } -bool CTvheadend::Connected(void) +bool CTvheadend::Connected() { htsmsg_t* msg; @@ -1706,7 +1706,7 @@ void CTvheadend::CloseExpiredSubscriptions() } } -void* CTvheadend::Process(void) +void* CTvheadend::Process() { HTSPMessage msg; const char* method; @@ -1877,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() { Logger::Log(LogLevel::LEVEL_INFO, "async updates initialised"); @@ -1906,7 +1906,7 @@ void CTvheadend::SyncCompleted(void) } } -void CTvheadend::SyncChannelsCompleted(void) +void CTvheadend::SyncChannelsCompleted() { /* check state engine */ if (m_asyncState.GetState() != ASYNC_CHN) @@ -1927,7 +1927,7 @@ void CTvheadend::SyncChannelsCompleted(void) m_asyncState.SetState(ASYNC_DVR); } -void CTvheadend::SyncDvrCompleted(void) +void CTvheadend::SyncDvrCompleted() { /* check state engine */ if (m_asyncState.GetState() != ASYNC_DVR) @@ -1964,7 +1964,7 @@ void CTvheadend::SyncDvrCompleted(void) m_asyncState.SetState(ASYNC_EPG); } -void CTvheadend::SyncEpgCompleted(void) +void CTvheadend::SyncEpgCompleted() { /* check state engine */ if (!Settings::GetInstance().GetAsyncEpg()) @@ -2893,7 +2893,7 @@ bool CTvheadend::DemuxOpen(const PVR_CHANNEL& chn) return m_playingLiveStream; } -DemuxPacket* CTvheadend::DemuxRead(void) +DemuxPacket* CTvheadend::DemuxRead() { DemuxPacket* pkt = NULL; @@ -2919,7 +2919,7 @@ DemuxPacket* CTvheadend::DemuxRead(void) return pkt; } -void CTvheadend::DemuxClose(void) +void CTvheadend::DemuxClose() { // If predictive tuning is active, demuxers will be closed automatically once they are expired. if (m_dmx.size() == 1) @@ -2928,12 +2928,12 @@ void CTvheadend::DemuxClose(void) m_playingLiveStream = false; } -void CTvheadend::DemuxFlush(void) +void CTvheadend::DemuxFlush() { m_dmx_active->Flush(); } -void CTvheadend::DemuxAbort(void) +void CTvheadend::DemuxAbort() { // If predictive tuning is active, demuxers will be closed/aborted automatically once they are expired. if (m_dmx.size() == 1) diff --git a/src/Tvheadend.h b/src/Tvheadend.h index e1f04162..4e1c9b70 100644 --- a/src/Tvheadend.h +++ b/src/Tvheadend.h @@ -71,8 +71,8 @@ class CTvheadend : public P8PLATFORM::CThread, public tvheadend::IHTSPConnection CTvheadend(PVR_PROPERTIES* pvrProps); ~CTvheadend() override; - void Start(void); - void Stop(void); + void Start(); + void Stop(); // IHTSPConnectionListener implementation void Disconnected() override; @@ -83,14 +83,14 @@ class CTvheadend : public P8PLATFORM::CThread, public tvheadend::IHTSPConnection PVR_ERROR GetDriveSpace(long long* total, long long* used); - int GetTagCount(void); + int GetTagCount(); PVR_ERROR GetTags(ADDON_HANDLE handle, bool bRadio); PVR_ERROR GetTagMembers(ADDON_HANDLE handle, const PVR_CHANNEL_GROUP& group); - int GetChannelCount(void); + int GetChannelCount(); PVR_ERROR GetChannels(ADDON_HANDLE handle, bool radio); - int GetRecordingCount(void); + int GetRecordingCount(); 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); @@ -100,7 +100,7 @@ class CTvheadend : public P8PLATFORM::CThread, public tvheadend::IHTSPConnection 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); + int GetTimerCount(); PVR_ERROR GetTimers(ADDON_HANDLE handle); PVR_ERROR AddTimer(const PVR_TIMER& tmr); PVR_ERROR DeleteTimer(const PVR_TIMER& tmr, bool force); @@ -165,10 +165,10 @@ class CTvheadend : public P8PLATFORM::CThread, public tvheadend::IHTSPConnection /* * Channel/Tags/Recordings/Events */ - void SyncChannelsCompleted(void); - void SyncDvrCompleted(void); - void SyncEpgCompleted(void); - void SyncCompleted(void); + void SyncChannelsCompleted(); + void SyncDvrCompleted(); + void SyncEpgCompleted(); + void SyncCompleted(); void ParseTagAddOrUpdate(htsmsg_t* m, bool bAdd); void ParseTagDelete(htsmsg_t* m); void ParseChannelAddOrUpdate(htsmsg_t* m, bool bAdd); @@ -203,10 +203,10 @@ class CTvheadend : public P8PLATFORM::CThread, public tvheadend::IHTSPConnection * Demuxer */ bool DemuxOpen(const PVR_CHANNEL& chn); - void DemuxClose(void); - DemuxPacket* DemuxRead(void); - void DemuxFlush(void); - void DemuxAbort(void); + void DemuxClose(); + DemuxPacket* DemuxRead(); + void DemuxFlush(); + void DemuxAbort(); bool DemuxSeek(double time, bool backward, double* startpts); void DemuxSpeed(int speed); void DemuxFillBuffer(bool mode); diff --git a/src/client.cpp b/src/client.cpp index 73bdf631..82a16c98 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -58,7 +58,7 @@ CTvheadend* tvh = NULL; extern "C" { -void ADDON_ReadSettings(void) { Settings::GetInstance().ReadSettings(); } +void ADDON_ReadSettings() { Settings::GetInstance().ReadSettings(); } ADDON_STATUS ADDON_Create(void* hdl, void* props) { @@ -192,7 +192,7 @@ PVR_ERROR GetAddonCapabilities(PVR_ADDON_CAPABILITIES* pCapabilities) return PVR_ERROR_NO_ERROR; } -const char* GetBackendName(void) +const char* GetBackendName() { static std::string serverName; @@ -200,7 +200,7 @@ const char* GetBackendName(void) return serverName.c_str(); } -const char* GetBackendVersion(void) +const char* GetBackendVersion() { static std::string serverVersion; @@ -208,7 +208,7 @@ const char* GetBackendVersion(void) return serverVersion.c_str(); } -const char* GetConnectionString(void) +const char* GetConnectionString() { static std::string serverString; @@ -216,7 +216,7 @@ const char* GetConnectionString(void) return serverString.c_str(); } -const char* GetBackendHostname(void) { return Settings::GetInstance().GetConstCharHostname(); } +const char* GetBackendHostname() { return Settings::GetInstance().GetConstCharHostname(); } PVR_ERROR GetDriveSpace(long long* iTotal, long long* iUsed) { @@ -245,9 +245,9 @@ PVR_ERROR GetStreamReadChunkSize(int* chunksize) return PVR_ERROR_NO_ERROR; } -bool CanPauseStream(void) { return tvh->HasCapability("timeshift"); } +bool CanPauseStream() { return tvh->HasCapability("timeshift"); } -bool CanSeekStream(void) { return tvh->HasCapability("timeshift"); } +bool CanSeekStream() { return tvh->HasCapability("timeshift"); } PVR_ERROR GetStreamTimes(PVR_STREAM_TIMES* times) { @@ -257,7 +257,7 @@ PVR_ERROR GetStreamTimes(PVR_STREAM_TIMES* times) return tvh->GetStreamTimes(times); } -bool IsTimeshifting(void) { return tvh->DemuxIsTimeShifting(); } +bool IsTimeshifting() { return tvh->DemuxIsTimeShifting(); } bool IsRealTimeStream() { @@ -269,7 +269,7 @@ bool IsRealTimeStream() bool OpenLiveStream(const PVR_CHANNEL& channel) { return tvh->DemuxOpen(channel); } -void CloseLiveStream(void) { tvh->DemuxClose(); } +void CloseLiveStream() { tvh->DemuxClose(); } bool SeekTime(double time, bool backward, double* startpts) { @@ -304,19 +304,19 @@ PVR_ERROR GetDescrambleInfo(PVR_DESCRAMBLE_INFO* descrambleInfo) return tvh->DemuxCurrentDescramble(descrambleInfo); } -DemuxPacket* DemuxRead(void) { return tvh->DemuxRead(); } +DemuxPacket* DemuxRead() { return tvh->DemuxRead(); } -void DemuxAbort(void) { tvh->DemuxAbort(); } +void DemuxAbort() { tvh->DemuxAbort(); } -void DemuxReset(void) {} +void DemuxReset() {} -void DemuxFlush(void) { tvh->DemuxFlush(); } +void DemuxFlush() { tvh->DemuxFlush(); } /* ************************************************************************** * Channel Management * *************************************************************************/ -int GetChannelGroupsAmount(void) { return tvh->GetTagCount(); } +int GetChannelGroupsAmount() { return tvh->GetTagCount(); } PVR_ERROR GetChannelGroups(ADDON_HANDLE handle, bool bRadio) { @@ -328,7 +328,7 @@ PVR_ERROR GetChannelGroupMembers(ADDON_HANDLE handle, const PVR_CHANNEL_GROUP& g return tvh->GetTagMembers(handle, group); } -int GetChannelsAmount(void) { return tvh->GetChannelCount(); } +int GetChannelsAmount() { return tvh->GetChannelCount(); } PVR_ERROR GetChannels(ADDON_HANDLE handle, bool bRadio) { @@ -397,7 +397,7 @@ PVR_ERROR GetTimerTypes(PVR_TIMER_TYPE types[], int* size) return tvh->GetTimerTypes(types, size); } -int GetTimersAmount(void) { return tvh->GetTimerCount(); } +int GetTimersAmount() { return tvh->GetTimerCount(); } PVR_ERROR GetTimers(ADDON_HANDLE handle) { return tvh->GetTimers(handle); } @@ -416,7 +416,7 @@ PVR_ERROR UpdateTimer(const PVR_TIMER& timer) { return tvh->UpdateTimer(timer); bool OpenRecordedStream(const PVR_RECORDING& recording) { return tvh->VfsOpen(recording); } -void CloseRecordedStream(void) { tvh->VfsClose(); } +void CloseRecordedStream() { tvh->VfsClose(); } int ReadRecordedStream(unsigned char* pBuffer, unsigned int iBufferSize) { @@ -428,13 +428,13 @@ 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() { return tvh->VfsSize(); } /* ************************************************************************** * Unused Functions * *************************************************************************/ -PVR_ERROR OpenDialogChannelScan(void) { return PVR_ERROR_NOT_IMPLEMENTED; } +PVR_ERROR OpenDialogChannelScan() { return PVR_ERROR_NOT_IMPLEMENTED; } PVR_ERROR DeleteChannel(const PVR_CHANNEL&) { return PVR_ERROR_NOT_IMPLEMENTED; } @@ -448,7 +448,7 @@ int ReadLiveStream(unsigned char*, unsigned int) { return 0; } long long SeekLiveStream(long long, int) { return -1; } -long long LengthLiveStream(void) { return -1; } +long long LengthLiveStream() { return -1; } PVR_ERROR GetChannelStreamProperties(const PVR_CHANNEL*, PVR_NAMED_VALUE*, unsigned int*) { diff --git a/src/tvheadend/HTSPConnection.cpp b/src/tvheadend/HTSPConnection.cpp index 22aed232..bf6c057e 100644 --- a/src/tvheadend/HTSPConnection.cpp +++ b/src/tvheadend/HTSPConnection.cpp @@ -162,7 +162,7 @@ std::string HTSPConnection::GetWebURL(const char* fmt, ...) const return url; } -bool HTSPConnection::WaitForConnection(void) +bool HTSPConnection::WaitForConnection() { if (!m_ready) { @@ -172,25 +172,25 @@ bool HTSPConnection::WaitForConnection(void) return m_ready; } -int HTSPConnection::GetProtocol(void) const +int HTSPConnection::GetProtocol() const { CLockObject lock(m_mutex); return m_htspVersion; } -std::string HTSPConnection::GetServerName(void) const +std::string HTSPConnection::GetServerName() const { CLockObject lock(m_mutex); return m_serverName; } -std::string HTSPConnection::GetServerVersion(void) const +std::string HTSPConnection::GetServerVersion() 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() const { const Settings& settings = Settings::GetInstance(); @@ -204,7 +204,7 @@ bool HTSPConnection::HasCapability(const std::string& capability) const m_capabilities.end(); } -void HTSPConnection::OnSleep(void) +void HTSPConnection::OnSleep() { CLockObject lock(m_mutex); @@ -214,7 +214,7 @@ void HTSPConnection::OnSleep(void) m_suspended = true; } -void HTSPConnection::OnWake(void) +void HTSPConnection::OnWake() { CLockObject lock(m_mutex); @@ -256,7 +256,7 @@ void HTSPConnection::SetState(PVR_CONNECTION_STATE state) /* * Close the connection */ -void HTSPConnection::Disconnect(void) +void HTSPConnection::Disconnect() { CLockObject lock(m_mutex); @@ -276,7 +276,7 @@ void HTSPConnection::Disconnect(void) * * Return false if an error occurs and the connection should be terminated */ -bool HTSPConnection::ReadMessage(void) +bool HTSPConnection::ReadMessage() { uint8_t* buf; uint8_t lb[4]; @@ -458,7 +458,7 @@ htsmsg_t* HTSPConnection::SendAndWait(const char* method, htsmsg_t* msg, int iRe return SendAndWait0(method, msg, iResponseTimeout); } -bool HTSPConnection::SendHello(void) +bool HTSPConnection::SendHello() { /* Build message */ htsmsg_t* msg = htsmsg_create_map(); @@ -562,7 +562,7 @@ bool HTSPConnection::SendAuth(const std::string& user, const std::string& pass) /** * Register the connection, hello+auth */ -void HTSPConnection::Register(void) +void HTSPConnection::Register() { std::string user = Settings::GetInstance().GetUsername(); std::string pass = Settings::GetInstance().GetPassword(); @@ -623,7 +623,7 @@ void HTSPConnection::Register(void) /* * Main thread loop for connection and rx handling */ -void* HTSPConnection::Process(void) +void* HTSPConnection::Process() { static bool log = false; static unsigned int retryAttempt = 0; diff --git a/src/tvheadend/HTSPDemuxer.cpp b/src/tvheadend/HTSPDemuxer.cpp index 75093228..8ad08c20 100644 --- a/src/tvheadend/HTSPDemuxer.cpp +++ b/src/tvheadend/HTSPDemuxer.cpp @@ -59,7 +59,7 @@ HTSPDemuxer::~HTSPDemuxer() { } -void HTSPDemuxer::Connected(void) +void HTSPDemuxer::Connected() { /* Re-subscribe */ if (m_subscription.IsActive()) @@ -76,7 +76,7 @@ void HTSPDemuxer::Connected(void) * Demuxer API * *************************************************************************/ -void HTSPDemuxer::Close0(void) +void HTSPDemuxer::Close0() { /* Send unsubscribe */ if (m_subscription.IsActive()) @@ -87,7 +87,7 @@ void HTSPDemuxer::Close0(void) Abort0(); } -void HTSPDemuxer::Abort0(void) +void HTSPDemuxer::Abort0() { CLockObject lock(m_mutex); m_streams.clear(); @@ -120,7 +120,7 @@ bool HTSPDemuxer::Open(uint32_t channelId, enum eSubscriptionWeight weight) return m_subscription.IsActive(); } -void HTSPDemuxer::Close(void) +void HTSPDemuxer::Close() { CLockObject lock(m_conn.Mutex()); Close0(); @@ -128,7 +128,7 @@ void HTSPDemuxer::Close(void) Logger::Log(LogLevel::LEVEL_DEBUG, "demux close"); } -DemuxPacket* HTSPDemuxer::Read(void) +DemuxPacket* HTSPDemuxer::Read() { DemuxPacket* pkt = NULL; m_lastUse.store(time(nullptr)); @@ -144,7 +144,7 @@ DemuxPacket* HTSPDemuxer::Read(void) return PVR->AllocateDemuxPacket(0); } -void HTSPDemuxer::Flush(void) +void HTSPDemuxer::Flush() { DemuxPacket* pkt; Logger::Log(LogLevel::LEVEL_TRACE, "demux flush"); @@ -152,7 +152,7 @@ void HTSPDemuxer::Flush(void) PVR->FreeDemuxPacket(pkt); } -void HTSPDemuxer::Trim(void) +void HTSPDemuxer::Trim() { DemuxPacket* pkt; @@ -164,7 +164,7 @@ void HTSPDemuxer::Trim(void) PVR->FreeDemuxPacket(pkt); } -void HTSPDemuxer::Abort(void) +void HTSPDemuxer::Abort() { Logger::Log(LogLevel::LEVEL_TRACE, "demux abort"); CLockObject lock(m_conn.Mutex()); diff --git a/src/tvheadend/HTSPVFS.cpp b/src/tvheadend/HTSPVFS.cpp index 905a460a..e4f12b7d 100644 --- a/src/tvheadend/HTSPVFS.cpp +++ b/src/tvheadend/HTSPVFS.cpp @@ -57,7 +57,7 @@ HTSPVFS::~HTSPVFS() { } -void HTSPVFS::Connected(void) +void HTSPVFS::Connected() { /* Re-open */ if (m_fileId != 0) @@ -95,7 +95,7 @@ bool HTSPVFS::Open(const PVR_RECORDING& rec) return true; } -void HTSPVFS::Close(void) +void HTSPVFS::Close() { if (m_fileId != 0) SendFileClose(); @@ -171,7 +171,7 @@ long long HTSPVFS::Seek(long long pos, int whence, bool inprogress) return ret; } -long long HTSPVFS::Size(void) +long long HTSPVFS::Size() { int64_t ret = -1; htsmsg_t* m; @@ -225,7 +225,7 @@ void HTSPVFS::PauseStream(bool paused) } } -bool HTSPVFS::IsRealTimeStream(void) +bool HTSPVFS::IsRealTimeStream() { return m_isRealTimeStream; } @@ -270,7 +270,7 @@ bool HTSPVFS::SendFileOpen(bool force) return m_fileId > 0; } -void HTSPVFS::SendFileClose(void) +void HTSPVFS::SendFileClose() { htsmsg_t* m; diff --git a/src/tvheadend/Subscription.cpp b/src/tvheadend/Subscription.cpp index d1bf18c0..c05728fc 100644 --- a/src/tvheadend/Subscription.cpp +++ b/src/tvheadend/Subscription.cpp @@ -159,7 +159,7 @@ void Subscription::SendSubscribe(uint32_t channelId, uint32_t weight, bool resta GetId()); } -void Subscription::SendUnsubscribe(void) +void Subscription::SendUnsubscribe() { /* Build message */ htsmsg_t* m = htsmsg_create_map(); @@ -299,7 +299,7 @@ void Subscription::ParseSubscriptionStatus(htsmsg_t* m) } } -void Subscription::ShowStateNotification(void) +void Subscription::ShowStateNotification() { if (GetState() == SUBSCRIPTION_NOFREEADAPTER) XBMC->QueueNotification(ADDON::QUEUE_WARNING, LocalizedString(30450).Get().c_str()); diff --git a/src/tvheadend/xbmc_codec_descriptor.hpp b/src/tvheadend/xbmc_codec_descriptor.hpp index e0b02f69..fccd0064 100644 --- a/src/tvheadend/xbmc_codec_descriptor.hpp +++ b/src/tvheadend/xbmc_codec_descriptor.hpp @@ -29,16 +29,16 @@ class CodecDescriptor { public: - CodecDescriptor(void) + CodecDescriptor() { 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) {} - virtual ~CodecDescriptor(void) {} + virtual ~CodecDescriptor() {} - xbmc_codec_t Codec(void) const { return m_codec; } + xbmc_codec_t Codec() const { return m_codec; } static CodecDescriptor GetCodecByName(const char* strCodecName) { From e71ff7fde7007ff609c207fa6b9dd445af2712ec Mon Sep 17 00:00:00 2001 From: Kai Sommerfeld Date: Fri, 18 Oct 2019 10:30:05 +0200 Subject: [PATCH 03/10] code cleanup: get rid of some c-style casts (I encountered along the way). --- src/Tvheadend.cpp | 20 ++++++++++---------- src/tvheadend/HTSPConnection.cpp | 14 ++++++++------ src/tvheadend/HTSPDemuxer.cpp | 9 +++++---- src/tvheadend/HTSPVFS.cpp | 6 +++--- src/tvheadend/utilities/AsyncState.cpp | 4 ++-- 5 files changed, 28 insertions(+), 25 deletions(-) diff --git a/src/Tvheadend.cpp b/src/Tvheadend.cpp index dd8cce30..5bb3505a 100644 --- a/src/Tvheadend.cpp +++ b/src/Tvheadend.cpp @@ -45,7 +45,7 @@ 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_queue(static_cast(-1)), m_asyncState(Settings::GetInstance().GetResponseTimeout()), m_timeRecordings(*m_conn), m_autoRecordings(*m_conn), @@ -1434,8 +1434,8 @@ PVR_ERROR CTvheadend::GetEPGForChannel(ADDON_HANDLE handle, { htsmsg_field_t* f; - Logger::Log(LogLevel::LEVEL_DEBUG, "get epg channel %d start %ld stop %ld", iChannelUid, - (long long)start, (long long)end); + Logger::Log(LogLevel::LEVEL_DEBUG, "get epg channel %d start %lld stop %lld", iChannelUid, + static_cast(start), static_cast(end)); /* Build message */ htsmsg_t* msg = htsmsg_create_map(); @@ -1541,7 +1541,7 @@ bool CTvheadend::Connected() msg = htsmsg_create_map(); if (Settings::GetInstance().GetAsyncEpg()) { - Logger::Log(LogLevel::LEVEL_INFO, "request async EPG (%ld)", (long)m_epgMaxDays); + Logger::Log(LogLevel::LEVEL_INFO, "request async EPG (%d)", m_epgMaxDays); htsmsg_add_u32(msg, "epg", 1); if (m_epgMaxDays > EPG_TIMEFRAME_UNLIMITED) htsmsg_add_s64(msg, "epgMaxTime", @@ -2065,7 +2065,7 @@ void CTvheadend::ParseTagAddOrUpdate(htsmsg_t* msg, bool bAdd) { if (f->hmf_type != HMF_S64) continue; - tag.GetChannels().emplace_back((int)f->hmf_s64); + tag.GetChannels().emplace_back(static_cast(f->hmf_s64)); } } @@ -2594,8 +2594,8 @@ bool CTvheadend::ParseEvent(htsmsg_t* msg, bool bAdd, Event& evt) evt.SetId(id); evt.SetChannel(channel); - evt.SetStart((time_t)start); - evt.SetStop((time_t)stop); + evt.SetStart(static_cast(start)); + evt.SetStop(static_cast(stop)); /* Add optional fields */ if ((str = htsmsg_get_str(msg, "title")) != NULL) @@ -2617,7 +2617,7 @@ bool CTvheadend::ParseEvent(htsmsg_t* msg, bool bAdd, Event& evt) if (!htsmsg_get_u32(msg, "ageRating", &u32)) evt.SetAge(u32); if (!htsmsg_get_s64(msg, "firstAired", &s64)) - evt.SetAired((time_t)s64); + evt.SetAired(static_cast(s64)); if (!htsmsg_get_u32(msg, "seasonNumber", &u32)) evt.SetSeason(u32); if (!htsmsg_get_u32(msg, "episodeNumber", &u32)) @@ -2745,8 +2745,8 @@ void CTvheadend::ParseEventAddOrUpdate(htsmsg_t* msg, bool bAdd) } Logger::Log(LogLevel::LEVEL_TRACE, "event id:%d channel:%d start:%d stop:%d title:%s desc:%s", - evt.GetId(), evt.GetChannel(), (int)evt.GetStart(), (int)evt.GetStop(), - evt.GetTitle().c_str(), evt.GetDesc().c_str()); + evt.GetId(), evt.GetChannel(), static_cast(evt.GetStart()), + static_cast(evt.GetStop()), evt.GetTitle().c_str(), evt.GetDesc().c_str()); /* Transfer event to Kodi (callback) */ PushEpgEventUpdate(evt, (!bAdd || bUpdated) ? EPG_EVENT_UPDATED : EPG_EVENT_CREATED); diff --git a/src/tvheadend/HTSPConnection.cpp b/src/tvheadend/HTSPConnection.cpp index bf6c057e..302b381a 100644 --- a/src/tvheadend/HTSPConnection.cpp +++ b/src/tvheadend/HTSPConnection.cpp @@ -293,11 +293,11 @@ bool HTSPConnection::ReadMessage() len = (lb[0] << 24) + (lb[1] << 16) + (lb[2] << 8) + lb[3]; /* Read rest of packet */ - buf = (uint8_t*)malloc(len); + buf = static_cast(malloc(len)); cnt = 0; while (cnt < len) { - r = m_socket->Read((char*)buf + cnt, len - cnt, Settings::GetInstance().GetResponseTimeout()); + r = m_socket->Read(buf + cnt, len - cnt, Settings::GetInstance().GetResponseTimeout()); if (r < 0) { Logger::Log(LogLevel::LEVEL_ERROR, "failed to read packet (%s)", @@ -376,11 +376,13 @@ bool HTSPConnection::SendMessage0(const char* method, htsmsg_t* msg) /* Send data */ c = m_socket->Write(buf, len); free(buf); - if (c != (ssize_t)len) + + if (c != static_cast(len)) { Logger::Log(LogLevel::LEVEL_ERROR, "failed to write (%s)", m_socket->GetError().c_str()); if (!m_suspended) Disconnect(); + return false; } @@ -517,12 +519,12 @@ bool HTSPConnection::SendAuth(const std::string& user, const std::string& pass) /* Add Password */ // Note: we MUST send a digest or TVH will not evaluate the - struct HTSSHA1* sha = (struct HTSSHA1*)malloc(hts_sha1_size); + struct HTSSHA1* sha = static_cast(malloc(hts_sha1_size)); uint8_t d[20]; hts_sha1_init(sha); - hts_sha1_update(sha, (const uint8_t*)pass.c_str(), pass.length()); + hts_sha1_update(sha, reinterpret_cast(pass.c_str()), pass.length()); if (m_challenge) - hts_sha1_update(sha, (const uint8_t*)m_challenge, m_challengeLen); + hts_sha1_update(sha, static_cast(m_challenge), m_challengeLen); hts_sha1_final(sha, d); htsmsg_add_bin(msg, "digest", d, sizeof(d)); free(sha); diff --git a/src/tvheadend/HTSPDemuxer.cpp b/src/tvheadend/HTSPDemuxer.cpp index 8ad08c20..bb4b4905 100644 --- a/src/tvheadend/HTSPDemuxer.cpp +++ b/src/tvheadend/HTSPDemuxer.cpp @@ -45,7 +45,7 @@ using namespace tvheadend::utilities; HTSPDemuxer::HTSPDemuxer(HTSPConnection& conn) : m_conn(conn), - m_pktBuffer((size_t)-1), + m_pktBuffer(static_cast(-1)), m_seekTime(INVALID_SEEKTIME), m_seeking(false), m_subscription(conn), @@ -136,7 +136,7 @@ DemuxPacket* HTSPDemuxer::Read() 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); + pkt->pts, static_cast(pkt->iSize)); return pkt; } Logger::Log(LogLevel::LEVEL_TRACE, "demux read nothing"); @@ -532,14 +532,15 @@ void HTSPDemuxer::ParseMuxPacket(htsmsg_t* m) /* Type (for debug only) */ if (!htsmsg_get_u32(m, "frametype", &u32)) - type = (char)u32; + type = static_cast(u32); if (!type) type = '_'; 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" : ""); + pkt->iStreamId, type, pkt->pts, static_cast(binlen), + ignore ? " IGNORE" : ""); /* Store */ if (!ignore) diff --git a/src/tvheadend/HTSPVFS.cpp b/src/tvheadend/HTSPVFS.cpp index e4f12b7d..112319a3 100644 --- a/src/tvheadend/HTSPVFS.cpp +++ b/src/tvheadend/HTSPVFS.cpp @@ -195,7 +195,7 @@ long long HTSPVFS::Size() if (htsmsg_get_s64(m, "size", &ret)) ret = -1; else - Logger::Log(LogLevel::LEVEL_TRACE, "vfs stat size=%lld", (long long)ret); + Logger::Log(LogLevel::LEVEL_TRACE, "vfs stat size=%lld", static_cast(ret)); htsmsg_destroy(m); @@ -311,7 +311,7 @@ long long HTSPVFS::SendFileSeek(int64_t pos, int whence, bool force) 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); + static_cast(pos)); /* Send */ { @@ -339,7 +339,7 @@ long long HTSPVFS::SendFileSeek(int64_t pos, int whence, bool force) } else { - Logger::Log(LogLevel::LEVEL_TRACE, "vfs seek offset=%lld", (long long)ret); + Logger::Log(LogLevel::LEVEL_TRACE, "vfs seek offset=%lld", static_cast(ret)); m_offset = ret; } diff --git a/src/tvheadend/utilities/AsyncState.cpp b/src/tvheadend/utilities/AsyncState.cpp index 4f8a66c1..1d7c931a 100644 --- a/src/tvheadend/utilities/AsyncState.cpp +++ b/src/tvheadend/utilities/AsyncState.cpp @@ -51,7 +51,7 @@ void AsyncState::SetState(eAsyncState state) bool AsyncState::PredicateCallback(void* p) { - Param* param = (Param*)p; + Param* param = reinterpret_cast(p); return param->self->m_state >= param->state; } @@ -62,5 +62,5 @@ bool AsyncState::WaitForState(eAsyncState state) p.self = this; CLockObject lock(m_mutex); - return m_condition.Wait(m_mutex, AsyncState::PredicateCallback, (void*)&p, m_timeout); + return m_condition.Wait(m_mutex, AsyncState::PredicateCallback, &p, m_timeout); } From 7d6217b11721177cf24fe14b901dfbea38d7fd43 Mon Sep 17 00:00:00 2001 From: Kai Sommerfeld Date: Fri, 18 Oct 2019 10:45:26 +0200 Subject: [PATCH 04/10] code cleanup: 'NULL' -> 'nullptr'. --- src/Tvheadend.cpp | 112 ++++++++++++------------- src/client.cpp | 8 +- src/tvheadend/AutoRecordings.cpp | 22 ++--- src/tvheadend/HTSPConnection.cpp | 26 +++--- src/tvheadend/HTSPDemuxer.cpp | 22 ++--- src/tvheadend/HTSPVFS.cpp | 8 +- src/tvheadend/Subscription.cpp | 8 +- src/tvheadend/TimeRecordings.cpp | 18 ++-- src/tvheadend/entity/RecordingBase.cpp | 2 +- 9 files changed, 113 insertions(+), 113 deletions(-) diff --git a/src/Tvheadend.cpp b/src/Tvheadend.cpp index 5bb3505a..d04806af 100644 --- a/src/Tvheadend.cpp +++ b/src/Tvheadend.cpp @@ -95,7 +95,7 @@ PVR_ERROR CTvheadend::GetDriveSpace(long long* total, long long* used) htsmsg_t* m = htsmsg_create_map(); m = m_conn->SendAndWait("getDiskSpace", m); - if (m == NULL) + if (!m) return PVR_ERROR_SERVER_ERROR; if (htsmsg_get_s64(m, "totaldiskspace", &s64)) @@ -143,13 +143,13 @@ void CTvheadend::QueryAvailableProfiles() } /* Validate */ - if (m == nullptr) + if (!m) return; htsmsg_t* l; htsmsg_field_t* f; - if ((l = htsmsg_get_list(m, "profiles")) == NULL) + if ((l = htsmsg_get_list(m, "profiles")) == nullptr) { Logger::Log(LogLevel::LEVEL_ERROR, "malformed getProfiles: 'profiles' missing"); htsmsg_destroy(m); @@ -162,11 +162,11 @@ void CTvheadend::QueryAvailableProfiles() const char* str; Profile profile; - if ((str = htsmsg_get_str(&f->hmf_msg, "uuid")) != NULL) + if ((str = htsmsg_get_str(&f->hmf_msg, "uuid")) != nullptr) profile.SetUuid(str); - if ((str = htsmsg_get_str(&f->hmf_msg, "name")) != NULL) + if ((str = htsmsg_get_str(&f->hmf_msg, "name")) != nullptr) profile.SetName(str); - if ((str = htsmsg_get_str(&f->hmf_msg, "comment")) != NULL) + if ((str = htsmsg_get_str(&f->hmf_msg, "comment")) != nullptr) profile.SetComment(str); Logger::Log(LogLevel::LEVEL_DEBUG, "profile name: %s, comment: %s added", @@ -349,7 +349,7 @@ PVR_ERROR CTvheadend::SendDvrDelete(uint32_t id, const char* method) /* Send and wait a bit longer than usual */ if ((m = m_conn->SendAndWait( - method, m, std::max(30000, Settings::GetInstance().GetResponseTimeout()))) == NULL) + method, m, std::max(30000, Settings::GetInstance().GetResponseTimeout()))) == nullptr) return PVR_ERROR_SERVER_ERROR; /* Check for error */ @@ -374,7 +374,7 @@ PVR_ERROR CTvheadend::SendDvrUpdate(htsmsg_t* m) m = m_conn->SendAndWait("updateDvrEntry", m); } - if (m == NULL) + if (!m) return PVR_ERROR_SERVER_ERROR; /* Check for error */ @@ -556,7 +556,7 @@ PVR_ERROR CTvheadend::GetRecordingEdl(const PVR_RECORDING& rec, PVR_EDL_ENTRY ed { CLockObject lock(m_conn->Mutex()); - if ((m = m_conn->SendAndWait("getDvrCutpoints", m)) == NULL) + if ((m = m_conn->SendAndWait("getDvrCutpoints", m)) == nullptr) return PVR_ERROR_SERVER_ERROR; } @@ -1154,7 +1154,7 @@ PVR_ERROR CTvheadend::AddTimer(const PVR_TIMER& timer) if (start == 0) { /* Instant timer. Adjust start time to 'now'. */ - start = time(NULL); + start = time(nullptr); } htsmsg_add_s64(m, "start", start); @@ -1183,7 +1183,7 @@ PVR_ERROR CTvheadend::AddTimer(const PVR_TIMER& timer) m = m_conn->SendAndWait("addDvrEntry", m); } - if (m == NULL) + if (!m) return PVR_ERROR_SERVER_ERROR; /* Check for error */ @@ -1303,7 +1303,7 @@ PVR_ERROR CTvheadend::UpdateTimer(const PVR_TIMER& timer) if (start == 0) { /* Instant timer. Adjust start time to 'now'. */ - start = time(NULL); + start = time(nullptr); } htsmsg_add_s64(m, "start", start); @@ -1378,12 +1378,12 @@ void CTvheadend::CreateEvent(const Event& event, EPG_TAG& epg) epg.endTime = event.GetStop(); epg.strPlotOutline = event.GetSummary().c_str(); epg.strPlot = event.GetDesc().c_str(); - epg.strOriginalTitle = NULL; /* not supported by tvh */ + epg.strOriginalTitle = nullptr; /* 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.strIMDBNumber = nullptr; /* not supported by tvh */ epg.strIconPath = event.GetImage().c_str(); epg.iGenreType = event.GetGenreType(); epg.iGenreSubType = event.GetGenreSubType(); @@ -1446,7 +1446,7 @@ PVR_ERROR CTvheadend::GetEPGForChannel(ADDON_HANDLE handle, { CLockObject lock(m_conn->Mutex()); - if ((msg = m_conn->SendAndWait0("getEvents", msg)) == NULL) + if ((msg = m_conn->SendAndWait0("getEvents", msg)) == nullptr) return PVR_ERROR_SERVER_ERROR; } @@ -1545,12 +1545,12 @@ bool CTvheadend::Connected() 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))); + static_cast(time(nullptr) + m_epgMaxDays * int64_t(24 * 60 * 60))); } else htsmsg_add_u32(msg, "epg", 0); - if ((msg = m_conn->SendAndWait0("enableAsyncMetadata", msg)) == NULL) + if ((msg = m_conn->SendAndWait0("enableAsyncMetadata", msg)) == nullptr) { m_asyncState.SetState(ASYNC_NONE); return false; @@ -2045,7 +2045,7 @@ void CTvheadend::ParseTagAddOrUpdate(htsmsg_t* msg, bool bAdd) tag.SetIndex(u32); /* Name */ - if ((str = htsmsg_get_str(msg, "tagName")) != NULL) + if ((str = htsmsg_get_str(msg, "tagName")) != nullptr) tag.SetName(str); else if (bAdd) { @@ -2054,11 +2054,11 @@ void CTvheadend::ParseTagAddOrUpdate(htsmsg_t* msg, bool bAdd) } /* Icon */ - if ((str = htsmsg_get_str(msg, "tagIcon")) != NULL) + if ((str = htsmsg_get_str(msg, "tagIcon")) != nullptr) tag.SetIcon(GetImageURL(str)); /* Members */ - if ((list = htsmsg_get_list(msg, "members")) != NULL) + if ((list = htsmsg_get_list(msg, "members")) != nullptr) { htsmsg_field_t* f; HTSMSG_FOREACH(f, list) @@ -2118,7 +2118,7 @@ void CTvheadend::ParseChannelAddOrUpdate(htsmsg_t* msg, bool bAdd) channel.SetDirty(false); /* Channel name */ - if ((str = htsmsg_get_str(msg, "channelName")) != NULL) + if ((str = htsmsg_get_str(msg, "channelName")) != nullptr) channel.SetName(str); else if (bAdd) { @@ -2146,11 +2146,11 @@ void CTvheadend::ParseChannelAddOrUpdate(htsmsg_t* msg, bool bAdd) channel.SetNumMinor(u32); /* Channel icon */ - if ((str = htsmsg_get_str(msg, "channelIcon")) != NULL) + if ((str = htsmsg_get_str(msg, "channelIcon")) != nullptr) channel.SetIcon(GetImageURL(str)); /* Services */ - if ((list = htsmsg_get_list(msg, "services")) != NULL) + if ((list = htsmsg_get_list(msg, "services")) != nullptr) { htsmsg_field_t* f; uint32_t caid = 0; @@ -2167,7 +2167,7 @@ void CTvheadend::ParseChannelAddOrUpdate(htsmsg_t* msg, bool bAdd) } else { - if ((str = htsmsg_get_str(&f->hmf_msg, "type")) != NULL) + if ((str = htsmsg_get_str(&f->hmf_msg, "type")) != nullptr) { if (!strcmp(str, "Radio")) channel.SetType(CHANNEL_TYPE_RADIO); @@ -2290,7 +2290,7 @@ void CTvheadend::ParseRecordingAddOrUpdate(htsmsg_t* msg, bool bAdd) } htsmsg_t *files, *streams; - if ((files = htsmsg_get_list(msg, "files")) != NULL) + if ((files = htsmsg_get_list(msg, "files")) != nullptr) { htsmsg_field_t *file, *stream; uint32_t u32; @@ -2309,7 +2309,7 @@ void CTvheadend::ParseRecordingAddOrUpdate(htsmsg_t* msg, bool bAdd) if (needChannelType && !(hasAudio && hasVideo)) { - if ((streams = htsmsg_get_list(&file->hmf_msg, "info")) != NULL) + if ((streams = htsmsg_get_list(&file->hmf_msg, "info")) != nullptr) { HTSMSG_FOREACH(stream, streams) // Loop through all streams { @@ -2346,7 +2346,7 @@ void CTvheadend::ParseRecordingAddOrUpdate(htsmsg_t* msg, bool bAdd) /* Channel name fallback (in case channel was deleted) */ if (rec.GetChannelName().empty() && m_conn->GetProtocol() >= 25) { - if ((str = htsmsg_get_str(msg, "channelName")) != NULL) + if ((str = htsmsg_get_str(msg, "channelName")) != nullptr) rec.SetChannelName(str); } @@ -2412,17 +2412,17 @@ void CTvheadend::ParseRecordingAddOrUpdate(htsmsg_t* msg, bool bAdd) } /* Parse state */ - if ((state = htsmsg_get_str(msg, "state")) != NULL) + if ((state = htsmsg_get_str(msg, "state")) != nullptr) { - if (strstr(state, "scheduled") != NULL) + if (strstr(state, "scheduled")) rec.SetState(PVR_TIMER_STATE_SCHEDULED); - else if (strstr(state, "recording") != NULL) + else if (strstr(state, "recording")) rec.SetState(PVR_TIMER_STATE_RECORDING); - else if (strstr(state, "completed") != NULL) + else if (strstr(state, "completed")) rec.SetState(PVR_TIMER_STATE_COMPLETED); - else if (strstr(state, "missed") != NULL) + else if (strstr(state, "missed")) rec.SetState(PVR_TIMER_STATE_ERROR); - else if (strstr(state, "invalid") != NULL) + else if (strstr(state, "invalid")) rec.SetState(PVR_TIMER_STATE_ERROR); } else if (bAdd) @@ -2436,25 +2436,25 @@ void CTvheadend::ParseRecordingAddOrUpdate(htsmsg_t* msg, bool bAdd) rec.SetEventId(eventId); if (!htsmsg_get_u32(msg, "enabled", &enabled)) rec.SetEnabled(enabled); - if ((str = htsmsg_get_str(msg, "title")) != NULL) + if ((str = htsmsg_get_str(msg, "title")) != nullptr) rec.SetTitle(str); - if ((str = htsmsg_get_str(msg, "subtitle")) != NULL) + if ((str = htsmsg_get_str(msg, "subtitle")) != nullptr) rec.SetSubtitle(str); - if ((str = htsmsg_get_str(msg, "path")) != NULL) + if ((str = htsmsg_get_str(msg, "path")) != nullptr) rec.SetPath(str); - if ((str = htsmsg_get_str(msg, "description")) != NULL) + if ((str = htsmsg_get_str(msg, "description")) != nullptr) rec.SetDescription(str); - else if ((str = htsmsg_get_str(msg, "summary")) != NULL) + else if ((str = htsmsg_get_str(msg, "summary")) != nullptr) rec.SetDescription(str); if (!htsmsg_get_u32(msg, "contentType", &contentType)) rec.SetContentType(contentType); - if ((str = htsmsg_get_str(msg, "timerecId")) != NULL) + if ((str = htsmsg_get_str(msg, "timerecId")) != nullptr) rec.SetTimerecId(str); - if ((str = htsmsg_get_str(msg, "autorecId")) != NULL) + if ((str = htsmsg_get_str(msg, "autorecId")) != nullptr) rec.SetAutorecId(str); - if ((str = htsmsg_get_str(msg, "image")) != NULL) + if ((str = htsmsg_get_str(msg, "image")) != nullptr) rec.SetImage(GetImageURL(str)); - if ((str = htsmsg_get_str(msg, "fanartImage")) != NULL) + if ((str = htsmsg_get_str(msg, "fanartImage")) != nullptr) rec.SetFanartImage(GetImageURL(str)); if (m_conn->GetProtocol() >= 32) @@ -2474,11 +2474,11 @@ void CTvheadend::ParseRecordingAddOrUpdate(htsmsg_t* msg, bool bAdd) } /* Error */ - if ((str = htsmsg_get_str(msg, "error")) != NULL) + if ((str = htsmsg_get_str(msg, "error")) != nullptr) { if (!strcmp(str, "300")) rec.SetState(PVR_TIMER_STATE_ABORTED); - else if (strstr(str, "missing") != NULL) + else if (strstr(str, "missing") != nullptr) rec.SetState(PVR_TIMER_STATE_ERROR); else rec.SetError(str); @@ -2489,7 +2489,7 @@ void CTvheadend::ParseRecordingAddOrUpdate(htsmsg_t* msg, bool bAdd) { /* Parse subscription error */ /* This field is absent when everything is fine or when htsp version < 20 */ - if ((str = htsmsg_get_str(msg, "subscriptionError")) != NULL) + if ((str = htsmsg_get_str(msg, "subscriptionError")) != nullptr) { /* No free adapter, AKA subscription conflict */ if (!strcmp("noFreeAdapter", str)) @@ -2598,15 +2598,15 @@ bool CTvheadend::ParseEvent(htsmsg_t* msg, bool bAdd, Event& evt) evt.SetStop(static_cast(stop)); /* Add optional fields */ - if ((str = htsmsg_get_str(msg, "title")) != NULL) + if ((str = htsmsg_get_str(msg, "title")) != nullptr) evt.SetTitle(str); - if ((str = htsmsg_get_str(msg, "subtitle")) != NULL) + if ((str = htsmsg_get_str(msg, "subtitle")) != nullptr) evt.SetSubtitle(str); - if ((str = htsmsg_get_str(msg, "summary")) != NULL) + if ((str = htsmsg_get_str(msg, "summary")) != nullptr) evt.SetSummary(str); - if ((str = htsmsg_get_str(msg, "description")) != NULL) + if ((str = htsmsg_get_str(msg, "description")) != nullptr) evt.SetDesc(str); - if ((str = htsmsg_get_str(msg, "image")) != NULL) + if ((str = htsmsg_get_str(msg, "image")) != nullptr) evt.SetImage(GetImageURL(str)); if (!htsmsg_get_u32(msg, "nextEventId", &u32)) evt.SetNext(u32); @@ -2624,7 +2624,7 @@ bool CTvheadend::ParseEvent(htsmsg_t* msg, bool bAdd, Event& evt) evt.SetEpisode(u32); if (!htsmsg_get_u32(msg, "partNumber", &u32)) evt.SetPart(u32); - if ((str = htsmsg_get_str(msg, "serieslinkUri")) != NULL) + if ((str = htsmsg_get_str(msg, "serieslinkUri")) != nullptr) evt.SetSeriesLink(str); if (!htsmsg_get_u32(msg, "copyrightYear", &u32)) evt.SetYear(u32); @@ -2666,11 +2666,11 @@ bool CTvheadend::ParseEvent(htsmsg_t* msg, bool bAdd, Event& evt) htsmsg_field_t* f; HTSMSG_FOREACH(f, l) { - if (f->hmf_name == nullptr) + if (!f->hmf_name) continue; const char* str = htsmsg_field_get_string(f); - if (str == nullptr) + if (!str) continue; if (!strcmp(str, "writer")) @@ -2796,7 +2796,7 @@ uint32_t CTvheadend::GetNextUnnumberedChannelNumber() void CTvheadend::TuneOnOldest(uint32_t channelId) { - HTSPDemuxer* oldest = NULL; + HTSPDemuxer* oldest = nullptr; for (auto* dmx : m_dmx) { @@ -2807,7 +2807,7 @@ void CTvheadend::TuneOnOldest(uint32_t channelId) } if (dmx == m_dmx_active) continue; - if (oldest == NULL || dmx->GetLastUse() <= oldest->GetLastUse()) + if (!oldest || dmx->GetLastUse() <= oldest->GetLastUse()) oldest = dmx; } if (oldest) @@ -2895,7 +2895,7 @@ bool CTvheadend::DemuxOpen(const PVR_CHANNEL& chn) DemuxPacket* CTvheadend::DemuxRead() { - DemuxPacket* pkt = NULL; + DemuxPacket* pkt = nullptr; if (m_streamchange) { diff --git a/src/client.cpp b/src/client.cpp index 82a16c98..9fac6633 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -46,10 +46,10 @@ 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 = nullptr; +CHelper_libXBMC_pvr* PVR = nullptr; +PVR_MENUHOOK* menuHook = nullptr; +CTvheadend* tvh = nullptr; /* ************************************************************************** * ADDON setup diff --git a/src/tvheadend/AutoRecordings.cpp b/src/tvheadend/AutoRecordings.cpp index cf85102a..e02cbdb0 100644 --- a/src/tvheadend/AutoRecordings.cpp +++ b/src/tvheadend/AutoRecordings.cpp @@ -82,7 +82,7 @@ void AutoRecordings::GetAutorecTimers(std::vector& timers) tmr.startTime = tmr.endTime - 60 * 60; // Nominal 1 hour duration if (tmr.bStartAnyTime && tmr.bEndAnyTime) { - tmr.startTime = time(NULL); // now + tmr.startTime = time(nullptr); // now tmr.endTime = tmr.startTime + 60 * 60; // Nominal 1 hour duration } @@ -298,7 +298,7 @@ PVR_ERROR AutoRecordings::SendAutorecAddOrUpdate(const PVR_TIMER& timer, bool up m = m_conn.SendAndWait(method.c_str(), m); } - if (m == NULL) + if (!m) return PVR_ERROR_SERVER_ERROR; /* Check for error */ @@ -329,7 +329,7 @@ PVR_ERROR AutoRecordings::SendAutorecDelete(const PVR_TIMER& timer) m = m_conn.SendAndWait("deleteAutorecEntry", m); } - if (m == NULL) + if (!m) return PVR_ERROR_SERVER_ERROR; /* Check for error */ @@ -350,7 +350,7 @@ bool AutoRecordings::ParseAutorecAddOrUpdate(htsmsg_t* msg, bool bAdd) int64_t s64; /* Validate/set mandatory fields */ - if ((str = htsmsg_get_str(msg, "id")) == NULL) + if ((str = htsmsg_get_str(msg, "id")) == nullptr) { Logger::Log(LogLevel::LEVEL_ERROR, "malformed autorecEntryAdd/autorecEntryUpdate: 'id' missing"); @@ -470,27 +470,27 @@ bool AutoRecordings::ParseAutorecAddOrUpdate(htsmsg_t* msg, bool bAdd) } /* Add optional fields */ - if ((str = htsmsg_get_str(msg, "title")) != NULL) + if ((str = htsmsg_get_str(msg, "title")) != nullptr) { rec.SetTitle(str); } - if ((str = htsmsg_get_str(msg, "name")) != NULL) + if ((str = htsmsg_get_str(msg, "name")) != nullptr) { rec.SetName(str); } - if ((str = htsmsg_get_str(msg, "directory")) != NULL) + if ((str = htsmsg_get_str(msg, "directory")) != nullptr) { rec.SetDirectory(str); } - if ((str = htsmsg_get_str(msg, "owner")) != NULL) + if ((str = htsmsg_get_str(msg, "owner")) != nullptr) { rec.SetOwner(str); } - if ((str = htsmsg_get_str(msg, "creator")) != NULL) + if ((str = htsmsg_get_str(msg, "creator")) != nullptr) { rec.SetCreator(str); } @@ -507,7 +507,7 @@ bool AutoRecordings::ParseAutorecAddOrUpdate(htsmsg_t* msg, bool bAdd) rec.SetFulltext(u32); } - if ((str = htsmsg_get_str(msg, "serieslinkUri")) != NULL) + if ((str = htsmsg_get_str(msg, "serieslinkUri")) != nullptr) { rec.SetSeriesLink(str); } @@ -520,7 +520,7 @@ bool AutoRecordings::ParseAutorecDelete(htsmsg_t* msg) const char* id; /* Validate/set mandatory fields */ - if ((id = htsmsg_get_str(msg, "id")) == NULL) + if ((id = htsmsg_get_str(msg, "id")) == nullptr) { Logger::Log(LogLevel::LEVEL_ERROR, "malformed autorecEntryDelete: 'id' missing"); return false; diff --git a/src/tvheadend/HTSPConnection.cpp b/src/tvheadend/HTSPConnection.cpp index 302b381a..98990b1e 100644 --- a/src/tvheadend/HTSPConnection.cpp +++ b/src/tvheadend/HTSPConnection.cpp @@ -72,7 +72,7 @@ class HTSPResponse { m_cond.Wait(mutex, m_flag, timeout); htsmsg_t* r = m_msg; - m_msg = NULL; + m_msg = nullptr; m_flag = false; return r; } @@ -98,7 +98,7 @@ class HTSPResponse HTSPConnection::HTSPConnection(IHTSPConnectionListener& connListener) : m_connListener(connListener), - m_socket(NULL), + m_socket(nullptr), m_regThread(new HTSPRegister(this)), m_ready(false), m_seq(0), @@ -106,7 +106,7 @@ HTSPConnection::HTSPConnection(IHTSPConnectionListener& connListener) m_serverVersion(""), m_htspVersion(0), m_webRoot(""), - m_challenge(NULL), + m_challenge(nullptr), m_challengeLen(0), m_suspended(false), m_state(PVR_CONNECTION_STATE_UNKNOWN) @@ -249,7 +249,7 @@ void HTSPConnection::SetState(PVR_CONNECTION_STATE state) /* Notify connection state change (callback!) */ serverString = GetServerString(); - PVR->ConnectionStateChange(serverString.c_str(), newState, NULL); + PVR->ConnectionStateChange(serverString.c_str(), newState, nullptr); } } @@ -410,7 +410,7 @@ htsmsg_t* HTSPConnection::SendAndWait0(const char* method, htsmsg_t* msg, int iR { m_messages.erase(seq); Logger::Log(LogLevel::LEVEL_ERROR, "failed to transmit"); - return NULL; + return nullptr; } /* Wait for response */ @@ -421,7 +421,7 @@ htsmsg_t* HTSPConnection::SendAndWait0(const char* method, htsmsg_t* msg, int iR Logger::Log(LogLevel::LEVEL_ERROR, "Command %s failed: No response received", method); if (!m_suspended) Disconnect(); - return NULL; + return nullptr; } /* Check result for errors and announce. */ @@ -431,16 +431,16 @@ htsmsg_t* HTSPConnection::SendAndWait0(const char* method, htsmsg_t* msg, int iR // access denied Logger::Log(LogLevel::LEVEL_ERROR, "Command %s failed: Access denied", method); htsmsg_destroy(msg); - return NULL; + return nullptr; } else { const char* strError; - if ((strError = htsmsg_get_str(msg, "error")) != NULL) + if ((strError = htsmsg_get_str(msg, "error")) != nullptr) { Logger::Log(LogLevel::LEVEL_ERROR, "Command %s failed: %s", method, strError); htsmsg_destroy(msg); - return NULL; + return nullptr; } } @@ -456,7 +456,7 @@ htsmsg_t* HTSPConnection::SendAndWait(const char* method, htsmsg_t* msg, int iRe iResponseTimeout = Settings::GetInstance().GetResponseTimeout(); if (!WaitForConnection()) - return NULL; + return nullptr; return SendAndWait0(method, msg, iResponseTimeout); } @@ -532,7 +532,7 @@ bool HTSPConnection::SendAuth(const std::string& user, const std::string& pass) /* Send and Wait */ msg = SendAndWait0("authenticate", msg); - if (msg == NULL) + if (!msg) return 0; if (m_htspVersion >= 26) @@ -652,7 +652,7 @@ void* HTSPConnection::Process() if (m_challenge) { free(m_challenge); - m_challenge = NULL; + m_challenge = nullptr; } } @@ -708,5 +708,5 @@ void* HTSPConnection::Process() m_regThread->StopThread(0); } - return NULL; + return nullptr; } diff --git a/src/tvheadend/HTSPDemuxer.cpp b/src/tvheadend/HTSPDemuxer.cpp index bb4b4905..041e87de 100644 --- a/src/tvheadend/HTSPDemuxer.cpp +++ b/src/tvheadend/HTSPDemuxer.cpp @@ -130,7 +130,7 @@ void HTSPDemuxer::Close() DemuxPacket* HTSPDemuxer::Read() { - DemuxPacket* pkt = NULL; + DemuxPacket* pkt = nullptr; m_lastUse.store(time(nullptr)); if (m_pktBuffer.Pop(pkt, 100)) @@ -629,7 +629,7 @@ bool HTSPDemuxer::AddTVHStream(uint32_t idx, const char* type, htsmsg_field_t* f stream.iCodecType == XBMC_CODEC_TYPE_RDS) { const char* language; - if ((language = htsmsg_get_str(&f->hmf_msg, "language")) != NULL) + if ((language = htsmsg_get_str(&f->hmf_msg, "language")) != nullptr) strncpy(stream.strLanguage, language, sizeof(stream.strLanguage) - 1); } @@ -694,7 +694,7 @@ void HTSPDemuxer::ParseSubscriptionStart(htsmsg_t* m) /* Validate */ htsmsg_t* l; - if ((l = htsmsg_get_list(m, "streams")) == NULL) + if ((l = htsmsg_get_list(m, "streams")) == nullptr) { Logger::Log(LogLevel::LEVEL_ERROR, "malformed subscriptionStart: 'streams' missing"); return; @@ -716,7 +716,7 @@ void HTSPDemuxer::ParseSubscriptionStart(htsmsg_t* m) continue; const char* type; - if ((type = htsmsg_get_str(&f->hmf_msg, "type")) == NULL) + if ((type = htsmsg_get_str(&f->hmf_msg, "type")) == nullptr) continue; uint32_t idx; @@ -751,34 +751,34 @@ void HTSPDemuxer::ParseSourceInfo(htsmsg_t* m) /* include position in mux name * as users might receive multiple satellite positions */ m_sourceInfo.si_mux.clear(); - if ((str = htsmsg_get_str(m, "satpos")) != NULL) + if ((str = htsmsg_get_str(m, "satpos")) != nullptr) { Logger::Log(LogLevel::LEVEL_TRACE, " satpos : %s", str); m_sourceInfo.si_mux.append(str); m_sourceInfo.si_mux.append(": "); } - if ((str = htsmsg_get_str(m, "mux")) != NULL) + if ((str = htsmsg_get_str(m, "mux")) != nullptr) { Logger::Log(LogLevel::LEVEL_TRACE, " mux : %s", str); m_sourceInfo.si_mux.append(str); } - if ((str = htsmsg_get_str(m, "adapter")) != NULL) + if ((str = htsmsg_get_str(m, "adapter")) != nullptr) { Logger::Log(LogLevel::LEVEL_TRACE, " adapter : %s", str); m_sourceInfo.si_adapter = str; } - if ((str = htsmsg_get_str(m, "network")) != NULL) + if ((str = htsmsg_get_str(m, "network")) != nullptr) { Logger::Log(LogLevel::LEVEL_TRACE, " network : %s", str); m_sourceInfo.si_network = str; } - if ((str = htsmsg_get_str(m, "provider")) != NULL) + if ((str = htsmsg_get_str(m, "provider")) != nullptr) { Logger::Log(LogLevel::LEVEL_TRACE, " provider : %s", str); m_sourceInfo.si_provider = str; } - if ((str = htsmsg_get_str(m, "service")) != NULL) + if ((str = htsmsg_get_str(m, "service")) != nullptr) { Logger::Log(LogLevel::LEVEL_TRACE, " service : %s", str); m_sourceInfo.si_service = str; @@ -862,7 +862,7 @@ void HTSPDemuxer::ParseSignalStatus(htsmsg_t* m) /* Parse */ Logger::Log(LogLevel::LEVEL_TRACE, "signalStatus:"); - if ((str = htsmsg_get_str(m, "feStatus")) != NULL) + if ((str = htsmsg_get_str(m, "feStatus")) != nullptr) { Logger::Log(LogLevel::LEVEL_TRACE, " status : %s", str); m_signalInfo.fe_status = str; diff --git a/src/tvheadend/HTSPVFS.cpp b/src/tvheadend/HTSPVFS.cpp index 112319a3..6821cec2 100644 --- a/src/tvheadend/HTSPVFS.cpp +++ b/src/tvheadend/HTSPVFS.cpp @@ -188,7 +188,7 @@ long long HTSPVFS::Size() m = m_conn.SendAndWait("fileStat", m); } - if (m == NULL) + if (!m) return -1; /* Get size. Note: 'size' field is optional. */ @@ -254,7 +254,7 @@ bool HTSPVFS::SendFileOpen(bool force) m = m_conn.SendAndWait("fileOpen", m); } - if (m == NULL) + if (!m) return false; /* Get ID */ @@ -323,7 +323,7 @@ long long HTSPVFS::SendFileSeek(int64_t pos, int whence, bool force) m = m_conn.SendAndWait("fileSeek", m); } - if (m == NULL) + if (!m) { Logger::Log(LogLevel::LEVEL_ERROR, "vfs fileSeek failed"); return -1; @@ -368,7 +368,7 @@ ssize_t HTSPVFS::SendFileRead(unsigned char* buf, unsigned int len) m = m_conn.SendAndWait("fileRead", m); } - if (m == NULL) + if (!m) { Logger::Log(LogLevel::LEVEL_ERROR, "vfs fileRead failed"); return -1; diff --git a/src/tvheadend/Subscription.cpp b/src/tvheadend/Subscription.cpp index c05728fc..063448b8 100644 --- a/src/tvheadend/Subscription.cpp +++ b/src/tvheadend/Subscription.cpp @@ -148,7 +148,7 @@ void Subscription::SendSubscribe(uint32_t channelId, uint32_t weight, bool resta m = m_conn.SendAndWait0("subscribe", m); else m = m_conn.SendAndWait("subscribe", m); - if (m == NULL) + if (!m) return; htsmsg_destroy(m); @@ -170,7 +170,7 @@ void Subscription::SendUnsubscribe() SetState(SUBSCRIPTION_STOPPED); /* Send and Wait */ - if ((m = m_conn.SendAndWait("unsubscribe", m)) == NULL) + if ((m = m_conn.SendAndWait("unsubscribe", m)) == nullptr) return; htsmsg_destroy(m); @@ -261,7 +261,7 @@ void Subscription::ParseSubscriptionStatus(htsmsg_t* m) const char* error = htsmsg_get_str(m, "subscriptionError"); /* This field is absent when everything is fine */ - if (error != NULL) + if (error) { if (!strcmp("badSignal", error)) SetState(SUBSCRIPTION_NOSIGNAL); @@ -287,7 +287,7 @@ void Subscription::ParseSubscriptionStatus(htsmsg_t* m) else { /* This field is absent when everything is fine */ - if (status != NULL) + if (status) { SetState(SUBSCRIPTION_UNKNOWN); diff --git a/src/tvheadend/TimeRecordings.cpp b/src/tvheadend/TimeRecordings.cpp index aae5f5ff..fc911d0a 100644 --- a/src/tvheadend/TimeRecordings.cpp +++ b/src/tvheadend/TimeRecordings.cpp @@ -204,7 +204,7 @@ PVR_ERROR TimeRecordings::SendTimerecAddOrUpdate(const PVR_TIMER& timer, bool up m = m_conn.SendAndWait(method.c_str(), m); } - if (m == NULL) + if (!m) return PVR_ERROR_SERVER_ERROR; /* Check for error */ @@ -235,7 +235,7 @@ PVR_ERROR TimeRecordings::SendTimerecDelete(const PVR_TIMER& timer) m = m_conn.SendAndWait("deleteTimerecEntry", m); } - if (m == NULL) + if (!m) return PVR_ERROR_SERVER_ERROR; /* Check for error */ @@ -255,7 +255,7 @@ bool TimeRecordings::ParseTimerecAddOrUpdate(htsmsg_t* msg, bool bAdd) int32_t s32; /* Validate/set mandatory fields */ - if ((str = htsmsg_get_str(msg, "id")) == NULL) + if ((str = htsmsg_get_str(msg, "id")) == nullptr) { Logger::Log(LogLevel::LEVEL_ERROR, "malformed timerecEntryAdd/timerecEntryUpdate: 'id' missing"); @@ -345,27 +345,27 @@ bool TimeRecordings::ParseTimerecAddOrUpdate(htsmsg_t* msg, bool bAdd) } /* Add optional fields */ - if ((str = htsmsg_get_str(msg, "title")) != NULL) + if ((str = htsmsg_get_str(msg, "title")) != nullptr) { rec.SetTitle(str); } - if ((str = htsmsg_get_str(msg, "name")) != NULL) + if ((str = htsmsg_get_str(msg, "name")) != nullptr) { rec.SetName(str); } - if ((str = htsmsg_get_str(msg, "directory")) != NULL) + if ((str = htsmsg_get_str(msg, "directory")) != nullptr) { rec.SetDirectory(str); } - if ((str = htsmsg_get_str(msg, "owner")) != NULL) + if ((str = htsmsg_get_str(msg, "owner")) != nullptr) { rec.SetOwner(str); } - if ((str = htsmsg_get_str(msg, "creator")) != NULL) + if ((str = htsmsg_get_str(msg, "creator")) != nullptr) { rec.SetCreator(str); } @@ -391,7 +391,7 @@ bool TimeRecordings::ParseTimerecDelete(htsmsg_t* msg) const char* id; /* Validate/set mandatory fields */ - if ((id = htsmsg_get_str(msg, "id")) == NULL) + if ((id = htsmsg_get_str(msg, "id")) == nullptr) { Logger::Log(LogLevel::LEVEL_ERROR, "malformed timerecEntryDelete: 'id' missing"); return false; diff --git a/src/tvheadend/entity/RecordingBase.cpp b/src/tvheadend/entity/RecordingBase.cpp index bd08e66e..8494d193 100644 --- a/src/tvheadend/entity/RecordingBase.cpp +++ b/src/tvheadend/entity/RecordingBase.cpp @@ -152,7 +152,7 @@ time_t RecordingBase::LocaltimeToUTC(int32_t lctime) /* Note: lctime contains minutes from midnight (up to 24*60) as local time. */ /* complete lctime with current year, month, day, ... */ - time_t t = time(NULL); + time_t t = time(nullptr); struct tm* tm_time = localtime(&t); tm_time->tm_hour = lctime / 60; From 0a6a80a9ccde4fce385b267c4a92f145153dccd5 Mon Sep 17 00:00:00 2001 From: Kai Sommerfeld Date: Fri, 18 Oct 2019 12:57:37 +0200 Subject: [PATCH 05/10] code cleanup: get rid of assignments in if-clauses. --- src/Tvheadend.cpp | 178 ++++++++++++++++++++----------- src/tvheadend/AutoRecordings.cpp | 39 +++---- src/tvheadend/HTSPConnection.cpp | 23 ++-- src/tvheadend/HTSPDemuxer.cpp | 52 +++++---- src/tvheadend/Subscription.cpp | 3 +- src/tvheadend/TimeRecordings.cpp | 34 +++--- src/tvheadend/entity/Tag.cpp | 4 +- 7 files changed, 193 insertions(+), 140 deletions(-) diff --git a/src/Tvheadend.cpp b/src/Tvheadend.cpp index d04806af..ff494e61 100644 --- a/src/Tvheadend.cpp +++ b/src/Tvheadend.cpp @@ -146,10 +146,9 @@ void CTvheadend::QueryAvailableProfiles() if (!m) return; - htsmsg_t* l; - htsmsg_field_t* f; + htsmsg_t* l = htsmsg_get_list(m, "profiles"); - if ((l = htsmsg_get_list(m, "profiles")) == nullptr) + if (!l) { Logger::Log(LogLevel::LEVEL_ERROR, "malformed getProfiles: 'profiles' missing"); htsmsg_destroy(m); @@ -157,16 +156,21 @@ void CTvheadend::QueryAvailableProfiles() } /* Process */ + htsmsg_field_t* f = nullptr; HTSMSG_FOREACH(f, l) { - const char* str; Profile profile; - if ((str = htsmsg_get_str(&f->hmf_msg, "uuid")) != nullptr) + const char* str = htsmsg_get_str(&f->hmf_msg, "uuid"); + if (str) profile.SetUuid(str); - if ((str = htsmsg_get_str(&f->hmf_msg, "name")) != nullptr) + + str = htsmsg_get_str(&f->hmf_msg, "name"); + if (str) profile.SetName(str); - if ((str = htsmsg_get_str(&f->hmf_msg, "comment")) != nullptr) + + str = htsmsg_get_str(&f->hmf_msg, "comment"); + if (str) profile.SetComment(str); Logger::Log(LogLevel::LEVEL_DEBUG, "profile name: %s, comment: %s added", @@ -348,8 +352,8 @@ PVR_ERROR CTvheadend::SendDvrDelete(uint32_t id, const char* method) 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()))) == nullptr) + m = m_conn->SendAndWait(method, m, std::max(30000, Settings::GetInstance().GetResponseTimeout())); + if (!m) return PVR_ERROR_SERVER_ERROR; /* Check for error */ @@ -407,7 +411,6 @@ PVR_ERROR CTvheadend::GetRecordings(ADDON_HANDLE handle) std::vector recs; { CLockObject lock(m_mutex); - Channels::const_iterator cit; char buf[128]; for (const auto& entry : m_recordings) @@ -421,10 +424,9 @@ PVR_ERROR CTvheadend::GetRecordings(ADDON_HANDLE handle) PVR_RECORDING rec = {0}; /* Channel icon */ - if ((cit = m_channels.find(recording.GetChannel())) != m_channels.end()) - { + const auto& cit = m_channels.find(recording.GetChannel()); + if (cit != m_channels.end()) strncpy(rec.strIconPath, cit->second.GetIcon().c_str(), sizeof(rec.strIconPath) - 1); - } /* Channel name */ strncpy(rec.strChannelName, recording.GetChannelName().c_str(), @@ -542,7 +544,6 @@ PVR_ERROR CTvheadend::GetRecordings(ADDON_HANDLE handle) PVR_ERROR CTvheadend::GetRecordingEdl(const PVR_RECORDING& rec, PVR_EDL_ENTRY edl[], int* num) { - htsmsg_t* list; htsmsg_field_t* f; int idx; @@ -556,12 +557,14 @@ PVR_ERROR CTvheadend::GetRecordingEdl(const PVR_RECORDING& rec, PVR_EDL_ENTRY ed { CLockObject lock(m_conn->Mutex()); - if ((m = m_conn->SendAndWait("getDvrCutpoints", m)) == nullptr) + m = m_conn->SendAndWait("getDvrCutpoints", m); + if (!m) return PVR_ERROR_SERVER_ERROR; } /* Check for optional "cutpoints" reply message field */ - if (!(list = htsmsg_get_list(m, "cutpoints"))) + htsmsg_t* list = htsmsg_get_list(m, "cutpoints"); + if (!list) { *num = 0; htsmsg_destroy(m); @@ -1446,14 +1449,14 @@ PVR_ERROR CTvheadend::GetEPGForChannel(ADDON_HANDLE handle, { CLockObject lock(m_conn->Mutex()); - if ((msg = m_conn->SendAndWait0("getEvents", msg)) == nullptr) + msg = m_conn->SendAndWait0("getEvents", msg); + if (!msg) return PVR_ERROR_SERVER_ERROR; } /* Process */ - htsmsg_t* l; - - if (!(l = htsmsg_get_list(msg, "events"))) + htsmsg_t* l = htsmsg_get_list(msg, "events"); + if (!l) { htsmsg_destroy(msg); Logger::Log(LogLevel::LEVEL_ERROR, "malformed getEvents response: 'events' missing"); @@ -1550,7 +1553,8 @@ bool CTvheadend::Connected() else htsmsg_add_u32(msg, "epg", 0); - if ((msg = m_conn->SendAndWait0("enableAsyncMetadata", msg)) == nullptr) + msg = m_conn->SendAndWait0("enableAsyncMetadata", msg); + if (!msg) { m_asyncState.SetState(ASYNC_NONE); return false; @@ -2022,8 +2026,6 @@ void CTvheadend::SyncEpgCompleted() void CTvheadend::ParseTagAddOrUpdate(htsmsg_t* msg, bool bAdd) { uint32_t u32; - const char* str; - htsmsg_t* list; /* Validate */ if (htsmsg_get_u32(msg, "tagId", &u32)) @@ -2045,8 +2047,11 @@ void CTvheadend::ParseTagAddOrUpdate(htsmsg_t* msg, bool bAdd) tag.SetIndex(u32); /* Name */ - if ((str = htsmsg_get_str(msg, "tagName")) != nullptr) + const char* str = htsmsg_get_str(msg, "tagName"); + if (str) + { tag.SetName(str); + } else if (bAdd) { Logger::Log(LogLevel::LEVEL_ERROR, "malformed tagAdd: 'tagName' missing"); @@ -2054,11 +2059,13 @@ void CTvheadend::ParseTagAddOrUpdate(htsmsg_t* msg, bool bAdd) } /* Icon */ - if ((str = htsmsg_get_str(msg, "tagIcon")) != nullptr) + str = htsmsg_get_str(msg, "tagIcon"); + if (str) tag.SetIcon(GetImageURL(str)); /* Members */ - if ((list = htsmsg_get_list(msg, "members")) != nullptr) + htsmsg_t* list = htsmsg_get_list(msg, "members"); + if (list) { htsmsg_field_t* f; HTSMSG_FOREACH(f, list) @@ -2101,8 +2108,6 @@ void CTvheadend::ParseTagDelete(htsmsg_t* msg) void CTvheadend::ParseChannelAddOrUpdate(htsmsg_t* msg, bool bAdd) { uint32_t u32; - const char* str; - htsmsg_t* list; /* Validate */ if (htsmsg_get_u32(msg, "channelId", &u32)) @@ -2118,8 +2123,11 @@ void CTvheadend::ParseChannelAddOrUpdate(htsmsg_t* msg, bool bAdd) channel.SetDirty(false); /* Channel name */ - if ((str = htsmsg_get_str(msg, "channelName")) != nullptr) + const char* str = htsmsg_get_str(msg, "channelName"); + if (str) + { channel.SetName(str); + } else if (bAdd) { Logger::Log(LogLevel::LEVEL_ERROR, "malformed channelAdd: 'channelName' missing"); @@ -2146,13 +2154,15 @@ void CTvheadend::ParseChannelAddOrUpdate(htsmsg_t* msg, bool bAdd) channel.SetNumMinor(u32); /* Channel icon */ - if ((str = htsmsg_get_str(msg, "channelIcon")) != nullptr) + str = htsmsg_get_str(msg, "channelIcon"); + if (str) channel.SetIcon(GetImageURL(str)); /* Services */ - if ((list = htsmsg_get_list(msg, "services")) != nullptr) + htsmsg_t* list = htsmsg_get_list(msg, "services"); + if (list) { - htsmsg_field_t* f; + htsmsg_field_t* f = nullptr; uint32_t caid = 0; HTSMSG_FOREACH(f, list) { @@ -2167,7 +2177,8 @@ void CTvheadend::ParseChannelAddOrUpdate(htsmsg_t* msg, bool bAdd) } else { - if ((str = htsmsg_get_str(&f->hmf_msg, "type")) != nullptr) + str = htsmsg_get_str(&f->hmf_msg, "type"); + if (str) { if (!strcmp(str, "Radio")) channel.SetType(CHANNEL_TYPE_RADIO); @@ -2220,7 +2231,6 @@ void CTvheadend::ParseChannelDelete(htsmsg_t* msg) 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; int64_t start, stop, startExtra, stopExtra; @@ -2289,10 +2299,9 @@ void CTvheadend::ParseRecordingAddOrUpdate(htsmsg_t* msg, bool bAdd) } } - htsmsg_t *files, *streams; - if ((files = htsmsg_get_list(msg, "files")) != nullptr) + htsmsg_t* files = htsmsg_get_list(msg, "files"); + if (files) { - htsmsg_field_t *file, *stream; uint32_t u32; int64_t s64; bool needChannelType = !rec.GetChannelType() && m_conn->GetProtocol() >= 25; @@ -2302,6 +2311,7 @@ void CTvheadend::ParseRecordingAddOrUpdate(htsmsg_t* msg, bool bAdd) start = 0; stop = 0; + htsmsg_field_t* file = nullptr; HTSMSG_FOREACH(file, files) // Loop through all files { if (file->hmf_type != HMF_MAP) @@ -2309,8 +2319,10 @@ void CTvheadend::ParseRecordingAddOrUpdate(htsmsg_t* msg, bool bAdd) if (needChannelType && !(hasAudio && hasVideo)) { - if ((streams = htsmsg_get_list(&file->hmf_msg, "info")) != nullptr) + htsmsg_t* streams = htsmsg_get_list(&file->hmf_msg, "info"); + if (streams) { + htsmsg_field_t* stream = nullptr; HTSMSG_FOREACH(stream, streams) // Loop through all streams { if (stream->hmf_type != HMF_MAP) @@ -2346,7 +2358,8 @@ void CTvheadend::ParseRecordingAddOrUpdate(htsmsg_t* msg, bool bAdd) /* Channel name fallback (in case channel was deleted) */ if (rec.GetChannelName().empty() && m_conn->GetProtocol() >= 25) { - if ((str = htsmsg_get_str(msg, "channelName")) != nullptr) + const char* str = htsmsg_get_str(msg, "channelName"); + if (str) rec.SetChannelName(str); } @@ -2412,7 +2425,8 @@ void CTvheadend::ParseRecordingAddOrUpdate(htsmsg_t* msg, bool bAdd) } /* Parse state */ - if ((state = htsmsg_get_str(msg, "state")) != nullptr) + const char* state = htsmsg_get_str(msg, "state"); + if (state) { if (strstr(state, "scheduled")) rec.SetState(PVR_TIMER_STATE_SCHEDULED); @@ -2436,25 +2450,48 @@ void CTvheadend::ParseRecordingAddOrUpdate(htsmsg_t* msg, bool bAdd) rec.SetEventId(eventId); if (!htsmsg_get_u32(msg, "enabled", &enabled)) rec.SetEnabled(enabled); - if ((str = htsmsg_get_str(msg, "title")) != nullptr) + + const char* str = htsmsg_get_str(msg, "title"); + if (str) rec.SetTitle(str); - if ((str = htsmsg_get_str(msg, "subtitle")) != nullptr) + + str = htsmsg_get_str(msg, "subtitle"); + if (str) rec.SetSubtitle(str); - if ((str = htsmsg_get_str(msg, "path")) != nullptr) + + str = htsmsg_get_str(msg, "path"); + if (str) rec.SetPath(str); - if ((str = htsmsg_get_str(msg, "description")) != nullptr) - rec.SetDescription(str); - else if ((str = htsmsg_get_str(msg, "summary")) != nullptr) + + str = htsmsg_get_str(msg, "description"); + if (str) + { rec.SetDescription(str); + } + else + { + str = htsmsg_get_str(msg, "summary"); + if (str) + rec.SetDescription(str); + } + if (!htsmsg_get_u32(msg, "contentType", &contentType)) rec.SetContentType(contentType); - if ((str = htsmsg_get_str(msg, "timerecId")) != nullptr) + + str = htsmsg_get_str(msg, "timerecId"); + if (str) rec.SetTimerecId(str); - if ((str = htsmsg_get_str(msg, "autorecId")) != nullptr) + + str = htsmsg_get_str(msg, "autorecId"); + if (str) rec.SetAutorecId(str); - if ((str = htsmsg_get_str(msg, "image")) != nullptr) + + str = htsmsg_get_str(msg, "image"); + if (str) rec.SetImage(GetImageURL(str)); - if ((str = htsmsg_get_str(msg, "fanartImage")) != nullptr) + + str = htsmsg_get_str(msg, "fanartImage"); + if (str) rec.SetFanartImage(GetImageURL(str)); if (m_conn->GetProtocol() >= 32) @@ -2474,7 +2511,8 @@ void CTvheadend::ParseRecordingAddOrUpdate(htsmsg_t* msg, bool bAdd) } /* Error */ - if ((str = htsmsg_get_str(msg, "error")) != nullptr) + str = htsmsg_get_str(msg, "error"); + if (str) { if (!strcmp(str, "300")) rec.SetState(PVR_TIMER_STATE_ABORTED); @@ -2489,7 +2527,8 @@ void CTvheadend::ParseRecordingAddOrUpdate(htsmsg_t* msg, bool bAdd) { /* Parse subscription error */ /* This field is absent when everything is fine or when htsp version < 20 */ - if ((str = htsmsg_get_str(msg, "subscriptionError")) != nullptr) + str = htsmsg_get_str(msg, "subscriptionError"); + if (str) { /* No free adapter, AKA subscription conflict */ if (!strcmp("noFreeAdapter", str)) @@ -2560,7 +2599,6 @@ void CTvheadend::ParseRecordingDelete(htsmsg_t* msg) bool CTvheadend::ParseEvent(htsmsg_t* msg, bool bAdd, Event& evt) { - const char* str; uint32_t u32, id, channel; int64_t s64, start, stop; @@ -2598,16 +2636,26 @@ bool CTvheadend::ParseEvent(htsmsg_t* msg, bool bAdd, Event& evt) evt.SetStop(static_cast(stop)); /* Add optional fields */ - if ((str = htsmsg_get_str(msg, "title")) != nullptr) + const char* str = htsmsg_get_str(msg, "title"); + if (str) evt.SetTitle(str); - if ((str = htsmsg_get_str(msg, "subtitle")) != nullptr) + + str = htsmsg_get_str(msg, "subtitle"); + if (str) evt.SetSubtitle(str); - if ((str = htsmsg_get_str(msg, "summary")) != nullptr) + + str = htsmsg_get_str(msg, "summary"); + if (str) evt.SetSummary(str); - if ((str = htsmsg_get_str(msg, "description")) != nullptr) + + str = htsmsg_get_str(msg, "description"); + if (str) evt.SetDesc(str); - if ((str = htsmsg_get_str(msg, "image")) != nullptr) + + str = htsmsg_get_str(msg, "image"); + if (str) evt.SetImage(GetImageURL(str)); + if (!htsmsg_get_u32(msg, "nextEventId", &u32)) evt.SetNext(u32); if (!htsmsg_get_u32(msg, "contentType", &u32)) @@ -2624,8 +2672,11 @@ bool CTvheadend::ParseEvent(htsmsg_t* msg, bool bAdd, Event& evt) evt.SetEpisode(u32); if (!htsmsg_get_u32(msg, "partNumber", &u32)) evt.SetPart(u32); - if ((str = htsmsg_get_str(msg, "serieslinkUri")) != nullptr) + + str = htsmsg_get_str(msg, "serieslinkUri"); + if (str) evt.SetSeriesLink(str); + if (!htsmsg_get_u32(msg, "copyrightYear", &u32)) evt.SetYear(u32); if (!htsmsg_get_u32(msg, "dvrId", &u32)) @@ -2656,14 +2707,14 @@ bool CTvheadend::ParseEvent(htsmsg_t* msg, bool bAdd, Event& evt) } } - htsmsg_t* l; - if ((l = htsmsg_get_map(msg, "credits")) != nullptr) + htsmsg_t* l = htsmsg_get_map(msg, "credits"); + if (l) { std::vector writers; std::vector directors; std::vector cast; - htsmsg_field_t* f; + htsmsg_field_t* f = nullptr; HTSMSG_FOREACH(f, l) { if (!f->hmf_name) @@ -2686,7 +2737,8 @@ bool CTvheadend::ParseEvent(htsmsg_t* msg, bool bAdd, Event& evt) evt.SetCast(cast); } - if ((l = htsmsg_get_list(msg, "category")) != nullptr) + l = htsmsg_get_list(msg, "category"); + if (l) { std::vector categories; diff --git a/src/tvheadend/AutoRecordings.cpp b/src/tvheadend/AutoRecordings.cpp index e02cbdb0..ad1620d0 100644 --- a/src/tvheadend/AutoRecordings.cpp +++ b/src/tvheadend/AutoRecordings.cpp @@ -344,13 +344,13 @@ PVR_ERROR AutoRecordings::SendAutorecDelete(const PVR_TIMER& timer) bool AutoRecordings::ParseAutorecAddOrUpdate(htsmsg_t* msg, bool bAdd) { - const char* str; uint32_t u32; int32_t s32; int64_t s64; /* Validate/set mandatory fields */ - if ((str = htsmsg_get_str(msg, "id")) == nullptr) + const char* str = htsmsg_get_str(msg, "id"); + if (!str) { Logger::Log(LogLevel::LEVEL_ERROR, "malformed autorecEntryAdd/autorecEntryUpdate: 'id' missing"); @@ -470,30 +470,25 @@ bool AutoRecordings::ParseAutorecAddOrUpdate(htsmsg_t* msg, bool bAdd) } /* Add optional fields */ - if ((str = htsmsg_get_str(msg, "title")) != nullptr) - { + str = htsmsg_get_str(msg, "title"); + if (str) rec.SetTitle(str); - } - if ((str = htsmsg_get_str(msg, "name")) != nullptr) - { + str = htsmsg_get_str(msg, "name"); + if (str) rec.SetName(str); - } - if ((str = htsmsg_get_str(msg, "directory")) != nullptr) - { + str = htsmsg_get_str(msg, "directory"); + if (str) rec.SetDirectory(str); - } - if ((str = htsmsg_get_str(msg, "owner")) != nullptr) - { + str = htsmsg_get_str(msg, "owner"); + if (str) rec.SetOwner(str); - } - if ((str = htsmsg_get_str(msg, "creator")) != nullptr) - { + str = htsmsg_get_str(msg, "creator"); + if (str) rec.SetCreator(str); - } if (!htsmsg_get_u32(msg, "channel", &u32)) { @@ -507,20 +502,18 @@ bool AutoRecordings::ParseAutorecAddOrUpdate(htsmsg_t* msg, bool bAdd) rec.SetFulltext(u32); } - if ((str = htsmsg_get_str(msg, "serieslinkUri")) != nullptr) - { + str = htsmsg_get_str(msg, "serieslinkUri"); + if (str) rec.SetSeriesLink(str); - } return true; } bool AutoRecordings::ParseAutorecDelete(htsmsg_t* msg) { - const char* id; - /* Validate/set mandatory fields */ - if ((id = htsmsg_get_str(msg, "id")) == nullptr) + const char* id = htsmsg_get_str(msg, "id"); + if (!id) { Logger::Log(LogLevel::LEVEL_ERROR, "malformed autorecEntryDelete: 'id' missing"); return false; diff --git a/src/tvheadend/HTSPConnection.cpp b/src/tvheadend/HTSPConnection.cpp index 98990b1e..89050bd9 100644 --- a/src/tvheadend/HTSPConnection.cpp +++ b/src/tvheadend/HTSPConnection.cpp @@ -309,7 +309,8 @@ bool HTSPConnection::ReadMessage() } /* Deserialize */ - if (!(msg = htsmsg_binary_deserialize(buf, len, buf))) + msg = htsmsg_binary_deserialize(buf, len, buf); + if (!msg) { /* Do not free buf here. Already done by htsmsg_binary_deserialize. */ Logger::Log(LogLevel::LEVEL_ERROR, "failed to decode message"); @@ -321,8 +322,8 @@ bool HTSPConnection::ReadMessage() { Logger::Log(LogLevel::LEVEL_TRACE, "received response [%d]", seq); CLockObject lock(m_mutex); - HTSPResponseList::iterator it; - if ((it = m_messages.find(seq)) != m_messages.end()) + HTSPResponseList::iterator it = m_messages.find(seq); + if (it != m_messages.end()) { it->second->Set(msg); return true; @@ -330,7 +331,8 @@ bool HTSPConnection::ReadMessage() } /* Get method */ - if (!(method = htsmsg_get_str(msg, "method"))) + method = htsmsg_get_str(msg, "method"); + if (!method) { Logger::Log(LogLevel::LEVEL_ERROR, "message without a method"); htsmsg_destroy(msg); @@ -435,8 +437,8 @@ htsmsg_t* HTSPConnection::SendAndWait0(const char* method, htsmsg_t* msg, int iR } else { - const char* strError; - if ((strError = htsmsg_get_str(msg, "error")) != nullptr) + const char* strError = htsmsg_get_str(msg, "error"); + if (strError) { Logger::Log(LogLevel::LEVEL_ERROR, "Command %s failed: %s", method, strError); htsmsg_destroy(msg); @@ -468,14 +470,14 @@ bool HTSPConnection::SendHello() htsmsg_add_u32(msg, "htspversion", HTSP_CLIENT_VERSION); /* Send and Wait */ - if (!(msg = SendAndWait0("hello", msg))) + msg = SendAndWait0("hello", msg); + if (!msg) return false; /* Process */ const char* webroot; const void* chal; size_t chal_len; - htsmsg_t* cap; /* Basic Info */ webroot = htsmsg_get_str(msg, "webroot"); @@ -487,9 +489,10 @@ bool HTSPConnection::SendHello() m_serverVersion.c_str(), m_htspVersion); /* Capabilities */ - if ((cap = htsmsg_get_list(msg, "servercapability"))) + htsmsg_t* cap = htsmsg_get_list(msg, "servercapability"); + if (cap) { - htsmsg_field_t* f; + htsmsg_field_t* f = nullptr; HTSMSG_FOREACH(f, cap) { if (f->hmf_type == HMF_STR) diff --git a/src/tvheadend/HTSPDemuxer.cpp b/src/tvheadend/HTSPDemuxer.cpp index 041e87de..5c0d47c6 100644 --- a/src/tvheadend/HTSPDemuxer.cpp +++ b/src/tvheadend/HTSPDemuxer.cpp @@ -476,7 +476,6 @@ void HTSPDemuxer::ParseMuxPacket(htsmsg_t* m) int64_t s64; const void* bin; size_t binlen; - DemuxPacket* pkt; char type = 0; int ignore; @@ -509,8 +508,10 @@ void HTSPDemuxer::ParseMuxPacket(htsmsg_t* m) m_streamStat[idx]++; /* Allocate buffer */ - if (!(pkt = PVR->AllocateDemuxPacket(binlen))) + DemuxPacket* pkt = PVR->AllocateDemuxPacket(binlen); + if (!pkt) return; + memcpy(pkt->pData, bin, binlen); pkt->iSize = binlen; pkt->iStreamId = idx; @@ -628,8 +629,8 @@ bool HTSPDemuxer::AddTVHStream(uint32_t idx, const char* type, htsmsg_field_t* f if (stream.iCodecType == XBMC_CODEC_TYPE_SUBTITLE || stream.iCodecType == XBMC_CODEC_TYPE_AUDIO || stream.iCodecType == XBMC_CODEC_TYPE_RDS) { - const char* language; - if ((language = htsmsg_get_str(&f->hmf_msg, "language")) != nullptr) + const char* language = htsmsg_get_str(&f->hmf_msg, "language"); + if (language) strncpy(stream.strLanguage, language, sizeof(stream.strLanguage) - 1); } @@ -665,8 +666,8 @@ bool HTSPDemuxer::AddTVHStream(uint32_t idx, const char* type, htsmsg_field_t* f /* Setting aspect ratio to zero will cause XBMC to handle changes in it */ stream.fAspect = 0.0f; - uint32_t duration; - if ((duration = htsmsg_get_u32_or_default(&f->hmf_msg, "duration", 0)) > 0) + uint32_t duration = htsmsg_get_u32_or_default(&f->hmf_msg, "duration", 0); + if (duration > 0) { stream.iFPSScale = duration; stream.iFPSRate = DVD_TIME_BASE; @@ -692,9 +693,8 @@ bool HTSPDemuxer::AddTVHStream(uint32_t idx, const char* type, htsmsg_field_t* f void HTSPDemuxer::ParseSubscriptionStart(htsmsg_t* m) { /* Validate */ - htsmsg_t* l; - - if ((l = htsmsg_get_list(m, "streams")) == nullptr) + htsmsg_t* l = htsmsg_get_list(m, "streams"); + if (!l) { Logger::Log(LogLevel::LEVEL_ERROR, "malformed subscriptionStart: 'streams' missing"); return; @@ -715,8 +715,8 @@ void HTSPDemuxer::ParseSubscriptionStart(htsmsg_t* m) if (f->hmf_type != HMF_MAP) continue; - const char* type; - if ((type = htsmsg_get_str(&f->hmf_msg, "type")) == nullptr) + const char* type = htsmsg_get_str(&f->hmf_msg, "type"); + if (!type) continue; uint32_t idx; @@ -740,8 +740,6 @@ void HTSPDemuxer::ParseSubscriptionStart(htsmsg_t* m) void HTSPDemuxer::ParseSourceInfo(htsmsg_t* m) { - const char* str; - /* Ignore */ if (!m) return; @@ -751,34 +749,45 @@ void HTSPDemuxer::ParseSourceInfo(htsmsg_t* m) /* include position in mux name * as users might receive multiple satellite positions */ m_sourceInfo.si_mux.clear(); - if ((str = htsmsg_get_str(m, "satpos")) != nullptr) + + const char* str = htsmsg_get_str(m, "satpos"); + if (str) { Logger::Log(LogLevel::LEVEL_TRACE, " satpos : %s", str); m_sourceInfo.si_mux.append(str); m_sourceInfo.si_mux.append(": "); } - if ((str = htsmsg_get_str(m, "mux")) != nullptr) + + str = htsmsg_get_str(m, "mux"); + if (str) { Logger::Log(LogLevel::LEVEL_TRACE, " mux : %s", str); m_sourceInfo.si_mux.append(str); } - if ((str = htsmsg_get_str(m, "adapter")) != nullptr) + str = htsmsg_get_str(m, "adapter"); + if (str) { Logger::Log(LogLevel::LEVEL_TRACE, " adapter : %s", str); m_sourceInfo.si_adapter = str; } - if ((str = htsmsg_get_str(m, "network")) != nullptr) + + str = htsmsg_get_str(m, "network"); + if (str) { Logger::Log(LogLevel::LEVEL_TRACE, " network : %s", str); m_sourceInfo.si_network = str; } - if ((str = htsmsg_get_str(m, "provider")) != nullptr) + + str = htsmsg_get_str(m, "provider"); + if (str) { Logger::Log(LogLevel::LEVEL_TRACE, " provider : %s", str); m_sourceInfo.si_provider = str; } - if ((str = htsmsg_get_str(m, "service")) != nullptr) + + str = htsmsg_get_str(m, "service"); + if (str) { Logger::Log(LogLevel::LEVEL_TRACE, " service : %s", str); m_sourceInfo.si_service = str; @@ -853,7 +862,6 @@ void HTSPDemuxer::ParseQueueStatus(htsmsg_t* m) void HTSPDemuxer::ParseSignalStatus(htsmsg_t* m) { uint32_t u32; - const char* str; CLockObject lock(m_mutex); @@ -862,7 +870,9 @@ void HTSPDemuxer::ParseSignalStatus(htsmsg_t* m) /* Parse */ Logger::Log(LogLevel::LEVEL_TRACE, "signalStatus:"); - if ((str = htsmsg_get_str(m, "feStatus")) != nullptr) + + const char* str = htsmsg_get_str(m, "feStatus"); + if (str) { Logger::Log(LogLevel::LEVEL_TRACE, " status : %s", str); m_signalInfo.fe_status = str; diff --git a/src/tvheadend/Subscription.cpp b/src/tvheadend/Subscription.cpp index 063448b8..96071ac2 100644 --- a/src/tvheadend/Subscription.cpp +++ b/src/tvheadend/Subscription.cpp @@ -170,7 +170,8 @@ void Subscription::SendUnsubscribe() SetState(SUBSCRIPTION_STOPPED); /* Send and Wait */ - if ((m = m_conn.SendAndWait("unsubscribe", m)) == nullptr) + m = m_conn.SendAndWait("unsubscribe", m); + if (!m) return; htsmsg_destroy(m); diff --git a/src/tvheadend/TimeRecordings.cpp b/src/tvheadend/TimeRecordings.cpp index fc911d0a..73cb42f4 100644 --- a/src/tvheadend/TimeRecordings.cpp +++ b/src/tvheadend/TimeRecordings.cpp @@ -250,12 +250,12 @@ PVR_ERROR TimeRecordings::SendTimerecDelete(const PVR_TIMER& timer) bool TimeRecordings::ParseTimerecAddOrUpdate(htsmsg_t* msg, bool bAdd) { - const char* str; uint32_t u32; int32_t s32; /* Validate/set mandatory fields */ - if ((str = htsmsg_get_str(msg, "id")) == nullptr) + const char* str = htsmsg_get_str(msg, "id"); + if (!str) { Logger::Log(LogLevel::LEVEL_ERROR, "malformed timerecEntryAdd/timerecEntryUpdate: 'id' missing"); @@ -345,30 +345,25 @@ bool TimeRecordings::ParseTimerecAddOrUpdate(htsmsg_t* msg, bool bAdd) } /* Add optional fields */ - if ((str = htsmsg_get_str(msg, "title")) != nullptr) - { + str = htsmsg_get_str(msg, "title"); + if (str) rec.SetTitle(str); - } - if ((str = htsmsg_get_str(msg, "name")) != nullptr) - { + str = htsmsg_get_str(msg, "name"); + if (str) rec.SetName(str); - } - if ((str = htsmsg_get_str(msg, "directory")) != nullptr) - { + str = htsmsg_get_str(msg, "directory"); + if (str) rec.SetDirectory(str); - } - if ((str = htsmsg_get_str(msg, "owner")) != nullptr) - { + str = htsmsg_get_str(msg, "owner"); + if (str) rec.SetOwner(str); - } - if ((str = htsmsg_get_str(msg, "creator")) != nullptr) - { + str = htsmsg_get_str(msg, "creator"); + if (str) rec.SetCreator(str); - } if (!htsmsg_get_u32(msg, "channel", &u32)) { @@ -388,10 +383,9 @@ bool TimeRecordings::ParseTimerecAddOrUpdate(htsmsg_t* msg, bool bAdd) bool TimeRecordings::ParseTimerecDelete(htsmsg_t* msg) { - const char* id; - /* Validate/set mandatory fields */ - if ((id = htsmsg_get_str(msg, "id")) == nullptr) + const char* id = htsmsg_get_str(msg, "id"); + if (!id) { Logger::Log(LogLevel::LEVEL_ERROR, "malformed timerecEntryDelete: 'id' missing"); return false; diff --git a/src/tvheadend/entity/Tag.cpp b/src/tvheadend/entity/Tag.cpp index 244073f6..04e2be6d 100644 --- a/src/tvheadend/entity/Tag.cpp +++ b/src/tvheadend/entity/Tag.cpp @@ -77,11 +77,11 @@ std::vector& Tag::GetChannels() bool Tag::ContainsChannelType(channel_type_t eType, const Channels& channels) const { std::vector::const_iterator it; - Channels::const_iterator cit; for (it = m_channels.begin(); it != m_channels.end(); ++it) { - if ((cit = channels.find(*it)) != channels.end()) + const auto cit = channels.find(*it); + if (cit != channels.end()) { if (cit->second.GetType() == eType) return true; From 648736495ac27c5f2fdcea66f16d86d2a543c9d8 Mon Sep 17 00:00:00 2001 From: Kai Sommerfeld Date: Fri, 18 Oct 2019 23:17:45 +0200 Subject: [PATCH 06/10] code cleanup: declare variables where they are actually first needed. --- src/Tvheadend.cpp | 136 +++++++++++++------------ src/tvheadend/AutoRecordings.cpp | 12 +-- src/tvheadend/HTSPConnection.cpp | 67 ++++++------ src/tvheadend/HTSPDemuxer.cpp | 77 +++++++------- src/tvheadend/HTSPVFS.cpp | 24 ++--- src/tvheadend/TimeRecordings.cpp | 10 +- src/tvheadend/entity/AutoRecording.cpp | 2 + src/tvheadend/utilities/Logger.cpp | 4 +- 8 files changed, 164 insertions(+), 168 deletions(-) diff --git a/src/Tvheadend.cpp b/src/Tvheadend.cpp index ff494e61..bc535753 100644 --- a/src/Tvheadend.cpp +++ b/src/Tvheadend.cpp @@ -90,7 +90,6 @@ void CTvheadend::Stop() PVR_ERROR CTvheadend::GetDriveSpace(long long* total, long long* used) { - int64_t s64; CLockObject lock(m_conn->Mutex()); htsmsg_t* m = htsmsg_create_map(); @@ -98,6 +97,7 @@ PVR_ERROR CTvheadend::GetDriveSpace(long long* total, long long* used) if (!m) return PVR_ERROR_SERVER_ERROR; + int64_t s64 = 0; if (htsmsg_get_s64(m, "totaldiskspace", &s64)) goto error; *total = s64 / 1024; @@ -225,12 +225,12 @@ PVR_ERROR CTvheadend::GetTags(ADDON_HANDLE handle, bool bRadio) strncpy(tag.strGroupName, entry.second.GetName().c_str(), sizeof(tag.strGroupName) - 1); tag.bIsRadio = bRadio; tag.iPosition = entry.second.GetIndex(); + tags.emplace_back(tag); } } - std::vector::const_iterator it; - for (it = tags.begin(); it != tags.end(); ++it) + for (auto it = tags.begin(); it != tags.end(); ++it) { /* Callback. */ PVR->TransferChannelGroup(handle, &(*it)); @@ -268,14 +268,14 @@ PVR_ERROR CTvheadend::GetTagMembers(ADDON_HANDLE handle, const PVR_CHANNEL_GROUP gm.iChannelUniqueId = cit->second.GetId(); gm.iChannelNumber = cit->second.GetNum(); gm.iSubChannelNumber = cit->second.GetNumMinor(); + gms.emplace_back(gm); } } } } - std::vector::const_iterator it; - for (it = gms.begin(); it != gms.end(); ++it) + for (auto it = gms.begin(); it != gms.end(); ++it) { /* Callback. */ PVR->TransferChannelGroupMember(handle, &(*it)); @@ -314,7 +314,6 @@ PVR_ERROR CTvheadend::GetChannels(ADDON_HANDLE handle, bool radio) continue; PVR_CHANNEL chn = {0}; - chn.iUniqueId = channel.GetId(); chn.bIsRadio = radio; chn.iChannelNumber = channel.GetNum(); @@ -323,12 +322,12 @@ PVR_ERROR CTvheadend::GetChannels(ADDON_HANDLE handle, bool radio) 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); } } - std::vector::const_iterator it; - for (it = channels.begin(); it != channels.end(); ++it) + for (auto it = channels.begin(); it != channels.end(); ++it) { /* Callback. */ PVR->TransferChannelEntry(handle, &(*it)); @@ -343,8 +342,6 @@ PVR_ERROR CTvheadend::GetChannels(ADDON_HANDLE handle, bool radio) PVR_ERROR CTvheadend::SendDvrDelete(uint32_t id, const char* method) { - uint32_t u32; - CLockObject lock(m_conn->Mutex()); /* Build message */ @@ -357,6 +354,7 @@ PVR_ERROR CTvheadend::SendDvrDelete(uint32_t id, const char* method) return PVR_ERROR_SERVER_ERROR; /* Check for error */ + uint32_t u32 = 0; if (htsmsg_get_u32(m, "success", &u32)) { Logger::Log(LogLevel::LEVEL_ERROR, @@ -370,8 +368,6 @@ PVR_ERROR CTvheadend::SendDvrDelete(uint32_t id, const char* method) PVR_ERROR CTvheadend::SendDvrUpdate(htsmsg_t* m) { - uint32_t u32; - /* Send and Wait */ { CLockObject lock(m_conn->Mutex()); @@ -382,6 +378,7 @@ PVR_ERROR CTvheadend::SendDvrUpdate(htsmsg_t* m) return PVR_ERROR_SERVER_ERROR; /* Check for error */ + uint32_t u32 = 0; if (htsmsg_get_u32(m, "success", &u32)) { Logger::Log(LogLevel::LEVEL_ERROR, "malformed updateDvrEntry response: 'success' missing"); @@ -532,8 +529,7 @@ PVR_ERROR CTvheadend::GetRecordings(ADDON_HANDLE handle) } } - std::vector::const_iterator it; - for (it = recs.begin(); it != recs.end(); ++it) + for (auto it = recs.begin(); it != recs.end(); ++it) { /* Callback. */ PVR->TransferRecordingEntry(handle, &(*it)); @@ -544,9 +540,6 @@ PVR_ERROR CTvheadend::GetRecordings(ADDON_HANDLE handle) PVR_ERROR CTvheadend::GetRecordingEdl(const PVR_RECORDING& rec, PVR_EDL_ENTRY edl[], int* num) { - htsmsg_field_t* f; - int idx; - /* Build request */ htsmsg_t* m = htsmsg_create_map(); htsmsg_add_u32(m, "id", atoi(rec.strRecordingId)); @@ -572,10 +565,13 @@ PVR_ERROR CTvheadend::GetRecordingEdl(const PVR_RECORDING& rec, PVR_EDL_ENTRY ed } /* Process */ - idx = 0; + htsmsg_field_t* f = nullptr; + int idx = 0; HTSMSG_FOREACH(f, list) { - uint32_t start, end, type; + uint32_t start = 0; + uint32_t end = 0; + uint32_t type = 0; if (f->hmf_type != HMF_MAP) continue; @@ -1053,7 +1049,6 @@ int CTvheadend::GetTimerCount() bool CTvheadend::CreateTimer(const Recording& tvhTmr, PVR_TIMER& tmr) { tmr = {0}; - tmr.iClientIndex = tvhTmr.GetId(); tmr.iClientChannelUid = (tvhTmr.GetChannel() > 0) ? tvhTmr.GetChannel() : PVR_CHANNEL_INVALID_UID; tmr.startTime = static_cast(tvhTmr.GetStart()); @@ -1122,8 +1117,7 @@ PVR_ERROR CTvheadend::GetTimers(ADDON_HANDLE handle) m_autoRecordings.GetAutorecTimers(timers); } - std::vector::const_iterator it; - for (it = timers.begin(); it != timers.end(); ++it) + for (auto it = timers.begin(); it != timers.end(); ++it) { /* Callback. */ PVR->TransferTimerEntry(handle, &(*it)); @@ -1138,8 +1132,6 @@ PVR_ERROR CTvheadend::AddTimer(const PVR_TIMER& timer) { /* one shot timer */ - uint32_t u32; - /* Build message */ htsmsg_t* m = htsmsg_create_map(); @@ -1190,6 +1182,7 @@ PVR_ERROR CTvheadend::AddTimer(const PVR_TIMER& timer) return PVR_ERROR_SERVER_ERROR; /* Check for error */ + uint32_t u32 = 0; if (htsmsg_get_u32(m, "success", &u32)) { Logger::Log(LogLevel::LEVEL_ERROR, "malformed addDvrEntry response: 'success' missing"); @@ -1464,7 +1457,6 @@ PVR_ERROR CTvheadend::GetEPGForChannel(ADDON_HANDLE handle, } int n = 0; - HTSMSG_FOREACH(f, l) { Event event; @@ -1512,8 +1504,6 @@ void CTvheadend::Disconnected() bool CTvheadend::Connected() { - htsmsg_t* msg; - /* Rebuild state */ for (auto* dmx : m_dmx) { @@ -1541,7 +1531,7 @@ bool CTvheadend::Connected() /* Request Async data, first is channels */ m_asyncState.SetState(ASYNC_CHN); - msg = htsmsg_create_map(); + htsmsg_t* msg = htsmsg_create_map(); if (Settings::GetInstance().GetAsyncEpg()) { Logger::Log(LogLevel::LEVEL_INFO, "request async EPG (%d)", m_epgMaxDays); @@ -1666,8 +1656,7 @@ bool CTvheadend::VfsIsRealTimeStream() bool CTvheadend::ProcessMessage(const char* method, htsmsg_t* msg) { - uint32_t subId; - + uint32_t subId = 0; if (!htsmsg_get_u32(msg, "subscriptionId", &subId)) { /* subscriptionId found - for a Demuxer */ @@ -1712,8 +1701,7 @@ void CTvheadend::CloseExpiredSubscriptions() void* CTvheadend::Process() { - HTSPMessage msg; - const char* method; + HTSPMessage msg = {}; while (!IsStopped()) { @@ -1730,7 +1718,7 @@ void* CTvheadend::Process() if (!bSuccess || !msg.GetMessage()) continue; - method = msg.GetMethod().c_str(); + const char* method = msg.GetMethod().c_str(); SHTSPEventList eventsCopy; /* Scope lock for processing */ @@ -1826,8 +1814,7 @@ void* CTvheadend::Process() * Note: due to potential deadly embrace this must be done without the * m_mutex held! */ - SHTSPEventList::const_iterator it; - for (it = eventsCopy.begin(); it != eventsCopy.end(); ++it) + for (auto it = eventsCopy.begin(); it != eventsCopy.end(); ++it) { switch (it->m_type) { @@ -1990,7 +1977,6 @@ void CTvheadend::SyncEpgCompleted() for (auto& evt : entry.second.GetEvents()) deletedEvents.emplace_back(std::make_pair(evt.second.GetId() /* event uid */, entry.second.GetId() /* channel uid */)); - return true; } return false; @@ -2010,10 +1996,10 @@ void CTvheadend::SyncEpgCompleted() }); } - Event evt; for (auto& entry : deletedEvents) { /* Transfer event to Kodi (callback) */ + Event evt; evt.SetId(entry.first); evt.SetChannel(entry.second); PushEpgEventUpdate(evt, EPG_EVENT_DELETED); @@ -2025,9 +2011,8 @@ void CTvheadend::SyncEpgCompleted() void CTvheadend::ParseTagAddOrUpdate(htsmsg_t* msg, bool bAdd) { - uint32_t u32; - /* Validate */ + uint32_t u32 = 0; if (htsmsg_get_u32(msg, "tagId", &u32)) { Logger::Log(LogLevel::LEVEL_ERROR, "malformed tagAdd/tagUpdate: 'tagId' missing"); @@ -2090,9 +2075,8 @@ void CTvheadend::ParseTagAddOrUpdate(htsmsg_t* msg, bool bAdd) void CTvheadend::ParseTagDelete(htsmsg_t* msg) { - uint32_t u32; - /* Validate */ + uint32_t u32 = 0; if (htsmsg_get_u32(msg, "tagId", &u32)) { Logger::Log(LogLevel::LEVEL_ERROR, "malformed tagDelete: 'tagId' missing"); @@ -2107,9 +2091,9 @@ void CTvheadend::ParseTagDelete(htsmsg_t* msg) void CTvheadend::ParseChannelAddOrUpdate(htsmsg_t* msg, bool bAdd) { - uint32_t u32; /* Validate */ + uint32_t u32 = 0; if (htsmsg_get_u32(msg, "channelId", &u32)) { Logger::Log(LogLevel::LEVEL_ERROR, "malformed channelAdd/channelUpdate: 'channelId' missing"); @@ -2213,9 +2197,8 @@ void CTvheadend::ParseChannelAddOrUpdate(htsmsg_t* msg, bool bAdd) void CTvheadend::ParseChannelDelete(htsmsg_t* msg) { - uint32_t u32; - /* Validate */ + uint32_t u32 = 0; if (htsmsg_get_u32(msg, "channelId", &u32)) { Logger::Log(LogLevel::LEVEL_ERROR, "malformed channelDelete: 'channelId' missing"); @@ -2231,14 +2214,11 @@ void CTvheadend::ParseChannelDelete(htsmsg_t* msg) void CTvheadend::ParseRecordingAddOrUpdate(htsmsg_t* msg, bool bAdd) { - 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 */ SyncChannelsCompleted(); /* Validate */ + uint32_t id = 0; if (htsmsg_get_u32(msg, "id", &id)) { Logger::Log(LogLevel::LEVEL_ERROR, "malformed dvrEntryAdd/dvrEntryUpdate: 'id' missing"); @@ -2265,6 +2245,7 @@ void CTvheadend::ParseRecordingAddOrUpdate(htsmsg_t* msg, bool bAdd) } // Set the time the recording was scheduled to start. This may differ from the actual start. + int64_t start = 0; if (!htsmsg_get_s64(msg, "start", &start)) rec.SetStart(start); else if (bAdd) @@ -2274,6 +2255,7 @@ void CTvheadend::ParseRecordingAddOrUpdate(htsmsg_t* msg, bool bAdd) } // Set the time the recording was scheduled to stop. This may differ from the actual stop. + int64_t stop = 0; if (!htsmsg_get_s64(msg, "stop", &stop)) rec.SetStop(stop); else if (bAdd) @@ -2283,6 +2265,7 @@ void CTvheadend::ParseRecordingAddOrUpdate(htsmsg_t* msg, bool bAdd) } /* Channel is optional, it may not exist anymore */ + uint32_t channel = 0; if (!htsmsg_get_u32(msg, "channel", &channel)) { /* Channel Id */ @@ -2302,8 +2285,6 @@ void CTvheadend::ParseRecordingAddOrUpdate(htsmsg_t* msg, bool bAdd) htsmsg_t* files = htsmsg_get_list(msg, "files"); if (files) { - uint32_t u32; - int64_t s64; bool needChannelType = !rec.GetChannelType() && m_conn->GetProtocol() >= 25; bool hasAudio = false; bool hasVideo = false; @@ -2328,9 +2309,11 @@ void CTvheadend::ParseRecordingAddOrUpdate(htsmsg_t* msg, bool bAdd) if (stream->hmf_type != HMF_MAP) continue; + uint32_t u32 = 0; 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 hasVideo = true; @@ -2338,6 +2321,7 @@ void CTvheadend::ParseRecordingAddOrUpdate(htsmsg_t* msg, bool bAdd) } } + int64_t s64 = 0; if (!htsmsg_get_s64(&file->hmf_msg, "start", &s64) && (start == 0 || start > s64)) start = s64; @@ -2363,6 +2347,7 @@ void CTvheadend::ParseRecordingAddOrUpdate(htsmsg_t* msg, bool bAdd) rec.SetChannelName(str); } + int64_t startExtra = 0; if (!htsmsg_get_s64(msg, "startExtra", &startExtra)) rec.SetStartExtra(startExtra); else if (bAdd) @@ -2371,6 +2356,7 @@ void CTvheadend::ParseRecordingAddOrUpdate(htsmsg_t* msg, bool bAdd) return; } + int64_t stopExtra = 0; if (!htsmsg_get_s64(msg, "stopExtra", &stopExtra)) rec.SetStopExtra(stopExtra); else if (bAdd) @@ -2381,8 +2367,11 @@ void CTvheadend::ParseRecordingAddOrUpdate(htsmsg_t* msg, bool bAdd) if (m_conn->GetProtocol() >= 25) { + uint32_t removal = 0; if (!htsmsg_get_u32(msg, "removal", &removal)) + { rec.SetLifetime(removal); + } else if (bAdd) { Logger::Log(LogLevel::LEVEL_ERROR, "malformed dvrEntryAdd: 'removal' missing"); @@ -2391,8 +2380,11 @@ void CTvheadend::ParseRecordingAddOrUpdate(htsmsg_t* msg, bool bAdd) } else { + uint32_t retention = 0; if (!htsmsg_get_u32(msg, "retention", &retention)) + { rec.SetLifetime(retention); + } else if (bAdd) { Logger::Log(LogLevel::LEVEL_ERROR, "malformed dvrEntryAdd: 'retention' missing"); @@ -2400,6 +2392,7 @@ void CTvheadend::ParseRecordingAddOrUpdate(htsmsg_t* msg, bool bAdd) } } + uint32_t priority = 0; if (!htsmsg_get_u32(msg, "priority", &priority)) { switch (priority) @@ -2446,8 +2439,11 @@ void CTvheadend::ParseRecordingAddOrUpdate(htsmsg_t* msg, bool bAdd) } /* Add optional fields */ + uint32_t eventId = 0; if (!htsmsg_get_u32(msg, "eventId", &eventId)) rec.SetEventId(eventId); + + uint32_t enabled = 0; if (!htsmsg_get_u32(msg, "enabled", &enabled)) rec.SetEnabled(enabled); @@ -2475,6 +2471,7 @@ void CTvheadend::ParseRecordingAddOrUpdate(htsmsg_t* msg, bool bAdd) rec.SetDescription(str); } + uint32_t contentType = 0; if (!htsmsg_get_u32(msg, "contentType", &contentType)) rec.SetContentType(contentType); @@ -2539,17 +2536,25 @@ void CTvheadend::ParseRecordingAddOrUpdate(htsmsg_t* msg, bool bAdd) /* Play status (optional) */ if (m_conn->GetProtocol() >= 27) { + uint32_t playCount = 0; if (!htsmsg_get_u32(msg, "playcount", &playCount)) rec.SetPlayCount(playCount); + + uint32_t playPosition = 0; if (!htsmsg_get_u32(msg, "playposition", &playPosition)) rec.SetPlayPosition(playPosition); } /* season/episode/part */ + uint32_t season = 0; if (!htsmsg_get_u32(msg, "seasonNumber", &season)) rec.SetSeason(season); + + uint32_t episode = 0; if (!htsmsg_get_u32(msg, "episodeNumber", &episode)) rec.SetEpisode(episode); + + uint32_t part = 0; if (!htsmsg_get_u32(msg, "partNumber", &part)) rec.SetPart(part); @@ -2572,9 +2577,8 @@ void CTvheadend::ParseRecordingAddOrUpdate(htsmsg_t* msg, bool bAdd) void CTvheadend::ParseRecordingDelete(htsmsg_t* msg) { - uint32_t u32; - /* Validate */ + uint32_t u32 = 0; if (htsmsg_get_u32(msg, "id", &u32)) { Logger::Log(LogLevel::LEVEL_ERROR, "malformed dvrEntryDelete: 'id' missing"); @@ -2599,31 +2603,32 @@ void CTvheadend::ParseRecordingDelete(htsmsg_t* msg) bool CTvheadend::ParseEvent(htsmsg_t* msg, bool bAdd, Event& evt) { - uint32_t u32, id, channel; - int64_t s64, start, stop; - /* Recordings complete */ SyncDvrCompleted(); /* Validate */ + uint32_t id = 0; if (htsmsg_get_u32(msg, "eventId", &id)) { Logger::Log(LogLevel::LEVEL_ERROR, "malformed eventAdd/eventUpdate: 'eventId' missing"); return false; } + uint32_t channel = 0; if (htsmsg_get_u32(msg, "channelId", &channel) && bAdd) { Logger::Log(LogLevel::LEVEL_ERROR, "malformed eventAdd: 'channelId' missing"); return false; } + int64_t start = 0; if (htsmsg_get_s64(msg, "start", &start) && bAdd) { Logger::Log(LogLevel::LEVEL_ERROR, "malformed eventAdd: 'start' missing"); return false; } + int64_t stop = 0; if (htsmsg_get_s64(msg, "stop", &stop) && bAdd) { Logger::Log(LogLevel::LEVEL_ERROR, "malformed eventAdd: 'stop' missing"); @@ -2656,6 +2661,7 @@ bool CTvheadend::ParseEvent(htsmsg_t* msg, bool bAdd, Event& evt) if (str) evt.SetImage(GetImageURL(str)); + uint32_t u32 = 0; if (!htsmsg_get_u32(msg, "nextEventId", &u32)) evt.SetNext(u32); if (!htsmsg_get_u32(msg, "contentType", &u32)) @@ -2664,6 +2670,8 @@ bool CTvheadend::ParseEvent(htsmsg_t* msg, bool bAdd, Event& evt) evt.SetStars(u32); if (!htsmsg_get_u32(msg, "ageRating", &u32)) evt.SetAge(u32); + + int64_t s64 = 0; if (!htsmsg_get_s64(msg, "firstAired", &s64)) evt.SetAired(static_cast(s64)); if (!htsmsg_get_u32(msg, "seasonNumber", &u32)) @@ -2742,7 +2750,7 @@ bool CTvheadend::ParseEvent(htsmsg_t* msg, bool bAdd, Event& evt) { std::vector categories; - htsmsg_field_t* f; + htsmsg_field_t* f = nullptr; HTSMSG_FOREACH(f, l) { const char* str = f->hmf_str; @@ -2772,7 +2780,7 @@ void CTvheadend::ParseEventAddOrUpdate(htsmsg_t* msg, bool bAdd) /* create/update event */ EventUids& events = sched.GetEvents(); - bool bUpdated(false); + bool bUpdated = false; if (bAdd && m_asyncState.GetState() < ASYNC_DONE) { // After a reconnect, during processing of "enableAsyncMetadata" htsp @@ -2806,9 +2814,8 @@ void CTvheadend::ParseEventAddOrUpdate(htsmsg_t* msg, bool bAdd) void CTvheadend::ParseEventDelete(htsmsg_t* msg) { - uint32_t u32; - /* Validate */ + uint32_t u32 = 0; if (htsmsg_get_u32(msg, "eventId", &u32)) { Logger::Log(LogLevel::LEVEL_ERROR, "malformed eventDelete: 'eventId' missing"); @@ -2859,9 +2866,11 @@ void CTvheadend::TuneOnOldest(uint32_t channelId) } if (dmx == m_dmx_active) continue; + if (!oldest || dmx->GetLastUse() <= oldest->GetLastUse()) oldest = dmx; } + if (oldest) { Logger::Log(LogLevel::LEVEL_TRACE, "pretuning channel %u on subscription %u", @@ -2885,10 +2894,7 @@ void CTvheadend::PredictiveTune(uint32_t fromChannelId, uint32_t toChannelId) bool CTvheadend::DemuxOpen(const PVR_CHANNEL& chn) { - HTSPDemuxer* oldest; - uint32_t prevId; - - oldest = m_dmx[0]; + HTSPDemuxer* oldest = m_dmx[0]; if (m_dmx.size() == 1) { @@ -2911,7 +2917,7 @@ bool CTvheadend::DemuxOpen(const PVR_CHANNEL& chn) { /* Lower the priority on the current subscrption */ m_dmx_active->Weight(SUBSCRIPTION_WEIGHT_POSTTUNING); - prevId = m_dmx_active->GetChannelId(); + uint32_t prevId = m_dmx_active->GetChannelId(); /* Promote the lingering subscription to the active one */ dmx->Weight(SUBSCRIPTION_WEIGHT_NORMAL); @@ -2934,7 +2940,7 @@ bool CTvheadend::DemuxOpen(const PVR_CHANNEL& chn) Logger::Log(LogLevel::LEVEL_TRACE, "tuning channel %u on subscription %u", m_channels[chn.iUniqueId].GetNum(), oldest->GetSubscriptionId()); - prevId = m_dmx_active->GetChannelId(); + uint32_t prevId = m_dmx_active->GetChannelId(); m_dmx_active->Weight(SUBSCRIPTION_WEIGHT_POSTTUNING); m_playingLiveStream = oldest->Open(chn.iUniqueId, SUBSCRIPTION_WEIGHT_NORMAL); diff --git a/src/tvheadend/AutoRecordings.cpp b/src/tvheadend/AutoRecordings.cpp index ad1620d0..b18fa403 100644 --- a/src/tvheadend/AutoRecordings.cpp +++ b/src/tvheadend/AutoRecordings.cpp @@ -167,7 +167,6 @@ PVR_ERROR AutoRecordings::SendAutorecUpdate(const PVR_TIMER& timer) PVR_ERROR AutoRecordings::SendAutorecAddOrUpdate(const PVR_TIMER& timer, bool update) { - uint32_t u32; const std::string method = update ? "updateAutorecEntry" : "addAutorecEntry"; /* Build message */ @@ -302,6 +301,7 @@ PVR_ERROR AutoRecordings::SendAutorecAddOrUpdate(const PVR_TIMER& timer, bool up return PVR_ERROR_SERVER_ERROR; /* Check for error */ + uint32_t u32 = 0; if (htsmsg_get_u32(m, "success", &u32)) { Logger::Log(LogLevel::LEVEL_ERROR, "malformed %s response: 'success' missing", method.c_str()); @@ -314,8 +314,6 @@ PVR_ERROR AutoRecordings::SendAutorecAddOrUpdate(const PVR_TIMER& timer, bool up PVR_ERROR AutoRecordings::SendAutorecDelete(const PVR_TIMER& timer) { - uint32_t u32; - std::string strId = GetTimerStringIdFromIntId(timer.iClientIndex); if (strId.empty()) return PVR_ERROR_FAILED; @@ -333,6 +331,7 @@ PVR_ERROR AutoRecordings::SendAutorecDelete(const PVR_TIMER& timer) return PVR_ERROR_SERVER_ERROR; /* Check for error */ + uint32_t u32 = 0; if (htsmsg_get_u32(m, "success", &u32)) { Logger::Log(LogLevel::LEVEL_ERROR, "malformed deleteAutorecEntry response: 'success' missing"); @@ -344,10 +343,6 @@ PVR_ERROR AutoRecordings::SendAutorecDelete(const PVR_TIMER& timer) bool AutoRecordings::ParseAutorecAddOrUpdate(htsmsg_t* msg, bool bAdd) { - uint32_t u32; - int32_t s32; - int64_t s64; - /* Validate/set mandatory fields */ const char* str = htsmsg_get_str(msg, "id"); if (!str) @@ -364,6 +359,7 @@ bool AutoRecordings::ParseAutorecAddOrUpdate(htsmsg_t* msg, bool bAdd) /* Validate/set fields mandatory for autorecEntryAdd */ + uint32_t u32 = 0; if (!htsmsg_get_u32(msg, "enabled", &u32)) { rec.SetEnabled(u32); @@ -419,6 +415,7 @@ bool AutoRecordings::ParseAutorecAddOrUpdate(htsmsg_t* msg, bool bAdd) return false; } + int32_t s32 = 0; if (!htsmsg_get_s32(msg, "start", &s32)) { rec.SetStartWindowBegin(s32); @@ -439,6 +436,7 @@ bool AutoRecordings::ParseAutorecAddOrUpdate(htsmsg_t* msg, bool bAdd) return false; } + int64_t s64 = 0; if (!htsmsg_get_s64(msg, "startExtra", &s64)) { rec.SetMarginStart(s64); diff --git a/src/tvheadend/HTSPConnection.cpp b/src/tvheadend/HTSPConnection.cpp index 89050bd9..10682524 100644 --- a/src/tvheadend/HTSPConnection.cpp +++ b/src/tvheadend/HTSPConnection.cpp @@ -140,7 +140,6 @@ void HTSPConnection::Stop() std::string HTSPConnection::GetWebURL(const char* fmt, ...) const { - va_list va; const Settings& settings = Settings::GetInstance(); // Generate the authentication string (user:pass@) @@ -153,6 +152,8 @@ std::string HTSPConnection::GetWebURL(const char* fmt, ...) const std::string url = StringUtils::Format("http://%s%s:%d", auth.c_str(), settings.GetHostname().c_str(), settings.GetPortHTTP()); + va_list va; + CLockObject lock(m_mutex); va_start(va, fmt); url += m_webRoot; @@ -278,26 +279,20 @@ void HTSPConnection::Disconnect() */ bool HTSPConnection::ReadMessage() { - uint8_t* buf; - uint8_t lb[4]; - size_t len, cnt; - ssize_t r; - uint32_t seq; - htsmsg_t* msg; - const char* method; - /* Read 4 byte len */ - len = m_socket->Read(&lb, sizeof(lb)); + uint8_t lb[4]; + size_t len = m_socket->Read(&lb, sizeof(lb)); if (len != sizeof(lb)) return false; + len = (lb[0] << 24) + (lb[1] << 16) + (lb[2] << 8) + lb[3]; /* Read rest of packet */ - buf = static_cast(malloc(len)); - cnt = 0; + uint8_t* buf = static_cast(malloc(len)); + size_t cnt = 0; while (cnt < len) { - r = m_socket->Read(buf + cnt, len - cnt, Settings::GetInstance().GetResponseTimeout()); + ssize_t r = m_socket->Read(buf + cnt, len - cnt, Settings::GetInstance().GetResponseTimeout()); if (r < 0) { Logger::Log(LogLevel::LEVEL_ERROR, "failed to read packet (%s)", @@ -309,7 +304,7 @@ bool HTSPConnection::ReadMessage() } /* Deserialize */ - msg = htsmsg_binary_deserialize(buf, len, buf); + htsmsg_t* msg = htsmsg_binary_deserialize(buf, len, buf); if (!msg) { /* Do not free buf here. Already done by htsmsg_binary_deserialize. */ @@ -318,6 +313,7 @@ bool HTSPConnection::ReadMessage() } /* Sequence number - response */ + uint32_t seq = 0; if (htsmsg_get_u32(msg, "seq", &seq) == 0) { Logger::Log(LogLevel::LEVEL_TRACE, "received response [%d]", seq); @@ -331,7 +327,7 @@ bool HTSPConnection::ReadMessage() } /* Get method */ - method = htsmsg_get_str(msg, "method"); + const char* method = htsmsg_get_str(msg, "method"); if (!method) { Logger::Log(LogLevel::LEVEL_ERROR, "message without a method"); @@ -353,12 +349,7 @@ bool HTSPConnection::ReadMessage() */ bool HTSPConnection::SendMessage0(const char* method, htsmsg_t* msg) { - int e; - void* buf; - size_t len; - ssize_t c; - uint32_t seq; - + uint32_t seq = 0; if (!htsmsg_get_u32(msg, "seq", &seq)) { Logger::Log(LogLevel::LEVEL_TRACE, "sending message [%s : %d]", method, seq); @@ -370,13 +361,15 @@ bool HTSPConnection::SendMessage0(const char* method, htsmsg_t* msg) htsmsg_add_str(msg, "method", method); /* Serialise */ - e = htsmsg_binary_serialize(msg, &buf, &len, -1); + void* buf = nullptr; + size_t len = 0; + int e = htsmsg_binary_serialize(msg, &buf, &len, -1); htsmsg_destroy(msg); if (e < 0) return false; /* Send data */ - c = m_socket->Write(buf, len); + ssize_t c = m_socket->Write(buf, len); free(buf); if (c != static_cast(len)) @@ -399,12 +392,11 @@ htsmsg_t* HTSPConnection::SendAndWait0(const char* method, htsmsg_t* msg, int iR if (iResponseTimeout == -1) iResponseTimeout = Settings::GetInstance().GetResponseTimeout(); - uint32_t seq; - /* Add Sequence number */ - HTSPResponse resp; - seq = ++m_seq; + uint32_t seq = ++m_seq; htsmsg_add_u32(msg, "seq", seq); + + HTSPResponse resp; m_messages[seq] = &resp; /* Send Message (bypass TX check) */ @@ -423,11 +415,12 @@ htsmsg_t* HTSPConnection::SendAndWait0(const char* method, htsmsg_t* msg, int iR Logger::Log(LogLevel::LEVEL_ERROR, "Command %s failed: No response received", method); if (!m_suspended) Disconnect(); + return nullptr; } /* Check result for errors and announce. */ - uint32_t noaccess; + uint32_t noaccess = 0; if (!htsmsg_get_u32(msg, "noaccess", &noaccess) && noaccess) { // access denied @@ -459,6 +452,7 @@ htsmsg_t* HTSPConnection::SendAndWait(const char* method, htsmsg_t* msg, int iRe if (!WaitForConnection()) return nullptr; + return SendAndWait0(method, msg, iResponseTimeout); } @@ -475,12 +469,9 @@ bool HTSPConnection::SendHello() return false; /* Process */ - const char* webroot; - const void* chal; - size_t chal_len; /* Basic Info */ - webroot = htsmsg_get_str(msg, "webroot"); + const char* webroot = htsmsg_get_str(msg, "webroot"); m_serverName = htsmsg_get_str(msg, "servername"); m_serverVersion = htsmsg_get_str(msg, "serverversion"); m_htspVersion = htsmsg_get_u32_or_default(msg, "htspversion", 0); @@ -501,6 +492,8 @@ bool HTSPConnection::SendHello() } /* Authentication */ + const void* chal = nullptr; + size_t chal_len = 0; htsmsg_get_bin(msg, "challenge", &chal, &chal_len); if (chal && chal_len) { @@ -510,13 +503,11 @@ bool HTSPConnection::SendHello() } htsmsg_destroy(msg); - return true; } bool HTSPConnection::SendAuth(const std::string& user, const std::string& pass) { - uint32_t u32; htsmsg_t* msg = htsmsg_create_map(); htsmsg_add_str(msg, "username", user.c_str()); @@ -542,6 +533,8 @@ bool HTSPConnection::SendAuth(const std::string& user, const std::string& pass) { /* Log received permissions */ Logger::Log(LogLevel::LEVEL_INFO, " Received permissions:"); + + uint32_t u32 = 0; if (!htsmsg_get_u32(msg, "admin", &u32)) Logger::Log(LogLevel::LEVEL_INFO, " administrator : %i", u32); if (!htsmsg_get_u32(msg, "streaming", &u32)) @@ -639,15 +632,15 @@ void* HTSPConnection::Process() Logger::Log(LogLevel::LEVEL_DEBUG, "new connection requested"); std::string host = settings.GetHostname(); - int port, timeout; - port = settings.GetPortHTSP(); - timeout = settings.GetConnectTimeout(); + int port = settings.GetPortHTSP(); + int timeout = settings.GetConnectTimeout(); /* Create socket (ensure mutex protection) */ { CLockObject lock(m_mutex); if (m_socket) delete m_socket; + m_connListener.Disconnected(); m_socket = new CTcpSocket(host.c_str(), port); m_ready = false; diff --git a/src/tvheadend/HTSPDemuxer.cpp b/src/tvheadend/HTSPDemuxer.cpp index 5c0d47c6..310ddf85 100644 --- a/src/tvheadend/HTSPDemuxer.cpp +++ b/src/tvheadend/HTSPDemuxer.cpp @@ -130,9 +130,9 @@ void HTSPDemuxer::Close() DemuxPacket* HTSPDemuxer::Read() { - DemuxPacket* pkt = nullptr; m_lastUse.store(time(nullptr)); + DemuxPacket* pkt = nullptr; if (m_pktBuffer.Pop(pkt, 100)) { Logger::Log(LogLevel::LEVEL_TRACE, "demux read idx :%d pts %lf len %lld", pkt->iStreamId, @@ -146,20 +146,21 @@ DemuxPacket* HTSPDemuxer::Read() void HTSPDemuxer::Flush() { - DemuxPacket* pkt; Logger::Log(LogLevel::LEVEL_TRACE, "demux flush"); + + DemuxPacket* pkt = nullptr; while (m_pktBuffer.Pop(pkt)) PVR->FreeDemuxPacket(pkt); } void HTSPDemuxer::Trim() { - DemuxPacket* pkt; - Logger::Log(LogLevel::LEVEL_TRACE, "demux trim"); + /* reduce used buffer space to what is needed for DVDPlayer to resume * playback without buffering. This depends on the bitrate, so we don't set * this too small. */ + DemuxPacket* pkt = nullptr; while (m_pktBuffer.Size() > 512 && m_pktBuffer.Pop(pkt)) PVR->FreeDemuxPacket(pkt); } @@ -167,6 +168,7 @@ void HTSPDemuxer::Trim() void HTSPDemuxer::Abort() { Logger::Log(LogLevel::LEVEL_TRACE, "demux abort"); + CLockObject lock(m_conn.Mutex()); Abort0(); ResetStatus(); @@ -210,6 +212,7 @@ bool HTSPDemuxer::Seek(double time, bool, double* startpts) void HTSPDemuxer::Speed(int speed) { CLockObject lock(m_conn.Mutex()); + if (!m_subscription.IsActive()) return; @@ -227,6 +230,7 @@ void HTSPDemuxer::Speed(int speed) void HTSPDemuxer::FillBuffer(bool mode) { CLockObject lock(m_conn.Mutex()); + if (!m_subscription.IsActive()) return; @@ -244,6 +248,7 @@ void HTSPDemuxer::Weight(enum eSubscriptionWeight weight) { if (!m_subscription.IsActive() || m_subscription.GetWeight() == static_cast(weight)) return; + m_subscription.SendWeight(static_cast(weight)); } @@ -349,6 +354,7 @@ uint32_t HTSPDemuxer::GetChannelId() const { if (m_subscription.IsActive()) return m_subscription.GetChannelId(); + return 0; } @@ -356,6 +362,7 @@ time_t HTSPDemuxer::GetLastUse() const { if (m_subscription.IsActive()) return m_lastUse.load(); + return 0; } @@ -363,6 +370,7 @@ bool HTSPDemuxer::IsPaused() const { if (m_subscription.IsActive()) return m_subscription.GetSpeed() == 0; + return false; } @@ -472,13 +480,6 @@ void HTSPDemuxer::ProcessRDS(uint32_t idx, const void* bin, size_t binlen) void HTSPDemuxer::ParseMuxPacket(htsmsg_t* m) { - uint32_t idx, u32; - int64_t s64; - const void* bin; - size_t binlen; - char type = 0; - int ignore; - CLockObject lock(m_mutex); /* Ignore packets while switching channels */ @@ -489,6 +490,9 @@ void HTSPDemuxer::ParseMuxPacket(htsmsg_t* m) } /* Validate fields */ + uint32_t idx = 0; + const void* bin = nullptr; + size_t binlen = 0; if (htsmsg_get_u32(m, "stream", &idx) || htsmsg_get_bin(m, "payload", &bin, &binlen)) { Logger::Log(LogLevel::LEVEL_ERROR, "malformed muxpkt: 'stream'/'payload' missing"); @@ -517,10 +521,12 @@ void HTSPDemuxer::ParseMuxPacket(htsmsg_t* m) pkt->iStreamId = idx; /* Duration */ + uint32_t u32 = 0; if (!htsmsg_get_u32(m, "duration", &u32)) pkt->duration = TVH_TO_DVD_TIME(u32); /* Timestamps */ + int64_t s64 = 0; if (!htsmsg_get_s64(m, "dts", &s64)) pkt->dts = TVH_TO_DVD_TIME(s64); else @@ -532,12 +538,13 @@ void HTSPDemuxer::ParseMuxPacket(htsmsg_t* m) pkt->pts = DVD_NOPTS_VALUE; /* Type (for debug only) */ + char type = 0; if (!htsmsg_get_u32(m, "frametype", &u32)) type = static_cast(u32); if (!type) type = '_'; - ignore = m_seeking; + bool 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, static_cast(binlen), @@ -709,7 +716,7 @@ void HTSPDemuxer::ParseSubscriptionStart(htsmsg_t* m) Logger::Log(LogLevel::LEVEL_DEBUG, "demux subscription start"); /* Process each */ - htsmsg_field_t* f; + htsmsg_field_t* f = nullptr; HTSMSG_FOREACH(f, l) { if (f->hmf_type != HMF_MAP) @@ -719,7 +726,7 @@ void HTSPDemuxer::ParseSubscriptionStart(htsmsg_t* m) if (!type) continue; - uint32_t idx; + uint32_t idx = 0; if (htsmsg_get_u32(&f->hmf_msg, "index", &idx)) continue; @@ -801,10 +808,9 @@ void HTSPDemuxer::ParseSubscriptionStop(htsmsg_t*) void HTSPDemuxer::ParseSubscriptionSkip(htsmsg_t* m) { - int64_t s64; - CLockObject lock(m_conn.Mutex()); + int64_t s64 = 0; if (htsmsg_get_s64(m, "time", &s64)) { m_seekTime = INVALID_SEEKTIME; @@ -820,11 +826,10 @@ void HTSPDemuxer::ParseSubscriptionSkip(htsmsg_t* m) void HTSPDemuxer::ParseSubscriptionSpeed(htsmsg_t* m) { - int32_t s32; + int32_t s32 = 0; if (!htsmsg_get_s32(m, "speed", &s32)) Logger::Log(LogLevel::LEVEL_TRACE, "recv speed %d", s32); - CLockObject lock(m_conn.Mutex()); m_actualSpeed = s32 * 10; } @@ -835,16 +840,17 @@ void HTSPDemuxer::ParseSubscriptionGrace(htsmsg_t* m) void HTSPDemuxer::ParseQueueStatus(htsmsg_t* m) { - uint32_t u32; - std::map::const_iterator it; - CLockObject lock(m_mutex); Logger::Log(LogLevel::LEVEL_TRACE, "stream stats:"); - for (it = m_streamStat.begin(); it != m_streamStat.end(); ++it) + for (auto it = m_streamStat.begin(); it != m_streamStat.end(); ++it) + { Logger::Log(LogLevel::LEVEL_TRACE, " idx:%d num:%d", it->first, it->second); + } Logger::Log(LogLevel::LEVEL_TRACE, "queue stats:"); + + uint32_t u32 = 0; if (!htsmsg_get_u32(m, "packets", &u32)) Logger::Log(LogLevel::LEVEL_TRACE, " pkts %d", u32); if (!htsmsg_get_u32(m, "bytes", &u32)) @@ -861,8 +867,6 @@ void HTSPDemuxer::ParseQueueStatus(htsmsg_t* m) void HTSPDemuxer::ParseSignalStatus(htsmsg_t* m) { - uint32_t u32; - CLockObject lock(m_mutex); /* Reset */ @@ -881,6 +885,8 @@ void HTSPDemuxer::ParseSignalStatus(htsmsg_t* m) { Logger::Log(LogLevel::LEVEL_ERROR, "malformed signalStatus: 'feStatus' missing, ignoring"); } + + uint32_t u32 = 0; if (!htsmsg_get_u32(m, "feSNR", &u32)) { Logger::Log(LogLevel::LEVEL_TRACE, " snr : %d", u32); @@ -905,13 +911,12 @@ void HTSPDemuxer::ParseSignalStatus(htsmsg_t* m) void HTSPDemuxer::ParseTimeshiftStatus(htsmsg_t* m) { - uint32_t u32; - int64_t s64; - CLockObject lock(m_mutex); /* Parse */ Logger::Log(LogLevel::LEVEL_TRACE, "timeshiftStatus:"); + + uint32_t u32 = 0; if (!htsmsg_get_u32(m, "full", &u32)) { Logger::Log(LogLevel::LEVEL_TRACE, " full : %d", u32); @@ -921,6 +926,8 @@ void HTSPDemuxer::ParseTimeshiftStatus(htsmsg_t* m) { Logger::Log(LogLevel::LEVEL_ERROR, "malformed timeshiftStatus: 'full' missing, ignoring"); } + + int64_t s64 = 0; if (!htsmsg_get_s64(m, "shift", &s64)) { Logger::Log(LogLevel::LEVEL_TRACE, " shift : %lld", s64); @@ -944,10 +951,12 @@ void HTSPDemuxer::ParseTimeshiftStatus(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 */ + uint32_t pid = 0; + uint32_t caid = 0; + uint32_t provid = 0; + uint32_t ecmtime = 0; + uint32_t hops = 0; 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)) @@ -957,10 +966,10 @@ void HTSPDemuxer::ParseDescrambleInfo(htsmsg_t* m) } /* Parse optional fields */ - cardsystem = htsmsg_get_str(m, "cardsystem"); - reader = htsmsg_get_str(m, "reader"); - from = htsmsg_get_str(m, "from"); - protocol = htsmsg_get_str(m, "protocol"); + const char* cardsystem = htsmsg_get_str(m, "cardsystem"); + const char* reader = htsmsg_get_str(m, "reader"); + const char* from = htsmsg_get_str(m, "from"); + const char* protocol = htsmsg_get_str(m, "protocol"); CLockObject lock(m_mutex); diff --git a/src/tvheadend/HTSPVFS.cpp b/src/tvheadend/HTSPVFS.cpp index 6821cec2..1ee9cc13 100644 --- a/src/tvheadend/HTSPVFS.cpp +++ b/src/tvheadend/HTSPVFS.cpp @@ -102,7 +102,7 @@ void HTSPVFS::Close() m_offset = 0; m_fileId = 0; - m_path = ""; + m_path.clear(); m_eofOffsetSecs = -1; m_pauseTime = 0; m_paused = false; @@ -174,10 +174,9 @@ long long HTSPVFS::Seek(long long pos, int whence, bool inprogress) long long HTSPVFS::Size() { int64_t ret = -1; - htsmsg_t* m; /* Build */ - m = htsmsg_create_map(); + htsmsg_t* m = htsmsg_create_map(); htsmsg_add_u32(m, "id", m_fileId); Logger::Log(LogLevel::LEVEL_TRACE, "vfs stat id=%d", m_fileId); @@ -236,10 +235,8 @@ bool HTSPVFS::IsRealTimeStream() bool HTSPVFS::SendFileOpen(bool force) { - htsmsg_t* m; - /* Build Message */ - m = htsmsg_create_map(); + htsmsg_t* m = htsmsg_create_map(); htsmsg_add_str(m, "file", m_path.c_str()); Logger::Log(LogLevel::LEVEL_DEBUG, "vfs open file=%s", m_path.c_str()); @@ -272,10 +269,8 @@ bool HTSPVFS::SendFileOpen(bool force) void HTSPVFS::SendFileClose() { - htsmsg_t* m; - /* Build */ - m = htsmsg_create_map(); + htsmsg_t* m = htsmsg_create_map(); htsmsg_add_u32(m, "id", m_fileId); /* If setting set, we will increase play count with CTvheadend::SetPlayCount */ @@ -298,11 +293,10 @@ void HTSPVFS::SendFileClose() long long HTSPVFS::SendFileSeek(int64_t pos, int whence, bool force) { - htsmsg_t* m; int64_t ret = -1; /* Build Message */ - m = htsmsg_create_map(); + htsmsg_t* m = htsmsg_create_map(); htsmsg_add_u32(m, "id", m_fileId); htsmsg_add_s64(m, "offset", pos); if (whence == SEEK_CUR) @@ -351,12 +345,8 @@ long long HTSPVFS::SendFileSeek(int64_t pos, int whence, bool force) ssize_t HTSPVFS::SendFileRead(unsigned char* buf, unsigned int len) { - htsmsg_t* m; - const void* buffer; - size_t read; - /* Build */ - m = htsmsg_create_map(); + htsmsg_t* m = htsmsg_create_map(); htsmsg_add_u32(m, "id", m_fileId); htsmsg_add_s64(m, "size", len); @@ -375,6 +365,8 @@ ssize_t HTSPVFS::SendFileRead(unsigned char* buf, unsigned int len) } /* Get Data */ + const void* buffer = nullptr; + size_t read = 0; if (htsmsg_get_bin(m, "data", &buffer, &read)) { Logger::Log(LogLevel::LEVEL_ERROR, "malformed fileRead response: 'data' missing"); diff --git a/src/tvheadend/TimeRecordings.cpp b/src/tvheadend/TimeRecordings.cpp index 73cb42f4..9d3c21e6 100644 --- a/src/tvheadend/TimeRecordings.cpp +++ b/src/tvheadend/TimeRecordings.cpp @@ -142,7 +142,6 @@ PVR_ERROR TimeRecordings::SendTimerecUpdate(const PVR_TIMER& timer) PVR_ERROR TimeRecordings::SendTimerecAddOrUpdate(const PVR_TIMER& timer, bool update) { - uint32_t u32; const std::string method = update ? "updateTimerecEntry" : "addTimerecEntry"; /* Build message */ @@ -208,6 +207,7 @@ PVR_ERROR TimeRecordings::SendTimerecAddOrUpdate(const PVR_TIMER& timer, bool up return PVR_ERROR_SERVER_ERROR; /* Check for error */ + uint32_t u32 = 0; if (htsmsg_get_u32(m, "success", &u32)) { Logger::Log(LogLevel::LEVEL_ERROR, "malformed %s response: 'success' missing", method.c_str()); @@ -220,8 +220,6 @@ PVR_ERROR TimeRecordings::SendTimerecAddOrUpdate(const PVR_TIMER& timer, bool up PVR_ERROR TimeRecordings::SendTimerecDelete(const PVR_TIMER& timer) { - uint32_t u32; - std::string strId = GetTimerStringIdFromIntId(timer.iClientIndex); if (strId.empty()) return PVR_ERROR_FAILED; @@ -239,6 +237,7 @@ PVR_ERROR TimeRecordings::SendTimerecDelete(const PVR_TIMER& timer) return PVR_ERROR_SERVER_ERROR; /* Check for error */ + uint32_t u32 = 0; if (htsmsg_get_u32(m, "success", &u32)) { Logger::Log(LogLevel::LEVEL_ERROR, "malformed deleteTimerecEntry response: 'success' missing"); @@ -250,9 +249,6 @@ PVR_ERROR TimeRecordings::SendTimerecDelete(const PVR_TIMER& timer) bool TimeRecordings::ParseTimerecAddOrUpdate(htsmsg_t* msg, bool bAdd) { - uint32_t u32; - int32_t s32; - /* Validate/set mandatory fields */ const char* str = htsmsg_get_str(msg, "id"); if (!str) @@ -269,6 +265,7 @@ bool TimeRecordings::ParseTimerecAddOrUpdate(htsmsg_t* msg, bool bAdd) /* Validate/set fields mandatory for timerecEntryAdd */ + uint32_t u32 = 0; if (!htsmsg_get_u32(msg, "enabled", &u32)) { rec.SetEnabled(u32); @@ -324,6 +321,7 @@ bool TimeRecordings::ParseTimerecAddOrUpdate(htsmsg_t* msg, bool bAdd) return false; } + int32_t s32 = 0; if (!htsmsg_get_s32(msg, "start", &s32)) { rec.SetStart(s32); diff --git a/src/tvheadend/entity/AutoRecording.cpp b/src/tvheadend/entity/AutoRecording.cpp index d37cac80..0f83785e 100644 --- a/src/tvheadend/entity/AutoRecording.cpp +++ b/src/tvheadend/entity/AutoRecording.cpp @@ -57,7 +57,9 @@ time_t AutoRecording::GetStart() const /* Calculate the approximate start time from the starting window */ if ((m_startWindowBegin == -1) || (m_startWindowEnd == -1)) // no starting window set => "any time" + { return 0; + } else if (m_startWindowEnd < m_startWindowBegin) { /* End of start window is a day in the future */ diff --git a/src/tvheadend/utilities/Logger.cpp b/src/tvheadend/utilities/Logger.cpp index 9c04bbb0..382615cb 100644 --- a/src/tvheadend/utilities/Logger.cpp +++ b/src/tvheadend/utilities/Logger.cpp @@ -28,9 +28,7 @@ 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() From 60c5e8b003850dc3f9db2efc405fd2699c67296c Mon Sep 17 00:00:00 2001 From: Kai Sommerfeld Date: Fri, 18 Oct 2019 23:50:05 +0200 Subject: [PATCH 07/10] code cleanup: use range-based for loops. --- src/Tvheadend.cpp | 57 +++++++++++++++++--------------- src/client.cpp | 7 ++-- src/tvheadend/AutoRecordings.cpp | 56 +++++++++++++++---------------- src/tvheadend/HTSPDemuxer.cpp | 4 +-- src/tvheadend/TimeRecordings.cpp | 38 ++++++++++----------- src/tvheadend/entity/Tag.cpp | 10 +++--- 6 files changed, 88 insertions(+), 84 deletions(-) diff --git a/src/Tvheadend.cpp b/src/Tvheadend.cpp index bc535753..9d117aac 100644 --- a/src/Tvheadend.cpp +++ b/src/Tvheadend.cpp @@ -230,10 +230,10 @@ PVR_ERROR CTvheadend::GetTags(ADDON_HANDLE handle, bool bRadio) } } - for (auto it = tags.begin(); it != tags.end(); ++it) + for (const auto& tag : tags) { /* Callback. */ - PVR->TransferChannelGroup(handle, &(*it)); + PVR->TransferChannelGroup(handle, &tag); } return PVR_ERROR_NO_ERROR; @@ -275,10 +275,10 @@ PVR_ERROR CTvheadend::GetTagMembers(ADDON_HANDLE handle, const PVR_CHANNEL_GROUP } } - for (auto it = gms.begin(); it != gms.end(); ++it) + for (const auto& gm : gms) { /* Callback. */ - PVR->TransferChannelGroupMember(handle, &(*it)); + PVR->TransferChannelGroupMember(handle, &gm); } return PVR_ERROR_NO_ERROR; @@ -327,10 +327,10 @@ PVR_ERROR CTvheadend::GetChannels(ADDON_HANDLE handle, bool radio) } } - for (auto it = channels.begin(); it != channels.end(); ++it) + for (const auto& channel : channels) { /* Callback. */ - PVR->TransferChannelEntry(handle, &(*it)); + PVR->TransferChannelEntry(handle, &channel); } return PVR_ERROR_NO_ERROR; @@ -529,10 +529,10 @@ PVR_ERROR CTvheadend::GetRecordings(ADDON_HANDLE handle) } } - for (auto it = recs.begin(); it != recs.end(); ++it) + for (const auto& rec : recs) { /* Callback. */ - PVR->TransferRecordingEntry(handle, &(*it)); + PVR->TransferRecordingEntry(handle, &rec); } return PVR_ERROR_NO_ERROR; @@ -734,27 +734,30 @@ struct TimerType : PVR_TIMER_TYPE strncpy(strDescription, description.c_str(), sizeof(strDescription) - 1); int i = 0; - for (auto it = priorityValues.begin(); it != priorityValues.end(); ++it, ++i) + for (const auto& priorityValue : priorityValues) { - priorities[i].iValue = it->first; - strncpy(priorities[i].strDescription, it->second.c_str(), + priorities[i].iValue = priorityValue.first; + strncpy(priorities[i].strDescription, priorityValue.second.c_str(), sizeof(priorities[i].strDescription) - 1); + ++i; } i = 0; - for (auto it = dupEpisodesValues.begin(); it != dupEpisodesValues.end(); ++it, ++i) + for (const auto& dupEpisodesValue : dupEpisodesValues) { - preventDuplicateEpisodes[i].iValue = it->first; - strncpy(preventDuplicateEpisodes[i].strDescription, it->second.c_str(), + preventDuplicateEpisodes[i].iValue = dupEpisodesValue.first; + strncpy(preventDuplicateEpisodes[i].strDescription, dupEpisodesValue.second.c_str(), sizeof(preventDuplicateEpisodes[i].strDescription) - 1); + ++i; } i = 0; - for (auto it = lifetimeValues.begin(); it != lifetimeValues.end(); ++it, ++i) + for (const auto& lifetimeValue : lifetimeValues) { - lifetimes[i].iValue = it->first; - strncpy(lifetimes[i].strDescription, it->second.c_str(), + lifetimes[i].iValue = lifetimeValue.first; + strncpy(lifetimes[i].strDescription, lifetimeValue.second.c_str(), sizeof(lifetimes[i].strDescription) - 1); + ++i; } } }; @@ -1020,8 +1023,11 @@ PVR_ERROR CTvheadend::GetTimerTypes(PVR_TIMER_TYPE types[], int* size) /* Copy data to target array. */ int i = 0; - for (auto it = timerTypes.begin(); it != timerTypes.end(); ++it, ++i) - types[i] = **it; + for (const auto& timerType : timerTypes) + { + types[i] = *timerType; + ++i; + } *size = timerTypes.size(); return PVR_ERROR_NO_ERROR; @@ -1117,10 +1123,10 @@ PVR_ERROR CTvheadend::GetTimers(ADDON_HANDLE handle) m_autoRecordings.GetAutorecTimers(timers); } - for (auto it = timers.begin(); it != timers.end(); ++it) + for (const auto& timer : timers) { /* Callback. */ - PVR->TransferTimerEntry(handle, &(*it)); + PVR->TransferTimerEntry(handle, &timer); } return PVR_ERROR_NO_ERROR; @@ -1506,9 +1512,8 @@ bool CTvheadend::Connected() { /* Rebuild state */ for (auto* dmx : m_dmx) - { dmx->Connected(); - } + m_vfs->Connected(); m_timeRecordings.Connected(); m_autoRecordings.Connected(); @@ -1814,9 +1819,9 @@ void* CTvheadend::Process() * Note: due to potential deadly embrace this must be done without the * m_mutex held! */ - for (auto it = eventsCopy.begin(); it != eventsCopy.end(); ++it) + for (const auto& event : eventsCopy) { - switch (it->m_type) + switch (event.m_type) { case HTSP_EVENT_TAG_UPDATE: PVR->TriggerChannelGroupsUpdate(); @@ -1829,7 +1834,7 @@ void* CTvheadend::Process() PVR->TriggerRecordingUpdate(); break; case HTSP_EVENT_EPG_UPDATE: - TransferEvent(it->m_epg, it->m_state); + TransferEvent(event.m_epg, event.m_state); break; case HTSP_EVENT_NONE: break; diff --git a/src/client.cpp b/src/client.cpp index 9fac6633..93fd4cf7 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -182,11 +182,12 @@ PVR_ERROR GetAddonCapabilities(PVR_ADDON_CAPABILITIES* pCapabilities) pCapabilities->iRecordingsLifetimesSize = lifetimeValues.size(); int i = 0; - for (auto it = lifetimeValues.cbegin(); it != lifetimeValues.cend(); ++it, ++i) + for (const auto& lifetimeValue : lifetimeValues) { - pCapabilities->recordingsLifetimeValues[i].iValue = it->first; - strncpy(pCapabilities->recordingsLifetimeValues[i].strDescription, it->second.c_str(), + pCapabilities->recordingsLifetimeValues[i].iValue = lifetimeValue.first; + strncpy(pCapabilities->recordingsLifetimeValues[i].strDescription, lifetimeValue.second.c_str(), sizeof(pCapabilities->recordingsLifetimeValues[i].strDescription) - 1); + ++i; } } return PVR_ERROR_NO_ERROR; diff --git a/src/tvheadend/AutoRecordings.cpp b/src/tvheadend/AutoRecordings.cpp index b18fa403..71ba04b5 100644 --- a/src/tvheadend/AutoRecordings.cpp +++ b/src/tvheadend/AutoRecordings.cpp @@ -44,8 +44,8 @@ AutoRecordings::~AutoRecordings() void AutoRecordings::Connected() { /* Flag all async fields in case they've been deleted */ - for (auto it = m_autoRecordings.begin(); it != m_autoRecordings.end(); ++it) - it->second.SetDirty(true); + for (auto& rec : m_autoRecordings) + rec.second.SetDirty(true); } void AutoRecordings::SyncDvrCompleted() @@ -61,16 +61,16 @@ int AutoRecordings::GetAutorecTimerCount() const void AutoRecordings::GetAutorecTimers(std::vector& timers) { - for (auto tit = m_autoRecordings.begin(); tit != m_autoRecordings.end(); ++tit) + for (const auto& rec : m_autoRecordings) { /* Setup entry */ PVR_TIMER tmr = {0}; - tmr.iClientIndex = tit->second.GetId(); + tmr.iClientIndex = rec.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(); + (rec.second.GetChannel() > 0) ? rec.second.GetChannel() : PVR_TIMER_ANY_CHANNEL; + tmr.startTime = rec.second.GetStart(); + tmr.endTime = rec.second.GetStop(); if (tmr.startTime == 0) tmr.bStartAnyTime = true; if (tmr.endTime == 0) @@ -86,36 +86,36 @@ void AutoRecordings::GetAutorecTimers(std::vector& timers) tmr.endTime = tmr.startTime + 60 * 60; // Nominal 1 hour duration } - 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); + if (rec.second.GetName().empty()) // timers created on backend may not contain a name + strncpy(tmr.strTitle, rec.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(), + strncpy(tmr.strTitle, rec.second.GetName().c_str(), sizeof(tmr.strTitle) - 1); + strncpy(tmr.strEpgSearchString, rec.second.GetTitle().c_str(), sizeof(tmr.strEpgSearchString) - 1); - strncpy(tmr.strDirectory, tit->second.GetDirectory().c_str(), sizeof(tmr.strDirectory) - 1); + strncpy(tmr.strDirectory, rec.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; + strncpy(tmr.strSeriesLink, rec.second.GetSeriesLink().c_str(), sizeof(tmr.strSeriesLink) - 1); + tmr.state = rec.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(); + rec.second.GetSeriesLink().empty() ? TIMER_REPEATING_EPG : TIMER_REPEATING_SERIESLINK; + tmr.iPriority = rec.second.GetPriority(); + tmr.iLifetime = rec.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(); + tmr.iPreventDuplicateEpisodes = rec.second.GetDupDetect(); else tmr.iPreventDuplicateEpisodes = 0; // not supported by tvh tmr.firstDay = 0; // not supported by tvh - tmr.iWeekdays = tit->second.GetDaysOfWeek(); + tmr.iWeekdays = rec.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.iMarginStart = static_cast(rec.second.GetMarginStart()); + tmr.iMarginEnd = static_cast(rec.second.GetMarginEnd()); tmr.iGenreType = 0; // not supported by tvh? tmr.iGenreSubType = 0; // not supported by tvh? - tmr.bFullTextEpgSearch = tit->second.GetFulltext(); + tmr.bFullTextEpgSearch = rec.second.GetFulltext(); tmr.iParentClientIndex = 0; timers.emplace_back(tmr); @@ -124,10 +124,10 @@ void AutoRecordings::GetAutorecTimers(std::vector& timers) const unsigned int AutoRecordings::GetTimerIntIdFromStringId(const std::string& strId) const { - for (auto tit = m_autoRecordings.begin(); tit != m_autoRecordings.end(); ++tit) + for (const auto& rec : m_autoRecordings) { - if (tit->second.GetStringId() == strId) - return tit->second.GetId(); + if (rec.second.GetStringId() == strId) + return rec.second.GetId(); } Logger::Log(LogLevel::LEVEL_ERROR, "Autorec: Unable to obtain int id for string id %s", strId.c_str()); @@ -136,10 +136,10 @@ const unsigned int AutoRecordings::GetTimerIntIdFromStringId(const std::string& const std::string AutoRecordings::GetTimerStringIdFromIntId(unsigned int intId) const { - for (auto tit = m_autoRecordings.begin(); tit != m_autoRecordings.end(); ++tit) + for (const auto& rec : m_autoRecordings) { - if (tit->second.GetId() == intId) - return tit->second.GetStringId(); + if (rec.second.GetId() == intId) + return rec.second.GetStringId(); } Logger::Log(LogLevel::LEVEL_ERROR, "Autorec: Unable to obtain string id for int id %s", intId); diff --git a/src/tvheadend/HTSPDemuxer.cpp b/src/tvheadend/HTSPDemuxer.cpp index 310ddf85..bfce08bd 100644 --- a/src/tvheadend/HTSPDemuxer.cpp +++ b/src/tvheadend/HTSPDemuxer.cpp @@ -843,9 +843,9 @@ void HTSPDemuxer::ParseQueueStatus(htsmsg_t* m) CLockObject lock(m_mutex); Logger::Log(LogLevel::LEVEL_TRACE, "stream stats:"); - for (auto it = m_streamStat.begin(); it != m_streamStat.end(); ++it) + for (const auto& stat : m_streamStat) { - Logger::Log(LogLevel::LEVEL_TRACE, " idx:%d num:%d", it->first, it->second); + Logger::Log(LogLevel::LEVEL_TRACE, " idx:%d num:%d", stat.first, stat.second); } Logger::Log(LogLevel::LEVEL_TRACE, "queue stats:"); diff --git a/src/tvheadend/TimeRecordings.cpp b/src/tvheadend/TimeRecordings.cpp index 9d3c21e6..1678bd9a 100644 --- a/src/tvheadend/TimeRecordings.cpp +++ b/src/tvheadend/TimeRecordings.cpp @@ -43,8 +43,8 @@ TimeRecordings::~TimeRecordings() void TimeRecordings::Connected() { /* Flag all async fields in case they've been deleted */ - for (auto it = m_timeRecordings.begin(); it != m_timeRecordings.end(); ++it) - it->second.SetDirty(true); + for (auto& rec : m_timeRecordings) + rec.second.SetDirty(true); } void TimeRecordings::SyncDvrCompleted() @@ -60,31 +60,31 @@ int TimeRecordings::GetTimerecTimerCount() const void TimeRecordings::GetTimerecTimers(std::vector& timers) { - for (auto tit = m_timeRecordings.begin(); tit != m_timeRecordings.end(); ++tit) + for (const auto& rec : m_timeRecordings) { /* Setup entry */ PVR_TIMER tmr = {0}; - tmr.iClientIndex = tit->second.GetId(); + tmr.iClientIndex = rec.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); + (rec.second.GetChannel() > 0) ? rec.second.GetChannel() : PVR_TIMER_ANY_CHANNEL; + tmr.startTime = rec.second.GetStart(); + tmr.endTime = rec.second.GetStop(); + strncpy(tmr.strTitle, rec.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.strDirectory, rec.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.state = rec.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.iPriority = rec.second.GetPriority(); + tmr.iLifetime = rec.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.iWeekdays = rec.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 @@ -99,10 +99,10 @@ void TimeRecordings::GetTimerecTimers(std::vector& timers) const unsigned int TimeRecordings::GetTimerIntIdFromStringId(const std::string& strId) const { - for (auto tit = m_timeRecordings.begin(); tit != m_timeRecordings.end(); ++tit) + for (const auto& rec : m_timeRecordings) { - if (tit->second.GetStringId() == strId) - return tit->second.GetId(); + if (rec.second.GetStringId() == strId) + return rec.second.GetId(); } Logger::Log(LogLevel::LEVEL_ERROR, "Timerec: Unable to obtain int id for string id %s", strId.c_str()); @@ -111,10 +111,10 @@ const unsigned int TimeRecordings::GetTimerIntIdFromStringId(const std::string& const std::string TimeRecordings::GetTimerStringIdFromIntId(unsigned int intId) const { - for (auto tit = m_timeRecordings.begin(); tit != m_timeRecordings.end(); ++tit) + for (const auto& rec : m_timeRecordings) { - if (tit->second.GetId() == intId) - return tit->second.GetStringId(); + if (rec.second.GetId() == intId) + return rec.second.GetStringId(); } Logger::Log(LogLevel::LEVEL_ERROR, "Timerec: Unable to obtain string id for int id %s", intId); diff --git a/src/tvheadend/entity/Tag.cpp b/src/tvheadend/entity/Tag.cpp index 04e2be6d..436803bf 100644 --- a/src/tvheadend/entity/Tag.cpp +++ b/src/tvheadend/entity/Tag.cpp @@ -76,14 +76,12 @@ std::vector& Tag::GetChannels() bool Tag::ContainsChannelType(channel_type_t eType, const Channels& channels) const { - std::vector::const_iterator it; - - for (it = m_channels.begin(); it != m_channels.end(); ++it) + for (const auto& channel : m_channels) { - const auto cit = channels.find(*it); - if (cit != channels.end()) + const auto it = channels.find(channel); + if (it != channels.end()) { - if (cit->second.GetType() == eType) + if (it->second.GetType() == eType) return true; } } From 732dc03f9303b64867033e55d280a47b57e15790 Mon Sep 17 00:00:00 2001 From: Kai Sommerfeld Date: Sat, 19 Oct 2019 00:09:53 +0200 Subject: [PATCH 08/10] code cleanup: use std:: prefix. --- src/Tvheadend.cpp | 131 ++++++++++++------------ src/client.cpp | 7 +- src/tvheadend/AutoRecordings.cpp | 28 ++--- src/tvheadend/HTSPConnection.cpp | 2 +- src/tvheadend/HTSPDemuxer.cpp | 68 ++++++------ src/tvheadend/HTSPVFS.cpp | 2 +- src/tvheadend/Subscription.cpp | 14 +-- src/tvheadend/TimeRecordings.cpp | 21 ++-- src/tvheadend/entity/RecordingBase.cpp | 7 +- src/tvheadend/xbmc_codec_descriptor.hpp | 8 +- 10 files changed, 157 insertions(+), 131 deletions(-) diff --git a/src/Tvheadend.cpp b/src/Tvheadend.cpp index 9d117aac..7ee183b7 100644 --- a/src/Tvheadend.cpp +++ b/src/Tvheadend.cpp @@ -32,6 +32,8 @@ #include "tvheadend/utilities/Utilities.h" #include +#include +#include #include #include @@ -222,7 +224,7 @@ PVR_ERROR CTvheadend::GetTags(ADDON_HANDLE handle, bool bRadio) continue; PVR_CHANNEL_GROUP tag = {0}; - strncpy(tag.strGroupName, entry.second.GetName().c_str(), sizeof(tag.strGroupName) - 1); + std::strncpy(tag.strGroupName, entry.second.GetName().c_str(), sizeof(tag.strGroupName) - 1); tag.bIsRadio = bRadio; tag.iPosition = entry.second.GetIndex(); @@ -264,7 +266,7 @@ PVR_ERROR CTvheadend::GetTagMembers(ADDON_HANDLE handle, const PVR_CHANNEL_GROUP 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); + std::strncpy(gm.strGroupName, group.strGroupName, sizeof(gm.strGroupName) - 1); gm.iChannelUniqueId = cit->second.GetId(); gm.iChannelNumber = cit->second.GetNum(); gm.iSubChannelNumber = cit->second.GetNumMinor(); @@ -320,8 +322,8 @@ PVR_ERROR CTvheadend::GetChannels(ADDON_HANDLE handle, bool radio) 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); + std::strncpy(chn.strChannelName, channel.GetName().c_str(), sizeof(chn.strChannelName) - 1); + std::strncpy(chn.strIconPath, channel.GetIcon().c_str(), sizeof(chn.strIconPath) - 1); channels.emplace_back(chn); } @@ -423,34 +425,37 @@ PVR_ERROR CTvheadend::GetRecordings(ADDON_HANDLE handle) /* Channel icon */ const auto& cit = m_channels.find(recording.GetChannel()); if (cit != m_channels.end()) - strncpy(rec.strIconPath, cit->second.GetIcon().c_str(), sizeof(rec.strIconPath) - 1); + std::strncpy(rec.strIconPath, cit->second.GetIcon().c_str(), sizeof(rec.strIconPath) - 1); /* Channel name */ - strncpy(rec.strChannelName, recording.GetChannelName().c_str(), + std::strncpy(rec.strChannelName, recording.GetChannelName().c_str(), sizeof(rec.strChannelName) - 1); /* Thumbnail image */ - strncpy(rec.strThumbnailPath, recording.GetImage().c_str(), sizeof(rec.strThumbnailPath) - 1); + std::strncpy(rec.strThumbnailPath, recording.GetImage().c_str(), + sizeof(rec.strThumbnailPath) - 1); /* Fanart image */ - strncpy(rec.strFanartPath, recording.GetFanartImage().c_str(), sizeof(rec.strFanartPath) - 1); + std::strncpy(rec.strFanartPath, recording.GetFanartImage().c_str(), + sizeof(rec.strFanartPath) - 1); /* ID */ snprintf(buf, sizeof(buf), "%i", recording.GetId()); - strncpy(rec.strRecordingId, buf, sizeof(rec.strRecordingId) - 1); + std::strncpy(rec.strRecordingId, buf, sizeof(rec.strRecordingId) - 1); /* Title */ - strncpy(rec.strTitle, recording.GetTitle().c_str(), sizeof(rec.strTitle) - 1); + std::strncpy(rec.strTitle, recording.GetTitle().c_str(), sizeof(rec.strTitle) - 1); /* Subtitle */ - strncpy(rec.strEpisodeName, recording.GetSubtitle().c_str(), sizeof(rec.strEpisodeName) - 1); + std::strncpy(rec.strEpisodeName, recording.GetSubtitle().c_str(), + sizeof(rec.strEpisodeName) - 1); /* season/episode (tvh 4.3+) */ rec.iSeriesNumber = recording.GetSeason(); rec.iEpisodeNumber = recording.GetEpisode(); /* Description */ - strncpy(rec.strPlot, recording.GetDescription().c_str(), sizeof(rec.strPlot) - 1); + std::strncpy(rec.strPlot, recording.GetDescription().c_str(), sizeof(rec.strPlot) - 1); /* Genre */ rec.iGenreType = recording.GetGenreType(); @@ -493,13 +498,13 @@ PVR_ERROR CTvheadend::GetRecordings(ADDON_HANDLE handle) { size_t idx = recording.GetPath().rfind("/"); if (idx == 0 || idx == std::string::npos) - strncpy(rec.strDirectory, "/", sizeof(rec.strDirectory) - 1); + std::strncpy(rec.strDirectory, "/", sizeof(rec.strDirectory) - 1); else { std::string d = recording.GetPath().substr(0, idx); if (d[0] != '/') d = "/" + d; - strncpy(rec.strDirectory, d.c_str(), sizeof(rec.strDirectory) - 1); + std::strncpy(rec.strDirectory, d.c_str(), sizeof(rec.strDirectory) - 1); } } @@ -542,7 +547,7 @@ PVR_ERROR CTvheadend::GetRecordingEdl(const PVR_RECORDING& rec, PVR_EDL_ENTRY ed { /* Build request */ htsmsg_t* m = htsmsg_create_map(); - htsmsg_add_u32(m, "id", atoi(rec.strRecordingId)); + htsmsg_add_u32(m, "id", std::atoi(rec.strRecordingId)); Logger::Log(LogLevel::LEVEL_DEBUG, "dvr get cutpoints id=%s", rec.strRecordingId); @@ -620,7 +625,7 @@ PVR_ERROR CTvheadend::GetRecordingEdl(const PVR_RECORDING& rec, PVR_EDL_ENTRY ed PVR_ERROR CTvheadend::DeleteRecording(const PVR_RECORDING& rec) { - return SendDvrDelete(atoi(rec.strRecordingId), "deleteDvrEntry"); + return SendDvrDelete(std::atoi(rec.strRecordingId), "deleteDvrEntry"); } PVR_ERROR CTvheadend::RenameRecording(const PVR_RECORDING& rec) @@ -630,7 +635,7 @@ PVR_ERROR CTvheadend::RenameRecording(const PVR_RECORDING& rec) /* Build message */ htsmsg_t* m = htsmsg_create_map(); - htsmsg_add_u32(m, "id", atoi(rec.strRecordingId)); + htsmsg_add_u32(m, "id", std::atoi(rec.strRecordingId)); htsmsg_add_str(m, "title", rec.strTitle); return SendDvrUpdate(m); @@ -646,7 +651,7 @@ PVR_ERROR CTvheadend::SetLifetime(const PVR_RECORDING& rec) /* Build message */ htsmsg_t* m = htsmsg_create_map(); - htsmsg_add_u32(m, "id", atoi(rec.strRecordingId)); + htsmsg_add_u32(m, "id", std::atoi(rec.strRecordingId)); if (m_conn->GetProtocol() >= 25) htsmsg_add_u32(m, "removal", LifetimeMapper::KodiToTvh(rec.iLifetime)); // remove from disk @@ -667,7 +672,7 @@ PVR_ERROR CTvheadend::SetPlayCount(const PVR_RECORDING& rec, int playCount) /* Build message */ htsmsg_t* m = htsmsg_create_map(); - htsmsg_add_u32(m, "id", atoi(rec.strRecordingId)); + htsmsg_add_u32(m, "id", std::atoi(rec.strRecordingId)); htsmsg_add_u32(m, "playcount", playCount); return SendDvrUpdate(m); } @@ -682,7 +687,7 @@ PVR_ERROR CTvheadend::SetPlayPosition(const PVR_RECORDING& rec, int playPosition /* Build message */ htsmsg_t* m = htsmsg_create_map(); - htsmsg_add_u32(m, "id", atoi(rec.strRecordingId)); + htsmsg_add_u32(m, "id", std::atoi(rec.strRecordingId)); htsmsg_add_u32(m, "playposition", playPosition >= 0 ? playPosition : 0); // Kodi uses -1 when fully watched return SendDvrUpdate(m); @@ -695,7 +700,7 @@ int CTvheadend::GetPlayPosition(const PVR_RECORDING& rec) CLockObject lock(m_mutex); - const auto& it = m_recordings.find(atoi(rec.strRecordingId)); + const auto& it = m_recordings.find(std::atoi(rec.strRecordingId)); if (it != m_recordings.end() && it->second.IsRecording()) { Logger::Log(LogLevel::LEVEL_DEBUG, "Getting play position %i for recording %s", @@ -731,14 +736,14 @@ struct TimerType : PVR_TIMER_TYPE iLifetimesSize = lifetimeValues.size(); iLifetimesDefault = LifetimeMapper::TvhToKodi(Settings::GetInstance().GetDvrLifetime()); - strncpy(strDescription, description.c_str(), sizeof(strDescription) - 1); + std::strncpy(strDescription, description.c_str(), sizeof(strDescription) - 1); int i = 0; for (const auto& priorityValue : priorityValues) { priorities[i].iValue = priorityValue.first; - strncpy(priorities[i].strDescription, priorityValue.second.c_str(), - sizeof(priorities[i].strDescription) - 1); + std::strncpy(priorities[i].strDescription, priorityValue.second.c_str(), + sizeof(priorities[i].strDescription) - 1); ++i; } @@ -746,8 +751,8 @@ struct TimerType : PVR_TIMER_TYPE for (const auto& dupEpisodesValue : dupEpisodesValues) { preventDuplicateEpisodes[i].iValue = dupEpisodesValue.first; - strncpy(preventDuplicateEpisodes[i].strDescription, dupEpisodesValue.second.c_str(), - sizeof(preventDuplicateEpisodes[i].strDescription) - 1); + std::strncpy(preventDuplicateEpisodes[i].strDescription, dupEpisodesValue.second.c_str(), + sizeof(preventDuplicateEpisodes[i].strDescription) - 1); ++i; } @@ -755,8 +760,8 @@ struct TimerType : PVR_TIMER_TYPE for (const auto& lifetimeValue : lifetimeValues) { lifetimes[i].iValue = lifetimeValue.first; - strncpy(lifetimes[i].strDescription, lifetimeValue.second.c_str(), - sizeof(lifetimes[i].strDescription) - 1); + std::strncpy(lifetimes[i].strDescription, lifetimeValue.second.c_str(), + sizeof(lifetimes[i].strDescription) - 1); ++i; } } @@ -1059,11 +1064,11 @@ bool CTvheadend::CreateTimer(const Recording& tvhTmr, PVR_TIMER& tmr) 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); + std::strncpy(tmr.strTitle, tvhTmr.GetTitle().c_str(), sizeof(tmr.strTitle) - 1); + std::strncpy(tmr.strEpgSearchString, "", + sizeof(tmr.strEpgSearchString) - 1); // n/a for one-shot timers + std::strncpy(tmr.strDirectory, "", sizeof(tmr.strDirectory) - 1); // n/a for one-shot timers + std::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(); @@ -1155,7 +1160,7 @@ PVR_ERROR CTvheadend::AddTimer(const PVR_TIMER& timer) if (start == 0) { /* Instant timer. Adjust start time to 'now'. */ - start = time(nullptr); + start = std::time(nullptr); } htsmsg_add_s64(m, "start", start); @@ -1305,7 +1310,7 @@ PVR_ERROR CTvheadend::UpdateTimer(const PVR_TIMER& timer) if (start == 0) { /* Instant timer. Adjust start time to 'now'. */ - start = time(nullptr); + start = std::time(nullptr); } htsmsg_add_s64(m, "start", start); @@ -1543,7 +1548,7 @@ bool CTvheadend::Connected() htsmsg_add_u32(msg, "epg", 1); if (m_epgMaxDays > EPG_TIMEFRAME_UNLIMITED) htsmsg_add_s64(msg, "epgMaxTime", - static_cast(time(nullptr) + m_epgMaxDays * int64_t(24 * 60 * 60))); + static_cast(std::time(nullptr) + m_epgMaxDays * int64_t(24 * 60 * 60))); } else htsmsg_add_u32(msg, "epg", 0); @@ -1608,7 +1613,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(std::atoi(rec.strRecordingId)); if (it != m_recordings.end()) { m_playingRecording = &(it->second); @@ -1731,73 +1736,73 @@ void* CTvheadend::Process() CLockObject lock(m_mutex); /* Channels */ - if (!strcmp("channelAdd", method)) + if (!std::strcmp("channelAdd", method)) ParseChannelAddOrUpdate(msg.GetMessage(), true); - else if (!strcmp("channelUpdate", method)) + else if (!std::strcmp("channelUpdate", method)) ParseChannelAddOrUpdate(msg.GetMessage(), false); - else if (!strcmp("channelDelete", method)) + else if (!std::strcmp("channelDelete", method)) ParseChannelDelete(msg.GetMessage()); /* Channel Tags (aka channel groups)*/ - else if (!strcmp("tagAdd", method)) + else if (!std::strcmp("tagAdd", method)) ParseTagAddOrUpdate(msg.GetMessage(), true); - else if (!strcmp("tagUpdate", method)) + else if (!std::strcmp("tagUpdate", method)) ParseTagAddOrUpdate(msg.GetMessage(), false); - else if (!strcmp("tagDelete", method)) + else if (!std::strcmp("tagDelete", method)) ParseTagDelete(msg.GetMessage()); /* Recordings */ - else if (!strcmp("dvrEntryAdd", method)) + else if (!std::strcmp("dvrEntryAdd", method)) ParseRecordingAddOrUpdate(msg.GetMessage(), true); - else if (!strcmp("dvrEntryUpdate", method)) + else if (!std::strcmp("dvrEntryUpdate", method)) ParseRecordingAddOrUpdate(msg.GetMessage(), false); - else if (!strcmp("dvrEntryDelete", method)) + else if (!std::strcmp("dvrEntryDelete", method)) ParseRecordingDelete(msg.GetMessage()); /* Timerec */ - else if (!strcmp("timerecEntryAdd", method)) + else if (!std::strcmp("timerecEntryAdd", method)) { if (m_timeRecordings.ParseTimerecAddOrUpdate(msg.GetMessage(), true)) TriggerTimerUpdate(); } - else if (!strcmp("timerecEntryUpdate", method)) + else if (!std::strcmp("timerecEntryUpdate", method)) { if (m_timeRecordings.ParseTimerecAddOrUpdate(msg.GetMessage(), false)) TriggerTimerUpdate(); } - else if (!strcmp("timerecEntryDelete", method)) + else if (!std::strcmp("timerecEntryDelete", method)) { if (m_timeRecordings.ParseTimerecDelete(msg.GetMessage())) TriggerTimerUpdate(); } /* Autorec */ - else if (!strcmp("autorecEntryAdd", method)) + else if (!std::strcmp("autorecEntryAdd", method)) { if (m_autoRecordings.ParseAutorecAddOrUpdate(msg.GetMessage(), true)) TriggerTimerUpdate(); } - else if (!strcmp("autorecEntryUpdate", method)) + else if (!std::strcmp("autorecEntryUpdate", method)) { if (m_autoRecordings.ParseAutorecAddOrUpdate(msg.GetMessage(), false)) TriggerTimerUpdate(); } - else if (!strcmp("autorecEntryDelete", method)) + else if (!std::strcmp("autorecEntryDelete", method)) { if (m_autoRecordings.ParseAutorecDelete(msg.GetMessage())) TriggerTimerUpdate(); } /* EPG */ - else if (!strcmp("eventAdd", method)) + else if (!std::strcmp("eventAdd", method)) ParseEventAddOrUpdate(msg.GetMessage(), true); - else if (!strcmp("eventUpdate", method)) + else if (!std::strcmp("eventUpdate", method)) ParseEventAddOrUpdate(msg.GetMessage(), false); - else if (!strcmp("eventDelete", method)) + else if (!std::strcmp("eventDelete", method)) ParseEventDelete(msg.GetMessage()); /* ASync complete */ - else if (!strcmp("initialSyncCompleted", method)) + else if (!std::strcmp("initialSyncCompleted", method)) SyncCompleted(); /* Unknown */ @@ -2169,9 +2174,9 @@ void CTvheadend::ParseChannelAddOrUpdate(htsmsg_t* msg, bool bAdd) str = htsmsg_get_str(&f->hmf_msg, "type"); if (str) { - if (!strcmp(str, "Radio")) + if (!std::strcmp(str, "Radio")) channel.SetType(CHANNEL_TYPE_RADIO); - else if (!strcmp(str, "SDTV") || !strcmp(str, "HDTV")) + else if (!std::strcmp(str, "SDTV") || !std::strcmp(str, "HDTV")) channel.SetType(CHANNEL_TYPE_TV); } } @@ -2516,7 +2521,7 @@ void CTvheadend::ParseRecordingAddOrUpdate(htsmsg_t* msg, bool bAdd) str = htsmsg_get_str(msg, "error"); if (str) { - if (!strcmp(str, "300")) + if (!std::strcmp(str, "300")) rec.SetState(PVR_TIMER_STATE_ABORTED); else if (strstr(str, "missing") != nullptr) rec.SetState(PVR_TIMER_STATE_ERROR); @@ -2533,7 +2538,7 @@ void CTvheadend::ParseRecordingAddOrUpdate(htsmsg_t* msg, bool bAdd) if (str) { /* No free adapter, AKA subscription conflict */ - if (!strcmp("noFreeAdapter", str)) + if (!std::strcmp("noFreeAdapter", str)) rec.SetState(PVR_TIMER_STATE_CONFLICT_NOK); } } @@ -2737,11 +2742,11 @@ bool CTvheadend::ParseEvent(htsmsg_t* msg, bool bAdd, Event& evt) if (!str) continue; - if (!strcmp(str, "writer")) + if (!std::strcmp(str, "writer")) writers.emplace_back(f->hmf_name); - else if (!strcmp(str, "director")) + else if (!std::strcmp(str, "director")) directors.emplace_back(f->hmf_name); - else if (!strcmp(str, "actor") || !strcmp(str, "guest") || !strcmp(str, "presenter")) + else if (!std::strcmp(str, "actor") || !std::strcmp(str, "guest") || !std::strcmp(str, "presenter")) cast.emplace_back(f->hmf_name); } diff --git a/src/client.cpp b/src/client.cpp index 93fd4cf7..a81e13a2 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -28,6 +28,8 @@ #include "tvheadend/Settings.h" #include "tvheadend/utilities/Logger.h" +#include + using namespace ADDON; using namespace P8PLATFORM; using namespace tvheadend; @@ -185,8 +187,9 @@ PVR_ERROR GetAddonCapabilities(PVR_ADDON_CAPABILITIES* pCapabilities) for (const auto& lifetimeValue : lifetimeValues) { pCapabilities->recordingsLifetimeValues[i].iValue = lifetimeValue.first; - strncpy(pCapabilities->recordingsLifetimeValues[i].strDescription, lifetimeValue.second.c_str(), - sizeof(pCapabilities->recordingsLifetimeValues[i].strDescription) - 1); + std::strncpy(pCapabilities->recordingsLifetimeValues[i].strDescription, + lifetimeValue.second.c_str(), + sizeof(pCapabilities->recordingsLifetimeValues[i].strDescription) - 1); ++i; } } diff --git a/src/tvheadend/AutoRecordings.cpp b/src/tvheadend/AutoRecordings.cpp index 71ba04b5..d880e3f8 100644 --- a/src/tvheadend/AutoRecordings.cpp +++ b/src/tvheadend/AutoRecordings.cpp @@ -28,6 +28,9 @@ #include "utilities/Logger.h" #include "utilities/Utilities.h" +#include +#include + using namespace P8PLATFORM; using namespace tvheadend; using namespace tvheadend::entity; @@ -82,19 +85,20 @@ void AutoRecordings::GetAutorecTimers(std::vector& timers) tmr.startTime = tmr.endTime - 60 * 60; // Nominal 1 hour duration if (tmr.bStartAnyTime && tmr.bEndAnyTime) { - tmr.startTime = time(nullptr); // now + tmr.startTime = std::time(nullptr); // now tmr.endTime = tmr.startTime + 60 * 60; // Nominal 1 hour duration } if (rec.second.GetName().empty()) // timers created on backend may not contain a name - strncpy(tmr.strTitle, rec.second.GetTitle().c_str(), sizeof(tmr.strTitle) - 1); + std::strncpy(tmr.strTitle, rec.second.GetTitle().c_str(), sizeof(tmr.strTitle) - 1); else - strncpy(tmr.strTitle, rec.second.GetName().c_str(), sizeof(tmr.strTitle) - 1); - strncpy(tmr.strEpgSearchString, rec.second.GetTitle().c_str(), - sizeof(tmr.strEpgSearchString) - 1); - strncpy(tmr.strDirectory, rec.second.GetDirectory().c_str(), sizeof(tmr.strDirectory) - 1); - strncpy(tmr.strSummary, "", sizeof(tmr.strSummary) - 1); // n/a for repeating timers - strncpy(tmr.strSeriesLink, rec.second.GetSeriesLink().c_str(), sizeof(tmr.strSeriesLink) - 1); + std::strncpy(tmr.strTitle, rec.second.GetName().c_str(), sizeof(tmr.strTitle) - 1); + std::strncpy(tmr.strEpgSearchString, rec.second.GetTitle().c_str(), + sizeof(tmr.strEpgSearchString) - 1); + std::strncpy(tmr.strDirectory, rec.second.GetDirectory().c_str(), sizeof(tmr.strDirectory) - 1); + std::strncpy(tmr.strSummary, "", sizeof(tmr.strSummary) - 1); // n/a for repeating timers + std::strncpy(tmr.strSeriesLink, rec.second.GetSeriesLink().c_str(), + sizeof(tmr.strSeriesLink) - 1); tmr.state = rec.second.IsEnabled() ? PVR_TIMER_STATE_SCHEDULED : PVR_TIMER_STATE_DISABLED; tmr.iTimerType = rec.second.GetSeriesLink().empty() ? TIMER_REPEATING_EPG : TIMER_REPEATING_SERIESLINK; @@ -227,7 +231,7 @@ PVR_ERROR AutoRecordings::SendAutorecAddOrUpdate(const PVR_TIMER& timer, bool up /* Note: As a result of internal filename cleanup, for "directory" == "/", */ /* tvh would put recordings into a folder named "-". Not a big issue */ /* but ugly. */ - if (strcmp(timer.strDirectory, "/") != 0) + if (std::strcmp(timer.strDirectory, "/") != 0) htsmsg_add_str(m, "directory", timer.strDirectory); @@ -244,7 +248,7 @@ 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); + struct tm* tm_start = std::localtime(&startTime); int32_t startWindowBegin = tm_start->tm_hour * 60 + tm_start->tm_min - settings.GetAutorecMaxDiff(); int32_t startWindowEnd = @@ -266,7 +270,7 @@ 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 = std::localtime(&startTime); htsmsg_add_s32(m, "start", tm_start->tm_hour * 60 + tm_start->tm_min); } else @@ -278,7 +282,7 @@ PVR_ERROR AutoRecordings::SendAutorecAddOrUpdate(const PVR_TIMER& timer, bool up { /* Exact stop time (minutes from midnight). */ time_t endTime = timer.endTime; - struct tm* tm_stop = localtime(&endTime); + struct tm* tm_stop = std::localtime(&endTime); htsmsg_add_s32(m, "startWindow", tm_stop->tm_hour * 60 + tm_stop->tm_min); } else diff --git a/src/tvheadend/HTSPConnection.cpp b/src/tvheadend/HTSPConnection.cpp index 10682524..a9bf580b 100644 --- a/src/tvheadend/HTSPConnection.cpp +++ b/src/tvheadend/HTSPConnection.cpp @@ -499,7 +499,7 @@ bool HTSPConnection::SendHello() { m_challenge = malloc(chal_len); m_challengeLen = chal_len; - memcpy(m_challenge, chal, chal_len); + std::memcpy(m_challenge, chal, chal_len); } htsmsg_destroy(msg); diff --git a/src/tvheadend/HTSPDemuxer.cpp b/src/tvheadend/HTSPDemuxer.cpp index bfce08bd..3193656f 100644 --- a/src/tvheadend/HTSPDemuxer.cpp +++ b/src/tvheadend/HTSPDemuxer.cpp @@ -27,6 +27,9 @@ #include "utilities/Logger.h" #include "xbmc_codec_descriptor.hpp" +#include +#include + #define TVH_TO_DVD_TIME(x) (static_cast(x) * DVD_TIME_BASE / 1000000.0f) #define INVALID_SEEKTIME (-1) @@ -115,7 +118,7 @@ bool HTSPDemuxer::Open(uint32_t channelId, enum eSubscriptionWeight weight) if (!m_subscription.IsActive()) m_subscription.SendUnsubscribe(); else - m_lastUse.store(time(nullptr)); + m_lastUse.store(std::time(nullptr)); return m_subscription.IsActive(); } @@ -130,7 +133,7 @@ void HTSPDemuxer::Close() DemuxPacket* HTSPDemuxer::Read() { - m_lastUse.store(time(nullptr)); + m_lastUse.store(std::time(nullptr)); DemuxPacket* pkt = nullptr; if (m_pktBuffer.Pop(pkt, 100)) @@ -258,7 +261,7 @@ PVR_ERROR HTSPDemuxer::CurrentStreams(PVR_STREAM_PROPERTIES* props) for (size_t i = 0; i < m_streams.size(); i++) { - memcpy(&props->stream[i], &m_streams.at(i), sizeof(PVR_STREAM_PROPERTIES::PVR_STREAM)); + std::memcpy(&props->stream[i], &m_streams.at(i), sizeof(PVR_STREAM_PROPERTIES::PVR_STREAM)); } props->iStreamCount = static_cast(m_streams.size()); @@ -271,11 +274,13 @@ PVR_ERROR HTSPDemuxer::CurrentSignal(PVR_SIGNAL_STATUS& sig) 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); + std::strncpy(sig.strAdapterName, m_sourceInfo.si_adapter.c_str(), sizeof(sig.strAdapterName) - 1); + std::strncpy(sig.strAdapterStatus, m_signalInfo.fe_status.c_str(), + sizeof(sig.strAdapterStatus) - 1); + std::strncpy(sig.strServiceName, m_sourceInfo.si_service.c_str(), sizeof(sig.strServiceName) - 1); + std::strncpy(sig.strProviderName, m_sourceInfo.si_provider.c_str(), + sizeof(sig.strProviderName) - 1); + std::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; @@ -297,11 +302,12 @@ 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->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); + std::strncpy(info->strCardSystem, m_descrambleInfo.GetCardSystem().c_str(), + sizeof(info->strCardSystem) - 1); + std::strncpy(info->strReader, m_descrambleInfo.GetReader().c_str(), sizeof(info->strReader) - 1); + std::strncpy(info->strFrom, m_descrambleInfo.GetFrom().c_str(), sizeof(info->strFrom) - 1); + std::strncpy(info->strProtocol, m_descrambleInfo.GetProtocol().c_str(), + sizeof(info->strProtocol) - 1); return PVR_ERROR_NO_ERROR; } @@ -399,27 +405,27 @@ void HTSPDemuxer::ResetStatus(bool resetStartTime /* = true */) bool HTSPDemuxer::ProcessMessage(const char* method, htsmsg_t* m) { /* Subscription messages */ - if (!strcmp("muxpkt", method)) + if (!std::strcmp("muxpkt", method)) ParseMuxPacket(m); - else if (!strcmp("subscriptionStatus", method)) + else if (!std::strcmp("subscriptionStatus", method)) m_subscription.ParseSubscriptionStatus(m); - else if (!strcmp("queueStatus", method)) + else if (!std::strcmp("queueStatus", method)) ParseQueueStatus(m); - else if (!strcmp("signalStatus", method)) + else if (!std::strcmp("signalStatus", method)) ParseSignalStatus(m); - else if (!strcmp("timeshiftStatus", method)) + else if (!std::strcmp("timeshiftStatus", method)) ParseTimeshiftStatus(m); - else if (!strcmp("descrambleInfo", method)) + else if (!std::strcmp("descrambleInfo", method)) ParseDescrambleInfo(m); - else if (!strcmp("subscriptionStart", method)) + else if (!std::strcmp("subscriptionStart", method)) ParseSubscriptionStart(m); - else if (!strcmp("subscriptionStop", method)) + else if (!std::strcmp("subscriptionStop", method)) ParseSubscriptionStop(m); - else if (!strcmp("subscriptionSkip", method)) + else if (!std::strcmp("subscriptionSkip", method)) ParseSubscriptionSkip(m); - else if (!strcmp("subscriptionSpeed", method)) + else if (!std::strcmp("subscriptionSpeed", method)) ParseSubscriptionSpeed(m); - else if (!strcmp("subscriptionGrace", method)) + else if (!std::strcmp("subscriptionGrace", method)) ParseSubscriptionGrace(m); else Logger::Log(LogLevel::LEVEL_DEBUG, "demux unhandled subscription message [%s]", method); @@ -468,7 +474,7 @@ void HTSPDemuxer::ProcessRDS(uint32_t idx, const void* bin, size_t binlen) for (size_t i = offset - 2, j = 0; i > 3 && i > offset - 2 - rdslen; i--, j++) rdsdata[j] = data[i]; - memcpy(pkt->pData, rdsdata, rdslen); + std::memcpy(pkt->pData, rdsdata, rdslen); pkt->iSize = rdslen; pkt->iStreamId = rdsIdx; @@ -516,7 +522,7 @@ void HTSPDemuxer::ParseMuxPacket(htsmsg_t* m) if (!pkt) return; - memcpy(pkt->pData, bin, binlen); + std::memcpy(pkt->pData, bin, binlen); pkt->iSize = binlen; pkt->iStreamId = idx; @@ -556,7 +562,7 @@ void HTSPDemuxer::ParseMuxPacket(htsmsg_t* m) if (m_startTime == 0) { // first paket for this subscription - m_startTime = time(nullptr); + m_startTime = std::time(nullptr); } m_pktBuffer.Push(pkt); @@ -587,7 +593,7 @@ bool HTSPDemuxer::AddRDSStream(uint32_t audioIdx, uint32_t rdsIdx) rdsStream.iCodecType = codec.codec_type; rdsStream.iCodecId = codec.codec_id; rdsStream.iPID = rdsIdx; - strncpy(rdsStream.strLanguage, stream.strLanguage, sizeof(rdsStream.strLanguage) - 1); + std::strncpy(rdsStream.strLanguage, stream.strLanguage, sizeof(rdsStream.strLanguage) - 1); // We can only use PVR_STREAM_MAX_STREAMS streams if (m_streams.size() < PVR_STREAM_MAX_STREAMS) @@ -624,7 +630,7 @@ 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) && !std::strcmp("DVBSUB", type)) { uint32_t composition_id = 0, ancillary_id = 0; htsmsg_get_u32(&f->hmf_msg, "composition_id", &composition_id); @@ -638,7 +644,7 @@ bool HTSPDemuxer::AddTVHStream(uint32_t idx, const char* type, htsmsg_field_t* f { const char* language = htsmsg_get_str(&f->hmf_msg, "language"); if (language) - strncpy(stream.strLanguage, language, sizeof(stream.strLanguage) - 1); + std::strncpy(stream.strLanguage, language, sizeof(stream.strLanguage) - 1); } /* Audio data */ @@ -647,7 +653,7 @@ bool HTSPDemuxer::AddTVHStream(uint32_t idx, const char* type, htsmsg_field_t* f stream.iChannels = htsmsg_get_u32_or_default(&f->hmf_msg, "channels", 2); stream.iSampleRate = htsmsg_get_u32_or_default(&f->hmf_msg, "rate", 48000); - if (strcmp("MPEG2AUDIO", type) == 0) + if (std::strcmp("MPEG2AUDIO", type) == 0) { // mpeg2 audio streams may contain embedded RDS data. // We will find out when the first stream packet arrives. diff --git a/src/tvheadend/HTSPVFS.cpp b/src/tvheadend/HTSPVFS.cpp index 1ee9cc13..3f07fad3 100644 --- a/src/tvheadend/HTSPVFS.cpp +++ b/src/tvheadend/HTSPVFS.cpp @@ -375,7 +375,7 @@ ssize_t HTSPVFS::SendFileRead(unsigned char* buf, unsigned int len) } else { - memcpy(buf, buffer, read); + std::memcpy(buf, buffer, read); } /* Cleanup */ diff --git a/src/tvheadend/Subscription.cpp b/src/tvheadend/Subscription.cpp index 96071ac2..848404e2 100644 --- a/src/tvheadend/Subscription.cpp +++ b/src/tvheadend/Subscription.cpp @@ -25,6 +25,8 @@ #include "utilities/LocalizedString.h" #include "utilities/Logger.h" +#include + using namespace P8PLATFORM; using namespace tvheadend; using namespace tvheadend::utilities; @@ -264,17 +266,17 @@ void Subscription::ParseSubscriptionStatus(htsmsg_t* m) /* This field is absent when everything is fine */ if (error) { - if (!strcmp("badSignal", error)) + if (!std::strcmp("badSignal", error)) SetState(SUBSCRIPTION_NOSIGNAL); - else if (!strcmp("scrambled", error)) + else if (!std::strcmp("scrambled", error)) SetState(SUBSCRIPTION_SCRAMBLED); - else if (!strcmp("userLimit", error)) + else if (!std::strcmp("userLimit", error)) SetState(SUBSCRIPTION_USERLIMIT); - else if (!strcmp("noFreeAdapter", error)) + else if (!std::strcmp("noFreeAdapter", error)) SetState(SUBSCRIPTION_NOFREEADAPTER); - else if (!strcmp("tuningFailed", error)) + else if (!std::strcmp("tuningFailed", error)) SetState(SUBSCRIPTION_TUNINGFAILED); - else if (!strcmp("userAccess", error)) + else if (!std::strcmp("userAccess", error)) SetState(SUBSCRIPTION_NOACCESS); else SetState(SUBSCRIPTION_UNKNOWN); diff --git a/src/tvheadend/TimeRecordings.cpp b/src/tvheadend/TimeRecordings.cpp index 1678bd9a..41d50594 100644 --- a/src/tvheadend/TimeRecordings.cpp +++ b/src/tvheadend/TimeRecordings.cpp @@ -27,6 +27,9 @@ #include "utilities/Logger.h" #include "utilities/Utilities.h" +#include +#include + using namespace P8PLATFORM; using namespace tvheadend; using namespace tvheadend::entity; @@ -70,12 +73,12 @@ void TimeRecordings::GetTimerecTimers(std::vector& timers) (rec.second.GetChannel() > 0) ? rec.second.GetChannel() : PVR_TIMER_ANY_CHANNEL; tmr.startTime = rec.second.GetStart(); tmr.endTime = rec.second.GetStop(); - strncpy(tmr.strTitle, rec.second.GetName().c_str(), sizeof(tmr.strTitle) - 1); - strncpy(tmr.strEpgSearchString, "", - sizeof(tmr.strEpgSearchString) - 1); // n/a for manual timers - strncpy(tmr.strDirectory, rec.second.GetDirectory().c_str(), sizeof(tmr.strDirectory) - 1); - strncpy(tmr.strSummary, "", - sizeof(tmr.strSummary) - 1); // n/a for repeating timers + std::strncpy(tmr.strTitle, rec.second.GetName().c_str(), sizeof(tmr.strTitle) - 1); + std::strncpy(tmr.strEpgSearchString, "", + sizeof(tmr.strEpgSearchString) - 1); // n/a for manual timers + std::strncpy(tmr.strDirectory, rec.second.GetDirectory().c_str(), sizeof(tmr.strDirectory) - 1); + std::strncpy(tmr.strSummary, "", + sizeof(tmr.strSummary) - 1); // n/a for repeating timers tmr.state = rec.second.IsEnabled() ? PVR_TIMER_STATE_SCHEDULED : PVR_TIMER_STATE_DISABLED; tmr.iTimerType = TIMER_REPEATING_MANUAL; tmr.iPriority = rec.second.GetPriority(); @@ -167,11 +170,11 @@ PVR_ERROR TimeRecordings::SendTimerecAddOrUpdate(const PVR_TIMER& timer, bool up htsmsg_add_str(m, "name", timer.strTitle); htsmsg_add_str(m, "title", title); time_t startTime = timer.startTime; - struct tm* tm_start = localtime(&startTime); + struct tm* tm_start = std::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); + struct tm* tm_stop = std::localtime(&endTime); htsmsg_add_u32(m, "stop", tm_stop->tm_hour * 60 + tm_stop->tm_min); // end time in minutes from midnight @@ -194,7 +197,7 @@ PVR_ERROR TimeRecordings::SendTimerecAddOrUpdate(const PVR_TIMER& timer, bool up /* Note: As a result of internal filename cleanup, for "directory" == "/", */ /* tvh would put recordings into a folder named "-". Not a big issue */ /* but ugly. */ - if (strcmp(timer.strDirectory, "/") != 0) + if (std::strcmp(timer.strDirectory, "/") != 0) htsmsg_add_str(m, "directory", timer.strDirectory); /* Send and Wait */ diff --git a/src/tvheadend/entity/RecordingBase.cpp b/src/tvheadend/entity/RecordingBase.cpp index 8494d193..26ae2d68 100644 --- a/src/tvheadend/entity/RecordingBase.cpp +++ b/src/tvheadend/entity/RecordingBase.cpp @@ -24,6 +24,7 @@ #include "../utilities/LifetimeMapper.h" #include +#include using namespace tvheadend::entity; @@ -152,14 +153,14 @@ time_t RecordingBase::LocaltimeToUTC(int32_t lctime) /* Note: lctime contains minutes from midnight (up to 24*60) as local time. */ /* complete lctime with current year, month, day, ... */ - time_t t = time(nullptr); - struct tm* tm_time = localtime(&t); + time_t t = std::time(nullptr); + struct tm* tm_time = std::localtime(&t); tm_time->tm_hour = lctime / 60; tm_time->tm_min = lctime % 60; tm_time->tm_sec = 0; - return mktime(tm_time); + return std::mktime(tm_time); } // static diff --git a/src/tvheadend/xbmc_codec_descriptor.hpp b/src/tvheadend/xbmc_codec_descriptor.hpp index fccd0064..fef000d1 100644 --- a/src/tvheadend/xbmc_codec_descriptor.hpp +++ b/src/tvheadend/xbmc_codec_descriptor.hpp @@ -22,6 +22,8 @@ #include "kodi/libXBMC_pvr.h" +#include + /** * Adapter which converts codec names used by tvheadend and VDR into their * FFmpeg equivalents. @@ -44,11 +46,11 @@ class CodecDescriptor { CodecDescriptor retVal; // some of Tvheadend's and VDR's codec names don't match ffmpeg's, so translate them to something ffmpeg understands - if (!strcmp(strCodecName, "MPEG2AUDIO")) + if (!std::strcmp(strCodecName, "MPEG2AUDIO")) retVal = CodecDescriptor(PVR->GetCodecByName("MP2"), strCodecName); - else if (!strcmp(strCodecName, "MPEGTS")) + else if (!std::strcmp(strCodecName, "MPEGTS")) retVal = CodecDescriptor(PVR->GetCodecByName("MPEG2VIDEO"), strCodecName); - else if (!strcmp(strCodecName, "TEXTSUB")) + else if (!std::strcmp(strCodecName, "TEXTSUB")) retVal = CodecDescriptor(PVR->GetCodecByName("TEXT"), strCodecName); else retVal = CodecDescriptor(PVR->GetCodecByName(strCodecName), strCodecName); From a93078dfcf32912f188db8b213fc5427bd9b2233 Mon Sep 17 00:00:00 2001 From: Kai Sommerfeld Date: Tue, 22 Oct 2019 14:40:35 +0200 Subject: [PATCH 09/10] code cleanup: strcmp -> std::string --- src/Tvheadend.cpp | 47 ++++++++++++------------- src/Tvheadend.h | 2 +- src/tvheadend/HTSPDemuxer.cpp | 26 +++++++------- src/tvheadend/HTSPDemuxer.h | 2 +- src/tvheadend/IHTSPConnectionListener.h | 2 +- 5 files changed, 39 insertions(+), 40 deletions(-) diff --git a/src/Tvheadend.cpp b/src/Tvheadend.cpp index 7ee183b7..ffc8f233 100644 --- a/src/Tvheadend.cpp +++ b/src/Tvheadend.cpp @@ -1664,7 +1664,7 @@ bool CTvheadend::VfsIsRealTimeStream() * Message handling * *************************************************************************/ -bool CTvheadend::ProcessMessage(const char* method, htsmsg_t* msg) +bool CTvheadend::ProcessMessage(const std::string& method, htsmsg_t* msg) { uint32_t subId = 0; if (!htsmsg_get_u32(msg, "subscriptionId", &subId)) @@ -1711,12 +1711,11 @@ void CTvheadend::CloseExpiredSubscriptions() void* CTvheadend::Process() { - HTSPMessage msg = {}; - while (!IsStopped()) { /* Check Q */ // this is a bit horrible, but meh + HTSPMessage msg = {}; bool bSuccess = m_queue.Pop(msg, 2000); if (IsStopped()) @@ -1728,7 +1727,7 @@ void* CTvheadend::Process() if (!bSuccess || !msg.GetMessage()) continue; - const char* method = msg.GetMethod().c_str(); + const std::string& method = msg.GetMethod(); SHTSPEventList eventsCopy; /* Scope lock for processing */ @@ -1736,78 +1735,78 @@ void* CTvheadend::Process() CLockObject lock(m_mutex); /* Channels */ - if (!std::strcmp("channelAdd", method)) + if (method == "channelAdd") ParseChannelAddOrUpdate(msg.GetMessage(), true); - else if (!std::strcmp("channelUpdate", method)) + else if (method == "channelUpdate") ParseChannelAddOrUpdate(msg.GetMessage(), false); - else if (!std::strcmp("channelDelete", method)) + else if (method == "channelDelete") ParseChannelDelete(msg.GetMessage()); /* Channel Tags (aka channel groups)*/ - else if (!std::strcmp("tagAdd", method)) + else if (method == "tagAdd") ParseTagAddOrUpdate(msg.GetMessage(), true); - else if (!std::strcmp("tagUpdate", method)) + else if (method == "tagUpdate") ParseTagAddOrUpdate(msg.GetMessage(), false); - else if (!std::strcmp("tagDelete", method)) + else if (method == "tagDelete") ParseTagDelete(msg.GetMessage()); /* Recordings */ - else if (!std::strcmp("dvrEntryAdd", method)) + else if (method == "dvrEntryAdd") ParseRecordingAddOrUpdate(msg.GetMessage(), true); - else if (!std::strcmp("dvrEntryUpdate", method)) + else if (method == "dvrEntryUpdate") ParseRecordingAddOrUpdate(msg.GetMessage(), false); - else if (!std::strcmp("dvrEntryDelete", method)) + else if (method == "dvrEntryDelete") ParseRecordingDelete(msg.GetMessage()); /* Timerec */ - else if (!std::strcmp("timerecEntryAdd", method)) + else if (method == "timerecEntryAdd") { if (m_timeRecordings.ParseTimerecAddOrUpdate(msg.GetMessage(), true)) TriggerTimerUpdate(); } - else if (!std::strcmp("timerecEntryUpdate", method)) + else if (method == "timerecEntryUpdate") { if (m_timeRecordings.ParseTimerecAddOrUpdate(msg.GetMessage(), false)) TriggerTimerUpdate(); } - else if (!std::strcmp("timerecEntryDelete", method)) + else if (method == "timerecEntryDelete") { if (m_timeRecordings.ParseTimerecDelete(msg.GetMessage())) TriggerTimerUpdate(); } /* Autorec */ - else if (!std::strcmp("autorecEntryAdd", method)) + else if (method == "autorecEntryAdd") { if (m_autoRecordings.ParseAutorecAddOrUpdate(msg.GetMessage(), true)) TriggerTimerUpdate(); } - else if (!std::strcmp("autorecEntryUpdate", method)) + else if (method == "autorecEntryUpdate") { if (m_autoRecordings.ParseAutorecAddOrUpdate(msg.GetMessage(), false)) TriggerTimerUpdate(); } - else if (!std::strcmp("autorecEntryDelete", method)) + else if (method == "autorecEntryDelete") { if (m_autoRecordings.ParseAutorecDelete(msg.GetMessage())) TriggerTimerUpdate(); } /* EPG */ - else if (!std::strcmp("eventAdd", method)) + else if (method == "eventAdd") ParseEventAddOrUpdate(msg.GetMessage(), true); - else if (!std::strcmp("eventUpdate", method)) + else if (method == "eventUpdate") ParseEventAddOrUpdate(msg.GetMessage(), false); - else if (!std::strcmp("eventDelete", method)) + else if (method == "eventDelete") ParseEventDelete(msg.GetMessage()); /* ASync complete */ - else if (!std::strcmp("initialSyncCompleted", method)) + else if (method == "initialSyncCompleted") SyncCompleted(); /* Unknown */ else - Logger::Log(LogLevel::LEVEL_DEBUG, "unhandled message [%s]", method); + Logger::Log(LogLevel::LEVEL_DEBUG, "unhandled message [%s]", method.c_str()); /* make a copy of events list to process it without lock. */ eventsCopy = m_events; diff --git a/src/Tvheadend.h b/src/Tvheadend.h index 4e1c9b70..b715a0ef 100644 --- a/src/Tvheadend.h +++ b/src/Tvheadend.h @@ -77,7 +77,7 @@ class CTvheadend : public P8PLATFORM::CThread, public tvheadend::IHTSPConnection // IHTSPConnectionListener implementation void Disconnected() override; bool Connected() override; - bool ProcessMessage(const char* method, htsmsg_t* msg) override; + bool ProcessMessage(const std::string& method, htsmsg_t* msg) override; const tvheadend::entity::Channels& GetChannels() const { return m_channels; } diff --git a/src/tvheadend/HTSPDemuxer.cpp b/src/tvheadend/HTSPDemuxer.cpp index 3193656f..49bc1565 100644 --- a/src/tvheadend/HTSPDemuxer.cpp +++ b/src/tvheadend/HTSPDemuxer.cpp @@ -402,33 +402,33 @@ void HTSPDemuxer::ResetStatus(bool resetStartTime /* = true */) * Parse incoming data * *************************************************************************/ -bool HTSPDemuxer::ProcessMessage(const char* method, htsmsg_t* m) +bool HTSPDemuxer::ProcessMessage(const std::string& method, htsmsg_t* m) { /* Subscription messages */ - if (!std::strcmp("muxpkt", method)) + if (method == "muxpkt") ParseMuxPacket(m); - else if (!std::strcmp("subscriptionStatus", method)) + else if (method == "subscriptionStatus") m_subscription.ParseSubscriptionStatus(m); - else if (!std::strcmp("queueStatus", method)) + else if (method == "queueStatus") ParseQueueStatus(m); - else if (!std::strcmp("signalStatus", method)) + else if (method == "signalStatus") ParseSignalStatus(m); - else if (!std::strcmp("timeshiftStatus", method)) + else if (method == "timeshiftStatus") ParseTimeshiftStatus(m); - else if (!std::strcmp("descrambleInfo", method)) + else if (method == "descrambleInfo") ParseDescrambleInfo(m); - else if (!std::strcmp("subscriptionStart", method)) + else if (method == "subscriptionStart") ParseSubscriptionStart(m); - else if (!std::strcmp("subscriptionStop", method)) + else if (method == "subscriptionStop") ParseSubscriptionStop(m); - else if (!std::strcmp("subscriptionSkip", method)) + else if (method == "subscriptionSkip") ParseSubscriptionSkip(m); - else if (!std::strcmp("subscriptionSpeed", method)) + else if (method == "subscriptionSpeed") ParseSubscriptionSpeed(m); - else if (!std::strcmp("subscriptionGrace", method)) + else if (method == "subscriptionGrace") ParseSubscriptionGrace(m); else - Logger::Log(LogLevel::LEVEL_DEBUG, "demux unhandled subscription message [%s]", method); + Logger::Log(LogLevel::LEVEL_DEBUG, "demux unhandled subscription message [%s]", method.c_str()); return true; } diff --git a/src/tvheadend/HTSPDemuxer.h b/src/tvheadend/HTSPDemuxer.h index 9089b873..8bb0d22b 100644 --- a/src/tvheadend/HTSPDemuxer.h +++ b/src/tvheadend/HTSPDemuxer.h @@ -55,7 +55,7 @@ class HTSPDemuxer HTSPDemuxer(HTSPConnection& conn); ~HTSPDemuxer(); - bool ProcessMessage(const char* method, htsmsg_t* m); + bool ProcessMessage(const std::string& method, htsmsg_t* m); void Connected(); bool Open(uint32_t channelId, diff --git a/src/tvheadend/IHTSPConnectionListener.h b/src/tvheadend/IHTSPConnectionListener.h index 1bebc9ef..acc867eb 100644 --- a/src/tvheadend/IHTSPConnectionListener.h +++ b/src/tvheadend/IHTSPConnectionListener.h @@ -39,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 std::string& method, htsmsg_t* msg) = 0; }; } // namespace tvheadend From bd6acb556274836f80185bcd87a2e1530a977d52 Mon Sep 17 00:00:00 2001 From: Kai Sommerfeld Date: Mon, 21 Oct 2019 20:03:46 +0200 Subject: [PATCH 10/10] Fixed: 'Stop recording' no longer aborts in-progress recordings (HTSP v26). --- pvr.hts/addon.xml.in | 2 +- pvr.hts/changelog.txt | 4 ++++ src/Tvheadend.cpp | 36 +++++++++++++++++++++++------------- 3 files changed, 28 insertions(+), 14 deletions(-) diff --git a/pvr.hts/addon.xml.in b/pvr.hts/addon.xml.in index 5788e82f..08c4a671 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 e3f74282..0ad09469 100644 --- a/pvr.hts/changelog.txt +++ b/pvr.hts/changelog.txt @@ -1,3 +1,7 @@ +5.3.0 +- Code cleanup +- Fixed: 'Stop recording' no longer aborts in-progress recordings (HTSP v26) + 5.2.1 - Code cleanup: Apply Kodi clang-format ruleset. diff --git a/src/Tvheadend.cpp b/src/Tvheadend.cpp index ffc8f233..ffe49db9 100644 --- a/src/Tvheadend.cpp +++ b/src/Tvheadend.cpp @@ -1224,6 +1224,27 @@ PVR_ERROR CTvheadend::AddTimer(const PVR_TIMER& timer) PVR_ERROR CTvheadend::DeleteTimer(const PVR_TIMER& timer, bool) { + { + CLockObject lock(m_mutex); + + const auto& it = m_recordings.find(timer.iClientIndex); + if (it != m_recordings.end() && it->second.IsRecording()) + { + // This is a request to stop an active recording. + if (m_conn->GetProtocol() >= 26) + { + // gracefully stop the recording (mark as success in tvh) + return SendDvrDelete(timer.iClientIndex, "stopDvrEntry"); + } + else + { + // abort the recording (mark as failure in tvh) - no other choice, + // because graceful stop HTSP method was not available before HTSP v26. + return SendDvrDelete(timer.iClientIndex, "cancelDvrEntry"); + } + } + } + if ((timer.iTimerType == TIMER_ONCE_MANUAL) || (timer.iTimerType == TIMER_ONCE_EPG)) { /* one shot timer */ @@ -1244,19 +1265,8 @@ PVR_ERROR CTvheadend::DeleteTimer(const PVR_TIMER& timer, bool) (timer.iTimerType == TIMER_ONCE_CREATED_BY_AUTOREC)) { /* Read-only timer created by autorec or timerec */ - CLockObject lock(m_mutex); - - 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. */ - return SendDvrDelete(timer.iClientIndex, "cancelDvrEntry"); - } - else - { - Logger::Log(LogLevel::LEVEL_ERROR, "timer is read-only"); - return PVR_ERROR_INVALID_PARAMETERS; - } + Logger::Log(LogLevel::LEVEL_ERROR, "timer is read-only"); + return PVR_ERROR_INVALID_PARAMETERS; } else {