| 1 |
/* |
| 2 |
* Copyright (c) 2018~now Palo Kisa <[email protected]> |
| 3 |
* |
| 4 |
* Copyright (C) 2014 Josef Rokos |
| 5 |
* http://github.com/PepaRokos/xbmc-pvr-addons/ |
| 6 |
* |
| 7 |
* Copyright (C) 2011 Pulse-Eight |
| 8 |
* http://www.pulse-eight.com/ |
| 9 |
* |
| 10 |
* This Program is free software; you can redistribute it and/or modify |
| 11 |
* it under the terms of the GNU General Public License as published by |
| 12 |
* the Free Software Foundation; either version 2, or (at your option) |
| 13 |
* any later version. |
| 14 |
* |
| 15 |
* This Program is distributed in the hope that it will be useful, |
| 16 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 18 |
* GNU General Public License for more details. |
| 19 |
* |
| 20 |
* You should have received a copy of the GNU General Public License |
| 21 |
* along with this addon; see the file COPYING. If not, write to |
| 22 |
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. |
| 23 |
* http://www.gnu.org/copyleft/gpl.html |
| 24 |
* |
| 25 |
*/ |
| 26 |
|
| 27 |
#ifndef sledovanitvcz_Data_h |
| 28 |
#define sledovanitvcz_Data_h |
| 29 |
|
| 30 |
#include <vector> |
| 31 |
#include "kodi/addon-instance/PVR.h" |
| 32 |
#include <thread> |
| 33 |
#include "ApiManager.h" |
| 34 |
#include <mutex> |
| 35 |
#include <memory> |
| 36 |
#include <condition_variable> |
| 37 |
#include <map> |
| 38 |
|
| 39 |
namespace sledovanitvcz |
| 40 |
{ |
| 41 |
|
| 42 |
struct EpgEntry |
| 43 |
{ |
| 44 |
unsigned iBroadcastId; |
| 45 |
int iChannelId; |
| 46 |
int iGenreType; |
| 47 |
int iGenreSubType; |
| 48 |
time_t startTime; |
| 49 |
time_t endTime; |
| 50 |
std::string strTitle; |
| 51 |
std::string strPlotOutline; |
| 52 |
std::string strPlot; |
| 53 |
std::string strIconPath; |
| 54 |
std::string strGenreString; |
| 55 |
std::string strEventId; |
| 56 |
bool availableTimeshift; |
| 57 |
std::string strRecordId; // optionally recorded |
| 58 |
int starRating; |
| 59 |
int parentalRating; |
| 60 |
}; |
| 61 |
|
| 62 |
typedef std::map<time_t, EpgEntry> epg_entry_container_t; |
| 63 |
struct EpgChannel |
| 64 |
{ |
| 65 |
std::string strId; |
| 66 |
std::string strName; |
| 67 |
epg_entry_container_t epg; |
| 68 |
}; |
| 69 |
|
| 70 |
struct Channel |
| 71 |
{ |
| 72 |
bool bIsRadio; |
| 73 |
int iUniqueId; |
| 74 |
int iChannelNumber; |
| 75 |
int iEncryptionSystem; |
| 76 |
int iTvgShift; |
| 77 |
std::string strChannelName; |
| 78 |
std::string strIconPath; |
| 79 |
std::string strStreamURL; |
| 80 |
std::string strId; |
| 81 |
std::string strGroupId; |
| 82 |
std::string strStreamType; |
| 83 |
bool bIsPinLocked; |
| 84 |
bool bIsDrm; |
| 85 |
}; |
| 86 |
|
| 87 |
struct ChannelGroup |
| 88 |
{ |
| 89 |
bool bRadio; |
| 90 |
std::string strGroupId; |
| 91 |
std::string strGroupName; |
| 92 |
std::vector<int> members; |
| 93 |
}; |
| 94 |
|
| 95 |
struct Recording |
| 96 |
{ |
| 97 |
std::string strRecordId; |
| 98 |
std::string strTitle; |
| 99 |
std::string strPlotOutline; |
| 100 |
std::string strPlot; |
| 101 |
std::string strChannelName; |
| 102 |
time_t startTime; |
| 103 |
int duration; |
| 104 |
std::string strDirectory; |
| 105 |
bool bRadio; |
| 106 |
int iLifeTime; |
| 107 |
int iChannelUid; |
| 108 |
bool bIsPinLocked; |
| 109 |
}; |
| 110 |
|
| 111 |
struct Timer |
| 112 |
{ |
| 113 |
unsigned int iClientIndex; |
| 114 |
int iClientChannelUid; |
| 115 |
time_t startTime; |
| 116 |
time_t endTime; |
| 117 |
PVR_TIMER_STATE state; /*!< @brief (required) the state of this timer */ |
| 118 |
std::string strTitle; |
| 119 |
std::string strSummary; |
| 120 |
int iLifetime; |
| 121 |
bool bIsRepeating; |
| 122 |
time_t firstDay; |
| 123 |
int iWeekdays; |
| 124 |
int iEpgUid; |
| 125 |
unsigned int iMarginStart; |
| 126 |
unsigned int iMarginEnd; |
| 127 |
int iGenreType; |
| 128 |
int iGenreSubType; |
| 129 |
int iLifeTime; |
| 130 |
std::string strDirectory; |
| 131 |
}; |
| 132 |
|
| 133 |
typedef std::vector<ChannelGroup> group_container_t; |
| 134 |
typedef std::vector<Channel> channel_container_t; |
| 135 |
typedef std::map<std::string, EpgChannel> epg_container_t; |
| 136 |
typedef std::vector<Recording> recording_container_t; |
| 137 |
typedef std::vector<Timer> timer_container_t; |
| 138 |
typedef std::map<std::string, std::string> properties_t; |
| 139 |
|
| 140 |
class ATTR_DLL_LOCAL Data : public kodi::addon::CInstancePVRClient |
| 141 |
{ |
| 142 |
public: |
| 143 |
Data(const kodi::addon::IInstanceInfo& instance); |
| 144 |
virtual ~Data(void); |
| 145 |
|
| 146 |
ADDON_STATUS SetInstanceSetting(const std::string & settingName, const kodi::addon::CSettingValue & settingValue) override; |
| 147 |
|
| 148 |
PVR_ERROR GetCapabilities(kodi::addon::PVRCapabilities& capabilities) override; |
| 149 |
PVR_ERROR GetBackendName(std::string& name) override; |
| 150 |
PVR_ERROR GetBackendVersion(std::string& version) override; |
| 151 |
PVR_ERROR GetConnectionString(std::string& connection) override; |
| 152 |
|
| 153 |
PVR_ERROR GetChannelsAmount(int& amount) override; |
| 154 |
PVR_ERROR GetChannels(bool radio, kodi::addon::PVRChannelsResultSet& results) override; |
| 155 |
PVR_ERROR GetChannelStreamProperties(const kodi::addon::PVRChannel& channel, std::vector<kodi::addon::PVRStreamProperty>& properties) override; |
| 156 |
PVR_ERROR GetSignalStatus(int channelUid, kodi::addon::PVRSignalStatus& signalStatus) override; |
| 157 |
PVR_ERROR GetEPGForChannel(int channelUid, time_t start, time_t end, kodi::addon::PVREPGTagsResultSet& results) override; |
| 158 |
PVR_ERROR IsEPGTagPlayable(const kodi::addon::PVREPGTag& tag, bool& isPlayable) override; |
| 159 |
PVR_ERROR IsEPGTagRecordable(const kodi::addon::PVREPGTag& tag, bool& isRecordable) override; |
| 160 |
PVR_ERROR GetEPGTagStreamProperties(const kodi::addon::PVREPGTag& tag, std::vector<kodi::addon::PVRStreamProperty>& properties) override; |
| 161 |
PVR_ERROR SetEPGMaxFutureDays(int iFutureDays) override; |
| 162 |
PVR_ERROR SetEPGMaxPastDays(int iPastDays) override; |
| 163 |
PVR_ERROR GetChannelGroupsAmount(int& amount) override; |
| 164 |
PVR_ERROR GetChannelGroups(bool radio, kodi::addon::PVRChannelGroupsResultSet& results) override; |
| 165 |
PVR_ERROR GetChannelGroupMembers(const kodi::addon::PVRChannelGroup& group, kodi::addon::PVRChannelGroupMembersResultSet& results) override; |
| 166 |
PVR_ERROR GetRecordingsAmount(bool deleted, int& amount) override; |
| 167 |
PVR_ERROR GetRecordings(bool deleted, kodi::addon::PVRRecordingsResultSet& results) override; |
| 168 |
PVR_ERROR DeleteRecording(const kodi::addon::PVRRecording& recording) override; |
| 169 |
PVR_ERROR GetRecordingStreamProperties(const kodi::addon::PVRRecording& recording, std::vector<kodi::addon::PVRStreamProperty>& properties) override; |
| 170 |
PVR_ERROR GetTimerTypes(std::vector<kodi::addon::PVRTimerType>& types) override; |
| 171 |
PVR_ERROR GetTimersAmount(int& amount) override; |
| 172 |
PVR_ERROR GetTimers(kodi::addon::PVRTimersResultSet& results) override; |
| 173 |
PVR_ERROR AddTimer(const kodi::addon::PVRTimer& timer) override; |
| 174 |
PVR_ERROR DeleteTimer(const kodi::addon::PVRTimer& timer, bool forceDelete) override; |
| 175 |
PVR_ERROR GetDriveSpace(uint64_t& total, uint64_t& used) override; |
| 176 |
|
| 177 |
bool LoggedIn() const; |
| 178 |
|
| 179 |
protected: |
| 180 |
static int ParseDateTime(std::string strDate); |
| 181 |
|
| 182 |
protected: |
| 183 |
bool KeepAlive(); |
| 184 |
void KeepAliveJob(); |
| 185 |
bool LoadPlayList(void); |
| 186 |
bool LoadEPG(time_t iStart, bool bSmallStep); |
| 187 |
void ReleaseUnneededEPG(); |
| 188 |
//! \return true if actual update was performed |
| 189 |
bool LoadEPGJob(); |
| 190 |
bool LoadRecordings(); |
| 191 |
template<typename Job> |
| 192 |
bool SimpleLoadJob(bool & jobGuard, const Job & job); |
| 193 |
void SetLoadRecordings(); |
| 194 |
void SetLoadPlaylist(); |
| 195 |
void LoginLoop(); |
| 196 |
bool WaitForChannels() const; |
| 197 |
void TriggerFullRefresh(); |
| 198 |
bool RecordingExists(const std::string & recordId) const; |
| 199 |
std::string ChannelsList() const; |
| 200 |
std::string ChannelStreamType(const std::string & channelId) const; |
| 201 |
bool PinCheckUnlock(bool isPinLocked, bool & unlockedNow); |
| 202 |
std::vector<kodi::addon::PVRStreamProperty> StreamProperties(const std::string & url, const std::string & streamType, bool isDrm, bool isLive) const; |
| 203 |
PVR_ERROR GetChannelStreamUrl(const kodi::addon::PVRChannel& channel, std::string & streamUrl, std::string & streamType, bool & isDrm); |
| 204 |
PVR_ERROR GetEPGStreamUrl(const kodi::addon::PVREPGTag& tag, std::string & streamUrl, std::string & streamType, bool & isDrm); |
| 205 |
PVR_ERROR GetRecordingStreamUrl(const std::string & recording, std::string & streamUrl, std::string & streamType, bool & isDrm); |
| 206 |
PVR_ERROR SetEPGMaxDays(int iFutureDays, int iPastDays); |
| 207 |
void registerDrm(); |
| 208 |
|
| 209 |
protected: |
| 210 |
void Process(void); |
| 211 |
|
| 212 |
private: |
| 213 |
bool m_bKeepAlive; |
| 214 |
bool m_bLoadRecordings; |
| 215 |
bool m_bLoadPlayList; |
| 216 |
mutable std::mutex m_mutex; |
| 217 |
bool m_bChannelsLoaded; |
| 218 |
mutable std::condition_variable m_waitCond; |
| 219 |
std::thread m_thread; |
| 220 |
|
| 221 |
// stored data from backend (used by multiple threads...) |
| 222 |
std::shared_ptr<const group_container_t> m_groups; |
| 223 |
std::shared_ptr<const channel_container_t> m_channels; |
| 224 |
std::shared_ptr<const epg_container_t> m_epg; |
| 225 |
std::shared_ptr<const recording_container_t> m_recordings; |
| 226 |
std::shared_ptr<const timer_container_t> m_timers; |
| 227 |
long long m_recordingAvailableDuration; |
| 228 |
long long m_recordingRecordedDuration; |
| 229 |
time_t m_epgMinTime; |
| 230 |
time_t m_epgMaxTime; |
| 231 |
int m_epgMaxFutureDays; |
| 232 |
int m_epgMaxPastDays; |
| 233 |
std::shared_ptr<const std::string> m_drmCertificate; |
| 234 |
std::shared_ptr<const std::string> m_drmLicenseUrl; |
| 235 |
|
| 236 |
// data used only by "job" thread |
| 237 |
bool m_bEGPLoaded; |
| 238 |
time_t m_iLastStart; |
| 239 |
time_t m_iLastEnd; |
| 240 |
ApiManager::StreamQuality_t m_streamQuality; |
| 241 |
unsigned m_fullChannelEpgRefresh; //!< delay (seconds) between full channel/EPG refresh |
| 242 |
unsigned m_loadingsRefresh; //!< delay (seconds) between loadings refresh |
| 243 |
unsigned m_keepAliveDelay; //!< delay (seconds) between keepalive calls |
| 244 |
unsigned m_epgCheckDelay; //!< delay (seconds) between checking if EPG load is needed |
| 245 |
bool m_useH265; //!< flag, if h265 codec should be requested |
| 246 |
bool m_useAdaptive; //!< flag, if inpustream.adaptive (aka adaptive bitrate streaming) should be used/requested |
| 247 |
bool m_showLockedChannels; //!< flag, if unavailable/locked channels should be presented |
| 248 |
bool m_showLockedOnlyPin; //!< flag, if PIN-locked only channels should be presented |
| 249 |
|
| 250 |
ApiManager m_manager; |
| 251 |
}; |
| 252 |
|
| 253 |
} //namespace sledovanitvcz |
| 254 |
#endif // sledovanitvcz_Data_h |