-
-
Notifications
You must be signed in to change notification settings - Fork 6.2k
/
CodecFactory.cpp
115 lines (105 loc) · 3.28 KB
/
CodecFactory.cpp
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
112
113
114
/*
* Copyright (C) 2005-2018 Team Kodi
* This file is part of Kodi - https://kodi.tv
*
* SPDX-License-Identifier: GPL-2.0-or-later
* See LICENSES/README.md for more information.
*/
#include "CodecFactory.h"
#include "ServiceBroker.h"
#include "URL.h"
#include "VideoPlayerCodec.h"
#include "addons/AudioDecoder.h"
#include "addons/binary-addons/BinaryAddonBase.h"
#include "utils/StringUtils.h"
using namespace ADDON;
ICodec* CodecFactory::CreateCodec(const std::string &strFileType)
{
std::string fileType = strFileType;
StringUtils::ToLower(fileType);
BinaryAddonBaseList addonInfos;
CServiceBroker::GetBinaryAddonManager().GetAddonInfos(addonInfos, true, ADDON_AUDIODECODER);
for (const auto& addonInfo : addonInfos)
{
auto exts = StringUtils::Split(CAudioDecoder::GetExtensions(addonInfo), "|");
if (std::find(exts.begin(), exts.end(), "." + fileType) != exts.end())
{
CAudioDecoder* result = new CAudioDecoder(addonInfo);
if (!result->CreateDecoder())
{
delete result;
return nullptr;
}
return result;
}
}
VideoPlayerCodec *dvdcodec = new VideoPlayerCodec();
return dvdcodec;
}
ICodec* CodecFactory::CreateCodecDemux(const CFileItem& file, unsigned int filecache)
{
CURL urlFile(file.GetDynPath());
std::string content = file.GetMimeType();
StringUtils::ToLower(content);
if (!content.empty())
{
BinaryAddonBaseList addonInfos;
CServiceBroker::GetBinaryAddonManager().GetAddonInfos(addonInfos, true, ADDON_AUDIODECODER);
for (const auto& addonInfo : addonInfos)
{
auto types = StringUtils::Split(CAudioDecoder::GetMimetypes(addonInfo), "|");
if (std::find(types.begin(), types.end(), content) != types.end())
{
CAudioDecoder* result = new CAudioDecoder(addonInfo);
if (!result->CreateDecoder())
{
delete result;
return nullptr;
}
return result;
}
}
}
if( content == "audio/mpeg" ||
content == "audio/mpeg3" ||
content == "audio/mp3" ||
content == "audio/aac" ||
content == "audio/aacp" ||
content == "audio/x-ms-wma" ||
content == "audio/x-ape" ||
content == "audio/ape" ||
content == "application/ogg" ||
content == "audio/ogg" ||
content == "audio/x-xbmc-pcm" ||
content == "audio/flac" ||
content == "audio/x-flac" ||
content == "application/x-flac"
)
{
VideoPlayerCodec *dvdcodec = new VideoPlayerCodec();
dvdcodec->SetContentType(content);
return dvdcodec;
}
else if (urlFile.IsProtocol("shout"))
{
VideoPlayerCodec *dvdcodec = new VideoPlayerCodec();
dvdcodec->SetContentType("audio/mp3");
return dvdcodec; // if we got this far with internet radio - content-type was wrong. gamble on mp3.
}
else if (urlFile.IsFileType("wav") ||
content == "audio/wav" ||
content == "audio/x-wav")
{
VideoPlayerCodec *dvdcodec = new VideoPlayerCodec();
dvdcodec->SetContentType("audio/x-spdif-compressed");
if (dvdcodec->Init(file, filecache))
{
return dvdcodec;
}
dvdcodec = new VideoPlayerCodec();
dvdcodec->SetContentType(content);
return dvdcodec;
}
else
return CreateCodec(urlFile.GetFileType());
}