Fix keymap.
[vuplus_xbmc] / xbmc / addons / AddonCallbacksCodec.cpp
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 "DllAvCodec.h"
25 #include "DllAvFormat.h"
26 #include "utils/StringUtils.h"
27
28 namespace ADDON
29 {
30 class CCodecIds
31 {
32 public:
33   virtual ~CCodecIds(void) {}
34
35   static CCodecIds& Get(void)
36   {
37     static CCodecIds _instance;
38     return _instance;
39   }
40
41   xbmc_codec_t GetCodecByName(const char* strCodecName)
42   {
43     xbmc_codec_t retVal = XBMC_INVALID_CODEC;
44     if (strlen(strCodecName) == 0)
45       return retVal;
46
47     std::string strUpperCodecName = strCodecName;
48     StringUtils::ToUpper(strUpperCodecName);
49
50     std::map<std::string, xbmc_codec_t>::const_iterator it = m_lookup.find(strUpperCodecName);
51     if (it != m_lookup.end())
52       retVal = it->second;
53
54     return retVal;
55   }
56
57 private:
58   CCodecIds(void)
59   {
60     DllAvCodec  dllAvCodec;
61     DllAvFormat dllAvFormat;
62
63     // load ffmpeg and register formats
64     if (!dllAvCodec.Load() || !dllAvFormat.Load())
65     {
66       CLog::Log(LOGWARNING, "failed to load ffmpeg");
67       return;
68     }
69     dllAvFormat.av_register_all();
70
71     // get ids and names
72     AVCodec* codec = NULL;
73     xbmc_codec_t tmp;
74     while ((codec = dllAvCodec.av_codec_next(codec)))
75     {
76       if (dllAvCodec.av_codec_is_decoder(codec))
77       {
78         tmp.codec_type = (xbmc_codec_type_t)codec->type;
79         tmp.codec_id   = codec->id;
80
81         std::string strUpperCodecName = codec->name;
82         StringUtils::ToUpper(strUpperCodecName);
83
84         m_lookup.insert(std::make_pair(strUpperCodecName, tmp));
85       }
86     }
87
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));
92   }
93
94   std::map<std::string, xbmc_codec_t> m_lookup;
95 };
96
97 CAddonCallbacksCodec::CAddonCallbacksCodec(CAddon* addon)
98 {
99   m_addon     = addon;
100   m_callbacks = new CB_CODECLib;
101
102   /* write XBMC addon-on specific add-on function addresses to the callback table */
103   m_callbacks->GetCodecByName   = GetCodecByName;
104 }
105
106 CAddonCallbacksCodec::~CAddonCallbacksCodec()
107 {
108   /* delete the callback table */
109   delete m_callbacks;
110 }
111
112 xbmc_codec_t CAddonCallbacksCodec::GetCodecByName(const void* addonData, const char* strCodecName)
113 {
114   (void)addonData;
115   return CCodecIds::Get().GetCodecByName(strCodecName);
116 }
117
118 }; /* namespace ADDON */
119