Debian Codegraph @

src/ClientInstance.h

raw
1 /*
2 * Copyright (C) 2010-2021 Team Kodi (https://kodi.tv)
3 * Copyright (C) 2010 Alwin Esch (Team Kodi)
4 *
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 * See LICENSE.md for more information.
7 */
8
9 #pragma once
10
11 #include "Session.h"
12
13 #include <atomic>
14 #include <kodi/addon-instance/PVR.h>
15 #include <condition_variable>
16 #include <map>
17 #include <mutex>
18 #include <string>
19 #include <thread>
20
21 class CPVRAddon;
22 class cResponsePacket;
23 class cRequestPacket;
24 class cVNSIDemux;
25 class cVNSIRecording;
26
27 class ATTR_DLL_LOCAL CVNSIClientInstance : public kodi::addon::CInstancePVRClient,
28 public cVNSISession
29 {
30 public:
31 CVNSIClientInstance(const CPVRAddon& base, const kodi::addon::IInstanceInfo& instance);
32 ~CVNSIClientInstance() override;
33
34 bool Start(const std::string& hostname,
35 int port,
36 const char* name = nullptr,
37 const std::string& mac = "");
38
39 PVR_ERROR GetCapabilities(kodi::addon::PVRCapabilities& capabilities) override;
40
41 PVR_ERROR GetBackendName(std::string& name) override;
42 PVR_ERROR GetBackendVersion(std::string& version) override;
43 PVR_ERROR GetBackendHostname(std::string& hostname) override;
44 PVR_ERROR GetConnectionString(std::string& connection) override;
45 PVR_ERROR GetDriveSpace(uint64_t& total, uint64_t& used) override;
46 PVR_ERROR CallSettingsMenuHook(const kodi::addon::PVRMenuhook& menuhook) override;
47 PVR_ERROR OpenDialogChannelScan() override;
48
49 //--==----==----==----==----==----==----==----==----==----==----==----==----==
50
51 PVR_ERROR OnSystemSleep() override;
52 PVR_ERROR OnSystemWake() override;
53 PVR_ERROR OnPowerSavingActivated() override;
54 PVR_ERROR OnPowerSavingDeactivated() override;
55
56 //--==----==----==----==----==----==----==----==----==----==----==----==----==
57
58 PVR_ERROR GetChannelsAmount(int& amount) override;
59 PVR_ERROR GetChannels(bool radio, kodi::addon::PVRChannelsResultSet& results) override;
60 PVR_ERROR GetSignalStatus(int channelUid, kodi::addon::PVRSignalStatus& signalStatus) override;
61
62 //--==----==----==----==----==----==----==----==----==----==----==----==----==
63
64 PVR_ERROR GetChannelGroupsAmount(int& amount) override;
65 PVR_ERROR GetChannelGroups(bool radio, kodi::addon::PVRChannelGroupsResultSet& results) override;
66 PVR_ERROR GetChannelGroupMembers(const kodi::addon::PVRChannelGroup& group,
67 kodi::addon::PVRChannelGroupMembersResultSet& results) override;
68
69 //--==----==----==----==----==----==----==----==----==----==----==----==----==
70
71 PVR_ERROR GetEPGForChannel(int channelUid,
72 time_t start,
73 time_t end,
74 kodi::addon::PVREPGTagsResultSet& results) override;
75
76 //--==----==----==----==----==----==----==----==----==----==----==----==----==
77
78 PVR_ERROR GetTimerTypes(std::vector<kodi::addon::PVRTimerType>& types) override;
79 PVR_ERROR GetTimersAmount(int& amount) override;
80 PVR_ERROR GetTimers(kodi::addon::PVRTimersResultSet& results) override;
81 PVR_ERROR AddTimer(const kodi::addon::PVRTimer& timer) override;
82 PVR_ERROR DeleteTimer(const kodi::addon::PVRTimer& timer, bool forceDelete) override;
83 PVR_ERROR UpdateTimer(const kodi::addon::PVRTimer& timer) override;
84
85 //--==----==----==----==----==----==----==----==----==----==----==----==----==
86
87 PVR_ERROR GetRecordingsAmount(bool deleted, int& amount) override;
88 PVR_ERROR GetRecordings(bool deleted, kodi::addon::PVRRecordingsResultSet& results) override;
89 PVR_ERROR DeleteRecording(const kodi::addon::PVRRecording& recording) override;
90 PVR_ERROR UndeleteRecording(const kodi::addon::PVRRecording& recording) override;
91 PVR_ERROR DeleteAllRecordingsFromTrash() override;
92 PVR_ERROR RenameRecording(const kodi::addon::PVRRecording& recording) override;
93 PVR_ERROR GetRecordingEdl(const kodi::addon::PVRRecording& recording,
94 std::vector<kodi::addon::PVREDLEntry>& edl) override;
95
96 //--==----==----==----==----==----==----==----==----==----==----==----==----==
97
98 bool OpenLiveStream(const kodi::addon::PVRChannel& channel) override;
99 void CloseLiveStream() override;
100 PVR_ERROR GetStreamProperties(std::vector<kodi::addon::PVRStreamProperties>& properties) override;
101 DEMUX_PACKET* DemuxRead() override;
102 void DemuxAbort() override;
103 bool SeekTime(double time, bool backwards, double& startpts) override;
104 bool CanPauseStream() override;
105 bool CanSeekStream() override;
106 bool IsRealTimeStream() override;
107 PVR_ERROR GetStreamTimes(kodi::addon::PVRStreamTimes& times) override;
108
109 //--==----==----==----==----==----==----==----==----==----==----==----==----==
110
111 bool OpenRecordedStream(const kodi::addon::PVRRecording& recording) override;
112 void CloseRecordedStream() override;
113 int ReadRecordedStream(unsigned char* buffer, unsigned int size) override;
114 int64_t SeekRecordedStream(int64_t position, int whence) override;
115 int64_t LengthRecordedStream() override;
116 PVR_ERROR GetStreamReadChunkSize(int& chunksize) override;
117
118 //--==----==----==----==----==----==----==----==----==----==----==----==----==
119
120 protected:
121 void Process();
122 virtual bool OnResponsePacket(cResponsePacket* pkt);
123
124 void OnDisconnect() override;
125 void OnReconnect() override;
126
127 private:
128 bool SupportChannelScan();
129 bool SupportRecordingsUndelete();
130 bool EnableStatusInterface(bool onOff, bool wait = true);
131 PVR_ERROR GetAvailableRecordings(kodi::addon::PVRRecordingsResultSet& results);
132 PVR_ERROR GetDeletedRecordings(kodi::addon::PVRRecordingsResultSet& results);
133 bool GenTimerChildren(const kodi::addon::PVRTimer& timer,
134 kodi::addon::PVRTimersResultSet& results);
135 std::string GenTimerFolder(std::string directory, std::string title);
136 PVR_ERROR GetTimerInfo(unsigned int timernumber, kodi::addon::PVRTimer& tag);
137 PVR_ERROR RenameTimer(const kodi::addon::PVRTimer& timerinfo, const std::string& newname);
138
139 std::unique_ptr<cResponsePacket> ReadResult(cRequestPacket* vrp);
140
141 struct SMessage
142 {
143 std::condition_variable_any m_condition;
144 std::recursive_mutex m_messageMutex;
145 std::unique_ptr<cResponsePacket> pkt;
146 };
147
148 class Queue
149 {
150 typedef std::map<int, SMessage> SMessages;
151 SMessages m_queue;
152
153 public:
154 std::recursive_mutex m_mutex;
155 SMessage& Enqueue(uint32_t serial);
156 std::unique_ptr<cResponsePacket> Dequeue(uint32_t serial, SMessage& message);
157 void Set(std::unique_ptr<cResponsePacket>&& vresp);
158 };
159
160 Queue m_queue;
161
162 std::string m_videodir;
163 std::string m_wolMac;
164
165 bool m_isTimeshift = false;
166 bool m_isRealtime = false;
167 int64_t m_ptsBufferEnd = 0;
168 std::recursive_mutex m_timeshiftMutex;
169
170 cVNSIDemux* m_demuxer = nullptr;
171 cVNSIRecording* m_recording = nullptr;
172
173 const CPVRAddon& m_base;
174
175 std::atomic<bool> m_running = {false};
176 std::thread m_thread;
177 std::thread m_startInformThread;
178 };