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