diff options
| author | manuel <manuel@mausz.at> | 2017-06-04 16:57:49 +0200 |
|---|---|---|
| committer | manuel <manuel@mausz.at> | 2017-06-04 16:57:49 +0200 |
| commit | f44ecaa4f27e7538ddcad66d40e543bffa2d2d86 (patch) | |
| tree | d8de60fc7e17edeb6f0921726c038ee54b281445 /xbmc/addons/kodi-addon-dev-kit/include/kodi/libKODI_game.h | |
| parent | ae08c8b7221bc965ac40d70e53fc8fcddb050c46 (diff) | |
| download | kodi-pvr-build-f44ecaa4f27e7538ddcad66d40e543bffa2d2d86.tar.gz kodi-pvr-build-f44ecaa4f27e7538ddcad66d40e543bffa2d2d86.tar.bz2 kodi-pvr-build-f44ecaa4f27e7538ddcad66d40e543bffa2d2d86.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.h | 252 |
1 files changed, 122 insertions, 130 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 index b5a46dd..1ca91a4 100644 --- a/xbmc/addons/kodi-addon-dev-kit/include/kodi/libKODI_game.h +++ b/xbmc/addons/kodi-addon-dev-kit/include/kodi/libKODI_game.h | |||
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | * Copyright (C) 2014-2016 Team Kodi | 2 | * Copyright (C) 2014-2017 Team Kodi |
| 3 | * http://kodi.tv | 3 | * http://kodi.tv |
| 4 | * | 4 | * |
| 5 | * This Program is free software; you can redistribute it and/or modify | 5 | * This Program is free software; you can redistribute it and/or modify |
| @@ -20,7 +20,7 @@ | |||
| 20 | #pragma once | 20 | #pragma once |
| 21 | 21 | ||
| 22 | #include "libXBMC_addon.h" | 22 | #include "libXBMC_addon.h" |
| 23 | #include "kodi_game_callbacks.h" | 23 | #include "kodi_game_types.h" |
| 24 | 24 | ||
| 25 | #include <string> | 25 | #include <string> |
| 26 | #include <stdio.h> | 26 | #include <stdio.h> |
| @@ -29,55 +29,17 @@ | |||
| 29 | #include <sys/stat.h> | 29 | #include <sys/stat.h> |
| 30 | #endif | 30 | #endif |
| 31 | 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 | |||
| 42 | class CHelper_libKODI_game | 32 | class CHelper_libKODI_game |
| 43 | { | 33 | { |
| 44 | public: | 34 | public: |
| 45 | CHelper_libKODI_game(void) : | 35 | 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), | 36 | m_handle(nullptr), |
| 63 | m_callbacks(nullptr), | 37 | m_callbacks(nullptr) |
| 64 | m_libKODI_game(nullptr) | ||
| 65 | { | 38 | { |
| 66 | } | 39 | } |
| 67 | 40 | ||
| 68 | ~CHelper_libKODI_game(void) | 41 | ~CHelper_libKODI_game(void) |
| 69 | { | 42 | { |
| 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 | } | 43 | } |
| 82 | 44 | ||
| 83 | /*! | 45 | /*! |
| @@ -87,152 +49,182 @@ public: | |||
| 87 | */ | 49 | */ |
| 88 | bool RegisterMe(void* handle) | 50 | bool RegisterMe(void* handle) |
| 89 | { | 51 | { |
| 90 | m_handle = handle; | 52 | m_handle = static_cast<AddonCB*>(handle); |
| 53 | if (m_handle) | ||
| 54 | m_callbacks = (AddonInstance_Game*)m_handle->GameLib_RegisterMe(m_handle->addonData); | ||
| 55 | if (!m_callbacks) | ||
| 56 | fprintf(stderr, "libKODI_game-ERROR: GameLib_RegisterMe can't get callback table from Kodi !!!\n"); | ||
| 91 | 57 | ||
| 92 | std::string libBasePath; | 58 | return m_callbacks != nullptr; |
| 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 | } | 59 | } |
| 140 | 60 | ||
| 61 | // --- Game callbacks -------------------------------------------------------- | ||
| 62 | |||
| 63 | /*! | ||
| 64 | * \brief Requests the frontend to stop the current game | ||
| 65 | */ | ||
| 141 | void CloseGame(void) | 66 | void CloseGame(void) |
| 142 | { | 67 | { |
| 143 | return GAME_close_game(m_handle, m_callbacks); | 68 | return m_callbacks->toKodi.CloseGame(m_callbacks->toKodi.kodiInstance); |
| 144 | } | 69 | } |
| 145 | 70 | ||
| 71 | /*! | ||
| 72 | * \brief Create a video stream for pixel data | ||
| 73 | * | ||
| 74 | * \param format The type of pixel data accepted by this stream | ||
| 75 | * \param width The frame width | ||
| 76 | * \param height The frame height | ||
| 77 | * \param rotation The rotation (counter-clockwise) of the video frames | ||
| 78 | * | ||
| 79 | * \return 0 on success or -1 if a video stream is already created | ||
| 80 | */ | ||
| 146 | bool OpenPixelStream(GAME_PIXEL_FORMAT format, unsigned int width, unsigned int height, GAME_VIDEO_ROTATION rotation) | 81 | bool OpenPixelStream(GAME_PIXEL_FORMAT format, unsigned int width, unsigned int height, GAME_VIDEO_ROTATION rotation) |
| 147 | { | 82 | { |
| 148 | return GAME_open_pixel_stream(m_handle, m_callbacks, format, width, height, rotation) == 0; | 83 | return m_callbacks->toKodi.OpenPixelStream(m_callbacks->toKodi.kodiInstance, format, width, height, rotation) == 0; |
| 149 | } | 84 | } |
| 150 | 85 | ||
| 86 | /*! | ||
| 87 | * \brief Create a video stream for encoded video data | ||
| 88 | * | ||
| 89 | * \param codec The video format accepted by this stream | ||
| 90 | * | ||
| 91 | * \return 0 on success or -1 if a video stream is already created | ||
| 92 | */ | ||
| 151 | bool OpenVideoStream(GAME_VIDEO_CODEC codec) | 93 | bool OpenVideoStream(GAME_VIDEO_CODEC codec) |
| 152 | { | 94 | { |
| 153 | return GAME_open_video_stream(m_handle, m_callbacks, codec) == 0; | 95 | return m_callbacks->toKodi.OpenVideoStream(m_callbacks->toKodi.kodiInstance, codec) == 0; |
| 154 | } | 96 | } |
| 155 | 97 | ||
| 98 | /*! | ||
| 99 | * \brief Create an audio stream for PCM audio data | ||
| 100 | * | ||
| 101 | * \param format The type of audio data accepted by this stream | ||
| 102 | * \param channel_map The channel layout terminated by GAME_CH_NULL | ||
| 103 | * | ||
| 104 | * \return 0 on success or -1 if an audio stream is already created | ||
| 105 | */ | ||
| 156 | bool OpenPCMStream(GAME_PCM_FORMAT format, const GAME_AUDIO_CHANNEL* channel_map) | 106 | bool OpenPCMStream(GAME_PCM_FORMAT format, const GAME_AUDIO_CHANNEL* channel_map) |
| 157 | { | 107 | { |
| 158 | return GAME_open_pcm_stream(m_handle, m_callbacks, format, channel_map) == 0; | 108 | return m_callbacks->toKodi.OpenPCMStream(m_callbacks->toKodi.kodiInstance, format, channel_map) == 0; |
| 159 | } | 109 | } |
| 160 | 110 | ||
| 111 | /*! | ||
| 112 | * \brief Create an audio stream for encoded audio data | ||
| 113 | * | ||
| 114 | * \param codec The audio format accepted by this stream | ||
| 115 | * \param channel_map The channel layout terminated by GAME_CH_NULL | ||
| 116 | * | ||
| 117 | * \return 0 on success or -1 if an audio stream is already created | ||
| 118 | */ | ||
| 161 | bool OpenAudioStream(GAME_AUDIO_CODEC codec, const GAME_AUDIO_CHANNEL* channel_map) | 119 | bool OpenAudioStream(GAME_AUDIO_CODEC codec, const GAME_AUDIO_CHANNEL* channel_map) |
| 162 | { | 120 | { |
| 163 | return GAME_open_audio_stream(m_handle, m_callbacks, codec, channel_map) == 0; | 121 | return m_callbacks->toKodi.OpenAudioStream(m_callbacks->toKodi.kodiInstance, codec, channel_map) == 0; |
| 164 | } | 122 | } |
| 165 | 123 | ||
| 124 | /*! | ||
| 125 | * \brief Add a data packet to an audio or video stream | ||
| 126 | * | ||
| 127 | * \param stream The target stream | ||
| 128 | * \param data The data packet | ||
| 129 | * \param size The size of the data | ||
| 130 | */ | ||
| 166 | void AddStreamData(GAME_STREAM_TYPE stream, const uint8_t* data, unsigned int size) | 131 | void AddStreamData(GAME_STREAM_TYPE stream, const uint8_t* data, unsigned int size) |
| 167 | { | 132 | { |
| 168 | GAME_add_stream_data(m_handle, m_callbacks, stream, data, size); | 133 | m_callbacks->toKodi.AddStreamData(m_callbacks->toKodi.kodiInstance, stream, data, size); |
| 169 | } | 134 | } |
| 170 | 135 | ||
| 136 | /*! | ||
| 137 | * \brief Free the specified stream | ||
| 138 | * | ||
| 139 | * \param stream The stream to close | ||
| 140 | */ | ||
| 171 | void CloseStream(GAME_STREAM_TYPE stream) | 141 | void CloseStream(GAME_STREAM_TYPE stream) |
| 172 | { | 142 | { |
| 173 | GAME_close_stream(m_handle, m_callbacks, stream); | 143 | m_callbacks->toKodi.CloseStream(m_callbacks->toKodi.kodiInstance, stream); |
| 174 | } | 144 | } |
| 175 | 145 | ||
| 146 | // -- Hardware rendering callbacks ------------------------------------------- | ||
| 147 | |||
| 148 | /*! | ||
| 149 | * \brief Enable hardware rendering | ||
| 150 | * | ||
| 151 | * \param hw_info A struct of properties for the hardware rendering system | ||
| 152 | */ | ||
| 176 | void EnableHardwareRendering(const struct game_hw_info* hw_info) | 153 | void EnableHardwareRendering(const struct game_hw_info* hw_info) |
| 177 | { | 154 | { |
| 178 | return GAME_enable_hardware_rendering(m_handle, m_callbacks, hw_info); | 155 | return m_callbacks->toKodi.EnableHardwareRendering(m_callbacks->toKodi.kodiInstance, hw_info); |
| 179 | } | 156 | } |
| 180 | 157 | ||
| 158 | /*! | ||
| 159 | * \brief Get the framebuffer for rendering | ||
| 160 | * | ||
| 161 | * \return The framebuffer | ||
| 162 | */ | ||
| 181 | uintptr_t HwGetCurrentFramebuffer(void) | 163 | uintptr_t HwGetCurrentFramebuffer(void) |
| 182 | { | 164 | { |
| 183 | return GAME_hw_get_current_framebuffer(m_handle, m_callbacks); | 165 | return m_callbacks->toKodi.HwGetCurrentFramebuffer(m_callbacks->toKodi.kodiInstance); |
| 184 | } | 166 | } |
| 185 | 167 | ||
| 168 | /*! | ||
| 169 | * \brief Get a symbol from the hardware context | ||
| 170 | * | ||
| 171 | * \param symbol The symbol's name | ||
| 172 | * | ||
| 173 | * \return A function pointer for the specified symbol | ||
| 174 | */ | ||
| 186 | game_proc_address_t HwGetProcAddress(const char* sym) | 175 | game_proc_address_t HwGetProcAddress(const char* sym) |
| 187 | { | 176 | { |
| 188 | return GAME_hw_get_proc_address(m_handle, m_callbacks, sym); | 177 | return m_callbacks->toKodi.HwGetProcAddress(m_callbacks->toKodi.kodiInstance, sym); |
| 189 | } | 178 | } |
| 190 | 179 | ||
| 180 | /*! | ||
| 181 | * \brief Called when a frame is being rendered | ||
| 182 | */ | ||
| 191 | void RenderFrame() | 183 | void RenderFrame() |
| 192 | { | 184 | { |
| 193 | return GAME_render_frame(m_handle, m_callbacks); | 185 | return m_callbacks->toKodi.RenderFrame(m_callbacks->toKodi.kodiInstance); |
| 194 | } | 186 | } |
| 195 | 187 | ||
| 188 | // --- Input callbacks ------------------------------------------------------- | ||
| 189 | |||
| 190 | /*! | ||
| 191 | * \brief Begin reporting events for the specified joystick port | ||
| 192 | * | ||
| 193 | * \param port The zero-indexed port number | ||
| 194 | * | ||
| 195 | * \return true if the port was opened, false otherwise | ||
| 196 | */ | ||
| 196 | bool OpenPort(unsigned int port) | 197 | bool OpenPort(unsigned int port) |
| 197 | { | 198 | { |
| 198 | return GAME_open_port(m_handle, m_callbacks, port); | 199 | return m_callbacks->toKodi.OpenPort(m_callbacks->toKodi.kodiInstance, port); |
| 199 | } | 200 | } |
| 200 | 201 | ||
| 202 | /*! | ||
| 203 | * \brief End reporting events for the specified port | ||
| 204 | * | ||
| 205 | * \param port The port number passed to OpenPort() | ||
| 206 | */ | ||
| 201 | void ClosePort(unsigned int port) | 207 | void ClosePort(unsigned int port) |
| 202 | { | 208 | { |
| 203 | return GAME_close_port(m_handle, m_callbacks, port); | 209 | return m_callbacks->toKodi.ClosePort(m_callbacks->toKodi.kodiInstance, port); |
| 204 | } | 210 | } |
| 205 | 211 | ||
| 212 | /*! | ||
| 213 | * \brief Notify the port of an input event | ||
| 214 | * | ||
| 215 | * \param event The input event | ||
| 216 | * | ||
| 217 | * Input events can arrive for the following sources: | ||
| 218 | * - GAME_INPUT_EVENT_MOTOR | ||
| 219 | * | ||
| 220 | * \return true if the event was handled, false otherwise | ||
| 221 | */ | ||
| 206 | bool InputEvent(const game_input_event& event) | 222 | bool InputEvent(const game_input_event& event) |
| 207 | { | 223 | { |
| 208 | return GAME_input_event(m_handle, m_callbacks, &event); | 224 | return m_callbacks->toKodi.InputEvent(m_callbacks->toKodi.kodiInstance, &event); |
| 209 | } | 225 | } |
| 210 | |||
| 211 | protected: | ||
| 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 | 226 | ||
| 229 | private: | 227 | private: |
| 230 | void* m_handle; | 228 | AddonCB* m_handle; |
| 231 | CB_GameLib* m_callbacks; | 229 | AddonInstance_Game* m_callbacks; |
| 232 | void* m_libKODI_game; | ||
| 233 | |||
| 234 | struct cb_array | ||
| 235 | { | ||
| 236 | const char* libBasePath; | ||
| 237 | }; | ||
| 238 | }; | 230 | }; |
