CEC Remote Plugin

CEC Plugin

Plugin to receive and send commands via CEC.

Requirements

Installation:

First get the connected devices either via the cec-client if the plugin is not running :

echo "scan" | cec-client -s -d 1

The output should look like:

    opening a connection to the CEC adapter...
    requesting CEC bus information ...
    CEC bus information
    ===================
    device #0: TV
    address:       0.0.0.0
    active source: no
    vendor:        Panasonic
    osd string:    TV
    CEC version:   1.4
    power status:  on
    language:      ger

   device #4: Playback 1
    address:       1.0.0.0
    active source: no
    vendor:        Panasonic
    osd string:    CECTester
    CEC version:   1.4
    power status:  on
    language:      eng

    device #8: Playback 2
    address:       2.0.0.0
    active source: no
    vendor:        Samsung
    osd string:    BD Player
    CEC version:   1.4
    power status:  on
    language:      ???

On a running VDR with the cecremote plugin enabled, this information can be retrieved via:

svdrpsend plug cecremote LSTD

The output should look like:

220 vdr SVDRP VideoDiskRecorder 2.0.7; Sun Mar  1 15:19:31 2015; UTF-8
214-Available CEC Devices:
214-  Device 0 path: /sys/devices/pci0000:00/0000:00:14.0/usb1/1-3 port: /dev/ttyACM0 Firmware 0004
214-
214-Active Devices:
214-   0# TV             @0000 TV              TV             Panasonic
214-   3# Tuner 1        @1000 Tuner 1         VDR            VDR
214-   4# Playback 1     @1000 VDR             VDR            VDR
214    8# Playback 2     @2000 BD Player       BD Player      Samsung
221 vdr closing connection

In the plugin configuration directory create the file cecremote.xml (an example can be found in the contrib directory) with a device entry for each device which should be handled by the plugin.

Format of the configuration file.

The configuration file is in XML format. The root element is <config>. Within this element one <global> child element is used to specify global options for this plugin and several <menu>, <device>, <ceckeymap> and <vdrkeymap> child elements.

<ceckeymap>

This element contains the definitions for mapping a CEC Key to one or more VDR keys. The <ceckeymap> tag must have the attribute "id" specified. This id is used later in the <player> section to address this key map.

This tag creates a new key map with a preconfigured map. Elements of this map can be overwritten with <key> elements.

<vdrkeymap>

This element contains definitions for mapping a VDR Key to one or more CEC keys. The <vdrkeymap> tag must have the attribute "id" specified. This id is used later in the <player> section to address this key map.

This tag creates a new key map with a preconfigured map. Elements of this map can be overwritten with <key> elements.

<key>

This element is used within <ceckeymap> or <vdrkeymap> to overwrite existing map entries. The <key> tag must have the attribute "code" specified. This specifies the key code to redefine. If used in <ceckeymap> code is a CEC key name (see svdrpsend plug cecremote LSTK for the name of the supported CEC key codes). When used in <vdrkeymap> the code is the vdr key name as used for example in keymacros.conf.

The <key> element can have <value> elements which specifies the key codes to map. If no <value> element is specified, this key code is not mapped and so this key is not usable.

<value>

This element is used within <key> to assign key codes to the key map.

If the <value> element is used in <vdrkeymap> the <value> element contains a CEC key name (see svdrpsend plug cecremote LSTK for the name of the supported CEC key codes). When used in <ceckeymap> the <value> element is the vdr key name as used for example in keymacros.conf. The following example create a new key map with id "TV" where the VDR key OK is mapped the the CEC "ROOT_MENU" key:

  <vdrkeymap id="TV">
    <key code="OK">
      <value>ROOT_MENU</value>
    </key>
  </vdrkeymap>

The next example creates an other key map with id "TV". If the CEC key code "SELECT" is received, this key is mapped to the VDR menu key. The key code "RIGHT_UP" is mapped to only "right" and not as default to right+up.

  <ceckeymap id="TV">
    <key code="SELECT">
      <value>Menu</value>
    </key>
    <key code="RIGHT_UP">
      <value>Right</value>
    </key>
  </ceckeymap>

<device>

The device element contains definitions for CEC devices. The main purpose is to specify a CEC device by the physical address, e.g. when more than one recording device may be available.

The following configuration would create an entry for a blueray player.

<device id="blueray">
   <physical>2000</physical>
   <logical>8</logical>
</device>

