From 4b3b7807b7df1964778855b5c0daab4cc417bd91 Mon Sep 17 00:00:00 2001 From: manuel Date: Mon, 14 Mar 2016 14:56:55 +0100 Subject: sync with upstream --- xbmc/addons/addon-bindings.mk | 6 + .../include/kodi/kodi_peripheral_callbacks.h | 53 ++ .../include/kodi/kodi_peripheral_dll.h | 198 +++++++ .../include/kodi/kodi_peripheral_types.h | 301 ++++++++++ .../include/kodi/kodi_peripheral_utils.hpp | 657 +++++++++++++++++++++ .../include/kodi/kodi_vfs_utils.hpp | 96 +++ .../include/kodi/libKODI_audioengine.h | 5 - .../include/kodi/libKODI_inputstream.h | 3 + .../include/kodi/libKODI_peripheral.h | 140 +++++ .../include/kodi/libXBMC_addon.h | 5 + .../include/kodi/xbmc_codec_types.h | 3 + .../cores/VideoPlayer/DVDDemuxers/DVDDemuxPacket.h | 5 +- 12 files changed, 1466 insertions(+), 6 deletions(-) create mode 100644 xbmc/addons/kodi-addon-dev-kit/include/kodi/kodi_peripheral_callbacks.h create mode 100644 xbmc/addons/kodi-addon-dev-kit/include/kodi/kodi_peripheral_dll.h create mode 100644 xbmc/addons/kodi-addon-dev-kit/include/kodi/kodi_peripheral_types.h create mode 100644 xbmc/addons/kodi-addon-dev-kit/include/kodi/kodi_peripheral_utils.hpp create mode 100644 xbmc/addons/kodi-addon-dev-kit/include/kodi/kodi_vfs_utils.hpp create mode 100644 xbmc/addons/kodi-addon-dev-kit/include/kodi/libKODI_peripheral.h (limited to 'xbmc') diff --git a/xbmc/addons/addon-bindings.mk b/xbmc/addons/addon-bindings.mk index 319185a..71fe609 100644 --- a/xbmc/addons/addon-bindings.mk +++ b/xbmc/addons/addon-bindings.mk @@ -12,7 +12,12 @@ BINDINGS+=xbmc/addons/kodi-addon-dev-kit/include/kodi/xbmc_codec_types.h BINDINGS+=xbmc/addons/kodi-addon-dev-kit/include/kodi/xbmc_epg_types.h BINDINGS+=xbmc/addons/kodi-addon-dev-kit/include/kodi/kodi_inputstream_dll.h BINDINGS+=xbmc/addons/kodi-addon-dev-kit/include/kodi/kodi_inputstream_types.h +BINDINGS+=xbmc/addons/kodi-addon-dev-kit/include/kodi/kodi_peripheral_callbacks.h +BINDINGS+=xbmc/addons/kodi-addon-dev-kit/include/kodi/kodi_peripheral_dll.h +BINDINGS+=xbmc/addons/kodi-addon-dev-kit/include/kodi/kodi_peripheral_types.h +BINDINGS+=xbmc/addons/kodi-addon-dev-kit/include/kodi/kodi_peripheral_utils.hpp BINDINGS+=xbmc/addons/kodi-addon-dev-kit/include/kodi/kodi_vfs_types.h +BINDINGS+=xbmc/addons/kodi-addon-dev-kit/include/kodi/kodi_vfs_utils.hpp BINDINGS+=xbmc/addons/kodi-addon-dev-kit/include/kodi/xbmc_pvr_dll.h BINDINGS+=xbmc/addons/kodi-addon-dev-kit/include/kodi/xbmc_pvr_types.h BINDINGS+=xbmc/addons/kodi-addon-dev-kit/include/kodi/xbmc_scr_dll.h @@ -24,6 +29,7 @@ BINDINGS+=xbmc/addons/kodi-addon-dev-kit/include/kodi/libKODI_audioengine.h BINDINGS+=xbmc/addons/kodi-addon-dev-kit/include/kodi/libKODI_adsp.h BINDINGS+=xbmc/addons/kodi-addon-dev-kit/include/kodi/libKODI_guilib.h BINDINGS+=xbmc/addons/kodi-addon-dev-kit/include/kodi/libKODI_inputstream.h +BINDINGS+=xbmc/addons/kodi-addon-dev-kit/include/kodi/libKODI_peripheral.h BINDINGS+=xbmc/addons/kodi-addon-dev-kit/include/kodi/libXBMC_pvr.h BINDINGS+=xbmc/addons/kodi-addon-dev-kit/include/kodi/libXBMC_codec.h BINDINGS+=xbmc/cores/VideoPlayer/DVDDemuxers/DVDDemuxPacket.h diff --git a/xbmc/addons/kodi-addon-dev-kit/include/kodi/kodi_peripheral_callbacks.h b/xbmc/addons/kodi-addon-dev-kit/include/kodi/kodi_peripheral_callbacks.h new file mode 100644 index 0000000..720c62f --- /dev/null +++ b/xbmc/addons/kodi-addon-dev-kit/include/kodi/kodi_peripheral_callbacks.h @@ -0,0 +1,53 @@ +/* + * Copyright (C) 2014-2016 Team Kodi + * http://kodi.tv + * + * 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 this Program; see the file COPYING. If not, see + * . + * + */ +#ifndef __PERIPHERAL_CALLBACKS_H__ +#define __PERIPHERAL_CALLBACKS_H__ + +#include "kodi_peripheral_types.h" + +#ifdef __cplusplus +extern "C" +{ +#endif + +typedef struct CB_PeripheralLib +{ + /*! + * @brief Trigger a scan for peripherals + * + * The add-on calls this if a change in hardware is detected. + */ + void (*TriggerScan)(void* addonData); + + /*! + * @brief Notify the frontend that button maps have changed + * + * @param[optional] deviceName The name of the device to refresh, or empty/null for all devices + * @param[optional] controllerId The controller ID to refresh, or empty/null for all controllers + */ + void (*RefreshButtonMaps)(void* addonData, const char* deviceName, const char* controllerId); + +} CB_PeripheralLib; + +#ifdef __cplusplus +} +#endif + +#endif // __PERIPHERAL_CALLBACKS_H__ diff --git a/xbmc/addons/kodi-addon-dev-kit/include/kodi/kodi_peripheral_dll.h b/xbmc/addons/kodi-addon-dev-kit/include/kodi/kodi_peripheral_dll.h new file mode 100644 index 0000000..591afcc --- /dev/null +++ b/xbmc/addons/kodi-addon-dev-kit/include/kodi/kodi_peripheral_dll.h @@ -0,0 +1,198 @@ +/* + * Copyright (C) 2014-2016 Team Kodi + * http://kodi.tv + * + * 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 this Program; see the file COPYING. If not, see + * . + * + */ +#ifndef __PERIPHERAL_DLL_H__ +#define __PERIPHERAL_DLL_H__ + +#include "kodi_peripheral_types.h" + +#define PERIPHERAL_ADDON_JOYSTICKS // TODO + +#ifdef __cplusplus +extern "C" +{ +#endif + + /// @name Peripheral operations + ///{ + /*! + * @brief Get the PERIPHERAL_API_VERSION used to compile this peripheral add-on + * @return KODI_PERIPHERAL_API_VERSION from kodi_peripheral_types.h + * @remarks Valid implementation required + * + * Used to check if the implementation is compatible with the frontend. + */ + const char* GetPeripheralAPIVersion(void); + + /*! + * @brief Get the KODI_PERIPHERAL_MIN_API_VERSION used to compile this peripheral add-on + * @return KODI_PERIPHERAL_MIN_API_VERSION from kodi_peripheral_types.h + * @remarks Valid implementation required + * + * Used to check if the implementation is compatible with the frontend. + */ + const char* GetMinimumPeripheralAPIVersion(void); + + /*! + * @brief Get the list of features that this add-on provides + * @param pCapabilities The add-on's capabilities. + * @return PERIPHERAL_NO_ERROR if the properties were fetched successfully. + * @remarks Valid implementation required. + * + * Called by the frontend to query the add-on's capabilities and supported + * peripherals. All capabilities that the add-on supports should be set to true. + * + */ + PERIPHERAL_ERROR GetAddonCapabilities(PERIPHERAL_CAPABILITIES *pCapabilities); + + /*! + * @brief Perform a scan for joysticks + * @param peripheral_count Assigned to the number of peripherals allocated + * @param scan_results Assigned to allocated memory + * @return PERIPHERAL_NO_ERROR if successful; peripherals must be freed using + * FreeScanResults() in this case + * + * The frontend calls this when a hardware change is detected. If an add-on + * detects a hardware change, it can trigger this function using the + * TriggerScan() callback. + */ + PERIPHERAL_ERROR PerformDeviceScan(unsigned int* peripheral_count, PERIPHERAL_INFO** scan_results); + + /*! + * @brief Free the memory allocated in PerformDeviceScan() + * + * Must be called if PerformDeviceScan() returns PERIPHERAL_NO_ERROR. + * + * @param peripheral_count The number of events allocated for the events array + * @param scan_results The array of allocated peripherals + */ + void FreeScanResults(unsigned int peripheral_count, PERIPHERAL_INFO* scan_results); + + /*! + * @brief Get all events that have occurred since the last call to GetEvents() + * @return PERIPHERAL_NO_ERROR if successful; events must be freed using + * FreeEvents() in this case + */ + PERIPHERAL_ERROR GetEvents(unsigned int* event_count, PERIPHERAL_EVENT** events); + + /*! + * @brief Free the memory allocated in GetEvents() + * + * Must be called if GetEvents() returns PERIPHERAL_NO_ERROR. + * + * @param event_count The number of events allocated for the events array + * @param events The array of allocated events + */ + void FreeEvents(unsigned int event_count, PERIPHERAL_EVENT* events); + ///} + + /// @name Joystick operations + /*! + * @note #define PERIPHERAL_ADDON_JOYSTICKS before including kodi_peripheral_dll.h + * in the add-on if the add-on provides joysticks and add provides_joysticks="true" + * to the kodi.peripheral extension point node in addon.xml. + */ + ///{ +#ifdef PERIPHERAL_ADDON_JOYSTICKS + /*! + * @brief Get extended info about an attached joystick + * @param index The joystick's driver index + * @param info The container for the allocated joystick info + * @return PERIPHERAL_NO_ERROR if successful; array must be freed using + * FreeJoystickInfo() in this case + */ + PERIPHERAL_ERROR GetJoystickInfo(unsigned int index, JOYSTICK_INFO* info); + + /*! + * @brief Free the memory allocated in GetJoystickInfo() + */ + void FreeJoystickInfo(JOYSTICK_INFO* info); + + /*! + * @brief Get the features that allow translating the joystick into the controller profile + * @param joystick The device's joystick properties; unknown values may be left at their default + * @param controller_id The controller profile being requested, e.g. game.controller.default + * @param feature_count The number of features allocated for the features array + * @param features The array of allocated features + * @return PERIPHERAL_NO_ERROR if successful; array must be freed using + * FreeButtonMap() in this case + */ + PERIPHERAL_ERROR GetFeatures(const JOYSTICK_INFO* joystick, const char* controller_id, + unsigned int* feature_count, JOYSTICK_FEATURE** features); + + /*! + * @brief Free the memory allocated in GetFeatures() + * + * Must be called if GetFeatures() returns PERIPHERAL_NO_ERROR. + * + * @param feature_count The number of features allocated for the features array + * @param features The array of allocated features + */ + void FreeFeatures(unsigned int feature_count, JOYSTICK_FEATURE* features); + + /*! + * @brief Add or update joystick features + * @param joystick The device's joystick properties; unknown values may be left at their default + * @param controller_id The game controller profile being updated + * @param feature_count The number of features int the features array + * @param features The array of features + * @return PERIPHERAL_NO_ERROR if successful + */ + PERIPHERAL_ERROR MapFeatures(const JOYSTICK_INFO* joystick, const char* controller_id, + unsigned int feature_count, JOYSTICK_FEATURE* features); + + /*! + * @brief Reset the button map for the given joystick and controller profile ID + * @param joystick The device's joystick properties + * @param controller_id The game controller profile being reset + */ + void ResetButtonMap(const JOYSTICK_INFO* joystick, const char* controller_id); +#endif + ///} + + /*! + * Called by the frontend to assign the function pointers of this add-on to + * pClient. Note that get_addon() is defined here, so it will be available in + * all compiled peripheral add-ons. + */ + void __declspec(dllexport) get_addon(struct PeripheralAddon* pClient) + { + pClient->GetPeripheralAPIVersion = GetPeripheralAPIVersion; + pClient->GetMinimumPeripheralAPIVersion = GetMinimumPeripheralAPIVersion; + pClient->GetAddonCapabilities = GetAddonCapabilities; + pClient->PerformDeviceScan = PerformDeviceScan; + pClient->FreeScanResults = FreeScanResults; + pClient->GetEvents = GetEvents; + pClient->FreeEvents = FreeEvents; + +#ifdef PERIPHERAL_ADDON_JOYSTICKS + pClient->GetJoystickInfo = GetJoystickInfo; + pClient->FreeJoystickInfo = FreeJoystickInfo; + pClient->GetFeatures = GetFeatures; + pClient->FreeFeatures = FreeFeatures; + pClient->MapFeatures = MapFeatures; + pClient->ResetButtonMap = ResetButtonMap; +#endif + } + +#ifdef __cplusplus +} +#endif + +#endif // __PERIPHERAL_DLL_H__ diff --git a/xbmc/addons/kodi-addon-dev-kit/include/kodi/kodi_peripheral_types.h b/xbmc/addons/kodi-addon-dev-kit/include/kodi/kodi_peripheral_types.h new file mode 100644 index 0000000..85e2363 --- /dev/null +++ b/xbmc/addons/kodi-addon-dev-kit/include/kodi/kodi_peripheral_types.h @@ -0,0 +1,301 @@ +/* + * Copyright (C) 2014-2016 Team Kodi + * http://kodi.tv + * + * 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 this Program; see the file COPYING. If not, see + * . + * + */ +#ifndef __PERIPHERAL_TYPES_H__ +#define __PERIPHERAL_TYPES_H__ + +#ifdef TARGET_WINDOWS + #include +#else + #ifndef __cdecl + #define __cdecl + #endif + #ifndef __declspec + #define __declspec(X) + #endif +#endif + +#include + +#undef ATTRIBUTE_PACKED +#undef PRAGMA_PACK_BEGIN +#undef PRAGMA_PACK_END + +#if defined(__GNUC__) + #if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 95) + #define ATTRIBUTE_PACKED __attribute__ ((packed)) + #define PRAGMA_PACK 0 + #endif +#endif + +#if !defined(ATTRIBUTE_PACKED) + #define ATTRIBUTE_PACKED + #define PRAGMA_PACK 1 +#endif + +/* current Peripheral API version */ +#define PERIPHERAL_API_VERSION "1.0.17" + +/* min. Peripheral API version */ +#define PERIPHERAL_MIN_API_VERSION "1.0.16" + +/* indicates a joystick has no preference for port number */ +#define NO_PORT_REQUESTED (-1) + +/* joystick's driver button/hat/axis index is unknown */ +#define DRIVER_INDEX_UNKNOWN (-1) + +#ifdef __cplusplus +extern "C" +{ +#endif + + /// @name Peripheral types + ///{ + typedef enum PERIPHERAL_ERROR + { + PERIPHERAL_NO_ERROR = 0, // no error occurred + PERIPHERAL_ERROR_UNKNOWN = -1, // an unknown error occurred + PERIPHERAL_ERROR_FAILED = -2, // the command failed + PERIPHERAL_ERROR_INVALID_PARAMETERS = -3, // the parameters of the method are invalid for this operation + PERIPHERAL_ERROR_NOT_IMPLEMENTED = -4, // the method that the frontend called is not implemented + PERIPHERAL_ERROR_NOT_CONNECTED = -5, // no peripherals are connected + PERIPHERAL_ERROR_CONNECTION_FAILED = -6, // peripherals are connected, but command was interrupted + } PERIPHERAL_ERROR; + + typedef enum PERIPHERAL_TYPE + { + PERIPHERAL_TYPE_UNKNOWN, + PERIPHERAL_TYPE_JOYSTICK, + } PERIPHERAL_TYPE; + + typedef struct PERIPHERAL_INFO + { + PERIPHERAL_TYPE type; /*!< @brief type of peripheral */ + char* name; /*!< @brief name of peripheral */ + uint16_t vendor_id; /*!< @brief vendor ID of peripheral, 0x0000 if unknown */ + uint16_t product_id; /*!< @brief product ID of peripheral, 0x0000 if unknown */ + unsigned int index; /*!< @brief the order in which the add-on identified this peripheral */ + } ATTRIBUTE_PACKED PERIPHERAL_INFO; + + /*! + * @brief Properties passed to the Create() method of an add-on. + */ + typedef struct PERIPHERAL_PROPERTIES + { + const char* user_path; /*!< @brief path to the user profile */ + const char* addon_path; /*!< @brief path to this add-on */ + } ATTRIBUTE_PACKED PERIPHERAL_PROPERTIES; + + /*! + * @brief Peripheral add-on capabilities. + * If a capability is set to true, then the corresponding methods from + * kodi_peripheral_dll.h need to be implemented. + */ + typedef struct PERIPHERAL_CAPABILITIES + { + bool provides_joysticks; /*!< @brief true if the add-on provides joysticks */ + } ATTRIBUTE_PACKED PERIPHERAL_CAPABILITIES; + ///} + + /// @name Event types + ///{ + typedef enum PERIPHERAL_EVENT_TYPE + { + PERIPHERAL_EVENT_TYPE_NONE, /*!< @brief unknown event */ + PERIPHERAL_EVENT_TYPE_DRIVER_BUTTON, /*!< @brief state changed for joystick driver button */ + PERIPHERAL_EVENT_TYPE_DRIVER_HAT, /*!< @brief state changed for joystick driver hat */ + PERIPHERAL_EVENT_TYPE_DRIVER_AXIS, /*!< @brief state changed for joystick driver axis */ + } PERIPHERAL_EVENT_TYPE; + + typedef enum JOYSTICK_STATE_BUTTON + { + JOYSTICK_STATE_BUTTON_UNPRESSED = 0x0, /*!< @brief button is released */ + JOYSTICK_STATE_BUTTON_PRESSED = 0x1, /*!< @brief button is pressed */ + } JOYSTICK_STATE_BUTTON; + + typedef enum JOYSTICK_STATE_HAT + { + JOYSTICK_STATE_HAT_UNPRESSED = 0x0, /*!< @brief no directions are pressed */ + JOYSTICK_STATE_HAT_LEFT = 0x1, /*!< @brief only left is pressed */ + JOYSTICK_STATE_HAT_RIGHT = 0x2, /*!< @brief only right is pressed */ + JOYSTICK_STATE_HAT_UP = 0x4, /*!< @brief only up is pressed */ + JOYSTICK_STATE_HAT_DOWN = 0x8, /*!< @brief only down is pressed */ + JOYSTICK_STATE_HAT_LEFT_UP = JOYSTICK_STATE_HAT_LEFT | JOYSTICK_STATE_HAT_UP, + JOYSTICK_STATE_HAT_LEFT_DOWN = JOYSTICK_STATE_HAT_LEFT | JOYSTICK_STATE_HAT_DOWN, + JOYSTICK_STATE_HAT_RIGHT_UP = JOYSTICK_STATE_HAT_RIGHT | JOYSTICK_STATE_HAT_UP, + JOYSTICK_STATE_HAT_RIGHT_DOWN = JOYSTICK_STATE_HAT_RIGHT | JOYSTICK_STATE_HAT_DOWN, + } JOYSTICK_STATE_HAT; + + /*! + * @brief value in the closed interval [-1.0, 1.0] + * + * The axis state uses the XInput coordinate system: + * - Negative values signify down or to the left + * - Positive values signify up or to the right + */ + typedef float JOYSTICK_STATE_AXIS; + + typedef struct PERIPHERAL_EVENT + { + unsigned int peripheral_index; + PERIPHERAL_EVENT_TYPE type; + unsigned int driver_index; + JOYSTICK_STATE_BUTTON driver_button_state; + JOYSTICK_STATE_HAT driver_hat_state; + JOYSTICK_STATE_AXIS driver_axis_state; + } ATTRIBUTE_PACKED PERIPHERAL_EVENT; + ///} + + /// @name Joystick types + ///{ + typedef struct JOYSTICK_INFO + { + PERIPHERAL_INFO peripheral; /*!< @brief peripheral info for this joystick */ + char* provider; /*!< @brief name of the driver or interface providing the joystick */ + int requested_port; /*!< @brief requested port number (such as for 360 controllers), or NO_PORT_REQUESTED */ + unsigned int button_count; /*!< @brief number of buttons reported by the driver */ + unsigned int hat_count; /*!< @brief number of hats reported by the driver */ + unsigned int axis_count; /*!< @brief number of axes reported by the driver */ + } ATTRIBUTE_PACKED JOYSTICK_INFO; + + typedef enum JOYSTICK_DRIVER_PRIMITIVE_TYPE + { + JOYSTICK_DRIVER_PRIMITIVE_TYPE_UNKNOWN, + JOYSTICK_DRIVER_PRIMITIVE_TYPE_BUTTON, + JOYSTICK_DRIVER_PRIMITIVE_TYPE_HAT_DIRECTION, + JOYSTICK_DRIVER_PRIMITIVE_TYPE_SEMIAXIS, + } JOYSTICK_DRIVER_PRIMITIVE_TYPE; + + typedef struct JOYSTICK_DRIVER_BUTTON + { + int index; + } ATTRIBUTE_PACKED JOYSTICK_DRIVER_BUTTON; + + typedef enum JOYSTICK_DRIVER_HAT_DIRECTION + { + JOYSTICK_DRIVER_HAT_UNKNOWN, + JOYSTICK_DRIVER_HAT_LEFT, + JOYSTICK_DRIVER_HAT_RIGHT, + JOYSTICK_DRIVER_HAT_UP, + JOYSTICK_DRIVER_HAT_DOWN, + } JOYSTICK_DRIVER_HAT_DIRECTION; + + typedef struct JOYSTICK_DRIVER_HAT + { + int index; + JOYSTICK_DRIVER_HAT_DIRECTION direction; + } ATTRIBUTE_PACKED JOYSTICK_DRIVER_HAT; + + typedef enum JOYSTICK_DRIVER_SEMIAXIS_DIRECTION + { + JOYSTICK_DRIVER_SEMIAXIS_NEGATIVE = -1, /*!< @brief negative half of the axis */ + JOYSTICK_DRIVER_SEMIAXIS_UNKNOWN = 0, /*!< @brief unknown direction */ + JOYSTICK_DRIVER_SEMIAXIS_POSITIVE = 1, /*!< @brief positive half of the axis */ + } JOYSTICK_DRIVER_SEMIAXIS_DIRECTION; + + typedef struct JOYSTICK_DRIVER_SEMIAXIS + { + int index; + JOYSTICK_DRIVER_SEMIAXIS_DIRECTION direction; + } ATTRIBUTE_PACKED JOYSTICK_DRIVER_SEMIAXIS; + + typedef struct JOYSTICK_DRIVER_PRIMITIVE + { + JOYSTICK_DRIVER_PRIMITIVE_TYPE type; + union + { + struct JOYSTICK_DRIVER_BUTTON button; + struct JOYSTICK_DRIVER_HAT hat; + struct JOYSTICK_DRIVER_SEMIAXIS semiaxis; + }; + } ATTRIBUTE_PACKED JOYSTICK_DRIVER_PRIMITIVE; + + typedef enum JOYSTICK_FEATURE_TYPE + { + JOYSTICK_FEATURE_TYPE_UNKNOWN, + JOYSTICK_FEATURE_TYPE_SCALAR, + JOYSTICK_FEATURE_TYPE_ANALOG_STICK, + JOYSTICK_FEATURE_TYPE_ACCELEROMETER, + } JOYSTICK_FEATURE_TYPE; + + typedef struct JOYSTICK_FEATURE_SCALAR + { + struct JOYSTICK_DRIVER_PRIMITIVE primitive; + } ATTRIBUTE_PACKED JOYSTICK_FEATURE_SCALAR; + + typedef struct JOYSTICK_FEATURE_ANALOG_STICK + { + struct JOYSTICK_DRIVER_PRIMITIVE up; + struct JOYSTICK_DRIVER_PRIMITIVE down; + struct JOYSTICK_DRIVER_PRIMITIVE right; + struct JOYSTICK_DRIVER_PRIMITIVE left; + } ATTRIBUTE_PACKED JOYSTICK_FEATURE_ANALOG_STICK; + + typedef struct JOYSTICK_FEATURE_ACCELEROMETER + { + struct JOYSTICK_DRIVER_PRIMITIVE positive_x; + struct JOYSTICK_DRIVER_PRIMITIVE positive_y; + struct JOYSTICK_DRIVER_PRIMITIVE positive_z; + } ATTRIBUTE_PACKED JOYSTICK_FEATURE_ACCELEROMETER; + + typedef struct JOYSTICK_FEATURE + { + char* name; + JOYSTICK_FEATURE_TYPE type; + union + { + struct JOYSTICK_FEATURE_SCALAR scalar; + struct JOYSTICK_FEATURE_ANALOG_STICK analog_stick; + struct JOYSTICK_FEATURE_ACCELEROMETER accelerometer; + }; + } ATTRIBUTE_PACKED JOYSTICK_FEATURE; + ///} + + // TODO: Mouse, light gun, multitouch + + /*! + * @brief Structure to transfer the methods from kodi_peripheral_dll.h to the frontend + */ + typedef struct PeripheralAddon + { + const char* (__cdecl* GetPeripheralAPIVersion)(void); + const char* (__cdecl* GetMinimumPeripheralAPIVersion)(void); + PERIPHERAL_ERROR (__cdecl* GetAddonCapabilities)(PERIPHERAL_CAPABILITIES*); + PERIPHERAL_ERROR (__cdecl* PerformDeviceScan)(unsigned int*, PERIPHERAL_INFO**); + void (__cdecl* FreeScanResults)(unsigned int, PERIPHERAL_INFO*); + PERIPHERAL_ERROR (__cdecl* GetEvents)(unsigned int*, PERIPHERAL_EVENT**); + void (__cdecl* FreeEvents)(unsigned int, PERIPHERAL_EVENT*); + + /// @name Joystick operations + ///{ + PERIPHERAL_ERROR (__cdecl* GetJoystickInfo)(unsigned int, JOYSTICK_INFO*); + void (__cdecl* FreeJoystickInfo)(JOYSTICK_INFO*); + PERIPHERAL_ERROR (__cdecl* GetFeatures)(const JOYSTICK_INFO*, const char*, unsigned int*, JOYSTICK_FEATURE**); + void (__cdecl* FreeFeatures)(unsigned int, JOYSTICK_FEATURE*); + PERIPHERAL_ERROR (__cdecl* MapFeatures)(const JOYSTICK_INFO*, const char*, unsigned int, JOYSTICK_FEATURE*); + void (__cdecl* ResetButtonMap)(const JOYSTICK_INFO*, const char*); + ///} + } PeripheralAddon; + +#ifdef __cplusplus +} +#endif + +#endif // __PERIPHERAL_TYPES_H__ diff --git a/xbmc/addons/kodi-addon-dev-kit/include/kodi/kodi_peripheral_utils.hpp b/xbmc/addons/kodi-addon-dev-kit/include/kodi/kodi_peripheral_utils.hpp new file mode 100644 index 0000000..4423cb4 --- /dev/null +++ b/xbmc/addons/kodi-addon-dev-kit/include/kodi/kodi_peripheral_utils.hpp @@ -0,0 +1,657 @@ +/* + * Copyright (C) 2014-2016 Team Kodi + * http://kodi.tv + * + * 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 this Program; see the file COPYING. If not, see + * . + * + */ +#pragma once + +#include "kodi_peripheral_types.h" + +#include +#include +#include +#include + +#define PERIPHERAL_SAFE_DELETE(x) do { delete (x); (x) = NULL; } while (0) +#define PERIPHERAL_SAFE_DELETE_ARRAY(x) do { delete[] (x); (x) = NULL; } while (0) + +namespace ADDON +{ + /*! + * Utility class to manipulate arrays of peripheral types. + */ + template + class PeripheralVector + { + public: + static void ToStructs(const std::vector& vecObjects, THE_STRUCT** pStructs) + { + if (!pStructs) + return; + + if (vecObjects.empty()) + { + *pStructs = NULL; + } + else + { + (*pStructs) = new THE_STRUCT[vecObjects.size()]; + for (unsigned int i = 0; i < vecObjects.size(); i++) + vecObjects.at(i).ToStruct((*pStructs)[i]); + } + } + + static void ToStructs(const std::vector& vecObjects, THE_STRUCT** pStructs) + { + if (!pStructs) + return; + + if (vecObjects.empty()) + { + *pStructs = NULL; + } + else + { + *pStructs = new THE_STRUCT[vecObjects.size()]; + for (unsigned int i = 0; i < vecObjects.size(); i++) + vecObjects.at(i)->ToStruct((*pStructs)[i]); + } + } + + static void FreeStructs(unsigned int structCount, THE_STRUCT* structs) + { + if (structs) + { + for (unsigned int i = 0; i < structCount; i++) + THE_CLASS::FreeStruct(structs[i]); + } + PERIPHERAL_SAFE_DELETE_ARRAY(structs); + } + }; + + /*! + * ADDON::Peripheral + * + * Wrapper class providing peripheral information. Classes can extend + * Peripheral to inherit peripheral properties. + */ + class Peripheral + { + public: + Peripheral(PERIPHERAL_TYPE type = PERIPHERAL_TYPE_UNKNOWN, const std::string& strName = "") : + m_type(type), + m_strName(strName), + m_vendorId(0), + m_productId(0), + m_index(0) + { + } + + Peripheral(const PERIPHERAL_INFO& info) : + m_type(info.type), + m_strName(info.name ? info.name : ""), + m_vendorId(info.vendor_id), + m_productId(info.product_id), + m_index(info.index) + { + } + + virtual ~Peripheral(void) { } + + PERIPHERAL_TYPE Type(void) const { return m_type; } + const std::string& Name(void) const { return m_strName; } + uint16_t VendorID(void) const { return m_vendorId; } + uint16_t ProductID(void) const { return m_productId; } + unsigned int Index(void) const { return m_index; } + + // Derived property: VID and PID are 0x0000 if unknown + bool IsVidPidKnown(void) const { return m_vendorId != 0 || m_productId != 0; } + + void SetType(PERIPHERAL_TYPE type) { m_type = type; } + void SetName(const std::string& strName) { m_strName = strName; } + void SetVendorID(uint16_t vendorId) { m_vendorId = vendorId; } + void SetProductID(uint16_t productId) { m_productId = productId; } + void SetIndex(unsigned int index) { m_index = index; } + + void ToStruct(PERIPHERAL_INFO& info) const + { + info.type = m_type; + info.name = new char[m_strName.size() + 1]; + info.vendor_id = m_vendorId; + info.product_id = m_productId; + info.index = m_index; + + std::strcpy(info.name, m_strName.c_str()); + } + + static void FreeStruct(PERIPHERAL_INFO& info) + { + PERIPHERAL_SAFE_DELETE_ARRAY(info.name); + } + + private: + PERIPHERAL_TYPE m_type; + std::string m_strName; + uint16_t m_vendorId; + uint16_t m_productId; + unsigned int m_index; + }; + + typedef PeripheralVector Peripherals; + + /*! + * ADDON::PeripheralEvent + * + * Wrapper class for peripheral events. + */ + class PeripheralEvent + { + public: + PeripheralEvent(void) : + m_event() + { + } + + PeripheralEvent(unsigned int peripheralIndex, unsigned int buttonIndex, JOYSTICK_STATE_BUTTON state) : + m_event() + { + SetType(PERIPHERAL_EVENT_TYPE_DRIVER_BUTTON); + SetPeripheralIndex(peripheralIndex); + SetDriverIndex(buttonIndex); + SetButtonState(state); + } + + PeripheralEvent(unsigned int peripheralIndex, unsigned int hatIndex, JOYSTICK_STATE_HAT state) : + m_event() + { + SetType(PERIPHERAL_EVENT_TYPE_DRIVER_HAT); + SetPeripheralIndex(peripheralIndex); + SetDriverIndex(hatIndex); + SetHatState(state); + } + + PeripheralEvent(unsigned int peripheralIndex, unsigned int axisIndex, JOYSTICK_STATE_AXIS state) : + m_event() + { + SetType(PERIPHERAL_EVENT_TYPE_DRIVER_AXIS); + SetPeripheralIndex(peripheralIndex); + SetDriverIndex(axisIndex); + SetAxisState(state); + } + + PeripheralEvent(const PERIPHERAL_EVENT& event) : + m_event(event) + { + } + + PERIPHERAL_EVENT_TYPE Type(void) const { return m_event.type; } + unsigned int PeripheralIndex(void) const { return m_event.peripheral_index; } + unsigned int DriverIndex(void) const { return m_event.driver_index; } + JOYSTICK_STATE_BUTTON ButtonState(void) const { return m_event.driver_button_state; } + JOYSTICK_STATE_HAT HatState(void) const { return m_event.driver_hat_state; } + JOYSTICK_STATE_AXIS AxisState(void) const { return m_event.driver_axis_state; } + + void SetType(PERIPHERAL_EVENT_TYPE type) { m_event.type = type; } + void SetPeripheralIndex(unsigned int index) { m_event.peripheral_index = index; } + void SetDriverIndex(unsigned int index) { m_event.driver_index = index; } + void SetButtonState(JOYSTICK_STATE_BUTTON state) { m_event.driver_button_state = state; } + void SetHatState(JOYSTICK_STATE_HAT state) { m_event.driver_hat_state = state; } + void SetAxisState(JOYSTICK_STATE_AXIS state) { m_event.driver_axis_state = state; } + + void ToStruct(PERIPHERAL_EVENT& event) const + { + event = m_event; + } + + static void FreeStruct(PERIPHERAL_EVENT& event) + { + (void)event; + } + + private: + PERIPHERAL_EVENT m_event; + }; + + typedef PeripheralVector PeripheralEvents; + + /*! + * ADDON::Joystick + * + * Wrapper class providing additional joystick information not provided by + * ADDON::Peripheral. + */ + class Joystick : public Peripheral + { + public: + Joystick(const std::string& provider = "", const std::string& strName = "") : + Peripheral(PERIPHERAL_TYPE_JOYSTICK, strName), + m_provider(provider), + m_requestedPort(NO_PORT_REQUESTED), + m_buttonCount(0), + m_hatCount(0), + m_axisCount(0) + { + } + + Joystick(const Joystick& other) + { + *this = other; + } + + Joystick(const JOYSTICK_INFO& info) : + Peripheral(info.peripheral), + m_provider(info.provider ? info.provider : ""), + m_requestedPort(info.requested_port), + m_buttonCount(info.button_count), + m_hatCount(info.hat_count), + m_axisCount(info.axis_count) + { + } + + virtual ~Joystick(void) { } + + Joystick& operator=(const Joystick& rhs) + { + if (this != &rhs) + { + Peripheral::operator=(rhs); + + m_provider = rhs.m_provider; + m_requestedPort = rhs.m_requestedPort; + m_buttonCount = rhs.m_buttonCount; + m_hatCount = rhs.m_hatCount; + m_axisCount = rhs.m_axisCount; + } + return *this; + } + + const std::string& Provider(void) const { return m_provider; } + int RequestedPort(void) const { return m_requestedPort; } + unsigned int ButtonCount(void) const { return m_buttonCount; } + unsigned int HatCount(void) const { return m_hatCount; } + unsigned int AxisCount(void) const { return m_axisCount; } + + // Derived property: Counts are unknown if all are zero + bool AreElementCountsKnown(void) const { return m_buttonCount != 0 || m_hatCount != 0 || m_axisCount != 0; } + + void SetProvider(const std::string& provider) { m_provider = provider; } + void SetRequestedPort(int requestedPort) { m_requestedPort = requestedPort; } + void SetButtonCount(unsigned int buttonCount) { m_buttonCount = buttonCount; } + void SetHatCount(unsigned int hatCount) { m_hatCount = hatCount; } + void SetAxisCount(unsigned int axisCount) { m_axisCount = axisCount; } + + void ToStruct(JOYSTICK_INFO& info) const + { + Peripheral::ToStruct(info.peripheral); + + info.provider = new char[m_provider.size() + 1]; + info.requested_port = m_requestedPort; + info.button_count = m_buttonCount; + info.hat_count = m_hatCount; + info.axis_count = m_axisCount; + + std::strcpy(info.provider, m_provider.c_str()); + } + + static void FreeStruct(JOYSTICK_INFO& info) + { + Peripheral::FreeStruct(info.peripheral); + + PERIPHERAL_SAFE_DELETE_ARRAY(info.provider); + } + + private: + std::string m_provider; + int m_requestedPort; + unsigned int m_buttonCount; + unsigned int m_hatCount; + unsigned int m_axisCount; + }; + + typedef PeripheralVector Joysticks; + + /*! + * ADDON::DriverPrimitive + * + * Base class for joystick driver primitives. A driver primitive can be: + * + * 1) a button + * 2) a hat direction + * 3) a semiaxis (either the positive or negative half of an axis) + * + * The type determines the fields in use: + * + * Button: + * - driver index + * + * Hat direction: + * - driver index + * - hat direction + * + * Semiaxis: + * - driver index + * - semiaxis direction + */ + class DriverPrimitive + { + public: + /*! + * \brief Construct an invalid driver primitive + */ + DriverPrimitive(void) : + m_type(JOYSTICK_DRIVER_PRIMITIVE_TYPE_UNKNOWN), + m_driverIndex(0), + m_hatDirection(JOYSTICK_DRIVER_HAT_UNKNOWN), + m_semiAxisDirection(JOYSTICK_DRIVER_SEMIAXIS_UNKNOWN) + { + } + + /*! + * \brief Construct a driver primitive representing a button + */ + DriverPrimitive(unsigned int buttonIndex) : + m_type(JOYSTICK_DRIVER_PRIMITIVE_TYPE_BUTTON), + m_driverIndex(buttonIndex), + m_hatDirection(JOYSTICK_DRIVER_HAT_UNKNOWN), + m_semiAxisDirection(JOYSTICK_DRIVER_SEMIAXIS_UNKNOWN) + { + } + + /*! + * \brief Construct a driver primitive representing one of the four direction + * arrows on a dpad + */ + DriverPrimitive(unsigned int hatIndex, JOYSTICK_DRIVER_HAT_DIRECTION direction) : + m_type(JOYSTICK_DRIVER_PRIMITIVE_TYPE_HAT_DIRECTION), + m_driverIndex(hatIndex), + m_hatDirection(direction), + m_semiAxisDirection(JOYSTICK_DRIVER_SEMIAXIS_UNKNOWN) + { + } + + /*! + * \brief Construct a driver primitive representing the positive or negative + * half of an axis + */ + DriverPrimitive(unsigned int axisIndex, JOYSTICK_DRIVER_SEMIAXIS_DIRECTION direction) : + m_type(JOYSTICK_DRIVER_PRIMITIVE_TYPE_SEMIAXIS), + m_driverIndex(axisIndex), + m_hatDirection(JOYSTICK_DRIVER_HAT_UNKNOWN), + m_semiAxisDirection(direction) + { + } + + DriverPrimitive(const JOYSTICK_DRIVER_PRIMITIVE& primitive) : + m_type(primitive.type), + m_driverIndex(0), + m_hatDirection(JOYSTICK_DRIVER_HAT_UNKNOWN), + m_semiAxisDirection(JOYSTICK_DRIVER_SEMIAXIS_UNKNOWN) + { + switch (m_type) + { + case JOYSTICK_DRIVER_PRIMITIVE_TYPE_BUTTON: + { + m_driverIndex = primitive.button.index; + break; + } + case JOYSTICK_DRIVER_PRIMITIVE_TYPE_HAT_DIRECTION: + { + m_driverIndex = primitive.hat.index; + m_hatDirection = primitive.hat.direction; + break; + } + case JOYSTICK_DRIVER_PRIMITIVE_TYPE_SEMIAXIS: + { + m_driverIndex = primitive.semiaxis.index; + m_semiAxisDirection = primitive.semiaxis.direction; + break; + } + default: + break; + } + } + + JOYSTICK_DRIVER_PRIMITIVE_TYPE Type(void) const { return m_type; } + unsigned int DriverIndex(void) const { return m_driverIndex; } + JOYSTICK_DRIVER_HAT_DIRECTION HatDirection(void) const { return m_hatDirection; } + JOYSTICK_DRIVER_SEMIAXIS_DIRECTION SemiAxisDirection(void) const { return m_semiAxisDirection; } + + bool operator==(const DriverPrimitive& other) const + { + if (m_type == other.m_type) + { + switch (m_type) + { + case JOYSTICK_DRIVER_PRIMITIVE_TYPE_BUTTON: + { + return m_driverIndex == other.m_driverIndex; + } + case JOYSTICK_DRIVER_PRIMITIVE_TYPE_HAT_DIRECTION: + { + return m_driverIndex == other.m_driverIndex && + m_hatDirection == other.m_hatDirection; + } + case JOYSTICK_DRIVER_PRIMITIVE_TYPE_SEMIAXIS: + { + return m_driverIndex == other.m_driverIndex && + m_semiAxisDirection == other.m_semiAxisDirection; + } + default: + break; + } + } + return false; + } + + void ToStruct(JOYSTICK_DRIVER_PRIMITIVE& driver_primitive) const + { + driver_primitive.type = m_type; + switch (m_type) + { + case JOYSTICK_DRIVER_PRIMITIVE_TYPE_BUTTON: + { + driver_primitive.button.index = m_driverIndex; + break; + } + case JOYSTICK_DRIVER_PRIMITIVE_TYPE_HAT_DIRECTION: + { + driver_primitive.hat.index = m_driverIndex; + driver_primitive.hat.direction = m_hatDirection; + break; + } + case JOYSTICK_DRIVER_PRIMITIVE_TYPE_SEMIAXIS: + { + driver_primitive.semiaxis.index = m_driverIndex; + driver_primitive.semiaxis.direction = m_semiAxisDirection; + break; + } + default: + break; + } + } + + private: + JOYSTICK_DRIVER_PRIMITIVE_TYPE m_type; + unsigned int m_driverIndex; + JOYSTICK_DRIVER_HAT_DIRECTION m_hatDirection; + JOYSTICK_DRIVER_SEMIAXIS_DIRECTION m_semiAxisDirection; + }; + + /*! + * ADDON::JoystickFeature + * + * Class for joystick features. A feature can be: + * + * 1) scalar[1] + * 2) analog stick + * 3) accelerometer + * + * [1] All three driver primitives (buttons, hats and axes) have a state that + * can be represented using a single scalar value. For this reason, + * features that map to a single primitive are called "scalar features". + * + * Features can be mapped to a variable number of driver primitives. The names + * of the primitives for each feature are: + * + * Scalar feature: + * - primitive + * + * Analog stick: + * - up + * - down + * - right + * - left + * + * Accelerometer: + * - positive X + * - positive Y + * - positive Z + */ + class JoystickFeature + { + public: + const unsigned int MAX_PRIMITIVES = 4; + + JoystickFeature(void) : + m_type(JOYSTICK_FEATURE_TYPE_UNKNOWN) + { + m_primitives.resize(MAX_PRIMITIVES); + } + + JoystickFeature(const std::string& name, JOYSTICK_FEATURE_TYPE type) : + m_name(name), + m_type(type) + { + m_primitives.resize(MAX_PRIMITIVES); + } + + JoystickFeature(const JoystickFeature& other) + { + *this = other; + } + + JoystickFeature(const JOYSTICK_FEATURE& feature) : + m_name(feature.name ? feature.name : ""), + m_type(feature.type) + { + m_primitives.resize(MAX_PRIMITIVES); + switch (m_type) + { + case JOYSTICK_FEATURE_TYPE_SCALAR: + SetPrimitive(feature.scalar.primitive); + break; + case JOYSTICK_FEATURE_TYPE_ANALOG_STICK: + SetUp(feature.analog_stick.up); + SetDown(feature.analog_stick.down); + SetRight(feature.analog_stick.right); + SetLeft(feature.analog_stick.left); + break; + case JOYSTICK_FEATURE_TYPE_ACCELEROMETER: + SetPositiveX(feature.accelerometer.positive_x); + SetPositiveY(feature.accelerometer.positive_y); + SetPositiveZ(feature.accelerometer.positive_z); + break; + default: + break; + } + } + + JoystickFeature& operator=(const JoystickFeature& rhs) + { + if (this != &rhs) + { + m_name = rhs.m_name; + m_type = rhs.m_type; + m_primitives = rhs.m_primitives; + } + return *this; + } + + bool operator==(const JoystickFeature& other) const + { + return m_name == other.m_name && + m_type == other.m_type && + m_primitives == other.m_primitives; + } + + const std::string& Name(void) const { return m_name; } + JOYSTICK_FEATURE_TYPE Type(void) const { return m_type; } + + void SetName(const std::string& name) { m_name = name; } + void SetType(JOYSTICK_FEATURE_TYPE type) { m_type = type; } + + // Scalar methods + const DriverPrimitive& Primitive(void) const { return m_primitives[0]; } + void SetPrimitive(const DriverPrimitive& primitive) { m_primitives[0] = primitive; } + + // Analog stick methods + const DriverPrimitive& Up(void) const { return m_primitives[0]; } + const DriverPrimitive& Down(void) const { return m_primitives[1]; } + const DriverPrimitive& Right(void) const { return m_primitives[2]; } + const DriverPrimitive& Left(void) const { return m_primitives[3]; } + void SetUp(const DriverPrimitive& primitive) { m_primitives[0] = primitive; } + void SetDown(const DriverPrimitive& primitive) { m_primitives[1] = primitive; } + void SetRight(const DriverPrimitive& primitive) { m_primitives[2] = primitive; } + void SetLeft(const DriverPrimitive& primitive) { m_primitives[3] = primitive; } + + // Accelerometer methods + const DriverPrimitive& PositiveX(void) const { return m_primitives[0]; } + const DriverPrimitive& PositiveY(void) const { return m_primitives[1]; } + const DriverPrimitive& PositiveZ(void) const { return m_primitives[2]; } + void SetPositiveX(const DriverPrimitive& primitive) { m_primitives[0] = primitive; } + void SetPositiveY(const DriverPrimitive& primitive) { m_primitives[1] = primitive; } + void SetPositiveZ(const DriverPrimitive& primitive) { m_primitives[2] = primitive; } + + void ToStruct(JOYSTICK_FEATURE& feature) const + { + feature.name = new char[m_name.length() + 1]; + feature.type = m_type; + switch (m_type) + { + case JOYSTICK_FEATURE_TYPE_SCALAR: + Primitive().ToStruct(feature.scalar.primitive); + break; + case JOYSTICK_FEATURE_TYPE_ANALOG_STICK: + Up().ToStruct(feature.analog_stick.up); + Down().ToStruct(feature.analog_stick.down); + Right().ToStruct(feature.analog_stick.right); + Left().ToStruct(feature.analog_stick.left); + break; + case JOYSTICK_FEATURE_TYPE_ACCELEROMETER: + PositiveX().ToStruct(feature.accelerometer.positive_x); + PositiveY().ToStruct(feature.accelerometer.positive_y); + PositiveZ().ToStruct(feature.accelerometer.positive_z); + break; + default: + break; + } + std::strcpy(feature.name, m_name.c_str()); + } + + static void FreeStruct(JOYSTICK_FEATURE& feature) + { + PERIPHERAL_SAFE_DELETE_ARRAY(feature.name); + } + + private: + std::string m_name; + JOYSTICK_FEATURE_TYPE m_type; + std::vector m_primitives; + }; + + typedef PeripheralVector JoystickFeatures; +} diff --git a/xbmc/addons/kodi-addon-dev-kit/include/kodi/kodi_vfs_utils.hpp b/xbmc/addons/kodi-addon-dev-kit/include/kodi/kodi_vfs_utils.hpp new file mode 100644 index 0000000..cebce7e --- /dev/null +++ b/xbmc/addons/kodi-addon-dev-kit/include/kodi/kodi_vfs_utils.hpp @@ -0,0 +1,96 @@ +/* + * Copyright (C) 2015-2016 Team Kodi + * http://kodi.tv + * + * 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 this Program; see the file COPYING. If not, see + * . + * + */ +#pragma once + +/*! + * @file kodi_vfs_utils.hpp - C++ wrappers for Kodi's VFS operations + */ + +#include "libXBMC_addon.h" +#include "kodi_vfs_types.h" + +#include +#include +#include + +namespace ADDON +{ + class CVFSDirEntry + { + public: + CVFSDirEntry(const std::string& label = "", + const std::string& path = "", + bool bFolder = false, + int64_t size = -1) : + m_label(label), + m_path(path), + m_bFolder(bFolder), + m_size(size) + { + } + + CVFSDirEntry(const VFSDirEntry& dirEntry) : + m_label(dirEntry.label ? dirEntry.label : ""), + m_path(dirEntry.path ? dirEntry.path : ""), + m_bFolder(dirEntry.folder), + m_size(dirEntry.size) + { + } + + const std::string& Label(void) const { return m_label; } + const std::string& Path(void) const { return m_path; } + bool IsFolder(void) const { return m_bFolder; } + int64_t Size(void) const { return m_size; } + + void SetLabel(const std::string& label) { m_label = label; } + void SetPath(const std::string& path) { m_path = path; } + void SetFolder(bool bFolder) { m_bFolder = bFolder; } + void SetSize(int64_t size) { m_size = size; } + + private: + std::string m_label; + std::string m_path; + bool m_bFolder; + int64_t m_size; + }; + + class VFSUtils + { + public: + static bool GetDirectory(ADDON::CHelper_libXBMC_addon* frontend, + const std::string& path, + const std::string& mask, + std::vector& items) + { + VFSDirEntry* dir_list = nullptr; + unsigned int num_items = 0; + if (frontend->GetDirectory(path.c_str(), mask.c_str(), &dir_list, &num_items)) + { + for (unsigned int i = 0; i < num_items; i++) + items.push_back(CVFSDirEntry(dir_list[i])); + + frontend->FreeDirectory(dir_list, num_items); + + return true; + } + return false; + } + }; +} diff --git a/xbmc/addons/kodi-addon-dev-kit/include/kodi/libKODI_audioengine.h b/xbmc/addons/kodi-addon-dev-kit/include/kodi/libKODI_audioengine.h index f541637..be3b93d 100644 --- a/xbmc/addons/kodi-addon-dev-kit/include/kodi/libKODI_audioengine.h +++ b/xbmc/addons/kodi-addon-dev-kit/include/kodi/libKODI_audioengine.h @@ -311,11 +311,6 @@ public: * @param ratio the new sample rate ratio, calculated by ((double)desiredRate / (double)GetSampleRate()) */ virtual void SetResampleRatio(double Ratio); - - /** - * Sginal a clock change - */ - virtual void Discontinuity(); private: AEStreamHandle *m_StreamHandle; diff --git a/xbmc/addons/kodi-addon-dev-kit/include/kodi/libKODI_inputstream.h b/xbmc/addons/kodi-addon-dev-kit/include/kodi/libKODI_inputstream.h index e0dc881..7fe1725 100644 --- a/xbmc/addons/kodi-addon-dev-kit/include/kodi/libKODI_inputstream.h +++ b/xbmc/addons/kodi-addon-dev-kit/include/kodi/libKODI_inputstream.h @@ -40,6 +40,9 @@ #define INPUTSTREAM_HELPER_DLL "/library.kodi.inputstream/" INPUTSTREAM_HELPER_DLL_NAME #endif +/* current input stream API version */ +#define KODI_INPUTSTREAM_API_VERSION "1.0.0" + class CHelper_libKODI_inputstream { public: diff --git a/xbmc/addons/kodi-addon-dev-kit/include/kodi/libKODI_peripheral.h b/xbmc/addons/kodi-addon-dev-kit/include/kodi/libKODI_peripheral.h new file mode 100644 index 0000000..9f3f986 --- /dev/null +++ b/xbmc/addons/kodi-addon-dev-kit/include/kodi/libKODI_peripheral.h @@ -0,0 +1,140 @@ +/* + * Copyright (C) 2014-2016 Team Kodi + * http://kodi.tv + * + * 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 this Program; see the file COPYING. If not, see + * . + * + */ +#pragma once + +#include "libXBMC_addon.h" +#include "kodi_peripheral_callbacks.h" + +#include +#include + +#if defined(ANDROID) + #include +#endif + +#ifdef _WIN32 + #define PERIPHERAL_HELPER_DLL "\\library.kodi.peripheral\\libKODI_peripheral" ADDON_HELPER_EXT +#else + #define PERIPHERAL_HELPER_DLL_NAME "libKODI_peripheral-" ADDON_HELPER_ARCH ADDON_HELPER_EXT + #define PERIPHERAL_HELPER_DLL "/library.kodi.peripheral/" PERIPHERAL_HELPER_DLL_NAME +#endif + +#define PERIPHERAL_REGISTER_SYMBOL(dll, functionPtr) \ + CHelper_libKODI_peripheral::RegisterSymbol(dll, functionPtr, #functionPtr) + +namespace ADDON +{ + +class CHelper_libKODI_peripheral +{ +public: + CHelper_libKODI_peripheral(void) + { + m_handle = NULL; + m_callbacks = NULL; + m_libKODI_peripheral = NULL; + } + + ~CHelper_libKODI_peripheral(void) + { + if (m_libKODI_peripheral) + { + PERIPHERAL_unregister_me(m_handle, m_callbacks); + dlclose(m_libKODI_peripheral); + } + } + + template + static bool RegisterSymbol(void* dll, T& functionPtr, const char* strFunctionPtr) + { + if ((functionPtr = (T)dlsym(dll, strFunctionPtr)) == NULL) + { + fprintf(stderr, "ERROR: Unable to assign function %s: %s\n", strFunctionPtr, dlerror()); + return false; + } + return true; + } + + /*! + * @brief Resolve all callback methods + * @param handle Pointer to the add-on + * @return True when all methods were resolved, false otherwise. + */ + bool RegisterMe(void* handle) + { + m_handle = handle; + + std::string libBasePath; + libBasePath = ((cb_array*)m_handle)->libPath; + libBasePath += PERIPHERAL_HELPER_DLL; + +#if defined(ANDROID) + struct stat st; + if (stat(libBasePath.c_str(),&st) != 0) + { + std::string tempbin = getenv("XBMC_ANDROID_LIBS"); + libBasePath = tempbin + "/" + PERIPHERAL_HELPER_DLL_NAME; + } +#endif + + m_libKODI_peripheral = dlopen(libBasePath.c_str(), RTLD_LAZY); + if (m_libKODI_peripheral == NULL) + { + fprintf(stderr, "Unable to load %s\n", dlerror()); + return false; + } + + if (!PERIPHERAL_REGISTER_SYMBOL(m_libKODI_peripheral, PERIPHERAL_register_me)) return false; + if (!PERIPHERAL_REGISTER_SYMBOL(m_libKODI_peripheral, PERIPHERAL_unregister_me)) return false; + if (!PERIPHERAL_REGISTER_SYMBOL(m_libKODI_peripheral, PERIPHERAL_trigger_scan)) return false; + if (!PERIPHERAL_REGISTER_SYMBOL(m_libKODI_peripheral, PERIPHERAL_refresh_button_maps)) return false; + + m_callbacks = PERIPHERAL_register_me(m_handle); + return m_callbacks != NULL; + } + + void TriggerScan(void) + { + return PERIPHERAL_trigger_scan(m_handle, m_callbacks); + } + + void RefreshButtonMaps(const std::string& strDeviceName = "", const std::string& strControllerId = "") + { + return PERIPHERAL_refresh_button_maps(m_handle, m_callbacks, strDeviceName.c_str(), strControllerId.c_str()); + } + +protected: + CB_PeripheralLib* (*PERIPHERAL_register_me)(void* handle); + void (*PERIPHERAL_unregister_me)(void* handle, CB_PeripheralLib* cb); + void (*PERIPHERAL_trigger_scan)(void* handle, CB_PeripheralLib* cb); + void (*PERIPHERAL_refresh_button_maps)(void* handle, CB_PeripheralLib* cb, const char* deviceName, const char* controllerId); + +private: + void* m_handle; + CB_PeripheralLib* m_callbacks; + void* m_libKODI_peripheral; + + struct cb_array + { + const char* libPath; + }; +}; + +} diff --git a/xbmc/addons/kodi-addon-dev-kit/include/kodi/libXBMC_addon.h b/xbmc/addons/kodi-addon-dev-kit/include/kodi/libXBMC_addon.h index e8d5ec7..b32ad86 100644 --- a/xbmc/addons/kodi-addon-dev-kit/include/kodi/libXBMC_addon.h +++ b/xbmc/addons/kodi-addon-dev-kit/include/kodi/libXBMC_addon.h @@ -86,6 +86,8 @@ typedef intptr_t ssize_t; #include #endif +struct __stat64; + #ifdef LOG_DEBUG #undef LOG_DEBUG #endif @@ -99,6 +101,9 @@ typedef intptr_t ssize_t; #undef LOG_ERROR #endif +/* current addon API version */ +#define KODI_ADDON_API_VERSION "1.0.0" + namespace ADDON { typedef enum addon_log diff --git a/xbmc/addons/kodi-addon-dev-kit/include/kodi/xbmc_codec_types.h b/xbmc/addons/kodi-addon-dev-kit/include/kodi/xbmc_codec_types.h index 01e7548..b1f43f9 100644 --- a/xbmc/addons/kodi-addon-dev-kit/include/kodi/xbmc_codec_types.h +++ b/xbmc/addons/kodi-addon-dev-kit/include/kodi/xbmc_codec_types.h @@ -24,6 +24,9 @@ extern "C" { #endif +/* current codec API version */ +#define KODI_CODEC_API_VERSION "1.0.0" + typedef unsigned int xbmc_codec_id_t; typedef enum diff --git a/xbmc/cores/VideoPlayer/DVDDemuxers/DVDDemuxPacket.h b/xbmc/cores/VideoPlayer/DVDDemuxers/DVDDemuxPacket.h index d64fbb3..dbee80a 100644 --- a/xbmc/cores/VideoPlayer/DVDDemuxers/DVDDemuxPacket.h +++ b/xbmc/cores/VideoPlayer/DVDDemuxers/DVDDemuxPacket.h @@ -20,14 +20,17 @@ * */ +#include + #define DMX_SPECIALID_STREAMINFO -10 #define DMX_SPECIALID_STREAMCHANGE -11 - typedef struct DemuxPacket +typedef struct DemuxPacket { unsigned char* pData; // data int iSize; // data size int iStreamId; // integer representing the stream index + int64_t demuxerId; // id of the demuxer that created the packet int iGroupId; // the group this data belongs to, used to group data from different streams together double pts; // pts in DVD_TIME_BASE -- cgit v1.2.3