3 * Copyright (C) 2005-2013 Team XBMC
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)
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.
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/>.
24 #if !defined(HAVE_LIBCEC)
25 #include "Peripheral.h"
27 // an empty implementation, so CPeripherals can be compiled without a bunch of #ifdef's when libCEC is not available
30 class CPeripheralCecAdapter : public CPeripheral
33 bool HasAudioControl(void) { return false; }
34 void VolumeUp(void) {}
35 void VolumeDown(void) {}
36 bool IsMuted(void) { return false; }
37 void ToggleMute(void) {}
39 int GetButton(void) { return 0; }
40 unsigned int GetHoldTime(void) { return 0; }
41 void ResetButton(void) {}
47 #include "PeripheralHID.h"
48 #include "interfaces/AnnouncementManager.h"
49 #include "threads/Thread.h"
50 #include "threads/CriticalSection.h"
53 // undefine macro isset, it collides with function in cectypes.h
57 #include <libcec/cectypes.h>
68 class CPeripheralCecAdapterUpdateThread;
73 unsigned int iDuration;
84 class CPeripheralCecAdapter : public CPeripheralHID, public ANNOUNCEMENT::IAnnouncer, private CThread
86 friend class CPeripheralCecAdapterUpdateThread;
89 CPeripheralCecAdapter(const PeripheralScanResult& scanResult);
90 virtual ~CPeripheralCecAdapter(void);
92 void Announce(ANNOUNCEMENT::AnnouncementFlag flag, const char *sender, const char *message, const CVariant &data);
95 bool HasAudioControl(void);
97 void VolumeDown(void);
98 void ToggleMute(void);
101 // CPeripheral callbacks
102 void OnSettingChanged(const CStdString &strChangedSetting);
103 void OnDeviceRemoved(void);
107 unsigned int GetHoldTime(void);
108 void ResetButton(void);
110 // public CEC methods
111 void ActivateSource(void);
112 void StandbyDevices(void);
115 bool InitialiseFeature(const PeripheralFeature feature);
116 void ResetMembers(void);
118 bool IsRunning(void) const;
120 bool OpenConnection(void);
121 bool ReopenConnection(void);
123 void SetConfigurationFromSettings(void);
124 void SetConfigurationFromLibCEC(const CEC::libcec_configuration &config);
125 void SetVersionInfo(const CEC::libcec_configuration &configuration);
127 static void ReadLogicalAddresses(const CStdString &strString, CEC::cec_logical_addresses &addresses);
128 static void ReadLogicalAddresses(int iLocalisedId, CEC::cec_logical_addresses &addresses);
129 bool WriteLogicalAddresses(const CEC::cec_logical_addresses& addresses, const std::string& strSettingName, const std::string& strAdvancedSettingName);
131 void ProcessActivateSource(void);
132 void ProcessStandbyDevices(void);
133 void ProcessVolumeChange(void);
135 void PushCecKeypress(const CEC::cec_keypress &key);
136 void PushCecKeypress(const CecButtonPress &key);
137 void GetNextKey(void);
139 void SetAudioSystemConnected(bool bSetTo);
140 void SetMenuLanguage(const char *strLanguage);
142 // callbacks from libCEC
143 static int CecLogMessage(void *cbParam, const CEC::cec_log_message message);
144 static int CecCommand(void *cbParam, const CEC::cec_command command);
145 static int CecConfiguration(void *cbParam, const CEC::libcec_configuration config);
146 static int CecAlert(void *cbParam, const CEC::libcec_alert alert, const CEC::libcec_parameter data);
147 static void CecSourceActivated(void *param, const CEC::cec_logical_address address, const uint8_t activated);
148 static int CecKeyPress(void *cbParam, const CEC::cec_keypress key);
151 CEC::ICECAdapter* m_cecAdapter;
155 bool m_bHasConnectedAudioSystem;
156 CStdString m_strMenuLanguage;
157 CDateTime m_screensaverLastActivated;
158 std::vector<CecButtonPress> m_buttonQueue;
159 CecButtonPress m_currentButton;
160 std::queue<CecVolumeChange> m_volumeChangeQueue;
161 unsigned int m_lastKeypress;
162 CecVolumeChange m_lastChange;
165 bool m_bGoingToStandby;
167 bool m_bDeviceRemoved;
168 CPeripheralCecAdapterUpdateThread*m_queryThread;
169 CEC::ICECCallbacks m_callbacks;
170 CCriticalSection m_critSection;
171 CEC::libcec_configuration m_configuration;
172 bool m_bActiveSourcePending;
173 bool m_bStandbyPending;
174 CDateTime m_preventActivateSourceOnPlay;
175 bool m_bActiveSourceBeforeStandby;
176 bool m_bOnPlayReceived;
177 bool m_bPlaybackPaused;
178 CStdString m_strComPort;
181 class CPeripheralCecAdapterUpdateThread : public CThread
184 CPeripheralCecAdapterUpdateThread(CPeripheralCecAdapter *adapter, CEC::libcec_configuration *configuration);
185 virtual ~CPeripheralCecAdapterUpdateThread(void);
188 bool UpdateConfiguration(CEC::libcec_configuration *configuration);
191 void UpdateMenuLanguage(void);
192 CStdString UpdateAudioSystemStatus(void);
193 bool WaitReady(void);
194 bool SetInitialConfiguration(void);
197 CPeripheralCecAdapter * m_adapter;
199 CCriticalSection m_critSection;
200 CEC::libcec_configuration m_configuration;
201 CEC::libcec_configuration m_nextConfiguration;
202 bool m_bNextConfigurationScheduled;