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 "../LibCEC.h"
42 using namespace PLATFORM
;
44 #define ToString(p) m_processor->ToString(p)
46 CCECBusDevice::CCECBusDevice(CCECProcessor
*processor
, cec_logical_address iLogicalAddress
, uint16_t iPhysicalAddress
) :
47 m_type(CEC_DEVICE_TYPE_RESERVED
),
48 m_iPhysicalAddress(iPhysicalAddress
),
50 m_iLogicalAddress(iLogicalAddress
),
51 m_powerStatus(CEC_POWER_STATUS_UNKNOWN
),
52 m_processor(processor
),
53 m_vendor(CEC_VENDOR_UNKNOWN
),
54 m_bReplaceHandler(false),
55 m_menuState(CEC_MENU_STATE_ACTIVATED
),
56 m_bActiveSource(false),
58 m_iLastPowerStateUpdate(0),
59 m_cecVersion(CEC_VERSION_UNKNOWN
),
60 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 bool CCECBusDevice::HandleCommand(const cec_command
&command
)
81 /* update "last active" */
83 CLockObject
lock(m_mutex
);
84 m_iLastActive
= GetTimeMs();
86 if (m_deviceStatus
!= CEC_DEVICE_STATUS_HANDLED_BY_LIBCEC
)
87 m_deviceStatus
= CEC_DEVICE_STATUS_PRESENT
;
90 /* handle the command */
91 bHandled
= m_handler
->HandleCommand(command
);
93 /* change status to present */
96 CLockObject
lock(m_mutex
);
97 if (m_deviceStatus
!= CEC_DEVICE_STATUS_HANDLED_BY_LIBCEC
)
99 if (m_deviceStatus
!= CEC_DEVICE_STATUS_PRESENT
)
100 CLibCEC::AddLog(CEC_LOG_DEBUG
, "device %s (%x) status changed to present after command %s", GetLogicalAddressName(), (uint8_t)GetLogicalAddress(), ToString(command
.opcode
));
101 m_deviceStatus
= CEC_DEVICE_STATUS_PRESENT
;
108 bool CCECBusDevice::PowerOn(void)
110 CLibCEC::AddLog(CEC_LOG_DEBUG
, "<< powering on '%s' (%X)", GetLogicalAddressName(), m_iLogicalAddress
);
112 if (m_handler
->TransmitImageViewOn(GetMyLogicalAddress(), m_iLogicalAddress
))
115 CLockObject
lock(m_mutex
);
116 // m_powerStatus = CEC_POWER_STATUS_UNKNOWN;
117 m_powerStatus
= CEC_POWER_STATUS_IN_TRANSITION_STANDBY_TO_ON
;
119 // cec_power_status status = GetPowerStatus();
120 // if (status == CEC_POWER_STATUS_STANDBY || status == CEC_POWER_STATUS_UNKNOWN)
122 // /* sending the normal power on command appears to have failed */
123 // CStdString strLog;
124 // strLog.Format("<< sending power on keypress to '%s' (%X)", GetLogicalAddressName(), m_iLogicalAddress);
125 // CLibCEC::AddLog(CEC_LOG_DEBUG, strLog.c_str());
127 // TransmitKeypress(CEC_USER_CONTROL_CODE_POWER);
128 // return TransmitKeyRelease();
136 bool CCECBusDevice::Standby(void)
138 CLibCEC::AddLog(CEC_LOG_DEBUG
, "<< putting '%s' (%X) in standby mode", GetLogicalAddressName(), m_iLogicalAddress
);
139 return m_handler
->TransmitStandby(GetMyLogicalAddress(), m_iLogicalAddress
);
144 cec_version
CCECBusDevice::GetCecVersion(bool bUpdate
/* = false */)
146 bool bRequestUpdate(false);
148 CLockObject
lock(m_mutex
);
149 bRequestUpdate
= (GetStatus() == CEC_DEVICE_STATUS_PRESENT
&&
150 (bUpdate
|| m_cecVersion
== CEC_VERSION_UNKNOWN
));
156 CLockObject
lock(m_mutex
);
160 bool CCECBusDevice::RequestCecVersion(void)
164 if (!MyLogicalAddressContains(m_iLogicalAddress
))
166 m_handler
->MarkBusy();
167 CLibCEC::AddLog(CEC_LOG_NOTICE
, "<< requesting CEC version of '%s' (%X)", GetLogicalAddressName(), m_iLogicalAddress
);
169 bReturn
= m_handler
->TransmitRequestCecVersion(GetMyLogicalAddress(), m_iLogicalAddress
);
170 m_handler
->MarkReady();
175 const char* CCECBusDevice::GetLogicalAddressName(void) const
177 return ToString(m_iLogicalAddress
);
180 cec_menu_language
&CCECBusDevice::GetMenuLanguage(bool bUpdate
/* = false */)
182 bool bRequestUpdate(false);
184 CLockObject
lock(m_mutex
);
185 bRequestUpdate
= (GetStatus() == CEC_DEVICE_STATUS_PRESENT
&&
186 (bUpdate
|| !strcmp(m_menuLanguage
.language
, "???")));
190 RequestMenuLanguage();
192 CLockObject
lock(m_mutex
);
193 return m_menuLanguage
;
196 bool CCECBusDevice::RequestMenuLanguage(void)
200 if (!MyLogicalAddressContains(m_iLogicalAddress
) &&
201 !IsUnsupportedFeature(CEC_OPCODE_GET_MENU_LANGUAGE
))
203 m_handler
->MarkBusy();
204 CLibCEC::AddLog(CEC_LOG_NOTICE
, "<< requesting menu language of '%s' (%X)", GetLogicalAddressName(), m_iLogicalAddress
);
205 bReturn
= m_handler
->TransmitRequestMenuLanguage(GetMyLogicalAddress(), m_iLogicalAddress
);
206 m_handler
->MarkReady();
211 cec_menu_state
CCECBusDevice::GetMenuState(void)
213 CLockObject
lock(m_mutex
);
217 cec_logical_address
CCECBusDevice::GetMyLogicalAddress(void) const
219 return m_processor
->GetLogicalAddress();
222 uint16_t CCECBusDevice::GetMyPhysicalAddress(void) const
224 return m_processor
->GetPhysicalAddress();
227 CStdString
CCECBusDevice::GetOSDName(bool bUpdate
/* = false */)
229 bool bRequestUpdate(false);
231 CLockObject
lock(m_mutex
);
232 bRequestUpdate
= (GetStatus() == CEC_DEVICE_STATUS_PRESENT
&&
233 (bUpdate
|| m_strDeviceName
.Equals(ToString(m_iLogicalAddress
))) &&
234 m_type
!= CEC_DEVICE_TYPE_TV
);
240 CLockObject
lock(m_mutex
);
241 return m_strDeviceName
;
244 bool CCECBusDevice::RequestOSDName(void)
248 if (!MyLogicalAddressContains(m_iLogicalAddress
) &&
249 !IsUnsupportedFeature(CEC_OPCODE_GIVE_OSD_NAME
))
251 m_handler
->MarkBusy();
252 CLibCEC::AddLog(CEC_LOG_NOTICE
, "<< requesting OSD name of '%s' (%X)", GetLogicalAddressName(), m_iLogicalAddress
);
253 bReturn
= m_handler
->TransmitRequestOSDName(GetMyLogicalAddress(), m_iLogicalAddress
);
254 m_handler
->MarkReady();
259 uint16_t CCECBusDevice::GetPhysicalAddress(bool bUpdate
/* = false */)
261 bool bRequestUpdate(false);
263 CLockObject
lock(m_mutex
);
264 bRequestUpdate
= (GetStatus() == CEC_DEVICE_STATUS_PRESENT
&&
265 (m_iPhysicalAddress
== 0xFFFF || bUpdate
));
268 if (bRequestUpdate
&& !RequestPhysicalAddress())
269 CLibCEC::AddLog(CEC_LOG_ERROR
, "failed to request the physical address");
271 CLockObject
lock(m_mutex
);
272 return m_iPhysicalAddress
;
275 bool CCECBusDevice::RequestPhysicalAddress(void)
279 if (!MyLogicalAddressContains(m_iLogicalAddress
))
281 m_handler
->MarkBusy();
282 CLibCEC::AddLog(CEC_LOG_NOTICE
, "<< requesting physical address of '%s' (%X)", GetLogicalAddressName(), m_iLogicalAddress
);
283 bReturn
= m_handler
->TransmitRequestPhysicalAddress(GetMyLogicalAddress(), m_iLogicalAddress
);
284 m_handler
->MarkReady();
289 cec_power_status
CCECBusDevice::GetPowerStatus(bool bUpdate
/* = false */)
291 bool bRequestUpdate(false);
293 CLockObject
lock(m_mutex
);
294 bRequestUpdate
= (GetStatus() == CEC_DEVICE_STATUS_PRESENT
&&
295 (bUpdate
|| m_powerStatus
== CEC_POWER_STATUS_UNKNOWN
||
296 m_powerStatus
== CEC_POWER_STATUS_IN_TRANSITION_STANDBY_TO_ON
||
297 m_powerStatus
== CEC_POWER_STATUS_IN_TRANSITION_ON_TO_STANDBY
||
298 GetTimeMs() - m_iLastPowerStateUpdate
>= CEC_POWER_STATE_REFRESH_TIME
));
302 RequestPowerStatus();
304 CLockObject
lock(m_mutex
);
305 return m_powerStatus
;
308 bool CCECBusDevice::RequestPowerStatus(void)
312 if (!MyLogicalAddressContains(m_iLogicalAddress
) &&
313 !IsUnsupportedFeature(CEC_OPCODE_GIVE_DEVICE_POWER_STATUS
))
315 m_handler
->MarkBusy();
316 CLibCEC::AddLog(CEC_LOG_NOTICE
, "<< requesting power status of '%s' (%X)", GetLogicalAddressName(), m_iLogicalAddress
);
317 bReturn
= m_handler
->TransmitRequestPowerStatus(GetMyLogicalAddress(), m_iLogicalAddress
);
318 m_handler
->MarkReady();
323 cec_vendor_id
CCECBusDevice::GetVendorId(bool bUpdate
/* = false */)
325 bool bRequestUpdate(false);
327 CLockObject
lock(m_mutex
);
328 bRequestUpdate
= (GetStatus() == CEC_DEVICE_STATUS_PRESENT
&&
329 (bUpdate
|| m_vendor
== CEC_VENDOR_UNKNOWN
));
335 CLockObject
lock(m_mutex
);
339 bool CCECBusDevice::RequestVendorId(void)
343 if (!MyLogicalAddressContains(m_iLogicalAddress
))
345 m_handler
->MarkBusy();
346 CLibCEC::AddLog(CEC_LOG_NOTICE
, "<< requesting vendor ID of '%s' (%X)", GetLogicalAddressName(), m_iLogicalAddress
);
347 bReturn
= m_handler
->TransmitRequestVendorId(GetMyLogicalAddress(), m_iLogicalAddress
);
348 m_handler
->MarkReady();
350 ReplaceHandler(true);
355 const char *CCECBusDevice::GetVendorName(bool bUpdate
/* = false */)
357 return ToString(GetVendorId(bUpdate
));
360 bool CCECBusDevice::MyLogicalAddressContains(cec_logical_address address
) const
362 return m_processor
->HasLogicalAddress(address
);
365 bool CCECBusDevice::NeedsPoll(void)
367 bool bSendPoll(false);
368 switch (m_iLogicalAddress
)
370 case CECDEVICE_PLAYBACKDEVICE3
:
371 if (m_processor
->m_busDevices
[CECDEVICE_PLAYBACKDEVICE2
]->GetStatus() == CEC_DEVICE_STATUS_PRESENT
)
374 case CECDEVICE_PLAYBACKDEVICE2
:
375 if (m_processor
->m_busDevices
[CECDEVICE_PLAYBACKDEVICE1
]->GetStatus() == CEC_DEVICE_STATUS_PRESENT
)
378 case CECDEVICE_RECORDINGDEVICE3
:
379 if (m_processor
->m_busDevices
[CECDEVICE_RECORDINGDEVICE2
]->GetStatus() == CEC_DEVICE_STATUS_PRESENT
)
382 case CECDEVICE_RECORDINGDEVICE2
:
383 if (m_processor
->m_busDevices
[CECDEVICE_RECORDINGDEVICE1
]->GetStatus() == CEC_DEVICE_STATUS_PRESENT
)
386 case CECDEVICE_TUNER4
:
387 if (m_processor
->m_busDevices
[CECDEVICE_TUNER3
]->GetStatus() == CEC_DEVICE_STATUS_PRESENT
)
390 case CECDEVICE_TUNER3
:
391 if (m_processor
->m_busDevices
[CECDEVICE_TUNER2
]->GetStatus() == CEC_DEVICE_STATUS_PRESENT
)
394 case CECDEVICE_TUNER2
:
395 if (m_processor
->m_busDevices
[CECDEVICE_TUNER1
]->GetStatus() == CEC_DEVICE_STATUS_PRESENT
)
398 case CECDEVICE_AUDIOSYSTEM
:
399 case CECDEVICE_PLAYBACKDEVICE1
:
400 case CECDEVICE_RECORDINGDEVICE1
:
401 case CECDEVICE_TUNER1
:
412 cec_bus_device_status
CCECBusDevice::GetStatus(bool bForcePoll
/* = false */)
414 CLockObject
lock(m_mutex
);
415 if (m_deviceStatus
!= CEC_DEVICE_STATUS_HANDLED_BY_LIBCEC
&&
416 (m_deviceStatus
== CEC_DEVICE_STATUS_UNKNOWN
|| bForcePoll
))
419 bool bPollAcked(false);
420 if (bForcePoll
|| NeedsPoll())
421 bPollAcked
= m_processor
->PollDevice(m_iLogicalAddress
);
424 m_deviceStatus
= bPollAcked
? CEC_DEVICE_STATUS_PRESENT
: CEC_DEVICE_STATUS_NOT_PRESENT
;
427 return m_deviceStatus
;
434 void CCECBusDevice::SetCecVersion(const cec_version newVersion
)
436 m_cecVersion
= newVersion
;
437 CLibCEC::AddLog(CEC_LOG_DEBUG
, "%s (%X): CEC version %s", GetLogicalAddressName(), m_iLogicalAddress
, ToString(newVersion
));
440 void CCECBusDevice::SetMenuLanguage(const cec_menu_language
&language
)
442 CLockObject
lock(m_mutex
);
443 if (language
.device
== m_iLogicalAddress
)
445 CLibCEC::AddLog(CEC_LOG_DEBUG
, ">> %s (%X): menu language set to '%s'", GetLogicalAddressName(), m_iLogicalAddress
, language
.language
);
446 m_menuLanguage
= language
;
450 void CCECBusDevice::SetOSDName(CStdString strName
)
452 CLockObject
lock(m_mutex
);
453 if (m_strDeviceName
!= strName
)
455 CLibCEC::AddLog(CEC_LOG_DEBUG
, ">> %s (%X): osd name set to '%s'", GetLogicalAddressName(), m_iLogicalAddress
, strName
.c_str());
456 m_strDeviceName
= strName
;
460 void CCECBusDevice::SetMenuState(const cec_menu_state state
)
462 CLockObject
lock(m_mutex
);
463 if (m_menuState
!= state
)
465 CLibCEC::AddLog(CEC_LOG_DEBUG
, ">> %s (%X): menu state set to '%s'", GetLogicalAddressName(), m_iLogicalAddress
, ToString(m_menuState
));
470 void CCECBusDevice::SetInactiveSource(void)
473 CLockObject
lock(m_mutex
);
474 m_bActiveSource
= false;
477 if (MyLogicalAddressContains(m_iLogicalAddress
))
478 SetPowerStatus(CEC_POWER_STATUS_STANDBY
);
481 void CCECBusDevice::SetActiveSource(void)
483 CLockObject
lock(m_mutex
);
484 if (!m_bActiveSource
)
485 CLibCEC::AddLog(CEC_LOG_DEBUG
, "making %s (%x) the active source", GetLogicalAddressName(), m_iLogicalAddress
);
487 for (int iPtr
= 0; iPtr
< 16; iPtr
++)
488 if (iPtr
!= m_iLogicalAddress
)
489 m_processor
->m_busDevices
[iPtr
]->SetInactiveSource();
491 m_bActiveSource
= true;
492 m_powerStatus
= CEC_POWER_STATUS_ON
;
495 bool CCECBusDevice::TryLogicalAddress(void)
497 CLibCEC::AddLog(CEC_LOG_DEBUG
, "trying logical address '%s'", GetLogicalAddressName());
499 m_processor
->SetAckMask(0x1 << m_iLogicalAddress
);
500 if (!TransmitPoll(m_iLogicalAddress
))
502 CLibCEC::AddLog(CEC_LOG_NOTICE
, "using logical address '%s'", GetLogicalAddressName());
503 SetDeviceStatus(CEC_DEVICE_STATUS_HANDLED_BY_LIBCEC
);
508 CLibCEC::AddLog(CEC_LOG_DEBUG
, "logical address '%s' already taken", GetLogicalAddressName());
509 SetDeviceStatus(CEC_DEVICE_STATUS_PRESENT
);
513 void CCECBusDevice::SetDeviceStatus(const cec_bus_device_status newStatus
)
515 CLockObject
lock(m_mutex
);
518 case CEC_DEVICE_STATUS_UNKNOWN
:
520 m_powerStatus
= CEC_POWER_STATUS_UNKNOWN
;
521 m_vendor
= CEC_VENDOR_UNKNOWN
;
522 m_menuState
= CEC_MENU_STATE_ACTIVATED
;
523 m_bActiveSource
= false;
525 m_cecVersion
= CEC_VERSION_UNKNOWN
;
526 m_deviceStatus
= newStatus
;
528 case CEC_DEVICE_STATUS_HANDLED_BY_LIBCEC
:
530 m_powerStatus
= CEC_POWER_STATUS_ON
;
531 m_vendor
= CEC_VENDOR_UNKNOWN
;
532 m_menuState
= CEC_MENU_STATE_ACTIVATED
;
533 m_bActiveSource
= false;
535 m_cecVersion
= CEC_VERSION_1_3A
;
536 m_deviceStatus
= newStatus
;
538 case CEC_DEVICE_STATUS_PRESENT
:
539 case CEC_DEVICE_STATUS_NOT_PRESENT
:
540 m_deviceStatus
= newStatus
;
545 void CCECBusDevice::SetPhysicalAddress(uint16_t iNewAddress
)
547 CLockObject
lock(m_mutex
);
548 if (iNewAddress
> 0 && m_iPhysicalAddress
!= iNewAddress
)
550 CLibCEC::AddLog(CEC_LOG_DEBUG
, ">> %s (%X): physical address changed from %04x to %04x", GetLogicalAddressName(), m_iLogicalAddress
, m_iPhysicalAddress
, iNewAddress
);
551 m_iPhysicalAddress
= iNewAddress
;
555 void CCECBusDevice::SetStreamPath(uint16_t iNewAddress
, uint16_t iOldAddress
/* = 0 */)
557 CLockObject
lock(m_mutex
);
560 CLibCEC::AddLog(CEC_LOG_DEBUG
, ">> %s (%X): stream path changed from %04x to %04x", GetLogicalAddressName(), m_iLogicalAddress
, iOldAddress
== 0 ? m_iStreamPath
: iOldAddress
, iNewAddress
);
561 m_iStreamPath
= iNewAddress
;
566 SetPowerStatus(CEC_POWER_STATUS_ON
);
571 void CCECBusDevice::SetPowerStatus(const cec_power_status powerStatus
)
573 CLockObject
lock(m_mutex
);
574 if (m_powerStatus
!= powerStatus
)
576 m_iLastPowerStateUpdate
= GetTimeMs();
577 CLibCEC::AddLog(CEC_LOG_DEBUG
, ">> %s (%X): power status changed from '%s' to '%s'", GetLogicalAddressName(), m_iLogicalAddress
, ToString(m_powerStatus
), ToString(powerStatus
));
578 m_powerStatus
= powerStatus
;
582 bool CCECBusDevice::ReplaceHandler(bool bActivateSource
/* = true */)
584 CLockObject
lock(m_mutex
);
585 CLockObject
handlerLock(m_handlerMutex
);
587 if (m_vendor
!= m_handler
->GetVendorId())
589 if (CCECCommandHandler::HasSpecificHandler(m_vendor
))
592 if (m_handler
->InUse())
594 CLibCEC::AddLog(CEC_LOG_DEBUG
, "handler for device '%s' (%x) is being used. not replacing the command handler", GetLogicalAddressName(), GetLogicalAddress());
598 CLibCEC::AddLog(CEC_LOG_DEBUG
, "replacing the command handler for device '%s' (%x)", GetLogicalAddressName(), GetLogicalAddress());
603 case CEC_VENDOR_SAMSUNG
:
604 m_handler
= new CANCommandHandler(this);
607 m_handler
= new CSLCommandHandler(this);
609 case CEC_VENDOR_PANASONIC
:
610 m_handler
= new CVLCommandHandler(this);
613 m_handler
= new CCECCommandHandler(this);
617 m_handler
->SetVendorId(m_vendor
);
618 m_handler
->InitHandler();
620 if (bActivateSource
&& m_processor
->GetLogicalAddresses().IsSet(m_iLogicalAddress
) && m_processor
->IsInitialised() && IsActiveSource())
621 m_handler
->ActivateSource();
628 bool CCECBusDevice::SetVendorId(uint64_t iVendorId
)
630 bool bVendorChanged(false);
633 CLockObject
lock(m_mutex
);
634 bVendorChanged
= (m_vendor
!= (cec_vendor_id
)iVendorId
);
635 m_vendor
= (cec_vendor_id
)iVendorId
;
638 CLibCEC::AddLog(CEC_LOG_DEBUG
, "%s (%X): vendor = %s (%06x)", GetLogicalAddressName(), m_iLogicalAddress
, ToString(m_vendor
), m_vendor
);
640 return bVendorChanged
;
644 /** @name Transmit methods */
646 bool CCECBusDevice::TransmitActiveSource(void)
648 bool bSendActiveSource(false);
651 CLockObject
lock(m_mutex
);
652 if (m_powerStatus
!= CEC_POWER_STATUS_ON
)
653 CLibCEC::AddLog(CEC_LOG_DEBUG
, "<< %s (%X) is not powered on", GetLogicalAddressName(), m_iLogicalAddress
);
654 else if (m_bActiveSource
)
656 CLibCEC::AddLog(CEC_LOG_NOTICE
, "<< %s (%X) -> broadcast (F): active source (%4x)", GetLogicalAddressName(), m_iLogicalAddress
, m_iPhysicalAddress
);
657 bSendActiveSource
= true;
660 CLibCEC::AddLog(CEC_LOG_DEBUG
, "<< %s (%X) is not the active source", GetLogicalAddressName(), m_iLogicalAddress
);
663 if (bSendActiveSource
)
665 m_handler
->TransmitImageViewOn(m_iLogicalAddress
, CECDEVICE_TV
);
666 m_handler
->TransmitActiveSource(m_iLogicalAddress
, m_iPhysicalAddress
);
673 bool CCECBusDevice::TransmitCECVersion(cec_logical_address dest
)
677 CLockObject
lock(m_mutex
);
678 CLibCEC::AddLog(CEC_LOG_NOTICE
, "<< %s (%X) -> %s (%X): cec version %s", GetLogicalAddressName(), m_iLogicalAddress
, ToString(dest
), dest
, ToString(m_cecVersion
));
679 version
= m_cecVersion
;
682 return m_handler
->TransmitCECVersion(m_iLogicalAddress
, dest
, version
);
685 bool CCECBusDevice::TransmitInactiveSource(void)
687 uint16_t iPhysicalAddress
;
689 CLockObject
lock(m_mutex
);
690 CLibCEC::AddLog(CEC_LOG_NOTICE
, "<< %s (%X) -> broadcast (F): inactive source", GetLogicalAddressName(), m_iLogicalAddress
);
691 iPhysicalAddress
= m_iPhysicalAddress
;
694 return m_handler
->TransmitInactiveSource(m_iLogicalAddress
, iPhysicalAddress
);
697 bool CCECBusDevice::TransmitMenuState(cec_logical_address dest
)
699 cec_menu_state menuState
;
701 CLockObject
lock(m_mutex
);
702 CLibCEC::AddLog(CEC_LOG_NOTICE
, "<< %s (%X) -> %s (%X): menu state '%s'", GetLogicalAddressName(), m_iLogicalAddress
, ToString(dest
), dest
, ToString(m_menuState
));
703 menuState
= m_menuState
;
706 return m_handler
->TransmitMenuState(m_iLogicalAddress
, dest
, menuState
);
709 bool CCECBusDevice::TransmitOSDName(cec_logical_address dest
)
711 CStdString strDeviceName
;
713 CLockObject
lock(m_mutex
);
714 CLibCEC::AddLog(CEC_LOG_NOTICE
, "<< %s (%X) -> %s (%X): OSD name '%s'", GetLogicalAddressName(), m_iLogicalAddress
, ToString(dest
), dest
, m_strDeviceName
.c_str());
715 strDeviceName
= m_strDeviceName
;
718 return m_handler
->TransmitOSDName(m_iLogicalAddress
, dest
, strDeviceName
);
721 bool CCECBusDevice::TransmitOSDString(cec_logical_address dest
, cec_display_control duration
, const char *strMessage
)
723 if (!IsUnsupportedFeature(CEC_OPCODE_SET_OSD_STRING
))
725 CLibCEC::AddLog(CEC_LOG_NOTICE
, "<< %s (%X) -> %s (%X): display OSD message '%s'", GetLogicalAddressName(), m_iLogicalAddress
, ToString(dest
), dest
, strMessage
);
726 return m_handler
->TransmitOSDString(m_iLogicalAddress
, dest
, duration
, strMessage
);
731 bool CCECBusDevice::TransmitPhysicalAddress(void)
733 uint16_t iPhysicalAddress
;
734 cec_device_type type
;
736 CLockObject
lock(m_mutex
);
737 if (m_iPhysicalAddress
== 0xffff)
740 CLibCEC::AddLog(CEC_LOG_NOTICE
, "<< %s (%X) -> broadcast (F): physical adddress %4x", GetLogicalAddressName(), m_iLogicalAddress
, m_iPhysicalAddress
);
741 iPhysicalAddress
= m_iPhysicalAddress
;
745 return m_handler
->TransmitPhysicalAddress(m_iLogicalAddress
, iPhysicalAddress
, type
);
748 bool CCECBusDevice::TransmitPoll(cec_logical_address dest
)
751 if (dest
== CECDEVICE_UNKNOWN
)
752 dest
= m_iLogicalAddress
;
754 CCECBusDevice
*destDevice
= m_processor
->m_busDevices
[dest
];
755 if (destDevice
->m_deviceStatus
== CEC_DEVICE_STATUS_HANDLED_BY_LIBCEC
)
758 CLibCEC::AddLog(CEC_LOG_NOTICE
, "<< %s (%X) -> %s (%X): POLL", GetLogicalAddressName(), m_iLogicalAddress
, ToString(dest
), dest
);
759 bReturn
= m_handler
->TransmitPoll(m_iLogicalAddress
, dest
);
760 CLibCEC::AddLog(CEC_LOG_DEBUG
, bReturn
? ">> POLL sent" : ">> POLL not sent");
762 CLockObject
lock(m_mutex
);
765 m_iLastActive
= GetTimeMs();
766 destDevice
->m_deviceStatus
= CEC_DEVICE_STATUS_PRESENT
;
769 destDevice
->m_deviceStatus
= CEC_DEVICE_STATUS_NOT_PRESENT
;
774 bool CCECBusDevice::TransmitPowerState(cec_logical_address dest
)
776 cec_power_status state
;
778 CLockObject
lock(m_mutex
);
779 CLibCEC::AddLog(CEC_LOG_NOTICE
, "<< %s (%X) -> %s (%X): %s", GetLogicalAddressName(), m_iLogicalAddress
, ToString(dest
), dest
, ToString(m_powerStatus
));
780 state
= m_powerStatus
;
783 return m_handler
->TransmitPowerState(m_iLogicalAddress
, dest
, state
);
786 bool CCECBusDevice::TransmitVendorID(cec_logical_address dest
, bool bSendAbort
/* = true */)
790 CLockObject
lock(m_mutex
);
791 iVendorId
= (uint64_t)m_vendor
;
794 if (iVendorId
== CEC_VENDOR_UNKNOWN
)
798 CLibCEC::AddLog(CEC_LOG_NOTICE
, "<< %s (%X) -> %s (%X): vendor id feature abort", GetLogicalAddressName(), m_iLogicalAddress
, ToString(dest
), dest
);
799 m_processor
->TransmitAbort(dest
, CEC_OPCODE_GIVE_DEVICE_VENDOR_ID
);
805 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
);
806 return m_handler
->TransmitVendorID(m_iLogicalAddress
, iVendorId
);
810 bool CCECBusDevice::TransmitKeypress(cec_user_control_code key
, bool bWait
/* = true */)
812 return m_handler
->TransmitKeypress(m_processor
->GetLogicalAddress(), m_iLogicalAddress
, key
, bWait
);
815 bool CCECBusDevice::TransmitKeyRelease(bool bWait
/* = true */)
817 return m_handler
->TransmitKeyRelease(m_processor
->GetLogicalAddress(), m_iLogicalAddress
, bWait
);
820 bool CCECBusDevice::IsUnsupportedFeature(cec_opcode opcode
) const
822 return m_unsupportedFeatures
.find(opcode
) != m_unsupportedFeatures
.end();
825 void CCECBusDevice::SetUnsupportedFeature(cec_opcode opcode
)
827 m_unsupportedFeatures
.insert(opcode
);
830 bool CCECBusDevice::ActivateSource(void)
832 CLockObject
lock(m_mutex
);
833 return m_handler
->ActivateSource();