2 * Copyright (C) 2012-2013 Team XBMC
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)
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.
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/>.
21 #include "Application.h"
23 #include "AddonCallbacksCodec.h"
24 #include "DllAvCodec.h"
25 #include "DllAvFormat.h"
26 #include "utils/StringUtils.h"
33 virtual ~CCodecIds(void) {}
35 static CCodecIds& Get(void)
37 static CCodecIds _instance;
41 xbmc_codec_t GetCodecByName(const char* strCodecName)
43 xbmc_codec_t retVal = XBMC_INVALID_CODEC;
44 if (strlen(strCodecName) == 0)
47 std::string strUpperCodecName = strCodecName;
48 StringUtils::ToUpper(strUpperCodecName);
50 std::map<std::string, xbmc_codec_t>::const_iterator it = m_lookup.find(strUpperCodecName);
51 if (it != m_lookup.end())
60 DllAvCodec dllAvCodec;
61 DllAvFormat dllAvFormat;
63 // load ffmpeg and register formats
64 if (!dllAvCodec.Load() || !dllAvFormat.Load())
66 CLog::Log(LOGWARNING, "failed to load ffmpeg");
69 dllAvFormat.av_register_all();
72 AVCodec* codec = NULL;
74 while ((codec = dllAvCodec.av_codec_next(codec)))
76 if (dllAvCodec.av_codec_is_decoder(codec))
78 tmp.codec_type = (xbmc_codec_type_t)codec->type;
79 tmp.codec_id = codec->id;
81 std::string strUpperCodecName = codec->name;
82 StringUtils::ToUpper(strUpperCodecName);
84 m_lookup.insert(std::make_pair(strUpperCodecName, tmp));
88 // teletext is not returned by av_codec_next. we got our own decoder
89 tmp.codec_type = XBMC_CODEC_TYPE_SUBTITLE;
90 tmp.codec_id = AV_CODEC_ID_DVB_TELETEXT;
91 m_lookup.insert(std::make_pair("TELETEXT", tmp));
94 std::map<std::string, xbmc_codec_t> m_lookup;
97 CAddonCallbacksCodec::CAddonCallbacksCodec(CAddon* addon)
100 m_callbacks = new CB_CODECLib;
102 /* write XBMC addon-on specific add-on function addresses to the callback table */
103 m_callbacks->GetCodecByName = GetCodecByName;
106 CAddonCallbacksCodec::~CAddonCallbacksCodec()
108 /* delete the callback table */
112 xbmc_codec_t CAddonCallbacksCodec::GetCodecByName(const void* addonData, const char* strCodecName)
115 return CCodecIds::Get().GetCodecByName(strCodecName);
118 }; /* namespace ADDON */