2 * This file is part of the libCEC(R) library.
4 * libCEC(R) is Copyright (C) 2011 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 "../platform/timeutils.h"
43 #define ToString(p) m_processor->ToString(p)
45 CCECBusDevice::CCECBusDevice(CCECProcessor
*processor
, cec_logical_address iLogicalAddress
, uint16_t iPhysicalAddress
) :
46 m_type(CEC_DEVICE_TYPE_RESERVED
),
47 m_iPhysicalAddress(iPhysicalAddress
),
49 m_iLogicalAddress(iLogicalAddress
),
50 m_powerStatus(CEC_POWER_STATUS_UNKNOWN
),
51 m_processor(processor
),
52 m_vendor(CEC_VENDOR_UNKNOWN
),
53 m_bReplaceHandler(false),
54 m_menuState(CEC_MENU_STATE_ACTIVATED
),
55 m_bActiveSource(false),
57 m_iLastPowerStateUpdate(0),
58 m_cecVersion(CEC_VERSION_UNKNOWN
),
59 m_deviceStatus(CEC_DEVICE_STATUS_UNKNOWN
),
62 m_handler
= new CCECCommandHandler(this);
64 for (unsigned int iPtr
= 0; iPtr
< 4; iPtr
++)
65 m_menuLanguage
.language
[iPtr
] = '?';
66 m_menuLanguage
.language
[3] = 0;
67 m_menuLanguage
.device
= iLogicalAddress
;
69 m_strDeviceName
= ToString(m_iLogicalAddress
);
72 CCECBusDevice::~CCECBusDevice(void)
77 void CCECBusDevice::AddLog(cec_log_level level
, const CStdString
&strMessage
)
79 m_processor
->AddLog(level
, strMessage
);
82 bool CCECBusDevice::HandleCommand(const cec_command
&command
)
86 /* update "last active" */
88 CLockObject
lock(&m_mutex
);
89 m_iLastActive
= GetTimeMs();
91 if (m_deviceStatus
!= CEC_DEVICE_STATUS_HANDLED_BY_LIBCEC
)
92 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
)
107 strLog
.Format("device %s (%x) status changed to present after command %s", GetLogicalAddressName(), (uint8_t)GetLogicalAddress(), ToString(command
.opcode
));
108 AddLog(CEC_LOG_DEBUG
, strLog
);
110 m_deviceStatus
= CEC_DEVICE_STATUS_PRESENT
;
117 bool CCECBusDevice::PowerOn(void)
120 strLog
.Format("<< powering on '%s' (%X)", GetLogicalAddressName(), m_iLogicalAddress
);
121 AddLog(CEC_LOG_DEBUG
, strLog
.c_str());
123 if (m_handler
->TransmitImageViewOn(GetMyLogicalAddress(), m_iLogicalAddress
))
126 CLockObject
lock(&m_mutex
);
127 // m_powerStatus = CEC_POWER_STATUS_UNKNOWN;
128 m_powerStatus
= CEC_POWER_STATUS_IN_TRANSITION_STANDBY_TO_ON
;
130 // cec_power_status status = GetPowerStatus();
131 // if (status == CEC_POWER_STATUS_STANDBY || status == CEC_POWER_STATUS_UNKNOWN)
133 // /* sending the normal power on command appears to have failed */
134 // CStdString strLog;
135 // strLog.Format("<< sending power on keypress to '%s' (%X)", GetLogicalAddressName(), m_iLogicalAddress);
136 // AddLog(CEC_LOG_DEBUG, strLog.c_str());
138 // TransmitKeypress(CEC_USER_CONTROL_CODE_POWER);
139 // return TransmitKeyRelease();
147 bool CCECBusDevice::Standby(void)
150 strLog
.Format("<< putting '%s' (%X) in standby mode", GetLogicalAddressName(), m_iLogicalAddress
);
151 AddLog(CEC_LOG_DEBUG
, strLog
.c_str());
153 return m_handler
->TransmitStandby(GetMyLogicalAddress(), m_iLogicalAddress
);
158 cec_version
CCECBusDevice::GetCecVersion(bool bUpdate
/* = false */)
160 bool bRequestUpdate(false);
162 CLockObject
lock(&m_mutex
);
163 bRequestUpdate
= (GetStatus() == CEC_DEVICE_STATUS_PRESENT
&&
164 (bUpdate
|| m_cecVersion
== CEC_VERSION_UNKNOWN
));
170 CLockObject
lock(&m_mutex
);
174 bool CCECBusDevice::RequestCecVersion(void)
178 if (!MyLogicalAddressContains(m_iLogicalAddress
))
180 m_handler
->MarkBusy();
182 strLog
.Format("<< requesting CEC version of '%s' (%X)", GetLogicalAddressName(), m_iLogicalAddress
);
183 AddLog(CEC_LOG_NOTICE
, strLog
);
185 bReturn
= m_handler
->TransmitRequestCecVersion(GetMyLogicalAddress(), m_iLogicalAddress
);
186 m_handler
->MarkReady();
191 const char* CCECBusDevice::GetLogicalAddressName(void) const
193 return ToString(m_iLogicalAddress
);
196 cec_menu_language
&CCECBusDevice::GetMenuLanguage(bool bUpdate
/* = false */)
198 bool bRequestUpdate(false);
200 CLockObject
lock(&m_mutex
);
201 bRequestUpdate
= (GetStatus() == CEC_DEVICE_STATUS_PRESENT
&&
202 (bUpdate
|| !strcmp(m_menuLanguage
.language
, "???")));
206 RequestMenuLanguage();
208 CLockObject
lock(&m_mutex
);
209 return m_menuLanguage
;
212 bool CCECBusDevice::RequestMenuLanguage(void)
216 if (!MyLogicalAddressContains(m_iLogicalAddress
) &&
217 !IsUnsupportedFeature(CEC_OPCODE_GET_MENU_LANGUAGE
))
219 m_handler
->MarkBusy();
221 strLog
.Format("<< requesting menu language of '%s' (%X)", GetLogicalAddressName(), m_iLogicalAddress
);
222 AddLog(CEC_LOG_NOTICE
, strLog
);
223 bReturn
= m_handler
->TransmitRequestMenuLanguage(GetMyLogicalAddress(), m_iLogicalAddress
);
224 m_handler
->MarkReady();
229 cec_menu_state
CCECBusDevice::GetMenuState(void)
231 CLockObject
lock(&m_mutex
);
235 cec_logical_address
CCECBusDevice::GetMyLogicalAddress(void) const
237 return m_processor
->GetLogicalAddress();
240 uint16_t CCECBusDevice::GetMyPhysicalAddress(void) const
242 return m_processor
->GetPhysicalAddress();
245 CStdString
CCECBusDevice::GetOSDName(bool bUpdate
/* = false */)
247 bool bRequestUpdate(false);
249 CLockObject
lock(&m_mutex
);
250 bRequestUpdate
= (GetStatus() == CEC_DEVICE_STATUS_PRESENT
&&
251 (bUpdate
|| m_strDeviceName
.Equals(ToString(m_iLogicalAddress
))) &&
252 m_type
!= CEC_DEVICE_TYPE_TV
);
258 CLockObject
lock(&m_mutex
);
259 return m_strDeviceName
;
262 bool CCECBusDevice::RequestOSDName(void)
266 if (!MyLogicalAddressContains(m_iLogicalAddress
) &&
267 !IsUnsupportedFeature(CEC_OPCODE_GIVE_OSD_NAME
))
269 m_handler
->MarkBusy();
271 strLog
.Format("<< requesting OSD name of '%s' (%X)", GetLogicalAddressName(), m_iLogicalAddress
);
272 AddLog(CEC_LOG_NOTICE
, strLog
);
273 bReturn
= m_handler
->TransmitRequestOSDName(GetMyLogicalAddress(), m_iLogicalAddress
);
274 m_handler
->MarkReady();
279 uint16_t CCECBusDevice::GetPhysicalAddress(bool bUpdate
/* = false */)
281 bool bRequestUpdate(false);
283 CLockObject
lock(&m_mutex
);
284 bRequestUpdate
= (GetStatus() == CEC_DEVICE_STATUS_PRESENT
&&
285 (m_iPhysicalAddress
== 0xFFFF || bUpdate
));
288 if (bRequestUpdate
&& !RequestPhysicalAddress())
289 AddLog(CEC_LOG_ERROR
, "failed to request the physical address (1)");
291 CLockObject
lock(&m_mutex
);
292 return m_iPhysicalAddress
;
295 bool CCECBusDevice::RequestPhysicalAddress(void)
299 if (!MyLogicalAddressContains(m_iLogicalAddress
))
301 m_handler
->MarkBusy();
303 strLog
.Format("<< requesting physical address of '%s' (%X)", GetLogicalAddressName(), m_iLogicalAddress
);
304 AddLog(CEC_LOG_NOTICE
, strLog
);
305 bReturn
= m_handler
->TransmitRequestPhysicalAddress(GetMyLogicalAddress(), m_iLogicalAddress
);
306 m_handler
->MarkReady();
311 cec_power_status
CCECBusDevice::GetPowerStatus(bool bUpdate
/* = false */)
313 bool bRequestUpdate(false);
315 CLockObject
lock(&m_mutex
);
316 bRequestUpdate
= (GetStatus() == CEC_DEVICE_STATUS_PRESENT
&&
317 (bUpdate
|| m_powerStatus
== CEC_POWER_STATUS_UNKNOWN
||
318 m_powerStatus
== CEC_POWER_STATUS_IN_TRANSITION_STANDBY_TO_ON
||
319 m_powerStatus
== CEC_POWER_STATUS_IN_TRANSITION_ON_TO_STANDBY
||
320 GetTimeMs() - m_iLastPowerStateUpdate
>= CEC_POWER_STATE_REFRESH_TIME
));
324 RequestPowerStatus();
326 CLockObject
lock(&m_mutex
);
327 return m_powerStatus
;
330 bool CCECBusDevice::RequestPowerStatus(void)
334 if (!MyLogicalAddressContains(m_iLogicalAddress
) &&
335 !IsUnsupportedFeature(CEC_OPCODE_GIVE_DEVICE_POWER_STATUS
))
337 m_handler
->MarkBusy();
339 strLog
.Format("<< requesting power status of '%s' (%X)", GetLogicalAddressName(), m_iLogicalAddress
);
340 AddLog(CEC_LOG_NOTICE
, strLog
);
341 bReturn
= m_handler
->TransmitRequestPowerStatus(GetMyLogicalAddress(), m_iLogicalAddress
);
342 m_handler
->MarkReady();
347 cec_vendor_id
CCECBusDevice::GetVendorId(bool bUpdate
/* = false */)
349 bool bRequestUpdate(false);
351 CLockObject
lock(&m_mutex
);
352 bRequestUpdate
= (GetStatus() == CEC_DEVICE_STATUS_PRESENT
&&
353 (bUpdate
|| m_vendor
== CEC_VENDOR_UNKNOWN
));
359 CLockObject
lock(&m_mutex
);
363 bool CCECBusDevice::RequestVendorId(void)
367 if (!MyLogicalAddressContains(m_iLogicalAddress
))
369 m_handler
->MarkBusy();
371 strLog
.Format("<< requesting vendor ID of '%s' (%X)", GetLogicalAddressName(), m_iLogicalAddress
);
372 AddLog(CEC_LOG_NOTICE
, strLog
);
373 bReturn
= m_handler
->TransmitRequestVendorId(GetMyLogicalAddress(), m_iLogicalAddress
);
374 m_handler
->MarkReady();
376 ReplaceHandler(true);
381 const char *CCECBusDevice::GetVendorName(bool bUpdate
/* = false */)
383 return ToString(GetVendorId(bUpdate
));
386 bool CCECBusDevice::MyLogicalAddressContains(cec_logical_address address
) const
388 return m_processor
->HasLogicalAddress(address
);
391 bool CCECBusDevice::NeedsPoll(void)
393 bool bSendPoll(false);
394 switch (m_iLogicalAddress
)
396 case CECDEVICE_PLAYBACKDEVICE3
:
397 if (m_processor
->m_busDevices
[CECDEVICE_PLAYBACKDEVICE2
]->GetStatus() == CEC_DEVICE_STATUS_PRESENT
)
400 case CECDEVICE_PLAYBACKDEVICE2
:
401 if (m_processor
->m_busDevices
[CECDEVICE_PLAYBACKDEVICE1
]->GetStatus() == CEC_DEVICE_STATUS_PRESENT
)
404 case CECDEVICE_RECORDINGDEVICE3
:
405 if (m_processor
->m_busDevices
[CECDEVICE_RECORDINGDEVICE2
]->GetStatus() == CEC_DEVICE_STATUS_PRESENT
)
408 case CECDEVICE_RECORDINGDEVICE2
:
409 if (m_processor
->m_busDevices
[CECDEVICE_RECORDINGDEVICE1
]->GetStatus() == CEC_DEVICE_STATUS_PRESENT
)
412 case CECDEVICE_TUNER4
:
413 if (m_processor
->m_busDevices
[CECDEVICE_TUNER3
]->GetStatus() == CEC_DEVICE_STATUS_PRESENT
)
416 case CECDEVICE_TUNER3
:
417 if (m_processor
->m_busDevices
[CECDEVICE_TUNER2
]->GetStatus() == CEC_DEVICE_STATUS_PRESENT
)
420 case CECDEVICE_TUNER2
:
421 if (m_processor
->m_busDevices
[CECDEVICE_TUNER1
]->GetStatus() == CEC_DEVICE_STATUS_PRESENT
)
424 case CECDEVICE_AUDIOSYSTEM
:
425 case CECDEVICE_PLAYBACKDEVICE1
:
426 case CECDEVICE_RECORDINGDEVICE1
:
427 case CECDEVICE_TUNER1
:
438 cec_bus_device_status
CCECBusDevice::GetStatus(bool bForcePoll
/* = false */)
440 CLockObject
lock(&m_mutex
);
441 if (m_deviceStatus
!= CEC_DEVICE_STATUS_HANDLED_BY_LIBCEC
&&
442 (m_deviceStatus
== CEC_DEVICE_STATUS_UNKNOWN
|| bForcePoll
))
445 bool bPollAcked(false);
446 if (bForcePoll
|| NeedsPoll())
447 bPollAcked
= m_processor
->PollDevice(m_iLogicalAddress
);
450 m_deviceStatus
= bPollAcked
? CEC_DEVICE_STATUS_PRESENT
: CEC_DEVICE_STATUS_NOT_PRESENT
;
453 return m_deviceStatus
;
460 void CCECBusDevice::SetCecVersion(const cec_version newVersion
)
462 m_cecVersion
= newVersion
;
465 strLog
.Format("%s (%X): CEC version %s", GetLogicalAddressName(), m_iLogicalAddress
, ToString(newVersion
));
466 AddLog(CEC_LOG_DEBUG
, strLog
);
469 void CCECBusDevice::SetMenuLanguage(const cec_menu_language
&language
)
471 CLockObject
lock(&m_mutex
);
472 if (language
.device
== m_iLogicalAddress
)
475 strLog
.Format(">> %s (%X): menu language set to '%s'", GetLogicalAddressName(), m_iLogicalAddress
, language
.language
);
476 m_processor
->AddLog(CEC_LOG_DEBUG
, strLog
);
477 m_menuLanguage
= language
;
481 void CCECBusDevice::SetOSDName(CStdString strName
)
483 CLockObject
lock(&m_mutex
);
484 if (m_strDeviceName
!= strName
)
487 strLog
.Format(">> %s (%X): osd name set to '%s'", GetLogicalAddressName(), m_iLogicalAddress
, strName
);
488 m_processor
->AddLog(CEC_LOG_DEBUG
, strLog
);
489 m_strDeviceName
= strName
;
493 void CCECBusDevice::SetMenuState(const cec_menu_state state
)
495 CLockObject
lock(&m_mutex
);
496 if (m_menuState
!= state
)
499 strLog
.Format(">> %s (%X): menu state set to '%s'", GetLogicalAddressName(), m_iLogicalAddress
, ToString(m_menuState
));
500 m_processor
->AddLog(CEC_LOG_DEBUG
, strLog
);
505 void CCECBusDevice::SetInactiveSource(void)
508 CLockObject
lock(&m_mutex
);
509 m_bActiveSource
= false;
512 if (MyLogicalAddressContains(m_iLogicalAddress
))
513 SetPowerStatus(CEC_POWER_STATUS_STANDBY
);
516 void CCECBusDevice::SetActiveSource(void)
518 CLockObject
lock(&m_mutex
);
519 if (!m_bActiveSource
)
522 strLog
.Format("making %s (%x) the active source", GetLogicalAddressName(), m_iLogicalAddress
);
523 AddLog(CEC_LOG_DEBUG
, strLog
);
526 for (int iPtr
= 0; iPtr
< 16; iPtr
++)
527 if (iPtr
!= m_iLogicalAddress
)
528 m_processor
->m_busDevices
[iPtr
]->SetInactiveSource();
530 m_bActiveSource
= true;
531 m_powerStatus
= CEC_POWER_STATUS_ON
;
534 bool CCECBusDevice::TryLogicalAddress(void)
537 strLog
.Format("trying logical address '%s'", GetLogicalAddressName());
538 AddLog(CEC_LOG_DEBUG
, strLog
);
540 m_processor
->SetAckMask(0x1 << m_iLogicalAddress
);
541 if (!TransmitPoll(m_iLogicalAddress
))
543 strLog
.Format("using logical address '%s'", GetLogicalAddressName());
544 AddLog(CEC_LOG_NOTICE
, strLog
);
545 SetDeviceStatus(CEC_DEVICE_STATUS_HANDLED_BY_LIBCEC
);
550 strLog
.Format("logical address '%s' already taken", GetLogicalAddressName());
551 AddLog(CEC_LOG_DEBUG
, strLog
);
552 SetDeviceStatus(CEC_DEVICE_STATUS_PRESENT
);
556 void CCECBusDevice::SetDeviceStatus(const cec_bus_device_status newStatus
)
558 CLockObject
lock(&m_mutex
);
561 case CEC_DEVICE_STATUS_UNKNOWN
:
563 m_powerStatus
= CEC_POWER_STATUS_UNKNOWN
;
564 m_vendor
= CEC_VENDOR_UNKNOWN
;
565 m_menuState
= CEC_MENU_STATE_ACTIVATED
;
566 m_bActiveSource
= false;
568 m_cecVersion
= CEC_VERSION_UNKNOWN
;
569 m_deviceStatus
= newStatus
;
571 case CEC_DEVICE_STATUS_HANDLED_BY_LIBCEC
:
573 m_powerStatus
= CEC_POWER_STATUS_ON
;
574 m_vendor
= CEC_VENDOR_UNKNOWN
;
575 m_menuState
= CEC_MENU_STATE_ACTIVATED
;
576 m_bActiveSource
= false;
578 m_cecVersion
= CEC_VERSION_1_3A
;
579 m_deviceStatus
= newStatus
;
581 case CEC_DEVICE_STATUS_PRESENT
:
582 case CEC_DEVICE_STATUS_NOT_PRESENT
:
583 m_deviceStatus
= newStatus
;
588 void CCECBusDevice::SetPhysicalAddress(uint16_t iNewAddress
)
590 CLockObject
lock(&m_mutex
);
591 if (iNewAddress
> 0 && m_iPhysicalAddress
!= iNewAddress
)
594 strLog
.Format(">> %s (%X): physical address changed from %04x to %04x", GetLogicalAddressName(), m_iLogicalAddress
, m_iPhysicalAddress
, iNewAddress
);
595 AddLog(CEC_LOG_DEBUG
, strLog
.c_str());
597 m_iPhysicalAddress
= iNewAddress
;
601 void CCECBusDevice::SetStreamPath(uint16_t iNewAddress
, uint16_t iOldAddress
/* = 0 */)
603 CLockObject
lock(&m_mutex
);
607 strLog
.Format(">> %s (%X): stream path changed from %04x to %04x", GetLogicalAddressName(), m_iLogicalAddress
, iOldAddress
== 0 ? m_iStreamPath
: iOldAddress
, iNewAddress
);
608 AddLog(CEC_LOG_DEBUG
, strLog
.c_str());
610 m_iStreamPath
= iNewAddress
;
615 SetPowerStatus(CEC_POWER_STATUS_ON
);
620 void CCECBusDevice::SetPowerStatus(const cec_power_status powerStatus
)
622 CLockObject
lock(&m_mutex
);
623 if (m_powerStatus
!= powerStatus
)
625 m_iLastPowerStateUpdate
= GetTimeMs();
627 strLog
.Format(">> %s (%X): power status changed from '%s' to '%s'", GetLogicalAddressName(), m_iLogicalAddress
, ToString(m_powerStatus
), ToString(powerStatus
));
628 m_processor
->AddLog(CEC_LOG_DEBUG
, strLog
);
629 m_powerStatus
= powerStatus
;
633 bool CCECBusDevice::ReplaceHandler(bool bActivateSource
/* = true */)
635 CLockObject
lock(&m_mutex
);
636 CLockObject
handlerLock(&m_handlerMutex
);
638 if (m_vendor
!= m_handler
->GetVendorId())
640 if (CCECCommandHandler::HasSpecificHandler(m_vendor
))
643 if (m_handler
->InUse())
645 strLog
.Format("handler for device '%s' (%x) is being used. not replacing the command handler", GetLogicalAddressName(), GetLogicalAddress());
646 m_processor
->AddLog(CEC_LOG_DEBUG
, strLog
);
650 strLog
.Format("replacing the command handler for device '%s' (%x)", GetLogicalAddressName(), GetLogicalAddress());
651 m_processor
->AddLog(CEC_LOG_DEBUG
, strLog
);
656 case CEC_VENDOR_SAMSUNG
:
657 m_handler
= new CANCommandHandler(this);
660 m_handler
= new CSLCommandHandler(this);
662 case CEC_VENDOR_PANASONIC
:
663 m_handler
= new CVLCommandHandler(this);
666 m_handler
= new CCECCommandHandler(this);
670 m_handler
->SetVendorId(m_vendor
);
671 m_handler
->InitHandler();
673 if (bActivateSource
&& m_processor
->GetLogicalAddresses().IsSet(m_iLogicalAddress
) && m_processor
->IsInitialised() && IsActiveSource())
674 m_handler
->ActivateSource();
681 bool CCECBusDevice::SetVendorId(uint64_t iVendorId
)
683 bool bVendorChanged(false);
686 CLockObject
lock(&m_mutex
);
687 bVendorChanged
= (m_vendor
!= (cec_vendor_id
)iVendorId
);
688 m_vendor
= (cec_vendor_id
)iVendorId
;
692 strLog
.Format("%s (%X): vendor = %s (%06x)", GetLogicalAddressName(), m_iLogicalAddress
, ToString(m_vendor
), m_vendor
);
693 m_processor
->AddLog(CEC_LOG_DEBUG
, strLog
.c_str());
695 return bVendorChanged
;
699 /** @name Transmit methods */
701 bool CCECBusDevice::TransmitActiveSource(void)
703 bool bSendActiveSource(false);
706 CLockObject
lock(&m_mutex
);
707 if (m_powerStatus
!= CEC_POWER_STATUS_ON
)
710 strLog
.Format("<< %s (%X) is not powered on", GetLogicalAddressName(), m_iLogicalAddress
);
711 AddLog(CEC_LOG_DEBUG
, strLog
);
713 else if (m_bActiveSource
)
716 strLog
.Format("<< %s (%X) -> broadcast (F): active source (%4x)", GetLogicalAddressName(), m_iLogicalAddress
, m_iPhysicalAddress
);
717 AddLog(CEC_LOG_NOTICE
, strLog
);
718 bSendActiveSource
= true;
723 strLog
.Format("<< %s (%X) is not the active source", GetLogicalAddressName(), m_iLogicalAddress
);
724 AddLog(CEC_LOG_DEBUG
, strLog
);
728 if (bSendActiveSource
)
730 m_handler
->TransmitImageViewOn(m_iLogicalAddress
, CECDEVICE_TV
);
731 m_handler
->TransmitActiveSource(m_iLogicalAddress
, m_iPhysicalAddress
);
738 bool CCECBusDevice::TransmitCECVersion(cec_logical_address dest
)
742 CLockObject
lock(&m_mutex
);
744 strLog
.Format("<< %s (%X) -> %s (%X): cec version %s", GetLogicalAddressName(), m_iLogicalAddress
, ToString(dest
), dest
, ToString(m_cecVersion
));
745 AddLog(CEC_LOG_NOTICE
, strLog
);
746 version
= m_cecVersion
;
749 return m_handler
->TransmitCECVersion(m_iLogicalAddress
, dest
, version
);
752 bool CCECBusDevice::TransmitInactiveSource(void)
754 uint16_t iPhysicalAddress
;
756 CLockObject
lock(&m_mutex
);
758 strLog
.Format("<< %s (%X) -> broadcast (F): inactive source", GetLogicalAddressName(), m_iLogicalAddress
);
759 AddLog(CEC_LOG_NOTICE
, strLog
);
760 iPhysicalAddress
= m_iPhysicalAddress
;
763 return m_handler
->TransmitInactiveSource(m_iLogicalAddress
, iPhysicalAddress
);
766 bool CCECBusDevice::TransmitMenuState(cec_logical_address dest
)
768 cec_menu_state menuState
;
770 CLockObject
lock(&m_mutex
);
772 strLog
.Format("<< %s (%X) -> %s (%X): menu state '%s'", GetLogicalAddressName(), m_iLogicalAddress
, ToString(dest
), dest
, ToString(m_menuState
));
773 AddLog(CEC_LOG_NOTICE
, strLog
);
774 menuState
= m_menuState
;
777 return m_handler
->TransmitMenuState(m_iLogicalAddress
, dest
, menuState
);
780 bool CCECBusDevice::TransmitOSDName(cec_logical_address dest
)
782 CStdString strDeviceName
;
784 CLockObject
lock(&m_mutex
);
786 strLog
.Format("<< %s (%X) -> %s (%X): OSD name '%s'", GetLogicalAddressName(), m_iLogicalAddress
, ToString(dest
), dest
, m_strDeviceName
.c_str());
787 AddLog(CEC_LOG_NOTICE
, strLog
.c_str());
788 strDeviceName
= m_strDeviceName
;
791 return m_handler
->TransmitOSDName(m_iLogicalAddress
, dest
, strDeviceName
);
794 bool CCECBusDevice::TransmitOSDString(cec_logical_address dest
, cec_display_control duration
, const char *strMessage
)
796 if (!IsUnsupportedFeature(CEC_OPCODE_SET_OSD_STRING
))
799 strLog
.Format("<< %s (%X) -> %s (%X): display OSD message '%s'", GetLogicalAddressName(), m_iLogicalAddress
, ToString(dest
), dest
, strMessage
);
800 AddLog(CEC_LOG_NOTICE
, strLog
.c_str());
802 return m_handler
->TransmitOSDString(m_iLogicalAddress
, dest
, duration
, strMessage
);
807 bool CCECBusDevice::TransmitPhysicalAddress(void)
809 uint16_t iPhysicalAddress
;
810 cec_device_type type
;
812 CLockObject
lock(&m_mutex
);
813 if (m_iPhysicalAddress
== 0xffff)
817 strLog
.Format("<< %s (%X) -> broadcast (F): physical adddress %4x", GetLogicalAddressName(), m_iLogicalAddress
, m_iPhysicalAddress
);
818 AddLog(CEC_LOG_NOTICE
, strLog
.c_str());
820 iPhysicalAddress
= m_iPhysicalAddress
;
824 return m_handler
->TransmitPhysicalAddress(m_iLogicalAddress
, iPhysicalAddress
, type
);
827 bool CCECBusDevice::TransmitPoll(cec_logical_address dest
)
830 if (dest
== CECDEVICE_UNKNOWN
)
831 dest
= m_iLogicalAddress
;
833 CCECBusDevice
*destDevice
= m_processor
->m_busDevices
[dest
];
834 if (destDevice
->m_deviceStatus
== CEC_DEVICE_STATUS_HANDLED_BY_LIBCEC
)
838 strLog
.Format("<< %s (%X) -> %s (%X): POLL", GetLogicalAddressName(), m_iLogicalAddress
, ToString(dest
), dest
);
839 AddLog(CEC_LOG_NOTICE
, strLog
.c_str());
840 bReturn
= m_handler
->TransmitPoll(m_iLogicalAddress
, dest
);
841 AddLog(CEC_LOG_DEBUG
, bReturn
? ">> POLL sent" : ">> POLL not sent");
843 CLockObject
lock(&m_mutex
);
846 m_iLastActive
= GetTimeMs();
847 destDevice
->m_deviceStatus
= CEC_DEVICE_STATUS_PRESENT
;
850 destDevice
->m_deviceStatus
= CEC_DEVICE_STATUS_NOT_PRESENT
;
855 bool CCECBusDevice::TransmitPowerState(cec_logical_address dest
)
857 cec_power_status state
;
859 CLockObject
lock(&m_mutex
);
861 strLog
.Format("<< %s (%X) -> %s (%X): %s", GetLogicalAddressName(), m_iLogicalAddress
, ToString(dest
), dest
, ToString(m_powerStatus
));
862 AddLog(CEC_LOG_NOTICE
, strLog
.c_str());
863 state
= m_powerStatus
;
866 return m_handler
->TransmitPowerState(m_iLogicalAddress
, dest
, state
);
869 bool CCECBusDevice::TransmitVendorID(cec_logical_address dest
, bool bSendAbort
/* = true */)
873 CLockObject
lock(&m_mutex
);
874 iVendorId
= (uint64_t)m_vendor
;
877 if (iVendorId
== CEC_VENDOR_UNKNOWN
)
882 strLog
.Format("<< %s (%X) -> %s (%X): vendor id feature abort", GetLogicalAddressName(), m_iLogicalAddress
, ToString(dest
), dest
);
883 AddLog(CEC_LOG_NOTICE
, strLog
);
885 m_processor
->TransmitAbort(dest
, CEC_OPCODE_GIVE_DEVICE_VENDOR_ID
);
892 strLog
.Format("<< %s (%X) -> %s (%X): vendor id %s (%x)", GetLogicalAddressName(), m_iLogicalAddress
, ToString(dest
), dest
, ToString((cec_vendor_id
)iVendorId
), iVendorId
);
893 AddLog(CEC_LOG_NOTICE
, strLog
);
895 return m_handler
->TransmitVendorID(m_iLogicalAddress
, iVendorId
);
899 bool CCECBusDevice::TransmitKeypress(cec_user_control_code key
, bool bWait
/* = true */)
901 return m_handler
->TransmitKeypress(m_processor
->GetLogicalAddress(), m_iLogicalAddress
, key
, bWait
);
904 bool CCECBusDevice::TransmitKeyRelease(bool bWait
/* = true */)
906 return 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)
921 CLockObject
lock(&m_mutex
);
922 return m_handler
->ActivateSource();