| 1 |
/* |
| 2 |
* Copyright (C) 2005-2021 Team Kodi (https://kodi.tv) |
| 3 |
* |
| 4 |
* SPDX-License-Identifier: GPL-2.0-or-later |
| 5 |
* See LICENSE.md for more information. |
| 6 |
*/ |
| 7 |
|
| 8 |
#pragma once |
| 9 |
|
| 10 |
#include <atomic> |
| 11 |
#include <chrono> |
| 12 |
#include <mutex> |
| 13 |
#include <thread> |
| 14 |
#include <vector> |
| 15 |
|
| 16 |
/* Master defines for client control */ |
| 17 |
#include <kodi/addon-instance/PVR.h> |
| 18 |
|
| 19 |
/* Local includes */ |
| 20 |
#include "Socket.h" |
| 21 |
#include "Cards.h" |
| 22 |
#include "epg.h" |
| 23 |
#include "channels.h" |
| 24 |
|
| 25 |
/* Use a forward declaration here. Including RTSPClient.h via TSReader.h at this point gives compile errors */ |
| 26 |
namespace MPTV |
| 27 |
{ |
| 28 |
class CTsReader; |
| 29 |
} |
| 30 |
class cRecording; |
| 31 |
|
| 32 |
class ATTR_DLL_LOCAL cPVRClientMediaPortal |
| 33 |
: public kodi::addon::CInstancePVRClient |
| 34 |
{ |
| 35 |
public: |
| 36 |
/* Class interface */ |
| 37 |
cPVRClientMediaPortal(const kodi::addon::IInstanceInfo& instance); |
| 38 |
~cPVRClientMediaPortal() override; |
| 39 |
|
| 40 |
/* Server handling */ |
| 41 |
ADDON_STATUS TryConnect(); |
| 42 |
void Disconnect(); |
| 43 |
bool IsUp(); |
| 44 |
|
| 45 |
/* General handling */ |
| 46 |
PVR_ERROR GetCapabilities(kodi::addon::PVRCapabilities& capabilities) override; |
| 47 |
PVR_ERROR GetBackendName(std::string& name) override; |
| 48 |
PVR_ERROR GetBackendVersion(std::string& version) override; |
| 49 |
PVR_ERROR GetConnectionString(std::string& connection) override; |
| 50 |
PVR_ERROR GetDriveSpace(uint64_t& total, uint64_t& used) override; |
| 51 |
PVR_ERROR GetBackendTime(time_t *localTime, int *gmtOffset); |
| 52 |
|
| 53 |
/* EPG handling */ |
| 54 |
PVR_ERROR GetEPGForChannel(int channelUid, time_t start, time_t end, kodi::addon::PVREPGTagsResultSet& results) override; |
| 55 |
|
| 56 |
/* Channel handling */ |
| 57 |
PVR_ERROR GetChannelsAmount(int& amount) override; |
| 58 |
PVR_ERROR GetChannels(bool radio, kodi::addon::PVRChannelsResultSet& results) override; |
| 59 |
|
| 60 |
/* Channel group handling */ |
| 61 |
PVR_ERROR GetChannelGroupsAmount(int& amount) override; |
| 62 |
PVR_ERROR GetChannelGroups(bool radio, kodi::addon::PVRChannelGroupsResultSet& results) override; |
| 63 |
PVR_ERROR GetChannelGroupMembers(const kodi::addon::PVRChannelGroup& group, kodi::addon::PVRChannelGroupMembersResultSet& results) override; |
| 64 |
|
| 65 |
/* Record handling **/ |
| 66 |
PVR_ERROR GetRecordingsAmount(bool deleted, int& amount) override; |
| 67 |
PVR_ERROR GetRecordings(bool deleted, kodi::addon::PVRRecordingsResultSet& results) override; |
| 68 |
PVR_ERROR DeleteRecording(const kodi::addon::PVRRecording& recording) override; |
| 69 |
PVR_ERROR RenameRecording(const kodi::addon::PVRRecording& recording) override; |
| 70 |
PVR_ERROR SetRecordingPlayCount(const kodi::addon::PVRRecording& recording, int count) override; |
| 71 |
PVR_ERROR SetRecordingLastPlayedPosition(const kodi::addon::PVRRecording& recording, int lastplayedposition) override; |
| 72 |
PVR_ERROR GetRecordingLastPlayedPosition(const kodi::addon::PVRRecording& recording, int& position) override; |
| 73 |
PVR_ERROR GetRecordingEdl(const kodi::addon::PVRRecording& recording, std::vector<kodi::addon::PVREDLEntry>& edl) override; |
| 74 |
|
| 75 |
/* Timer handling */ |
| 76 |
PVR_ERROR GetTimersAmount(int& amount) override; |
| 77 |
PVR_ERROR GetTimers(kodi::addon::PVRTimersResultSet& results) override; |
| 78 |
PVR_ERROR GetTimerInfo(unsigned int timernumber, kodi::addon::PVRTimer& timer); |
| 79 |
PVR_ERROR AddTimer(const kodi::addon::PVRTimer& timer) override; |
| 80 |
PVR_ERROR DeleteTimer(const kodi::addon::PVRTimer& timer, bool forceDelete) override; |
| 81 |
PVR_ERROR UpdateTimer(const kodi::addon::PVRTimer& timer) override; |
| 82 |
PVR_ERROR GetTimerTypes(std::vector<kodi::addon::PVRTimerType>& types) override; |
| 83 |
|
| 84 |
/* Live stream handling */ |
| 85 |
bool OpenLiveStream(const kodi::addon::PVRChannel& channel) override; |
| 86 |
void CloseLiveStream() override; |
| 87 |
int ReadLiveStream(unsigned char *pBuffer, unsigned int iBufferSize) override; |
| 88 |
PVR_ERROR GetSignalStatus(int channelUid, kodi::addon::PVRSignalStatus& signalStatus) override; |
| 89 |
PVR_ERROR GetChannelStreamProperties(const kodi::addon::PVRChannel& channel, std::vector<kodi::addon::PVRStreamProperty>& properties) override; |
| 90 |
int64_t SeekLiveStream(int64_t iPosition, int iWhence = SEEK_SET) override; |
| 91 |
int64_t LengthLiveStream(void) override; |
| 92 |
|
| 93 |
/* Record stream handling */ |
| 94 |
bool OpenRecordedStream(const kodi::addon::PVRRecording& recording) override; |
| 95 |
void CloseRecordedStream() override; |
| 96 |
int ReadRecordedStream(unsigned char *pBuffer, unsigned int iBufferSize) override; |
| 97 |
int64_t SeekRecordedStream(int64_t iPosition, int iWhence = SEEK_SET) override; |
| 98 |
int64_t LengthRecordedStream() override; |
| 99 |
PVR_ERROR GetRecordingStreamProperties(const kodi::addon::PVRRecording& recording, std::vector<kodi::addon::PVRStreamProperty>& properties) override; |
| 100 |
|
| 101 |
/* Common stream handing functions */ |
| 102 |
bool CanPauseStream() override; |
| 103 |
bool CanSeekStream() override; |
| 104 |
void PauseStream(bool bPaused) override; |
| 105 |
bool IsRealTimeStream() override; |
| 106 |
PVR_ERROR GetStreamReadChunkSize(int& chunksize) override; |
| 107 |
PVR_ERROR GetStreamTimes(kodi::addon::PVRStreamTimes& stream_times) override; |
| 108 |
|
| 109 |
protected: |
| 110 |
MPTV::Socket *m_tcpclient; |
| 111 |
|
| 112 |
private: |
| 113 |
/* TVServerKodi Listening Thread */ |
| 114 |
void Process(); |
| 115 |
PVR_CONNECTION_STATE Connect(bool updateConnectionState = true); |
| 116 |
|
| 117 |
void LoadGenreTable(void); |
| 118 |
void LoadCardSettings(void); |
| 119 |
void SetConnectionState(PVR_CONNECTION_STATE newState); |
| 120 |
cRecording* GetRecordingInfo(const kodi::addon::PVRRecording& recording); |
| 121 |
const char* GetConnectionStateString(PVR_CONNECTION_STATE state) const; |
| 122 |
|
| 123 |
int m_iCurrentChannel; |
| 124 |
int m_iCurrentCard; |
| 125 |
bool m_bCurrentChannelIsRadio; |
| 126 |
PVR_CONNECTION_STATE m_state; |
| 127 |
bool m_bStop; |
| 128 |
bool m_bTimeShiftStarted; |
| 129 |
bool m_bSkipCloseLiveStream; |
| 130 |
std::string m_ConnectionString; |
| 131 |
std::string m_PlaybackURL; |
| 132 |
std::string m_BackendName; |
| 133 |
std::string m_BackendVersion; |
| 134 |
int m_BackendUTCoffset; |
| 135 |
time_t m_BackendTime; |
| 136 |
CCards m_cCards; |
| 137 |
CGenreTable* m_genretable; |
| 138 |
std::mutex m_mutex; |
| 139 |
std::mutex m_connectionMutex; |
| 140 |
std::chrono::system_clock::time_point m_iLastRecordingUpdate; |
| 141 |
MPTV::CTsReader* m_tsreader; |
| 142 |
std::map<int,cChannel> m_channels; |
| 143 |
int m_signalStateCounter; |
| 144 |
int m_iSignal; |
| 145 |
int m_iSNR; |
| 146 |
|
| 147 |
cRecording* m_lastSelectedRecording; |
| 148 |
|
| 149 |
std::atomic<bool> m_running = {false}; |
| 150 |
std::thread m_thread; |
| 151 |
|
| 152 |
//Used for TV Server communication: |
| 153 |
std::string SendCommand(const char* command); |
| 154 |
std::string SendCommand(const std::string& command); |
| 155 |
bool SendCommand2(const std::string& command, std::vector<std::string>& lines); |
| 156 |
}; |