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/implementations/PHCommandHandler.h"
43 #include "lib/LibCEC.h"
44 #include "lib/CECTypeUtils.h"
45 #include "lib/platform/util/timeutils.h"
46 #include "lib/platform/util/util.h"
48 #include "CECAudioSystem.h"
49 #include "CECPlaybackDevice.h"
50 #include "CECRecordingDevice.h"
56 using namespace PLATFORM
;
58 #define LIB_CEC m_processor->GetLib()
59 #define ToString(p) CCECTypeUtils::ToString(p)
61 CCECBusDevice::CCECBusDevice(CCECProcessor
*processor
, cec_logical_address iLogicalAddress
, uint16_t iPhysicalAddress
/* = CEC_INVALID_PHYSICAL_ADDRESS */) :
62 m_type (CEC_DEVICE_TYPE_RESERVED
),
63 m_iPhysicalAddress (iPhysicalAddress
),
64 m_iStreamPath (CEC_INVALID_PHYSICAL_ADDRESS
),
65 m_iLogicalAddress (iLogicalAddress
),
66 m_powerStatus (CEC_POWER_STATUS_UNKNOWN
),
67 m_processor (processor
),
68 m_vendor (CEC_VENDOR_UNKNOWN
),
69 m_bReplaceHandler (false),
70 m_menuState (CEC_MENU_STATE_ACTIVATED
),
71 m_bActiveSource (false),
73 m_iLastPowerStateUpdate (0),
74 m_cecVersion (CEC_VERSION_UNKNOWN
),
75 m_deviceStatus (CEC_DEVICE_STATUS_UNKNOWN
),
76 m_iHandlerUseCount (0),
77 m_bAwaitingReceiveFailed(false),
78 m_bVendorIdRequested (false),
79 m_waitForResponse (new CWaitForResponse
),
80 m_bImageViewOnSent (false)
82 m_handler
= new CCECCommandHandler(this);
84 for (unsigned int iPtr
= 0; iPtr
< 4; iPtr
++)
85 m_menuLanguage
.language
[iPtr
] = '?';
86 m_menuLanguage
.language
[3] = 0;
87 m_menuLanguage
.device
= iLogicalAddress
;
89 m_strDeviceName
= ToString(m_iLogicalAddress
);
92 CCECBusDevice::~CCECBusDevice(void)
94 DELETE_AND_NULL(m_handler
);
95 DELETE_AND_NULL(m_waitForResponse
);
98 bool CCECBusDevice::ReplaceHandler(bool bActivateSource
/* = true */)
100 if (m_iLogicalAddress
== CECDEVICE_BROADCAST
)
103 bool bInitHandler(false);
105 CLockObject
lock(m_mutex
);
106 CLockObject
handlerLock(m_handlerMutex
);
107 if (m_iHandlerUseCount
> 0)
112 if (m_vendor
!= m_handler
->GetVendorId())
114 if (CCECCommandHandler::HasSpecificHandler(m_vendor
))
116 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "replacing the command handler for device '%s' (%x)", GetLogicalAddressName(), GetLogicalAddress());
118 int32_t iTransmitTimeout
= m_handler
->m_iTransmitTimeout
;
119 int32_t iTransmitWait
= m_handler
->m_iTransmitWait
;
120 int8_t iTransmitRetries
= m_handler
->m_iTransmitRetries
;
121 int64_t iActiveSourcePending
= m_handler
->m_iActiveSourcePending
;
123 DELETE_AND_NULL(m_handler
);
127 case CEC_VENDOR_SAMSUNG
:
128 m_handler
= new CANCommandHandler(this, iTransmitTimeout
, iTransmitWait
, iTransmitRetries
, iActiveSourcePending
);
131 m_handler
= new CSLCommandHandler(this, iTransmitTimeout
, iTransmitWait
, iTransmitRetries
, iActiveSourcePending
);
133 case CEC_VENDOR_PANASONIC
:
134 m_handler
= new CVLCommandHandler(this, iTransmitTimeout
, iTransmitWait
, iTransmitRetries
, iActiveSourcePending
);
136 case CEC_VENDOR_PHILIPS
:
137 m_handler
= new CPHCommandHandler(this, iTransmitTimeout
, iTransmitWait
, iTransmitRetries
, iActiveSourcePending
);
140 m_handler
= new CCECCommandHandler(this, iTransmitTimeout
, iTransmitWait
, iTransmitRetries
, iActiveSourcePending
);
144 m_handler
->SetVendorId(m_vendor
);
152 CCECBusDevice
*primary
= GetProcessor()->GetPrimaryDevice();
153 if (primary
->GetLogicalAddress() != CECDEVICE_UNREGISTERED
)
155 m_handler
->InitHandler();
157 if (bActivateSource
&& IsHandledByLibCEC() && IsActiveSource())
158 m_handler
->ActivateSource();
167 CCECCommandHandler
*CCECBusDevice::GetHandler(void)
169 ReplaceHandler(false);
174 bool CCECBusDevice::HandleCommand(const cec_command
&command
)
176 bool bHandled(false);
178 /* update "last active" */
180 CLockObject
lock(m_mutex
);
181 m_iLastActive
= GetTimeMs();
185 /* handle the command */
186 bHandled
= m_handler
->HandleCommand(command
);
188 /* change status to present */
189 if (bHandled
&& GetLogicalAddress() != CECDEVICE_BROADCAST
)
191 CLockObject
lock(m_mutex
);
192 if (m_deviceStatus
!= CEC_DEVICE_STATUS_HANDLED_BY_LIBCEC
)
194 if (m_deviceStatus
!= CEC_DEVICE_STATUS_PRESENT
)
195 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "device %s (%x) status changed to present after command %s", GetLogicalAddressName(), (uint8_t)GetLogicalAddress(), ToString(command
.opcode
));
196 m_deviceStatus
= CEC_DEVICE_STATUS_PRESENT
;
204 const char* CCECBusDevice::GetLogicalAddressName(void) const
206 return ToString(m_iLogicalAddress
);
209 bool CCECBusDevice::IsPresent(void)
211 CLockObject
lock(m_mutex
);
212 return m_deviceStatus
== CEC_DEVICE_STATUS_PRESENT
;
215 bool CCECBusDevice::IsHandledByLibCEC(void)
217 CLockObject
lock(m_mutex
);
218 return m_deviceStatus
== CEC_DEVICE_STATUS_HANDLED_BY_LIBCEC
;
221 void CCECBusDevice::SetUnsupportedFeature(cec_opcode opcode
)
223 // some commands should never be marked as unsupported
224 if (opcode
== CEC_OPCODE_VENDOR_COMMAND
||
225 opcode
== CEC_OPCODE_VENDOR_COMMAND_WITH_ID
||
226 opcode
== CEC_OPCODE_VENDOR_REMOTE_BUTTON_DOWN
||
227 opcode
== CEC_OPCODE_VENDOR_REMOTE_BUTTON_UP
||
228 opcode
== CEC_OPCODE_ABORT
||
229 opcode
== CEC_OPCODE_FEATURE_ABORT
||
230 opcode
== CEC_OPCODE_NONE
)
234 CLockObject
lock(m_mutex
);
235 if (m_unsupportedFeatures
.find(opcode
) == m_unsupportedFeatures
.end())
237 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "marking opcode '%s' as unsupported feature for device '%s'", ToString(opcode
), GetLogicalAddressName());
238 m_unsupportedFeatures
.insert(opcode
);
242 // signal threads that are waiting for a reponse
244 SignalOpcode(cec_command::GetResponseOpcode(opcode
));
248 bool CCECBusDevice::IsUnsupportedFeature(cec_opcode opcode
)
250 CLockObject
lock(m_mutex
);
251 bool bUnsupported
= (m_unsupportedFeatures
.find(opcode
) != m_unsupportedFeatures
.end());
253 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "'%s' is marked as unsupported feature for device '%s'", ToString(opcode
), GetLogicalAddressName());
257 bool CCECBusDevice::TransmitKeypress(const cec_logical_address initiator
, cec_user_control_code key
, bool bWait
/* = true */)
260 bool bReturn
= m_handler
->TransmitKeypress(initiator
, m_iLogicalAddress
, key
, bWait
);
265 bool CCECBusDevice::TransmitKeyRelease(const cec_logical_address initiator
, bool bWait
/* = true */)
268 bool bReturn
= m_handler
->TransmitKeyRelease(initiator
, m_iLogicalAddress
, bWait
);
273 cec_version
CCECBusDevice::GetCecVersion(const cec_logical_address initiator
, bool bUpdate
/* = false */)
275 bool bIsPresent(GetStatus() == CEC_DEVICE_STATUS_PRESENT
);
276 bool bRequestUpdate(false);
278 CLockObject
lock(m_mutex
);
279 bRequestUpdate
= bIsPresent
&&
280 (bUpdate
|| m_cecVersion
== CEC_VERSION_UNKNOWN
);
285 CheckVendorIdRequested(initiator
);
286 RequestCecVersion(initiator
);
289 CLockObject
lock(m_mutex
);
293 void CCECBusDevice::SetCecVersion(const cec_version newVersion
)
295 CLockObject
lock(m_mutex
);
296 if (m_cecVersion
!= newVersion
)
297 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "%s (%X): CEC version %s", GetLogicalAddressName(), m_iLogicalAddress
, ToString(newVersion
));
298 m_cecVersion
= newVersion
;
301 bool CCECBusDevice::RequestCecVersion(const cec_logical_address initiator
, bool bWaitForResponse
/* = true */)
305 if (!IsHandledByLibCEC() &&
306 !IsUnsupportedFeature(CEC_OPCODE_GET_CEC_VERSION
))
309 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "<< requesting CEC version of '%s' (%X)", GetLogicalAddressName(), m_iLogicalAddress
);
310 bReturn
= m_handler
->TransmitRequestCecVersion(initiator
, m_iLogicalAddress
, bWaitForResponse
);
316 bool CCECBusDevice::TransmitCECVersion(const cec_logical_address destination
, bool bIsReply
)
320 CLockObject
lock(m_mutex
);
321 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "<< %s (%X) -> %s (%X): cec version %s", GetLogicalAddressName(), m_iLogicalAddress
, ToString(destination
), destination
, ToString(m_cecVersion
));
322 version
= m_cecVersion
;
326 bool bReturn
= m_handler
->TransmitCECVersion(m_iLogicalAddress
, destination
, version
, bIsReply
);
331 cec_menu_language
&CCECBusDevice::GetMenuLanguage(const cec_logical_address initiator
, bool bUpdate
/* = false */)
333 bool bIsPresent(GetStatus() == CEC_DEVICE_STATUS_PRESENT
);
334 bool bRequestUpdate(false);
336 CLockObject
lock(m_mutex
);
337 bRequestUpdate
= (bIsPresent
&&
338 (bUpdate
|| !strcmp(m_menuLanguage
.language
, "???")));
343 CheckVendorIdRequested(initiator
);
344 RequestMenuLanguage(initiator
);
347 CLockObject
lock(m_mutex
);
348 return m_menuLanguage
;
351 void CCECBusDevice::SetMenuLanguage(const char *strLanguage
)
356 CLockObject
lock(m_mutex
);
357 if (strcmp(strLanguage
, m_menuLanguage
.language
))
359 memcpy(m_menuLanguage
.language
, strLanguage
, 3);
360 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "%s (%X): menu language set to '%s'", GetLogicalAddressName(), m_iLogicalAddress
, m_menuLanguage
.language
);
364 void CCECBusDevice::SetMenuLanguage(const cec_menu_language
&language
)
366 if (language
.device
== m_iLogicalAddress
)
367 SetMenuLanguage(language
.language
);
370 bool CCECBusDevice::RequestMenuLanguage(const cec_logical_address initiator
, bool bWaitForResponse
/* = true */)
374 if (!IsHandledByLibCEC() &&
375 !IsUnsupportedFeature(CEC_OPCODE_GET_MENU_LANGUAGE
))
378 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "<< requesting menu language of '%s' (%X)", GetLogicalAddressName(), m_iLogicalAddress
);
379 bReturn
= m_handler
->TransmitRequestMenuLanguage(initiator
, m_iLogicalAddress
, bWaitForResponse
);
385 bool CCECBusDevice::TransmitSetMenuLanguage(const cec_logical_address destination
, bool bIsReply
)
388 cec_menu_language language
;
390 CLockObject
lock(m_mutex
);
391 language
= m_menuLanguage
;
396 CLockObject
lock(m_mutex
);
397 lang
[0] = language
.language
[0];
398 lang
[1] = language
.language
[1];
399 lang
[2] = language
.language
[2];
403 if (lang
[0] == '?' && lang
[1] == '?' && lang
[2] == '?')
405 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "<< %s (%X) -> %s (%X): menu language feature abort", GetLogicalAddressName(), m_iLogicalAddress
, ToString(destination
), destination
);
406 m_processor
->TransmitAbort(m_iLogicalAddress
, destination
, CEC_OPCODE_GIVE_DEVICE_VENDOR_ID
);
411 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "<< %s (%X) -> broadcast (F): menu language '%s'", GetLogicalAddressName(), m_iLogicalAddress
, lang
);
412 bReturn
= m_handler
->TransmitSetMenuLanguage(m_iLogicalAddress
, lang
, bIsReply
);
418 bool CCECBusDevice::TransmitOSDString(const cec_logical_address destination
, cec_display_control duration
, const char *strMessage
, bool bIsReply
)
421 if (!m_processor
->GetDevice(destination
)->IsUnsupportedFeature(CEC_OPCODE_SET_OSD_STRING
))
423 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "<< %s (%X) -> %s (%X): display OSD message '%s'", GetLogicalAddressName(), m_iLogicalAddress
, ToString(destination
), destination
, strMessage
);
425 bReturn
= m_handler
->TransmitOSDString(m_iLogicalAddress
, destination
, duration
, strMessage
, bIsReply
);
431 CStdString
CCECBusDevice::GetCurrentOSDName(void)
433 CLockObject
lock(m_mutex
);
434 return m_strDeviceName
;
437 CStdString
CCECBusDevice::GetOSDName(const cec_logical_address initiator
, bool bUpdate
/* = false */)
439 bool bIsPresent(GetStatus() == CEC_DEVICE_STATUS_PRESENT
);
440 bool bRequestUpdate(false);
442 CLockObject
lock(m_mutex
);
443 bRequestUpdate
= bIsPresent
&&
444 (bUpdate
|| m_strDeviceName
.Equals(ToString(m_iLogicalAddress
))) &&
445 m_type
!= CEC_DEVICE_TYPE_TV
;
450 CheckVendorIdRequested(initiator
);
451 RequestOSDName(initiator
);
454 CLockObject
lock(m_mutex
);
455 return m_strDeviceName
;
458 void CCECBusDevice::SetOSDName(CStdString strName
)
460 CLockObject
lock(m_mutex
);
461 if (m_strDeviceName
!= strName
)
463 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "%s (%X): osd name set to '%s'", GetLogicalAddressName(), m_iLogicalAddress
, strName
.c_str());
464 m_strDeviceName
= strName
;
468 bool CCECBusDevice::RequestOSDName(const cec_logical_address initiator
, bool bWaitForResponse
/* = true */)
472 if (!IsHandledByLibCEC() &&
473 !IsUnsupportedFeature(CEC_OPCODE_GIVE_OSD_NAME
))
476 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "<< requesting OSD name of '%s' (%X)", GetLogicalAddressName(), m_iLogicalAddress
);
477 bReturn
= m_handler
->TransmitRequestOSDName(initiator
, m_iLogicalAddress
, bWaitForResponse
);
483 bool CCECBusDevice::TransmitOSDName(const cec_logical_address destination
, bool bIsReply
)
485 CStdString strDeviceName
;
487 CLockObject
lock(m_mutex
);
488 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "<< %s (%X) -> %s (%X): OSD name '%s'", GetLogicalAddressName(), m_iLogicalAddress
, ToString(destination
), destination
, m_strDeviceName
.c_str());
489 strDeviceName
= m_strDeviceName
;
493 bool bReturn
= m_handler
->TransmitOSDName(m_iLogicalAddress
, destination
, strDeviceName
, bIsReply
);
498 bool CCECBusDevice::HasValidPhysicalAddress(void)
500 CLockObject
lock(m_mutex
);
501 return CLibCEC::IsValidPhysicalAddress(m_iPhysicalAddress
);
504 uint16_t CCECBusDevice::GetCurrentPhysicalAddress(void)
506 CLockObject
lock(m_mutex
);
507 return m_iPhysicalAddress
;
510 uint16_t CCECBusDevice::GetPhysicalAddress(const cec_logical_address initiator
, bool bSuppressUpdate
/* = false */)
512 if (!bSuppressUpdate
)
514 bool bIsPresent(GetStatus() == CEC_DEVICE_STATUS_PRESENT
);
515 bool bRequestUpdate(false);
517 CLockObject
lock(m_mutex
);
518 bRequestUpdate
= bIsPresent
&& m_iPhysicalAddress
== CEC_INVALID_PHYSICAL_ADDRESS
;
523 CheckVendorIdRequested(initiator
);
524 if (!RequestPhysicalAddress(initiator
))
525 LIB_CEC
->AddLog(CEC_LOG_ERROR
, "failed to request the physical address");
529 CLockObject
lock(m_mutex
);
530 return m_iPhysicalAddress
;
533 bool CCECBusDevice::SetPhysicalAddress(uint16_t iNewAddress
)
535 CLockObject
lock(m_mutex
);
536 if (iNewAddress
> 0 && m_iPhysicalAddress
!= iNewAddress
)
538 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "%s (%X): physical address changed from %04x to %04x", GetLogicalAddressName(), m_iLogicalAddress
, m_iPhysicalAddress
, iNewAddress
);
539 m_iPhysicalAddress
= iNewAddress
;
544 bool CCECBusDevice::RequestPhysicalAddress(const cec_logical_address initiator
, bool bWaitForResponse
/* = true */)
548 if (!IsHandledByLibCEC())
551 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "<< requesting physical address of '%s' (%X)", GetLogicalAddressName(), m_iLogicalAddress
);
552 bReturn
= m_handler
->TransmitRequestPhysicalAddress(initiator
, m_iLogicalAddress
, bWaitForResponse
);
558 bool CCECBusDevice::TransmitPhysicalAddress(bool bIsReply
)
560 uint16_t iPhysicalAddress
;
561 cec_device_type type
;
563 CLockObject
lock(m_mutex
);
564 if (m_iPhysicalAddress
== CEC_INVALID_PHYSICAL_ADDRESS
)
567 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "<< %s (%X) -> broadcast (F): physical adddress %4x", GetLogicalAddressName(), m_iLogicalAddress
, m_iPhysicalAddress
);
568 iPhysicalAddress
= m_iPhysicalAddress
;
573 bool bReturn
= m_handler
->TransmitPhysicalAddress(m_iLogicalAddress
, iPhysicalAddress
, type
, bIsReply
);
578 cec_power_status
CCECBusDevice::GetCurrentPowerStatus(void)
580 CLockObject
lock(m_mutex
);
581 return m_powerStatus
;
584 cec_power_status
CCECBusDevice::GetPowerStatus(const cec_logical_address initiator
, bool bUpdate
/* = false */)
586 bool bIsPresent(GetStatus() == CEC_DEVICE_STATUS_PRESENT
);
587 bool bRequestUpdate(false);
589 CLockObject
lock(m_mutex
);
590 bRequestUpdate
= (bIsPresent
&&
591 (bUpdate
|| m_powerStatus
== CEC_POWER_STATUS_UNKNOWN
||
592 m_powerStatus
== CEC_POWER_STATUS_IN_TRANSITION_STANDBY_TO_ON
||
593 m_powerStatus
== CEC_POWER_STATUS_IN_TRANSITION_ON_TO_STANDBY
||
594 GetTimeMs() - m_iLastPowerStateUpdate
>= CEC_POWER_STATE_REFRESH_TIME
));
599 CheckVendorIdRequested(initiator
);
600 RequestPowerStatus(initiator
);
603 CLockObject
lock(m_mutex
);
604 return m_powerStatus
;
607 void CCECBusDevice::SetPowerStatus(const cec_power_status powerStatus
)
609 CLockObject
lock(m_mutex
);
610 if (m_powerStatus
!= powerStatus
)
612 m_iLastPowerStateUpdate
= GetTimeMs();
613 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "%s (%X): power status changed from '%s' to '%s'", GetLogicalAddressName(), m_iLogicalAddress
, ToString(m_powerStatus
), ToString(powerStatus
));
614 m_powerStatus
= powerStatus
;
618 void CCECBusDevice::OnImageViewOnSent(bool bSentByLibCEC
)
620 CLockObject
lock(m_mutex
);
621 m_bImageViewOnSent
= bSentByLibCEC
;
623 if (m_powerStatus
!= CEC_POWER_STATUS_ON
&& m_powerStatus
!= CEC_POWER_STATUS_IN_TRANSITION_STANDBY_TO_ON
)
625 m_iLastPowerStateUpdate
= GetTimeMs();
626 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "%s (%X): power status changed from '%s' to '%s'", GetLogicalAddressName(), m_iLogicalAddress
, ToString(m_powerStatus
), ToString(CEC_POWER_STATUS_IN_TRANSITION_STANDBY_TO_ON
));
627 m_powerStatus
= CEC_POWER_STATUS_IN_TRANSITION_STANDBY_TO_ON
;
631 bool CCECBusDevice::ImageViewOnSent(void)
633 CLockObject
lock(m_mutex
);
634 return m_bImageViewOnSent
;
637 bool CCECBusDevice::RequestPowerStatus(const cec_logical_address initiator
, bool bWaitForResponse
/* = true */)
641 if (!IsHandledByLibCEC() &&
642 !IsUnsupportedFeature(CEC_OPCODE_GIVE_DEVICE_POWER_STATUS
))
645 bReturn
= m_handler
->TransmitRequestPowerStatus(initiator
, m_iLogicalAddress
, bWaitForResponse
);
647 SetPowerStatus(CEC_POWER_STATUS_UNKNOWN
);
653 bool CCECBusDevice::TransmitPowerState(const cec_logical_address destination
, bool bIsReply
)
655 cec_power_status state
;
657 CLockObject
lock(m_mutex
);
658 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "<< %s (%X) -> %s (%X): %s", GetLogicalAddressName(), m_iLogicalAddress
, ToString(destination
), destination
, ToString(m_powerStatus
));
659 state
= m_powerStatus
;
663 bool bReturn
= m_handler
->TransmitPowerState(m_iLogicalAddress
, destination
, state
, bIsReply
);
668 cec_vendor_id
CCECBusDevice::GetCurrentVendorId(void)
670 CLockObject
lock(m_mutex
);
674 cec_vendor_id
CCECBusDevice::GetVendorId(const cec_logical_address initiator
, bool bUpdate
/* = false */)
676 bool bIsPresent(GetStatus() == CEC_DEVICE_STATUS_PRESENT
);
677 bool bRequestUpdate(false);
679 CLockObject
lock(m_mutex
);
680 bRequestUpdate
= (bIsPresent
&&
681 (bUpdate
|| m_vendor
== CEC_VENDOR_UNKNOWN
));
685 RequestVendorId(initiator
);
687 CLockObject
lock(m_mutex
);
691 const char *CCECBusDevice::GetVendorName(const cec_logical_address initiator
, bool bUpdate
/* = false */)
693 return ToString(GetVendorId(initiator
, bUpdate
));
696 bool CCECBusDevice::SetVendorId(uint64_t iVendorId
)
698 bool bVendorChanged(false);
701 CLockObject
lock(m_mutex
);
702 bVendorChanged
= (m_vendor
!= (cec_vendor_id
)iVendorId
);
703 m_vendor
= (cec_vendor_id
)iVendorId
;
707 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "%s (%X): vendor = %s (%06x)", GetLogicalAddressName(), m_iLogicalAddress
, ToString(m_vendor
), m_vendor
);
709 return bVendorChanged
;
712 bool CCECBusDevice::RequestVendorId(const cec_logical_address initiator
, bool bWaitForResponse
/* = true */)
716 if (!IsHandledByLibCEC() && initiator
!= CECDEVICE_UNKNOWN
)
719 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "<< requesting vendor ID of '%s' (%X)", GetLogicalAddressName(), m_iLogicalAddress
);
720 bReturn
= m_handler
->TransmitRequestVendorId(initiator
, m_iLogicalAddress
, bWaitForResponse
);
723 if (bWaitForResponse
)
724 ReplaceHandler(true);
729 bool CCECBusDevice::TransmitVendorID(const cec_logical_address destination
, bool bSendAbort
, bool bIsReply
)
734 CLockObject
lock(m_mutex
);
735 iVendorId
= (uint64_t)m_vendor
;
739 if (iVendorId
== CEC_VENDOR_UNKNOWN
)
743 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "<< %s (%X) -> %s (%X): vendor id feature abort", GetLogicalAddressName(), m_iLogicalAddress
, ToString(destination
), destination
);
744 m_processor
->TransmitAbort(m_iLogicalAddress
, destination
, CEC_OPCODE_GIVE_DEVICE_VENDOR_ID
);
750 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "<< %s (%X) -> %s (%X): vendor id %s (%x)", GetLogicalAddressName(), m_iLogicalAddress
, ToString(destination
), destination
, ToString((cec_vendor_id
)iVendorId
), iVendorId
);
751 bReturn
= m_handler
->TransmitVendorID(m_iLogicalAddress
, iVendorId
, bIsReply
);
757 cec_bus_device_status
CCECBusDevice::GetStatus(bool bForcePoll
/* = false */, bool bSuppressPoll
/* = false */)
759 if (m_iLogicalAddress
== CECDEVICE_BROADCAST
)
760 return CEC_DEVICE_STATUS_NOT_PRESENT
;
762 cec_bus_device_status
status(CEC_DEVICE_STATUS_UNKNOWN
);
763 bool bNeedsPoll(false);
766 CLockObject
lock(m_mutex
);
767 status
= m_deviceStatus
;
768 bNeedsPoll
= !bSuppressPoll
&&
769 m_deviceStatus
!= CEC_DEVICE_STATUS_HANDLED_BY_LIBCEC
&&
772 // don't know the status
773 m_deviceStatus
== CEC_DEVICE_STATUS_UNKNOWN
||
774 // always poll the TV if it's marked as not present
775 (m_deviceStatus
== CEC_DEVICE_STATUS_NOT_PRESENT
&& m_iLogicalAddress
== CECDEVICE_TV
));
780 bool bPollAcked(false);
781 if (bNeedsPoll
&& NeedsPoll())
782 bPollAcked
= m_processor
->PollDevice(m_iLogicalAddress
);
784 status
= bPollAcked
? CEC_DEVICE_STATUS_PRESENT
: CEC_DEVICE_STATUS_NOT_PRESENT
;
785 SetDeviceStatus(status
);
791 void CCECBusDevice::SetDeviceStatus(const cec_bus_device_status newStatus
, cec_version libCECSpecVersion
/* = CEC_VERSION_1_4 */)
793 if (m_iLogicalAddress
== CECDEVICE_UNREGISTERED
)
797 CLockObject
lock(m_mutex
);
800 case CEC_DEVICE_STATUS_HANDLED_BY_LIBCEC
:
801 if (m_deviceStatus
!= newStatus
)
802 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "%s (%X): device status changed into 'handled by libCEC'", GetLogicalAddressName(), m_iLogicalAddress
);
803 SetPowerStatus (CEC_POWER_STATUS_ON
);
804 SetVendorId (CEC_VENDOR_UNKNOWN
);
805 SetMenuState (CEC_MENU_STATE_ACTIVATED
);
806 SetCecVersion (libCECSpecVersion
);
807 SetStreamPath (CEC_INVALID_PHYSICAL_ADDRESS
);
808 MarkAsInactiveSource();
810 m_deviceStatus
= newStatus
;
812 case CEC_DEVICE_STATUS_PRESENT
:
813 if (m_deviceStatus
!= newStatus
)
814 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "%s (%X): device status changed into 'present'", GetLogicalAddressName(), m_iLogicalAddress
);
815 m_deviceStatus
= newStatus
;
816 m_iLastActive
= GetTimeMs();
818 case CEC_DEVICE_STATUS_NOT_PRESENT
:
819 if (m_deviceStatus
!= newStatus
)
821 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "%s (%X): device status changed into 'not present'", GetLogicalAddressName(), m_iLogicalAddress
);
822 ResetDeviceStatus(true);
823 m_deviceStatus
= newStatus
;
833 void CCECBusDevice::ResetDeviceStatus(bool bClientUnregistered
/* = false */)
835 CLockObject
lock(m_mutex
);
836 SetPowerStatus (CEC_POWER_STATUS_UNKNOWN
);
837 SetVendorId (CEC_VENDOR_UNKNOWN
);
838 SetMenuState (CEC_MENU_STATE_ACTIVATED
);
839 SetCecVersion (CEC_VERSION_UNKNOWN
);
840 SetStreamPath (CEC_INVALID_PHYSICAL_ADDRESS
);
841 SetOSDName (ToString(m_iLogicalAddress
));
842 MarkAsInactiveSource(bClientUnregistered
);
845 m_bVendorIdRequested
= false;
846 m_unsupportedFeatures
.clear();
847 m_waitForResponse
->Clear();
849 if (m_deviceStatus
!= CEC_DEVICE_STATUS_UNKNOWN
)
850 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "%s (%X): device status changed into 'unknown'", GetLogicalAddressName(), m_iLogicalAddress
);
851 m_deviceStatus
= CEC_DEVICE_STATUS_UNKNOWN
;
854 bool CCECBusDevice::TransmitPoll(const cec_logical_address dest
, bool bUpdateDeviceStatus
)
857 cec_logical_address
destination(dest
);
858 if (destination
== CECDEVICE_UNKNOWN
)
859 destination
= m_iLogicalAddress
;
861 CCECBusDevice
*destDevice
= m_processor
->GetDevice(destination
);
862 if (destDevice
->m_deviceStatus
== CEC_DEVICE_STATUS_HANDLED_BY_LIBCEC
)
866 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "<< %s (%X) -> %s (%X): POLL", GetLogicalAddressName(), m_iLogicalAddress
, ToString(dest
), dest
);
867 bReturn
= m_handler
->TransmitPoll(m_iLogicalAddress
, destination
, false);
868 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, bReturn
? ">> POLL sent" : ">> POLL not sent");
870 if (bUpdateDeviceStatus
)
871 destDevice
->SetDeviceStatus(bReturn
? CEC_DEVICE_STATUS_PRESENT
: CEC_DEVICE_STATUS_NOT_PRESENT
);
877 void CCECBusDevice::HandlePoll(const cec_logical_address destination
)
879 if (destination
>= 0 && destination
< CECDEVICE_BROADCAST
)
881 CCECBusDevice
*device
= m_processor
->GetDevice(destination
);
883 device
->HandlePollFrom(m_iLogicalAddress
);
887 void CCECBusDevice::HandlePollFrom(const cec_logical_address initiator
)
889 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "<< POLL: %s (%x) -> %s (%x)", ToString(initiator
), initiator
, ToString(m_iLogicalAddress
), m_iLogicalAddress
);
890 m_bAwaitingReceiveFailed
= true;
893 bool CCECBusDevice::HandleReceiveFailed(void)
895 bool bReturn
= m_bAwaitingReceiveFailed
;
896 m_bAwaitingReceiveFailed
= false;
900 cec_menu_state
CCECBusDevice::GetMenuState(const cec_logical_address
UNUSED(initiator
))
902 CLockObject
lock(m_mutex
);
906 void CCECBusDevice::SetMenuState(const cec_menu_state state
)
908 CLockObject
lock(m_mutex
);
909 if (m_menuState
!= state
)
911 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "%s (%X): menu state set to '%s'", GetLogicalAddressName(), m_iLogicalAddress
, ToString(m_menuState
));
916 bool CCECBusDevice::TransmitMenuState(const cec_logical_address dest
, bool bIsReply
)
918 cec_menu_state menuState
;
920 CLockObject
lock(m_mutex
);
921 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "<< %s (%X) -> %s (%X): menu state '%s'", GetLogicalAddressName(), m_iLogicalAddress
, ToString(dest
), dest
, ToString(m_menuState
));
922 menuState
= m_menuState
;
926 bool bReturn
= m_handler
->TransmitMenuState(m_iLogicalAddress
, dest
, menuState
, bIsReply
);
931 bool CCECBusDevice::ActivateSource(uint64_t iDelay
/* = 0 */)
933 MarkAsActiveSource();
938 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "sending active source message for '%s'", ToString(m_iLogicalAddress
));
939 bReturn
= m_handler
->ActivateSource();
943 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "scheduling active source message for '%s'", ToString(m_iLogicalAddress
));
944 m_handler
->ScheduleActivateSource(iDelay
);
950 bool CCECBusDevice::RequestActiveSource(bool bWaitForResponse
/* = true */)
954 if (IsHandledByLibCEC())
957 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "<< requesting active source");
959 bReturn
= m_handler
->TransmitRequestActiveSource(m_iLogicalAddress
, bWaitForResponse
);
965 void CCECBusDevice::MarkAsActiveSource(void)
967 bool bWasActivated(false);
969 // set the power status to powered on
970 SetPowerStatus(CEC_POWER_STATUS_ON
);
972 // mark this device as active source
974 CLockObject
lock(m_mutex
);
975 if (!m_bActiveSource
)
977 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "making %s (%x) the active source", GetLogicalAddressName(), m_iLogicalAddress
);
978 bWasActivated
= true;
981 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "%s (%x) was already marked as active source", GetLogicalAddressName(), m_iLogicalAddress
);
983 m_bActiveSource
= true;
986 CCECBusDevice
* tv
= m_processor
->GetDevice(CECDEVICE_TV
);
988 tv
->OnImageViewOnSent(false);
990 // mark other devices as inactive sources
991 CECDEVICEVEC devices
;
992 m_processor
->GetDevices()->Get(devices
);
993 for (CECDEVICEVEC::iterator it
= devices
.begin(); it
!= devices
.end(); it
++)
994 if ((*it
)->GetLogicalAddress() != m_iLogicalAddress
)
995 (*it
)->MarkAsInactiveSource();
999 if (IsHandledByLibCEC())
1000 m_processor
->SetActiveSource(true, false);
1001 CCECClient
*client
= GetClient();
1003 client
->SourceActivated(m_iLogicalAddress
);
1007 void CCECBusDevice::MarkAsInactiveSource(bool bClientUnregistered
/* = false */)
1009 bool bWasDeactivated(false);
1011 CLockObject
lock(m_mutex
);
1012 if (m_bActiveSource
)
1014 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "marking %s (%X) as inactive source", GetLogicalAddressName(), m_iLogicalAddress
);
1015 bWasDeactivated
= true;
1017 m_bActiveSource
= false;
1020 if (bWasDeactivated
)
1022 if (IsHandledByLibCEC())
1023 m_processor
->SetActiveSource(false, bClientUnregistered
);
1024 CCECClient
*client
= GetClient();
1026 client
->SourceDeactivated(m_iLogicalAddress
);
1030 bool CCECBusDevice::TransmitActiveSource(bool bIsReply
)
1032 bool bSendActiveSource(false);
1033 uint16_t iPhysicalAddress(CEC_INVALID_PHYSICAL_ADDRESS
);
1036 CLockObject
lock(m_mutex
);
1037 if (!HasValidPhysicalAddress())
1039 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "%s (%X) has an invalid physical address (%04x), not sending active source commands", GetLogicalAddressName(), m_iLogicalAddress
, m_iPhysicalAddress
);
1043 iPhysicalAddress
= m_iPhysicalAddress
;
1045 if (m_powerStatus
!= CEC_POWER_STATUS_ON
&& m_powerStatus
!= CEC_POWER_STATUS_IN_TRANSITION_STANDBY_TO_ON
)
1046 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "<< %s (%X) is not powered on", GetLogicalAddressName(), m_iLogicalAddress
);
1047 else if (m_bActiveSource
)
1049 LIB_CEC
->AddLog(CEC_LOG_NOTICE
, "<< %s (%X) -> broadcast (F): active source (%4x)", GetLogicalAddressName(), m_iLogicalAddress
, m_iPhysicalAddress
);
1050 bSendActiveSource
= true;
1053 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "<< %s (%X) is not the active source", GetLogicalAddressName(), m_iLogicalAddress
);
1056 bool bActiveSourceSent(false);
1057 if (bSendActiveSource
)
1060 bActiveSourceSent
= m_handler
->TransmitActiveSource(m_iLogicalAddress
, iPhysicalAddress
, bIsReply
);
1064 return bActiveSourceSent
;
1067 bool CCECBusDevice::TransmitImageViewOn(void)
1070 CLockObject
lock(m_mutex
);
1071 if (m_powerStatus
!= CEC_POWER_STATUS_ON
&& m_powerStatus
!= CEC_POWER_STATUS_IN_TRANSITION_STANDBY_TO_ON
)
1073 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "<< %s (%X) is not powered on", GetLogicalAddressName(), m_iLogicalAddress
);
1078 CCECBusDevice
* tv
= m_processor
->GetDevice(CECDEVICE_TV
);
1081 LIB_CEC
->AddLog(CEC_LOG_ERROR
, "%s - couldn't get TV instance", __FUNCTION__
);
1085 if (tv
->ImageViewOnSent())
1087 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "%s - 'image view on' already sent", __FUNCTION__
);
1091 bool bImageViewOnSent(false);
1093 bImageViewOnSent
= m_handler
->TransmitImageViewOn(m_iLogicalAddress
, CECDEVICE_TV
);
1096 if (bImageViewOnSent
)
1097 tv
->OnImageViewOnSent(true);
1099 return bImageViewOnSent
;
1102 bool CCECBusDevice::TransmitInactiveSource(void)
1104 uint16_t iPhysicalAddress
;
1106 CLockObject
lock(m_mutex
);
1107 LIB_CEC
->AddLog(CEC_LOG_NOTICE
, "<< %s (%X) -> broadcast (F): inactive source", GetLogicalAddressName(), m_iLogicalAddress
);
1108 iPhysicalAddress
= m_iPhysicalAddress
;
1112 bool bReturn
= m_handler
->TransmitInactiveSource(m_iLogicalAddress
, iPhysicalAddress
);
1117 bool CCECBusDevice::TransmitPendingActiveSourceCommands(void)
1120 bool bReturn
= m_handler
->ActivateSource(true);
1125 void CCECBusDevice::SetActiveRoute(uint16_t iRoute
)
1127 SetPowerStatus(CEC_POWER_STATUS_ON
);
1129 CCECDeviceMap
* map
= m_processor
->GetDevices();
1133 CCECBusDevice
* previouslyActive
= map
->GetActiveSource();
1134 if (!previouslyActive
)
1137 CECDEVICEVEC devices
;
1138 m_processor
->GetDevices()->GetChildrenOf(devices
, this);
1140 for (CECDEVICEVEC::iterator it
= devices
.begin(); it
!= devices
.end(); it
++)
1142 if (!CCECTypeUtils::PhysicalAddressIsIncluded(iRoute
, (*it
)->GetCurrentPhysicalAddress()))
1143 (*it
)->MarkAsInactiveSource();
1147 void CCECBusDevice::SetStreamPath(uint16_t iNewAddress
, uint16_t iOldAddress
/* = CEC_INVALID_PHYSICAL_ADDRESS */)
1149 if (iNewAddress
!= CEC_INVALID_PHYSICAL_ADDRESS
)
1150 SetPowerStatus(CEC_POWER_STATUS_ON
);
1152 CLockObject
lock(m_mutex
);
1153 if (iNewAddress
!= m_iStreamPath
)
1155 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "%s (%X): stream path changed from %04x to %04x", GetLogicalAddressName(), m_iLogicalAddress
, iOldAddress
== 0 ? m_iStreamPath
: iOldAddress
, iNewAddress
);
1156 m_iStreamPath
= iNewAddress
;
1159 if (!LIB_CEC
->IsValidPhysicalAddress(iNewAddress
))
1162 CCECBusDevice
*device
= m_processor
->GetDeviceByPhysicalAddress(iNewAddress
);
1165 // if a device is found with the new physical address, mark it as active, which will automatically mark all other devices as inactive
1166 device
->MarkAsActiveSource();
1168 // respond with an active source message if this device is handled by libCEC
1169 if (device
->IsHandledByLibCEC())
1170 device
->TransmitActiveSource(true);
1174 // try to find the device with the old address, and mark it as inactive when found
1175 device
= m_processor
->GetDeviceByPhysicalAddress(iOldAddress
);
1177 device
->MarkAsInactiveSource();
1181 bool CCECBusDevice::PowerOn(const cec_logical_address initiator
)
1183 bool bReturn(false);
1184 GetVendorId(initiator
); // ensure that we got the vendor id, because the implementations vary per vendor
1187 cec_power_status currentStatus
;
1188 if (m_iLogicalAddress
== CECDEVICE_TV
||
1189 ((currentStatus
= GetPowerStatus(initiator
, false)) != CEC_POWER_STATUS_IN_TRANSITION_STANDBY_TO_ON
&&
1190 currentStatus
!= CEC_POWER_STATUS_ON
))
1192 LIB_CEC
->AddLog(CEC_LOG_NOTICE
, "<< powering on '%s' (%X)", GetLogicalAddressName(), m_iLogicalAddress
);
1193 bReturn
= m_handler
->PowerOn(initiator
, m_iLogicalAddress
);
1197 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "'%s' (%X) is already '%s'", GetLogicalAddressName(), m_iLogicalAddress
, ToString(currentStatus
));
1204 bool CCECBusDevice::Standby(const cec_logical_address initiator
)
1206 GetVendorId(initiator
); // ensure that we got the vendor id, because the implementations vary per vendor
1208 LIB_CEC
->AddLog(CEC_LOG_NOTICE
, "<< putting '%s' (%X) in standby mode", GetLogicalAddressName(), m_iLogicalAddress
);
1210 bool bReturn
= m_handler
->TransmitStandby(initiator
, m_iLogicalAddress
);
1215 bool CCECBusDevice::NeedsPoll(void)
1217 bool bSendPoll(false);
1218 cec_logical_address
pollAddress(CECDEVICE_UNKNOWN
);
1219 switch (m_iLogicalAddress
)
1221 case CECDEVICE_PLAYBACKDEVICE3
:
1222 pollAddress
= CECDEVICE_PLAYBACKDEVICE2
;
1224 case CECDEVICE_PLAYBACKDEVICE2
:
1225 pollAddress
= CECDEVICE_PLAYBACKDEVICE1
;
1227 case CECDEVICE_RECORDINGDEVICE3
:
1228 pollAddress
= CECDEVICE_RECORDINGDEVICE2
;
1230 case CECDEVICE_RECORDINGDEVICE2
:
1231 pollAddress
= CECDEVICE_RECORDINGDEVICE1
;
1233 case CECDEVICE_TUNER4
:
1234 pollAddress
= CECDEVICE_TUNER3
;
1236 case CECDEVICE_TUNER3
:
1237 pollAddress
= CECDEVICE_TUNER2
;
1239 case CECDEVICE_TUNER2
:
1240 pollAddress
= CECDEVICE_TUNER1
;
1242 case CECDEVICE_AUDIOSYSTEM
:
1243 case CECDEVICE_PLAYBACKDEVICE1
:
1244 case CECDEVICE_RECORDINGDEVICE1
:
1245 case CECDEVICE_TUNER1
:
1253 if (!bSendPoll
&& pollAddress
!= CECDEVICE_UNKNOWN
)
1255 CCECBusDevice
*device
= m_processor
->GetDevice(pollAddress
);
1258 cec_bus_device_status status
= device
->GetStatus();
1259 bSendPoll
= (status
== CEC_DEVICE_STATUS_PRESENT
|| status
== CEC_DEVICE_STATUS_HANDLED_BY_LIBCEC
);
1270 void CCECBusDevice::CheckVendorIdRequested(const cec_logical_address initiator
)
1272 bool bRequestVendorId(false);
1274 CLockObject
lock(m_mutex
);
1275 bRequestVendorId
= !m_bVendorIdRequested
;
1276 m_bVendorIdRequested
= true;
1279 if (bRequestVendorId
)
1281 ReplaceHandler(false);
1282 GetVendorId(initiator
);
1287 CCECAudioSystem
*CCECBusDevice::AsAudioSystem(void)
1289 return AsAudioSystem(this);
1292 CCECPlaybackDevice
*CCECBusDevice::AsPlaybackDevice(void)
1294 return AsPlaybackDevice(this);
1297 CCECRecordingDevice
*CCECBusDevice::AsRecordingDevice(void)
1299 return AsRecordingDevice(this);
1302 CCECTuner
*CCECBusDevice::AsTuner(void)
1304 return AsTuner(this);
1307 CCECTV
*CCECBusDevice::AsTV(void)
1312 CCECAudioSystem
*CCECBusDevice::AsAudioSystem(CCECBusDevice
*device
)
1314 if (device
&& device
->GetType() == CEC_DEVICE_TYPE_AUDIO_SYSTEM
)
1315 return static_cast<CCECAudioSystem
*>(device
);
1319 CCECPlaybackDevice
*CCECBusDevice::AsPlaybackDevice(CCECBusDevice
*device
)
1322 (device
->GetType() == CEC_DEVICE_TYPE_PLAYBACK_DEVICE
||
1323 device
->GetType() == CEC_DEVICE_TYPE_RECORDING_DEVICE
))
1324 return static_cast<CCECPlaybackDevice
*>(device
);
1328 CCECRecordingDevice
*CCECBusDevice::AsRecordingDevice(CCECBusDevice
*device
)
1330 if (device
&& device
->GetType() == CEC_DEVICE_TYPE_RECORDING_DEVICE
)
1331 return static_cast<CCECRecordingDevice
*>(device
);
1335 CCECTuner
*CCECBusDevice::AsTuner(CCECBusDevice
*device
)
1337 if (device
&& device
->GetType() == CEC_DEVICE_TYPE_TUNER
)
1338 return static_cast<CCECTuner
*>(device
);
1342 CCECTV
*CCECBusDevice::AsTV(CCECBusDevice
*device
)
1344 if (device
&& device
->GetType() == CEC_DEVICE_TYPE_TV
)
1345 return static_cast<CCECTV
*>(device
);
1349 void CCECBusDevice::MarkBusy(void)
1351 CLockObject
handlerLock(m_handlerMutex
);
1352 ++m_iHandlerUseCount
;
1355 void CCECBusDevice::MarkReady(void)
1357 CLockObject
handlerLock(m_handlerMutex
);
1358 if (m_iHandlerUseCount
> 0)
1359 --m_iHandlerUseCount
;
1362 bool CCECBusDevice::TryLogicalAddress(cec_version libCECSpecVersion
/* = CEC_VERSION_1_4 */)
1364 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "trying logical address '%s'", GetLogicalAddressName());
1366 if (!TransmitPoll(m_iLogicalAddress
, false))
1368 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "using logical address '%s'", GetLogicalAddressName());
1369 SetDeviceStatus(CEC_DEVICE_STATUS_HANDLED_BY_LIBCEC
, libCECSpecVersion
);
1374 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "logical address '%s' already taken", GetLogicalAddressName());
1375 SetDeviceStatus(CEC_DEVICE_STATUS_PRESENT
);
1379 CCECClient
*CCECBusDevice::GetClient(void)
1381 return m_processor
->GetClient(m_iLogicalAddress
);
1384 void CCECBusDevice::SignalOpcode(cec_opcode opcode
)
1386 m_waitForResponse
->Received(opcode
);
1389 bool CCECBusDevice::WaitForOpcode(cec_opcode opcode
)
1391 return m_waitForResponse
->Wait(opcode
);