diff options
Diffstat (limited to 'xbmc/addons/kodi-addon-dev-kit/include/kodi/libXBMC_codec.h')
| -rw-r--r-- | xbmc/addons/kodi-addon-dev-kit/include/kodi/libXBMC_codec.h | 124 |
1 files changed, 124 insertions, 0 deletions
diff --git a/xbmc/addons/kodi-addon-dev-kit/include/kodi/libXBMC_codec.h b/xbmc/addons/kodi-addon-dev-kit/include/kodi/libXBMC_codec.h new file mode 100644 index 0000000..3853f08 --- /dev/null +++ b/xbmc/addons/kodi-addon-dev-kit/include/kodi/libXBMC_codec.h | |||
| @@ -0,0 +1,124 @@ | |||
| 1 | #pragma once | ||
| 2 | /* | ||
| 3 | * Copyright (C) 2005-2013 Team XBMC | ||
| 4 | * http://xbmc.org | ||
| 5 | * | ||
| 6 | * This Program is free software; you can redistribute it and/or modify | ||
| 7 | * it under the terms of the GNU General Public License as published by | ||
| 8 | * the Free Software Foundation; either version 2, or (at your option) | ||
| 9 | * any later version. | ||
| 10 | * | ||
| 11 | * This Program is distributed in the hope that it will be useful, | ||
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 14 | * GNU General Public License for more details. | ||
| 15 | * | ||
| 16 | * You should have received a copy of the GNU General Public License | ||
| 17 | * along with XBMC; see the file COPYING. If not, see | ||
| 18 | * <http://www.gnu.org/licenses/>. | ||
| 19 | * | ||
| 20 | */ | ||
| 21 | |||
| 22 | #include <string> | ||
| 23 | #include <vector> | ||
| 24 | #include <string.h> | ||
| 25 | #include <stdlib.h> | ||
| 26 | #include <stdio.h> | ||
| 27 | #include "xbmc_codec_types.h" | ||
| 28 | #include "libXBMC_addon.h" | ||
| 29 | |||
| 30 | #ifdef _WIN32 | ||
| 31 | #define CODEC_HELPER_DLL "\\library.xbmc.codec\\libXBMC_codec" ADDON_HELPER_EXT | ||
| 32 | #else | ||
| 33 | #define CODEC_HELPER_DLL_NAME "libXBMC_codec-" ADDON_HELPER_ARCH ADDON_HELPER_EXT | ||
| 34 | #define CODEC_HELPER_DLL "/library.xbmc.codec/" CODEC_HELPER_DLL_NAME | ||
| 35 | #endif | ||
| 36 | |||
| 37 | class CHelper_libXBMC_codec | ||
| 38 | { | ||
| 39 | public: | ||
| 40 | CHelper_libXBMC_codec(void) | ||
| 41 | { | ||
| 42 | m_libXBMC_codec = NULL; | ||
| 43 | m_Handle = NULL; | ||
| 44 | } | ||
| 45 | |||
| 46 | ~CHelper_libXBMC_codec(void) | ||
| 47 | { | ||
| 48 | if (m_libXBMC_codec) | ||
| 49 | { | ||
| 50 | CODEC_unregister_me(m_Handle, m_Callbacks); | ||
| 51 | dlclose(m_libXBMC_codec); | ||
| 52 | } | ||
| 53 | } | ||
| 54 | |||
| 55 | /*! | ||
| 56 | * @brief Resolve all callback methods | ||
| 57 | * @param handle Pointer to the add-on | ||
| 58 | * @return True when all methods were resolved, false otherwise. | ||
| 59 | */ | ||
| 60 | bool RegisterMe(void* handle) | ||
| 61 | { | ||
| 62 | m_Handle = handle; | ||
| 63 | |||
| 64 | std::string libBasePath; | ||
| 65 | libBasePath = ((cb_array*)m_Handle)->libPath; | ||
| 66 | libBasePath += CODEC_HELPER_DLL; | ||
| 67 | |||
| 68 | #if defined(ANDROID) | ||
| 69 | struct stat st; | ||
| 70 | if(stat(libBasePath.c_str(),&st) != 0) | ||
| 71 | { | ||
| 72 | std::string tempbin = getenv("XBMC_ANDROID_LIBS"); | ||
| 73 | libBasePath = tempbin + "/" + CODEC_HELPER_DLL_NAME; | ||
| 74 | } | ||
| 75 | #endif | ||
| 76 | |||
| 77 | m_libXBMC_codec = dlopen(libBasePath.c_str(), RTLD_LAZY); | ||
| 78 | if (m_libXBMC_codec == NULL) | ||
| 79 | { | ||
| 80 | fprintf(stderr, "Unable to load %s\n", dlerror()); | ||
| 81 | return false; | ||
| 82 | } | ||
| 83 | |||
| 84 | CODEC_register_me = (void* (*)(void *HANDLE)) | ||
| 85 | dlsym(m_libXBMC_codec, "CODEC_register_me"); | ||
| 86 | if (CODEC_register_me == NULL) { fprintf(stderr, "Unable to assign function %s\n", dlerror()); return false; } | ||
| 87 | |||
| 88 | CODEC_unregister_me = (void (*)(void* HANDLE, void* CB)) | ||
| 89 | dlsym(m_libXBMC_codec, "CODEC_unregister_me"); | ||
| 90 | if (CODEC_unregister_me == NULL) { fprintf(stderr, "Unable to assign function %s\n", dlerror()); return false; } | ||
| 91 | |||
| 92 | CODEC_get_codec_by_name = (xbmc_codec_t (*)(void* HANDLE, void* CB, const char* strCodecName)) | ||
| 93 | dlsym(m_libXBMC_codec, "CODEC_get_codec_by_name"); | ||
| 94 | if (CODEC_get_codec_by_name == NULL) { fprintf(stderr, "Unable to assign function %s\n", dlerror()); return false; } | ||
| 95 | |||
| 96 | m_Callbacks = CODEC_register_me(m_Handle); | ||
| 97 | return m_Callbacks != NULL; | ||
| 98 | } | ||
| 99 | |||
| 100 | /*! | ||
| 101 | * @brief Get the codec id used by XBMC | ||
| 102 | * @param strCodecName The name of the codec | ||
| 103 | * @return The codec_id, or a codec_id with 0 values when not supported | ||
| 104 | */ | ||
| 105 | xbmc_codec_t GetCodecByName(const char* strCodecName) | ||
| 106 | { | ||
| 107 | return CODEC_get_codec_by_name(m_Handle, m_Callbacks, strCodecName); | ||
| 108 | } | ||
| 109 | |||
| 110 | protected: | ||
| 111 | void* (*CODEC_register_me)(void*); | ||
| 112 | void (*CODEC_unregister_me)(void*, void*); | ||
| 113 | xbmc_codec_t (*CODEC_get_codec_by_name)(void *HANDLE, void* CB, const char* strCodecName); | ||
| 114 | |||
| 115 | private: | ||
| 116 | void* m_libXBMC_codec; | ||
| 117 | void* m_Handle; | ||
| 118 | void* m_Callbacks; | ||
| 119 | struct cb_array | ||
| 120 | { | ||
| 121 | const char* libPath; | ||
| 122 | }; | ||
| 123 | }; | ||
| 124 | |||
