From f44ecaa4f27e7538ddcad66d40e543bffa2d2d86 Mon Sep 17 00:00:00 2001 From: manuel Date: Sun, 4 Jun 2017 16:57:49 +0200 Subject: sync with upstream --- .../kodi-addon-dev-kit/include/kodi/libKODI_game.h | 252 ++++++++++----------- 1 file changed, 122 insertions(+), 130 deletions(-) (limited to 'xbmc/addons/kodi-addon-dev-kit/include/kodi/libKODI_game.h') 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 @@ /* - * Copyright (C) 2014-2016 Team Kodi + * Copyright (C) 2014-2017 Team Kodi * http://kodi.tv * * This Program is free software; you can redistribute it and/or modify @@ -20,7 +20,7 @@ #pragma once #include "libXBMC_addon.h" -#include "kodi_game_callbacks.h" +#include "kodi_game_types.h" #include #include @@ -29,55 +29,17 @@ #include #endif -#ifdef _WIN32 - #define GAME_HELPER_DLL "\\library.kodi.game\\libKODI_game" ADDON_HELPER_EXT -#else - #define GAME_HELPER_DLL_NAME "libKODI_game-" ADDON_HELPER_ARCH ADDON_HELPER_EXT - #define GAME_HELPER_DLL "/library.kodi.game/" GAME_HELPER_DLL_NAME -#endif - -#define GAME_REGISTER_SYMBOL(dll, functionPtr) \ - CHelper_libKODI_game::RegisterSymbol(dll, functionPtr, #functionPtr) - class CHelper_libKODI_game { public: CHelper_libKODI_game(void) : - GAME_register_me(nullptr), - GAME_unregister_me(nullptr), - GAME_close_game(nullptr), - GAME_open_pixel_stream(nullptr), - GAME_open_video_stream(nullptr), - GAME_open_pcm_stream(nullptr), - GAME_open_audio_stream(nullptr), - GAME_add_stream_data(nullptr), - GAME_close_stream(nullptr), - GAME_enable_hardware_rendering(nullptr), - GAME_hw_get_current_framebuffer(nullptr), - GAME_hw_get_proc_address(nullptr), - GAME_render_frame(nullptr), - GAME_open_port(nullptr), - GAME_close_port(nullptr), - GAME_input_event(nullptr), m_handle(nullptr), - m_callbacks(nullptr), - m_libKODI_game(nullptr) + m_callbacks(nullptr) { } ~CHelper_libKODI_game(void) { - if (m_libKODI_game) - { - GAME_unregister_me(m_handle, m_callbacks); - dlclose(m_libKODI_game); - } - } - - template - static bool RegisterSymbol(void* dll, T& functionPtr, const char* strFunctionPtr) - { - return (functionPtr = (T)dlsym(dll, strFunctionPtr)) != NULL; } /*! @@ -87,152 +49,182 @@ public: */ bool RegisterMe(void* handle) { - m_handle = handle; + m_handle = static_cast(handle); + if (m_handle) + m_callbacks = (AddonInstance_Game*)m_handle->GameLib_RegisterMe(m_handle->addonData); + if (!m_callbacks) + fprintf(stderr, "libKODI_game-ERROR: GameLib_RegisterMe can't get callback table from Kodi !!!\n"); - std::string libBasePath; - libBasePath = ((cb_array*)m_handle)->libBasePath; - libBasePath += GAME_HELPER_DLL; - -#if defined(ANDROID) - struct stat st; - if (stat(libBasePath.c_str(),&st) != 0) - { - std::string tempbin = getenv("XBMC_ANDROID_LIBS"); - libBasePath = tempbin + "/" + GAME_HELPER_DLL_NAME; - } -#endif - - m_libKODI_game = dlopen(libBasePath.c_str(), RTLD_LAZY); - if (m_libKODI_game == NULL) - { - fprintf(stderr, "Unable to load %s\n", dlerror()); - return false; - } - - try - { - if (!GAME_REGISTER_SYMBOL(m_libKODI_game, GAME_register_me)) throw false; - if (!GAME_REGISTER_SYMBOL(m_libKODI_game, GAME_unregister_me)) throw false; - if (!GAME_REGISTER_SYMBOL(m_libKODI_game, GAME_close_game)) throw false; - if (!GAME_REGISTER_SYMBOL(m_libKODI_game, GAME_open_pixel_stream)) throw false; - if (!GAME_REGISTER_SYMBOL(m_libKODI_game, GAME_open_video_stream)) throw false; - if (!GAME_REGISTER_SYMBOL(m_libKODI_game, GAME_open_pcm_stream)) throw false; - if (!GAME_REGISTER_SYMBOL(m_libKODI_game, GAME_open_audio_stream)) throw false; - if (!GAME_REGISTER_SYMBOL(m_libKODI_game, GAME_add_stream_data)) throw false; - if (!GAME_REGISTER_SYMBOL(m_libKODI_game, GAME_close_stream)) throw false; - if (!GAME_REGISTER_SYMBOL(m_libKODI_game, GAME_enable_hardware_rendering)) throw false; - if (!GAME_REGISTER_SYMBOL(m_libKODI_game, GAME_hw_get_current_framebuffer)) throw false; - if (!GAME_REGISTER_SYMBOL(m_libKODI_game, GAME_hw_get_proc_address)) throw false; - if (!GAME_REGISTER_SYMBOL(m_libKODI_game, GAME_render_frame)) throw false; - if (!GAME_REGISTER_SYMBOL(m_libKODI_game, GAME_open_port)) throw false; - if (!GAME_REGISTER_SYMBOL(m_libKODI_game, GAME_close_port)) throw false; - if (!GAME_REGISTER_SYMBOL(m_libKODI_game, GAME_input_event)) throw false; - } - catch (const bool& bSuccess) - { - fprintf(stderr, "ERROR: Unable to assign function %s\n", dlerror()); - return bSuccess; - } - - m_callbacks = GAME_register_me(m_handle); - return m_callbacks != NULL; + return m_callbacks != nullptr; } + // --- Game callbacks -------------------------------------------------------- + + /*! + * \brief Requests the frontend to stop the current game + */ void CloseGame(void) { - return GAME_close_game(m_handle, m_callbacks); + return m_callbacks->toKodi.CloseGame(m_callbacks->toKodi.kodiInstance); } + /*! + * \brief Create a video stream for pixel data + * + * \param format The type of pixel data accepted by this stream + * \param width The frame width + * \param height The frame height + * \param rotation The rotation (counter-clockwise) of the video frames + * + * \return 0 on success or -1 if a video stream is already created + */ bool OpenPixelStream(GAME_PIXEL_FORMAT format, unsigned int width, unsigned int height, GAME_VIDEO_ROTATION rotation) { - return GAME_open_pixel_stream(m_handle, m_callbacks, format, width, height, rotation) == 0; + return m_callbacks->toKodi.OpenPixelStream(m_callbacks->toKodi.kodiInstance, format, width, height, rotation) == 0; } + /*! + * \brief Create a video stream for encoded video data + * + * \param codec The video format accepted by this stream + * + * \return 0 on success or -1 if a video stream is already created + */ bool OpenVideoStream(GAME_VIDEO_CODEC codec) { - return GAME_open_video_stream(m_handle, m_callbacks, codec) == 0; + return m_callbacks->toKodi.OpenVideoStream(m_callbacks->toKodi.kodiInstance, codec) == 0; } + /*! + * \brief Create an audio stream for PCM audio data + * + * \param format The type of audio data accepted by this stream + * \param channel_map The channel layout terminated by GAME_CH_NULL + * + * \return 0 on success or -1 if an audio stream is already created + */ bool OpenPCMStream(GAME_PCM_FORMAT format, const GAME_AUDIO_CHANNEL* channel_map) { - return GAME_open_pcm_stream(m_handle, m_callbacks, format, channel_map) == 0; + return m_callbacks->toKodi.OpenPCMStream(m_callbacks->toKodi.kodiInstance, format, channel_map) == 0; } + /*! + * \brief Create an audio stream for encoded audio data + * + * \param codec The audio format accepted by this stream + * \param channel_map The channel layout terminated by GAME_CH_NULL + * + * \return 0 on success or -1 if an audio stream is already created + */ bool OpenAudioStream(GAME_AUDIO_CODEC codec, const GAME_AUDIO_CHANNEL* channel_map) { - return GAME_open_audio_stream(m_handle, m_callbacks, codec, channel_map) == 0; + return m_callbacks->toKodi.OpenAudioStream(m_callbacks->toKodi.kodiInstance, codec, channel_map) == 0; } + /*! + * \brief Add a data packet to an audio or video stream + * + * \param stream The target stream + * \param data The data packet + * \param size The size of the data + */ void AddStreamData(GAME_STREAM_TYPE stream, const uint8_t* data, unsigned int size) { - GAME_add_stream_data(m_handle, m_callbacks, stream, data, size); + m_callbacks->toKodi.AddStreamData(m_callbacks->toKodi.kodiInstance, stream, data, size); } + /*! + * \brief Free the specified stream + * + * \param stream The stream to close + */ void CloseStream(GAME_STREAM_TYPE stream) { - GAME_close_stream(m_handle, m_callbacks, stream); + m_callbacks->toKodi.CloseStream(m_callbacks->toKodi.kodiInstance, stream); } + // -- Hardware rendering callbacks ------------------------------------------- + + /*! + * \brief Enable hardware rendering + * + * \param hw_info A struct of properties for the hardware rendering system + */ void EnableHardwareRendering(const struct game_hw_info* hw_info) { - return GAME_enable_hardware_rendering(m_handle, m_callbacks, hw_info); + return m_callbacks->toKodi.EnableHardwareRendering(m_callbacks->toKodi.kodiInstance, hw_info); } + /*! + * \brief Get the framebuffer for rendering + * + * \return The framebuffer + */ uintptr_t HwGetCurrentFramebuffer(void) { - return GAME_hw_get_current_framebuffer(m_handle, m_callbacks); + return m_callbacks->toKodi.HwGetCurrentFramebuffer(m_callbacks->toKodi.kodiInstance); } + /*! + * \brief Get a symbol from the hardware context + * + * \param symbol The symbol's name + * + * \return A function pointer for the specified symbol + */ game_proc_address_t HwGetProcAddress(const char* sym) { - return GAME_hw_get_proc_address(m_handle, m_callbacks, sym); + return m_callbacks->toKodi.HwGetProcAddress(m_callbacks->toKodi.kodiInstance, sym); } + /*! + * \brief Called when a frame is being rendered + */ void RenderFrame() { - return GAME_render_frame(m_handle, m_callbacks); + return m_callbacks->toKodi.RenderFrame(m_callbacks->toKodi.kodiInstance); } + // --- Input callbacks ------------------------------------------------------- + + /*! + * \brief Begin reporting events for the specified joystick port + * + * \param port The zero-indexed port number + * + * \return true if the port was opened, false otherwise + */ bool OpenPort(unsigned int port) { - return GAME_open_port(m_handle, m_callbacks, port); + return m_callbacks->toKodi.OpenPort(m_callbacks->toKodi.kodiInstance, port); } + /*! + * \brief End reporting events for the specified port + * + * \param port The port number passed to OpenPort() + */ void ClosePort(unsigned int port) { - return GAME_close_port(m_handle, m_callbacks, port); + return m_callbacks->toKodi.ClosePort(m_callbacks->toKodi.kodiInstance, port); } + /*! + * \brief Notify the port of an input event + * + * \param event The input event + * + * Input events can arrive for the following sources: + * - GAME_INPUT_EVENT_MOTOR + * + * \return true if the event was handled, false otherwise + */ bool InputEvent(const game_input_event& event) { - return GAME_input_event(m_handle, m_callbacks, &event); - } - -protected: - CB_GameLib* (*GAME_register_me)(void* handle); - void (*GAME_unregister_me)(void* handle, CB_GameLib* cb); - void (*GAME_close_game)(void* handle, CB_GameLib* cb); - int (*GAME_open_pixel_stream)(void* handle, CB_GameLib* cb, GAME_PIXEL_FORMAT, unsigned int, unsigned int, GAME_VIDEO_ROTATION); - int (*GAME_open_video_stream)(void* handle, CB_GameLib* cb, GAME_VIDEO_CODEC); - int (*GAME_open_pcm_stream)(void* handle, CB_GameLib* cb, GAME_PCM_FORMAT, const GAME_AUDIO_CHANNEL*); - int (*GAME_open_audio_stream)(void* handle, CB_GameLib* cb, GAME_AUDIO_CODEC, const GAME_AUDIO_CHANNEL*); - int (*GAME_add_stream_data)(void* handle, CB_GameLib* cb, GAME_STREAM_TYPE, const uint8_t*, unsigned int); - int (*GAME_close_stream)(void* handle, CB_GameLib* cb, GAME_STREAM_TYPE); - void (*GAME_enable_hardware_rendering)(void* handle, CB_GameLib* cb, const struct game_hw_info*); - uintptr_t (*GAME_hw_get_current_framebuffer)(void* handle, CB_GameLib* cb); - game_proc_address_t (*GAME_hw_get_proc_address)(void* handle, CB_GameLib* cb, const char*); - void (*GAME_render_frame)(void* handle, CB_GameLib* cb); - bool (*GAME_open_port)(void* handle, CB_GameLib* cb, unsigned int); - void (*GAME_close_port)(void* handle, CB_GameLib* cb, unsigned int); - bool (*GAME_input_event)(void* handle, CB_GameLib* cb, const game_input_event* event); + return m_callbacks->toKodi.InputEvent(m_callbacks->toKodi.kodiInstance, &event); + } private: - void* m_handle; - CB_GameLib* m_callbacks; - void* m_libKODI_game; - - struct cb_array - { - const char* libBasePath; - }; + AddonCB* m_handle; + AddonInstance_Game* m_callbacks; }; -- cgit v1.2.3