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)
67 // unregister all clients client
70 // delete the adapter connection
75 bool CLibCEC::Open(const char *strPort
, uint32_t iTimeoutMs
/* = CEC_DEFAULT_CONNECT_TIMEOUT */)
77 if (!m_cec
|| !strPort
)
80 // open a new connection
81 if (!m_cec
->Start(strPort
, CEC_SERIAL_DEFAULT_BAUDRATE
, iTimeoutMs
))
83 AddLog(CEC_LOG_ERROR
, "could not start CEC communications");
87 // register all clients
88 for (vector
<CCECClient
*>::iterator it
= m_clients
.begin(); it
!= m_clients
.end(); it
++)
90 if (!m_cec
->RegisterClient(*it
))
92 AddLog(CEC_LOG_ERROR
, "failed to register a CEC client");
100 void CLibCEC::Close(void)
102 // unregister all clients
105 // close the connection
110 int8_t CLibCEC::FindAdapters(cec_adapter
*deviceList
, uint8_t iBufSize
, const char *strDevicePath
/* = NULL */)
112 return CUSBCECAdapterDetection::FindAdapters(deviceList
, iBufSize
, strDevicePath
);
115 bool CLibCEC::StartBootloader(void)
117 return m_cec
? m_cec
->StartBootloader() : false;
120 bool CLibCEC::PingAdapter(void)
122 return m_client
? m_client
->PingAdapter() : false;
125 bool CLibCEC::EnableCallbacks(void *cbParam
, ICECCallbacks
*callbacks
)
127 return m_client
? m_client
->EnableCallbacks(cbParam
, callbacks
) : false;
130 bool CLibCEC::GetCurrentConfiguration(libcec_configuration
*configuration
)
132 return m_client
? m_client
->GetCurrentConfiguration(*configuration
) : false;
135 bool CLibCEC::SetConfiguration(const libcec_configuration
*configuration
)
137 return m_client
? m_client
->SetConfiguration(*configuration
) : false;
140 bool CLibCEC::CanPersistConfiguration(void)
142 return m_client
? m_client
->CanPersistConfiguration() : false;
145 bool CLibCEC::PersistConfiguration(libcec_configuration
*configuration
)
147 return m_client
? m_client
->PersistConfiguration(*configuration
) : false;
150 void CLibCEC::RescanActiveDevices(void)
153 m_client
->RescanActiveDevices();
156 bool CLibCEC::IsLibCECActiveSource(void)
158 return m_client
? m_client
->IsLibCECActiveSource() : false;
161 bool CLibCEC::Transmit(const cec_command
&data
)
163 return m_client
? m_client
->Transmit(data
) : false;
166 bool CLibCEC::SetLogicalAddress(cec_logical_address iLogicalAddress
)
168 return m_client
? m_client
->SetLogicalAddress(iLogicalAddress
) : false;
171 bool CLibCEC::SetPhysicalAddress(uint16_t iPhysicalAddress
/* = CEC_DEFAULT_PHYSICAL_ADDRESS */)
173 return m_client
? m_client
->SetPhysicalAddress(iPhysicalAddress
) : false;
176 bool CLibCEC::SetHDMIPort(cec_logical_address iBaseDevice
, uint8_t iPort
/* = CEC_DEFAULT_HDMI_PORT */)
178 return m_client
? m_client
->SetHDMIPort(iBaseDevice
, iPort
) : false;
181 bool CLibCEC::PowerOnDevices(cec_logical_address address
/* = CECDEVICE_TV */)
183 return m_client
? m_client
->SendPowerOnDevices(address
) : false;
186 bool CLibCEC::StandbyDevices(cec_logical_address address
/* = CECDEVICE_BROADCAST */)
188 return m_client
? m_client
->SendStandbyDevices(address
) : false;
191 bool CLibCEC::SetActiveSource(cec_device_type type
/* = CEC_DEVICE_TYPE_RESERVED */)
193 return m_client
? m_client
->SendSetActiveSource(type
) : false;
196 bool CLibCEC::SetDeckControlMode(cec_deck_control_mode mode
, bool bSendUpdate
/* = true */)
198 return m_client
? m_client
->SendSetDeckControlMode(mode
, bSendUpdate
) : false;
201 bool CLibCEC::SetDeckInfo(cec_deck_info info
, bool bSendUpdate
/* = true */)
203 return m_client
? m_client
->SendSetDeckInfo(info
, bSendUpdate
) : false;
206 bool CLibCEC::SetInactiveView(void)
208 return m_client
? m_client
->SendSetInactiveView() : false;
211 bool CLibCEC::SetMenuState(cec_menu_state state
, bool bSendUpdate
/* = true */)
213 return m_client
? m_client
->SendSetMenuState(state
, bSendUpdate
) : false;
216 bool CLibCEC::SetOSDString(cec_logical_address iLogicalAddress
, cec_display_control duration
, const char *strMessage
)
218 return m_client
? m_client
->SendSetOSDString(iLogicalAddress
, duration
, strMessage
) : false;
221 bool CLibCEC::SwitchMonitoring(bool bEnable
)
223 return m_client
? m_client
->SwitchMonitoring(bEnable
) : false;
226 cec_version
CLibCEC::GetDeviceCecVersion(cec_logical_address iAddress
)
228 return m_client
? m_client
->GetDeviceCecVersion(iAddress
) : CEC_VERSION_UNKNOWN
;
231 bool CLibCEC::GetDeviceMenuLanguage(cec_logical_address iAddress
, cec_menu_language
*language
)
233 return m_client
? m_client
->GetDeviceMenuLanguage(iAddress
, *language
) : false;
236 uint64_t CLibCEC::GetDeviceVendorId(cec_logical_address iAddress
)
238 return m_client
? m_client
->GetDeviceVendorId(iAddress
) : (uint64_t)CEC_VENDOR_UNKNOWN
;
241 uint16_t CLibCEC::GetDevicePhysicalAddress(cec_logical_address iAddress
)
243 return m_client
? m_client
->GetDevicePhysicalAddress(iAddress
) : CEC_INVALID_PHYSICAL_ADDRESS
;
246 cec_power_status
CLibCEC::GetDevicePowerStatus(cec_logical_address iAddress
)
248 return m_client
? m_client
->GetDevicePowerStatus(iAddress
) : CEC_POWER_STATUS_UNKNOWN
;
251 bool CLibCEC::PollDevice(cec_logical_address iAddress
)
253 return m_client
? m_client
->PollDevice(iAddress
) : false;
256 cec_logical_addresses
CLibCEC::GetActiveDevices(void)
258 cec_logical_addresses addresses
;
261 addresses
= m_client
->GetActiveDevices();
265 bool CLibCEC::IsActiveDevice(cec_logical_address iAddress
)
267 return m_client
? m_client
->IsActiveDevice(iAddress
) : false;
270 bool CLibCEC::IsActiveDeviceType(cec_device_type type
)
272 return m_client
? m_client
->IsActiveDeviceType(type
) : false;
275 uint8_t CLibCEC::VolumeUp(bool bSendRelease
/* = true */)
277 return m_client
? m_client
->SendVolumeUp(bSendRelease
) : (uint8_t)CEC_AUDIO_VOLUME_STATUS_UNKNOWN
;
280 uint8_t CLibCEC::VolumeDown(bool bSendRelease
/* = true */)
282 return m_client
? m_client
->SendVolumeDown(bSendRelease
) : (uint8_t)CEC_AUDIO_VOLUME_STATUS_UNKNOWN
;
285 uint8_t CLibCEC::MuteAudio(bool UNUSED(bSendRelease
) /* = true */)
287 return m_client
? m_client
->SendMuteAudio() : (uint8_t)CEC_AUDIO_VOLUME_STATUS_UNKNOWN
;
290 bool CLibCEC::SendKeypress(cec_logical_address iDestination
, cec_user_control_code key
, bool bWait
/* = true */)
292 return m_client
? m_client
->SendKeypress(iDestination
, key
, bWait
) : false;
295 bool CLibCEC::SendKeyRelease(cec_logical_address iDestination
, bool bWait
/* = true */)
297 return m_client
? m_client
->SendKeyRelease(iDestination
, bWait
) : false;
300 cec_osd_name
CLibCEC::GetDeviceOSDName(cec_logical_address iAddress
)
303 retVal
.device
= CECDEVICE_UNKNOWN
;
304 memset(retVal
.name
, 0, 14);
307 retVal
= m_client
->GetDeviceOSDName(iAddress
);
311 cec_logical_address
CLibCEC::GetActiveSource(void)
313 return m_client
? m_client
->GetActiveSource() : CECDEVICE_UNKNOWN
;
316 bool CLibCEC::IsActiveSource(cec_logical_address iAddress
)
318 return m_client
? m_client
->IsActiveSource(iAddress
) : false;
320 bool CLibCEC::SetStreamPath(cec_logical_address iAddress
)
322 return m_client
? m_client
->SetStreamPath(iAddress
) : false;
325 bool CLibCEC::SetStreamPath(uint16_t iPhysicalAddress
)
327 return m_client
? m_client
->SetStreamPath(iPhysicalAddress
) : false;
330 cec_logical_addresses
CLibCEC::GetLogicalAddresses(void)
332 cec_logical_addresses addresses
;
335 m_client
->GetLogicalAddresses();
339 bool CLibCEC::GetNextLogMessage(cec_log_message
*message
)
341 return m_client
? m_client
->GetNextLogMessage(message
) : false;
344 bool CLibCEC::GetNextKeypress(cec_keypress
*key
)
346 return m_client
? m_client
->GetNextKeypress(key
) : false;
349 bool CLibCEC::GetNextCommand(cec_command
*command
)
351 return m_client
? m_client
->GetNextCommand(command
) : false;
354 cec_device_type
CLibCEC::GetType(cec_logical_address address
)
358 case CECDEVICE_AUDIOSYSTEM
:
359 return CEC_DEVICE_TYPE_AUDIO_SYSTEM
;
360 case CECDEVICE_PLAYBACKDEVICE1
:
361 case CECDEVICE_PLAYBACKDEVICE2
:
362 case CECDEVICE_PLAYBACKDEVICE3
:
363 return CEC_DEVICE_TYPE_PLAYBACK_DEVICE
;
364 case CECDEVICE_RECORDINGDEVICE1
:
365 case CECDEVICE_RECORDINGDEVICE2
:
366 case CECDEVICE_RECORDINGDEVICE3
:
367 return CEC_DEVICE_TYPE_RECORDING_DEVICE
;
368 case CECDEVICE_TUNER1
:
369 case CECDEVICE_TUNER2
:
370 case CECDEVICE_TUNER3
:
371 case CECDEVICE_TUNER4
:
372 return CEC_DEVICE_TYPE_TUNER
;
374 return CEC_DEVICE_TYPE_TV
;
376 return CEC_DEVICE_TYPE_RESERVED
;
380 uint16_t CLibCEC::GetMaskForType(cec_logical_address address
)
382 return GetMaskForType(GetType(address
));
385 uint16_t CLibCEC::GetMaskForType(cec_device_type type
)
389 case CEC_DEVICE_TYPE_AUDIO_SYSTEM
:
391 cec_logical_addresses addr
;
393 addr
.Set(CECDEVICE_AUDIOSYSTEM
);
394 return addr
.AckMask();
396 case CEC_DEVICE_TYPE_PLAYBACK_DEVICE
:
398 cec_logical_addresses addr
;
400 addr
.Set(CECDEVICE_PLAYBACKDEVICE1
);
401 addr
.Set(CECDEVICE_PLAYBACKDEVICE2
);
402 addr
.Set(CECDEVICE_PLAYBACKDEVICE3
);
403 return addr
.AckMask();
405 case CEC_DEVICE_TYPE_RECORDING_DEVICE
:
407 cec_logical_addresses addr
;
409 addr
.Set(CECDEVICE_RECORDINGDEVICE1
);
410 addr
.Set(CECDEVICE_RECORDINGDEVICE2
);
411 addr
.Set(CECDEVICE_RECORDINGDEVICE3
);
412 return addr
.AckMask();
414 case CEC_DEVICE_TYPE_TUNER
:
416 cec_logical_addresses addr
;
418 addr
.Set(CECDEVICE_TUNER1
);
419 addr
.Set(CECDEVICE_TUNER2
);
420 addr
.Set(CECDEVICE_TUNER3
);
421 addr
.Set(CECDEVICE_TUNER4
);
422 return addr
.AckMask();
424 case CEC_DEVICE_TYPE_TV
:
426 cec_logical_addresses addr
;
428 addr
.Set(CECDEVICE_TV
);
429 return addr
.AckMask();
436 bool CLibCEC::IsValidPhysicalAddress(uint16_t iPhysicalAddress
)
438 return iPhysicalAddress
>= CEC_MIN_PHYSICAL_ADDRESS
&&
439 iPhysicalAddress
<= CEC_MAX_PHYSICAL_ADDRESS
;
442 const char *CLibCEC::ToString(const cec_device_type type
)
446 case CEC_DEVICE_TYPE_AUDIO_SYSTEM
:
447 return "audio system";
448 case CEC_DEVICE_TYPE_PLAYBACK_DEVICE
:
449 return "playback device";
450 case CEC_DEVICE_TYPE_RECORDING_DEVICE
:
451 return "recording device";
452 case CEC_DEVICE_TYPE_RESERVED
:
454 case CEC_DEVICE_TYPE_TUNER
:
456 case CEC_DEVICE_TYPE_TV
:
463 const char *CLibCEC::ToString(const cec_menu_state state
)
467 case CEC_MENU_STATE_ACTIVATED
:
469 case CEC_MENU_STATE_DEACTIVATED
:
470 return "deactivated";
476 const char *CLibCEC::ToString(const cec_version version
)
480 case CEC_VERSION_1_2
:
482 case CEC_VERSION_1_2A
:
484 case CEC_VERSION_1_3
:
486 case CEC_VERSION_1_3A
:
488 case CEC_VERSION_1_4
:
495 const char *CLibCEC::ToString(const cec_power_status status
)
499 case CEC_POWER_STATUS_ON
:
501 case CEC_POWER_STATUS_STANDBY
:
503 case CEC_POWER_STATUS_IN_TRANSITION_ON_TO_STANDBY
:
504 return "in transition from on to standby";
505 case CEC_POWER_STATUS_IN_TRANSITION_STANDBY_TO_ON
:
506 return "in transition from standby to on";
512 const char *CLibCEC::ToString(const cec_logical_address address
)
516 case CECDEVICE_AUDIOSYSTEM
:
518 case CECDEVICE_BROADCAST
:
520 case CECDEVICE_FREEUSE
:
522 case CECDEVICE_PLAYBACKDEVICE1
:
524 case CECDEVICE_PLAYBACKDEVICE2
:
526 case CECDEVICE_PLAYBACKDEVICE3
:
528 case CECDEVICE_RECORDINGDEVICE1
:
530 case CECDEVICE_RECORDINGDEVICE2
:
532 case CECDEVICE_RECORDINGDEVICE3
:
534 case CECDEVICE_RESERVED1
:
536 case CECDEVICE_RESERVED2
:
538 case CECDEVICE_TUNER1
:
540 case CECDEVICE_TUNER2
:
542 case CECDEVICE_TUNER3
:
544 case CECDEVICE_TUNER4
:
553 const char *CLibCEC::ToString(const cec_deck_control_mode mode
)
557 case CEC_DECK_CONTROL_MODE_SKIP_FORWARD_WIND
:
558 return "skip forward wind";
559 case CEC_DECK_CONTROL_MODE_EJECT
:
561 case CEC_DECK_CONTROL_MODE_SKIP_REVERSE_REWIND
:
562 return "reverse rewind";
563 case CEC_DECK_CONTROL_MODE_STOP
:
570 const char *CLibCEC::ToString(const cec_deck_info status
)
574 case CEC_DECK_INFO_PLAY
:
576 case CEC_DECK_INFO_RECORD
:
578 case CEC_DECK_INFO_PLAY_REVERSE
:
579 return "play reverse";
580 case CEC_DECK_INFO_STILL
:
582 case CEC_DECK_INFO_SLOW
:
584 case CEC_DECK_INFO_SLOW_REVERSE
:
585 return "slow reverse";
586 case CEC_DECK_INFO_FAST_FORWARD
:
587 return "fast forward";
588 case CEC_DECK_INFO_FAST_REVERSE
:
589 return "fast reverse";
590 case CEC_DECK_INFO_NO_MEDIA
:
592 case CEC_DECK_INFO_STOP
:
594 case CEC_DECK_INFO_SKIP_FORWARD_WIND
:
595 return "info skip forward wind";
596 case CEC_DECK_INFO_SKIP_REVERSE_REWIND
:
597 return "info skip reverse rewind";
598 case CEC_DECK_INFO_INDEX_SEARCH_FORWARD
:
599 return "info index search forward";
600 case CEC_DECK_INFO_INDEX_SEARCH_REVERSE
:
601 return "info index search reverse";
602 case CEC_DECK_INFO_OTHER_STATUS
:
604 case CEC_DECK_INFO_OTHER_STATUS_LG
:
611 const char *CLibCEC::ToString(const cec_opcode opcode
)
615 case CEC_OPCODE_ACTIVE_SOURCE
:
616 return "active source";
617 case CEC_OPCODE_IMAGE_VIEW_ON
:
618 return "image view on";
619 case CEC_OPCODE_TEXT_VIEW_ON
:
620 return "text view on";
621 case CEC_OPCODE_INACTIVE_SOURCE
:
622 return "inactive source";
623 case CEC_OPCODE_REQUEST_ACTIVE_SOURCE
:
624 return "request active source";
625 case CEC_OPCODE_ROUTING_CHANGE
:
626 return "routing change";
627 case CEC_OPCODE_ROUTING_INFORMATION
:
628 return "routing information";
629 case CEC_OPCODE_SET_STREAM_PATH
:
630 return "set stream path";
631 case CEC_OPCODE_STANDBY
:
633 case CEC_OPCODE_RECORD_OFF
:
635 case CEC_OPCODE_RECORD_ON
:
637 case CEC_OPCODE_RECORD_STATUS
:
638 return "record status";
639 case CEC_OPCODE_RECORD_TV_SCREEN
:
640 return "record tv screen";
641 case CEC_OPCODE_CLEAR_ANALOGUE_TIMER
:
642 return "clear analogue timer";
643 case CEC_OPCODE_CLEAR_DIGITAL_TIMER
:
644 return "clear digital timer";
645 case CEC_OPCODE_CLEAR_EXTERNAL_TIMER
:
646 return "clear external timer";
647 case CEC_OPCODE_SET_ANALOGUE_TIMER
:
648 return "set analogue timer";
649 case CEC_OPCODE_SET_DIGITAL_TIMER
:
650 return "set digital timer";
651 case CEC_OPCODE_SET_EXTERNAL_TIMER
:
652 return "set external timer";
653 case CEC_OPCODE_SET_TIMER_PROGRAM_TITLE
:
654 return "set timer program title";
655 case CEC_OPCODE_TIMER_CLEARED_STATUS
:
656 return "timer cleared status";
657 case CEC_OPCODE_TIMER_STATUS
:
658 return "timer status";
659 case CEC_OPCODE_CEC_VERSION
:
660 return "cec version";
661 case CEC_OPCODE_GET_CEC_VERSION
:
662 return "get cec version";
663 case CEC_OPCODE_GIVE_PHYSICAL_ADDRESS
:
664 return "give physical address";
665 case CEC_OPCODE_GET_MENU_LANGUAGE
:
666 return "get menu language";
667 case CEC_OPCODE_REPORT_PHYSICAL_ADDRESS
:
668 return "report physical address";
669 case CEC_OPCODE_SET_MENU_LANGUAGE
:
670 return "set menu language";
671 case CEC_OPCODE_DECK_CONTROL
:
672 return "deck control";
673 case CEC_OPCODE_DECK_STATUS
:
674 return "deck status";
675 case CEC_OPCODE_GIVE_DECK_STATUS
:
676 return "give deck status";
677 case CEC_OPCODE_PLAY
:
679 case CEC_OPCODE_GIVE_TUNER_DEVICE_STATUS
:
680 return "give tuner status";
681 case CEC_OPCODE_SELECT_ANALOGUE_SERVICE
:
682 return "select analogue service";
683 case CEC_OPCODE_SELECT_DIGITAL_SERVICE
:
684 return "set digital service";
685 case CEC_OPCODE_TUNER_DEVICE_STATUS
:
686 return "tuner device status";
687 case CEC_OPCODE_TUNER_STEP_DECREMENT
:
688 return "tuner step decrement";
689 case CEC_OPCODE_TUNER_STEP_INCREMENT
:
690 return "tuner step increment";
691 case CEC_OPCODE_DEVICE_VENDOR_ID
:
692 return "device vendor id";
693 case CEC_OPCODE_GIVE_DEVICE_VENDOR_ID
:
694 return "give device vendor id";
695 case CEC_OPCODE_VENDOR_COMMAND
:
696 return "vendor command";
697 case CEC_OPCODE_VENDOR_COMMAND_WITH_ID
:
698 return "vendor command with id";
699 case CEC_OPCODE_VENDOR_REMOTE_BUTTON_DOWN
:
700 return "vendor remote button down";
701 case CEC_OPCODE_VENDOR_REMOTE_BUTTON_UP
:
702 return "vendor remote button up";
703 case CEC_OPCODE_SET_OSD_STRING
:
704 return "set osd string";
705 case CEC_OPCODE_GIVE_OSD_NAME
:
706 return "give osd name";
707 case CEC_OPCODE_SET_OSD_NAME
:
708 return "set osd name";
709 case CEC_OPCODE_MENU_REQUEST
:
710 return "menu request";
711 case CEC_OPCODE_MENU_STATUS
:
712 return "menu status";
713 case CEC_OPCODE_USER_CONTROL_PRESSED
:
714 return "user control pressed";
715 case CEC_OPCODE_USER_CONTROL_RELEASE
:
716 return "user control release";
717 case CEC_OPCODE_GIVE_DEVICE_POWER_STATUS
:
718 return "give device power status";
719 case CEC_OPCODE_REPORT_POWER_STATUS
:
720 return "report power status";
721 case CEC_OPCODE_FEATURE_ABORT
:
722 return "feature abort";
723 case CEC_OPCODE_ABORT
:
725 case CEC_OPCODE_GIVE_AUDIO_STATUS
:
726 return "give audio status";
727 case CEC_OPCODE_GIVE_SYSTEM_AUDIO_MODE_STATUS
:
728 return "give audio mode status";
729 case CEC_OPCODE_REPORT_AUDIO_STATUS
:
730 return "report audio status";
731 case CEC_OPCODE_SET_SYSTEM_AUDIO_MODE
:
732 return "set system audio mode";
733 case CEC_OPCODE_SYSTEM_AUDIO_MODE_REQUEST
:
734 return "system audio mode request";
735 case CEC_OPCODE_SYSTEM_AUDIO_MODE_STATUS
:
736 return "system audio mode status";
737 case CEC_OPCODE_SET_AUDIO_RATE
:
738 return "set audio rate";
739 case CEC_OPCODE_START_ARC
:
741 case CEC_OPCODE_REPORT_ARC_STARTED
:
742 return "report ARC started";
743 case CEC_OPCODE_REPORT_ARC_ENDED
:
744 return "report ARC ended";
745 case CEC_OPCODE_REQUEST_ARC_START
:
746 return "request ARC start";
747 case CEC_OPCODE_REQUEST_ARC_END
:
748 return "request ARC end";
749 case CEC_OPCODE_END_ARC
:
753 case CEC_OPCODE_NONE
:
760 const char *CLibCEC::ToString(const cec_system_audio_status mode
)
764 case CEC_SYSTEM_AUDIO_STATUS_ON
:
766 case CEC_SYSTEM_AUDIO_STATUS_OFF
:
773 const char *CLibCEC::ToString(const cec_audio_status
UNUSED(status
))
775 // TODO this is a mask
779 const char *CLibCEC::ToString(const cec_vendor_id vendor
)
783 case CEC_VENDOR_SAMSUNG
:
787 case CEC_VENDOR_PANASONIC
:
789 case CEC_VENDOR_PIONEER
:
791 case CEC_VENDOR_ONKYO
:
793 case CEC_VENDOR_YAMAHA
:
795 case CEC_VENDOR_PHILIPS
:
797 case CEC_VENDOR_SONY
:
799 case CEC_VENDOR_TOSHIBA
:
806 const char *CLibCEC::ToString(const cec_client_version version
)
810 case CEC_CLIENT_VERSION_PRE_1_5
:
812 case CEC_CLIENT_VERSION_1_5_0
:
814 case CEC_CLIENT_VERSION_1_5_1
:
816 case CEC_CLIENT_VERSION_1_5_2
:
818 case CEC_CLIENT_VERSION_1_5_3
:
820 case CEC_CLIENT_VERSION_1_6_0
:
822 case CEC_CLIENT_VERSION_1_6_1
:
824 case CEC_CLIENT_VERSION_1_6_2
:
826 case CEC_CLIENT_VERSION_1_6_3
:
833 const char *CLibCEC::ToString(const cec_server_version version
)
837 case CEC_SERVER_VERSION_PRE_1_5
:
839 case CEC_SERVER_VERSION_1_5_0
:
841 case CEC_SERVER_VERSION_1_5_1
:
843 case CEC_SERVER_VERSION_1_5_2
:
845 case CEC_SERVER_VERSION_1_5_3
:
847 case CEC_SERVER_VERSION_1_6_0
:
849 case CEC_SERVER_VERSION_1_6_1
:
851 case CEC_SERVER_VERSION_1_6_2
:
853 case CEC_SERVER_VERSION_1_6_3
:
860 void CLibCEC::CheckKeypressTimeout(void)
863 for (vector
<CCECClient
*>::iterator it
= m_clients
.begin(); it
!= m_clients
.end(); it
++)
864 (*it
)->CheckKeypressTimeout();
867 void CLibCEC::AddLog(const cec_log_level level
, const char *strFormat
, ...)
871 // format the message
873 va_start(argList
, strFormat
);
874 strLog
.FormatV(strFormat
, argList
);
877 cec_log_message message
;
878 message
.level
= level
;
879 message
.time
= GetTimeMs() - m_iStartTime
;
880 snprintf(message
.message
, sizeof(message
.message
), "%s", strLog
.c_str());
882 // send the message to all clients
883 for (vector
<CCECClient
*>::iterator it
= m_clients
.begin(); it
!= m_clients
.end(); it
++)
884 (*it
)->AddLog(message
);
887 void CLibCEC::Alert(const libcec_alert type
, const libcec_parameter
¶m
)
889 // send the alert to all clients
890 for (vector
<CCECClient
*>::iterator it
= m_clients
.begin(); it
!= m_clients
.end(); it
++)
891 (*it
)->Alert(type
, param
);
894 bool CLibCEC::SetActiveView(void)
896 AddLog(CEC_LOG_WARNING
, "deprecated method %s called", __FUNCTION__
);
897 return SetActiveSource();
900 bool CLibCEC::EnablePhysicalAddressDetection(void)
902 AddLog(CEC_LOG_WARNING
, "deprecated method %s called", __FUNCTION__
);
906 CCECClient
*CLibCEC::RegisterClient(libcec_configuration
&configuration
)
911 // create a new client instance
912 CCECClient
*newClient
= new CCECClient(m_cec
, configuration
);
915 m_clients
.push_back(newClient
);
917 // if the default client isn't set, set it
919 m_client
= newClient
;
921 // register the new client
922 if (m_cec
->CECInitialised())
923 m_cec
->RegisterClient(newClient
);
928 void CLibCEC::UnregisterClients(void)
931 m_cec
->UnregisterClients();
939 void * CECInitialise(libcec_configuration
*configuration
)
944 // create a new libCEC instance
945 CLibCEC
*lib
= new CLibCEC(NULL
);
947 // register a new client
948 CCECClient
*client(NULL
);
949 if (lib
&& configuration
)
950 client
= lib
->RegisterClient(*configuration
);
952 // update the current configuration
954 client
->GetCurrentConfiguration(*configuration
);
956 // ensure that the correct server version is set
957 configuration
->serverVersion
= LIBCEC_VERSION_CURRENT
;
959 return static_cast< void* > (lib
);
962 void * CECInit(const char *strDeviceName
, CEC::cec_device_type_list types
, uint16_t iPhysicalAddress
/* = 0 */)
964 libcec_configuration configuration
;
966 // client version < 1.5.0
967 snprintf(configuration
.strDeviceName
, 13, "%s", strDeviceName
);
968 configuration
.deviceTypes
= types
;
969 configuration
.iPhysicalAddress
= iPhysicalAddress
;
971 if (configuration
.deviceTypes
.IsEmpty())
972 configuration
.deviceTypes
.Add(CEC_DEVICE_TYPE_RECORDING_DEVICE
);
974 return CECInitialise(&configuration
);
977 bool CECStartBootloader(void)
980 cec_adapter deviceList
[1];
981 if (CUSBCECAdapterDetection::FindAdapters(deviceList
, 1) > 0)
983 CUSBCECAdapterCommunication
comm(NULL
, deviceList
[0].comm
);
984 CTimeout
timeout(CEC_DEFAULT_CONNECT_TIMEOUT
);
985 while (timeout
.TimeLeft() > 0 && (bReturn
= comm
.Open(timeout
.TimeLeft() / CEC_CONNECT_TRIES
, true)) == false)
991 bReturn
= comm
.StartBootloader();
997 void CECDestroy(CEC::ICECAdapter
*instance
)
1002 bool CLibCEC::GetDeviceInformation(const char *strPort
, libcec_configuration
*config
, uint32_t iTimeoutMs
/* = CEC_DEFAULT_CONNECT_TIMEOUT */)
1004 if (m_cec
->IsRunning())
1007 return m_cec
->GetDeviceInformation(strPort
, config
, iTimeoutMs
);
1010 // no longer being used
1011 void CLibCEC::AddKey(const cec_keypress
&UNUSED(key
)) {}
1012 void CLibCEC::AddCommand(const cec_command
&UNUSED(command
)) {}
1013 void CLibCEC::ConfigurationChanged(const libcec_configuration
&UNUSED(config
)) {}
1014 void CLibCEC::SetCurrentButton(cec_user_control_code
UNUSED(iButtonCode
)) {}
1015 CLibCEC
*CLibCEC::GetInstance(void) { return NULL
; }
1016 void CLibCEC::SetInstance(CLibCEC
*UNUSED(instance
)) {}