summaryrefslogtreecommitdiffstats
path: root/xbmc/addons/kodi-addon-dev-kit/include/kodi/libXBMC_pvr.h
diff options
context:
space:
mode:
Diffstat (limited to 'xbmc/addons/kodi-addon-dev-kit/include/kodi/libXBMC_pvr.h')
-rw-r--r--xbmc/addons/kodi-addon-dev-kit/include/kodi/libXBMC_pvr.h366
1 files changed, 366 insertions, 0 deletions
diff --git a/xbmc/addons/kodi-addon-dev-kit/include/kodi/libXBMC_pvr.h b/xbmc/addons/kodi-addon-dev-kit/include/kodi/libXBMC_pvr.h
new file mode 100644
index 0000000..3e3d479
--- /dev/null
+++ b/xbmc/addons/kodi-addon-dev-kit/include/kodi/libXBMC_pvr.h
@@ -0,0 +1,366 @@
1#pragma once
2/*
3 * Copyright (C) 2005-2013 Team XBMC
4 * http://xbmc.org
5 *
6 * This Program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2, or (at your option)
9 * any later version.
10 *
11 * This Program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with XBMC; see the file COPYING. If not, see
18 * <http://www.gnu.org/licenses/>.
19 *
20 */
21
22#include <string>
23#include <vector>
24#include <string.h>
25#include <stdlib.h>
26#include <stdio.h>
27#include "xbmc_pvr_types.h"
28#include "libXBMC_addon.h"
29
30#ifdef _WIN32
31#define PVR_HELPER_DLL "\\library.xbmc.pvr\\libXBMC_pvr" ADDON_HELPER_EXT
32#else
33#define PVR_HELPER_DLL_NAME "libXBMC_pvr-" ADDON_HELPER_ARCH ADDON_HELPER_EXT
34#define PVR_HELPER_DLL "/library.xbmc.pvr/" PVR_HELPER_DLL_NAME
35#endif
36
37#define DVD_TIME_BASE 1000000
38#define DVD_NOPTS_VALUE (-1LL<<52) // should be possible to represent in both double and __int64
39
40class CHelper_libXBMC_pvr
41{
42public:
43 CHelper_libXBMC_pvr(void)
44 {
45 m_libXBMC_pvr = NULL;
46 m_Handle = NULL;
47 }
48
49 ~CHelper_libXBMC_pvr(void)
50 {
51 if (m_libXBMC_pvr)
52 {
53 PVR_unregister_me(m_Handle, m_Callbacks);
54 dlclose(m_libXBMC_pvr);
55 }
56 }
57
58 /*!
59 * @brief Resolve all callback methods
60 * @param handle Pointer to the add-on
61 * @return True when all methods were resolved, false otherwise.
62 */
63 bool RegisterMe(void* handle)
64 {
65 m_Handle = handle;
66
67 std::string libBasePath;
68 libBasePath = ((cb_array*)m_Handle)->libPath;
69 libBasePath += PVR_HELPER_DLL;
70
71#if defined(ANDROID)
72 struct stat st;
73 if(stat(libBasePath.c_str(),&st) != 0)
74 {
75 std::string tempbin = getenv("XBMC_ANDROID_LIBS");
76 libBasePath = tempbin + "/" + PVR_HELPER_DLL_NAME;
77 }
78#endif
79
80 m_libXBMC_pvr = dlopen(libBasePath.c_str(), RTLD_LAZY);
81 if (m_libXBMC_pvr == NULL)
82 {
83 fprintf(stderr, "Unable to load %s\n", dlerror());
84 return false;
85 }
86
87 PVR_register_me = (void* (*)(void *HANDLE))
88 dlsym(m_libXBMC_pvr, "PVR_register_me");
89 if (PVR_register_me == NULL) { fprintf(stderr, "Unable to assign function %s\n", dlerror()); return false; }
90
91 PVR_unregister_me = (void (*)(void* HANDLE, void* CB))
92 dlsym(m_libXBMC_pvr, "PVR_unregister_me");
93 if (PVR_unregister_me == NULL) { fprintf(stderr, "Unable to assign function %s\n", dlerror()); return false; }
94
95 PVR_transfer_epg_entry = (void (*)(void* HANDLE, void* CB, const ADDON_HANDLE handle, const EPG_TAG *epgentry))
96 dlsym(m_libXBMC_pvr, "PVR_transfer_epg_entry");
97 if (PVR_transfer_epg_entry == NULL) { fprintf(stderr, "Unable to assign function %s\n", dlerror()); return false; }
98
99 PVR_transfer_channel_entry = (void (*)(void* HANDLE, void* CB, const ADDON_HANDLE handle, const PVR_CHANNEL *chan))
100 dlsym(m_libXBMC_pvr, "PVR_transfer_channel_entry");
101 if (PVR_transfer_channel_entry == NULL) { fprintf(stderr, "Unable to assign function %s\n", dlerror()); return false; }
102
103 PVR_transfer_timer_entry = (void (*)(void* HANDLE, void* CB, const ADDON_HANDLE handle, const PVR_TIMER *timer))
104 dlsym(m_libXBMC_pvr, "PVR_transfer_timer_entry");
105 if (PVR_transfer_timer_entry == NULL) { fprintf(stderr, "Unable to assign function %s\n", dlerror()); return false; }
106
107 PVR_transfer_recording_entry = (void (*)(void* HANDLE, void* CB, const ADDON_HANDLE handle, const PVR_RECORDING *recording))
108 dlsym(m_libXBMC_pvr, "PVR_transfer_recording_entry");
109 if (PVR_transfer_recording_entry == NULL) { fprintf(stderr, "Unable to assign function %s\n", dlerror()); return false; }
110
111 PVR_add_menu_hook = (void (*)(void* HANDLE, void* CB, PVR_MENUHOOK *hook))
112 dlsym(m_libXBMC_pvr, "PVR_add_menu_hook");
113 if (PVR_add_menu_hook == NULL) { fprintf(stderr, "Unable to assign function %s\n", dlerror()); return false; }
114
115 PVR_recording = (void (*)(void* HANDLE, void* CB, const char *Name, const char *FileName, bool On))
116 dlsym(m_libXBMC_pvr, "PVR_recording");
117 if (PVR_recording == NULL) { fprintf(stderr, "Unable to assign function %s\n", dlerror()); return false; }
118
119 PVR_trigger_timer_update = (void (*)(void* HANDLE, void* CB))
120 dlsym(m_libXBMC_pvr, "PVR_trigger_timer_update");
121 if (PVR_trigger_timer_update == NULL) { fprintf(stderr, "Unable to assign function %s\n", dlerror()); return false; }
122
123 PVR_trigger_recording_update = (void (*)(void* HANDLE, void* CB))
124 dlsym(m_libXBMC_pvr, "PVR_trigger_recording_update");
125 if (PVR_trigger_recording_update == NULL) { fprintf(stderr, "Unable to assign function %s\n", dlerror()); return false; }
126
127 PVR_trigger_channel_update = (void (*)(void* HANDLE, void* CB))
128 dlsym(m_libXBMC_pvr, "PVR_trigger_channel_update");
129 if (PVR_trigger_channel_update == NULL) { fprintf(stderr, "Unable to assign function %s\n", dlerror()); return false; }
130
131 PVR_trigger_channel_groups_update = (void (*)(void* HANDLE, void* CB))
132 dlsym(m_libXBMC_pvr, "PVR_trigger_channel_groups_update");
133 if (PVR_trigger_channel_groups_update == NULL) { fprintf(stderr, "Unable to assign function %s\n", dlerror()); return false; }
134
135 PVR_trigger_epg_update = (void (*)(void* HANDLE, void* CB, unsigned int iChannelUid))
136 dlsym(m_libXBMC_pvr, "PVR_trigger_epg_update");
137 if (PVR_trigger_epg_update == NULL) { fprintf(stderr, "Unable to assign function %s\n", dlerror()); return false; }
138
139 PVR_transfer_channel_group = (void (*)(void* HANDLE, void* CB, const ADDON_HANDLE handle, const PVR_CHANNEL_GROUP *group))
140 dlsym(m_libXBMC_pvr, "PVR_transfer_channel_group");
141 if (PVR_transfer_channel_group == NULL) { fprintf(stderr, "Unable to assign function %s\n", dlerror()); return false; }
142
143 PVR_transfer_channel_group_member = (void (*)(void* HANDLE, void* CB, const ADDON_HANDLE handle, const PVR_CHANNEL_GROUP_MEMBER *member))
144 dlsym(m_libXBMC_pvr, "PVR_transfer_channel_group_member");
145 if (PVR_transfer_channel_group_member == NULL) { fprintf(stderr, "Unable to assign function %s\n", dlerror()); return false; }
146
147#ifdef USE_DEMUX
148 PVR_free_demux_packet = (void (*)(void* HANDLE, void* CB, DemuxPacket* pPacket))
149 dlsym(m_libXBMC_pvr, "PVR_free_demux_packet");
150 if (PVR_free_demux_packet == NULL) { fprintf(stderr, "Unable to assign function %s\n", dlerror()); return false; }
151
152 PVR_allocate_demux_packet = (DemuxPacket* (*)(void* HANDLE, void* CB, int iDataSize))
153 dlsym(m_libXBMC_pvr, "PVR_allocate_demux_packet");
154 if (PVR_allocate_demux_packet == NULL) { fprintf(stderr, "Unable to assign function %s\n", dlerror()); return false; }
155#endif
156
157 PVR_connection_state_change = (void (*)(void* HANDLE, void* CB, const char *strConnectionString, PVR_CONNECTION_STATE newState, const char *strMessage))
158 dlsym(m_libXBMC_pvr, "PVR_connection_state_change");
159 if (PVR_connection_state_change == NULL) { fprintf(stderr, "Unable to assign function %s\n", dlerror()); return false; }
160
161 PVR_epg_event_state_change = (void (*)(void* HANDLE, void* CB, EPG_TAG* tag, unsigned int iUniqueChannelId, EPG_EVENT_STATE newState))
162 dlsym(m_libXBMC_pvr, "PVR_epg_event_state_change");
163 if (PVR_epg_event_state_change == NULL) { fprintf(stderr, "Unable to assign function %s\n", dlerror()); return false; }
164
165 m_Callbacks = PVR_register_me(m_Handle);
166 return m_Callbacks != NULL;
167 }
168
169 /*!
170 * @brief Transfer an EPG tag from the add-on to XBMC
171 * @param handle The handle parameter that XBMC used when requesting the EPG data
172 * @param entry The entry to transfer to XBMC
173 */
174 void TransferEpgEntry(const ADDON_HANDLE handle, const EPG_TAG* entry)
175 {
176 return PVR_transfer_epg_entry(m_Handle, m_Callbacks, handle, entry);
177 }
178
179 /*!
180 * @brief Transfer a channel entry from the add-on to XBMC
181 * @param handle The handle parameter that XBMC used when requesting the channel list
182 * @param entry The entry to transfer to XBMC
183 */
184 void TransferChannelEntry(const ADDON_HANDLE handle, const PVR_CHANNEL* entry)
185 {
186 return PVR_transfer_channel_entry(m_Handle, m_Callbacks, handle, entry);
187 }
188
189 /*!
190 * @brief Transfer a timer entry from the add-on to XBMC
191 * @param handle The handle parameter that XBMC used when requesting the timers list
192 * @param entry The entry to transfer to XBMC
193 */
194 void TransferTimerEntry(const ADDON_HANDLE handle, const PVR_TIMER* entry)
195 {
196 return PVR_transfer_timer_entry(m_Handle, m_Callbacks, handle, entry);
197 }
198
199 /*!
200 * @brief Transfer a recording entry from the add-on to XBMC
201 * @param handle The handle parameter that XBMC used when requesting the recordings list
202 * @param entry The entry to transfer to XBMC
203 */
204 void TransferRecordingEntry(const ADDON_HANDLE handle, const PVR_RECORDING* entry)
205 {
206 return PVR_transfer_recording_entry(m_Handle, m_Callbacks, handle, entry);
207 }
208
209 /*!
210 * @brief Transfer a channel group from the add-on to XBMC. The group will be created if it doesn't exist.
211 * @param handle The handle parameter that XBMC used when requesting the channel groups list
212 * @param entry The entry to transfer to XBMC
213 */
214 void TransferChannelGroup(const ADDON_HANDLE handle, const PVR_CHANNEL_GROUP* entry)
215 {
216 return PVR_transfer_channel_group(m_Handle, m_Callbacks, handle, entry);
217 }
218
219 /*!
220 * @brief Transfer a channel group member entry from the add-on to XBMC. The channel will be added to the group if the group can be found.
221 * @param handle The handle parameter that XBMC used when requesting the channel group members list
222 * @param entry The entry to transfer to XBMC
223 */
224 void TransferChannelGroupMember(const ADDON_HANDLE handle, const PVR_CHANNEL_GROUP_MEMBER* entry)
225 {
226 return PVR_transfer_channel_group_member(m_Handle, m_Callbacks, handle, entry);
227 }
228
229 /*!
230 * @brief Add or replace a menu hook for the context menu for this add-on
231 * @param hook The hook to add
232 */
233 void AddMenuHook(PVR_MENUHOOK* hook)
234 {
235 return PVR_add_menu_hook(m_Handle, m_Callbacks, hook);
236 }
237
238 /*!
239 * @brief Display a notification in XBMC that a recording started or stopped on the server
240 * @param strRecordingName The name of the recording to display
241 * @param strFileName The filename of the recording
242 * @param bOn True when recording started, false when it stopped
243 */
244 void Recording(const char* strRecordingName, const char* strFileName, bool bOn)
245 {
246 return PVR_recording(m_Handle, m_Callbacks, strRecordingName, strFileName, bOn);
247 }
248
249 /*!
250 * @brief Request XBMC to update it's list of timers
251 */
252 void TriggerTimerUpdate(void)
253 {
254 return PVR_trigger_timer_update(m_Handle, m_Callbacks);
255 }
256
257 /*!
258 * @brief Request XBMC to update it's list of recordings
259 */
260 void TriggerRecordingUpdate(void)
261 {
262 return PVR_trigger_recording_update(m_Handle, m_Callbacks);
263 }
264
265 /*!
266 * @brief Request XBMC to update it's list of channels
267 */
268 void TriggerChannelUpdate(void)
269 {
270 return PVR_trigger_channel_update(m_Handle, m_Callbacks);
271 }
272
273 /*!
274 * @brief Schedule an EPG update for the given channel channel
275 * @param iChannelUid The unique id of the channel for this add-on
276 */
277 void TriggerEpgUpdate(unsigned int iChannelUid)
278 {
279 return PVR_trigger_epg_update(m_Handle, m_Callbacks, iChannelUid);
280 }
281
282 /*!
283 * @brief Request XBMC to update it's list of channel groups
284 */
285 void TriggerChannelGroupsUpdate(void)
286 {
287 return PVR_trigger_channel_groups_update(m_Handle, m_Callbacks);
288 }
289
290#ifdef USE_DEMUX
291 /*!
292 * @brief Free a packet that was allocated with AllocateDemuxPacket
293 * @param pPacket The packet to free
294 */
295 void FreeDemuxPacket(DemuxPacket* pPacket)
296 {
297 return PVR_free_demux_packet(m_Handle, m_Callbacks, pPacket);
298 }
299
300 /*!
301 * @brief Allocate a demux packet. Free with FreeDemuxPacket
302 * @param iDataSize The size of the data that will go into the packet
303 * @return The allocated packet
304 */
305 DemuxPacket* AllocateDemuxPacket(int iDataSize)
306 {
307 return PVR_allocate_demux_packet(m_Handle, m_Callbacks, iDataSize);
308 }
309#endif
310
311 /*!
312 * @brief Notify a state change for a PVR backend connection
313 * @param strConnectionString The connection string reported by the backend that can be displayed in the UI.
314 * @param newState The new state.
315 * @param strMessage A localized addon-defined string representing the new state, that can be displayed
316 * in the UI or NULL if the Kodi-defined default string for the new state shall be displayed.
317 */
318 void ConnectionStateChange(const char *strConnectionString, PVR_CONNECTION_STATE newState, const char *strMessage)
319 {
320 return PVR_connection_state_change(m_Handle, m_Callbacks, strConnectionString, newState, strMessage);
321 }
322
323 /*!
324 * @brief Notify a state change for an EPG event
325 * @param tag The EPG event.
326 * @param iUniqueChannelId The unique id of the channel for the EPG event
327 * @param newState The new state. For EPG_EVENT_CREATED and EPG_EVENT_UPDATED, tag must be filled with all available
328 * event data, not just a delta. For EPG_EVENT_DELETED, it is sufficient to fill EPG_TAG.iUniqueBroadcastId
329 */
330 void EpgEventStateChange(EPG_TAG *tag, unsigned int iUniqueChannelId, EPG_EVENT_STATE newState)
331 {
332 return PVR_epg_event_state_change(m_Handle, m_Callbacks, tag, iUniqueChannelId, newState);
333 }
334
335protected:
336 void* (*PVR_register_me)(void*);
337 void (*PVR_unregister_me)(void*, void*);
338 void (*PVR_transfer_epg_entry)(void*, void*, const ADDON_HANDLE, const EPG_TAG*);
339 void (*PVR_transfer_channel_entry)(void*, void*, const ADDON_HANDLE, const PVR_CHANNEL*);
340 void (*PVR_transfer_timer_entry)(void*, void*, const ADDON_HANDLE, const PVR_TIMER*);
341 void (*PVR_transfer_recording_entry)(void*, void*, const ADDON_HANDLE, const PVR_RECORDING*);
342 void (*PVR_add_menu_hook)(void*, void*, PVR_MENUHOOK*);
343 void (*PVR_recording)(void*, void*, const char*, const char*, bool);
344 void (*PVR_trigger_channel_update)(void*, void*);
345 void (*PVR_trigger_channel_groups_update)(void*, void*);
346 void (*PVR_trigger_timer_update)(void*, void*);
347 void (*PVR_trigger_recording_update)(void* , void*);
348 void (*PVR_trigger_epg_update)(void*, void*, unsigned int);
349 void (*PVR_transfer_channel_group)(void*, void*, const ADDON_HANDLE, const PVR_CHANNEL_GROUP*);
350 void (*PVR_transfer_channel_group_member)(void*, void*, const ADDON_HANDLE, const PVR_CHANNEL_GROUP_MEMBER*);
351#ifdef USE_DEMUX
352 void (*PVR_free_demux_packet)(void*, void*, DemuxPacket*);
353 DemuxPacket* (*PVR_allocate_demux_packet)(void*, void*, int);
354#endif
355 void (*PVR_connection_state_change)(void*, void*, const char*, PVR_CONNECTION_STATE, const char*);
356 void (*PVR_epg_event_state_change)(void*, void*, EPG_TAG*, unsigned int, EPG_EVENT_STATE);
357
358private:
359 void* m_libXBMC_pvr;
360 void* m_Handle;
361 void* m_Callbacks;
362 struct cb_array
363 {
364 const char* libPath;
365 };
366};