/xbmc/cores/playercorefactory/PlayerCoreConfig.h

http://github.com/xbmc/xbmc · C Header · 124 lines · 102 code · 15 blank · 7 comment · 20 complexity · 1bb2f72607d0e930443d387c64a36b47 MD5 · raw file

  1. /*
  2. * Copyright (C) 2005-2018 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. #pragma once
  9. #include "utils/XBMCTinyXML.h"
  10. #include "cores/IPlayer.h"
  11. #include "cores/VideoPlayer/VideoPlayer.h"
  12. #include "cores/paplayer/PAPlayer.h"
  13. #include "cores/RetroPlayer/RetroPlayer.h"
  14. #include "cores/ExternalPlayer/ExternalPlayer.h"
  15. #ifdef HAS_UPNP
  16. #include "network/upnp/UPnPPlayer.h"
  17. #endif
  18. #include "system.h"
  19. #include "utils/log.h"
  20. class CPlayerCoreConfig
  21. {
  22. public:
  23. CPlayerCoreConfig(std::string name, std::string type, const TiXmlElement* pConfig, const std::string& id = ""):
  24. m_name(name),
  25. m_id(id),
  26. m_type(type)
  27. {
  28. m_bPlaysAudio = false;
  29. m_bPlaysVideo = false;
  30. if (pConfig)
  31. {
  32. m_config = static_cast<TiXmlElement*>(pConfig->Clone());
  33. const char *sAudio = pConfig->Attribute("audio");
  34. const char *sVideo = pConfig->Attribute("video");
  35. m_bPlaysAudio = sAudio && StringUtils::CompareNoCase(sAudio, "true") == 0;
  36. m_bPlaysVideo = sVideo && StringUtils::CompareNoCase(sVideo, "true") == 0;
  37. }
  38. else
  39. {
  40. m_config = nullptr;
  41. }
  42. CLog::Log(LOGDEBUG, "CPlayerCoreConfig::<ctor>: created player %s", m_name.c_str());
  43. }
  44. virtual ~CPlayerCoreConfig()
  45. {
  46. SAFE_DELETE(m_config);
  47. }
  48. const std::string& GetName() const
  49. {
  50. return m_name;
  51. }
  52. const std::string& GetId() const
  53. {
  54. return m_id;
  55. }
  56. bool PlaysAudio() const
  57. {
  58. return m_bPlaysAudio;
  59. }
  60. bool PlaysVideo() const
  61. {
  62. return m_bPlaysVideo;
  63. }
  64. IPlayer* CreatePlayer(IPlayerCallback& callback) const
  65. {
  66. IPlayer* pPlayer;
  67. if (m_type.compare("video") == 0)
  68. {
  69. pPlayer = new CVideoPlayer(callback);
  70. }
  71. else if (m_type.compare("music") == 0)
  72. {
  73. pPlayer = new PAPlayer(callback);
  74. }
  75. else if (m_type.compare("game") == 0)
  76. {
  77. pPlayer = new KODI::RETRO::CRetroPlayer(callback);
  78. }
  79. else if (m_type.compare("external") == 0)
  80. {
  81. pPlayer = new CExternalPlayer(callback);
  82. }
  83. #if defined(HAS_UPNP)
  84. else if (m_type.compare("remote") == 0)
  85. {
  86. pPlayer = new UPNP::CUPnPPlayer(callback, m_id.c_str());
  87. }
  88. #endif
  89. else
  90. return nullptr;
  91. pPlayer->m_name = m_name;
  92. pPlayer->m_type = m_type;
  93. if (pPlayer->Initialize(m_config))
  94. {
  95. return pPlayer;
  96. }
  97. else
  98. {
  99. SAFE_DELETE(pPlayer);
  100. return nullptr;
  101. }
  102. }
  103. std::string m_name;
  104. std::string m_id; // uuid for upnp
  105. std::string m_type;
  106. bool m_bPlaysAudio;
  107. bool m_bPlaysVideo;
  108. TiXmlElement* m_config;
  109. };