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