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