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 | ||
2b44051c | 33 | #include "env.h" |
e9de9629 | 34 | #include "CECBusDevice.h" |
2b44051c LOK |
35 | |
36 | #include "lib/CECProcessor.h" | |
37 | #include "lib/CECClient.h" | |
38 | #include "lib/implementations/ANCommandHandler.h" | |
39 | #include "lib/implementations/CECCommandHandler.h" | |
40 | #include "lib/implementations/SLCommandHandler.h" | |
41 | #include "lib/implementations/VLCommandHandler.h" | |
42 | #include "lib/LibCEC.h" | |
43 | #include "lib/CECTypeUtils.h" | |
44 | #include "lib/platform/util/timeutils.h" | |
45 | #include "lib/platform/util/util.h" | |
e9de9629 | 46 | |
004b8382 LOK |
47 | #include "CECAudioSystem.h" |
48 | #include "CECPlaybackDevice.h" | |
49 | #include "CECRecordingDevice.h" | |
50 | #include "CECTuner.h" | |
51 | #include "CECTV.h" | |
52 | ||
53 | using namespace std; | |
e9de9629 | 54 | using namespace CEC; |
f00ff009 | 55 | using namespace PLATFORM; |
e9de9629 | 56 | |
004b8382 | 57 | #define LIB_CEC m_processor->GetLib() |
0d800fe5 | 58 | #define ToString(p) CCECTypeUtils::ToString(p) |
c4098482 | 59 | |
d2d1660c | 60 | CCECBusDevice::CCECBusDevice(CCECProcessor *processor, cec_logical_address iLogicalAddress, uint16_t iPhysicalAddress /* = CEC_INVALID_PHYSICAL_ADDRESS */) : |
ecc676ca LOK |
61 | m_type (CEC_DEVICE_TYPE_RESERVED), |
62 | m_iPhysicalAddress (iPhysicalAddress), | |
b32ffd87 | 63 | m_iStreamPath (CEC_INVALID_PHYSICAL_ADDRESS), |
ecc676ca LOK |
64 | m_iLogicalAddress (iLogicalAddress), |
65 | m_powerStatus (CEC_POWER_STATUS_UNKNOWN), | |
66 | m_processor (processor), | |
67 | m_vendor (CEC_VENDOR_UNKNOWN), | |
68 | m_bReplaceHandler (false), | |
69 | m_menuState (CEC_MENU_STATE_ACTIVATED), | |
70 | m_bActiveSource (false), | |
71 | m_iLastActive (0), | |
72 | m_iLastPowerStateUpdate (0), | |
73 | m_cecVersion (CEC_VERSION_UNKNOWN), | |
74 | m_deviceStatus (CEC_DEVICE_STATUS_UNKNOWN), | |
75 | m_iHandlerUseCount (0), | |
ebb6ddb3 | 76 | m_bAwaitingReceiveFailed(false), |
060a7b5e LOK |
77 | m_bVendorIdRequested (false), |
78 | m_waitForResponse (new CWaitForResponse) | |
e9de9629 LOK |
79 | { |
80 | m_handler = new CCECCommandHandler(this); | |
51b2a094 | 81 | |
a3269a0a LOK |
82 | for (unsigned int iPtr = 0; iPtr < 4; iPtr++) |
83 | m_menuLanguage.language[iPtr] = '?'; | |
84 | m_menuLanguage.language[3] = 0; | |
85 | m_menuLanguage.device = iLogicalAddress; | |
1fcf5a3f | 86 | |
c4098482 | 87 | m_strDeviceName = ToString(m_iLogicalAddress); |
e9de9629 LOK |
88 | } |
89 | ||
90 | CCECBusDevice::~CCECBusDevice(void) | |
91 | { | |
c9d15485 | 92 | DELETE_AND_NULL(m_handler); |
060a7b5e | 93 | DELETE_AND_NULL(m_waitForResponse); |
e9de9629 LOK |
94 | } |
95 | ||
004b8382 LOK |
96 | bool CCECBusDevice::ReplaceHandler(bool bActivateSource /* = true */) |
97 | { | |
880f082e LOK |
98 | if (m_iLogicalAddress == CECDEVICE_BROADCAST) |
99 | return false; | |
100 | ||
004b8382 LOK |
101 | bool bInitHandler(false); |
102 | { | |
2b44051c | 103 | CLockObject lock(m_mutex); |
004b8382 LOK |
104 | CLockObject handlerLock(m_handlerMutex); |
105 | if (m_iHandlerUseCount > 0) | |
106 | return false; | |
107 | ||
108 | MarkBusy(); | |
109 | ||
110 | if (m_vendor != m_handler->GetVendorId()) | |
111 | { | |
112 | if (CCECCommandHandler::HasSpecificHandler(m_vendor)) | |
113 | { | |
114 | LIB_CEC->AddLog(CEC_LOG_DEBUG, "replacing the command handler for device '%s' (%x)", GetLogicalAddressName(), GetLogicalAddress()); | |
060a7b5e LOK |
115 | |
116 | int32_t iTransmitTimeout = m_handler->m_iTransmitTimeout; | |
117 | int32_t iTransmitWait = m_handler->m_iTransmitWait; | |
118 | int8_t iTransmitRetries = m_handler->m_iTransmitRetries; | |
119 | int64_t iActiveSourcePending = m_handler->m_iActiveSourcePending; | |
120 | ||
c9d15485 | 121 | DELETE_AND_NULL(m_handler); |
004b8382 LOK |
122 | |
123 | switch (m_vendor) | |
124 | { | |
125 | case CEC_VENDOR_SAMSUNG: | |
060a7b5e | 126 | m_handler = new CANCommandHandler(this, iTransmitTimeout, iTransmitWait, iTransmitRetries, iActiveSourcePending); |
004b8382 LOK |
127 | break; |
128 | case CEC_VENDOR_LG: | |
060a7b5e | 129 | m_handler = new CSLCommandHandler(this, iTransmitTimeout, iTransmitWait, iTransmitRetries, iActiveSourcePending); |
004b8382 LOK |
130 | break; |
131 | case CEC_VENDOR_PANASONIC: | |
060a7b5e | 132 | m_handler = new CVLCommandHandler(this, iTransmitTimeout, iTransmitWait, iTransmitRetries, iActiveSourcePending); |
004b8382 LOK |
133 | break; |
134 | default: | |
060a7b5e | 135 | m_handler = new CCECCommandHandler(this, iTransmitTimeout, iTransmitWait, iTransmitRetries, iActiveSourcePending); |
004b8382 LOK |
136 | break; |
137 | } | |
138 | ||
139 | m_handler->SetVendorId(m_vendor); | |
140 | bInitHandler = true; | |
141 | } | |
142 | } | |
143 | } | |
144 | ||
145 | if (bInitHandler) | |
146 | { | |
42d28d15 LOK |
147 | CCECBusDevice *primary = GetProcessor()->GetPrimaryDevice(); |
148 | if (primary->GetLogicalAddress() != CECDEVICE_UNREGISTERED) | |
149 | { | |
150 | m_handler->InitHandler(); | |
004b8382 | 151 | |
42d28d15 LOK |
152 | if (bActivateSource && IsHandledByLibCEC() && IsActiveSource()) |
153 | m_handler->ActivateSource(); | |
154 | } | |
004b8382 LOK |
155 | } |
156 | ||
157 | MarkReady(); | |
158 | ||
159 | return true; | |
160 | } | |
161 | ||
91ef4e2d LOK |
162 | CCECCommandHandler *CCECBusDevice::GetHandler(void) |
163 | { | |
164 | ReplaceHandler(false); | |
165 | MarkBusy(); | |
166 | return m_handler; | |
167 | } | |
168 | ||
93729720 | 169 | bool CCECBusDevice::HandleCommand(const cec_command &command) |
f8513317 | 170 | { |
7f919115 LOK |
171 | bool bHandled(false); |
172 | ||
173 | /* update "last active" */ | |
8fa35473 | 174 | { |
f00ff009 | 175 | CLockObject lock(m_mutex); |
8fa35473 | 176 | m_iLastActive = GetTimeMs(); |
1344fd1a | 177 | MarkBusy(); |
8fa35473 LOK |
178 | } |
179 | ||
7f919115 LOK |
180 | /* handle the command */ |
181 | bHandled = m_handler->HandleCommand(command); | |
8fa35473 | 182 | |
7f919115 | 183 | /* change status to present */ |
004b8382 | 184 | if (bHandled && GetLogicalAddress() != CECDEVICE_BROADCAST) |
8d915412 | 185 | { |
f00ff009 | 186 | CLockObject lock(m_mutex); |
8fa35473 | 187 | if (m_deviceStatus != CEC_DEVICE_STATUS_HANDLED_BY_LIBCEC) |
8d915412 | 188 | { |
8fa35473 | 189 | if (m_deviceStatus != CEC_DEVICE_STATUS_PRESENT) |
004b8382 | 190 | LIB_CEC->AddLog(CEC_LOG_DEBUG, "device %s (%x) status changed to present after command %s", GetLogicalAddressName(), (uint8_t)GetLogicalAddress(), ToString(command.opcode)); |
8fa35473 | 191 | m_deviceStatus = CEC_DEVICE_STATUS_PRESENT; |
8d915412 | 192 | } |
8d915412 | 193 | } |
7f919115 | 194 | |
1344fd1a | 195 | MarkReady(); |
7f919115 | 196 | return bHandled; |
93729720 LOK |
197 | } |
198 | ||
004b8382 | 199 | const char* CCECBusDevice::GetLogicalAddressName(void) const |
93729720 | 200 | { |
004b8382 LOK |
201 | return ToString(m_iLogicalAddress); |
202 | } | |
203 | ||
204 | bool CCECBusDevice::IsPresent(void) | |
205 | { | |
206 | CLockObject lock(m_mutex); | |
207 | return m_deviceStatus == CEC_DEVICE_STATUS_PRESENT; | |
208 | } | |
209 | ||
210 | bool CCECBusDevice::IsHandledByLibCEC(void) | |
211 | { | |
212 | CLockObject lock(m_mutex); | |
213 | return m_deviceStatus == CEC_DEVICE_STATUS_HANDLED_BY_LIBCEC; | |
214 | } | |
215 | ||
216 | void CCECBusDevice::SetUnsupportedFeature(cec_opcode opcode) | |
217 | { | |
218 | // some commands should never be marked as unsupported | |
219 | if (opcode == CEC_OPCODE_VENDOR_COMMAND || | |
220 | opcode == CEC_OPCODE_VENDOR_COMMAND_WITH_ID || | |
221 | opcode == CEC_OPCODE_VENDOR_REMOTE_BUTTON_DOWN || | |
222 | opcode == CEC_OPCODE_VENDOR_REMOTE_BUTTON_UP || | |
223 | opcode == CEC_OPCODE_ABORT || | |
224 | opcode == CEC_OPCODE_FEATURE_ABORT || | |
225 | opcode == CEC_OPCODE_NONE) | |
226 | return; | |
c6d7f0e1 | 227 | |
5e5637c6 | 228 | { |
004b8382 LOK |
229 | CLockObject lock(m_mutex); |
230 | if (m_unsupportedFeatures.find(opcode) == m_unsupportedFeatures.end()) | |
8670c970 | 231 | { |
004b8382 LOK |
232 | LIB_CEC->AddLog(CEC_LOG_DEBUG, "marking opcode '%s' as unsupported feature for device '%s'", ToString(opcode), GetLogicalAddressName()); |
233 | m_unsupportedFeatures.insert(opcode); | |
8670c970 LOK |
234 | } |
235 | } | |
f437e4be | 236 | |
004b8382 LOK |
237 | // signal threads that are waiting for a reponse |
238 | MarkBusy(); | |
060a7b5e | 239 | SignalOpcode(cec_command::GetResponseOpcode(opcode)); |
004b8382 LOK |
240 | MarkReady(); |
241 | } | |
242 | ||
243 | bool CCECBusDevice::IsUnsupportedFeature(cec_opcode opcode) | |
244 | { | |
245 | CLockObject lock(m_mutex); | |
246 | bool bUnsupported = (m_unsupportedFeatures.find(opcode) != m_unsupportedFeatures.end()); | |
247 | if (bUnsupported) | |
248 | LIB_CEC->AddLog(CEC_LOG_DEBUG, "'%s' is marked as unsupported feature for device '%s'", ToString(opcode), GetLogicalAddressName()); | |
249 | return bUnsupported; | |
250 | } | |
251 | ||
252 | bool CCECBusDevice::TransmitKeypress(const cec_logical_address initiator, cec_user_control_code key, bool bWait /* = true */) | |
253 | { | |
254 | MarkBusy(); | |
255 | bool bReturn = m_handler->TransmitKeypress(initiator, m_iLogicalAddress, key, bWait); | |
1344fd1a LOK |
256 | MarkReady(); |
257 | return bReturn; | |
93729720 LOK |
258 | } |
259 | ||
004b8382 | 260 | bool CCECBusDevice::TransmitKeyRelease(const cec_logical_address initiator, bool bWait /* = true */) |
93729720 | 261 | { |
1344fd1a | 262 | MarkBusy(); |
004b8382 | 263 | bool bReturn = m_handler->TransmitKeyRelease(initiator, m_iLogicalAddress, bWait); |
1344fd1a LOK |
264 | MarkReady(); |
265 | return bReturn; | |
93729720 LOK |
266 | } |
267 | ||
004b8382 | 268 | cec_version CCECBusDevice::GetCecVersion(const cec_logical_address initiator, bool bUpdate /* = false */) |
93729720 | 269 | { |
6bbfc3f7 | 270 | bool bIsPresent(GetStatus() == CEC_DEVICE_STATUS_PRESENT); |
97fc4ffb LOK |
271 | bool bRequestUpdate(false); |
272 | { | |
f00ff009 | 273 | CLockObject lock(m_mutex); |
ddb6ac5b | 274 | bRequestUpdate = bIsPresent && |
6bbfc3f7 | 275 | (bUpdate || m_cecVersion == CEC_VERSION_UNKNOWN); |
97fc4ffb LOK |
276 | } |
277 | ||
278 | if (bRequestUpdate) | |
ebb6ddb3 | 279 | { |
004b8382 LOK |
280 | CheckVendorIdRequested(initiator); |
281 | RequestCecVersion(initiator); | |
ebb6ddb3 | 282 | } |
f294b22f | 283 | |
f00ff009 | 284 | CLockObject lock(m_mutex); |
f294b22f LOK |
285 | return m_cecVersion; |
286 | } | |
287 | ||
004b8382 | 288 | void CCECBusDevice::SetCecVersion(const cec_version newVersion) |
5734016c | 289 | { |
004b8382 LOK |
290 | CLockObject lock(m_mutex); |
291 | if (m_cecVersion != newVersion) | |
292 | LIB_CEC->AddLog(CEC_LOG_DEBUG, "%s (%X): CEC version %s", GetLogicalAddressName(), m_iLogicalAddress, ToString(newVersion)); | |
293 | m_cecVersion = newVersion; | |
5734016c LOK |
294 | } |
295 | ||
004b8382 | 296 | bool CCECBusDevice::RequestCecVersion(const cec_logical_address initiator, bool bWaitForResponse /* = true */) |
f294b22f LOK |
297 | { |
298 | bool bReturn(false); | |
b64db02e | 299 | |
004b8382 | 300 | if (!IsHandledByLibCEC() && |
66c3ef5a | 301 | !IsUnsupportedFeature(CEC_OPCODE_GET_CEC_VERSION)) |
93729720 | 302 | { |
1344fd1a | 303 | MarkBusy(); |
ff07d530 | 304 | LIB_CEC->AddLog(CEC_LOG_DEBUG, "<< requesting CEC version of '%s' (%X)", GetLogicalAddressName(), m_iLogicalAddress); |
004b8382 | 305 | bReturn = m_handler->TransmitRequestCecVersion(initiator, m_iLogicalAddress, bWaitForResponse); |
1344fd1a | 306 | MarkReady(); |
93729720 | 307 | } |
f294b22f | 308 | return bReturn; |
93729720 LOK |
309 | } |
310 | ||
2b44051c | 311 | bool CCECBusDevice::TransmitCECVersion(const cec_logical_address destination, bool bIsReply) |
62f5527d | 312 | { |
004b8382 LOK |
313 | cec_version version; |
314 | { | |
315 | CLockObject lock(m_mutex); | |
ff07d530 | 316 | LIB_CEC->AddLog(CEC_LOG_DEBUG, "<< %s (%X) -> %s (%X): cec version %s", GetLogicalAddressName(), m_iLogicalAddress, ToString(destination), destination, ToString(m_cecVersion)); |
004b8382 LOK |
317 | version = m_cecVersion; |
318 | } | |
319 | ||
320 | MarkBusy(); | |
2b44051c | 321 | bool bReturn = m_handler->TransmitCECVersion(m_iLogicalAddress, destination, version, bIsReply); |
004b8382 LOK |
322 | MarkReady(); |
323 | return bReturn; | |
62f5527d LOK |
324 | } |
325 | ||
004b8382 | 326 | cec_menu_language &CCECBusDevice::GetMenuLanguage(const cec_logical_address initiator, bool bUpdate /* = false */) |
93729720 | 327 | { |
6bbfc3f7 | 328 | bool bIsPresent(GetStatus() == CEC_DEVICE_STATUS_PRESENT); |
97fc4ffb LOK |
329 | bool bRequestUpdate(false); |
330 | { | |
f00ff009 | 331 | CLockObject lock(m_mutex); |
ddb6ac5b | 332 | bRequestUpdate = (bIsPresent && |
97fc4ffb LOK |
333 | (bUpdate || !strcmp(m_menuLanguage.language, "???"))); |
334 | } | |
335 | ||
336 | if (bRequestUpdate) | |
ebb6ddb3 | 337 | { |
004b8382 LOK |
338 | CheckVendorIdRequested(initiator); |
339 | RequestMenuLanguage(initiator); | |
ebb6ddb3 | 340 | } |
5e5637c6 | 341 | |
f00ff009 | 342 | CLockObject lock(m_mutex); |
f294b22f LOK |
343 | return m_menuLanguage; |
344 | } | |
345 | ||
004b8382 LOK |
346 | void CCECBusDevice::SetMenuLanguage(const char *strLanguage) |
347 | { | |
348 | if (!strLanguage) | |
349 | return; | |
350 | ||
351 | CLockObject lock(m_mutex); | |
352 | if (strcmp(strLanguage, m_menuLanguage.language)) | |
353 | { | |
354 | memcpy(m_menuLanguage.language, strLanguage, 3); | |
60c28d82 | 355 | LIB_CEC->AddLog(CEC_LOG_DEBUG, "%s (%X): menu language set to '%s'", GetLogicalAddressName(), m_iLogicalAddress, m_menuLanguage.language); |
004b8382 LOK |
356 | } |
357 | } | |
358 | ||
359 | void CCECBusDevice::SetMenuLanguage(const cec_menu_language &language) | |
360 | { | |
361 | if (language.device == m_iLogicalAddress) | |
362 | SetMenuLanguage(language.language); | |
363 | } | |
364 | ||
365 | bool CCECBusDevice::RequestMenuLanguage(const cec_logical_address initiator, bool bWaitForResponse /* = true */) | |
f294b22f LOK |
366 | { |
367 | bool bReturn(false); | |
b64db02e | 368 | |
004b8382 | 369 | if (!IsHandledByLibCEC() && |
4d738fe3 | 370 | !IsUnsupportedFeature(CEC_OPCODE_GET_MENU_LANGUAGE)) |
93729720 | 371 | { |
1344fd1a | 372 | MarkBusy(); |
ff07d530 | 373 | LIB_CEC->AddLog(CEC_LOG_DEBUG, "<< requesting menu language of '%s' (%X)", GetLogicalAddressName(), m_iLogicalAddress); |
004b8382 | 374 | bReturn = m_handler->TransmitRequestMenuLanguage(initiator, m_iLogicalAddress, bWaitForResponse); |
1344fd1a | 375 | MarkReady(); |
93729720 | 376 | } |
f294b22f | 377 | return bReturn; |
93729720 LOK |
378 | } |
379 | ||
2b44051c | 380 | bool CCECBusDevice::TransmitSetMenuLanguage(const cec_logical_address destination, bool bIsReply) |
3e61b350 | 381 | { |
004b8382 LOK |
382 | bool bReturn(false); |
383 | cec_menu_language language; | |
384 | { | |
385 | CLockObject lock(m_mutex); | |
386 | language = m_menuLanguage; | |
387 | } | |
3e61b350 | 388 | |
004b8382 LOK |
389 | char lang[3]; |
390 | { | |
391 | CLockObject lock(m_mutex); | |
392 | lang[0] = language.language[0]; | |
393 | lang[1] = language.language[1]; | |
394 | lang[2] = language.language[2]; | |
395 | } | |
396 | ||
397 | MarkBusy(); | |
398 | if (lang[0] == '?' && lang[1] == '?' && lang[2] == '?') | |
399 | { | |
ff07d530 | 400 | LIB_CEC->AddLog(CEC_LOG_DEBUG, "<< %s (%X) -> %s (%X): menu language feature abort", GetLogicalAddressName(), m_iLogicalAddress, ToString(destination), destination); |
004b8382 LOK |
401 | m_processor->TransmitAbort(m_iLogicalAddress, destination, CEC_OPCODE_GIVE_DEVICE_VENDOR_ID); |
402 | bReturn = true; | |
403 | } | |
404 | else | |
405 | { | |
ff07d530 | 406 | LIB_CEC->AddLog(CEC_LOG_DEBUG, "<< %s (%X) -> broadcast (F): menu language '%s'", GetLogicalAddressName(), m_iLogicalAddress, lang); |
2b44051c | 407 | bReturn = m_handler->TransmitSetMenuLanguage(m_iLogicalAddress, lang, bIsReply); |
004b8382 LOK |
408 | } |
409 | MarkReady(); | |
410 | return bReturn; | |
f8513317 LOK |
411 | } |
412 | ||
2b44051c | 413 | bool CCECBusDevice::TransmitOSDString(const cec_logical_address destination, cec_display_control duration, const char *strMessage, bool bIsReply) |
e9de9629 | 414 | { |
004b8382 LOK |
415 | bool bReturn(false); |
416 | if (!m_processor->GetDevice(destination)->IsUnsupportedFeature(CEC_OPCODE_SET_OSD_STRING)) | |
417 | { | |
ff07d530 | 418 | LIB_CEC->AddLog(CEC_LOG_DEBUG, "<< %s (%X) -> %s (%X): display OSD message '%s'", GetLogicalAddressName(), m_iLogicalAddress, ToString(destination), destination, strMessage); |
004b8382 | 419 | MarkBusy(); |
2b44051c | 420 | bReturn = m_handler->TransmitOSDString(m_iLogicalAddress, destination, duration, strMessage, bIsReply); |
004b8382 LOK |
421 | MarkReady(); |
422 | } | |
423 | return bReturn; | |
e9de9629 LOK |
424 | } |
425 | ||
c0152c09 LOK |
426 | CStdString CCECBusDevice::GetCurrentOSDName(void) |
427 | { | |
428 | CLockObject lock(m_mutex); | |
429 | return m_strDeviceName; | |
430 | } | |
431 | ||
004b8382 | 432 | CStdString CCECBusDevice::GetOSDName(const cec_logical_address initiator, bool bUpdate /* = false */) |
ed21be2a | 433 | { |
6bbfc3f7 | 434 | bool bIsPresent(GetStatus() == CEC_DEVICE_STATUS_PRESENT); |
97fc4ffb LOK |
435 | bool bRequestUpdate(false); |
436 | { | |
f00ff009 | 437 | CLockObject lock(m_mutex); |
ddb6ac5b | 438 | bRequestUpdate = bIsPresent && |
97fc4ffb | 439 | (bUpdate || m_strDeviceName.Equals(ToString(m_iLogicalAddress))) && |
ddb6ac5b | 440 | m_type != CEC_DEVICE_TYPE_TV; |
97fc4ffb LOK |
441 | } |
442 | ||
443 | if (bRequestUpdate) | |
ebb6ddb3 | 444 | { |
004b8382 LOK |
445 | CheckVendorIdRequested(initiator); |
446 | RequestOSDName(initiator); | |
ebb6ddb3 | 447 | } |
5e5637c6 | 448 | |
f00ff009 | 449 | CLockObject lock(m_mutex); |
ed21be2a LOK |
450 | return m_strDeviceName; |
451 | } | |
452 | ||
004b8382 LOK |
453 | void CCECBusDevice::SetOSDName(CStdString strName) |
454 | { | |
455 | CLockObject lock(m_mutex); | |
456 | if (m_strDeviceName != strName) | |
457 | { | |
60c28d82 | 458 | LIB_CEC->AddLog(CEC_LOG_DEBUG, "%s (%X): osd name set to '%s'", GetLogicalAddressName(), m_iLogicalAddress, strName.c_str()); |
004b8382 LOK |
459 | m_strDeviceName = strName; |
460 | } | |
461 | } | |
462 | ||
463 | bool CCECBusDevice::RequestOSDName(const cec_logical_address initiator, bool bWaitForResponse /* = true */) | |
ed21be2a LOK |
464 | { |
465 | bool bReturn(false); | |
b64db02e | 466 | |
004b8382 | 467 | if (!IsHandledByLibCEC() && |
4d738fe3 | 468 | !IsUnsupportedFeature(CEC_OPCODE_GIVE_OSD_NAME)) |
ed21be2a | 469 | { |
1344fd1a | 470 | MarkBusy(); |
ff07d530 | 471 | LIB_CEC->AddLog(CEC_LOG_DEBUG, "<< requesting OSD name of '%s' (%X)", GetLogicalAddressName(), m_iLogicalAddress); |
004b8382 | 472 | bReturn = m_handler->TransmitRequestOSDName(initiator, m_iLogicalAddress, bWaitForResponse); |
1344fd1a | 473 | MarkReady(); |
ed21be2a LOK |
474 | } |
475 | return bReturn; | |
476 | } | |
477 | ||
2b44051c | 478 | bool CCECBusDevice::TransmitOSDName(const cec_logical_address destination, bool bIsReply) |
004b8382 LOK |
479 | { |
480 | CStdString strDeviceName; | |
481 | { | |
482 | CLockObject lock(m_mutex); | |
ff07d530 | 483 | LIB_CEC->AddLog(CEC_LOG_DEBUG, "<< %s (%X) -> %s (%X): OSD name '%s'", GetLogicalAddressName(), m_iLogicalAddress, ToString(destination), destination, m_strDeviceName.c_str()); |
004b8382 LOK |
484 | strDeviceName = m_strDeviceName; |
485 | } | |
486 | ||
487 | MarkBusy(); | |
2b44051c | 488 | bool bReturn = m_handler->TransmitOSDName(m_iLogicalAddress, destination, strDeviceName, bIsReply); |
004b8382 LOK |
489 | MarkReady(); |
490 | return bReturn; | |
491 | } | |
492 | ||
493 | bool CCECBusDevice::HasValidPhysicalAddress(void) | |
494 | { | |
495 | CLockObject lock(m_mutex); | |
496 | return CLibCEC::IsValidPhysicalAddress(m_iPhysicalAddress); | |
497 | } | |
498 | ||
499 | uint16_t CCECBusDevice::GetCurrentPhysicalAddress(void) | |
500 | { | |
501 | CLockObject lock(m_mutex); | |
502 | return m_iPhysicalAddress; | |
503 | } | |
504 | ||
505 | uint16_t CCECBusDevice::GetPhysicalAddress(const cec_logical_address initiator, bool bSuppressUpdate /* = false */) | |
16b1e052 | 506 | { |
0680dab3 | 507 | if (!bSuppressUpdate) |
16b1e052 | 508 | { |
0680dab3 LOK |
509 | bool bIsPresent(GetStatus() == CEC_DEVICE_STATUS_PRESENT); |
510 | bool bRequestUpdate(false); | |
511 | { | |
512 | CLockObject lock(m_mutex); | |
b32ffd87 | 513 | bRequestUpdate = bIsPresent && m_iPhysicalAddress == CEC_INVALID_PHYSICAL_ADDRESS; |
0680dab3 | 514 | } |
16b1e052 | 515 | |
0680dab3 LOK |
516 | if (bRequestUpdate) |
517 | { | |
004b8382 LOK |
518 | CheckVendorIdRequested(initiator); |
519 | if (!RequestPhysicalAddress(initiator)) | |
520 | LIB_CEC->AddLog(CEC_LOG_ERROR, "failed to request the physical address"); | |
0680dab3 | 521 | } |
ebb6ddb3 | 522 | } |
97fc4ffb | 523 | |
f00ff009 | 524 | CLockObject lock(m_mutex); |
16b1e052 LOK |
525 | return m_iPhysicalAddress; |
526 | } | |
527 | ||
004b8382 LOK |
528 | bool CCECBusDevice::SetPhysicalAddress(uint16_t iNewAddress) |
529 | { | |
530 | CLockObject lock(m_mutex); | |
531 | if (iNewAddress > 0 && m_iPhysicalAddress != iNewAddress) | |
532 | { | |
60c28d82 | 533 | LIB_CEC->AddLog(CEC_LOG_DEBUG, "%s (%X): physical address changed from %04x to %04x", GetLogicalAddressName(), m_iLogicalAddress, m_iPhysicalAddress, iNewAddress); |
004b8382 | 534 | m_iPhysicalAddress = iNewAddress; |
d3caa81b LOK |
535 | |
536 | if (m_processor->GetDevices()->GetActiveSourceAddress() == iNewAddress) | |
537 | MarkAsActiveSource(); | |
004b8382 LOK |
538 | } |
539 | return true; | |
540 | } | |
541 | ||
542 | bool CCECBusDevice::RequestPhysicalAddress(const cec_logical_address initiator, bool bWaitForResponse /* = true */) | |
16b1e052 LOK |
543 | { |
544 | bool bReturn(false); | |
b64db02e | 545 | |
004b8382 | 546 | if (!IsHandledByLibCEC()) |
16b1e052 | 547 | { |
1344fd1a | 548 | MarkBusy(); |
ff07d530 | 549 | LIB_CEC->AddLog(CEC_LOG_DEBUG, "<< requesting physical address of '%s' (%X)", GetLogicalAddressName(), m_iLogicalAddress); |
004b8382 | 550 | bReturn = m_handler->TransmitRequestPhysicalAddress(initiator, m_iLogicalAddress, bWaitForResponse); |
1344fd1a | 551 | MarkReady(); |
16b1e052 LOK |
552 | } |
553 | return bReturn; | |
554 | } | |
555 | ||
2b44051c | 556 | bool CCECBusDevice::TransmitPhysicalAddress(bool bIsReply) |
004b8382 LOK |
557 | { |
558 | uint16_t iPhysicalAddress; | |
559 | cec_device_type type; | |
560 | { | |
561 | CLockObject lock(m_mutex); | |
562 | if (m_iPhysicalAddress == CEC_INVALID_PHYSICAL_ADDRESS) | |
563 | return false; | |
564 | ||
ff07d530 | 565 | LIB_CEC->AddLog(CEC_LOG_DEBUG, "<< %s (%X) -> broadcast (F): physical adddress %4x", GetLogicalAddressName(), m_iLogicalAddress, m_iPhysicalAddress); |
004b8382 LOK |
566 | iPhysicalAddress = m_iPhysicalAddress; |
567 | type = m_type; | |
568 | } | |
569 | ||
570 | MarkBusy(); | |
2b44051c | 571 | bool bReturn = m_handler->TransmitPhysicalAddress(m_iLogicalAddress, iPhysicalAddress, type, bIsReply); |
004b8382 LOK |
572 | MarkReady(); |
573 | return bReturn; | |
574 | } | |
575 | ||
576 | cec_power_status CCECBusDevice::GetCurrentPowerStatus(void) | |
577 | { | |
578 | CLockObject lock(m_mutex); | |
579 | return m_powerStatus; | |
580 | } | |
581 | ||
582 | cec_power_status CCECBusDevice::GetPowerStatus(const cec_logical_address initiator, bool bUpdate /* = false */) | |
e9de9629 | 583 | { |
6bbfc3f7 | 584 | bool bIsPresent(GetStatus() == CEC_DEVICE_STATUS_PRESENT); |
97fc4ffb LOK |
585 | bool bRequestUpdate(false); |
586 | { | |
f00ff009 | 587 | CLockObject lock(m_mutex); |
ddb6ac5b | 588 | bRequestUpdate = (bIsPresent && |
c8f0eef0 | 589 | (bUpdate || m_powerStatus == CEC_POWER_STATUS_UNKNOWN || |
2efa39b7 LOK |
590 | m_powerStatus == CEC_POWER_STATUS_IN_TRANSITION_STANDBY_TO_ON || |
591 | m_powerStatus == CEC_POWER_STATUS_IN_TRANSITION_ON_TO_STANDBY || | |
592 | GetTimeMs() - m_iLastPowerStateUpdate >= CEC_POWER_STATE_REFRESH_TIME)); | |
97fc4ffb LOK |
593 | } |
594 | ||
595 | if (bRequestUpdate) | |
ebb6ddb3 | 596 | { |
004b8382 LOK |
597 | CheckVendorIdRequested(initiator); |
598 | RequestPowerStatus(initiator); | |
ebb6ddb3 | 599 | } |
5e5637c6 | 600 | |
f00ff009 | 601 | CLockObject lock(m_mutex); |
f294b22f LOK |
602 | return m_powerStatus; |
603 | } | |
604 | ||
004b8382 LOK |
605 | void CCECBusDevice::SetPowerStatus(const cec_power_status powerStatus) |
606 | { | |
607 | CLockObject lock(m_mutex); | |
608 | if (m_powerStatus != powerStatus) | |
609 | { | |
610 | m_iLastPowerStateUpdate = GetTimeMs(); | |
60c28d82 | 611 | LIB_CEC->AddLog(CEC_LOG_DEBUG, "%s (%X): power status changed from '%s' to '%s'", GetLogicalAddressName(), m_iLogicalAddress, ToString(m_powerStatus), ToString(powerStatus)); |
004b8382 LOK |
612 | m_powerStatus = powerStatus; |
613 | } | |
614 | } | |
615 | ||
75273cc6 LOK |
616 | void CCECBusDevice::ImageViewOnSent(void) |
617 | { | |
618 | CLockObject lock(m_mutex); | |
619 | if (m_powerStatus != CEC_POWER_STATUS_ON && m_powerStatus != CEC_POWER_STATUS_IN_TRANSITION_STANDBY_TO_ON) | |
620 | { | |
621 | m_iLastPowerStateUpdate = GetTimeMs(); | |
622 | LIB_CEC->AddLog(CEC_LOG_DEBUG, "%s (%X): power status changed from '%s' to '%s'", GetLogicalAddressName(), m_iLogicalAddress, ToString(m_powerStatus), ToString(CEC_POWER_STATUS_IN_TRANSITION_STANDBY_TO_ON)); | |
623 | m_powerStatus = CEC_POWER_STATUS_IN_TRANSITION_STANDBY_TO_ON; | |
624 | } | |
625 | } | |
626 | ||
004b8382 | 627 | bool CCECBusDevice::RequestPowerStatus(const cec_logical_address initiator, bool bWaitForResponse /* = true */) |
f294b22f LOK |
628 | { |
629 | bool bReturn(false); | |
b64db02e | 630 | |
004b8382 | 631 | if (!IsHandledByLibCEC() && |
4d738fe3 | 632 | !IsUnsupportedFeature(CEC_OPCODE_GIVE_DEVICE_POWER_STATUS)) |
93729720 | 633 | { |
1344fd1a | 634 | MarkBusy(); |
004b8382 | 635 | bReturn = m_handler->TransmitRequestPowerStatus(initiator, m_iLogicalAddress, bWaitForResponse); |
1344fd1a | 636 | MarkReady(); |
93729720 | 637 | } |
f294b22f LOK |
638 | return bReturn; |
639 | } | |
93729720 | 640 | |
2b44051c | 641 | bool CCECBusDevice::TransmitPowerState(const cec_logical_address destination, bool bIsReply) |
f294b22f | 642 | { |
004b8382 | 643 | cec_power_status state; |
97fc4ffb | 644 | { |
f00ff009 | 645 | CLockObject lock(m_mutex); |
ff07d530 | 646 | LIB_CEC->AddLog(CEC_LOG_DEBUG, "<< %s (%X) -> %s (%X): %s", GetLogicalAddressName(), m_iLogicalAddress, ToString(destination), destination, ToString(m_powerStatus)); |
004b8382 | 647 | state = m_powerStatus; |
97fc4ffb LOK |
648 | } |
649 | ||
004b8382 | 650 | MarkBusy(); |
2b44051c | 651 | bool bReturn = m_handler->TransmitPowerState(m_iLogicalAddress, destination, state, bIsReply); |
004b8382 LOK |
652 | MarkReady(); |
653 | return bReturn; | |
654 | } | |
655 | ||
656 | cec_vendor_id CCECBusDevice::GetCurrentVendorId(void) | |
657 | { | |
658 | CLockObject lock(m_mutex); | |
f294b22f | 659 | return m_vendor; |
e9de9629 LOK |
660 | } |
661 | ||
004b8382 LOK |
662 | cec_vendor_id CCECBusDevice::GetVendorId(const cec_logical_address initiator, bool bUpdate /* = false */) |
663 | { | |
664 | bool bIsPresent(GetStatus() == CEC_DEVICE_STATUS_PRESENT); | |
665 | bool bRequestUpdate(false); | |
666 | { | |
667 | CLockObject lock(m_mutex); | |
668 | bRequestUpdate = (bIsPresent && | |
669 | (bUpdate || m_vendor == CEC_VENDOR_UNKNOWN)); | |
670 | } | |
671 | ||
672 | if (bRequestUpdate) | |
673 | RequestVendorId(initiator); | |
674 | ||
675 | CLockObject lock(m_mutex); | |
676 | return m_vendor; | |
677 | } | |
678 | ||
679 | const char *CCECBusDevice::GetVendorName(const cec_logical_address initiator, bool bUpdate /* = false */) | |
680 | { | |
681 | return ToString(GetVendorId(initiator, bUpdate)); | |
682 | } | |
683 | ||
684 | bool CCECBusDevice::SetVendorId(uint64_t iVendorId) | |
685 | { | |
686 | bool bVendorChanged(false); | |
687 | ||
688 | { | |
689 | CLockObject lock(m_mutex); | |
690 | bVendorChanged = (m_vendor != (cec_vendor_id)iVendorId); | |
691 | m_vendor = (cec_vendor_id)iVendorId; | |
692 | } | |
693 | ||
694 | if (bVendorChanged) | |
695 | LIB_CEC->AddLog(CEC_LOG_DEBUG, "%s (%X): vendor = %s (%06x)", GetLogicalAddressName(), m_iLogicalAddress, ToString(m_vendor), m_vendor); | |
696 | ||
697 | return bVendorChanged; | |
698 | } | |
699 | ||
700 | bool CCECBusDevice::RequestVendorId(const cec_logical_address initiator, bool bWaitForResponse /* = true */) | |
a3269a0a | 701 | { |
f294b22f | 702 | bool bReturn(false); |
b64db02e | 703 | |
004b8382 | 704 | if (!IsHandledByLibCEC() && initiator != CECDEVICE_UNKNOWN) |
a3269a0a | 705 | { |
1344fd1a | 706 | MarkBusy(); |
ff07d530 | 707 | LIB_CEC->AddLog(CEC_LOG_DEBUG, "<< requesting vendor ID of '%s' (%X)", GetLogicalAddressName(), m_iLogicalAddress); |
004b8382 | 708 | bReturn = m_handler->TransmitRequestVendorId(initiator, m_iLogicalAddress, bWaitForResponse); |
1344fd1a | 709 | MarkReady(); |
3e61b350 | 710 | |
a75e3a5a LOK |
711 | if (bWaitForResponse) |
712 | ReplaceHandler(true); | |
a3269a0a | 713 | } |
f294b22f | 714 | return bReturn; |
93729720 LOK |
715 | } |
716 | ||
2b44051c | 717 | bool CCECBusDevice::TransmitVendorID(const cec_logical_address destination, bool bSendAbort, bool bIsReply) |
93729720 | 718 | { |
004b8382 LOK |
719 | bool bReturn(false); |
720 | uint64_t iVendorId; | |
721 | { | |
722 | CLockObject lock(m_mutex); | |
723 | iVendorId = (uint64_t)m_vendor; | |
724 | } | |
a3269a0a | 725 | |
004b8382 LOK |
726 | MarkBusy(); |
727 | if (iVendorId == CEC_VENDOR_UNKNOWN) | |
9fd73dd4 | 728 | { |
004b8382 | 729 | if (bSendAbort) |
c6d7f0e1 | 730 | { |
ff07d530 | 731 | LIB_CEC->AddLog(CEC_LOG_DEBUG, "<< %s (%X) -> %s (%X): vendor id feature abort", GetLogicalAddressName(), m_iLogicalAddress, ToString(destination), destination); |
004b8382 LOK |
732 | m_processor->TransmitAbort(m_iLogicalAddress, destination, CEC_OPCODE_GIVE_DEVICE_VENDOR_ID); |
733 | bReturn = true; | |
c6d7f0e1 | 734 | } |
9fd73dd4 | 735 | } |
004b8382 LOK |
736 | else |
737 | { | |
ff07d530 | 738 | LIB_CEC->AddLog(CEC_LOG_DEBUG, "<< %s (%X) -> %s (%X): vendor id %s (%x)", GetLogicalAddressName(), m_iLogicalAddress, ToString(destination), destination, ToString((cec_vendor_id)iVendorId), iVendorId); |
2b44051c | 739 | bReturn = m_handler->TransmitVendorID(m_iLogicalAddress, iVendorId, bIsReply); |
004b8382 LOK |
740 | } |
741 | MarkReady(); | |
742 | return bReturn; | |
9fd73dd4 LOK |
743 | } |
744 | ||
a75e3a5a | 745 | cec_bus_device_status CCECBusDevice::GetStatus(bool bForcePoll /* = false */, bool bSuppressPoll /* = false */) |
f8ae3295 | 746 | { |
a2facc35 LOK |
747 | if (m_iLogicalAddress == CECDEVICE_BROADCAST) |
748 | return CEC_DEVICE_STATUS_NOT_PRESENT; | |
749 | ||
ba427965 LOK |
750 | cec_bus_device_status status(CEC_DEVICE_STATUS_UNKNOWN); |
751 | bool bNeedsPoll(false); | |
752 | ||
753 | { | |
754 | CLockObject lock(m_mutex); | |
755 | status = m_deviceStatus; | |
a75e3a5a | 756 | bNeedsPoll = !bSuppressPoll && |
79efa271 LOK |
757 | m_deviceStatus != CEC_DEVICE_STATUS_HANDLED_BY_LIBCEC && |
758 | // poll forced | |
759 | (bForcePoll || | |
760 | // don't know the status | |
761 | m_deviceStatus == CEC_DEVICE_STATUS_UNKNOWN || | |
762 | // always poll the TV if it's marked as not present | |
763 | (m_deviceStatus == CEC_DEVICE_STATUS_NOT_PRESENT && m_iLogicalAddress == CECDEVICE_TV)); | |
ba427965 LOK |
764 | } |
765 | ||
766 | if (bNeedsPoll) | |
f8ae3295 | 767 | { |
9fd73dd4 | 768 | bool bPollAcked(false); |
7b62b76e | 769 | if (bNeedsPoll && NeedsPoll()) |
9fd73dd4 | 770 | bPollAcked = m_processor->PollDevice(m_iLogicalAddress); |
95a73fa7 | 771 | |
ba427965 LOK |
772 | status = bPollAcked ? CEC_DEVICE_STATUS_PRESENT : CEC_DEVICE_STATUS_NOT_PRESENT; |
773 | SetDeviceStatus(status); | |
f8ae3295 LOK |
774 | } |
775 | ||
ba427965 | 776 | return status; |
f8ae3295 LOK |
777 | } |
778 | ||
2b44051c | 779 | void CCECBusDevice::SetDeviceStatus(const cec_bus_device_status newStatus, cec_version libCECSpecVersion /* = CEC_VERSION_1_4 */) |
93fff5c1 | 780 | { |
f3b448b7 LOK |
781 | if (m_iLogicalAddress == CECDEVICE_UNREGISTERED) |
782 | return; | |
783 | ||
93fff5c1 | 784 | { |
ee17ad58 LOK |
785 | CLockObject lock(m_mutex); |
786 | switch (newStatus) | |
787 | { | |
ee17ad58 LOK |
788 | case CEC_DEVICE_STATUS_HANDLED_BY_LIBCEC: |
789 | if (m_deviceStatus != newStatus) | |
f5aa7e4c | 790 | LIB_CEC->AddLog(CEC_LOG_DEBUG, "%s (%X): device status changed into 'handled by libCEC'", GetLogicalAddressName(), m_iLogicalAddress); |
a20d808d LOK |
791 | SetPowerStatus (CEC_POWER_STATUS_ON); |
792 | SetVendorId (CEC_VENDOR_UNKNOWN); | |
793 | SetMenuState (CEC_MENU_STATE_ACTIVATED); | |
2b44051c | 794 | SetCecVersion (libCECSpecVersion); |
b32ffd87 | 795 | SetStreamPath (CEC_INVALID_PHYSICAL_ADDRESS); |
004b8382 | 796 | MarkAsInactiveSource(); |
a20d808d LOK |
797 | m_iLastActive = 0; |
798 | m_deviceStatus = newStatus; | |
ee17ad58 LOK |
799 | break; |
800 | case CEC_DEVICE_STATUS_PRESENT: | |
801 | if (m_deviceStatus != newStatus) | |
f5aa7e4c | 802 | LIB_CEC->AddLog(CEC_LOG_DEBUG, "%s (%X): device status changed into 'present'", GetLogicalAddressName(), m_iLogicalAddress); |
ee17ad58 | 803 | m_deviceStatus = newStatus; |
be3b6983 | 804 | m_iLastActive = GetTimeMs(); |
ee17ad58 LOK |
805 | break; |
806 | case CEC_DEVICE_STATUS_NOT_PRESENT: | |
807 | if (m_deviceStatus != newStatus) | |
a20d808d | 808 | { |
f5aa7e4c | 809 | LIB_CEC->AddLog(CEC_LOG_DEBUG, "%s (%X): device status changed into 'not present'", GetLogicalAddressName(), m_iLogicalAddress); |
a582c2bb | 810 | ResetDeviceStatus(true); |
a20d808d LOK |
811 | m_deviceStatus = newStatus; |
812 | } | |
ee17ad58 | 813 | break; |
f5aa7e4c LOK |
814 | default: |
815 | ResetDeviceStatus(); | |
816 | break; | |
ee17ad58 | 817 | } |
93fff5c1 LOK |
818 | } |
819 | } | |
820 | ||
a582c2bb | 821 | void CCECBusDevice::ResetDeviceStatus(bool bClientUnregistered /* = false */) |
93729720 | 822 | { |
f00ff009 | 823 | CLockObject lock(m_mutex); |
004b8382 LOK |
824 | SetPowerStatus (CEC_POWER_STATUS_UNKNOWN); |
825 | SetVendorId (CEC_VENDOR_UNKNOWN); | |
826 | SetMenuState (CEC_MENU_STATE_ACTIVATED); | |
827 | SetCecVersion (CEC_VERSION_UNKNOWN); | |
828 | SetStreamPath (CEC_INVALID_PHYSICAL_ADDRESS); | |
829 | SetOSDName (ToString(m_iLogicalAddress)); | |
a582c2bb | 830 | MarkAsInactiveSource(bClientUnregistered); |
f5aa7e4c | 831 | |
004b8382 LOK |
832 | m_iLastActive = 0; |
833 | m_bVendorIdRequested = false; | |
834 | m_unsupportedFeatures.clear(); | |
060a7b5e | 835 | m_waitForResponse->Clear(); |
f5aa7e4c LOK |
836 | |
837 | if (m_deviceStatus != CEC_DEVICE_STATUS_UNKNOWN) | |
838 | LIB_CEC->AddLog(CEC_LOG_DEBUG, "%s (%X): device status changed into 'unknown'", GetLogicalAddressName(), m_iLogicalAddress); | |
839 | m_deviceStatus = CEC_DEVICE_STATUS_UNKNOWN; | |
93729720 LOK |
840 | } |
841 | ||
be3b6983 | 842 | bool CCECBusDevice::TransmitPoll(const cec_logical_address dest, bool bUpdateDeviceStatus) |
9dc04b07 | 843 | { |
004b8382 LOK |
844 | bool bReturn(false); |
845 | cec_logical_address destination(dest); | |
846 | if (destination == CECDEVICE_UNKNOWN) | |
847 | destination = m_iLogicalAddress; | |
96274140 | 848 | |
004b8382 LOK |
849 | CCECBusDevice *destDevice = m_processor->GetDevice(destination); |
850 | if (destDevice->m_deviceStatus == CEC_DEVICE_STATUS_HANDLED_BY_LIBCEC) | |
851 | return bReturn; | |
852 | ||
853 | MarkBusy(); | |
ff07d530 | 854 | LIB_CEC->AddLog(CEC_LOG_DEBUG, "<< %s (%X) -> %s (%X): POLL", GetLogicalAddressName(), m_iLogicalAddress, ToString(dest), dest); |
be3b6983 | 855 | bReturn = m_handler->TransmitPoll(m_iLogicalAddress, destination, false); |
004b8382 LOK |
856 | LIB_CEC->AddLog(CEC_LOG_DEBUG, bReturn ? ">> POLL sent" : ">> POLL not sent"); |
857 | ||
be3b6983 LOK |
858 | if (bUpdateDeviceStatus) |
859 | destDevice->SetDeviceStatus(bReturn ? CEC_DEVICE_STATUS_PRESENT : CEC_DEVICE_STATUS_NOT_PRESENT); | |
004b8382 LOK |
860 | |
861 | MarkReady(); | |
862 | return bReturn; | |
863 | } | |
864 | ||
865 | void CCECBusDevice::HandlePoll(const cec_logical_address destination) | |
866 | { | |
867 | if (destination >= 0 && destination < CECDEVICE_BROADCAST) | |
5f2068fe | 868 | { |
004b8382 | 869 | CCECBusDevice *device = m_processor->GetDevice(destination); |
0cb55c43 | 870 | if (device) |
004b8382 | 871 | device->HandlePollFrom(m_iLogicalAddress); |
9dc04b07 LOK |
872 | } |
873 | } | |
874 | ||
004b8382 | 875 | void CCECBusDevice::HandlePollFrom(const cec_logical_address initiator) |
e55f3f70 | 876 | { |
004b8382 LOK |
877 | LIB_CEC->AddLog(CEC_LOG_DEBUG, "<< POLL: %s (%x) -> %s (%x)", ToString(initiator), initiator, ToString(m_iLogicalAddress), m_iLogicalAddress); |
878 | m_bAwaitingReceiveFailed = true; | |
e55f3f70 LOK |
879 | } |
880 | ||
004b8382 | 881 | bool CCECBusDevice::HandleReceiveFailed(void) |
1344fd1a | 882 | { |
004b8382 LOK |
883 | bool bReturn = m_bAwaitingReceiveFailed; |
884 | m_bAwaitingReceiveFailed = false; | |
885 | return bReturn; | |
1344fd1a LOK |
886 | } |
887 | ||
004b8382 | 888 | cec_menu_state CCECBusDevice::GetMenuState(const cec_logical_address UNUSED(initiator)) |
1344fd1a | 889 | { |
004b8382 LOK |
890 | CLockObject lock(m_mutex); |
891 | return m_menuState; | |
1344fd1a LOK |
892 | } |
893 | ||
004b8382 | 894 | void CCECBusDevice::SetMenuState(const cec_menu_state state) |
e9de9629 | 895 | { |
004b8382 LOK |
896 | CLockObject lock(m_mutex); |
897 | if (m_menuState != state) | |
94e9a2af | 898 | { |
60c28d82 | 899 | LIB_CEC->AddLog(CEC_LOG_DEBUG, "%s (%X): menu state set to '%s'", GetLogicalAddressName(), m_iLogicalAddress, ToString(m_menuState)); |
004b8382 LOK |
900 | m_menuState = state; |
901 | } | |
902 | } | |
d211708b | 903 | |
2b44051c | 904 | bool CCECBusDevice::TransmitMenuState(const cec_logical_address dest, bool bIsReply) |
004b8382 LOK |
905 | { |
906 | cec_menu_state menuState; | |
907 | { | |
908 | CLockObject lock(m_mutex); | |
ff07d530 | 909 | LIB_CEC->AddLog(CEC_LOG_DEBUG, "<< %s (%X) -> %s (%X): menu state '%s'", GetLogicalAddressName(), m_iLogicalAddress, ToString(dest), dest, ToString(m_menuState)); |
004b8382 LOK |
910 | menuState = m_menuState; |
911 | } | |
104125dc | 912 | |
004b8382 | 913 | MarkBusy(); |
2b44051c | 914 | bool bReturn = m_handler->TransmitMenuState(m_iLogicalAddress, dest, menuState, bIsReply); |
004b8382 LOK |
915 | MarkReady(); |
916 | return bReturn; | |
917 | } | |
94e9a2af | 918 | |
060a7b5e | 919 | bool CCECBusDevice::ActivateSource(uint64_t iDelay /* = 0 */) |
004b8382 LOK |
920 | { |
921 | MarkAsActiveSource(); | |
004b8382 | 922 | MarkBusy(); |
060a7b5e LOK |
923 | bool bReturn(true); |
924 | if (iDelay == 0) | |
925 | { | |
926 | LIB_CEC->AddLog(CEC_LOG_DEBUG, "sending active source message for '%s'", ToString(m_iLogicalAddress)); | |
927 | bReturn = m_handler->ActivateSource(); | |
928 | } | |
929 | else | |
930 | { | |
931 | LIB_CEC->AddLog(CEC_LOG_DEBUG, "scheduling active source message for '%s'", ToString(m_iLogicalAddress)); | |
932 | m_handler->ScheduleActivateSource(iDelay); | |
933 | } | |
004b8382 LOK |
934 | MarkReady(); |
935 | return bReturn; | |
936 | } | |
94e9a2af | 937 | |
004b8382 LOK |
938 | bool CCECBusDevice::RequestActiveSource(bool bWaitForResponse /* = true */) |
939 | { | |
940 | bool bReturn(false); | |
e9de9629 | 941 | |
004b8382 | 942 | if (IsHandledByLibCEC()) |
104125dc | 943 | { |
004b8382 | 944 | MarkBusy(); |
ff07d530 | 945 | LIB_CEC->AddLog(CEC_LOG_DEBUG, "<< requesting active source"); |
104125dc | 946 | |
004b8382 LOK |
947 | bReturn = m_handler->TransmitRequestActiveSource(m_iLogicalAddress, bWaitForResponse); |
948 | MarkReady(); | |
104125dc | 949 | } |
004b8382 LOK |
950 | return bReturn; |
951 | } | |
104125dc | 952 | |
004b8382 LOK |
953 | void CCECBusDevice::MarkAsActiveSource(void) |
954 | { | |
29d5198c LOK |
955 | bool bWasActivated(false); |
956 | ||
957 | // set the power status to powered on | |
958 | SetPowerStatus(CEC_POWER_STATUS_ON); | |
959 | ||
960 | // mark this device as active source | |
961 | { | |
962 | CLockObject lock(m_mutex); | |
963 | if (!m_bActiveSource) | |
964 | { | |
965 | LIB_CEC->AddLog(CEC_LOG_DEBUG, "making %s (%x) the active source", GetLogicalAddressName(), m_iLogicalAddress); | |
966 | bWasActivated = true; | |
967 | } | |
968 | else | |
969 | LIB_CEC->AddLog(CEC_LOG_DEBUG, "%s (%x) was already marked as active source", GetLogicalAddressName(), m_iLogicalAddress); | |
104125dc | 970 | |
29d5198c LOK |
971 | m_bActiveSource = true; |
972 | } | |
973 | ||
974 | // mark other devices as inactive sources | |
004b8382 LOK |
975 | CECDEVICEVEC devices; |
976 | m_processor->GetDevices()->Get(devices); | |
977 | for (CECDEVICEVEC::iterator it = devices.begin(); it != devices.end(); it++) | |
978 | if ((*it)->GetLogicalAddress() != m_iLogicalAddress) | |
979 | (*it)->MarkAsInactiveSource(); | |
980 | ||
29d5198c LOK |
981 | if (bWasActivated) |
982 | { | |
d3caa81b LOK |
983 | if (IsHandledByLibCEC()) |
984 | m_processor->SetActiveSource(true, false); | |
29d5198c LOK |
985 | CCECClient *client = GetClient(); |
986 | if (client) | |
987 | client->SourceActivated(m_iLogicalAddress); | |
988 | } | |
b64db02e LOK |
989 | } |
990 | ||
a582c2bb | 991 | void CCECBusDevice::MarkAsInactiveSource(bool bClientUnregistered /* = false */) |
b64db02e | 992 | { |
29d5198c | 993 | bool bWasDeactivated(false); |
b64db02e | 994 | { |
f00ff009 | 995 | CLockObject lock(m_mutex); |
004b8382 | 996 | if (m_bActiveSource) |
29d5198c | 997 | { |
004b8382 | 998 | LIB_CEC->AddLog(CEC_LOG_DEBUG, "marking %s (%X) as inactive source", GetLogicalAddressName(), m_iLogicalAddress); |
29d5198c LOK |
999 | bWasDeactivated = true; |
1000 | } | |
004b8382 | 1001 | m_bActiveSource = false; |
b64db02e | 1002 | } |
29d5198c LOK |
1003 | |
1004 | if (bWasDeactivated) | |
1005 | { | |
d3caa81b LOK |
1006 | if (IsHandledByLibCEC()) |
1007 | m_processor->SetActiveSource(false, bClientUnregistered); | |
29d5198c LOK |
1008 | CCECClient *client = GetClient(); |
1009 | if (client) | |
1010 | client->SourceDeactivated(m_iLogicalAddress); | |
1011 | } | |
e9de9629 LOK |
1012 | } |
1013 | ||
2b44051c | 1014 | bool CCECBusDevice::TransmitActiveSource(bool bIsReply) |
0f23c85c | 1015 | { |
8fa35473 | 1016 | bool bSendActiveSource(false); |
3a48aeae | 1017 | uint16_t iPhysicalAddress(CEC_INVALID_PHYSICAL_ADDRESS); |
0f23c85c | 1018 | |
8747dd4f | 1019 | { |
f00ff009 | 1020 | CLockObject lock(m_mutex); |
3a48aeae LOK |
1021 | if (!HasValidPhysicalAddress()) |
1022 | { | |
b1d821c6 | 1023 | LIB_CEC->AddLog(CEC_LOG_DEBUG, "%s (%X) has an invalid physical address (%04x), not sending active source commands", GetLogicalAddressName(), m_iLogicalAddress, m_iPhysicalAddress); |
3a48aeae LOK |
1024 | return false; |
1025 | } | |
1026 | ||
1027 | iPhysicalAddress = m_iPhysicalAddress; | |
1028 | ||
49c8f2e4 | 1029 | if (m_powerStatus != CEC_POWER_STATUS_ON && m_powerStatus != CEC_POWER_STATUS_IN_TRANSITION_STANDBY_TO_ON) |
004b8382 | 1030 | LIB_CEC->AddLog(CEC_LOG_DEBUG, "<< %s (%X) is not powered on", GetLogicalAddressName(), m_iLogicalAddress); |
8fa35473 LOK |
1031 | else if (m_bActiveSource) |
1032 | { | |
004b8382 | 1033 | LIB_CEC->AddLog(CEC_LOG_NOTICE, "<< %s (%X) -> broadcast (F): active source (%4x)", GetLogicalAddressName(), m_iLogicalAddress, m_iPhysicalAddress); |
8fa35473 LOK |
1034 | bSendActiveSource = true; |
1035 | } | |
1036 | else | |
004b8382 | 1037 | LIB_CEC->AddLog(CEC_LOG_DEBUG, "<< %s (%X) is not the active source", GetLogicalAddressName(), m_iLogicalAddress); |
8747dd4f LOK |
1038 | } |
1039 | ||
dbad810a | 1040 | bool bActiveSourceSent(false); |
b64db02e LOK |
1041 | if (bSendActiveSource) |
1042 | { | |
1344fd1a | 1043 | MarkBusy(); |
2b44051c | 1044 | bActiveSourceSent = m_handler->TransmitActiveSource(m_iLogicalAddress, iPhysicalAddress, bIsReply); |
1344fd1a | 1045 | MarkReady(); |
b64db02e LOK |
1046 | } |
1047 | ||
dbad810a | 1048 | return bActiveSourceSent; |
0f23c85c LOK |
1049 | } |
1050 | ||
49c8f2e4 LOK |
1051 | bool CCECBusDevice::TransmitImageViewOn(void) |
1052 | { | |
49c8f2e4 | 1053 | { |
9a2f12df LOK |
1054 | CLockObject lock(m_mutex); |
1055 | if (m_powerStatus != CEC_POWER_STATUS_ON && m_powerStatus != CEC_POWER_STATUS_IN_TRANSITION_STANDBY_TO_ON) | |
1056 | { | |
004b8382 | 1057 | LIB_CEC->AddLog(CEC_LOG_DEBUG, "<< %s (%X) is not powered on", GetLogicalAddressName(), m_iLogicalAddress); |
9a2f12df LOK |
1058 | return false; |
1059 | } | |
49c8f2e4 | 1060 | } |
9a2f12df | 1061 | |
dbad810a | 1062 | bool bImageViewOnSent(false); |
9a2f12df | 1063 | MarkBusy(); |
dbad810a | 1064 | bImageViewOnSent = m_handler->TransmitImageViewOn(m_iLogicalAddress, CECDEVICE_TV); |
9a2f12df | 1065 | MarkReady(); |
75273cc6 LOK |
1066 | |
1067 | if (bImageViewOnSent) | |
1068 | { | |
1069 | CCECBusDevice* tv = m_processor->GetDevice(CECDEVICE_TV); | |
1070 | if (tv) | |
1071 | tv->ImageViewOnSent(); | |
1072 | } | |
1073 | ||
dbad810a | 1074 | return bImageViewOnSent; |
49c8f2e4 LOK |
1075 | } |
1076 | ||
ab27363d | 1077 | bool CCECBusDevice::TransmitInactiveSource(void) |
93729720 | 1078 | { |
8fa35473 LOK |
1079 | uint16_t iPhysicalAddress; |
1080 | { | |
f00ff009 | 1081 | CLockObject lock(m_mutex); |
004b8382 | 1082 | LIB_CEC->AddLog(CEC_LOG_NOTICE, "<< %s (%X) -> broadcast (F): inactive source", GetLogicalAddressName(), m_iLogicalAddress); |
8fa35473 LOK |
1083 | iPhysicalAddress = m_iPhysicalAddress; |
1084 | } | |
93729720 | 1085 | |
1344fd1a LOK |
1086 | MarkBusy(); |
1087 | bool bReturn = m_handler->TransmitInactiveSource(m_iLogicalAddress, iPhysicalAddress); | |
1088 | MarkReady(); | |
1089 | return bReturn; | |
93729720 LOK |
1090 | } |
1091 | ||
004b8382 | 1092 | bool CCECBusDevice::TransmitPendingActiveSourceCommands(void) |
0f23c85c | 1093 | { |
1344fd1a | 1094 | MarkBusy(); |
aa4c0d34 | 1095 | bool bReturn = m_handler->ActivateSource(true); |
1344fd1a LOK |
1096 | MarkReady(); |
1097 | return bReturn; | |
0f23c85c LOK |
1098 | } |
1099 | ||
844eab4e LOK |
1100 | void CCECBusDevice::SetActiveRoute(uint16_t iRoute) |
1101 | { | |
1102 | CCECDeviceMap* map = m_processor->GetDevices(); | |
1103 | if (!map) | |
1104 | return; | |
1105 | ||
1106 | CCECBusDevice* previouslyActive = map->GetActiveSource(); | |
1107 | if (!previouslyActive) | |
1108 | return; | |
1109 | ||
1110 | CECDEVICEVEC devices; | |
1111 | m_processor->GetDevices()->GetChildrenOf(devices, this); | |
1112 | ||
1113 | for (CECDEVICEVEC::iterator it = devices.begin(); it != devices.end(); it++) | |
1114 | { | |
1115 | if (!CCECTypeUtils::PhysicalAddressIsIncluded(iRoute, (*it)->GetCurrentPhysicalAddress())) | |
1116 | (*it)->MarkAsInactiveSource(); | |
1117 | } | |
1118 | } | |
1119 | ||
004b8382 | 1120 | void CCECBusDevice::SetStreamPath(uint16_t iNewAddress, uint16_t iOldAddress /* = CEC_INVALID_PHYSICAL_ADDRESS */) |
0f23c85c | 1121 | { |
004b8382 LOK |
1122 | CLockObject lock(m_mutex); |
1123 | if (iNewAddress != m_iStreamPath) | |
8fa35473 | 1124 | { |
60c28d82 | 1125 | LIB_CEC->AddLog(CEC_LOG_DEBUG, "%s (%X): stream path changed from %04x to %04x", GetLogicalAddressName(), m_iLogicalAddress, iOldAddress == 0 ? m_iStreamPath : iOldAddress, iNewAddress); |
004b8382 | 1126 | m_iStreamPath = iNewAddress; |
8fa35473 | 1127 | } |
0f23c85c | 1128 | |
99aeafb9 LOK |
1129 | if (!LIB_CEC->IsValidPhysicalAddress(iNewAddress)) |
1130 | return; | |
1131 | ||
004b8382 LOK |
1132 | CCECBusDevice *device = m_processor->GetDeviceByPhysicalAddress(iNewAddress); |
1133 | if (device) | |
4d738fe3 | 1134 | { |
004b8382 LOK |
1135 | // if a device is found with the new physical address, mark it as active, which will automatically mark all other devices as inactive |
1136 | device->MarkAsActiveSource(); | |
e681f8a5 LOK |
1137 | |
1138 | // respond with an active source message if this device is handled by libCEC | |
1139 | if (device->IsHandledByLibCEC()) | |
1140 | device->TransmitActiveSource(true); | |
4d738fe3 | 1141 | } |
004b8382 | 1142 | else |
8fa35473 | 1143 | { |
004b8382 LOK |
1144 | // try to find the device with the old address, and mark it as inactive when found |
1145 | device = m_processor->GetDeviceByPhysicalAddress(iOldAddress); | |
1146 | if (device) | |
1147 | device->MarkAsInactiveSource(); | |
8fa35473 | 1148 | } |
0f23c85c LOK |
1149 | } |
1150 | ||
004b8382 | 1151 | bool CCECBusDevice::PowerOn(const cec_logical_address initiator) |
fbdea54c MK |
1152 | { |
1153 | bool bReturn(false); | |
004b8382 | 1154 | GetVendorId(initiator); // ensure that we got the vendor id, because the implementations vary per vendor |
fbdea54c MK |
1155 | |
1156 | MarkBusy(); | |
f81fdbfa LOK |
1157 | cec_power_status currentStatus; |
1158 | if (m_iLogicalAddress == CECDEVICE_TV || | |
1159 | ((currentStatus = GetPowerStatus(initiator, false)) != CEC_POWER_STATUS_IN_TRANSITION_STANDBY_TO_ON && | |
1160 | currentStatus != CEC_POWER_STATUS_ON)) | |
fbdea54c | 1161 | { |
004b8382 | 1162 | LIB_CEC->AddLog(CEC_LOG_NOTICE, "<< powering on '%s' (%X)", GetLogicalAddressName(), m_iLogicalAddress); |
f81fdbfa | 1163 | bReturn = m_handler->PowerOn(initiator, m_iLogicalAddress); |
fbdea54c MK |
1164 | } |
1165 | else | |
1166 | { | |
ff07d530 | 1167 | LIB_CEC->AddLog(CEC_LOG_DEBUG, "'%s' (%X) is already '%s'", GetLogicalAddressName(), m_iLogicalAddress, ToString(currentStatus)); |
fbdea54c | 1168 | } |
004b8382 | 1169 | |
fbdea54c MK |
1170 | MarkReady(); |
1171 | return bReturn; | |
1172 | } | |
1173 | ||
004b8382 | 1174 | bool CCECBusDevice::Standby(const cec_logical_address initiator) |
57f45e6c | 1175 | { |
004b8382 | 1176 | GetVendorId(initiator); // ensure that we got the vendor id, because the implementations vary per vendor |
b750a5c3 | 1177 | |
ff07d530 | 1178 | LIB_CEC->AddLog(CEC_LOG_NOTICE, "<< putting '%s' (%X) in standby mode", GetLogicalAddressName(), m_iLogicalAddress); |
1344fd1a | 1179 | MarkBusy(); |
004b8382 | 1180 | bool bReturn = m_handler->TransmitStandby(initiator, m_iLogicalAddress); |
1344fd1a | 1181 | MarkReady(); |
57f45e6c LOK |
1182 | return bReturn; |
1183 | } | |
93729720 | 1184 | |
004b8382 | 1185 | bool CCECBusDevice::NeedsPoll(void) |
93729720 | 1186 | { |
004b8382 LOK |
1187 | bool bSendPoll(false); |
1188 | cec_logical_address pollAddress(CECDEVICE_UNKNOWN); | |
1189 | switch (m_iLogicalAddress) | |
8fa35473 | 1190 | { |
004b8382 LOK |
1191 | case CECDEVICE_PLAYBACKDEVICE3: |
1192 | pollAddress = CECDEVICE_PLAYBACKDEVICE2; | |
1193 | break; | |
1194 | case CECDEVICE_PLAYBACKDEVICE2: | |
1195 | pollAddress = CECDEVICE_PLAYBACKDEVICE1; | |
1196 | break; | |
1197 | case CECDEVICE_RECORDINGDEVICE3: | |
1198 | pollAddress = CECDEVICE_RECORDINGDEVICE2; | |
1199 | break; | |
1200 | case CECDEVICE_RECORDINGDEVICE2: | |
1201 | pollAddress = CECDEVICE_RECORDINGDEVICE1; | |
1202 | break; | |
1203 | case CECDEVICE_TUNER4: | |
1204 | pollAddress = CECDEVICE_TUNER3; | |
1205 | break; | |
1206 | case CECDEVICE_TUNER3: | |
1207 | pollAddress = CECDEVICE_TUNER2; | |
1208 | break; | |
1209 | case CECDEVICE_TUNER2: | |
1210 | pollAddress = CECDEVICE_TUNER1; | |
1211 | break; | |
1212 | case CECDEVICE_AUDIOSYSTEM: | |
1213 | case CECDEVICE_PLAYBACKDEVICE1: | |
1214 | case CECDEVICE_RECORDINGDEVICE1: | |
1215 | case CECDEVICE_TUNER1: | |
1216 | case CECDEVICE_TV: | |
1217 | bSendPoll = true; | |
1218 | break; | |
1219 | default: | |
1220 | break; | |
8fa35473 | 1221 | } |
93729720 | 1222 | |
004b8382 LOK |
1223 | if (!bSendPoll && pollAddress != CECDEVICE_UNKNOWN) |
1224 | { | |
1225 | CCECBusDevice *device = m_processor->GetDevice(pollAddress); | |
1226 | if (device) | |
1227 | { | |
1228 | cec_bus_device_status status = device->GetStatus(); | |
1229 | bSendPoll = (status == CEC_DEVICE_STATUS_PRESENT || status == CEC_DEVICE_STATUS_HANDLED_BY_LIBCEC); | |
1230 | } | |
1231 | else | |
1232 | { | |
1233 | bSendPoll = true; | |
1234 | } | |
1235 | } | |
1236 | ||
1237 | return bSendPoll; | |
93729720 LOK |
1238 | } |
1239 | ||
004b8382 | 1240 | void CCECBusDevice::CheckVendorIdRequested(const cec_logical_address initiator) |
93729720 | 1241 | { |
004b8382 | 1242 | bool bRequestVendorId(false); |
8fa35473 | 1243 | { |
f00ff009 | 1244 | CLockObject lock(m_mutex); |
004b8382 LOK |
1245 | bRequestVendorId = !m_bVendorIdRequested; |
1246 | m_bVendorIdRequested = true; | |
8fa35473 LOK |
1247 | } |
1248 | ||
004b8382 | 1249 | if (bRequestVendorId) |
c4098482 | 1250 | { |
004b8382 LOK |
1251 | ReplaceHandler(false); |
1252 | GetVendorId(initiator); | |
c4098482 | 1253 | } |
93729720 | 1254 | } |
004b8382 | 1255 | //@} |
a33794d8 | 1256 | |
004b8382 | 1257 | CCECAudioSystem *CCECBusDevice::AsAudioSystem(void) |
a33794d8 | 1258 | { |
004b8382 | 1259 | return AsAudioSystem(this); |
a33794d8 LOK |
1260 | } |
1261 | ||
004b8382 | 1262 | CCECPlaybackDevice *CCECBusDevice::AsPlaybackDevice(void) |
a33794d8 | 1263 | { |
004b8382 | 1264 | return AsPlaybackDevice(this); |
a33794d8 | 1265 | } |
4d738fe3 | 1266 | |
004b8382 | 1267 | CCECRecordingDevice *CCECBusDevice::AsRecordingDevice(void) |
4d738fe3 | 1268 | { |
004b8382 | 1269 | return AsRecordingDevice(this); |
4d738fe3 LOK |
1270 | } |
1271 | ||
004b8382 | 1272 | CCECTuner *CCECBusDevice::AsTuner(void) |
4d738fe3 | 1273 | { |
004b8382 LOK |
1274 | return AsTuner(this); |
1275 | } | |
ad7e0696 | 1276 | |
004b8382 LOK |
1277 | CCECTV *CCECBusDevice::AsTV(void) |
1278 | { | |
1279 | return AsTV(this); | |
1280 | } | |
b499cf16 | 1281 | |
004b8382 LOK |
1282 | CCECAudioSystem *CCECBusDevice::AsAudioSystem(CCECBusDevice *device) |
1283 | { | |
1284 | if (device && device->GetType() == CEC_DEVICE_TYPE_AUDIO_SYSTEM) | |
1285 | return static_cast<CCECAudioSystem *>(device); | |
1286 | return NULL; | |
4d738fe3 | 1287 | } |
b64db02e | 1288 | |
004b8382 | 1289 | CCECPlaybackDevice *CCECBusDevice::AsPlaybackDevice(CCECBusDevice *device) |
b64db02e | 1290 | { |
004b8382 LOK |
1291 | if (device && |
1292 | (device->GetType() == CEC_DEVICE_TYPE_PLAYBACK_DEVICE || | |
1293 | device->GetType() == CEC_DEVICE_TYPE_RECORDING_DEVICE)) | |
1294 | return static_cast<CCECPlaybackDevice *>(device); | |
1295 | return NULL; | |
b64db02e LOK |
1296 | } |
1297 | ||
004b8382 | 1298 | CCECRecordingDevice *CCECBusDevice::AsRecordingDevice(CCECBusDevice *device) |
a75e3a5a | 1299 | { |
004b8382 LOK |
1300 | if (device && device->GetType() == CEC_DEVICE_TYPE_RECORDING_DEVICE) |
1301 | return static_cast<CCECRecordingDevice *>(device); | |
1302 | return NULL; | |
a75e3a5a LOK |
1303 | } |
1304 | ||
004b8382 | 1305 | CCECTuner *CCECBusDevice::AsTuner(CCECBusDevice *device) |
0cfdeb5a | 1306 | { |
004b8382 LOK |
1307 | if (device && device->GetType() == CEC_DEVICE_TYPE_TUNER) |
1308 | return static_cast<CCECTuner *>(device); | |
1309 | return NULL; | |
0cfdeb5a LOK |
1310 | } |
1311 | ||
004b8382 | 1312 | CCECTV *CCECBusDevice::AsTV(CCECBusDevice *device) |
0cfdeb5a | 1313 | { |
004b8382 LOK |
1314 | if (device && device->GetType() == CEC_DEVICE_TYPE_TV) |
1315 | return static_cast<CCECTV *>(device); | |
1316 | return NULL; | |
0cfdeb5a LOK |
1317 | } |
1318 | ||
004b8382 | 1319 | void CCECBusDevice::MarkBusy(void) |
ebb6ddb3 | 1320 | { |
004b8382 LOK |
1321 | CLockObject handlerLock(m_handlerMutex); |
1322 | ++m_iHandlerUseCount; | |
1323 | } | |
ebb6ddb3 | 1324 | |
004b8382 LOK |
1325 | void CCECBusDevice::MarkReady(void) |
1326 | { | |
1327 | CLockObject handlerLock(m_handlerMutex); | |
1328 | if (m_iHandlerUseCount > 0) | |
1329 | --m_iHandlerUseCount; | |
1330 | } | |
1331 | ||
2b44051c | 1332 | bool CCECBusDevice::TryLogicalAddress(cec_version libCECSpecVersion /* = CEC_VERSION_1_4 */) |
004b8382 LOK |
1333 | { |
1334 | LIB_CEC->AddLog(CEC_LOG_DEBUG, "trying logical address '%s'", GetLogicalAddressName()); | |
1335 | ||
2b44051c | 1336 | if (!TransmitPoll(m_iLogicalAddress, false)) |
ebb6ddb3 | 1337 | { |
ff07d530 | 1338 | LIB_CEC->AddLog(CEC_LOG_DEBUG, "using logical address '%s'", GetLogicalAddressName()); |
2b44051c | 1339 | SetDeviceStatus(CEC_DEVICE_STATUS_HANDLED_BY_LIBCEC, libCECSpecVersion); |
004b8382 LOK |
1340 | |
1341 | return true; | |
ebb6ddb3 | 1342 | } |
004b8382 LOK |
1343 | |
1344 | LIB_CEC->AddLog(CEC_LOG_DEBUG, "logical address '%s' already taken", GetLogicalAddressName()); | |
1345 | SetDeviceStatus(CEC_DEVICE_STATUS_PRESENT); | |
1346 | return false; | |
ebb6ddb3 LOK |
1347 | } |
1348 | ||
004b8382 | 1349 | CCECClient *CCECBusDevice::GetClient(void) |
b78b4e33 | 1350 | { |
004b8382 | 1351 | return m_processor->GetClient(m_iLogicalAddress); |
b78b4e33 | 1352 | } |
060a7b5e LOK |
1353 | |
1354 | void CCECBusDevice::SignalOpcode(cec_opcode opcode) | |
1355 | { | |
1356 | m_waitForResponse->Received(opcode); | |
1357 | } | |
1358 | ||
1359 | bool CCECBusDevice::WaitForOpcode(cec_opcode opcode) | |
1360 | { | |
1361 | return m_waitForResponse->Wait(opcode); | |
1362 | } |