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