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/implementations/AQCommandHandler.h"
46 #include "lib/LibCEC.h"
47 #include "lib/CECTypeUtils.h"
48 #include "lib/platform/util/timeutils.h"
49 #include "lib/platform/util/util.h"
51 #include "CECAudioSystem.h"
52 #include "CECPlaybackDevice.h"
53 #include "CECRecordingDevice.h"
59 using namespace PLATFORM
;
61 #define LIB_CEC m_processor->GetLib()
62 #define ToString(p) CCECTypeUtils::ToString(p)
64 CCECBusDevice::CCECBusDevice(CCECProcessor
*processor
, cec_logical_address iLogicalAddress
, uint16_t iPhysicalAddress
/* = CEC_INVALID_PHYSICAL_ADDRESS */) :
65 m_type (CEC_DEVICE_TYPE_RESERVED
),
66 m_iPhysicalAddress (iPhysicalAddress
),
67 m_iStreamPath (CEC_INVALID_PHYSICAL_ADDRESS
),
68 m_iLogicalAddress (iLogicalAddress
),
69 m_powerStatus (CEC_POWER_STATUS_UNKNOWN
),
70 m_processor (processor
),
71 m_vendor (CEC_VENDOR_UNKNOWN
),
72 m_bReplaceHandler (false),
73 m_menuState (CEC_MENU_STATE_ACTIVATED
),
74 m_bActiveSource (false),
76 m_iLastPowerStateUpdate (0),
77 m_cecVersion (CEC_VERSION_UNKNOWN
),
78 m_deviceStatus (CEC_DEVICE_STATUS_UNKNOWN
),
79 m_iHandlerUseCount (0),
80 m_bAwaitingReceiveFailed(false),
81 m_bVendorIdRequested (false),
82 m_waitForResponse (new CWaitForResponse
),
83 m_bImageViewOnSent (false)
85 m_handler
= new CCECCommandHandler(this);
87 for (unsigned int iPtr
= 0; iPtr
< 4; iPtr
++)
88 m_menuLanguage
.language
[iPtr
] = '?';
89 m_menuLanguage
.language
[3] = 0;
90 m_menuLanguage
.device
= iLogicalAddress
;
92 m_strDeviceName
= ToString(m_iLogicalAddress
);
95 CCECBusDevice::~CCECBusDevice(void)
97 DELETE_AND_NULL(m_handler
);
98 DELETE_AND_NULL(m_waitForResponse
);
101 bool CCECBusDevice::ReplaceHandler(bool bActivateSource
/* = true */)
103 if (m_iLogicalAddress
== CECDEVICE_BROADCAST
)
106 bool bInitHandler(false);
108 CLockObject
lock(m_mutex
);
109 CLockObject
handlerLock(m_handlerMutex
);
110 if (m_iHandlerUseCount
> 0)
115 if (m_vendor
!= m_handler
->GetVendorId())
117 if (CCECCommandHandler::HasSpecificHandler(m_vendor
))
119 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "replacing the command handler for device '%s' (%x)", GetLogicalAddressName(), GetLogicalAddress());
121 int32_t iTransmitTimeout
= m_handler
->m_iTransmitTimeout
;
122 int32_t iTransmitWait
= m_handler
->m_iTransmitWait
;
123 int8_t iTransmitRetries
= m_handler
->m_iTransmitRetries
;
124 int64_t iActiveSourcePending
= m_handler
->m_iActiveSourcePending
;
126 DELETE_AND_NULL(m_handler
);
130 case CEC_VENDOR_SAMSUNG
:
131 m_handler
= new CANCommandHandler(this, iTransmitTimeout
, iTransmitWait
, iTransmitRetries
, iActiveSourcePending
);
134 m_handler
= new CSLCommandHandler(this, iTransmitTimeout
, iTransmitWait
, iTransmitRetries
, iActiveSourcePending
);
136 case CEC_VENDOR_PANASONIC
:
137 m_handler
= new CVLCommandHandler(this, iTransmitTimeout
, iTransmitWait
, iTransmitRetries
, iActiveSourcePending
);
139 case CEC_VENDOR_PHILIPS
:
140 m_handler
= new CPHCommandHandler(this, iTransmitTimeout
, iTransmitWait
, iTransmitRetries
, iActiveSourcePending
);
142 case CEC_VENDOR_TOSHIBA
:
143 case CEC_VENDOR_TOSHIBA2
:
144 m_handler
= new CRLCommandHandler(this, iTransmitTimeout
, iTransmitWait
, iTransmitRetries
, iActiveSourcePending
);
146 case CEC_VENDOR_ONKYO
:
147 m_handler
= new CRHCommandHandler(this, iTransmitTimeout
, iTransmitWait
, iTransmitRetries
, iActiveSourcePending
);
149 case CEC_VENDOR_SHARP
:
150 m_handler
= new CAQCommandHandler(this, iTransmitTimeout
, iTransmitWait
, iTransmitRetries
, iActiveSourcePending
);
153 m_handler
= new CCECCommandHandler(this, iTransmitTimeout
, iTransmitWait
, iTransmitRetries
, iActiveSourcePending
);
157 m_handler
->SetVendorId(m_vendor
);
165 CCECBusDevice
*primary
= GetProcessor()->GetPrimaryDevice();
166 if (primary
->GetLogicalAddress() != CECDEVICE_UNREGISTERED
)
168 m_handler
->InitHandler();
170 if (bActivateSource
&& IsHandledByLibCEC() && IsActiveSource())
171 m_handler
->ActivateSource();
180 CCECCommandHandler
*CCECBusDevice::GetHandler(void)
182 ReplaceHandler(false);
187 bool CCECBusDevice::HandleCommand(const cec_command
&command
)
189 bool bHandled(false);
191 /* update "last active" */
193 CLockObject
lock(m_mutex
);
194 m_iLastActive
= GetTimeMs();
198 /* handle the command */
199 bHandled
= m_handler
->HandleCommand(command
);
201 /* change status to present */
202 if (bHandled
&& GetLogicalAddress() != CECDEVICE_BROADCAST
&& command
.opcode_set
== 1)
204 CLockObject
lock(m_mutex
);
205 if (m_deviceStatus
!= CEC_DEVICE_STATUS_HANDLED_BY_LIBCEC
)
207 if (m_deviceStatus
!= CEC_DEVICE_STATUS_PRESENT
)
208 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "device %s (%x) status changed to present after command %s", GetLogicalAddressName(), (uint8_t)GetLogicalAddress(), ToString(command
.opcode
));
209 m_deviceStatus
= CEC_DEVICE_STATUS_PRESENT
;
217 const char* CCECBusDevice::GetLogicalAddressName(void) const
219 return ToString(m_iLogicalAddress
);
222 bool CCECBusDevice::IsPresent(void)
224 CLockObject
lock(m_mutex
);
225 return m_deviceStatus
== CEC_DEVICE_STATUS_PRESENT
;
228 bool CCECBusDevice::IsHandledByLibCEC(void)
230 CLockObject
lock(m_mutex
);
231 return m_deviceStatus
== CEC_DEVICE_STATUS_HANDLED_BY_LIBCEC
;
234 void CCECBusDevice::SetUnsupportedFeature(cec_opcode opcode
)
236 // some commands should never be marked as unsupported
237 if (opcode
== CEC_OPCODE_VENDOR_COMMAND
||
238 opcode
== CEC_OPCODE_VENDOR_COMMAND_WITH_ID
||
239 opcode
== CEC_OPCODE_VENDOR_REMOTE_BUTTON_DOWN
||
240 opcode
== CEC_OPCODE_VENDOR_REMOTE_BUTTON_UP
||
241 opcode
== CEC_OPCODE_ABORT
||
242 opcode
== CEC_OPCODE_FEATURE_ABORT
||
243 opcode
== CEC_OPCODE_NONE
||
244 opcode
== CEC_OPCODE_USER_CONTROL_PRESSED
||
245 opcode
== CEC_OPCODE_USER_CONTROL_RELEASE
)
249 CLockObject
lock(m_mutex
);
250 if (m_unsupportedFeatures
.find(opcode
) == m_unsupportedFeatures
.end())
252 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "marking opcode '%s' as unsupported feature for device '%s'", ToString(opcode
), GetLogicalAddressName());
253 m_unsupportedFeatures
.insert(opcode
);
257 // signal threads that are waiting for a reponse
259 SignalOpcode(cec_command::GetResponseOpcode(opcode
));
263 bool CCECBusDevice::IsUnsupportedFeature(cec_opcode opcode
)
265 CLockObject
lock(m_mutex
);
266 bool bUnsupported
= (m_unsupportedFeatures
.find(opcode
) != m_unsupportedFeatures
.end());
268 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "'%s' is marked as unsupported feature for device '%s'", ToString(opcode
), GetLogicalAddressName());
272 bool CCECBusDevice::TransmitKeypress(const cec_logical_address initiator
, cec_user_control_code key
, bool bWait
/* = true */)
275 bool bReturn
= m_handler
->TransmitKeypress(initiator
, m_iLogicalAddress
, key
, bWait
);
280 bool CCECBusDevice::TransmitKeyRelease(const cec_logical_address initiator
, bool bWait
/* = true */)
283 bool bReturn
= m_handler
->TransmitKeyRelease(initiator
, m_iLogicalAddress
, bWait
);
288 cec_version
CCECBusDevice::GetCecVersion(const cec_logical_address initiator
, bool bUpdate
/* = false */)
290 bool bIsPresent(GetStatus() == CEC_DEVICE_STATUS_PRESENT
);
291 bool bRequestUpdate(false);
293 CLockObject
lock(m_mutex
);
294 bRequestUpdate
= bIsPresent
&&
295 (bUpdate
|| m_cecVersion
== CEC_VERSION_UNKNOWN
);
300 CheckVendorIdRequested(initiator
);
301 RequestCecVersion(initiator
);
304 CLockObject
lock(m_mutex
);
308 void CCECBusDevice::SetCecVersion(const cec_version newVersion
)
310 CLockObject
lock(m_mutex
);
311 if (m_cecVersion
!= newVersion
)
312 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "%s (%X): CEC version %s", GetLogicalAddressName(), m_iLogicalAddress
, ToString(newVersion
));
313 m_cecVersion
= newVersion
;
316 bool CCECBusDevice::RequestCecVersion(const cec_logical_address initiator
, bool bWaitForResponse
/* = true */)
320 if (!IsHandledByLibCEC() &&
321 !IsUnsupportedFeature(CEC_OPCODE_GET_CEC_VERSION
))
324 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "<< requesting CEC version of '%s' (%X)", GetLogicalAddressName(), m_iLogicalAddress
);
325 bReturn
= m_handler
->TransmitRequestCecVersion(initiator
, m_iLogicalAddress
, bWaitForResponse
);
331 bool CCECBusDevice::TransmitCECVersion(const cec_logical_address destination
, bool bIsReply
)
335 CLockObject
lock(m_mutex
);
336 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "<< %s (%X) -> %s (%X): cec version %s", GetLogicalAddressName(), m_iLogicalAddress
, ToString(destination
), destination
, ToString(m_cecVersion
));
337 version
= m_cecVersion
;
341 bool bReturn
= m_handler
->TransmitCECVersion(m_iLogicalAddress
, destination
, version
, bIsReply
);
346 cec_menu_language
&CCECBusDevice::GetMenuLanguage(const cec_logical_address initiator
, bool bUpdate
/* = false */)
348 bool bIsPresent(GetStatus() == CEC_DEVICE_STATUS_PRESENT
);
349 bool bRequestUpdate(false);
351 CLockObject
lock(m_mutex
);
352 bRequestUpdate
= (bIsPresent
&&
353 (bUpdate
|| !strcmp(m_menuLanguage
.language
, "???")));
358 CheckVendorIdRequested(initiator
);
359 RequestMenuLanguage(initiator
);
362 CLockObject
lock(m_mutex
);
363 return m_menuLanguage
;
366 void CCECBusDevice::SetMenuLanguage(const char *strLanguage
)
371 CLockObject
lock(m_mutex
);
372 if (strcmp(strLanguage
, m_menuLanguage
.language
))
374 memcpy(m_menuLanguage
.language
, strLanguage
, 3);
375 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "%s (%X): menu language set to '%s'", GetLogicalAddressName(), m_iLogicalAddress
, m_menuLanguage
.language
);
379 void CCECBusDevice::SetMenuLanguage(const cec_menu_language
&language
)
381 if (language
.device
== m_iLogicalAddress
)
382 SetMenuLanguage(language
.language
);
385 bool CCECBusDevice::RequestMenuLanguage(const cec_logical_address initiator
, bool bWaitForResponse
/* = true */)
389 if (!IsHandledByLibCEC() &&
390 !IsUnsupportedFeature(CEC_OPCODE_GET_MENU_LANGUAGE
))
393 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "<< requesting menu language of '%s' (%X)", GetLogicalAddressName(), m_iLogicalAddress
);
394 bReturn
= m_handler
->TransmitRequestMenuLanguage(initiator
, m_iLogicalAddress
, bWaitForResponse
);
400 bool CCECBusDevice::TransmitSetMenuLanguage(const cec_logical_address destination
, bool bIsReply
)
403 cec_menu_language language
;
405 CLockObject
lock(m_mutex
);
406 language
= m_menuLanguage
;
411 CLockObject
lock(m_mutex
);
412 lang
[0] = language
.language
[0];
413 lang
[1] = language
.language
[1];
414 lang
[2] = language
.language
[2];
419 if (lang
[0] == '?' && lang
[1] == '?' && lang
[2] == '?')
421 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "<< %s (%X) -> %s (%X): menu language feature abort", GetLogicalAddressName(), m_iLogicalAddress
, ToString(destination
), destination
);
422 m_processor
->TransmitAbort(m_iLogicalAddress
, destination
, CEC_OPCODE_GIVE_DEVICE_VENDOR_ID
);
427 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "<< %s (%X) -> broadcast (F): menu language '%s'", GetLogicalAddressName(), m_iLogicalAddress
, lang
);
428 bReturn
= m_handler
->TransmitSetMenuLanguage(m_iLogicalAddress
, lang
, bIsReply
);
434 bool CCECBusDevice::TransmitOSDString(const cec_logical_address destination
, cec_display_control duration
, const char *strMessage
, bool bIsReply
)
437 if (!m_processor
->GetDevice(destination
)->IsUnsupportedFeature(CEC_OPCODE_SET_OSD_STRING
))
439 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "<< %s (%X) -> %s (%X): display OSD message '%s'", GetLogicalAddressName(), m_iLogicalAddress
, ToString(destination
), destination
, strMessage
);
441 bReturn
= m_handler
->TransmitOSDString(m_iLogicalAddress
, destination
, duration
, strMessage
, bIsReply
);
447 CStdString
CCECBusDevice::GetCurrentOSDName(void)
449 CLockObject
lock(m_mutex
);
450 return m_strDeviceName
;
453 CStdString
CCECBusDevice::GetOSDName(const cec_logical_address initiator
, bool bUpdate
/* = false */)
455 bool bIsPresent(GetStatus() == CEC_DEVICE_STATUS_PRESENT
);
456 bool bRequestUpdate(false);
458 CLockObject
lock(m_mutex
);
459 bRequestUpdate
= bIsPresent
&&
460 (bUpdate
|| m_strDeviceName
.Equals(ToString(m_iLogicalAddress
))) &&
461 m_type
!= CEC_DEVICE_TYPE_TV
;
466 CheckVendorIdRequested(initiator
);
467 RequestOSDName(initiator
);
470 CLockObject
lock(m_mutex
);
471 return m_strDeviceName
;
474 void CCECBusDevice::SetOSDName(CStdString strName
)
476 CLockObject
lock(m_mutex
);
477 if (m_strDeviceName
!= strName
)
479 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "%s (%X): osd name set to '%s'", GetLogicalAddressName(), m_iLogicalAddress
, strName
.c_str());
480 m_strDeviceName
= strName
;
484 bool CCECBusDevice::RequestOSDName(const cec_logical_address initiator
, bool bWaitForResponse
/* = true */)
488 if (!IsHandledByLibCEC() &&
489 !IsUnsupportedFeature(CEC_OPCODE_GIVE_OSD_NAME
))
492 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "<< requesting OSD name of '%s' (%X)", GetLogicalAddressName(), m_iLogicalAddress
);
493 bReturn
= m_handler
->TransmitRequestOSDName(initiator
, m_iLogicalAddress
, bWaitForResponse
);
499 bool CCECBusDevice::TransmitOSDName(const cec_logical_address destination
, bool bIsReply
)
501 CStdString strDeviceName
;
503 CLockObject
lock(m_mutex
);
504 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "<< %s (%X) -> %s (%X): OSD name '%s'", GetLogicalAddressName(), m_iLogicalAddress
, ToString(destination
), destination
, m_strDeviceName
.c_str());
505 strDeviceName
= m_strDeviceName
;
509 bool bReturn
= m_handler
->TransmitOSDName(m_iLogicalAddress
, destination
, strDeviceName
, bIsReply
);
514 bool CCECBusDevice::HasValidPhysicalAddress(void)
516 CLockObject
lock(m_mutex
);
517 return CLibCEC::IsValidPhysicalAddress(m_iPhysicalAddress
);
520 uint16_t CCECBusDevice::GetCurrentPhysicalAddress(void)
522 CLockObject
lock(m_mutex
);
523 return m_iPhysicalAddress
;
526 uint16_t CCECBusDevice::GetPhysicalAddress(const cec_logical_address initiator
, bool bSuppressUpdate
/* = false */)
528 if (!bSuppressUpdate
)
530 bool bIsPresent(GetStatus() == CEC_DEVICE_STATUS_PRESENT
);
531 bool bRequestUpdate(false);
533 CLockObject
lock(m_mutex
);
534 bRequestUpdate
= bIsPresent
&& m_iPhysicalAddress
== CEC_INVALID_PHYSICAL_ADDRESS
;
539 CheckVendorIdRequested(initiator
);
540 if (!RequestPhysicalAddress(initiator
))
541 LIB_CEC
->AddLog(CEC_LOG_ERROR
, "failed to request the physical address");
545 CLockObject
lock(m_mutex
);
546 return m_iPhysicalAddress
;
549 bool CCECBusDevice::SetPhysicalAddress(uint16_t iNewAddress
)
551 CLockObject
lock(m_mutex
);
552 if (iNewAddress
> 0 && m_iPhysicalAddress
!= iNewAddress
)
554 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "%s (%X): physical address changed from %04x to %04x", GetLogicalAddressName(), m_iLogicalAddress
, m_iPhysicalAddress
, iNewAddress
);
555 m_iPhysicalAddress
= iNewAddress
;
560 bool CCECBusDevice::RequestPhysicalAddress(const cec_logical_address initiator
, bool bWaitForResponse
/* = true */)
564 if (!IsHandledByLibCEC())
567 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "<< requesting physical address of '%s' (%X)", GetLogicalAddressName(), m_iLogicalAddress
);
568 bReturn
= m_handler
->TransmitRequestPhysicalAddress(initiator
, m_iLogicalAddress
, bWaitForResponse
);
574 bool CCECBusDevice::TransmitPhysicalAddress(bool bIsReply
)
576 uint16_t iPhysicalAddress
;
577 cec_device_type type
;
579 CLockObject
lock(m_mutex
);
580 if (m_iPhysicalAddress
== CEC_INVALID_PHYSICAL_ADDRESS
)
583 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "<< %s (%X) -> broadcast (F): physical adddress %4x", GetLogicalAddressName(), m_iLogicalAddress
, m_iPhysicalAddress
);
584 iPhysicalAddress
= m_iPhysicalAddress
;
589 bool bReturn
= m_handler
->TransmitPhysicalAddress(m_iLogicalAddress
, iPhysicalAddress
, type
, bIsReply
);
594 cec_power_status
CCECBusDevice::GetCurrentPowerStatus(void)
596 CLockObject
lock(m_mutex
);
597 return m_powerStatus
;
600 cec_power_status
CCECBusDevice::GetPowerStatus(const cec_logical_address initiator
, bool bUpdate
/* = false */)
602 bool bIsPresent(GetStatus() == CEC_DEVICE_STATUS_PRESENT
);
603 bool bRequestUpdate(false);
605 CLockObject
lock(m_mutex
);
606 bRequestUpdate
= (bIsPresent
&&
607 (bUpdate
|| m_powerStatus
== CEC_POWER_STATUS_UNKNOWN
||
608 m_powerStatus
== CEC_POWER_STATUS_IN_TRANSITION_STANDBY_TO_ON
||
609 m_powerStatus
== CEC_POWER_STATUS_IN_TRANSITION_ON_TO_STANDBY
||
610 GetTimeMs() - m_iLastPowerStateUpdate
>= CEC_POWER_STATE_REFRESH_TIME
));
615 CheckVendorIdRequested(initiator
);
616 RequestPowerStatus(initiator
, bUpdate
);
619 CLockObject
lock(m_mutex
);
620 return m_powerStatus
;
623 void CCECBusDevice::SetPowerStatus(const cec_power_status powerStatus
)
625 CLockObject
lock(m_mutex
);
626 if (m_powerStatus
!= powerStatus
)
628 m_iLastPowerStateUpdate
= GetTimeMs();
629 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "%s (%X): power status changed from '%s' to '%s'", GetLogicalAddressName(), m_iLogicalAddress
, ToString(m_powerStatus
), ToString(powerStatus
));
630 m_powerStatus
= powerStatus
;
634 void CCECBusDevice::OnImageViewOnSent(bool bSentByLibCEC
)
636 CLockObject
lock(m_mutex
);
637 m_bImageViewOnSent
= bSentByLibCEC
;
639 if (m_powerStatus
!= CEC_POWER_STATUS_ON
&& m_powerStatus
!= CEC_POWER_STATUS_IN_TRANSITION_STANDBY_TO_ON
)
641 m_iLastPowerStateUpdate
= GetTimeMs();
642 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
));
643 m_powerStatus
= CEC_POWER_STATUS_IN_TRANSITION_STANDBY_TO_ON
;
647 bool CCECBusDevice::ImageViewOnSent(void)
649 CLockObject
lock(m_mutex
);
650 return m_bImageViewOnSent
;
653 bool CCECBusDevice::RequestPowerStatus(const cec_logical_address initiator
, bool bUpdate
, bool bWaitForResponse
/* = true */)
657 if (!IsHandledByLibCEC() &&
658 !IsUnsupportedFeature(CEC_OPCODE_GIVE_DEVICE_POWER_STATUS
))
661 bReturn
= m_handler
->TransmitRequestPowerStatus(initiator
, m_iLogicalAddress
, bUpdate
, bWaitForResponse
);
663 SetPowerStatus(CEC_POWER_STATUS_UNKNOWN
);
669 bool CCECBusDevice::TransmitPowerState(const cec_logical_address destination
, bool bIsReply
)
671 cec_power_status state
;
673 CLockObject
lock(m_mutex
);
674 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "<< %s (%X) -> %s (%X): %s", GetLogicalAddressName(), m_iLogicalAddress
, ToString(destination
), destination
, ToString(m_powerStatus
));
675 state
= m_powerStatus
;
679 bool bReturn
= m_handler
->TransmitPowerState(m_iLogicalAddress
, destination
, state
, bIsReply
);
684 cec_vendor_id
CCECBusDevice::GetCurrentVendorId(void)
686 CLockObject
lock(m_mutex
);
690 cec_vendor_id
CCECBusDevice::GetVendorId(const cec_logical_address initiator
, bool bUpdate
/* = false */)
692 bool bIsPresent(GetStatus() == CEC_DEVICE_STATUS_PRESENT
);
693 bool bRequestUpdate(false);
695 CLockObject
lock(m_mutex
);
696 bRequestUpdate
= (bIsPresent
&&
697 (bUpdate
|| m_vendor
== CEC_VENDOR_UNKNOWN
));
701 RequestVendorId(initiator
);
703 CLockObject
lock(m_mutex
);
707 const char *CCECBusDevice::GetVendorName(const cec_logical_address initiator
, bool bUpdate
/* = false */)
709 return ToString(GetVendorId(initiator
, bUpdate
));
712 bool CCECBusDevice::SetVendorId(uint64_t iVendorId
)
714 bool bVendorChanged(false);
717 CLockObject
lock(m_mutex
);
718 bVendorChanged
= (m_vendor
!= (cec_vendor_id
)iVendorId
);
719 m_vendor
= (cec_vendor_id
)iVendorId
;
723 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "%s (%X): vendor = %s (%06x)", GetLogicalAddressName(), m_iLogicalAddress
, ToString(m_vendor
), m_vendor
);
725 return bVendorChanged
;
728 bool CCECBusDevice::RequestVendorId(const cec_logical_address initiator
, bool bWaitForResponse
/* = true */)
732 if (!IsHandledByLibCEC() && initiator
!= CECDEVICE_UNKNOWN
)
735 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "<< requesting vendor ID of '%s' (%X)", GetLogicalAddressName(), m_iLogicalAddress
);
736 bReturn
= m_handler
->TransmitRequestVendorId(initiator
, m_iLogicalAddress
, bWaitForResponse
);
739 if (bWaitForResponse
)
740 ReplaceHandler(true);
745 bool CCECBusDevice::TransmitVendorID(const cec_logical_address destination
, bool bSendAbort
, bool bIsReply
)
750 CLockObject
lock(m_mutex
);
751 iVendorId
= (uint64_t)m_vendor
;
755 if (iVendorId
== CEC_VENDOR_UNKNOWN
)
759 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "<< %s (%X) -> %s (%X): vendor id feature abort", GetLogicalAddressName(), m_iLogicalAddress
, ToString(destination
), destination
);
760 m_processor
->TransmitAbort(m_iLogicalAddress
, destination
, CEC_OPCODE_GIVE_DEVICE_VENDOR_ID
);
766 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
);
767 bReturn
= m_handler
->TransmitVendorID(m_iLogicalAddress
, destination
, iVendorId
, bIsReply
);
773 cec_bus_device_status
CCECBusDevice::GetStatus(bool bForcePoll
/* = false */, bool bSuppressPoll
/* = false */)
775 if (m_iLogicalAddress
== CECDEVICE_BROADCAST
)
776 return CEC_DEVICE_STATUS_NOT_PRESENT
;
778 cec_bus_device_status
status(CEC_DEVICE_STATUS_UNKNOWN
);
779 bool bNeedsPoll(false);
782 CLockObject
lock(m_mutex
);
783 status
= m_deviceStatus
;
784 bNeedsPoll
= !bSuppressPoll
&&
785 m_deviceStatus
!= CEC_DEVICE_STATUS_HANDLED_BY_LIBCEC
&&
788 // don't know the status
789 m_deviceStatus
== CEC_DEVICE_STATUS_UNKNOWN
||
790 // always poll the TV if it's marked as not present
791 (m_deviceStatus
== CEC_DEVICE_STATUS_NOT_PRESENT
&& m_iLogicalAddress
== CECDEVICE_TV
));
796 bool bPollAcked(false);
798 bPollAcked
= m_processor
->PollDevice(m_iLogicalAddress
);
800 status
= bPollAcked
? CEC_DEVICE_STATUS_PRESENT
: CEC_DEVICE_STATUS_NOT_PRESENT
;
801 SetDeviceStatus(status
);
807 void CCECBusDevice::SetDeviceStatus(const cec_bus_device_status newStatus
, cec_version libCECSpecVersion
/* = CEC_VERSION_1_4 */)
809 if (m_iLogicalAddress
== CECDEVICE_UNREGISTERED
)
813 CLockObject
lock(m_mutex
);
816 case CEC_DEVICE_STATUS_HANDLED_BY_LIBCEC
:
817 if (m_deviceStatus
!= newStatus
)
818 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "%s (%X): device status changed into 'handled by libCEC'", GetLogicalAddressName(), m_iLogicalAddress
);
819 SetPowerStatus (CEC_POWER_STATUS_ON
);
820 SetVendorId (CEC_VENDOR_UNKNOWN
);
821 SetMenuState (CEC_MENU_STATE_ACTIVATED
);
822 SetCecVersion (libCECSpecVersion
);
823 SetStreamPath (CEC_INVALID_PHYSICAL_ADDRESS
);
824 MarkAsInactiveSource();
826 m_deviceStatus
= newStatus
;
828 case CEC_DEVICE_STATUS_PRESENT
:
829 if (m_deviceStatus
!= newStatus
)
830 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "%s (%X): device status changed into 'present'", GetLogicalAddressName(), m_iLogicalAddress
);
831 m_deviceStatus
= newStatus
;
832 m_iLastActive
= GetTimeMs();
834 case CEC_DEVICE_STATUS_NOT_PRESENT
:
835 if (m_deviceStatus
!= newStatus
)
837 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "%s (%X): device status changed into 'not present'", GetLogicalAddressName(), m_iLogicalAddress
);
838 ResetDeviceStatus(true);
839 m_deviceStatus
= newStatus
;
849 void CCECBusDevice::ResetDeviceStatus(bool bClientUnregistered
/* = false */)
851 CLockObject
lock(m_mutex
);
852 SetPowerStatus (CEC_POWER_STATUS_UNKNOWN
);
853 SetVendorId (CEC_VENDOR_UNKNOWN
);
854 SetMenuState (CEC_MENU_STATE_ACTIVATED
);
855 SetCecVersion (CEC_VERSION_UNKNOWN
);
856 SetStreamPath (CEC_INVALID_PHYSICAL_ADDRESS
);
857 SetOSDName (ToString(m_iLogicalAddress
));
858 MarkAsInactiveSource(bClientUnregistered
);
861 m_bVendorIdRequested
= false;
862 m_unsupportedFeatures
.clear();
863 m_waitForResponse
->Clear();
865 if (m_deviceStatus
!= CEC_DEVICE_STATUS_UNKNOWN
)
866 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "%s (%X): device status changed into 'unknown'", GetLogicalAddressName(), m_iLogicalAddress
);
867 m_deviceStatus
= CEC_DEVICE_STATUS_UNKNOWN
;
870 bool CCECBusDevice::TransmitPoll(const cec_logical_address dest
, bool bUpdateDeviceStatus
)
873 cec_logical_address
destination(dest
);
874 if (destination
== CECDEVICE_UNKNOWN
)
875 destination
= m_iLogicalAddress
;
877 CCECBusDevice
*destDevice
= m_processor
->GetDevice(destination
);
878 if (destDevice
->m_deviceStatus
== CEC_DEVICE_STATUS_HANDLED_BY_LIBCEC
)
882 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "<< %s (%X) -> %s (%X): POLL", GetLogicalAddressName(), m_iLogicalAddress
, ToString(dest
), dest
);
883 bReturn
= m_handler
->TransmitPoll(m_iLogicalAddress
, destination
, false);
884 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, bReturn
? ">> POLL sent" : ">> POLL not sent");
886 if (bUpdateDeviceStatus
)
887 destDevice
->SetDeviceStatus(bReturn
? CEC_DEVICE_STATUS_PRESENT
: CEC_DEVICE_STATUS_NOT_PRESENT
);
893 void CCECBusDevice::HandlePoll(const cec_logical_address destination
)
895 if (destination
>= 0 && destination
< CECDEVICE_BROADCAST
)
897 CCECBusDevice
*device
= m_processor
->GetDevice(destination
);
899 device
->HandlePollFrom(m_iLogicalAddress
);
903 void CCECBusDevice::HandlePollFrom(const cec_logical_address initiator
)
905 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "<< POLL: %s (%x) -> %s (%x)", ToString(initiator
), initiator
, ToString(m_iLogicalAddress
), m_iLogicalAddress
);
906 m_bAwaitingReceiveFailed
= true;
909 bool CCECBusDevice::HandleReceiveFailed(void)
911 bool bReturn
= m_bAwaitingReceiveFailed
;
912 m_bAwaitingReceiveFailed
= false;
916 cec_menu_state
CCECBusDevice::GetMenuState(const cec_logical_address
UNUSED(initiator
))
918 CLockObject
lock(m_mutex
);
922 void CCECBusDevice::SetMenuState(const cec_menu_state state
)
924 CLockObject
lock(m_mutex
);
925 if (m_menuState
!= state
)
927 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "%s (%X): menu state set to '%s'", GetLogicalAddressName(), m_iLogicalAddress
, ToString(m_menuState
));
932 bool CCECBusDevice::TransmitMenuState(const cec_logical_address dest
, bool bIsReply
)
934 cec_menu_state menuState
;
936 CLockObject
lock(m_mutex
);
937 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "<< %s (%X) -> %s (%X): menu state '%s'", GetLogicalAddressName(), m_iLogicalAddress
, ToString(dest
), dest
, ToString(m_menuState
));
938 menuState
= m_menuState
;
942 bool bReturn
= m_handler
->TransmitMenuState(m_iLogicalAddress
, dest
, menuState
, bIsReply
);
947 bool CCECBusDevice::ActivateSource(uint64_t iDelay
/* = 0 */)
949 MarkAsActiveSource();
954 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "sending active source message for '%s'", ToString(m_iLogicalAddress
));
955 bReturn
= m_handler
->ActivateSource();
959 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "scheduling active source message for '%s'", ToString(m_iLogicalAddress
));
960 m_handler
->ScheduleActivateSource(iDelay
);
966 bool CCECBusDevice::RequestActiveSource(bool bWaitForResponse
/* = true */)
970 if (IsHandledByLibCEC())
973 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "<< requesting active source");
975 bReturn
= m_handler
->TransmitRequestActiveSource(m_iLogicalAddress
, bWaitForResponse
);
981 void CCECBusDevice::MarkAsActiveSource(void)
983 bool bWasActivated(false);
985 // set the power status to powered on
986 SetPowerStatus(CEC_POWER_STATUS_ON
);
988 // mark this device as active source
990 CLockObject
lock(m_mutex
);
991 if (!m_bActiveSource
)
993 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "making %s (%x) the active source", GetLogicalAddressName(), m_iLogicalAddress
);
994 bWasActivated
= true;
997 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "%s (%x) was already marked as active source", GetLogicalAddressName(), m_iLogicalAddress
);
999 m_bActiveSource
= true;
1002 CCECBusDevice
* tv
= m_processor
->GetDevice(CECDEVICE_TV
);
1004 tv
->OnImageViewOnSent(false);
1006 // mark other devices as inactive sources
1007 CECDEVICEVEC devices
;
1008 m_processor
->GetDevices()->Get(devices
);
1009 for (CECDEVICEVEC::iterator it
= devices
.begin(); it
!= devices
.end(); it
++)
1010 if ((*it
)->GetLogicalAddress() != m_iLogicalAddress
)
1011 (*it
)->MarkAsInactiveSource();
1015 if (IsHandledByLibCEC())
1016 m_processor
->SetActiveSource(true, false);
1017 CCECClient
*client
= GetClient();
1019 client
->SourceActivated(m_iLogicalAddress
);
1023 void CCECBusDevice::MarkAsInactiveSource(bool bClientUnregistered
/* = false */)
1025 bool bWasDeactivated(false);
1027 CLockObject
lock(m_mutex
);
1028 if (m_bActiveSource
)
1030 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "marking %s (%X) as inactive source", GetLogicalAddressName(), m_iLogicalAddress
);
1031 bWasDeactivated
= true;
1033 m_bActiveSource
= false;
1036 if (bWasDeactivated
)
1038 if (IsHandledByLibCEC())
1039 m_processor
->SetActiveSource(false, bClientUnregistered
);
1040 CCECClient
*client
= GetClient();
1042 client
->SourceDeactivated(m_iLogicalAddress
);
1046 bool CCECBusDevice::TransmitActiveSource(bool bIsReply
)
1048 bool bSendActiveSource(false);
1049 uint16_t iPhysicalAddress(CEC_INVALID_PHYSICAL_ADDRESS
);
1052 CLockObject
lock(m_mutex
);
1053 if (!HasValidPhysicalAddress())
1055 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "%s (%X) has an invalid physical address (%04x), not sending active source commands", GetLogicalAddressName(), m_iLogicalAddress
, m_iPhysicalAddress
);
1059 iPhysicalAddress
= m_iPhysicalAddress
;
1061 if (m_powerStatus
!= CEC_POWER_STATUS_ON
&& m_powerStatus
!= CEC_POWER_STATUS_IN_TRANSITION_STANDBY_TO_ON
)
1062 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "<< %s (%X) is not powered on", GetLogicalAddressName(), m_iLogicalAddress
);
1063 else if (m_bActiveSource
)
1065 LIB_CEC
->AddLog(CEC_LOG_NOTICE
, "<< %s (%X) -> broadcast (F): active source (%4x)", GetLogicalAddressName(), m_iLogicalAddress
, m_iPhysicalAddress
);
1066 bSendActiveSource
= true;
1069 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "<< %s (%X) is not the active source", GetLogicalAddressName(), m_iLogicalAddress
);
1072 bool bActiveSourceSent(false);
1073 if (bSendActiveSource
)
1076 bActiveSourceSent
= m_handler
->TransmitActiveSource(m_iLogicalAddress
, iPhysicalAddress
, bIsReply
);
1080 return bActiveSourceSent
;
1083 bool CCECBusDevice::TransmitImageViewOn(void)
1086 CLockObject
lock(m_mutex
);
1087 if (m_powerStatus
!= CEC_POWER_STATUS_ON
&& m_powerStatus
!= CEC_POWER_STATUS_IN_TRANSITION_STANDBY_TO_ON
)
1089 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "<< %s (%X) is not powered on", GetLogicalAddressName(), m_iLogicalAddress
);
1094 CCECBusDevice
* tv
= m_processor
->GetDevice(CECDEVICE_TV
);
1097 LIB_CEC
->AddLog(CEC_LOG_ERROR
, "%s - couldn't get TV instance", __FUNCTION__
);
1101 if (tv
->ImageViewOnSent())
1103 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "%s - 'image view on' already sent", __FUNCTION__
);
1107 bool bImageViewOnSent(false);
1109 bImageViewOnSent
= m_handler
->TransmitImageViewOn(m_iLogicalAddress
, CECDEVICE_TV
);
1112 if (bImageViewOnSent
)
1113 tv
->OnImageViewOnSent(true);
1115 return bImageViewOnSent
;
1118 bool CCECBusDevice::TransmitInactiveSource(void)
1120 uint16_t iPhysicalAddress
;
1122 CLockObject
lock(m_mutex
);
1123 LIB_CEC
->AddLog(CEC_LOG_NOTICE
, "<< %s (%X) -> broadcast (F): inactive source", GetLogicalAddressName(), m_iLogicalAddress
);
1124 iPhysicalAddress
= m_iPhysicalAddress
;
1128 bool bReturn
= m_handler
->TransmitInactiveSource(m_iLogicalAddress
, iPhysicalAddress
);
1133 bool CCECBusDevice::TransmitPendingActiveSourceCommands(void)
1136 bool bReturn
= m_handler
->ActivateSource(true);
1141 void CCECBusDevice::SetActiveRoute(uint16_t iRoute
)
1143 SetPowerStatus(CEC_POWER_STATUS_ON
);
1145 CCECDeviceMap
* map
= m_processor
->GetDevices();
1149 CCECBusDevice
* newRoute
= m_processor
->GetDeviceByPhysicalAddress(iRoute
, true);
1152 // we were made the active source, send notification
1153 if (newRoute
->IsHandledByLibCEC())
1154 newRoute
->ActivateSource();
1155 // another device was made active
1157 newRoute
->MarkAsActiveSource();
1161 void CCECBusDevice::SetStreamPath(uint16_t iNewAddress
, uint16_t iOldAddress
/* = CEC_INVALID_PHYSICAL_ADDRESS */)
1163 if (iNewAddress
!= CEC_INVALID_PHYSICAL_ADDRESS
)
1164 SetPowerStatus(CEC_POWER_STATUS_ON
);
1166 CLockObject
lock(m_mutex
);
1167 if (iNewAddress
!= m_iStreamPath
)
1169 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "%s (%X): stream path changed from %04x to %04x", GetLogicalAddressName(), m_iLogicalAddress
, iOldAddress
== 0 ? m_iStreamPath
: iOldAddress
, iNewAddress
);
1170 m_iStreamPath
= iNewAddress
;
1173 if (!LIB_CEC
->IsValidPhysicalAddress(iNewAddress
))
1176 CCECBusDevice
*device
= m_processor
->GetDeviceByPhysicalAddress(iNewAddress
);
1179 // if a device is found with the new physical address, mark it as active, which will automatically mark all other devices as inactive
1180 device
->MarkAsActiveSource();
1182 // respond with an active source message if this device is handled by libCEC
1183 if (device
->IsHandledByLibCEC())
1184 device
->TransmitActiveSource(true);
1188 // try to find the device with the old address, and mark it as inactive when found
1189 device
= m_processor
->GetDeviceByPhysicalAddress(iOldAddress
);
1191 device
->MarkAsInactiveSource();
1195 bool CCECBusDevice::PowerOn(const cec_logical_address initiator
)
1197 bool bReturn(false);
1198 GetVendorId(initiator
); // ensure that we got the vendor id, because the implementations vary per vendor
1201 cec_power_status currentStatus
;
1202 if (m_iLogicalAddress
== CECDEVICE_TV
||
1203 ((currentStatus
= GetPowerStatus(initiator
, false)) != CEC_POWER_STATUS_IN_TRANSITION_STANDBY_TO_ON
&&
1204 currentStatus
!= CEC_POWER_STATUS_ON
))
1206 LIB_CEC
->AddLog(CEC_LOG_NOTICE
, "<< powering on '%s' (%X)", GetLogicalAddressName(), m_iLogicalAddress
);
1207 bReturn
= m_handler
->PowerOn(initiator
, m_iLogicalAddress
);
1211 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "'%s' (%X) is already '%s'", GetLogicalAddressName(), m_iLogicalAddress
, ToString(currentStatus
));
1218 bool CCECBusDevice::Standby(const cec_logical_address initiator
)
1220 GetVendorId(initiator
); // ensure that we got the vendor id, because the implementations vary per vendor
1222 LIB_CEC
->AddLog(CEC_LOG_NOTICE
, "<< putting '%s' (%X) in standby mode", GetLogicalAddressName(), m_iLogicalAddress
);
1224 bool bReturn
= m_handler
->TransmitStandby(initiator
, m_iLogicalAddress
);
1229 bool CCECBusDevice::NeedsPoll(void)
1231 bool bSendPoll(false);
1232 cec_logical_address
pollAddress(CECDEVICE_UNKNOWN
);
1233 switch (m_iLogicalAddress
)
1235 case CECDEVICE_PLAYBACKDEVICE3
:
1236 pollAddress
= CECDEVICE_PLAYBACKDEVICE2
;
1238 case CECDEVICE_PLAYBACKDEVICE2
:
1239 pollAddress
= CECDEVICE_PLAYBACKDEVICE1
;
1241 case CECDEVICE_RECORDINGDEVICE3
:
1242 pollAddress
= CECDEVICE_RECORDINGDEVICE2
;
1244 case CECDEVICE_RECORDINGDEVICE2
:
1245 pollAddress
= CECDEVICE_RECORDINGDEVICE1
;
1247 case CECDEVICE_TUNER4
:
1248 pollAddress
= CECDEVICE_TUNER3
;
1250 case CECDEVICE_TUNER3
:
1251 pollAddress
= CECDEVICE_TUNER2
;
1253 case CECDEVICE_TUNER2
:
1254 pollAddress
= CECDEVICE_TUNER1
;
1256 case CECDEVICE_AUDIOSYSTEM
:
1257 case CECDEVICE_PLAYBACKDEVICE1
:
1258 case CECDEVICE_RECORDINGDEVICE1
:
1259 case CECDEVICE_TUNER1
:
1267 if (!bSendPoll
&& pollAddress
!= CECDEVICE_UNKNOWN
)
1269 CCECBusDevice
*device
= m_processor
->GetDevice(pollAddress
);
1272 cec_bus_device_status status
= device
->GetStatus();
1273 bSendPoll
= (status
== CEC_DEVICE_STATUS_PRESENT
|| status
== CEC_DEVICE_STATUS_HANDLED_BY_LIBCEC
);
1284 void CCECBusDevice::CheckVendorIdRequested(const cec_logical_address initiator
)
1286 bool bRequestVendorId(false);
1288 CLockObject
lock(m_mutex
);
1289 bRequestVendorId
= !m_bVendorIdRequested
;
1290 m_bVendorIdRequested
= true;
1293 if (bRequestVendorId
)
1295 ReplaceHandler(false);
1296 GetVendorId(initiator
);
1301 CCECAudioSystem
*CCECBusDevice::AsAudioSystem(void)
1303 return AsAudioSystem(this);
1306 CCECPlaybackDevice
*CCECBusDevice::AsPlaybackDevice(void)
1308 return AsPlaybackDevice(this);
1311 CCECRecordingDevice
*CCECBusDevice::AsRecordingDevice(void)
1313 return AsRecordingDevice(this);
1316 CCECTuner
*CCECBusDevice::AsTuner(void)
1318 return AsTuner(this);
1321 CCECTV
*CCECBusDevice::AsTV(void)
1326 CCECAudioSystem
*CCECBusDevice::AsAudioSystem(CCECBusDevice
*device
)
1328 if (device
&& device
->GetType() == CEC_DEVICE_TYPE_AUDIO_SYSTEM
)
1329 return static_cast<CCECAudioSystem
*>(device
);
1333 CCECPlaybackDevice
*CCECBusDevice::AsPlaybackDevice(CCECBusDevice
*device
)
1336 (device
->GetType() == CEC_DEVICE_TYPE_PLAYBACK_DEVICE
||
1337 device
->GetType() == CEC_DEVICE_TYPE_RECORDING_DEVICE
))
1338 return static_cast<CCECPlaybackDevice
*>(device
);
1342 CCECRecordingDevice
*CCECBusDevice::AsRecordingDevice(CCECBusDevice
*device
)
1344 if (device
&& device
->GetType() == CEC_DEVICE_TYPE_RECORDING_DEVICE
)
1345 return static_cast<CCECRecordingDevice
*>(device
);
1349 CCECTuner
*CCECBusDevice::AsTuner(CCECBusDevice
*device
)
1351 if (device
&& device
->GetType() == CEC_DEVICE_TYPE_TUNER
)
1352 return static_cast<CCECTuner
*>(device
);
1356 CCECTV
*CCECBusDevice::AsTV(CCECBusDevice
*device
)
1358 if (device
&& device
->GetType() == CEC_DEVICE_TYPE_TV
)
1359 return static_cast<CCECTV
*>(device
);
1363 void CCECBusDevice::MarkBusy(void)
1365 CLockObject
handlerLock(m_handlerMutex
);
1366 ++m_iHandlerUseCount
;
1369 void CCECBusDevice::MarkReady(void)
1371 CLockObject
handlerLock(m_handlerMutex
);
1372 if (m_iHandlerUseCount
> 0)
1373 --m_iHandlerUseCount
;
1376 bool CCECBusDevice::TryLogicalAddress(cec_version libCECSpecVersion
/* = CEC_VERSION_1_4 */)
1378 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "trying logical address '%s'", GetLogicalAddressName());
1380 if (!TransmitPoll(m_iLogicalAddress
, false))
1382 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "using logical address '%s'", GetLogicalAddressName());
1383 SetDeviceStatus(CEC_DEVICE_STATUS_HANDLED_BY_LIBCEC
, libCECSpecVersion
);
1388 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "logical address '%s' already taken", GetLogicalAddressName());
1389 SetDeviceStatus(CEC_DEVICE_STATUS_PRESENT
);
1393 CCECClient
*CCECBusDevice::GetClient(void)
1395 return m_processor
->GetClient(m_iLogicalAddress
);
1398 void CCECBusDevice::SignalOpcode(cec_opcode opcode
)
1400 m_waitForResponse
->Received(opcode
);
1403 bool CCECBusDevice::WaitForOpcode(cec_opcode opcode
)
1405 return m_waitForResponse
->Wait(opcode
);