3 * Copyright (C) 2005-2013 Team XBMC
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)
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.
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/>.
27 #include "xbmc_pvr_types.h"
28 #include "../library.xbmc.addon/libXBMC_addon.h"
31 #define PVR_HELPER_DLL "\\library.xbmc.pvr\\libXBMC_pvr" ADDON_HELPER_EXT
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
37 #define DVD_TIME_BASE 1000000
38 #define DVD_NOPTS_VALUE (-1LL<<52) // should be possible to represent in both double and __int64
40 class CHelper_libXBMC_pvr
43 CHelper_libXBMC_pvr(void)
49 ~CHelper_libXBMC_pvr(void)
53 PVR_unregister_me(m_Handle, m_Callbacks);
54 dlclose(m_libXBMC_pvr);
59 * @brief Resolve all callback methods
60 * @param handle Pointer to the add-on
61 * @return True when all methods were resolved, false otherwise.
63 bool RegisterMe(void* handle)
67 std::string libBasePath;
68 libBasePath = ((cb_array*)m_Handle)->libPath;
69 libBasePath += PVR_HELPER_DLL;
73 if(stat(libBasePath.c_str(),&st) != 0)
75 std::string tempbin = getenv("XBMC_ANDROID_LIBS");
76 libBasePath = tempbin + "/" + PVR_HELPER_DLL_NAME;
80 m_libXBMC_pvr = dlopen(libBasePath.c_str(), RTLD_LAZY);
81 if (m_libXBMC_pvr == NULL)
83 fprintf(stderr, "Unable to load %s\n", dlerror());
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; }
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; }
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; }
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; }
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; }
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; }
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; }
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; }
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; }
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; }
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; }
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; }
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; }
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; }
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; }
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; }
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; }
157 m_Callbacks = PVR_register_me(m_Handle);
158 return m_Callbacks != NULL;
162 * @brief Transfer an EPG tag from the add-on to XBMC
163 * @param handle The handle parameter that XBMC used when requesting the EPG data
164 * @param entry The entry to transfer to XBMC
166 void TransferEpgEntry(const ADDON_HANDLE handle, const EPG_TAG* entry)
168 return PVR_transfer_epg_entry(m_Handle, m_Callbacks, handle, entry);
172 * @brief Transfer a channel entry from the add-on to XBMC
173 * @param handle The handle parameter that XBMC used when requesting the channel list
174 * @param entry The entry to transfer to XBMC
176 void TransferChannelEntry(const ADDON_HANDLE handle, const PVR_CHANNEL* entry)
178 return PVR_transfer_channel_entry(m_Handle, m_Callbacks, handle, entry);
182 * @brief Transfer a timer entry from the add-on to XBMC
183 * @param handle The handle parameter that XBMC used when requesting the timers list
184 * @param entry The entry to transfer to XBMC
186 void TransferTimerEntry(const ADDON_HANDLE handle, const PVR_TIMER* entry)
188 return PVR_transfer_timer_entry(m_Handle, m_Callbacks, handle, entry);
192 * @brief Transfer a recording entry from the add-on to XBMC
193 * @param handle The handle parameter that XBMC used when requesting the recordings list
194 * @param entry The entry to transfer to XBMC
196 void TransferRecordingEntry(const ADDON_HANDLE handle, const PVR_RECORDING* entry)
198 return PVR_transfer_recording_entry(m_Handle, m_Callbacks, handle, entry);
202 * @brief Transfer a channel group from the add-on to XBMC. The group will be created if it doesn't exist.
203 * @param handle The handle parameter that XBMC used when requesting the channel groups list
204 * @param entry The entry to transfer to XBMC
206 void TransferChannelGroup(const ADDON_HANDLE handle, const PVR_CHANNEL_GROUP* entry)
208 return PVR_transfer_channel_group(m_Handle, m_Callbacks, handle, entry);
212 * @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.
213 * @param handle The handle parameter that XBMC used when requesting the channel group members list
214 * @param entry The entry to transfer to XBMC
216 void TransferChannelGroupMember(const ADDON_HANDLE handle, const PVR_CHANNEL_GROUP_MEMBER* entry)
218 return PVR_transfer_channel_group_member(m_Handle, m_Callbacks, handle, entry);
222 * @brief Add or replace a menu hook for the context menu for this add-on
223 * @param hook The hook to add
225 void AddMenuHook(PVR_MENUHOOK* hook)
227 return PVR_add_menu_hook(m_Handle, m_Callbacks, hook);
231 * @brief Display a notification in XBMC that a recording started or stopped on the server
232 * @param strRecordingName The name of the recording to display
233 * @param strFileName The filename of the recording
234 * @param bOn True when recording started, false when it stopped
236 void Recording(const char* strRecordingName, const char* strFileName, bool bOn)
238 return PVR_recording(m_Handle, m_Callbacks, strRecordingName, strFileName, bOn);
242 * @brief Request XBMC to update it's list of timers
244 void TriggerTimerUpdate(void)
246 return PVR_trigger_timer_update(m_Handle, m_Callbacks);
250 * @brief Request XBMC to update it's list of recordings
252 void TriggerRecordingUpdate(void)
254 return PVR_trigger_recording_update(m_Handle, m_Callbacks);
258 * @brief Request XBMC to update it's list of channels
260 void TriggerChannelUpdate(void)
262 return PVR_trigger_channel_update(m_Handle, m_Callbacks);
266 * @brief Schedule an EPG update for the given channel channel
267 * @param iChannelUid The unique id of the channel for this add-on
269 void TriggerEpgUpdate(unsigned int iChannelUid)
271 return PVR_trigger_epg_update(m_Handle, m_Callbacks, iChannelUid);
275 * @brief Request XBMC to update it's list of channel groups
277 void TriggerChannelGroupsUpdate(void)
279 return PVR_trigger_channel_groups_update(m_Handle, m_Callbacks);
284 * @brief Free a packet that was allocated with AllocateDemuxPacket
285 * @param pPacket The packet to free
287 void FreeDemuxPacket(DemuxPacket* pPacket)
289 return PVR_free_demux_packet(m_Handle, m_Callbacks, pPacket);
293 * @brief Allocate a demux packet. Free with FreeDemuxPacket
294 * @param iDataSize The size of the data that will go into the packet
295 * @return The allocated packet
297 DemuxPacket* AllocateDemuxPacket(int iDataSize)
299 return PVR_allocate_demux_packet(m_Handle, m_Callbacks, iDataSize);
304 void* (*PVR_register_me)(void*);
305 void (*PVR_unregister_me)(void*, void*);
306 void (*PVR_transfer_epg_entry)(void*, void*, const ADDON_HANDLE, const EPG_TAG*);
307 void (*PVR_transfer_channel_entry)(void*, void*, const ADDON_HANDLE, const PVR_CHANNEL*);
308 void (*PVR_transfer_timer_entry)(void*, void*, const ADDON_HANDLE, const PVR_TIMER*);
309 void (*PVR_transfer_recording_entry)(void*, void*, const ADDON_HANDLE, const PVR_RECORDING*);
310 void (*PVR_add_menu_hook)(void*, void*, PVR_MENUHOOK*);
311 void (*PVR_recording)(void*, void*, const char*, const char*, bool);
312 void (*PVR_trigger_channel_update)(void*, void*);
313 void (*PVR_trigger_channel_groups_update)(void*, void*);
314 void (*PVR_trigger_timer_update)(void*, void*);
315 void (*PVR_trigger_recording_update)(void* , void*);
316 void (*PVR_trigger_epg_update)(void*, void*, unsigned int);
317 void (*PVR_transfer_channel_group)(void*, void*, const ADDON_HANDLE, const PVR_CHANNEL_GROUP*);
318 void (*PVR_transfer_channel_group_member)(void*, void*, const ADDON_HANDLE, const PVR_CHANNEL_GROUP_MEMBER*);
320 void (*PVR_free_demux_packet)(void*, void*, DemuxPacket*);
321 DemuxPacket* (*PVR_allocate_demux_packet)(void*, void*, int);