diff options
Diffstat (limited to 'xbmc/addons/AddonCallbacksCodec.cpp')
| -rw-r--r-- | xbmc/addons/AddonCallbacksCodec.cpp | 116 |
1 files changed, 116 insertions, 0 deletions
diff --git a/xbmc/addons/AddonCallbacksCodec.cpp b/xbmc/addons/AddonCallbacksCodec.cpp new file mode 100644 index 0000000..9c7be30 --- /dev/null +++ b/xbmc/addons/AddonCallbacksCodec.cpp | |||
| @@ -0,0 +1,116 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (C) 2012-2013 Team XBMC | ||
| 3 | * http://xbmc.org | ||
| 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 XBMC; see the file COPYING. If not, see | ||
| 17 | * <http://www.gnu.org/licenses/>. | ||
| 18 | * | ||
| 19 | */ | ||
| 20 | |||
| 21 | #include "Application.h" | ||
| 22 | #include "Addon.h" | ||
| 23 | #include "AddonCallbacksCodec.h" | ||
| 24 | #include "utils/StringUtils.h" | ||
| 25 | |||
| 26 | extern "C" { | ||
| 27 | #include "libavcodec/avcodec.h" | ||
| 28 | #include "libavformat/avformat.h" | ||
| 29 | } | ||
| 30 | |||
| 31 | namespace ADDON | ||
| 32 | { | ||
| 33 | class CCodecIds | ||
| 34 | { | ||
| 35 | public: | ||
| 36 | virtual ~CCodecIds(void) {} | ||
| 37 | |||
| 38 | static CCodecIds& Get(void) | ||
| 39 | { | ||
| 40 | static CCodecIds _instance; | ||
| 41 | return _instance; | ||
| 42 | } | ||
| 43 | |||
| 44 | xbmc_codec_t GetCodecByName(const char* strCodecName) | ||
| 45 | { | ||
| 46 | xbmc_codec_t retVal = XBMC_INVALID_CODEC; | ||
| 47 | if (strlen(strCodecName) == 0) | ||
| 48 | return retVal; | ||
| 49 | |||
| 50 | std::string strUpperCodecName = strCodecName; | ||
| 51 | StringUtils::ToUpper(strUpperCodecName); | ||
| 52 | |||
| 53 | std::map<std::string, xbmc_codec_t>::const_iterator it = m_lookup.find(strUpperCodecName); | ||
| 54 | if (it != m_lookup.end()) | ||
| 55 | retVal = it->second; | ||
| 56 | |||
| 57 | return retVal; | ||
| 58 | } | ||
| 59 | |||
| 60 | private: | ||
| 61 | CCodecIds(void) | ||
| 62 | { | ||
| 63 | // get ids and names | ||
| 64 | AVCodec* codec = NULL; | ||
| 65 | xbmc_codec_t tmp; | ||
| 66 | while ((codec = av_codec_next(codec))) | ||
| 67 | { | ||
| 68 | if (av_codec_is_decoder(codec)) | ||
| 69 | { | ||
| 70 | tmp.codec_type = (xbmc_codec_type_t)codec->type; | ||
| 71 | tmp.codec_id = codec->id; | ||
| 72 | |||
| 73 | std::string strUpperCodecName = codec->name; | ||
| 74 | StringUtils::ToUpper(strUpperCodecName); | ||
| 75 | |||
| 76 | m_lookup.insert(std::make_pair(strUpperCodecName, tmp)); | ||
| 77 | } | ||
| 78 | } | ||
| 79 | |||
| 80 | // teletext is not returned by av_codec_next. we got our own decoder | ||
| 81 | tmp.codec_type = XBMC_CODEC_TYPE_SUBTITLE; | ||
| 82 | tmp.codec_id = AV_CODEC_ID_DVB_TELETEXT; | ||
| 83 | m_lookup.insert(std::make_pair("TELETEXT", tmp)); | ||
| 84 | |||
| 85 | // rds is not returned by av_codec_next. we got our own decoder | ||
| 86 | tmp.codec_type = XBMC_CODEC_TYPE_RDS; | ||
| 87 | tmp.codec_id = AV_CODEC_ID_NONE; | ||
| 88 | m_lookup.insert(std::make_pair("RDS", tmp)); | ||
| 89 | } | ||
| 90 | |||
| 91 | std::map<std::string, xbmc_codec_t> m_lookup; | ||
| 92 | }; | ||
| 93 | |||
| 94 | CAddonCallbacksCodec::CAddonCallbacksCodec(CAddon* addon) | ||
| 95 | { | ||
| 96 | m_addon = addon; | ||
| 97 | m_callbacks = new CB_CODECLib; | ||
| 98 | |||
| 99 | /* write XBMC addon-on specific add-on function addresses to the callback table */ | ||
| 100 | m_callbacks->GetCodecByName = GetCodecByName; | ||
| 101 | } | ||
| 102 | |||
| 103 | CAddonCallbacksCodec::~CAddonCallbacksCodec() | ||
| 104 | { | ||
| 105 | /* delete the callback table */ | ||
| 106 | delete m_callbacks; | ||
| 107 | } | ||
| 108 | |||
| 109 | xbmc_codec_t CAddonCallbacksCodec::GetCodecByName(const void* addonData, const char* strCodecName) | ||
| 110 | { | ||
| 111 | (void)addonData; | ||
| 112 | return CCodecIds::Get().GetCodecByName(strCodecName); | ||
| 113 | } | ||
| 114 | |||
| 115 | }; /* namespace ADDON */ | ||
| 116 | |||
