[bluray] Fix stream info/language retrieval for blurays in non-nav mode.
[vuplus_xbmc] / addons / library.xbmc.pvr / libXBMC_pvr.h
1 #pragma once
2 /*
3  *      Copyright (C) 2005-2013 Team XBMC
4  *      http://www.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 "../library.xbmc.addon/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
40 class CHelper_libXBMC_pvr
41 {
42 public:
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     m_Callbacks = PVR_register_me(m_Handle);
158     return m_Callbacks != NULL;
159   }
160
161   /*!
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
165    */
166   void TransferEpgEntry(const ADDON_HANDLE handle, const EPG_TAG* entry)
167   {
168     return PVR_transfer_epg_entry(m_Handle, m_Callbacks, handle, entry);
169   }
170
171   /*!
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
175    */
176   void TransferChannelEntry(const ADDON_HANDLE handle, const PVR_CHANNEL* entry)
177   {
178     return PVR_transfer_channel_entry(m_Handle, m_Callbacks, handle, entry);
179   }
180
181   /*!
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
185    */
186   void TransferTimerEntry(const ADDON_HANDLE handle, const PVR_TIMER* entry)
187   {
188     return PVR_transfer_timer_entry(m_Handle, m_Callbacks, handle, entry);
189   }
190
191   /*!
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
195    */
196   void TransferRecordingEntry(const ADDON_HANDLE handle, const PVR_RECORDING* entry)
197   {
198     return PVR_transfer_recording_entry(m_Handle, m_Callbacks, handle, entry);
199   }
200
201   /*!
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
205    */
206   void TransferChannelGroup(const ADDON_HANDLE handle, const PVR_CHANNEL_GROUP* entry)
207   {
208     return PVR_transfer_channel_group(m_Handle, m_Callbacks, handle, entry);
209   }
210
211   /*!
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
215    */
216   void TransferChannelGroupMember(const ADDON_HANDLE handle, const PVR_CHANNEL_GROUP_MEMBER* entry)
217   {
218     return PVR_transfer_channel_group_member(m_Handle, m_Callbacks, handle, entry);
219   }
220
221   /*!
222    * @brief Add or replace a menu hook for the context menu for this add-on
223    * @param hook The hook to add
224    */
225   void AddMenuHook(PVR_MENUHOOK* hook)
226   {
227     return PVR_add_menu_hook(m_Handle, m_Callbacks, hook);
228   }
229
230   /*!
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
235    */
236   void Recording(const char* strRecordingName, const char* strFileName, bool bOn)
237   {
238     return PVR_recording(m_Handle, m_Callbacks, strRecordingName, strFileName, bOn);
239   }
240
241   /*!
242    * @brief Request XBMC to update it's list of timers
243    */
244   void TriggerTimerUpdate(void)
245   {
246     return PVR_trigger_timer_update(m_Handle, m_Callbacks);
247   }
248
249   /*!
250    * @brief Request XBMC to update it's list of recordings
251    */
252   void TriggerRecordingUpdate(void)
253   {
254     return PVR_trigger_recording_update(m_Handle, m_Callbacks);
255   }
256
257   /*!
258    * @brief Request XBMC to update it's list of channels
259    */
260   void TriggerChannelUpdate(void)
261   {
262     return PVR_trigger_channel_update(m_Handle, m_Callbacks);
263   }
264
265   /*!
266    * @brief Schedule an EPG update for the given channel channel
267    * @param iChannelUid The unique id of the channel for this add-on
268    */
269   void TriggerEpgUpdate(unsigned int iChannelUid)
270   {
271     return PVR_trigger_epg_update(m_Handle, m_Callbacks, iChannelUid);
272   }
273
274   /*!
275    * @brief Request XBMC to update it's list of channel groups
276    */
277   void TriggerChannelGroupsUpdate(void)
278   {
279     return PVR_trigger_channel_groups_update(m_Handle, m_Callbacks);
280   }
281
282 #ifdef USE_DEMUX
283   /*!
284    * @brief Free a packet that was allocated with AllocateDemuxPacket
285    * @param pPacket The packet to free
286    */
287   void FreeDemuxPacket(DemuxPacket* pPacket)
288   {
289     return PVR_free_demux_packet(m_Handle, m_Callbacks, pPacket);
290   }
291
292   /*!
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
296    */
297   DemuxPacket* AllocateDemuxPacket(int iDataSize)
298   {
299     return PVR_allocate_demux_packet(m_Handle, m_Callbacks, iDataSize);
300   }
301 #endif
302
303 protected:
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*);
319 #ifdef USE_DEMUX
320   void (*PVR_free_demux_packet)(void*, void*, DemuxPacket*);
321   DemuxPacket* (*PVR_allocate_demux_packet)(void*, void*, int);
322 #endif
323
324 private:
325   void* m_libXBMC_pvr;
326   void* m_Handle;
327   void* m_Callbacks;
328   struct cb_array
329   {
330     const char* libPath;
331   };
332 };