PageRenderTime 37ms CodeModel.GetById 12ms app.highlight 19ms RepoModel.GetById 1ms app.codeStats 1ms

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