2 * This file is part of the libCEC(R) library.
4 * libCEC(R) is Copyright (C) 2011-2013 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/implementations/PHCommandHandler.h"
43 #include "lib/implementations/RLCommandHandler.h"
44 #include "lib/implementations/RHCommandHandler.h"
45 #include "lib/LibCEC.h"
46 #include "lib/CECTypeUtils.h"
47 #include "lib/platform/util/timeutils.h"
48 #include "lib/platform/util/util.h"
50 #include "CECAudioSystem.h"
51 #include "CECPlaybackDevice.h"
52 #include "CECRecordingDevice.h"
58 using namespace PLATFORM
;
60 #define LIB_CEC m_processor->GetLib()
61 #define ToString(p) CCECTypeUtils::ToString(p)
63 CCECBusDevice::CCECBusDevice(CCECProcessor
*processor
, cec_logical_address iLogicalAddress
, uint16_t iPhysicalAddress
/* = CEC_INVALID_PHYSICAL_ADDRESS */) :
64 m_type (CEC_DEVICE_TYPE_RESERVED
),
65 m_iPhysicalAddress (iPhysicalAddress
),
66 m_iStreamPath (CEC_INVALID_PHYSICAL_ADDRESS
),
67 m_iLogicalAddress (iLogicalAddress
),
68 m_powerStatus (CEC_POWER_STATUS_UNKNOWN
),
69 m_processor (processor
),
70 m_vendor (CEC_VENDOR_UNKNOWN
),
71 m_bReplaceHandler (false),
72 m_menuState (CEC_MENU_STATE_ACTIVATED
),
73 m_bActiveSource (false),
75 m_iLastPowerStateUpdate (0),
76 m_cecVersion (CEC_VERSION_UNKNOWN
),
77 m_deviceStatus (CEC_DEVICE_STATUS_UNKNOWN
),
78 m_iHandlerUseCount (0),
79 m_bAwaitingReceiveFailed(false),
80 m_bVendorIdRequested (false),
81 m_waitForResponse (new CWaitForResponse
),
82 m_bImageViewOnSent (false)
84 m_handler
= new CCECCommandHandler(this);
86 for (unsigned int iPtr
= 0; iPtr
< 4; iPtr
++)
87 m_menuLanguage
.language
[iPtr
] = '?';
88 m_menuLanguage
.language
[3] = 0;
89 m_menuLanguage
.device
= iLogicalAddress
;
91 m_strDeviceName
= ToString(m_iLogicalAddress
);
94 CCECBusDevice::~CCECBusDevice(void)
96 DELETE_AND_NULL(m_handler
);
97 DELETE_AND_NULL(m_waitForResponse
);
100 bool CCECBusDevice::ReplaceHandler(bool bActivateSource
/* = true */)
102 if (m_iLogicalAddress
== CECDEVICE_BROADCAST
)
105 bool bInitHandler(false);
107 CLockObject
lock(m_mutex
);
108 CLockObject
handlerLock(m_handlerMutex
);
109 if (m_iHandlerUseCount
> 0)
114 if (m_vendor
!= m_handler
->GetVendorId())
116 if (CCECCommandHandler::HasSpecificHandler(m_vendor
))
118 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "replacing the command handler for device '%s' (%x)", GetLogicalAddressName(), GetLogicalAddress());
120 int32_t iTransmitTimeout
= m_handler
->m_iTransmitTimeout
;
121 int32_t iTransmitWait
= m_handler
->m_iTransmitWait
;
122 int8_t iTransmitRetries
= m_handler
->m_iTransmitRetries
;
123 int64_t iActiveSourcePending
= m_handler
->m_iActiveSourcePending
;
125 DELETE_AND_NULL(m_handler
);
129 case CEC_VENDOR_SAMSUNG
:
130 m_handler
= new CANCommandHandler(this, iTransmitTimeout
, iTransmitWait
, iTransmitRetries
, iActiveSourcePending
);
133 m_handler
= new CSLCommandHandler(this, iTransmitTimeout
, iTransmitWait
, iTransmitRetries
, iActiveSourcePending
);
135 case CEC_VENDOR_PANASONIC
:
136 m_handler
= new CVLCommandHandler(this, iTransmitTimeout
, iTransmitWait
, iTransmitRetries
, iActiveSourcePending
);
138 case CEC_VENDOR_PHILIPS
:
139 m_handler
= new CPHCommandHandler(this, iTransmitTimeout
, iTransmitWait
, iTransmitRetries
, iActiveSourcePending
);
141 case CEC_VENDOR_TOSHIBA
:
142 case CEC_VENDOR_TOSHIBA2
:
143 m_handler
= new CRLCommandHandler(this, iTransmitTimeout
, iTransmitWait
, iTransmitRetries
, iActiveSourcePending
);
145 case CEC_VENDOR_ONKYO
:
146 m_handler
= new CRHCommandHandler(this, iTransmitTimeout
, iTransmitWait
, iTransmitRetries
, iActiveSourcePending
);
149 m_handler
= new CCECCommandHandler(this, iTransmitTimeout
, iTransmitWait
, iTransmitRetries
, iActiveSourcePending
);
153 m_handler
->SetVendorId(m_vendor
);
161 CCECBusDevice
*primary
= GetProcessor()->GetPrimaryDevice();
162 if (primary
->GetLogicalAddress() != CECDEVICE_UNREGISTERED
)
164 m_handler
->InitHandler();
166 if (bActivateSource
&& IsHandledByLibCEC() && IsActiveSource())
167 m_handler
->ActivateSource();
176 CCECCommandHandler
*CCECBusDevice::GetHandler(void)
178 ReplaceHandler(false);
183 bool CCECBusDevice::HandleCommand(const cec_command
&command
)
185 bool bHandled(false);
187 /* update "last active" */
189 CLockObject
lock(m_mutex
);
190 m_iLastActive
= GetTimeMs();
194 /* handle the command */
195 bHandled
= m_handler
->HandleCommand(command
);
197 /* change status to present */
198 if (bHandled
&& GetLogicalAddress() != CECDEVICE_BROADCAST
&& command
.opcode_set
== 1)
200 CLockObject
lock(m_mutex
);
201 if (m_deviceStatus
!= CEC_DEVICE_STATUS_HANDLED_BY_LIBCEC
)
203 if (m_deviceStatus
!= CEC_DEVICE_STATUS_PRESENT
)
204 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "device %s (%x) status changed to present after command %s", GetLogicalAddressName(), (uint8_t)GetLogicalAddress(), ToString(command
.opcode
));
205 m_deviceStatus
= CEC_DEVICE_STATUS_PRESENT
;
213 const char* CCECBusDevice::GetLogicalAddressName(void) const
215 return ToString(m_iLogicalAddress
);
218 bool CCECBusDevice::IsPresent(void)
220 CLockObject
lock(m_mutex
);
221 return m_deviceStatus
== CEC_DEVICE_STATUS_PRESENT
;
224 bool CCECBusDevice::IsHandledByLibCEC(void)
226 CLockObject
lock(m_mutex
);
227 return m_deviceStatus
== CEC_DEVICE_STATUS_HANDLED_BY_LIBCEC
;
230 void CCECBusDevice::SetUnsupportedFeature(cec_opcode opcode
)
232 // some commands should never be marked as unsupported
233 if (opcode
== CEC_OPCODE_VENDOR_COMMAND
||
234 opcode
== CEC_OPCODE_VENDOR_COMMAND_WITH_ID
||
235 opcode
== CEC_OPCODE_VENDOR_REMOTE_BUTTON_DOWN
||
236 opcode
== CEC_OPCODE_VENDOR_REMOTE_BUTTON_UP
||
237 opcode
== CEC_OPCODE_ABORT
||
238 opcode
== CEC_OPCODE_FEATURE_ABORT
||
239 opcode
== CEC_OPCODE_NONE
||
240 opcode
== CEC_OPCODE_USER_CONTROL_PRESSED
||
241 opcode
== CEC_OPCODE_USER_CONTROL_RELEASE
)
245 CLockObject
lock(m_mutex
);
246 if (m_unsupportedFeatures
.find(opcode
) == m_unsupportedFeatures
.end())
248 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "marking opcode '%s' as unsupported feature for device '%s'", ToString(opcode
), GetLogicalAddressName());
249 m_unsupportedFeatures
.insert(opcode
);
253 // signal threads that are waiting for a reponse
255 SignalOpcode(cec_command::GetResponseOpcode(opcode
));
259 bool CCECBusDevice::IsUnsupportedFeature(cec_opcode opcode
)
261 CLockObject
lock(m_mutex
);
262 bool bUnsupported
= (m_unsupportedFeatures
.find(opcode
) != m_unsupportedFeatures
.end());
264 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "'%s' is marked as unsupported feature for device '%s'", ToString(opcode
), GetLogicalAddressName());
268 bool CCECBusDevice::TransmitKeypress(const cec_logical_address initiator
, cec_user_control_code key
, bool bWait
/* = true */)
271 bool bReturn
= m_handler
->TransmitKeypress(initiator
, m_iLogicalAddress
, key
, bWait
);
276 bool CCECBusDevice::TransmitKeyRelease(const cec_logical_address initiator
, bool bWait
/* = true */)
279 bool bReturn
= m_handler
->TransmitKeyRelease(initiator
, m_iLogicalAddress
, bWait
);
284 cec_version
CCECBusDevice::GetCecVersion(const cec_logical_address initiator
, bool bUpdate
/* = false */)
286 bool bIsPresent(GetStatus() == CEC_DEVICE_STATUS_PRESENT
);
287 bool bRequestUpdate(false);
289 CLockObject
lock(m_mutex
);
290 bRequestUpdate
= bIsPresent
&&
291 (bUpdate
|| m_cecVersion
== CEC_VERSION_UNKNOWN
);
296 CheckVendorIdRequested(initiator
);
297 RequestCecVersion(initiator
);
300 CLockObject
lock(m_mutex
);
304 void CCECBusDevice::SetCecVersion(const cec_version newVersion
)
306 CLockObject
lock(m_mutex
);
307 if (m_cecVersion
!= newVersion
)
308 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "%s (%X): CEC version %s", GetLogicalAddressName(), m_iLogicalAddress
, ToString(newVersion
));
309 m_cecVersion
= newVersion
;
312 bool CCECBusDevice::RequestCecVersion(const cec_logical_address initiator
, bool bWaitForResponse
/* = true */)
316 if (!IsHandledByLibCEC() &&
317 !IsUnsupportedFeature(CEC_OPCODE_GET_CEC_VERSION
))
320 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "<< requesting CEC version of '%s' (%X)", GetLogicalAddressName(), m_iLogicalAddress
);
321 bReturn
= m_handler
->TransmitRequestCecVersion(initiator
, m_iLogicalAddress
, bWaitForResponse
);
327 bool CCECBusDevice::TransmitCECVersion(const cec_logical_address destination
, bool bIsReply
)
331 CLockObject
lock(m_mutex
);
332 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "<< %s (%X) -> %s (%X): cec version %s", GetLogicalAddressName(), m_iLogicalAddress
, ToString(destination
), destination
, ToString(m_cecVersion
));
333 version
= m_cecVersion
;
337 bool bReturn
= m_handler
->TransmitCECVersion(m_iLogicalAddress
, destination
, version
, bIsReply
);
342 cec_menu_language
&CCECBusDevice::GetMenuLanguage(const cec_logical_address initiator
, bool bUpdate
/* = false */)
344 bool bIsPresent(GetStatus() == CEC_DEVICE_STATUS_PRESENT
);
345 bool bRequestUpdate(false);
347 CLockObject
lock(m_mutex
);
348 bRequestUpdate
= (bIsPresent
&&
349 (bUpdate
|| !strcmp(m_menuLanguage
.language
, "???")));
354 CheckVendorIdRequested(initiator
);
355 RequestMenuLanguage(initiator
);
358 CLockObject
lock(m_mutex
);
359 return m_menuLanguage
;
362 void CCECBusDevice::SetMenuLanguage(const char *strLanguage
)
367 CLockObject
lock(m_mutex
);
368 if (strcmp(strLanguage
, m_menuLanguage
.language
))
370 memcpy(m_menuLanguage
.language
, strLanguage
, 3);
371 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "%s (%X): menu language set to '%s'", GetLogicalAddressName(), m_iLogicalAddress
, m_menuLanguage
.language
);
375 void CCECBusDevice::SetMenuLanguage(const cec_menu_language
&language
)
377 if (language
.device
== m_iLogicalAddress
)
378 SetMenuLanguage(language
.language
);
381 bool CCECBusDevice::RequestMenuLanguage(const cec_logical_address initiator
, bool bWaitForResponse
/* = true */)
385 if (!IsHandledByLibCEC() &&
386 !IsUnsupportedFeature(CEC_OPCODE_GET_MENU_LANGUAGE
))
389 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "<< requesting menu language of '%s' (%X)", GetLogicalAddressName(), m_iLogicalAddress
);
390 bReturn
= m_handler
->TransmitRequestMenuLanguage(initiator
, m_iLogicalAddress
, bWaitForResponse
);
396 bool CCECBusDevice::TransmitSetMenuLanguage(const cec_logical_address destination
, bool bIsReply
)
399 cec_menu_language language
;
401 CLockObject
lock(m_mutex
);
402 language
= m_menuLanguage
;
407 CLockObject
lock(m_mutex
);
408 lang
[0] = language
.language
[0];
409 lang
[1] = language
.language
[1];
410 lang
[2] = language
.language
[2];
415 if (lang
[0] == '?' && lang
[1] == '?' && lang
[2] == '?')
417 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "<< %s (%X) -> %s (%X): menu language feature abort", GetLogicalAddressName(), m_iLogicalAddress
, ToString(destination
), destination
);
418 m_processor
->TransmitAbort(m_iLogicalAddress
, destination
, CEC_OPCODE_GIVE_DEVICE_VENDOR_ID
);
423 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "<< %s (%X) -> broadcast (F): menu language '%s'", GetLogicalAddressName(), m_iLogicalAddress
, lang
);
424 bReturn
= m_handler
->TransmitSetMenuLanguage(m_iLogicalAddress
, lang
, bIsReply
);
430 bool CCECBusDevice::TransmitOSDString(const cec_logical_address destination
, cec_display_control duration
, const char *strMessage
, bool bIsReply
)
433 if (!m_processor
->GetDevice(destination
)->IsUnsupportedFeature(CEC_OPCODE_SET_OSD_STRING
))
435 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "<< %s (%X) -> %s (%X): display OSD message '%s'", GetLogicalAddressName(), m_iLogicalAddress
, ToString(destination
), destination
, strMessage
);
437 bReturn
= m_handler
->TransmitOSDString(m_iLogicalAddress
, destination
, duration
, strMessage
, bIsReply
);
443 CStdString
CCECBusDevice::GetCurrentOSDName(void)
445 CLockObject
lock(m_mutex
);
446 return m_strDeviceName
;
449 CStdString
CCECBusDevice::GetOSDName(const cec_logical_address initiator
, bool bUpdate
/* = false */)
451 bool bIsPresent(GetStatus() == CEC_DEVICE_STATUS_PRESENT
);
452 bool bRequestUpdate(false);
454 CLockObject
lock(m_mutex
);
455 bRequestUpdate
= bIsPresent
&&
456 (bUpdate
|| m_strDeviceName
.Equals(ToString(m_iLogicalAddress
))) &&
457 m_type
!= CEC_DEVICE_TYPE_TV
;
462 CheckVendorIdRequested(initiator
);
463 RequestOSDName(initiator
);
466 CLockObject
lock(m_mutex
);
467 return m_strDeviceName
;
470 void CCECBusDevice::SetOSDName(CStdString strName
)
472 CLockObject
lock(m_mutex
);
473 if (m_strDeviceName
!= strName
)
475 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "%s (%X): osd name set to '%s'", GetLogicalAddressName(), m_iLogicalAddress
, strName
.c_str());
476 m_strDeviceName
= strName
;
480 bool CCECBusDevice::RequestOSDName(const cec_logical_address initiator
, bool bWaitForResponse
/* = true */)
484 if (!IsHandledByLibCEC() &&
485 !IsUnsupportedFeature(CEC_OPCODE_GIVE_OSD_NAME
))
488 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "<< requesting OSD name of '%s' (%X)", GetLogicalAddressName(), m_iLogicalAddress
);
489 bReturn
= m_handler
->TransmitRequestOSDName(initiator
, m_iLogicalAddress
, bWaitForResponse
);
495 bool CCECBusDevice::TransmitOSDName(const cec_logical_address destination
, bool bIsReply
)
497 CStdString strDeviceName
;
499 CLockObject
lock(m_mutex
);
500 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "<< %s (%X) -> %s (%X): OSD name '%s'", GetLogicalAddressName(), m_iLogicalAddress
, ToString(destination
), destination
, m_strDeviceName
.c_str());
501 strDeviceName
= m_strDeviceName
;
505 bool bReturn
= m_handler
->TransmitOSDName(m_iLogicalAddress
, destination
, strDeviceName
, bIsReply
);
510 bool CCECBusDevice::HasValidPhysicalAddress(void)
512 CLockObject
lock(m_mutex
);
513 return CLibCEC::IsValidPhysicalAddress(m_iPhysicalAddress
);
516 uint16_t CCECBusDevice::GetCurrentPhysicalAddress(void)
518 CLockObject
lock(m_mutex
);
519 return m_iPhysicalAddress
;
522 uint16_t CCECBusDevice::GetPhysicalAddress(const cec_logical_address initiator
, bool bSuppressUpdate
/* = false */)
524 if (!bSuppressUpdate
)
526 bool bIsPresent(GetStatus() == CEC_DEVICE_STATUS_PRESENT
);
527 bool bRequestUpdate(false);
529 CLockObject
lock(m_mutex
);
530 bRequestUpdate
= bIsPresent
&& m_iPhysicalAddress
== CEC_INVALID_PHYSICAL_ADDRESS
;
535 CheckVendorIdRequested(initiator
);
536 if (!RequestPhysicalAddress(initiator
))
537 LIB_CEC
->AddLog(CEC_LOG_ERROR
, "failed to request the physical address");
541 CLockObject
lock(m_mutex
);
542 return m_iPhysicalAddress
;
545 bool CCECBusDevice::SetPhysicalAddress(uint16_t iNewAddress
)
547 CLockObject
lock(m_mutex
);
548 if (iNewAddress
> 0 && m_iPhysicalAddress
!= iNewAddress
)
550 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "%s (%X): physical address changed from %04x to %04x", GetLogicalAddressName(), m_iLogicalAddress
, m_iPhysicalAddress
, iNewAddress
);
551 m_iPhysicalAddress
= iNewAddress
;
556 bool CCECBusDevice::RequestPhysicalAddress(const cec_logical_address initiator
, bool bWaitForResponse
/* = true */)
560 if (!IsHandledByLibCEC())
563 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "<< requesting physical address of '%s' (%X)", GetLogicalAddressName(), m_iLogicalAddress
);
564 bReturn
= m_handler
->TransmitRequestPhysicalAddress(initiator
, m_iLogicalAddress
, bWaitForResponse
);
570 bool CCECBusDevice::TransmitPhysicalAddress(bool bIsReply
)
572 uint16_t iPhysicalAddress
;
573 cec_device_type type
;
575 CLockObject
lock(m_mutex
);
576 if (m_iPhysicalAddress
== CEC_INVALID_PHYSICAL_ADDRESS
)
579 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "<< %s (%X) -> broadcast (F): physical adddress %4x", GetLogicalAddressName(), m_iLogicalAddress
, m_iPhysicalAddress
);
580 iPhysicalAddress
= m_iPhysicalAddress
;
585 bool bReturn
= m_handler
->TransmitPhysicalAddress(m_iLogicalAddress
, iPhysicalAddress
, type
, bIsReply
);
590 cec_power_status
CCECBusDevice::GetCurrentPowerStatus(void)
592 CLockObject
lock(m_mutex
);
593 return m_powerStatus
;
596 cec_power_status
CCECBusDevice::GetPowerStatus(const cec_logical_address initiator
, bool bUpdate
/* = false */)
598 bool bIsPresent(GetStatus() == CEC_DEVICE_STATUS_PRESENT
);
599 bool bRequestUpdate(false);
601 CLockObject
lock(m_mutex
);
602 bRequestUpdate
= (bIsPresent
&&
603 (bUpdate
|| m_powerStatus
== CEC_POWER_STATUS_UNKNOWN
||
604 m_powerStatus
== CEC_POWER_STATUS_IN_TRANSITION_STANDBY_TO_ON
||
605 m_powerStatus
== CEC_POWER_STATUS_IN_TRANSITION_ON_TO_STANDBY
||
606 GetTimeMs() - m_iLastPowerStateUpdate
>= CEC_POWER_STATE_REFRESH_TIME
));
611 CheckVendorIdRequested(initiator
);
612 RequestPowerStatus(initiator
);
615 CLockObject
lock(m_mutex
);
616 return m_powerStatus
;
619 void CCECBusDevice::SetPowerStatus(const cec_power_status powerStatus
)
621 CLockObject
lock(m_mutex
);
622 if (m_powerStatus
!= powerStatus
)
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(powerStatus
));
626 m_powerStatus
= powerStatus
;
630 void CCECBusDevice::OnImageViewOnSent(bool bSentByLibCEC
)
632 CLockObject
lock(m_mutex
);
633 m_bImageViewOnSent
= bSentByLibCEC
;
635 if (m_powerStatus
!= CEC_POWER_STATUS_ON
&& m_powerStatus
!= CEC_POWER_STATUS_IN_TRANSITION_STANDBY_TO_ON
)
637 m_iLastPowerStateUpdate
= GetTimeMs();
638 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
));
639 m_powerStatus
= CEC_POWER_STATUS_IN_TRANSITION_STANDBY_TO_ON
;
643 bool CCECBusDevice::ImageViewOnSent(void)
645 CLockObject
lock(m_mutex
);
646 return m_bImageViewOnSent
;
649 bool CCECBusDevice::RequestPowerStatus(const cec_logical_address initiator
, bool bWaitForResponse
/* = true */)
653 if (!IsHandledByLibCEC() &&
654 !IsUnsupportedFeature(CEC_OPCODE_GIVE_DEVICE_POWER_STATUS
))
657 bReturn
= m_handler
->TransmitRequestPowerStatus(initiator
, m_iLogicalAddress
, bWaitForResponse
);
659 SetPowerStatus(CEC_POWER_STATUS_UNKNOWN
);
665 bool CCECBusDevice::TransmitPowerState(const cec_logical_address destination
, bool bIsReply
)
667 cec_power_status state
;
669 CLockObject
lock(m_mutex
);
670 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "<< %s (%X) -> %s (%X): %s", GetLogicalAddressName(), m_iLogicalAddress
, ToString(destination
), destination
, ToString(m_powerStatus
));
671 state
= m_powerStatus
;
675 bool bReturn
= m_handler
->TransmitPowerState(m_iLogicalAddress
, destination
, state
, bIsReply
);
680 cec_vendor_id
CCECBusDevice::GetCurrentVendorId(void)
682 CLockObject
lock(m_mutex
);
686 cec_vendor_id
CCECBusDevice::GetVendorId(const cec_logical_address initiator
, bool bUpdate
/* = false */)
688 bool bIsPresent(GetStatus() == CEC_DEVICE_STATUS_PRESENT
);
689 bool bRequestUpdate(false);
691 CLockObject
lock(m_mutex
);
692 bRequestUpdate
= (bIsPresent
&&
693 (bUpdate
|| m_vendor
== CEC_VENDOR_UNKNOWN
));
697 RequestVendorId(initiator
);
699 CLockObject
lock(m_mutex
);
703 const char *CCECBusDevice::GetVendorName(const cec_logical_address initiator
, bool bUpdate
/* = false */)
705 return ToString(GetVendorId(initiator
, bUpdate
));
708 bool CCECBusDevice::SetVendorId(uint64_t iVendorId
)
710 bool bVendorChanged(false);
713 CLockObject
lock(m_mutex
);
714 bVendorChanged
= (m_vendor
!= (cec_vendor_id
)iVendorId
);
715 m_vendor
= (cec_vendor_id
)iVendorId
;
719 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "%s (%X): vendor = %s (%06x)", GetLogicalAddressName(), m_iLogicalAddress
, ToString(m_vendor
), m_vendor
);
721 return bVendorChanged
;
724 bool CCECBusDevice::RequestVendorId(const cec_logical_address initiator
, bool bWaitForResponse
/* = true */)
728 if (!IsHandledByLibCEC() && initiator
!= CECDEVICE_UNKNOWN
)
731 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "<< requesting vendor ID of '%s' (%X)", GetLogicalAddressName(), m_iLogicalAddress
);
732 bReturn
= m_handler
->TransmitRequestVendorId(initiator
, m_iLogicalAddress
, bWaitForResponse
);
735 if (bWaitForResponse
)
736 ReplaceHandler(true);
741 bool CCECBusDevice::TransmitVendorID(const cec_logical_address destination
, bool bSendAbort
, bool bIsReply
)
746 CLockObject
lock(m_mutex
);
747 iVendorId
= (uint64_t)m_vendor
;
751 if (iVendorId
== CEC_VENDOR_UNKNOWN
)
755 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "<< %s (%X) -> %s (%X): vendor id feature abort", GetLogicalAddressName(), m_iLogicalAddress
, ToString(destination
), destination
);
756 m_processor
->TransmitAbort(m_iLogicalAddress
, destination
, CEC_OPCODE_GIVE_DEVICE_VENDOR_ID
);
762 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
);
763 bReturn
= m_handler
->TransmitVendorID(m_iLogicalAddress
, destination
, iVendorId
, bIsReply
);
769 cec_bus_device_status
CCECBusDevice::GetStatus(bool bForcePoll
/* = false */, bool bSuppressPoll
/* = false */)
771 if (m_iLogicalAddress
== CECDEVICE_BROADCAST
)
772 return CEC_DEVICE_STATUS_NOT_PRESENT
;
774 cec_bus_device_status
status(CEC_DEVICE_STATUS_UNKNOWN
);
775 bool bNeedsPoll(false);
778 CLockObject
lock(m_mutex
);
779 status
= m_deviceStatus
;
780 bNeedsPoll
= !bSuppressPoll
&&
781 m_deviceStatus
!= CEC_DEVICE_STATUS_HANDLED_BY_LIBCEC
&&
784 // don't know the status
785 m_deviceStatus
== CEC_DEVICE_STATUS_UNKNOWN
||
786 // always poll the TV if it's marked as not present
787 (m_deviceStatus
== CEC_DEVICE_STATUS_NOT_PRESENT
&& m_iLogicalAddress
== CECDEVICE_TV
));
792 bool bPollAcked(false);
794 bPollAcked
= m_processor
->PollDevice(m_iLogicalAddress
);
796 status
= bPollAcked
? CEC_DEVICE_STATUS_PRESENT
: CEC_DEVICE_STATUS_NOT_PRESENT
;
797 SetDeviceStatus(status
);
803 void CCECBusDevice::SetDeviceStatus(const cec_bus_device_status newStatus
, cec_version libCECSpecVersion
/* = CEC_VERSION_1_4 */)
805 if (m_iLogicalAddress
== CECDEVICE_UNREGISTERED
)
809 CLockObject
lock(m_mutex
);
812 case CEC_DEVICE_STATUS_HANDLED_BY_LIBCEC
:
813 if (m_deviceStatus
!= newStatus
)
814 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "%s (%X): device status changed into 'handled by libCEC'", GetLogicalAddressName(), m_iLogicalAddress
);
815 SetPowerStatus (CEC_POWER_STATUS_ON
);
816 SetVendorId (CEC_VENDOR_UNKNOWN
);
817 SetMenuState (CEC_MENU_STATE_ACTIVATED
);
818 SetCecVersion (libCECSpecVersion
);
819 SetStreamPath (CEC_INVALID_PHYSICAL_ADDRESS
);
820 MarkAsInactiveSource();
822 m_deviceStatus
= newStatus
;
824 case CEC_DEVICE_STATUS_PRESENT
:
825 if (m_deviceStatus
!= newStatus
)
826 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "%s (%X): device status changed into 'present'", GetLogicalAddressName(), m_iLogicalAddress
);
827 m_deviceStatus
= newStatus
;
828 m_iLastActive
= GetTimeMs();
830 case CEC_DEVICE_STATUS_NOT_PRESENT
:
831 if (m_deviceStatus
!= newStatus
)
833 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "%s (%X): device status changed into 'not present'", GetLogicalAddressName(), m_iLogicalAddress
);
834 ResetDeviceStatus(true);
835 m_deviceStatus
= newStatus
;
845 void CCECBusDevice::ResetDeviceStatus(bool bClientUnregistered
/* = false */)
847 CLockObject
lock(m_mutex
);
848 SetPowerStatus (CEC_POWER_STATUS_UNKNOWN
);
849 SetVendorId (CEC_VENDOR_UNKNOWN
);
850 SetMenuState (CEC_MENU_STATE_ACTIVATED
);
851 SetCecVersion (CEC_VERSION_UNKNOWN
);
852 SetStreamPath (CEC_INVALID_PHYSICAL_ADDRESS
);
853 SetOSDName (ToString(m_iLogicalAddress
));
854 MarkAsInactiveSource(bClientUnregistered
);
857 m_bVendorIdRequested
= false;
858 m_unsupportedFeatures
.clear();
859 m_waitForResponse
->Clear();
861 if (m_deviceStatus
!= CEC_DEVICE_STATUS_UNKNOWN
)
862 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "%s (%X): device status changed into 'unknown'", GetLogicalAddressName(), m_iLogicalAddress
);
863 m_deviceStatus
= CEC_DEVICE_STATUS_UNKNOWN
;
866 bool CCECBusDevice::TransmitPoll(const cec_logical_address dest
, bool bUpdateDeviceStatus
)
869 cec_logical_address
destination(dest
);
870 if (destination
== CECDEVICE_UNKNOWN
)
871 destination
= m_iLogicalAddress
;
873 CCECBusDevice
*destDevice
= m_processor
->GetDevice(destination
);
874 if (destDevice
->m_deviceStatus
== CEC_DEVICE_STATUS_HANDLED_BY_LIBCEC
)
878 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "<< %s (%X) -> %s (%X): POLL", GetLogicalAddressName(), m_iLogicalAddress
, ToString(dest
), dest
);
879 bReturn
= m_handler
->TransmitPoll(m_iLogicalAddress
, destination
, false);
880 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, bReturn
? ">> POLL sent" : ">> POLL not sent");
882 if (bUpdateDeviceStatus
)
883 destDevice
->SetDeviceStatus(bReturn
? CEC_DEVICE_STATUS_PRESENT
: CEC_DEVICE_STATUS_NOT_PRESENT
);
889 void CCECBusDevice::HandlePoll(const cec_logical_address destination
)
891 if (destination
>= 0 && destination
< CECDEVICE_BROADCAST
)
893 CCECBusDevice
*device
= m_processor
->GetDevice(destination
);
895 device
->HandlePollFrom(m_iLogicalAddress
);
899 void CCECBusDevice::HandlePollFrom(const cec_logical_address initiator
)
901 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "<< POLL: %s (%x) -> %s (%x)", ToString(initiator
), initiator
, ToString(m_iLogicalAddress
), m_iLogicalAddress
);
902 m_bAwaitingReceiveFailed
= true;
905 bool CCECBusDevice::HandleReceiveFailed(void)
907 bool bReturn
= m_bAwaitingReceiveFailed
;
908 m_bAwaitingReceiveFailed
= false;
912 cec_menu_state
CCECBusDevice::GetMenuState(const cec_logical_address
UNUSED(initiator
))
914 CLockObject
lock(m_mutex
);
918 void CCECBusDevice::SetMenuState(const cec_menu_state state
)
920 CLockObject
lock(m_mutex
);
921 if (m_menuState
!= state
)
923 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "%s (%X): menu state set to '%s'", GetLogicalAddressName(), m_iLogicalAddress
, ToString(m_menuState
));
928 bool CCECBusDevice::TransmitMenuState(const cec_logical_address dest
, bool bIsReply
)
930 cec_menu_state menuState
;
932 CLockObject
lock(m_mutex
);
933 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "<< %s (%X) -> %s (%X): menu state '%s'", GetLogicalAddressName(), m_iLogicalAddress
, ToString(dest
), dest
, ToString(m_menuState
));
934 menuState
= m_menuState
;
938 bool bReturn
= m_handler
->TransmitMenuState(m_iLogicalAddress
, dest
, menuState
, bIsReply
);
943 bool CCECBusDevice::ActivateSource(uint64_t iDelay
/* = 0 */)
945 MarkAsActiveSource();
950 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "sending active source message for '%s'", ToString(m_iLogicalAddress
));
951 bReturn
= m_handler
->ActivateSource();
955 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "scheduling active source message for '%s'", ToString(m_iLogicalAddress
));
956 m_handler
->ScheduleActivateSource(iDelay
);
962 bool CCECBusDevice::RequestActiveSource(bool bWaitForResponse
/* = true */)
966 if (IsHandledByLibCEC())
969 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "<< requesting active source");
971 bReturn
= m_handler
->TransmitRequestActiveSource(m_iLogicalAddress
, bWaitForResponse
);
977 void CCECBusDevice::MarkAsActiveSource(void)
979 bool bWasActivated(false);
981 // set the power status to powered on
982 SetPowerStatus(CEC_POWER_STATUS_ON
);
984 // mark this device as active source
986 CLockObject
lock(m_mutex
);
987 if (!m_bActiveSource
)
989 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "making %s (%x) the active source", GetLogicalAddressName(), m_iLogicalAddress
);
990 bWasActivated
= true;
993 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "%s (%x) was already marked as active source", GetLogicalAddressName(), m_iLogicalAddress
);
995 m_bActiveSource
= true;
998 CCECBusDevice
* tv
= m_processor
->GetDevice(CECDEVICE_TV
);
1000 tv
->OnImageViewOnSent(false);
1002 // mark other devices as inactive sources
1003 CECDEVICEVEC devices
;
1004 m_processor
->GetDevices()->Get(devices
);
1005 for (CECDEVICEVEC::iterator it
= devices
.begin(); it
!= devices
.end(); it
++)
1006 if ((*it
)->GetLogicalAddress() != m_iLogicalAddress
)
1007 (*it
)->MarkAsInactiveSource();
1011 if (IsHandledByLibCEC())
1012 m_processor
->SetActiveSource(true, false);
1013 CCECClient
*client
= GetClient();
1015 client
->SourceActivated(m_iLogicalAddress
);
1019 void CCECBusDevice::MarkAsInactiveSource(bool bClientUnregistered
/* = false */)
1021 bool bWasDeactivated(false);
1023 CLockObject
lock(m_mutex
);
1024 if (m_bActiveSource
)
1026 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "marking %s (%X) as inactive source", GetLogicalAddressName(), m_iLogicalAddress
);
1027 bWasDeactivated
= true;
1029 m_bActiveSource
= false;
1032 if (bWasDeactivated
)
1034 if (IsHandledByLibCEC())
1035 m_processor
->SetActiveSource(false, bClientUnregistered
);
1036 CCECClient
*client
= GetClient();
1038 client
->SourceDeactivated(m_iLogicalAddress
);
1042 bool CCECBusDevice::TransmitActiveSource(bool bIsReply
)
1044 bool bSendActiveSource(false);
1045 uint16_t iPhysicalAddress(CEC_INVALID_PHYSICAL_ADDRESS
);
1048 CLockObject
lock(m_mutex
);
1049 if (!HasValidPhysicalAddress())
1051 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "%s (%X) has an invalid physical address (%04x), not sending active source commands", GetLogicalAddressName(), m_iLogicalAddress
, m_iPhysicalAddress
);
1055 iPhysicalAddress
= m_iPhysicalAddress
;
1057 if (m_powerStatus
!= CEC_POWER_STATUS_ON
&& m_powerStatus
!= CEC_POWER_STATUS_IN_TRANSITION_STANDBY_TO_ON
)
1058 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "<< %s (%X) is not powered on", GetLogicalAddressName(), m_iLogicalAddress
);
1059 else if (m_bActiveSource
)
1061 LIB_CEC
->AddLog(CEC_LOG_NOTICE
, "<< %s (%X) -> broadcast (F): active source (%4x)", GetLogicalAddressName(), m_iLogicalAddress
, m_iPhysicalAddress
);
1062 bSendActiveSource
= true;
1065 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "<< %s (%X) is not the active source", GetLogicalAddressName(), m_iLogicalAddress
);
1068 bool bActiveSourceSent(false);
1069 if (bSendActiveSource
)
1072 bActiveSourceSent
= m_handler
->TransmitActiveSource(m_iLogicalAddress
, iPhysicalAddress
, bIsReply
);
1076 return bActiveSourceSent
;
1079 bool CCECBusDevice::TransmitImageViewOn(void)
1082 CLockObject
lock(m_mutex
);
1083 if (m_powerStatus
!= CEC_POWER_STATUS_ON
&& m_powerStatus
!= CEC_POWER_STATUS_IN_TRANSITION_STANDBY_TO_ON
)
1085 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "<< %s (%X) is not powered on", GetLogicalAddressName(), m_iLogicalAddress
);
1090 CCECBusDevice
* tv
= m_processor
->GetDevice(CECDEVICE_TV
);
1093 LIB_CEC
->AddLog(CEC_LOG_ERROR
, "%s - couldn't get TV instance", __FUNCTION__
);
1097 if (tv
->ImageViewOnSent())
1099 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "%s - 'image view on' already sent", __FUNCTION__
);
1103 bool bImageViewOnSent(false);
1105 bImageViewOnSent
= m_handler
->TransmitImageViewOn(m_iLogicalAddress
, CECDEVICE_TV
);
1108 if (bImageViewOnSent
)
1109 tv
->OnImageViewOnSent(true);
1111 return bImageViewOnSent
;
1114 bool CCECBusDevice::TransmitInactiveSource(void)
1116 uint16_t iPhysicalAddress
;
1118 CLockObject
lock(m_mutex
);
1119 LIB_CEC
->AddLog(CEC_LOG_NOTICE
, "<< %s (%X) -> broadcast (F): inactive source", GetLogicalAddressName(), m_iLogicalAddress
);
1120 iPhysicalAddress
= m_iPhysicalAddress
;
1124 bool bReturn
= m_handler
->TransmitInactiveSource(m_iLogicalAddress
, iPhysicalAddress
);
1129 bool CCECBusDevice::TransmitPendingActiveSourceCommands(void)
1132 bool bReturn
= m_handler
->ActivateSource(true);
1137 void CCECBusDevice::SetActiveRoute(uint16_t iRoute
)
1139 SetPowerStatus(CEC_POWER_STATUS_ON
);
1141 CCECDeviceMap
* map
= m_processor
->GetDevices();
1145 CCECBusDevice
* newRoute
= m_processor
->GetDeviceByPhysicalAddress(iRoute
, true);
1148 // we were made the active source, send notification
1149 if (newRoute
->IsHandledByLibCEC())
1150 newRoute
->ActivateSource();
1151 // another device was made active
1153 newRoute
->MarkAsActiveSource();
1157 void CCECBusDevice::SetStreamPath(uint16_t iNewAddress
, uint16_t iOldAddress
/* = CEC_INVALID_PHYSICAL_ADDRESS */)
1159 if (iNewAddress
!= CEC_INVALID_PHYSICAL_ADDRESS
)
1160 SetPowerStatus(CEC_POWER_STATUS_ON
);
1162 CLockObject
lock(m_mutex
);
1163 if (iNewAddress
!= m_iStreamPath
)
1165 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "%s (%X): stream path changed from %04x to %04x", GetLogicalAddressName(), m_iLogicalAddress
, iOldAddress
== 0 ? m_iStreamPath
: iOldAddress
, iNewAddress
);
1166 m_iStreamPath
= iNewAddress
;
1169 if (!LIB_CEC
->IsValidPhysicalAddress(iNewAddress
))
1172 CCECBusDevice
*device
= m_processor
->GetDeviceByPhysicalAddress(iNewAddress
);
1175 // if a device is found with the new physical address, mark it as active, which will automatically mark all other devices as inactive
1176 device
->MarkAsActiveSource();
1178 // respond with an active source message if this device is handled by libCEC
1179 if (device
->IsHandledByLibCEC())
1180 device
->TransmitActiveSource(true);
1184 // try to find the device with the old address, and mark it as inactive when found
1185 device
= m_processor
->GetDeviceByPhysicalAddress(iOldAddress
);
1187 device
->MarkAsInactiveSource();
1191 bool CCECBusDevice::PowerOn(const cec_logical_address initiator
)
1193 bool bReturn(false);
1194 GetVendorId(initiator
); // ensure that we got the vendor id, because the implementations vary per vendor
1197 cec_power_status currentStatus
;
1198 if (m_iLogicalAddress
== CECDEVICE_TV
||
1199 ((currentStatus
= GetPowerStatus(initiator
, false)) != CEC_POWER_STATUS_IN_TRANSITION_STANDBY_TO_ON
&&
1200 currentStatus
!= CEC_POWER_STATUS_ON
))
1202 LIB_CEC
->AddLog(CEC_LOG_NOTICE
, "<< powering on '%s' (%X)", GetLogicalAddressName(), m_iLogicalAddress
);
1203 bReturn
= m_handler
->PowerOn(initiator
, m_iLogicalAddress
);
1207 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "'%s' (%X) is already '%s'", GetLogicalAddressName(), m_iLogicalAddress
, ToString(currentStatus
));
1214 bool CCECBusDevice::Standby(const cec_logical_address initiator
)
1216 GetVendorId(initiator
); // ensure that we got the vendor id, because the implementations vary per vendor
1218 LIB_CEC
->AddLog(CEC_LOG_NOTICE
, "<< putting '%s' (%X) in standby mode", GetLogicalAddressName(), m_iLogicalAddress
);
1220 bool bReturn
= m_handler
->TransmitStandby(initiator
, m_iLogicalAddress
);
1225 bool CCECBusDevice::NeedsPoll(void)
1227 bool bSendPoll(false);
1228 cec_logical_address
pollAddress(CECDEVICE_UNKNOWN
);
1229 switch (m_iLogicalAddress
)
1231 case CECDEVICE_PLAYBACKDEVICE3
:
1232 pollAddress
= CECDEVICE_PLAYBACKDEVICE2
;
1234 case CECDEVICE_PLAYBACKDEVICE2
:
1235 pollAddress
= CECDEVICE_PLAYBACKDEVICE1
;
1237 case CECDEVICE_RECORDINGDEVICE3
:
1238 pollAddress
= CECDEVICE_RECORDINGDEVICE2
;
1240 case CECDEVICE_RECORDINGDEVICE2
:
1241 pollAddress
= CECDEVICE_RECORDINGDEVICE1
;
1243 case CECDEVICE_TUNER4
:
1244 pollAddress
= CECDEVICE_TUNER3
;
1246 case CECDEVICE_TUNER3
:
1247 pollAddress
= CECDEVICE_TUNER2
;
1249 case CECDEVICE_TUNER2
:
1250 pollAddress
= CECDEVICE_TUNER1
;
1252 case CECDEVICE_AUDIOSYSTEM
:
1253 case CECDEVICE_PLAYBACKDEVICE1
:
1254 case CECDEVICE_RECORDINGDEVICE1
:
1255 case CECDEVICE_TUNER1
:
1263 if (!bSendPoll
&& pollAddress
!= CECDEVICE_UNKNOWN
)
1265 CCECBusDevice
*device
= m_processor
->GetDevice(pollAddress
);
1268 cec_bus_device_status status
= device
->GetStatus();
1269 bSendPoll
= (status
== CEC_DEVICE_STATUS_PRESENT
|| status
== CEC_DEVICE_STATUS_HANDLED_BY_LIBCEC
);
1280 void CCECBusDevice::CheckVendorIdRequested(const cec_logical_address initiator
)
1282 bool bRequestVendorId(false);
1284 CLockObject
lock(m_mutex
);
1285 bRequestVendorId
= !m_bVendorIdRequested
;
1286 m_bVendorIdRequested
= true;
1289 if (bRequestVendorId
)
1291 ReplaceHandler(false);
1292 GetVendorId(initiator
);
1297 CCECAudioSystem
*CCECBusDevice::AsAudioSystem(void)
1299 return AsAudioSystem(this);
1302 CCECPlaybackDevice
*CCECBusDevice::AsPlaybackDevice(void)
1304 return AsPlaybackDevice(this);
1307 CCECRecordingDevice
*CCECBusDevice::AsRecordingDevice(void)
1309 return AsRecordingDevice(this);
1312 CCECTuner
*CCECBusDevice::AsTuner(void)
1314 return AsTuner(this);
1317 CCECTV
*CCECBusDevice::AsTV(void)
1322 CCECAudioSystem
*CCECBusDevice::AsAudioSystem(CCECBusDevice
*device
)
1324 if (device
&& device
->GetType() == CEC_DEVICE_TYPE_AUDIO_SYSTEM
)
1325 return static_cast<CCECAudioSystem
*>(device
);
1329 CCECPlaybackDevice
*CCECBusDevice::AsPlaybackDevice(CCECBusDevice
*device
)
1332 (device
->GetType() == CEC_DEVICE_TYPE_PLAYBACK_DEVICE
||
1333 device
->GetType() == CEC_DEVICE_TYPE_RECORDING_DEVICE
))
1334 return static_cast<CCECPlaybackDevice
*>(device
);
1338 CCECRecordingDevice
*CCECBusDevice::AsRecordingDevice(CCECBusDevice
*device
)
1340 if (device
&& device
->GetType() == CEC_DEVICE_TYPE_RECORDING_DEVICE
)
1341 return static_cast<CCECRecordingDevice
*>(device
);
1345 CCECTuner
*CCECBusDevice::AsTuner(CCECBusDevice
*device
)
1347 if (device
&& device
->GetType() == CEC_DEVICE_TYPE_TUNER
)
1348 return static_cast<CCECTuner
*>(device
);
1352 CCECTV
*CCECBusDevice::AsTV(CCECBusDevice
*device
)
1354 if (device
&& device
->GetType() == CEC_DEVICE_TYPE_TV
)
1355 return static_cast<CCECTV
*>(device
);
1359 void CCECBusDevice::MarkBusy(void)
1361 CLockObject
handlerLock(m_handlerMutex
);
1362 ++m_iHandlerUseCount
;
1365 void CCECBusDevice::MarkReady(void)
1367 CLockObject
handlerLock(m_handlerMutex
);
1368 if (m_iHandlerUseCount
> 0)
1369 --m_iHandlerUseCount
;
1372 bool CCECBusDevice::TryLogicalAddress(cec_version libCECSpecVersion
/* = CEC_VERSION_1_4 */)
1374 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "trying logical address '%s'", GetLogicalAddressName());
1376 if (!TransmitPoll(m_iLogicalAddress
, false))
1378 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "using logical address '%s'", GetLogicalAddressName());
1379 SetDeviceStatus(CEC_DEVICE_STATUS_HANDLED_BY_LIBCEC
, libCECSpecVersion
);
1384 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "logical address '%s' already taken", GetLogicalAddressName());
1385 SetDeviceStatus(CEC_DEVICE_STATUS_PRESENT
);
1389 CCECClient
*CCECBusDevice::GetClient(void)
1391 return m_processor
->GetClient(m_iLogicalAddress
);
1394 void CCECBusDevice::SignalOpcode(cec_opcode opcode
)
1396 m_waitForResponse
->Received(opcode
);
1399 bool CCECBusDevice::WaitForOpcode(cec_opcode opcode
)
1401 return m_waitForResponse
->Wait(opcode
);