2 * This file is part of the libCEC(R) library.
4 * libCEC(R) is Copyright (C) 2011-2012 Pulse-Eight Limited. All rights reserved.
5 * libCEC(R) is an original work, containing original code.
7 * libCEC(R) is a trademark of Pulse-Eight Limited.
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.
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.
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.
24 * Alternatively, you can license this library under a commercial license,
25 * please contact Pulse-Eight Licensing for more information.
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/
34 #include "CECBusDevice.h"
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"
47 #include "CECAudioSystem.h"
48 #include "CECPlaybackDevice.h"
49 #include "CECRecordingDevice.h"
55 using namespace PLATFORM
;
57 #define LIB_CEC m_processor->GetLib()
58 #define ToString(p) CCECTypeUtils::ToString(p)
60 CCECBusDevice::CCECBusDevice(CCECProcessor
*processor
, cec_logical_address iLogicalAddress
, uint16_t iPhysicalAddress
/* = CEC_INVALID_PHYSICAL_ADDRESS */) :
61 m_type (CEC_DEVICE_TYPE_RESERVED
),
62 m_iPhysicalAddress (iPhysicalAddress
),
63 m_iStreamPath (CEC_INVALID_PHYSICAL_ADDRESS
),
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),
72 m_iLastPowerStateUpdate (0),
73 m_cecVersion (CEC_VERSION_UNKNOWN
),
74 m_deviceStatus (CEC_DEVICE_STATUS_UNKNOWN
),
75 m_iHandlerUseCount (0),
76 m_bAwaitingReceiveFailed(false),
77 m_bVendorIdRequested (false),
78 m_waitForResponse (new CWaitForResponse
)
80 m_handler
= new CCECCommandHandler(this);
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
;
87 m_strDeviceName
= ToString(m_iLogicalAddress
);
90 CCECBusDevice::~CCECBusDevice(void)
92 DELETE_AND_NULL(m_handler
);
93 DELETE_AND_NULL(m_waitForResponse
);
96 bool CCECBusDevice::ReplaceHandler(bool bActivateSource
/* = true */)
98 if (m_iLogicalAddress
== CECDEVICE_BROADCAST
)
101 bool bInitHandler(false);
103 CLockObject
lock(m_mutex
);
104 CLockObject
handlerLock(m_handlerMutex
);
105 if (m_iHandlerUseCount
> 0)
110 if (m_vendor
!= m_handler
->GetVendorId())
112 if (CCECCommandHandler::HasSpecificHandler(m_vendor
))
114 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "replacing the command handler for device '%s' (%x)", GetLogicalAddressName(), GetLogicalAddress());
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
;
121 DELETE_AND_NULL(m_handler
);
125 case CEC_VENDOR_SAMSUNG
:
126 m_handler
= new CANCommandHandler(this, iTransmitTimeout
, iTransmitWait
, iTransmitRetries
, iActiveSourcePending
);
129 m_handler
= new CSLCommandHandler(this, iTransmitTimeout
, iTransmitWait
, iTransmitRetries
, iActiveSourcePending
);
131 case CEC_VENDOR_PANASONIC
:
132 m_handler
= new CVLCommandHandler(this, iTransmitTimeout
, iTransmitWait
, iTransmitRetries
, iActiveSourcePending
);
135 m_handler
= new CCECCommandHandler(this, iTransmitTimeout
, iTransmitWait
, iTransmitRetries
, iActiveSourcePending
);
139 m_handler
->SetVendorId(m_vendor
);
147 CCECBusDevice
*primary
= GetProcessor()->GetPrimaryDevice();
148 if (primary
->GetLogicalAddress() != CECDEVICE_UNREGISTERED
)
150 m_handler
->InitHandler();
152 if (bActivateSource
&& IsHandledByLibCEC() && IsActiveSource())
153 m_handler
->ActivateSource();
162 CCECCommandHandler
*CCECBusDevice::GetHandler(void)
164 ReplaceHandler(false);
169 bool CCECBusDevice::HandleCommand(const cec_command
&command
)
171 bool bHandled(false);
173 /* update "last active" */
175 CLockObject
lock(m_mutex
);
176 m_iLastActive
= GetTimeMs();
180 /* handle the command */
181 bHandled
= m_handler
->HandleCommand(command
);
183 /* change status to present */
184 if (bHandled
&& GetLogicalAddress() != CECDEVICE_BROADCAST
)
186 CLockObject
lock(m_mutex
);
187 if (m_deviceStatus
!= CEC_DEVICE_STATUS_HANDLED_BY_LIBCEC
)
189 if (m_deviceStatus
!= CEC_DEVICE_STATUS_PRESENT
)
190 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "device %s (%x) status changed to present after command %s", GetLogicalAddressName(), (uint8_t)GetLogicalAddress(), ToString(command
.opcode
));
191 m_deviceStatus
= CEC_DEVICE_STATUS_PRESENT
;
199 const char* CCECBusDevice::GetLogicalAddressName(void) const
201 return ToString(m_iLogicalAddress
);
204 bool CCECBusDevice::IsPresent(void)
206 CLockObject
lock(m_mutex
);
207 return m_deviceStatus
== CEC_DEVICE_STATUS_PRESENT
;
210 bool CCECBusDevice::IsHandledByLibCEC(void)
212 CLockObject
lock(m_mutex
);
213 return m_deviceStatus
== CEC_DEVICE_STATUS_HANDLED_BY_LIBCEC
;
216 void CCECBusDevice::SetUnsupportedFeature(cec_opcode opcode
)
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
)
229 CLockObject
lock(m_mutex
);
230 if (m_unsupportedFeatures
.find(opcode
) == m_unsupportedFeatures
.end())
232 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "marking opcode '%s' as unsupported feature for device '%s'", ToString(opcode
), GetLogicalAddressName());
233 m_unsupportedFeatures
.insert(opcode
);
237 // signal threads that are waiting for a reponse
239 SignalOpcode(cec_command::GetResponseOpcode(opcode
));
243 bool CCECBusDevice::IsUnsupportedFeature(cec_opcode opcode
)
245 CLockObject
lock(m_mutex
);
246 bool bUnsupported
= (m_unsupportedFeatures
.find(opcode
) != m_unsupportedFeatures
.end());
248 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "'%s' is marked as unsupported feature for device '%s'", ToString(opcode
), GetLogicalAddressName());
252 bool CCECBusDevice::TransmitKeypress(const cec_logical_address initiator
, cec_user_control_code key
, bool bWait
/* = true */)
255 bool bReturn
= m_handler
->TransmitKeypress(initiator
, m_iLogicalAddress
, key
, bWait
);
260 bool CCECBusDevice::TransmitKeyRelease(const cec_logical_address initiator
, bool bWait
/* = true */)
263 bool bReturn
= m_handler
->TransmitKeyRelease(initiator
, m_iLogicalAddress
, bWait
);
268 cec_version
CCECBusDevice::GetCecVersion(const cec_logical_address initiator
, bool bUpdate
/* = false */)
270 bool bIsPresent(GetStatus() == CEC_DEVICE_STATUS_PRESENT
);
271 bool bRequestUpdate(false);
273 CLockObject
lock(m_mutex
);
274 bRequestUpdate
= bIsPresent
&&
275 (bUpdate
|| m_cecVersion
== CEC_VERSION_UNKNOWN
);
280 CheckVendorIdRequested(initiator
);
281 RequestCecVersion(initiator
);
284 CLockObject
lock(m_mutex
);
288 void CCECBusDevice::SetCecVersion(const cec_version newVersion
)
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
;
296 bool CCECBusDevice::RequestCecVersion(const cec_logical_address initiator
, bool bWaitForResponse
/* = true */)
300 if (!IsHandledByLibCEC() &&
301 !IsUnsupportedFeature(CEC_OPCODE_GET_CEC_VERSION
))
304 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "<< requesting CEC version of '%s' (%X)", GetLogicalAddressName(), m_iLogicalAddress
);
305 bReturn
= m_handler
->TransmitRequestCecVersion(initiator
, m_iLogicalAddress
, bWaitForResponse
);
311 bool CCECBusDevice::TransmitCECVersion(const cec_logical_address destination
, bool bIsReply
)
315 CLockObject
lock(m_mutex
);
316 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "<< %s (%X) -> %s (%X): cec version %s", GetLogicalAddressName(), m_iLogicalAddress
, ToString(destination
), destination
, ToString(m_cecVersion
));
317 version
= m_cecVersion
;
321 bool bReturn
= m_handler
->TransmitCECVersion(m_iLogicalAddress
, destination
, version
, bIsReply
);
326 cec_menu_language
&CCECBusDevice::GetMenuLanguage(const cec_logical_address initiator
, bool bUpdate
/* = false */)
328 bool bIsPresent(GetStatus() == CEC_DEVICE_STATUS_PRESENT
);
329 bool bRequestUpdate(false);
331 CLockObject
lock(m_mutex
);
332 bRequestUpdate
= (bIsPresent
&&
333 (bUpdate
|| !strcmp(m_menuLanguage
.language
, "???")));
338 CheckVendorIdRequested(initiator
);
339 RequestMenuLanguage(initiator
);
342 CLockObject
lock(m_mutex
);
343 return m_menuLanguage
;
346 void CCECBusDevice::SetMenuLanguage(const char *strLanguage
)
351 CLockObject
lock(m_mutex
);
352 if (strcmp(strLanguage
, m_menuLanguage
.language
))
354 memcpy(m_menuLanguage
.language
, strLanguage
, 3);
355 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "%s (%X): menu language set to '%s'", GetLogicalAddressName(), m_iLogicalAddress
, m_menuLanguage
.language
);
359 void CCECBusDevice::SetMenuLanguage(const cec_menu_language
&language
)
361 if (language
.device
== m_iLogicalAddress
)
362 SetMenuLanguage(language
.language
);
365 bool CCECBusDevice::RequestMenuLanguage(const cec_logical_address initiator
, bool bWaitForResponse
/* = true */)
369 if (!IsHandledByLibCEC() &&
370 !IsUnsupportedFeature(CEC_OPCODE_GET_MENU_LANGUAGE
))
373 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "<< requesting menu language of '%s' (%X)", GetLogicalAddressName(), m_iLogicalAddress
);
374 bReturn
= m_handler
->TransmitRequestMenuLanguage(initiator
, m_iLogicalAddress
, bWaitForResponse
);
380 bool CCECBusDevice::TransmitSetMenuLanguage(const cec_logical_address destination
, bool bIsReply
)
383 cec_menu_language language
;
385 CLockObject
lock(m_mutex
);
386 language
= m_menuLanguage
;
391 CLockObject
lock(m_mutex
);
392 lang
[0] = language
.language
[0];
393 lang
[1] = language
.language
[1];
394 lang
[2] = language
.language
[2];
398 if (lang
[0] == '?' && lang
[1] == '?' && lang
[2] == '?')
400 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "<< %s (%X) -> %s (%X): menu language feature abort", GetLogicalAddressName(), m_iLogicalAddress
, ToString(destination
), destination
);
401 m_processor
->TransmitAbort(m_iLogicalAddress
, destination
, CEC_OPCODE_GIVE_DEVICE_VENDOR_ID
);
406 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "<< %s (%X) -> broadcast (F): menu language '%s'", GetLogicalAddressName(), m_iLogicalAddress
, lang
);
407 bReturn
= m_handler
->TransmitSetMenuLanguage(m_iLogicalAddress
, lang
, bIsReply
);
413 bool CCECBusDevice::TransmitOSDString(const cec_logical_address destination
, cec_display_control duration
, const char *strMessage
, bool bIsReply
)
416 if (!m_processor
->GetDevice(destination
)->IsUnsupportedFeature(CEC_OPCODE_SET_OSD_STRING
))
418 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "<< %s (%X) -> %s (%X): display OSD message '%s'", GetLogicalAddressName(), m_iLogicalAddress
, ToString(destination
), destination
, strMessage
);
420 bReturn
= m_handler
->TransmitOSDString(m_iLogicalAddress
, destination
, duration
, strMessage
, bIsReply
);
426 CStdString
CCECBusDevice::GetCurrentOSDName(void)
428 CLockObject
lock(m_mutex
);
429 return m_strDeviceName
;
432 CStdString
CCECBusDevice::GetOSDName(const cec_logical_address initiator
, bool bUpdate
/* = false */)
434 bool bIsPresent(GetStatus() == CEC_DEVICE_STATUS_PRESENT
);
435 bool bRequestUpdate(false);
437 CLockObject
lock(m_mutex
);
438 bRequestUpdate
= bIsPresent
&&
439 (bUpdate
|| m_strDeviceName
.Equals(ToString(m_iLogicalAddress
))) &&
440 m_type
!= CEC_DEVICE_TYPE_TV
;
445 CheckVendorIdRequested(initiator
);
446 RequestOSDName(initiator
);
449 CLockObject
lock(m_mutex
);
450 return m_strDeviceName
;
453 void CCECBusDevice::SetOSDName(CStdString strName
)
455 CLockObject
lock(m_mutex
);
456 if (m_strDeviceName
!= strName
)
458 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "%s (%X): osd name set to '%s'", GetLogicalAddressName(), m_iLogicalAddress
, strName
.c_str());
459 m_strDeviceName
= strName
;
463 bool CCECBusDevice::RequestOSDName(const cec_logical_address initiator
, bool bWaitForResponse
/* = true */)
467 if (!IsHandledByLibCEC() &&
468 !IsUnsupportedFeature(CEC_OPCODE_GIVE_OSD_NAME
))
471 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "<< requesting OSD name of '%s' (%X)", GetLogicalAddressName(), m_iLogicalAddress
);
472 bReturn
= m_handler
->TransmitRequestOSDName(initiator
, m_iLogicalAddress
, bWaitForResponse
);
478 bool CCECBusDevice::TransmitOSDName(const cec_logical_address destination
, bool bIsReply
)
480 CStdString strDeviceName
;
482 CLockObject
lock(m_mutex
);
483 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "<< %s (%X) -> %s (%X): OSD name '%s'", GetLogicalAddressName(), m_iLogicalAddress
, ToString(destination
), destination
, m_strDeviceName
.c_str());
484 strDeviceName
= m_strDeviceName
;
488 bool bReturn
= m_handler
->TransmitOSDName(m_iLogicalAddress
, destination
, strDeviceName
, bIsReply
);
493 bool CCECBusDevice::HasValidPhysicalAddress(void)
495 CLockObject
lock(m_mutex
);
496 return CLibCEC::IsValidPhysicalAddress(m_iPhysicalAddress
);
499 uint16_t CCECBusDevice::GetCurrentPhysicalAddress(void)
501 CLockObject
lock(m_mutex
);
502 return m_iPhysicalAddress
;
505 uint16_t CCECBusDevice::GetPhysicalAddress(const cec_logical_address initiator
, bool bSuppressUpdate
/* = false */)
507 if (!bSuppressUpdate
)
509 bool bIsPresent(GetStatus() == CEC_DEVICE_STATUS_PRESENT
);
510 bool bRequestUpdate(false);
512 CLockObject
lock(m_mutex
);
513 bRequestUpdate
= bIsPresent
&& m_iPhysicalAddress
== CEC_INVALID_PHYSICAL_ADDRESS
;
518 CheckVendorIdRequested(initiator
);
519 if (!RequestPhysicalAddress(initiator
))
520 LIB_CEC
->AddLog(CEC_LOG_ERROR
, "failed to request the physical address");
524 CLockObject
lock(m_mutex
);
525 return m_iPhysicalAddress
;
528 bool CCECBusDevice::SetPhysicalAddress(uint16_t iNewAddress
)
530 CLockObject
lock(m_mutex
);
531 if (iNewAddress
> 0 && m_iPhysicalAddress
!= iNewAddress
)
533 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "%s (%X): physical address changed from %04x to %04x", GetLogicalAddressName(), m_iLogicalAddress
, m_iPhysicalAddress
, iNewAddress
);
534 m_iPhysicalAddress
= iNewAddress
;
536 if (m_processor
->GetDevices()->GetActiveSourceAddress() == iNewAddress
)
537 MarkAsActiveSource();
542 bool CCECBusDevice::RequestPhysicalAddress(const cec_logical_address initiator
, bool bWaitForResponse
/* = true */)
546 if (!IsHandledByLibCEC())
549 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "<< requesting physical address of '%s' (%X)", GetLogicalAddressName(), m_iLogicalAddress
);
550 bReturn
= m_handler
->TransmitRequestPhysicalAddress(initiator
, m_iLogicalAddress
, bWaitForResponse
);
556 bool CCECBusDevice::TransmitPhysicalAddress(bool bIsReply
)
558 uint16_t iPhysicalAddress
;
559 cec_device_type type
;
561 CLockObject
lock(m_mutex
);
562 if (m_iPhysicalAddress
== CEC_INVALID_PHYSICAL_ADDRESS
)
565 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "<< %s (%X) -> broadcast (F): physical adddress %4x", GetLogicalAddressName(), m_iLogicalAddress
, m_iPhysicalAddress
);
566 iPhysicalAddress
= m_iPhysicalAddress
;
571 bool bReturn
= m_handler
->TransmitPhysicalAddress(m_iLogicalAddress
, iPhysicalAddress
, type
, bIsReply
);
576 cec_power_status
CCECBusDevice::GetCurrentPowerStatus(void)
578 CLockObject
lock(m_mutex
);
579 return m_powerStatus
;
582 cec_power_status
CCECBusDevice::GetPowerStatus(const cec_logical_address initiator
, bool bUpdate
/* = false */)
584 bool bIsPresent(GetStatus() == CEC_DEVICE_STATUS_PRESENT
);
585 bool bRequestUpdate(false);
587 CLockObject
lock(m_mutex
);
588 bRequestUpdate
= (bIsPresent
&&
589 (bUpdate
|| m_powerStatus
== CEC_POWER_STATUS_UNKNOWN
||
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
));
597 CheckVendorIdRequested(initiator
);
598 RequestPowerStatus(initiator
);
601 CLockObject
lock(m_mutex
);
602 return m_powerStatus
;
605 void CCECBusDevice::SetPowerStatus(const cec_power_status powerStatus
)
607 CLockObject
lock(m_mutex
);
608 if (m_powerStatus
!= powerStatus
)
610 m_iLastPowerStateUpdate
= GetTimeMs();
611 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "%s (%X): power status changed from '%s' to '%s'", GetLogicalAddressName(), m_iLogicalAddress
, ToString(m_powerStatus
), ToString(powerStatus
));
612 m_powerStatus
= powerStatus
;
616 void CCECBusDevice::ImageViewOnSent(void)
618 CLockObject
lock(m_mutex
);
619 if (m_powerStatus
!= CEC_POWER_STATUS_ON
&& m_powerStatus
!= CEC_POWER_STATUS_IN_TRANSITION_STANDBY_TO_ON
)
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
;
627 bool CCECBusDevice::RequestPowerStatus(const cec_logical_address initiator
, bool bWaitForResponse
/* = true */)
631 if (!IsHandledByLibCEC() &&
632 !IsUnsupportedFeature(CEC_OPCODE_GIVE_DEVICE_POWER_STATUS
))
635 bReturn
= m_handler
->TransmitRequestPowerStatus(initiator
, m_iLogicalAddress
, bWaitForResponse
);
641 bool CCECBusDevice::TransmitPowerState(const cec_logical_address destination
, bool bIsReply
)
643 cec_power_status state
;
645 CLockObject
lock(m_mutex
);
646 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "<< %s (%X) -> %s (%X): %s", GetLogicalAddressName(), m_iLogicalAddress
, ToString(destination
), destination
, ToString(m_powerStatus
));
647 state
= m_powerStatus
;
651 bool bReturn
= m_handler
->TransmitPowerState(m_iLogicalAddress
, destination
, state
, bIsReply
);
656 cec_vendor_id
CCECBusDevice::GetCurrentVendorId(void)
658 CLockObject
lock(m_mutex
);
662 cec_vendor_id
CCECBusDevice::GetVendorId(const cec_logical_address initiator
, bool bUpdate
/* = false */)
664 bool bIsPresent(GetStatus() == CEC_DEVICE_STATUS_PRESENT
);
665 bool bRequestUpdate(false);
667 CLockObject
lock(m_mutex
);
668 bRequestUpdate
= (bIsPresent
&&
669 (bUpdate
|| m_vendor
== CEC_VENDOR_UNKNOWN
));
673 RequestVendorId(initiator
);
675 CLockObject
lock(m_mutex
);
679 const char *CCECBusDevice::GetVendorName(const cec_logical_address initiator
, bool bUpdate
/* = false */)
681 return ToString(GetVendorId(initiator
, bUpdate
));
684 bool CCECBusDevice::SetVendorId(uint64_t iVendorId
)
686 bool bVendorChanged(false);
689 CLockObject
lock(m_mutex
);
690 bVendorChanged
= (m_vendor
!= (cec_vendor_id
)iVendorId
);
691 m_vendor
= (cec_vendor_id
)iVendorId
;
695 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "%s (%X): vendor = %s (%06x)", GetLogicalAddressName(), m_iLogicalAddress
, ToString(m_vendor
), m_vendor
);
697 return bVendorChanged
;
700 bool CCECBusDevice::RequestVendorId(const cec_logical_address initiator
, bool bWaitForResponse
/* = true */)
704 if (!IsHandledByLibCEC() && initiator
!= CECDEVICE_UNKNOWN
)
707 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "<< requesting vendor ID of '%s' (%X)", GetLogicalAddressName(), m_iLogicalAddress
);
708 bReturn
= m_handler
->TransmitRequestVendorId(initiator
, m_iLogicalAddress
, bWaitForResponse
);
711 if (bWaitForResponse
)
712 ReplaceHandler(true);
717 bool CCECBusDevice::TransmitVendorID(const cec_logical_address destination
, bool bSendAbort
, bool bIsReply
)
722 CLockObject
lock(m_mutex
);
723 iVendorId
= (uint64_t)m_vendor
;
727 if (iVendorId
== CEC_VENDOR_UNKNOWN
)
731 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "<< %s (%X) -> %s (%X): vendor id feature abort", GetLogicalAddressName(), m_iLogicalAddress
, ToString(destination
), destination
);
732 m_processor
->TransmitAbort(m_iLogicalAddress
, destination
, CEC_OPCODE_GIVE_DEVICE_VENDOR_ID
);
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
);
739 bReturn
= m_handler
->TransmitVendorID(m_iLogicalAddress
, iVendorId
, bIsReply
);
745 cec_bus_device_status
CCECBusDevice::GetStatus(bool bForcePoll
/* = false */, bool bSuppressPoll
/* = false */)
747 if (m_iLogicalAddress
== CECDEVICE_BROADCAST
)
748 return CEC_DEVICE_STATUS_NOT_PRESENT
;
750 cec_bus_device_status
status(CEC_DEVICE_STATUS_UNKNOWN
);
751 bool bNeedsPoll(false);
754 CLockObject
lock(m_mutex
);
755 status
= m_deviceStatus
;
756 bNeedsPoll
= !bSuppressPoll
&&
757 m_deviceStatus
!= CEC_DEVICE_STATUS_HANDLED_BY_LIBCEC
&&
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
));
768 bool bPollAcked(false);
769 if (bNeedsPoll
&& NeedsPoll())
770 bPollAcked
= m_processor
->PollDevice(m_iLogicalAddress
);
772 status
= bPollAcked
? CEC_DEVICE_STATUS_PRESENT
: CEC_DEVICE_STATUS_NOT_PRESENT
;
773 SetDeviceStatus(status
);
779 void CCECBusDevice::SetDeviceStatus(const cec_bus_device_status newStatus
, cec_version libCECSpecVersion
/* = CEC_VERSION_1_4 */)
781 if (m_iLogicalAddress
== CECDEVICE_UNREGISTERED
)
785 CLockObject
lock(m_mutex
);
788 case CEC_DEVICE_STATUS_HANDLED_BY_LIBCEC
:
789 if (m_deviceStatus
!= newStatus
)
790 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "%s (%X): device status changed into 'handled by libCEC'", GetLogicalAddressName(), m_iLogicalAddress
);
791 SetPowerStatus (CEC_POWER_STATUS_ON
);
792 SetVendorId (CEC_VENDOR_UNKNOWN
);
793 SetMenuState (CEC_MENU_STATE_ACTIVATED
);
794 SetCecVersion (libCECSpecVersion
);
795 SetStreamPath (CEC_INVALID_PHYSICAL_ADDRESS
);
796 MarkAsInactiveSource();
798 m_deviceStatus
= newStatus
;
800 case CEC_DEVICE_STATUS_PRESENT
:
801 if (m_deviceStatus
!= newStatus
)
802 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "%s (%X): device status changed into 'present'", GetLogicalAddressName(), m_iLogicalAddress
);
803 m_deviceStatus
= newStatus
;
804 m_iLastActive
= GetTimeMs();
806 case CEC_DEVICE_STATUS_NOT_PRESENT
:
807 if (m_deviceStatus
!= newStatus
)
809 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "%s (%X): device status changed into 'not present'", GetLogicalAddressName(), m_iLogicalAddress
);
810 ResetDeviceStatus(true);
811 m_deviceStatus
= newStatus
;
821 void CCECBusDevice::ResetDeviceStatus(bool bClientUnregistered
/* = false */)
823 CLockObject
lock(m_mutex
);
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
));
830 MarkAsInactiveSource(bClientUnregistered
);
833 m_bVendorIdRequested
= false;
834 m_unsupportedFeatures
.clear();
835 m_waitForResponse
->Clear();
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
;
842 bool CCECBusDevice::TransmitPoll(const cec_logical_address dest
, bool bUpdateDeviceStatus
)
845 cec_logical_address
destination(dest
);
846 if (destination
== CECDEVICE_UNKNOWN
)
847 destination
= m_iLogicalAddress
;
849 CCECBusDevice
*destDevice
= m_processor
->GetDevice(destination
);
850 if (destDevice
->m_deviceStatus
== CEC_DEVICE_STATUS_HANDLED_BY_LIBCEC
)
854 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "<< %s (%X) -> %s (%X): POLL", GetLogicalAddressName(), m_iLogicalAddress
, ToString(dest
), dest
);
855 bReturn
= m_handler
->TransmitPoll(m_iLogicalAddress
, destination
, false);
856 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, bReturn
? ">> POLL sent" : ">> POLL not sent");
858 if (bUpdateDeviceStatus
)
859 destDevice
->SetDeviceStatus(bReturn
? CEC_DEVICE_STATUS_PRESENT
: CEC_DEVICE_STATUS_NOT_PRESENT
);
865 void CCECBusDevice::HandlePoll(const cec_logical_address destination
)
867 if (destination
>= 0 && destination
< CECDEVICE_BROADCAST
)
869 CCECBusDevice
*device
= m_processor
->GetDevice(destination
);
871 device
->HandlePollFrom(m_iLogicalAddress
);
875 void CCECBusDevice::HandlePollFrom(const cec_logical_address initiator
)
877 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "<< POLL: %s (%x) -> %s (%x)", ToString(initiator
), initiator
, ToString(m_iLogicalAddress
), m_iLogicalAddress
);
878 m_bAwaitingReceiveFailed
= true;
881 bool CCECBusDevice::HandleReceiveFailed(void)
883 bool bReturn
= m_bAwaitingReceiveFailed
;
884 m_bAwaitingReceiveFailed
= false;
888 cec_menu_state
CCECBusDevice::GetMenuState(const cec_logical_address
UNUSED(initiator
))
890 CLockObject
lock(m_mutex
);
894 void CCECBusDevice::SetMenuState(const cec_menu_state state
)
896 CLockObject
lock(m_mutex
);
897 if (m_menuState
!= state
)
899 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "%s (%X): menu state set to '%s'", GetLogicalAddressName(), m_iLogicalAddress
, ToString(m_menuState
));
904 bool CCECBusDevice::TransmitMenuState(const cec_logical_address dest
, bool bIsReply
)
906 cec_menu_state menuState
;
908 CLockObject
lock(m_mutex
);
909 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "<< %s (%X) -> %s (%X): menu state '%s'", GetLogicalAddressName(), m_iLogicalAddress
, ToString(dest
), dest
, ToString(m_menuState
));
910 menuState
= m_menuState
;
914 bool bReturn
= m_handler
->TransmitMenuState(m_iLogicalAddress
, dest
, menuState
, bIsReply
);
919 bool CCECBusDevice::ActivateSource(uint64_t iDelay
/* = 0 */)
921 MarkAsActiveSource();
926 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "sending active source message for '%s'", ToString(m_iLogicalAddress
));
927 bReturn
= m_handler
->ActivateSource();
931 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "scheduling active source message for '%s'", ToString(m_iLogicalAddress
));
932 m_handler
->ScheduleActivateSource(iDelay
);
938 bool CCECBusDevice::RequestActiveSource(bool bWaitForResponse
/* = true */)
942 if (IsHandledByLibCEC())
945 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "<< requesting active source");
947 bReturn
= m_handler
->TransmitRequestActiveSource(m_iLogicalAddress
, bWaitForResponse
);
953 void CCECBusDevice::MarkAsActiveSource(void)
955 bool bWasActivated(false);
957 // set the power status to powered on
958 SetPowerStatus(CEC_POWER_STATUS_ON
);
960 // mark this device as active source
962 CLockObject
lock(m_mutex
);
963 if (!m_bActiveSource
)
965 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "making %s (%x) the active source", GetLogicalAddressName(), m_iLogicalAddress
);
966 bWasActivated
= true;
969 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "%s (%x) was already marked as active source", GetLogicalAddressName(), m_iLogicalAddress
);
971 m_bActiveSource
= true;
974 // mark other devices as inactive sources
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();
983 if (IsHandledByLibCEC())
984 m_processor
->SetActiveSource(true, false);
985 CCECClient
*client
= GetClient();
987 client
->SourceActivated(m_iLogicalAddress
);
991 void CCECBusDevice::MarkAsInactiveSource(bool bClientUnregistered
/* = false */)
993 bool bWasDeactivated(false);
995 CLockObject
lock(m_mutex
);
998 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "marking %s (%X) as inactive source", GetLogicalAddressName(), m_iLogicalAddress
);
999 bWasDeactivated
= true;
1001 m_bActiveSource
= false;
1004 if (bWasDeactivated
)
1006 if (IsHandledByLibCEC())
1007 m_processor
->SetActiveSource(false, bClientUnregistered
);
1008 CCECClient
*client
= GetClient();
1010 client
->SourceDeactivated(m_iLogicalAddress
);
1014 bool CCECBusDevice::TransmitActiveSource(bool bIsReply
)
1016 bool bSendActiveSource(false);
1017 uint16_t iPhysicalAddress(CEC_INVALID_PHYSICAL_ADDRESS
);
1020 CLockObject
lock(m_mutex
);
1021 if (!HasValidPhysicalAddress())
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
);
1027 iPhysicalAddress
= m_iPhysicalAddress
;
1029 if (m_powerStatus
!= CEC_POWER_STATUS_ON
&& m_powerStatus
!= CEC_POWER_STATUS_IN_TRANSITION_STANDBY_TO_ON
)
1030 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "<< %s (%X) is not powered on", GetLogicalAddressName(), m_iLogicalAddress
);
1031 else if (m_bActiveSource
)
1033 LIB_CEC
->AddLog(CEC_LOG_NOTICE
, "<< %s (%X) -> broadcast (F): active source (%4x)", GetLogicalAddressName(), m_iLogicalAddress
, m_iPhysicalAddress
);
1034 bSendActiveSource
= true;
1037 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "<< %s (%X) is not the active source", GetLogicalAddressName(), m_iLogicalAddress
);
1040 bool bActiveSourceSent(false);
1041 if (bSendActiveSource
)
1044 bActiveSourceSent
= m_handler
->TransmitActiveSource(m_iLogicalAddress
, iPhysicalAddress
, bIsReply
);
1048 return bActiveSourceSent
;
1051 bool CCECBusDevice::TransmitImageViewOn(void)
1054 CLockObject
lock(m_mutex
);
1055 if (m_powerStatus
!= CEC_POWER_STATUS_ON
&& m_powerStatus
!= CEC_POWER_STATUS_IN_TRANSITION_STANDBY_TO_ON
)
1057 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "<< %s (%X) is not powered on", GetLogicalAddressName(), m_iLogicalAddress
);
1062 bool bImageViewOnSent(false);
1064 bImageViewOnSent
= m_handler
->TransmitImageViewOn(m_iLogicalAddress
, CECDEVICE_TV
);
1067 if (bImageViewOnSent
)
1069 CCECBusDevice
* tv
= m_processor
->GetDevice(CECDEVICE_TV
);
1071 tv
->ImageViewOnSent();
1074 return bImageViewOnSent
;
1077 bool CCECBusDevice::TransmitInactiveSource(void)
1079 uint16_t iPhysicalAddress
;
1081 CLockObject
lock(m_mutex
);
1082 LIB_CEC
->AddLog(CEC_LOG_NOTICE
, "<< %s (%X) -> broadcast (F): inactive source", GetLogicalAddressName(), m_iLogicalAddress
);
1083 iPhysicalAddress
= m_iPhysicalAddress
;
1087 bool bReturn
= m_handler
->TransmitInactiveSource(m_iLogicalAddress
, iPhysicalAddress
);
1092 bool CCECBusDevice::TransmitPendingActiveSourceCommands(void)
1095 bool bReturn
= m_handler
->ActivateSource(true);
1100 void CCECBusDevice::SetActiveRoute(uint16_t iRoute
)
1102 CCECDeviceMap
* map
= m_processor
->GetDevices();
1106 CCECBusDevice
* previouslyActive
= map
->GetActiveSource();
1107 if (!previouslyActive
)
1110 CECDEVICEVEC devices
;
1111 m_processor
->GetDevices()->GetChildrenOf(devices
, this);
1113 for (CECDEVICEVEC::iterator it
= devices
.begin(); it
!= devices
.end(); it
++)
1115 if (!CCECTypeUtils::PhysicalAddressIsIncluded(iRoute
, (*it
)->GetCurrentPhysicalAddress()))
1116 (*it
)->MarkAsInactiveSource();
1120 void CCECBusDevice::SetStreamPath(uint16_t iNewAddress
, uint16_t iOldAddress
/* = CEC_INVALID_PHYSICAL_ADDRESS */)
1122 CLockObject
lock(m_mutex
);
1123 if (iNewAddress
!= m_iStreamPath
)
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
);
1126 m_iStreamPath
= iNewAddress
;
1129 if (!LIB_CEC
->IsValidPhysicalAddress(iNewAddress
))
1132 CCECBusDevice
*device
= m_processor
->GetDeviceByPhysicalAddress(iNewAddress
);
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();
1138 // respond with an active source message if this device is handled by libCEC
1139 if (device
->IsHandledByLibCEC())
1140 device
->TransmitActiveSource(true);
1144 // try to find the device with the old address, and mark it as inactive when found
1145 device
= m_processor
->GetDeviceByPhysicalAddress(iOldAddress
);
1147 device
->MarkAsInactiveSource();
1151 bool CCECBusDevice::PowerOn(const cec_logical_address initiator
)
1153 bool bReturn(false);
1154 GetVendorId(initiator
); // ensure that we got the vendor id, because the implementations vary per vendor
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
))
1162 LIB_CEC
->AddLog(CEC_LOG_NOTICE
, "<< powering on '%s' (%X)", GetLogicalAddressName(), m_iLogicalAddress
);
1163 bReturn
= m_handler
->PowerOn(initiator
, m_iLogicalAddress
);
1167 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "'%s' (%X) is already '%s'", GetLogicalAddressName(), m_iLogicalAddress
, ToString(currentStatus
));
1174 bool CCECBusDevice::Standby(const cec_logical_address initiator
)
1176 GetVendorId(initiator
); // ensure that we got the vendor id, because the implementations vary per vendor
1178 LIB_CEC
->AddLog(CEC_LOG_NOTICE
, "<< putting '%s' (%X) in standby mode", GetLogicalAddressName(), m_iLogicalAddress
);
1180 bool bReturn
= m_handler
->TransmitStandby(initiator
, m_iLogicalAddress
);
1185 bool CCECBusDevice::NeedsPoll(void)
1187 bool bSendPoll(false);
1188 cec_logical_address
pollAddress(CECDEVICE_UNKNOWN
);
1189 switch (m_iLogicalAddress
)
1191 case CECDEVICE_PLAYBACKDEVICE3
:
1192 pollAddress
= CECDEVICE_PLAYBACKDEVICE2
;
1194 case CECDEVICE_PLAYBACKDEVICE2
:
1195 pollAddress
= CECDEVICE_PLAYBACKDEVICE1
;
1197 case CECDEVICE_RECORDINGDEVICE3
:
1198 pollAddress
= CECDEVICE_RECORDINGDEVICE2
;
1200 case CECDEVICE_RECORDINGDEVICE2
:
1201 pollAddress
= CECDEVICE_RECORDINGDEVICE1
;
1203 case CECDEVICE_TUNER4
:
1204 pollAddress
= CECDEVICE_TUNER3
;
1206 case CECDEVICE_TUNER3
:
1207 pollAddress
= CECDEVICE_TUNER2
;
1209 case CECDEVICE_TUNER2
:
1210 pollAddress
= CECDEVICE_TUNER1
;
1212 case CECDEVICE_AUDIOSYSTEM
:
1213 case CECDEVICE_PLAYBACKDEVICE1
:
1214 case CECDEVICE_RECORDINGDEVICE1
:
1215 case CECDEVICE_TUNER1
:
1223 if (!bSendPoll
&& pollAddress
!= CECDEVICE_UNKNOWN
)
1225 CCECBusDevice
*device
= m_processor
->GetDevice(pollAddress
);
1228 cec_bus_device_status status
= device
->GetStatus();
1229 bSendPoll
= (status
== CEC_DEVICE_STATUS_PRESENT
|| status
== CEC_DEVICE_STATUS_HANDLED_BY_LIBCEC
);
1240 void CCECBusDevice::CheckVendorIdRequested(const cec_logical_address initiator
)
1242 bool bRequestVendorId(false);
1244 CLockObject
lock(m_mutex
);
1245 bRequestVendorId
= !m_bVendorIdRequested
;
1246 m_bVendorIdRequested
= true;
1249 if (bRequestVendorId
)
1251 ReplaceHandler(false);
1252 GetVendorId(initiator
);
1257 CCECAudioSystem
*CCECBusDevice::AsAudioSystem(void)
1259 return AsAudioSystem(this);
1262 CCECPlaybackDevice
*CCECBusDevice::AsPlaybackDevice(void)
1264 return AsPlaybackDevice(this);
1267 CCECRecordingDevice
*CCECBusDevice::AsRecordingDevice(void)
1269 return AsRecordingDevice(this);
1272 CCECTuner
*CCECBusDevice::AsTuner(void)
1274 return AsTuner(this);
1277 CCECTV
*CCECBusDevice::AsTV(void)
1282 CCECAudioSystem
*CCECBusDevice::AsAudioSystem(CCECBusDevice
*device
)
1284 if (device
&& device
->GetType() == CEC_DEVICE_TYPE_AUDIO_SYSTEM
)
1285 return static_cast<CCECAudioSystem
*>(device
);
1289 CCECPlaybackDevice
*CCECBusDevice::AsPlaybackDevice(CCECBusDevice
*device
)
1292 (device
->GetType() == CEC_DEVICE_TYPE_PLAYBACK_DEVICE
||
1293 device
->GetType() == CEC_DEVICE_TYPE_RECORDING_DEVICE
))
1294 return static_cast<CCECPlaybackDevice
*>(device
);
1298 CCECRecordingDevice
*CCECBusDevice::AsRecordingDevice(CCECBusDevice
*device
)
1300 if (device
&& device
->GetType() == CEC_DEVICE_TYPE_RECORDING_DEVICE
)
1301 return static_cast<CCECRecordingDevice
*>(device
);
1305 CCECTuner
*CCECBusDevice::AsTuner(CCECBusDevice
*device
)
1307 if (device
&& device
->GetType() == CEC_DEVICE_TYPE_TUNER
)
1308 return static_cast<CCECTuner
*>(device
);
1312 CCECTV
*CCECBusDevice::AsTV(CCECBusDevice
*device
)
1314 if (device
&& device
->GetType() == CEC_DEVICE_TYPE_TV
)
1315 return static_cast<CCECTV
*>(device
);
1319 void CCECBusDevice::MarkBusy(void)
1321 CLockObject
handlerLock(m_handlerMutex
);
1322 ++m_iHandlerUseCount
;
1325 void CCECBusDevice::MarkReady(void)
1327 CLockObject
handlerLock(m_handlerMutex
);
1328 if (m_iHandlerUseCount
> 0)
1329 --m_iHandlerUseCount
;
1332 bool CCECBusDevice::TryLogicalAddress(cec_version libCECSpecVersion
/* = CEC_VERSION_1_4 */)
1334 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "trying logical address '%s'", GetLogicalAddressName());
1336 if (!TransmitPoll(m_iLogicalAddress
, false))
1338 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "using logical address '%s'", GetLogicalAddressName());
1339 SetDeviceStatus(CEC_DEVICE_STATUS_HANDLED_BY_LIBCEC
, libCECSpecVersion
);
1344 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "logical address '%s' already taken", GetLogicalAddressName());
1345 SetDeviceStatus(CEC_DEVICE_STATUS_PRESENT
);
1349 CCECClient
*CCECBusDevice::GetClient(void)
1351 return m_processor
->GetClient(m_iLogicalAddress
);
1354 void CCECBusDevice::SignalOpcode(cec_opcode opcode
)
1356 m_waitForResponse
->Received(opcode
);
1359 bool CCECBusDevice::WaitForOpcode(cec_opcode opcode
)
1361 return m_waitForResponse
->Wait(opcode
);