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 CLibCEC::AddLog(CEC_LOG_DEBUG
, "<< powering on '%s' (%X)", GetLogicalAddressName(), m_iLogicalAddress
);
119 if (m_handler
->TransmitImageViewOn(GetMyLogicalAddress(), m_iLogicalAddress
))
122 CLockObject
lock(m_mutex
);
123 // m_powerStatus = CEC_POWER_STATUS_UNKNOWN;
124 m_powerStatus
= CEC_POWER_STATUS_IN_TRANSITION_STANDBY_TO_ON
;
126 // cec_power_status status = GetPowerStatus();
127 // if (status == CEC_POWER_STATUS_STANDBY || status == CEC_POWER_STATUS_UNKNOWN)
129 // /* sending the normal power on command appears to have failed */
130 // CStdString strLog;
131 // strLog.Format("<< sending power on keypress to '%s' (%X)", GetLogicalAddressName(), m_iLogicalAddress);
132 // CLibCEC::AddLog(CEC_LOG_DEBUG, strLog.c_str());
134 // TransmitKeypress(CEC_USER_CONTROL_CODE_POWER);
135 // return TransmitKeyRelease();
144 bool CCECBusDevice::Standby(void)
146 CLibCEC::AddLog(CEC_LOG_DEBUG
, "<< putting '%s' (%X) in standby mode", GetLogicalAddressName(), m_iLogicalAddress
);
148 bool bReturn
= m_handler
->TransmitStandby(GetMyLogicalAddress(), m_iLogicalAddress
);
155 cec_version
CCECBusDevice::GetCecVersion(bool bUpdate
/* = false */)
157 bool bRequestUpdate(false);
159 CLockObject
lock(m_mutex
);
160 bRequestUpdate
= (GetStatus() == CEC_DEVICE_STATUS_PRESENT
&&
161 (bUpdate
|| m_cecVersion
== CEC_VERSION_UNKNOWN
));
167 CLockObject
lock(m_mutex
);
171 bool CCECBusDevice::RequestCecVersion(void)
175 if (!MyLogicalAddressContains(m_iLogicalAddress
))
178 CLibCEC::AddLog(CEC_LOG_NOTICE
, "<< requesting CEC version of '%s' (%X)", GetLogicalAddressName(), m_iLogicalAddress
);
180 bReturn
= m_handler
->TransmitRequestCecVersion(GetMyLogicalAddress(), m_iLogicalAddress
);
186 const char* CCECBusDevice::GetLogicalAddressName(void) const
188 return ToString(m_iLogicalAddress
);
191 cec_menu_language
&CCECBusDevice::GetMenuLanguage(bool bUpdate
/* = false */)
193 bool bRequestUpdate(false);
195 CLockObject
lock(m_mutex
);
196 bRequestUpdate
= (GetStatus() == CEC_DEVICE_STATUS_PRESENT
&&
197 (bUpdate
|| !strcmp(m_menuLanguage
.language
, "???")));
201 RequestMenuLanguage();
203 CLockObject
lock(m_mutex
);
204 return m_menuLanguage
;
207 bool CCECBusDevice::RequestMenuLanguage(void)
211 if (!MyLogicalAddressContains(m_iLogicalAddress
) &&
212 !IsUnsupportedFeature(CEC_OPCODE_GET_MENU_LANGUAGE
))
215 CLibCEC::AddLog(CEC_LOG_NOTICE
, "<< requesting menu language of '%s' (%X)", GetLogicalAddressName(), m_iLogicalAddress
);
216 bReturn
= m_handler
->TransmitRequestMenuLanguage(GetMyLogicalAddress(), m_iLogicalAddress
);
222 cec_menu_state
CCECBusDevice::GetMenuState(void)
224 CLockObject
lock(m_mutex
);
228 cec_logical_address
CCECBusDevice::GetMyLogicalAddress(void) const
230 return m_processor
->GetLogicalAddress();
233 uint16_t CCECBusDevice::GetMyPhysicalAddress(void) const
235 return m_processor
->GetPhysicalAddress();
238 CStdString
CCECBusDevice::GetOSDName(bool bUpdate
/* = false */)
240 bool bRequestUpdate(false);
242 CLockObject
lock(m_mutex
);
243 bRequestUpdate
= (GetStatus() == CEC_DEVICE_STATUS_PRESENT
&&
244 (bUpdate
|| m_strDeviceName
.Equals(ToString(m_iLogicalAddress
))) &&
245 m_type
!= CEC_DEVICE_TYPE_TV
);
251 CLockObject
lock(m_mutex
);
252 return m_strDeviceName
;
255 bool CCECBusDevice::RequestOSDName(void)
259 if (!MyLogicalAddressContains(m_iLogicalAddress
) &&
260 !IsUnsupportedFeature(CEC_OPCODE_GIVE_OSD_NAME
))
263 CLibCEC::AddLog(CEC_LOG_NOTICE
, "<< requesting OSD name of '%s' (%X)", GetLogicalAddressName(), m_iLogicalAddress
);
264 bReturn
= m_handler
->TransmitRequestOSDName(GetMyLogicalAddress(), m_iLogicalAddress
);
270 uint16_t CCECBusDevice::GetPhysicalAddress(bool bUpdate
/* = false */)
272 bool bRequestUpdate(false);
274 CLockObject
lock(m_mutex
);
275 bRequestUpdate
= (GetStatus() == CEC_DEVICE_STATUS_PRESENT
&&
276 (m_iPhysicalAddress
== 0xFFFF || bUpdate
));
279 if (bRequestUpdate
&& !RequestPhysicalAddress())
280 CLibCEC::AddLog(CEC_LOG_ERROR
, "failed to request the physical address");
282 CLockObject
lock(m_mutex
);
283 return m_iPhysicalAddress
;
286 bool CCECBusDevice::RequestPhysicalAddress(void)
290 if (!MyLogicalAddressContains(m_iLogicalAddress
))
293 CLibCEC::AddLog(CEC_LOG_NOTICE
, "<< requesting physical address of '%s' (%X)", GetLogicalAddressName(), m_iLogicalAddress
);
294 bReturn
= m_handler
->TransmitRequestPhysicalAddress(GetMyLogicalAddress(), m_iLogicalAddress
);
300 cec_power_status
CCECBusDevice::GetPowerStatus(bool bUpdate
/* = false */)
302 bool bRequestUpdate(false);
304 CLockObject
lock(m_mutex
);
305 bRequestUpdate
= (GetStatus() == CEC_DEVICE_STATUS_PRESENT
&&
306 (bUpdate
|| m_powerStatus
== CEC_POWER_STATUS_UNKNOWN
||
307 m_powerStatus
== CEC_POWER_STATUS_IN_TRANSITION_STANDBY_TO_ON
||
308 m_powerStatus
== CEC_POWER_STATUS_IN_TRANSITION_ON_TO_STANDBY
||
309 GetTimeMs() - m_iLastPowerStateUpdate
>= CEC_POWER_STATE_REFRESH_TIME
));
313 RequestPowerStatus();
315 CLockObject
lock(m_mutex
);
316 return m_powerStatus
;
319 bool CCECBusDevice::RequestPowerStatus(void)
323 if (!MyLogicalAddressContains(m_iLogicalAddress
) &&
324 !IsUnsupportedFeature(CEC_OPCODE_GIVE_DEVICE_POWER_STATUS
))
327 CLibCEC::AddLog(CEC_LOG_NOTICE
, "<< requesting power status of '%s' (%X)", GetLogicalAddressName(), m_iLogicalAddress
);
328 bReturn
= m_handler
->TransmitRequestPowerStatus(GetMyLogicalAddress(), m_iLogicalAddress
);
334 cec_vendor_id
CCECBusDevice::GetVendorId(bool bUpdate
/* = false */)
336 bool bRequestUpdate(false);
338 CLockObject
lock(m_mutex
);
339 bRequestUpdate
= (GetStatus() == CEC_DEVICE_STATUS_PRESENT
&&
340 (bUpdate
|| m_vendor
== CEC_VENDOR_UNKNOWN
));
346 CLockObject
lock(m_mutex
);
350 bool CCECBusDevice::RequestVendorId(void)
354 if (!MyLogicalAddressContains(m_iLogicalAddress
))
357 CLibCEC::AddLog(CEC_LOG_NOTICE
, "<< requesting vendor ID of '%s' (%X)", GetLogicalAddressName(), m_iLogicalAddress
);
358 bReturn
= m_handler
->TransmitRequestVendorId(GetMyLogicalAddress(), m_iLogicalAddress
);
361 ReplaceHandler(true);
366 const char *CCECBusDevice::GetVendorName(bool bUpdate
/* = false */)
368 return ToString(GetVendorId(bUpdate
));
371 bool CCECBusDevice::MyLogicalAddressContains(cec_logical_address address
) const
373 return m_processor
->HasLogicalAddress(address
);
376 bool CCECBusDevice::NeedsPoll(void)
378 bool bSendPoll(false);
379 switch (m_iLogicalAddress
)
381 case CECDEVICE_PLAYBACKDEVICE3
:
382 if (m_processor
->m_busDevices
[CECDEVICE_PLAYBACKDEVICE2
]->GetStatus() == CEC_DEVICE_STATUS_PRESENT
)
385 case CECDEVICE_PLAYBACKDEVICE2
:
386 if (m_processor
->m_busDevices
[CECDEVICE_PLAYBACKDEVICE1
]->GetStatus() == CEC_DEVICE_STATUS_PRESENT
)
389 case CECDEVICE_RECORDINGDEVICE3
:
390 if (m_processor
->m_busDevices
[CECDEVICE_RECORDINGDEVICE2
]->GetStatus() == CEC_DEVICE_STATUS_PRESENT
)
393 case CECDEVICE_RECORDINGDEVICE2
:
394 if (m_processor
->m_busDevices
[CECDEVICE_RECORDINGDEVICE1
]->GetStatus() == CEC_DEVICE_STATUS_PRESENT
)
397 case CECDEVICE_TUNER4
:
398 if (m_processor
->m_busDevices
[CECDEVICE_TUNER3
]->GetStatus() == CEC_DEVICE_STATUS_PRESENT
)
401 case CECDEVICE_TUNER3
:
402 if (m_processor
->m_busDevices
[CECDEVICE_TUNER2
]->GetStatus() == CEC_DEVICE_STATUS_PRESENT
)
405 case CECDEVICE_TUNER2
:
406 if (m_processor
->m_busDevices
[CECDEVICE_TUNER1
]->GetStatus() == CEC_DEVICE_STATUS_PRESENT
)
409 case CECDEVICE_AUDIOSYSTEM
:
410 case CECDEVICE_PLAYBACKDEVICE1
:
411 case CECDEVICE_RECORDINGDEVICE1
:
412 case CECDEVICE_TUNER1
:
423 cec_bus_device_status
CCECBusDevice::GetStatus(bool bForcePoll
/* = false */)
425 CLockObject
lock(m_mutex
);
426 if (m_deviceStatus
!= CEC_DEVICE_STATUS_HANDLED_BY_LIBCEC
&&
427 (m_deviceStatus
== CEC_DEVICE_STATUS_UNKNOWN
|| bForcePoll
))
430 bool bPollAcked(false);
431 if (bForcePoll
|| NeedsPoll())
432 bPollAcked
= m_processor
->PollDevice(m_iLogicalAddress
);
435 m_deviceStatus
= bPollAcked
? CEC_DEVICE_STATUS_PRESENT
: CEC_DEVICE_STATUS_NOT_PRESENT
;
438 return m_deviceStatus
;
445 void CCECBusDevice::SetCecVersion(const cec_version newVersion
)
447 m_cecVersion
= newVersion
;
448 CLibCEC::AddLog(CEC_LOG_DEBUG
, "%s (%X): CEC version %s", GetLogicalAddressName(), m_iLogicalAddress
, ToString(newVersion
));
451 void CCECBusDevice::SetMenuLanguage(const cec_menu_language
&language
)
453 CLockObject
lock(m_mutex
);
454 if (language
.device
== m_iLogicalAddress
)
456 CLibCEC::AddLog(CEC_LOG_DEBUG
, ">> %s (%X): menu language set to '%s'", GetLogicalAddressName(), m_iLogicalAddress
, language
.language
);
457 m_menuLanguage
= language
;
461 void CCECBusDevice::SetOSDName(CStdString strName
)
463 CLockObject
lock(m_mutex
);
464 if (m_strDeviceName
!= strName
)
466 CLibCEC::AddLog(CEC_LOG_DEBUG
, ">> %s (%X): osd name set to '%s'", GetLogicalAddressName(), m_iLogicalAddress
, strName
.c_str());
467 m_strDeviceName
= strName
;
471 void CCECBusDevice::SetMenuState(const cec_menu_state state
)
473 CLockObject
lock(m_mutex
);
474 if (m_menuState
!= state
)
476 CLibCEC::AddLog(CEC_LOG_DEBUG
, ">> %s (%X): menu state set to '%s'", GetLogicalAddressName(), m_iLogicalAddress
, ToString(m_menuState
));
481 void CCECBusDevice::SetInactiveSource(void)
484 CLockObject
lock(m_mutex
);
485 m_bActiveSource
= false;
488 if (MyLogicalAddressContains(m_iLogicalAddress
))
489 SetPowerStatus(CEC_POWER_STATUS_STANDBY
);
492 void CCECBusDevice::SetActiveSource(void)
494 CLockObject
lock(m_mutex
);
495 if (!m_bActiveSource
)
496 CLibCEC::AddLog(CEC_LOG_DEBUG
, "making %s (%x) the active source", GetLogicalAddressName(), m_iLogicalAddress
);
498 for (int iPtr
= 0; iPtr
< 16; iPtr
++)
499 if (iPtr
!= m_iLogicalAddress
)
500 m_processor
->m_busDevices
[iPtr
]->SetInactiveSource();
502 m_bActiveSource
= true;
503 m_powerStatus
= CEC_POWER_STATUS_ON
;
506 bool CCECBusDevice::TryLogicalAddress(void)
508 CLibCEC::AddLog(CEC_LOG_DEBUG
, "trying logical address '%s'", GetLogicalAddressName());
510 m_processor
->SetAckMask(0);
511 if (!TransmitPoll(m_iLogicalAddress
))
513 CLibCEC::AddLog(CEC_LOG_NOTICE
, "using logical address '%s'", GetLogicalAddressName());
514 SetDeviceStatus(CEC_DEVICE_STATUS_HANDLED_BY_LIBCEC
);
519 CLibCEC::AddLog(CEC_LOG_DEBUG
, "logical address '%s' already taken", GetLogicalAddressName());
520 SetDeviceStatus(CEC_DEVICE_STATUS_PRESENT
);
524 void CCECBusDevice::SetDeviceStatus(const cec_bus_device_status newStatus
)
526 CLockObject
lock(m_mutex
);
529 case CEC_DEVICE_STATUS_UNKNOWN
:
531 m_powerStatus
= CEC_POWER_STATUS_UNKNOWN
;
532 m_vendor
= CEC_VENDOR_UNKNOWN
;
533 m_menuState
= CEC_MENU_STATE_ACTIVATED
;
534 m_bActiveSource
= false;
536 m_cecVersion
= CEC_VERSION_UNKNOWN
;
537 m_deviceStatus
= newStatus
;
539 case CEC_DEVICE_STATUS_HANDLED_BY_LIBCEC
:
541 m_powerStatus
= CEC_POWER_STATUS_ON
;
542 m_vendor
= CEC_VENDOR_UNKNOWN
;
543 m_menuState
= CEC_MENU_STATE_ACTIVATED
;
544 m_bActiveSource
= false;
546 m_cecVersion
= CEC_VERSION_1_3A
;
547 m_deviceStatus
= newStatus
;
549 case CEC_DEVICE_STATUS_PRESENT
:
550 case CEC_DEVICE_STATUS_NOT_PRESENT
:
551 m_deviceStatus
= newStatus
;
556 void CCECBusDevice::SetPhysicalAddress(uint16_t iNewAddress
)
558 CLockObject
lock(m_mutex
);
559 if (iNewAddress
> 0 && m_iPhysicalAddress
!= iNewAddress
)
561 CLibCEC::AddLog(CEC_LOG_DEBUG
, ">> %s (%X): physical address changed from %04x to %04x", GetLogicalAddressName(), m_iLogicalAddress
, m_iPhysicalAddress
, iNewAddress
);
562 m_iPhysicalAddress
= iNewAddress
;
566 void CCECBusDevice::SetStreamPath(uint16_t iNewAddress
, uint16_t iOldAddress
/* = 0 */)
568 CLockObject
lock(m_mutex
);
571 CLibCEC::AddLog(CEC_LOG_DEBUG
, ">> %s (%X): stream path changed from %04x to %04x", GetLogicalAddressName(), m_iLogicalAddress
, iOldAddress
== 0 ? m_iStreamPath
: iOldAddress
, iNewAddress
);
572 m_iStreamPath
= iNewAddress
;
577 SetPowerStatus(CEC_POWER_STATUS_ON
);
582 void CCECBusDevice::SetPowerStatus(const cec_power_status powerStatus
)
584 CLockObject
lock(m_mutex
);
585 if (m_powerStatus
!= powerStatus
)
587 m_iLastPowerStateUpdate
= GetTimeMs();
588 CLibCEC::AddLog(CEC_LOG_DEBUG
, ">> %s (%X): power status changed from '%s' to '%s'", GetLogicalAddressName(), m_iLogicalAddress
, ToString(m_powerStatus
), ToString(powerStatus
));
589 m_powerStatus
= powerStatus
;
593 void CCECBusDevice::MarkBusy(void)
595 CLockObject
handlerLock(m_handlerMutex
);
596 ++m_iHandlerUseCount
;
599 void CCECBusDevice::MarkReady(void)
601 CLockObject
handlerLock(m_handlerMutex
);
602 if (m_iHandlerUseCount
> 0)
603 --m_iHandlerUseCount
;
606 bool CCECBusDevice::ReplaceHandler(bool bActivateSource
/* = true */)
608 CTryLockObject
lock(m_mutex
);
609 if (!lock
.IsLocked())
612 CLockObject
handlerLock(m_handlerMutex
);
613 if (m_iHandlerUseCount
> 0)
616 bool bInitHandler(false);
619 if (m_vendor
!= m_handler
->GetVendorId())
621 if (CCECCommandHandler::HasSpecificHandler(m_vendor
))
623 CLibCEC::AddLog(CEC_LOG_DEBUG
, "replacing the command handler for device '%s' (%x)", GetLogicalAddressName(), GetLogicalAddress());
628 case CEC_VENDOR_SAMSUNG
:
629 m_handler
= new CANCommandHandler(this);
632 m_handler
= new CSLCommandHandler(this);
634 case CEC_VENDOR_PANASONIC
:
635 m_handler
= new CVLCommandHandler(this);
638 m_handler
= new CCECCommandHandler(this);
642 m_handler
->SetVendorId(m_vendor
);
649 m_handler
->InitHandler();
651 if (bActivateSource
&& m_processor
->GetLogicalAddresses().IsSet(m_iLogicalAddress
) && m_processor
->IsInitialised() && IsActiveSource())
652 m_handler
->ActivateSource();
660 bool CCECBusDevice::SetVendorId(uint64_t iVendorId
)
662 bool bVendorChanged(false);
665 CLockObject
lock(m_mutex
);
666 bVendorChanged
= (m_vendor
!= (cec_vendor_id
)iVendorId
);
667 m_vendor
= (cec_vendor_id
)iVendorId
;
670 CLibCEC::AddLog(CEC_LOG_DEBUG
, "%s (%X): vendor = %s (%06x)", GetLogicalAddressName(), m_iLogicalAddress
, ToString(m_vendor
), m_vendor
);
672 return bVendorChanged
;
676 /** @name Transmit methods */
678 bool CCECBusDevice::TransmitActiveSource(void)
680 bool bSendActiveSource(false);
683 CLockObject
lock(m_mutex
);
684 if (m_powerStatus
!= CEC_POWER_STATUS_ON
)
685 CLibCEC::AddLog(CEC_LOG_DEBUG
, "<< %s (%X) is not powered on", GetLogicalAddressName(), m_iLogicalAddress
);
686 else if (m_bActiveSource
)
688 CLibCEC::AddLog(CEC_LOG_NOTICE
, "<< %s (%X) -> broadcast (F): active source (%4x)", GetLogicalAddressName(), m_iLogicalAddress
, m_iPhysicalAddress
);
689 bSendActiveSource
= true;
692 CLibCEC::AddLog(CEC_LOG_DEBUG
, "<< %s (%X) is not the active source", GetLogicalAddressName(), m_iLogicalAddress
);
695 if (bSendActiveSource
)
698 m_handler
->TransmitImageViewOn(m_iLogicalAddress
, CECDEVICE_TV
);
699 m_handler
->TransmitActiveSource(m_iLogicalAddress
, m_iPhysicalAddress
);
707 bool CCECBusDevice::TransmitCECVersion(cec_logical_address dest
)
711 CLockObject
lock(m_mutex
);
712 CLibCEC::AddLog(CEC_LOG_NOTICE
, "<< %s (%X) -> %s (%X): cec version %s", GetLogicalAddressName(), m_iLogicalAddress
, ToString(dest
), dest
, ToString(m_cecVersion
));
713 version
= m_cecVersion
;
717 bool bReturn
= m_handler
->TransmitCECVersion(m_iLogicalAddress
, dest
, version
);
722 bool CCECBusDevice::TransmitInactiveSource(void)
724 uint16_t iPhysicalAddress
;
726 CLockObject
lock(m_mutex
);
727 CLibCEC::AddLog(CEC_LOG_NOTICE
, "<< %s (%X) -> broadcast (F): inactive source", GetLogicalAddressName(), m_iLogicalAddress
);
728 iPhysicalAddress
= m_iPhysicalAddress
;
732 bool bReturn
= m_handler
->TransmitInactiveSource(m_iLogicalAddress
, iPhysicalAddress
);
737 bool CCECBusDevice::TransmitMenuState(cec_logical_address dest
)
739 cec_menu_state menuState
;
741 CLockObject
lock(m_mutex
);
742 CLibCEC::AddLog(CEC_LOG_NOTICE
, "<< %s (%X) -> %s (%X): menu state '%s'", GetLogicalAddressName(), m_iLogicalAddress
, ToString(dest
), dest
, ToString(m_menuState
));
743 menuState
= m_menuState
;
747 bool bReturn
= m_handler
->TransmitMenuState(m_iLogicalAddress
, dest
, menuState
);
752 bool CCECBusDevice::TransmitOSDName(cec_logical_address dest
)
754 CStdString strDeviceName
;
756 CLockObject
lock(m_mutex
);
757 CLibCEC::AddLog(CEC_LOG_NOTICE
, "<< %s (%X) -> %s (%X): OSD name '%s'", GetLogicalAddressName(), m_iLogicalAddress
, ToString(dest
), dest
, m_strDeviceName
.c_str());
758 strDeviceName
= m_strDeviceName
;
762 bool bReturn
= m_handler
->TransmitOSDName(m_iLogicalAddress
, dest
, strDeviceName
);
767 bool CCECBusDevice::TransmitOSDString(cec_logical_address dest
, cec_display_control duration
, const char *strMessage
)
770 if (!IsUnsupportedFeature(CEC_OPCODE_SET_OSD_STRING
))
772 CLibCEC::AddLog(CEC_LOG_NOTICE
, "<< %s (%X) -> %s (%X): display OSD message '%s'", GetLogicalAddressName(), m_iLogicalAddress
, ToString(dest
), dest
, strMessage
);
774 bReturn
= m_handler
->TransmitOSDString(m_iLogicalAddress
, dest
, duration
, strMessage
);
780 bool CCECBusDevice::TransmitPhysicalAddress(void)
782 uint16_t iPhysicalAddress
;
783 cec_device_type type
;
785 CLockObject
lock(m_mutex
);
786 if (m_iPhysicalAddress
== 0xffff)
789 CLibCEC::AddLog(CEC_LOG_NOTICE
, "<< %s (%X) -> broadcast (F): physical adddress %4x", GetLogicalAddressName(), m_iLogicalAddress
, m_iPhysicalAddress
);
790 iPhysicalAddress
= m_iPhysicalAddress
;
795 bool bReturn
= m_handler
->TransmitPhysicalAddress(m_iLogicalAddress
, iPhysicalAddress
, type
);
800 bool CCECBusDevice::TransmitPoll(cec_logical_address dest
)
803 if (dest
== CECDEVICE_UNKNOWN
)
804 dest
= m_iLogicalAddress
;
806 CCECBusDevice
*destDevice
= m_processor
->m_busDevices
[dest
];
807 if (destDevice
->m_deviceStatus
== CEC_DEVICE_STATUS_HANDLED_BY_LIBCEC
)
811 CLibCEC::AddLog(CEC_LOG_NOTICE
, "<< %s (%X) -> %s (%X): POLL", GetLogicalAddressName(), m_iLogicalAddress
, ToString(dest
), dest
);
812 bReturn
= m_handler
->TransmitPoll(m_iLogicalAddress
, dest
);
813 CLibCEC::AddLog(CEC_LOG_DEBUG
, bReturn
? ">> POLL sent" : ">> POLL not sent");
815 CLockObject
lock(m_mutex
);
818 m_iLastActive
= GetTimeMs();
819 destDevice
->m_deviceStatus
= CEC_DEVICE_STATUS_PRESENT
;
822 destDevice
->m_deviceStatus
= CEC_DEVICE_STATUS_NOT_PRESENT
;
828 bool CCECBusDevice::TransmitPowerState(cec_logical_address dest
)
830 cec_power_status state
;
832 CLockObject
lock(m_mutex
);
833 CLibCEC::AddLog(CEC_LOG_NOTICE
, "<< %s (%X) -> %s (%X): %s", GetLogicalAddressName(), m_iLogicalAddress
, ToString(dest
), dest
, ToString(m_powerStatus
));
834 state
= m_powerStatus
;
838 bool bReturn
= m_handler
->TransmitPowerState(m_iLogicalAddress
, dest
, state
);
843 bool CCECBusDevice::TransmitVendorID(cec_logical_address dest
, bool bSendAbort
/* = true */)
848 CLockObject
lock(m_mutex
);
849 iVendorId
= (uint64_t)m_vendor
;
853 if (iVendorId
== CEC_VENDOR_UNKNOWN
)
857 CLibCEC::AddLog(CEC_LOG_NOTICE
, "<< %s (%X) -> %s (%X): vendor id feature abort", GetLogicalAddressName(), m_iLogicalAddress
, ToString(dest
), dest
);
858 m_processor
->TransmitAbort(dest
, CEC_OPCODE_GIVE_DEVICE_VENDOR_ID
);
864 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
);
865 bReturn
= m_handler
->TransmitVendorID(m_iLogicalAddress
, iVendorId
);
871 bool CCECBusDevice::TransmitKeypress(cec_user_control_code key
, bool bWait
/* = true */)
874 bool bReturn
= m_handler
->TransmitKeypress(m_processor
->GetLogicalAddress(), m_iLogicalAddress
, key
, bWait
);
879 bool CCECBusDevice::TransmitKeyRelease(bool bWait
/* = true */)
882 bool bReturn
= m_handler
->TransmitKeyRelease(m_processor
->GetLogicalAddress(), m_iLogicalAddress
, bWait
);
887 bool CCECBusDevice::IsUnsupportedFeature(cec_opcode opcode
) const
889 return m_unsupportedFeatures
.find(opcode
) != m_unsupportedFeatures
.end();
892 void CCECBusDevice::SetUnsupportedFeature(cec_opcode opcode
)
894 m_unsupportedFeatures
.insert(opcode
);
897 bool CCECBusDevice::ActivateSource(void)
900 bool bReturn
= m_handler
->ActivateSource();
905 void CCECBusDevice::HandlePoll(cec_logical_address iDestination
)
907 CLockObject
lock(m_mutex
);
908 CLibCEC::AddLog(CEC_LOG_DEBUG
, "<< POLL: %s (%x) -> %s (%x)", ToString(m_iLogicalAddress
), m_iLogicalAddress
, ToString(iDestination
), iDestination
);
909 m_bAwaitingReceiveFailed
= true;
912 bool CCECBusDevice::HandleReceiveFailed(void)
914 CLockObject
lock(m_mutex
);
915 bool bReturn
= m_bAwaitingReceiveFailed
;
916 m_bAwaitingReceiveFailed
= false;