[cosmetics] update date in GPL header
[vuplus_xbmc] / xbmc / cores / playercorefactory / PlayerCoreConfig.h
1 #pragma once
2 /*
3  *      Copyright (C) 2005-2013 Team XBMC
4  *      http://xbmc.org
5  *
6  *  This Program is free software; you can redistribute it and/or modify
7  *  it under the terms of the GNU General Public License as published by
8  *  the Free Software Foundation; either version 2, or (at your option)
9  *  any later version.
10  *
11  *  This Program is distributed in the hope that it will be useful,
12  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  *  GNU General Public License for more details.
15  *
16  *  You should have received a copy of the GNU General Public License
17  *  along with XBMC; see the file COPYING.  If not, see
18  *  <http://www.gnu.org/licenses/>.
19  *
20  */
21
22 #include "utils/XBMCTinyXML.h"
23 #include "cores/IPlayer.h"
24 #include "PlayerCoreFactory.h"
25 #include "cores/dvdplayer/DVDPlayer.h"
26 #include "cores/paplayer/PAPlayer.h"
27 #if defined(HAS_AMLPLAYER)
28 #include "cores/amlplayer/AMLPlayer.h"
29 #endif
30 #if defined(HAS_OMXPLAYER)
31 #include "cores/omxplayer/OMXPlayer.h"
32 #endif
33 #include "cores/ExternalPlayer/ExternalPlayer.h"
34 #ifdef HAS_UPNP
35 #include "network/upnp/UPnPPlayer.h"
36 #endif
37 #include "utils/log.h"
38
39 class CPlayerCoreConfig
40 {
41 friend class CPlayerCoreFactory;
42
43 public:
44   CPlayerCoreConfig(CStdString name, const EPLAYERCORES eCore, const TiXmlElement* pConfig, const CStdString& id = "")
45   {
46     m_name = name;
47     m_id = id;
48     m_eCore = eCore;
49     m_bPlaysAudio = false;
50     m_bPlaysVideo = false;
51
52     if (pConfig)
53     {
54       m_config = (TiXmlElement*)pConfig->Clone();
55       const char *szAudio = pConfig->Attribute("audio");
56       const char *szVideo = pConfig->Attribute("video");
57       m_bPlaysAudio = szAudio && stricmp(szAudio, "true") == 0;
58       m_bPlaysVideo = szVideo && stricmp(szVideo, "true") == 0;
59     }
60     else
61     {
62       m_config = NULL;
63     }
64     CLog::Log(LOGDEBUG, "CPlayerCoreConfig::<ctor>: created player %s for core %d", m_name.c_str(), m_eCore);
65   }
66
67   virtual ~CPlayerCoreConfig()
68   {
69     SAFE_DELETE(m_config);
70   }
71
72   const CStdString& GetName() const
73   {
74     return m_name;
75   }
76
77   const CStdString& GetId() const
78   {
79     return m_id;
80   }
81
82   const EPLAYERCORES& GetType() const
83   {
84     return m_eCore;
85   }
86
87   IPlayer* CreatePlayer(IPlayerCallback& callback) const
88   {
89     IPlayer* pPlayer;
90     switch(m_eCore)
91     {
92       case EPC_MPLAYER:
93       // TODO: this hack needs removal until we have a better player selection
94 #if defined(HAS_OMXPLAYER)
95       case EPC_DVDPLAYER: 
96         pPlayer = new COMXPlayer(callback); 
97         CLog::Log(LOGINFO, "Created player %s for core %d / OMXPlayer forced as DVDPlayer", "OMXPlayer", m_eCore);
98         break;
99       case EPC_PAPLAYER: 
100         pPlayer = new COMXPlayer(callback); 
101         CLog::Log(LOGINFO, "Created player %s for core %d / OMXPlayer forced as PAPLayer", "OMXPlayer", m_eCore);
102         break;
103 #else
104       case EPC_DVDPLAYER: pPlayer = new CDVDPlayer(callback); break;
105       case EPC_PAPLAYER: pPlayer = new PAPlayer(callback); break;
106 #endif
107       case EPC_EXTPLAYER: pPlayer = new CExternalPlayer(callback); break;
108 #if defined(HAS_AMLPLAYER)
109       case EPC_AMLPLAYER: pPlayer = new CAMLPlayer(callback); break;
110 #endif
111 #if defined(HAS_OMXPLAYER)
112       case EPC_OMXPLAYER: pPlayer = new COMXPlayer(callback); break;
113 #endif
114 #if defined(HAS_UPNP)
115       case EPC_UPNPPLAYER: pPlayer = new UPNP::CUPnPPlayer(callback, m_id.c_str()); break;
116 #endif
117       default: return NULL;
118     }
119
120     if (pPlayer->Initialize(m_config))
121     {
122       return pPlayer;
123     }
124     else
125     {
126       SAFE_DELETE(pPlayer);
127       return NULL;
128     }
129   }
130
131 private:
132   CStdString m_name;
133   CStdString m_id;
134   bool m_bPlaysAudio;
135   bool m_bPlaysVideo;
136   EPLAYERCORES m_eCore;
137   TiXmlElement* m_config;
138 };