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