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/
34 #include "CECClient.h"
36 #include "CECProcessor.h"
38 #include "CECTypeUtils.h"
39 #include "devices/CECPlaybackDevice.h"
40 #include "devices/CECAudioSystem.h"
41 #include "devices/CECTV.h"
42 #include "implementations/CECCommandHandler.h"
45 using namespace PLATFORM
;
47 #define LIB_CEC m_processor->GetLib()
48 #define ToString(x) CCECTypeUtils::ToString(x)
50 #define COMBO_KEY CEC_USER_CONTROL_CODE_STOP
51 #define COMBO_TIMEOUT_MS 1000
53 CCECClient::CCECClient(CCECProcessor
*processor
, const libcec_configuration
&configuration
) :
54 m_processor(processor
),
55 m_bInitialised(false),
57 m_iCurrentButton(CEC_USER_CONTROL_CODE_UNKNOWN
),
59 m_iPreventForwardingPowerOffCommand(0)
61 m_configuration
.Clear();
62 // set the initial configuration
63 SetConfiguration(configuration
);
66 CCECClient::~CCECClient(void)
68 // unregister the client
69 if (m_processor
&& IsRegistered())
70 m_processor
->UnregisterClient(this);
73 bool CCECClient::IsInitialised(void)
75 CLockObject
lock(m_mutex
);
76 return m_bInitialised
&& m_processor
;
79 void CCECClient::SetInitialised(bool bSetTo
)
81 CLockObject
lock(m_mutex
);
82 m_bInitialised
= bSetTo
;
85 bool CCECClient::IsRegistered(void)
87 CLockObject
lock(m_mutex
);
88 return m_bRegistered
&& m_processor
;
91 void CCECClient::SetRegistered(bool bSetTo
)
93 CLockObject
lock(m_mutex
);
94 m_bRegistered
= bSetTo
;
97 bool CCECClient::OnRegister(void)
99 // return false if already initialised
103 // get all device we control
104 CECDEVICEVEC devices
;
105 m_processor
->GetDevices()->GetByLogicalAddresses(devices
, m_configuration
.logicalAddresses
);
107 // return false when no devices were found
110 LIB_CEC
->AddLog(CEC_LOG_WARNING
, "cannot find the primary device (logical address %x)", GetPrimaryLogicalAdddress());
114 // mark as initialised
115 SetInitialised(true);
117 // configure all devices
118 for (CECDEVICEVEC::iterator it
= devices
.begin(); it
!= devices
.end(); it
++)
120 // only set our OSD name for the primary device
121 if ((*it
)->GetLogicalAddress() == GetPrimaryLogicalAdddress())
122 (*it
)->SetOSDName(m_configuration
.strDeviceName
);
124 // set the default menu language for devices we control
125 (*it
)->SetMenuLanguage(m_configuration
.strDeviceLanguage
);
128 // set the physical address
129 SetPhysicalAddress(m_configuration
);
131 // make the primary device the active source if the option is set
132 if (m_configuration
.bActivateSource
== 1)
133 GetPrimaryDevice()->ActivateSource(500);
138 bool CCECClient::SetHDMIPort(const cec_logical_address iBaseDevice
, const uint8_t iPort
, bool bForce
/* = false */)
142 // limit the HDMI port range to 1-15
143 if (iPort
< CEC_MIN_HDMI_PORTNUMBER
||
144 iPort
> CEC_MAX_HDMI_PORTNUMBER
)
147 LIB_CEC
->AddLog(CEC_LOG_NOTICE
, "setting HDMI port to %d on device %s (%d)", iPort
, ToString(iBaseDevice
), (int)iBaseDevice
);
149 // update the configuration
151 CLockObject
lock(m_mutex
);
152 m_configuration
.baseDevice
= iBaseDevice
;
153 m_configuration
.iHDMIPort
= iPort
;
156 // don't continue if the connection isn't opened
157 if (!m_processor
->CECInitialised() && !bForce
)
160 // get the PA of the base device
161 uint16_t iPhysicalAddress(CEC_INVALID_PHYSICAL_ADDRESS
);
162 CCECBusDevice
*baseDevice
= m_processor
->GetDevice(iBaseDevice
);
164 iPhysicalAddress
= baseDevice
->GetPhysicalAddress(GetPrimaryLogicalAdddress());
166 // add our port number
167 if (iPhysicalAddress
<= CEC_MAX_PHYSICAL_ADDRESS
)
169 if (iPhysicalAddress
== 0)
170 iPhysicalAddress
+= 0x1000 * iPort
;
171 else if (iPhysicalAddress
% 0x1000 == 0)
172 iPhysicalAddress
+= 0x100 * iPort
;
173 else if (iPhysicalAddress
% 0x100 == 0)
174 iPhysicalAddress
+= 0x10 * iPort
;
175 else if (iPhysicalAddress
% 0x10 == 0)
176 iPhysicalAddress
+= iPort
;
181 // set the default address when something went wrong
184 LIB_CEC
->AddLog(CEC_LOG_WARNING
, "failed to set the physical address to %04X, setting it to the default value %04X", iPhysicalAddress
, CEC_DEFAULT_PHYSICAL_ADDRESS
);
185 iPhysicalAddress
= CEC_DEFAULT_PHYSICAL_ADDRESS
;
188 // and set the address
189 SetDevicePhysicalAddress(iPhysicalAddress
);
191 CallbackConfigurationChanged(m_configuration
);
196 void CCECClient::ResetPhysicalAddress(void)
198 SetPhysicalAddress(m_configuration
);
201 void CCECClient::SetPhysicalAddress(const libcec_configuration
&configuration
)
205 // override the physical address from configuration.iPhysicalAddress if it's set
206 if (!bPASet
&& CLibCEC::IsValidPhysicalAddress(configuration
.iPhysicalAddress
))
207 bPASet
= SetPhysicalAddress(configuration
.iPhysicalAddress
);
209 // try to autodetect the address
210 if (!bPASet
&& m_processor
->CECInitialised())
212 bPASet
= AutodetectPhysicalAddress();
213 m_configuration
.bAutodetectAddress
= bPASet
? 1 : 0;
216 // use the base device + hdmi port settings
218 bPASet
= SetHDMIPort(configuration
.baseDevice
, configuration
.iHDMIPort
);
220 // reset to defaults if something went wrong
223 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "%s - resetting HDMI port and base device to defaults", __FUNCTION__
);
224 m_configuration
.baseDevice
= CECDEVICE_UNKNOWN
;
225 m_configuration
.iHDMIPort
= CEC_HDMI_PORTNUMBER_NONE
;
229 bool CCECClient::SetPhysicalAddress(const uint16_t iPhysicalAddress
)
231 // update the configuration
234 CLockObject
lock(m_mutex
);
235 if (m_configuration
.iPhysicalAddress
== iPhysicalAddress
)
238 m_configuration
.iPhysicalAddress
= iPhysicalAddress
;
242 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "physical address unchanged (%04X)", iPhysicalAddress
);
246 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "setting physical address to '%04X'", iPhysicalAddress
);
248 // set the physical address for each device
249 SetDevicePhysicalAddress(iPhysicalAddress
);
251 // and send back the updated configuration
252 CallbackConfigurationChanged(m_configuration
);
257 void CCECClient::SetSupportedDeviceTypes(void)
259 cec_device_type_list types
;
262 // get the command handler for the tv
263 CCECCommandHandler
*tvHandler
= m_processor
->GetTV()->GetHandler();
267 // check all device types
268 for (uint8_t iPtr
= 0; iPtr
< 5; iPtr
++)
270 if (m_configuration
.deviceTypes
.types
[iPtr
] == CEC_DEVICE_TYPE_RESERVED
)
273 // get the supported device type. the handler will replace types it doesn't support by one it does support
274 cec_device_type type
= tvHandler
->GetReplacementDeviceType(m_configuration
.deviceTypes
.types
[iPtr
]);
275 if (!types
.IsSet(type
))
278 m_processor
->GetTV()->MarkHandlerReady();
280 // set the new type list
281 m_configuration
.deviceTypes
= types
;
283 // persist the new configuration
284 PersistConfiguration(m_configuration
);
287 bool CCECClient::AllocateLogicalAddresses(void)
289 // reset all previous LAs that were set
290 m_configuration
.logicalAddresses
.Clear();
292 // get the supported device types from the command handler of the TV
293 SetSupportedDeviceTypes();
295 // display an error if no device types are set
296 if (m_configuration
.deviceTypes
.IsEmpty())
298 LIB_CEC
->AddLog(CEC_LOG_ERROR
, "no device types given");
302 // check each entry of the list
303 for (uint8_t iPtr
= 0; iPtr
< 5; iPtr
++)
305 if (m_configuration
.deviceTypes
.types
[iPtr
] == CEC_DEVICE_TYPE_RESERVED
)
308 // find an LA for this type
309 cec_logical_address
address(CECDEVICE_UNKNOWN
);
310 if (m_configuration
.deviceTypes
.types
[iPtr
] == CEC_DEVICE_TYPE_RECORDING_DEVICE
)
311 address
= AllocateLogicalAddressRecordingDevice();
312 if (m_configuration
.deviceTypes
.types
[iPtr
] == CEC_DEVICE_TYPE_TUNER
)
313 address
= AllocateLogicalAddressTuner();
314 if (m_configuration
.deviceTypes
.types
[iPtr
] == CEC_DEVICE_TYPE_PLAYBACK_DEVICE
)
315 address
= AllocateLogicalAddressPlaybackDevice();
316 if (m_configuration
.deviceTypes
.types
[iPtr
] == CEC_DEVICE_TYPE_AUDIO_SYSTEM
)
317 address
= AllocateLogicalAddressAudioSystem();
319 // display an error if no LA could be allocated
320 if (address
== CECDEVICE_UNKNOWN
)
322 LIB_CEC
->AddLog(CEC_LOG_ERROR
, "%s - failed to allocate device '%d', type '%s'", __FUNCTION__
, iPtr
, ToString(m_configuration
.deviceTypes
.types
[iPtr
]));
326 // display the registered LA
327 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "%s - device '%d', type '%s', LA '%X'", __FUNCTION__
, iPtr
, ToString(m_configuration
.deviceTypes
.types
[iPtr
]), address
);
328 m_configuration
.logicalAddresses
.Set(address
);
331 // persist the new configuration
332 PersistConfiguration(m_configuration
);
337 cec_logical_address
CCECClient::AllocateLogicalAddressRecordingDevice(void)
339 cec_logical_address
retVal(CECDEVICE_UNKNOWN
);
341 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "detecting logical address for type 'recording device'");
342 if (m_processor
->TryLogicalAddress(CECDEVICE_RECORDINGDEVICE1
, m_configuration
.cecVersion
))
343 retVal
= CECDEVICE_RECORDINGDEVICE1
;
344 else if (m_processor
->TryLogicalAddress(CECDEVICE_RECORDINGDEVICE2
, m_configuration
.cecVersion
))
345 retVal
= CECDEVICE_RECORDINGDEVICE2
;
346 else if (m_processor
->TryLogicalAddress(CECDEVICE_RECORDINGDEVICE3
, m_configuration
.cecVersion
))
347 retVal
= CECDEVICE_RECORDINGDEVICE3
;
352 cec_logical_address
CCECClient::AllocateLogicalAddressTuner(void)
354 cec_logical_address
retVal(CECDEVICE_UNKNOWN
);
356 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "detecting logical address for type 'tuner'");
357 if (m_processor
->TryLogicalAddress(CECDEVICE_TUNER1
, m_configuration
.cecVersion
))
358 retVal
= CECDEVICE_TUNER1
;
359 else if (m_processor
->TryLogicalAddress(CECDEVICE_TUNER2
, m_configuration
.cecVersion
))
360 retVal
= CECDEVICE_TUNER2
;
361 else if (m_processor
->TryLogicalAddress(CECDEVICE_TUNER3
, m_configuration
.cecVersion
))
362 retVal
= CECDEVICE_TUNER3
;
363 else if (m_processor
->TryLogicalAddress(CECDEVICE_TUNER4
, m_configuration
.cecVersion
))
364 retVal
= CECDEVICE_TUNER4
;
369 cec_logical_address
CCECClient::AllocateLogicalAddressPlaybackDevice(void)
371 cec_logical_address
retVal(CECDEVICE_UNKNOWN
);
373 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "detecting logical address for type 'playback device'");
374 if (m_processor
->TryLogicalAddress(CECDEVICE_PLAYBACKDEVICE1
, m_configuration
.cecVersion
))
375 retVal
= CECDEVICE_PLAYBACKDEVICE1
;
376 else if (m_processor
->TryLogicalAddress(CECDEVICE_PLAYBACKDEVICE2
, m_configuration
.cecVersion
))
377 retVal
= CECDEVICE_PLAYBACKDEVICE2
;
378 else if (m_processor
->TryLogicalAddress(CECDEVICE_PLAYBACKDEVICE3
, m_configuration
.cecVersion
))
379 retVal
= CECDEVICE_PLAYBACKDEVICE3
;
384 cec_logical_address
CCECClient::AllocateLogicalAddressAudioSystem(void)
386 cec_logical_address
retVal(CECDEVICE_UNKNOWN
);
388 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "detecting logical address for type 'audiosystem'");
389 if (m_processor
->TryLogicalAddress(CECDEVICE_AUDIOSYSTEM
, m_configuration
.cecVersion
))
390 retVal
= CECDEVICE_AUDIOSYSTEM
;
395 CCECBusDevice
*CCECClient::GetDeviceByType(const cec_device_type type
) const
397 // get all devices that match our logical addresses
398 CECDEVICEVEC devices
;
399 m_processor
->GetDevices()->GetByLogicalAddresses(devices
, m_configuration
.logicalAddresses
);
401 // filter the type we need
402 CCECDeviceMap::FilterType(type
, devices
);
404 return devices
.empty() ?
409 bool CCECClient::ChangeDeviceType(const cec_device_type from
, const cec_device_type to
)
414 LIB_CEC
->AddLog(CEC_LOG_NOTICE
, "changing device type '%s' into '%s'", ToString(from
), ToString(to
));
417 CLockObject
lock(m_mutex
);
419 // get the previous device that was allocated
420 CCECBusDevice
*previousDevice
= GetDeviceByType(from
);
424 // change the type in the device type list
425 bool bChanged(false);
426 for (uint8_t iPtr
= 0; iPtr
< 5; iPtr
++)
428 if (m_configuration
.deviceTypes
.types
[iPtr
] == CEC_DEVICE_TYPE_RESERVED
)
431 if (m_configuration
.deviceTypes
.types
[iPtr
] == from
)
434 m_configuration
.deviceTypes
.types
[iPtr
] = to
;
436 else if (m_configuration
.deviceTypes
.types
[iPtr
] == to
&& bChanged
)
438 // ensure that dupes are removed
439 m_configuration
.deviceTypes
.types
[iPtr
] = CEC_DEVICE_TYPE_RESERVED
;
444 // re-register the client to set the new ackmask
445 if (!m_processor
->RegisterClient(this))
448 // persist the new configuration
449 PersistConfiguration(m_configuration
);
454 bool CCECClient::SetLogicalAddress(const cec_logical_address iLogicalAddress
)
458 if (GetPrimaryLogicalAdddress() != iLogicalAddress
)
460 LIB_CEC
->AddLog(CEC_LOG_NOTICE
, "<< setting primary logical address to %1x", iLogicalAddress
);
462 CLockObject
lock(m_mutex
);
463 m_configuration
.logicalAddresses
.primary
= iLogicalAddress
;
464 m_configuration
.logicalAddresses
.Set(iLogicalAddress
);
467 bReturn
= m_processor
->RegisterClient(this);
469 // persist the new configuration
471 PersistConfiguration(m_configuration
);
477 bool CCECClient::Transmit(const cec_command
&data
, bool bIsReply
)
479 return m_processor
? m_processor
->Transmit(data
, bIsReply
) : false;
482 bool CCECClient::SendPowerOnDevices(const cec_logical_address address
/* = CECDEVICE_TV */)
484 // if the broadcast address if set as destination and the client version >=1.5.0, read the wakeDevices setting
485 if (address
== CECDEVICE_BROADCAST
&& m_configuration
.clientVersion
>= CEC_CLIENT_VERSION_1_5_0
)
487 CECDEVICEVEC devices
;
488 m_processor
->GetDevices()->GetWakeDevices(m_configuration
, devices
);
489 return m_processor
->PowerOnDevices(GetPrimaryLogicalAdddress(), devices
);
492 return m_processor
->PowerOnDevice(GetPrimaryLogicalAdddress(), address
);
495 bool CCECClient::SendStandbyDevices(const cec_logical_address address
/* = CECDEVICE_BROADCAST */)
497 // if the broadcast address if set as destination and the client version >=1.5.0, read the standbyDevices setting
498 if (address
== CECDEVICE_BROADCAST
&& m_configuration
.clientVersion
>= CEC_CLIENT_VERSION_1_5_0
)
500 CECDEVICEVEC devices
;
501 m_processor
->GetDevices()->GetPowerOffDevices(m_configuration
, devices
);
502 return m_processor
->StandbyDevices(GetPrimaryLogicalAdddress(), devices
);
505 return m_processor
->StandbyDevice(GetPrimaryLogicalAdddress(), address
);
508 bool CCECClient::SendSetActiveSource(const cec_device_type type
/* = CEC_DEVICE_TYPE_RESERVED */)
510 // get the devices that are controlled by us
511 CECDEVICEVEC devices
;
512 m_processor
->GetDevices()->GetByLogicalAddresses(devices
, m_configuration
.logicalAddresses
);
514 // filter out the device that matches the given type
515 if (type
!= CEC_DEVICE_TYPE_RESERVED
)
516 CCECDeviceMap::FilterType(type
, devices
);
518 // no devices left, re-fetch the list of devices that are controlled by us
520 m_processor
->GetDevices()->GetByLogicalAddresses(devices
, m_configuration
.logicalAddresses
);
522 if (!devices
.empty())
524 // get the first device from the list
525 CCECBusDevice
*device
= *devices
.begin();
528 if (!m_processor
->CECInitialised())
529 device
->MarkAsActiveSource();
530 else if (device
->HasValidPhysicalAddress())
531 return device
->ActivateSource();
537 CCECPlaybackDevice
*CCECClient::GetPlaybackDevice(void)
539 CCECPlaybackDevice
*device(NULL
);
540 CECDEVICEVEC devices
;
542 // get the playback devices
543 m_processor
->GetDevices()->GetByLogicalAddresses(devices
, m_configuration
.logicalAddresses
);
544 CCECDeviceMap::FilterType(CEC_DEVICE_TYPE_PLAYBACK_DEVICE
, devices
);
546 // no matches, get the recording devices
549 m_processor
->GetDevices()->GetByLogicalAddresses(devices
, m_configuration
.logicalAddresses
);
550 CCECDeviceMap::FilterType(CEC_DEVICE_TYPE_RECORDING_DEVICE
, devices
);
553 // get the first device that matches, and cast it to CCECPlaybackDevice
554 if (!devices
.empty())
555 device
= (*devices
.begin())->AsPlaybackDevice();
560 cec_logical_address
CCECClient::GetPrimaryLogicalAdddress(void)
562 CLockObject
lock(m_mutex
);
563 return m_configuration
.logicalAddresses
.primary
;
566 CCECBusDevice
*CCECClient::GetPrimaryDevice(void)
568 return m_processor
->GetDevice(GetPrimaryLogicalAdddress());
571 bool CCECClient::SendSetDeckControlMode(const cec_deck_control_mode mode
, bool bSendUpdate
/* = true */)
573 // find a playback device that we control
574 CCECPlaybackDevice
*device
= GetPlaybackDevice();
577 // and set the deck control mode if there is a match
578 device
->SetDeckControlMode(mode
);
580 return device
->TransmitDeckStatus(CECDEVICE_TV
, false);
588 bool CCECClient::SendSetDeckInfo(const cec_deck_info info
, bool bSendUpdate
/* = true */)
590 // find a playback device that we control
591 CCECPlaybackDevice
*device
= GetPlaybackDevice();
594 // and set the deck status if there is a match
595 device
->SetDeckStatus(info
);
597 return device
->AsPlaybackDevice()->TransmitDeckStatus(CECDEVICE_TV
, false);
605 bool CCECClient::SendSetMenuState(const cec_menu_state state
, bool bSendUpdate
/* = true */)
607 CECDEVICEVEC devices
;
609 // set the menu state for all devices that are controlled by us
610 m_processor
->GetDevices()->GetByLogicalAddresses(devices
, m_configuration
.logicalAddresses
);
611 for (CECDEVICEVEC::iterator it
= devices
.begin(); it
!= devices
.end(); it
++)
613 (*it
)->SetMenuState(state
);
615 (*it
)->TransmitMenuState(CECDEVICE_TV
, false);
621 bool CCECClient::SendSetInactiveView(void)
623 CECDEVICEVEC devices
;
625 // mark all devices that are controlled by us as inactive source
626 m_processor
->GetDevices()->GetByLogicalAddresses(devices
, m_configuration
.logicalAddresses
);
627 for (CECDEVICEVEC::iterator it
= devices
.begin(); it
!= devices
.end(); it
++)
629 if ((*it
)->IsActiveSource())
631 (*it
)->MarkAsInactiveSource();
632 return (*it
)->TransmitInactiveSource();
639 bool CCECClient::SendSetOSDString(const cec_logical_address iLogicalAddress
, const cec_display_control duration
, const char *strMessage
)
641 CCECBusDevice
*primary
= GetPrimaryDevice();
643 return primary
->TransmitOSDString(iLogicalAddress
, duration
, strMessage
, false);
648 cec_version
CCECClient::GetDeviceCecVersion(const cec_logical_address iAddress
)
650 CCECBusDevice
*device
= m_processor
->GetDevice(iAddress
);
652 return device
->GetCecVersion(GetPrimaryLogicalAdddress());
653 return CEC_VERSION_UNKNOWN
;
656 bool CCECClient::GetDeviceMenuLanguage(const cec_logical_address iAddress
, cec_menu_language
&language
)
658 CCECBusDevice
*device
= m_processor
->GetDevice(iAddress
);
661 language
= device
->GetMenuLanguage(GetPrimaryLogicalAdddress());
662 return (strcmp(language
.language
, "???") != 0);
667 cec_osd_name
CCECClient::GetDeviceOSDName(const cec_logical_address iAddress
)
670 retVal
.device
= iAddress
;
673 CCECBusDevice
*device
= m_processor
->GetDevice(iAddress
);
676 CStdString strOSDName
= device
->GetOSDName(GetPrimaryLogicalAdddress());
677 snprintf(retVal
.name
, sizeof(retVal
.name
), "%s", strOSDName
.c_str());
678 retVal
.device
= iAddress
;
684 uint16_t CCECClient::GetDevicePhysicalAddress(const cec_logical_address iAddress
)
686 CCECBusDevice
*device
= m_processor
->GetDevice(iAddress
);
688 return device
->GetPhysicalAddress(GetPrimaryLogicalAdddress());
689 return CEC_INVALID_PHYSICAL_ADDRESS
;
692 cec_power_status
CCECClient::GetDevicePowerStatus(const cec_logical_address iAddress
)
694 CCECBusDevice
*device
= m_processor
->GetDevice(iAddress
);
696 return device
->GetPowerStatus(GetPrimaryLogicalAdddress());
697 return CEC_POWER_STATUS_UNKNOWN
;
700 uint64_t CCECClient::GetDeviceVendorId(const cec_logical_address iAddress
)
702 CCECBusDevice
*device
= m_processor
->GetDevice(iAddress
);
704 return device
->GetVendorId(GetPrimaryLogicalAdddress());
705 return CEC_VENDOR_UNKNOWN
;
708 uint8_t CCECClient::SendVolumeUp(bool bSendRelease
/* = true */)
710 CCECBusDevice
*device
= GetPrimaryDevice();
711 CCECAudioSystem
*audio
= m_processor
->GetAudioSystem();
713 return device
&& audio
&& audio
->IsPresent() ?
714 audio
->VolumeUp(device
->GetLogicalAddress(), bSendRelease
) :
715 (uint8_t)CEC_AUDIO_VOLUME_STATUS_UNKNOWN
;
718 uint8_t CCECClient::SendVolumeDown(bool bSendRelease
/* = true */)
720 CCECBusDevice
*device
= GetPrimaryDevice();
721 CCECAudioSystem
*audio
= m_processor
->GetAudioSystem();
723 return device
&& audio
&& audio
->IsPresent() ?
724 audio
->VolumeDown(device
->GetLogicalAddress(), bSendRelease
) :
725 (uint8_t)CEC_AUDIO_VOLUME_STATUS_UNKNOWN
;
728 uint8_t CCECClient::SendMuteAudio(void)
730 CCECBusDevice
*device
= GetPrimaryDevice();
731 CCECAudioSystem
*audio
= m_processor
->GetAudioSystem();
733 return device
&& audio
&& audio
->IsPresent() ?
734 audio
->MuteAudio(device
->GetLogicalAddress()) :
735 (uint8_t)CEC_AUDIO_VOLUME_STATUS_UNKNOWN
;
738 bool CCECClient::SendKeypress(const cec_logical_address iDestination
, const cec_user_control_code key
, bool bWait
/* = true */)
740 CCECBusDevice
*dest
= m_processor
->GetDevice(iDestination
);
743 dest
->TransmitKeypress(GetPrimaryLogicalAdddress(), key
, bWait
) :
747 bool CCECClient::SendKeyRelease(const cec_logical_address iDestination
, bool bWait
/* = true */)
749 CCECBusDevice
*dest
= m_processor
->GetDevice(iDestination
);
752 dest
->TransmitKeyRelease(GetPrimaryLogicalAdddress(), bWait
) :
756 bool CCECClient::GetCurrentConfiguration(libcec_configuration
&configuration
)
758 CLockObject
lock(m_mutex
);
760 // client version 1.5.0
761 snprintf(configuration
.strDeviceName
, 13, "%s", m_configuration
.strDeviceName
);
762 configuration
.deviceTypes
= m_configuration
.deviceTypes
;
763 configuration
.bAutodetectAddress
= m_configuration
.bAutodetectAddress
;
764 configuration
.iPhysicalAddress
= m_configuration
.iPhysicalAddress
;
765 configuration
.baseDevice
= m_configuration
.baseDevice
;
766 configuration
.iHDMIPort
= m_configuration
.iHDMIPort
;
767 configuration
.clientVersion
= m_configuration
.clientVersion
;
768 configuration
.serverVersion
= m_configuration
.serverVersion
;
769 configuration
.tvVendor
= m_configuration
.tvVendor
;
771 configuration
.bGetSettingsFromROM
= m_configuration
.bGetSettingsFromROM
;
772 configuration
.bUseTVMenuLanguage
= m_configuration
.bUseTVMenuLanguage
;
773 configuration
.bActivateSource
= m_configuration
.bActivateSource
;
774 configuration
.wakeDevices
= m_configuration
.wakeDevices
;
775 configuration
.powerOffDevices
= m_configuration
.powerOffDevices
;
776 configuration
.bPowerOffScreensaver
= m_configuration
.bPowerOffScreensaver
;
777 configuration
.bPowerOffOnStandby
= m_configuration
.bPowerOffOnStandby
;
779 // client version 1.5.1
780 if (configuration
.clientVersion
>= CEC_CLIENT_VERSION_1_5_1
)
781 configuration
.bSendInactiveSource
= m_configuration
.bSendInactiveSource
;
783 // client version 1.5.3
784 if (configuration
.clientVersion
>= CEC_CLIENT_VERSION_1_5_3
)
785 configuration
.logicalAddresses
= m_configuration
.logicalAddresses
;
787 // client version 1.6.0
788 if (configuration
.clientVersion
>= CEC_CLIENT_VERSION_1_6_0
)
790 configuration
.iFirmwareVersion
= m_configuration
.iFirmwareVersion
;
791 configuration
.bPowerOffDevicesOnStandby
= m_configuration
.bPowerOffDevicesOnStandby
;
792 configuration
.bShutdownOnStandby
= m_configuration
.bShutdownOnStandby
;
795 // client version 1.6.2
796 if (configuration
.clientVersion
>= CEC_CLIENT_VERSION_1_6_2
)
798 memcpy(configuration
.strDeviceLanguage
, m_configuration
.strDeviceLanguage
, 3);
799 configuration
.iFirmwareBuildDate
= m_configuration
.iFirmwareBuildDate
;
802 // client version 1.6.3
803 if (configuration
.clientVersion
>= CEC_CLIENT_VERSION_1_6_3
)
805 configuration
.bMonitorOnly
= m_configuration
.bMonitorOnly
;
808 // client version 1.8.0
809 if (configuration
.clientVersion
>= CEC_CLIENT_VERSION_1_8_0
)
810 configuration
.cecVersion
= m_configuration
.cecVersion
;
812 // client version 1.8.2
813 if (configuration
.clientVersion
>= CEC_CLIENT_VERSION_1_8_2
)
814 configuration
.adapterType
= m_configuration
.adapterType
;
819 bool CCECClient::SetConfiguration(const libcec_configuration
&configuration
)
821 bool bIsRunning(m_processor
&& m_processor
->CECInitialised());
822 CCECBusDevice
*primary
= bIsRunning
? GetPrimaryDevice() : NULL
;
823 uint16_t iPA
= primary
? primary
->GetCurrentPhysicalAddress() : CEC_INVALID_PHYSICAL_ADDRESS
;
825 // update the callbacks
826 if (configuration
.callbacks
)
827 EnableCallbacks(configuration
.callbackParam
, configuration
.callbacks
);
829 // update the client version
830 SetClientVersion((cec_client_version
)configuration
.clientVersion
);
832 // update the OSD name
833 CStdString
strOSDName(configuration
.strDeviceName
);
834 SetOSDName(strOSDName
);
836 // update the TV vendor override
837 SetTVVendorOverride((cec_vendor_id
)configuration
.tvVendor
);
841 CLockObject
lock(m_mutex
);
842 m_configuration
.bUseTVMenuLanguage
= configuration
.bUseTVMenuLanguage
;
843 m_configuration
.bActivateSource
= configuration
.bActivateSource
;
844 m_configuration
.bGetSettingsFromROM
= configuration
.bGetSettingsFromROM
;
845 m_configuration
.wakeDevices
= configuration
.wakeDevices
;
846 m_configuration
.powerOffDevices
= configuration
.powerOffDevices
;
847 m_configuration
.bPowerOffScreensaver
= configuration
.bPowerOffScreensaver
;
848 m_configuration
.bPowerOffOnStandby
= configuration
.bPowerOffOnStandby
;
850 // client version 1.5.1
851 if (configuration
.clientVersion
>= CEC_CLIENT_VERSION_1_5_1
)
852 m_configuration
.bSendInactiveSource
= configuration
.bSendInactiveSource
;
854 // client version 1.6.0
855 if (configuration
.clientVersion
>= CEC_CLIENT_VERSION_1_6_0
)
857 m_configuration
.bPowerOffDevicesOnStandby
= configuration
.bPowerOffDevicesOnStandby
;
858 m_configuration
.bShutdownOnStandby
= configuration
.bShutdownOnStandby
;
861 // client version 1.6.2
862 if (configuration
.clientVersion
>= CEC_CLIENT_VERSION_1_6_2
)
864 memcpy(m_configuration
.strDeviceLanguage
, configuration
.strDeviceLanguage
, 3);
867 // client version 1.6.3
868 if (configuration
.clientVersion
>= CEC_CLIENT_VERSION_1_6_3
)
870 m_configuration
.bMonitorOnly
= configuration
.bMonitorOnly
;
873 // client version 1.8.0
874 if (configuration
.clientVersion
>= CEC_CLIENT_VERSION_1_8_0
)
875 m_configuration
.cecVersion
= configuration
.cecVersion
;
877 // client version 1.8.2
878 if (configuration
.clientVersion
>= CEC_CLIENT_VERSION_1_8_2
)
879 m_configuration
.adapterType
= configuration
.adapterType
;
881 // ensure that there is at least 1 device type set
882 if (m_configuration
.deviceTypes
.IsEmpty())
883 m_configuration
.deviceTypes
.Add(CEC_DEVICE_TYPE_RECORDING_DEVICE
);
886 bool bNeedReinit(false);
889 if (SetDeviceTypes(configuration
.deviceTypes
))
891 // the device type changed. just copy the rest, and re-register
893 CLockObject
lock(m_mutex
);
894 m_configuration
.iPhysicalAddress
= configuration
.iPhysicalAddress
;
895 m_configuration
.baseDevice
= configuration
.baseDevice
;
896 m_configuration
.iHDMIPort
= configuration
.iHDMIPort
;
902 // set the physical address
903 SetPhysicalAddress(configuration
);
906 // persist the new configuration
907 PersistConfiguration(m_configuration
);
910 primary
= GetPrimaryDevice();
912 if (bNeedReinit
|| !primary
|| primary
->GetCurrentPhysicalAddress() != iPA
)
914 // PA or device type changed
915 m_processor
->RegisterClient(this);
917 else if (primary
&& configuration
.bActivateSource
== 1 && bIsRunning
&& !primary
->IsActiveSource())
919 // activate the source if we're not already the active source
920 primary
->ActivateSource();
926 void CCECClient::AddCommand(const cec_command
&command
)
928 // don't forward the standby opcode more than once every 10 seconds
929 if (command
.opcode
== CEC_OPCODE_STANDBY
)
931 CLockObject
lock(m_mutex
);
932 if (m_iPreventForwardingPowerOffCommand
!= 0 &&
933 m_iPreventForwardingPowerOffCommand
> GetTimeMs())
936 m_iPreventForwardingPowerOffCommand
= GetTimeMs() + CEC_FORWARD_STANDBY_MIN_INTERVAL
;
939 if (command
.destination
== CECDEVICE_BROADCAST
|| GetLogicalAddresses().IsSet(command
.destination
))
941 LIB_CEC
->AddLog(CEC_LOG_NOTICE
, ">> %s (%X) -> %s (%X): %s (%2X)", ToString(command
.initiator
), command
.initiator
, ToString(command
.destination
), command
.destination
, ToString(command
.opcode
), command
.opcode
);
942 CallbackAddCommand(command
);
946 int CCECClient::MenuStateChanged(const cec_menu_state newState
)
948 LIB_CEC
->AddLog(CEC_LOG_NOTICE
, ">> %s: %s", ToString(CEC_OPCODE_MENU_REQUEST
), ToString(newState
));
949 return CallbackMenuStateChanged(newState
);
952 void CCECClient::AddKey(bool bSendComboKey
/* = false */)
955 key
.keycode
= CEC_USER_CONTROL_CODE_UNKNOWN
;
958 CLockObject
lock(m_mutex
);
959 if (m_iCurrentButton
!= CEC_USER_CONTROL_CODE_UNKNOWN
)
961 key
.duration
= (unsigned int) (GetTimeMs() - m_buttontime
);
963 if (key
.duration
> COMBO_TIMEOUT_MS
|| m_iCurrentButton
!= COMBO_KEY
|| bSendComboKey
)
965 key
.keycode
= m_iCurrentButton
;
967 m_iCurrentButton
= CEC_USER_CONTROL_CODE_UNKNOWN
;
973 if (key
.keycode
!= CEC_USER_CONTROL_CODE_UNKNOWN
)
975 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "key released: %s (%1x)", ToString(key
.keycode
), key
.keycode
);
980 void CCECClient::AddKey(const cec_keypress
&key
)
982 // send back the previous key if there is one
985 cec_keypress
transmitKey(key
);
988 CLockObject
lock(m_mutex
);
989 if (key
.duration
> 0 || key
.keycode
> CEC_USER_CONTROL_CODE_MAX
)
991 transmitKey
.keycode
= CEC_USER_CONTROL_CODE_UNKNOWN
;
993 else if (m_iCurrentButton
== COMBO_KEY
)
996 if (key
.keycode
== CEC_USER_CONTROL_CODE_SELECT
)
997 transmitKey
.keycode
= CEC_USER_CONTROL_CODE_EXIT
;
998 // stop + pause -> root menu
999 else if (key
.keycode
== CEC_USER_CONTROL_CODE_ROOT_MENU
)
1000 transmitKey
.keycode
= CEC_USER_CONTROL_CODE_ROOT_MENU
;
1001 // stop + play -> dot (which is handled as context menu in xbmc)
1002 else if (key
.keycode
== CEC_USER_CONTROL_CODE_PLAY
)
1003 transmitKey
.keycode
= CEC_USER_CONTROL_CODE_DOT
;
1004 // default, send back the previous key
1009 m_iCurrentButton
= transmitKey
.keycode
;
1010 m_buttontime
= m_iCurrentButton
== CEC_USER_CONTROL_CODE_UNKNOWN
|| key
.duration
> 0 ? 0 : GetTimeMs();
1013 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "key pressed: %s (%1x)", ToString(transmitKey
.keycode
), transmitKey
.keycode
);
1014 CallbackAddKey(transmitKey
);
1017 void CCECClient::SetCurrentButton(const cec_user_control_code iButtonCode
)
1019 // push a keypress to the buffer with 0 duration and another with the duration set when released
1022 key
.keycode
= iButtonCode
;
1027 void CCECClient::CheckKeypressTimeout(void)
1032 CLockObject
lock(m_mutex
);
1033 uint64_t iNow
= GetTimeMs();
1035 if (m_iCurrentButton
!= CEC_USER_CONTROL_CODE_UNKNOWN
&&
1036 ((m_iCurrentButton
== COMBO_KEY
&& iNow
- m_buttontime
> COMBO_TIMEOUT_MS
) ||
1037 (m_iCurrentButton
!= COMBO_KEY
&& iNow
- m_buttontime
> CEC_BUTTON_TIMEOUT
)))
1039 key
.duration
= (unsigned int) (iNow
- m_buttontime
);
1040 key
.keycode
= m_iCurrentButton
;
1042 m_iCurrentButton
= CEC_USER_CONTROL_CODE_UNKNOWN
;
1051 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "key auto-released: %s (%1x)", ToString(key
.keycode
), key
.keycode
);
1052 CallbackAddKey(key
);
1055 bool CCECClient::EnableCallbacks(void *cbParam
, ICECCallbacks
*callbacks
)
1057 CLockObject
lock(m_cbMutex
);
1058 m_configuration
.callbackParam
= cbParam
;
1059 m_configuration
.callbacks
= callbacks
;
1063 bool CCECClient::PingAdapter(void)
1065 return m_processor
? m_processor
->PingAdapter() : false;
1068 bool CCECClient::GetNextLogMessage(cec_log_message
*message
)
1070 return (m_logBuffer
.Pop(*message
));
1073 bool CCECClient::GetNextKeypress(cec_keypress
*key
)
1075 return m_keyBuffer
.Pop(*key
);
1078 bool CCECClient::GetNextCommand(cec_command
*command
)
1080 return m_commandBuffer
.Pop(*command
);
1083 std::string
CCECClient::GetConnectionInfo(void)
1086 strLog
.Format("libCEC version = %s, client version = %s, firmware version = %d", ToString((cec_server_version
)m_configuration
.serverVersion
), ToString((cec_client_version
)m_configuration
.clientVersion
), m_configuration
.iFirmwareVersion
);
1087 if (m_configuration
.iFirmwareBuildDate
!= CEC_FW_BUILD_UNKNOWN
)
1089 time_t buildTime
= (time_t)m_configuration
.iFirmwareBuildDate
;
1090 strLog
.AppendFormat(", firmware build date: %s", asctime(gmtime(&buildTime
)));
1091 strLog
= strLog
.Left((int)strLog
.length() - 1); // strip \n added by asctime
1092 strLog
.append(" +0000");
1095 // log the addresses that are being used
1096 if (!m_configuration
.logicalAddresses
.IsEmpty())
1098 strLog
.append(", logical address(es) = ");
1099 CECDEVICEVEC devices
;
1100 m_processor
->GetDevices()->GetByLogicalAddresses(devices
, m_configuration
.logicalAddresses
);
1101 for (CECDEVICEVEC::iterator it
= devices
.begin(); it
!= devices
.end(); it
++)
1102 strLog
.AppendFormat("%s (%X) ", (*it
)->GetLogicalAddressName(), (*it
)->GetLogicalAddress());
1105 if (!CLibCEC::IsValidPhysicalAddress(m_configuration
.iPhysicalAddress
))
1106 strLog
.AppendFormat(", base device: %s (%X), HDMI port number: %d", ToString(m_configuration
.baseDevice
), m_configuration
.baseDevice
, m_configuration
.iHDMIPort
);
1108 strLog
.AppendFormat(", physical address: %04x", m_configuration
.iPhysicalAddress
);
1110 strLog
.AppendFormat(", %s", LIB_CEC
->GetLibInfo());
1112 std::string
strReturn(strLog
.c_str());
1116 void CCECClient::SetTVVendorOverride(const cec_vendor_id id
)
1119 CLockObject
lock(m_mutex
);
1120 m_configuration
.tvVendor
= id
;
1123 if (id
!= CEC_VENDOR_UNKNOWN
)
1125 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "%s - vendor id '%s'", __FUNCTION__
, ToString(id
));
1127 CCECBusDevice
*tv
= m_processor
? m_processor
->GetTV() : NULL
;
1129 tv
->SetVendorId((uint64_t)id
);
1132 // persist the new configuration
1133 PersistConfiguration(m_configuration
);
1136 cec_vendor_id
CCECClient::GetTVVendorOverride(void)
1138 CLockObject
lock(m_mutex
);
1139 return (cec_vendor_id
)m_configuration
.tvVendor
;
1142 void CCECClient::SetOSDName(const std::string
&strDeviceName
)
1145 CLockObject
lock(m_mutex
);
1146 snprintf(m_configuration
.strDeviceName
, 13, "%s", strDeviceName
.c_str());
1149 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "%s - using OSD name '%s'", __FUNCTION__
, strDeviceName
.c_str());
1151 CCECBusDevice
*primary
= GetPrimaryDevice();
1152 if (primary
&& !primary
->GetCurrentOSDName().Equals(strDeviceName
.c_str()))
1154 primary
->SetOSDName(strDeviceName
);
1155 if (m_processor
&& m_processor
->CECInitialised())
1156 primary
->TransmitOSDName(CECDEVICE_TV
, false);
1159 // persist the new configuration
1160 PersistConfiguration(m_configuration
);
1163 std::string
CCECClient::GetOSDName(void)
1165 CLockObject
lock(m_mutex
);
1166 std::string
strOSDName(m_configuration
.strDeviceName
);
1170 void CCECClient::SetWakeDevices(const cec_logical_addresses
&addresses
)
1173 CLockObject
lock(m_mutex
);
1174 m_configuration
.wakeDevices
= addresses
;
1176 // persist the new configuration
1177 PersistConfiguration(m_configuration
);
1180 cec_logical_addresses
CCECClient::GetWakeDevices(void)
1182 CLockObject
lock(m_mutex
);
1183 return m_configuration
.wakeDevices
;
1186 bool CCECClient::AutodetectPhysicalAddress(void)
1188 bool bPhysicalAutodetected(false);
1189 uint16_t iPhysicalAddress
= m_processor
? m_processor
->GetDetectedPhysicalAddress() : CEC_INVALID_PHYSICAL_ADDRESS
;
1191 if (CLibCEC::IsValidPhysicalAddress(iPhysicalAddress
))
1193 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "%s - autodetected physical address '%04X'", __FUNCTION__
, iPhysicalAddress
);
1195 CLockObject
lock(m_mutex
);
1196 m_configuration
.iPhysicalAddress
= iPhysicalAddress
;
1197 m_configuration
.iHDMIPort
= CEC_HDMI_PORTNUMBER_NONE
;
1198 m_configuration
.baseDevice
= CECDEVICE_UNKNOWN
;
1199 bPhysicalAutodetected
= true;
1202 SetDevicePhysicalAddress(iPhysicalAddress
);
1204 return bPhysicalAutodetected
;
1207 void CCECClient::SetClientVersion(const cec_client_version version
)
1209 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "%s - using client version '%s'", __FUNCTION__
, ToString(version
));
1211 CLockObject
lock(m_mutex
);
1212 m_configuration
.clientVersion
= (uint32_t)version
;
1215 cec_client_version
CCECClient::GetClientVersion(void)
1217 CLockObject
lock(m_mutex
);
1218 return (cec_client_version
)m_configuration
.clientVersion
;
1221 bool CCECClient::SetDeviceTypes(const cec_device_type_list
&deviceTypes
)
1223 bool bNeedReinit(false);
1226 CLockObject
lock(m_mutex
);
1227 bNeedReinit
= m_processor
&& m_processor
->CECInitialised() &&
1228 (m_configuration
.deviceTypes
!= deviceTypes
);
1229 m_configuration
.deviceTypes
= deviceTypes
;
1232 // persist the new configuration
1233 PersistConfiguration(m_configuration
);
1236 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "%s - using primary device type '%s'", __FUNCTION__
, ToString(deviceTypes
[0]));
1241 cec_device_type_list
CCECClient::GetDeviceTypes(void)
1243 cec_device_type_list retVal
;
1244 CLockObject
lock(m_mutex
);
1245 retVal
= m_configuration
.deviceTypes
;
1249 bool CCECClient::SetDevicePhysicalAddress(const uint16_t iPhysicalAddress
)
1251 if (!CLibCEC::IsValidPhysicalAddress(iPhysicalAddress
))
1253 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "%s - not setting invalid physical address %04x", __FUNCTION__
, iPhysicalAddress
);
1257 // reconfigure all devices
1258 cec_logical_address
reactivateSource(CECDEVICE_UNKNOWN
);
1259 CECDEVICEVEC devices
;
1260 m_processor
->GetDevices()->GetByLogicalAddresses(devices
, m_configuration
.logicalAddresses
);
1261 for (CECDEVICEVEC::iterator it
= devices
.begin(); it
!= devices
.end(); it
++)
1263 // if this device was the active source, reactivate it afterwards
1264 if ((*it
)->IsActiveSource())
1265 reactivateSource
= (*it
)->GetLogicalAddress();
1267 // mark the device as inactive source
1268 if (IsInitialised())
1269 (*it
)->MarkAsInactiveSource();
1271 // set the new physical address
1272 (*it
)->SetPhysicalAddress(iPhysicalAddress
);
1275 if (IsInitialised())
1276 (*it
)->TransmitPhysicalAddress(false);
1279 // reactivate the previous active source
1280 if (reactivateSource
!= CECDEVICE_UNKNOWN
&&
1281 m_processor
->CECInitialised() &&
1284 CCECBusDevice
*device
= m_processor
->GetDevice(reactivateSource
);
1286 device
->ActivateSource();
1289 // persist the new configuration
1290 PersistConfiguration(m_configuration
);
1295 bool CCECClient::SwitchMonitoring(bool bEnable
)
1297 LIB_CEC
->AddLog(CEC_LOG_NOTICE
, "== %s monitoring mode ==", bEnable
? "enabling" : "disabling");
1301 m_processor
->SwitchMonitoring(bEnable
);
1302 m_configuration
.bMonitorOnly
= bEnable
;
1303 return bEnable
? true: m_processor
->RegisterClient(this);
1309 bool CCECClient::PollDevice(const cec_logical_address iAddress
)
1311 // try to find the primary device
1312 CCECBusDevice
*primary
= GetPrimaryDevice();
1313 // poll the destination, with the primary as source
1315 return primary
->TransmitPoll(iAddress
, false);
1317 return m_processor
? m_processor
->PollDevice(iAddress
) : false;
1320 cec_logical_addresses
CCECClient::GetActiveDevices(void)
1322 CECDEVICEVEC activeDevices
;
1324 m_processor
->GetDevices()->GetActive(activeDevices
);
1325 return CCECDeviceMap::ToLogicalAddresses(activeDevices
);
1328 bool CCECClient::IsActiveDevice(const cec_logical_address iAddress
)
1330 cec_logical_addresses activeDevices
= GetActiveDevices();
1331 return activeDevices
.IsSet(iAddress
);
1334 bool CCECClient::IsActiveDeviceType(const cec_device_type type
)
1336 CECDEVICEVEC activeDevices
;
1338 m_processor
->GetDevices()->GetActive(activeDevices
);
1339 CCECDeviceMap::FilterType(type
, activeDevices
);
1340 return !activeDevices
.empty();
1343 cec_logical_address
CCECClient::GetActiveSource(void)
1345 return m_processor
? m_processor
->GetActiveSource() : CECDEVICE_UNKNOWN
;
1348 bool CCECClient::IsActiveSource(const cec_logical_address iAddress
)
1350 return m_processor
? m_processor
->IsActiveSource(iAddress
) : false;
1353 bool CCECClient::SetStreamPath(const cec_logical_address iAddress
)
1355 uint16_t iPhysicalAddress
= GetDevicePhysicalAddress(iAddress
);
1356 if (iPhysicalAddress
!= CEC_INVALID_PHYSICAL_ADDRESS
)
1357 return SetStreamPath(iPhysicalAddress
);
1361 bool CCECClient::SetStreamPath(const uint16_t iPhysicalAddress
)
1363 bool bReturn(false);
1365 CCECBusDevice
*device
= GetDeviceByType(CEC_DEVICE_TYPE_TV
);
1368 device
->SetStreamPath(iPhysicalAddress
);
1369 bReturn
= device
->GetHandler()->TransmitSetStreamPath(iPhysicalAddress
, false);
1370 device
->MarkHandlerReady();
1374 LIB_CEC
->AddLog(CEC_LOG_ERROR
, "only the TV is allowed to send CEC_OPCODE_SET_STREAM_PATH");
1380 cec_logical_addresses
CCECClient::GetLogicalAddresses(void)
1382 cec_logical_addresses addresses
;
1383 CLockObject
lock(m_mutex
);
1384 addresses
= m_configuration
.logicalAddresses
;
1388 bool CCECClient::CanPersistConfiguration(void)
1390 return m_processor
? m_processor
->CanPersistConfiguration() : false;
1393 bool CCECClient::PersistConfiguration(const libcec_configuration
&configuration
)
1395 return m_processor
&& IsRegistered() ?
1396 m_processor
->PersistConfiguration(configuration
) :
1400 void CCECClient::RescanActiveDevices(void)
1403 m_processor
->RescanActiveDevices();
1406 bool CCECClient::IsLibCECActiveSource(void)
1408 bool bReturn(false);
1411 cec_logical_address activeSource
= m_processor
->GetActiveSource();
1412 CCECBusDevice
*device
= m_processor
->GetDevice(activeSource
);
1414 bReturn
= device
->IsHandledByLibCEC();
1419 void CCECClient::SourceActivated(const cec_logical_address logicalAddress
)
1421 LIB_CEC
->AddLog(CEC_LOG_NOTICE
, ">> source activated: %s (%x)", ToString(logicalAddress
), logicalAddress
);
1422 CallbackSourceActivated(true, logicalAddress
);
1425 void CCECClient::SourceDeactivated(const cec_logical_address logicalAddress
)
1427 LIB_CEC
->AddLog(CEC_LOG_NOTICE
, ">> source deactivated: %s (%x)", ToString(logicalAddress
), logicalAddress
);
1428 CallbackSourceActivated(false, logicalAddress
);
1431 void CCECClient::CallbackAddCommand(const cec_command
&command
)
1434 CLockObject
lock(m_cbMutex
);
1435 if (m_configuration
.callbacks
&& m_configuration
.callbacks
->CBCecCommand
)
1437 m_configuration
.callbacks
->CBCecCommand(m_configuration
.callbackParam
, command
);
1441 m_commandBuffer
.Push(command
);
1444 void CCECClient::CallbackAddKey(const cec_keypress
&key
)
1447 CLockObject
lock(m_cbMutex
);
1448 if (m_configuration
.callbacks
&& m_configuration
.callbacks
->CBCecKeyPress
)
1450 m_configuration
.callbacks
->CBCecKeyPress(m_configuration
.callbackParam
, key
);
1454 m_keyBuffer
.Push(key
);
1457 void CCECClient::CallbackAddLog(const cec_log_message
&message
)
1460 CLockObject
lock(m_cbMutex
);
1461 if (m_configuration
.callbacks
&& m_configuration
.callbacks
->CBCecLogMessage
)
1463 m_configuration
.callbacks
->CBCecLogMessage(m_configuration
.callbackParam
, message
);
1467 m_logBuffer
.Push(message
);
1470 void CCECClient::CallbackConfigurationChanged(const libcec_configuration
&config
)
1472 CLockObject
lock(m_cbMutex
);
1473 if (m_configuration
.callbacks
&&
1474 m_configuration
.clientVersion
>= CEC_CLIENT_VERSION_1_5_0
&&
1475 m_configuration
.callbacks
->CBCecConfigurationChanged
&&
1476 m_processor
->CECInitialised())
1477 m_configuration
.callbacks
->CBCecConfigurationChanged(m_configuration
.callbackParam
, config
);
1480 void CCECClient::CallbackSourceActivated(bool bActivated
, const cec_logical_address logicalAddress
)
1482 CLockObject
lock(m_cbMutex
);
1483 if (m_configuration
.callbacks
&&
1484 m_configuration
.clientVersion
>= CEC_CLIENT_VERSION_1_7_1
&&
1485 m_configuration
.callbacks
->CBCecSourceActivated
)
1486 m_configuration
.callbacks
->CBCecSourceActivated(m_configuration
.callbackParam
, logicalAddress
, bActivated
? 1 : 0);
1489 void CCECClient::CallbackAlert(const libcec_alert type
, const libcec_parameter
¶m
)
1491 CLockObject
lock(m_cbMutex
);
1492 if (m_configuration
.callbacks
&&
1493 m_configuration
.clientVersion
>= CEC_CLIENT_VERSION_1_6_0
&&
1494 m_configuration
.callbacks
->CBCecAlert
)
1495 m_configuration
.callbacks
->CBCecAlert(m_configuration
.callbackParam
, type
, param
);
1498 int CCECClient::CallbackMenuStateChanged(const cec_menu_state newState
)
1500 CLockObject
lock(m_cbMutex
);
1501 if (m_configuration
.callbacks
&&
1502 m_configuration
.clientVersion
>= CEC_CLIENT_VERSION_1_6_2
&&
1503 m_configuration
.callbacks
->CBCecMenuStateChanged
)
1504 return m_configuration
.callbacks
->CBCecMenuStateChanged(m_configuration
.callbackParam
, newState
);