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 */)
71 if (m_cec
->IsRunning())
73 AddLog(CEC_LOG_ERROR
, "connection already open");
77 if (!m_cec
->Start(strPort
, CEC_SERIAL_DEFAULT_BAUDRATE
, iTimeoutMs
))
79 AddLog(CEC_LOG_ERROR
, "could not start CEC communications");
83 for (vector
<CCECClient
*>::iterator it
= m_clients
.begin(); it
!= m_clients
.end(); it
++)
85 if (!m_cec
->RegisterClient(*it
))
87 AddLog(CEC_LOG_ERROR
, "failed to register a CEC client");
95 void CLibCEC::Close(void)
100 for (vector
<CCECClient
*>::iterator it
= m_clients
.begin(); it
!= m_clients
.end(); it
++)
102 (*it
)->SetRegistered(false);
103 (*it
)->SetInitialised(false);
107 int8_t CLibCEC::FindAdapters(cec_adapter
*deviceList
, uint8_t iBufSize
, const char *strDevicePath
/* = NULL */)
109 return CUSBCECAdapterDetection::FindAdapters(deviceList
, iBufSize
, strDevicePath
);
112 bool CLibCEC::PingAdapter(void)
114 return m_cec
? m_cec
->PingAdapter() : false;
117 bool CLibCEC::StartBootloader(void)
119 return m_cec
? m_cec
->StartBootloader() : false;
122 bool CLibCEC::SwitchMonitoring(bool bEnable
)
124 return m_cec
? m_cec
->SwitchMonitoring(bEnable
) : false;
127 cec_logical_address
CLibCEC::GetActiveSource(void)
129 return m_cec
? m_cec
->GetActiveSource() : CECDEVICE_UNKNOWN
;
132 bool CLibCEC::IsActiveSource(cec_logical_address iAddress
)
134 return m_cec
? m_cec
->IsActiveSource(iAddress
) : false;
137 bool CLibCEC::PollDevice(cec_logical_address iAddress
)
139 return m_cec
? m_cec
->PollDevice(iAddress
) : false;
142 cec_logical_addresses
CLibCEC::GetActiveDevices(void)
144 CECDEVICEVEC activeDevices
;
146 m_cec
->GetDevices()->GetActive(activeDevices
);
147 return CCECDeviceMap::ToLogicalAddresses(activeDevices
);
150 bool CLibCEC::IsActiveDevice(cec_logical_address iAddress
)
152 cec_logical_addresses activeDevices
= GetActiveDevices();
153 return activeDevices
.IsSet(iAddress
);
156 bool CLibCEC::IsActiveDeviceType(cec_device_type type
)
158 CECDEVICEVEC activeDevices
;
160 m_cec
->GetDevices()->GetActive(activeDevices
);
161 CCECDeviceMap::FilterType(type
, activeDevices
);
162 return !activeDevices
.empty();
165 bool CLibCEC::SetStreamPath(cec_logical_address iAddress
)
167 uint16_t iPhysicalAddress
= GetDevicePhysicalAddress(iAddress
);
168 if (iPhysicalAddress
!= CEC_INVALID_PHYSICAL_ADDRESS
)
169 return SetStreamPath(iPhysicalAddress
);
173 bool CLibCEC::SetStreamPath(uint16_t iPhysicalAddress
)
175 return m_cec
->SetStreamPath(iPhysicalAddress
);
178 bool CLibCEC::IsLibCECActiveSource(void)
183 cec_logical_address activeSource
= m_cec
->GetActiveSource();
184 CCECBusDevice
*device
= m_cec
->GetDevice(activeSource
);
186 bReturn
= device
->IsHandledByLibCEC();
191 bool CLibCEC::CanPersistConfiguration(void)
193 return m_cec
->CanPersistConfiguration();
196 bool CLibCEC::PersistConfiguration(libcec_configuration
*configuration
)
198 return m_cec
->PersistConfiguration(configuration
);
201 void CLibCEC::RescanActiveDevices(void)
203 return m_cec
->RescanActiveDevices();
206 bool CLibCEC::EnableCallbacks(void *cbParam
, ICECCallbacks
*callbacks
)
208 return m_client
? m_client
->EnableCallbacks(cbParam
, callbacks
) : false;
211 bool CLibCEC::GetCurrentConfiguration(libcec_configuration
*configuration
)
213 return m_client
? m_client
->GetCurrentConfiguration(configuration
) : false;
216 bool CLibCEC::SetConfiguration(const libcec_configuration
*configuration
)
218 return m_client
? m_client
->SetConfiguration(configuration
) : false;
221 bool CLibCEC::Transmit(const cec_command
&data
)
223 return m_client
? m_client
->Transmit(data
) : false;
226 bool CLibCEC::SetLogicalAddress(cec_logical_address iLogicalAddress
)
228 return m_client
? m_client
->SetLogicalAddress(iLogicalAddress
) : false;
231 bool CLibCEC::SetPhysicalAddress(uint16_t iPhysicalAddress
/* = CEC_DEFAULT_PHYSICAL_ADDRESS */)
233 return m_client
? m_client
->SetPhysicalAddress(iPhysicalAddress
) : false;
236 bool CLibCEC::SetHDMIPort(cec_logical_address iBaseDevice
, uint8_t iPort
/* = CEC_DEFAULT_HDMI_PORT */)
238 return m_client
? m_client
->SetHDMIPort(iBaseDevice
, iPort
) : false;
241 bool CLibCEC::PowerOnDevices(cec_logical_address address
/* = CECDEVICE_TV */)
243 return m_client
? m_client
->SendPowerOnDevices(address
) : false;
246 bool CLibCEC::StandbyDevices(cec_logical_address address
/* = CECDEVICE_BROADCAST */)
248 return m_client
? m_client
->SendStandbyDevices(address
) : false;
251 bool CLibCEC::SetActiveSource(cec_device_type type
/* = CEC_DEVICE_TYPE_RESERVED */)
253 return m_client
? m_client
->SendSetActiveSource(type
) : false;
256 bool CLibCEC::SetDeckControlMode(cec_deck_control_mode mode
, bool bSendUpdate
/* = true */)
258 return m_client
? m_client
->SendSetDeckControlMode(mode
, bSendUpdate
) : false;
261 bool CLibCEC::SetDeckInfo(cec_deck_info info
, bool bSendUpdate
/* = true */)
263 return m_client
? m_client
->SendSetDeckInfo(info
, bSendUpdate
) : false;
266 bool CLibCEC::SetInactiveView(void)
268 return m_client
? m_client
->SendSetInactiveView() : false;
271 bool CLibCEC::SetMenuState(cec_menu_state state
, bool bSendUpdate
/* = true */)
273 return m_client
? m_client
->SendSetMenuState(state
, bSendUpdate
) : false;
276 bool CLibCEC::SetOSDString(cec_logical_address iLogicalAddress
, cec_display_control duration
, const char *strMessage
)
278 return m_client
? m_client
->SendSetOSDString(iLogicalAddress
, duration
, strMessage
) : false;
281 cec_version
CLibCEC::GetDeviceCecVersion(cec_logical_address iAddress
)
283 return m_client
? m_client
->GetDeviceCecVersion(iAddress
) : CEC_VERSION_UNKNOWN
;
286 bool CLibCEC::GetDeviceMenuLanguage(cec_logical_address iAddress
, cec_menu_language
*language
)
288 return m_client
? m_client
->GetDeviceMenuLanguage(iAddress
, language
) : false;
291 uint64_t CLibCEC::GetDeviceVendorId(cec_logical_address iAddress
)
293 return m_client
? m_client
->GetDeviceVendorId(iAddress
) : (uint64_t)CEC_VENDOR_UNKNOWN
;
296 uint16_t CLibCEC::GetDevicePhysicalAddress(cec_logical_address iAddress
)
298 return m_client
? m_client
->GetDevicePhysicalAddress(iAddress
) : CEC_INVALID_PHYSICAL_ADDRESS
;
301 cec_power_status
CLibCEC::GetDevicePowerStatus(cec_logical_address iAddress
)
303 return m_client
? m_client
->GetDevicePowerStatus(iAddress
) : CEC_POWER_STATUS_UNKNOWN
;
306 uint8_t CLibCEC::VolumeUp(bool bSendRelease
/* = true */)
308 return m_client
? m_client
->SendVolumeUp(bSendRelease
) : (uint8_t)CEC_AUDIO_VOLUME_STATUS_UNKNOWN
;
311 uint8_t CLibCEC::VolumeDown(bool bSendRelease
/* = true */)
313 return m_client
? m_client
->SendVolumeDown(bSendRelease
) : (uint8_t)CEC_AUDIO_VOLUME_STATUS_UNKNOWN
;
316 uint8_t CLibCEC::MuteAudio(bool UNUSED(bSendRelease
) /* = true */)
318 return m_client
? m_client
->SendMuteAudio() : (uint8_t)CEC_AUDIO_VOLUME_STATUS_UNKNOWN
;
321 bool CLibCEC::SendKeypress(cec_logical_address iDestination
, cec_user_control_code key
, bool bWait
/* = true */)
323 return m_client
? m_client
->SendKeypress(iDestination
, key
, bWait
) : false;
326 bool CLibCEC::SendKeyRelease(cec_logical_address iDestination
, bool bWait
/* = true */)
328 return m_client
? m_client
->SendKeyRelease(iDestination
, bWait
) : false;
331 cec_osd_name
CLibCEC::GetDeviceOSDName(cec_logical_address iAddress
)
335 retVal
= m_client
->GetDeviceOSDName(iAddress
);
339 cec_logical_addresses
CLibCEC::GetLogicalAddresses(void)
341 cec_logical_addresses addresses
;
343 addresses
= m_cec
->GetLogicalAddresses();
347 bool CLibCEC::GetNextLogMessage(cec_log_message
*message
)
349 return m_client
? m_client
->GetNextLogMessage(message
) : false;
352 bool CLibCEC::GetNextKeypress(cec_keypress
*key
)
354 return m_client
? m_client
->GetNextKeypress(key
) : false;
357 bool CLibCEC::GetNextCommand(cec_command
*command
)
359 return m_client
? m_client
->GetNextCommand(command
) : false;
362 cec_device_type
CLibCEC::GetType(cec_logical_address address
)
366 case CECDEVICE_AUDIOSYSTEM
:
367 return CEC_DEVICE_TYPE_AUDIO_SYSTEM
;
368 case CECDEVICE_PLAYBACKDEVICE1
:
369 case CECDEVICE_PLAYBACKDEVICE2
:
370 case CECDEVICE_PLAYBACKDEVICE3
:
371 return CEC_DEVICE_TYPE_PLAYBACK_DEVICE
;
372 case CECDEVICE_RECORDINGDEVICE1
:
373 case CECDEVICE_RECORDINGDEVICE2
:
374 case CECDEVICE_RECORDINGDEVICE3
:
375 return CEC_DEVICE_TYPE_RECORDING_DEVICE
;
376 case CECDEVICE_TUNER1
:
377 case CECDEVICE_TUNER2
:
378 case CECDEVICE_TUNER3
:
379 case CECDEVICE_TUNER4
:
380 return CEC_DEVICE_TYPE_TUNER
;
382 return CEC_DEVICE_TYPE_TV
;
384 return CEC_DEVICE_TYPE_RESERVED
;
388 uint16_t CLibCEC::GetMaskForType(cec_logical_address address
)
390 return GetMaskForType(GetType(address
));
393 uint16_t CLibCEC::GetMaskForType(cec_device_type type
)
397 case CEC_DEVICE_TYPE_AUDIO_SYSTEM
:
399 cec_logical_addresses addr
;
401 addr
.Set(CECDEVICE_AUDIOSYSTEM
);
402 return addr
.AckMask();
404 case CEC_DEVICE_TYPE_PLAYBACK_DEVICE
:
406 cec_logical_addresses addr
;
408 addr
.Set(CECDEVICE_PLAYBACKDEVICE1
);
409 addr
.Set(CECDEVICE_PLAYBACKDEVICE2
);
410 addr
.Set(CECDEVICE_PLAYBACKDEVICE3
);
411 return addr
.AckMask();
413 case CEC_DEVICE_TYPE_RECORDING_DEVICE
:
415 cec_logical_addresses addr
;
417 addr
.Set(CECDEVICE_RECORDINGDEVICE1
);
418 addr
.Set(CECDEVICE_RECORDINGDEVICE2
);
419 addr
.Set(CECDEVICE_RECORDINGDEVICE3
);
420 return addr
.AckMask();
422 case CEC_DEVICE_TYPE_TUNER
:
424 cec_logical_addresses addr
;
426 addr
.Set(CECDEVICE_TUNER1
);
427 addr
.Set(CECDEVICE_TUNER2
);
428 addr
.Set(CECDEVICE_TUNER3
);
429 addr
.Set(CECDEVICE_TUNER4
);
430 return addr
.AckMask();
432 case CEC_DEVICE_TYPE_TV
:
434 cec_logical_addresses addr
;
436 addr
.Set(CECDEVICE_TV
);
437 return addr
.AckMask();
444 bool CLibCEC::IsValidPhysicalAddress(uint16_t iPhysicalAddress
)
446 return iPhysicalAddress
>= CEC_MIN_PHYSICAL_ADDRESS
&&
447 iPhysicalAddress
<= CEC_MAX_PHYSICAL_ADDRESS
;
450 const char *CLibCEC::ToString(const cec_device_type type
)
454 case CEC_DEVICE_TYPE_AUDIO_SYSTEM
:
455 return "audio system";
456 case CEC_DEVICE_TYPE_PLAYBACK_DEVICE
:
457 return "playback device";
458 case CEC_DEVICE_TYPE_RECORDING_DEVICE
:
459 return "recording device";
460 case CEC_DEVICE_TYPE_RESERVED
:
462 case CEC_DEVICE_TYPE_TUNER
:
464 case CEC_DEVICE_TYPE_TV
:
471 const char *CLibCEC::ToString(const cec_menu_state state
)
475 case CEC_MENU_STATE_ACTIVATED
:
477 case CEC_MENU_STATE_DEACTIVATED
:
478 return "deactivated";
484 const char *CLibCEC::ToString(const cec_version version
)
488 case CEC_VERSION_1_2
:
490 case CEC_VERSION_1_2A
:
492 case CEC_VERSION_1_3
:
494 case CEC_VERSION_1_3A
:
496 case CEC_VERSION_1_4
:
503 const char *CLibCEC::ToString(const cec_power_status status
)
507 case CEC_POWER_STATUS_ON
:
509 case CEC_POWER_STATUS_STANDBY
:
511 case CEC_POWER_STATUS_IN_TRANSITION_ON_TO_STANDBY
:
512 return "in transition from on to standby";
513 case CEC_POWER_STATUS_IN_TRANSITION_STANDBY_TO_ON
:
514 return "in transition from standby to on";
520 const char *CLibCEC::ToString(const cec_logical_address address
)
524 case CECDEVICE_AUDIOSYSTEM
:
526 case CECDEVICE_BROADCAST
:
528 case CECDEVICE_FREEUSE
:
530 case CECDEVICE_PLAYBACKDEVICE1
:
532 case CECDEVICE_PLAYBACKDEVICE2
:
534 case CECDEVICE_PLAYBACKDEVICE3
:
536 case CECDEVICE_RECORDINGDEVICE1
:
538 case CECDEVICE_RECORDINGDEVICE2
:
540 case CECDEVICE_RECORDINGDEVICE3
:
542 case CECDEVICE_RESERVED1
:
544 case CECDEVICE_RESERVED2
:
546 case CECDEVICE_TUNER1
:
548 case CECDEVICE_TUNER2
:
550 case CECDEVICE_TUNER3
:
552 case CECDEVICE_TUNER4
:
561 const char *CLibCEC::ToString(const cec_deck_control_mode mode
)
565 case CEC_DECK_CONTROL_MODE_SKIP_FORWARD_WIND
:
566 return "skip forward wind";
567 case CEC_DECK_CONTROL_MODE_EJECT
:
569 case CEC_DECK_CONTROL_MODE_SKIP_REVERSE_REWIND
:
570 return "reverse rewind";
571 case CEC_DECK_CONTROL_MODE_STOP
:
578 const char *CLibCEC::ToString(const cec_deck_info status
)
582 case CEC_DECK_INFO_PLAY
:
584 case CEC_DECK_INFO_RECORD
:
586 case CEC_DECK_INFO_PLAY_REVERSE
:
587 return "play reverse";
588 case CEC_DECK_INFO_STILL
:
590 case CEC_DECK_INFO_SLOW
:
592 case CEC_DECK_INFO_SLOW_REVERSE
:
593 return "slow reverse";
594 case CEC_DECK_INFO_FAST_FORWARD
:
595 return "fast forward";
596 case CEC_DECK_INFO_FAST_REVERSE
:
597 return "fast reverse";
598 case CEC_DECK_INFO_NO_MEDIA
:
600 case CEC_DECK_INFO_STOP
:
602 case CEC_DECK_INFO_SKIP_FORWARD_WIND
:
603 return "info skip forward wind";
604 case CEC_DECK_INFO_SKIP_REVERSE_REWIND
:
605 return "info skip reverse rewind";
606 case CEC_DECK_INFO_INDEX_SEARCH_FORWARD
:
607 return "info index search forward";
608 case CEC_DECK_INFO_INDEX_SEARCH_REVERSE
:
609 return "info index search reverse";
610 case CEC_DECK_INFO_OTHER_STATUS
:
612 case CEC_DECK_INFO_OTHER_STATUS_LG
:
619 const char *CLibCEC::ToString(const cec_opcode opcode
)
623 case CEC_OPCODE_ACTIVE_SOURCE
:
624 return "active source";
625 case CEC_OPCODE_IMAGE_VIEW_ON
:
626 return "image view on";
627 case CEC_OPCODE_TEXT_VIEW_ON
:
628 return "text view on";
629 case CEC_OPCODE_INACTIVE_SOURCE
:
630 return "inactive source";
631 case CEC_OPCODE_REQUEST_ACTIVE_SOURCE
:
632 return "request active source";
633 case CEC_OPCODE_ROUTING_CHANGE
:
634 return "routing change";
635 case CEC_OPCODE_ROUTING_INFORMATION
:
636 return "routing information";
637 case CEC_OPCODE_SET_STREAM_PATH
:
638 return "set stream path";
639 case CEC_OPCODE_STANDBY
:
641 case CEC_OPCODE_RECORD_OFF
:
643 case CEC_OPCODE_RECORD_ON
:
645 case CEC_OPCODE_RECORD_STATUS
:
646 return "record status";
647 case CEC_OPCODE_RECORD_TV_SCREEN
:
648 return "record tv screen";
649 case CEC_OPCODE_CLEAR_ANALOGUE_TIMER
:
650 return "clear analogue timer";
651 case CEC_OPCODE_CLEAR_DIGITAL_TIMER
:
652 return "clear digital timer";
653 case CEC_OPCODE_CLEAR_EXTERNAL_TIMER
:
654 return "clear external timer";
655 case CEC_OPCODE_SET_ANALOGUE_TIMER
:
656 return "set analogue timer";
657 case CEC_OPCODE_SET_DIGITAL_TIMER
:
658 return "set digital timer";
659 case CEC_OPCODE_SET_EXTERNAL_TIMER
:
660 return "set external timer";
661 case CEC_OPCODE_SET_TIMER_PROGRAM_TITLE
:
662 return "set timer program title";
663 case CEC_OPCODE_TIMER_CLEARED_STATUS
:
664 return "timer cleared status";
665 case CEC_OPCODE_TIMER_STATUS
:
666 return "timer status";
667 case CEC_OPCODE_CEC_VERSION
:
668 return "cec version";
669 case CEC_OPCODE_GET_CEC_VERSION
:
670 return "get cec version";
671 case CEC_OPCODE_GIVE_PHYSICAL_ADDRESS
:
672 return "give physical address";
673 case CEC_OPCODE_GET_MENU_LANGUAGE
:
674 return "get menu language";
675 case CEC_OPCODE_REPORT_PHYSICAL_ADDRESS
:
676 return "report physical address";
677 case CEC_OPCODE_SET_MENU_LANGUAGE
:
678 return "set menu language";
679 case CEC_OPCODE_DECK_CONTROL
:
680 return "deck control";
681 case CEC_OPCODE_DECK_STATUS
:
682 return "deck status";
683 case CEC_OPCODE_GIVE_DECK_STATUS
:
684 return "give deck status";
685 case CEC_OPCODE_PLAY
:
687 case CEC_OPCODE_GIVE_TUNER_DEVICE_STATUS
:
688 return "give tuner status";
689 case CEC_OPCODE_SELECT_ANALOGUE_SERVICE
:
690 return "select analogue service";
691 case CEC_OPCODE_SELECT_DIGITAL_SERVICE
:
692 return "set digital service";
693 case CEC_OPCODE_TUNER_DEVICE_STATUS
:
694 return "tuner device status";
695 case CEC_OPCODE_TUNER_STEP_DECREMENT
:
696 return "tuner step decrement";
697 case CEC_OPCODE_TUNER_STEP_INCREMENT
:
698 return "tuner step increment";
699 case CEC_OPCODE_DEVICE_VENDOR_ID
:
700 return "device vendor id";
701 case CEC_OPCODE_GIVE_DEVICE_VENDOR_ID
:
702 return "give device vendor id";
703 case CEC_OPCODE_VENDOR_COMMAND
:
704 return "vendor command";
705 case CEC_OPCODE_VENDOR_COMMAND_WITH_ID
:
706 return "vendor command with id";
707 case CEC_OPCODE_VENDOR_REMOTE_BUTTON_DOWN
:
708 return "vendor remote button down";
709 case CEC_OPCODE_VENDOR_REMOTE_BUTTON_UP
:
710 return "vendor remote button up";
711 case CEC_OPCODE_SET_OSD_STRING
:
712 return "set osd string";
713 case CEC_OPCODE_GIVE_OSD_NAME
:
714 return "give osd name";
715 case CEC_OPCODE_SET_OSD_NAME
:
716 return "set osd name";
717 case CEC_OPCODE_MENU_REQUEST
:
718 return "menu request";
719 case CEC_OPCODE_MENU_STATUS
:
720 return "menu status";
721 case CEC_OPCODE_USER_CONTROL_PRESSED
:
722 return "user control pressed";
723 case CEC_OPCODE_USER_CONTROL_RELEASE
:
724 return "user control release";
725 case CEC_OPCODE_GIVE_DEVICE_POWER_STATUS
:
726 return "give device power status";
727 case CEC_OPCODE_REPORT_POWER_STATUS
:
728 return "report power status";
729 case CEC_OPCODE_FEATURE_ABORT
:
730 return "feature abort";
731 case CEC_OPCODE_ABORT
:
733 case CEC_OPCODE_GIVE_AUDIO_STATUS
:
734 return "give audio status";
735 case CEC_OPCODE_GIVE_SYSTEM_AUDIO_MODE_STATUS
:
736 return "give audio mode status";
737 case CEC_OPCODE_REPORT_AUDIO_STATUS
:
738 return "report audio status";
739 case CEC_OPCODE_SET_SYSTEM_AUDIO_MODE
:
740 return "set system audio mode";
741 case CEC_OPCODE_SYSTEM_AUDIO_MODE_REQUEST
:
742 return "system audio mode request";
743 case CEC_OPCODE_SYSTEM_AUDIO_MODE_STATUS
:
744 return "system audio mode status";
745 case CEC_OPCODE_SET_AUDIO_RATE
:
746 return "set audio rate";
747 case CEC_OPCODE_START_ARC
:
749 case CEC_OPCODE_REPORT_ARC_STARTED
:
750 return "report ARC started";
751 case CEC_OPCODE_REPORT_ARC_ENDED
:
752 return "report ARC ended";
753 case CEC_OPCODE_REQUEST_ARC_START
:
754 return "request ARC start";
755 case CEC_OPCODE_REQUEST_ARC_END
:
756 return "request ARC end";
757 case CEC_OPCODE_END_ARC
:
761 case CEC_OPCODE_NONE
:
768 const char *CLibCEC::ToString(const cec_system_audio_status mode
)
772 case CEC_SYSTEM_AUDIO_STATUS_ON
:
774 case CEC_SYSTEM_AUDIO_STATUS_OFF
:
781 const char *CLibCEC::ToString(const cec_audio_status
UNUSED(status
))
783 // TODO this is a mask
787 const char *CLibCEC::ToString(const cec_vendor_id vendor
)
791 case CEC_VENDOR_SAMSUNG
:
795 case CEC_VENDOR_PANASONIC
:
797 case CEC_VENDOR_PIONEER
:
799 case CEC_VENDOR_ONKYO
:
801 case CEC_VENDOR_YAMAHA
:
803 case CEC_VENDOR_PHILIPS
:
805 case CEC_VENDOR_SONY
:
807 case CEC_VENDOR_TOSHIBA
:
814 const char *CLibCEC::ToString(const cec_client_version version
)
818 case CEC_CLIENT_VERSION_PRE_1_5
:
820 case CEC_CLIENT_VERSION_1_5_0
:
822 case CEC_CLIENT_VERSION_1_5_1
:
824 case CEC_CLIENT_VERSION_1_5_2
:
826 case CEC_CLIENT_VERSION_1_5_3
:
828 case CEC_CLIENT_VERSION_1_6_0
:
830 case CEC_CLIENT_VERSION_1_6_1
:
832 case CEC_CLIENT_VERSION_1_6_2
:
839 const char *CLibCEC::ToString(const cec_server_version version
)
843 case CEC_SERVER_VERSION_PRE_1_5
:
845 case CEC_SERVER_VERSION_1_5_0
:
847 case CEC_SERVER_VERSION_1_5_1
:
849 case CEC_SERVER_VERSION_1_5_2
:
851 case CEC_SERVER_VERSION_1_5_3
:
853 case CEC_SERVER_VERSION_1_6_0
:
855 case CEC_SERVER_VERSION_1_6_1
:
857 case CEC_SERVER_VERSION_1_6_2
:
864 void CLibCEC::CheckKeypressTimeout(void)
867 for (vector
<CCECClient
*>::iterator it
= m_clients
.begin(); it
!= m_clients
.end(); it
++)
868 (*it
)->CheckKeypressTimeout();
871 void CLibCEC::AddLog(const cec_log_level level
, const char *strFormat
, ...)
876 va_start(argList
, strFormat
);
877 strLog
.FormatV(strFormat
, argList
);
880 cec_log_message message
;
881 message
.level
= level
;
882 message
.time
= GetTimeMs() - m_iStartTime
;
883 snprintf(message
.message
, sizeof(message
.message
), "%s", strLog
.c_str());
885 // send the message to all clients
886 for (vector
<CCECClient
*>::iterator it
= m_clients
.begin(); it
!= m_clients
.end(); it
++)
887 (*it
)->AddLog(message
);
890 void CLibCEC::Alert(const libcec_alert type
, const libcec_parameter
¶m
)
892 // send the alert to all clients
893 for (vector
<CCECClient
*>::iterator it
= m_clients
.begin(); it
!= m_clients
.end(); it
++)
894 (*it
)->Alert(type
, param
);
897 bool CLibCEC::SetActiveView(void)
899 AddLog(CEC_LOG_WARNING
, "deprecated method %s called", __FUNCTION__
);
900 return SetActiveSource();
903 bool CLibCEC::EnablePhysicalAddressDetection(void)
905 AddLog(CEC_LOG_WARNING
, "deprecated method %s called", __FUNCTION__
);
909 CCECClient
*CLibCEC::RegisterClient(libcec_configuration
*configuration
)
914 CCECClient
*newClient
= new CCECClient(m_cec
, configuration
);
918 m_clients
.push_back(newClient
);
920 m_client
= newClient
;
922 if (m_cec
->IsRunning())
923 m_cec
->RegisterClient(newClient
);
928 void CLibCEC::UnregisterClients(void)
935 void * CECInitialise(libcec_configuration
*configuration
)
940 CLibCEC
*lib
= new CLibCEC
;
941 CCECClient
*client(NULL
);
943 client
= lib
->RegisterClient(configuration
);
946 client
->GetCurrentConfiguration(configuration
);
948 // ensure that the correct server version is set
949 configuration
->serverVersion
= LIBCEC_VERSION_CURRENT
;
951 return static_cast< void* > (lib
);
954 void * CECInit(const char *strDeviceName
, CEC::cec_device_type_list types
, uint16_t iPhysicalAddress
/* = 0 */)
956 libcec_configuration configuration
;
958 // client version < 1.5.0
959 snprintf(configuration
.strDeviceName
, 13, "%s", strDeviceName
);
960 configuration
.deviceTypes
= types
;
961 configuration
.iPhysicalAddress
= iPhysicalAddress
;
963 if (configuration
.deviceTypes
.IsEmpty())
964 configuration
.deviceTypes
.Add(CEC_DEVICE_TYPE_RECORDING_DEVICE
);
966 return CECInitialise(&configuration
);
969 bool CECStartBootloader(void)
972 cec_adapter deviceList
[1];
973 if (CUSBCECAdapterDetection::FindAdapters(deviceList
, 1) > 0)
975 CUSBCECAdapterCommunication
comm(NULL
, deviceList
[0].comm
);
976 CTimeout
timeout(CEC_DEFAULT_CONNECT_TIMEOUT
);
977 while (timeout
.TimeLeft() > 0 && (bReturn
= comm
.Open(timeout
.TimeLeft() / CEC_CONNECT_TRIES
, true)) == false)
983 bReturn
= comm
.StartBootloader();
989 void CECDestroy(CEC::ICECAdapter
*instance
)
994 bool CLibCEC::GetDeviceInformation(const char *strPort
, libcec_configuration
*config
, uint32_t iTimeoutMs
/* = CEC_DEFAULT_CONNECT_TIMEOUT */)
996 if (m_cec
->IsRunning())
999 return m_cec
->GetDeviceInformation(strPort
, config
, iTimeoutMs
);