![]() |
libCEC 8.1.0
C / C++ API — control CEC-capable HDMI devices
|
libCEC lets applications control CEC-capable HDMI hardware — power a TV on or to standby, become the active source, send remote-control keys, read device state — and receive everything happening on the CEC bus. It works over Pulse-Eight's USB-CEC adapter (the cross-platform default) and SoC-native CEC on Linux and Raspberry Pi.
This is the reference for the native interface. Everything else — the .NET, Node.js and Python bindings — is a thin wrapper over the same engine, so the concepts documented here (logical and physical addresses, device types, opcodes, power states) carry across all of them.
There are two native surfaces:
CEC::ICECAdapter interface in cec.h, the object you send commands through. Events arrive via the CEC::ICECCallbacks function pointers in cectypes.h.libcec_* functions in cecc.h, the same surface the .NET and Node.js bindings bind. Prefer this for FFI.cec shared library).On Pulse-Eight's own package feed the development package is named after the SONAME (libcec8-dev); distribution repositories ship it as libcec-dev.
Platform-native CEC backends are off by default and enabled with cmake flags (e.g. -DHAVE_LINUX_API=1, -DHAVE_RPI_API=1); without one, only the Pulse-Eight USB adapter backend is built. See the platform notes for Linux, macOS and Raspberry Pi.
Install the USB-CEC Adapter software from Pulse-Eight (it ships cec.dll, the import library cec.lib and the headers), or build the library and installer from source with python windows\create-installer.py (see the Windows build notes). Compile against the flat headers and link cec.lib; at runtime keep cec.dll on the DLL search path.
The lifecycle is: describe yourself in a CEC::libcec_configuration, register callbacks, create the instance with LibCecInitialise() (from cecloader.h, which loads the shared library for you), open a connection, then send commands. Tear down with Close() + UnloadLibCec().
Build it against the installed library with pkg-config:
Every CEC::ICECCallbacks member is optional — set only the ones you need and leave the rest null (that is what Clear() does). libCEC invokes them from its own worker thread, so treat the payloads as read-only and hand work off to your own thread if it is expensive. The menuStateChanged and commandHandler callbacks additionally return an int telling libCEC whether you handled the event; the others are notifications.
For FFI or C code, use cecc.h instead: libcec_initialise(), libcec_open(), libcec_power_on_devices(), libcec_close(), libcec_destroy(), and so on — the same operations as ICECAdapter, taking a libcec_connection_t handle as the first argument. ceccloader.h provides the matching dynamic loader.
CEC::ICECAdapter — the full method reference (open, transmit, power, queries).CEC::ICECCallbacks — the event surface.CEC::libcec_configuration — every configurable field.libCEC is Copyright © Pulse-Eight Limited, dual-licensed (GPL-2.0-or-later or commercial). See the project on GitHub.