Consumer electronic control (CEC) is a feature of the HDMI interface 1.3 standard (high definition multimedia interface), which is used to transmit audio/video data for multimedia consumer products such as HDTV, DVDs, satellite receivers etc. For example, One Touch Play lets a media source device turn on the TV and switch its input port automatically, so you don’t have to search for the TV remote to switch from your Chromecast to Blu-ray player or using the remote control of a CEC enabled TV, you can control the set-top box or DVD player, controlling the TV from HDMI-CEC enabled android device via HDMI CEC application. The most commonly used CEC commands are : One Touch Play,System Standby, One Touch Record, System Information,Tuner Control,Routing Control, OSD Display, System Audio Control etc. This article explains the basic of HDMI CEC protocols and how this can be implemented in android framework.

Here are the important terminologies related to HDMI CEC.

Broadcast Message This is a message, sent to logical address 15, which all devices are expected to receive.

Deck The part of a Recording Device or Playback Device that provides playback functionality e.g. from a removable media.

Destination The target device for a CEC message.

Follower A device that has just received a CEC message and is required to respond to it.

Initiator The device that is sending, or has just sent, a CEC message and, if appropriate, is waiting for a follower to respond.

Physical address Whenever a HPD is de-asserted or upon power-up, a CEC device should allocate a physical address as described in HDMI specification . (refer section 8.7.3 in High-Definition Multimedia Interface Specification Version 1.3a)

Logical address A unique address assigned to each device. Each device appearing on the control signal line has a logical address which is allocated to only one device in the system. The following is list of local address for the corresponding device.

Address Device
0 TV
1 Recording Device 1
2 Recording Device 2
3 Tuner 1
4 Playback Device 1
5 Audio System
6 Tuner 2
7 Tuner 3
8 Playback Device 2
9 Recording Device 3
10 Tuner 4
11 Playback Device 3
12 Reserved
13 Reserved
14 Free Use
15 Unregistered (as initiator address) or Broadcast (as destination address)

Playback device A device that has the ability to play media, e.g. a DVD Player.

Recording device A device that has the ability to record a source such as an internal tuner or an external connection.

Source Device A device that is currently providing an AV stream via HDMI.

Tuner Device A device that contains a tuner, e.g. a STB or a Recording Device.

TV A device with HDMI input that has the ability to display the input HDMI signal. Generally it has no HDMI output.

CEC frame

The CEC bus is a single-wire protocol and this communication is handled by the CEC pin (Pin 13 )of the HDMI connector. CEC wiring in HDMI is mandatory, while implementation of CEC in a product is optional. CEC Frame mainly consists of below blocks.

  • Start bit
  • Header block
  • Data Block

Below image shows the block diagram of a HDMI-CEC frame.

CEC Frame

Start bit CEC message transaction must begin with one start bit. It is unique and identifies the start of a frame.

Header block Header blocks contain the 4-bit logical address of the Initiator and 4-bit logical address of the destination followed by the end-of-message (EOM) bit and the Acknowledge (ACK) bit. The EOM bit is used to indicate if this is the final block in the message. The below image shows a example header bock in CEC message.

CEC Header

Data Block A Data block is a sequence of 10 bits of which first 8 -bit field that represents the opcode or the operand, and followed by the end-of-message (EOM) bit and the Acknowledge (ACK) bit. The following bock diagram shows a data block in HDMI CEC message.

Data Block

HDMI CEC in Android Framework

With the introduction of the Android TV Input Framework (TIF), Android has created a system service called HdmiControlService to support HDMI-CEC in Android frameworks. Before Android 5.0, hardware vendors used to develop custom CEC HAL. After Android 5.0, AOSP supports HDMI control service via HdmiControlService. To support HDMI,CEC in your android device, hardware vendor has to develop HDMI-CEC hardware abstraction layer (HAL) .

HDMI-CEC in Android

A standard implementation of HDMI-CEC for all manufacturers, which will reduce device incompatibility. Previously, manufacturers had to develop their own implementations of HDMI-CEC or use third-party solutions.For more details on implementing HDMI CEC HAL, you can refer Android development resource.

HDMI CEC in Linux kernel

HDMI CEC driver should be implemented in the Linux kernel in-order to support HDMI-CEC. Once the HDMI CEC driver is implemented, you can found HDMI CEC device name under /dev/devicename_cec/. Here is the github link for an example Linux HDMI-CEC stack/driver in Linux.

In order to communicate with CEC adaptor , you can use libCEC which is an open-source dual licensed library. Here is the link for source code of libcec.

This libcec will support Windows, Mac OS X, and Linux, and Android (in case of Android you need to develop HAL and Framework)

References

  1. http://www.microprocessor.org/HDMISpecification13a.pdf
  2. https://source.android.com/devices/tv/HDMI-CEC.html

Portions of this page are reproduced from work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.