libCEC 8.1.0
C / C++ API — control CEC-capable HDMI devices
Loading...
Searching...
No Matches
ceccloader.h
Go to the documentation of this file.
1#pragma once
2/*
3 * This file is part of the libCEC(R) library.
4 *
5 * libCEC(R) is Copyright (C) 2011-2015 Pulse-Eight Limited. All rights reserved.
6 * libCEC(R) is an original work, containing original code.
7 *
8 * libCEC(R) is a trademark of Pulse-Eight Limited.
9 *
10 * This program is dual-licensed; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 *
24 *
25 * Alternatively, you can license this library under a commercial license,
26 * please contact Pulse-Eight Licensing for more information.
27 *
28 * For more information contact:
29 * Pulse-Eight Licensing <license@pulse-eight.com>
30 * http://www.pulse-eight.com/
31 * http://www.pulse-eight.net/
32 */
33
34#include "cecc.h"
35
36#include <stdio.h>
37#if defined(_WIN32) || defined(_WIN64) || defined(_M_ARM64)
38#include <windows.h>
39#include <conio.h>
40typedef HINSTANCE libcecc_lib_instance_t;
41#else
42#include <dlfcn.h>
44#ifndef CDECL
45#define CDECL
46#endif
47#endif
48
49static libcecc_lib_instance_t libcecc_load_library(const char* strLib);
51static void* libcecc_resolve(void* lib, const char* name);
52
53#define _libcecc_resolve(lib, tar, name, method) \
54 do { \
55 tar = (method) libcecc_resolve(lib, name); \
56 if (tar == NULL) \
57 { \
58 libcecc_close_library(lib); \
59 return -1; \
60 } \
61 } while(0)
62
63typedef struct {
66 libcec_connection_t (CDECL *initialise)(CEC_NAMESPACE libcec_configuration* configuration);
67 void (CDECL *destroy)(libcec_connection_t connection);
68 int (CDECL *open)(libcec_connection_t connection, const char* strPort, uint32_t iTimeout);
69 void (CDECL *close)(libcec_connection_t connection);
70 void (CDECL *clear_configuration)(CEC_NAMESPACE libcec_configuration* configuration);
71#if CEC_LIB_VERSION_MAJOR >= 5
72 int (CDECL *set_callbacks)(libcec_connection_t connection, CEC_NAMESPACE ICECCallbacks* callbacks, void* cbParam);
73 int (CDECL *disable_callbacks)(libcec_connection_t connection);
74#else
75 int (CDECL *enable_callbacks)(libcec_connection_t connection, void* cbParam, CEC_NAMESPACE ICECCallbacks* callbacks);
76#endif
77 int8_t (CDECL *find_adapters)(libcec_connection_t connection, CEC_NAMESPACE cec_adapter* deviceList, uint8_t iBufSize, const char* strDevicePath);
78 int (CDECL *ping_adapters)(libcec_connection_t connection);
79 int (CDECL *start_bootloader)(libcec_connection_t connection);
80 int (CDECL *power_on_devices)(libcec_connection_t connection, CEC_NAMESPACE cec_logical_address address);
81 int (CDECL *standby_devices)(libcec_connection_t connection, CEC_NAMESPACE cec_logical_address address);
82 int (CDECL *set_active_source)(libcec_connection_t connection, CEC_NAMESPACE cec_device_type type);
83 int (CDECL *set_deck_control_mode)(libcec_connection_t connection, CEC_NAMESPACE cec_deck_control_mode mode, int bSendUpdate);
84 int (CDECL *set_deck_info)(libcec_connection_t connection, CEC_NAMESPACE cec_deck_info info, int bSendUpdate);
85 int (CDECL *set_inactive_view)(libcec_connection_t connection);
86 int (CDECL *set_menu_state)(libcec_connection_t connection, CEC_NAMESPACE cec_menu_state state, int bSendUpdate);
87 int (CDECL *transmit)(libcec_connection_t connection, const CEC_NAMESPACE cec_command* data);
88 int (CDECL *set_logical_address)(libcec_connection_t connection, CEC_NAMESPACE cec_logical_address iLogicalAddress);
89 int (CDECL *set_physical_address)(libcec_connection_t connection, uint16_t iPhysicalAddress);
90 int (CDECL *set_osd_string)(libcec_connection_t connection, CEC_NAMESPACE cec_logical_address iLogicalAddress, CEC_NAMESPACE cec_display_control duration, const char* strMessage);
91 int (CDECL *switch_monitoring)(libcec_connection_t connection, int bEnable);
92 CEC_NAMESPACE cec_version (CDECL *get_device_cec_version)(libcec_connection_t connection, CEC_NAMESPACE cec_logical_address iLogicalAddress);
93 int (CDECL *get_device_menu_language)(libcec_connection_t connection, CEC_NAMESPACE cec_logical_address iLogicalAddress, CEC_NAMESPACE cec_menu_language language);
94 uint32_t (CDECL *get_device_vendor_id)(libcec_connection_t connection, CEC_NAMESPACE cec_logical_address iLogicalAddress);
95 uint16_t (CDECL *get_device_physical_address)(libcec_connection_t connection, CEC_NAMESPACE cec_logical_address iLogicalAddress);
96 CEC_NAMESPACE cec_logical_address (CDECL *get_active_source)(libcec_connection_t connection);
97 int (CDECL *is_active_source)(libcec_connection_t connection, CEC_NAMESPACE cec_logical_address iAddress);
98 CEC_NAMESPACE cec_power_status (CDECL *get_device_power_status)(libcec_connection_t connection, CEC_NAMESPACE cec_logical_address iLogicalAddress);
99 int (CDECL *poll_device)(libcec_connection_t connection, CEC_NAMESPACE cec_logical_address iLogicalAddress);
101 int (CDECL *is_active_device)(libcec_connection_t connection, CEC_NAMESPACE cec_logical_address address);
102 int (CDECL *is_active_device_type)(libcec_connection_t connection, CEC_NAMESPACE cec_device_type type);
103 int (CDECL *set_hdmi_port)(libcec_connection_t connection, CEC_NAMESPACE cec_logical_address baseDevice, uint8_t iPort);
104 int (CDECL *volume_up)(libcec_connection_t connection, int bSendRelease);
105 int (CDECL *volume_down)(libcec_connection_t connection, int bSendRelease);
106#if CEC_LIB_VERSION_MAJOR >= 5
107 int (CDECL *mute_audio)(libcec_connection_t connection, int bSendRelease);
108#endif
109 int (CDECL *send_keypress)(libcec_connection_t connection, CEC_NAMESPACE cec_logical_address iDestination, CEC_NAMESPACE cec_user_control_code key, int bWait);
110 int (CDECL *send_key_release)(libcec_connection_t connection, CEC_NAMESPACE cec_logical_address iDestination, int bWait);
111 int (CDECL *get_device_osd_name)(libcec_connection_t connection, CEC_NAMESPACE cec_logical_address iAddress, CEC_NAMESPACE cec_osd_name name);
112 int (CDECL *set_stream_path_logical)(libcec_connection_t connection, CEC_NAMESPACE cec_logical_address iAddress);
113 int (CDECL *set_stream_path_physical)(libcec_connection_t connection, uint16_t iPhysicalAddress);
114 CEC_NAMESPACE cec_logical_addresses (CDECL *get_logical_addresses)(libcec_connection_t connection);
115 int (CDECL *get_current_configuration)(libcec_connection_t connection, CEC_NAMESPACE libcec_configuration* configuration);
116#if CEC_LIB_VERSION_MAJOR >= 5
117 int (CDECL *can_save_configuration)(libcec_connection_t connection);
118#else
119 int (CDECL *can_persist_configuration)(libcec_connection_t connection);
120 int (CDECL *persist_configuration)(libcec_connection_t connection, CEC_NAMESPACE libcec_configuration* configuration);
121#endif
122 int (CDECL *set_configuration)(libcec_connection_t connection, const CEC_NAMESPACE libcec_configuration* configuration);
123 void (CDECL *rescan_devices)(libcec_connection_t connection);
124 int (CDECL *is_libcec_active_source)(libcec_connection_t connection);
125 int (CDECL *get_device_information)(libcec_connection_t connection, const char* strPort, CEC_NAMESPACE libcec_configuration* config, uint32_t iTimeoutMs);
126 const char* (CDECL *get_lib_info)(libcec_connection_t connection);
127 void (CDECL *init_video_standalone)(libcec_connection_t connection);
128 uint16_t (CDECL *get_adapter_vendor_id)(libcec_connection_t connection);
129 uint16_t (CDECL *get_adapter_product_id)(libcec_connection_t connection);
130 uint8_t (CDECL *audio_toggle_mute)(libcec_connection_t connection);
131 uint8_t (CDECL *audio_mute)(libcec_connection_t connection);
132 uint8_t (CDECL *audio_unmute)(libcec_connection_t connection);
133 uint8_t (CDECL *audio_get_status)(libcec_connection_t connection);
134 int (CDECL *system_audio_mode)(libcec_connection_t connection, int bEnable);
135 uint8_t (CDECL *system_audio_mode_get_status)(libcec_connection_t connection);
136 int8_t (CDECL *detect_adapters)(libcec_connection_t connection, CEC_NAMESPACE cec_adapter_descriptor* deviceList, uint8_t iBufSize, const char* strDevicePath, int bQuickScan);
137 void (CDECL *menu_state_to_string)(const CEC_NAMESPACE cec_menu_state state, char* buf, size_t bufsize);
138 void (CDECL *cec_version_to_string)(const CEC_NAMESPACE cec_version version, char* buf, size_t bufsize);
139 void (CDECL *power_status_to_string)(const CEC_NAMESPACE cec_power_status status, char* buf, size_t bufsize);
140 void (CDECL *logical_address_to_string)(const CEC_NAMESPACE cec_logical_address address, char* buf, size_t bufsize);
141 void (CDECL *deck_control_mode_to_string)(const CEC_NAMESPACE cec_deck_control_mode mode, char* buf, size_t bufsize);
142 void (CDECL *deck_status_to_string)(const CEC_NAMESPACE cec_deck_info status, char* buf, size_t bufsize);
143 void (CDECL *opcode_to_string)(const CEC_NAMESPACE cec_opcode opcode, char* buf, size_t bufsize);
144 void (CDECL *system_audio_status_to_string)(const CEC_NAMESPACE cec_system_audio_status mode, char* buf, size_t bufsize);
145 void (CDECL *audio_status_to_string)(const CEC_NAMESPACE cec_audio_status status, char* buf, size_t bufsize);
146 void (CDECL *vendor_id_to_string)(const CEC_NAMESPACE cec_vendor_id vendor, char* buf, size_t bufsize);
147 void (CDECL *user_control_key_to_string)(const CEC_NAMESPACE cec_user_control_code key, char* buf, size_t bufsize);
148 void (CDECL *adapter_type_to_string)(const CEC_NAMESPACE cec_adapter_type type, char* buf, size_t bufsize);
149 void (CDECL *version_to_string)(uint32_t version, char* buf, size_t bufsize);
151
152static int libcecc_resolve_all(void* lib, libcec_interface_t* iface)
153{
154 if (!lib || !iface)
155 return -1;
156
157 _libcecc_resolve(lib, iface->initialise, "libcec_initialise", libcec_connection_t(CDECL *)(CEC_NAMESPACE libcec_configuration*));
158 _libcecc_resolve(lib, iface->destroy, "libcec_destroy", void(CDECL *)(libcec_connection_t));
159 _libcecc_resolve(lib, iface->open, "libcec_open", int(CDECL *)(libcec_connection_t, const char*, uint32_t));
160 _libcecc_resolve(lib, iface->close, "libcec_close", void(CDECL *)(libcec_connection_t));
161 _libcecc_resolve(lib, iface->clear_configuration, "libcec_clear_configuration", void(CDECL *)(CEC_NAMESPACE libcec_configuration*));
162#if CEC_LIB_VERSION_MAJOR >= 5
163 _libcecc_resolve(lib, iface->set_callbacks, "libcec_set_callbacks", int(CDECL *)(libcec_connection_t, CEC_NAMESPACE ICECCallbacks*, void*));
164 _libcecc_resolve(lib, iface->disable_callbacks, "libcec_disable_callbacks", int(CDECL *)(libcec_connection_t));
165#else
166 _libcecc_resolve(lib, iface->enable_callbacks, "libcec_enable_callbacks", int(CDECL *)(libcec_connection_t, void*, CEC_NAMESPACE ICECCallbacks*));
167#endif
168 _libcecc_resolve(lib, iface->find_adapters, "libcec_find_adapters", int8_t(CDECL *)(libcec_connection_t, CEC_NAMESPACE cec_adapter*, uint8_t, const char*));
169 _libcecc_resolve(lib, iface->ping_adapters, "libcec_ping_adapters", int(CDECL *)(libcec_connection_t));
170 _libcecc_resolve(lib, iface->start_bootloader, "libcec_start_bootloader", int(CDECL *)(libcec_connection_t));
171 _libcecc_resolve(lib, iface->power_on_devices, "libcec_power_on_devices", int(CDECL *)(libcec_connection_t, CEC_NAMESPACE cec_logical_address));
172 _libcecc_resolve(lib, iface->standby_devices, "libcec_standby_devices", int(CDECL *)(libcec_connection_t, CEC_NAMESPACE cec_logical_address));
173 _libcecc_resolve(lib, iface->set_active_source, "libcec_set_active_source", int(CDECL *)(libcec_connection_t, CEC_NAMESPACE cec_device_type));
174 _libcecc_resolve(lib, iface->set_deck_control_mode, "libcec_set_deck_control_mode", int(CDECL *)(libcec_connection_t, CEC_NAMESPACE cec_deck_control_mode, int));
175 _libcecc_resolve(lib, iface->set_deck_info, "libcec_set_deck_info", int(CDECL *)(libcec_connection_t, CEC_NAMESPACE cec_deck_info, int));
176 _libcecc_resolve(lib, iface->set_inactive_view, "libcec_set_inactive_view", int(CDECL *)(libcec_connection_t));
177 _libcecc_resolve(lib, iface->set_menu_state, "libcec_set_menu_state", int(CDECL *)(libcec_connection_t, CEC_NAMESPACE cec_menu_state, int));
178 _libcecc_resolve(lib, iface->transmit, "libcec_transmit", int(CDECL *)(libcec_connection_t, const CEC_NAMESPACE cec_command*));
179 _libcecc_resolve(lib, iface->set_logical_address, "libcec_set_logical_address", int(CDECL *)(libcec_connection_t, CEC_NAMESPACE cec_logical_address));
180 _libcecc_resolve(lib, iface->set_physical_address, "libcec_set_physical_address", int(CDECL *)(libcec_connection_t, uint16_t));
181 _libcecc_resolve(lib, iface->set_osd_string, "libcec_set_osd_string", int(CDECL *)(libcec_connection_t, CEC_NAMESPACE cec_logical_address, CEC_NAMESPACE cec_display_control, const char*));
182 _libcecc_resolve(lib, iface->switch_monitoring, "libcec_switch_monitoring", int(CDECL *)(libcec_connection_t, int));
183 _libcecc_resolve(lib, iface->get_device_cec_version, "libcec_get_device_cec_version", CEC_NAMESPACE cec_version(CDECL *)(libcec_connection_t, CEC_NAMESPACE cec_logical_address));
184 _libcecc_resolve(lib, iface->get_device_menu_language, "libcec_get_device_menu_language", int(CDECL *)(libcec_connection_t, CEC_NAMESPACE cec_logical_address, CEC_NAMESPACE cec_menu_language));
185 _libcecc_resolve(lib, iface->get_device_vendor_id, "libcec_get_device_vendor_id", uint32_t(CDECL *)(libcec_connection_t, CEC_NAMESPACE cec_logical_address));
186 _libcecc_resolve(lib, iface->get_device_physical_address, "libcec_get_device_physical_address", uint16_t(CDECL *)(libcec_connection_t, CEC_NAMESPACE cec_logical_address));
187 _libcecc_resolve(lib, iface->get_active_source, "libcec_get_active_source", CEC_NAMESPACE cec_logical_address(CDECL *)(libcec_connection_t));
188 _libcecc_resolve(lib, iface->is_active_source, "libcec_is_active_source", int(CDECL *)(libcec_connection_t, CEC_NAMESPACE cec_logical_address));
189 _libcecc_resolve(lib, iface->get_device_power_status, "libcec_get_device_power_status", CEC_NAMESPACE cec_power_status(CDECL *)(libcec_connection_t, CEC_NAMESPACE cec_logical_address));
190 _libcecc_resolve(lib, iface->poll_device, "libcec_poll_device", int(CDECL *)(libcec_connection_t, CEC_NAMESPACE cec_logical_address));
192 _libcecc_resolve(lib, iface->is_active_device, "libcec_is_active_device", int(CDECL *)(libcec_connection_t, CEC_NAMESPACE cec_logical_address));
193 _libcecc_resolve(lib, iface->is_active_device_type, "libcec_is_active_device_type", int(CDECL *)(libcec_connection_t, CEC_NAMESPACE cec_device_type));
194 _libcecc_resolve(lib, iface->set_hdmi_port, "libcec_set_hdmi_port", int(CDECL *)(libcec_connection_t, CEC_NAMESPACE cec_logical_address, uint8_t));
195 _libcecc_resolve(lib, iface->volume_up, "libcec_volume_up", int(CDECL *)(libcec_connection_t, int));
196 _libcecc_resolve(lib, iface->volume_down, "libcec_volume_down", int(CDECL *)(libcec_connection_t, int));
197#if CEC_LIB_VERSION_MAJOR >= 5
198 _libcecc_resolve(lib, iface->mute_audio, "libcec_mute_audio", int(CDECL *)(libcec_connection_t, int));
199#endif
200 _libcecc_resolve(lib, iface->send_keypress, "libcec_send_keypress", int(CDECL *)(libcec_connection_t, CEC_NAMESPACE cec_logical_address, CEC_NAMESPACE cec_user_control_code, int));
201 _libcecc_resolve(lib, iface->send_key_release, "libcec_send_key_release", int(CDECL *)(libcec_connection_t, CEC_NAMESPACE cec_logical_address, int));
202 _libcecc_resolve(lib, iface->get_device_osd_name, "libcec_get_device_osd_name", int(CDECL *)(libcec_connection_t, CEC_NAMESPACE cec_logical_address, CEC_NAMESPACE cec_osd_name));
203 _libcecc_resolve(lib, iface->set_stream_path_logical, "libcec_set_stream_path_logical", int(CDECL *)(libcec_connection_t, CEC_NAMESPACE cec_logical_address));
204 _libcecc_resolve(lib, iface->set_stream_path_physical, "libcec_set_stream_path_physical", int(CDECL *)(libcec_connection_t, uint16_t));
206 _libcecc_resolve(lib, iface->get_current_configuration, "libcec_get_current_configuration", int(CDECL *)(libcec_connection_t, CEC_NAMESPACE libcec_configuration*));
207#if CEC_LIB_VERSION_MAJOR >= 5
208 _libcecc_resolve(lib, iface->can_save_configuration, "libcec_can_save_configuration", int(CDECL *)(libcec_connection_t));
209#else
210 _libcecc_resolve(lib, iface->can_persist_configuration, "libcec_can_persist_configuration", int(CDECL *)(libcec_connection_t));
211 _libcecc_resolve(lib, iface->persist_configuration, "libcec_persist_configuration", int(CDECL *)(libcec_connection_t, CEC_NAMESPACE libcec_configuration*));
212#endif
213 _libcecc_resolve(lib, iface->set_configuration, "libcec_set_configuration", int(CDECL *)(libcec_connection_t, const CEC_NAMESPACE libcec_configuration*));
214 _libcecc_resolve(lib, iface->rescan_devices, "libcec_rescan_devices", void(CDECL *)(libcec_connection_t));
215 _libcecc_resolve(lib, iface->is_libcec_active_source, "libcec_is_libcec_active_source", int(CDECL *)(libcec_connection_t));
216 _libcecc_resolve(lib, iface->get_device_information, "libcec_get_device_information", int(CDECL *)(libcec_connection_t, const char*, CEC_NAMESPACE libcec_configuration*, uint32_t));
217 _libcecc_resolve(lib, iface->get_lib_info, "libcec_get_lib_info", const char*(CDECL *)(libcec_connection_t));
218 _libcecc_resolve(lib, iface->init_video_standalone, "libcec_init_video_standalone", void(CDECL *)(libcec_connection_t));
219 _libcecc_resolve(lib, iface->get_adapter_vendor_id, "libcec_get_adapter_vendor_id", uint16_t(CDECL *)(libcec_connection_t));
220 _libcecc_resolve(lib, iface->get_adapter_product_id, "libcec_get_adapter_product_id", uint16_t(CDECL *)(libcec_connection_t));
221 _libcecc_resolve(lib, iface->audio_toggle_mute, "libcec_audio_toggle_mute", uint8_t(CDECL *)(libcec_connection_t));
222 _libcecc_resolve(lib, iface->audio_mute, "libcec_audio_mute", uint8_t(CDECL *)(libcec_connection_t));
223 _libcecc_resolve(lib, iface->audio_unmute, "libcec_audio_unmute", uint8_t(CDECL *)(libcec_connection_t));
224 _libcecc_resolve(lib, iface->audio_get_status, "libcec_audio_get_status", uint8_t(CDECL *)(libcec_connection_t));
225 _libcecc_resolve(lib, iface->system_audio_mode, "libcec_system_audio_mode", int(CDECL *)(libcec_connection_t, int));
226 _libcecc_resolve(lib, iface->system_audio_mode_get_status, "libcec_system_audio_mode_get_status", uint8_t(CDECL *)(libcec_connection_t));
227 _libcecc_resolve(lib, iface->detect_adapters, "libcec_detect_adapters", int8_t(CDECL *)(libcec_connection_t, CEC_NAMESPACE cec_adapter_descriptor*, uint8_t, const char*, int));
228 _libcecc_resolve(lib, iface->menu_state_to_string, "libcec_menu_state_to_string", void(CDECL *)(const CEC_NAMESPACE cec_menu_state, char*, size_t));
229 _libcecc_resolve(lib, iface->cec_version_to_string, "libcec_cec_version_to_string", void(CDECL *)(const CEC_NAMESPACE cec_version, char*, size_t));
230 _libcecc_resolve(lib, iface->power_status_to_string, "libcec_power_status_to_string", void(CDECL *)(const CEC_NAMESPACE cec_power_status, char*, size_t));
231 _libcecc_resolve(lib, iface->logical_address_to_string, "libcec_logical_address_to_string", void(CDECL *)(const CEC_NAMESPACE cec_logical_address, char*, size_t));
232 _libcecc_resolve(lib, iface->deck_control_mode_to_string, "libcec_deck_control_mode_to_string", void(CDECL *)(const CEC_NAMESPACE cec_deck_control_mode, char*, size_t));
233 _libcecc_resolve(lib, iface->deck_status_to_string, "libcec_deck_status_to_string", void(CDECL *)(const CEC_NAMESPACE cec_deck_info, char*, size_t));
234 _libcecc_resolve(lib, iface->opcode_to_string, "libcec_opcode_to_string", void(CDECL *)(const CEC_NAMESPACE cec_opcode, char*, size_t));
235 _libcecc_resolve(lib, iface->system_audio_status_to_string, "libcec_system_audio_status_to_string", void(CDECL *)(const CEC_NAMESPACE cec_system_audio_status, char*, size_t));
236 _libcecc_resolve(lib, iface->audio_status_to_string, "libcec_audio_status_to_string", void(CDECL *)(const CEC_NAMESPACE cec_audio_status, char*, size_t));
237 _libcecc_resolve(lib, iface->vendor_id_to_string, "libcec_vendor_id_to_string", void(CDECL *)(const CEC_NAMESPACE cec_vendor_id, char*, size_t));
238 _libcecc_resolve(lib, iface->user_control_key_to_string, "libcec_user_control_key_to_string", void(CDECL *)(const CEC_NAMESPACE cec_user_control_code, char*, size_t));
239 _libcecc_resolve(lib, iface->adapter_type_to_string, "libcec_adapter_type_to_string", void(CDECL *)(const CEC_NAMESPACE cec_adapter_type, char*, size_t));
240 _libcecc_resolve(lib, iface->version_to_string, "libcec_version_to_string", void(CDECL *)(uint32_t, char*, size_t));
241
242 return 1;
243}
244
246{
248#if defined(_WIN32) || defined(_WIN64) || defined(_M_ARM64)
249 lib = LoadLibrary(strLib ? strLib : "cec.dll");
250 if (lib == NULL)
251 printf("failed to load cec.dll\n");
252#else
253 #if defined(__APPLE__)
254 lib = dlopen(strLib ? strLib : "libcec." CEC_LIB_VERSION_MAJOR_STR ".dylib", RTLD_LAZY);
255 #else
256 lib = dlopen(strLib ? strLib : "libcec.so." CEC_LIB_VERSION_MAJOR_STR, RTLD_LAZY);
257 #endif
258 if (lib == NULL)
259 printf("%s\n", dlerror());
260#endif
261 return lib;
262}
263
265{
266#if defined(_WIN32) || defined(_WIN64) || defined(_M_ARM64)
267 FreeLibrary(lib);
268#else
269 dlclose(lib);
270#endif
271}
272
273static void* libcecc_resolve(void* lib, const char* name)
274{
275#if defined(_WIN32) || defined(_WIN64) || defined(_M_ARM64)
276 return GetProcAddress(lib, name);
277#else
278 return dlsym(lib, name);
279#endif
280}
281
282void libcecc_reset_configuration(CEC_NAMESPACE libcec_configuration* configuration)
283{
284 void(CDECL * _clear_configuration)(CEC_NAMESPACE libcec_configuration*);
286
287 memset(configuration, 0, sizeof(CEC_NAMESPACE libcec_configuration));
288 lib = libcecc_load_library(NULL);
289 if (lib == NULL)
290 return;
291
292 _clear_configuration = (void(CDECL *)(CEC_NAMESPACE libcec_configuration*)) libcecc_resolve(lib, "libcec_clear_configuration");
293 if (_clear_configuration)
294 _clear_configuration(configuration);
295
297}
298
305int libcecc_initialise(CEC_NAMESPACE libcec_configuration* configuration, libcec_interface_t* iface, const char* strLib)
306{
307 void* (CDECL *_cec_initialise)(CEC_NAMESPACE libcec_configuration*);
308
310 lib = libcecc_load_library(strLib);
311 if (lib == NULL)
312 return -1;
313
314 _libcecc_resolve(lib, _cec_initialise, "libcec_initialise", void* (CDECL *)(CEC_NAMESPACE libcec_configuration*));
315
316 iface->lib_instance = lib;
317 iface->connection = _cec_initialise(configuration);
318
319 return iface->connection ?
320 libcecc_resolve_all(lib, iface) :
321 0;
322}
323
329{
330 if (iface->destroy)
331 iface->destroy(iface->connection);
333 memset(iface, 0, sizeof(libcec_interface_t));
334}
CEC::ICECAdapter * libcec_connection_t
Definition cecc.h:45
#define CEC_NAMESPACE
Definition cecc.h:44
#define CDECL
Definition ceccloader.h:45
static void libcecc_close_library(libcecc_lib_instance_t lib)
Definition ceccloader.h:264
static libcecc_lib_instance_t libcecc_load_library(const char *strLib)
Definition ceccloader.h:245
#define _libcecc_resolve(lib, tar, name, method)
Definition ceccloader.h:53
static int libcecc_resolve_all(void *lib, libcec_interface_t *iface)
Definition ceccloader.h:152
static void * libcecc_resolve(void *lib, const char *name)
Definition ceccloader.h:273
void * libcecc_lib_instance_t
Definition ceccloader.h:43
void libcecc_reset_configuration(CEC::libcec_configuration *configuration)
Definition ceccloader.h:282
void libcecc_destroy(libcec_interface_t *iface)
Destroy an instance of libCEC.
Definition ceccloader.h:328
int libcecc_initialise(CEC::libcec_configuration *configuration, libcec_interface_t *iface, const char *strLib)
Create a new libCEC instance.
Definition ceccloader.h:305
To create a new libCEC instance, call CECInitialise() and pass the configuration as argument.
Definition cec.h:54
const char *(* get_lib_info)(libcec_connection_t connection)
Definition ceccloader.h:126
CEC::cec_logical_addresses(* get_active_devices)(libcec_connection_t connection)
Definition ceccloader.h:100
int(* volume_down)(libcec_connection_t connection, int bSendRelease)
Definition ceccloader.h:105
int(* open)(libcec_connection_t connection, const char *strPort, uint32_t iTimeout)
Definition ceccloader.h:68
uint16_t(* get_device_physical_address)(libcec_connection_t connection, CEC::cec_logical_address iLogicalAddress)
Definition ceccloader.h:95
void(* audio_status_to_string)(const CEC::cec_audio_status status, char *buf, size_t bufsize)
Definition ceccloader.h:145
void(* logical_address_to_string)(const CEC::cec_logical_address address, char *buf, size_t bufsize)
Definition ceccloader.h:140
int(* set_configuration)(libcec_connection_t connection, const CEC::libcec_configuration *configuration)
Definition ceccloader.h:122
uint8_t(* audio_unmute)(libcec_connection_t connection)
Definition ceccloader.h:132
uint16_t(* get_adapter_product_id)(libcec_connection_t connection)
Definition ceccloader.h:129
int(* set_logical_address)(libcec_connection_t connection, CEC::cec_logical_address iLogicalAddress)
Definition ceccloader.h:88
libcecc_lib_instance_t lib_instance
Definition ceccloader.h:65
int(* get_device_menu_language)(libcec_connection_t connection, CEC::cec_logical_address iLogicalAddress, CEC::cec_menu_language language)
Definition ceccloader.h:93
void(* version_to_string)(uint32_t version, char *buf, size_t bufsize)
Definition ceccloader.h:149
int(* power_on_devices)(libcec_connection_t connection, CEC::cec_logical_address address)
Definition ceccloader.h:80
int(* is_active_device)(libcec_connection_t connection, CEC::cec_logical_address address)
Definition ceccloader.h:101
int(* get_device_information)(libcec_connection_t connection, const char *strPort, CEC::libcec_configuration *config, uint32_t iTimeoutMs)
Definition ceccloader.h:125
uint8_t(* audio_mute)(libcec_connection_t connection)
Definition ceccloader.h:131
int(* get_current_configuration)(libcec_connection_t connection, CEC::libcec_configuration *configuration)
Definition ceccloader.h:115
uint16_t(* get_adapter_vendor_id)(libcec_connection_t connection)
Definition ceccloader.h:128
void(* opcode_to_string)(const CEC::cec_opcode opcode, char *buf, size_t bufsize)
Definition ceccloader.h:143
int8_t(* detect_adapters)(libcec_connection_t connection, CEC::cec_adapter_descriptor *deviceList, uint8_t iBufSize, const char *strDevicePath, int bQuickScan)
Definition ceccloader.h:136
void(* adapter_type_to_string)(const CEC::cec_adapter_type type, char *buf, size_t bufsize)
Definition ceccloader.h:148
uint8_t(* audio_get_status)(libcec_connection_t connection)
Definition ceccloader.h:133
int(* send_keypress)(libcec_connection_t connection, CEC::cec_logical_address iDestination, CEC::cec_user_control_code key, int bWait)
Definition ceccloader.h:109
CEC::cec_logical_address(* get_active_source)(libcec_connection_t connection)
Definition ceccloader.h:96
int(* set_deck_info)(libcec_connection_t connection, CEC::cec_deck_info info, int bSendUpdate)
Definition ceccloader.h:84
int(* volume_up)(libcec_connection_t connection, int bSendRelease)
Definition ceccloader.h:104
int(* ping_adapters)(libcec_connection_t connection)
Definition ceccloader.h:78
int(* set_osd_string)(libcec_connection_t connection, CEC::cec_logical_address iLogicalAddress, CEC::cec_display_control duration, const char *strMessage)
Definition ceccloader.h:90
int(* is_active_device_type)(libcec_connection_t connection, CEC::cec_device_type type)
Definition ceccloader.h:102
void(* clear_configuration)(CEC::libcec_configuration *configuration)
Definition ceccloader.h:70
int(* switch_monitoring)(libcec_connection_t connection, int bEnable)
Definition ceccloader.h:91
int(* mute_audio)(libcec_connection_t connection, int bSendRelease)
Definition ceccloader.h:107
int(* start_bootloader)(libcec_connection_t connection)
Definition ceccloader.h:79
libcec_connection_t connection
Definition ceccloader.h:64
void(* menu_state_to_string)(const CEC::cec_menu_state state, char *buf, size_t bufsize)
Definition ceccloader.h:137
int(* send_key_release)(libcec_connection_t connection, CEC::cec_logical_address iDestination, int bWait)
Definition ceccloader.h:110
int(* is_libcec_active_source)(libcec_connection_t connection)
Definition ceccloader.h:124
CEC::cec_power_status(* get_device_power_status)(libcec_connection_t connection, CEC::cec_logical_address iLogicalAddress)
Definition ceccloader.h:98
CEC::cec_logical_addresses(* get_logical_addresses)(libcec_connection_t connection)
Definition ceccloader.h:114
int(* set_physical_address)(libcec_connection_t connection, uint16_t iPhysicalAddress)
Definition ceccloader.h:89
int(* set_menu_state)(libcec_connection_t connection, CEC::cec_menu_state state, int bSendUpdate)
Definition ceccloader.h:86
int(* poll_device)(libcec_connection_t connection, CEC::cec_logical_address iLogicalAddress)
Definition ceccloader.h:99
int(* set_callbacks)(libcec_connection_t connection, CEC::ICECCallbacks *callbacks, void *cbParam)
Definition ceccloader.h:72
int(* system_audio_mode)(libcec_connection_t connection, int bEnable)
Definition ceccloader.h:134
void(* init_video_standalone)(libcec_connection_t connection)
Definition ceccloader.h:127
void(* cec_version_to_string)(const CEC::cec_version version, char *buf, size_t bufsize)
Definition ceccloader.h:138
int(* get_device_osd_name)(libcec_connection_t connection, CEC::cec_logical_address iAddress, CEC::cec_osd_name name)
Definition ceccloader.h:111
int(* is_active_source)(libcec_connection_t connection, CEC::cec_logical_address iAddress)
Definition ceccloader.h:97
int(* set_deck_control_mode)(libcec_connection_t connection, CEC::cec_deck_control_mode mode, int bSendUpdate)
Definition ceccloader.h:83
void(* user_control_key_to_string)(const CEC::cec_user_control_code key, char *buf, size_t bufsize)
Definition ceccloader.h:147
int(* transmit)(libcec_connection_t connection, const CEC::cec_command *data)
Definition ceccloader.h:87
void(* deck_status_to_string)(const CEC::cec_deck_info status, char *buf, size_t bufsize)
Definition ceccloader.h:142
int(* set_active_source)(libcec_connection_t connection, CEC::cec_device_type type)
Definition ceccloader.h:82
void(* system_audio_status_to_string)(const CEC::cec_system_audio_status mode, char *buf, size_t bufsize)
Definition ceccloader.h:144
CEC::cec_version(* get_device_cec_version)(libcec_connection_t connection, CEC::cec_logical_address iLogicalAddress)
Definition ceccloader.h:92
int(* standby_devices)(libcec_connection_t connection, CEC::cec_logical_address address)
Definition ceccloader.h:81
int(* can_save_configuration)(libcec_connection_t connection)
Definition ceccloader.h:117
void(* close)(libcec_connection_t connection)
Definition ceccloader.h:69
int(* disable_callbacks)(libcec_connection_t connection)
Definition ceccloader.h:73
int8_t(* find_adapters)(libcec_connection_t connection, CEC::cec_adapter *deviceList, uint8_t iBufSize, const char *strDevicePath)
Definition ceccloader.h:77
void(* vendor_id_to_string)(const CEC::cec_vendor_id vendor, char *buf, size_t bufsize)
Definition ceccloader.h:146
uint8_t(* system_audio_mode_get_status)(libcec_connection_t connection)
Definition ceccloader.h:135
void(* deck_control_mode_to_string)(const CEC::cec_deck_control_mode mode, char *buf, size_t bufsize)
Definition ceccloader.h:141
int(* set_hdmi_port)(libcec_connection_t connection, CEC::cec_logical_address baseDevice, uint8_t iPort)
Definition ceccloader.h:103
libcec_connection_t(* initialise)(CEC::libcec_configuration *configuration)
Definition ceccloader.h:66
int(* set_inactive_view)(libcec_connection_t connection)
Definition ceccloader.h:85
int(* set_stream_path_physical)(libcec_connection_t connection, uint16_t iPhysicalAddress)
Definition ceccloader.h:113
void(* destroy)(libcec_connection_t connection)
Definition ceccloader.h:67
uint32_t(* get_device_vendor_id)(libcec_connection_t connection, CEC::cec_logical_address iLogicalAddress)
Definition ceccloader.h:94
int(* set_stream_path_logical)(libcec_connection_t connection, CEC::cec_logical_address iAddress)
Definition ceccloader.h:112
void(* power_status_to_string)(const CEC::cec_power_status status, char *buf, size_t bufsize)
Definition ceccloader.h:139
void(* rescan_devices)(libcec_connection_t connection)
Definition ceccloader.h:123
uint8_t(* audio_toggle_mute)(libcec_connection_t connection)
Definition ceccloader.h:130