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/
33 #include "CECBusDevice.h"
34 #include "../CECProcessor.h"
35 #include "../implementations/ANCommandHandler.h"
36 #include "../implementations/CECCommandHandler.h"
37 #include "../implementations/SLCommandHandler.h"
38 #include "../implementations/VLCommandHandler.h"
39 #include "../LibCEC.h"
40 #include "../platform/util/timeutils.h"
43 using namespace PLATFORM
;
45 #define ToString(p) m_processor->ToString(p)
47 CCECBusDevice::CCECBusDevice(CCECProcessor
*processor
, cec_logical_address iLogicalAddress
, uint16_t iPhysicalAddress
) :
48 m_type(CEC_DEVICE_TYPE_RESERVED
),
49 m_iPhysicalAddress(iPhysicalAddress
),
51 m_iLogicalAddress(iLogicalAddress
),
52 m_powerStatus(CEC_POWER_STATUS_UNKNOWN
),
53 m_processor(processor
),
54 m_vendor(CEC_VENDOR_UNKNOWN
),
55 m_bReplaceHandler(false),
56 m_menuState(CEC_MENU_STATE_ACTIVATED
),
57 m_bActiveSource(false),
59 m_iLastPowerStateUpdate(0),
60 m_cecVersion(CEC_VERSION_UNKNOWN
),
61 m_deviceStatus(CEC_DEVICE_STATUS_UNKNOWN
),
62 m_iHandlerUseCount(0),
63 m_bAwaitingReceiveFailed(false)
65 m_handler
= new CCECCommandHandler(this);
67 for (unsigned int iPtr
= 0; iPtr
< 4; iPtr
++)
68 m_menuLanguage
.language
[iPtr
] = '?';
69 m_menuLanguage
.language
[3] = 0;
70 m_menuLanguage
.device
= iLogicalAddress
;
72 m_strDeviceName
= ToString(m_iLogicalAddress
);
75 CCECBusDevice::~CCECBusDevice(void)
80 bool CCECBusDevice::HandleCommand(const cec_command
&command
)
84 /* update "last active" */
86 CLockObject
lock(m_mutex
);
87 m_iLastActive
= GetTimeMs();
89 if (m_deviceStatus
!= CEC_DEVICE_STATUS_HANDLED_BY_LIBCEC
)
90 m_deviceStatus
= CEC_DEVICE_STATUS_PRESENT
;
95 /* handle the command */
96 bHandled
= m_handler
->HandleCommand(command
);
98 /* change status to present */
101 CLockObject
lock(m_mutex
);
102 if (m_deviceStatus
!= CEC_DEVICE_STATUS_HANDLED_BY_LIBCEC
)
104 if (m_deviceStatus
!= CEC_DEVICE_STATUS_PRESENT
)
105 CLibCEC::AddLog(CEC_LOG_DEBUG
, "device %s (%x) status changed to present after command %s", GetLogicalAddressName(), (uint8_t)GetLogicalAddress(), ToString(command
.opcode
));
106 m_deviceStatus
= CEC_DEVICE_STATUS_PRESENT
;
114 bool CCECBusDevice::PowerOn(void)
117 GetVendorId(); // ensure that we got the vendor id, because the implementations vary per vendor
120 CLibCEC::AddLog(CEC_LOG_NOTICE
, "<< powering on '%s' (%X)", GetLogicalAddressName(), m_iLogicalAddress
);
121 if (m_handler
->PowerOn(GetMyLogicalAddress(), m_iLogicalAddress
))
123 SetPowerStatus(CEC_POWER_STATUS_IN_TRANSITION_STANDBY_TO_ON
);
131 bool CCECBusDevice::Standby(void)
133 CLibCEC::AddLog(CEC_LOG_DEBUG
, "<< putting '%s' (%X) in standby mode", GetLogicalAddressName(), m_iLogicalAddress
);
135 bool bReturn
= m_handler
->TransmitStandby(GetMyLogicalAddress(), m_iLogicalAddress
);
142 cec_version
CCECBusDevice::GetCecVersion(bool bUpdate
/* = false */)
144 bool bRequestUpdate(false);
146 CLockObject
lock(m_mutex
);
147 bRequestUpdate
= (GetStatus() == CEC_DEVICE_STATUS_PRESENT
&&
148 (bUpdate
|| m_cecVersion
== CEC_VERSION_UNKNOWN
));
154 CLockObject
lock(m_mutex
);
158 bool CCECBusDevice::RequestCecVersion(void)
162 if (!MyLogicalAddressContains(m_iLogicalAddress
))
165 CLibCEC::AddLog(CEC_LOG_NOTICE
, "<< requesting CEC version of '%s' (%X)", GetLogicalAddressName(), m_iLogicalAddress
);
167 bReturn
= m_handler
->TransmitRequestCecVersion(GetMyLogicalAddress(), m_iLogicalAddress
);
173 const char* CCECBusDevice::GetLogicalAddressName(void) const
175 return ToString(m_iLogicalAddress
);
178 cec_menu_language
&CCECBusDevice::GetMenuLanguage(bool bUpdate
/* = false */)
180 bool bRequestUpdate(false);
182 CLockObject
lock(m_mutex
);
183 bRequestUpdate
= (GetStatus() == CEC_DEVICE_STATUS_PRESENT
&&
184 (bUpdate
|| !strcmp(m_menuLanguage
.language
, "???")));
188 RequestMenuLanguage();
190 CLockObject
lock(m_mutex
);
191 return m_menuLanguage
;
194 bool CCECBusDevice::RequestMenuLanguage(void)
198 if (!MyLogicalAddressContains(m_iLogicalAddress
) &&
199 !IsUnsupportedFeature(CEC_OPCODE_GET_MENU_LANGUAGE
))
202 CLibCEC::AddLog(CEC_LOG_NOTICE
, "<< requesting menu language of '%s' (%X)", GetLogicalAddressName(), m_iLogicalAddress
);
203 bReturn
= m_handler
->TransmitRequestMenuLanguage(GetMyLogicalAddress(), m_iLogicalAddress
);
209 cec_menu_state
CCECBusDevice::GetMenuState(void)
211 CLockObject
lock(m_mutex
);
215 cec_logical_address
CCECBusDevice::GetMyLogicalAddress(void) const
217 return m_processor
->GetLogicalAddress();
220 uint16_t CCECBusDevice::GetMyPhysicalAddress(void) const
222 return m_processor
->GetPhysicalAddress();
225 CStdString
CCECBusDevice::GetOSDName(bool bUpdate
/* = false */)
227 bool bRequestUpdate(false);
229 CLockObject
lock(m_mutex
);
230 bRequestUpdate
= (GetStatus() == CEC_DEVICE_STATUS_PRESENT
&&
231 (bUpdate
|| m_strDeviceName
.Equals(ToString(m_iLogicalAddress
))) &&
232 m_type
!= CEC_DEVICE_TYPE_TV
);
238 CLockObject
lock(m_mutex
);
239 return m_strDeviceName
;
242 bool CCECBusDevice::RequestOSDName(void)
246 if (!MyLogicalAddressContains(m_iLogicalAddress
) &&
247 !IsUnsupportedFeature(CEC_OPCODE_GIVE_OSD_NAME
))
250 CLibCEC::AddLog(CEC_LOG_NOTICE
, "<< requesting OSD name of '%s' (%X)", GetLogicalAddressName(), m_iLogicalAddress
);
251 bReturn
= m_handler
->TransmitRequestOSDName(GetMyLogicalAddress(), m_iLogicalAddress
);
257 uint16_t CCECBusDevice::GetPhysicalAddress(bool bUpdate
/* = false */)
259 bool bRequestUpdate(false);
261 CLockObject
lock(m_mutex
);
262 bRequestUpdate
= (GetStatus() == CEC_DEVICE_STATUS_PRESENT
&&
263 (m_iPhysicalAddress
== 0xFFFF || bUpdate
));
266 if (bRequestUpdate
&& !RequestPhysicalAddress())
267 CLibCEC::AddLog(CEC_LOG_ERROR
, "failed to request the physical address");
269 CLockObject
lock(m_mutex
);
270 return m_iPhysicalAddress
;
273 bool CCECBusDevice::RequestPhysicalAddress(void)
277 if (!MyLogicalAddressContains(m_iLogicalAddress
))
280 CLibCEC::AddLog(CEC_LOG_NOTICE
, "<< requesting physical address of '%s' (%X)", GetLogicalAddressName(), m_iLogicalAddress
);
281 bReturn
= m_handler
->TransmitRequestPhysicalAddress(GetMyLogicalAddress(), m_iLogicalAddress
);
287 cec_power_status
CCECBusDevice::GetPowerStatus(bool bUpdate
/* = false */)
289 bool bRequestUpdate(false);
291 CLockObject
lock(m_mutex
);
292 bRequestUpdate
= (GetStatus() == CEC_DEVICE_STATUS_PRESENT
&&
293 (bUpdate
|| m_powerStatus
== CEC_POWER_STATUS_UNKNOWN
||
294 m_powerStatus
== CEC_POWER_STATUS_IN_TRANSITION_STANDBY_TO_ON
||
295 m_powerStatus
== CEC_POWER_STATUS_IN_TRANSITION_ON_TO_STANDBY
||
296 GetTimeMs() - m_iLastPowerStateUpdate
>= CEC_POWER_STATE_REFRESH_TIME
));
300 RequestPowerStatus();
302 CLockObject
lock(m_mutex
);
303 return m_powerStatus
;
306 bool CCECBusDevice::RequestPowerStatus(void)
310 if (!MyLogicalAddressContains(m_iLogicalAddress
) &&
311 !IsUnsupportedFeature(CEC_OPCODE_GIVE_DEVICE_POWER_STATUS
))
314 CLibCEC::AddLog(CEC_LOG_NOTICE
, "<< requesting power status of '%s' (%X)", GetLogicalAddressName(), m_iLogicalAddress
);
315 bReturn
= m_handler
->TransmitRequestPowerStatus(GetMyLogicalAddress(), m_iLogicalAddress
);
321 cec_vendor_id
CCECBusDevice::GetVendorId(bool bUpdate
/* = false */)
323 bool bRequestUpdate(false);
325 CLockObject
lock(m_mutex
);
326 bRequestUpdate
= (GetStatus() == CEC_DEVICE_STATUS_PRESENT
&&
327 (bUpdate
|| m_vendor
== CEC_VENDOR_UNKNOWN
));
333 CLockObject
lock(m_mutex
);
337 bool CCECBusDevice::RequestVendorId(void)
341 if (!MyLogicalAddressContains(m_iLogicalAddress
))
344 CLibCEC::AddLog(CEC_LOG_NOTICE
, "<< requesting vendor ID of '%s' (%X)", GetLogicalAddressName(), m_iLogicalAddress
);
345 bReturn
= m_handler
->TransmitRequestVendorId(GetMyLogicalAddress(), m_iLogicalAddress
);
348 ReplaceHandler(true);
353 const char *CCECBusDevice::GetVendorName(bool bUpdate
/* = false */)
355 return ToString(GetVendorId(bUpdate
));
358 bool CCECBusDevice::MyLogicalAddressContains(cec_logical_address address
) const
360 return m_processor
->HasLogicalAddress(address
);
363 bool CCECBusDevice::NeedsPoll(void)
365 bool bSendPoll(false);
366 switch (m_iLogicalAddress
)
368 case CECDEVICE_PLAYBACKDEVICE3
:
370 cec_bus_device_status status
= m_processor
->m_busDevices
[CECDEVICE_PLAYBACKDEVICE2
]->GetStatus();
371 bSendPoll
= (status
== CEC_DEVICE_STATUS_PRESENT
|| status
== CEC_DEVICE_STATUS_HANDLED_BY_LIBCEC
);
374 case CECDEVICE_PLAYBACKDEVICE2
:
376 cec_bus_device_status status
= m_processor
->m_busDevices
[CECDEVICE_PLAYBACKDEVICE1
]->GetStatus();
377 bSendPoll
= (status
== CEC_DEVICE_STATUS_PRESENT
|| status
== CEC_DEVICE_STATUS_HANDLED_BY_LIBCEC
);
380 case CECDEVICE_RECORDINGDEVICE3
:
382 cec_bus_device_status status
= m_processor
->m_busDevices
[CECDEVICE_RECORDINGDEVICE2
]->GetStatus();
383 bSendPoll
= (status
== CEC_DEVICE_STATUS_PRESENT
|| status
== CEC_DEVICE_STATUS_HANDLED_BY_LIBCEC
);
386 case CECDEVICE_RECORDINGDEVICE2
:
388 cec_bus_device_status status
= m_processor
->m_busDevices
[CECDEVICE_RECORDINGDEVICE1
]->GetStatus();
389 bSendPoll
= (status
== CEC_DEVICE_STATUS_PRESENT
|| status
== CEC_DEVICE_STATUS_HANDLED_BY_LIBCEC
);
392 case CECDEVICE_TUNER4
:
394 cec_bus_device_status status
= m_processor
->m_busDevices
[CECDEVICE_TUNER3
]->GetStatus();
395 bSendPoll
= (status
== CEC_DEVICE_STATUS_PRESENT
|| status
== CEC_DEVICE_STATUS_HANDLED_BY_LIBCEC
);
398 case CECDEVICE_TUNER3
:
400 cec_bus_device_status status
= m_processor
->m_busDevices
[CECDEVICE_TUNER2
]->GetStatus();
401 bSendPoll
= (status
== CEC_DEVICE_STATUS_PRESENT
|| status
== CEC_DEVICE_STATUS_HANDLED_BY_LIBCEC
);
404 case CECDEVICE_TUNER2
:
406 cec_bus_device_status status
= m_processor
->m_busDevices
[CECDEVICE_TUNER1
]->GetStatus();
407 bSendPoll
= (status
== CEC_DEVICE_STATUS_PRESENT
|| status
== CEC_DEVICE_STATUS_HANDLED_BY_LIBCEC
);
410 case CECDEVICE_AUDIOSYSTEM
:
411 case CECDEVICE_PLAYBACKDEVICE1
:
412 case CECDEVICE_RECORDINGDEVICE1
:
413 case CECDEVICE_TUNER1
:
424 cec_bus_device_status
CCECBusDevice::GetStatus(bool bForcePoll
/* = false */)
426 CLockObject
lock(m_mutex
);
427 if (m_deviceStatus
!= CEC_DEVICE_STATUS_HANDLED_BY_LIBCEC
&&
428 (m_deviceStatus
== CEC_DEVICE_STATUS_UNKNOWN
|| bForcePoll
))
431 bool bPollAcked(false);
432 if (bForcePoll
|| NeedsPoll())
433 bPollAcked
= m_processor
->PollDevice(m_iLogicalAddress
);
436 m_deviceStatus
= bPollAcked
? CEC_DEVICE_STATUS_PRESENT
: CEC_DEVICE_STATUS_NOT_PRESENT
;
439 return m_deviceStatus
;
446 void CCECBusDevice::SetCecVersion(const cec_version newVersion
)
448 m_cecVersion
= newVersion
;
449 CLibCEC::AddLog(CEC_LOG_DEBUG
, "%s (%X): CEC version %s", GetLogicalAddressName(), m_iLogicalAddress
, ToString(newVersion
));
452 void CCECBusDevice::SetMenuLanguage(const cec_menu_language
&language
)
454 CLockObject
lock(m_mutex
);
455 if (language
.device
== m_iLogicalAddress
)
457 CLibCEC::AddLog(CEC_LOG_DEBUG
, ">> %s (%X): menu language set to '%s'", GetLogicalAddressName(), m_iLogicalAddress
, language
.language
);
458 m_menuLanguage
= language
;
462 void CCECBusDevice::SetOSDName(CStdString strName
)
464 CLockObject
lock(m_mutex
);
465 if (m_strDeviceName
!= strName
)
467 CLibCEC::AddLog(CEC_LOG_DEBUG
, ">> %s (%X): osd name set to '%s'", GetLogicalAddressName(), m_iLogicalAddress
, strName
.c_str());
468 m_strDeviceName
= strName
;
472 void CCECBusDevice::SetMenuState(const cec_menu_state state
)
474 CLockObject
lock(m_mutex
);
475 if (m_menuState
!= state
)
477 CLibCEC::AddLog(CEC_LOG_DEBUG
, ">> %s (%X): menu state set to '%s'", GetLogicalAddressName(), m_iLogicalAddress
, ToString(m_menuState
));
482 void CCECBusDevice::SetInactiveSource(void)
485 CLockObject
lock(m_mutex
);
486 m_bActiveSource
= false;
489 if (MyLogicalAddressContains(m_iLogicalAddress
))
490 SetPowerStatus(CEC_POWER_STATUS_STANDBY
);
493 void CCECBusDevice::SetActiveSource(void)
495 CLockObject
lock(m_mutex
);
496 if (!m_bActiveSource
)
497 CLibCEC::AddLog(CEC_LOG_DEBUG
, "making %s (%x) the active source", GetLogicalAddressName(), m_iLogicalAddress
);
499 for (int iPtr
= 0; iPtr
< 16; iPtr
++)
500 if (iPtr
!= m_iLogicalAddress
)
501 m_processor
->m_busDevices
[iPtr
]->SetInactiveSource();
503 m_bActiveSource
= true;
504 SetPowerStatus(CEC_POWER_STATUS_ON
);
507 bool CCECBusDevice::TryLogicalAddress(void)
509 CLibCEC::AddLog(CEC_LOG_DEBUG
, "trying logical address '%s'", GetLogicalAddressName());
511 m_processor
->SetAckMask(0);
512 if (!TransmitPoll(m_iLogicalAddress
))
514 CLibCEC::AddLog(CEC_LOG_NOTICE
, "using logical address '%s'", GetLogicalAddressName());
515 SetDeviceStatus(CEC_DEVICE_STATUS_HANDLED_BY_LIBCEC
);
520 CLibCEC::AddLog(CEC_LOG_DEBUG
, "logical address '%s' already taken", GetLogicalAddressName());
521 SetDeviceStatus(CEC_DEVICE_STATUS_PRESENT
);
525 void CCECBusDevice::SetDeviceStatus(const cec_bus_device_status newStatus
)
527 CLockObject
lock(m_mutex
);
530 case CEC_DEVICE_STATUS_UNKNOWN
:
532 m_powerStatus
= CEC_POWER_STATUS_UNKNOWN
;
533 m_vendor
= CEC_VENDOR_UNKNOWN
;
534 m_menuState
= CEC_MENU_STATE_ACTIVATED
;
535 m_bActiveSource
= false;
537 m_cecVersion
= CEC_VERSION_UNKNOWN
;
538 m_deviceStatus
= newStatus
;
540 case CEC_DEVICE_STATUS_HANDLED_BY_LIBCEC
:
542 m_powerStatus
= CEC_POWER_STATUS_IN_TRANSITION_STANDBY_TO_ON
;
543 m_vendor
= CEC_VENDOR_UNKNOWN
;
544 m_menuState
= CEC_MENU_STATE_ACTIVATED
;
545 m_bActiveSource
= false;
547 m_cecVersion
= CEC_VERSION_1_3A
;
548 m_deviceStatus
= newStatus
;
550 case CEC_DEVICE_STATUS_PRESENT
:
551 case CEC_DEVICE_STATUS_NOT_PRESENT
:
552 m_deviceStatus
= newStatus
;
557 void CCECBusDevice::SetPhysicalAddress(uint16_t iNewAddress
)
559 CLockObject
lock(m_mutex
);
560 if (iNewAddress
> 0 && m_iPhysicalAddress
!= iNewAddress
)
562 CLibCEC::AddLog(CEC_LOG_DEBUG
, ">> %s (%X): physical address changed from %04x to %04x", GetLogicalAddressName(), m_iLogicalAddress
, m_iPhysicalAddress
, iNewAddress
);
563 m_iPhysicalAddress
= iNewAddress
;
567 void CCECBusDevice::SetStreamPath(uint16_t iNewAddress
, uint16_t iOldAddress
/* = 0 */)
569 CLockObject
lock(m_mutex
);
572 CLibCEC::AddLog(CEC_LOG_DEBUG
, ">> %s (%X): stream path changed from %04x to %04x", GetLogicalAddressName(), m_iLogicalAddress
, iOldAddress
== 0 ? m_iStreamPath
: iOldAddress
, iNewAddress
);
573 m_iStreamPath
= iNewAddress
;
578 SetPowerStatus(CEC_POWER_STATUS_ON
);
583 void CCECBusDevice::SetPowerStatus(const cec_power_status powerStatus
)
585 CLockObject
lock(m_mutex
);
586 if (m_powerStatus
!= powerStatus
)
588 m_iLastPowerStateUpdate
= GetTimeMs();
589 CLibCEC::AddLog(CEC_LOG_DEBUG
, ">> %s (%X): power status changed from '%s' to '%s'", GetLogicalAddressName(), m_iLogicalAddress
, ToString(m_powerStatus
), ToString(powerStatus
));
590 m_powerStatus
= powerStatus
;
594 void CCECBusDevice::MarkBusy(void)
596 CLockObject
handlerLock(m_handlerMutex
);
597 ++m_iHandlerUseCount
;
600 void CCECBusDevice::MarkReady(void)
602 CLockObject
handlerLock(m_handlerMutex
);
603 if (m_iHandlerUseCount
> 0)
604 --m_iHandlerUseCount
;
607 bool CCECBusDevice::ReplaceHandler(bool bActivateSource
/* = true */)
609 bool bInitHandler(false);
611 CTryLockObject
lock(m_mutex
);
612 if (!lock
.IsLocked())
615 CLockObject
handlerLock(m_handlerMutex
);
616 if (m_iHandlerUseCount
> 0)
621 if (m_vendor
!= m_handler
->GetVendorId())
623 if (CCECCommandHandler::HasSpecificHandler(m_vendor
))
625 CLibCEC::AddLog(CEC_LOG_DEBUG
, "replacing the command handler for device '%s' (%x)", GetLogicalAddressName(), GetLogicalAddress());
630 case CEC_VENDOR_SAMSUNG
:
631 m_handler
= new CANCommandHandler(this);
634 m_handler
= new CSLCommandHandler(this);
636 case CEC_VENDOR_PANASONIC
:
637 m_handler
= new CVLCommandHandler(this);
640 m_handler
= new CCECCommandHandler(this);
644 m_handler
->SetVendorId(m_vendor
);
652 m_handler
->InitHandler();
654 if (bActivateSource
&& m_processor
->GetLogicalAddresses().IsSet(m_iLogicalAddress
) && m_processor
->IsInitialised() && IsActiveSource())
655 m_handler
->ActivateSource();
663 bool CCECBusDevice::SetVendorId(uint64_t iVendorId
)
665 bool bVendorChanged(false);
668 CLockObject
lock(m_mutex
);
669 bVendorChanged
= (m_vendor
!= (cec_vendor_id
)iVendorId
);
670 m_vendor
= (cec_vendor_id
)iVendorId
;
673 CLibCEC::AddLog(CEC_LOG_DEBUG
, "%s (%X): vendor = %s (%06x)", GetLogicalAddressName(), m_iLogicalAddress
, ToString(m_vendor
), m_vendor
);
675 return bVendorChanged
;
679 /** @name Transmit methods */
681 bool CCECBusDevice::TransmitActiveSource(void)
683 bool bSendActiveSource(false);
686 CLockObject
lock(m_mutex
);
687 if (m_powerStatus
!= CEC_POWER_STATUS_ON
&& m_powerStatus
!= CEC_POWER_STATUS_IN_TRANSITION_STANDBY_TO_ON
)
688 CLibCEC::AddLog(CEC_LOG_DEBUG
, "<< %s (%X) is not powered on", GetLogicalAddressName(), m_iLogicalAddress
);
689 else if (m_bActiveSource
)
691 CLibCEC::AddLog(CEC_LOG_NOTICE
, "<< %s (%X) -> broadcast (F): active source (%4x)", GetLogicalAddressName(), m_iLogicalAddress
, m_iPhysicalAddress
);
692 bSendActiveSource
= true;
695 CLibCEC::AddLog(CEC_LOG_DEBUG
, "<< %s (%X) is not the active source", GetLogicalAddressName(), m_iLogicalAddress
);
698 if (bSendActiveSource
)
701 m_handler
->TransmitActiveSource(m_iLogicalAddress
, m_iPhysicalAddress
);
709 bool CCECBusDevice::TransmitCECVersion(cec_logical_address dest
)
713 CLockObject
lock(m_mutex
);
714 CLibCEC::AddLog(CEC_LOG_NOTICE
, "<< %s (%X) -> %s (%X): cec version %s", GetLogicalAddressName(), m_iLogicalAddress
, ToString(dest
), dest
, ToString(m_cecVersion
));
715 version
= m_cecVersion
;
719 bool bReturn
= m_handler
->TransmitCECVersion(m_iLogicalAddress
, dest
, version
);
724 bool CCECBusDevice::TransmitImageViewOn(void)
727 CLockObject
lock(m_mutex
);
728 if (m_powerStatus
!= CEC_POWER_STATUS_ON
&& m_powerStatus
!= CEC_POWER_STATUS_IN_TRANSITION_STANDBY_TO_ON
)
730 CLibCEC::AddLog(CEC_LOG_DEBUG
, "<< %s (%X) is not powered on", GetLogicalAddressName(), m_iLogicalAddress
);
736 m_handler
->TransmitImageViewOn(m_iLogicalAddress
, CECDEVICE_TV
);
741 bool CCECBusDevice::TransmitInactiveSource(void)
743 uint16_t iPhysicalAddress
;
745 CLockObject
lock(m_mutex
);
746 CLibCEC::AddLog(CEC_LOG_NOTICE
, "<< %s (%X) -> broadcast (F): inactive source", GetLogicalAddressName(), m_iLogicalAddress
);
747 iPhysicalAddress
= m_iPhysicalAddress
;
751 bool bReturn
= m_handler
->TransmitInactiveSource(m_iLogicalAddress
, iPhysicalAddress
);
756 bool CCECBusDevice::TransmitMenuState(cec_logical_address dest
)
758 cec_menu_state menuState
;
760 CLockObject
lock(m_mutex
);
761 CLibCEC::AddLog(CEC_LOG_NOTICE
, "<< %s (%X) -> %s (%X): menu state '%s'", GetLogicalAddressName(), m_iLogicalAddress
, ToString(dest
), dest
, ToString(m_menuState
));
762 menuState
= m_menuState
;
766 bool bReturn
= m_handler
->TransmitMenuState(m_iLogicalAddress
, dest
, menuState
);
771 bool CCECBusDevice::TransmitOSDName(cec_logical_address dest
)
773 CStdString strDeviceName
;
775 CLockObject
lock(m_mutex
);
776 CLibCEC::AddLog(CEC_LOG_NOTICE
, "<< %s (%X) -> %s (%X): OSD name '%s'", GetLogicalAddressName(), m_iLogicalAddress
, ToString(dest
), dest
, m_strDeviceName
.c_str());
777 strDeviceName
= m_strDeviceName
;
781 bool bReturn
= m_handler
->TransmitOSDName(m_iLogicalAddress
, dest
, strDeviceName
);
786 bool CCECBusDevice::TransmitOSDString(cec_logical_address dest
, cec_display_control duration
, const char *strMessage
)
789 if (!IsUnsupportedFeature(CEC_OPCODE_SET_OSD_STRING
))
791 CLibCEC::AddLog(CEC_LOG_NOTICE
, "<< %s (%X) -> %s (%X): display OSD message '%s'", GetLogicalAddressName(), m_iLogicalAddress
, ToString(dest
), dest
, strMessage
);
793 bReturn
= m_handler
->TransmitOSDString(m_iLogicalAddress
, dest
, duration
, strMessage
);
799 bool CCECBusDevice::TransmitPhysicalAddress(void)
801 uint16_t iPhysicalAddress
;
802 cec_device_type type
;
804 CLockObject
lock(m_mutex
);
805 if (m_iPhysicalAddress
== 0xffff)
808 CLibCEC::AddLog(CEC_LOG_NOTICE
, "<< %s (%X) -> broadcast (F): physical adddress %4x", GetLogicalAddressName(), m_iLogicalAddress
, m_iPhysicalAddress
);
809 iPhysicalAddress
= m_iPhysicalAddress
;
814 bool bReturn
= m_handler
->TransmitPhysicalAddress(m_iLogicalAddress
, iPhysicalAddress
, type
);
819 bool CCECBusDevice::TransmitPoll(cec_logical_address dest
)
822 if (dest
== CECDEVICE_UNKNOWN
)
823 dest
= m_iLogicalAddress
;
825 CCECBusDevice
*destDevice
= m_processor
->m_busDevices
[dest
];
826 if (destDevice
->m_deviceStatus
== CEC_DEVICE_STATUS_HANDLED_BY_LIBCEC
)
830 CLibCEC::AddLog(CEC_LOG_NOTICE
, "<< %s (%X) -> %s (%X): POLL", GetLogicalAddressName(), m_iLogicalAddress
, ToString(dest
), dest
);
831 bReturn
= m_handler
->TransmitPoll(m_iLogicalAddress
, dest
);
832 CLibCEC::AddLog(CEC_LOG_DEBUG
, bReturn
? ">> POLL sent" : ">> POLL not sent");
834 CLockObject
lock(m_mutex
);
837 m_iLastActive
= GetTimeMs();
838 destDevice
->m_deviceStatus
= CEC_DEVICE_STATUS_PRESENT
;
841 destDevice
->m_deviceStatus
= CEC_DEVICE_STATUS_NOT_PRESENT
;
847 bool CCECBusDevice::TransmitPowerState(cec_logical_address dest
)
849 cec_power_status state
;
851 CLockObject
lock(m_mutex
);
852 if (!IsActiveSource())
853 SetPowerStatus(CEC_POWER_STATUS_STANDBY
);
855 CLibCEC::AddLog(CEC_LOG_NOTICE
, "<< %s (%X) -> %s (%X): %s", GetLogicalAddressName(), m_iLogicalAddress
, ToString(dest
), dest
, ToString(m_powerStatus
));
856 state
= m_powerStatus
;
860 bool bReturn
= m_handler
->TransmitPowerState(m_iLogicalAddress
, dest
, state
);
865 bool CCECBusDevice::TransmitVendorID(cec_logical_address dest
, bool bSendAbort
/* = true */)
870 CLockObject
lock(m_mutex
);
871 iVendorId
= (uint64_t)m_vendor
;
875 if (iVendorId
== CEC_VENDOR_UNKNOWN
)
879 CLibCEC::AddLog(CEC_LOG_NOTICE
, "<< %s (%X) -> %s (%X): vendor id feature abort", GetLogicalAddressName(), m_iLogicalAddress
, ToString(dest
), dest
);
880 m_processor
->TransmitAbort(dest
, CEC_OPCODE_GIVE_DEVICE_VENDOR_ID
);
886 CLibCEC::AddLog(CEC_LOG_NOTICE
, "<< %s (%X) -> %s (%X): vendor id %s (%x)", GetLogicalAddressName(), m_iLogicalAddress
, ToString(dest
), dest
, ToString((cec_vendor_id
)iVendorId
), iVendorId
);
887 bReturn
= m_handler
->TransmitVendorID(m_iLogicalAddress
, iVendorId
);
893 bool CCECBusDevice::TransmitKeypress(cec_user_control_code key
, bool bWait
/* = true */)
896 bool bReturn
= m_handler
->TransmitKeypress(m_processor
->GetLogicalAddress(), m_iLogicalAddress
, key
, bWait
);
901 bool CCECBusDevice::TransmitKeyRelease(bool bWait
/* = true */)
904 bool bReturn
= m_handler
->TransmitKeyRelease(m_processor
->GetLogicalAddress(), m_iLogicalAddress
, bWait
);
909 bool CCECBusDevice::IsUnsupportedFeature(cec_opcode opcode
) const
911 return m_unsupportedFeatures
.find(opcode
) != m_unsupportedFeatures
.end();
914 void CCECBusDevice::SetUnsupportedFeature(cec_opcode opcode
)
916 m_unsupportedFeatures
.insert(opcode
);
919 bool CCECBusDevice::ActivateSource(void)
922 bool bReturn
= m_handler
->ActivateSource();
927 void CCECBusDevice::HandlePoll(cec_logical_address iDestination
)
929 CLibCEC::AddLog(CEC_LOG_DEBUG
, "<< POLL: %s (%x) -> %s (%x)", ToString(m_iLogicalAddress
), m_iLogicalAddress
, ToString(iDestination
), iDestination
);
930 m_bAwaitingReceiveFailed
= true;
933 bool CCECBusDevice::HandleReceiveFailed(void)
935 bool bReturn
= m_bAwaitingReceiveFailed
;
936 m_bAwaitingReceiveFailed
= false;