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
&& command
.opcode_set
== 1)
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
||
231 opcode
== CEC_OPCODE_USER_CONTROL_PRESSED
||
232 opcode
== CEC_OPCODE_USER_CONTROL_RELEASE
)
236 CLockObject
lock(m_mutex
);
237 if (m_unsupportedFeatures
.find(opcode
) == m_unsupportedFeatures
.end())
239 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "marking opcode '%s' as unsupported feature for device '%s'", ToString(opcode
), GetLogicalAddressName());
240 m_unsupportedFeatures
.insert(opcode
);
244 // signal threads that are waiting for a reponse
246 SignalOpcode(cec_command::GetResponseOpcode(opcode
));
250 bool CCECBusDevice::IsUnsupportedFeature(cec_opcode opcode
)
252 CLockObject
lock(m_mutex
);
253 bool bUnsupported
= (m_unsupportedFeatures
.find(opcode
) != m_unsupportedFeatures
.end());
255 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "'%s' is marked as unsupported feature for device '%s'", ToString(opcode
), GetLogicalAddressName());
259 bool CCECBusDevice::TransmitKeypress(const cec_logical_address initiator
, cec_user_control_code key
, bool bWait
/* = true */)
262 bool bReturn
= m_handler
->TransmitKeypress(initiator
, m_iLogicalAddress
, key
, bWait
);
267 bool CCECBusDevice::TransmitKeyRelease(const cec_logical_address initiator
, bool bWait
/* = true */)
270 bool bReturn
= m_handler
->TransmitKeyRelease(initiator
, m_iLogicalAddress
, bWait
);
275 cec_version
CCECBusDevice::GetCecVersion(const cec_logical_address initiator
, bool bUpdate
/* = false */)
277 bool bIsPresent(GetStatus() == CEC_DEVICE_STATUS_PRESENT
);
278 bool bRequestUpdate(false);
280 CLockObject
lock(m_mutex
);
281 bRequestUpdate
= bIsPresent
&&
282 (bUpdate
|| m_cecVersion
== CEC_VERSION_UNKNOWN
);
287 CheckVendorIdRequested(initiator
);
288 RequestCecVersion(initiator
);
291 CLockObject
lock(m_mutex
);
295 void CCECBusDevice::SetCecVersion(const cec_version newVersion
)
297 CLockObject
lock(m_mutex
);
298 if (m_cecVersion
!= newVersion
)
299 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "%s (%X): CEC version %s", GetLogicalAddressName(), m_iLogicalAddress
, ToString(newVersion
));
300 m_cecVersion
= newVersion
;
303 bool CCECBusDevice::RequestCecVersion(const cec_logical_address initiator
, bool bWaitForResponse
/* = true */)
307 if (!IsHandledByLibCEC() &&
308 !IsUnsupportedFeature(CEC_OPCODE_GET_CEC_VERSION
))
311 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "<< requesting CEC version of '%s' (%X)", GetLogicalAddressName(), m_iLogicalAddress
);
312 bReturn
= m_handler
->TransmitRequestCecVersion(initiator
, m_iLogicalAddress
, bWaitForResponse
);
318 bool CCECBusDevice::TransmitCECVersion(const cec_logical_address destination
, bool bIsReply
)
322 CLockObject
lock(m_mutex
);
323 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "<< %s (%X) -> %s (%X): cec version %s", GetLogicalAddressName(), m_iLogicalAddress
, ToString(destination
), destination
, ToString(m_cecVersion
));
324 version
= m_cecVersion
;
328 bool bReturn
= m_handler
->TransmitCECVersion(m_iLogicalAddress
, destination
, version
, bIsReply
);
333 cec_menu_language
&CCECBusDevice::GetMenuLanguage(const cec_logical_address initiator
, bool bUpdate
/* = false */)
335 bool bIsPresent(GetStatus() == CEC_DEVICE_STATUS_PRESENT
);
336 bool bRequestUpdate(false);
338 CLockObject
lock(m_mutex
);
339 bRequestUpdate
= (bIsPresent
&&
340 (bUpdate
|| !strcmp(m_menuLanguage
.language
, "???")));
345 CheckVendorIdRequested(initiator
);
346 RequestMenuLanguage(initiator
);
349 CLockObject
lock(m_mutex
);
350 return m_menuLanguage
;
353 void CCECBusDevice::SetMenuLanguage(const char *strLanguage
)
358 CLockObject
lock(m_mutex
);
359 if (strcmp(strLanguage
, m_menuLanguage
.language
))
361 memcpy(m_menuLanguage
.language
, strLanguage
, 3);
362 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "%s (%X): menu language set to '%s'", GetLogicalAddressName(), m_iLogicalAddress
, m_menuLanguage
.language
);
366 void CCECBusDevice::SetMenuLanguage(const cec_menu_language
&language
)
368 if (language
.device
== m_iLogicalAddress
)
369 SetMenuLanguage(language
.language
);
372 bool CCECBusDevice::RequestMenuLanguage(const cec_logical_address initiator
, bool bWaitForResponse
/* = true */)
376 if (!IsHandledByLibCEC() &&
377 !IsUnsupportedFeature(CEC_OPCODE_GET_MENU_LANGUAGE
))
380 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "<< requesting menu language of '%s' (%X)", GetLogicalAddressName(), m_iLogicalAddress
);
381 bReturn
= m_handler
->TransmitRequestMenuLanguage(initiator
, m_iLogicalAddress
, bWaitForResponse
);
387 bool CCECBusDevice::TransmitSetMenuLanguage(const cec_logical_address destination
, bool bIsReply
)
390 cec_menu_language language
;
392 CLockObject
lock(m_mutex
);
393 language
= m_menuLanguage
;
398 CLockObject
lock(m_mutex
);
399 lang
[0] = language
.language
[0];
400 lang
[1] = language
.language
[1];
401 lang
[2] = language
.language
[2];
406 if (lang
[0] == '?' && lang
[1] == '?' && lang
[2] == '?')
408 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "<< %s (%X) -> %s (%X): menu language feature abort", GetLogicalAddressName(), m_iLogicalAddress
, ToString(destination
), destination
);
409 m_processor
->TransmitAbort(m_iLogicalAddress
, destination
, CEC_OPCODE_GIVE_DEVICE_VENDOR_ID
);
414 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "<< %s (%X) -> broadcast (F): menu language '%s'", GetLogicalAddressName(), m_iLogicalAddress
, lang
);
415 bReturn
= m_handler
->TransmitSetMenuLanguage(m_iLogicalAddress
, lang
, bIsReply
);
421 bool CCECBusDevice::TransmitOSDString(const cec_logical_address destination
, cec_display_control duration
, const char *strMessage
, bool bIsReply
)
424 if (!m_processor
->GetDevice(destination
)->IsUnsupportedFeature(CEC_OPCODE_SET_OSD_STRING
))
426 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "<< %s (%X) -> %s (%X): display OSD message '%s'", GetLogicalAddressName(), m_iLogicalAddress
, ToString(destination
), destination
, strMessage
);
428 bReturn
= m_handler
->TransmitOSDString(m_iLogicalAddress
, destination
, duration
, strMessage
, bIsReply
);
434 CStdString
CCECBusDevice::GetCurrentOSDName(void)
436 CLockObject
lock(m_mutex
);
437 return m_strDeviceName
;
440 CStdString
CCECBusDevice::GetOSDName(const cec_logical_address initiator
, bool bUpdate
/* = false */)
442 bool bIsPresent(GetStatus() == CEC_DEVICE_STATUS_PRESENT
);
443 bool bRequestUpdate(false);
445 CLockObject
lock(m_mutex
);
446 bRequestUpdate
= bIsPresent
&&
447 (bUpdate
|| m_strDeviceName
.Equals(ToString(m_iLogicalAddress
))) &&
448 m_type
!= CEC_DEVICE_TYPE_TV
;
453 CheckVendorIdRequested(initiator
);
454 RequestOSDName(initiator
);
457 CLockObject
lock(m_mutex
);
458 return m_strDeviceName
;
461 void CCECBusDevice::SetOSDName(CStdString strName
)
463 CLockObject
lock(m_mutex
);
464 if (m_strDeviceName
!= strName
)
466 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "%s (%X): osd name set to '%s'", GetLogicalAddressName(), m_iLogicalAddress
, strName
.c_str());
467 m_strDeviceName
= strName
;
471 bool CCECBusDevice::RequestOSDName(const cec_logical_address initiator
, bool bWaitForResponse
/* = true */)
475 if (!IsHandledByLibCEC() &&
476 !IsUnsupportedFeature(CEC_OPCODE_GIVE_OSD_NAME
))
479 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "<< requesting OSD name of '%s' (%X)", GetLogicalAddressName(), m_iLogicalAddress
);
480 bReturn
= m_handler
->TransmitRequestOSDName(initiator
, m_iLogicalAddress
, bWaitForResponse
);
486 bool CCECBusDevice::TransmitOSDName(const cec_logical_address destination
, bool bIsReply
)
488 CStdString strDeviceName
;
490 CLockObject
lock(m_mutex
);
491 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "<< %s (%X) -> %s (%X): OSD name '%s'", GetLogicalAddressName(), m_iLogicalAddress
, ToString(destination
), destination
, m_strDeviceName
.c_str());
492 strDeviceName
= m_strDeviceName
;
496 bool bReturn
= m_handler
->TransmitOSDName(m_iLogicalAddress
, destination
, strDeviceName
, bIsReply
);
501 bool CCECBusDevice::HasValidPhysicalAddress(void)
503 CLockObject
lock(m_mutex
);
504 return CLibCEC::IsValidPhysicalAddress(m_iPhysicalAddress
);
507 uint16_t CCECBusDevice::GetCurrentPhysicalAddress(void)
509 CLockObject
lock(m_mutex
);
510 return m_iPhysicalAddress
;
513 uint16_t CCECBusDevice::GetPhysicalAddress(const cec_logical_address initiator
, bool bSuppressUpdate
/* = false */)
515 if (!bSuppressUpdate
)
517 bool bIsPresent(GetStatus() == CEC_DEVICE_STATUS_PRESENT
);
518 bool bRequestUpdate(false);
520 CLockObject
lock(m_mutex
);
521 bRequestUpdate
= bIsPresent
&& m_iPhysicalAddress
== CEC_INVALID_PHYSICAL_ADDRESS
;
526 CheckVendorIdRequested(initiator
);
527 if (!RequestPhysicalAddress(initiator
))
528 LIB_CEC
->AddLog(CEC_LOG_ERROR
, "failed to request the physical address");
532 CLockObject
lock(m_mutex
);
533 return m_iPhysicalAddress
;
536 bool CCECBusDevice::SetPhysicalAddress(uint16_t iNewAddress
)
538 CLockObject
lock(m_mutex
);
539 if (iNewAddress
> 0 && m_iPhysicalAddress
!= iNewAddress
)
541 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "%s (%X): physical address changed from %04x to %04x", GetLogicalAddressName(), m_iLogicalAddress
, m_iPhysicalAddress
, iNewAddress
);
542 m_iPhysicalAddress
= iNewAddress
;
547 bool CCECBusDevice::RequestPhysicalAddress(const cec_logical_address initiator
, bool bWaitForResponse
/* = true */)
551 if (!IsHandledByLibCEC())
554 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "<< requesting physical address of '%s' (%X)", GetLogicalAddressName(), m_iLogicalAddress
);
555 bReturn
= m_handler
->TransmitRequestPhysicalAddress(initiator
, m_iLogicalAddress
, bWaitForResponse
);
561 bool CCECBusDevice::TransmitPhysicalAddress(bool bIsReply
)
563 uint16_t iPhysicalAddress
;
564 cec_device_type type
;
566 CLockObject
lock(m_mutex
);
567 if (m_iPhysicalAddress
== CEC_INVALID_PHYSICAL_ADDRESS
)
570 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "<< %s (%X) -> broadcast (F): physical adddress %4x", GetLogicalAddressName(), m_iLogicalAddress
, m_iPhysicalAddress
);
571 iPhysicalAddress
= m_iPhysicalAddress
;
576 bool bReturn
= m_handler
->TransmitPhysicalAddress(m_iLogicalAddress
, iPhysicalAddress
, type
, bIsReply
);
581 cec_power_status
CCECBusDevice::GetCurrentPowerStatus(void)
583 CLockObject
lock(m_mutex
);
584 return m_powerStatus
;
587 cec_power_status
CCECBusDevice::GetPowerStatus(const cec_logical_address initiator
, bool bUpdate
/* = false */)
589 bool bIsPresent(GetStatus() == CEC_DEVICE_STATUS_PRESENT
);
590 bool bRequestUpdate(false);
592 CLockObject
lock(m_mutex
);
593 bRequestUpdate
= (bIsPresent
&&
594 (bUpdate
|| m_powerStatus
== CEC_POWER_STATUS_UNKNOWN
||
595 m_powerStatus
== CEC_POWER_STATUS_IN_TRANSITION_STANDBY_TO_ON
||
596 m_powerStatus
== CEC_POWER_STATUS_IN_TRANSITION_ON_TO_STANDBY
||
597 GetTimeMs() - m_iLastPowerStateUpdate
>= CEC_POWER_STATE_REFRESH_TIME
));
602 CheckVendorIdRequested(initiator
);
603 RequestPowerStatus(initiator
);
606 CLockObject
lock(m_mutex
);
607 return m_powerStatus
;
610 void CCECBusDevice::SetPowerStatus(const cec_power_status powerStatus
)
612 CLockObject
lock(m_mutex
);
613 if (m_powerStatus
!= powerStatus
)
615 m_iLastPowerStateUpdate
= GetTimeMs();
616 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "%s (%X): power status changed from '%s' to '%s'", GetLogicalAddressName(), m_iLogicalAddress
, ToString(m_powerStatus
), ToString(powerStatus
));
617 m_powerStatus
= powerStatus
;
621 void CCECBusDevice::OnImageViewOnSent(bool bSentByLibCEC
)
623 CLockObject
lock(m_mutex
);
624 m_bImageViewOnSent
= bSentByLibCEC
;
626 if (m_powerStatus
!= CEC_POWER_STATUS_ON
&& m_powerStatus
!= CEC_POWER_STATUS_IN_TRANSITION_STANDBY_TO_ON
)
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(CEC_POWER_STATUS_IN_TRANSITION_STANDBY_TO_ON
));
630 m_powerStatus
= CEC_POWER_STATUS_IN_TRANSITION_STANDBY_TO_ON
;
634 bool CCECBusDevice::ImageViewOnSent(void)
636 CLockObject
lock(m_mutex
);
637 return m_bImageViewOnSent
;
640 bool CCECBusDevice::RequestPowerStatus(const cec_logical_address initiator
, bool bWaitForResponse
/* = true */)
644 if (!IsHandledByLibCEC() &&
645 !IsUnsupportedFeature(CEC_OPCODE_GIVE_DEVICE_POWER_STATUS
))
648 bReturn
= m_handler
->TransmitRequestPowerStatus(initiator
, m_iLogicalAddress
, bWaitForResponse
);
650 SetPowerStatus(CEC_POWER_STATUS_UNKNOWN
);
656 bool CCECBusDevice::TransmitPowerState(const cec_logical_address destination
, bool bIsReply
)
658 cec_power_status state
;
660 CLockObject
lock(m_mutex
);
661 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "<< %s (%X) -> %s (%X): %s", GetLogicalAddressName(), m_iLogicalAddress
, ToString(destination
), destination
, ToString(m_powerStatus
));
662 state
= m_powerStatus
;
666 bool bReturn
= m_handler
->TransmitPowerState(m_iLogicalAddress
, destination
, state
, bIsReply
);
671 cec_vendor_id
CCECBusDevice::GetCurrentVendorId(void)
673 CLockObject
lock(m_mutex
);
677 cec_vendor_id
CCECBusDevice::GetVendorId(const cec_logical_address initiator
, bool bUpdate
/* = false */)
679 bool bIsPresent(GetStatus() == CEC_DEVICE_STATUS_PRESENT
);
680 bool bRequestUpdate(false);
682 CLockObject
lock(m_mutex
);
683 bRequestUpdate
= (bIsPresent
&&
684 (bUpdate
|| m_vendor
== CEC_VENDOR_UNKNOWN
));
688 RequestVendorId(initiator
);
690 CLockObject
lock(m_mutex
);
694 const char *CCECBusDevice::GetVendorName(const cec_logical_address initiator
, bool bUpdate
/* = false */)
696 return ToString(GetVendorId(initiator
, bUpdate
));
699 bool CCECBusDevice::SetVendorId(uint64_t iVendorId
)
701 bool bVendorChanged(false);
704 CLockObject
lock(m_mutex
);
705 bVendorChanged
= (m_vendor
!= (cec_vendor_id
)iVendorId
);
706 m_vendor
= (cec_vendor_id
)iVendorId
;
710 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "%s (%X): vendor = %s (%06x)", GetLogicalAddressName(), m_iLogicalAddress
, ToString(m_vendor
), m_vendor
);
712 return bVendorChanged
;
715 bool CCECBusDevice::RequestVendorId(const cec_logical_address initiator
, bool bWaitForResponse
/* = true */)
719 if (!IsHandledByLibCEC() && initiator
!= CECDEVICE_UNKNOWN
)
722 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "<< requesting vendor ID of '%s' (%X)", GetLogicalAddressName(), m_iLogicalAddress
);
723 bReturn
= m_handler
->TransmitRequestVendorId(initiator
, m_iLogicalAddress
, bWaitForResponse
);
726 if (bWaitForResponse
)
727 ReplaceHandler(true);
732 bool CCECBusDevice::TransmitVendorID(const cec_logical_address destination
, bool bSendAbort
, bool bIsReply
)
737 CLockObject
lock(m_mutex
);
738 iVendorId
= (uint64_t)m_vendor
;
742 if (iVendorId
== CEC_VENDOR_UNKNOWN
)
746 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "<< %s (%X) -> %s (%X): vendor id feature abort", GetLogicalAddressName(), m_iLogicalAddress
, ToString(destination
), destination
);
747 m_processor
->TransmitAbort(m_iLogicalAddress
, destination
, CEC_OPCODE_GIVE_DEVICE_VENDOR_ID
);
753 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
);
754 bReturn
= m_handler
->TransmitVendorID(m_iLogicalAddress
, destination
, iVendorId
, bIsReply
);
760 cec_bus_device_status
CCECBusDevice::GetStatus(bool bForcePoll
/* = false */, bool bSuppressPoll
/* = false */)
762 if (m_iLogicalAddress
== CECDEVICE_BROADCAST
)
763 return CEC_DEVICE_STATUS_NOT_PRESENT
;
765 cec_bus_device_status
status(CEC_DEVICE_STATUS_UNKNOWN
);
766 bool bNeedsPoll(false);
769 CLockObject
lock(m_mutex
);
770 status
= m_deviceStatus
;
771 bNeedsPoll
= !bSuppressPoll
&&
772 m_deviceStatus
!= CEC_DEVICE_STATUS_HANDLED_BY_LIBCEC
&&
775 // don't know the status
776 m_deviceStatus
== CEC_DEVICE_STATUS_UNKNOWN
||
777 // always poll the TV if it's marked as not present
778 (m_deviceStatus
== CEC_DEVICE_STATUS_NOT_PRESENT
&& m_iLogicalAddress
== CECDEVICE_TV
));
783 bool bPollAcked(false);
784 if (bNeedsPoll
&& NeedsPoll())
785 bPollAcked
= m_processor
->PollDevice(m_iLogicalAddress
);
787 status
= bPollAcked
? CEC_DEVICE_STATUS_PRESENT
: CEC_DEVICE_STATUS_NOT_PRESENT
;
788 SetDeviceStatus(status
);
794 void CCECBusDevice::SetDeviceStatus(const cec_bus_device_status newStatus
, cec_version libCECSpecVersion
/* = CEC_VERSION_1_4 */)
796 if (m_iLogicalAddress
== CECDEVICE_UNREGISTERED
)
800 CLockObject
lock(m_mutex
);
803 case CEC_DEVICE_STATUS_HANDLED_BY_LIBCEC
:
804 if (m_deviceStatus
!= newStatus
)
805 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "%s (%X): device status changed into 'handled by libCEC'", GetLogicalAddressName(), m_iLogicalAddress
);
806 SetPowerStatus (CEC_POWER_STATUS_ON
);
807 SetVendorId (CEC_VENDOR_UNKNOWN
);
808 SetMenuState (CEC_MENU_STATE_ACTIVATED
);
809 SetCecVersion (libCECSpecVersion
);
810 SetStreamPath (CEC_INVALID_PHYSICAL_ADDRESS
);
811 MarkAsInactiveSource();
813 m_deviceStatus
= newStatus
;
815 case CEC_DEVICE_STATUS_PRESENT
:
816 if (m_deviceStatus
!= newStatus
)
817 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "%s (%X): device status changed into 'present'", GetLogicalAddressName(), m_iLogicalAddress
);
818 m_deviceStatus
= newStatus
;
819 m_iLastActive
= GetTimeMs();
821 case CEC_DEVICE_STATUS_NOT_PRESENT
:
822 if (m_deviceStatus
!= newStatus
)
824 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "%s (%X): device status changed into 'not present'", GetLogicalAddressName(), m_iLogicalAddress
);
825 ResetDeviceStatus(true);
826 m_deviceStatus
= newStatus
;
836 void CCECBusDevice::ResetDeviceStatus(bool bClientUnregistered
/* = false */)
838 CLockObject
lock(m_mutex
);
839 SetPowerStatus (CEC_POWER_STATUS_UNKNOWN
);
840 SetVendorId (CEC_VENDOR_UNKNOWN
);
841 SetMenuState (CEC_MENU_STATE_ACTIVATED
);
842 SetCecVersion (CEC_VERSION_UNKNOWN
);
843 SetStreamPath (CEC_INVALID_PHYSICAL_ADDRESS
);
844 SetOSDName (ToString(m_iLogicalAddress
));
845 MarkAsInactiveSource(bClientUnregistered
);
848 m_bVendorIdRequested
= false;
849 m_unsupportedFeatures
.clear();
850 m_waitForResponse
->Clear();
852 if (m_deviceStatus
!= CEC_DEVICE_STATUS_UNKNOWN
)
853 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "%s (%X): device status changed into 'unknown'", GetLogicalAddressName(), m_iLogicalAddress
);
854 m_deviceStatus
= CEC_DEVICE_STATUS_UNKNOWN
;
857 bool CCECBusDevice::TransmitPoll(const cec_logical_address dest
, bool bUpdateDeviceStatus
)
860 cec_logical_address
destination(dest
);
861 if (destination
== CECDEVICE_UNKNOWN
)
862 destination
= m_iLogicalAddress
;
864 CCECBusDevice
*destDevice
= m_processor
->GetDevice(destination
);
865 if (destDevice
->m_deviceStatus
== CEC_DEVICE_STATUS_HANDLED_BY_LIBCEC
)
869 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "<< %s (%X) -> %s (%X): POLL", GetLogicalAddressName(), m_iLogicalAddress
, ToString(dest
), dest
);
870 bReturn
= m_handler
->TransmitPoll(m_iLogicalAddress
, destination
, false);
871 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, bReturn
? ">> POLL sent" : ">> POLL not sent");
873 if (bUpdateDeviceStatus
)
874 destDevice
->SetDeviceStatus(bReturn
? CEC_DEVICE_STATUS_PRESENT
: CEC_DEVICE_STATUS_NOT_PRESENT
);
880 void CCECBusDevice::HandlePoll(const cec_logical_address destination
)
882 if (destination
>= 0 && destination
< CECDEVICE_BROADCAST
)
884 CCECBusDevice
*device
= m_processor
->GetDevice(destination
);
886 device
->HandlePollFrom(m_iLogicalAddress
);
890 void CCECBusDevice::HandlePollFrom(const cec_logical_address initiator
)
892 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "<< POLL: %s (%x) -> %s (%x)", ToString(initiator
), initiator
, ToString(m_iLogicalAddress
), m_iLogicalAddress
);
893 m_bAwaitingReceiveFailed
= true;
896 bool CCECBusDevice::HandleReceiveFailed(void)
898 bool bReturn
= m_bAwaitingReceiveFailed
;
899 m_bAwaitingReceiveFailed
= false;
903 cec_menu_state
CCECBusDevice::GetMenuState(const cec_logical_address
UNUSED(initiator
))
905 CLockObject
lock(m_mutex
);
909 void CCECBusDevice::SetMenuState(const cec_menu_state state
)
911 CLockObject
lock(m_mutex
);
912 if (m_menuState
!= state
)
914 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "%s (%X): menu state set to '%s'", GetLogicalAddressName(), m_iLogicalAddress
, ToString(m_menuState
));
919 bool CCECBusDevice::TransmitMenuState(const cec_logical_address dest
, bool bIsReply
)
921 cec_menu_state menuState
;
923 CLockObject
lock(m_mutex
);
924 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "<< %s (%X) -> %s (%X): menu state '%s'", GetLogicalAddressName(), m_iLogicalAddress
, ToString(dest
), dest
, ToString(m_menuState
));
925 menuState
= m_menuState
;
929 bool bReturn
= m_handler
->TransmitMenuState(m_iLogicalAddress
, dest
, menuState
, bIsReply
);
934 bool CCECBusDevice::ActivateSource(uint64_t iDelay
/* = 0 */)
936 MarkAsActiveSource();
941 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "sending active source message for '%s'", ToString(m_iLogicalAddress
));
942 bReturn
= m_handler
->ActivateSource();
946 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "scheduling active source message for '%s'", ToString(m_iLogicalAddress
));
947 m_handler
->ScheduleActivateSource(iDelay
);
953 bool CCECBusDevice::RequestActiveSource(bool bWaitForResponse
/* = true */)
957 if (IsHandledByLibCEC())
960 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "<< requesting active source");
962 bReturn
= m_handler
->TransmitRequestActiveSource(m_iLogicalAddress
, bWaitForResponse
);
968 void CCECBusDevice::MarkAsActiveSource(void)
970 bool bWasActivated(false);
972 // set the power status to powered on
973 SetPowerStatus(CEC_POWER_STATUS_ON
);
975 // mark this device as active source
977 CLockObject
lock(m_mutex
);
978 if (!m_bActiveSource
)
980 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "making %s (%x) the active source", GetLogicalAddressName(), m_iLogicalAddress
);
981 bWasActivated
= true;
984 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "%s (%x) was already marked as active source", GetLogicalAddressName(), m_iLogicalAddress
);
986 m_bActiveSource
= true;
989 CCECBusDevice
* tv
= m_processor
->GetDevice(CECDEVICE_TV
);
991 tv
->OnImageViewOnSent(false);
993 // mark other devices as inactive sources
994 CECDEVICEVEC devices
;
995 m_processor
->GetDevices()->Get(devices
);
996 for (CECDEVICEVEC::iterator it
= devices
.begin(); it
!= devices
.end(); it
++)
997 if ((*it
)->GetLogicalAddress() != m_iLogicalAddress
)
998 (*it
)->MarkAsInactiveSource();
1002 if (IsHandledByLibCEC())
1003 m_processor
->SetActiveSource(true, false);
1004 CCECClient
*client
= GetClient();
1006 client
->SourceActivated(m_iLogicalAddress
);
1010 void CCECBusDevice::MarkAsInactiveSource(bool bClientUnregistered
/* = false */)
1012 bool bWasDeactivated(false);
1014 CLockObject
lock(m_mutex
);
1015 if (m_bActiveSource
)
1017 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "marking %s (%X) as inactive source", GetLogicalAddressName(), m_iLogicalAddress
);
1018 bWasDeactivated
= true;
1020 m_bActiveSource
= false;
1023 if (bWasDeactivated
)
1025 if (IsHandledByLibCEC())
1026 m_processor
->SetActiveSource(false, bClientUnregistered
);
1027 CCECClient
*client
= GetClient();
1029 client
->SourceDeactivated(m_iLogicalAddress
);
1033 bool CCECBusDevice::TransmitActiveSource(bool bIsReply
)
1035 bool bSendActiveSource(false);
1036 uint16_t iPhysicalAddress(CEC_INVALID_PHYSICAL_ADDRESS
);
1039 CLockObject
lock(m_mutex
);
1040 if (!HasValidPhysicalAddress())
1042 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "%s (%X) has an invalid physical address (%04x), not sending active source commands", GetLogicalAddressName(), m_iLogicalAddress
, m_iPhysicalAddress
);
1046 iPhysicalAddress
= m_iPhysicalAddress
;
1048 if (m_powerStatus
!= CEC_POWER_STATUS_ON
&& m_powerStatus
!= CEC_POWER_STATUS_IN_TRANSITION_STANDBY_TO_ON
)
1049 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "<< %s (%X) is not powered on", GetLogicalAddressName(), m_iLogicalAddress
);
1050 else if (m_bActiveSource
)
1052 LIB_CEC
->AddLog(CEC_LOG_NOTICE
, "<< %s (%X) -> broadcast (F): active source (%4x)", GetLogicalAddressName(), m_iLogicalAddress
, m_iPhysicalAddress
);
1053 bSendActiveSource
= true;
1056 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "<< %s (%X) is not the active source", GetLogicalAddressName(), m_iLogicalAddress
);
1059 bool bActiveSourceSent(false);
1060 if (bSendActiveSource
)
1063 bActiveSourceSent
= m_handler
->TransmitActiveSource(m_iLogicalAddress
, iPhysicalAddress
, bIsReply
);
1067 return bActiveSourceSent
;
1070 bool CCECBusDevice::TransmitImageViewOn(void)
1073 CLockObject
lock(m_mutex
);
1074 if (m_powerStatus
!= CEC_POWER_STATUS_ON
&& m_powerStatus
!= CEC_POWER_STATUS_IN_TRANSITION_STANDBY_TO_ON
)
1076 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "<< %s (%X) is not powered on", GetLogicalAddressName(), m_iLogicalAddress
);
1081 CCECBusDevice
* tv
= m_processor
->GetDevice(CECDEVICE_TV
);
1084 LIB_CEC
->AddLog(CEC_LOG_ERROR
, "%s - couldn't get TV instance", __FUNCTION__
);
1088 if (tv
->ImageViewOnSent())
1090 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "%s - 'image view on' already sent", __FUNCTION__
);
1094 bool bImageViewOnSent(false);
1096 bImageViewOnSent
= m_handler
->TransmitImageViewOn(m_iLogicalAddress
, CECDEVICE_TV
);
1099 if (bImageViewOnSent
)
1100 tv
->OnImageViewOnSent(true);
1102 return bImageViewOnSent
;
1105 bool CCECBusDevice::TransmitInactiveSource(void)
1107 uint16_t iPhysicalAddress
;
1109 CLockObject
lock(m_mutex
);
1110 LIB_CEC
->AddLog(CEC_LOG_NOTICE
, "<< %s (%X) -> broadcast (F): inactive source", GetLogicalAddressName(), m_iLogicalAddress
);
1111 iPhysicalAddress
= m_iPhysicalAddress
;
1115 bool bReturn
= m_handler
->TransmitInactiveSource(m_iLogicalAddress
, iPhysicalAddress
);
1120 bool CCECBusDevice::TransmitPendingActiveSourceCommands(void)
1123 bool bReturn
= m_handler
->ActivateSource(true);
1128 void CCECBusDevice::SetActiveRoute(uint16_t iRoute
)
1130 SetPowerStatus(CEC_POWER_STATUS_ON
);
1132 CCECDeviceMap
* map
= m_processor
->GetDevices();
1136 CCECBusDevice
* newRoute
= m_processor
->GetDeviceByPhysicalAddress(iRoute
, true);
1137 if (newRoute
&& newRoute
->IsHandledByLibCEC())
1138 newRoute
->ActivateSource();
1141 void CCECBusDevice::SetStreamPath(uint16_t iNewAddress
, uint16_t iOldAddress
/* = CEC_INVALID_PHYSICAL_ADDRESS */)
1143 if (iNewAddress
!= CEC_INVALID_PHYSICAL_ADDRESS
)
1144 SetPowerStatus(CEC_POWER_STATUS_ON
);
1146 CLockObject
lock(m_mutex
);
1147 if (iNewAddress
!= m_iStreamPath
)
1149 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "%s (%X): stream path changed from %04x to %04x", GetLogicalAddressName(), m_iLogicalAddress
, iOldAddress
== 0 ? m_iStreamPath
: iOldAddress
, iNewAddress
);
1150 m_iStreamPath
= iNewAddress
;
1153 if (!LIB_CEC
->IsValidPhysicalAddress(iNewAddress
))
1156 CCECBusDevice
*device
= m_processor
->GetDeviceByPhysicalAddress(iNewAddress
);
1159 // if a device is found with the new physical address, mark it as active, which will automatically mark all other devices as inactive
1160 device
->MarkAsActiveSource();
1162 // respond with an active source message if this device is handled by libCEC
1163 if (device
->IsHandledByLibCEC())
1164 device
->TransmitActiveSource(true);
1168 // try to find the device with the old address, and mark it as inactive when found
1169 device
= m_processor
->GetDeviceByPhysicalAddress(iOldAddress
);
1171 device
->MarkAsInactiveSource();
1175 bool CCECBusDevice::PowerOn(const cec_logical_address initiator
)
1177 bool bReturn(false);
1178 GetVendorId(initiator
); // ensure that we got the vendor id, because the implementations vary per vendor
1181 cec_power_status currentStatus
;
1182 if (m_iLogicalAddress
== CECDEVICE_TV
||
1183 ((currentStatus
= GetPowerStatus(initiator
, false)) != CEC_POWER_STATUS_IN_TRANSITION_STANDBY_TO_ON
&&
1184 currentStatus
!= CEC_POWER_STATUS_ON
))
1186 LIB_CEC
->AddLog(CEC_LOG_NOTICE
, "<< powering on '%s' (%X)", GetLogicalAddressName(), m_iLogicalAddress
);
1187 bReturn
= m_handler
->PowerOn(initiator
, m_iLogicalAddress
);
1191 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "'%s' (%X) is already '%s'", GetLogicalAddressName(), m_iLogicalAddress
, ToString(currentStatus
));
1198 bool CCECBusDevice::Standby(const cec_logical_address initiator
)
1200 GetVendorId(initiator
); // ensure that we got the vendor id, because the implementations vary per vendor
1202 LIB_CEC
->AddLog(CEC_LOG_NOTICE
, "<< putting '%s' (%X) in standby mode", GetLogicalAddressName(), m_iLogicalAddress
);
1204 bool bReturn
= m_handler
->TransmitStandby(initiator
, m_iLogicalAddress
);
1209 bool CCECBusDevice::NeedsPoll(void)
1211 bool bSendPoll(false);
1212 cec_logical_address
pollAddress(CECDEVICE_UNKNOWN
);
1213 switch (m_iLogicalAddress
)
1215 case CECDEVICE_PLAYBACKDEVICE3
:
1216 pollAddress
= CECDEVICE_PLAYBACKDEVICE2
;
1218 case CECDEVICE_PLAYBACKDEVICE2
:
1219 pollAddress
= CECDEVICE_PLAYBACKDEVICE1
;
1221 case CECDEVICE_RECORDINGDEVICE3
:
1222 pollAddress
= CECDEVICE_RECORDINGDEVICE2
;
1224 case CECDEVICE_RECORDINGDEVICE2
:
1225 pollAddress
= CECDEVICE_RECORDINGDEVICE1
;
1227 case CECDEVICE_TUNER4
:
1228 pollAddress
= CECDEVICE_TUNER3
;
1230 case CECDEVICE_TUNER3
:
1231 pollAddress
= CECDEVICE_TUNER2
;
1233 case CECDEVICE_TUNER2
:
1234 pollAddress
= CECDEVICE_TUNER1
;
1236 case CECDEVICE_AUDIOSYSTEM
:
1237 case CECDEVICE_PLAYBACKDEVICE1
:
1238 case CECDEVICE_RECORDINGDEVICE1
:
1239 case CECDEVICE_TUNER1
:
1247 if (!bSendPoll
&& pollAddress
!= CECDEVICE_UNKNOWN
)
1249 CCECBusDevice
*device
= m_processor
->GetDevice(pollAddress
);
1252 cec_bus_device_status status
= device
->GetStatus();
1253 bSendPoll
= (status
== CEC_DEVICE_STATUS_PRESENT
|| status
== CEC_DEVICE_STATUS_HANDLED_BY_LIBCEC
);
1264 void CCECBusDevice::CheckVendorIdRequested(const cec_logical_address initiator
)
1266 bool bRequestVendorId(false);
1268 CLockObject
lock(m_mutex
);
1269 bRequestVendorId
= !m_bVendorIdRequested
;
1270 m_bVendorIdRequested
= true;
1273 if (bRequestVendorId
)
1275 ReplaceHandler(false);
1276 GetVendorId(initiator
);
1281 CCECAudioSystem
*CCECBusDevice::AsAudioSystem(void)
1283 return AsAudioSystem(this);
1286 CCECPlaybackDevice
*CCECBusDevice::AsPlaybackDevice(void)
1288 return AsPlaybackDevice(this);
1291 CCECRecordingDevice
*CCECBusDevice::AsRecordingDevice(void)
1293 return AsRecordingDevice(this);
1296 CCECTuner
*CCECBusDevice::AsTuner(void)
1298 return AsTuner(this);
1301 CCECTV
*CCECBusDevice::AsTV(void)
1306 CCECAudioSystem
*CCECBusDevice::AsAudioSystem(CCECBusDevice
*device
)
1308 if (device
&& device
->GetType() == CEC_DEVICE_TYPE_AUDIO_SYSTEM
)
1309 return static_cast<CCECAudioSystem
*>(device
);
1313 CCECPlaybackDevice
*CCECBusDevice::AsPlaybackDevice(CCECBusDevice
*device
)
1316 (device
->GetType() == CEC_DEVICE_TYPE_PLAYBACK_DEVICE
||
1317 device
->GetType() == CEC_DEVICE_TYPE_RECORDING_DEVICE
))
1318 return static_cast<CCECPlaybackDevice
*>(device
);
1322 CCECRecordingDevice
*CCECBusDevice::AsRecordingDevice(CCECBusDevice
*device
)
1324 if (device
&& device
->GetType() == CEC_DEVICE_TYPE_RECORDING_DEVICE
)
1325 return static_cast<CCECRecordingDevice
*>(device
);
1329 CCECTuner
*CCECBusDevice::AsTuner(CCECBusDevice
*device
)
1331 if (device
&& device
->GetType() == CEC_DEVICE_TYPE_TUNER
)
1332 return static_cast<CCECTuner
*>(device
);
1336 CCECTV
*CCECBusDevice::AsTV(CCECBusDevice
*device
)
1338 if (device
&& device
->GetType() == CEC_DEVICE_TYPE_TV
)
1339 return static_cast<CCECTV
*>(device
);
1343 void CCECBusDevice::MarkBusy(void)
1345 CLockObject
handlerLock(m_handlerMutex
);
1346 ++m_iHandlerUseCount
;
1349 void CCECBusDevice::MarkReady(void)
1351 CLockObject
handlerLock(m_handlerMutex
);
1352 if (m_iHandlerUseCount
> 0)
1353 --m_iHandlerUseCount
;
1356 bool CCECBusDevice::TryLogicalAddress(cec_version libCECSpecVersion
/* = CEC_VERSION_1_4 */)
1358 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "trying logical address '%s'", GetLogicalAddressName());
1360 if (!TransmitPoll(m_iLogicalAddress
, false))
1362 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "using logical address '%s'", GetLogicalAddressName());
1363 SetDeviceStatus(CEC_DEVICE_STATUS_HANDLED_BY_LIBCEC
, libCECSpecVersion
);
1368 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "logical address '%s' already taken", GetLogicalAddressName());
1369 SetDeviceStatus(CEC_DEVICE_STATUS_PRESENT
);
1373 CCECClient
*CCECBusDevice::GetClient(void)
1375 return m_processor
->GetClient(m_iLogicalAddress
);
1378 void CCECBusDevice::SignalOpcode(cec_opcode opcode
)
1380 m_waitForResponse
->Received(opcode
);
1383 bool CCECBusDevice::WaitForOpcode(cec_opcode opcode
)
1385 return m_waitForResponse
->Wait(opcode
);