Debian Codegraph @

xbmc/cores/playercorefactory/PlayerCoreConfig.cpp

raw
1 /*
2 * Copyright (C) 2022 Team Kodi
3 * This file is part of Kodi - https://kodi.tv
4 *
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 * See LICENSES/README.md for more information.
7 */
8
9 #include "PlayerCoreConfig.h"
10
11 #include "cores/ExternalPlayer/ExternalPlayer.h"
12 #include "cores/IPlayer.h"
13 #include "cores/RetroPlayer/RetroPlayer.h"
14 #include "cores/VideoPlayer/VideoPlayer.h"
15 #include "cores/paplayer/PAPlayer.h"
16 #ifdef HAS_UPNP
17 #include "network/upnp/UPnPPlayer.h"
18 #endif
19 #include "utils/StringUtils.h"
20 #include "utils/XBMCTinyXML.h"
21 #include "utils/log.h"
22
23 #include <utility>
24
25 CPlayerCoreConfig::CPlayerCoreConfig(std::string name,
26 std::string type,
27 const TiXmlElement* pConfig,
28 const std::string& id /* = "" */)
29 : m_name(std::move(name)), m_id(id), m_type(std::move(type))
30 {
31 if (pConfig)
32 {
33 m_config.reset(static_cast<TiXmlElement*>(pConfig->Clone()));
34 const char* sAudio = pConfig->Attribute("audio");
35 const char* sVideo = pConfig->Attribute("video");
36 m_bPlaysAudio = sAudio && StringUtils::CompareNoCase(sAudio, "true") == 0;
37 m_bPlaysVideo = sVideo && StringUtils::CompareNoCase(sVideo, "true") == 0;
38 }
39
40 CLog::Log(LOGDEBUG, "CPlayerCoreConfig::<ctor>: created player {}", m_name);
41 }
42
43 std::shared_ptr<IPlayer> CPlayerCoreConfig::CreatePlayer(IPlayerCallback& callback) const
44 {
45 std::shared_ptr<IPlayer> player;
46
47 if (m_type.compare("video") == 0)
48 {
49 player = std::make_shared<CVideoPlayer>(callback);
50 }
51 else if (m_type.compare("music") == 0)
52 {
53 player = std::make_shared<PAPlayer>(callback);
54 }
55 else if (m_type.compare("game") == 0)
56 {
57 player = std::make_shared<KODI::RETRO::CRetroPlayer>(callback);
58 }
59 else if (m_type.compare("external") == 0)
60 {
61 player = std::make_shared<CExternalPlayer>(callback);
62 }
63
64 #if defined(HAS_UPNP)
65 else if (m_type.compare("remote") == 0)
66 {
67 player = std::make_shared<UPNP::CUPnPPlayer>(callback, m_id.c_str());
68 }
69 #endif
70 else
71 return nullptr;
72
73 if (!player)
74 return nullptr;
75
76 player->m_name = m_name;
77 player->m_type = m_type;
78
79 if (player->Initialize(m_config.get()))
80 return player;
81
82 return nullptr;
83 }