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
),
79 m_bImageViewOnSent (false)
81 m_handler
= new CCECCommandHandler(this);
83 for (unsigned int iPtr
= 0; iPtr
< 4; iPtr
++)
84 m_menuLanguage
.language
[iPtr
] = '?';
85 m_menuLanguage
.language
[3] = 0;
86 m_menuLanguage
.device
= iLogicalAddress
;
88 m_strDeviceName
= ToString(m_iLogicalAddress
);
91 CCECBusDevice::~CCECBusDevice(void)
93 DELETE_AND_NULL(m_handler
);
94 DELETE_AND_NULL(m_waitForResponse
);
97 bool CCECBusDevice::ReplaceHandler(bool bActivateSource
/* = true */)
99 if (m_iLogicalAddress
== CECDEVICE_BROADCAST
)
102 bool bInitHandler(false);
104 CLockObject
lock(m_mutex
);
105 CLockObject
handlerLock(m_handlerMutex
);
106 if (m_iHandlerUseCount
> 0)
111 if (m_vendor
!= m_handler
->GetVendorId())
113 if (CCECCommandHandler::HasSpecificHandler(m_vendor
))
115 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "replacing the command handler for device '%s' (%x)", GetLogicalAddressName(), GetLogicalAddress());
117 int32_t iTransmitTimeout
= m_handler
->m_iTransmitTimeout
;
118 int32_t iTransmitWait
= m_handler
->m_iTransmitWait
;
119 int8_t iTransmitRetries
= m_handler
->m_iTransmitRetries
;
120 int64_t iActiveSourcePending
= m_handler
->m_iActiveSourcePending
;
122 DELETE_AND_NULL(m_handler
);
126 case CEC_VENDOR_SAMSUNG
:
127 m_handler
= new CANCommandHandler(this, iTransmitTimeout
, iTransmitWait
, iTransmitRetries
, iActiveSourcePending
);
130 m_handler
= new CSLCommandHandler(this, iTransmitTimeout
, iTransmitWait
, iTransmitRetries
, iActiveSourcePending
);
132 case CEC_VENDOR_PANASONIC
:
133 m_handler
= new CVLCommandHandler(this, iTransmitTimeout
, iTransmitWait
, iTransmitRetries
, iActiveSourcePending
);
136 m_handler
= new CCECCommandHandler(this, iTransmitTimeout
, iTransmitWait
, iTransmitRetries
, iActiveSourcePending
);
140 m_handler
->SetVendorId(m_vendor
);
148 CCECBusDevice
*primary
= GetProcessor()->GetPrimaryDevice();
149 if (primary
->GetLogicalAddress() != CECDEVICE_UNREGISTERED
)
151 m_handler
->InitHandler();
153 if (bActivateSource
&& IsHandledByLibCEC() && IsActiveSource())
154 m_handler
->ActivateSource();
163 CCECCommandHandler
*CCECBusDevice::GetHandler(void)
165 ReplaceHandler(false);
170 bool CCECBusDevice::HandleCommand(const cec_command
&command
)
172 bool bHandled(false);
174 /* update "last active" */
176 CLockObject
lock(m_mutex
);
177 m_iLastActive
= GetTimeMs();
181 /* handle the command */
182 bHandled
= m_handler
->HandleCommand(command
);
184 /* change status to present */
185 if (bHandled
&& GetLogicalAddress() != CECDEVICE_BROADCAST
)
187 CLockObject
lock(m_mutex
);
188 if (m_deviceStatus
!= CEC_DEVICE_STATUS_HANDLED_BY_LIBCEC
)
190 if (m_deviceStatus
!= CEC_DEVICE_STATUS_PRESENT
)
191 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "device %s (%x) status changed to present after command %s", GetLogicalAddressName(), (uint8_t)GetLogicalAddress(), ToString(command
.opcode
));
192 m_deviceStatus
= CEC_DEVICE_STATUS_PRESENT
;
200 const char* CCECBusDevice::GetLogicalAddressName(void) const
202 return ToString(m_iLogicalAddress
);
205 bool CCECBusDevice::IsPresent(void)
207 CLockObject
lock(m_mutex
);
208 return m_deviceStatus
== CEC_DEVICE_STATUS_PRESENT
;
211 bool CCECBusDevice::IsHandledByLibCEC(void)
213 CLockObject
lock(m_mutex
);
214 return m_deviceStatus
== CEC_DEVICE_STATUS_HANDLED_BY_LIBCEC
;
217 void CCECBusDevice::SetUnsupportedFeature(cec_opcode opcode
)
219 // some commands should never be marked as unsupported
220 if (opcode
== CEC_OPCODE_VENDOR_COMMAND
||
221 opcode
== CEC_OPCODE_VENDOR_COMMAND_WITH_ID
||
222 opcode
== CEC_OPCODE_VENDOR_REMOTE_BUTTON_DOWN
||
223 opcode
== CEC_OPCODE_VENDOR_REMOTE_BUTTON_UP
||
224 opcode
== CEC_OPCODE_ABORT
||
225 opcode
== CEC_OPCODE_FEATURE_ABORT
||
226 opcode
== CEC_OPCODE_NONE
)
230 CLockObject
lock(m_mutex
);
231 if (m_unsupportedFeatures
.find(opcode
) == m_unsupportedFeatures
.end())
233 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "marking opcode '%s' as unsupported feature for device '%s'", ToString(opcode
), GetLogicalAddressName());
234 m_unsupportedFeatures
.insert(opcode
);
238 // signal threads that are waiting for a reponse
240 SignalOpcode(cec_command::GetResponseOpcode(opcode
));
244 bool CCECBusDevice::IsUnsupportedFeature(cec_opcode opcode
)
246 CLockObject
lock(m_mutex
);
247 bool bUnsupported
= (m_unsupportedFeatures
.find(opcode
) != m_unsupportedFeatures
.end());
249 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "'%s' is marked as unsupported feature for device '%s'", ToString(opcode
), GetLogicalAddressName());
253 bool CCECBusDevice::TransmitKeypress(const cec_logical_address initiator
, cec_user_control_code key
, bool bWait
/* = true */)
256 bool bReturn
= m_handler
->TransmitKeypress(initiator
, m_iLogicalAddress
, key
, bWait
);
261 bool CCECBusDevice::TransmitKeyRelease(const cec_logical_address initiator
, bool bWait
/* = true */)
264 bool bReturn
= m_handler
->TransmitKeyRelease(initiator
, m_iLogicalAddress
, bWait
);
269 cec_version
CCECBusDevice::GetCecVersion(const cec_logical_address initiator
, bool bUpdate
/* = false */)
271 bool bIsPresent(GetStatus() == CEC_DEVICE_STATUS_PRESENT
);
272 bool bRequestUpdate(false);
274 CLockObject
lock(m_mutex
);
275 bRequestUpdate
= bIsPresent
&&
276 (bUpdate
|| m_cecVersion
== CEC_VERSION_UNKNOWN
);
281 CheckVendorIdRequested(initiator
);
282 RequestCecVersion(initiator
);
285 CLockObject
lock(m_mutex
);
289 void CCECBusDevice::SetCecVersion(const cec_version newVersion
)
291 CLockObject
lock(m_mutex
);
292 if (m_cecVersion
!= newVersion
)
293 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "%s (%X): CEC version %s", GetLogicalAddressName(), m_iLogicalAddress
, ToString(newVersion
));
294 m_cecVersion
= newVersion
;
297 bool CCECBusDevice::RequestCecVersion(const cec_logical_address initiator
, bool bWaitForResponse
/* = true */)
301 if (!IsHandledByLibCEC() &&
302 !IsUnsupportedFeature(CEC_OPCODE_GET_CEC_VERSION
))
305 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "<< requesting CEC version of '%s' (%X)", GetLogicalAddressName(), m_iLogicalAddress
);
306 bReturn
= m_handler
->TransmitRequestCecVersion(initiator
, m_iLogicalAddress
, bWaitForResponse
);
312 bool CCECBusDevice::TransmitCECVersion(const cec_logical_address destination
, bool bIsReply
)
316 CLockObject
lock(m_mutex
);
317 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "<< %s (%X) -> %s (%X): cec version %s", GetLogicalAddressName(), m_iLogicalAddress
, ToString(destination
), destination
, ToString(m_cecVersion
));
318 version
= m_cecVersion
;
322 bool bReturn
= m_handler
->TransmitCECVersion(m_iLogicalAddress
, destination
, version
, bIsReply
);
327 cec_menu_language
&CCECBusDevice::GetMenuLanguage(const cec_logical_address initiator
, bool bUpdate
/* = false */)
329 bool bIsPresent(GetStatus() == CEC_DEVICE_STATUS_PRESENT
);
330 bool bRequestUpdate(false);
332 CLockObject
lock(m_mutex
);
333 bRequestUpdate
= (bIsPresent
&&
334 (bUpdate
|| !strcmp(m_menuLanguage
.language
, "???")));
339 CheckVendorIdRequested(initiator
);
340 RequestMenuLanguage(initiator
);
343 CLockObject
lock(m_mutex
);
344 return m_menuLanguage
;
347 void CCECBusDevice::SetMenuLanguage(const char *strLanguage
)
352 CLockObject
lock(m_mutex
);
353 if (strcmp(strLanguage
, m_menuLanguage
.language
))
355 memcpy(m_menuLanguage
.language
, strLanguage
, 3);
356 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "%s (%X): menu language set to '%s'", GetLogicalAddressName(), m_iLogicalAddress
, m_menuLanguage
.language
);
360 void CCECBusDevice::SetMenuLanguage(const cec_menu_language
&language
)
362 if (language
.device
== m_iLogicalAddress
)
363 SetMenuLanguage(language
.language
);
366 bool CCECBusDevice::RequestMenuLanguage(const cec_logical_address initiator
, bool bWaitForResponse
/* = true */)
370 if (!IsHandledByLibCEC() &&
371 !IsUnsupportedFeature(CEC_OPCODE_GET_MENU_LANGUAGE
))
374 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "<< requesting menu language of '%s' (%X)", GetLogicalAddressName(), m_iLogicalAddress
);
375 bReturn
= m_handler
->TransmitRequestMenuLanguage(initiator
, m_iLogicalAddress
, bWaitForResponse
);
381 bool CCECBusDevice::TransmitSetMenuLanguage(const cec_logical_address destination
, bool bIsReply
)
384 cec_menu_language language
;
386 CLockObject
lock(m_mutex
);
387 language
= m_menuLanguage
;
392 CLockObject
lock(m_mutex
);
393 lang
[0] = language
.language
[0];
394 lang
[1] = language
.language
[1];
395 lang
[2] = language
.language
[2];
399 if (lang
[0] == '?' && lang
[1] == '?' && lang
[2] == '?')
401 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "<< %s (%X) -> %s (%X): menu language feature abort", GetLogicalAddressName(), m_iLogicalAddress
, ToString(destination
), destination
);
402 m_processor
->TransmitAbort(m_iLogicalAddress
, destination
, CEC_OPCODE_GIVE_DEVICE_VENDOR_ID
);
407 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "<< %s (%X) -> broadcast (F): menu language '%s'", GetLogicalAddressName(), m_iLogicalAddress
, lang
);
408 bReturn
= m_handler
->TransmitSetMenuLanguage(m_iLogicalAddress
, lang
, bIsReply
);
414 bool CCECBusDevice::TransmitOSDString(const cec_logical_address destination
, cec_display_control duration
, const char *strMessage
, bool bIsReply
)
417 if (!m_processor
->GetDevice(destination
)->IsUnsupportedFeature(CEC_OPCODE_SET_OSD_STRING
))
419 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "<< %s (%X) -> %s (%X): display OSD message '%s'", GetLogicalAddressName(), m_iLogicalAddress
, ToString(destination
), destination
, strMessage
);
421 bReturn
= m_handler
->TransmitOSDString(m_iLogicalAddress
, destination
, duration
, strMessage
, bIsReply
);
427 CStdString
CCECBusDevice::GetCurrentOSDName(void)
429 CLockObject
lock(m_mutex
);
430 return m_strDeviceName
;
433 CStdString
CCECBusDevice::GetOSDName(const cec_logical_address initiator
, bool bUpdate
/* = false */)
435 bool bIsPresent(GetStatus() == CEC_DEVICE_STATUS_PRESENT
);
436 bool bRequestUpdate(false);
438 CLockObject
lock(m_mutex
);
439 bRequestUpdate
= bIsPresent
&&
440 (bUpdate
|| m_strDeviceName
.Equals(ToString(m_iLogicalAddress
))) &&
441 m_type
!= CEC_DEVICE_TYPE_TV
;
446 CheckVendorIdRequested(initiator
);
447 RequestOSDName(initiator
);
450 CLockObject
lock(m_mutex
);
451 return m_strDeviceName
;
454 void CCECBusDevice::SetOSDName(CStdString strName
)
456 CLockObject
lock(m_mutex
);
457 if (m_strDeviceName
!= strName
)
459 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "%s (%X): osd name set to '%s'", GetLogicalAddressName(), m_iLogicalAddress
, strName
.c_str());
460 m_strDeviceName
= strName
;
464 bool CCECBusDevice::RequestOSDName(const cec_logical_address initiator
, bool bWaitForResponse
/* = true */)
468 if (!IsHandledByLibCEC() &&
469 !IsUnsupportedFeature(CEC_OPCODE_GIVE_OSD_NAME
))
472 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "<< requesting OSD name of '%s' (%X)", GetLogicalAddressName(), m_iLogicalAddress
);
473 bReturn
= m_handler
->TransmitRequestOSDName(initiator
, m_iLogicalAddress
, bWaitForResponse
);
479 bool CCECBusDevice::TransmitOSDName(const cec_logical_address destination
, bool bIsReply
)
481 CStdString strDeviceName
;
483 CLockObject
lock(m_mutex
);
484 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "<< %s (%X) -> %s (%X): OSD name '%s'", GetLogicalAddressName(), m_iLogicalAddress
, ToString(destination
), destination
, m_strDeviceName
.c_str());
485 strDeviceName
= m_strDeviceName
;
489 bool bReturn
= m_handler
->TransmitOSDName(m_iLogicalAddress
, destination
, strDeviceName
, bIsReply
);
494 bool CCECBusDevice::HasValidPhysicalAddress(void)
496 CLockObject
lock(m_mutex
);
497 return CLibCEC::IsValidPhysicalAddress(m_iPhysicalAddress
);
500 uint16_t CCECBusDevice::GetCurrentPhysicalAddress(void)
502 CLockObject
lock(m_mutex
);
503 return m_iPhysicalAddress
;
506 uint16_t CCECBusDevice::GetPhysicalAddress(const cec_logical_address initiator
, bool bSuppressUpdate
/* = false */)
508 if (!bSuppressUpdate
)
510 bool bIsPresent(GetStatus() == CEC_DEVICE_STATUS_PRESENT
);
511 bool bRequestUpdate(false);
513 CLockObject
lock(m_mutex
);
514 bRequestUpdate
= bIsPresent
&& m_iPhysicalAddress
== CEC_INVALID_PHYSICAL_ADDRESS
;
519 CheckVendorIdRequested(initiator
);
520 if (!RequestPhysicalAddress(initiator
))
521 LIB_CEC
->AddLog(CEC_LOG_ERROR
, "failed to request the physical address");
525 CLockObject
lock(m_mutex
);
526 return m_iPhysicalAddress
;
529 bool CCECBusDevice::SetPhysicalAddress(uint16_t iNewAddress
)
531 CLockObject
lock(m_mutex
);
532 if (iNewAddress
> 0 && m_iPhysicalAddress
!= iNewAddress
)
534 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "%s (%X): physical address changed from %04x to %04x", GetLogicalAddressName(), m_iLogicalAddress
, m_iPhysicalAddress
, iNewAddress
);
535 m_iPhysicalAddress
= iNewAddress
;
537 if (m_processor
->GetDevices()->GetActiveSourceAddress() == iNewAddress
)
538 MarkAsActiveSource();
543 bool CCECBusDevice::RequestPhysicalAddress(const cec_logical_address initiator
, bool bWaitForResponse
/* = true */)
547 if (!IsHandledByLibCEC())
550 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "<< requesting physical address of '%s' (%X)", GetLogicalAddressName(), m_iLogicalAddress
);
551 bReturn
= m_handler
->TransmitRequestPhysicalAddress(initiator
, m_iLogicalAddress
, bWaitForResponse
);
557 bool CCECBusDevice::TransmitPhysicalAddress(bool bIsReply
)
559 uint16_t iPhysicalAddress
;
560 cec_device_type type
;
562 CLockObject
lock(m_mutex
);
563 if (m_iPhysicalAddress
== CEC_INVALID_PHYSICAL_ADDRESS
)
566 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "<< %s (%X) -> broadcast (F): physical adddress %4x", GetLogicalAddressName(), m_iLogicalAddress
, m_iPhysicalAddress
);
567 iPhysicalAddress
= m_iPhysicalAddress
;
572 bool bReturn
= m_handler
->TransmitPhysicalAddress(m_iLogicalAddress
, iPhysicalAddress
, type
, bIsReply
);
577 cec_power_status
CCECBusDevice::GetCurrentPowerStatus(void)
579 CLockObject
lock(m_mutex
);
580 return m_powerStatus
;
583 cec_power_status
CCECBusDevice::GetPowerStatus(const cec_logical_address initiator
, bool bUpdate
/* = false */)
585 bool bIsPresent(GetStatus() == CEC_DEVICE_STATUS_PRESENT
);
586 bool bRequestUpdate(false);
588 CLockObject
lock(m_mutex
);
589 bRequestUpdate
= (bIsPresent
&&
590 (bUpdate
|| m_powerStatus
== CEC_POWER_STATUS_UNKNOWN
||
591 m_powerStatus
== CEC_POWER_STATUS_IN_TRANSITION_STANDBY_TO_ON
||
592 m_powerStatus
== CEC_POWER_STATUS_IN_TRANSITION_ON_TO_STANDBY
||
593 GetTimeMs() - m_iLastPowerStateUpdate
>= CEC_POWER_STATE_REFRESH_TIME
));
598 CheckVendorIdRequested(initiator
);
599 RequestPowerStatus(initiator
);
602 CLockObject
lock(m_mutex
);
603 return m_powerStatus
;
606 void CCECBusDevice::SetPowerStatus(const cec_power_status powerStatus
)
608 CLockObject
lock(m_mutex
);
609 if (m_powerStatus
!= powerStatus
)
611 m_iLastPowerStateUpdate
= GetTimeMs();
612 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "%s (%X): power status changed from '%s' to '%s'", GetLogicalAddressName(), m_iLogicalAddress
, ToString(m_powerStatus
), ToString(powerStatus
));
613 m_powerStatus
= powerStatus
;
617 void CCECBusDevice::OnImageViewOnSent(bool bSentByLibCEC
)
619 CLockObject
lock(m_mutex
);
620 m_bImageViewOnSent
= bSentByLibCEC
;
622 if (m_powerStatus
!= CEC_POWER_STATUS_ON
&& m_powerStatus
!= CEC_POWER_STATUS_IN_TRANSITION_STANDBY_TO_ON
)
624 m_iLastPowerStateUpdate
= GetTimeMs();
625 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
));
626 m_powerStatus
= CEC_POWER_STATUS_IN_TRANSITION_STANDBY_TO_ON
;
630 bool CCECBusDevice::ImageViewOnSent(void)
632 CLockObject
lock(m_mutex
);
633 return m_bImageViewOnSent
;
636 bool CCECBusDevice::RequestPowerStatus(const cec_logical_address initiator
, bool bWaitForResponse
/* = true */)
640 if (!IsHandledByLibCEC() &&
641 !IsUnsupportedFeature(CEC_OPCODE_GIVE_DEVICE_POWER_STATUS
))
644 bReturn
= m_handler
->TransmitRequestPowerStatus(initiator
, m_iLogicalAddress
, bWaitForResponse
);
650 bool CCECBusDevice::TransmitPowerState(const cec_logical_address destination
, bool bIsReply
)
652 cec_power_status state
;
654 CLockObject
lock(m_mutex
);
655 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "<< %s (%X) -> %s (%X): %s", GetLogicalAddressName(), m_iLogicalAddress
, ToString(destination
), destination
, ToString(m_powerStatus
));
656 state
= m_powerStatus
;
660 bool bReturn
= m_handler
->TransmitPowerState(m_iLogicalAddress
, destination
, state
, bIsReply
);
665 cec_vendor_id
CCECBusDevice::GetCurrentVendorId(void)
667 CLockObject
lock(m_mutex
);
671 cec_vendor_id
CCECBusDevice::GetVendorId(const cec_logical_address initiator
, bool bUpdate
/* = false */)
673 bool bIsPresent(GetStatus() == CEC_DEVICE_STATUS_PRESENT
);
674 bool bRequestUpdate(false);
676 CLockObject
lock(m_mutex
);
677 bRequestUpdate
= (bIsPresent
&&
678 (bUpdate
|| m_vendor
== CEC_VENDOR_UNKNOWN
));
682 RequestVendorId(initiator
);
684 CLockObject
lock(m_mutex
);
688 const char *CCECBusDevice::GetVendorName(const cec_logical_address initiator
, bool bUpdate
/* = false */)
690 return ToString(GetVendorId(initiator
, bUpdate
));
693 bool CCECBusDevice::SetVendorId(uint64_t iVendorId
)
695 bool bVendorChanged(false);
698 CLockObject
lock(m_mutex
);
699 bVendorChanged
= (m_vendor
!= (cec_vendor_id
)iVendorId
);
700 m_vendor
= (cec_vendor_id
)iVendorId
;
704 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "%s (%X): vendor = %s (%06x)", GetLogicalAddressName(), m_iLogicalAddress
, ToString(m_vendor
), m_vendor
);
706 return bVendorChanged
;
709 bool CCECBusDevice::RequestVendorId(const cec_logical_address initiator
, bool bWaitForResponse
/* = true */)
713 if (!IsHandledByLibCEC() && initiator
!= CECDEVICE_UNKNOWN
)
716 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "<< requesting vendor ID of '%s' (%X)", GetLogicalAddressName(), m_iLogicalAddress
);
717 bReturn
= m_handler
->TransmitRequestVendorId(initiator
, m_iLogicalAddress
, bWaitForResponse
);
720 if (bWaitForResponse
)
721 ReplaceHandler(true);
726 bool CCECBusDevice::TransmitVendorID(const cec_logical_address destination
, bool bSendAbort
, bool bIsReply
)
731 CLockObject
lock(m_mutex
);
732 iVendorId
= (uint64_t)m_vendor
;
736 if (iVendorId
== CEC_VENDOR_UNKNOWN
)
740 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "<< %s (%X) -> %s (%X): vendor id feature abort", GetLogicalAddressName(), m_iLogicalAddress
, ToString(destination
), destination
);
741 m_processor
->TransmitAbort(m_iLogicalAddress
, destination
, CEC_OPCODE_GIVE_DEVICE_VENDOR_ID
);
747 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
);
748 bReturn
= m_handler
->TransmitVendorID(m_iLogicalAddress
, iVendorId
, bIsReply
);
754 cec_bus_device_status
CCECBusDevice::GetStatus(bool bForcePoll
/* = false */, bool bSuppressPoll
/* = false */)
756 if (m_iLogicalAddress
== CECDEVICE_BROADCAST
)
757 return CEC_DEVICE_STATUS_NOT_PRESENT
;
759 cec_bus_device_status
status(CEC_DEVICE_STATUS_UNKNOWN
);
760 bool bNeedsPoll(false);
763 CLockObject
lock(m_mutex
);
764 status
= m_deviceStatus
;
765 bNeedsPoll
= !bSuppressPoll
&&
766 m_deviceStatus
!= CEC_DEVICE_STATUS_HANDLED_BY_LIBCEC
&&
769 // don't know the status
770 m_deviceStatus
== CEC_DEVICE_STATUS_UNKNOWN
||
771 // always poll the TV if it's marked as not present
772 (m_deviceStatus
== CEC_DEVICE_STATUS_NOT_PRESENT
&& m_iLogicalAddress
== CECDEVICE_TV
));
777 bool bPollAcked(false);
778 if (bNeedsPoll
&& NeedsPoll())
779 bPollAcked
= m_processor
->PollDevice(m_iLogicalAddress
);
781 status
= bPollAcked
? CEC_DEVICE_STATUS_PRESENT
: CEC_DEVICE_STATUS_NOT_PRESENT
;
782 SetDeviceStatus(status
);
788 void CCECBusDevice::SetDeviceStatus(const cec_bus_device_status newStatus
, cec_version libCECSpecVersion
/* = CEC_VERSION_1_4 */)
790 if (m_iLogicalAddress
== CECDEVICE_UNREGISTERED
)
794 CLockObject
lock(m_mutex
);
797 case CEC_DEVICE_STATUS_HANDLED_BY_LIBCEC
:
798 if (m_deviceStatus
!= newStatus
)
799 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "%s (%X): device status changed into 'handled by libCEC'", GetLogicalAddressName(), m_iLogicalAddress
);
800 SetPowerStatus (CEC_POWER_STATUS_ON
);
801 SetVendorId (CEC_VENDOR_UNKNOWN
);
802 SetMenuState (CEC_MENU_STATE_ACTIVATED
);
803 SetCecVersion (libCECSpecVersion
);
804 SetStreamPath (CEC_INVALID_PHYSICAL_ADDRESS
);
805 MarkAsInactiveSource();
807 m_deviceStatus
= newStatus
;
809 case CEC_DEVICE_STATUS_PRESENT
:
810 if (m_deviceStatus
!= newStatus
)
811 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "%s (%X): device status changed into 'present'", GetLogicalAddressName(), m_iLogicalAddress
);
812 m_deviceStatus
= newStatus
;
813 m_iLastActive
= GetTimeMs();
815 case CEC_DEVICE_STATUS_NOT_PRESENT
:
816 if (m_deviceStatus
!= newStatus
)
818 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "%s (%X): device status changed into 'not present'", GetLogicalAddressName(), m_iLogicalAddress
);
819 ResetDeviceStatus(true);
820 m_deviceStatus
= newStatus
;
830 void CCECBusDevice::ResetDeviceStatus(bool bClientUnregistered
/* = false */)
832 CLockObject
lock(m_mutex
);
833 SetPowerStatus (CEC_POWER_STATUS_UNKNOWN
);
834 SetVendorId (CEC_VENDOR_UNKNOWN
);
835 SetMenuState (CEC_MENU_STATE_ACTIVATED
);
836 SetCecVersion (CEC_VERSION_UNKNOWN
);
837 SetStreamPath (CEC_INVALID_PHYSICAL_ADDRESS
);
838 SetOSDName (ToString(m_iLogicalAddress
));
839 MarkAsInactiveSource(bClientUnregistered
);
842 m_bVendorIdRequested
= false;
843 m_unsupportedFeatures
.clear();
844 m_waitForResponse
->Clear();
846 if (m_deviceStatus
!= CEC_DEVICE_STATUS_UNKNOWN
)
847 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "%s (%X): device status changed into 'unknown'", GetLogicalAddressName(), m_iLogicalAddress
);
848 m_deviceStatus
= CEC_DEVICE_STATUS_UNKNOWN
;
851 bool CCECBusDevice::TransmitPoll(const cec_logical_address dest
, bool bUpdateDeviceStatus
)
854 cec_logical_address
destination(dest
);
855 if (destination
== CECDEVICE_UNKNOWN
)
856 destination
= m_iLogicalAddress
;
858 CCECBusDevice
*destDevice
= m_processor
->GetDevice(destination
);
859 if (destDevice
->m_deviceStatus
== CEC_DEVICE_STATUS_HANDLED_BY_LIBCEC
)
863 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "<< %s (%X) -> %s (%X): POLL", GetLogicalAddressName(), m_iLogicalAddress
, ToString(dest
), dest
);
864 bReturn
= m_handler
->TransmitPoll(m_iLogicalAddress
, destination
, false);
865 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, bReturn
? ">> POLL sent" : ">> POLL not sent");
867 if (bUpdateDeviceStatus
)
868 destDevice
->SetDeviceStatus(bReturn
? CEC_DEVICE_STATUS_PRESENT
: CEC_DEVICE_STATUS_NOT_PRESENT
);
874 void CCECBusDevice::HandlePoll(const cec_logical_address destination
)
876 if (destination
>= 0 && destination
< CECDEVICE_BROADCAST
)
878 CCECBusDevice
*device
= m_processor
->GetDevice(destination
);
880 device
->HandlePollFrom(m_iLogicalAddress
);
884 void CCECBusDevice::HandlePollFrom(const cec_logical_address initiator
)
886 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "<< POLL: %s (%x) -> %s (%x)", ToString(initiator
), initiator
, ToString(m_iLogicalAddress
), m_iLogicalAddress
);
887 m_bAwaitingReceiveFailed
= true;
890 bool CCECBusDevice::HandleReceiveFailed(void)
892 bool bReturn
= m_bAwaitingReceiveFailed
;
893 m_bAwaitingReceiveFailed
= false;
897 cec_menu_state
CCECBusDevice::GetMenuState(const cec_logical_address
UNUSED(initiator
))
899 CLockObject
lock(m_mutex
);
903 void CCECBusDevice::SetMenuState(const cec_menu_state state
)
905 CLockObject
lock(m_mutex
);
906 if (m_menuState
!= state
)
908 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "%s (%X): menu state set to '%s'", GetLogicalAddressName(), m_iLogicalAddress
, ToString(m_menuState
));
913 bool CCECBusDevice::TransmitMenuState(const cec_logical_address dest
, bool bIsReply
)
915 cec_menu_state menuState
;
917 CLockObject
lock(m_mutex
);
918 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "<< %s (%X) -> %s (%X): menu state '%s'", GetLogicalAddressName(), m_iLogicalAddress
, ToString(dest
), dest
, ToString(m_menuState
));
919 menuState
= m_menuState
;
923 bool bReturn
= m_handler
->TransmitMenuState(m_iLogicalAddress
, dest
, menuState
, bIsReply
);
928 bool CCECBusDevice::ActivateSource(uint64_t iDelay
/* = 0 */)
930 MarkAsActiveSource();
935 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "sending active source message for '%s'", ToString(m_iLogicalAddress
));
936 bReturn
= m_handler
->ActivateSource();
940 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "scheduling active source message for '%s'", ToString(m_iLogicalAddress
));
941 m_handler
->ScheduleActivateSource(iDelay
);
947 bool CCECBusDevice::RequestActiveSource(bool bWaitForResponse
/* = true */)
951 if (IsHandledByLibCEC())
954 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "<< requesting active source");
956 bReturn
= m_handler
->TransmitRequestActiveSource(m_iLogicalAddress
, bWaitForResponse
);
962 void CCECBusDevice::MarkAsActiveSource(void)
964 bool bWasActivated(false);
966 // set the power status to powered on
967 SetPowerStatus(CEC_POWER_STATUS_ON
);
969 // mark this device as active source
971 CLockObject
lock(m_mutex
);
972 if (!m_bActiveSource
)
974 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "making %s (%x) the active source", GetLogicalAddressName(), m_iLogicalAddress
);
975 bWasActivated
= true;
978 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "%s (%x) was already marked as active source", GetLogicalAddressName(), m_iLogicalAddress
);
980 m_bActiveSource
= true;
983 CCECBusDevice
* tv
= m_processor
->GetDevice(CECDEVICE_TV
);
985 tv
->OnImageViewOnSent(false);
987 // mark other devices as inactive sources
988 CECDEVICEVEC devices
;
989 m_processor
->GetDevices()->Get(devices
);
990 for (CECDEVICEVEC::iterator it
= devices
.begin(); it
!= devices
.end(); it
++)
991 if ((*it
)->GetLogicalAddress() != m_iLogicalAddress
)
992 (*it
)->MarkAsInactiveSource();
996 if (IsHandledByLibCEC())
997 m_processor
->SetActiveSource(true, false);
998 CCECClient
*client
= GetClient();
1000 client
->SourceActivated(m_iLogicalAddress
);
1004 void CCECBusDevice::MarkAsInactiveSource(bool bClientUnregistered
/* = false */)
1006 bool bWasDeactivated(false);
1008 CLockObject
lock(m_mutex
);
1009 if (m_bActiveSource
)
1011 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "marking %s (%X) as inactive source", GetLogicalAddressName(), m_iLogicalAddress
);
1012 bWasDeactivated
= true;
1014 m_bActiveSource
= false;
1017 if (bWasDeactivated
)
1019 if (IsHandledByLibCEC())
1020 m_processor
->SetActiveSource(false, bClientUnregistered
);
1021 CCECClient
*client
= GetClient();
1023 client
->SourceDeactivated(m_iLogicalAddress
);
1027 bool CCECBusDevice::TransmitActiveSource(bool bIsReply
)
1029 bool bSendActiveSource(false);
1030 uint16_t iPhysicalAddress(CEC_INVALID_PHYSICAL_ADDRESS
);
1033 CLockObject
lock(m_mutex
);
1034 if (!HasValidPhysicalAddress())
1036 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "%s (%X) has an invalid physical address (%04x), not sending active source commands", GetLogicalAddressName(), m_iLogicalAddress
, m_iPhysicalAddress
);
1040 iPhysicalAddress
= m_iPhysicalAddress
;
1042 if (m_powerStatus
!= CEC_POWER_STATUS_ON
&& m_powerStatus
!= CEC_POWER_STATUS_IN_TRANSITION_STANDBY_TO_ON
)
1043 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "<< %s (%X) is not powered on", GetLogicalAddressName(), m_iLogicalAddress
);
1044 else if (m_bActiveSource
)
1046 LIB_CEC
->AddLog(CEC_LOG_NOTICE
, "<< %s (%X) -> broadcast (F): active source (%4x)", GetLogicalAddressName(), m_iLogicalAddress
, m_iPhysicalAddress
);
1047 bSendActiveSource
= true;
1050 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "<< %s (%X) is not the active source", GetLogicalAddressName(), m_iLogicalAddress
);
1053 bool bActiveSourceSent(false);
1054 if (bSendActiveSource
)
1057 bActiveSourceSent
= m_handler
->TransmitActiveSource(m_iLogicalAddress
, iPhysicalAddress
, bIsReply
);
1061 return bActiveSourceSent
;
1064 bool CCECBusDevice::TransmitImageViewOn(void)
1067 CLockObject
lock(m_mutex
);
1068 if (m_powerStatus
!= CEC_POWER_STATUS_ON
&& m_powerStatus
!= CEC_POWER_STATUS_IN_TRANSITION_STANDBY_TO_ON
)
1070 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "<< %s (%X) is not powered on", GetLogicalAddressName(), m_iLogicalAddress
);
1075 CCECBusDevice
* tv
= m_processor
->GetDevice(CECDEVICE_TV
);
1078 LIB_CEC
->AddLog(CEC_LOG_ERROR
, "%s - couldn't get TV instance", __FUNCTION__
);
1082 if (tv
->ImageViewOnSent())
1084 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "%s - 'image view on' already sent", __FUNCTION__
);
1088 bool bImageViewOnSent(false);
1090 bImageViewOnSent
= m_handler
->TransmitImageViewOn(m_iLogicalAddress
, CECDEVICE_TV
);
1093 if (bImageViewOnSent
)
1094 tv
->OnImageViewOnSent(true);
1096 return bImageViewOnSent
;
1099 bool CCECBusDevice::TransmitInactiveSource(void)
1101 uint16_t iPhysicalAddress
;
1103 CLockObject
lock(m_mutex
);
1104 LIB_CEC
->AddLog(CEC_LOG_NOTICE
, "<< %s (%X) -> broadcast (F): inactive source", GetLogicalAddressName(), m_iLogicalAddress
);
1105 iPhysicalAddress
= m_iPhysicalAddress
;
1109 bool bReturn
= m_handler
->TransmitInactiveSource(m_iLogicalAddress
, iPhysicalAddress
);
1114 bool CCECBusDevice::TransmitPendingActiveSourceCommands(void)
1117 bool bReturn
= m_handler
->ActivateSource(true);
1122 void CCECBusDevice::SetActiveRoute(uint16_t iRoute
)
1124 CCECDeviceMap
* map
= m_processor
->GetDevices();
1128 CCECBusDevice
* previouslyActive
= map
->GetActiveSource();
1129 if (!previouslyActive
)
1132 CECDEVICEVEC devices
;
1133 m_processor
->GetDevices()->GetChildrenOf(devices
, this);
1135 for (CECDEVICEVEC::iterator it
= devices
.begin(); it
!= devices
.end(); it
++)
1137 if (!CCECTypeUtils::PhysicalAddressIsIncluded(iRoute
, (*it
)->GetCurrentPhysicalAddress()))
1138 (*it
)->MarkAsInactiveSource();
1142 void CCECBusDevice::SetStreamPath(uint16_t iNewAddress
, uint16_t iOldAddress
/* = CEC_INVALID_PHYSICAL_ADDRESS */)
1144 CLockObject
lock(m_mutex
);
1145 if (iNewAddress
!= m_iStreamPath
)
1147 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "%s (%X): stream path changed from %04x to %04x", GetLogicalAddressName(), m_iLogicalAddress
, iOldAddress
== 0 ? m_iStreamPath
: iOldAddress
, iNewAddress
);
1148 m_iStreamPath
= iNewAddress
;
1151 if (!LIB_CEC
->IsValidPhysicalAddress(iNewAddress
))
1154 CCECBusDevice
*device
= m_processor
->GetDeviceByPhysicalAddress(iNewAddress
);
1157 // if a device is found with the new physical address, mark it as active, which will automatically mark all other devices as inactive
1158 device
->MarkAsActiveSource();
1160 // respond with an active source message if this device is handled by libCEC
1161 if (device
->IsHandledByLibCEC())
1162 device
->TransmitActiveSource(true);
1166 // try to find the device with the old address, and mark it as inactive when found
1167 device
= m_processor
->GetDeviceByPhysicalAddress(iOldAddress
);
1169 device
->MarkAsInactiveSource();
1173 bool CCECBusDevice::PowerOn(const cec_logical_address initiator
)
1175 bool bReturn(false);
1176 GetVendorId(initiator
); // ensure that we got the vendor id, because the implementations vary per vendor
1179 cec_power_status currentStatus
;
1180 if (m_iLogicalAddress
== CECDEVICE_TV
||
1181 ((currentStatus
= GetPowerStatus(initiator
, false)) != CEC_POWER_STATUS_IN_TRANSITION_STANDBY_TO_ON
&&
1182 currentStatus
!= CEC_POWER_STATUS_ON
))
1184 LIB_CEC
->AddLog(CEC_LOG_NOTICE
, "<< powering on '%s' (%X)", GetLogicalAddressName(), m_iLogicalAddress
);
1185 bReturn
= m_handler
->PowerOn(initiator
, m_iLogicalAddress
);
1189 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "'%s' (%X) is already '%s'", GetLogicalAddressName(), m_iLogicalAddress
, ToString(currentStatus
));
1196 bool CCECBusDevice::Standby(const cec_logical_address initiator
)
1198 GetVendorId(initiator
); // ensure that we got the vendor id, because the implementations vary per vendor
1200 LIB_CEC
->AddLog(CEC_LOG_NOTICE
, "<< putting '%s' (%X) in standby mode", GetLogicalAddressName(), m_iLogicalAddress
);
1202 bool bReturn
= m_handler
->TransmitStandby(initiator
, m_iLogicalAddress
);
1207 bool CCECBusDevice::NeedsPoll(void)
1209 bool bSendPoll(false);
1210 cec_logical_address
pollAddress(CECDEVICE_UNKNOWN
);
1211 switch (m_iLogicalAddress
)
1213 case CECDEVICE_PLAYBACKDEVICE3
:
1214 pollAddress
= CECDEVICE_PLAYBACKDEVICE2
;
1216 case CECDEVICE_PLAYBACKDEVICE2
:
1217 pollAddress
= CECDEVICE_PLAYBACKDEVICE1
;
1219 case CECDEVICE_RECORDINGDEVICE3
:
1220 pollAddress
= CECDEVICE_RECORDINGDEVICE2
;
1222 case CECDEVICE_RECORDINGDEVICE2
:
1223 pollAddress
= CECDEVICE_RECORDINGDEVICE1
;
1225 case CECDEVICE_TUNER4
:
1226 pollAddress
= CECDEVICE_TUNER3
;
1228 case CECDEVICE_TUNER3
:
1229 pollAddress
= CECDEVICE_TUNER2
;
1231 case CECDEVICE_TUNER2
:
1232 pollAddress
= CECDEVICE_TUNER1
;
1234 case CECDEVICE_AUDIOSYSTEM
:
1235 case CECDEVICE_PLAYBACKDEVICE1
:
1236 case CECDEVICE_RECORDINGDEVICE1
:
1237 case CECDEVICE_TUNER1
:
1245 if (!bSendPoll
&& pollAddress
!= CECDEVICE_UNKNOWN
)
1247 CCECBusDevice
*device
= m_processor
->GetDevice(pollAddress
);
1250 cec_bus_device_status status
= device
->GetStatus();
1251 bSendPoll
= (status
== CEC_DEVICE_STATUS_PRESENT
|| status
== CEC_DEVICE_STATUS_HANDLED_BY_LIBCEC
);
1262 void CCECBusDevice::CheckVendorIdRequested(const cec_logical_address initiator
)
1264 bool bRequestVendorId(false);
1266 CLockObject
lock(m_mutex
);
1267 bRequestVendorId
= !m_bVendorIdRequested
;
1268 m_bVendorIdRequested
= true;
1271 if (bRequestVendorId
)
1273 ReplaceHandler(false);
1274 GetVendorId(initiator
);
1279 CCECAudioSystem
*CCECBusDevice::AsAudioSystem(void)
1281 return AsAudioSystem(this);
1284 CCECPlaybackDevice
*CCECBusDevice::AsPlaybackDevice(void)
1286 return AsPlaybackDevice(this);
1289 CCECRecordingDevice
*CCECBusDevice::AsRecordingDevice(void)
1291 return AsRecordingDevice(this);
1294 CCECTuner
*CCECBusDevice::AsTuner(void)
1296 return AsTuner(this);
1299 CCECTV
*CCECBusDevice::AsTV(void)
1304 CCECAudioSystem
*CCECBusDevice::AsAudioSystem(CCECBusDevice
*device
)
1306 if (device
&& device
->GetType() == CEC_DEVICE_TYPE_AUDIO_SYSTEM
)
1307 return static_cast<CCECAudioSystem
*>(device
);
1311 CCECPlaybackDevice
*CCECBusDevice::AsPlaybackDevice(CCECBusDevice
*device
)
1314 (device
->GetType() == CEC_DEVICE_TYPE_PLAYBACK_DEVICE
||
1315 device
->GetType() == CEC_DEVICE_TYPE_RECORDING_DEVICE
))
1316 return static_cast<CCECPlaybackDevice
*>(device
);
1320 CCECRecordingDevice
*CCECBusDevice::AsRecordingDevice(CCECBusDevice
*device
)
1322 if (device
&& device
->GetType() == CEC_DEVICE_TYPE_RECORDING_DEVICE
)
1323 return static_cast<CCECRecordingDevice
*>(device
);
1327 CCECTuner
*CCECBusDevice::AsTuner(CCECBusDevice
*device
)
1329 if (device
&& device
->GetType() == CEC_DEVICE_TYPE_TUNER
)
1330 return static_cast<CCECTuner
*>(device
);
1334 CCECTV
*CCECBusDevice::AsTV(CCECBusDevice
*device
)
1336 if (device
&& device
->GetType() == CEC_DEVICE_TYPE_TV
)
1337 return static_cast<CCECTV
*>(device
);
1341 void CCECBusDevice::MarkBusy(void)
1343 CLockObject
handlerLock(m_handlerMutex
);
1344 ++m_iHandlerUseCount
;
1347 void CCECBusDevice::MarkReady(void)
1349 CLockObject
handlerLock(m_handlerMutex
);
1350 if (m_iHandlerUseCount
> 0)
1351 --m_iHandlerUseCount
;
1354 bool CCECBusDevice::TryLogicalAddress(cec_version libCECSpecVersion
/* = CEC_VERSION_1_4 */)
1356 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "trying logical address '%s'", GetLogicalAddressName());
1358 if (!TransmitPoll(m_iLogicalAddress
, false))
1360 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "using logical address '%s'", GetLogicalAddressName());
1361 SetDeviceStatus(CEC_DEVICE_STATUS_HANDLED_BY_LIBCEC
, libCECSpecVersion
);
1366 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "logical address '%s' already taken", GetLogicalAddressName());
1367 SetDeviceStatus(CEC_DEVICE_STATUS_PRESENT
);
1371 CCECClient
*CCECBusDevice::GetClient(void)
1373 return m_processor
->GetClient(m_iLogicalAddress
);
1376 void CCECBusDevice::SignalOpcode(cec_opcode opcode
)
1378 m_waitForResponse
->Received(opcode
);
1381 bool CCECBusDevice::WaitForOpcode(cec_opcode opcode
)
1383 return m_waitForResponse
->Wait(opcode
);