summaryrefslogtreecommitdiffstats
path: root/xbmc/addons/kodi-addon-dev-kit/include/kodi/libKODI_game.h
diff options
context:
space:
mode:
authormanuel <manuel@mausz.at>2016-12-13 13:45:04 +0100
committermanuel <manuel@mausz.at>2016-12-13 13:45:04 +0100
commit1e5bdca69f7676b2dbcd64f0f44f31b12b337b7c (patch)
treede36b55c5b49c0b266ebf8a5276815d2ac1a8ae5 /xbmc/addons/kodi-addon-dev-kit/include/kodi/libKODI_game.h
parent8cdf8dec703d882b46ca50a769fabb95ffc48e2c (diff)
downloadkodi-pvr-build-1e5bdca69f7676b2dbcd64f0f44f31b12b337b7c.tar.gz
kodi-pvr-build-1e5bdca69f7676b2dbcd64f0f44f31b12b337b7c.tar.bz2
kodi-pvr-build-1e5bdca69f7676b2dbcd64f0f44f31b12b337b7c.zip
sync with upstream
Diffstat (limited to 'xbmc/addons/kodi-addon-dev-kit/include/kodi/libKODI_game.h')
-rw-r--r--xbmc/addons/kodi-addon-dev-kit/include/kodi/libKODI_game.h238
1 files changed, 238 insertions, 0 deletions
diff --git a/xbmc/addons/kodi-addon-dev-kit/include/kodi/libKODI_game.h b/xbmc/addons/kodi-addon-dev-kit/include/kodi/libKODI_game.h
new file mode 100644
index 0000000..b5a46dd
--- /dev/null
+++ b/xbmc/addons/kodi-addon-dev-kit/include/kodi/libKODI_game.h
@@ -0,0 +1,238 @@
1/*
2 * Copyright (C) 2014-2016 Team Kodi
3 * http://kodi.tv
4 *
5 * This Program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2, or (at your option)
8 * any later version.
9 *
10 * This Program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this Program; see the file COPYING. If not, see
17 * <http://www.gnu.org/licenses/>.
18 *
19 */
20#pragma once
21
22#include "libXBMC_addon.h"
23#include "kodi_game_callbacks.h"
24
25#include <string>
26#include <stdio.h>
27
28#if defined(ANDROID)
29 #include <sys/stat.h>
30#endif
31
32#ifdef _WIN32
33 #define GAME_HELPER_DLL "\\library.kodi.game\\libKODI_game" ADDON_HELPER_EXT
34#else
35 #define GAME_HELPER_DLL_NAME "libKODI_game-" ADDON_HELPER_ARCH ADDON_HELPER_EXT
36 #define GAME_HELPER_DLL "/library.kodi.game/" GAME_HELPER_DLL_NAME
37#endif
38
39#define GAME_REGISTER_SYMBOL(dll, functionPtr) \
40 CHelper_libKODI_game::RegisterSymbol(dll, functionPtr, #functionPtr)
41
42class CHelper_libKODI_game
43{
44public:
45 CHelper_libKODI_game(void) :
46 GAME_register_me(nullptr),
47 GAME_unregister_me(nullptr),
48 GAME_close_game(nullptr),
49 GAME_open_pixel_stream(nullptr),
50 GAME_open_video_stream(nullptr),
51 GAME_open_pcm_stream(nullptr),
52 GAME_open_audio_stream(nullptr),
53 GAME_add_stream_data(nullptr),
54 GAME_close_stream(nullptr),
55 GAME_enable_hardware_rendering(nullptr),
56 GAME_hw_get_current_framebuffer(nullptr),
57 GAME_hw_get_proc_address(nullptr),
58 GAME_render_frame(nullptr),
59 GAME_open_port(nullptr),
60 GAME_close_port(nullptr),
61 GAME_input_event(nullptr),
62 m_handle(nullptr),
63 m_callbacks(nullptr),
64 m_libKODI_game(nullptr)
65 {
66 }
67
68 ~CHelper_libKODI_game(void)
69 {
70 if (m_libKODI_game)
71 {
72 GAME_unregister_me(m_handle, m_callbacks);
73 dlclose(m_libKODI_game);
74 }
75 }
76
77 template <typename T>
78 static bool RegisterSymbol(void* dll, T& functionPtr, const char* strFunctionPtr)
79 {
80 return (functionPtr = (T)dlsym(dll, strFunctionPtr)) != NULL;
81 }
82
83 /*!
84 * @brief Resolve all callback methods
85 * @param handle Pointer to the add-on
86 * @return True when all methods were resolved, false otherwise.
87 */
88 bool RegisterMe(void* handle)
89 {
90 m_handle = handle;
91
92 std::string libBasePath;
93 libBasePath = ((cb_array*)m_handle)->libBasePath;
94 libBasePath += GAME_HELPER_DLL;
95
96#if defined(ANDROID)
97 struct stat st;
98 if (stat(libBasePath.c_str(),&st) != 0)
99 {
100 std::string tempbin = getenv("XBMC_ANDROID_LIBS");
101 libBasePath = tempbin + "/" + GAME_HELPER_DLL_NAME;
102 }
103#endif
104
105 m_libKODI_game = dlopen(libBasePath.c_str(), RTLD_LAZY);
106 if (m_libKODI_game == NULL)
107 {
108 fprintf(stderr, "Unable to load %s\n", dlerror());
109 return false;
110 }
111
112 try
113 {
114 if (!GAME_REGISTER_SYMBOL(m_libKODI_game, GAME_register_me)) throw false;
115 if (!GAME_REGISTER_SYMBOL(m_libKODI_game, GAME_unregister_me)) throw false;
116 if (!GAME_REGISTER_SYMBOL(m_libKODI_game, GAME_close_game)) throw false;
117 if (!GAME_REGISTER_SYMBOL(m_libKODI_game, GAME_open_pixel_stream)) throw false;
118 if (!GAME_REGISTER_SYMBOL(m_libKODI_game, GAME_open_video_stream)) throw false;
119 if (!GAME_REGISTER_SYMBOL(m_libKODI_game, GAME_open_pcm_stream)) throw false;
120 if (!GAME_REGISTER_SYMBOL(m_libKODI_game, GAME_open_audio_stream)) throw false;
121 if (!GAME_REGISTER_SYMBOL(m_libKODI_game, GAME_add_stream_data)) throw false;
122 if (!GAME_REGISTER_SYMBOL(m_libKODI_game, GAME_close_stream)) throw false;
123 if (!GAME_REGISTER_SYMBOL(m_libKODI_game, GAME_enable_hardware_rendering)) throw false;
124 if (!GAME_REGISTER_SYMBOL(m_libKODI_game, GAME_hw_get_current_framebuffer)) throw false;
125 if (!GAME_REGISTER_SYMBOL(m_libKODI_game, GAME_hw_get_proc_address)) throw false;
126 if (!GAME_REGISTER_SYMBOL(m_libKODI_game, GAME_render_frame)) throw false;
127 if (!GAME_REGISTER_SYMBOL(m_libKODI_game, GAME_open_port)) throw false;
128 if (!GAME_REGISTER_SYMBOL(m_libKODI_game, GAME_close_port)) throw false;
129 if (!GAME_REGISTER_SYMBOL(m_libKODI_game, GAME_input_event)) throw false;
130 }
131 catch (const bool& bSuccess)
132 {
133 fprintf(stderr, "ERROR: Unable to assign function %s\n", dlerror());
134 return bSuccess;
135 }
136
137 m_callbacks = GAME_register_me(m_handle);
138 return m_callbacks != NULL;
139 }
140
141 void CloseGame(void)
142 {
143 return GAME_close_game(m_handle, m_callbacks);
144 }
145
146 bool OpenPixelStream(GAME_PIXEL_FORMAT format, unsigned int width, unsigned int height, GAME_VIDEO_ROTATION rotation)
147 {
148 return GAME_open_pixel_stream(m_handle, m_callbacks, format, width, height, rotation) == 0;
149 }
150
151 bool OpenVideoStream(GAME_VIDEO_CODEC codec)
152 {
153 return GAME_open_video_stream(m_handle, m_callbacks, codec) == 0;
154 }
155
156 bool OpenPCMStream(GAME_PCM_FORMAT format, const GAME_AUDIO_CHANNEL* channel_map)
157 {
158 return GAME_open_pcm_stream(m_handle, m_callbacks, format, channel_map) == 0;
159 }
160
161 bool OpenAudioStream(GAME_AUDIO_CODEC codec, const GAME_AUDIO_CHANNEL* channel_map)
162 {
163 return GAME_open_audio_stream(m_handle, m_callbacks, codec, channel_map) == 0;
164 }
165
166 void AddStreamData(GAME_STREAM_TYPE stream, const uint8_t* data, unsigned int size)
167 {
168 GAME_add_stream_data(m_handle, m_callbacks, stream, data, size);
169 }
170
171 void CloseStream(GAME_STREAM_TYPE stream)
172 {
173 GAME_close_stream(m_handle, m_callbacks, stream);
174 }
175
176 void EnableHardwareRendering(const struct game_hw_info* hw_info)
177 {
178 return GAME_enable_hardware_rendering(m_handle, m_callbacks, hw_info);
179 }
180
181 uintptr_t HwGetCurrentFramebuffer(void)
182 {
183 return GAME_hw_get_current_framebuffer(m_handle, m_callbacks);
184 }
185
186 game_proc_address_t HwGetProcAddress(const char* sym)
187 {
188 return GAME_hw_get_proc_address(m_handle, m_callbacks, sym);
189 }
190
191 void RenderFrame()
192 {
193 return GAME_render_frame(m_handle, m_callbacks);
194 }
195
196 bool OpenPort(unsigned int port)
197 {
198 return GAME_open_port(m_handle, m_callbacks, port);
199 }
200
201 void ClosePort(unsigned int port)
202 {
203 return GAME_close_port(m_handle, m_callbacks, port);
204 }
205
206 bool InputEvent(const game_input_event& event)
207 {
208 return GAME_input_event(m_handle, m_callbacks, &event);
209 }
210
211protected:
212 CB_GameLib* (*GAME_register_me)(void* handle);
213 void (*GAME_unregister_me)(void* handle, CB_GameLib* cb);
214 void (*GAME_close_game)(void* handle, CB_GameLib* cb);
215 int (*GAME_open_pixel_stream)(void* handle, CB_GameLib* cb, GAME_PIXEL_FORMAT, unsigned int, unsigned int, GAME_VIDEO_ROTATION);
216 int (*GAME_open_video_stream)(void* handle, CB_GameLib* cb, GAME_VIDEO_CODEC);
217 int (*GAME_open_pcm_stream)(void* handle, CB_GameLib* cb, GAME_PCM_FORMAT, const GAME_AUDIO_CHANNEL*);
218 int (*GAME_open_audio_stream)(void* handle, CB_GameLib* cb, GAME_AUDIO_CODEC, const GAME_AUDIO_CHANNEL*);
219 int (*GAME_add_stream_data)(void* handle, CB_GameLib* cb, GAME_STREAM_TYPE, const uint8_t*, unsigned int);
220 int (*GAME_close_stream)(void* handle, CB_GameLib* cb, GAME_STREAM_TYPE);
221 void (*GAME_enable_hardware_rendering)(void* handle, CB_GameLib* cb, const struct game_hw_info*);
222 uintptr_t (*GAME_hw_get_current_framebuffer)(void* handle, CB_GameLib* cb);
223 game_proc_address_t (*GAME_hw_get_proc_address)(void* handle, CB_GameLib* cb, const char*);
224 void (*GAME_render_frame)(void* handle, CB_GameLib* cb);
225 bool (*GAME_open_port)(void* handle, CB_GameLib* cb, unsigned int);
226 void (*GAME_close_port)(void* handle, CB_GameLib* cb, unsigned int);
227 bool (*GAME_input_event)(void* handle, CB_GameLib* cb, const game_input_event* event);
228
229private:
230 void* m_handle;
231 CB_GameLib* m_callbacks;
232 void* m_libKODI_game;
233
234 struct cb_array
235 {
236 const char* libBasePath;
237 };
238};