Commit | Line | Data |
---|---|---|
abbca718 LOK |
1 | /* |
2 | * This file is part of the libCEC(R) library. | |
3 | * | |
b492c10e | 4 | * libCEC(R) is Copyright (C) 2011-2012 Pulse-Eight Limited. All rights reserved. |
abbca718 LOK |
5 | * libCEC(R) is an original work, containing original code. |
6 | * | |
7 | * libCEC(R) is a trademark of Pulse-Eight Limited. | |
8 | * | |
9 | * This program is dual-licensed; you can redistribute it and/or modify | |
10 | * it under the terms of the GNU General Public License as published by | |
11 | * the Free Software Foundation; either version 2 of the License, or | |
12 | * (at your option) any later version. | |
13 | * | |
14 | * This program is distributed in the hope that it will be useful, | |
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 | * GNU General Public License for more details. | |
18 | * | |
19 | * You should have received a copy of the GNU General Public License | |
20 | * along with this program; if not, write to the Free Software | |
21 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | |
22 | * | |
23 | * | |
24 | * Alternatively, you can license this library under a commercial license, | |
25 | * please contact Pulse-Eight Licensing for more information. | |
26 | * | |
27 | * For more information contact: | |
28 | * Pulse-Eight Licensing <license@pulse-eight.com> | |
29 | * http://www.pulse-eight.com/ | |
30 | * http://www.pulse-eight.net/ | |
31 | */ | |
32 | ||
2abe74eb | 33 | #include "CECProcessor.h" |
abbca718 | 34 | |
7bb4ed43 | 35 | #include "adapter/USBCECAdapterCommunication.h" |
eafa9d46 | 36 | #include "devices/CECBusDevice.h" |
51b2a094 LOK |
37 | #include "devices/CECAudioSystem.h" |
38 | #include "devices/CECPlaybackDevice.h" | |
39 | #include "devices/CECRecordingDevice.h" | |
40 | #include "devices/CECTuner.h" | |
41 | #include "devices/CECTV.h" | |
62f5527d | 42 | #include "implementations/CECCommandHandler.h" |
2abe74eb | 43 | #include "LibCEC.h" |
ba65909d | 44 | #include "platform/util/timeutils.h" |
abbca718 LOK |
45 | |
46 | using namespace CEC; | |
47 | using namespace std; | |
f00ff009 | 48 | using namespace PLATFORM; |
abbca718 | 49 | |
3efda01a | 50 | CCECProcessor::CCECProcessor(CLibCEC *controller, libcec_configuration *configuration) : |
80726797 | 51 | m_bConnectionOpened(false), |
caca2d81 | 52 | m_bInitialised(false), |
caca2d81 LOK |
53 | m_communication(NULL), |
54 | m_controller(controller), | |
55 | m_bMonitor(false), | |
56 | m_iStandardLineTimeout(3), | |
57 | m_iRetryLineTimeout(3), | |
30b4aac0 | 58 | m_iLastTransmission(0) |
caca2d81 | 59 | { |
caca2d81 | 60 | CreateBusDevices(); |
30b4aac0 | 61 | m_configuration.Clear(); |
41e3372a | 62 | m_configuration.serverVersion = configuration->serverVersion; |
30b4aac0 LOK |
63 | SetConfiguration(configuration); |
64 | ||
65 | if (m_configuration.tvVendor != CEC_VENDOR_UNKNOWN) | |
ed63a515 | 66 | m_busDevices[CECDEVICE_TV]->ReplaceHandler(false); |
caca2d81 LOK |
67 | } |
68 | ||
7bdfd76c | 69 | CCECProcessor::CCECProcessor(CLibCEC *controller, const char *strDeviceName, const cec_device_type_list &types, uint16_t iPhysicalAddress) : |
80726797 | 70 | m_bConnectionOpened(false), |
b64db02e | 71 | m_bInitialised(false), |
99666519 | 72 | m_communication(NULL), |
f8513317 | 73 | m_controller(controller), |
dcd240b2 LOK |
74 | m_bMonitor(false), |
75 | m_iStandardLineTimeout(3), | |
5f316715 | 76 | m_iRetryLineTimeout(3), |
30b4aac0 | 77 | m_iLastTransmission(0) |
f8513317 | 78 | { |
30b4aac0 | 79 | m_configuration.Clear(); |
2e82cff0 | 80 | m_configuration.serverVersion = CEC_SERVER_VERSION_1_5_2; |
30b4aac0 LOK |
81 | |
82 | // client version < 1.5.0 | |
3efda01a | 83 | m_configuration.clientVersion = (uint32_t)CEC_CLIENT_VERSION_PRE_1_5; |
30b4aac0 LOK |
84 | snprintf(m_configuration.strDeviceName, 13, "%s", strDeviceName); |
85 | m_configuration.deviceTypes = types; | |
86 | m_configuration.iPhysicalAddress = iPhysicalAddress; | |
87 | m_configuration.baseDevice = (cec_logical_address)CEC_DEFAULT_BASE_DEVICE; | |
88 | m_configuration.iHDMIPort = CEC_DEFAULT_HDMI_PORT; | |
89 | ||
90 | if (m_configuration.deviceTypes.IsEmpty()) | |
91 | m_configuration.deviceTypes.Add(CEC_DEVICE_TYPE_RECORDING_DEVICE); | |
caca2d81 LOK |
92 | CreateBusDevices(); |
93 | } | |
94 | ||
95 | void CCECProcessor::CreateBusDevices(void) | |
96 | { | |
f8513317 | 97 | for (int iPtr = 0; iPtr < 16; iPtr++) |
51b2a094 LOK |
98 | { |
99 | switch(iPtr) | |
100 | { | |
101 | case CECDEVICE_AUDIOSYSTEM: | |
5d5a2dc2 | 102 | m_busDevices[iPtr] = new CCECAudioSystem(this, (cec_logical_address) iPtr, 0xFFFF); |
51b2a094 LOK |
103 | break; |
104 | case CECDEVICE_PLAYBACKDEVICE1: | |
105 | case CECDEVICE_PLAYBACKDEVICE2: | |
106 | case CECDEVICE_PLAYBACKDEVICE3: | |
5d5a2dc2 | 107 | m_busDevices[iPtr] = new CCECPlaybackDevice(this, (cec_logical_address) iPtr, 0xFFFF); |
51b2a094 LOK |
108 | break; |
109 | case CECDEVICE_RECORDINGDEVICE1: | |
110 | case CECDEVICE_RECORDINGDEVICE2: | |
111 | case CECDEVICE_RECORDINGDEVICE3: | |
5d5a2dc2 | 112 | m_busDevices[iPtr] = new CCECRecordingDevice(this, (cec_logical_address) iPtr, 0xFFFF); |
51b2a094 LOK |
113 | break; |
114 | case CECDEVICE_TUNER1: | |
115 | case CECDEVICE_TUNER2: | |
116 | case CECDEVICE_TUNER3: | |
117 | case CECDEVICE_TUNER4: | |
5d5a2dc2 | 118 | m_busDevices[iPtr] = new CCECTuner(this, (cec_logical_address) iPtr, 0xFFFF); |
51b2a094 LOK |
119 | break; |
120 | case CECDEVICE_TV: | |
121 | m_busDevices[iPtr] = new CCECTV(this, (cec_logical_address) iPtr, 0); | |
122 | break; | |
123 | default: | |
5d5a2dc2 | 124 | m_busDevices[iPtr] = new CCECBusDevice(this, (cec_logical_address) iPtr, 0xFFFF); |
51b2a094 LOK |
125 | break; |
126 | } | |
127 | } | |
f8513317 LOK |
128 | } |
129 | ||
2abe74eb | 130 | CCECProcessor::~CCECProcessor(void) |
abbca718 | 131 | { |
eca71746 | 132 | Close(); |
7c63a480 | 133 | |
d1998c7b LOK |
134 | for (unsigned int iPtr = 0; iPtr < 16; iPtr++) |
135 | delete m_busDevices[iPtr]; | |
abbca718 LOK |
136 | } |
137 | ||
eca71746 LOK |
138 | void CCECProcessor::Close(void) |
139 | { | |
f9e01dac LOK |
140 | StopThread(false); |
141 | SetInitialised(false); | |
eca71746 LOK |
142 | StopThread(); |
143 | ||
80726797 LOK |
144 | bool bClose(false); |
145 | { | |
146 | CLockObject lock(m_mutex); | |
147 | bClose = m_bConnectionOpened; | |
148 | m_bConnectionOpened = false; | |
149 | } | |
150 | ||
151 | if (bClose && m_communication) | |
eca71746 LOK |
152 | { |
153 | m_communication->Close(); | |
154 | delete m_communication; | |
155 | m_communication = NULL; | |
156 | } | |
157 | } | |
158 | ||
578c3905 | 159 | bool CCECProcessor::OpenConnection(const char *strPort, uint16_t iBaudRate, uint32_t iTimeoutMs) |
abbca718 | 160 | { |
a674fd68 | 161 | bool bReturn(false); |
80726797 LOK |
162 | Close(); |
163 | ||
578c3905 | 164 | { |
80726797 LOK |
165 | CLockObject lock(m_mutex); |
166 | if (m_bConnectionOpened) | |
167 | { | |
168 | CLibCEC::AddLog(CEC_LOG_ERROR, "connection already opened"); | |
169 | return false; | |
170 | } | |
171 | m_communication = new CUSBCECAdapterCommunication(this, strPort, iBaudRate); | |
172 | m_bConnectionOpened = (m_communication != NULL); | |
578c3905 | 173 | } |
1113cb7d | 174 | |
578c3905 LOK |
175 | /* check for an already opened connection */ |
176 | if (m_communication->IsOpen()) | |
1113cb7d | 177 | { |
5477a250 | 178 | CLibCEC::AddLog(CEC_LOG_ERROR, "connection already opened"); |
578c3905 LOK |
179 | return bReturn; |
180 | } | |
abbca718 | 181 | |
3b5e433a | 182 | CTimeout timeout(iTimeoutMs > 0 ? iTimeoutMs : CEC_DEFAULT_TRANSMIT_WAIT); |
c520af4f | 183 | |
578c3905 | 184 | /* open a new connection */ |
efed01e1 | 185 | unsigned iConnectTry(0); |
3b5e433a | 186 | while (timeout.TimeLeft() > 0 && (bReturn = m_communication->Open(this, (timeout.TimeLeft() / CEC_CONNECT_TRIES))) == false) |
3d78df91 LOK |
187 | { |
188 | CLibCEC::AddLog(CEC_LOG_ERROR, "could not open a connection (try %d)", ++iConnectTry); | |
d55f263f | 189 | m_communication->Close(); |
a88017b8 | 190 | CEvent::Sleep(1000); |
3d78df91 | 191 | } |
56035c86 | 192 | |
efed01e1 | 193 | if (bReturn) |
3efda01a | 194 | CLibCEC::AddLog(CEC_LOG_NOTICE, "connected to the CEC adapter. firmware version = %d, client version = %s", m_communication->GetFirmwareVersion(), ToString((cec_client_version)m_configuration.clientVersion)); |
3d78df91 | 195 | |
578c3905 LOK |
196 | return bReturn; |
197 | } | |
198 | ||
0cfdeb5a LOK |
199 | bool CCECProcessor::IsInitialised(void) |
200 | { | |
201 | CLockObject lock(m_mutex); | |
202 | return m_bInitialised; | |
203 | } | |
204 | ||
2db8981f | 205 | void CCECProcessor::SetInitialised(bool bSetTo /* = true */) |
578c3905 | 206 | { |
578c3905 | 207 | CLockObject lock(m_mutex); |
2db8981f LOK |
208 | m_bInitialised = bSetTo; |
209 | } | |
578c3905 | 210 | |
2db8981f LOK |
211 | bool CCECProcessor::Initialise(void) |
212 | { | |
213 | bool bReturn(false); | |
578c3905 | 214 | { |
2db8981f | 215 | CLockObject lock(m_mutex); |
dd18e809 LOK |
216 | if (!m_configuration.logicalAddresses.IsEmpty()) |
217 | m_configuration.logicalAddresses.Clear(); | |
578c3905 | 218 | |
2db8981f LOK |
219 | if (!FindLogicalAddresses()) |
220 | { | |
5477a250 | 221 | CLibCEC::AddLog(CEC_LOG_ERROR, "could not detect our logical addresses"); |
2db8981f LOK |
222 | return bReturn; |
223 | } | |
224 | ||
225 | /* only set our OSD name for the primary device */ | |
dd18e809 | 226 | m_busDevices[m_configuration.logicalAddresses.primary]->m_strDeviceName = m_configuration.strDeviceName; |
80726797 LOK |
227 | |
228 | /* make the primary device the active source if the option is set */ | |
229 | if (m_configuration.bActivateSource == 1) | |
dd18e809 | 230 | m_busDevices[m_configuration.logicalAddresses.primary]->m_bActiveSource = true; |
2db8981f | 231 | } |
578c3905 LOK |
232 | |
233 | /* get the vendor id from the TV, so we are using the correct handler */ | |
30b4aac0 | 234 | m_busDevices[CECDEVICE_TV]->GetVendorId(); |
578c3905 | 235 | |
30b4aac0 | 236 | if (m_configuration.iPhysicalAddress != 0) |
4f362964 | 237 | { |
30b4aac0 | 238 | CLibCEC::AddLog(CEC_LOG_NOTICE, "setting the physical address to %4x", m_configuration.iPhysicalAddress); |
dd18e809 LOK |
239 | m_busDevices[m_configuration.logicalAddresses.primary]->m_iPhysicalAddress = m_configuration.iPhysicalAddress; |
240 | if ((bReturn = m_busDevices[m_configuration.logicalAddresses.primary]->TransmitPhysicalAddress()) == false) | |
30b4aac0 | 241 | CLibCEC::AddLog(CEC_LOG_ERROR, "unable to set the physical address to %4x", m_configuration.iPhysicalAddress); |
4f362964 | 242 | } |
30b4aac0 LOK |
243 | else if (m_configuration.iPhysicalAddress == 0 && (bReturn = SetHDMIPort(m_configuration.baseDevice, m_configuration.iHDMIPort, true)) == false) |
244 | CLibCEC::AddLog(CEC_LOG_ERROR, "unable to set HDMI port %d on %s (%x)", m_configuration.iHDMIPort, ToString(m_configuration.baseDevice), (uint8_t)m_configuration.baseDevice); | |
2db8981f | 245 | |
80726797 | 246 | if (m_configuration.bActivateSource == 1) |
dd18e809 | 247 | m_busDevices[m_configuration.logicalAddresses.primary]->ActivateSource(); |
80726797 | 248 | |
2db8981f | 249 | SetInitialised(bReturn); |
ba73be2f LOK |
250 | if (bReturn) |
251 | CLibCEC::ConfigurationChanged(m_configuration); | |
578c3905 LOK |
252 | |
253 | return bReturn; | |
254 | } | |
255 | ||
256 | bool CCECProcessor::Start(const char *strPort, uint16_t iBaudRate /* = 38400 */, uint32_t iTimeoutMs /* = 10000 */) | |
257 | { | |
258 | bool bReturn(false); | |
259 | ||
260 | { | |
261 | CLockObject lock(m_mutex); | |
262 | if (!OpenConnection(strPort, iBaudRate, iTimeoutMs)) | |
a674fd68 | 263 | return bReturn; |
994dbaaa | 264 | |
a674fd68 | 265 | /* create the processor thread */ |
8e57f83c | 266 | if (!CreateThread()) |
a674fd68 | 267 | { |
5477a250 | 268 | CLibCEC::AddLog(CEC_LOG_ERROR, "could not create a processor thread"); |
a674fd68 | 269 | return bReturn; |
994dbaaa | 270 | } |
a674fd68 LOK |
271 | } |
272 | ||
578c3905 | 273 | if ((bReturn = Initialise()) == false) |
a674fd68 | 274 | { |
5477a250 | 275 | CLibCEC::AddLog(CEC_LOG_ERROR, "could not create a processor thread"); |
578c3905 | 276 | StopThread(true); |
a674fd68 LOK |
277 | } |
278 | else | |
279 | { | |
5477a250 | 280 | CLibCEC::AddLog(CEC_LOG_DEBUG, "processor thread started"); |
a674fd68 LOK |
281 | } |
282 | ||
283 | return bReturn; | |
abbca718 LOK |
284 | } |
285 | ||
b58d9277 | 286 | bool CCECProcessor::TryLogicalAddress(cec_logical_address address) |
f8513317 | 287 | { |
93fff5c1 | 288 | if (m_busDevices[address]->TryLogicalAddress()) |
f8513317 | 289 | { |
dd18e809 | 290 | m_configuration.logicalAddresses.Set(address); |
f8513317 LOK |
291 | return true; |
292 | } | |
293 | ||
f8513317 LOK |
294 | return false; |
295 | } | |
296 | ||
b58d9277 | 297 | bool CCECProcessor::FindLogicalAddressRecordingDevice(void) |
f8513317 | 298 | { |
5477a250 | 299 | CLibCEC::AddLog(CEC_LOG_DEBUG, "detecting logical address for type 'recording device'"); |
b58d9277 LOK |
300 | return TryLogicalAddress(CECDEVICE_RECORDINGDEVICE1) || |
301 | TryLogicalAddress(CECDEVICE_RECORDINGDEVICE2) || | |
302 | TryLogicalAddress(CECDEVICE_RECORDINGDEVICE3); | |
f8513317 LOK |
303 | } |
304 | ||
b58d9277 | 305 | bool CCECProcessor::FindLogicalAddressTuner(void) |
f8513317 | 306 | { |
5477a250 | 307 | CLibCEC::AddLog(CEC_LOG_DEBUG, "detecting logical address for type 'tuner'"); |
b58d9277 LOK |
308 | return TryLogicalAddress(CECDEVICE_TUNER1) || |
309 | TryLogicalAddress(CECDEVICE_TUNER2) || | |
310 | TryLogicalAddress(CECDEVICE_TUNER3) || | |
311 | TryLogicalAddress(CECDEVICE_TUNER4); | |
f8513317 LOK |
312 | } |
313 | ||
b58d9277 | 314 | bool CCECProcessor::FindLogicalAddressPlaybackDevice(void) |
f8513317 | 315 | { |
5477a250 | 316 | CLibCEC::AddLog(CEC_LOG_DEBUG, "detecting logical address for type 'playback device'"); |
b58d9277 LOK |
317 | return TryLogicalAddress(CECDEVICE_PLAYBACKDEVICE1) || |
318 | TryLogicalAddress(CECDEVICE_PLAYBACKDEVICE2) || | |
319 | TryLogicalAddress(CECDEVICE_PLAYBACKDEVICE3); | |
f8513317 LOK |
320 | } |
321 | ||
b58d9277 | 322 | bool CCECProcessor::FindLogicalAddressAudioSystem(void) |
f8513317 | 323 | { |
5477a250 | 324 | CLibCEC::AddLog(CEC_LOG_DEBUG, "detecting logical address for type 'audio'"); |
b58d9277 | 325 | return TryLogicalAddress(CECDEVICE_AUDIOSYSTEM); |
f8513317 LOK |
326 | } |
327 | ||
3e61b350 LOK |
328 | bool CCECProcessor::ChangeDeviceType(cec_device_type from, cec_device_type to) |
329 | { | |
330 | bool bChanged(false); | |
331 | ||
5477a250 | 332 | CLibCEC::AddLog(CEC_LOG_NOTICE, "changing device type '%s' into '%s'", ToString(from), ToString(to)); |
3e61b350 | 333 | |
f00ff009 | 334 | CLockObject lock(m_mutex); |
3e61b350 | 335 | CCECBusDevice *previousDevice = GetDeviceByType(from); |
dd18e809 | 336 | m_configuration.logicalAddresses.primary = CECDEVICE_UNKNOWN; |
3e61b350 LOK |
337 | |
338 | for (unsigned int iPtr = 0; iPtr < 5; iPtr++) | |
339 | { | |
30b4aac0 | 340 | if (m_configuration.deviceTypes.types[iPtr] == CEC_DEVICE_TYPE_RESERVED) |
3e61b350 LOK |
341 | continue; |
342 | ||
30b4aac0 | 343 | if (m_configuration.deviceTypes.types[iPtr] == from) |
3e61b350 LOK |
344 | { |
345 | bChanged = true; | |
30b4aac0 | 346 | m_configuration.deviceTypes.types[iPtr] = to; |
3e61b350 | 347 | } |
30b4aac0 | 348 | else if (m_configuration.deviceTypes.types[iPtr] == to && bChanged) |
3e61b350 | 349 | { |
30b4aac0 | 350 | m_configuration.deviceTypes.types[iPtr] = CEC_DEVICE_TYPE_RESERVED; |
3e61b350 LOK |
351 | } |
352 | } | |
353 | ||
354 | if (bChanged) | |
355 | { | |
356 | FindLogicalAddresses(); | |
357 | ||
358 | CCECBusDevice *newDevice = GetDeviceByType(to); | |
359 | if (previousDevice && newDevice) | |
360 | { | |
361 | newDevice->SetDeviceStatus(CEC_DEVICE_STATUS_HANDLED_BY_LIBCEC); | |
4478bc79 | 362 | previousDevice->SetDeviceStatus(CEC_DEVICE_STATUS_NOT_PRESENT); |
3e61b350 LOK |
363 | |
364 | newDevice->SetCecVersion(previousDevice->GetCecVersion(false)); | |
365 | previousDevice->SetCecVersion(CEC_VERSION_UNKNOWN); | |
366 | ||
367 | newDevice->SetMenuLanguage(previousDevice->GetMenuLanguage(false)); | |
368 | cec_menu_language lang; | |
369 | lang.device = previousDevice->GetLogicalAddress(); | |
370 | for (unsigned int iPtr = 0; iPtr < 4; iPtr++) | |
371 | lang.language[iPtr] = '?'; | |
372 | lang.language[3] = 0; | |
373 | previousDevice->SetMenuLanguage(lang); | |
374 | ||
375 | newDevice->SetMenuState(previousDevice->GetMenuState()); | |
376 | previousDevice->SetMenuState(CEC_MENU_STATE_DEACTIVATED); | |
377 | ||
378 | newDevice->SetOSDName(previousDevice->GetOSDName(false)); | |
379 | previousDevice->SetOSDName(ToString(previousDevice->GetLogicalAddress())); | |
380 | ||
381 | newDevice->SetPhysicalAddress(previousDevice->GetPhysicalAddress(false)); | |
382 | previousDevice->SetPhysicalAddress(0xFFFF); | |
383 | ||
384 | newDevice->SetPowerStatus(previousDevice->GetPowerStatus(false)); | |
385 | previousDevice->SetPowerStatus(CEC_POWER_STATUS_UNKNOWN); | |
386 | ||
387 | newDevice->SetVendorId(previousDevice->GetVendorId(false)); | |
388 | previousDevice->SetVendorId(CEC_VENDOR_UNKNOWN); | |
389 | ||
390 | if ((from == CEC_DEVICE_TYPE_PLAYBACK_DEVICE || from == CEC_DEVICE_TYPE_RECORDING_DEVICE) && | |
391 | (to == CEC_DEVICE_TYPE_PLAYBACK_DEVICE || to == CEC_DEVICE_TYPE_RECORDING_DEVICE)) | |
392 | { | |
393 | ((CCECPlaybackDevice *) newDevice)->SetDeckControlMode(((CCECPlaybackDevice *) previousDevice)->GetDeckControlMode()); | |
394 | ((CCECPlaybackDevice *) previousDevice)->SetDeckControlMode(CEC_DECK_CONTROL_MODE_STOP); | |
395 | ||
396 | ((CCECPlaybackDevice *) newDevice)->SetDeckStatus(((CCECPlaybackDevice *) previousDevice)->GetDeckStatus()); | |
397 | ((CCECPlaybackDevice *) previousDevice)->SetDeckStatus(CEC_DECK_INFO_STOP); | |
398 | } | |
399 | } | |
400 | } | |
401 | ||
402 | return true; | |
403 | } | |
404 | ||
f8513317 LOK |
405 | bool CCECProcessor::FindLogicalAddresses(void) |
406 | { | |
407 | bool bReturn(true); | |
dd18e809 | 408 | m_configuration.logicalAddresses.Clear(); |
f8513317 | 409 | |
30b4aac0 | 410 | if (m_configuration.deviceTypes.IsEmpty()) |
c39611ec LOK |
411 | { |
412 | CLibCEC::AddLog(CEC_LOG_ERROR, "no device types set"); | |
413 | return false; | |
414 | } | |
415 | ||
f8513317 LOK |
416 | for (unsigned int iPtr = 0; iPtr < 5; iPtr++) |
417 | { | |
30b4aac0 | 418 | if (m_configuration.deviceTypes.types[iPtr] == CEC_DEVICE_TYPE_RESERVED) |
f8513317 LOK |
419 | continue; |
420 | ||
30b4aac0 | 421 | CLibCEC::AddLog(CEC_LOG_DEBUG, "%s - device %d: type %d", __FUNCTION__, iPtr, m_configuration.deviceTypes.types[iPtr]); |
f8513317 | 422 | |
30b4aac0 | 423 | if (m_configuration.deviceTypes.types[iPtr] == CEC_DEVICE_TYPE_RECORDING_DEVICE) |
b58d9277 | 424 | bReturn &= FindLogicalAddressRecordingDevice(); |
30b4aac0 | 425 | if (m_configuration.deviceTypes.types[iPtr] == CEC_DEVICE_TYPE_TUNER) |
b58d9277 | 426 | bReturn &= FindLogicalAddressTuner(); |
30b4aac0 | 427 | if (m_configuration.deviceTypes.types[iPtr] == CEC_DEVICE_TYPE_PLAYBACK_DEVICE) |
b58d9277 | 428 | bReturn &= FindLogicalAddressPlaybackDevice(); |
30b4aac0 | 429 | if (m_configuration.deviceTypes.types[iPtr] == CEC_DEVICE_TYPE_AUDIO_SYSTEM) |
b58d9277 | 430 | bReturn &= FindLogicalAddressAudioSystem(); |
f8513317 LOK |
431 | } |
432 | ||
a674fd68 | 433 | if (bReturn) |
dd18e809 | 434 | SetAckMask(m_configuration.logicalAddresses.AckMask()); |
a674fd68 | 435 | |
f8513317 LOK |
436 | return bReturn; |
437 | } | |
438 | ||
a3ffc068 LOK |
439 | void CCECProcessor::ReplaceHandlers(void) |
440 | { | |
0cfdeb5a LOK |
441 | if (!IsInitialised()) |
442 | return; | |
a3ffc068 | 443 | for (uint8_t iPtr = 0; iPtr <= CECDEVICE_PLAYBACKDEVICE3; iPtr++) |
591170fd | 444 | m_busDevices[iPtr]->ReplaceHandler(m_bInitialised); |
a3ffc068 LOK |
445 | } |
446 | ||
b1f94db1 LOK |
447 | bool CCECProcessor::OnCommandReceived(const cec_command &command) |
448 | { | |
f6b94ad2 | 449 | ParseCommand(command); |
b1f94db1 LOK |
450 | return true; |
451 | } | |
452 | ||
2abe74eb | 453 | void *CCECProcessor::Process(void) |
f99bc831 | 454 | { |
8e57f83c | 455 | CLibCEC::AddLog(CEC_LOG_DEBUG, "processor thread started"); |
abbca718 | 456 | |
b1f94db1 | 457 | while (!IsStopped() && m_communication->IsOpen()) |
abbca718 | 458 | { |
f0154449 LOK |
459 | if (IsInitialised()) |
460 | { | |
461 | ReplaceHandlers(); | |
b5f34cf9 | 462 | |
f0154449 LOK |
463 | m_controller->CheckKeypressTimeout(); |
464 | } | |
b1f94db1 | 465 | Sleep(5); |
abbca718 LOK |
466 | } |
467 | ||
60fa4578 | 468 | return NULL; |
abbca718 LOK |
469 | } |
470 | ||
18203d17 | 471 | bool CCECProcessor::SetActiveSource(cec_device_type type /* = CEC_DEVICE_TYPE_RESERVED */) |
abbca718 | 472 | { |
8ac9c610 LOK |
473 | bool bReturn(false); |
474 | ||
60fa4578 | 475 | if (!IsRunning()) |
8ac9c610 | 476 | return bReturn; |
f99bc831 | 477 | |
dd18e809 | 478 | cec_logical_address addr = m_configuration.logicalAddresses.primary; |
04437dcf | 479 | |
18203d17 LOK |
480 | if (type != CEC_DEVICE_TYPE_RESERVED) |
481 | { | |
90ea9066 | 482 | for (uint8_t iPtr = 0; iPtr <= 11; iPtr++) |
18203d17 | 483 | { |
dd18e809 | 484 | if (m_configuration.logicalAddresses[iPtr] && m_busDevices[iPtr]->m_type == type) |
18203d17 LOK |
485 | { |
486 | addr = (cec_logical_address) iPtr; | |
487 | break; | |
488 | } | |
489 | } | |
490 | } | |
491 | ||
37b0c572 | 492 | m_busDevices[addr]->SetActiveSource(); |
d383d6d0 | 493 | if (m_busDevices[addr]->GetPhysicalAddress(false) != 0xFFFF) |
bbc71623 | 494 | bReturn = m_busDevices[addr]->ActivateSource(); |
8d915412 LOK |
495 | |
496 | return bReturn; | |
18203d17 LOK |
497 | } |
498 | ||
37b0c572 LOK |
499 | bool CCECProcessor::SetActiveSource(uint16_t iStreamPath) |
500 | { | |
501 | bool bReturn(false); | |
502 | ||
503 | CCECBusDevice *device = GetDeviceByPhysicalAddress(iStreamPath); | |
504 | if (device) | |
505 | { | |
506 | device->SetActiveSource(); | |
507 | bReturn = true; | |
508 | } | |
509 | ||
510 | return bReturn; | |
511 | } | |
512 | ||
dcd240b2 LOK |
513 | void CCECProcessor::SetStandardLineTimeout(uint8_t iTimeout) |
514 | { | |
f00ff009 | 515 | CLockObject lock(m_mutex); |
dcd240b2 LOK |
516 | m_iStandardLineTimeout = iTimeout; |
517 | } | |
518 | ||
519 | void CCECProcessor::SetRetryLineTimeout(uint8_t iTimeout) | |
520 | { | |
f00ff009 | 521 | CLockObject lock(m_mutex); |
dcd240b2 LOK |
522 | m_iRetryLineTimeout = iTimeout; |
523 | } | |
524 | ||
18203d17 LOK |
525 | bool CCECProcessor::SetActiveView(void) |
526 | { | |
8670c970 | 527 | CLibCEC::AddLog(CEC_LOG_WARNING, "deprecated method %s called", __FUNCTION__); |
30b4aac0 | 528 | return SetActiveSource(m_configuration.deviceTypes.IsEmpty() ? CEC_DEVICE_TYPE_RESERVED : m_configuration.deviceTypes[0]); |
8ac9c610 LOK |
529 | } |
530 | ||
28fa6c97 | 531 | bool CCECProcessor::SetDeckControlMode(cec_deck_control_mode mode, bool bSendUpdate /* = true */) |
a9232a79 LOK |
532 | { |
533 | bool bReturn(false); | |
534 | ||
535 | CCECBusDevice *device = GetDeviceByType(CEC_DEVICE_TYPE_PLAYBACK_DEVICE); | |
536 | if (device) | |
537 | { | |
538 | ((CCECPlaybackDevice *) device)->SetDeckControlMode(mode); | |
28fa6c97 LOK |
539 | if (bSendUpdate) |
540 | ((CCECPlaybackDevice *) device)->TransmitDeckStatus(CECDEVICE_TV); | |
a9232a79 LOK |
541 | bReturn = true; |
542 | } | |
543 | ||
544 | return bReturn; | |
545 | } | |
546 | ||
28fa6c97 | 547 | bool CCECProcessor::SetDeckInfo(cec_deck_info info, bool bSendUpdate /* = true */) |
a9232a79 LOK |
548 | { |
549 | bool bReturn(false); | |
550 | ||
551 | CCECBusDevice *device = GetDeviceByType(CEC_DEVICE_TYPE_PLAYBACK_DEVICE); | |
552 | if (device) | |
553 | { | |
554 | ((CCECPlaybackDevice *) device)->SetDeckStatus(info); | |
28fa6c97 LOK |
555 | if (bSendUpdate) |
556 | ((CCECPlaybackDevice *) device)->TransmitDeckStatus(CECDEVICE_TV); | |
a9232a79 LOK |
557 | bReturn = true; |
558 | } | |
559 | ||
560 | return bReturn; | |
561 | } | |
562 | ||
d2f1c157 | 563 | bool CCECProcessor::SetHDMIPort(cec_logical_address iBaseDevice, uint8_t iPort, bool bForce /* = false */) |
16b1e052 LOK |
564 | { |
565 | bool bReturn(false); | |
566 | ||
8670c970 LOK |
567 | { |
568 | CLockObject lock(m_mutex); | |
569 | m_configuration.baseDevice = iBaseDevice; | |
570 | m_configuration.iHDMIPort = iPort; | |
8670c970 LOK |
571 | } |
572 | ||
8e57f83c | 573 | if (!IsRunning() && !bForce) |
89b3c9df | 574 | return true; |
16b1e052 | 575 | |
5477a250 | 576 | CLibCEC::AddLog(CEC_LOG_DEBUG, "setting HDMI port to %d on device %s (%d)", iPort, ToString(iBaseDevice), (int)iBaseDevice); |
56035c86 | 577 | |
16b1e052 | 578 | uint16_t iPhysicalAddress(0); |
1e7afacd | 579 | if (iBaseDevice > CECDEVICE_TV) |
5d0c1164 | 580 | { |
1e7afacd | 581 | iPhysicalAddress = m_busDevices[iBaseDevice]->GetPhysicalAddress(); |
5d0c1164 | 582 | } |
1e7afacd | 583 | |
a674fd68 | 584 | if (iPhysicalAddress < 0xffff) |
1e7afacd | 585 | { |
1e7afacd | 586 | if (iPhysicalAddress == 0) |
5d355340 | 587 | iPhysicalAddress += 0x1000 * iPort; |
1e7afacd | 588 | else if (iPhysicalAddress % 0x1000 == 0) |
5d355340 | 589 | iPhysicalAddress += 0x100 * iPort; |
1e7afacd | 590 | else if (iPhysicalAddress % 0x100 == 0) |
5d355340 | 591 | iPhysicalAddress += 0x10 * iPort; |
1e7afacd | 592 | else if (iPhysicalAddress % 0x10 == 0) |
5d355340 | 593 | iPhysicalAddress += iPort; |
1e7afacd | 594 | |
5d355340 | 595 | bReturn = true; |
16b1e052 LOK |
596 | } |
597 | ||
a674fd68 | 598 | if (!bReturn) |
5477a250 | 599 | CLibCEC::AddLog(CEC_LOG_ERROR, "failed to set the physical address"); |
f070564b | 600 | else |
f070564b | 601 | SetPhysicalAddress(iPhysicalAddress); |
a674fd68 | 602 | |
16b1e052 LOK |
603 | return bReturn; |
604 | } | |
605 | ||
45b97de7 | 606 | bool CCECProcessor::PhysicalAddressInUse(uint16_t iPhysicalAddress) |
16b1e052 | 607 | { |
9fd73dd4 | 608 | for (unsigned int iPtr = 0; iPtr < 15; iPtr++) |
16b1e052 LOK |
609 | { |
610 | if (m_busDevices[iPtr]->GetPhysicalAddress(false) == iPhysicalAddress) | |
611 | return true; | |
612 | } | |
613 | return false; | |
614 | } | |
615 | ||
ab27363d | 616 | bool CCECProcessor::TransmitInactiveSource(void) |
abbca718 | 617 | { |
60fa4578 | 618 | if (!IsRunning()) |
f99bc831 LOK |
619 | return false; |
620 | ||
dd18e809 LOK |
621 | if (!m_configuration.logicalAddresses.IsEmpty() && m_busDevices[m_configuration.logicalAddresses.primary]) |
622 | return m_busDevices[m_configuration.logicalAddresses.primary]->TransmitInactiveSource(); | |
cc60ab1c | 623 | return false; |
abbca718 LOK |
624 | } |
625 | ||
9dee1670 | 626 | void CCECProcessor::LogOutput(const cec_command &data) |
abbca718 | 627 | { |
1d3ca3de | 628 | CStdString strTx; |
57f45e6c LOK |
629 | strTx.Format("<< %02x", ((uint8_t)data.initiator << 4) + (uint8_t)data.destination); |
630 | if (data.opcode_set) | |
631 | strTx.AppendFormat(":%02x", (uint8_t)data.opcode); | |
9dee1670 | 632 | |
06a1f7ce | 633 | for (uint8_t iPtr = 0; iPtr < data.parameters.size; iPtr++) |
1d3ca3de | 634 | strTx.AppendFormat(":%02x", data.parameters[iPtr]); |
5477a250 | 635 | CLibCEC::AddLog(CEC_LOG_TRAFFIC, strTx.c_str()); |
9dee1670 | 636 | } |
2abe74eb | 637 | |
06bfd4d7 | 638 | bool CCECProcessor::SetLogicalAddress(cec_logical_address iLogicalAddress) |
abbca718 | 639 | { |
f00ff009 | 640 | CLockObject lock(m_mutex); |
dd18e809 | 641 | if (m_configuration.logicalAddresses.primary != iLogicalAddress) |
06775107 | 642 | { |
5477a250 | 643 | CLibCEC::AddLog(CEC_LOG_NOTICE, "<< setting primary logical address to %1x", iLogicalAddress); |
dd18e809 LOK |
644 | m_configuration.logicalAddresses.primary = iLogicalAddress; |
645 | m_configuration.logicalAddresses.Set(iLogicalAddress); | |
646 | return SetAckMask(m_configuration.logicalAddresses.AckMask()); | |
06775107 | 647 | } |
2abe74eb | 648 | |
06bfd4d7 | 649 | return true; |
abbca718 | 650 | } |
825ddb96 | 651 | |
28fa6c97 LOK |
652 | bool CCECProcessor::SetMenuState(cec_menu_state state, bool bSendUpdate /* = true */) |
653 | { | |
654 | for (uint8_t iPtr = 0; iPtr < 16; iPtr++) | |
655 | { | |
dd18e809 | 656 | if (m_configuration.logicalAddresses[iPtr]) |
28fa6c97 LOK |
657 | m_busDevices[iPtr]->SetMenuState(state); |
658 | } | |
659 | ||
660 | if (bSendUpdate) | |
dd18e809 | 661 | m_busDevices[m_configuration.logicalAddresses.primary]->TransmitMenuState(CECDEVICE_TV); |
28fa6c97 LOK |
662 | |
663 | return true; | |
664 | } | |
665 | ||
bebb19dc | 666 | bool CCECProcessor::SetPhysicalAddress(uint16_t iPhysicalAddress, bool bSendUpdate /* = true */) |
2492216a | 667 | { |
f070564b LOK |
668 | bool bSendActiveView(false); |
669 | bool bReturn(false); | |
4d6f5ac7 | 670 | cec_logical_addresses sendUpdatesTo; |
ded7e7ce | 671 | sendUpdatesTo.Clear(); |
ff684fef | 672 | |
f070564b | 673 | { |
f00ff009 | 674 | CLockObject lock(m_mutex); |
30b4aac0 | 675 | m_configuration.iPhysicalAddress = iPhysicalAddress; |
30a09f32 | 676 | CLibCEC::AddLog(CEC_LOG_DEBUG, "setting physical address to '%4x'", iPhysicalAddress); |
4f362964 | 677 | |
dd18e809 | 678 | if (!m_configuration.logicalAddresses.IsEmpty()) |
f070564b LOK |
679 | { |
680 | bool bWasActiveSource(false); | |
681 | for (uint8_t iPtr = 0; iPtr < 15; iPtr++) | |
dd18e809 | 682 | if (m_configuration.logicalAddresses[iPtr]) |
f070564b LOK |
683 | { |
684 | bWasActiveSource |= m_busDevices[iPtr]->IsActiveSource(); | |
685 | m_busDevices[iPtr]->SetInactiveSource(); | |
686 | m_busDevices[iPtr]->SetPhysicalAddress(iPhysicalAddress); | |
687 | if (bSendUpdate) | |
4d6f5ac7 | 688 | sendUpdatesTo.Set((cec_logical_address)iPtr); |
f070564b LOK |
689 | } |
690 | ||
691 | bSendActiveView = bWasActiveSource && bSendUpdate; | |
692 | bReturn = true; | |
693 | } | |
cc60ab1c | 694 | } |
f070564b | 695 | |
4d6f5ac7 LOK |
696 | for (uint8_t iPtr = 0; iPtr < 15; iPtr++) |
697 | if (sendUpdatesTo[iPtr]) | |
698 | m_busDevices[iPtr]->TransmitPhysicalAddress(); | |
699 | ||
f070564b LOK |
700 | if (bSendActiveView) |
701 | SetActiveView(); | |
702 | ||
32403cc3 LOK |
703 | if (bReturn) |
704 | CLibCEC::ConfigurationChanged(m_configuration); | |
705 | ||
f070564b | 706 | return bReturn; |
1969b140 LOK |
707 | } |
708 | ||
8b7e5ff6 LOK |
709 | bool CCECProcessor::SwitchMonitoring(bool bEnable) |
710 | { | |
5477a250 | 711 | CLibCEC::AddLog(CEC_LOG_NOTICE, "== %s monitoring mode ==", bEnable ? "enabling" : "disabling"); |
8b7e5ff6 | 712 | |
855a3a98 | 713 | { |
f00ff009 | 714 | CLockObject lock(m_mutex); |
855a3a98 | 715 | m_bMonitor = bEnable; |
855a3a98 LOK |
716 | } |
717 | ||
8b7e5ff6 | 718 | if (bEnable) |
06bfd4d7 | 719 | return SetAckMask(0); |
8b7e5ff6 | 720 | else |
dd18e809 | 721 | return SetAckMask(m_configuration.logicalAddresses.AckMask()); |
8b7e5ff6 LOK |
722 | } |
723 | ||
57f45e6c LOK |
724 | bool CCECProcessor::PollDevice(cec_logical_address iAddress) |
725 | { | |
726 | if (iAddress != CECDEVICE_UNKNOWN && m_busDevices[iAddress]) | |
95a73fa7 | 727 | { |
dd18e809 | 728 | return m_configuration.logicalAddresses.primary == CECDEVICE_UNKNOWN ? |
95a73fa7 | 729 | m_busDevices[iAddress]->TransmitPoll(iAddress) : |
dd18e809 | 730 | m_busDevices[m_configuration.logicalAddresses.primary]->TransmitPoll(iAddress); |
95a73fa7 | 731 | } |
57f45e6c LOK |
732 | return false; |
733 | } | |
734 | ||
5c73f7f7 | 735 | uint8_t CCECProcessor::VolumeUp(bool bSendRelease /* = true */) |
04e637f9 LOK |
736 | { |
737 | uint8_t status = 0; | |
37b0c572 | 738 | if (IsPresentDevice(CECDEVICE_AUDIOSYSTEM)) |
5c73f7f7 | 739 | status = ((CCECAudioSystem *)m_busDevices[CECDEVICE_AUDIOSYSTEM])->VolumeUp(bSendRelease); |
04e637f9 LOK |
740 | |
741 | return status; | |
742 | } | |
743 | ||
5c73f7f7 | 744 | uint8_t CCECProcessor::VolumeDown(bool bSendRelease /* = true */) |
04e637f9 LOK |
745 | { |
746 | uint8_t status = 0; | |
37b0c572 | 747 | if (IsPresentDevice(CECDEVICE_AUDIOSYSTEM)) |
5c73f7f7 | 748 | status = ((CCECAudioSystem *)m_busDevices[CECDEVICE_AUDIOSYSTEM])->VolumeDown(bSendRelease); |
04e637f9 LOK |
749 | |
750 | return status; | |
751 | } | |
752 | ||
5c73f7f7 | 753 | uint8_t CCECProcessor::MuteAudio(bool bSendRelease /* = true */) |
04e637f9 LOK |
754 | { |
755 | uint8_t status = 0; | |
37b0c572 | 756 | if (IsPresentDevice(CECDEVICE_AUDIOSYSTEM)) |
5c73f7f7 | 757 | status = ((CCECAudioSystem *)m_busDevices[CECDEVICE_AUDIOSYSTEM])->MuteAudio(bSendRelease); |
04e637f9 LOK |
758 | |
759 | return status; | |
760 | } | |
761 | ||
16b1e052 | 762 | CCECBusDevice *CCECProcessor::GetDeviceByPhysicalAddress(uint16_t iPhysicalAddress, bool bRefresh /* = false */) const |
8ac9c610 | 763 | { |
dd18e809 LOK |
764 | if (m_busDevices[m_configuration.logicalAddresses.primary]->GetPhysicalAddress(false) == iPhysicalAddress) |
765 | return m_busDevices[m_configuration.logicalAddresses.primary]; | |
8ac9c610 | 766 | |
b58d9277 | 767 | CCECBusDevice *device = NULL; |
8ac9c610 LOK |
768 | for (unsigned int iPtr = 0; iPtr < 16; iPtr++) |
769 | { | |
16b1e052 | 770 | if (m_busDevices[iPtr]->GetPhysicalAddress(bRefresh) == iPhysicalAddress) |
8ac9c610 LOK |
771 | { |
772 | device = m_busDevices[iPtr]; | |
773 | break; | |
774 | } | |
775 | } | |
776 | ||
777 | return device; | |
778 | } | |
779 | ||
a9232a79 LOK |
780 | CCECBusDevice *CCECProcessor::GetDeviceByType(cec_device_type type) const |
781 | { | |
782 | CCECBusDevice *device = NULL; | |
783 | ||
7619faad | 784 | for (uint8_t iPtr = 0; iPtr < 16; iPtr++) |
a9232a79 | 785 | { |
dd18e809 | 786 | if (m_busDevices[iPtr]->m_type == type && m_configuration.logicalAddresses[iPtr]) |
a9232a79 LOK |
787 | { |
788 | device = m_busDevices[iPtr]; | |
789 | break; | |
790 | } | |
791 | } | |
792 | ||
793 | return device; | |
794 | } | |
795 | ||
842262d8 LOK |
796 | CCECBusDevice *CCECProcessor::GetPrimaryDevice(void) const |
797 | { | |
798 | CCECBusDevice *device(NULL); | |
dd18e809 | 799 | cec_logical_address primary = m_configuration.logicalAddresses.primary; |
842262d8 LOK |
800 | if (primary != CECDEVICE_UNKNOWN) |
801 | device = m_busDevices[primary]; | |
802 | return device; | |
803 | } | |
804 | ||
6a1c0009 LOK |
805 | cec_version CCECProcessor::GetDeviceCecVersion(cec_logical_address iAddress) |
806 | { | |
807 | return m_busDevices[iAddress]->GetCecVersion(); | |
808 | } | |
809 | ||
ed21be2a LOK |
810 | cec_osd_name CCECProcessor::GetDeviceOSDName(cec_logical_address iAddress) |
811 | { | |
812 | CStdString strOSDName = m_busDevices[iAddress]->GetOSDName(); | |
813 | cec_osd_name retVal; | |
814 | ||
815 | snprintf(retVal.name, sizeof(retVal.name), "%s", strOSDName.c_str()); | |
816 | retVal.device = iAddress; | |
817 | ||
818 | return retVal; | |
819 | } | |
820 | ||
a3269a0a LOK |
821 | bool CCECProcessor::GetDeviceMenuLanguage(cec_logical_address iAddress, cec_menu_language *language) |
822 | { | |
cc60ab1c LOK |
823 | if (m_busDevices[iAddress]) |
824 | { | |
825 | *language = m_busDevices[iAddress]->GetMenuLanguage(); | |
5744fbba | 826 | return (strcmp(language->language, "???") != 0); |
cc60ab1c LOK |
827 | } |
828 | return false; | |
a3269a0a LOK |
829 | } |
830 | ||
44c74256 LOK |
831 | uint64_t CCECProcessor::GetDeviceVendorId(cec_logical_address iAddress) |
832 | { | |
cc60ab1c LOK |
833 | if (m_busDevices[iAddress]) |
834 | return m_busDevices[iAddress]->GetVendorId(); | |
835 | return false; | |
44c74256 LOK |
836 | } |
837 | ||
eab72c40 LOK |
838 | uint16_t CCECProcessor::GetDevicePhysicalAddress(cec_logical_address iAddress) |
839 | { | |
840 | if (m_busDevices[iAddress]) | |
841 | return m_busDevices[iAddress]->GetPhysicalAddress(false); | |
842 | return false; | |
843 | } | |
844 | ||
e55f3f70 LOK |
845 | cec_power_status CCECProcessor::GetDevicePowerStatus(cec_logical_address iAddress) |
846 | { | |
cc60ab1c LOK |
847 | if (m_busDevices[iAddress]) |
848 | return m_busDevices[iAddress]->GetPowerStatus(); | |
849 | return CEC_POWER_STATUS_UNKNOWN; | |
e55f3f70 LOK |
850 | } |
851 | ||
b4b1b49b LOK |
852 | cec_logical_address CCECProcessor::GetActiveSource(void) |
853 | { | |
854 | for (uint8_t iPtr = 0; iPtr <= 11; iPtr++) | |
855 | { | |
856 | if (m_busDevices[iPtr]->IsActiveSource()) | |
857 | return (cec_logical_address)iPtr; | |
858 | } | |
859 | ||
860 | return CECDEVICE_UNKNOWN; | |
861 | } | |
862 | ||
863 | bool CCECProcessor::IsActiveSource(cec_logical_address iAddress) | |
864 | { | |
865 | return m_busDevices[iAddress]->IsActiveSource(); | |
866 | } | |
867 | ||
8d84e2c0 | 868 | bool CCECProcessor::Transmit(const cec_command &data) |
825ddb96 | 869 | { |
dd18e809 | 870 | if (m_configuration.logicalAddresses[(uint8_t)data.destination]) |
c4287bcd LOK |
871 | { |
872 | CLibCEC::AddLog(CEC_LOG_WARNING, "not sending data to myself!"); | |
873 | return false; | |
874 | } | |
875 | ||
7cf8ba15 | 876 | uint8_t iMaxTries(0); |
eb35e4ca | 877 | { |
7bb4ed43 | 878 | CLockObject lock(m_mutex); |
44a1d92a LOK |
879 | if (IsStopped()) |
880 | return false; | |
7bb4ed43 | 881 | LogOutput(data); |
5f316715 | 882 | m_iLastTransmission = GetTimeMs(); |
44195125 | 883 | if (!m_communication || !m_communication->IsOpen()) |
f9e01dac LOK |
884 | { |
885 | CLibCEC::AddLog(CEC_LOG_ERROR, "cannot transmit command: connection closed"); | |
7bb4ed43 | 886 | return false; |
f9e01dac | 887 | } |
7cf8ba15 | 888 | iMaxTries = m_busDevices[data.initiator]->GetHandler()->GetTransmitRetries() + 1; |
2abe74eb LOK |
889 | } |
890 | ||
7cf8ba15 LOK |
891 | return m_communication->Write(data, iMaxTries, m_iLineTimeout, m_iRetryLineTimeout) |
892 | == ADAPTER_MESSAGE_STATE_SENT_ACKED; | |
825ddb96 | 893 | } |
abbca718 | 894 | |
22b4e74a | 895 | void CCECProcessor::TransmitAbort(cec_logical_address address, cec_opcode opcode, cec_abort_reason reason /* = CEC_ABORT_REASON_UNRECOGNIZED_OPCODE */) |
abbca718 | 896 | { |
5477a250 | 897 | CLibCEC::AddLog(CEC_LOG_DEBUG, "<< transmitting abort message"); |
9dee1670 | 898 | |
06a1f7ce | 899 | cec_command command; |
f8513317 | 900 | // TODO |
dd18e809 | 901 | cec_command::Format(command, m_configuration.logicalAddresses.primary, address, CEC_OPCODE_FEATURE_ABORT); |
ab1469a0 LOK |
902 | command.parameters.PushBack((uint8_t)opcode); |
903 | command.parameters.PushBack((uint8_t)reason); | |
9dee1670 LOK |
904 | |
905 | Transmit(command); | |
abbca718 LOK |
906 | } |
907 | ||
b1f94db1 | 908 | void CCECProcessor::ParseCommand(const cec_command &command) |
abbca718 | 909 | { |
e9de9629 | 910 | CStdString dataStr; |
1d3ca3de | 911 | dataStr.Format(">> %1x%1x:%02x", command.initiator, command.destination, command.opcode); |
e9de9629 LOK |
912 | for (uint8_t iPtr = 0; iPtr < command.parameters.size; iPtr++) |
913 | dataStr.AppendFormat(":%02x", (unsigned int)command.parameters[iPtr]); | |
5477a250 | 914 | CLibCEC::AddLog(CEC_LOG_TRAFFIC, dataStr.c_str()); |
dc113aca | 915 | |
7871d66e | 916 | if (!m_bMonitor && command.initiator >= CECDEVICE_TV && command.initiator <= CECDEVICE_BROADCAST) |
e9de9629 | 917 | m_busDevices[(uint8_t)command.initiator]->HandleCommand(command); |
dc113aca LOK |
918 | } |
919 | ||
6d858ba4 LOK |
920 | cec_logical_addresses CCECProcessor::GetActiveDevices(void) |
921 | { | |
922 | cec_logical_addresses addresses; | |
988de7b9 | 923 | addresses.Clear(); |
6d858ba4 LOK |
924 | for (unsigned int iPtr = 0; iPtr < 15; iPtr++) |
925 | { | |
926 | if (m_busDevices[iPtr]->GetStatus() == CEC_DEVICE_STATUS_PRESENT) | |
927 | addresses.Set((cec_logical_address) iPtr); | |
928 | } | |
929 | return addresses; | |
930 | } | |
931 | ||
37b0c572 | 932 | bool CCECProcessor::IsPresentDevice(cec_logical_address address) |
6d858ba4 LOK |
933 | { |
934 | return m_busDevices[address]->GetStatus() == CEC_DEVICE_STATUS_PRESENT; | |
935 | } | |
936 | ||
37b0c572 | 937 | bool CCECProcessor::IsPresentDeviceType(cec_device_type type) |
6d858ba4 | 938 | { |
6d858ba4 | 939 | for (unsigned int iPtr = 0; iPtr < 15; iPtr++) |
2813bd07 LOK |
940 | { |
941 | if (m_busDevices[iPtr]->GetType() == type && m_busDevices[iPtr]->GetStatus() == CEC_DEVICE_STATUS_PRESENT) | |
6d858ba4 | 942 | return true; |
2813bd07 LOK |
943 | } |
944 | ||
6d858ba4 LOK |
945 | return false; |
946 | } | |
947 | ||
0f23c85c LOK |
948 | uint16_t CCECProcessor::GetPhysicalAddress(void) const |
949 | { | |
dd18e809 LOK |
950 | if (!m_configuration.logicalAddresses.IsEmpty() && m_busDevices[m_configuration.logicalAddresses.primary]) |
951 | return m_busDevices[m_configuration.logicalAddresses.primary]->GetPhysicalAddress(false); | |
cc60ab1c | 952 | return false; |
0f23c85c LOK |
953 | } |
954 | ||
06bfd4d7 LOK |
955 | bool CCECProcessor::SetAckMask(uint16_t iMask) |
956 | { | |
5dcf9f25 | 957 | return m_communication->SetAckMask(iMask); |
06bfd4d7 | 958 | } |
a33794d8 | 959 | |
4bec9d79 | 960 | bool CCECProcessor::TransmitKeypress(cec_logical_address iDestination, cec_user_control_code key, bool bWait /* = true */) |
a33794d8 | 961 | { |
86869f8f | 962 | return m_busDevices[iDestination]->TransmitKeypress(key, bWait); |
a33794d8 LOK |
963 | } |
964 | ||
4bec9d79 | 965 | bool CCECProcessor::TransmitKeyRelease(cec_logical_address iDestination, bool bWait /* = true */) |
a33794d8 | 966 | { |
86869f8f | 967 | return m_busDevices[iDestination]->TransmitKeyRelease(bWait); |
a33794d8 | 968 | } |
7c63a480 | 969 | |
8670c970 LOK |
970 | bool CCECProcessor::EnablePhysicalAddressDetection(void) |
971 | { | |
972 | CLibCEC::AddLog(CEC_LOG_WARNING, "deprecated method %s called", __FUNCTION__); | |
973 | uint16_t iPhysicalAddress = m_communication->GetPhysicalAddress(); | |
974 | if (iPhysicalAddress != 0) | |
975 | { | |
976 | m_configuration.bAutodetectAddress = 1; | |
977 | m_configuration.iPhysicalAddress = iPhysicalAddress; | |
978 | m_configuration.baseDevice = CECDEVICE_UNKNOWN; | |
979 | m_configuration.iHDMIPort = 0; | |
980 | return SetPhysicalAddress(iPhysicalAddress); | |
981 | } | |
982 | return false; | |
983 | } | |
984 | ||
ca27e6cf LOK |
985 | bool CCECProcessor::StandbyDevices(cec_logical_address address /* = CECDEVICE_BROADCAST */) |
986 | { | |
987 | if (address == CECDEVICE_BROADCAST && m_configuration.clientVersion >= CEC_CLIENT_VERSION_1_5_0) | |
988 | { | |
989 | bool bReturn(true); | |
990 | for (uint8_t iPtr = 0; iPtr <= 0xF; iPtr++) | |
991 | { | |
992 | if (m_configuration.powerOffDevices[iPtr]) | |
993 | bReturn &= m_busDevices[iPtr]->Standby(); | |
994 | } | |
995 | return bReturn; | |
996 | } | |
997 | ||
998 | return m_busDevices[address]->Standby(); | |
999 | } | |
1000 | ||
1001 | bool CCECProcessor::PowerOnDevices(cec_logical_address address /* = CECDEVICE_BROADCAST */) | |
1002 | { | |
1003 | if (address == CECDEVICE_BROADCAST && m_configuration.clientVersion >= CEC_CLIENT_VERSION_1_5_0) | |
1004 | { | |
1005 | bool bReturn(true); | |
1006 | for (uint8_t iPtr = 0; iPtr <= 0xF; iPtr++) | |
1007 | { | |
1008 | if (m_configuration.powerOffDevices[iPtr]) | |
1009 | bReturn &= m_busDevices[iPtr]->PowerOn(); | |
1010 | } | |
1011 | return bReturn; | |
1012 | } | |
1013 | ||
1014 | return m_busDevices[address]->PowerOn(); | |
1015 | } | |
1016 | ||
3e61b350 LOK |
1017 | const char *CCECProcessor::ToString(const cec_device_type type) |
1018 | { | |
1019 | switch (type) | |
1020 | { | |
1021 | case CEC_DEVICE_TYPE_AUDIO_SYSTEM: | |
1022 | return "audio system"; | |
1023 | case CEC_DEVICE_TYPE_PLAYBACK_DEVICE: | |
1024 | return "playback device"; | |
1025 | case CEC_DEVICE_TYPE_RECORDING_DEVICE: | |
1026 | return "recording device"; | |
1027 | case CEC_DEVICE_TYPE_RESERVED: | |
1028 | return "reserved"; | |
1029 | case CEC_DEVICE_TYPE_TUNER: | |
1030 | return "tuner"; | |
1031 | case CEC_DEVICE_TYPE_TV: | |
1032 | return "TV"; | |
1033 | default: | |
1034 | return "unknown"; | |
1035 | } | |
1036 | } | |
1037 | ||
03ae897d LOK |
1038 | const char *CCECProcessor::ToString(const cec_menu_state state) |
1039 | { | |
1040 | switch (state) | |
1041 | { | |
1042 | case CEC_MENU_STATE_ACTIVATED: | |
1043 | return "activated"; | |
1044 | case CEC_MENU_STATE_DEACTIVATED: | |
1045 | return "deactivated"; | |
1046 | default: | |
1047 | return "unknown"; | |
1048 | } | |
1049 | } | |
1050 | ||
1051 | const char *CCECProcessor::ToString(const cec_version version) | |
1052 | { | |
1053 | switch (version) | |
1054 | { | |
1055 | case CEC_VERSION_1_2: | |
1056 | return "1.2"; | |
1057 | case CEC_VERSION_1_2A: | |
1058 | return "1.2a"; | |
1059 | case CEC_VERSION_1_3: | |
1060 | return "1.3"; | |
1061 | case CEC_VERSION_1_3A: | |
1062 | return "1.3a"; | |
1063 | case CEC_VERSION_1_4: | |
1064 | return "1.4"; | |
1065 | default: | |
1066 | return "unknown"; | |
1067 | } | |
1068 | } | |
1069 | ||
1070 | const char *CCECProcessor::ToString(const cec_power_status status) | |
1071 | { | |
1072 | switch (status) | |
1073 | { | |
1074 | case CEC_POWER_STATUS_ON: | |
1075 | return "on"; | |
1076 | case CEC_POWER_STATUS_STANDBY: | |
1077 | return "standby"; | |
1078 | case CEC_POWER_STATUS_IN_TRANSITION_ON_TO_STANDBY: | |
1079 | return "in transition from on to standby"; | |
1080 | case CEC_POWER_STATUS_IN_TRANSITION_STANDBY_TO_ON: | |
1081 | return "in transition from standby to on"; | |
1082 | default: | |
1083 | return "unknown"; | |
1084 | } | |
1085 | } | |
1086 | ||
1087 | const char *CCECProcessor::ToString(const cec_logical_address address) | |
1088 | { | |
1089 | switch(address) | |
1090 | { | |
1091 | case CECDEVICE_AUDIOSYSTEM: | |
1092 | return "Audio"; | |
1093 | case CECDEVICE_BROADCAST: | |
1094 | return "Broadcast"; | |
1095 | case CECDEVICE_FREEUSE: | |
1096 | return "Free use"; | |
1097 | case CECDEVICE_PLAYBACKDEVICE1: | |
1098 | return "Playback 1"; | |
1099 | case CECDEVICE_PLAYBACKDEVICE2: | |
1100 | return "Playback 2"; | |
1101 | case CECDEVICE_PLAYBACKDEVICE3: | |
1102 | return "Playback 3"; | |
1103 | case CECDEVICE_RECORDINGDEVICE1: | |
1104 | return "Recorder 1"; | |
1105 | case CECDEVICE_RECORDINGDEVICE2: | |
1106 | return "Recorder 2"; | |
1107 | case CECDEVICE_RECORDINGDEVICE3: | |
1108 | return "Recorder 3"; | |
1109 | case CECDEVICE_RESERVED1: | |
1110 | return "Reserved 1"; | |
1111 | case CECDEVICE_RESERVED2: | |
1112 | return "Reserved 2"; | |
1113 | case CECDEVICE_TUNER1: | |
1114 | return "Tuner 1"; | |
1115 | case CECDEVICE_TUNER2: | |
1116 | return "Tuner 2"; | |
1117 | case CECDEVICE_TUNER3: | |
1118 | return "Tuner 3"; | |
1119 | case CECDEVICE_TUNER4: | |
1120 | return "Tuner 4"; | |
1121 | case CECDEVICE_TV: | |
1122 | return "TV"; | |
1123 | default: | |
1124 | return "unknown"; | |
1125 | } | |
1126 | } | |
1127 | ||
1128 | const char *CCECProcessor::ToString(const cec_deck_control_mode mode) | |
1129 | { | |
1130 | switch (mode) | |
1131 | { | |
1132 | case CEC_DECK_CONTROL_MODE_SKIP_FORWARD_WIND: | |
1133 | return "skip forward wind"; | |
1134 | case CEC_DECK_CONTROL_MODE_EJECT: | |
1135 | return "eject"; | |
1136 | case CEC_DECK_CONTROL_MODE_SKIP_REVERSE_REWIND: | |
1137 | return "reverse rewind"; | |
1138 | case CEC_DECK_CONTROL_MODE_STOP: | |
1139 | return "stop"; | |
1140 | default: | |
1141 | return "unknown"; | |
1142 | } | |
1143 | } | |
1144 | ||
1145 | const char *CCECProcessor::ToString(const cec_deck_info status) | |
1146 | { | |
1147 | switch (status) | |
1148 | { | |
1149 | case CEC_DECK_INFO_PLAY: | |
1150 | return "play"; | |
1151 | case CEC_DECK_INFO_RECORD: | |
1152 | return "record"; | |
1153 | case CEC_DECK_INFO_PLAY_REVERSE: | |
1154 | return "play reverse"; | |
1155 | case CEC_DECK_INFO_STILL: | |
1156 | return "still"; | |
1157 | case CEC_DECK_INFO_SLOW: | |
1158 | return "slow"; | |
1159 | case CEC_DECK_INFO_SLOW_REVERSE: | |
1160 | return "slow reverse"; | |
1161 | case CEC_DECK_INFO_FAST_FORWARD: | |
1162 | return "fast forward"; | |
1163 | case CEC_DECK_INFO_FAST_REVERSE: | |
1164 | return "fast reverse"; | |
1165 | case CEC_DECK_INFO_NO_MEDIA: | |
1166 | return "no media"; | |
1167 | case CEC_DECK_INFO_STOP: | |
1168 | return "stop"; | |
1169 | case CEC_DECK_INFO_SKIP_FORWARD_WIND: | |
1170 | return "info skip forward wind"; | |
1171 | case CEC_DECK_INFO_SKIP_REVERSE_REWIND: | |
1172 | return "info skip reverse rewind"; | |
1173 | case CEC_DECK_INFO_INDEX_SEARCH_FORWARD: | |
1174 | return "info index search forward"; | |
1175 | case CEC_DECK_INFO_INDEX_SEARCH_REVERSE: | |
1176 | return "info index search reverse"; | |
1177 | case CEC_DECK_INFO_OTHER_STATUS: | |
1178 | return "other"; | |
1179 | default: | |
1180 | return "unknown"; | |
1181 | } | |
1182 | } | |
1183 | ||
1184 | const char *CCECProcessor::ToString(const cec_opcode opcode) | |
1185 | { | |
1186 | switch (opcode) | |
1187 | { | |
1188 | case CEC_OPCODE_ACTIVE_SOURCE: | |
1189 | return "active source"; | |
1190 | case CEC_OPCODE_IMAGE_VIEW_ON: | |
1191 | return "image view on"; | |
1192 | case CEC_OPCODE_TEXT_VIEW_ON: | |
1193 | return "text view on"; | |
1194 | case CEC_OPCODE_INACTIVE_SOURCE: | |
1195 | return "inactive source"; | |
1196 | case CEC_OPCODE_REQUEST_ACTIVE_SOURCE: | |
1197 | return "request active source"; | |
1198 | case CEC_OPCODE_ROUTING_CHANGE: | |
1199 | return "routing change"; | |
1200 | case CEC_OPCODE_ROUTING_INFORMATION: | |
1201 | return "routing information"; | |
1202 | case CEC_OPCODE_SET_STREAM_PATH: | |
1203 | return "set stream path"; | |
1204 | case CEC_OPCODE_STANDBY: | |
1205 | return "standby"; | |
1206 | case CEC_OPCODE_RECORD_OFF: | |
1207 | return "record off"; | |
1208 | case CEC_OPCODE_RECORD_ON: | |
1209 | return "record on"; | |
1210 | case CEC_OPCODE_RECORD_STATUS: | |
1211 | return "record status"; | |
1212 | case CEC_OPCODE_RECORD_TV_SCREEN: | |
1213 | return "record tv screen"; | |
1214 | case CEC_OPCODE_CLEAR_ANALOGUE_TIMER: | |
1215 | return "clear analogue timer"; | |
1216 | case CEC_OPCODE_CLEAR_DIGITAL_TIMER: | |
1217 | return "clear digital timer"; | |
1218 | case CEC_OPCODE_CLEAR_EXTERNAL_TIMER: | |
1219 | return "clear external timer"; | |
1220 | case CEC_OPCODE_SET_ANALOGUE_TIMER: | |
1221 | return "set analogue timer"; | |
1222 | case CEC_OPCODE_SET_DIGITAL_TIMER: | |
1223 | return "set digital timer"; | |
1224 | case CEC_OPCODE_SET_EXTERNAL_TIMER: | |
1225 | return "set external timer"; | |
1226 | case CEC_OPCODE_SET_TIMER_PROGRAM_TITLE: | |
1227 | return "set timer program title"; | |
1228 | case CEC_OPCODE_TIMER_CLEARED_STATUS: | |
1229 | return "timer cleared status"; | |
1230 | case CEC_OPCODE_TIMER_STATUS: | |
1231 | return "timer status"; | |
1232 | case CEC_OPCODE_CEC_VERSION: | |
1233 | return "cec version"; | |
1234 | case CEC_OPCODE_GET_CEC_VERSION: | |
1235 | return "get cec version"; | |
1236 | case CEC_OPCODE_GIVE_PHYSICAL_ADDRESS: | |
1237 | return "give physical address"; | |
1238 | case CEC_OPCODE_GET_MENU_LANGUAGE: | |
1239 | return "get menu language"; | |
1240 | case CEC_OPCODE_REPORT_PHYSICAL_ADDRESS: | |
1241 | return "report physical address"; | |
1242 | case CEC_OPCODE_SET_MENU_LANGUAGE: | |
1243 | return "set menu language"; | |
1244 | case CEC_OPCODE_DECK_CONTROL: | |
1245 | return "deck control"; | |
1246 | case CEC_OPCODE_DECK_STATUS: | |
1247 | return "deck status"; | |
1248 | case CEC_OPCODE_GIVE_DECK_STATUS: | |
1249 | return "give deck status"; | |
1250 | case CEC_OPCODE_PLAY: | |
1251 | return "play"; | |
1252 | case CEC_OPCODE_GIVE_TUNER_DEVICE_STATUS: | |
1253 | return "give tuner status"; | |
1254 | case CEC_OPCODE_SELECT_ANALOGUE_SERVICE: | |
1255 | return "select analogue service"; | |
1256 | case CEC_OPCODE_SELECT_DIGITAL_SERVICE: | |
1257 | return "set digital service"; | |
1258 | case CEC_OPCODE_TUNER_DEVICE_STATUS: | |
1259 | return "tuner device status"; | |
1260 | case CEC_OPCODE_TUNER_STEP_DECREMENT: | |
1261 | return "tuner step decrement"; | |
1262 | case CEC_OPCODE_TUNER_STEP_INCREMENT: | |
1263 | return "tuner step increment"; | |
1264 | case CEC_OPCODE_DEVICE_VENDOR_ID: | |
1265 | return "device vendor id"; | |
1266 | case CEC_OPCODE_GIVE_DEVICE_VENDOR_ID: | |
1267 | return "give device vendor id"; | |
1268 | case CEC_OPCODE_VENDOR_COMMAND: | |
1269 | return "vendor command"; | |
1270 | case CEC_OPCODE_VENDOR_COMMAND_WITH_ID: | |
1271 | return "vendor command with id"; | |
1272 | case CEC_OPCODE_VENDOR_REMOTE_BUTTON_DOWN: | |
1273 | return "vendor remote button down"; | |
1274 | case CEC_OPCODE_VENDOR_REMOTE_BUTTON_UP: | |
1275 | return "vendor remote button up"; | |
1276 | case CEC_OPCODE_SET_OSD_STRING: | |
1277 | return "set osd string"; | |
1278 | case CEC_OPCODE_GIVE_OSD_NAME: | |
1279 | return "give osd name"; | |
1280 | case CEC_OPCODE_SET_OSD_NAME: | |
1281 | return "set osd name"; | |
1282 | case CEC_OPCODE_MENU_REQUEST: | |
1283 | return "menu request"; | |
1284 | case CEC_OPCODE_MENU_STATUS: | |
1285 | return "menu status"; | |
1286 | case CEC_OPCODE_USER_CONTROL_PRESSED: | |
1287 | return "user control pressed"; | |
1288 | case CEC_OPCODE_USER_CONTROL_RELEASE: | |
1289 | return "user control release"; | |
1290 | case CEC_OPCODE_GIVE_DEVICE_POWER_STATUS: | |
1291 | return "give device power status"; | |
1292 | case CEC_OPCODE_REPORT_POWER_STATUS: | |
1293 | return "report power status"; | |
1294 | case CEC_OPCODE_FEATURE_ABORT: | |
1295 | return "feature abort"; | |
1296 | case CEC_OPCODE_ABORT: | |
1297 | return "abort"; | |
1298 | case CEC_OPCODE_GIVE_AUDIO_STATUS: | |
1299 | return "give audio status"; | |
1300 | case CEC_OPCODE_GIVE_SYSTEM_AUDIO_MODE_STATUS: | |
1301 | return "give audio mode status"; | |
1302 | case CEC_OPCODE_REPORT_AUDIO_STATUS: | |
1303 | return "report audio status"; | |
1304 | case CEC_OPCODE_SET_SYSTEM_AUDIO_MODE: | |
1305 | return "set system audio mode"; | |
1306 | case CEC_OPCODE_SYSTEM_AUDIO_MODE_REQUEST: | |
1307 | return "system audio mode request"; | |
1308 | case CEC_OPCODE_SYSTEM_AUDIO_MODE_STATUS: | |
1309 | return "system audio mode status"; | |
1310 | case CEC_OPCODE_SET_AUDIO_RATE: | |
1311 | return "set audio rate"; | |
24dd566c LOK |
1312 | case CEC_OPCODE_NONE: |
1313 | return "poll"; | |
03ae897d LOK |
1314 | default: |
1315 | return "UNKNOWN"; | |
1316 | } | |
1317 | } | |
1318 | ||
1319 | const char *CCECProcessor::ToString(const cec_system_audio_status mode) | |
1320 | { | |
1321 | switch(mode) | |
1322 | { | |
1323 | case CEC_SYSTEM_AUDIO_STATUS_ON: | |
1324 | return "on"; | |
1325 | case CEC_SYSTEM_AUDIO_STATUS_OFF: | |
1326 | return "off"; | |
1327 | default: | |
1328 | return "unknown"; | |
1329 | } | |
1330 | } | |
1331 | ||
1de6617c | 1332 | const char *CCECProcessor::ToString(const cec_audio_status UNUSED(status)) |
03ae897d LOK |
1333 | { |
1334 | // TODO this is a mask | |
1335 | return "TODO"; | |
1336 | } | |
1337 | ||
1338 | const char *CCECProcessor::ToString(const cec_vendor_id vendor) | |
1339 | { | |
1340 | switch (vendor) | |
1341 | { | |
1342 | case CEC_VENDOR_SAMSUNG: | |
1343 | return "Samsung"; | |
1344 | case CEC_VENDOR_LG: | |
1345 | return "LG"; | |
1346 | case CEC_VENDOR_PANASONIC: | |
1347 | return "Panasonic"; | |
1348 | case CEC_VENDOR_PIONEER: | |
1349 | return "Pioneer"; | |
1350 | case CEC_VENDOR_ONKYO: | |
1351 | return "Onkyo"; | |
1352 | case CEC_VENDOR_YAMAHA: | |
1353 | return "Yamaha"; | |
ec0deac1 LOK |
1354 | case CEC_VENDOR_PHILIPS: |
1355 | return "Philips"; | |
1a87cacc LOK |
1356 | case CEC_VENDOR_SONY: |
1357 | return "Sony"; | |
26555d6b LOK |
1358 | case CEC_VENDOR_TOSHIBA: |
1359 | return "Toshiba"; | |
03ae897d LOK |
1360 | default: |
1361 | return "Unknown"; | |
1362 | } | |
1363 | } | |
1364 | ||
caca2d81 LOK |
1365 | const char *CCECProcessor::ToString(const cec_client_version version) |
1366 | { | |
1367 | switch (version) | |
1368 | { | |
1369 | case CEC_CLIENT_VERSION_PRE_1_5: | |
1370 | return "pre-1.5"; | |
1371 | case CEC_CLIENT_VERSION_1_5_0: | |
1372 | return "1.5.0"; | |
41e3372a LOK |
1373 | case CEC_CLIENT_VERSION_1_5_1: |
1374 | return "1.5.1"; | |
2e82cff0 LOK |
1375 | case CEC_CLIENT_VERSION_1_5_2: |
1376 | return "1.5.2"; | |
caca2d81 LOK |
1377 | default: |
1378 | return "Unknown"; | |
1379 | } | |
1380 | } | |
1381 | ||
3efda01a LOK |
1382 | const char *CCECProcessor::ToString(const cec_server_version version) |
1383 | { | |
1384 | switch (version) | |
1385 | { | |
1386 | case CEC_SERVER_VERSION_PRE_1_5: | |
1387 | return "pre-1.5"; | |
1388 | case CEC_SERVER_VERSION_1_5_0: | |
1389 | return "1.5.0"; | |
41e3372a | 1390 | case CEC_SERVER_VERSION_1_5_1: |
2e82cff0 LOK |
1391 | return "1.5.1"; |
1392 | case CEC_SERVER_VERSION_1_5_2: | |
1393 | return "1.5.2"; | |
3efda01a LOK |
1394 | default: |
1395 | return "Unknown"; | |
1396 | } | |
1397 | } | |
1398 | ||
7c63a480 LOK |
1399 | void *CCECBusScan::Process(void) |
1400 | { | |
1401 | CCECBusDevice *device(NULL); | |
fe6f8e37 | 1402 | uint8_t iCounter(0); |
5f316715 | 1403 | |
5e5637c6 | 1404 | while (!IsStopped()) |
7c63a480 | 1405 | { |
bdb0f7f4 | 1406 | if (++iCounter < 10) |
fe6f8e37 LOK |
1407 | { |
1408 | Sleep(1000); | |
1409 | continue; | |
1410 | } | |
5f316715 | 1411 | for (unsigned int iPtr = 0; iPtr <= 11 && !IsStopped(); iPtr++) |
7c63a480 | 1412 | { |
5f316715 LOK |
1413 | device = m_processor->m_busDevices[iPtr]; |
1414 | WaitUntilIdle(); | |
1415 | if (device && device->GetStatus(true) == CEC_DEVICE_STATUS_PRESENT) | |
5e5637c6 | 1416 | { |
5f316715 LOK |
1417 | WaitUntilIdle(); |
1418 | if (!IsStopped()) | |
1419 | device->GetVendorId(); | |
1420 | ||
1421 | WaitUntilIdle(); | |
1422 | if (!IsStopped()) | |
1423 | device->GetPowerStatus(true); | |
5e5637c6 | 1424 | } |
7c63a480 LOK |
1425 | } |
1426 | } | |
5f316715 | 1427 | |
7c63a480 LOK |
1428 | return NULL; |
1429 | } | |
1113cb7d | 1430 | |
5f316715 LOK |
1431 | void CCECBusScan::WaitUntilIdle(void) |
1432 | { | |
1433 | if (IsStopped()) | |
1434 | return; | |
1435 | ||
701f753b | 1436 | int32_t iWaitTime = 3000 - (int32_t)(GetTimeMs() - m_processor->GetLastTransmission()); |
5f316715 LOK |
1437 | while (iWaitTime > 0) |
1438 | { | |
1439 | Sleep(iWaitTime); | |
701f753b | 1440 | iWaitTime = 3000 - (int32_t)(GetTimeMs() - m_processor->GetLastTransmission()); |
5f316715 LOK |
1441 | } |
1442 | } | |
1443 | ||
a2198e5e | 1444 | bool CCECProcessor::StartBootloader(const char *strPort /* = NULL */) |
1113cb7d | 1445 | { |
a2198e5e LOK |
1446 | if (!m_communication && strPort) |
1447 | { | |
1448 | bool bReturn(false); | |
1449 | IAdapterCommunication *comm = new CUSBCECAdapterCommunication(this, strPort); | |
1450 | CTimeout timeout(10000); | |
1451 | int iConnectTry(0); | |
1452 | while (timeout.TimeLeft() > 0 && (bReturn = comm->Open(NULL, (timeout.TimeLeft() / CEC_CONNECT_TRIES)), true) == false) | |
1453 | { | |
1454 | CLibCEC::AddLog(CEC_LOG_ERROR, "could not open a connection (try %d)", ++iConnectTry); | |
1455 | comm->Close(); | |
1456 | Sleep(500); | |
1457 | } | |
1458 | if (comm->IsOpen()) | |
1459 | { | |
1460 | bReturn = comm->StartBootloader(); | |
1461 | delete comm; | |
1462 | } | |
1463 | return bReturn; | |
1464 | } | |
1465 | else | |
1466 | { | |
1467 | return m_communication->StartBootloader(); | |
1468 | } | |
1113cb7d LOK |
1469 | } |
1470 | ||
1471 | bool CCECProcessor::PingAdapter(void) | |
1472 | { | |
1473 | return m_communication->PingAdapter(); | |
1474 | } | |
6729ac71 LOK |
1475 | |
1476 | void CCECProcessor::HandlePoll(cec_logical_address initiator, cec_logical_address destination) | |
1477 | { | |
0cfdeb5a | 1478 | m_busDevices[initiator]->HandlePoll(destination); |
6729ac71 LOK |
1479 | } |
1480 | ||
7bb4ed43 | 1481 | bool CCECProcessor::HandleReceiveFailed(cec_logical_address initiator) |
6729ac71 | 1482 | { |
0cfdeb5a | 1483 | return !m_busDevices[initiator]->HandleReceiveFailed(); |
6729ac71 | 1484 | } |
f42d3e0f LOK |
1485 | |
1486 | bool CCECProcessor::SetStreamPath(uint16_t iPhysicalAddress) | |
1487 | { | |
1488 | // stream path changes are sent by the TV | |
1489 | return m_busDevices[CECDEVICE_TV]->GetHandler()->TransmitSetStreamPath(iPhysicalAddress); | |
1490 | } | |
d40928b5 | 1491 | |
30b4aac0 LOK |
1492 | bool CCECProcessor::SetConfiguration(const libcec_configuration *configuration) |
1493 | { | |
30a09f32 | 1494 | bool bReinit(false); |
30b4aac0 | 1495 | CCECBusDevice *primary = IsRunning() ? GetPrimaryDevice() : NULL; |
30a09f32 | 1496 | cec_device_type oldPrimaryType = primary ? primary->GetType() : CEC_DEVICE_TYPE_RECORDING_DEVICE; |
f0154449 | 1497 | m_configuration.clientVersion = configuration->clientVersion; |
30b4aac0 LOK |
1498 | |
1499 | // client version 1.5.0 | |
1500 | ||
1501 | // device types | |
8670c970 | 1502 | bool bDeviceTypeChanged = IsRunning () && m_configuration.deviceTypes != configuration->deviceTypes; |
30b4aac0 LOK |
1503 | m_configuration.deviceTypes = configuration->deviceTypes; |
1504 | ||
30a09f32 LOK |
1505 | bool bPhysicalAddressChanged(false); |
1506 | ||
8670c970 | 1507 | // autodetect address |
30a09f32 LOK |
1508 | bool bPhysicalAutodetected(false); |
1509 | if (IsRunning() && configuration->bAutodetectAddress == 1) | |
8670c970 | 1510 | { |
30a09f32 LOK |
1511 | uint16_t iPhysicalAddress = m_communication->GetPhysicalAddress(); |
1512 | if (iPhysicalAddress != 0) | |
1513 | { | |
1514 | if (IsRunning()) | |
1515 | CLibCEC::AddLog(CEC_LOG_DEBUG, "%s - autodetected physical address '%4x'", __FUNCTION__, iPhysicalAddress); | |
1516 | bPhysicalAddressChanged = (m_configuration.iPhysicalAddress != iPhysicalAddress); | |
1517 | m_configuration.iPhysicalAddress = iPhysicalAddress; | |
1518 | m_configuration.iHDMIPort = 0; | |
1519 | m_configuration.baseDevice = CECDEVICE_UNKNOWN; | |
1520 | bPhysicalAutodetected = true; | |
1521 | } | |
8670c970 LOK |
1522 | } |
1523 | ||
30b4aac0 | 1524 | // physical address |
8670c970 LOK |
1525 | if (!bPhysicalAutodetected) |
1526 | { | |
30a09f32 LOK |
1527 | if (configuration->iPhysicalAddress != 0) |
1528 | bPhysicalAddressChanged = IsRunning() && m_configuration.iPhysicalAddress != configuration->iPhysicalAddress; | |
1529 | if (IsRunning()) | |
1530 | CLibCEC::AddLog(CEC_LOG_DEBUG, "%s - using physical address '%4x'", __FUNCTION__, configuration->iPhysicalAddress); | |
8670c970 LOK |
1531 | m_configuration.iPhysicalAddress = configuration->iPhysicalAddress; |
1532 | } | |
30b4aac0 | 1533 | |
8670c970 LOK |
1534 | bool bHdmiPortChanged(false); |
1535 | if (!bPhysicalAutodetected && !bPhysicalAddressChanged) | |
1536 | { | |
30a09f32 | 1537 | // base device |
8670c970 | 1538 | bHdmiPortChanged = IsRunning() && m_configuration.baseDevice != configuration->baseDevice; |
30a09f32 LOK |
1539 | if (IsRunning()) |
1540 | CLibCEC::AddLog(CEC_LOG_DEBUG, "%s - using base device '%x'", __FUNCTION__, (int)configuration->baseDevice); | |
8670c970 | 1541 | m_configuration.baseDevice = configuration->baseDevice; |
30b4aac0 | 1542 | |
30a09f32 | 1543 | // hdmi port |
8670c970 | 1544 | bHdmiPortChanged |= IsRunning() && m_configuration.iHDMIPort != configuration->iHDMIPort; |
30a09f32 LOK |
1545 | if (IsRunning()) |
1546 | CLibCEC::AddLog(CEC_LOG_DEBUG, "%s - using HDMI port '%d'", __FUNCTION__, configuration->iHDMIPort); | |
8670c970 LOK |
1547 | m_configuration.iHDMIPort = configuration->iHDMIPort; |
1548 | } | |
1549 | else | |
1550 | { | |
30a09f32 LOK |
1551 | if (IsRunning()) |
1552 | CLibCEC::AddLog(CEC_LOG_DEBUG, "%s - resetting HDMI port and base device to defaults", __FUNCTION__); | |
1553 | m_configuration.baseDevice = CECDEVICE_UNKNOWN; | |
1554 | m_configuration.iHDMIPort = 0; | |
8670c970 | 1555 | } |
30b4aac0 | 1556 | |
30a09f32 | 1557 | bReinit = bPhysicalAddressChanged || bHdmiPortChanged || bDeviceTypeChanged; |
f0154449 | 1558 | |
30b4aac0 LOK |
1559 | // device name |
1560 | snprintf(m_configuration.strDeviceName, 13, "%s", configuration->strDeviceName); | |
1561 | if (primary && !primary->GetOSDName().Equals(m_configuration.strDeviceName)) | |
1562 | { | |
1563 | primary->SetOSDName(m_configuration.strDeviceName); | |
f0154449 | 1564 | if (!bReinit && IsRunning()) |
30b4aac0 LOK |
1565 | primary->TransmitOSDName(CECDEVICE_TV); |
1566 | } | |
1567 | ||
1568 | // tv vendor id override | |
1569 | if (m_configuration.tvVendor != configuration->tvVendor) | |
1570 | { | |
1571 | m_configuration.tvVendor= configuration->tvVendor; | |
1572 | m_busDevices[CECDEVICE_TV]->SetVendorId((uint64_t)m_configuration.tvVendor); | |
1573 | } | |
1574 | ||
1575 | // wake CEC devices | |
1576 | if (m_configuration.wakeDevices != configuration->wakeDevices) | |
1577 | { | |
1578 | m_configuration.wakeDevices = configuration->wakeDevices; | |
f0154449 | 1579 | if (!bReinit && IsRunning()) |
ca27e6cf | 1580 | PowerOnDevices(); |
30b4aac0 LOK |
1581 | } |
1582 | ||
1583 | // just copy these | |
3efda01a LOK |
1584 | m_configuration.clientVersion = configuration->clientVersion; |
1585 | m_configuration.bActivateSource = configuration->bActivateSource; | |
30b4aac0 | 1586 | m_configuration.bGetSettingsFromROM = configuration->bGetSettingsFromROM; |
ca27e6cf | 1587 | m_configuration.powerOffDevices = configuration->powerOffDevices; |
30b4aac0 LOK |
1588 | m_configuration.bPowerOffScreensaver = configuration->bPowerOffScreensaver; |
1589 | m_configuration.bPowerOffOnStandby = configuration->bPowerOffOnStandby; | |
1590 | ||
41e3372a LOK |
1591 | // client version 1.5.1 |
1592 | if (configuration->clientVersion >= CEC_CLIENT_VERSION_1_5_1) | |
1593 | m_configuration.bSendInactiveSource = configuration->bSendInactiveSource; | |
1594 | ||
30b4aac0 LOK |
1595 | // ensure that there is at least 1 device type set |
1596 | if (m_configuration.deviceTypes.IsEmpty()) | |
1597 | m_configuration.deviceTypes.Add(CEC_DEVICE_TYPE_RECORDING_DEVICE); | |
1598 | ||
f0154449 | 1599 | if (bReinit) |
30b4aac0 | 1600 | { |
44a1d92a LOK |
1601 | if (bDeviceTypeChanged) |
1602 | return ChangeDeviceType(oldPrimaryType, m_configuration.deviceTypes[0]); | |
1603 | else if (bPhysicalAddressChanged) | |
1604 | return SetPhysicalAddress(m_configuration.iPhysicalAddress); | |
8670c970 | 1605 | else |
f0154449 | 1606 | return SetHDMIPort(m_configuration.baseDevice, m_configuration.iHDMIPort); |
30b4aac0 | 1607 | } |
dd18e809 | 1608 | else if (m_configuration.bActivateSource == 1 && IsRunning() && !IsActiveSource(m_configuration.logicalAddresses.primary)) |
c3c13157 LOK |
1609 | { |
1610 | // activate the source if we're not already the active source | |
1611 | SetActiveSource(m_configuration.deviceTypes.types[0]); | |
1612 | } | |
30b4aac0 LOK |
1613 | |
1614 | return true; | |
1615 | } | |
1616 | ||
d40928b5 LOK |
1617 | bool CCECProcessor::GetCurrentConfiguration(libcec_configuration *configuration) |
1618 | { | |
30b4aac0 | 1619 | // client version 1.5.0 |
30b4aac0 LOK |
1620 | snprintf(configuration->strDeviceName, 13, "%s", m_configuration.strDeviceName); |
1621 | configuration->deviceTypes = m_configuration.deviceTypes; | |
8670c970 | 1622 | configuration->bAutodetectAddress = m_configuration.bAutodetectAddress; |
30b4aac0 LOK |
1623 | configuration->iPhysicalAddress = m_configuration.iPhysicalAddress; |
1624 | configuration->baseDevice = m_configuration.baseDevice; | |
1625 | configuration->iHDMIPort = m_configuration.iHDMIPort; | |
3efda01a LOK |
1626 | configuration->clientVersion = m_configuration.clientVersion; |
1627 | configuration->serverVersion = m_configuration.serverVersion; | |
30b4aac0 | 1628 | configuration->tvVendor = m_configuration.tvVendor; |
3efda01a | 1629 | |
30b4aac0 | 1630 | configuration->bGetSettingsFromROM = m_configuration.bGetSettingsFromROM; |
3efda01a LOK |
1631 | configuration->bUseTVMenuLanguage = m_configuration.bUseTVMenuLanguage; |
1632 | configuration->bActivateSource = m_configuration.bActivateSource; | |
1633 | configuration->wakeDevices = m_configuration.wakeDevices; | |
ca27e6cf | 1634 | configuration->powerOffDevices = m_configuration.powerOffDevices; |
30b4aac0 LOK |
1635 | configuration->bPowerOffScreensaver = m_configuration.bPowerOffScreensaver; |
1636 | configuration->bPowerOffOnStandby = m_configuration.bPowerOffOnStandby; | |
1637 | ||
41e3372a LOK |
1638 | // client version 1.5.1 |
1639 | if (configuration->clientVersion >= CEC_CLIENT_VERSION_1_5_1) | |
1640 | configuration->bSendInactiveSource = m_configuration.bSendInactiveSource; | |
1641 | ||
dd18e809 LOK |
1642 | // client version 1.5.3 |
1643 | if (configuration->clientVersion >= CEC_CLIENT_VERSION_1_5_3) | |
1644 | configuration->logicalAddresses = m_configuration.logicalAddresses; | |
1645 | ||
d40928b5 LOK |
1646 | return true; |
1647 | } | |
224ea877 LOK |
1648 | |
1649 | bool CCECProcessor::CanPersistConfiguration(void) | |
1650 | { | |
1651 | return m_communication->GetFirmwareVersion() >= 2; | |
1652 | } | |
1653 | ||
1654 | bool CCECProcessor::PersistConfiguration(libcec_configuration *configuration) | |
1655 | { | |
1656 | return m_communication->PersistConfiguration(configuration); | |
1657 | } | |
3efda01a LOK |
1658 | |
1659 | void CCECProcessor::RescanActiveDevices(void) | |
1660 | { | |
1661 | for (unsigned int iPtr = 0; iPtr < 16; iPtr++) | |
1662 | m_busDevices[iPtr]->GetStatus(true); | |
1663 | } |