The software first tries to get the logical address by the device located at the physical address 2000 (second HDMI port connected to the TV, for the address concept see for example http://elinux.org/CEC_%28Consumer_Electronics_Control%29_over_HDMI).

In case that there is more than one device available at the physical address or no device could be found on the physical address the logical address (in this case Playback 2) is used.

<global>

The child elements of <global> are <rtcdetect>, <cecdebug>, <onstart>, <onmanualstart>, <onstop> <onswitchtotv>, <onswitchtoradio>, <onswitchtoreplay>, <shutdownonstandby>, <poweroffonstandby> and <keymaps>.

<cecdebug> Debug level for CEC debugging (see cec_log_level in cectypes.h)
<onstart> A command list which is executed upon plugin start.
<onmanualstart> A command list which is executed upon manual plugin start, but not if the VDR was started due to a timer.
<onstop> A command list which is executed upon plugin shutdown.
<onswitchtotv> A command list which is executed if switched to a TV program.
<onswitchtoradio> A command list which is executed if switched to a radio program.
<onswitchtoreplay> A command list which is executed if the VDR replays a recording.
<keymaps> The <keymaps> tag has the attribute cec, which addresses the id specified within a <ceckeymap>. This keymap is used to convert a CEC-Keycode to a VDR-Key.
<cecdevicetype> The device types to register with libCEC. The following device types are available:
  • RECORDING_DEVICE
  • TUNER
  • TV
  • PLAYBACK_DEVICE
  • AUDIO_SYSTEM
NOTE: There seems to be a bug in the libCEC implementation for the Raspberry PI which causes a crash when registering more than one device type.
<hdmiport> Specify the HDMI-Port where the adapter is connected to.
<shutdownonstandby> Put this PC to standby when the TV is switched off. Only used when PowerOffOnStandby = false.
<poweroffonstandby> Power off the PC when the TV powers off.
<rtcdetect> If set to true (default) use the rtc driver to detect if the vdr was started manually or by rtc alarm. Otherwise use a heuristic. If the VDR was started in a time range 5 minutes before or after an timer was running, the VDR start is detected as timed start.

For the description of a command list see below.

<menu>

Defines a menu for executing CEC and shell commands.

The <menu> tag must have the following attributes:

The child elements of <menu> are <onstart>, <onstop>, <player>, <onpoweron>, <onpoweroff>. <onstart>, <onstop> and <onpoweron>, <onpoweroff> are mutually exclusive.

<player> : (see below).
<onstart> : A command list which is executed when the menu entry is selected.
<onstop> : A command list which is executed if <stillpic> is present and the player is stopped.
<onpoweron> : A command list which is executed if the device is currently powered off.
<onpoweroff> : A command list which is executed if the device is currently powered on.

<player>

Starts a stillpic player and waits until the player is stopped. This tag can not be used with <onpoweron> and <onpoweroff>.

The <player> tag must have the following attribute:

The child elements of <player> are <stop>.and <keymaps>

<stop> : Can be used several times and contains a VDR-Key to stop this player.
<keymaps> : The <keymaps> tag has the attributes "cec" and "vdr" which addresses the id specified within <ceckeymap> or <vdrkeymap>. When the player is started, these keymaps are activated. If a tag is missing, the default keymap is used.

Command lists

A command list defines a list of actions to be executed.

The child elements of a command list are <poweron>, <poweroff>, <makeactive> and <exec>.

<poweron>CEC Device Address</poweron> : Powers the device on.
<poweroff>CEC Device Address</poweroff> : Powers the device off.
<makeactive/> : Makes the VDR the active device.
<makeinactive/> : Remove the VDR as the active device.
<textviewon>CEC Device Address</textviewon> : Send the TextViewOn CEC command to the CEC device.
<exec>Command</exec> : Executes a shell command.

SVDRP Commands

LSTK : List all supported CEC keycodes
LSTD : List active CEC devices
KEYM : List available key maps
VDRK [id] : Display the VDR->CEC key map with the given id
CECK [id] : Display the CEC->VDR key map with the given id
CONN : Connect the CEC adapter.
DISC : Disconnect the CEC adapter. This can be used for example, if an other program requires access to the CEC adapter.

Commandline arguments

-c --configdir <dir> : Directory for the configuration file. If the directory does not start with a slash, the directory is relative to the vdr config directory, otherwise it specifies an absolute path. Default is cecremote.
-x --configfile <file> : Name of the configuartion file. Default is cecremote.xml.

Problems.

After the first start of the VDR ensure, that the CEC device is not accessed by the Modem-Manager or mtp-probe by grep for the device path (/sys/devices/pci00 ...) in the log.

Such accesses can be found in the syslog with:

    root@vdr:~> journalctl | grep /sys/devices/pci0000:00/0000:00:14.0/usb1/1-2/1-2.3
    Apr 30 16:57:37 vdr mtp-probe[746]: checking bus 1, device 4: "/sys/devices/pci0000:00/0000:00:14.0/usb1/1-2/1-2.3"
    Apr 30 16:57:52 vdr vdr[1105]: [cecremote] Device 0 path: /sys/devices/pci0000:00/0000:00:14.0/usb1/1-2/1-2.3 port: /dev/ttyACM0 Firmware 0001
    Apr 30 16:57:55 vdr ModemManager[538]: Couldn't create modem for device at '/sys/devices/pci0000:00/0000:00:14.0/usb1/1-2/1-2.3': Failed to find primary AT port

An udev rule for disabling the access can be installed for example as /etc/udev/rules.d/20-libcec.rules:

    # ModemManager and mtp probe should ignore /dev/ttyACM0
    ACTION=="add", SUBSYSTEM=="usb", ATTRS{idVendor}=="2548", ATTRS{idProduct}=="1002", ENV{ID_MM_DEVICE_IGNORE}="1", ENV{MTP_NO_PROBE}="1"

Dadurch kommt es zu einer längeren Startdauer und ggf. auch zu Instabilitäten

Download