Controlling Multiple Devices with a single Remote Control
The CEC protocol is a simple protocol adopted by Consumer Electronics manufacturers to pass control signals down HDMI cables to other devices. One application of CEC is to pass control signals from a Television remote control to a media centre such as MythTV or XBMC. Configuring and using CEC is considerably easier in most cases than setting up LIRC to use an infra red remote control directly with the media centre.
Most computers are unable to read the CEC signals coming over the HDMI cables so there is a market for HDMI to USB adapters to intercept the CEC commands and pass them to an application via a USB interface. A suitable adapter verified to work with Mageia is manufactured by Pulse-Eight. Other manufacturers are Kwikwai and RainShadowTech.
These adapters all operate in the same way. They sit between the HDMI port of your television, and the HDMI port of your computer video card. The CEC signals carried on two conductors of the HDMI cable are intercepted and converted to a serial data stream which is fed into a USB port. Be aware that many of the HDMI cables sold in shops and on ebay do not have the extra two conductors for CEC. Only buy HDMI cables labelled as CEC compliant. Most problems with setting up CEC are due to using the wrong cable.
Applications that are CEC aware include XBMS and MythTV.
In order to use libCEC to manage your media server using your TV remote you will need :-
- A television with HDMI interfaces with support for CEC protocol. Manufactures have their own names for this feature such as Anynet+ (Samsung); Aquos Link (Sharp); BRAVIA Link and BRAVIA Sync (Sony); HDMI-CEC (Hitachi); E-link (AOC); Kuro Link (Pioneer); CE-Link and Regza Link (Toshiba); RIHD (Remote Interactive over HDMI) (Onkyo); RuncoLink (Runco International); SimpLink (LG); HDAVI Control, EZ-Sync, VIERA Link (Panasonic); EasyLink (Philips); and NetCommand for HDMI (Mitsubishi).
- A computer with HDMI output and a spare USB socket.
- A USB to HDMI CEC adapter
- In the future we can expect computers to come with built in CEC capability. At the moment the only computer known to have built in CEC is the humble Raspberry-Pi
The library used to communicate with the CEC adapter is libcec2. In Mageia 4 the version is libcec-2.1.3-2.mga4. This version of the library is compatible with mythtv-frontend-0.27-20131222.2.mga4.
Anyone attempting to use libCEC on Mageia2 should be aware that libcec1 shipped with Mageia 2 is not compatible with mythtv-frontend and a later version of libcec1 (not libcec2) must be manually compiled.
- In Mageia 3 mythtv-frontend has been hard coded to always use HDMI Port 2 '. You must connect the HDMI cable to socket number 2 on your television. If your television has only one HDMI socket then hard luck.
Plugging in the usb port of the adapter will load the kernel module cdc_acm and the serial port /dev/ttyACM0 will be used to communicate with the adapter. Your user will need to be a member of the 'dialout' and 'lock' groups. Use userdrake in Mageia Control Centre to make your user a member of these groups.
Testing a USB<=>HDMI adapter
Included in Mageia is the cec-utils package which contains the utility cec-client which can be used to verify the operation of the CEC adapter. To use cec-client ensure that mythfrontend or XBMS are not running or else they will take control of the adapter themselves. Running cec-client without any parameters will display the protocol handshake between the computer and the television.
# cec-client No device type given. Using 'recording device' CEC Parser created - libCEC version 2.1.1 no serial port given. trying autodetect: path: /sys/devices/pci0000:00/0000:00:1d.3/usb4/4-1 com port: /dev/ttyACM0 opening a connection to the CEC adapter... DEBUG: [ 53] unregistering all CEC clients DEBUG: [ 53] Broadcast (F): osd name set to 'Broadcast' DEBUG: [ 56] connection opened, clearing any previous input and waiting for active transmissions to end before starting DEBUG: [ 57] communication thread started DEBUG: [ 68] turning controlled mode on NOTICE: [ 89] connection opened DEBUG: [ 125] TV (0): device status changed into 'present' DEBUG: [ 125] << requesting vendor ID of 'TV' (0) TRAFFIC: [ 125] << f0:8c TRAFFIC: [ 322] >> 0f:87:08:00:46 DEBUG: [ 323] >> TV (0) -> Broadcast (F): device vendor id (87) DEBUG: [ 323] TV (0): vendor = Sony (080046) DEBUG: [ 323] expected response received (87: device vendor id) NOTICE: [ 323] registering new CEC client - v2.1.1 DEBUG: [ 323] detecting logical address for type 'recording device' DEBUG: [ 323] trying logical address 'Recorder 1' DEBUG: [ 391] using logical address 'Recorder 1' DEBUG: [ 391] Recorder 1 (1): device status changed into 'handled by libCEC' DEBUG: [ 391] Recorder 1 (1): power status changed from 'unknown' to 'on' DEBUG: [ 391] Recorder 1 (1): CEC version 1.4 DEBUG: [ 391] AllocateLogicalAddresses - device '0', type 'recording device', LA '1' DEBUG: [ 391] setting ackmask to 2 DEBUG: [ 396] Recorder 1 (1): osd name set to 'CECTester' DEBUG: [ 396] Recorder 1 (1): menu language set to 'eng' DEBUG: [ 396] GetPhysicalAddress - trying to get the physical address via ADL DEBUG: [ 399] SetDevicePhysicalAddress - not setting invalid physical address 0000 NOTICE: [ 399] setting HDMI port to 1 on device TV (0) DEBUG: [ 399] Recorder 1 (1): physical address changed from ffff to 1000 DEBUG: [ 399] << Recorder 1 (1) -> broadcast (F): physical adddress 1000 TRAFFIC: [ 399] << 1f:84:10:00:01 DEBUG: [ 536] using persisted autonomous mode setting: 'enabled' DEBUG: [ 541] using persisted CEC version setting: '1.4' DEBUG: [ 546] using persisted logical address setting: 'Recorder 1' DEBUG: [ 552] using persisted device type setting: 'recording device' DEBUG: [ 557] using persisted logical address mask setting: '206' DEBUG: [ 572] using persisted device name setting: 'CECTester' DEBUG: [ 577] using persisted physical address setting: '1000' NOTICE: [ 578] CEC client registered: libCEC version = 2.1.1, client version = 2.1.1, firmware version = 4, firmware build date: Thu Dec 6 11:15:20 2012 +0000, logical address(es) = Recorder 1 (1) , base device: TV (0), HDMI port number: 1, physical address: 22.214.171.124, host: x86_64-mageia-linux-gnu, features: 'P8 USB' 'P8 USB detect', compiled on: Fri Mar 29 06:40:39 UTC 2013 by email@example.com on Linux 3.4.34-server-1.mga2 (x86_64) DEBUG: [ 578] << Recorder 1 (1) -> TV (0): OSD name 'CECTester' TRAFFIC: [ 578] << 10:47:43:45:43:54:65:73:74:65:72 DEBUG: [ 853] << requesting power status of 'TV' (0) TRAFFIC: [ 853] << 10:8f TRAFFIC: [ 1024] >> 01:00:47:01 DEBUG: [ 1024] >> TV (0) -> Recorder 1 (1): feature abort ( 0) DEBUG: [ 1910] expected response not received (90: report power status) TRAFFIC: [ 1910] << 10:8f TRAFFIC: [ 2057] >> 01:90:01 DEBUG: [ 2058] >> TV (0) -> Recorder 1 (1): report power status (90) DEBUG: [ 2058] TV (0): power status changed from 'unknown' to 'standby' DEBUG: [ 2058] expected response received (90: report power status) waiting for input TRAFFIC: [ 51654] >> 01:8c DEBUG: [ 51654] >> TV (0) -> Recorder 1 (1): give device vendor id (8C) DEBUG: [ 51654] << Recorder 1 (1) -> TV (0): vendor id feature abort DEBUG: [ 51654] << transmitting abort message TRAFFIC: [ 55981] >> 01:44:00 DEBUG: [ 55981] >> TV (0) -> Recorder 1 (1): user control pressed (44) DEBUG: [ 55982] key pressed: select (0) TRAFFIC: [ 56247] >> 01:45 DEBUG: [ 56247] >> TV (0) -> Recorder 1 (1): user control release (45) DEBUG: [ 56247] key released: select (0) TRAFFIC: [ 58264] >> 01:44:04 DEBUG: [ 58264] >> TV (0) -> Recorder 1 (1): user control pressed (44) DEBUG: [ 58264] key pressed: right (4) TRAFFIC: [ 58331] >> 01:45 DEBUG: [ 58331] >> TV (0) -> Recorder 1 (1): user control release (45) DEBUG: [ 58331] key released: right (4)
By pressing keys on the remote you will be able to see the code generated for each key.
cec-client called with the -l switch will list all the CEC devices detected
# cec-client -l Found devices: 1 device: 1 com port: /dev/ttyACM0 vendor id: 2548 product id: 1002 firmware version: 4 firmware build date: Thu Dec 6 11:15:20 2012 +0000 type: Pulse-Eight USB-CEC Adapter
Using libcec with MythTV
There is no set up required to use libCEC with MythTV. On starting mythfrontend the log will show that a CEC device has been detected on the port /dev/ttyACM0. The television remote control can now be used to select and control the mythfrontend. On a Sony Bravia television for example the "Sync" button on the remote will open a box to select the remote device to control, and will switch the television to HDMI Port 2. Button presses on the remote control will be passed to mythfrontend.
The keybindings that translate what the television remote control buttons do in MythTV are not complete by default. Some buttons are unassigned. It is a simple matter to make new key assignments using the keybindings setup in mythfrontend>Settings.
Updating Pulse-Eight adapter firmware
Future releases of Mageia with newer versions of libcec2 may require the firmware in the adapter to be upgraded also. Pulse-Eight provide update scripts for Windows and Ubuntu which can be downloaded from their web site. In their wisdom Pulse-Eight do not provide a tarball containing the firmware installer so users of other Linux distros can upgrade the firmware. So to upgrade the adapter firmware it is necessary to download the Ubuntu .deb package and extract the firmware updating utility from it. A list of Ubuntu packages is here.
Once the appropriate .deb package has been downloaded the package can be uncompressed using Ark or File-Roller. Inside you will find a file called cec-firmware-upgrade. Executing that file will upgrade the CEC adapter firmware. (Do not forget to close XBMC or mythfrontend first)