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(void) :
53 m_iStartTime(GetTimeMs())
55 m_cec
= new CCECProcessor(this);
58 CLibCEC::~CLibCEC(void)
66 bool CLibCEC::Open(const char *strPort
, uint32_t iTimeoutMs
/* = CEC_DEFAULT_CONNECT_TIMEOUT */)
68 if (m_cec
->IsRunning())
70 AddLog(CEC_LOG_ERROR
, "connection already open");
74 if (!m_cec
->Start(strPort
, CEC_SERIAL_DEFAULT_BAUDRATE
, iTimeoutMs
))
76 AddLog(CEC_LOG_ERROR
, "could not start CEC communications");
80 for (vector
<CCECClient
*>::iterator it
= m_clients
.begin(); it
!= m_clients
.end(); it
++)
82 if (!m_cec
->RegisterClient(*it
))
84 AddLog(CEC_LOG_ERROR
, "failed to register a CEC client");
92 void CLibCEC::Close(void)
108 int8_t CLibCEC::FindAdapters(cec_adapter
*deviceList
, uint8_t iBufSize
, const char *strDevicePath
/* = NULL */)
110 return CUSBCECAdapterDetection::FindAdapters(deviceList
, iBufSize
, strDevicePath
);
113 bool CLibCEC::PingAdapter(void)
115 return m_cec
? m_cec
->PingAdapter() : false;
118 bool CLibCEC::StartBootloader(void)
120 return m_cec
? m_cec
->StartBootloader() : false;
123 bool CLibCEC::SwitchMonitoring(bool bEnable
)
125 return m_cec
? m_cec
->SwitchMonitoring(bEnable
) : false;
128 cec_logical_address
CLibCEC::GetActiveSource(void)
130 return m_cec
? m_cec
->GetActiveSource() : CECDEVICE_UNKNOWN
;
133 bool CLibCEC::IsActiveSource(cec_logical_address iAddress
)
135 return m_cec
? m_cec
->IsActiveSource(iAddress
) : false;
138 bool CLibCEC::PollDevice(cec_logical_address iAddress
)
140 return m_cec
? m_cec
->PollDevice(iAddress
) : false;
143 cec_logical_addresses
CLibCEC::GetActiveDevices(void)
145 CECDEVICEVEC activeDevices
;
147 m_cec
->GetDevices()->GetActive(activeDevices
);
148 return CCECDeviceMap::ToLogicalAddresses(activeDevices
);
151 bool CLibCEC::IsActiveDevice(cec_logical_address iAddress
)
153 cec_logical_addresses activeDevices
= GetActiveDevices();
154 return activeDevices
.IsSet(iAddress
);
157 bool CLibCEC::IsActiveDeviceType(cec_device_type type
)
159 CECDEVICEVEC activeDevices
;
161 m_cec
->GetDevices()->GetActive(activeDevices
);
162 CCECDeviceMap::FilterType(type
, activeDevices
);
163 return !activeDevices
.empty();
166 bool CLibCEC::SetStreamPath(cec_logical_address iAddress
)
168 uint16_t iPhysicalAddress
= GetDevicePhysicalAddress(iAddress
);
169 if (iPhysicalAddress
!= CEC_INVALID_PHYSICAL_ADDRESS
)
170 return SetStreamPath(iPhysicalAddress
);
174 bool CLibCEC::SetStreamPath(uint16_t iPhysicalAddress
)
176 return m_cec
->SetStreamPath(iPhysicalAddress
);
179 bool CLibCEC::IsLibCECActiveSource(void)
184 cec_logical_address activeSource
= m_cec
->GetActiveSource();
185 CCECBusDevice
*device
= m_cec
->GetDevice(activeSource
);
187 bReturn
= device
->IsHandledByLibCEC();
192 bool CLibCEC::CanPersistConfiguration(void)
194 return m_cec
->CanPersistConfiguration();
197 bool CLibCEC::PersistConfiguration(libcec_configuration
*configuration
)
199 return m_cec
->PersistConfiguration(configuration
);
202 void CLibCEC::RescanActiveDevices(void)
204 return m_cec
->RescanActiveDevices();
207 bool CLibCEC::EnableCallbacks(void *cbParam
, ICECCallbacks
*callbacks
)
209 return m_client
? m_client
->EnableCallbacks(cbParam
, callbacks
) : false;
212 bool CLibCEC::GetCurrentConfiguration(libcec_configuration
*configuration
)
214 return m_client
? m_client
->GetCurrentConfiguration(configuration
) : false;
217 bool CLibCEC::SetConfiguration(const libcec_configuration
*configuration
)
219 return m_client
? m_client
->SetConfiguration(configuration
) : false;
222 bool CLibCEC::Transmit(const cec_command
&data
)
224 return m_client
? m_client
->Transmit(data
) : false;
227 bool CLibCEC::SetLogicalAddress(cec_logical_address iLogicalAddress
)
229 return m_client
? m_client
->SetLogicalAddress(iLogicalAddress
) : false;
232 bool CLibCEC::SetPhysicalAddress(uint16_t iPhysicalAddress
/* = CEC_DEFAULT_PHYSICAL_ADDRESS */)
234 return m_client
? m_client
->SetPhysicalAddress(iPhysicalAddress
) : false;
237 bool CLibCEC::SetHDMIPort(cec_logical_address iBaseDevice
, uint8_t iPort
/* = CEC_DEFAULT_HDMI_PORT */)
239 return m_client
? m_client
->SetHDMIPort(iBaseDevice
, iPort
) : false;
242 bool CLibCEC::PowerOnDevices(cec_logical_address address
/* = CECDEVICE_TV */)
244 return m_client
? m_client
->SendPowerOnDevices(address
) : false;
247 bool CLibCEC::StandbyDevices(cec_logical_address address
/* = CECDEVICE_BROADCAST */)
249 return m_client
? m_client
->SendStandbyDevices(address
) : false;
252 bool CLibCEC::SetActiveSource(cec_device_type type
/* = CEC_DEVICE_TYPE_RESERVED */)
254 return m_client
? m_client
->SendSetActiveSource(type
) : false;
257 bool CLibCEC::SetDeckControlMode(cec_deck_control_mode mode
, bool bSendUpdate
/* = true */)
259 return m_client
? m_client
->SendSetDeckControlMode(mode
, bSendUpdate
) : false;
262 bool CLibCEC::SetDeckInfo(cec_deck_info info
, bool bSendUpdate
/* = true */)
264 return m_client
? m_client
->SendSetDeckInfo(info
, bSendUpdate
) : false;
267 bool CLibCEC::SetInactiveView(void)
269 return m_client
? m_client
->SendSetInactiveView() : false;
272 bool CLibCEC::SetMenuState(cec_menu_state state
, bool bSendUpdate
/* = true */)
274 return m_client
? m_client
->SendSetMenuState(state
, bSendUpdate
) : false;
277 bool CLibCEC::SetOSDString(cec_logical_address iLogicalAddress
, cec_display_control duration
, const char *strMessage
)
279 return m_client
? m_client
->SendSetOSDString(iLogicalAddress
, duration
, strMessage
) : false;
282 cec_version
CLibCEC::GetDeviceCecVersion(cec_logical_address iAddress
)
284 return m_client
? m_client
->GetDeviceCecVersion(iAddress
) : CEC_VERSION_UNKNOWN
;
287 bool CLibCEC::GetDeviceMenuLanguage(cec_logical_address iAddress
, cec_menu_language
*language
)
289 return m_client
? m_client
->GetDeviceMenuLanguage(iAddress
, language
) : false;
292 uint64_t CLibCEC::GetDeviceVendorId(cec_logical_address iAddress
)
294 return m_client
? m_client
->GetDeviceVendorId(iAddress
) : (uint64_t)CEC_VENDOR_UNKNOWN
;
297 uint16_t CLibCEC::GetDevicePhysicalAddress(cec_logical_address iAddress
)
299 return m_client
? m_client
->GetDevicePhysicalAddress(iAddress
) : CEC_INVALID_PHYSICAL_ADDRESS
;
302 cec_power_status
CLibCEC::GetDevicePowerStatus(cec_logical_address iAddress
)
304 return m_client
? m_client
->GetDevicePowerStatus(iAddress
) : CEC_POWER_STATUS_UNKNOWN
;
307 uint8_t CLibCEC::VolumeUp(bool bSendRelease
/* = true */)
309 return m_client
? m_client
->SendVolumeUp(bSendRelease
) : (uint8_t)CEC_AUDIO_VOLUME_STATUS_UNKNOWN
;
312 uint8_t CLibCEC::VolumeDown(bool bSendRelease
/* = true */)
314 return m_client
? m_client
->SendVolumeDown(bSendRelease
) : (uint8_t)CEC_AUDIO_VOLUME_STATUS_UNKNOWN
;
317 uint8_t CLibCEC::MuteAudio(bool UNUSED(bSendRelease
) /* = true */)
319 return m_client
? m_client
->SendMuteAudio() : (uint8_t)CEC_AUDIO_VOLUME_STATUS_UNKNOWN
;
322 bool CLibCEC::SendKeypress(cec_logical_address iDestination
, cec_user_control_code key
, bool bWait
/* = true */)
324 return m_client
? m_client
->SendKeypress(iDestination
, key
, bWait
) : false;
327 bool CLibCEC::SendKeyRelease(cec_logical_address iDestination
, bool bWait
/* = true */)
329 return m_client
? m_client
->SendKeyRelease(iDestination
, bWait
) : false;
332 cec_osd_name
CLibCEC::GetDeviceOSDName(cec_logical_address iAddress
)
336 retVal
= m_client
->GetDeviceOSDName(iAddress
);
340 cec_logical_addresses
CLibCEC::GetLogicalAddresses(void)
342 cec_logical_addresses addresses
;
344 addresses
= m_cec
->GetLogicalAddresses();
348 bool CLibCEC::GetNextLogMessage(cec_log_message
*message
)
350 return m_client
? m_client
->GetNextLogMessage(message
) : false;
353 bool CLibCEC::GetNextKeypress(cec_keypress
*key
)
355 return m_client
? m_client
->GetNextKeypress(key
) : false;
358 bool CLibCEC::GetNextCommand(cec_command
*command
)
360 return m_client
? m_client
->GetNextCommand(command
) : false;
363 cec_device_type
CLibCEC::GetType(cec_logical_address address
)
367 case CECDEVICE_AUDIOSYSTEM
:
368 return CEC_DEVICE_TYPE_AUDIO_SYSTEM
;
369 case CECDEVICE_PLAYBACKDEVICE1
:
370 case CECDEVICE_PLAYBACKDEVICE2
:
371 case CECDEVICE_PLAYBACKDEVICE3
:
372 return CEC_DEVICE_TYPE_PLAYBACK_DEVICE
;
373 case CECDEVICE_RECORDINGDEVICE1
:
374 case CECDEVICE_RECORDINGDEVICE2
:
375 case CECDEVICE_RECORDINGDEVICE3
:
376 return CEC_DEVICE_TYPE_RECORDING_DEVICE
;
377 case CECDEVICE_TUNER1
:
378 case CECDEVICE_TUNER2
:
379 case CECDEVICE_TUNER3
:
380 case CECDEVICE_TUNER4
:
381 return CEC_DEVICE_TYPE_TUNER
;
383 return CEC_DEVICE_TYPE_TV
;
385 return CEC_DEVICE_TYPE_RESERVED
;
389 uint16_t CLibCEC::GetMaskForType(cec_logical_address address
)
391 return GetMaskForType(GetType(address
));
394 uint16_t CLibCEC::GetMaskForType(cec_device_type type
)
398 case CEC_DEVICE_TYPE_AUDIO_SYSTEM
:
400 cec_logical_addresses addr
;
402 addr
.Set(CECDEVICE_AUDIOSYSTEM
);
403 return addr
.AckMask();
405 case CEC_DEVICE_TYPE_PLAYBACK_DEVICE
:
407 cec_logical_addresses addr
;
409 addr
.Set(CECDEVICE_PLAYBACKDEVICE1
);
410 addr
.Set(CECDEVICE_PLAYBACKDEVICE2
);
411 addr
.Set(CECDEVICE_PLAYBACKDEVICE3
);
412 return addr
.AckMask();
414 case CEC_DEVICE_TYPE_RECORDING_DEVICE
:
416 cec_logical_addresses addr
;
418 addr
.Set(CECDEVICE_RECORDINGDEVICE1
);
419 addr
.Set(CECDEVICE_RECORDINGDEVICE2
);
420 addr
.Set(CECDEVICE_RECORDINGDEVICE3
);
421 return addr
.AckMask();
423 case CEC_DEVICE_TYPE_TUNER
:
425 cec_logical_addresses addr
;
427 addr
.Set(CECDEVICE_TUNER1
);
428 addr
.Set(CECDEVICE_TUNER2
);
429 addr
.Set(CECDEVICE_TUNER3
);
430 addr
.Set(CECDEVICE_TUNER4
);
431 return addr
.AckMask();
433 case CEC_DEVICE_TYPE_TV
:
435 cec_logical_addresses addr
;
437 addr
.Set(CECDEVICE_TV
);
438 return addr
.AckMask();
445 bool CLibCEC::IsValidPhysicalAddress(uint16_t iPhysicalAddress
)
447 return iPhysicalAddress
>= CEC_MIN_PHYSICAL_ADDRESS
&&
448 iPhysicalAddress
<= CEC_MAX_PHYSICAL_ADDRESS
;
451 const char *CLibCEC::ToString(const cec_device_type type
)
455 case CEC_DEVICE_TYPE_AUDIO_SYSTEM
:
456 return "audio system";
457 case CEC_DEVICE_TYPE_PLAYBACK_DEVICE
:
458 return "playback device";
459 case CEC_DEVICE_TYPE_RECORDING_DEVICE
:
460 return "recording device";
461 case CEC_DEVICE_TYPE_RESERVED
:
463 case CEC_DEVICE_TYPE_TUNER
:
465 case CEC_DEVICE_TYPE_TV
:
472 const char *CLibCEC::ToString(const cec_menu_state state
)
476 case CEC_MENU_STATE_ACTIVATED
:
478 case CEC_MENU_STATE_DEACTIVATED
:
479 return "deactivated";
485 const char *CLibCEC::ToString(const cec_version version
)
489 case CEC_VERSION_1_2
:
491 case CEC_VERSION_1_2A
:
493 case CEC_VERSION_1_3
:
495 case CEC_VERSION_1_3A
:
497 case CEC_VERSION_1_4
:
504 const char *CLibCEC::ToString(const cec_power_status status
)
508 case CEC_POWER_STATUS_ON
:
510 case CEC_POWER_STATUS_STANDBY
:
512 case CEC_POWER_STATUS_IN_TRANSITION_ON_TO_STANDBY
:
513 return "in transition from on to standby";
514 case CEC_POWER_STATUS_IN_TRANSITION_STANDBY_TO_ON
:
515 return "in transition from standby to on";
521 const char *CLibCEC::ToString(const cec_logical_address address
)
525 case CECDEVICE_AUDIOSYSTEM
:
527 case CECDEVICE_BROADCAST
:
529 case CECDEVICE_FREEUSE
:
531 case CECDEVICE_PLAYBACKDEVICE1
:
533 case CECDEVICE_PLAYBACKDEVICE2
:
535 case CECDEVICE_PLAYBACKDEVICE3
:
537 case CECDEVICE_RECORDINGDEVICE1
:
539 case CECDEVICE_RECORDINGDEVICE2
:
541 case CECDEVICE_RECORDINGDEVICE3
:
543 case CECDEVICE_RESERVED1
:
545 case CECDEVICE_RESERVED2
:
547 case CECDEVICE_TUNER1
:
549 case CECDEVICE_TUNER2
:
551 case CECDEVICE_TUNER3
:
553 case CECDEVICE_TUNER4
:
562 const char *CLibCEC::ToString(const cec_deck_control_mode mode
)
566 case CEC_DECK_CONTROL_MODE_SKIP_FORWARD_WIND
:
567 return "skip forward wind";
568 case CEC_DECK_CONTROL_MODE_EJECT
:
570 case CEC_DECK_CONTROL_MODE_SKIP_REVERSE_REWIND
:
571 return "reverse rewind";
572 case CEC_DECK_CONTROL_MODE_STOP
:
579 const char *CLibCEC::ToString(const cec_deck_info status
)
583 case CEC_DECK_INFO_PLAY
:
585 case CEC_DECK_INFO_RECORD
:
587 case CEC_DECK_INFO_PLAY_REVERSE
:
588 return "play reverse";
589 case CEC_DECK_INFO_STILL
:
591 case CEC_DECK_INFO_SLOW
:
593 case CEC_DECK_INFO_SLOW_REVERSE
:
594 return "slow reverse";
595 case CEC_DECK_INFO_FAST_FORWARD
:
596 return "fast forward";
597 case CEC_DECK_INFO_FAST_REVERSE
:
598 return "fast reverse";
599 case CEC_DECK_INFO_NO_MEDIA
:
601 case CEC_DECK_INFO_STOP
:
603 case CEC_DECK_INFO_SKIP_FORWARD_WIND
:
604 return "info skip forward wind";
605 case CEC_DECK_INFO_SKIP_REVERSE_REWIND
:
606 return "info skip reverse rewind";
607 case CEC_DECK_INFO_INDEX_SEARCH_FORWARD
:
608 return "info index search forward";
609 case CEC_DECK_INFO_INDEX_SEARCH_REVERSE
:
610 return "info index search reverse";
611 case CEC_DECK_INFO_OTHER_STATUS
:
613 case CEC_DECK_INFO_OTHER_STATUS_LG
:
620 const char *CLibCEC::ToString(const cec_opcode opcode
)
624 case CEC_OPCODE_ACTIVE_SOURCE
:
625 return "active source";
626 case CEC_OPCODE_IMAGE_VIEW_ON
:
627 return "image view on";
628 case CEC_OPCODE_TEXT_VIEW_ON
:
629 return "text view on";
630 case CEC_OPCODE_INACTIVE_SOURCE
:
631 return "inactive source";
632 case CEC_OPCODE_REQUEST_ACTIVE_SOURCE
:
633 return "request active source";
634 case CEC_OPCODE_ROUTING_CHANGE
:
635 return "routing change";
636 case CEC_OPCODE_ROUTING_INFORMATION
:
637 return "routing information";
638 case CEC_OPCODE_SET_STREAM_PATH
:
639 return "set stream path";
640 case CEC_OPCODE_STANDBY
:
642 case CEC_OPCODE_RECORD_OFF
:
644 case CEC_OPCODE_RECORD_ON
:
646 case CEC_OPCODE_RECORD_STATUS
:
647 return "record status";
648 case CEC_OPCODE_RECORD_TV_SCREEN
:
649 return "record tv screen";
650 case CEC_OPCODE_CLEAR_ANALOGUE_TIMER
:
651 return "clear analogue timer";
652 case CEC_OPCODE_CLEAR_DIGITAL_TIMER
:
653 return "clear digital timer";
654 case CEC_OPCODE_CLEAR_EXTERNAL_TIMER
:
655 return "clear external timer";
656 case CEC_OPCODE_SET_ANALOGUE_TIMER
:
657 return "set analogue timer";
658 case CEC_OPCODE_SET_DIGITAL_TIMER
:
659 return "set digital timer";
660 case CEC_OPCODE_SET_EXTERNAL_TIMER
:
661 return "set external timer";
662 case CEC_OPCODE_SET_TIMER_PROGRAM_TITLE
:
663 return "set timer program title";
664 case CEC_OPCODE_TIMER_CLEARED_STATUS
:
665 return "timer cleared status";
666 case CEC_OPCODE_TIMER_STATUS
:
667 return "timer status";
668 case CEC_OPCODE_CEC_VERSION
:
669 return "cec version";
670 case CEC_OPCODE_GET_CEC_VERSION
:
671 return "get cec version";
672 case CEC_OPCODE_GIVE_PHYSICAL_ADDRESS
:
673 return "give physical address";
674 case CEC_OPCODE_GET_MENU_LANGUAGE
:
675 return "get menu language";
676 case CEC_OPCODE_REPORT_PHYSICAL_ADDRESS
:
677 return "report physical address";
678 case CEC_OPCODE_SET_MENU_LANGUAGE
:
679 return "set menu language";
680 case CEC_OPCODE_DECK_CONTROL
:
681 return "deck control";
682 case CEC_OPCODE_DECK_STATUS
:
683 return "deck status";
684 case CEC_OPCODE_GIVE_DECK_STATUS
:
685 return "give deck status";
686 case CEC_OPCODE_PLAY
:
688 case CEC_OPCODE_GIVE_TUNER_DEVICE_STATUS
:
689 return "give tuner status";
690 case CEC_OPCODE_SELECT_ANALOGUE_SERVICE
:
691 return "select analogue service";
692 case CEC_OPCODE_SELECT_DIGITAL_SERVICE
:
693 return "set digital service";
694 case CEC_OPCODE_TUNER_DEVICE_STATUS
:
695 return "tuner device status";
696 case CEC_OPCODE_TUNER_STEP_DECREMENT
:
697 return "tuner step decrement";
698 case CEC_OPCODE_TUNER_STEP_INCREMENT
:
699 return "tuner step increment";
700 case CEC_OPCODE_DEVICE_VENDOR_ID
:
701 return "device vendor id";
702 case CEC_OPCODE_GIVE_DEVICE_VENDOR_ID
:
703 return "give device vendor id";
704 case CEC_OPCODE_VENDOR_COMMAND
:
705 return "vendor command";
706 case CEC_OPCODE_VENDOR_COMMAND_WITH_ID
:
707 return "vendor command with id";
708 case CEC_OPCODE_VENDOR_REMOTE_BUTTON_DOWN
:
709 return "vendor remote button down";
710 case CEC_OPCODE_VENDOR_REMOTE_BUTTON_UP
:
711 return "vendor remote button up";
712 case CEC_OPCODE_SET_OSD_STRING
:
713 return "set osd string";
714 case CEC_OPCODE_GIVE_OSD_NAME
:
715 return "give osd name";
716 case CEC_OPCODE_SET_OSD_NAME
:
717 return "set osd name";
718 case CEC_OPCODE_MENU_REQUEST
:
719 return "menu request";
720 case CEC_OPCODE_MENU_STATUS
:
721 return "menu status";
722 case CEC_OPCODE_USER_CONTROL_PRESSED
:
723 return "user control pressed";
724 case CEC_OPCODE_USER_CONTROL_RELEASE
:
725 return "user control release";
726 case CEC_OPCODE_GIVE_DEVICE_POWER_STATUS
:
727 return "give device power status";
728 case CEC_OPCODE_REPORT_POWER_STATUS
:
729 return "report power status";
730 case CEC_OPCODE_FEATURE_ABORT
:
731 return "feature abort";
732 case CEC_OPCODE_ABORT
:
734 case CEC_OPCODE_GIVE_AUDIO_STATUS
:
735 return "give audio status";
736 case CEC_OPCODE_GIVE_SYSTEM_AUDIO_MODE_STATUS
:
737 return "give audio mode status";
738 case CEC_OPCODE_REPORT_AUDIO_STATUS
:
739 return "report audio status";
740 case CEC_OPCODE_SET_SYSTEM_AUDIO_MODE
:
741 return "set system audio mode";
742 case CEC_OPCODE_SYSTEM_AUDIO_MODE_REQUEST
:
743 return "system audio mode request";
744 case CEC_OPCODE_SYSTEM_AUDIO_MODE_STATUS
:
745 return "system audio mode status";
746 case CEC_OPCODE_SET_AUDIO_RATE
:
747 return "set audio rate";
748 case CEC_OPCODE_START_ARC
:
750 case CEC_OPCODE_REPORT_ARC_STARTED
:
751 return "report ARC started";
752 case CEC_OPCODE_REPORT_ARC_ENDED
:
753 return "report ARC ended";
754 case CEC_OPCODE_REQUEST_ARC_START
:
755 return "request ARC start";
756 case CEC_OPCODE_REQUEST_ARC_END
:
757 return "request ARC end";
758 case CEC_OPCODE_END_ARC
:
762 case CEC_OPCODE_NONE
:
769 const char *CLibCEC::ToString(const cec_system_audio_status mode
)
773 case CEC_SYSTEM_AUDIO_STATUS_ON
:
775 case CEC_SYSTEM_AUDIO_STATUS_OFF
:
782 const char *CLibCEC::ToString(const cec_audio_status
UNUSED(status
))
784 // TODO this is a mask
788 const char *CLibCEC::ToString(const cec_vendor_id vendor
)
792 case CEC_VENDOR_SAMSUNG
:
796 case CEC_VENDOR_PANASONIC
:
798 case CEC_VENDOR_PIONEER
:
800 case CEC_VENDOR_ONKYO
:
802 case CEC_VENDOR_YAMAHA
:
804 case CEC_VENDOR_PHILIPS
:
806 case CEC_VENDOR_SONY
:
808 case CEC_VENDOR_TOSHIBA
:
815 const char *CLibCEC::ToString(const cec_client_version version
)
819 case CEC_CLIENT_VERSION_PRE_1_5
:
821 case CEC_CLIENT_VERSION_1_5_0
:
823 case CEC_CLIENT_VERSION_1_5_1
:
825 case CEC_CLIENT_VERSION_1_5_2
:
827 case CEC_CLIENT_VERSION_1_5_3
:
829 case CEC_CLIENT_VERSION_1_6_0
:
831 case CEC_CLIENT_VERSION_1_6_1
:
833 case CEC_CLIENT_VERSION_1_6_2
:
840 const char *CLibCEC::ToString(const cec_server_version version
)
844 case CEC_SERVER_VERSION_PRE_1_5
:
846 case CEC_SERVER_VERSION_1_5_0
:
848 case CEC_SERVER_VERSION_1_5_1
:
850 case CEC_SERVER_VERSION_1_5_2
:
852 case CEC_SERVER_VERSION_1_5_3
:
854 case CEC_SERVER_VERSION_1_6_0
:
856 case CEC_SERVER_VERSION_1_6_1
:
858 case CEC_SERVER_VERSION_1_6_2
:
865 void CLibCEC::CheckKeypressTimeout(void)
868 for (vector
<CCECClient
*>::iterator it
= m_clients
.begin(); it
!= m_clients
.end(); it
++)
869 (*it
)->CheckKeypressTimeout();
872 void CLibCEC::AddLog(const cec_log_level level
, const char *strFormat
, ...)
877 va_start(argList
, strFormat
);
878 strLog
.FormatV(strFormat
, argList
);
881 cec_log_message message
;
882 message
.level
= level
;
883 message
.time
= GetTimeMs() - m_iStartTime
;
884 snprintf(message
.message
, sizeof(message
.message
), "%s", strLog
.c_str());
886 // send the message to all clients
887 for (vector
<CCECClient
*>::iterator it
= m_clients
.begin(); it
!= m_clients
.end(); it
++)
888 (*it
)->AddLog(message
);
891 void CLibCEC::Alert(const libcec_alert type
, const libcec_parameter
¶m
)
893 // send the alert to all clients
894 for (vector
<CCECClient
*>::iterator it
= m_clients
.begin(); it
!= m_clients
.end(); it
++)
895 (*it
)->Alert(type
, param
);
898 bool CLibCEC::SetActiveView(void)
900 AddLog(CEC_LOG_WARNING
, "deprecated method %s called", __FUNCTION__
);
901 return SetActiveSource();
904 bool CLibCEC::EnablePhysicalAddressDetection(void)
906 AddLog(CEC_LOG_WARNING
, "deprecated method %s called", __FUNCTION__
);
910 CCECClient
*CLibCEC::RegisterClient(libcec_configuration
*configuration
)
915 CCECClient
*newClient
= new CCECClient(m_cec
, configuration
);
919 m_clients
.push_back(newClient
);
921 m_client
= newClient
;
923 if (m_cec
->IsRunning())
924 m_cec
->RegisterClient(newClient
);
929 void CLibCEC::UnregisterClients(void)
936 void * CECInitialise(libcec_configuration
*configuration
)
941 CLibCEC
*lib
= new CLibCEC
;
943 lib
->RegisterClient(configuration
);
945 return static_cast< void* > (lib
);
948 void * CECInit(const char *strDeviceName
, CEC::cec_device_type_list types
, uint16_t iPhysicalAddress
/* = 0 */)
950 libcec_configuration configuration
;
951 configuration
.serverVersion
= LIBCEC_VERSION_CURRENT
;
953 // client version < 1.5.0
954 snprintf(configuration
.strDeviceName
, 13, "%s", strDeviceName
);
955 configuration
.deviceTypes
= types
;
956 configuration
.iPhysicalAddress
= iPhysicalAddress
;
958 if (configuration
.deviceTypes
.IsEmpty())
959 configuration
.deviceTypes
.Add(CEC_DEVICE_TYPE_RECORDING_DEVICE
);
961 return CECInitialise(&configuration
);
964 bool CECStartBootloader(void)
967 cec_adapter deviceList
[1];
968 if (CUSBCECAdapterDetection::FindAdapters(deviceList
, 1) > 0)
970 CUSBCECAdapterCommunication
comm(NULL
, deviceList
[0].comm
);
971 CTimeout
timeout(CEC_DEFAULT_CONNECT_TIMEOUT
);
972 while (timeout
.TimeLeft() > 0 && (bReturn
= comm
.Open(timeout
.TimeLeft() / CEC_CONNECT_TRIES
, true)) == false)
978 bReturn
= comm
.StartBootloader();
984 void CECDestroy(CEC::ICECAdapter
*instance
)
989 bool CLibCEC::GetDeviceInformation(const char *strPort
, libcec_configuration
*config
, uint32_t iTimeoutMs
/* = CEC_DEFAULT_CONNECT_TIMEOUT */)
991 if (m_cec
->IsRunning())
994 return m_cec
->GetDeviceInformation(strPort
, config
, iTimeoutMs
);