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