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),
60 m_iLastKeypressTime(0)
62 m_lastKeypress
.keycode
= CEC_USER_CONTROL_CODE_UNKNOWN
;
63 m_lastKeypress
.duration
= 0;
64 m_configuration
.Clear();
65 // set the initial configuration
66 SetConfiguration(configuration
);
69 CCECClient::~CCECClient(void)
71 // unregister the client
72 if (m_processor
&& IsRegistered())
73 m_processor
->UnregisterClient(this);
76 bool CCECClient::IsInitialised(void)
78 CLockObject
lock(m_mutex
);
79 return m_bInitialised
&& m_processor
;
82 void CCECClient::SetInitialised(bool bSetTo
)
84 CLockObject
lock(m_mutex
);
85 m_bInitialised
= bSetTo
;
88 bool CCECClient::IsRegistered(void)
90 CLockObject
lock(m_mutex
);
91 return m_bRegistered
&& m_processor
;
94 void CCECClient::SetRegistered(bool bSetTo
)
96 CLockObject
lock(m_mutex
);
97 m_bRegistered
= bSetTo
;
100 bool CCECClient::OnRegister(void)
102 // return false if already initialised
106 // get all device we control
107 CECDEVICEVEC devices
;
108 m_processor
->GetDevices()->GetByLogicalAddresses(devices
, m_configuration
.logicalAddresses
);
110 // return false when no devices were found
113 LIB_CEC
->AddLog(CEC_LOG_WARNING
, "cannot find the primary device (logical address %x)", GetPrimaryLogicalAdddress());
117 // mark as initialised
118 SetInitialised(true);
120 // configure all devices
121 for (CECDEVICEVEC::iterator it
= devices
.begin(); it
!= devices
.end(); it
++)
123 // only set our OSD name for the primary device
124 if ((*it
)->GetLogicalAddress() == GetPrimaryLogicalAdddress())
125 (*it
)->SetOSDName(m_configuration
.strDeviceName
);
127 // set the default menu language for devices we control
128 (*it
)->SetMenuLanguage(m_configuration
.strDeviceLanguage
);
131 // set the physical address
132 SetPhysicalAddress(m_configuration
);
134 // make the primary device the active source if the option is set
135 if (m_configuration
.bActivateSource
== 1)
136 GetPrimaryDevice()->ActivateSource(500);
141 bool CCECClient::SetHDMIPort(const cec_logical_address iBaseDevice
, const uint8_t iPort
, bool bForce
/* = false */)
145 // limit the HDMI port range to 1-15
146 if (iPort
< CEC_MIN_HDMI_PORTNUMBER
||
147 iPort
> CEC_MAX_HDMI_PORTNUMBER
)
150 LIB_CEC
->AddLog(CEC_LOG_NOTICE
, "setting HDMI port to %d on device %s (%d)", iPort
, ToString(iBaseDevice
), (int)iBaseDevice
);
152 // update the configuration
154 CLockObject
lock(m_mutex
);
155 m_configuration
.baseDevice
= iBaseDevice
;
156 m_configuration
.iHDMIPort
= iPort
;
159 // don't continue if the connection isn't opened
160 if (!m_processor
->CECInitialised() && !bForce
)
163 // get the PA of the base device
164 uint16_t iPhysicalAddress(CEC_INVALID_PHYSICAL_ADDRESS
);
165 CCECBusDevice
*baseDevice
= m_processor
->GetDevice(iBaseDevice
);
167 iPhysicalAddress
= baseDevice
->GetPhysicalAddress(GetPrimaryLogicalAdddress());
169 // add our port number
170 if (iPhysicalAddress
<= CEC_MAX_PHYSICAL_ADDRESS
)
172 if (iPhysicalAddress
== 0)
173 iPhysicalAddress
+= 0x1000 * iPort
;
174 else if (iPhysicalAddress
% 0x1000 == 0)
175 iPhysicalAddress
+= 0x100 * iPort
;
176 else if (iPhysicalAddress
% 0x100 == 0)
177 iPhysicalAddress
+= 0x10 * iPort
;
178 else if (iPhysicalAddress
% 0x10 == 0)
179 iPhysicalAddress
+= iPort
;
184 // set the default address when something went wrong
187 uint16_t iEepromAddress
= m_processor
->GetPhysicalAddressFromEeprom();
188 if (CLibCEC::IsValidPhysicalAddress(iEepromAddress
))
190 LIB_CEC
->AddLog(CEC_LOG_WARNING
, "failed to set the physical address to %04X, setting it to the value that was persisted in the eeprom, %04X", iPhysicalAddress
, iEepromAddress
);
191 iPhysicalAddress
= iEepromAddress
;
196 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
);
197 iPhysicalAddress
= CEC_DEFAULT_PHYSICAL_ADDRESS
;
201 // and set the address
202 SetDevicePhysicalAddress(iPhysicalAddress
);
204 CallbackConfigurationChanged(m_configuration
);
209 void CCECClient::ResetPhysicalAddress(void)
211 SetPhysicalAddress(m_configuration
);
214 void CCECClient::SetPhysicalAddress(const libcec_configuration
&configuration
)
218 // override the physical address from configuration.iPhysicalAddress if it's set
219 if (!bPASet
&& CLibCEC::IsValidPhysicalAddress(configuration
.iPhysicalAddress
))
220 bPASet
= SetPhysicalAddress(configuration
.iPhysicalAddress
);
222 // try to autodetect the address
223 if (!bPASet
&& m_processor
->CECInitialised())
225 bPASet
= AutodetectPhysicalAddress();
226 m_configuration
.bAutodetectAddress
= bPASet
? 1 : 0;
229 // use the base device + hdmi port settings
231 bPASet
= SetHDMIPort(configuration
.baseDevice
, configuration
.iHDMIPort
);
233 // reset to defaults if something went wrong
236 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "%s - resetting HDMI port and base device to defaults", __FUNCTION__
);
237 m_configuration
.baseDevice
= CECDEVICE_UNKNOWN
;
238 m_configuration
.iHDMIPort
= CEC_HDMI_PORTNUMBER_NONE
;
242 bool CCECClient::SetPhysicalAddress(const uint16_t iPhysicalAddress
)
244 // update the configuration
247 CLockObject
lock(m_mutex
);
248 if (m_configuration
.iPhysicalAddress
== iPhysicalAddress
)
251 m_configuration
.iPhysicalAddress
= iPhysicalAddress
;
255 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "physical address unchanged (%04X)", iPhysicalAddress
);
259 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "setting physical address to '%04X'", iPhysicalAddress
);
261 // set the physical address for each device
262 SetDevicePhysicalAddress(iPhysicalAddress
);
264 // and send back the updated configuration
265 CallbackConfigurationChanged(m_configuration
);
270 void CCECClient::SetSupportedDeviceTypes(void)
272 cec_device_type_list types
;
275 // get the command handler for the tv
276 CCECCommandHandler
*tvHandler
= m_processor
->GetTV()->GetHandler();
280 // check all device types
281 for (uint8_t iPtr
= 0; iPtr
< 5; iPtr
++)
283 if (m_configuration
.deviceTypes
.types
[iPtr
] == CEC_DEVICE_TYPE_RESERVED
)
286 // get the supported device type. the handler will replace types it doesn't support by one it does support
287 cec_device_type type
= tvHandler
->GetReplacementDeviceType(m_configuration
.deviceTypes
.types
[iPtr
]);
288 if (!types
.IsSet(type
))
291 m_processor
->GetTV()->MarkHandlerReady();
293 // set the new type list
294 m_configuration
.deviceTypes
= types
;
296 // persist the new configuration
297 PersistConfiguration(m_configuration
);
300 bool CCECClient::AllocateLogicalAddresses(void)
302 // reset all previous LAs that were set
303 m_configuration
.logicalAddresses
.Clear();
305 // get the supported device types from the command handler of the TV
306 SetSupportedDeviceTypes();
308 // display an error if no device types are set
309 if (m_configuration
.deviceTypes
.IsEmpty())
311 LIB_CEC
->AddLog(CEC_LOG_ERROR
, "no device types given");
315 // check each entry of the list
316 for (uint8_t iPtr
= 0; iPtr
< 5; iPtr
++)
318 if (m_configuration
.deviceTypes
.types
[iPtr
] == CEC_DEVICE_TYPE_RESERVED
)
321 // find an LA for this type
322 cec_logical_address
address(CECDEVICE_UNKNOWN
);
323 if (m_configuration
.deviceTypes
.types
[iPtr
] == CEC_DEVICE_TYPE_RECORDING_DEVICE
)
324 address
= AllocateLogicalAddressRecordingDevice();
325 if (m_configuration
.deviceTypes
.types
[iPtr
] == CEC_DEVICE_TYPE_TUNER
)
326 address
= AllocateLogicalAddressTuner();
327 if (m_configuration
.deviceTypes
.types
[iPtr
] == CEC_DEVICE_TYPE_PLAYBACK_DEVICE
)
328 address
= AllocateLogicalAddressPlaybackDevice();
329 if (m_configuration
.deviceTypes
.types
[iPtr
] == CEC_DEVICE_TYPE_AUDIO_SYSTEM
)
330 address
= AllocateLogicalAddressAudioSystem();
332 // display an error if no LA could be allocated
333 if (address
== CECDEVICE_UNKNOWN
)
335 LIB_CEC
->AddLog(CEC_LOG_ERROR
, "%s - failed to allocate device '%d', type '%s'", __FUNCTION__
, iPtr
, ToString(m_configuration
.deviceTypes
.types
[iPtr
]));
339 // display the registered LA
340 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "%s - device '%d', type '%s', LA '%X'", __FUNCTION__
, iPtr
, ToString(m_configuration
.deviceTypes
.types
[iPtr
]), address
);
341 m_configuration
.logicalAddresses
.Set(address
);
344 // persist the new configuration
345 PersistConfiguration(m_configuration
);
350 cec_logical_address
CCECClient::AllocateLogicalAddressRecordingDevice(void)
352 cec_logical_address
retVal(CECDEVICE_UNKNOWN
);
354 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "detecting logical address for type 'recording device'");
355 if (m_processor
->TryLogicalAddress(CECDEVICE_RECORDINGDEVICE1
, m_configuration
.cecVersion
))
356 retVal
= CECDEVICE_RECORDINGDEVICE1
;
357 else if (m_processor
->TryLogicalAddress(CECDEVICE_RECORDINGDEVICE2
, m_configuration
.cecVersion
))
358 retVal
= CECDEVICE_RECORDINGDEVICE2
;
359 else if (m_processor
->TryLogicalAddress(CECDEVICE_RECORDINGDEVICE3
, m_configuration
.cecVersion
))
360 retVal
= CECDEVICE_RECORDINGDEVICE3
;
365 cec_logical_address
CCECClient::AllocateLogicalAddressTuner(void)
367 cec_logical_address
retVal(CECDEVICE_UNKNOWN
);
369 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "detecting logical address for type 'tuner'");
370 if (m_processor
->TryLogicalAddress(CECDEVICE_TUNER1
, m_configuration
.cecVersion
))
371 retVal
= CECDEVICE_TUNER1
;
372 else if (m_processor
->TryLogicalAddress(CECDEVICE_TUNER2
, m_configuration
.cecVersion
))
373 retVal
= CECDEVICE_TUNER2
;
374 else if (m_processor
->TryLogicalAddress(CECDEVICE_TUNER3
, m_configuration
.cecVersion
))
375 retVal
= CECDEVICE_TUNER3
;
376 else if (m_processor
->TryLogicalAddress(CECDEVICE_TUNER4
, m_configuration
.cecVersion
))
377 retVal
= CECDEVICE_TUNER4
;
382 cec_logical_address
CCECClient::AllocateLogicalAddressPlaybackDevice(void)
384 cec_logical_address
retVal(CECDEVICE_UNKNOWN
);
386 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "detecting logical address for type 'playback device'");
387 if (m_processor
->TryLogicalAddress(CECDEVICE_PLAYBACKDEVICE1
, m_configuration
.cecVersion
))
388 retVal
= CECDEVICE_PLAYBACKDEVICE1
;
389 else if (m_processor
->TryLogicalAddress(CECDEVICE_PLAYBACKDEVICE2
, m_configuration
.cecVersion
))
390 retVal
= CECDEVICE_PLAYBACKDEVICE2
;
391 else if (m_processor
->TryLogicalAddress(CECDEVICE_PLAYBACKDEVICE3
, m_configuration
.cecVersion
))
392 retVal
= CECDEVICE_PLAYBACKDEVICE3
;
397 cec_logical_address
CCECClient::AllocateLogicalAddressAudioSystem(void)
399 cec_logical_address
retVal(CECDEVICE_UNKNOWN
);
401 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "detecting logical address for type 'audiosystem'");
402 if (m_processor
->TryLogicalAddress(CECDEVICE_AUDIOSYSTEM
, m_configuration
.cecVersion
))
403 retVal
= CECDEVICE_AUDIOSYSTEM
;
408 CCECBusDevice
*CCECClient::GetDeviceByType(const cec_device_type type
) const
410 // get all devices that match our logical addresses
411 CECDEVICEVEC devices
;
412 m_processor
->GetDevices()->GetByLogicalAddresses(devices
, m_configuration
.logicalAddresses
);
414 // filter the type we need
415 CCECDeviceMap::FilterType(type
, devices
);
417 return devices
.empty() ?
422 bool CCECClient::ChangeDeviceType(const cec_device_type from
, const cec_device_type to
)
427 LIB_CEC
->AddLog(CEC_LOG_NOTICE
, "changing device type '%s' into '%s'", ToString(from
), ToString(to
));
430 CLockObject
lock(m_mutex
);
432 // get the previous device that was allocated
433 CCECBusDevice
*previousDevice
= GetDeviceByType(from
);
437 // change the type in the device type list
438 bool bChanged(false);
439 for (uint8_t iPtr
= 0; iPtr
< 5; iPtr
++)
441 if (m_configuration
.deviceTypes
.types
[iPtr
] == CEC_DEVICE_TYPE_RESERVED
)
444 if (m_configuration
.deviceTypes
.types
[iPtr
] == from
)
447 m_configuration
.deviceTypes
.types
[iPtr
] = to
;
449 else if (m_configuration
.deviceTypes
.types
[iPtr
] == to
&& bChanged
)
451 // ensure that dupes are removed
452 m_configuration
.deviceTypes
.types
[iPtr
] = CEC_DEVICE_TYPE_RESERVED
;
457 // re-register the client to set the new ackmask
458 if (!m_processor
->RegisterClient(this))
461 // persist the new configuration
462 PersistConfiguration(m_configuration
);
467 bool CCECClient::SetLogicalAddress(const cec_logical_address iLogicalAddress
)
471 if (GetPrimaryLogicalAdddress() != iLogicalAddress
)
473 LIB_CEC
->AddLog(CEC_LOG_NOTICE
, "setting primary logical address to %1x", iLogicalAddress
);
475 CLockObject
lock(m_mutex
);
476 m_configuration
.logicalAddresses
.primary
= iLogicalAddress
;
477 m_configuration
.logicalAddresses
.Set(iLogicalAddress
);
480 bReturn
= m_processor
->RegisterClient(this);
482 // persist the new configuration
484 PersistConfiguration(m_configuration
);
490 bool CCECClient::Transmit(const cec_command
&data
, bool bIsReply
)
492 return m_processor
? m_processor
->Transmit(data
, bIsReply
) : false;
495 bool CCECClient::SendPowerOnDevices(const cec_logical_address address
/* = CECDEVICE_TV */)
497 // if the broadcast address if set as destination, read the wakeDevices setting
498 if (address
== CECDEVICE_BROADCAST
)
500 CECDEVICEVEC devices
;
501 m_processor
->GetDevices()->GetWakeDevices(m_configuration
, devices
);
502 return m_processor
->PowerOnDevices(GetPrimaryLogicalAdddress(), devices
);
505 return m_processor
->PowerOnDevice(GetPrimaryLogicalAdddress(), address
);
508 bool CCECClient::SendStandbyDevices(const cec_logical_address address
/* = CECDEVICE_BROADCAST */)
510 // if the broadcast address if set as destination, read the standbyDevices setting
511 if (address
== CECDEVICE_BROADCAST
)
513 CECDEVICEVEC devices
;
514 m_processor
->GetDevices()->GetPowerOffDevices(m_configuration
, devices
);
515 return m_processor
->StandbyDevices(GetPrimaryLogicalAdddress(), devices
);
518 return m_processor
->StandbyDevice(GetPrimaryLogicalAdddress(), address
);
521 bool CCECClient::SendSetActiveSource(const cec_device_type type
/* = CEC_DEVICE_TYPE_RESERVED */)
523 // get the devices that are controlled by us
524 CECDEVICEVEC devices
;
525 m_processor
->GetDevices()->GetByLogicalAddresses(devices
, m_configuration
.logicalAddresses
);
527 // filter out the device that matches the given type
528 if (type
!= CEC_DEVICE_TYPE_RESERVED
)
529 CCECDeviceMap::FilterType(type
, devices
);
531 // no devices left, re-fetch the list of devices that are controlled by us
533 m_processor
->GetDevices()->GetByLogicalAddresses(devices
, m_configuration
.logicalAddresses
);
535 if (!devices
.empty())
537 // get the first device from the list
538 CCECBusDevice
*device
= *devices
.begin();
541 if (!m_processor
->CECInitialised())
542 device
->MarkAsActiveSource();
543 else if (device
->HasValidPhysicalAddress())
544 return device
->ActivateSource();
550 CCECPlaybackDevice
*CCECClient::GetPlaybackDevice(void)
552 CCECPlaybackDevice
*device(NULL
);
553 CECDEVICEVEC devices
;
555 // get the playback devices
556 m_processor
->GetDevices()->GetByLogicalAddresses(devices
, m_configuration
.logicalAddresses
);
557 CCECDeviceMap::FilterType(CEC_DEVICE_TYPE_PLAYBACK_DEVICE
, devices
);
559 // no matches, get the recording devices
562 m_processor
->GetDevices()->GetByLogicalAddresses(devices
, m_configuration
.logicalAddresses
);
563 CCECDeviceMap::FilterType(CEC_DEVICE_TYPE_RECORDING_DEVICE
, devices
);
566 // get the first device that matches, and cast it to CCECPlaybackDevice
567 if (!devices
.empty())
568 device
= (*devices
.begin())->AsPlaybackDevice();
573 cec_logical_address
CCECClient::GetPrimaryLogicalAdddress(void)
575 CLockObject
lock(m_mutex
);
576 return m_configuration
.logicalAddresses
.primary
;
579 CCECBusDevice
*CCECClient::GetPrimaryDevice(void)
581 return m_processor
->GetDevice(GetPrimaryLogicalAdddress());
584 bool CCECClient::SendSetDeckControlMode(const cec_deck_control_mode mode
, bool bSendUpdate
/* = true */)
586 // find a playback device that we control
587 CCECPlaybackDevice
*device
= GetPlaybackDevice();
590 // and set the deck control mode if there is a match
591 device
->SetDeckControlMode(mode
);
593 return device
->TransmitDeckStatus(CECDEVICE_TV
, false);
601 bool CCECClient::SendSetDeckInfo(const cec_deck_info info
, bool bSendUpdate
/* = true */)
603 // find a playback device that we control
604 CCECPlaybackDevice
*device
= GetPlaybackDevice();
607 // and set the deck status if there is a match
608 device
->SetDeckStatus(info
);
610 return device
->AsPlaybackDevice()->TransmitDeckStatus(CECDEVICE_TV
, false);
618 bool CCECClient::SendSetMenuState(const cec_menu_state state
, bool bSendUpdate
/* = true */)
620 CECDEVICEVEC devices
;
622 // set the menu state for all devices that are controlled by us
623 m_processor
->GetDevices()->GetByLogicalAddresses(devices
, m_configuration
.logicalAddresses
);
624 for (CECDEVICEVEC::iterator it
= devices
.begin(); it
!= devices
.end(); it
++)
626 (*it
)->SetMenuState(state
);
628 (*it
)->TransmitMenuState(CECDEVICE_TV
, false);
634 bool CCECClient::SendSetInactiveView(void)
636 CECDEVICEVEC devices
;
638 // mark all devices that are controlled by us as inactive source
639 m_processor
->GetDevices()->GetByLogicalAddresses(devices
, m_configuration
.logicalAddresses
);
640 for (CECDEVICEVEC::iterator it
= devices
.begin(); it
!= devices
.end(); it
++)
642 if ((*it
)->IsActiveSource())
644 (*it
)->MarkAsInactiveSource();
645 return (*it
)->TransmitInactiveSource();
652 bool CCECClient::SendSetOSDString(const cec_logical_address iLogicalAddress
, const cec_display_control duration
, const char *strMessage
)
654 CCECBusDevice
*primary
= GetPrimaryDevice();
656 return primary
->TransmitOSDString(iLogicalAddress
, duration
, strMessage
, false);
661 cec_version
CCECClient::GetDeviceCecVersion(const cec_logical_address iAddress
)
663 CCECBusDevice
*device
= m_processor
->GetDevice(iAddress
);
665 return device
->GetCecVersion(GetPrimaryLogicalAdddress());
666 return CEC_VERSION_UNKNOWN
;
669 bool CCECClient::GetDeviceMenuLanguage(const cec_logical_address iAddress
, cec_menu_language
&language
)
671 CCECBusDevice
*device
= m_processor
->GetDevice(iAddress
);
674 language
= device
->GetMenuLanguage(GetPrimaryLogicalAdddress());
675 return (strcmp(language
.language
, "???") != 0);
680 cec_osd_name
CCECClient::GetDeviceOSDName(const cec_logical_address iAddress
)
683 retVal
.device
= iAddress
;
686 CCECBusDevice
*device
= m_processor
->GetDevice(iAddress
);
689 CStdString strOSDName
= device
->GetOSDName(GetPrimaryLogicalAdddress());
690 snprintf(retVal
.name
, sizeof(retVal
.name
), "%s", strOSDName
.c_str());
691 retVal
.device
= iAddress
;
697 uint16_t CCECClient::GetDevicePhysicalAddress(const cec_logical_address iAddress
)
699 CCECBusDevice
*device
= m_processor
->GetDevice(iAddress
);
701 return device
->GetPhysicalAddress(GetPrimaryLogicalAdddress());
702 return CEC_INVALID_PHYSICAL_ADDRESS
;
705 cec_power_status
CCECClient::GetDevicePowerStatus(const cec_logical_address iAddress
)
707 CCECBusDevice
*device
= m_processor
->GetDevice(iAddress
);
709 return device
->GetPowerStatus(GetPrimaryLogicalAdddress());
710 return CEC_POWER_STATUS_UNKNOWN
;
713 uint64_t CCECClient::GetDeviceVendorId(const cec_logical_address iAddress
)
715 CCECBusDevice
*device
= m_processor
->GetDevice(iAddress
);
717 return device
->GetVendorId(GetPrimaryLogicalAdddress());
718 return CEC_VENDOR_UNKNOWN
;
721 uint8_t CCECClient::SendVolumeUp(bool bSendRelease
/* = true */)
723 CCECBusDevice
*device
= GetPrimaryDevice();
724 CCECAudioSystem
*audio
= m_processor
->GetAudioSystem();
726 return device
&& audio
&& audio
->IsPresent() ?
727 audio
->VolumeUp(device
->GetLogicalAddress(), bSendRelease
) :
728 (uint8_t)CEC_AUDIO_VOLUME_STATUS_UNKNOWN
;
731 uint8_t CCECClient::SendVolumeDown(bool bSendRelease
/* = true */)
733 CCECBusDevice
*device
= GetPrimaryDevice();
734 CCECAudioSystem
*audio
= m_processor
->GetAudioSystem();
736 return device
&& audio
&& audio
->IsPresent() ?
737 audio
->VolumeDown(device
->GetLogicalAddress(), bSendRelease
) :
738 (uint8_t)CEC_AUDIO_VOLUME_STATUS_UNKNOWN
;
741 uint8_t CCECClient::SendMuteAudio(void)
743 CCECBusDevice
*device
= GetPrimaryDevice();
744 CCECAudioSystem
*audio
= m_processor
->GetAudioSystem();
746 return device
&& audio
&& audio
->IsPresent() ?
747 audio
->MuteAudio(device
->GetLogicalAddress()) :
748 (uint8_t)CEC_AUDIO_VOLUME_STATUS_UNKNOWN
;
751 bool CCECClient::SendKeypress(const cec_logical_address iDestination
, const cec_user_control_code key
, bool bWait
/* = true */)
753 CCECBusDevice
*dest
= m_processor
->GetDevice(iDestination
);
756 dest
->TransmitKeypress(GetPrimaryLogicalAdddress(), key
, bWait
) :
760 bool CCECClient::SendKeyRelease(const cec_logical_address iDestination
, bool bWait
/* = true */)
762 CCECBusDevice
*dest
= m_processor
->GetDevice(iDestination
);
765 dest
->TransmitKeyRelease(GetPrimaryLogicalAdddress(), bWait
) :
769 bool CCECClient::GetCurrentConfiguration(libcec_configuration
&configuration
)
771 CLockObject
lock(m_mutex
);
773 // client version 1.5.0
774 snprintf(configuration
.strDeviceName
, 13, "%s", m_configuration
.strDeviceName
);
775 configuration
.deviceTypes
= m_configuration
.deviceTypes
;
776 configuration
.bAutodetectAddress
= m_configuration
.bAutodetectAddress
;
777 configuration
.iPhysicalAddress
= m_configuration
.iPhysicalAddress
;
778 configuration
.baseDevice
= m_configuration
.baseDevice
;
779 configuration
.iHDMIPort
= m_configuration
.iHDMIPort
;
780 configuration
.clientVersion
= m_configuration
.clientVersion
;
781 configuration
.serverVersion
= m_configuration
.serverVersion
;
782 configuration
.tvVendor
= m_configuration
.tvVendor
;
783 configuration
.bGetSettingsFromROM
= m_configuration
.bGetSettingsFromROM
;
784 configuration
.bUseTVMenuLanguage
= m_configuration
.bUseTVMenuLanguage
;
785 configuration
.bActivateSource
= m_configuration
.bActivateSource
;
786 configuration
.wakeDevices
= m_configuration
.wakeDevices
;
787 configuration
.powerOffDevices
= m_configuration
.powerOffDevices
;
788 configuration
.bPowerOffScreensaver
= m_configuration
.bPowerOffScreensaver
;
789 configuration
.bPowerOffOnStandby
= m_configuration
.bPowerOffOnStandby
;
790 configuration
.bSendInactiveSource
= m_configuration
.bSendInactiveSource
;
791 configuration
.logicalAddresses
= m_configuration
.logicalAddresses
;
792 configuration
.iFirmwareVersion
= m_configuration
.iFirmwareVersion
;
793 configuration
.bPowerOffDevicesOnStandby
= m_configuration
.bPowerOffDevicesOnStandby
;
794 configuration
.bShutdownOnStandby
= m_configuration
.bShutdownOnStandby
;
795 memcpy(configuration
.strDeviceLanguage
, m_configuration
.strDeviceLanguage
, 3);
796 configuration
.iFirmwareBuildDate
= m_configuration
.iFirmwareBuildDate
;
797 configuration
.bMonitorOnly
= m_configuration
.bMonitorOnly
;
798 configuration
.cecVersion
= m_configuration
.cecVersion
;
799 configuration
.adapterType
= m_configuration
.adapterType
;
804 bool CCECClient::SetConfiguration(const libcec_configuration
&configuration
)
806 bool bIsRunning(m_processor
&& m_processor
->CECInitialised());
807 CCECBusDevice
*primary
= bIsRunning
? GetPrimaryDevice() : NULL
;
808 uint16_t iPA
= primary
? primary
->GetCurrentPhysicalAddress() : CEC_INVALID_PHYSICAL_ADDRESS
;
810 // update the callbacks
811 if (configuration
.callbacks
)
812 EnableCallbacks(configuration
.callbackParam
, configuration
.callbacks
);
814 // update the client version
815 SetClientVersion((cec_client_version
)configuration
.clientVersion
);
817 // update the OSD name
818 CStdString
strOSDName(configuration
.strDeviceName
);
819 SetOSDName(strOSDName
);
821 // update the TV vendor override
822 SetTVVendorOverride((cec_vendor_id
)configuration
.tvVendor
);
826 CLockObject
lock(m_mutex
);
827 m_configuration
.bUseTVMenuLanguage
= configuration
.bUseTVMenuLanguage
;
828 m_configuration
.bActivateSource
= configuration
.bActivateSource
;
829 m_configuration
.bGetSettingsFromROM
= configuration
.bGetSettingsFromROM
;
830 m_configuration
.wakeDevices
= configuration
.wakeDevices
;
831 m_configuration
.powerOffDevices
= configuration
.powerOffDevices
;
832 m_configuration
.bPowerOffScreensaver
= configuration
.bPowerOffScreensaver
;
833 m_configuration
.bPowerOffOnStandby
= configuration
.bPowerOffOnStandby
;
834 m_configuration
.bSendInactiveSource
= configuration
.bSendInactiveSource
;
835 m_configuration
.bPowerOffDevicesOnStandby
= configuration
.bPowerOffDevicesOnStandby
;
836 m_configuration
.bShutdownOnStandby
= configuration
.bShutdownOnStandby
;
837 memcpy(m_configuration
.strDeviceLanguage
, configuration
.strDeviceLanguage
, 3);
838 m_configuration
.bMonitorOnly
= configuration
.bMonitorOnly
;
839 m_configuration
.cecVersion
= configuration
.cecVersion
;
840 m_configuration
.adapterType
= configuration
.adapterType
;
841 m_configuration
.deviceTypes
.Add(CEC_DEVICE_TYPE_RECORDING_DEVICE
);
844 bool bNeedReinit(false);
847 if (SetDeviceTypes(configuration
.deviceTypes
))
849 // the device type changed. just copy the rest, and re-register
851 CLockObject
lock(m_mutex
);
852 m_configuration
.iPhysicalAddress
= configuration
.iPhysicalAddress
;
853 m_configuration
.baseDevice
= configuration
.baseDevice
;
854 m_configuration
.iHDMIPort
= configuration
.iHDMIPort
;
860 // set the physical address
861 SetPhysicalAddress(configuration
);
864 // persist the new configuration
865 PersistConfiguration(m_configuration
);
868 primary
= GetPrimaryDevice();
870 if (bNeedReinit
|| !primary
|| primary
->GetCurrentPhysicalAddress() != iPA
)
872 // PA or device type changed
873 m_processor
->RegisterClient(this);
875 else if (primary
&& configuration
.bActivateSource
== 1 && bIsRunning
&& !primary
->IsActiveSource())
877 // activate the source if we're not already the active source
878 primary
->ActivateSource();
884 void CCECClient::AddCommand(const cec_command
&command
)
886 // don't forward the standby opcode more than once every 10 seconds
887 if (command
.opcode
== CEC_OPCODE_STANDBY
)
889 CLockObject
lock(m_mutex
);
890 if (m_iPreventForwardingPowerOffCommand
!= 0 &&
891 m_iPreventForwardingPowerOffCommand
> GetTimeMs())
894 m_iPreventForwardingPowerOffCommand
= GetTimeMs() + CEC_FORWARD_STANDBY_MIN_INTERVAL
;
897 if (command
.destination
== CECDEVICE_BROADCAST
|| GetLogicalAddresses().IsSet(command
.destination
))
899 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, ">> %s (%X) -> %s (%X): %s (%2X)", ToString(command
.initiator
), command
.initiator
, ToString(command
.destination
), command
.destination
, ToString(command
.opcode
), command
.opcode
);
900 CallbackAddCommand(command
);
904 int CCECClient::MenuStateChanged(const cec_menu_state newState
)
906 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, ">> %s: %s", ToString(CEC_OPCODE_MENU_REQUEST
), ToString(newState
));
907 return CallbackMenuStateChanged(newState
);
910 void CCECClient::AddKey(bool bSendComboKey
/* = false */)
913 key
.keycode
= CEC_USER_CONTROL_CODE_UNKNOWN
;
916 CLockObject
lock(m_mutex
);
917 if (m_iCurrentButton
!= CEC_USER_CONTROL_CODE_UNKNOWN
)
919 key
.duration
= (unsigned int) (GetTimeMs() - m_buttontime
);
921 if (key
.duration
> COMBO_TIMEOUT_MS
|| m_iCurrentButton
!= COMBO_KEY
|| bSendComboKey
)
923 key
.keycode
= m_iCurrentButton
;
925 m_iCurrentButton
= CEC_USER_CONTROL_CODE_UNKNOWN
;
931 if (key
.keycode
!= CEC_USER_CONTROL_CODE_UNKNOWN
)
933 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "key released: %s (%1x)", ToString(key
.keycode
), key
.keycode
);
938 void CCECClient::AddKey(const cec_keypress
&key
)
940 // send back the previous key if there is one
943 cec_keypress
transmitKey(key
);
946 CLockObject
lock(m_mutex
);
947 if (key
.duration
> 0 || key
.keycode
> CEC_USER_CONTROL_CODE_MAX
)
949 transmitKey
.keycode
= CEC_USER_CONTROL_CODE_UNKNOWN
;
951 else if (m_iCurrentButton
== COMBO_KEY
)
954 if (key
.keycode
== CEC_USER_CONTROL_CODE_SELECT
)
955 transmitKey
.keycode
= CEC_USER_CONTROL_CODE_EXIT
;
956 // stop + pause -> root menu
957 else if (key
.keycode
== CEC_USER_CONTROL_CODE_ROOT_MENU
)
958 transmitKey
.keycode
= CEC_USER_CONTROL_CODE_ROOT_MENU
;
959 // stop + play -> dot (which is handled as context menu in xbmc)
960 else if (key
.keycode
== CEC_USER_CONTROL_CODE_PLAY
)
961 transmitKey
.keycode
= CEC_USER_CONTROL_CODE_DOT
;
962 // default, send back the previous key
967 m_iCurrentButton
= transmitKey
.keycode
;
968 m_buttontime
= m_iCurrentButton
== CEC_USER_CONTROL_CODE_UNKNOWN
|| key
.duration
> 0 ? 0 : GetTimeMs();
971 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "key pressed: %s (%1x)", ToString(transmitKey
.keycode
), transmitKey
.keycode
);
972 CallbackAddKey(transmitKey
);
975 void CCECClient::SetCurrentButton(const cec_user_control_code iButtonCode
)
977 // push a keypress to the buffer with 0 duration and another with the duration set when released
980 key
.keycode
= iButtonCode
;
985 void CCECClient::CheckKeypressTimeout(void)
990 CLockObject
lock(m_mutex
);
991 uint64_t iNow
= GetTimeMs();
993 if (m_iCurrentButton
!= CEC_USER_CONTROL_CODE_UNKNOWN
&&
994 ((m_iCurrentButton
== COMBO_KEY
&& iNow
- m_buttontime
> COMBO_TIMEOUT_MS
) ||
995 (m_iCurrentButton
!= COMBO_KEY
&& iNow
- m_buttontime
> CEC_BUTTON_TIMEOUT
)))
997 key
.duration
= (unsigned int) (iNow
- m_buttontime
);
998 key
.keycode
= m_iCurrentButton
;
1000 m_iCurrentButton
= CEC_USER_CONTROL_CODE_UNKNOWN
;
1009 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "key auto-released: %s (%1x)", ToString(key
.keycode
), key
.keycode
);
1010 CallbackAddKey(key
);
1013 bool CCECClient::EnableCallbacks(void *cbParam
, ICECCallbacks
*callbacks
)
1015 CLockObject
lock(m_cbMutex
);
1016 m_configuration
.callbackParam
= cbParam
;
1017 m_configuration
.callbacks
= callbacks
;
1021 bool CCECClient::PingAdapter(void)
1023 return m_processor
? m_processor
->PingAdapter() : false;
1026 std::string
CCECClient::GetConnectionInfo(void)
1029 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
);
1030 if (m_configuration
.iFirmwareBuildDate
!= CEC_FW_BUILD_UNKNOWN
)
1032 time_t buildTime
= (time_t)m_configuration
.iFirmwareBuildDate
;
1033 strLog
.AppendFormat(", firmware build date: %s", asctime(gmtime(&buildTime
)));
1034 strLog
= strLog
.substr(0, strLog
.length() > 0 ? (size_t)(strLog
.length() - 1) : 0); // strip \n added by asctime
1035 strLog
.append(" +0000");
1038 // log the addresses that are being used
1039 if (!m_configuration
.logicalAddresses
.IsEmpty())
1041 strLog
.append(", logical address(es) = ");
1042 CECDEVICEVEC devices
;
1043 m_processor
->GetDevices()->GetByLogicalAddresses(devices
, m_configuration
.logicalAddresses
);
1044 for (CECDEVICEVEC::iterator it
= devices
.begin(); it
!= devices
.end(); it
++)
1045 strLog
.AppendFormat("%s (%X) ", (*it
)->GetLogicalAddressName(), (*it
)->GetLogicalAddress());
1048 if (!CLibCEC::IsValidPhysicalAddress(m_configuration
.iPhysicalAddress
))
1049 strLog
.AppendFormat(", base device: %s (%X), HDMI port number: %d", ToString(m_configuration
.baseDevice
), m_configuration
.baseDevice
, m_configuration
.iHDMIPort
);
1050 uint16_t iPhysicalAddress
= GetPrimaryDevice()->GetPhysicalAddress(GetLogicalAddresses().primary
, false);
1051 strLog
.AppendFormat(", physical address: %x.%x.%x.%x", (iPhysicalAddress
>> 12) & 0xF, (iPhysicalAddress
>> 8) & 0xF, (iPhysicalAddress
>> 4) & 0xF, iPhysicalAddress
& 0xF);
1053 strLog
.AppendFormat(", %s", LIB_CEC
->GetLibInfo());
1055 std::string
strReturn(strLog
.c_str());
1059 void CCECClient::SetTVVendorOverride(const cec_vendor_id id
)
1062 CLockObject
lock(m_mutex
);
1063 m_configuration
.tvVendor
= id
;
1066 if (id
!= CEC_VENDOR_UNKNOWN
)
1068 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "%s - vendor id '%s'", __FUNCTION__
, ToString(id
));
1070 CCECBusDevice
*tv
= m_processor
? m_processor
->GetTV() : NULL
;
1072 tv
->SetVendorId((uint64_t)id
);
1075 // persist the new configuration
1076 PersistConfiguration(m_configuration
);
1079 cec_vendor_id
CCECClient::GetTVVendorOverride(void)
1081 CLockObject
lock(m_mutex
);
1082 return (cec_vendor_id
)m_configuration
.tvVendor
;
1085 void CCECClient::SetOSDName(const std::string
&strDeviceName
)
1088 CLockObject
lock(m_mutex
);
1089 snprintf(m_configuration
.strDeviceName
, 13, "%s", strDeviceName
.c_str());
1092 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "%s - using OSD name '%s'", __FUNCTION__
, strDeviceName
.c_str());
1094 CCECBusDevice
*primary
= GetPrimaryDevice();
1095 if (primary
&& !primary
->GetCurrentOSDName().Equals(strDeviceName
.c_str()))
1097 primary
->SetOSDName(strDeviceName
);
1098 if (m_processor
&& m_processor
->CECInitialised())
1099 primary
->TransmitOSDName(CECDEVICE_TV
, false);
1102 // persist the new configuration
1103 PersistConfiguration(m_configuration
);
1106 std::string
CCECClient::GetOSDName(void)
1108 CLockObject
lock(m_mutex
);
1109 std::string
strOSDName(m_configuration
.strDeviceName
);
1113 void CCECClient::SetWakeDevices(const cec_logical_addresses
&addresses
)
1116 CLockObject
lock(m_mutex
);
1117 m_configuration
.wakeDevices
= addresses
;
1119 // persist the new configuration
1120 PersistConfiguration(m_configuration
);
1123 cec_logical_addresses
CCECClient::GetWakeDevices(void)
1125 CLockObject
lock(m_mutex
);
1126 return m_configuration
.wakeDevices
;
1129 bool CCECClient::AutodetectPhysicalAddress(void)
1131 bool bPhysicalAutodetected(false);
1132 uint16_t iPhysicalAddress
= m_processor
? m_processor
->GetDetectedPhysicalAddress() : CEC_INVALID_PHYSICAL_ADDRESS
;
1134 if (CLibCEC::IsValidPhysicalAddress(iPhysicalAddress
))
1136 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "%s - autodetected physical address '%04X'", __FUNCTION__
, iPhysicalAddress
);
1138 CLockObject
lock(m_mutex
);
1139 m_configuration
.iPhysicalAddress
= iPhysicalAddress
;
1140 m_configuration
.iHDMIPort
= CEC_HDMI_PORTNUMBER_NONE
;
1141 m_configuration
.baseDevice
= CECDEVICE_UNKNOWN
;
1142 bPhysicalAutodetected
= true;
1145 SetDevicePhysicalAddress(iPhysicalAddress
);
1147 return bPhysicalAutodetected
;
1150 void CCECClient::SetClientVersion(const cec_client_version version
)
1152 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "%s - using client version '%s'", __FUNCTION__
, ToString(version
));
1154 CLockObject
lock(m_mutex
);
1155 m_configuration
.clientVersion
= (uint32_t)version
;
1158 cec_client_version
CCECClient::GetClientVersion(void)
1160 CLockObject
lock(m_mutex
);
1161 return (cec_client_version
)m_configuration
.clientVersion
;
1164 bool CCECClient::SetDeviceTypes(const cec_device_type_list
&deviceTypes
)
1166 bool bNeedReinit(false);
1169 CLockObject
lock(m_mutex
);
1170 bNeedReinit
= m_processor
&& m_processor
->CECInitialised() &&
1171 (m_configuration
.deviceTypes
!= deviceTypes
);
1172 m_configuration
.deviceTypes
= deviceTypes
;
1175 // persist the new configuration
1176 PersistConfiguration(m_configuration
);
1179 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "%s - using primary device type '%s'", __FUNCTION__
, ToString(deviceTypes
[0]));
1184 cec_device_type_list
CCECClient::GetDeviceTypes(void)
1186 cec_device_type_list retVal
;
1187 CLockObject
lock(m_mutex
);
1188 retVal
= m_configuration
.deviceTypes
;
1192 bool CCECClient::SetDevicePhysicalAddress(const uint16_t iPhysicalAddress
)
1194 if (!CLibCEC::IsValidPhysicalAddress(iPhysicalAddress
))
1196 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "%s - not setting invalid physical address %04x", __FUNCTION__
, iPhysicalAddress
);
1200 // reconfigure all devices
1201 cec_logical_address
reactivateSource(CECDEVICE_UNKNOWN
);
1202 CECDEVICEVEC devices
;
1203 m_processor
->GetDevices()->GetByLogicalAddresses(devices
, m_configuration
.logicalAddresses
);
1204 for (CECDEVICEVEC::iterator it
= devices
.begin(); it
!= devices
.end(); it
++)
1206 // if this device was the active source, reactivate it afterwards
1207 if ((*it
)->IsActiveSource())
1208 reactivateSource
= (*it
)->GetLogicalAddress();
1210 // mark the device as inactive source
1211 if (IsInitialised())
1212 (*it
)->MarkAsInactiveSource();
1214 // set the new physical address
1215 (*it
)->SetPhysicalAddress(iPhysicalAddress
);
1218 if (IsInitialised())
1219 (*it
)->TransmitPhysicalAddress(false);
1222 // reactivate the previous active source
1223 if (reactivateSource
!= CECDEVICE_UNKNOWN
&&
1224 m_processor
->CECInitialised() &&
1227 CCECBusDevice
*device
= m_processor
->GetDevice(reactivateSource
);
1229 device
->ActivateSource();
1232 // persist the new configuration
1233 PersistConfiguration(m_configuration
);
1238 bool CCECClient::SwitchMonitoring(bool bEnable
)
1240 LIB_CEC
->AddLog(CEC_LOG_NOTICE
, "== %s monitoring mode ==", bEnable
? "enabling" : "disabling");
1244 m_processor
->SwitchMonitoring(bEnable
);
1245 m_configuration
.bMonitorOnly
= bEnable
;
1246 return bEnable
? true: m_processor
->RegisterClient(this);
1252 bool CCECClient::PollDevice(const cec_logical_address iAddress
)
1254 // try to find the primary device
1255 CCECBusDevice
*primary
= GetPrimaryDevice();
1256 // poll the destination, with the primary as source
1258 return primary
->TransmitPoll(iAddress
, false);
1260 return m_processor
? m_processor
->PollDevice(iAddress
) : false;
1263 cec_logical_addresses
CCECClient::GetActiveDevices(void)
1265 CECDEVICEVEC activeDevices
;
1267 m_processor
->GetDevices()->GetActive(activeDevices
);
1268 return CCECDeviceMap::ToLogicalAddresses(activeDevices
);
1271 bool CCECClient::IsActiveDevice(const cec_logical_address iAddress
)
1273 cec_logical_addresses activeDevices
= GetActiveDevices();
1274 return activeDevices
.IsSet(iAddress
);
1277 bool CCECClient::IsActiveDeviceType(const cec_device_type type
)
1279 CECDEVICEVEC activeDevices
;
1281 m_processor
->GetDevices()->GetActive(activeDevices
);
1282 CCECDeviceMap::FilterType(type
, activeDevices
);
1283 return !activeDevices
.empty();
1286 cec_logical_address
CCECClient::GetActiveSource(void)
1288 return m_processor
? m_processor
->GetActiveSource() : CECDEVICE_UNKNOWN
;
1291 bool CCECClient::IsActiveSource(const cec_logical_address iAddress
)
1293 return m_processor
? m_processor
->IsActiveSource(iAddress
) : false;
1296 bool CCECClient::SetStreamPath(const cec_logical_address iAddress
)
1298 uint16_t iPhysicalAddress
= GetDevicePhysicalAddress(iAddress
);
1299 if (iPhysicalAddress
!= CEC_INVALID_PHYSICAL_ADDRESS
)
1300 return SetStreamPath(iPhysicalAddress
);
1304 bool CCECClient::SetStreamPath(const uint16_t iPhysicalAddress
)
1306 bool bReturn(false);
1308 CCECBusDevice
*device
= GetDeviceByType(CEC_DEVICE_TYPE_TV
);
1311 device
->SetStreamPath(iPhysicalAddress
);
1312 bReturn
= device
->GetHandler()->TransmitSetStreamPath(iPhysicalAddress
, false);
1313 device
->MarkHandlerReady();
1317 LIB_CEC
->AddLog(CEC_LOG_ERROR
, "only the TV is allowed to send CEC_OPCODE_SET_STREAM_PATH");
1323 cec_logical_addresses
CCECClient::GetLogicalAddresses(void)
1325 cec_logical_addresses addresses
;
1326 CLockObject
lock(m_mutex
);
1327 addresses
= m_configuration
.logicalAddresses
;
1331 bool CCECClient::CanPersistConfiguration(void)
1333 return m_processor
? m_processor
->CanPersistConfiguration() : false;
1336 bool CCECClient::PersistConfiguration(const libcec_configuration
&configuration
)
1338 return m_processor
&& IsRegistered() ?
1339 m_processor
->PersistConfiguration(configuration
) :
1343 void CCECClient::RescanActiveDevices(void)
1346 m_processor
->RescanActiveDevices();
1349 bool CCECClient::IsLibCECActiveSource(void)
1351 bool bReturn(false);
1354 cec_logical_address activeSource
= m_processor
->GetActiveSource();
1355 CCECBusDevice
*device
= m_processor
->GetDevice(activeSource
);
1357 bReturn
= device
->IsHandledByLibCEC() && !device
->GetHandler()->ActiveSourcePending();
1362 void CCECClient::SourceActivated(const cec_logical_address logicalAddress
)
1364 LIB_CEC
->AddLog(CEC_LOG_NOTICE
, ">> source activated: %s (%x)", ToString(logicalAddress
), logicalAddress
);
1365 CallbackSourceActivated(true, logicalAddress
);
1368 void CCECClient::SourceDeactivated(const cec_logical_address logicalAddress
)
1370 LIB_CEC
->AddLog(CEC_LOG_NOTICE
, ">> source deactivated: %s (%x)", ToString(logicalAddress
), logicalAddress
);
1371 CallbackSourceActivated(false, logicalAddress
);
1374 void CCECClient::CallbackAddCommand(const cec_command
&command
)
1376 CLockObject
lock(m_cbMutex
);
1377 if (m_configuration
.callbacks
&& m_configuration
.callbacks
->CBCecCommand
)
1378 m_configuration
.callbacks
->CBCecCommand(m_configuration
.callbackParam
, command
);
1381 void CCECClient::CallbackAddKey(const cec_keypress
&key
)
1383 CLockObject
lock(m_cbMutex
);
1384 if (m_configuration
.callbacks
&& m_configuration
.callbacks
->CBCecKeyPress
)
1386 // prevent double taps
1387 int64_t now
= GetTimeMs();
1388 if (m_lastKeypress
.keycode
!= key
.keycode
||
1390 now
- m_iLastKeypressTime
>= m_configuration
.iDoubleTapTimeoutMs
)
1393 if (key
.duration
== 0)
1394 m_iLastKeypressTime
= now
;
1395 m_lastKeypress
= key
;
1396 m_configuration
.callbacks
->CBCecKeyPress(m_configuration
.callbackParam
, key
);
1401 void CCECClient::CallbackAddLog(const cec_log_message
&message
)
1403 CLockObject
lock(m_cbMutex
);
1404 if (m_configuration
.callbacks
&& m_configuration
.callbacks
->CBCecLogMessage
)
1405 m_configuration
.callbacks
->CBCecLogMessage(m_configuration
.callbackParam
, message
);
1408 void CCECClient::CallbackConfigurationChanged(const libcec_configuration
&config
)
1410 CLockObject
lock(m_cbMutex
);
1411 if (m_configuration
.callbacks
&&
1412 m_configuration
.callbacks
->CBCecConfigurationChanged
&&
1413 m_processor
->CECInitialised())
1414 m_configuration
.callbacks
->CBCecConfigurationChanged(m_configuration
.callbackParam
, config
);
1417 void CCECClient::CallbackSourceActivated(bool bActivated
, const cec_logical_address logicalAddress
)
1419 CLockObject
lock(m_cbMutex
);
1420 if (m_configuration
.callbacks
&&
1421 m_configuration
.callbacks
->CBCecSourceActivated
)
1422 m_configuration
.callbacks
->CBCecSourceActivated(m_configuration
.callbackParam
, logicalAddress
, bActivated
? 1 : 0);
1425 void CCECClient::CallbackAlert(const libcec_alert type
, const libcec_parameter
¶m
)
1427 CLockObject
lock(m_cbMutex
);
1428 if (m_configuration
.callbacks
&&
1429 m_configuration
.callbacks
->CBCecAlert
)
1430 m_configuration
.callbacks
->CBCecAlert(m_configuration
.callbackParam
, type
, param
);
1433 int CCECClient::CallbackMenuStateChanged(const cec_menu_state newState
)
1435 CLockObject
lock(m_cbMutex
);
1436 if (m_configuration
.callbacks
&&
1437 m_configuration
.callbacks
->CBCecMenuStateChanged
)
1438 return m_configuration
.callbacks
->CBCecMenuStateChanged(m_configuration
.callbackParam
, newState
);