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
)
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];
404 if (lang
[0] == '?' && lang
[1] == '?' && lang
[2] == '?')
406 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "<< %s (%X) -> %s (%X): menu language feature abort", GetLogicalAddressName(), m_iLogicalAddress
, ToString(destination
), destination
);
407 m_processor
->TransmitAbort(m_iLogicalAddress
, destination
, CEC_OPCODE_GIVE_DEVICE_VENDOR_ID
);
412 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "<< %s (%X) -> broadcast (F): menu language '%s'", GetLogicalAddressName(), m_iLogicalAddress
, lang
);
413 bReturn
= m_handler
->TransmitSetMenuLanguage(m_iLogicalAddress
, lang
, bIsReply
);
419 bool CCECBusDevice::TransmitOSDString(const cec_logical_address destination
, cec_display_control duration
, const char *strMessage
, bool bIsReply
)
422 if (!m_processor
->GetDevice(destination
)->IsUnsupportedFeature(CEC_OPCODE_SET_OSD_STRING
))
424 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "<< %s (%X) -> %s (%X): display OSD message '%s'", GetLogicalAddressName(), m_iLogicalAddress
, ToString(destination
), destination
, strMessage
);
426 bReturn
= m_handler
->TransmitOSDString(m_iLogicalAddress
, destination
, duration
, strMessage
, bIsReply
);
432 CStdString
CCECBusDevice::GetCurrentOSDName(void)
434 CLockObject
lock(m_mutex
);
435 return m_strDeviceName
;
438 CStdString
CCECBusDevice::GetOSDName(const cec_logical_address initiator
, bool bUpdate
/* = false */)
440 bool bIsPresent(GetStatus() == CEC_DEVICE_STATUS_PRESENT
);
441 bool bRequestUpdate(false);
443 CLockObject
lock(m_mutex
);
444 bRequestUpdate
= bIsPresent
&&
445 (bUpdate
|| m_strDeviceName
.Equals(ToString(m_iLogicalAddress
))) &&
446 m_type
!= CEC_DEVICE_TYPE_TV
;
451 CheckVendorIdRequested(initiator
);
452 RequestOSDName(initiator
);
455 CLockObject
lock(m_mutex
);
456 return m_strDeviceName
;
459 void CCECBusDevice::SetOSDName(CStdString strName
)
461 CLockObject
lock(m_mutex
);
462 if (m_strDeviceName
!= strName
)
464 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "%s (%X): osd name set to '%s'", GetLogicalAddressName(), m_iLogicalAddress
, strName
.c_str());
465 m_strDeviceName
= strName
;
469 bool CCECBusDevice::RequestOSDName(const cec_logical_address initiator
, bool bWaitForResponse
/* = true */)
473 if (!IsHandledByLibCEC() &&
474 !IsUnsupportedFeature(CEC_OPCODE_GIVE_OSD_NAME
))
477 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "<< requesting OSD name of '%s' (%X)", GetLogicalAddressName(), m_iLogicalAddress
);
478 bReturn
= m_handler
->TransmitRequestOSDName(initiator
, m_iLogicalAddress
, bWaitForResponse
);
484 bool CCECBusDevice::TransmitOSDName(const cec_logical_address destination
, bool bIsReply
)
486 CStdString strDeviceName
;
488 CLockObject
lock(m_mutex
);
489 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "<< %s (%X) -> %s (%X): OSD name '%s'", GetLogicalAddressName(), m_iLogicalAddress
, ToString(destination
), destination
, m_strDeviceName
.c_str());
490 strDeviceName
= m_strDeviceName
;
494 bool bReturn
= m_handler
->TransmitOSDName(m_iLogicalAddress
, destination
, strDeviceName
, bIsReply
);
499 bool CCECBusDevice::HasValidPhysicalAddress(void)
501 CLockObject
lock(m_mutex
);
502 return CLibCEC::IsValidPhysicalAddress(m_iPhysicalAddress
);
505 uint16_t CCECBusDevice::GetCurrentPhysicalAddress(void)
507 CLockObject
lock(m_mutex
);
508 return m_iPhysicalAddress
;
511 uint16_t CCECBusDevice::GetPhysicalAddress(const cec_logical_address initiator
, bool bSuppressUpdate
/* = false */)
513 if (!bSuppressUpdate
)
515 bool bIsPresent(GetStatus() == CEC_DEVICE_STATUS_PRESENT
);
516 bool bRequestUpdate(false);
518 CLockObject
lock(m_mutex
);
519 bRequestUpdate
= bIsPresent
&& m_iPhysicalAddress
== CEC_INVALID_PHYSICAL_ADDRESS
;
524 CheckVendorIdRequested(initiator
);
525 if (!RequestPhysicalAddress(initiator
))
526 LIB_CEC
->AddLog(CEC_LOG_ERROR
, "failed to request the physical address");
530 CLockObject
lock(m_mutex
);
531 return m_iPhysicalAddress
;
534 bool CCECBusDevice::SetPhysicalAddress(uint16_t iNewAddress
)
536 CLockObject
lock(m_mutex
);
537 if (iNewAddress
> 0 && m_iPhysicalAddress
!= iNewAddress
)
539 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "%s (%X): physical address changed from %04x to %04x", GetLogicalAddressName(), m_iLogicalAddress
, m_iPhysicalAddress
, iNewAddress
);
540 m_iPhysicalAddress
= iNewAddress
;
545 bool CCECBusDevice::RequestPhysicalAddress(const cec_logical_address initiator
, bool bWaitForResponse
/* = true */)
549 if (!IsHandledByLibCEC())
552 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "<< requesting physical address of '%s' (%X)", GetLogicalAddressName(), m_iLogicalAddress
);
553 bReturn
= m_handler
->TransmitRequestPhysicalAddress(initiator
, m_iLogicalAddress
, bWaitForResponse
);
559 bool CCECBusDevice::TransmitPhysicalAddress(bool bIsReply
)
561 uint16_t iPhysicalAddress
;
562 cec_device_type type
;
564 CLockObject
lock(m_mutex
);
565 if (m_iPhysicalAddress
== CEC_INVALID_PHYSICAL_ADDRESS
)
568 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "<< %s (%X) -> broadcast (F): physical adddress %4x", GetLogicalAddressName(), m_iLogicalAddress
, m_iPhysicalAddress
);
569 iPhysicalAddress
= m_iPhysicalAddress
;
574 bool bReturn
= m_handler
->TransmitPhysicalAddress(m_iLogicalAddress
, iPhysicalAddress
, type
, bIsReply
);
579 cec_power_status
CCECBusDevice::GetCurrentPowerStatus(void)
581 CLockObject
lock(m_mutex
);
582 return m_powerStatus
;
585 cec_power_status
CCECBusDevice::GetPowerStatus(const cec_logical_address initiator
, bool bUpdate
/* = false */)
587 bool bIsPresent(GetStatus() == CEC_DEVICE_STATUS_PRESENT
);
588 bool bRequestUpdate(false);
590 CLockObject
lock(m_mutex
);
591 bRequestUpdate
= (bIsPresent
&&
592 (bUpdate
|| m_powerStatus
== CEC_POWER_STATUS_UNKNOWN
||
593 m_powerStatus
== CEC_POWER_STATUS_IN_TRANSITION_STANDBY_TO_ON
||
594 m_powerStatus
== CEC_POWER_STATUS_IN_TRANSITION_ON_TO_STANDBY
||
595 GetTimeMs() - m_iLastPowerStateUpdate
>= CEC_POWER_STATE_REFRESH_TIME
));
600 CheckVendorIdRequested(initiator
);
601 RequestPowerStatus(initiator
);
604 CLockObject
lock(m_mutex
);
605 return m_powerStatus
;
608 void CCECBusDevice::SetPowerStatus(const cec_power_status powerStatus
)
610 CLockObject
lock(m_mutex
);
611 if (m_powerStatus
!= powerStatus
)
613 m_iLastPowerStateUpdate
= GetTimeMs();
614 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "%s (%X): power status changed from '%s' to '%s'", GetLogicalAddressName(), m_iLogicalAddress
, ToString(m_powerStatus
), ToString(powerStatus
));
615 m_powerStatus
= powerStatus
;
619 void CCECBusDevice::OnImageViewOnSent(bool bSentByLibCEC
)
621 CLockObject
lock(m_mutex
);
622 m_bImageViewOnSent
= bSentByLibCEC
;
624 if (m_powerStatus
!= CEC_POWER_STATUS_ON
&& m_powerStatus
!= CEC_POWER_STATUS_IN_TRANSITION_STANDBY_TO_ON
)
626 m_iLastPowerStateUpdate
= GetTimeMs();
627 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
));
628 m_powerStatus
= CEC_POWER_STATUS_IN_TRANSITION_STANDBY_TO_ON
;
632 bool CCECBusDevice::ImageViewOnSent(void)
634 CLockObject
lock(m_mutex
);
635 return m_bImageViewOnSent
;
638 bool CCECBusDevice::RequestPowerStatus(const cec_logical_address initiator
, bool bWaitForResponse
/* = true */)
642 if (!IsHandledByLibCEC() &&
643 !IsUnsupportedFeature(CEC_OPCODE_GIVE_DEVICE_POWER_STATUS
))
646 bReturn
= m_handler
->TransmitRequestPowerStatus(initiator
, m_iLogicalAddress
, bWaitForResponse
);
648 SetPowerStatus(CEC_POWER_STATUS_UNKNOWN
);
654 bool CCECBusDevice::TransmitPowerState(const cec_logical_address destination
, bool bIsReply
)
656 cec_power_status state
;
658 CLockObject
lock(m_mutex
);
659 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "<< %s (%X) -> %s (%X): %s", GetLogicalAddressName(), m_iLogicalAddress
, ToString(destination
), destination
, ToString(m_powerStatus
));
660 state
= m_powerStatus
;
664 bool bReturn
= m_handler
->TransmitPowerState(m_iLogicalAddress
, destination
, state
, bIsReply
);
669 cec_vendor_id
CCECBusDevice::GetCurrentVendorId(void)
671 CLockObject
lock(m_mutex
);
675 cec_vendor_id
CCECBusDevice::GetVendorId(const cec_logical_address initiator
, bool bUpdate
/* = false */)
677 bool bIsPresent(GetStatus() == CEC_DEVICE_STATUS_PRESENT
);
678 bool bRequestUpdate(false);
680 CLockObject
lock(m_mutex
);
681 bRequestUpdate
= (bIsPresent
&&
682 (bUpdate
|| m_vendor
== CEC_VENDOR_UNKNOWN
));
686 RequestVendorId(initiator
);
688 CLockObject
lock(m_mutex
);
692 const char *CCECBusDevice::GetVendorName(const cec_logical_address initiator
, bool bUpdate
/* = false */)
694 return ToString(GetVendorId(initiator
, bUpdate
));
697 bool CCECBusDevice::SetVendorId(uint64_t iVendorId
)
699 bool bVendorChanged(false);
702 CLockObject
lock(m_mutex
);
703 bVendorChanged
= (m_vendor
!= (cec_vendor_id
)iVendorId
);
704 m_vendor
= (cec_vendor_id
)iVendorId
;
708 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "%s (%X): vendor = %s (%06x)", GetLogicalAddressName(), m_iLogicalAddress
, ToString(m_vendor
), m_vendor
);
710 return bVendorChanged
;
713 bool CCECBusDevice::RequestVendorId(const cec_logical_address initiator
, bool bWaitForResponse
/* = true */)
717 if (!IsHandledByLibCEC() && initiator
!= CECDEVICE_UNKNOWN
)
720 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "<< requesting vendor ID of '%s' (%X)", GetLogicalAddressName(), m_iLogicalAddress
);
721 bReturn
= m_handler
->TransmitRequestVendorId(initiator
, m_iLogicalAddress
, bWaitForResponse
);
724 if (bWaitForResponse
)
725 ReplaceHandler(true);
730 bool CCECBusDevice::TransmitVendorID(const cec_logical_address destination
, bool bSendAbort
, bool bIsReply
)
735 CLockObject
lock(m_mutex
);
736 iVendorId
= (uint64_t)m_vendor
;
740 if (iVendorId
== CEC_VENDOR_UNKNOWN
)
744 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "<< %s (%X) -> %s (%X): vendor id feature abort", GetLogicalAddressName(), m_iLogicalAddress
, ToString(destination
), destination
);
745 m_processor
->TransmitAbort(m_iLogicalAddress
, destination
, CEC_OPCODE_GIVE_DEVICE_VENDOR_ID
);
751 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
);
752 bReturn
= m_handler
->TransmitVendorID(m_iLogicalAddress
, destination
, iVendorId
, bIsReply
);
758 cec_bus_device_status
CCECBusDevice::GetStatus(bool bForcePoll
/* = false */, bool bSuppressPoll
/* = false */)
760 if (m_iLogicalAddress
== CECDEVICE_BROADCAST
)
761 return CEC_DEVICE_STATUS_NOT_PRESENT
;
763 cec_bus_device_status
status(CEC_DEVICE_STATUS_UNKNOWN
);
764 bool bNeedsPoll(false);
767 CLockObject
lock(m_mutex
);
768 status
= m_deviceStatus
;
769 bNeedsPoll
= !bSuppressPoll
&&
770 m_deviceStatus
!= CEC_DEVICE_STATUS_HANDLED_BY_LIBCEC
&&
773 // don't know the status
774 m_deviceStatus
== CEC_DEVICE_STATUS_UNKNOWN
||
775 // always poll the TV if it's marked as not present
776 (m_deviceStatus
== CEC_DEVICE_STATUS_NOT_PRESENT
&& m_iLogicalAddress
== CECDEVICE_TV
));
781 bool bPollAcked(false);
782 if (bNeedsPoll
&& NeedsPoll())
783 bPollAcked
= m_processor
->PollDevice(m_iLogicalAddress
);
785 status
= bPollAcked
? CEC_DEVICE_STATUS_PRESENT
: CEC_DEVICE_STATUS_NOT_PRESENT
;
786 SetDeviceStatus(status
);
792 void CCECBusDevice::SetDeviceStatus(const cec_bus_device_status newStatus
, cec_version libCECSpecVersion
/* = CEC_VERSION_1_4 */)
794 if (m_iLogicalAddress
== CECDEVICE_UNREGISTERED
)
798 CLockObject
lock(m_mutex
);
801 case CEC_DEVICE_STATUS_HANDLED_BY_LIBCEC
:
802 if (m_deviceStatus
!= newStatus
)
803 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "%s (%X): device status changed into 'handled by libCEC'", GetLogicalAddressName(), m_iLogicalAddress
);
804 SetPowerStatus (CEC_POWER_STATUS_ON
);
805 SetVendorId (CEC_VENDOR_UNKNOWN
);
806 SetMenuState (CEC_MENU_STATE_ACTIVATED
);
807 SetCecVersion (libCECSpecVersion
);
808 SetStreamPath (CEC_INVALID_PHYSICAL_ADDRESS
);
809 MarkAsInactiveSource();
811 m_deviceStatus
= newStatus
;
813 case CEC_DEVICE_STATUS_PRESENT
:
814 if (m_deviceStatus
!= newStatus
)
815 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "%s (%X): device status changed into 'present'", GetLogicalAddressName(), m_iLogicalAddress
);
816 m_deviceStatus
= newStatus
;
817 m_iLastActive
= GetTimeMs();
819 case CEC_DEVICE_STATUS_NOT_PRESENT
:
820 if (m_deviceStatus
!= newStatus
)
822 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "%s (%X): device status changed into 'not present'", GetLogicalAddressName(), m_iLogicalAddress
);
823 ResetDeviceStatus(true);
824 m_deviceStatus
= newStatus
;
834 void CCECBusDevice::ResetDeviceStatus(bool bClientUnregistered
/* = false */)
836 CLockObject
lock(m_mutex
);
837 SetPowerStatus (CEC_POWER_STATUS_UNKNOWN
);
838 SetVendorId (CEC_VENDOR_UNKNOWN
);
839 SetMenuState (CEC_MENU_STATE_ACTIVATED
);
840 SetCecVersion (CEC_VERSION_UNKNOWN
);
841 SetStreamPath (CEC_INVALID_PHYSICAL_ADDRESS
);
842 SetOSDName (ToString(m_iLogicalAddress
));
843 MarkAsInactiveSource(bClientUnregistered
);
846 m_bVendorIdRequested
= false;
847 m_unsupportedFeatures
.clear();
848 m_waitForResponse
->Clear();
850 if (m_deviceStatus
!= CEC_DEVICE_STATUS_UNKNOWN
)
851 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "%s (%X): device status changed into 'unknown'", GetLogicalAddressName(), m_iLogicalAddress
);
852 m_deviceStatus
= CEC_DEVICE_STATUS_UNKNOWN
;
855 bool CCECBusDevice::TransmitPoll(const cec_logical_address dest
, bool bUpdateDeviceStatus
)
858 cec_logical_address
destination(dest
);
859 if (destination
== CECDEVICE_UNKNOWN
)
860 destination
= m_iLogicalAddress
;
862 CCECBusDevice
*destDevice
= m_processor
->GetDevice(destination
);
863 if (destDevice
->m_deviceStatus
== CEC_DEVICE_STATUS_HANDLED_BY_LIBCEC
)
867 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "<< %s (%X) -> %s (%X): POLL", GetLogicalAddressName(), m_iLogicalAddress
, ToString(dest
), dest
);
868 bReturn
= m_handler
->TransmitPoll(m_iLogicalAddress
, destination
, false);
869 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, bReturn
? ">> POLL sent" : ">> POLL not sent");
871 if (bUpdateDeviceStatus
)
872 destDevice
->SetDeviceStatus(bReturn
? CEC_DEVICE_STATUS_PRESENT
: CEC_DEVICE_STATUS_NOT_PRESENT
);
878 void CCECBusDevice::HandlePoll(const cec_logical_address destination
)
880 if (destination
>= 0 && destination
< CECDEVICE_BROADCAST
)
882 CCECBusDevice
*device
= m_processor
->GetDevice(destination
);
884 device
->HandlePollFrom(m_iLogicalAddress
);
888 void CCECBusDevice::HandlePollFrom(const cec_logical_address initiator
)
890 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "<< POLL: %s (%x) -> %s (%x)", ToString(initiator
), initiator
, ToString(m_iLogicalAddress
), m_iLogicalAddress
);
891 m_bAwaitingReceiveFailed
= true;
894 bool CCECBusDevice::HandleReceiveFailed(void)
896 bool bReturn
= m_bAwaitingReceiveFailed
;
897 m_bAwaitingReceiveFailed
= false;
901 cec_menu_state
CCECBusDevice::GetMenuState(const cec_logical_address
UNUSED(initiator
))
903 CLockObject
lock(m_mutex
);
907 void CCECBusDevice::SetMenuState(const cec_menu_state state
)
909 CLockObject
lock(m_mutex
);
910 if (m_menuState
!= state
)
912 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "%s (%X): menu state set to '%s'", GetLogicalAddressName(), m_iLogicalAddress
, ToString(m_menuState
));
917 bool CCECBusDevice::TransmitMenuState(const cec_logical_address dest
, bool bIsReply
)
919 cec_menu_state menuState
;
921 CLockObject
lock(m_mutex
);
922 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "<< %s (%X) -> %s (%X): menu state '%s'", GetLogicalAddressName(), m_iLogicalAddress
, ToString(dest
), dest
, ToString(m_menuState
));
923 menuState
= m_menuState
;
927 bool bReturn
= m_handler
->TransmitMenuState(m_iLogicalAddress
, dest
, menuState
, bIsReply
);
932 bool CCECBusDevice::ActivateSource(uint64_t iDelay
/* = 0 */)
934 MarkAsActiveSource();
939 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "sending active source message for '%s'", ToString(m_iLogicalAddress
));
940 bReturn
= m_handler
->ActivateSource();
944 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "scheduling active source message for '%s'", ToString(m_iLogicalAddress
));
945 m_handler
->ScheduleActivateSource(iDelay
);
951 bool CCECBusDevice::RequestActiveSource(bool bWaitForResponse
/* = true */)
955 if (IsHandledByLibCEC())
958 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "<< requesting active source");
960 bReturn
= m_handler
->TransmitRequestActiveSource(m_iLogicalAddress
, bWaitForResponse
);
966 void CCECBusDevice::MarkAsActiveSource(void)
968 bool bWasActivated(false);
970 // set the power status to powered on
971 SetPowerStatus(CEC_POWER_STATUS_ON
);
973 // mark this device as active source
975 CLockObject
lock(m_mutex
);
976 if (!m_bActiveSource
)
978 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "making %s (%x) the active source", GetLogicalAddressName(), m_iLogicalAddress
);
979 bWasActivated
= true;
982 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "%s (%x) was already marked as active source", GetLogicalAddressName(), m_iLogicalAddress
);
984 m_bActiveSource
= true;
987 CCECBusDevice
* tv
= m_processor
->GetDevice(CECDEVICE_TV
);
989 tv
->OnImageViewOnSent(false);
991 // mark other devices as inactive sources
992 CECDEVICEVEC devices
;
993 m_processor
->GetDevices()->Get(devices
);
994 for (CECDEVICEVEC::iterator it
= devices
.begin(); it
!= devices
.end(); it
++)
995 if ((*it
)->GetLogicalAddress() != m_iLogicalAddress
)
996 (*it
)->MarkAsInactiveSource();
1000 if (IsHandledByLibCEC())
1001 m_processor
->SetActiveSource(true, false);
1002 CCECClient
*client
= GetClient();
1004 client
->SourceActivated(m_iLogicalAddress
);
1008 void CCECBusDevice::MarkAsInactiveSource(bool bClientUnregistered
/* = false */)
1010 bool bWasDeactivated(false);
1012 CLockObject
lock(m_mutex
);
1013 if (m_bActiveSource
)
1015 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "marking %s (%X) as inactive source", GetLogicalAddressName(), m_iLogicalAddress
);
1016 bWasDeactivated
= true;
1018 m_bActiveSource
= false;
1021 if (bWasDeactivated
)
1023 if (IsHandledByLibCEC())
1024 m_processor
->SetActiveSource(false, bClientUnregistered
);
1025 CCECClient
*client
= GetClient();
1027 client
->SourceDeactivated(m_iLogicalAddress
);
1031 bool CCECBusDevice::TransmitActiveSource(bool bIsReply
)
1033 bool bSendActiveSource(false);
1034 uint16_t iPhysicalAddress(CEC_INVALID_PHYSICAL_ADDRESS
);
1037 CLockObject
lock(m_mutex
);
1038 if (!HasValidPhysicalAddress())
1040 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "%s (%X) has an invalid physical address (%04x), not sending active source commands", GetLogicalAddressName(), m_iLogicalAddress
, m_iPhysicalAddress
);
1044 iPhysicalAddress
= m_iPhysicalAddress
;
1046 if (m_powerStatus
!= CEC_POWER_STATUS_ON
&& m_powerStatus
!= CEC_POWER_STATUS_IN_TRANSITION_STANDBY_TO_ON
)
1047 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "<< %s (%X) is not powered on", GetLogicalAddressName(), m_iLogicalAddress
);
1048 else if (m_bActiveSource
)
1050 LIB_CEC
->AddLog(CEC_LOG_NOTICE
, "<< %s (%X) -> broadcast (F): active source (%4x)", GetLogicalAddressName(), m_iLogicalAddress
, m_iPhysicalAddress
);
1051 bSendActiveSource
= true;
1054 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "<< %s (%X) is not the active source", GetLogicalAddressName(), m_iLogicalAddress
);
1057 bool bActiveSourceSent(false);
1058 if (bSendActiveSource
)
1061 bActiveSourceSent
= m_handler
->TransmitActiveSource(m_iLogicalAddress
, iPhysicalAddress
, bIsReply
);
1065 return bActiveSourceSent
;
1068 bool CCECBusDevice::TransmitImageViewOn(void)
1071 CLockObject
lock(m_mutex
);
1072 if (m_powerStatus
!= CEC_POWER_STATUS_ON
&& m_powerStatus
!= CEC_POWER_STATUS_IN_TRANSITION_STANDBY_TO_ON
)
1074 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "<< %s (%X) is not powered on", GetLogicalAddressName(), m_iLogicalAddress
);
1079 CCECBusDevice
* tv
= m_processor
->GetDevice(CECDEVICE_TV
);
1082 LIB_CEC
->AddLog(CEC_LOG_ERROR
, "%s - couldn't get TV instance", __FUNCTION__
);
1086 if (tv
->ImageViewOnSent())
1088 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "%s - 'image view on' already sent", __FUNCTION__
);
1092 bool bImageViewOnSent(false);
1094 bImageViewOnSent
= m_handler
->TransmitImageViewOn(m_iLogicalAddress
, CECDEVICE_TV
);
1097 if (bImageViewOnSent
)
1098 tv
->OnImageViewOnSent(true);
1100 return bImageViewOnSent
;
1103 bool CCECBusDevice::TransmitInactiveSource(void)
1105 uint16_t iPhysicalAddress
;
1107 CLockObject
lock(m_mutex
);
1108 LIB_CEC
->AddLog(CEC_LOG_NOTICE
, "<< %s (%X) -> broadcast (F): inactive source", GetLogicalAddressName(), m_iLogicalAddress
);
1109 iPhysicalAddress
= m_iPhysicalAddress
;
1113 bool bReturn
= m_handler
->TransmitInactiveSource(m_iLogicalAddress
, iPhysicalAddress
);
1118 bool CCECBusDevice::TransmitPendingActiveSourceCommands(void)
1121 bool bReturn
= m_handler
->ActivateSource(true);
1126 void CCECBusDevice::SetActiveRoute(uint16_t iRoute
)
1128 SetPowerStatus(CEC_POWER_STATUS_ON
);
1130 CCECDeviceMap
* map
= m_processor
->GetDevices();
1134 CCECBusDevice
* newRoute
= m_processor
->GetDeviceByPhysicalAddress(iRoute
, true);
1135 if (newRoute
&& newRoute
->IsHandledByLibCEC())
1136 newRoute
->ActivateSource();
1139 void CCECBusDevice::SetStreamPath(uint16_t iNewAddress
, uint16_t iOldAddress
/* = CEC_INVALID_PHYSICAL_ADDRESS */)
1141 if (iNewAddress
!= CEC_INVALID_PHYSICAL_ADDRESS
)
1142 SetPowerStatus(CEC_POWER_STATUS_ON
);
1144 CLockObject
lock(m_mutex
);
1145 if (iNewAddress
!= m_iStreamPath
)
1147 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "%s (%X): stream path changed from %04x to %04x", GetLogicalAddressName(), m_iLogicalAddress
, iOldAddress
== 0 ? m_iStreamPath
: iOldAddress
, iNewAddress
);
1148 m_iStreamPath
= iNewAddress
;
1151 if (!LIB_CEC
->IsValidPhysicalAddress(iNewAddress
))
1154 CCECBusDevice
*device
= m_processor
->GetDeviceByPhysicalAddress(iNewAddress
);
1157 // if a device is found with the new physical address, mark it as active, which will automatically mark all other devices as inactive
1158 device
->MarkAsActiveSource();
1160 // respond with an active source message if this device is handled by libCEC
1161 if (device
->IsHandledByLibCEC())
1162 device
->TransmitActiveSource(true);
1166 // try to find the device with the old address, and mark it as inactive when found
1167 device
= m_processor
->GetDeviceByPhysicalAddress(iOldAddress
);
1169 device
->MarkAsInactiveSource();
1173 bool CCECBusDevice::PowerOn(const cec_logical_address initiator
)
1175 bool bReturn(false);
1176 GetVendorId(initiator
); // ensure that we got the vendor id, because the implementations vary per vendor
1179 cec_power_status currentStatus
;
1180 if (m_iLogicalAddress
== CECDEVICE_TV
||
1181 ((currentStatus
= GetPowerStatus(initiator
, false)) != CEC_POWER_STATUS_IN_TRANSITION_STANDBY_TO_ON
&&
1182 currentStatus
!= CEC_POWER_STATUS_ON
))
1184 LIB_CEC
->AddLog(CEC_LOG_NOTICE
, "<< powering on '%s' (%X)", GetLogicalAddressName(), m_iLogicalAddress
);
1185 bReturn
= m_handler
->PowerOn(initiator
, m_iLogicalAddress
);
1189 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "'%s' (%X) is already '%s'", GetLogicalAddressName(), m_iLogicalAddress
, ToString(currentStatus
));
1196 bool CCECBusDevice::Standby(const cec_logical_address initiator
)
1198 GetVendorId(initiator
); // ensure that we got the vendor id, because the implementations vary per vendor
1200 LIB_CEC
->AddLog(CEC_LOG_NOTICE
, "<< putting '%s' (%X) in standby mode", GetLogicalAddressName(), m_iLogicalAddress
);
1202 bool bReturn
= m_handler
->TransmitStandby(initiator
, m_iLogicalAddress
);
1207 bool CCECBusDevice::NeedsPoll(void)
1209 bool bSendPoll(false);
1210 cec_logical_address
pollAddress(CECDEVICE_UNKNOWN
);
1211 switch (m_iLogicalAddress
)
1213 case CECDEVICE_PLAYBACKDEVICE3
:
1214 pollAddress
= CECDEVICE_PLAYBACKDEVICE2
;
1216 case CECDEVICE_PLAYBACKDEVICE2
:
1217 pollAddress
= CECDEVICE_PLAYBACKDEVICE1
;
1219 case CECDEVICE_RECORDINGDEVICE3
:
1220 pollAddress
= CECDEVICE_RECORDINGDEVICE2
;
1222 case CECDEVICE_RECORDINGDEVICE2
:
1223 pollAddress
= CECDEVICE_RECORDINGDEVICE1
;
1225 case CECDEVICE_TUNER4
:
1226 pollAddress
= CECDEVICE_TUNER3
;
1228 case CECDEVICE_TUNER3
:
1229 pollAddress
= CECDEVICE_TUNER2
;
1231 case CECDEVICE_TUNER2
:
1232 pollAddress
= CECDEVICE_TUNER1
;
1234 case CECDEVICE_AUDIOSYSTEM
:
1235 case CECDEVICE_PLAYBACKDEVICE1
:
1236 case CECDEVICE_RECORDINGDEVICE1
:
1237 case CECDEVICE_TUNER1
:
1245 if (!bSendPoll
&& pollAddress
!= CECDEVICE_UNKNOWN
)
1247 CCECBusDevice
*device
= m_processor
->GetDevice(pollAddress
);
1250 cec_bus_device_status status
= device
->GetStatus();
1251 bSendPoll
= (status
== CEC_DEVICE_STATUS_PRESENT
|| status
== CEC_DEVICE_STATUS_HANDLED_BY_LIBCEC
);
1262 void CCECBusDevice::CheckVendorIdRequested(const cec_logical_address initiator
)
1264 bool bRequestVendorId(false);
1266 CLockObject
lock(m_mutex
);
1267 bRequestVendorId
= !m_bVendorIdRequested
;
1268 m_bVendorIdRequested
= true;
1271 if (bRequestVendorId
)
1273 ReplaceHandler(false);
1274 GetVendorId(initiator
);
1279 CCECAudioSystem
*CCECBusDevice::AsAudioSystem(void)
1281 return AsAudioSystem(this);
1284 CCECPlaybackDevice
*CCECBusDevice::AsPlaybackDevice(void)
1286 return AsPlaybackDevice(this);
1289 CCECRecordingDevice
*CCECBusDevice::AsRecordingDevice(void)
1291 return AsRecordingDevice(this);
1294 CCECTuner
*CCECBusDevice::AsTuner(void)
1296 return AsTuner(this);
1299 CCECTV
*CCECBusDevice::AsTV(void)
1304 CCECAudioSystem
*CCECBusDevice::AsAudioSystem(CCECBusDevice
*device
)
1306 if (device
&& device
->GetType() == CEC_DEVICE_TYPE_AUDIO_SYSTEM
)
1307 return static_cast<CCECAudioSystem
*>(device
);
1311 CCECPlaybackDevice
*CCECBusDevice::AsPlaybackDevice(CCECBusDevice
*device
)
1314 (device
->GetType() == CEC_DEVICE_TYPE_PLAYBACK_DEVICE
||
1315 device
->GetType() == CEC_DEVICE_TYPE_RECORDING_DEVICE
))
1316 return static_cast<CCECPlaybackDevice
*>(device
);
1320 CCECRecordingDevice
*CCECBusDevice::AsRecordingDevice(CCECBusDevice
*device
)
1322 if (device
&& device
->GetType() == CEC_DEVICE_TYPE_RECORDING_DEVICE
)
1323 return static_cast<CCECRecordingDevice
*>(device
);
1327 CCECTuner
*CCECBusDevice::AsTuner(CCECBusDevice
*device
)
1329 if (device
&& device
->GetType() == CEC_DEVICE_TYPE_TUNER
)
1330 return static_cast<CCECTuner
*>(device
);
1334 CCECTV
*CCECBusDevice::AsTV(CCECBusDevice
*device
)
1336 if (device
&& device
->GetType() == CEC_DEVICE_TYPE_TV
)
1337 return static_cast<CCECTV
*>(device
);
1341 void CCECBusDevice::MarkBusy(void)
1343 CLockObject
handlerLock(m_handlerMutex
);
1344 ++m_iHandlerUseCount
;
1347 void CCECBusDevice::MarkReady(void)
1349 CLockObject
handlerLock(m_handlerMutex
);
1350 if (m_iHandlerUseCount
> 0)
1351 --m_iHandlerUseCount
;
1354 bool CCECBusDevice::TryLogicalAddress(cec_version libCECSpecVersion
/* = CEC_VERSION_1_4 */)
1356 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "trying logical address '%s'", GetLogicalAddressName());
1358 if (!TransmitPoll(m_iLogicalAddress
, false))
1360 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "using logical address '%s'", GetLogicalAddressName());
1361 SetDeviceStatus(CEC_DEVICE_STATUS_HANDLED_BY_LIBCEC
, libCECSpecVersion
);
1366 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "logical address '%s' already taken", GetLogicalAddressName());
1367 SetDeviceStatus(CEC_DEVICE_STATUS_PRESENT
);
1371 CCECClient
*CCECBusDevice::GetClient(void)
1373 return m_processor
->GetClient(m_iLogicalAddress
);
1376 void CCECBusDevice::SignalOpcode(cec_opcode opcode
)
1378 m_waitForResponse
->Received(opcode
);
1381 bool CCECBusDevice::WaitForOpcode(cec_opcode opcode
)
1383 return m_waitForResponse
->Wait(opcode
);