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
)
63 m_handler
= new CCECCommandHandler(this);
65 for (unsigned int iPtr
= 0; iPtr
< 4; iPtr
++)
66 m_menuLanguage
.language
[iPtr
] = '?';
67 m_menuLanguage
.language
[3] = 0;
68 m_menuLanguage
.device
= iLogicalAddress
;
70 m_strDeviceName
= ToString(m_iLogicalAddress
);
73 CCECBusDevice::~CCECBusDevice(void)
78 bool CCECBusDevice::HandleCommand(const cec_command
&command
)
82 /* update "last active" */
84 CLockObject
lock(m_mutex
);
85 m_iLastActive
= GetTimeMs();
87 if (m_deviceStatus
!= CEC_DEVICE_STATUS_HANDLED_BY_LIBCEC
)
88 m_deviceStatus
= CEC_DEVICE_STATUS_PRESENT
;
91 /* handle the command */
92 bHandled
= m_handler
->HandleCommand(command
);
94 /* change status to present */
97 CLockObject
lock(m_mutex
);
98 if (m_deviceStatus
!= CEC_DEVICE_STATUS_HANDLED_BY_LIBCEC
)
100 if (m_deviceStatus
!= CEC_DEVICE_STATUS_PRESENT
)
101 CLibCEC::AddLog(CEC_LOG_DEBUG
, "device %s (%x) status changed to present after command %s", GetLogicalAddressName(), (uint8_t)GetLogicalAddress(), ToString(command
.opcode
));
102 m_deviceStatus
= CEC_DEVICE_STATUS_PRESENT
;
109 bool CCECBusDevice::PowerOn(void)
111 CLibCEC::AddLog(CEC_LOG_DEBUG
, "<< powering on '%s' (%X)", GetLogicalAddressName(), m_iLogicalAddress
);
113 if (m_handler
->TransmitImageViewOn(GetMyLogicalAddress(), m_iLogicalAddress
))
116 CLockObject
lock(m_mutex
);
117 // m_powerStatus = CEC_POWER_STATUS_UNKNOWN;
118 m_powerStatus
= CEC_POWER_STATUS_IN_TRANSITION_STANDBY_TO_ON
;
120 // cec_power_status status = GetPowerStatus();
121 // if (status == CEC_POWER_STATUS_STANDBY || status == CEC_POWER_STATUS_UNKNOWN)
123 // /* sending the normal power on command appears to have failed */
124 // CStdString strLog;
125 // strLog.Format("<< sending power on keypress to '%s' (%X)", GetLogicalAddressName(), m_iLogicalAddress);
126 // CLibCEC::AddLog(CEC_LOG_DEBUG, strLog.c_str());
128 // TransmitKeypress(CEC_USER_CONTROL_CODE_POWER);
129 // return TransmitKeyRelease();
137 bool CCECBusDevice::Standby(void)
139 CLibCEC::AddLog(CEC_LOG_DEBUG
, "<< putting '%s' (%X) in standby mode", GetLogicalAddressName(), m_iLogicalAddress
);
140 return m_handler
->TransmitStandby(GetMyLogicalAddress(), m_iLogicalAddress
);
145 cec_version
CCECBusDevice::GetCecVersion(bool bUpdate
/* = false */)
147 bool bRequestUpdate(false);
149 CLockObject
lock(m_mutex
);
150 bRequestUpdate
= (GetStatus() == CEC_DEVICE_STATUS_PRESENT
&&
151 (bUpdate
|| m_cecVersion
== CEC_VERSION_UNKNOWN
));
157 CLockObject
lock(m_mutex
);
161 bool CCECBusDevice::RequestCecVersion(void)
165 if (!MyLogicalAddressContains(m_iLogicalAddress
))
167 m_handler
->MarkBusy();
168 CLibCEC::AddLog(CEC_LOG_NOTICE
, "<< requesting CEC version of '%s' (%X)", GetLogicalAddressName(), m_iLogicalAddress
);
170 bReturn
= m_handler
->TransmitRequestCecVersion(GetMyLogicalAddress(), m_iLogicalAddress
);
171 m_handler
->MarkReady();
176 const char* CCECBusDevice::GetLogicalAddressName(void) const
178 return ToString(m_iLogicalAddress
);
181 cec_menu_language
&CCECBusDevice::GetMenuLanguage(bool bUpdate
/* = false */)
183 bool bRequestUpdate(false);
185 CLockObject
lock(m_mutex
);
186 bRequestUpdate
= (GetStatus() == CEC_DEVICE_STATUS_PRESENT
&&
187 (bUpdate
|| !strcmp(m_menuLanguage
.language
, "???")));
191 RequestMenuLanguage();
193 CLockObject
lock(m_mutex
);
194 return m_menuLanguage
;
197 bool CCECBusDevice::RequestMenuLanguage(void)
201 if (!MyLogicalAddressContains(m_iLogicalAddress
) &&
202 !IsUnsupportedFeature(CEC_OPCODE_GET_MENU_LANGUAGE
))
204 m_handler
->MarkBusy();
205 CLibCEC::AddLog(CEC_LOG_NOTICE
, "<< requesting menu language of '%s' (%X)", GetLogicalAddressName(), m_iLogicalAddress
);
206 bReturn
= m_handler
->TransmitRequestMenuLanguage(GetMyLogicalAddress(), m_iLogicalAddress
);
207 m_handler
->MarkReady();
212 cec_menu_state
CCECBusDevice::GetMenuState(void)
214 CLockObject
lock(m_mutex
);
218 cec_logical_address
CCECBusDevice::GetMyLogicalAddress(void) const
220 return m_processor
->GetLogicalAddress();
223 uint16_t CCECBusDevice::GetMyPhysicalAddress(void) const
225 return m_processor
->GetPhysicalAddress();
228 CStdString
CCECBusDevice::GetOSDName(bool bUpdate
/* = false */)
230 bool bRequestUpdate(false);
232 CLockObject
lock(m_mutex
);
233 bRequestUpdate
= (GetStatus() == CEC_DEVICE_STATUS_PRESENT
&&
234 (bUpdate
|| m_strDeviceName
.Equals(ToString(m_iLogicalAddress
))) &&
235 m_type
!= CEC_DEVICE_TYPE_TV
);
241 CLockObject
lock(m_mutex
);
242 return m_strDeviceName
;
245 bool CCECBusDevice::RequestOSDName(void)
249 if (!MyLogicalAddressContains(m_iLogicalAddress
) &&
250 !IsUnsupportedFeature(CEC_OPCODE_GIVE_OSD_NAME
))
252 m_handler
->MarkBusy();
253 CLibCEC::AddLog(CEC_LOG_NOTICE
, "<< requesting OSD name of '%s' (%X)", GetLogicalAddressName(), m_iLogicalAddress
);
254 bReturn
= m_handler
->TransmitRequestOSDName(GetMyLogicalAddress(), m_iLogicalAddress
);
255 m_handler
->MarkReady();
260 uint16_t CCECBusDevice::GetPhysicalAddress(bool bUpdate
/* = false */)
262 bool bRequestUpdate(false);
264 CLockObject
lock(m_mutex
);
265 bRequestUpdate
= (GetStatus() == CEC_DEVICE_STATUS_PRESENT
&&
266 (m_iPhysicalAddress
== 0xFFFF || bUpdate
));
269 if (bRequestUpdate
&& !RequestPhysicalAddress())
270 CLibCEC::AddLog(CEC_LOG_ERROR
, "failed to request the physical address");
272 CLockObject
lock(m_mutex
);
273 return m_iPhysicalAddress
;
276 bool CCECBusDevice::RequestPhysicalAddress(void)
280 if (!MyLogicalAddressContains(m_iLogicalAddress
))
282 m_handler
->MarkBusy();
283 CLibCEC::AddLog(CEC_LOG_NOTICE
, "<< requesting physical address of '%s' (%X)", GetLogicalAddressName(), m_iLogicalAddress
);
284 bReturn
= m_handler
->TransmitRequestPhysicalAddress(GetMyLogicalAddress(), m_iLogicalAddress
);
285 m_handler
->MarkReady();
290 cec_power_status
CCECBusDevice::GetPowerStatus(bool bUpdate
/* = false */)
292 bool bRequestUpdate(false);
294 CLockObject
lock(m_mutex
);
295 bRequestUpdate
= (GetStatus() == CEC_DEVICE_STATUS_PRESENT
&&
296 (bUpdate
|| m_powerStatus
== CEC_POWER_STATUS_UNKNOWN
||
297 m_powerStatus
== CEC_POWER_STATUS_IN_TRANSITION_STANDBY_TO_ON
||
298 m_powerStatus
== CEC_POWER_STATUS_IN_TRANSITION_ON_TO_STANDBY
||
299 GetTimeMs() - m_iLastPowerStateUpdate
>= CEC_POWER_STATE_REFRESH_TIME
));
303 RequestPowerStatus();
305 CLockObject
lock(m_mutex
);
306 return m_powerStatus
;
309 bool CCECBusDevice::RequestPowerStatus(void)
313 if (!MyLogicalAddressContains(m_iLogicalAddress
) &&
314 !IsUnsupportedFeature(CEC_OPCODE_GIVE_DEVICE_POWER_STATUS
))
316 m_handler
->MarkBusy();
317 CLibCEC::AddLog(CEC_LOG_NOTICE
, "<< requesting power status of '%s' (%X)", GetLogicalAddressName(), m_iLogicalAddress
);
318 bReturn
= m_handler
->TransmitRequestPowerStatus(GetMyLogicalAddress(), m_iLogicalAddress
);
319 m_handler
->MarkReady();
324 cec_vendor_id
CCECBusDevice::GetVendorId(bool bUpdate
/* = false */)
326 bool bRequestUpdate(false);
328 CLockObject
lock(m_mutex
);
329 bRequestUpdate
= (GetStatus() == CEC_DEVICE_STATUS_PRESENT
&&
330 (bUpdate
|| m_vendor
== CEC_VENDOR_UNKNOWN
));
336 CLockObject
lock(m_mutex
);
340 bool CCECBusDevice::RequestVendorId(void)
344 if (!MyLogicalAddressContains(m_iLogicalAddress
))
346 m_handler
->MarkBusy();
347 CLibCEC::AddLog(CEC_LOG_NOTICE
, "<< requesting vendor ID of '%s' (%X)", GetLogicalAddressName(), m_iLogicalAddress
);
348 bReturn
= m_handler
->TransmitRequestVendorId(GetMyLogicalAddress(), m_iLogicalAddress
);
349 m_handler
->MarkReady();
351 ReplaceHandler(true);
356 const char *CCECBusDevice::GetVendorName(bool bUpdate
/* = false */)
358 return ToString(GetVendorId(bUpdate
));
361 bool CCECBusDevice::MyLogicalAddressContains(cec_logical_address address
) const
363 return m_processor
->HasLogicalAddress(address
);
366 bool CCECBusDevice::NeedsPoll(void)
368 bool bSendPoll(false);
369 switch (m_iLogicalAddress
)
371 case CECDEVICE_PLAYBACKDEVICE3
:
372 if (m_processor
->m_busDevices
[CECDEVICE_PLAYBACKDEVICE2
]->GetStatus() == CEC_DEVICE_STATUS_PRESENT
)
375 case CECDEVICE_PLAYBACKDEVICE2
:
376 if (m_processor
->m_busDevices
[CECDEVICE_PLAYBACKDEVICE1
]->GetStatus() == CEC_DEVICE_STATUS_PRESENT
)
379 case CECDEVICE_RECORDINGDEVICE3
:
380 if (m_processor
->m_busDevices
[CECDEVICE_RECORDINGDEVICE2
]->GetStatus() == CEC_DEVICE_STATUS_PRESENT
)
383 case CECDEVICE_RECORDINGDEVICE2
:
384 if (m_processor
->m_busDevices
[CECDEVICE_RECORDINGDEVICE1
]->GetStatus() == CEC_DEVICE_STATUS_PRESENT
)
387 case CECDEVICE_TUNER4
:
388 if (m_processor
->m_busDevices
[CECDEVICE_TUNER3
]->GetStatus() == CEC_DEVICE_STATUS_PRESENT
)
391 case CECDEVICE_TUNER3
:
392 if (m_processor
->m_busDevices
[CECDEVICE_TUNER2
]->GetStatus() == CEC_DEVICE_STATUS_PRESENT
)
395 case CECDEVICE_TUNER2
:
396 if (m_processor
->m_busDevices
[CECDEVICE_TUNER1
]->GetStatus() == CEC_DEVICE_STATUS_PRESENT
)
399 case CECDEVICE_AUDIOSYSTEM
:
400 case CECDEVICE_PLAYBACKDEVICE1
:
401 case CECDEVICE_RECORDINGDEVICE1
:
402 case CECDEVICE_TUNER1
:
413 cec_bus_device_status
CCECBusDevice::GetStatus(bool bForcePoll
/* = false */)
415 CLockObject
lock(m_mutex
);
416 if (m_deviceStatus
!= CEC_DEVICE_STATUS_HANDLED_BY_LIBCEC
&&
417 (m_deviceStatus
== CEC_DEVICE_STATUS_UNKNOWN
|| bForcePoll
))
420 bool bPollAcked(false);
421 if (bForcePoll
|| NeedsPoll())
422 bPollAcked
= m_processor
->PollDevice(m_iLogicalAddress
);
425 m_deviceStatus
= bPollAcked
? CEC_DEVICE_STATUS_PRESENT
: CEC_DEVICE_STATUS_NOT_PRESENT
;
428 return m_deviceStatus
;
435 void CCECBusDevice::SetCecVersion(const cec_version newVersion
)
437 m_cecVersion
= newVersion
;
438 CLibCEC::AddLog(CEC_LOG_DEBUG
, "%s (%X): CEC version %s", GetLogicalAddressName(), m_iLogicalAddress
, ToString(newVersion
));
441 void CCECBusDevice::SetMenuLanguage(const cec_menu_language
&language
)
443 CLockObject
lock(m_mutex
);
444 if (language
.device
== m_iLogicalAddress
)
446 CLibCEC::AddLog(CEC_LOG_DEBUG
, ">> %s (%X): menu language set to '%s'", GetLogicalAddressName(), m_iLogicalAddress
, language
.language
);
447 m_menuLanguage
= language
;
451 void CCECBusDevice::SetOSDName(CStdString strName
)
453 CLockObject
lock(m_mutex
);
454 if (m_strDeviceName
!= strName
)
456 CLibCEC::AddLog(CEC_LOG_DEBUG
, ">> %s (%X): osd name set to '%s'", GetLogicalAddressName(), m_iLogicalAddress
, strName
.c_str());
457 m_strDeviceName
= strName
;
461 void CCECBusDevice::SetMenuState(const cec_menu_state state
)
463 CLockObject
lock(m_mutex
);
464 if (m_menuState
!= state
)
466 CLibCEC::AddLog(CEC_LOG_DEBUG
, ">> %s (%X): menu state set to '%s'", GetLogicalAddressName(), m_iLogicalAddress
, ToString(m_menuState
));
471 void CCECBusDevice::SetInactiveSource(void)
474 CLockObject
lock(m_mutex
);
475 m_bActiveSource
= false;
478 if (MyLogicalAddressContains(m_iLogicalAddress
))
479 SetPowerStatus(CEC_POWER_STATUS_STANDBY
);
482 void CCECBusDevice::SetActiveSource(void)
484 CLockObject
lock(m_mutex
);
485 if (!m_bActiveSource
)
486 CLibCEC::AddLog(CEC_LOG_DEBUG
, "making %s (%x) the active source", GetLogicalAddressName(), m_iLogicalAddress
);
488 for (int iPtr
= 0; iPtr
< 16; iPtr
++)
489 if (iPtr
!= m_iLogicalAddress
)
490 m_processor
->m_busDevices
[iPtr
]->SetInactiveSource();
492 m_bActiveSource
= true;
493 m_powerStatus
= CEC_POWER_STATUS_ON
;
496 bool CCECBusDevice::TryLogicalAddress(void)
498 CLibCEC::AddLog(CEC_LOG_DEBUG
, "trying logical address '%s'", GetLogicalAddressName());
500 m_processor
->SetAckMask(0);
501 if (!TransmitPoll(m_iLogicalAddress
))
503 CLibCEC::AddLog(CEC_LOG_NOTICE
, "using logical address '%s'", GetLogicalAddressName());
504 SetDeviceStatus(CEC_DEVICE_STATUS_HANDLED_BY_LIBCEC
);
509 CLibCEC::AddLog(CEC_LOG_DEBUG
, "logical address '%s' already taken", GetLogicalAddressName());
510 SetDeviceStatus(CEC_DEVICE_STATUS_PRESENT
);
514 void CCECBusDevice::SetDeviceStatus(const cec_bus_device_status newStatus
)
516 CLockObject
lock(m_mutex
);
519 case CEC_DEVICE_STATUS_UNKNOWN
:
521 m_powerStatus
= CEC_POWER_STATUS_UNKNOWN
;
522 m_vendor
= CEC_VENDOR_UNKNOWN
;
523 m_menuState
= CEC_MENU_STATE_ACTIVATED
;
524 m_bActiveSource
= false;
526 m_cecVersion
= CEC_VERSION_UNKNOWN
;
527 m_deviceStatus
= newStatus
;
529 case CEC_DEVICE_STATUS_HANDLED_BY_LIBCEC
:
531 m_powerStatus
= CEC_POWER_STATUS_ON
;
532 m_vendor
= CEC_VENDOR_UNKNOWN
;
533 m_menuState
= CEC_MENU_STATE_ACTIVATED
;
534 m_bActiveSource
= false;
536 m_cecVersion
= CEC_VERSION_1_3A
;
537 m_deviceStatus
= newStatus
;
539 case CEC_DEVICE_STATUS_PRESENT
:
540 case CEC_DEVICE_STATUS_NOT_PRESENT
:
541 m_deviceStatus
= newStatus
;
546 void CCECBusDevice::SetPhysicalAddress(uint16_t iNewAddress
)
548 CLockObject
lock(m_mutex
);
549 if (iNewAddress
> 0 && m_iPhysicalAddress
!= iNewAddress
)
551 CLibCEC::AddLog(CEC_LOG_DEBUG
, ">> %s (%X): physical address changed from %04x to %04x", GetLogicalAddressName(), m_iLogicalAddress
, m_iPhysicalAddress
, iNewAddress
);
552 m_iPhysicalAddress
= iNewAddress
;
556 void CCECBusDevice::SetStreamPath(uint16_t iNewAddress
, uint16_t iOldAddress
/* = 0 */)
558 CLockObject
lock(m_mutex
);
561 CLibCEC::AddLog(CEC_LOG_DEBUG
, ">> %s (%X): stream path changed from %04x to %04x", GetLogicalAddressName(), m_iLogicalAddress
, iOldAddress
== 0 ? m_iStreamPath
: iOldAddress
, iNewAddress
);
562 m_iStreamPath
= iNewAddress
;
567 SetPowerStatus(CEC_POWER_STATUS_ON
);
572 void CCECBusDevice::SetPowerStatus(const cec_power_status powerStatus
)
574 CLockObject
lock(m_mutex
);
575 if (m_powerStatus
!= powerStatus
)
577 m_iLastPowerStateUpdate
= GetTimeMs();
578 CLibCEC::AddLog(CEC_LOG_DEBUG
, ">> %s (%X): power status changed from '%s' to '%s'", GetLogicalAddressName(), m_iLogicalAddress
, ToString(m_powerStatus
), ToString(powerStatus
));
579 m_powerStatus
= powerStatus
;
583 bool CCECBusDevice::ReplaceHandler(bool bActivateSource
/* = true */)
585 CLockObject
lock(m_mutex
);
586 CLockObject
handlerLock(m_handlerMutex
);
588 if (m_vendor
!= m_handler
->GetVendorId())
590 if (CCECCommandHandler::HasSpecificHandler(m_vendor
))
593 if (m_handler
->InUse())
595 CLibCEC::AddLog(CEC_LOG_DEBUG
, "handler for device '%s' (%x) is being used. not replacing the command handler", GetLogicalAddressName(), GetLogicalAddress());
599 CLibCEC::AddLog(CEC_LOG_DEBUG
, "replacing the command handler for device '%s' (%x)", GetLogicalAddressName(), GetLogicalAddress());
604 case CEC_VENDOR_SAMSUNG
:
605 m_handler
= new CANCommandHandler(this);
608 m_handler
= new CSLCommandHandler(this);
610 case CEC_VENDOR_PANASONIC
:
611 m_handler
= new CVLCommandHandler(this);
614 m_handler
= new CCECCommandHandler(this);
618 m_handler
->SetVendorId(m_vendor
);
619 m_handler
->InitHandler();
621 if (bActivateSource
&& m_processor
->GetLogicalAddresses().IsSet(m_iLogicalAddress
) && m_processor
->IsInitialised() && IsActiveSource())
622 m_handler
->ActivateSource();
629 bool CCECBusDevice::SetVendorId(uint64_t iVendorId
)
631 bool bVendorChanged(false);
634 CLockObject
lock(m_mutex
);
635 bVendorChanged
= (m_vendor
!= (cec_vendor_id
)iVendorId
);
636 m_vendor
= (cec_vendor_id
)iVendorId
;
639 CLibCEC::AddLog(CEC_LOG_DEBUG
, "%s (%X): vendor = %s (%06x)", GetLogicalAddressName(), m_iLogicalAddress
, ToString(m_vendor
), m_vendor
);
641 return bVendorChanged
;
645 /** @name Transmit methods */
647 bool CCECBusDevice::TransmitActiveSource(void)
649 bool bSendActiveSource(false);
652 CLockObject
lock(m_mutex
);
653 if (m_powerStatus
!= CEC_POWER_STATUS_ON
)
654 CLibCEC::AddLog(CEC_LOG_DEBUG
, "<< %s (%X) is not powered on", GetLogicalAddressName(), m_iLogicalAddress
);
655 else if (m_bActiveSource
)
657 CLibCEC::AddLog(CEC_LOG_NOTICE
, "<< %s (%X) -> broadcast (F): active source (%4x)", GetLogicalAddressName(), m_iLogicalAddress
, m_iPhysicalAddress
);
658 bSendActiveSource
= true;
661 CLibCEC::AddLog(CEC_LOG_DEBUG
, "<< %s (%X) is not the active source", GetLogicalAddressName(), m_iLogicalAddress
);
664 if (bSendActiveSource
)
666 m_handler
->TransmitImageViewOn(m_iLogicalAddress
, CECDEVICE_TV
);
667 m_handler
->TransmitActiveSource(m_iLogicalAddress
, m_iPhysicalAddress
);
674 bool CCECBusDevice::TransmitCECVersion(cec_logical_address dest
)
678 CLockObject
lock(m_mutex
);
679 CLibCEC::AddLog(CEC_LOG_NOTICE
, "<< %s (%X) -> %s (%X): cec version %s", GetLogicalAddressName(), m_iLogicalAddress
, ToString(dest
), dest
, ToString(m_cecVersion
));
680 version
= m_cecVersion
;
683 return m_handler
->TransmitCECVersion(m_iLogicalAddress
, dest
, version
);
686 bool CCECBusDevice::TransmitInactiveSource(void)
688 uint16_t iPhysicalAddress
;
690 CLockObject
lock(m_mutex
);
691 CLibCEC::AddLog(CEC_LOG_NOTICE
, "<< %s (%X) -> broadcast (F): inactive source", GetLogicalAddressName(), m_iLogicalAddress
);
692 iPhysicalAddress
= m_iPhysicalAddress
;
695 return m_handler
->TransmitInactiveSource(m_iLogicalAddress
, iPhysicalAddress
);
698 bool CCECBusDevice::TransmitMenuState(cec_logical_address dest
)
700 cec_menu_state menuState
;
702 CLockObject
lock(m_mutex
);
703 CLibCEC::AddLog(CEC_LOG_NOTICE
, "<< %s (%X) -> %s (%X): menu state '%s'", GetLogicalAddressName(), m_iLogicalAddress
, ToString(dest
), dest
, ToString(m_menuState
));
704 menuState
= m_menuState
;
707 return m_handler
->TransmitMenuState(m_iLogicalAddress
, dest
, menuState
);
710 bool CCECBusDevice::TransmitOSDName(cec_logical_address dest
)
712 CStdString strDeviceName
;
714 CLockObject
lock(m_mutex
);
715 CLibCEC::AddLog(CEC_LOG_NOTICE
, "<< %s (%X) -> %s (%X): OSD name '%s'", GetLogicalAddressName(), m_iLogicalAddress
, ToString(dest
), dest
, m_strDeviceName
.c_str());
716 strDeviceName
= m_strDeviceName
;
719 return m_handler
->TransmitOSDName(m_iLogicalAddress
, dest
, strDeviceName
);
722 bool CCECBusDevice::TransmitOSDString(cec_logical_address dest
, cec_display_control duration
, const char *strMessage
)
724 if (!IsUnsupportedFeature(CEC_OPCODE_SET_OSD_STRING
))
726 CLibCEC::AddLog(CEC_LOG_NOTICE
, "<< %s (%X) -> %s (%X): display OSD message '%s'", GetLogicalAddressName(), m_iLogicalAddress
, ToString(dest
), dest
, strMessage
);
727 return m_handler
->TransmitOSDString(m_iLogicalAddress
, dest
, duration
, strMessage
);
732 bool CCECBusDevice::TransmitPhysicalAddress(void)
734 uint16_t iPhysicalAddress
;
735 cec_device_type type
;
737 CLockObject
lock(m_mutex
);
738 if (m_iPhysicalAddress
== 0xffff)
741 CLibCEC::AddLog(CEC_LOG_NOTICE
, "<< %s (%X) -> broadcast (F): physical adddress %4x", GetLogicalAddressName(), m_iLogicalAddress
, m_iPhysicalAddress
);
742 iPhysicalAddress
= m_iPhysicalAddress
;
746 return m_handler
->TransmitPhysicalAddress(m_iLogicalAddress
, iPhysicalAddress
, type
);
749 bool CCECBusDevice::TransmitPoll(cec_logical_address dest
)
752 if (dest
== CECDEVICE_UNKNOWN
)
753 dest
= m_iLogicalAddress
;
755 CCECBusDevice
*destDevice
= m_processor
->m_busDevices
[dest
];
756 if (destDevice
->m_deviceStatus
== CEC_DEVICE_STATUS_HANDLED_BY_LIBCEC
)
759 CLibCEC::AddLog(CEC_LOG_NOTICE
, "<< %s (%X) -> %s (%X): POLL", GetLogicalAddressName(), m_iLogicalAddress
, ToString(dest
), dest
);
760 bReturn
= m_handler
->TransmitPoll(m_iLogicalAddress
, dest
);
761 CLibCEC::AddLog(CEC_LOG_DEBUG
, bReturn
? ">> POLL sent" : ">> POLL not sent");
763 CLockObject
lock(m_mutex
);
766 m_iLastActive
= GetTimeMs();
767 destDevice
->m_deviceStatus
= CEC_DEVICE_STATUS_PRESENT
;
770 destDevice
->m_deviceStatus
= CEC_DEVICE_STATUS_NOT_PRESENT
;
775 bool CCECBusDevice::TransmitPowerState(cec_logical_address dest
)
777 cec_power_status state
;
779 CLockObject
lock(m_mutex
);
780 CLibCEC::AddLog(CEC_LOG_NOTICE
, "<< %s (%X) -> %s (%X): %s", GetLogicalAddressName(), m_iLogicalAddress
, ToString(dest
), dest
, ToString(m_powerStatus
));
781 state
= m_powerStatus
;
784 return m_handler
->TransmitPowerState(m_iLogicalAddress
, dest
, state
);
787 bool CCECBusDevice::TransmitVendorID(cec_logical_address dest
, bool bSendAbort
/* = true */)
791 CLockObject
lock(m_mutex
);
792 iVendorId
= (uint64_t)m_vendor
;
795 if (iVendorId
== CEC_VENDOR_UNKNOWN
)
799 CLibCEC::AddLog(CEC_LOG_NOTICE
, "<< %s (%X) -> %s (%X): vendor id feature abort", GetLogicalAddressName(), m_iLogicalAddress
, ToString(dest
), dest
);
800 m_processor
->TransmitAbort(dest
, CEC_OPCODE_GIVE_DEVICE_VENDOR_ID
);
806 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
);
807 return m_handler
->TransmitVendorID(m_iLogicalAddress
, iVendorId
);
811 bool CCECBusDevice::TransmitKeypress(cec_user_control_code key
, bool bWait
/* = true */)
813 return m_handler
->TransmitKeypress(m_processor
->GetLogicalAddress(), m_iLogicalAddress
, key
, bWait
);
816 bool CCECBusDevice::TransmitKeyRelease(bool bWait
/* = true */)
818 return m_handler
->TransmitKeyRelease(m_processor
->GetLogicalAddress(), m_iLogicalAddress
, bWait
);
821 bool CCECBusDevice::IsUnsupportedFeature(cec_opcode opcode
) const
823 return m_unsupportedFeatures
.find(opcode
) != m_unsupportedFeatures
.end();
826 void CCECBusDevice::SetUnsupportedFeature(cec_opcode opcode
)
828 m_unsupportedFeatures
.insert(opcode
);
831 bool CCECBusDevice::ActivateSource(void)
833 CLockObject
lock(m_mutex
);
834 return m_handler
->ActivateSource();