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/
35 #include "adapter/USBCECAdapterDetection.h"
36 #include "adapter/USBCECAdapterCommunication.h"
37 #include "CECProcessor.h"
38 #include "devices/CECAudioSystem.h"
39 #include "devices/CECBusDevice.h"
40 #include "devices/CECPlaybackDevice.h"
41 #include "devices/CECTV.h"
42 #include "platform/util/timeutils.h"
43 #include "platform/util/StdString.h"
45 #include "CECClient.h"
49 using namespace PLATFORM
;
51 CLibCEC::CLibCEC(const char *UNUSED(strDeviceName
), cec_device_type_list
UNUSED(types
), uint16_t UNUSED(iPhysicalAddress
) /* = 0 */) :
52 m_iStartTime(GetTimeMs()),
55 m_cec
= new CCECProcessor(this);
58 CLibCEC::CLibCEC(libcec_configuration
*UNUSED(configuration
)) :
59 m_iStartTime(GetTimeMs()),
62 m_cec
= new CCECProcessor(this);
65 CLibCEC::~CLibCEC(void)
73 bool CLibCEC::Open(const char *strPort
, uint32_t iTimeoutMs
/* = CEC_DEFAULT_CONNECT_TIMEOUT */)
78 if (m_cec
->IsRunning())
80 AddLog(CEC_LOG_ERROR
, "connection already open");
84 if (!m_cec
->Start(strPort
, CEC_SERIAL_DEFAULT_BAUDRATE
, iTimeoutMs
))
86 AddLog(CEC_LOG_ERROR
, "could not start CEC communications");
90 for (vector
<CCECClient
*>::iterator it
= m_clients
.begin(); it
!= m_clients
.end(); it
++)
92 if (!m_cec
->RegisterClient(*it
))
94 AddLog(CEC_LOG_ERROR
, "failed to register a CEC client");
102 void CLibCEC::Close(void)
107 for (vector
<CCECClient
*>::iterator it
= m_clients
.begin(); it
!= m_clients
.end(); it
++)
109 (*it
)->SetRegistered(false);
110 (*it
)->SetInitialised(false);
114 int8_t CLibCEC::FindAdapters(cec_adapter
*deviceList
, uint8_t iBufSize
, const char *strDevicePath
/* = NULL */)
116 return CUSBCECAdapterDetection::FindAdapters(deviceList
, iBufSize
, strDevicePath
);
119 bool CLibCEC::PingAdapter(void)
121 return m_cec
? m_cec
->PingAdapter() : false;
124 bool CLibCEC::StartBootloader(void)
126 return m_cec
? m_cec
->StartBootloader() : false;
129 bool CLibCEC::SwitchMonitoring(bool bEnable
)
131 return m_cec
? m_cec
->SwitchMonitoring(bEnable
) : false;
134 cec_logical_address
CLibCEC::GetActiveSource(void)
136 return m_cec
? m_cec
->GetActiveSource() : CECDEVICE_UNKNOWN
;
139 bool CLibCEC::IsActiveSource(cec_logical_address iAddress
)
141 return m_cec
? m_cec
->IsActiveSource(iAddress
) : false;
144 bool CLibCEC::PollDevice(cec_logical_address iAddress
)
146 return m_cec
? m_cec
->PollDevice(iAddress
) : false;
149 cec_logical_addresses
CLibCEC::GetActiveDevices(void)
151 CECDEVICEVEC activeDevices
;
153 m_cec
->GetDevices()->GetActive(activeDevices
);
154 return CCECDeviceMap::ToLogicalAddresses(activeDevices
);
157 bool CLibCEC::IsActiveDevice(cec_logical_address iAddress
)
159 cec_logical_addresses activeDevices
= GetActiveDevices();
160 return activeDevices
.IsSet(iAddress
);
163 bool CLibCEC::IsActiveDeviceType(cec_device_type type
)
165 CECDEVICEVEC activeDevices
;
167 m_cec
->GetDevices()->GetActive(activeDevices
);
168 CCECDeviceMap::FilterType(type
, activeDevices
);
169 return !activeDevices
.empty();
172 bool CLibCEC::SetStreamPath(cec_logical_address iAddress
)
174 uint16_t iPhysicalAddress
= GetDevicePhysicalAddress(iAddress
);
175 if (iPhysicalAddress
!= CEC_INVALID_PHYSICAL_ADDRESS
)
176 return SetStreamPath(iPhysicalAddress
);
180 bool CLibCEC::SetStreamPath(uint16_t iPhysicalAddress
)
182 return m_cec
->SetStreamPath(iPhysicalAddress
);
185 bool CLibCEC::IsLibCECActiveSource(void)
190 cec_logical_address activeSource
= m_cec
->GetActiveSource();
191 CCECBusDevice
*device
= m_cec
->GetDevice(activeSource
);
193 bReturn
= device
->IsHandledByLibCEC();
198 bool CLibCEC::CanPersistConfiguration(void)
200 return m_cec
->CanPersistConfiguration();
203 bool CLibCEC::PersistConfiguration(libcec_configuration
*configuration
)
205 return m_cec
->PersistConfiguration(configuration
);
208 void CLibCEC::RescanActiveDevices(void)
210 return m_cec
->RescanActiveDevices();
213 bool CLibCEC::EnableCallbacks(void *cbParam
, ICECCallbacks
*callbacks
)
215 return m_client
? m_client
->EnableCallbacks(cbParam
, callbacks
) : false;
218 bool CLibCEC::GetCurrentConfiguration(libcec_configuration
*configuration
)
220 return m_client
? m_client
->GetCurrentConfiguration(configuration
) : false;
223 bool CLibCEC::SetConfiguration(const libcec_configuration
*configuration
)
225 return m_client
? m_client
->SetConfiguration(configuration
) : false;
228 bool CLibCEC::Transmit(const cec_command
&data
)
230 return m_client
? m_client
->Transmit(data
) : false;
233 bool CLibCEC::SetLogicalAddress(cec_logical_address iLogicalAddress
)
235 return m_client
? m_client
->SetLogicalAddress(iLogicalAddress
) : false;
238 bool CLibCEC::SetPhysicalAddress(uint16_t iPhysicalAddress
/* = CEC_DEFAULT_PHYSICAL_ADDRESS */)
240 return m_client
? m_client
->SetPhysicalAddress(iPhysicalAddress
) : false;
243 bool CLibCEC::SetHDMIPort(cec_logical_address iBaseDevice
, uint8_t iPort
/* = CEC_DEFAULT_HDMI_PORT */)
245 return m_client
? m_client
->SetHDMIPort(iBaseDevice
, iPort
) : false;
248 bool CLibCEC::PowerOnDevices(cec_logical_address address
/* = CECDEVICE_TV */)
250 return m_client
? m_client
->SendPowerOnDevices(address
) : false;
253 bool CLibCEC::StandbyDevices(cec_logical_address address
/* = CECDEVICE_BROADCAST */)
255 return m_client
? m_client
->SendStandbyDevices(address
) : false;
258 bool CLibCEC::SetActiveSource(cec_device_type type
/* = CEC_DEVICE_TYPE_RESERVED */)
260 return m_client
? m_client
->SendSetActiveSource(type
) : false;
263 bool CLibCEC::SetDeckControlMode(cec_deck_control_mode mode
, bool bSendUpdate
/* = true */)
265 return m_client
? m_client
->SendSetDeckControlMode(mode
, bSendUpdate
) : false;
268 bool CLibCEC::SetDeckInfo(cec_deck_info info
, bool bSendUpdate
/* = true */)
270 return m_client
? m_client
->SendSetDeckInfo(info
, bSendUpdate
) : false;
273 bool CLibCEC::SetInactiveView(void)
275 return m_client
? m_client
->SendSetInactiveView() : false;
278 bool CLibCEC::SetMenuState(cec_menu_state state
, bool bSendUpdate
/* = true */)
280 return m_client
? m_client
->SendSetMenuState(state
, bSendUpdate
) : false;
283 bool CLibCEC::SetOSDString(cec_logical_address iLogicalAddress
, cec_display_control duration
, const char *strMessage
)
285 return m_client
? m_client
->SendSetOSDString(iLogicalAddress
, duration
, strMessage
) : false;
288 cec_version
CLibCEC::GetDeviceCecVersion(cec_logical_address iAddress
)
290 return m_client
? m_client
->GetDeviceCecVersion(iAddress
) : CEC_VERSION_UNKNOWN
;
293 bool CLibCEC::GetDeviceMenuLanguage(cec_logical_address iAddress
, cec_menu_language
*language
)
295 return m_client
? m_client
->GetDeviceMenuLanguage(iAddress
, language
) : false;
298 uint64_t CLibCEC::GetDeviceVendorId(cec_logical_address iAddress
)
300 return m_client
? m_client
->GetDeviceVendorId(iAddress
) : (uint64_t)CEC_VENDOR_UNKNOWN
;
303 uint16_t CLibCEC::GetDevicePhysicalAddress(cec_logical_address iAddress
)
305 return m_client
? m_client
->GetDevicePhysicalAddress(iAddress
) : CEC_INVALID_PHYSICAL_ADDRESS
;
308 cec_power_status
CLibCEC::GetDevicePowerStatus(cec_logical_address iAddress
)
310 return m_client
? m_client
->GetDevicePowerStatus(iAddress
) : CEC_POWER_STATUS_UNKNOWN
;
313 uint8_t CLibCEC::VolumeUp(bool bSendRelease
/* = true */)
315 return m_client
? m_client
->SendVolumeUp(bSendRelease
) : (uint8_t)CEC_AUDIO_VOLUME_STATUS_UNKNOWN
;
318 uint8_t CLibCEC::VolumeDown(bool bSendRelease
/* = true */)
320 return m_client
? m_client
->SendVolumeDown(bSendRelease
) : (uint8_t)CEC_AUDIO_VOLUME_STATUS_UNKNOWN
;
323 uint8_t CLibCEC::MuteAudio(bool UNUSED(bSendRelease
) /* = true */)
325 return m_client
? m_client
->SendMuteAudio() : (uint8_t)CEC_AUDIO_VOLUME_STATUS_UNKNOWN
;
328 bool CLibCEC::SendKeypress(cec_logical_address iDestination
, cec_user_control_code key
, bool bWait
/* = true */)
330 return m_client
? m_client
->SendKeypress(iDestination
, key
, bWait
) : false;
333 bool CLibCEC::SendKeyRelease(cec_logical_address iDestination
, bool bWait
/* = true */)
335 return m_client
? m_client
->SendKeyRelease(iDestination
, bWait
) : false;
338 cec_osd_name
CLibCEC::GetDeviceOSDName(cec_logical_address iAddress
)
341 retVal
.device
= CECDEVICE_UNKNOWN
;
342 memset(retVal
.name
, 0, 14);
345 retVal
= m_client
->GetDeviceOSDName(iAddress
);
349 cec_logical_addresses
CLibCEC::GetLogicalAddresses(void)
351 cec_logical_addresses addresses
;
354 addresses
= m_cec
->GetLogicalAddresses();
358 bool CLibCEC::GetNextLogMessage(cec_log_message
*message
)
360 return m_client
? m_client
->GetNextLogMessage(message
) : false;
363 bool CLibCEC::GetNextKeypress(cec_keypress
*key
)
365 return m_client
? m_client
->GetNextKeypress(key
) : false;
368 bool CLibCEC::GetNextCommand(cec_command
*command
)
370 return m_client
? m_client
->GetNextCommand(command
) : false;
373 cec_device_type
CLibCEC::GetType(cec_logical_address address
)
377 case CECDEVICE_AUDIOSYSTEM
:
378 return CEC_DEVICE_TYPE_AUDIO_SYSTEM
;
379 case CECDEVICE_PLAYBACKDEVICE1
:
380 case CECDEVICE_PLAYBACKDEVICE2
:
381 case CECDEVICE_PLAYBACKDEVICE3
:
382 return CEC_DEVICE_TYPE_PLAYBACK_DEVICE
;
383 case CECDEVICE_RECORDINGDEVICE1
:
384 case CECDEVICE_RECORDINGDEVICE2
:
385 case CECDEVICE_RECORDINGDEVICE3
:
386 return CEC_DEVICE_TYPE_RECORDING_DEVICE
;
387 case CECDEVICE_TUNER1
:
388 case CECDEVICE_TUNER2
:
389 case CECDEVICE_TUNER3
:
390 case CECDEVICE_TUNER4
:
391 return CEC_DEVICE_TYPE_TUNER
;
393 return CEC_DEVICE_TYPE_TV
;
395 return CEC_DEVICE_TYPE_RESERVED
;
399 uint16_t CLibCEC::GetMaskForType(cec_logical_address address
)
401 return GetMaskForType(GetType(address
));
404 uint16_t CLibCEC::GetMaskForType(cec_device_type type
)
408 case CEC_DEVICE_TYPE_AUDIO_SYSTEM
:
410 cec_logical_addresses addr
;
412 addr
.Set(CECDEVICE_AUDIOSYSTEM
);
413 return addr
.AckMask();
415 case CEC_DEVICE_TYPE_PLAYBACK_DEVICE
:
417 cec_logical_addresses addr
;
419 addr
.Set(CECDEVICE_PLAYBACKDEVICE1
);
420 addr
.Set(CECDEVICE_PLAYBACKDEVICE2
);
421 addr
.Set(CECDEVICE_PLAYBACKDEVICE3
);
422 return addr
.AckMask();
424 case CEC_DEVICE_TYPE_RECORDING_DEVICE
:
426 cec_logical_addresses addr
;
428 addr
.Set(CECDEVICE_RECORDINGDEVICE1
);
429 addr
.Set(CECDEVICE_RECORDINGDEVICE2
);
430 addr
.Set(CECDEVICE_RECORDINGDEVICE3
);
431 return addr
.AckMask();
433 case CEC_DEVICE_TYPE_TUNER
:
435 cec_logical_addresses addr
;
437 addr
.Set(CECDEVICE_TUNER1
);
438 addr
.Set(CECDEVICE_TUNER2
);
439 addr
.Set(CECDEVICE_TUNER3
);
440 addr
.Set(CECDEVICE_TUNER4
);
441 return addr
.AckMask();
443 case CEC_DEVICE_TYPE_TV
:
445 cec_logical_addresses addr
;
447 addr
.Set(CECDEVICE_TV
);
448 return addr
.AckMask();
455 bool CLibCEC::IsValidPhysicalAddress(uint16_t iPhysicalAddress
)
457 return iPhysicalAddress
>= CEC_MIN_PHYSICAL_ADDRESS
&&
458 iPhysicalAddress
<= CEC_MAX_PHYSICAL_ADDRESS
;
461 const char *CLibCEC::ToString(const cec_device_type type
)
465 case CEC_DEVICE_TYPE_AUDIO_SYSTEM
:
466 return "audio system";
467 case CEC_DEVICE_TYPE_PLAYBACK_DEVICE
:
468 return "playback device";
469 case CEC_DEVICE_TYPE_RECORDING_DEVICE
:
470 return "recording device";
471 case CEC_DEVICE_TYPE_RESERVED
:
473 case CEC_DEVICE_TYPE_TUNER
:
475 case CEC_DEVICE_TYPE_TV
:
482 const char *CLibCEC::ToString(const cec_menu_state state
)
486 case CEC_MENU_STATE_ACTIVATED
:
488 case CEC_MENU_STATE_DEACTIVATED
:
489 return "deactivated";
495 const char *CLibCEC::ToString(const cec_version version
)
499 case CEC_VERSION_1_2
:
501 case CEC_VERSION_1_2A
:
503 case CEC_VERSION_1_3
:
505 case CEC_VERSION_1_3A
:
507 case CEC_VERSION_1_4
:
514 const char *CLibCEC::ToString(const cec_power_status status
)
518 case CEC_POWER_STATUS_ON
:
520 case CEC_POWER_STATUS_STANDBY
:
522 case CEC_POWER_STATUS_IN_TRANSITION_ON_TO_STANDBY
:
523 return "in transition from on to standby";
524 case CEC_POWER_STATUS_IN_TRANSITION_STANDBY_TO_ON
:
525 return "in transition from standby to on";
531 const char *CLibCEC::ToString(const cec_logical_address address
)
535 case CECDEVICE_AUDIOSYSTEM
:
537 case CECDEVICE_BROADCAST
:
539 case CECDEVICE_FREEUSE
:
541 case CECDEVICE_PLAYBACKDEVICE1
:
543 case CECDEVICE_PLAYBACKDEVICE2
:
545 case CECDEVICE_PLAYBACKDEVICE3
:
547 case CECDEVICE_RECORDINGDEVICE1
:
549 case CECDEVICE_RECORDINGDEVICE2
:
551 case CECDEVICE_RECORDINGDEVICE3
:
553 case CECDEVICE_RESERVED1
:
555 case CECDEVICE_RESERVED2
:
557 case CECDEVICE_TUNER1
:
559 case CECDEVICE_TUNER2
:
561 case CECDEVICE_TUNER3
:
563 case CECDEVICE_TUNER4
:
572 const char *CLibCEC::ToString(const cec_deck_control_mode mode
)
576 case CEC_DECK_CONTROL_MODE_SKIP_FORWARD_WIND
:
577 return "skip forward wind";
578 case CEC_DECK_CONTROL_MODE_EJECT
:
580 case CEC_DECK_CONTROL_MODE_SKIP_REVERSE_REWIND
:
581 return "reverse rewind";
582 case CEC_DECK_CONTROL_MODE_STOP
:
589 const char *CLibCEC::ToString(const cec_deck_info status
)
593 case CEC_DECK_INFO_PLAY
:
595 case CEC_DECK_INFO_RECORD
:
597 case CEC_DECK_INFO_PLAY_REVERSE
:
598 return "play reverse";
599 case CEC_DECK_INFO_STILL
:
601 case CEC_DECK_INFO_SLOW
:
603 case CEC_DECK_INFO_SLOW_REVERSE
:
604 return "slow reverse";
605 case CEC_DECK_INFO_FAST_FORWARD
:
606 return "fast forward";
607 case CEC_DECK_INFO_FAST_REVERSE
:
608 return "fast reverse";
609 case CEC_DECK_INFO_NO_MEDIA
:
611 case CEC_DECK_INFO_STOP
:
613 case CEC_DECK_INFO_SKIP_FORWARD_WIND
:
614 return "info skip forward wind";
615 case CEC_DECK_INFO_SKIP_REVERSE_REWIND
:
616 return "info skip reverse rewind";
617 case CEC_DECK_INFO_INDEX_SEARCH_FORWARD
:
618 return "info index search forward";
619 case CEC_DECK_INFO_INDEX_SEARCH_REVERSE
:
620 return "info index search reverse";
621 case CEC_DECK_INFO_OTHER_STATUS
:
623 case CEC_DECK_INFO_OTHER_STATUS_LG
:
630 const char *CLibCEC::ToString(const cec_opcode opcode
)
634 case CEC_OPCODE_ACTIVE_SOURCE
:
635 return "active source";
636 case CEC_OPCODE_IMAGE_VIEW_ON
:
637 return "image view on";
638 case CEC_OPCODE_TEXT_VIEW_ON
:
639 return "text view on";
640 case CEC_OPCODE_INACTIVE_SOURCE
:
641 return "inactive source";
642 case CEC_OPCODE_REQUEST_ACTIVE_SOURCE
:
643 return "request active source";
644 case CEC_OPCODE_ROUTING_CHANGE
:
645 return "routing change";
646 case CEC_OPCODE_ROUTING_INFORMATION
:
647 return "routing information";
648 case CEC_OPCODE_SET_STREAM_PATH
:
649 return "set stream path";
650 case CEC_OPCODE_STANDBY
:
652 case CEC_OPCODE_RECORD_OFF
:
654 case CEC_OPCODE_RECORD_ON
:
656 case CEC_OPCODE_RECORD_STATUS
:
657 return "record status";
658 case CEC_OPCODE_RECORD_TV_SCREEN
:
659 return "record tv screen";
660 case CEC_OPCODE_CLEAR_ANALOGUE_TIMER
:
661 return "clear analogue timer";
662 case CEC_OPCODE_CLEAR_DIGITAL_TIMER
:
663 return "clear digital timer";
664 case CEC_OPCODE_CLEAR_EXTERNAL_TIMER
:
665 return "clear external timer";
666 case CEC_OPCODE_SET_ANALOGUE_TIMER
:
667 return "set analogue timer";
668 case CEC_OPCODE_SET_DIGITAL_TIMER
:
669 return "set digital timer";
670 case CEC_OPCODE_SET_EXTERNAL_TIMER
:
671 return "set external timer";
672 case CEC_OPCODE_SET_TIMER_PROGRAM_TITLE
:
673 return "set timer program title";
674 case CEC_OPCODE_TIMER_CLEARED_STATUS
:
675 return "timer cleared status";
676 case CEC_OPCODE_TIMER_STATUS
:
677 return "timer status";
678 case CEC_OPCODE_CEC_VERSION
:
679 return "cec version";
680 case CEC_OPCODE_GET_CEC_VERSION
:
681 return "get cec version";
682 case CEC_OPCODE_GIVE_PHYSICAL_ADDRESS
:
683 return "give physical address";
684 case CEC_OPCODE_GET_MENU_LANGUAGE
:
685 return "get menu language";
686 case CEC_OPCODE_REPORT_PHYSICAL_ADDRESS
:
687 return "report physical address";
688 case CEC_OPCODE_SET_MENU_LANGUAGE
:
689 return "set menu language";
690 case CEC_OPCODE_DECK_CONTROL
:
691 return "deck control";
692 case CEC_OPCODE_DECK_STATUS
:
693 return "deck status";
694 case CEC_OPCODE_GIVE_DECK_STATUS
:
695 return "give deck status";
696 case CEC_OPCODE_PLAY
:
698 case CEC_OPCODE_GIVE_TUNER_DEVICE_STATUS
:
699 return "give tuner status";
700 case CEC_OPCODE_SELECT_ANALOGUE_SERVICE
:
701 return "select analogue service";
702 case CEC_OPCODE_SELECT_DIGITAL_SERVICE
:
703 return "set digital service";
704 case CEC_OPCODE_TUNER_DEVICE_STATUS
:
705 return "tuner device status";
706 case CEC_OPCODE_TUNER_STEP_DECREMENT
:
707 return "tuner step decrement";
708 case CEC_OPCODE_TUNER_STEP_INCREMENT
:
709 return "tuner step increment";
710 case CEC_OPCODE_DEVICE_VENDOR_ID
:
711 return "device vendor id";
712 case CEC_OPCODE_GIVE_DEVICE_VENDOR_ID
:
713 return "give device vendor id";
714 case CEC_OPCODE_VENDOR_COMMAND
:
715 return "vendor command";
716 case CEC_OPCODE_VENDOR_COMMAND_WITH_ID
:
717 return "vendor command with id";
718 case CEC_OPCODE_VENDOR_REMOTE_BUTTON_DOWN
:
719 return "vendor remote button down";
720 case CEC_OPCODE_VENDOR_REMOTE_BUTTON_UP
:
721 return "vendor remote button up";
722 case CEC_OPCODE_SET_OSD_STRING
:
723 return "set osd string";
724 case CEC_OPCODE_GIVE_OSD_NAME
:
725 return "give osd name";
726 case CEC_OPCODE_SET_OSD_NAME
:
727 return "set osd name";
728 case CEC_OPCODE_MENU_REQUEST
:
729 return "menu request";
730 case CEC_OPCODE_MENU_STATUS
:
731 return "menu status";
732 case CEC_OPCODE_USER_CONTROL_PRESSED
:
733 return "user control pressed";
734 case CEC_OPCODE_USER_CONTROL_RELEASE
:
735 return "user control release";
736 case CEC_OPCODE_GIVE_DEVICE_POWER_STATUS
:
737 return "give device power status";
738 case CEC_OPCODE_REPORT_POWER_STATUS
:
739 return "report power status";
740 case CEC_OPCODE_FEATURE_ABORT
:
741 return "feature abort";
742 case CEC_OPCODE_ABORT
:
744 case CEC_OPCODE_GIVE_AUDIO_STATUS
:
745 return "give audio status";
746 case CEC_OPCODE_GIVE_SYSTEM_AUDIO_MODE_STATUS
:
747 return "give audio mode status";
748 case CEC_OPCODE_REPORT_AUDIO_STATUS
:
749 return "report audio status";
750 case CEC_OPCODE_SET_SYSTEM_AUDIO_MODE
:
751 return "set system audio mode";
752 case CEC_OPCODE_SYSTEM_AUDIO_MODE_REQUEST
:
753 return "system audio mode request";
754 case CEC_OPCODE_SYSTEM_AUDIO_MODE_STATUS
:
755 return "system audio mode status";
756 case CEC_OPCODE_SET_AUDIO_RATE
:
757 return "set audio rate";
758 case CEC_OPCODE_START_ARC
:
760 case CEC_OPCODE_REPORT_ARC_STARTED
:
761 return "report ARC started";
762 case CEC_OPCODE_REPORT_ARC_ENDED
:
763 return "report ARC ended";
764 case CEC_OPCODE_REQUEST_ARC_START
:
765 return "request ARC start";
766 case CEC_OPCODE_REQUEST_ARC_END
:
767 return "request ARC end";
768 case CEC_OPCODE_END_ARC
:
772 case CEC_OPCODE_NONE
:
779 const char *CLibCEC::ToString(const cec_system_audio_status mode
)
783 case CEC_SYSTEM_AUDIO_STATUS_ON
:
785 case CEC_SYSTEM_AUDIO_STATUS_OFF
:
792 const char *CLibCEC::ToString(const cec_audio_status
UNUSED(status
))
794 // TODO this is a mask
798 const char *CLibCEC::ToString(const cec_vendor_id vendor
)
802 case CEC_VENDOR_SAMSUNG
:
806 case CEC_VENDOR_PANASONIC
:
808 case CEC_VENDOR_PIONEER
:
810 case CEC_VENDOR_ONKYO
:
812 case CEC_VENDOR_YAMAHA
:
814 case CEC_VENDOR_PHILIPS
:
816 case CEC_VENDOR_SONY
:
818 case CEC_VENDOR_TOSHIBA
:
825 const char *CLibCEC::ToString(const cec_client_version version
)
829 case CEC_CLIENT_VERSION_PRE_1_5
:
831 case CEC_CLIENT_VERSION_1_5_0
:
833 case CEC_CLIENT_VERSION_1_5_1
:
835 case CEC_CLIENT_VERSION_1_5_2
:
837 case CEC_CLIENT_VERSION_1_5_3
:
839 case CEC_CLIENT_VERSION_1_6_0
:
841 case CEC_CLIENT_VERSION_1_6_1
:
843 case CEC_CLIENT_VERSION_1_6_2
:
850 const char *CLibCEC::ToString(const cec_server_version version
)
854 case CEC_SERVER_VERSION_PRE_1_5
:
856 case CEC_SERVER_VERSION_1_5_0
:
858 case CEC_SERVER_VERSION_1_5_1
:
860 case CEC_SERVER_VERSION_1_5_2
:
862 case CEC_SERVER_VERSION_1_5_3
:
864 case CEC_SERVER_VERSION_1_6_0
:
866 case CEC_SERVER_VERSION_1_6_1
:
868 case CEC_SERVER_VERSION_1_6_2
:
875 void CLibCEC::CheckKeypressTimeout(void)
878 for (vector
<CCECClient
*>::iterator it
= m_clients
.begin(); it
!= m_clients
.end(); it
++)
879 (*it
)->CheckKeypressTimeout();
882 void CLibCEC::AddLog(const cec_log_level level
, const char *strFormat
, ...)
887 va_start(argList
, strFormat
);
888 strLog
.FormatV(strFormat
, argList
);
891 cec_log_message message
;
892 message
.level
= level
;
893 message
.time
= GetTimeMs() - m_iStartTime
;
894 snprintf(message
.message
, sizeof(message
.message
), "%s", strLog
.c_str());
896 // send the message to all clients
897 for (vector
<CCECClient
*>::iterator it
= m_clients
.begin(); it
!= m_clients
.end(); it
++)
898 (*it
)->AddLog(message
);
901 void CLibCEC::Alert(const libcec_alert type
, const libcec_parameter
¶m
)
903 // send the alert to all clients
904 for (vector
<CCECClient
*>::iterator it
= m_clients
.begin(); it
!= m_clients
.end(); it
++)
905 (*it
)->Alert(type
, param
);
908 bool CLibCEC::SetActiveView(void)
910 AddLog(CEC_LOG_WARNING
, "deprecated method %s called", __FUNCTION__
);
911 return SetActiveSource();
914 bool CLibCEC::EnablePhysicalAddressDetection(void)
916 AddLog(CEC_LOG_WARNING
, "deprecated method %s called", __FUNCTION__
);
920 CCECClient
*CLibCEC::RegisterClient(libcec_configuration
*configuration
)
925 CCECClient
*newClient
= new CCECClient(m_cec
, configuration
);
929 m_clients
.push_back(newClient
);
931 m_client
= newClient
;
933 if (m_cec
->IsRunning())
934 m_cec
->RegisterClient(newClient
);
939 void CLibCEC::UnregisterClients(void)
946 void * CECInitialise(libcec_configuration
*configuration
)
951 CLibCEC
*lib
= new CLibCEC(NULL
);
952 CCECClient
*client(NULL
);
954 client
= lib
->RegisterClient(configuration
);
957 client
->GetCurrentConfiguration(configuration
);
959 // ensure that the correct server version is set
960 configuration
->serverVersion
= LIBCEC_VERSION_CURRENT
;
962 return static_cast< void* > (lib
);
965 void * CECInit(const char *strDeviceName
, CEC::cec_device_type_list types
, uint16_t iPhysicalAddress
/* = 0 */)
967 libcec_configuration configuration
;
969 // client version < 1.5.0
970 snprintf(configuration
.strDeviceName
, 13, "%s", strDeviceName
);
971 configuration
.deviceTypes
= types
;
972 configuration
.iPhysicalAddress
= iPhysicalAddress
;
974 if (configuration
.deviceTypes
.IsEmpty())
975 configuration
.deviceTypes
.Add(CEC_DEVICE_TYPE_RECORDING_DEVICE
);
977 return CECInitialise(&configuration
);
980 bool CECStartBootloader(void)
983 cec_adapter deviceList
[1];
984 if (CUSBCECAdapterDetection::FindAdapters(deviceList
, 1) > 0)
986 CUSBCECAdapterCommunication
comm(NULL
, deviceList
[0].comm
);
987 CTimeout
timeout(CEC_DEFAULT_CONNECT_TIMEOUT
);
988 while (timeout
.TimeLeft() > 0 && (bReturn
= comm
.Open(timeout
.TimeLeft() / CEC_CONNECT_TRIES
, true)) == false)
994 bReturn
= comm
.StartBootloader();
1000 void CECDestroy(CEC::ICECAdapter
*instance
)
1005 bool CLibCEC::GetDeviceInformation(const char *strPort
, libcec_configuration
*config
, uint32_t iTimeoutMs
/* = CEC_DEFAULT_CONNECT_TIMEOUT */)
1007 if (m_cec
->IsRunning())
1010 return m_cec
->GetDeviceInformation(strPort
, config
, iTimeoutMs
);
1013 void CLibCEC::AddKey(const cec_keypress
&UNUSED(key
)) {}
1014 void CLibCEC::AddCommand(const cec_command
&UNUSED(command
)) {}
1015 void CLibCEC::ConfigurationChanged(const libcec_configuration
&UNUSED(config
)) {}
1016 void CLibCEC::SetCurrentButton(cec_user_control_code
UNUSED(iButtonCode
)) {}
1017 CLibCEC
*CLibCEC::GetInstance(void) { return NULL
; }
1018 void CLibCEC::SetInstance(CLibCEC
*UNUSED(instance
)) {}