Commit | Line | Data |
---|---|---|
e9de9629 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. |
e9de9629 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 | ||
33 | #include "CECBusDevice.h" | |
eafa9d46 LOK |
34 | #include "../CECProcessor.h" |
35 | #include "../implementations/ANCommandHandler.h" | |
36 | #include "../implementations/CECCommandHandler.h" | |
37 | #include "../implementations/SLCommandHandler.h" | |
11621576 | 38 | #include "../implementations/VLCommandHandler.h" |
5477a250 | 39 | #include "../LibCEC.h" |
ba65909d | 40 | #include "../platform/util/timeutils.h" |
e9de9629 LOK |
41 | |
42 | using namespace CEC; | |
f00ff009 | 43 | using namespace PLATFORM; |
e9de9629 | 44 | |
03ae897d | 45 | #define ToString(p) m_processor->ToString(p) |
c4098482 | 46 | |
e9de9629 | 47 | CCECBusDevice::CCECBusDevice(CCECProcessor *processor, cec_logical_address iLogicalAddress, uint16_t iPhysicalAddress) : |
c4098482 | 48 | m_type(CEC_DEVICE_TYPE_RESERVED), |
e9de9629 | 49 | m_iPhysicalAddress(iPhysicalAddress), |
9dc04b07 | 50 | m_iStreamPath(0), |
e9de9629 | 51 | m_iLogicalAddress(iLogicalAddress), |
e55f3f70 | 52 | m_powerStatus(CEC_POWER_STATUS_UNKNOWN), |
e9de9629 | 53 | m_processor(processor), |
c4098482 | 54 | m_vendor(CEC_VENDOR_UNKNOWN), |
b64db02e | 55 | m_bReplaceHandler(false), |
4abd6768 | 56 | m_menuState(CEC_MENU_STATE_ACTIVATED), |
8747dd4f | 57 | m_bActiveSource(false), |
6a1c0009 | 58 | m_iLastActive(0), |
2efa39b7 | 59 | m_iLastPowerStateUpdate(0), |
f8ae3295 | 60 | m_cecVersion(CEC_VERSION_UNKNOWN), |
1344fd1a LOK |
61 | m_deviceStatus(CEC_DEVICE_STATUS_UNKNOWN), |
62 | m_iHandlerUseCount(0), | |
ebb6ddb3 LOK |
63 | m_bAwaitingReceiveFailed(false), |
64 | m_bVendorIdRequested(false) | |
e9de9629 LOK |
65 | { |
66 | m_handler = new CCECCommandHandler(this); | |
51b2a094 | 67 | |
a3269a0a LOK |
68 | for (unsigned int iPtr = 0; iPtr < 4; iPtr++) |
69 | m_menuLanguage.language[iPtr] = '?'; | |
70 | m_menuLanguage.language[3] = 0; | |
71 | m_menuLanguage.device = iLogicalAddress; | |
1fcf5a3f | 72 | |
c4098482 | 73 | m_strDeviceName = ToString(m_iLogicalAddress); |
e9de9629 LOK |
74 | } |
75 | ||
76 | CCECBusDevice::~CCECBusDevice(void) | |
77 | { | |
78 | delete m_handler; | |
79 | } | |
80 | ||
93729720 | 81 | bool CCECBusDevice::HandleCommand(const cec_command &command) |
f8513317 | 82 | { |
7f919115 LOK |
83 | bool bHandled(false); |
84 | ||
85 | /* update "last active" */ | |
8fa35473 | 86 | { |
f00ff009 | 87 | CLockObject lock(m_mutex); |
8fa35473 | 88 | m_iLastActive = GetTimeMs(); |
f4b7b1dc | 89 | |
ba427965 | 90 | /* don't call GetStatus() here, just read the value with the mutex locked */ |
f4b7b1dc LOK |
91 | if (m_deviceStatus != CEC_DEVICE_STATUS_HANDLED_BY_LIBCEC) |
92 | m_deviceStatus = CEC_DEVICE_STATUS_PRESENT; | |
1344fd1a LOK |
93 | |
94 | MarkBusy(); | |
8fa35473 LOK |
95 | } |
96 | ||
7f919115 LOK |
97 | /* handle the command */ |
98 | bHandled = m_handler->HandleCommand(command); | |
8fa35473 | 99 | |
7f919115 LOK |
100 | /* change status to present */ |
101 | if (bHandled) | |
8d915412 | 102 | { |
f00ff009 | 103 | CLockObject lock(m_mutex); |
8fa35473 | 104 | if (m_deviceStatus != CEC_DEVICE_STATUS_HANDLED_BY_LIBCEC) |
8d915412 | 105 | { |
8fa35473 | 106 | if (m_deviceStatus != CEC_DEVICE_STATUS_PRESENT) |
5477a250 | 107 | CLibCEC::AddLog(CEC_LOG_DEBUG, "device %s (%x) status changed to present after command %s", GetLogicalAddressName(), (uint8_t)GetLogicalAddress(), ToString(command.opcode)); |
8fa35473 | 108 | m_deviceStatus = CEC_DEVICE_STATUS_PRESENT; |
8d915412 | 109 | } |
8d915412 | 110 | } |
7f919115 | 111 | |
1344fd1a | 112 | MarkReady(); |
7f919115 | 113 | return bHandled; |
93729720 LOK |
114 | } |
115 | ||
93729720 LOK |
116 | bool CCECBusDevice::PowerOn(void) |
117 | { | |
1344fd1a | 118 | bool bReturn(false); |
f4698390 | 119 | GetVendorId(); // ensure that we got the vendor id, because the implementations vary per vendor |
c6d7f0e1 | 120 | |
1344fd1a | 121 | MarkBusy(); |
8670c970 LOK |
122 | cec_power_status currentStatus = GetPowerStatus(false); |
123 | if (currentStatus != CEC_POWER_STATUS_IN_TRANSITION_STANDBY_TO_ON && | |
124 | currentStatus != CEC_POWER_STATUS_ON) | |
5e5637c6 | 125 | { |
8670c970 LOK |
126 | CLibCEC::AddLog(CEC_LOG_NOTICE, "<< powering on '%s' (%X)", GetLogicalAddressName(), m_iLogicalAddress); |
127 | if (m_handler->PowerOn(GetMyLogicalAddress(), m_iLogicalAddress)) | |
128 | { | |
129 | SetPowerStatus(CEC_POWER_STATUS_IN_TRANSITION_STANDBY_TO_ON); | |
130 | bReturn = true; | |
131 | } | |
132 | } | |
133 | else | |
134 | { | |
135 | CLibCEC::AddLog(CEC_LOG_NOTICE, "'%s' (%X) is already '%s'", GetLogicalAddressName(), m_iLogicalAddress, ToString(currentStatus)); | |
f437e4be LOK |
136 | } |
137 | ||
1344fd1a LOK |
138 | MarkReady(); |
139 | return bReturn; | |
93729720 LOK |
140 | } |
141 | ||
142 | bool CCECBusDevice::Standby(void) | |
143 | { | |
5477a250 | 144 | CLibCEC::AddLog(CEC_LOG_DEBUG, "<< putting '%s' (%X) in standby mode", GetLogicalAddressName(), m_iLogicalAddress); |
1344fd1a LOK |
145 | MarkBusy(); |
146 | bool bReturn = m_handler->TransmitStandby(GetMyLogicalAddress(), m_iLogicalAddress); | |
147 | MarkReady(); | |
148 | return bReturn; | |
93729720 LOK |
149 | } |
150 | ||
151 | /** @name Getters */ | |
152 | //@{ | |
7f919115 | 153 | cec_version CCECBusDevice::GetCecVersion(bool bUpdate /* = false */) |
93729720 | 154 | { |
6bbfc3f7 | 155 | bool bIsPresent(GetStatus() == CEC_DEVICE_STATUS_PRESENT); |
97fc4ffb LOK |
156 | bool bRequestUpdate(false); |
157 | { | |
f00ff009 | 158 | CLockObject lock(m_mutex); |
ddb6ac5b | 159 | bRequestUpdate = bIsPresent && |
6bbfc3f7 | 160 | (bUpdate || m_cecVersion == CEC_VERSION_UNKNOWN); |
97fc4ffb LOK |
161 | } |
162 | ||
163 | if (bRequestUpdate) | |
ebb6ddb3 LOK |
164 | { |
165 | CheckVendorIdRequested(); | |
f294b22f | 166 | RequestCecVersion(); |
ebb6ddb3 | 167 | } |
f294b22f | 168 | |
f00ff009 | 169 | CLockObject lock(m_mutex); |
f294b22f LOK |
170 | return m_cecVersion; |
171 | } | |
172 | ||
173 | bool CCECBusDevice::RequestCecVersion(void) | |
174 | { | |
175 | bool bReturn(false); | |
b64db02e | 176 | |
66c3ef5a LOK |
177 | if (!MyLogicalAddressContains(m_iLogicalAddress) && |
178 | !IsUnsupportedFeature(CEC_OPCODE_GET_CEC_VERSION)) | |
93729720 | 179 | { |
1344fd1a | 180 | MarkBusy(); |
5477a250 | 181 | CLibCEC::AddLog(CEC_LOG_NOTICE, "<< requesting CEC version of '%s' (%X)", GetLogicalAddressName(), m_iLogicalAddress); |
8fa35473 LOK |
182 | |
183 | bReturn = m_handler->TransmitRequestCecVersion(GetMyLogicalAddress(), m_iLogicalAddress); | |
1344fd1a | 184 | MarkReady(); |
93729720 | 185 | } |
f294b22f | 186 | return bReturn; |
93729720 LOK |
187 | } |
188 | ||
62f5527d LOK |
189 | const char* CCECBusDevice::GetLogicalAddressName(void) const |
190 | { | |
c4098482 | 191 | return ToString(m_iLogicalAddress); |
62f5527d LOK |
192 | } |
193 | ||
7f919115 | 194 | cec_menu_language &CCECBusDevice::GetMenuLanguage(bool bUpdate /* = false */) |
93729720 | 195 | { |
6bbfc3f7 | 196 | bool bIsPresent(GetStatus() == CEC_DEVICE_STATUS_PRESENT); |
97fc4ffb LOK |
197 | bool bRequestUpdate(false); |
198 | { | |
f00ff009 | 199 | CLockObject lock(m_mutex); |
ddb6ac5b | 200 | bRequestUpdate = (bIsPresent && |
97fc4ffb LOK |
201 | (bUpdate || !strcmp(m_menuLanguage.language, "???"))); |
202 | } | |
203 | ||
204 | if (bRequestUpdate) | |
ebb6ddb3 LOK |
205 | { |
206 | CheckVendorIdRequested(); | |
f294b22f | 207 | RequestMenuLanguage(); |
ebb6ddb3 | 208 | } |
5e5637c6 | 209 | |
f00ff009 | 210 | CLockObject lock(m_mutex); |
f294b22f LOK |
211 | return m_menuLanguage; |
212 | } | |
213 | ||
214 | bool CCECBusDevice::RequestMenuLanguage(void) | |
215 | { | |
216 | bool bReturn(false); | |
b64db02e | 217 | |
4d738fe3 LOK |
218 | if (!MyLogicalAddressContains(m_iLogicalAddress) && |
219 | !IsUnsupportedFeature(CEC_OPCODE_GET_MENU_LANGUAGE)) | |
93729720 | 220 | { |
1344fd1a | 221 | MarkBusy(); |
5477a250 | 222 | CLibCEC::AddLog(CEC_LOG_NOTICE, "<< requesting menu language of '%s' (%X)", GetLogicalAddressName(), m_iLogicalAddress); |
8fa35473 | 223 | bReturn = m_handler->TransmitRequestMenuLanguage(GetMyLogicalAddress(), m_iLogicalAddress); |
1344fd1a | 224 | MarkReady(); |
93729720 | 225 | } |
f294b22f | 226 | return bReturn; |
93729720 LOK |
227 | } |
228 | ||
3e61b350 LOK |
229 | cec_menu_state CCECBusDevice::GetMenuState(void) |
230 | { | |
f00ff009 | 231 | CLockObject lock(m_mutex); |
3e61b350 LOK |
232 | return m_menuState; |
233 | } | |
234 | ||
93729720 LOK |
235 | cec_logical_address CCECBusDevice::GetMyLogicalAddress(void) const |
236 | { | |
237 | return m_processor->GetLogicalAddress(); | |
f8513317 LOK |
238 | } |
239 | ||
e9de9629 LOK |
240 | uint16_t CCECBusDevice::GetMyPhysicalAddress(void) const |
241 | { | |
242 | return m_processor->GetPhysicalAddress(); | |
243 | } | |
244 | ||
7f919115 | 245 | CStdString CCECBusDevice::GetOSDName(bool bUpdate /* = false */) |
ed21be2a | 246 | { |
6bbfc3f7 | 247 | bool bIsPresent(GetStatus() == CEC_DEVICE_STATUS_PRESENT); |
97fc4ffb LOK |
248 | bool bRequestUpdate(false); |
249 | { | |
f00ff009 | 250 | CLockObject lock(m_mutex); |
ddb6ac5b | 251 | bRequestUpdate = bIsPresent && |
97fc4ffb | 252 | (bUpdate || m_strDeviceName.Equals(ToString(m_iLogicalAddress))) && |
ddb6ac5b | 253 | m_type != CEC_DEVICE_TYPE_TV; |
97fc4ffb LOK |
254 | } |
255 | ||
256 | if (bRequestUpdate) | |
ebb6ddb3 LOK |
257 | { |
258 | CheckVendorIdRequested(); | |
5e5637c6 | 259 | RequestOSDName(); |
ebb6ddb3 | 260 | } |
5e5637c6 | 261 | |
f00ff009 | 262 | CLockObject lock(m_mutex); |
ed21be2a LOK |
263 | return m_strDeviceName; |
264 | } | |
265 | ||
266 | bool CCECBusDevice::RequestOSDName(void) | |
267 | { | |
268 | bool bReturn(false); | |
b64db02e | 269 | |
4d738fe3 LOK |
270 | if (!MyLogicalAddressContains(m_iLogicalAddress) && |
271 | !IsUnsupportedFeature(CEC_OPCODE_GIVE_OSD_NAME)) | |
ed21be2a | 272 | { |
1344fd1a | 273 | MarkBusy(); |
5477a250 | 274 | CLibCEC::AddLog(CEC_LOG_NOTICE, "<< requesting OSD name of '%s' (%X)", GetLogicalAddressName(), m_iLogicalAddress); |
8fa35473 | 275 | bReturn = m_handler->TransmitRequestOSDName(GetMyLogicalAddress(), m_iLogicalAddress); |
1344fd1a | 276 | MarkReady(); |
ed21be2a LOK |
277 | } |
278 | return bReturn; | |
279 | } | |
280 | ||
7f919115 | 281 | uint16_t CCECBusDevice::GetPhysicalAddress(bool bUpdate /* = false */) |
16b1e052 | 282 | { |
6bbfc3f7 | 283 | bool bIsPresent(GetStatus() == CEC_DEVICE_STATUS_PRESENT); |
97fc4ffb | 284 | bool bRequestUpdate(false); |
16b1e052 | 285 | { |
f00ff009 | 286 | CLockObject lock(m_mutex); |
ddb6ac5b LOK |
287 | bRequestUpdate = bIsPresent && |
288 | (m_iPhysicalAddress == 0xFFFF || bUpdate); | |
16b1e052 LOK |
289 | } |
290 | ||
ebb6ddb3 LOK |
291 | if (bRequestUpdate) |
292 | { | |
293 | CheckVendorIdRequested(); | |
294 | if (!RequestPhysicalAddress()) | |
295 | CLibCEC::AddLog(CEC_LOG_ERROR, "failed to request the physical address"); | |
296 | } | |
97fc4ffb | 297 | |
f00ff009 | 298 | CLockObject lock(m_mutex); |
16b1e052 LOK |
299 | return m_iPhysicalAddress; |
300 | } | |
301 | ||
302 | bool CCECBusDevice::RequestPhysicalAddress(void) | |
303 | { | |
304 | bool bReturn(false); | |
b64db02e | 305 | |
16b1e052 LOK |
306 | if (!MyLogicalAddressContains(m_iLogicalAddress)) |
307 | { | |
1344fd1a | 308 | MarkBusy(); |
5477a250 | 309 | CLibCEC::AddLog(CEC_LOG_NOTICE, "<< requesting physical address of '%s' (%X)", GetLogicalAddressName(), m_iLogicalAddress); |
8fa35473 | 310 | bReturn = m_handler->TransmitRequestPhysicalAddress(GetMyLogicalAddress(), m_iLogicalAddress); |
1344fd1a | 311 | MarkReady(); |
16b1e052 LOK |
312 | } |
313 | return bReturn; | |
314 | } | |
315 | ||
7f919115 | 316 | cec_power_status CCECBusDevice::GetPowerStatus(bool bUpdate /* = false */) |
e9de9629 | 317 | { |
6bbfc3f7 | 318 | bool bIsPresent(GetStatus() == CEC_DEVICE_STATUS_PRESENT); |
97fc4ffb LOK |
319 | bool bRequestUpdate(false); |
320 | { | |
f00ff009 | 321 | CLockObject lock(m_mutex); |
ddb6ac5b | 322 | bRequestUpdate = (bIsPresent && |
c8f0eef0 | 323 | (bUpdate || m_powerStatus == CEC_POWER_STATUS_UNKNOWN || |
2efa39b7 LOK |
324 | m_powerStatus == CEC_POWER_STATUS_IN_TRANSITION_STANDBY_TO_ON || |
325 | m_powerStatus == CEC_POWER_STATUS_IN_TRANSITION_ON_TO_STANDBY || | |
326 | GetTimeMs() - m_iLastPowerStateUpdate >= CEC_POWER_STATE_REFRESH_TIME)); | |
97fc4ffb LOK |
327 | } |
328 | ||
329 | if (bRequestUpdate) | |
ebb6ddb3 LOK |
330 | { |
331 | CheckVendorIdRequested(); | |
f294b22f | 332 | RequestPowerStatus(); |
ebb6ddb3 | 333 | } |
5e5637c6 | 334 | |
f00ff009 | 335 | CLockObject lock(m_mutex); |
f294b22f LOK |
336 | return m_powerStatus; |
337 | } | |
338 | ||
339 | bool CCECBusDevice::RequestPowerStatus(void) | |
340 | { | |
341 | bool bReturn(false); | |
b64db02e | 342 | |
4d738fe3 LOK |
343 | if (!MyLogicalAddressContains(m_iLogicalAddress) && |
344 | !IsUnsupportedFeature(CEC_OPCODE_GIVE_DEVICE_POWER_STATUS)) | |
93729720 | 345 | { |
1344fd1a | 346 | MarkBusy(); |
5477a250 | 347 | CLibCEC::AddLog(CEC_LOG_NOTICE, "<< requesting power status of '%s' (%X)", GetLogicalAddressName(), m_iLogicalAddress); |
8fa35473 | 348 | bReturn = m_handler->TransmitRequestPowerStatus(GetMyLogicalAddress(), m_iLogicalAddress); |
1344fd1a | 349 | MarkReady(); |
93729720 | 350 | } |
f294b22f LOK |
351 | return bReturn; |
352 | } | |
93729720 | 353 | |
7f919115 | 354 | cec_vendor_id CCECBusDevice::GetVendorId(bool bUpdate /* = false */) |
f294b22f | 355 | { |
6bbfc3f7 | 356 | bool bIsPresent(GetStatus() == CEC_DEVICE_STATUS_PRESENT); |
97fc4ffb LOK |
357 | bool bRequestUpdate(false); |
358 | { | |
f00ff009 | 359 | CLockObject lock(m_mutex); |
ddb6ac5b | 360 | bRequestUpdate = (bIsPresent && |
97fc4ffb LOK |
361 | (bUpdate || m_vendor == CEC_VENDOR_UNKNOWN)); |
362 | } | |
363 | ||
364 | if (bRequestUpdate) | |
f294b22f | 365 | RequestVendorId(); |
5e5637c6 | 366 | |
f00ff009 | 367 | CLockObject lock(m_mutex); |
f294b22f | 368 | return m_vendor; |
e9de9629 LOK |
369 | } |
370 | ||
f294b22f | 371 | bool CCECBusDevice::RequestVendorId(void) |
a3269a0a | 372 | { |
f294b22f | 373 | bool bReturn(false); |
b64db02e | 374 | |
81a1e39d | 375 | if (!MyLogicalAddressContains(m_iLogicalAddress)) |
a3269a0a | 376 | { |
1344fd1a | 377 | MarkBusy(); |
5477a250 | 378 | CLibCEC::AddLog(CEC_LOG_NOTICE, "<< requesting vendor ID of '%s' (%X)", GetLogicalAddressName(), m_iLogicalAddress); |
8fa35473 | 379 | bReturn = m_handler->TransmitRequestVendorId(GetMyLogicalAddress(), m_iLogicalAddress); |
1344fd1a | 380 | MarkReady(); |
3e61b350 LOK |
381 | |
382 | ReplaceHandler(true); | |
a3269a0a | 383 | } |
f294b22f | 384 | return bReturn; |
93729720 LOK |
385 | } |
386 | ||
7f919115 | 387 | const char *CCECBusDevice::GetVendorName(bool bUpdate /* = false */) |
c4098482 | 388 | { |
7f919115 | 389 | return ToString(GetVendorId(bUpdate)); |
c4098482 LOK |
390 | } |
391 | ||
93729720 LOK |
392 | bool CCECBusDevice::MyLogicalAddressContains(cec_logical_address address) const |
393 | { | |
394 | return m_processor->HasLogicalAddress(address); | |
a3269a0a LOK |
395 | } |
396 | ||
9fd73dd4 LOK |
397 | bool CCECBusDevice::NeedsPoll(void) |
398 | { | |
399 | bool bSendPoll(false); | |
400 | switch (m_iLogicalAddress) | |
401 | { | |
402 | case CECDEVICE_PLAYBACKDEVICE3: | |
c6d7f0e1 LOK |
403 | { |
404 | cec_bus_device_status status = m_processor->m_busDevices[CECDEVICE_PLAYBACKDEVICE2]->GetStatus(); | |
405 | bSendPoll = (status == CEC_DEVICE_STATUS_PRESENT || status == CEC_DEVICE_STATUS_HANDLED_BY_LIBCEC); | |
406 | } | |
9fd73dd4 LOK |
407 | break; |
408 | case CECDEVICE_PLAYBACKDEVICE2: | |
c6d7f0e1 LOK |
409 | { |
410 | cec_bus_device_status status = m_processor->m_busDevices[CECDEVICE_PLAYBACKDEVICE1]->GetStatus(); | |
411 | bSendPoll = (status == CEC_DEVICE_STATUS_PRESENT || status == CEC_DEVICE_STATUS_HANDLED_BY_LIBCEC); | |
412 | } | |
9fd73dd4 LOK |
413 | break; |
414 | case CECDEVICE_RECORDINGDEVICE3: | |
c6d7f0e1 LOK |
415 | { |
416 | cec_bus_device_status status = m_processor->m_busDevices[CECDEVICE_RECORDINGDEVICE2]->GetStatus(); | |
417 | bSendPoll = (status == CEC_DEVICE_STATUS_PRESENT || status == CEC_DEVICE_STATUS_HANDLED_BY_LIBCEC); | |
418 | } | |
9fd73dd4 LOK |
419 | break; |
420 | case CECDEVICE_RECORDINGDEVICE2: | |
c6d7f0e1 LOK |
421 | { |
422 | cec_bus_device_status status = m_processor->m_busDevices[CECDEVICE_RECORDINGDEVICE1]->GetStatus(); | |
423 | bSendPoll = (status == CEC_DEVICE_STATUS_PRESENT || status == CEC_DEVICE_STATUS_HANDLED_BY_LIBCEC); | |
424 | } | |
9fd73dd4 LOK |
425 | break; |
426 | case CECDEVICE_TUNER4: | |
c6d7f0e1 LOK |
427 | { |
428 | cec_bus_device_status status = m_processor->m_busDevices[CECDEVICE_TUNER3]->GetStatus(); | |
429 | bSendPoll = (status == CEC_DEVICE_STATUS_PRESENT || status == CEC_DEVICE_STATUS_HANDLED_BY_LIBCEC); | |
430 | } | |
9fd73dd4 LOK |
431 | break; |
432 | case CECDEVICE_TUNER3: | |
c6d7f0e1 LOK |
433 | { |
434 | cec_bus_device_status status = m_processor->m_busDevices[CECDEVICE_TUNER2]->GetStatus(); | |
435 | bSendPoll = (status == CEC_DEVICE_STATUS_PRESENT || status == CEC_DEVICE_STATUS_HANDLED_BY_LIBCEC); | |
436 | } | |
9fd73dd4 LOK |
437 | break; |
438 | case CECDEVICE_TUNER2: | |
c6d7f0e1 LOK |
439 | { |
440 | cec_bus_device_status status = m_processor->m_busDevices[CECDEVICE_TUNER1]->GetStatus(); | |
441 | bSendPoll = (status == CEC_DEVICE_STATUS_PRESENT || status == CEC_DEVICE_STATUS_HANDLED_BY_LIBCEC); | |
442 | } | |
9fd73dd4 LOK |
443 | break; |
444 | case CECDEVICE_AUDIOSYSTEM: | |
445 | case CECDEVICE_PLAYBACKDEVICE1: | |
446 | case CECDEVICE_RECORDINGDEVICE1: | |
447 | case CECDEVICE_TUNER1: | |
448 | case CECDEVICE_TV: | |
449 | bSendPoll = true; | |
450 | break; | |
451 | default: | |
452 | break; | |
453 | } | |
454 | ||
455 | return bSendPoll; | |
456 | } | |
457 | ||
458 | cec_bus_device_status CCECBusDevice::GetStatus(bool bForcePoll /* = false */) | |
f8ae3295 | 459 | { |
ba427965 LOK |
460 | cec_bus_device_status status(CEC_DEVICE_STATUS_UNKNOWN); |
461 | bool bNeedsPoll(false); | |
462 | ||
463 | { | |
464 | CLockObject lock(m_mutex); | |
465 | status = m_deviceStatus; | |
466 | bNeedsPoll = (m_deviceStatus != CEC_DEVICE_STATUS_HANDLED_BY_LIBCEC && | |
467 | (m_deviceStatus == CEC_DEVICE_STATUS_UNKNOWN || bForcePoll)); | |
468 | } | |
469 | ||
470 | if (bNeedsPoll) | |
f8ae3295 | 471 | { |
9fd73dd4 | 472 | bool bPollAcked(false); |
7b62b76e | 473 | if (bNeedsPoll && NeedsPoll()) |
9fd73dd4 | 474 | bPollAcked = m_processor->PollDevice(m_iLogicalAddress); |
95a73fa7 | 475 | |
ba427965 LOK |
476 | status = bPollAcked ? CEC_DEVICE_STATUS_PRESENT : CEC_DEVICE_STATUS_NOT_PRESENT; |
477 | SetDeviceStatus(status); | |
f8ae3295 LOK |
478 | } |
479 | ||
ba427965 | 480 | return status; |
f8ae3295 LOK |
481 | } |
482 | ||
93729720 LOK |
483 | //@} |
484 | ||
485 | /** @name Setters */ | |
486 | //@{ | |
e55f3f70 | 487 | void CCECBusDevice::SetCecVersion(const cec_version newVersion) |
6a1c0009 | 488 | { |
6a1c0009 | 489 | m_cecVersion = newVersion; |
5477a250 | 490 | CLibCEC::AddLog(CEC_LOG_DEBUG, "%s (%X): CEC version %s", GetLogicalAddressName(), m_iLogicalAddress, ToString(newVersion)); |
6a1c0009 LOK |
491 | } |
492 | ||
93729720 LOK |
493 | void CCECBusDevice::SetMenuLanguage(const cec_menu_language &language) |
494 | { | |
f00ff009 | 495 | CLockObject lock(m_mutex); |
93729720 LOK |
496 | if (language.device == m_iLogicalAddress) |
497 | { | |
5477a250 | 498 | CLibCEC::AddLog(CEC_LOG_DEBUG, ">> %s (%X): menu language set to '%s'", GetLogicalAddressName(), m_iLogicalAddress, language.language); |
93729720 LOK |
499 | m_menuLanguage = language; |
500 | } | |
501 | } | |
502 | ||
15d1a84c LOK |
503 | void CCECBusDevice::SetOSDName(CStdString strName) |
504 | { | |
f00ff009 | 505 | CLockObject lock(m_mutex); |
15d1a84c LOK |
506 | if (m_strDeviceName != strName) |
507 | { | |
5477a250 | 508 | CLibCEC::AddLog(CEC_LOG_DEBUG, ">> %s (%X): osd name set to '%s'", GetLogicalAddressName(), m_iLogicalAddress, strName.c_str()); |
15d1a84c LOK |
509 | m_strDeviceName = strName; |
510 | } | |
511 | } | |
512 | ||
28fa6c97 LOK |
513 | void CCECBusDevice::SetMenuState(const cec_menu_state state) |
514 | { | |
f00ff009 | 515 | CLockObject lock(m_mutex); |
28fa6c97 LOK |
516 | if (m_menuState != state) |
517 | { | |
5477a250 | 518 | CLibCEC::AddLog(CEC_LOG_DEBUG, ">> %s (%X): menu state set to '%s'", GetLogicalAddressName(), m_iLogicalAddress, ToString(m_menuState)); |
28fa6c97 LOK |
519 | m_menuState = state; |
520 | } | |
521 | } | |
522 | ||
3fd2a2b8 | 523 | void CCECBusDevice::SetInactiveSource(void) |
7856411b | 524 | { |
3fd2a2b8 | 525 | { |
f00ff009 | 526 | CLockObject lock(m_mutex); |
24dd566c LOK |
527 | if (m_bActiveSource) |
528 | CLibCEC::AddLog(CEC_LOG_DEBUG, "marking %s (%X) as inactive source", GetLogicalAddressName(), m_iLogicalAddress); | |
3fd2a2b8 LOK |
529 | m_bActiveSource = false; |
530 | } | |
531 | ||
532 | if (MyLogicalAddressContains(m_iLogicalAddress)) | |
533 | SetPowerStatus(CEC_POWER_STATUS_STANDBY); | |
7856411b LOK |
534 | } |
535 | ||
37b0c572 | 536 | void CCECBusDevice::SetActiveSource(void) |
7856411b | 537 | { |
f00ff009 | 538 | CLockObject lock(m_mutex); |
ff684fef | 539 | if (!m_bActiveSource) |
5477a250 | 540 | CLibCEC::AddLog(CEC_LOG_DEBUG, "making %s (%x) the active source", GetLogicalAddressName(), m_iLogicalAddress); |
7856411b LOK |
541 | |
542 | for (int iPtr = 0; iPtr < 16; iPtr++) | |
543 | if (iPtr != m_iLogicalAddress) | |
3fd2a2b8 | 544 | m_processor->m_busDevices[iPtr]->SetInactiveSource(); |
7856411b LOK |
545 | |
546 | m_bActiveSource = true; | |
9a2f12df | 547 | SetPowerStatus(CEC_POWER_STATUS_ON); |
7856411b LOK |
548 | } |
549 | ||
93fff5c1 LOK |
550 | bool CCECBusDevice::TryLogicalAddress(void) |
551 | { | |
5477a250 | 552 | CLibCEC::AddLog(CEC_LOG_DEBUG, "trying logical address '%s'", GetLogicalAddressName()); |
93fff5c1 | 553 | |
b81f75db | 554 | m_processor->SetAckMask(0); |
93fff5c1 LOK |
555 | if (!TransmitPoll(m_iLogicalAddress)) |
556 | { | |
5477a250 | 557 | CLibCEC::AddLog(CEC_LOG_NOTICE, "using logical address '%s'", GetLogicalAddressName()); |
93fff5c1 LOK |
558 | SetDeviceStatus(CEC_DEVICE_STATUS_HANDLED_BY_LIBCEC); |
559 | ||
560 | return true; | |
561 | } | |
562 | ||
5477a250 | 563 | CLibCEC::AddLog(CEC_LOG_DEBUG, "logical address '%s' already taken", GetLogicalAddressName()); |
93fff5c1 LOK |
564 | SetDeviceStatus(CEC_DEVICE_STATUS_PRESENT); |
565 | return false; | |
566 | } | |
567 | ||
568 | void CCECBusDevice::SetDeviceStatus(const cec_bus_device_status newStatus) | |
569 | { | |
f00ff009 | 570 | CLockObject lock(m_mutex); |
93fff5c1 LOK |
571 | switch (newStatus) |
572 | { | |
573 | case CEC_DEVICE_STATUS_UNKNOWN: | |
c4287bcd LOK |
574 | if (m_deviceStatus != newStatus) |
575 | CLibCEC::AddLog(CEC_LOG_DEBUG, "device status of %s changed into 'unknown'", ToString(m_iLogicalAddress)); | |
93fff5c1 LOK |
576 | m_iStreamPath = 0; |
577 | m_powerStatus = CEC_POWER_STATUS_UNKNOWN; | |
578 | m_vendor = CEC_VENDOR_UNKNOWN; | |
579 | m_menuState = CEC_MENU_STATE_ACTIVATED; | |
580 | m_bActiveSource = false; | |
93fff5c1 LOK |
581 | m_iLastActive = 0; |
582 | m_cecVersion = CEC_VERSION_UNKNOWN; | |
583 | m_deviceStatus = newStatus; | |
584 | break; | |
585 | case CEC_DEVICE_STATUS_HANDLED_BY_LIBCEC: | |
c4287bcd LOK |
586 | if (m_deviceStatus != newStatus) |
587 | CLibCEC::AddLog(CEC_LOG_DEBUG, "device status of %s changed into 'handled by libCEC'", ToString(m_iLogicalAddress)); | |
93fff5c1 | 588 | m_iStreamPath = 0; |
9a2f12df | 589 | m_powerStatus = CEC_POWER_STATUS_IN_TRANSITION_STANDBY_TO_ON; |
93fff5c1 LOK |
590 | m_vendor = CEC_VENDOR_UNKNOWN; |
591 | m_menuState = CEC_MENU_STATE_ACTIVATED; | |
592 | m_bActiveSource = false; | |
93fff5c1 LOK |
593 | m_iLastActive = 0; |
594 | m_cecVersion = CEC_VERSION_1_3A; | |
595 | m_deviceStatus = newStatus; | |
596 | break; | |
597 | case CEC_DEVICE_STATUS_PRESENT: | |
c4287bcd LOK |
598 | if (m_deviceStatus != newStatus) |
599 | CLibCEC::AddLog(CEC_LOG_DEBUG, "device status of %s changed into 'present'", ToString(m_iLogicalAddress)); | |
600 | m_deviceStatus = newStatus; | |
601 | break; | |
93fff5c1 | 602 | case CEC_DEVICE_STATUS_NOT_PRESENT: |
c4287bcd LOK |
603 | if (m_deviceStatus != newStatus) |
604 | CLibCEC::AddLog(CEC_LOG_DEBUG, "device status of %s changed into 'not present'", ToString(m_iLogicalAddress)); | |
93fff5c1 LOK |
605 | m_deviceStatus = newStatus; |
606 | break; | |
607 | } | |
608 | } | |
609 | ||
9dc04b07 | 610 | void CCECBusDevice::SetPhysicalAddress(uint16_t iNewAddress) |
93729720 | 611 | { |
f00ff009 | 612 | CLockObject lock(m_mutex); |
b8176e3c | 613 | if (iNewAddress > 0 && m_iPhysicalAddress != iNewAddress) |
93729720 | 614 | { |
5477a250 | 615 | CLibCEC::AddLog(CEC_LOG_DEBUG, ">> %s (%X): physical address changed from %04x to %04x", GetLogicalAddressName(), m_iLogicalAddress, m_iPhysicalAddress, iNewAddress); |
93729720 LOK |
616 | m_iPhysicalAddress = iNewAddress; |
617 | } | |
618 | } | |
619 | ||
9dc04b07 LOK |
620 | void CCECBusDevice::SetStreamPath(uint16_t iNewAddress, uint16_t iOldAddress /* = 0 */) |
621 | { | |
f00ff009 | 622 | CLockObject lock(m_mutex); |
9dc04b07 LOK |
623 | if (iNewAddress > 0) |
624 | { | |
5477a250 | 625 | CLibCEC::AddLog(CEC_LOG_DEBUG, ">> %s (%X): stream path changed from %04x to %04x", GetLogicalAddressName(), m_iLogicalAddress, iOldAddress == 0 ? m_iStreamPath : iOldAddress, iNewAddress); |
9dc04b07 | 626 | m_iStreamPath = iNewAddress; |
96274140 LOK |
627 | |
628 | if (iNewAddress > 0) | |
81a1e39d | 629 | { |
f00ff009 | 630 | lock.Unlock(); |
96274140 | 631 | SetPowerStatus(CEC_POWER_STATUS_ON); |
81a1e39d | 632 | } |
9dc04b07 LOK |
633 | } |
634 | } | |
635 | ||
e55f3f70 LOK |
636 | void CCECBusDevice::SetPowerStatus(const cec_power_status powerStatus) |
637 | { | |
f00ff009 | 638 | CLockObject lock(m_mutex); |
b0271d54 LOK |
639 | if (m_powerStatus != powerStatus) |
640 | { | |
2efa39b7 | 641 | m_iLastPowerStateUpdate = GetTimeMs(); |
5477a250 | 642 | CLibCEC::AddLog(CEC_LOG_DEBUG, ">> %s (%X): power status changed from '%s' to '%s'", GetLogicalAddressName(), m_iLogicalAddress, ToString(m_powerStatus), ToString(powerStatus)); |
b0271d54 LOK |
643 | m_powerStatus = powerStatus; |
644 | } | |
e55f3f70 LOK |
645 | } |
646 | ||
1344fd1a LOK |
647 | void CCECBusDevice::MarkBusy(void) |
648 | { | |
649 | CLockObject handlerLock(m_handlerMutex); | |
650 | ++m_iHandlerUseCount; | |
651 | } | |
652 | ||
653 | void CCECBusDevice::MarkReady(void) | |
654 | { | |
655 | CLockObject handlerLock(m_handlerMutex); | |
656 | if (m_iHandlerUseCount > 0) | |
657 | --m_iHandlerUseCount; | |
658 | } | |
659 | ||
3e61b350 | 660 | bool CCECBusDevice::ReplaceHandler(bool bActivateSource /* = true */) |
e9de9629 | 661 | { |
94e9a2af LOK |
662 | bool bInitHandler(false); |
663 | { | |
664 | CTryLockObject lock(m_mutex); | |
665 | if (!lock.IsLocked()) | |
666 | return false; | |
2563e7eb | 667 | |
94e9a2af LOK |
668 | CLockObject handlerLock(m_handlerMutex); |
669 | if (m_iHandlerUseCount > 0) | |
670 | return false; | |
d211708b | 671 | |
94e9a2af | 672 | MarkBusy(); |
104125dc | 673 | |
94e9a2af | 674 | if (m_vendor != m_handler->GetVendorId()) |
3e61b350 | 675 | { |
94e9a2af | 676 | if (CCECCommandHandler::HasSpecificHandler(m_vendor)) |
2e49a6e4 | 677 | { |
94e9a2af LOK |
678 | CLibCEC::AddLog(CEC_LOG_DEBUG, "replacing the command handler for device '%s' (%x)", GetLogicalAddressName(), GetLogicalAddress()); |
679 | delete m_handler; | |
680 | ||
681 | switch (m_vendor) | |
682 | { | |
683 | case CEC_VENDOR_SAMSUNG: | |
684 | m_handler = new CANCommandHandler(this); | |
685 | break; | |
686 | case CEC_VENDOR_LG: | |
687 | m_handler = new CSLCommandHandler(this); | |
688 | break; | |
689 | case CEC_VENDOR_PANASONIC: | |
690 | m_handler = new CVLCommandHandler(this); | |
691 | break; | |
692 | default: | |
693 | m_handler = new CCECCommandHandler(this); | |
694 | break; | |
695 | } | |
696 | ||
697 | m_handler->SetVendorId(m_vendor); | |
698 | bInitHandler = true; | |
2e49a6e4 | 699 | } |
2e49a6e4 | 700 | } |
e9de9629 LOK |
701 | } |
702 | ||
104125dc LOK |
703 | if (bInitHandler) |
704 | { | |
705 | m_handler->InitHandler(); | |
706 | ||
707 | if (bActivateSource && m_processor->GetLogicalAddresses().IsSet(m_iLogicalAddress) && m_processor->IsInitialised() && IsActiveSource()) | |
708 | m_handler->ActivateSource(); | |
709 | } | |
710 | ||
711 | MarkReady(); | |
712 | ||
b64db02e LOK |
713 | return true; |
714 | } | |
715 | ||
3e61b350 | 716 | bool CCECBusDevice::SetVendorId(uint64_t iVendorId) |
b64db02e LOK |
717 | { |
718 | bool bVendorChanged(false); | |
719 | ||
720 | { | |
f00ff009 | 721 | CLockObject lock(m_mutex); |
b64db02e LOK |
722 | bVendorChanged = (m_vendor != (cec_vendor_id)iVendorId); |
723 | m_vendor = (cec_vendor_id)iVendorId; | |
b64db02e | 724 | } |
8d915412 | 725 | |
5477a250 | 726 | CLibCEC::AddLog(CEC_LOG_DEBUG, "%s (%X): vendor = %s (%06x)", GetLogicalAddressName(), m_iLogicalAddress, ToString(m_vendor), m_vendor); |
8fa35473 LOK |
727 | |
728 | return bVendorChanged; | |
e9de9629 | 729 | } |
93729720 | 730 | //@} |
e9de9629 | 731 | |
93729720 LOK |
732 | /** @name Transmit methods */ |
733 | //@{ | |
734 | bool CCECBusDevice::TransmitActiveSource(void) | |
0f23c85c | 735 | { |
8fa35473 | 736 | bool bSendActiveSource(false); |
0f23c85c | 737 | |
8747dd4f | 738 | { |
f00ff009 | 739 | CLockObject lock(m_mutex); |
49c8f2e4 | 740 | if (m_powerStatus != CEC_POWER_STATUS_ON && m_powerStatus != CEC_POWER_STATUS_IN_TRANSITION_STANDBY_TO_ON) |
5477a250 | 741 | CLibCEC::AddLog(CEC_LOG_DEBUG, "<< %s (%X) is not powered on", GetLogicalAddressName(), m_iLogicalAddress); |
8fa35473 LOK |
742 | else if (m_bActiveSource) |
743 | { | |
5477a250 | 744 | CLibCEC::AddLog(CEC_LOG_NOTICE, "<< %s (%X) -> broadcast (F): active source (%4x)", GetLogicalAddressName(), m_iLogicalAddress, m_iPhysicalAddress); |
8fa35473 LOK |
745 | bSendActiveSource = true; |
746 | } | |
747 | else | |
5477a250 | 748 | CLibCEC::AddLog(CEC_LOG_DEBUG, "<< %s (%X) is not the active source", GetLogicalAddressName(), m_iLogicalAddress); |
8747dd4f LOK |
749 | } |
750 | ||
b64db02e LOK |
751 | if (bSendActiveSource) |
752 | { | |
1344fd1a | 753 | MarkBusy(); |
468a1414 | 754 | m_handler->TransmitActiveSource(m_iLogicalAddress, m_iPhysicalAddress); |
1344fd1a | 755 | MarkReady(); |
b64db02e LOK |
756 | return true; |
757 | } | |
758 | ||
759 | return false; | |
0f23c85c LOK |
760 | } |
761 | ||
29912296 | 762 | bool CCECBusDevice::TransmitCECVersion(cec_logical_address dest) |
0f23c85c | 763 | { |
8fa35473 LOK |
764 | cec_version version; |
765 | { | |
f00ff009 | 766 | CLockObject lock(m_mutex); |
5477a250 | 767 | CLibCEC::AddLog(CEC_LOG_NOTICE, "<< %s (%X) -> %s (%X): cec version %s", GetLogicalAddressName(), m_iLogicalAddress, ToString(dest), dest, ToString(m_cecVersion)); |
8fa35473 LOK |
768 | version = m_cecVersion; |
769 | } | |
0f23c85c | 770 | |
1344fd1a LOK |
771 | MarkBusy(); |
772 | bool bReturn = m_handler->TransmitCECVersion(m_iLogicalAddress, dest, version); | |
773 | MarkReady(); | |
774 | return bReturn; | |
0f23c85c LOK |
775 | } |
776 | ||
49c8f2e4 LOK |
777 | bool CCECBusDevice::TransmitImageViewOn(void) |
778 | { | |
49c8f2e4 | 779 | { |
9a2f12df LOK |
780 | CLockObject lock(m_mutex); |
781 | if (m_powerStatus != CEC_POWER_STATUS_ON && m_powerStatus != CEC_POWER_STATUS_IN_TRANSITION_STANDBY_TO_ON) | |
782 | { | |
783 | CLibCEC::AddLog(CEC_LOG_DEBUG, "<< %s (%X) is not powered on", GetLogicalAddressName(), m_iLogicalAddress); | |
784 | return false; | |
785 | } | |
49c8f2e4 | 786 | } |
9a2f12df LOK |
787 | |
788 | MarkBusy(); | |
789 | m_handler->TransmitImageViewOn(m_iLogicalAddress, CECDEVICE_TV); | |
790 | MarkReady(); | |
791 | return true; | |
49c8f2e4 LOK |
792 | } |
793 | ||
ab27363d | 794 | bool CCECBusDevice::TransmitInactiveSource(void) |
93729720 | 795 | { |
8fa35473 LOK |
796 | uint16_t iPhysicalAddress; |
797 | { | |
f00ff009 | 798 | CLockObject lock(m_mutex); |
5477a250 | 799 | CLibCEC::AddLog(CEC_LOG_NOTICE, "<< %s (%X) -> broadcast (F): inactive source", GetLogicalAddressName(), m_iLogicalAddress); |
8fa35473 LOK |
800 | iPhysicalAddress = m_iPhysicalAddress; |
801 | } | |
93729720 | 802 | |
1344fd1a LOK |
803 | MarkBusy(); |
804 | bool bReturn = m_handler->TransmitInactiveSource(m_iLogicalAddress, iPhysicalAddress); | |
805 | MarkReady(); | |
806 | return bReturn; | |
93729720 LOK |
807 | } |
808 | ||
29912296 | 809 | bool CCECBusDevice::TransmitMenuState(cec_logical_address dest) |
0f23c85c | 810 | { |
8fa35473 LOK |
811 | cec_menu_state menuState; |
812 | { | |
f00ff009 | 813 | CLockObject lock(m_mutex); |
5477a250 | 814 | CLibCEC::AddLog(CEC_LOG_NOTICE, "<< %s (%X) -> %s (%X): menu state '%s'", GetLogicalAddressName(), m_iLogicalAddress, ToString(dest), dest, ToString(m_menuState)); |
8fa35473 LOK |
815 | menuState = m_menuState; |
816 | } | |
0f23c85c | 817 | |
1344fd1a LOK |
818 | MarkBusy(); |
819 | bool bReturn = m_handler->TransmitMenuState(m_iLogicalAddress, dest, menuState); | |
820 | MarkReady(); | |
821 | return bReturn; | |
0f23c85c LOK |
822 | } |
823 | ||
29912296 | 824 | bool CCECBusDevice::TransmitOSDName(cec_logical_address dest) |
0f23c85c | 825 | { |
8fa35473 LOK |
826 | CStdString strDeviceName; |
827 | { | |
f00ff009 | 828 | CLockObject lock(m_mutex); |
5477a250 | 829 | CLibCEC::AddLog(CEC_LOG_NOTICE, "<< %s (%X) -> %s (%X): OSD name '%s'", GetLogicalAddressName(), m_iLogicalAddress, ToString(dest), dest, m_strDeviceName.c_str()); |
8fa35473 LOK |
830 | strDeviceName = m_strDeviceName; |
831 | } | |
0f23c85c | 832 | |
1344fd1a LOK |
833 | MarkBusy(); |
834 | bool bReturn = m_handler->TransmitOSDName(m_iLogicalAddress, dest, strDeviceName); | |
835 | MarkReady(); | |
836 | return bReturn; | |
0f23c85c LOK |
837 | } |
838 | ||
38bdb943 LOK |
839 | bool CCECBusDevice::TransmitOSDString(cec_logical_address dest, cec_display_control duration, const char *strMessage) |
840 | { | |
1344fd1a | 841 | bool bReturn(false); |
66c3ef5a | 842 | if (!m_processor->m_busDevices[dest]->IsUnsupportedFeature(CEC_OPCODE_SET_OSD_STRING)) |
4d738fe3 | 843 | { |
5477a250 | 844 | CLibCEC::AddLog(CEC_LOG_NOTICE, "<< %s (%X) -> %s (%X): display OSD message '%s'", GetLogicalAddressName(), m_iLogicalAddress, ToString(dest), dest, strMessage); |
1344fd1a LOK |
845 | MarkBusy(); |
846 | bReturn = m_handler->TransmitOSDString(m_iLogicalAddress, dest, duration, strMessage); | |
847 | MarkReady(); | |
4d738fe3 | 848 | } |
1344fd1a | 849 | return bReturn; |
38bdb943 LOK |
850 | } |
851 | ||
29912296 | 852 | bool CCECBusDevice::TransmitPhysicalAddress(void) |
0f23c85c | 853 | { |
8fa35473 LOK |
854 | uint16_t iPhysicalAddress; |
855 | cec_device_type type; | |
856 | { | |
f00ff009 | 857 | CLockObject lock(m_mutex); |
8fa35473 LOK |
858 | if (m_iPhysicalAddress == 0xffff) |
859 | return false; | |
2bdfdeef | 860 | |
5477a250 | 861 | CLibCEC::AddLog(CEC_LOG_NOTICE, "<< %s (%X) -> broadcast (F): physical adddress %4x", GetLogicalAddressName(), m_iLogicalAddress, m_iPhysicalAddress); |
8fa35473 LOK |
862 | iPhysicalAddress = m_iPhysicalAddress; |
863 | type = m_type; | |
864 | } | |
0f23c85c | 865 | |
1344fd1a LOK |
866 | MarkBusy(); |
867 | bool bReturn = m_handler->TransmitPhysicalAddress(m_iLogicalAddress, iPhysicalAddress, type); | |
868 | MarkReady(); | |
869 | return bReturn; | |
0f23c85c LOK |
870 | } |
871 | ||
93729720 | 872 | bool CCECBusDevice::TransmitPoll(cec_logical_address dest) |
57f45e6c LOK |
873 | { |
874 | bool bReturn(false); | |
93729720 LOK |
875 | if (dest == CECDEVICE_UNKNOWN) |
876 | dest = m_iLogicalAddress; | |
f8513317 | 877 | |
b750a5c3 LOK |
878 | CCECBusDevice *destDevice = m_processor->m_busDevices[dest]; |
879 | if (destDevice->m_deviceStatus == CEC_DEVICE_STATUS_HANDLED_BY_LIBCEC) | |
880 | return bReturn; | |
881 | ||
1344fd1a | 882 | MarkBusy(); |
5477a250 | 883 | CLibCEC::AddLog(CEC_LOG_NOTICE, "<< %s (%X) -> %s (%X): POLL", GetLogicalAddressName(), m_iLogicalAddress, ToString(dest), dest); |
8fa35473 | 884 | bReturn = m_handler->TransmitPoll(m_iLogicalAddress, dest); |
5477a250 | 885 | CLibCEC::AddLog(CEC_LOG_DEBUG, bReturn ? ">> POLL sent" : ">> POLL not sent"); |
8fa35473 | 886 | |
f00ff009 | 887 | CLockObject lock(m_mutex); |
1674de37 | 888 | if (bReturn) |
8fa35473 | 889 | { |
1674de37 | 890 | m_iLastActive = GetTimeMs(); |
b750a5c3 | 891 | destDevice->m_deviceStatus = CEC_DEVICE_STATUS_PRESENT; |
8fa35473 | 892 | } |
b750a5c3 LOK |
893 | else |
894 | destDevice->m_deviceStatus = CEC_DEVICE_STATUS_NOT_PRESENT; | |
1674de37 | 895 | |
1344fd1a | 896 | MarkReady(); |
57f45e6c LOK |
897 | return bReturn; |
898 | } | |
93729720 LOK |
899 | |
900 | bool CCECBusDevice::TransmitPowerState(cec_logical_address dest) | |
901 | { | |
8fa35473 LOK |
902 | cec_power_status state; |
903 | { | |
f00ff009 | 904 | CLockObject lock(m_mutex); |
bbc71623 | 905 | if (!IsActiveSource()) |
24dd566c LOK |
906 | { |
907 | CLibCEC::AddLog(CEC_LOG_NOTICE, "power state requested of %s (%X), but we are not the active source. setting power state to standby", GetLogicalAddressName(), m_iLogicalAddress); | |
bbc71623 | 908 | SetPowerStatus(CEC_POWER_STATUS_STANDBY); |
24dd566c | 909 | } |
bbc71623 | 910 | |
5477a250 | 911 | CLibCEC::AddLog(CEC_LOG_NOTICE, "<< %s (%X) -> %s (%X): %s", GetLogicalAddressName(), m_iLogicalAddress, ToString(dest), dest, ToString(m_powerStatus)); |
8fa35473 LOK |
912 | state = m_powerStatus; |
913 | } | |
93729720 | 914 | |
1344fd1a LOK |
915 | MarkBusy(); |
916 | bool bReturn = m_handler->TransmitPowerState(m_iLogicalAddress, dest, state); | |
917 | MarkReady(); | |
918 | return bReturn; | |
93729720 LOK |
919 | } |
920 | ||
fe6f8e37 | 921 | bool CCECBusDevice::TransmitVendorID(cec_logical_address dest, bool bSendAbort /* = true */) |
93729720 | 922 | { |
1344fd1a | 923 | bool bReturn(false); |
8fa35473 LOK |
924 | uint64_t iVendorId; |
925 | { | |
f00ff009 | 926 | CLockObject lock(m_mutex); |
8fa35473 LOK |
927 | iVendorId = (uint64_t)m_vendor; |
928 | } | |
929 | ||
1344fd1a | 930 | MarkBusy(); |
8fa35473 | 931 | if (iVendorId == CEC_VENDOR_UNKNOWN) |
c4098482 | 932 | { |
fe6f8e37 LOK |
933 | if (bSendAbort) |
934 | { | |
5477a250 | 935 | CLibCEC::AddLog(CEC_LOG_NOTICE, "<< %s (%X) -> %s (%X): vendor id feature abort", GetLogicalAddressName(), m_iLogicalAddress, ToString(dest), dest); |
fe6f8e37 | 936 | m_processor->TransmitAbort(dest, CEC_OPCODE_GIVE_DEVICE_VENDOR_ID); |
1344fd1a | 937 | bReturn = true; |
fe6f8e37 | 938 | } |
c4098482 LOK |
939 | } |
940 | else | |
941 | { | |
5477a250 | 942 | CLibCEC::AddLog(CEC_LOG_NOTICE, "<< %s (%X) -> %s (%X): vendor id %s (%x)", GetLogicalAddressName(), m_iLogicalAddress, ToString(dest), dest, ToString((cec_vendor_id)iVendorId), iVendorId); |
1344fd1a | 943 | bReturn = m_handler->TransmitVendorID(m_iLogicalAddress, iVendorId); |
c4098482 | 944 | } |
1344fd1a LOK |
945 | MarkReady(); |
946 | return bReturn; | |
93729720 | 947 | } |
a33794d8 | 948 | |
4bec9d79 | 949 | bool CCECBusDevice::TransmitKeypress(cec_user_control_code key, bool bWait /* = true */) |
a33794d8 | 950 | { |
1344fd1a LOK |
951 | MarkBusy(); |
952 | bool bReturn = m_handler->TransmitKeypress(m_processor->GetLogicalAddress(), m_iLogicalAddress, key, bWait); | |
953 | MarkReady(); | |
954 | return bReturn; | |
a33794d8 LOK |
955 | } |
956 | ||
4bec9d79 | 957 | bool CCECBusDevice::TransmitKeyRelease(bool bWait /* = true */) |
a33794d8 | 958 | { |
1344fd1a LOK |
959 | MarkBusy(); |
960 | bool bReturn = m_handler->TransmitKeyRelease(m_processor->GetLogicalAddress(), m_iLogicalAddress, bWait); | |
961 | MarkReady(); | |
962 | return bReturn; | |
a33794d8 | 963 | } |
4d738fe3 LOK |
964 | |
965 | bool CCECBusDevice::IsUnsupportedFeature(cec_opcode opcode) const | |
966 | { | |
66c3ef5a LOK |
967 | bool bUnsupported = (m_unsupportedFeatures.find(opcode) != m_unsupportedFeatures.end()); |
968 | if (bUnsupported) | |
969 | CLibCEC::AddLog(CEC_LOG_NOTICE, "'%s' is marked as unsupported feature for device '%s'", ToString(opcode), GetLogicalAddressName()); | |
970 | return bUnsupported; | |
4d738fe3 LOK |
971 | } |
972 | ||
973 | void CCECBusDevice::SetUnsupportedFeature(cec_opcode opcode) | |
974 | { | |
66c3ef5a | 975 | CLibCEC::AddLog(CEC_LOG_DEBUG, "marking opcode '%s' as unsupported feature for device '%s'", ToString(opcode), GetLogicalAddressName()); |
4d738fe3 LOK |
976 | m_unsupportedFeatures.insert(opcode); |
977 | } | |
b64db02e | 978 | |
3e61b350 | 979 | bool CCECBusDevice::ActivateSource(void) |
b64db02e | 980 | { |
1344fd1a LOK |
981 | MarkBusy(); |
982 | bool bReturn = m_handler->ActivateSource(); | |
983 | MarkReady(); | |
984 | return bReturn; | |
b64db02e LOK |
985 | } |
986 | ||
ef583662 | 987 | void CCECBusDevice::HandlePoll(cec_logical_address iDestination) |
0cfdeb5a | 988 | { |
ef583662 LOK |
989 | CLibCEC::AddLog(CEC_LOG_DEBUG, "<< POLL: %s (%x) -> %s (%x)", ToString(m_iLogicalAddress), m_iLogicalAddress, ToString(iDestination), iDestination); |
990 | m_bAwaitingReceiveFailed = true; | |
0cfdeb5a LOK |
991 | } |
992 | ||
993 | bool CCECBusDevice::HandleReceiveFailed(void) | |
994 | { | |
ef583662 LOK |
995 | bool bReturn = m_bAwaitingReceiveFailed; |
996 | m_bAwaitingReceiveFailed = false; | |
997 | return bReturn; | |
0cfdeb5a LOK |
998 | } |
999 | ||
ebb6ddb3 LOK |
1000 | void CCECBusDevice::CheckVendorIdRequested(void) |
1001 | { | |
1002 | bool bRequestVendorId(false); | |
1003 | { | |
1004 | CLockObject lock(m_mutex); | |
1005 | bRequestVendorId = !m_bVendorIdRequested; | |
1006 | m_bVendorIdRequested = true; | |
1007 | } | |
1008 | ||
1009 | if (bRequestVendorId) | |
1010 | { | |
1011 | ReplaceHandler(false); | |
1012 | GetVendorId(); | |
1013 | } | |
1014 | } | |
1015 | ||
93729720 | 1016 | //@} |