Merge pull request #26273 from 78andyp/blurayfixes2
[xbmc.git] / xbmc / cores / paplayer / CodecFactory.cpp
blob70684d876c23bbb92d20c6d258ec72632ba43beb
1 /*
2 * Copyright (C) 2005-2018 Team Kodi
3 * This file is part of Kodi - https://kodi.tv
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 * See LICENSES/README.md for more information.
7 */
9 #include "CodecFactory.h"
11 #include "ServiceBroker.h"
12 #include "URL.h"
13 #include "VideoPlayerCodec.h"
14 #include "addons/AudioDecoder.h"
15 #include "addons/ExtsMimeSupportList.h"
16 #include "addons/addoninfo/AddonType.h"
17 #include "utils/StringUtils.h"
19 using namespace KODI::ADDONS;
21 ICodec* CodecFactory::CreateCodec(const CURL& urlFile)
23 std::string fileType = urlFile.GetFileType();
24 StringUtils::ToLower(fileType);
26 auto addonInfos = CServiceBroker::GetExtsMimeSupportList().GetExtensionSupportedAddonInfos(
27 "." + fileType, CExtsMimeSupportList::FilterSelect::all);
28 for (const auto& addonInfo : addonInfos)
30 // Check asked and given extension is supported by only for here allowed audiodecoder addons.
31 if (addonInfo.first == ADDON::AddonType::AUDIODECODER)
33 std::unique_ptr<CAudioDecoder> result = std::make_unique<CAudioDecoder>(addonInfo.second);
34 if (!result->CreateDecoder())
35 continue;
37 return result.release();
41 VideoPlayerCodec *dvdcodec = new VideoPlayerCodec();
42 return dvdcodec;
45 ICodec* CodecFactory::CreateCodecDemux(const CFileItem& file, unsigned int filecache)
47 CURL urlFile(file.GetDynPath());
48 std::string content = file.GetMimeType();
49 StringUtils::ToLower(content);
50 if (!content.empty())
52 auto addonInfos = CServiceBroker::GetExtsMimeSupportList().GetMimetypeSupportedAddonInfos(
53 content, CExtsMimeSupportList::FilterSelect::all);
54 for (const auto& addonInfo : addonInfos)
56 // Check asked and given mime type is supported by only for here allowed audiodecoder addons.
57 if (addonInfo.first == ADDON::AddonType::AUDIODECODER)
59 std::unique_ptr<CAudioDecoder> result = std::make_unique<CAudioDecoder>(addonInfo.second);
60 if (!result->CreateDecoder() && result->SupportsFile(file.GetPath()))
61 continue;
63 return result.release();
68 if( content == "audio/mpeg" ||
69 content == "audio/mpeg3" ||
70 content == "audio/mp3" ||
71 content == "audio/aac" ||
72 content == "audio/aacp" ||
73 content == "audio/x-ms-wma" ||
74 content == "audio/x-ape" ||
75 content == "audio/ape" ||
76 content == "application/ogg" ||
77 content == "audio/ogg" ||
78 content == "audio/x-xbmc-pcm" ||
79 content == "audio/flac" ||
80 content == "audio/x-flac" ||
81 content == "application/x-flac"
84 VideoPlayerCodec *dvdcodec = new VideoPlayerCodec();
85 dvdcodec->SetContentType(content);
86 return dvdcodec;
88 else if (urlFile.IsProtocol("shout"))
90 VideoPlayerCodec *dvdcodec = new VideoPlayerCodec();
91 dvdcodec->SetContentType("audio/mp3");
92 return dvdcodec; // if we got this far with internet radio - content-type was wrong. gamble on mp3.
94 else if (urlFile.IsFileType("wav") ||
95 content == "audio/wav" ||
96 content == "audio/x-wav")
98 VideoPlayerCodec *dvdcodec = new VideoPlayerCodec();
99 dvdcodec->SetContentType("audio/x-spdif-compressed");
100 if (dvdcodec->Init(file, filecache))
102 return dvdcodec;
105 dvdcodec = new VideoPlayerCodec();
106 dvdcodec->SetContentType(content);
107 return dvdcodec;
109 else
110 return CreateCodec(urlFile);