1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
|
#pragma once
/*
* Copyright (C) 2005-2010 Team XBMC
* http://www.xbmc.org
*
* This Program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with XBMC; see the file COPYING. If not, see
* <http://www.gnu.org/licenses/>.
*
*/
#include <string>
#include <vector>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include "xbmc_pvr_types.h"
#include "../library.xbmc.addon/libXBMC_addon.h"
#ifdef _WIN32
#define PVR_HELPER_DLL "\\library.xbmc.pvr\\libXBMC_pvr" ADDON_HELPER_EXT
#else
#define PVR_HELPER_DLL "/library.xbmc.pvr/libXBMC_pvr-" ADDON_HELPER_ARCH ADDON_HELPER_EXT
#endif
#define DVD_TIME_BASE 1000000
#define DVD_NOPTS_VALUE (-1LL<<52) // should be possible to represent in both double and __int64
class CHelper_libXBMC_pvr
{
public:
CHelper_libXBMC_pvr()
{
m_libXBMC_pvr = NULL;
m_Handle = NULL;
}
~CHelper_libXBMC_pvr()
{
if (m_libXBMC_pvr)
{
PVR_unregister_me(m_Handle, m_Callbacks);
dlclose(m_libXBMC_pvr);
}
}
bool RegisterMe(void *Handle)
{
m_Handle = Handle;
std::string libBasePath;
libBasePath = ((cb_array*)m_Handle)->libPath;
libBasePath += PVR_HELPER_DLL;
m_libXBMC_pvr = dlopen(libBasePath.c_str(), RTLD_LAZY);
if (m_libXBMC_pvr == NULL)
{
fprintf(stderr, "Unable to load %s\n", dlerror());
return false;
}
PVR_register_me = (void* (*)(void *HANDLE))
dlsym(m_libXBMC_pvr, "PVR_register_me");
if (PVR_register_me == NULL) { fprintf(stderr, "Unable to assign function %s\n", dlerror()); return false; }
PVR_unregister_me = (void (*)(void* HANDLE, void* CB))
dlsym(m_libXBMC_pvr, "PVR_unregister_me");
if (PVR_unregister_me == NULL) { fprintf(stderr, "Unable to assign function %s\n", dlerror()); return false; }
PVR_transfer_epg_entry = (void (*)(void* HANDLE, void* CB, const ADDON_HANDLE handle, const EPG_TAG *epgentry))
dlsym(m_libXBMC_pvr, "PVR_transfer_epg_entry");
if (PVR_transfer_epg_entry == NULL) { fprintf(stderr, "Unable to assign function %s\n", dlerror()); return false; }
PVR_transfer_channel_entry = (void (*)(void* HANDLE, void* CB, const ADDON_HANDLE handle, const PVR_CHANNEL *chan))
dlsym(m_libXBMC_pvr, "PVR_transfer_channel_entry");
if (PVR_transfer_channel_entry == NULL) { fprintf(stderr, "Unable to assign function %s\n", dlerror()); return false; }
PVR_transfer_timer_entry = (void (*)(void* HANDLE, void* CB, const ADDON_HANDLE handle, const PVR_TIMER *timer))
dlsym(m_libXBMC_pvr, "PVR_transfer_timer_entry");
if (PVR_transfer_timer_entry == NULL) { fprintf(stderr, "Unable to assign function %s\n", dlerror()); return false; }
PVR_transfer_recording_entry = (void (*)(void* HANDLE, void* CB, const ADDON_HANDLE handle, const PVR_RECORDING *recording))
dlsym(m_libXBMC_pvr, "PVR_transfer_recording_entry");
if (PVR_transfer_recording_entry == NULL) { fprintf(stderr, "Unable to assign function %s\n", dlerror()); return false; }
PVR_add_menu_hook = (void (*)(void* HANDLE, void* CB, PVR_MENUHOOK *hook))
dlsym(m_libXBMC_pvr, "PVR_add_menu_hook");
if (PVR_add_menu_hook == NULL) { fprintf(stderr, "Unable to assign function %s\n", dlerror()); return false; }
PVR_recording = (void (*)(void* HANDLE, void* CB, const char *Name, const char *FileName, bool On))
dlsym(m_libXBMC_pvr, "PVR_recording");
if (PVR_recording == NULL) { fprintf(stderr, "Unable to assign function %s\n", dlerror()); return false; }
PVR_trigger_timer_update = (void (*)(void* HANDLE, void* CB))
dlsym(m_libXBMC_pvr, "PVR_trigger_timer_update");
if (PVR_trigger_timer_update == NULL) { fprintf(stderr, "Unable to assign function %s\n", dlerror()); return false; }
PVR_trigger_recording_update = (void (*)(void* HANDLE, void* CB))
dlsym(m_libXBMC_pvr, "PVR_trigger_recording_update");
if (PVR_trigger_recording_update == NULL) { fprintf(stderr, "Unable to assign function %s\n", dlerror()); return false; }
PVR_trigger_channel_update = (void (*)(void* HANDLE, void* CB))
dlsym(m_libXBMC_pvr, "PVR_trigger_channel_update");
if (PVR_trigger_channel_update == NULL) { fprintf(stderr, "Unable to assign function %s\n", dlerror()); return false; }
PVR_trigger_channel_groups_update = (void (*)(void* HANDLE, void* CB))
dlsym(m_libXBMC_pvr, "PVR_trigger_channel_groups_update");
if (PVR_trigger_channel_groups_update == NULL) { fprintf(stderr, "Unable to assign function %s\n", dlerror()); return false; }
PVR_trigger_epg_update = (void (*)(void* HANDLE, void* CB, unsigned int iChannelUid))
dlsym(m_libXBMC_pvr, "PVR_trigger_epg_update");
if (PVR_trigger_epg_update == NULL) { fprintf(stderr, "Unable to assign function %s\n", dlerror()); return false; }
PVR_transfer_channel_group = (void (*)(void* HANDLE, void* CB, const ADDON_HANDLE handle, const PVR_CHANNEL_GROUP *group))
dlsym(m_libXBMC_pvr, "PVR_transfer_channel_group");
if (PVR_transfer_channel_group == NULL) { fprintf(stderr, "Unable to assign function %s\n", dlerror()); return false; }
PVR_transfer_channel_group_member = (void (*)(void* HANDLE, void* CB, const ADDON_HANDLE handle, const PVR_CHANNEL_GROUP_MEMBER *member))
dlsym(m_libXBMC_pvr, "PVR_transfer_channel_group_member");
if (PVR_transfer_channel_group_member == NULL) { fprintf(stderr, "Unable to assign function %s\n", dlerror()); return false; }
#ifdef USE_DEMUX
PVR_free_demux_packet = (void (*)(void* HANDLE, void* CB, DemuxPacket* pPacket))
dlsym(m_libXBMC_pvr, "PVR_free_demux_packet");
if (PVR_free_demux_packet == NULL) { fprintf(stderr, "Unable to assign function %s\n", dlerror()); return false; }
PVR_allocate_demux_packet = (DemuxPacket* (*)(void* HANDLE, void* CB, int iDataSize))
dlsym(m_libXBMC_pvr, "PVR_allocate_demux_packet");
if (PVR_allocate_demux_packet == NULL) { fprintf(stderr, "Unable to assign function %s\n", dlerror()); return false; }
#endif
m_Callbacks = PVR_register_me(m_Handle);
return m_Callbacks != NULL;
}
void TransferEpgEntry(const ADDON_HANDLE handle, const EPG_TAG *epgentry)
{
return PVR_transfer_epg_entry(m_Handle, m_Callbacks, handle, epgentry);
}
void TransferChannelEntry(const ADDON_HANDLE handle, const PVR_CHANNEL *chan)
{
return PVR_transfer_channel_entry(m_Handle, m_Callbacks, handle, chan);
}
void TransferTimerEntry(const ADDON_HANDLE handle, const PVR_TIMER *timer)
{
return PVR_transfer_timer_entry(m_Handle, m_Callbacks, handle, timer);
}
void TransferRecordingEntry(const ADDON_HANDLE handle, const PVR_RECORDING *recording)
{
return PVR_transfer_recording_entry(m_Handle, m_Callbacks, handle, recording);
}
void AddMenuHook(PVR_MENUHOOK *hook)
{
return PVR_add_menu_hook(m_Handle, m_Callbacks, hook);
}
void Recording(const char *Name, const char *FileName, bool On)
{
return PVR_recording(m_Handle, m_Callbacks, Name, FileName, On);
}
void TriggerTimerUpdate()
{
return PVR_trigger_timer_update(m_Handle, m_Callbacks);
}
void TriggerRecordingUpdate()
{
return PVR_trigger_recording_update(m_Handle, m_Callbacks);
}
void TriggerChannelUpdate()
{
return PVR_trigger_channel_update(m_Handle, m_Callbacks);
}
void TriggerEpgUpdate(unsigned int iChannelUid)
{
return PVR_trigger_epg_update(m_Handle, m_Callbacks, iChannelUid);
}
void TriggerChannelGroupsUpdate()
{
return PVR_trigger_channel_groups_update(m_Handle, m_Callbacks);
}
void TransferChannelGroup(const ADDON_HANDLE handle, const PVR_CHANNEL_GROUP *group)
{
return PVR_transfer_channel_group(m_Handle, m_Callbacks, handle, group);
}
void TransferChannelGroupMember(const ADDON_HANDLE handle, const PVR_CHANNEL_GROUP_MEMBER *member)
{
return PVR_transfer_channel_group_member(m_Handle, m_Callbacks, handle, member);
}
#ifdef USE_DEMUX
void FreeDemuxPacket(DemuxPacket* pPacket)
{
return PVR_free_demux_packet(m_Handle, m_Callbacks, pPacket);
}
DemuxPacket* AllocateDemuxPacket(int iDataSize)
{
return PVR_allocate_demux_packet(m_Handle, m_Callbacks, iDataSize);
}
#endif
protected:
void* (*PVR_register_me)(void *HANDLE);
void (*PVR_unregister_me)(void* HANDLE, void* CB);
void (*PVR_transfer_epg_entry)(void* HANDLE, void* CB, const ADDON_HANDLE handle, const EPG_TAG *epgentry);
void (*PVR_transfer_channel_entry)(void* HANDLE, void* CB, const ADDON_HANDLE handle, const PVR_CHANNEL *chan);
void (*PVR_transfer_timer_entry)(void* HANDLE, void* CB, const ADDON_HANDLE handle, const PVR_TIMER *timer);
void (*PVR_transfer_recording_entry)(void* HANDLE, void* CB, const ADDON_HANDLE handle, const PVR_RECORDING *recording);
void (*PVR_add_menu_hook)(void* HANDLE, void* CB, PVR_MENUHOOK *hook);
void (*PVR_recording)(void* HANDLE, void* CB, const char *Name, const char *FileName, bool On);
void (*PVR_trigger_channel_update)(void* HANDLE, void* CB);
void (*PVR_trigger_channel_groups_update)(void* HANDLE, void* CB);
void (*PVR_trigger_timer_update)(void* HANDLE, void* CB);
void (*PVR_trigger_recording_update)(void* HANDLE, void* CB);
void (*PVR_trigger_epg_update)(void* HANDLE, void* CB, unsigned int iChannelUid);
void (*PVR_transfer_channel_group)(void* HANDLE, void* CB, const ADDON_HANDLE handle, const PVR_CHANNEL_GROUP *group);
void (*PVR_transfer_channel_group_member)(void* HANDLE, void* CB, const ADDON_HANDLE handle, const PVR_CHANNEL_GROUP_MEMBER *member);
#ifdef USE_DEMUX
void (*PVR_free_demux_packet)(void* HANDLE, void* CB, DemuxPacket* pPacket);
DemuxPacket* (*PVR_allocate_demux_packet)(void* HANDLE, void* CB, int iDataSize);
#endif
private:
void *m_libXBMC_pvr;
void *m_Handle;
void *m_Callbacks;
struct cb_array
{
const char* libPath;
};
};
|