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 CResponse::CResponse(cec_opcode opcode
) :
69 CResponse::~CResponse(void)
74 bool CResponse::Wait(uint32_t iTimeout
)
76 return m_event
.Wait(iTimeout
);
79 void CResponse::Broadcast(void)
84 CWaitForResponse::CWaitForResponse(void)
88 CWaitForResponse::~CWaitForResponse(void)
93 void CWaitForResponse::Clear()
95 PLATFORM::CLockObject
lock(m_mutex
);
96 for (std::map
<cec_opcode
, CResponse
*>::iterator it
= m_waitingFor
.begin(); it
!= m_waitingFor
.end(); it
++)
98 it
->second
->Broadcast();
101 m_waitingFor
.clear();
104 bool CWaitForResponse::Wait(cec_opcode opcode
, uint32_t iTimeout
)
106 CResponse
*response
= GetEvent(opcode
);
107 return response
? response
->Wait(iTimeout
) : false;
110 void CWaitForResponse::Received(cec_opcode opcode
)
112 CResponse
*response
= GetEvent(opcode
);
114 response
->Broadcast();
117 CResponse
* CWaitForResponse::GetEvent(cec_opcode opcode
)
119 CResponse
*retVal(NULL
);
121 PLATFORM::CLockObject
lock(m_mutex
);
122 std::map
<cec_opcode
, CResponse
*>::iterator it
= m_waitingFor
.find(opcode
);
123 if (it
!= m_waitingFor
.end())
129 retVal
= new CResponse(opcode
);
130 m_waitingFor
[opcode
] = retVal
;
136 CCECBusDevice::CCECBusDevice(CCECProcessor
*processor
, cec_logical_address iLogicalAddress
, uint16_t iPhysicalAddress
/* = CEC_INVALID_PHYSICAL_ADDRESS */) :
137 m_type (CEC_DEVICE_TYPE_RESERVED
),
138 m_iPhysicalAddress (iPhysicalAddress
),
139 m_iStreamPath (CEC_INVALID_PHYSICAL_ADDRESS
),
140 m_iLogicalAddress (iLogicalAddress
),
141 m_powerStatus (CEC_POWER_STATUS_UNKNOWN
),
142 m_processor (processor
),
143 m_vendor (CEC_VENDOR_UNKNOWN
),
144 m_bReplaceHandler (false),
145 m_menuState (CEC_MENU_STATE_ACTIVATED
),
146 m_bActiveSource (false),
148 m_iLastPowerStateUpdate (0),
149 m_cecVersion (CEC_VERSION_UNKNOWN
),
150 m_deviceStatus (CEC_DEVICE_STATUS_UNKNOWN
),
151 m_iHandlerUseCount (0),
152 m_bAwaitingReceiveFailed(false),
153 m_bVendorIdRequested (false),
154 m_waitForResponse (new CWaitForResponse
),
155 m_bImageViewOnSent (false)
157 m_handler
= new CCECCommandHandler(this);
159 for (unsigned int iPtr
= 0; iPtr
< 4; iPtr
++)
160 m_menuLanguage
.language
[iPtr
] = '?';
161 m_menuLanguage
.language
[3] = 0;
162 m_menuLanguage
.device
= iLogicalAddress
;
164 m_strDeviceName
= ToString(m_iLogicalAddress
);
167 CCECBusDevice::~CCECBusDevice(void)
169 DELETE_AND_NULL(m_handler
);
170 DELETE_AND_NULL(m_waitForResponse
);
173 bool CCECBusDevice::ReplaceHandler(bool bActivateSource
/* = true */)
175 if (m_iLogicalAddress
== CECDEVICE_BROADCAST
)
178 bool bInitHandler(false);
180 CLockObject
lock(m_mutex
);
181 CLockObject
handlerLock(m_handlerMutex
);
182 if (m_iHandlerUseCount
> 0)
187 if (m_vendor
!= m_handler
->GetVendorId())
189 if (CCECCommandHandler::HasSpecificHandler(m_vendor
))
191 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "replacing the command handler for device '%s' (%x)", GetLogicalAddressName(), GetLogicalAddress());
193 int32_t iTransmitTimeout
= m_handler
->m_iTransmitTimeout
;
194 int32_t iTransmitWait
= m_handler
->m_iTransmitWait
;
195 int8_t iTransmitRetries
= m_handler
->m_iTransmitRetries
;
196 int64_t iActiveSourcePending
= m_handler
->m_iActiveSourcePending
;
198 DELETE_AND_NULL(m_handler
);
202 case CEC_VENDOR_SAMSUNG
:
203 m_handler
= new CANCommandHandler(this, iTransmitTimeout
, iTransmitWait
, iTransmitRetries
, iActiveSourcePending
);
206 m_handler
= new CSLCommandHandler(this, iTransmitTimeout
, iTransmitWait
, iTransmitRetries
, iActiveSourcePending
);
208 case CEC_VENDOR_PANASONIC
:
209 m_handler
= new CVLCommandHandler(this, iTransmitTimeout
, iTransmitWait
, iTransmitRetries
, iActiveSourcePending
);
211 case CEC_VENDOR_PHILIPS
:
212 m_handler
= new CPHCommandHandler(this, iTransmitTimeout
, iTransmitWait
, iTransmitRetries
, iActiveSourcePending
);
214 case CEC_VENDOR_TOSHIBA
:
215 case CEC_VENDOR_TOSHIBA2
:
216 m_handler
= new CRLCommandHandler(this, iTransmitTimeout
, iTransmitWait
, iTransmitRetries
, iActiveSourcePending
);
218 case CEC_VENDOR_ONKYO
:
219 m_handler
= new CRHCommandHandler(this, iTransmitTimeout
, iTransmitWait
, iTransmitRetries
, iActiveSourcePending
);
221 case CEC_VENDOR_SHARP
:
222 m_handler
= new CAQCommandHandler(this, iTransmitTimeout
, iTransmitWait
, iTransmitRetries
, iActiveSourcePending
);
225 m_handler
= new CCECCommandHandler(this, iTransmitTimeout
, iTransmitWait
, iTransmitRetries
, iActiveSourcePending
);
229 m_handler
->SetVendorId(m_vendor
);
237 CCECBusDevice
*primary
= GetProcessor()->GetPrimaryDevice();
238 if (primary
->GetLogicalAddress() != CECDEVICE_UNREGISTERED
)
240 m_handler
->InitHandler();
242 if (bActivateSource
&& IsHandledByLibCEC() && IsActiveSource())
243 m_handler
->ActivateSource();
252 CCECCommandHandler
*CCECBusDevice::GetHandler(void)
254 ReplaceHandler(false);
259 bool CCECBusDevice::HandleCommand(const cec_command
&command
)
261 bool bHandled(false);
263 /* update "last active" */
265 CLockObject
lock(m_mutex
);
266 m_iLastActive
= GetTimeMs();
270 /* handle the command */
271 bHandled
= m_handler
->HandleCommand(command
);
273 /* change status to present */
274 if (bHandled
&& GetLogicalAddress() != CECDEVICE_BROADCAST
&& command
.opcode_set
== 1)
276 CLockObject
lock(m_mutex
);
277 if (m_deviceStatus
!= CEC_DEVICE_STATUS_HANDLED_BY_LIBCEC
)
279 if (m_deviceStatus
!= CEC_DEVICE_STATUS_PRESENT
)
280 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "device %s (%x) status changed to present after command %s", GetLogicalAddressName(), (uint8_t)GetLogicalAddress(), ToString(command
.opcode
));
281 m_deviceStatus
= CEC_DEVICE_STATUS_PRESENT
;
289 const char* CCECBusDevice::GetLogicalAddressName(void) const
291 return ToString(m_iLogicalAddress
);
294 bool CCECBusDevice::IsPresent(void)
296 CLockObject
lock(m_mutex
);
297 return m_deviceStatus
== CEC_DEVICE_STATUS_PRESENT
;
300 bool CCECBusDevice::IsHandledByLibCEC(void)
302 CLockObject
lock(m_mutex
);
303 return m_deviceStatus
== CEC_DEVICE_STATUS_HANDLED_BY_LIBCEC
;
306 void CCECBusDevice::SetUnsupportedFeature(cec_opcode opcode
)
308 // some commands should never be marked as unsupported
309 if (opcode
== CEC_OPCODE_VENDOR_COMMAND
||
310 opcode
== CEC_OPCODE_VENDOR_COMMAND_WITH_ID
||
311 opcode
== CEC_OPCODE_VENDOR_REMOTE_BUTTON_DOWN
||
312 opcode
== CEC_OPCODE_VENDOR_REMOTE_BUTTON_UP
||
313 opcode
== CEC_OPCODE_ABORT
||
314 opcode
== CEC_OPCODE_FEATURE_ABORT
||
315 opcode
== CEC_OPCODE_NONE
||
316 opcode
== CEC_OPCODE_USER_CONTROL_PRESSED
||
317 opcode
== CEC_OPCODE_USER_CONTROL_RELEASE
)
321 CLockObject
lock(m_mutex
);
322 if (m_unsupportedFeatures
.find(opcode
) == m_unsupportedFeatures
.end())
324 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "marking opcode '%s' as unsupported feature for device '%s'", ToString(opcode
), GetLogicalAddressName());
325 m_unsupportedFeatures
.insert(opcode
);
329 // signal threads that are waiting for a reponse
331 SignalOpcode(cec_command::GetResponseOpcode(opcode
));
335 bool CCECBusDevice::IsUnsupportedFeature(cec_opcode opcode
)
337 CLockObject
lock(m_mutex
);
338 bool bUnsupported
= (m_unsupportedFeatures
.find(opcode
) != m_unsupportedFeatures
.end());
340 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "'%s' is marked as unsupported feature for device '%s'", ToString(opcode
), GetLogicalAddressName());
344 bool CCECBusDevice::TransmitKeypress(const cec_logical_address initiator
, cec_user_control_code key
, bool bWait
/* = true */)
347 bool bReturn
= m_handler
->TransmitKeypress(initiator
, m_iLogicalAddress
, key
, bWait
);
352 bool CCECBusDevice::TransmitKeyRelease(const cec_logical_address initiator
, bool bWait
/* = true */)
355 bool bReturn
= m_handler
->TransmitKeyRelease(initiator
, m_iLogicalAddress
, bWait
);
360 cec_version
CCECBusDevice::GetCecVersion(const cec_logical_address initiator
, bool bUpdate
/* = false */)
362 bool bIsPresent(GetStatus() == CEC_DEVICE_STATUS_PRESENT
);
363 bool bRequestUpdate(false);
365 CLockObject
lock(m_mutex
);
366 bRequestUpdate
= bIsPresent
&&
367 (bUpdate
|| m_cecVersion
== CEC_VERSION_UNKNOWN
);
372 CheckVendorIdRequested(initiator
);
373 RequestCecVersion(initiator
);
376 CLockObject
lock(m_mutex
);
380 void CCECBusDevice::SetCecVersion(const cec_version newVersion
)
382 CLockObject
lock(m_mutex
);
383 if (m_cecVersion
!= newVersion
)
384 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "%s (%X): CEC version %s", GetLogicalAddressName(), m_iLogicalAddress
, ToString(newVersion
));
385 m_cecVersion
= newVersion
;
388 bool CCECBusDevice::RequestCecVersion(const cec_logical_address initiator
, bool bWaitForResponse
/* = true */)
392 if (!IsHandledByLibCEC() &&
393 !IsUnsupportedFeature(CEC_OPCODE_GET_CEC_VERSION
))
396 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "<< requesting CEC version of '%s' (%X)", GetLogicalAddressName(), m_iLogicalAddress
);
397 bReturn
= m_handler
->TransmitRequestCecVersion(initiator
, m_iLogicalAddress
, bWaitForResponse
);
403 bool CCECBusDevice::TransmitCECVersion(const cec_logical_address destination
, bool bIsReply
)
407 CLockObject
lock(m_mutex
);
408 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "<< %s (%X) -> %s (%X): cec version %s", GetLogicalAddressName(), m_iLogicalAddress
, ToString(destination
), destination
, ToString(m_cecVersion
));
409 version
= m_cecVersion
;
413 bool bReturn
= m_handler
->TransmitCECVersion(m_iLogicalAddress
, destination
, version
, bIsReply
);
418 cec_menu_language
&CCECBusDevice::GetMenuLanguage(const cec_logical_address initiator
, bool bUpdate
/* = false */)
420 bool bIsPresent(GetStatus() == CEC_DEVICE_STATUS_PRESENT
);
421 bool bRequestUpdate(false);
423 CLockObject
lock(m_mutex
);
424 bRequestUpdate
= (bIsPresent
&&
425 (bUpdate
|| !strcmp(m_menuLanguage
.language
, "???")));
430 CheckVendorIdRequested(initiator
);
431 RequestMenuLanguage(initiator
);
434 CLockObject
lock(m_mutex
);
435 return m_menuLanguage
;
438 void CCECBusDevice::SetMenuLanguage(const char *strLanguage
)
443 CLockObject
lock(m_mutex
);
444 if (strcmp(strLanguage
, m_menuLanguage
.language
))
446 memcpy(m_menuLanguage
.language
, strLanguage
, 3);
447 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "%s (%X): menu language set to '%s'", GetLogicalAddressName(), m_iLogicalAddress
, m_menuLanguage
.language
);
451 void CCECBusDevice::SetMenuLanguage(const cec_menu_language
&language
)
453 if (language
.device
== m_iLogicalAddress
)
454 SetMenuLanguage(language
.language
);
457 bool CCECBusDevice::RequestMenuLanguage(const cec_logical_address initiator
, bool bWaitForResponse
/* = true */)
461 if (!IsHandledByLibCEC() &&
462 !IsUnsupportedFeature(CEC_OPCODE_GET_MENU_LANGUAGE
))
465 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "<< requesting menu language of '%s' (%X)", GetLogicalAddressName(), m_iLogicalAddress
);
466 bReturn
= m_handler
->TransmitRequestMenuLanguage(initiator
, m_iLogicalAddress
, bWaitForResponse
);
472 bool CCECBusDevice::TransmitSetMenuLanguage(const cec_logical_address destination
, bool bIsReply
)
475 cec_menu_language language
;
477 CLockObject
lock(m_mutex
);
478 language
= m_menuLanguage
;
483 CLockObject
lock(m_mutex
);
484 lang
[0] = language
.language
[0];
485 lang
[1] = language
.language
[1];
486 lang
[2] = language
.language
[2];
491 if (lang
[0] == '?' && lang
[1] == '?' && lang
[2] == '?')
493 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "<< %s (%X) -> %s (%X): menu language feature abort", GetLogicalAddressName(), m_iLogicalAddress
, ToString(destination
), destination
);
494 m_processor
->TransmitAbort(m_iLogicalAddress
, destination
, CEC_OPCODE_GIVE_DEVICE_VENDOR_ID
);
499 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "<< %s (%X) -> broadcast (F): menu language '%s'", GetLogicalAddressName(), m_iLogicalAddress
, lang
);
500 bReturn
= m_handler
->TransmitSetMenuLanguage(m_iLogicalAddress
, lang
, bIsReply
);
506 bool CCECBusDevice::TransmitOSDString(const cec_logical_address destination
, cec_display_control duration
, const char *strMessage
, bool bIsReply
)
509 if (!m_processor
->GetDevice(destination
)->IsUnsupportedFeature(CEC_OPCODE_SET_OSD_STRING
))
511 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "<< %s (%X) -> %s (%X): display OSD message '%s'", GetLogicalAddressName(), m_iLogicalAddress
, ToString(destination
), destination
, strMessage
);
513 bReturn
= m_handler
->TransmitOSDString(m_iLogicalAddress
, destination
, duration
, strMessage
, bIsReply
);
519 CStdString
CCECBusDevice::GetCurrentOSDName(void)
521 CLockObject
lock(m_mutex
);
522 return m_strDeviceName
;
525 CStdString
CCECBusDevice::GetOSDName(const cec_logical_address initiator
, bool bUpdate
/* = false */)
527 bool bIsPresent(GetStatus() == CEC_DEVICE_STATUS_PRESENT
);
528 bool bRequestUpdate(false);
530 CLockObject
lock(m_mutex
);
531 bRequestUpdate
= bIsPresent
&&
532 (bUpdate
|| m_strDeviceName
.Equals(ToString(m_iLogicalAddress
))) &&
533 m_type
!= CEC_DEVICE_TYPE_TV
;
538 CheckVendorIdRequested(initiator
);
539 RequestOSDName(initiator
);
542 CLockObject
lock(m_mutex
);
543 return m_strDeviceName
;
546 void CCECBusDevice::SetOSDName(CStdString strName
)
548 CLockObject
lock(m_mutex
);
549 if (m_strDeviceName
!= strName
)
551 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "%s (%X): osd name set to '%s'", GetLogicalAddressName(), m_iLogicalAddress
, strName
.c_str());
552 m_strDeviceName
= strName
;
556 bool CCECBusDevice::RequestOSDName(const cec_logical_address initiator
, bool bWaitForResponse
/* = true */)
560 if (!IsHandledByLibCEC() &&
561 !IsUnsupportedFeature(CEC_OPCODE_GIVE_OSD_NAME
))
564 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "<< requesting OSD name of '%s' (%X)", GetLogicalAddressName(), m_iLogicalAddress
);
565 bReturn
= m_handler
->TransmitRequestOSDName(initiator
, m_iLogicalAddress
, bWaitForResponse
);
571 bool CCECBusDevice::TransmitOSDName(const cec_logical_address destination
, bool bIsReply
)
573 CStdString strDeviceName
;
575 CLockObject
lock(m_mutex
);
576 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "<< %s (%X) -> %s (%X): OSD name '%s'", GetLogicalAddressName(), m_iLogicalAddress
, ToString(destination
), destination
, m_strDeviceName
.c_str());
577 strDeviceName
= m_strDeviceName
;
581 bool bReturn
= m_handler
->TransmitOSDName(m_iLogicalAddress
, destination
, strDeviceName
, bIsReply
);
586 bool CCECBusDevice::HasValidPhysicalAddress(void)
588 CLockObject
lock(m_mutex
);
589 return CLibCEC::IsValidPhysicalAddress(m_iPhysicalAddress
);
592 uint16_t CCECBusDevice::GetCurrentPhysicalAddress(void)
594 CLockObject
lock(m_mutex
);
595 return m_iPhysicalAddress
;
598 uint16_t CCECBusDevice::GetPhysicalAddress(const cec_logical_address initiator
, bool bSuppressUpdate
/* = false */)
600 if (!bSuppressUpdate
)
602 bool bIsPresent(GetStatus() == CEC_DEVICE_STATUS_PRESENT
);
603 bool bRequestUpdate(false);
605 CLockObject
lock(m_mutex
);
606 bRequestUpdate
= bIsPresent
&& m_iPhysicalAddress
== CEC_INVALID_PHYSICAL_ADDRESS
;
611 CheckVendorIdRequested(initiator
);
612 if (!RequestPhysicalAddress(initiator
))
613 LIB_CEC
->AddLog(CEC_LOG_ERROR
, "failed to request the physical address");
617 CLockObject
lock(m_mutex
);
618 return m_iPhysicalAddress
;
621 bool CCECBusDevice::SetPhysicalAddress(uint16_t iNewAddress
)
623 CLockObject
lock(m_mutex
);
624 if (iNewAddress
> 0 && m_iPhysicalAddress
!= iNewAddress
)
626 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "%s (%X): physical address changed from %04x to %04x", GetLogicalAddressName(), m_iLogicalAddress
, m_iPhysicalAddress
, iNewAddress
);
627 m_iPhysicalAddress
= iNewAddress
;
632 bool CCECBusDevice::RequestPhysicalAddress(const cec_logical_address initiator
, bool bWaitForResponse
/* = true */)
636 if (!IsHandledByLibCEC())
639 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "<< requesting physical address of '%s' (%X)", GetLogicalAddressName(), m_iLogicalAddress
);
640 bReturn
= m_handler
->TransmitRequestPhysicalAddress(initiator
, m_iLogicalAddress
, bWaitForResponse
);
646 bool CCECBusDevice::TransmitPhysicalAddress(bool bIsReply
)
648 uint16_t iPhysicalAddress
;
649 cec_device_type type
;
651 CLockObject
lock(m_mutex
);
652 if (m_iPhysicalAddress
== CEC_INVALID_PHYSICAL_ADDRESS
)
655 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "<< %s (%X) -> broadcast (F): physical adddress %4x", GetLogicalAddressName(), m_iLogicalAddress
, m_iPhysicalAddress
);
656 iPhysicalAddress
= m_iPhysicalAddress
;
661 bool bReturn
= m_handler
->TransmitPhysicalAddress(m_iLogicalAddress
, iPhysicalAddress
, type
, bIsReply
);
666 cec_power_status
CCECBusDevice::GetCurrentPowerStatus(void)
668 CLockObject
lock(m_mutex
);
669 return m_powerStatus
;
672 cec_power_status
CCECBusDevice::GetPowerStatus(const cec_logical_address initiator
, bool bUpdate
/* = false */)
674 bool bIsPresent(GetStatus() == CEC_DEVICE_STATUS_PRESENT
);
675 bool bRequestUpdate(false);
677 CLockObject
lock(m_mutex
);
678 bRequestUpdate
= (bIsPresent
&&
679 (bUpdate
|| m_powerStatus
== CEC_POWER_STATUS_UNKNOWN
||
680 m_powerStatus
== CEC_POWER_STATUS_IN_TRANSITION_STANDBY_TO_ON
||
681 m_powerStatus
== CEC_POWER_STATUS_IN_TRANSITION_ON_TO_STANDBY
||
682 GetTimeMs() - m_iLastPowerStateUpdate
>= CEC_POWER_STATE_REFRESH_TIME
));
687 CheckVendorIdRequested(initiator
);
688 RequestPowerStatus(initiator
, bUpdate
);
691 CLockObject
lock(m_mutex
);
692 return m_powerStatus
;
695 void CCECBusDevice::SetPowerStatus(const cec_power_status powerStatus
)
697 CLockObject
lock(m_mutex
);
698 if (m_powerStatus
!= powerStatus
)
700 m_iLastPowerStateUpdate
= GetTimeMs();
701 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "%s (%X): power status changed from '%s' to '%s'", GetLogicalAddressName(), m_iLogicalAddress
, ToString(m_powerStatus
), ToString(powerStatus
));
702 m_powerStatus
= powerStatus
;
706 void CCECBusDevice::OnImageViewOnSent(bool bSentByLibCEC
)
708 CLockObject
lock(m_mutex
);
709 m_bImageViewOnSent
= bSentByLibCEC
;
711 if (m_powerStatus
!= CEC_POWER_STATUS_ON
&& m_powerStatus
!= CEC_POWER_STATUS_IN_TRANSITION_STANDBY_TO_ON
)
713 m_iLastPowerStateUpdate
= GetTimeMs();
714 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
));
715 m_powerStatus
= CEC_POWER_STATUS_IN_TRANSITION_STANDBY_TO_ON
;
719 bool CCECBusDevice::ImageViewOnSent(void)
721 CLockObject
lock(m_mutex
);
722 return m_bImageViewOnSent
;
725 bool CCECBusDevice::RequestPowerStatus(const cec_logical_address initiator
, bool bUpdate
, bool bWaitForResponse
/* = true */)
729 if (!IsHandledByLibCEC() &&
730 !IsUnsupportedFeature(CEC_OPCODE_GIVE_DEVICE_POWER_STATUS
))
733 bReturn
= m_handler
->TransmitRequestPowerStatus(initiator
, m_iLogicalAddress
, bUpdate
, bWaitForResponse
);
735 SetPowerStatus(CEC_POWER_STATUS_UNKNOWN
);
741 bool CCECBusDevice::TransmitPowerState(const cec_logical_address destination
, bool bIsReply
)
743 cec_power_status state
;
745 CLockObject
lock(m_mutex
);
746 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "<< %s (%X) -> %s (%X): %s", GetLogicalAddressName(), m_iLogicalAddress
, ToString(destination
), destination
, ToString(m_powerStatus
));
747 state
= m_powerStatus
;
751 bool bReturn
= m_handler
->TransmitPowerState(m_iLogicalAddress
, destination
, state
, bIsReply
);
756 cec_vendor_id
CCECBusDevice::GetCurrentVendorId(void)
758 CLockObject
lock(m_mutex
);
762 cec_vendor_id
CCECBusDevice::GetVendorId(const cec_logical_address initiator
, bool bUpdate
/* = false */)
764 bool bIsPresent(GetStatus() == CEC_DEVICE_STATUS_PRESENT
);
765 bool bRequestUpdate(false);
767 CLockObject
lock(m_mutex
);
768 bRequestUpdate
= (bIsPresent
&&
769 (bUpdate
|| m_vendor
== CEC_VENDOR_UNKNOWN
));
773 RequestVendorId(initiator
);
775 CLockObject
lock(m_mutex
);
779 const char *CCECBusDevice::GetVendorName(const cec_logical_address initiator
, bool bUpdate
/* = false */)
781 return ToString(GetVendorId(initiator
, bUpdate
));
784 bool CCECBusDevice::SetVendorId(uint64_t iVendorId
)
786 bool bVendorChanged(false);
789 CLockObject
lock(m_mutex
);
790 bVendorChanged
= (m_vendor
!= (cec_vendor_id
)iVendorId
);
791 m_vendor
= (cec_vendor_id
)iVendorId
;
795 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "%s (%X): vendor = %s (%06x)", GetLogicalAddressName(), m_iLogicalAddress
, ToString(m_vendor
), m_vendor
);
797 return bVendorChanged
;
800 bool CCECBusDevice::RequestVendorId(const cec_logical_address initiator
, bool bWaitForResponse
/* = true */)
804 if (!IsHandledByLibCEC() && initiator
!= CECDEVICE_UNKNOWN
)
807 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "<< requesting vendor ID of '%s' (%X)", GetLogicalAddressName(), m_iLogicalAddress
);
808 bReturn
= m_handler
->TransmitRequestVendorId(initiator
, m_iLogicalAddress
, bWaitForResponse
);
811 if (bWaitForResponse
)
812 ReplaceHandler(true);
817 bool CCECBusDevice::TransmitVendorID(const cec_logical_address destination
, bool bSendAbort
, bool bIsReply
)
822 CLockObject
lock(m_mutex
);
823 iVendorId
= (uint64_t)m_vendor
;
827 if (iVendorId
== CEC_VENDOR_UNKNOWN
)
831 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "<< %s (%X) -> %s (%X): vendor id feature abort", GetLogicalAddressName(), m_iLogicalAddress
, ToString(destination
), destination
);
832 m_processor
->TransmitAbort(m_iLogicalAddress
, destination
, CEC_OPCODE_GIVE_DEVICE_VENDOR_ID
);
838 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
);
839 bReturn
= m_handler
->TransmitVendorID(m_iLogicalAddress
, destination
, iVendorId
, bIsReply
);
845 cec_bus_device_status
CCECBusDevice::GetStatus(bool bForcePoll
/* = false */, bool bSuppressPoll
/* = false */)
847 if (m_iLogicalAddress
== CECDEVICE_BROADCAST
)
848 return CEC_DEVICE_STATUS_NOT_PRESENT
;
850 cec_bus_device_status
status(CEC_DEVICE_STATUS_UNKNOWN
);
851 bool bNeedsPoll(false);
854 CLockObject
lock(m_mutex
);
855 status
= m_deviceStatus
;
856 bNeedsPoll
= !bSuppressPoll
&&
857 m_deviceStatus
!= CEC_DEVICE_STATUS_HANDLED_BY_LIBCEC
&&
860 // don't know the status
861 m_deviceStatus
== CEC_DEVICE_STATUS_UNKNOWN
||
862 // always poll the TV if it's marked as not present
863 (m_deviceStatus
== CEC_DEVICE_STATUS_NOT_PRESENT
&& m_iLogicalAddress
== CECDEVICE_TV
));
868 bool bPollAcked(false);
870 bPollAcked
= m_processor
->PollDevice(m_iLogicalAddress
);
872 status
= bPollAcked
? CEC_DEVICE_STATUS_PRESENT
: CEC_DEVICE_STATUS_NOT_PRESENT
;
873 SetDeviceStatus(status
);
879 void CCECBusDevice::SetDeviceStatus(const cec_bus_device_status newStatus
, cec_version libCECSpecVersion
/* = CEC_VERSION_1_4 */)
881 if (m_iLogicalAddress
== CECDEVICE_UNREGISTERED
)
885 CLockObject
lock(m_mutex
);
888 case CEC_DEVICE_STATUS_HANDLED_BY_LIBCEC
:
889 if (m_deviceStatus
!= newStatus
)
890 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "%s (%X): device status changed into 'handled by libCEC'", GetLogicalAddressName(), m_iLogicalAddress
);
891 SetPowerStatus (CEC_POWER_STATUS_ON
);
892 SetVendorId (CEC_VENDOR_PULSE_EIGHT
);
893 SetMenuState (CEC_MENU_STATE_ACTIVATED
);
894 SetCecVersion (libCECSpecVersion
);
895 SetStreamPath (CEC_INVALID_PHYSICAL_ADDRESS
);
896 MarkAsInactiveSource();
898 m_deviceStatus
= newStatus
;
900 case CEC_DEVICE_STATUS_PRESENT
:
901 if (m_deviceStatus
!= newStatus
)
902 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "%s (%X): device status changed into 'present'", GetLogicalAddressName(), m_iLogicalAddress
);
903 m_deviceStatus
= newStatus
;
904 m_iLastActive
= GetTimeMs();
906 case CEC_DEVICE_STATUS_NOT_PRESENT
:
907 if (m_deviceStatus
!= newStatus
)
909 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "%s (%X): device status changed into 'not present'", GetLogicalAddressName(), m_iLogicalAddress
);
910 ResetDeviceStatus(true);
911 m_deviceStatus
= newStatus
;
921 void CCECBusDevice::ResetDeviceStatus(bool bClientUnregistered
/* = false */)
923 CLockObject
lock(m_mutex
);
924 SetPowerStatus (CEC_POWER_STATUS_UNKNOWN
);
925 SetVendorId (CEC_VENDOR_UNKNOWN
);
926 SetMenuState (CEC_MENU_STATE_ACTIVATED
);
927 SetCecVersion (CEC_VERSION_UNKNOWN
);
928 SetStreamPath (CEC_INVALID_PHYSICAL_ADDRESS
);
929 SetOSDName (ToString(m_iLogicalAddress
));
930 MarkAsInactiveSource(bClientUnregistered
);
933 m_bVendorIdRequested
= false;
934 m_unsupportedFeatures
.clear();
935 m_waitForResponse
->Clear();
937 if (m_deviceStatus
!= CEC_DEVICE_STATUS_UNKNOWN
)
938 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "%s (%X): device status changed into 'unknown'", GetLogicalAddressName(), m_iLogicalAddress
);
939 m_deviceStatus
= CEC_DEVICE_STATUS_UNKNOWN
;
942 bool CCECBusDevice::TransmitPoll(const cec_logical_address dest
, bool bUpdateDeviceStatus
)
945 cec_logical_address
destination(dest
);
946 if (destination
== CECDEVICE_UNKNOWN
)
947 destination
= m_iLogicalAddress
;
949 CCECBusDevice
*destDevice
= m_processor
->GetDevice(destination
);
950 if (destDevice
->m_deviceStatus
== CEC_DEVICE_STATUS_HANDLED_BY_LIBCEC
)
954 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "<< %s (%X) -> %s (%X): POLL", GetLogicalAddressName(), m_iLogicalAddress
, ToString(dest
), dest
);
955 bReturn
= m_handler
->TransmitPoll(m_iLogicalAddress
, destination
, false);
956 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, bReturn
? ">> POLL sent" : ">> POLL not sent");
958 if (bUpdateDeviceStatus
)
959 destDevice
->SetDeviceStatus(bReturn
? CEC_DEVICE_STATUS_PRESENT
: CEC_DEVICE_STATUS_NOT_PRESENT
);
965 void CCECBusDevice::HandlePoll(const cec_logical_address destination
)
967 if (destination
>= 0 && destination
< CECDEVICE_BROADCAST
)
969 CCECBusDevice
*device
= m_processor
->GetDevice(destination
);
971 device
->HandlePollFrom(m_iLogicalAddress
);
975 void CCECBusDevice::HandlePollFrom(const cec_logical_address initiator
)
977 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "<< POLL: %s (%x) -> %s (%x)", ToString(initiator
), initiator
, ToString(m_iLogicalAddress
), m_iLogicalAddress
);
978 m_bAwaitingReceiveFailed
= true;
981 bool CCECBusDevice::HandleReceiveFailed(void)
983 bool bReturn
= m_bAwaitingReceiveFailed
;
984 m_bAwaitingReceiveFailed
= false;
988 cec_menu_state
CCECBusDevice::GetMenuState(const cec_logical_address
UNUSED(initiator
))
990 CLockObject
lock(m_mutex
);
994 void CCECBusDevice::SetMenuState(const cec_menu_state state
)
996 CLockObject
lock(m_mutex
);
997 if (m_menuState
!= state
)
999 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "%s (%X): menu state set to '%s'", GetLogicalAddressName(), m_iLogicalAddress
, ToString(m_menuState
));
1000 m_menuState
= state
;
1004 bool CCECBusDevice::TransmitMenuState(const cec_logical_address dest
, bool bIsReply
)
1006 cec_menu_state menuState
;
1008 CLockObject
lock(m_mutex
);
1009 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "<< %s (%X) -> %s (%X): menu state '%s'", GetLogicalAddressName(), m_iLogicalAddress
, ToString(dest
), dest
, ToString(m_menuState
));
1010 menuState
= m_menuState
;
1014 bool bReturn
= m_handler
->TransmitMenuState(m_iLogicalAddress
, dest
, menuState
, bIsReply
);
1019 bool CCECBusDevice::ActivateSource(uint64_t iDelay
/* = 0 */)
1021 MarkAsActiveSource();
1026 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "sending active source message for '%s'", ToString(m_iLogicalAddress
));
1027 bReturn
= m_handler
->ActivateSource();
1031 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "scheduling active source message for '%s'", ToString(m_iLogicalAddress
));
1032 m_handler
->ScheduleActivateSource(iDelay
);
1038 bool CCECBusDevice::RequestActiveSource(bool bWaitForResponse
/* = true */)
1040 bool bReturn(false);
1042 if (IsHandledByLibCEC())
1045 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "<< requesting active source");
1047 bReturn
= m_handler
->TransmitRequestActiveSource(m_iLogicalAddress
, bWaitForResponse
);
1053 void CCECBusDevice::MarkAsActiveSource(void)
1055 bool bWasActivated(false);
1057 // set the power status to powered on
1058 SetPowerStatus(CEC_POWER_STATUS_ON
);
1060 // mark this device as active source
1062 CLockObject
lock(m_mutex
);
1063 if (!m_bActiveSource
)
1065 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "making %s (%x) the active source", GetLogicalAddressName(), m_iLogicalAddress
);
1066 bWasActivated
= true;
1069 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "%s (%x) was already marked as active source", GetLogicalAddressName(), m_iLogicalAddress
);
1071 m_bActiveSource
= true;
1074 CCECBusDevice
* tv
= m_processor
->GetDevice(CECDEVICE_TV
);
1076 tv
->OnImageViewOnSent(false);
1078 // mark other devices as inactive sources
1079 CECDEVICEVEC devices
;
1080 m_processor
->GetDevices()->Get(devices
);
1081 for (CECDEVICEVEC::iterator it
= devices
.begin(); it
!= devices
.end(); it
++)
1082 if ((*it
)->GetLogicalAddress() != m_iLogicalAddress
)
1083 (*it
)->MarkAsInactiveSource();
1085 if (bWasActivated
&& IsHandledByLibCEC())
1086 m_processor
->SetActiveSource(true, false);
1088 CCECClient
*client
= GetClient();
1090 client
->SourceActivated(m_iLogicalAddress
);
1093 void CCECBusDevice::MarkAsInactiveSource(bool bClientUnregistered
/* = false */)
1095 bool bWasDeactivated(false);
1097 CLockObject
lock(m_mutex
);
1098 if (m_bActiveSource
)
1100 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "marking %s (%X) as inactive source", GetLogicalAddressName(), m_iLogicalAddress
);
1101 bWasDeactivated
= true;
1103 m_bActiveSource
= false;
1106 if (bWasDeactivated
)
1108 if (IsHandledByLibCEC())
1109 m_processor
->SetActiveSource(false, bClientUnregistered
);
1110 CCECClient
*client
= GetClient();
1112 client
->SourceDeactivated(m_iLogicalAddress
);
1116 bool CCECBusDevice::TransmitActiveSource(bool bIsReply
)
1118 bool bSendActiveSource(false);
1119 uint16_t iPhysicalAddress(CEC_INVALID_PHYSICAL_ADDRESS
);
1122 CLockObject
lock(m_mutex
);
1123 if (!HasValidPhysicalAddress())
1125 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "%s (%X) has an invalid physical address (%04x), not sending active source commands", GetLogicalAddressName(), m_iLogicalAddress
, m_iPhysicalAddress
);
1129 iPhysicalAddress
= m_iPhysicalAddress
;
1131 if (m_powerStatus
!= CEC_POWER_STATUS_ON
&& m_powerStatus
!= CEC_POWER_STATUS_IN_TRANSITION_STANDBY_TO_ON
)
1132 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "<< %s (%X) is not powered on", GetLogicalAddressName(), m_iLogicalAddress
);
1133 else if (m_bActiveSource
)
1135 LIB_CEC
->AddLog(CEC_LOG_NOTICE
, "<< %s (%X) -> broadcast (F): active source (%4x)", GetLogicalAddressName(), m_iLogicalAddress
, m_iPhysicalAddress
);
1136 bSendActiveSource
= true;
1139 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "<< %s (%X) is not the active source", GetLogicalAddressName(), m_iLogicalAddress
);
1142 bool bActiveSourceSent(false);
1143 if (bSendActiveSource
)
1146 bActiveSourceSent
= m_handler
->TransmitActiveSource(m_iLogicalAddress
, iPhysicalAddress
, bIsReply
);
1150 return bActiveSourceSent
;
1153 bool CCECBusDevice::TransmitImageViewOn(void)
1156 CLockObject
lock(m_mutex
);
1157 if (m_powerStatus
!= CEC_POWER_STATUS_ON
&& m_powerStatus
!= CEC_POWER_STATUS_IN_TRANSITION_STANDBY_TO_ON
)
1159 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "<< %s (%X) is not powered on", GetLogicalAddressName(), m_iLogicalAddress
);
1164 CCECBusDevice
* tv
= m_processor
->GetDevice(CECDEVICE_TV
);
1167 LIB_CEC
->AddLog(CEC_LOG_ERROR
, "%s - couldn't get TV instance", __FUNCTION__
);
1171 if (tv
->ImageViewOnSent())
1173 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "%s - 'image view on' already sent", __FUNCTION__
);
1177 bool bImageViewOnSent(false);
1179 bImageViewOnSent
= m_handler
->TransmitImageViewOn(m_iLogicalAddress
, CECDEVICE_TV
);
1182 if (bImageViewOnSent
)
1183 tv
->OnImageViewOnSent(true);
1185 return bImageViewOnSent
;
1188 bool CCECBusDevice::TransmitInactiveSource(void)
1190 uint16_t iPhysicalAddress
;
1192 CLockObject
lock(m_mutex
);
1193 LIB_CEC
->AddLog(CEC_LOG_NOTICE
, "<< %s (%X) -> broadcast (F): inactive source", GetLogicalAddressName(), m_iLogicalAddress
);
1194 iPhysicalAddress
= m_iPhysicalAddress
;
1198 bool bReturn
= m_handler
->TransmitInactiveSource(m_iLogicalAddress
, iPhysicalAddress
);
1203 bool CCECBusDevice::TransmitPendingActiveSourceCommands(void)
1206 bool bReturn
= m_handler
->ActivateSource(true);
1211 void CCECBusDevice::SetActiveRoute(uint16_t iRoute
)
1213 SetPowerStatus(CEC_POWER_STATUS_ON
);
1215 CCECDeviceMap
* map
= m_processor
->GetDevices();
1219 CCECBusDevice
* newRoute
= m_processor
->GetDeviceByPhysicalAddress(iRoute
, true);
1220 if (newRoute
&& newRoute
->IsHandledByLibCEC())
1222 // we were made the active source, send notification
1223 newRoute
->ActivateSource();
1227 void CCECBusDevice::SetStreamPath(uint16_t iNewAddress
, uint16_t iOldAddress
/* = CEC_INVALID_PHYSICAL_ADDRESS */)
1229 if (iNewAddress
!= CEC_INVALID_PHYSICAL_ADDRESS
)
1230 SetPowerStatus(CEC_POWER_STATUS_ON
);
1232 CLockObject
lock(m_mutex
);
1233 if (iNewAddress
!= m_iStreamPath
)
1235 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "%s (%X): stream path changed from %04x to %04x", GetLogicalAddressName(), m_iLogicalAddress
, iOldAddress
== 0 ? m_iStreamPath
: iOldAddress
, iNewAddress
);
1236 m_iStreamPath
= iNewAddress
;
1239 if (!LIB_CEC
->IsValidPhysicalAddress(iNewAddress
))
1242 CCECBusDevice
*device
= m_processor
->GetDeviceByPhysicalAddress(iNewAddress
);
1245 // if a device is found with the new physical address, mark it as active, which will automatically mark all other devices as inactive
1246 device
->MarkAsActiveSource();
1248 // respond with an active source message if this device is handled by libCEC
1249 if (device
->IsHandledByLibCEC())
1250 device
->TransmitActiveSource(true);
1254 // try to find the device with the old address, and mark it as inactive when found
1255 device
= m_processor
->GetDeviceByPhysicalAddress(iOldAddress
);
1257 device
->MarkAsInactiveSource();
1261 bool CCECBusDevice::PowerOn(const cec_logical_address initiator
)
1263 bool bReturn(false);
1264 GetVendorId(initiator
); // ensure that we got the vendor id, because the implementations vary per vendor
1267 cec_power_status currentStatus
;
1268 if (m_iLogicalAddress
== CECDEVICE_TV
||
1269 ((currentStatus
= GetPowerStatus(initiator
, false)) != CEC_POWER_STATUS_IN_TRANSITION_STANDBY_TO_ON
&&
1270 currentStatus
!= CEC_POWER_STATUS_ON
))
1272 LIB_CEC
->AddLog(CEC_LOG_NOTICE
, "<< powering on '%s' (%X)", GetLogicalAddressName(), m_iLogicalAddress
);
1273 bReturn
= m_handler
->PowerOn(initiator
, m_iLogicalAddress
);
1277 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "'%s' (%X) is already '%s'", GetLogicalAddressName(), m_iLogicalAddress
, ToString(currentStatus
));
1284 bool CCECBusDevice::Standby(const cec_logical_address initiator
)
1286 GetVendorId(initiator
); // ensure that we got the vendor id, because the implementations vary per vendor
1288 LIB_CEC
->AddLog(CEC_LOG_NOTICE
, "<< putting '%s' (%X) in standby mode", GetLogicalAddressName(), m_iLogicalAddress
);
1290 bool bReturn
= m_handler
->TransmitStandby(initiator
, m_iLogicalAddress
);
1295 bool CCECBusDevice::NeedsPoll(void)
1297 bool bSendPoll(false);
1298 cec_logical_address
pollAddress(CECDEVICE_UNKNOWN
);
1299 switch (m_iLogicalAddress
)
1301 case CECDEVICE_PLAYBACKDEVICE3
:
1302 pollAddress
= CECDEVICE_PLAYBACKDEVICE2
;
1304 case CECDEVICE_PLAYBACKDEVICE2
:
1305 pollAddress
= CECDEVICE_PLAYBACKDEVICE1
;
1307 case CECDEVICE_RECORDINGDEVICE3
:
1308 pollAddress
= CECDEVICE_RECORDINGDEVICE2
;
1310 case CECDEVICE_RECORDINGDEVICE2
:
1311 pollAddress
= CECDEVICE_RECORDINGDEVICE1
;
1313 case CECDEVICE_TUNER4
:
1314 pollAddress
= CECDEVICE_TUNER3
;
1316 case CECDEVICE_TUNER3
:
1317 pollAddress
= CECDEVICE_TUNER2
;
1319 case CECDEVICE_TUNER2
:
1320 pollAddress
= CECDEVICE_TUNER1
;
1322 case CECDEVICE_AUDIOSYSTEM
:
1323 case CECDEVICE_PLAYBACKDEVICE1
:
1324 case CECDEVICE_RECORDINGDEVICE1
:
1325 case CECDEVICE_TUNER1
:
1333 if (!bSendPoll
&& pollAddress
!= CECDEVICE_UNKNOWN
)
1335 CCECBusDevice
*device
= m_processor
->GetDevice(pollAddress
);
1338 cec_bus_device_status status
= device
->GetStatus();
1339 bSendPoll
= (status
== CEC_DEVICE_STATUS_PRESENT
|| status
== CEC_DEVICE_STATUS_HANDLED_BY_LIBCEC
);
1350 void CCECBusDevice::CheckVendorIdRequested(const cec_logical_address initiator
)
1352 bool bRequestVendorId(false);
1354 CLockObject
lock(m_mutex
);
1355 bRequestVendorId
= !m_bVendorIdRequested
;
1356 m_bVendorIdRequested
= true;
1359 if (bRequestVendorId
)
1361 ReplaceHandler(false);
1362 GetVendorId(initiator
);
1367 CCECAudioSystem
*CCECBusDevice::AsAudioSystem(void)
1369 return AsAudioSystem(this);
1372 CCECPlaybackDevice
*CCECBusDevice::AsPlaybackDevice(void)
1374 return AsPlaybackDevice(this);
1377 CCECRecordingDevice
*CCECBusDevice::AsRecordingDevice(void)
1379 return AsRecordingDevice(this);
1382 CCECTuner
*CCECBusDevice::AsTuner(void)
1384 return AsTuner(this);
1387 CCECTV
*CCECBusDevice::AsTV(void)
1392 CCECAudioSystem
*CCECBusDevice::AsAudioSystem(CCECBusDevice
*device
)
1394 if (device
&& device
->GetType() == CEC_DEVICE_TYPE_AUDIO_SYSTEM
)
1395 return static_cast<CCECAudioSystem
*>(device
);
1399 CCECPlaybackDevice
*CCECBusDevice::AsPlaybackDevice(CCECBusDevice
*device
)
1402 (device
->GetType() == CEC_DEVICE_TYPE_PLAYBACK_DEVICE
||
1403 device
->GetType() == CEC_DEVICE_TYPE_RECORDING_DEVICE
))
1404 return static_cast<CCECPlaybackDevice
*>(device
);
1408 CCECRecordingDevice
*CCECBusDevice::AsRecordingDevice(CCECBusDevice
*device
)
1410 if (device
&& device
->GetType() == CEC_DEVICE_TYPE_RECORDING_DEVICE
)
1411 return static_cast<CCECRecordingDevice
*>(device
);
1415 CCECTuner
*CCECBusDevice::AsTuner(CCECBusDevice
*device
)
1417 if (device
&& device
->GetType() == CEC_DEVICE_TYPE_TUNER
)
1418 return static_cast<CCECTuner
*>(device
);
1422 CCECTV
*CCECBusDevice::AsTV(CCECBusDevice
*device
)
1424 if (device
&& device
->GetType() == CEC_DEVICE_TYPE_TV
)
1425 return static_cast<CCECTV
*>(device
);
1429 void CCECBusDevice::MarkBusy(void)
1431 CLockObject
handlerLock(m_handlerMutex
);
1432 ++m_iHandlerUseCount
;
1435 void CCECBusDevice::MarkReady(void)
1437 CLockObject
handlerLock(m_handlerMutex
);
1438 if (m_iHandlerUseCount
> 0)
1439 --m_iHandlerUseCount
;
1442 bool CCECBusDevice::TryLogicalAddress(cec_version libCECSpecVersion
/* = CEC_VERSION_1_4 */)
1444 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "trying logical address '%s'", GetLogicalAddressName());
1446 if (!TransmitPoll(m_iLogicalAddress
, false))
1448 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "using logical address '%s'", GetLogicalAddressName());
1449 SetDeviceStatus(CEC_DEVICE_STATUS_HANDLED_BY_LIBCEC
, libCECSpecVersion
);
1454 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "logical address '%s' already taken", GetLogicalAddressName());
1455 SetDeviceStatus(CEC_DEVICE_STATUS_PRESENT
);
1459 CCECClient
*CCECBusDevice::GetClient(void)
1461 return m_processor
->GetClient(m_iLogicalAddress
);
1464 void CCECBusDevice::SignalOpcode(cec_opcode opcode
)
1466 m_waitForResponse
->Received(opcode
);
1469 bool CCECBusDevice::WaitForOpcode(cec_opcode opcode
)
1471 return m_waitForResponse
->Wait(opcode
);