Work in progress in branch client-device-config

  1. Device custom configuration
  2. Per-device Access-Control to backends
    1. Examples
  3. custom data types mapping
  4. Updates to process-style transcoders

See branch client-device-config

Device custom configuration

I am currently working in branch client-device-config on a way to externalize in the config file client device or specificities such as:

  • adherence to specific mimetype or DLNA additionnal info for given data types
  • transcoding profiles
  • DLNA support
  • protocols idioms
  • ...

This works by identifying client devices thanks to characteristics such as IP address, Ethernet MAC address, HTTP user-agent or alternative HTTP header and associate them to specific paremeters. The config actually defines a set of 'rules', which are read through by the framework when needed. Each 'rule' associates a given criterium (ex: IP address is XX.XX.XX.XX) with one or more parameter. Different rules can apply to a given client, and they are handled in the order they appear. For each applying rule, the parameters are added or overwrite the previous ones.

Parameters can be:

  • "tag": a tag which will modify the framework behaviour. Currently supported tags are:
    • NO_TRANSCODING: the client device does not support transcoded resources, or thre is no need to transcode anything.
    • NO_DLNA_ADDITIONNAL_INFO: the client device doe not support any info other than the generic "*" value as additionnal value in the UPnP resources information.
    • NO_REF_ID
    • SIMULATE_WMC_SERVER: useful for Microsoft-style devices (XBOX, WMP...) Other tags can be defined (For instance, in order to control access to specific backends from a given set of devices: see below)
  • "forced-mimetype". All resources with a given mimetype will be presented to the client with another mimetype value (usefull when a device will not recognize the firsg mimetype). The mimetype may be replaced by a type family: audio, video or image.
  • "transcoders": list of transcoding profile (e.g. lpcm, mpegps..) to apply to ressources with a given mimetype. The special profile "native" corresponds to the native resource: it has to be provided if we want this resource to be present. The mimetype may be replaced by a type family: audio, video or image.
  • "dlna_additional_info" (for DLNA certified devices). All resource with a given mimetype will be presented to the client with the configuration value (usefull when a device will only accept a given value)
  • "device-info": free text characterizing the device (useful for logging)

Rules criteria can be:

  • "all": applies to any client device
  • "user-agent": applies to any device for which the HTTP client device matches a given regular expression
  • "ip": applies to any device for which the IP address matches a given value
  • "mac": applies to any device for which the MAC address matches a given value (not supported yet)
  • "http-header": applies to any device for which the HTTP header contains a given key/value (value/value2)

Sample configuration (to be included within the <config> element)

<devices>
    <rule type="all">
        <device-info>Generic device</device-info>
        <forced-mimetype mimetype="video/x-msvideo">video/divx</forced-mimetype>
        <forced-mimetype mimetype="video/avi">video/divx</forced-mimetype>
        <transcoders mimetype="audio">native,lpcm</transcoders>
        <transcoders mimetype="video">native,mpegts</transcoders>
    </rule>
    <rule type="user-agent" value="Coherence">
        <device-info>Coherence</device-info>
      	<!--<tag>NO_TRANSCODING</tag>-->
    </rule>
    <rule type="user-agent" value="Xbox/">
        <device-info>XBox</device-info>
        <tag>XBox</tag>
        <tag>NO_DLNA_ADDITIONAL_INFO</tag>
        <tag>NO_REF_ID</tag>
        <tag>SIMULATE_WMC_SERVER</tag>
        <forced-mimetype mimetype="video/x-msvideo">video/avi</forced-mimetype>
        <forced-mimetype mimetype="video/divx">video/avi</forced-mimetype>
        <forced-mimetype mimetype="audio/x-wav">audio/wav</forced-mimetype>
        <transcoders mimetype="audio">mp3</transcoders>
    </rule>
    <rule type="user-agent" value="Mozilla/4.0 \(compatible; UPnP/1.0; Windows">
        <device-info>Windows Media Player</device-info>
        <tag>SIMULATE_WMC_SERVER</tag>
    </rule>
    <rule type="user-agent" value="FDSSDP">
  	<device-info>Windows 7</device-info>
      <tag>SIMULATE_WMC_SERVER</tag>
    </rule>
    <rule type="user-agent" value="fbxupnpav">
        <device-info>Freebox HD</device-info>
        <forced-mimetype mimetype="video/x-msvideo">video/avi</forced-mimetype>
        <forced-mimetype mimetype="video/divx">video/avi</forced-mimetype>
    </rule>
    <rule type="user-agent" value="Philips-Software-WebClient">
        <device-info>Philips-TV</device-info>
        <tag>NO_DLNA_ADDITIONAL_INFO</tag>
    </rule>
    <rule type="user-agent" value="Allegro-Software-WebClient">
        <device-info>Philips-TV</device-info>
        <tag>NO_DLNA_ADDITIONAL_INFO</tag>
    </rule>
    <rule type="http-header" value="x-av-client-info" value2="PLAYSTATION3">
        <device-info>Playstation 3</device-info>
        <dlna_additional_info mimetype="video">*</dlna_additional_info>
    </rule>
    <rule type="http-header" value="x-av-client-info" value2="BRAVIA KDL" >
  	<device-info>Sony Bravia KDL</device-info>
        <dlna_additional_info mimetype="video/mpegts">MPEG_TS_SD_EU_ISO</dlna_additional_info>
    </rule>
</devices>

Per-device Access-Control to backends

You can filter access to the backend on a per-device basis, either with:

  • a whitelist: no device can access the backend resources, except for the ones specifically identified (allowed)
  • a blacklist: all devices can access the backend resources, except for the ones specifically identified (denied)

Devices are not identified directly in the black/list lists, but through tags.

A blacklist can be defined in the backend configuration, by adding the deny element, with a commas-separated list of tags (Any device with one of the tag will be denied. All others will be allowed).

A whitelist can be defined in the backend configuration, by adding the allow element, with a commas-separated list of tags (Any device with one of the tag will be allowed. All others will be denied).

Defining both a black list and a white liste is invalid.

Examples

To allow all devices except device A (children device) to access backend B:

  • choose a tag to describe the denied device(s): e.g. CHILDREN_DEVICE
  • add a new rule identifying the device (e.g. by IP) and defining tag CHILDREN_DEVICE
  • add the following element to backend B definition: <deny>CHILDREN_DEVICE</deny>

To deny all devices except device A (device) to access backend B:

  • choose a tag to describe the allowed device(s): e.g. GOD_DEVICE
  • add a new rule identifying the device (e.g. by IP, or by type: XBox) and setting tag GOD_DEVICE
  • add the following element to backend B definition: <allow>GOD_DEVICE</allow>
  • other devices can be allowed, by adding a new rule identifying the device and setting tag GOD_DEVICE

custom data types mapping

it is possible to add new mappings if the framework does not behave as expected with your files:

  • file extension to mimetype
  • mimetype to UPnPClass

Just edit your configuration file as in the sample below.

<mapping type="extension-mimetype" from=".srt" to="application/x-srt"/>
<mapping type="mimetype-upnpclass" from="application/x-srt" to="object.item.videoItem"/>
<mapping type="mimetype-upnpclass" from="application/x-bittorrent" to="object.item.videoItem"/>

Notes: file extension value are to be provided with a dot. UPnP classes are to be provided with the fully qualified name.

Updates to process-style transcoders

Support for transcoders with type "process" has been extended as follows. data output by the 'process' is bufferized in a FIFO, up to a given size. Above this size, the process is paused. To be frank, the concepts here are heavily 'borrowed' from [mediatomb]. Here are to the available parameters, besides existing type, name and target:

pipeline : the command to launch the transcoder process. This command takes the form of a python formatting string, with the following variables:

  • either a single %s or %uri variable, corresponding to the source URI or file path. The command has to output transcoded data to its standard output.
  • either both %uri and %output variables, corresponding to the source URI or file path, and file path to a pipe file that coherence will stream to the client

source : the mimetype (as attribute mimetype) for which the transcoder will be applied. For other data types, no transcoded resources will be proposed.

priority : defines how the transcoded resource will be published, besides the original one. Available values are:

  • -1: the transcoded resource will be published before the original one(s)
  • 0: the transcoded resource will be published in place of the original one(s)
  • 1: the transcoded resource will be published after the original one(s)
  • 2: the transcoded resource will be published at the end of the list

buffer : (optional)tuning parameters for the buffering taking place at the server side, when streaming the transcoded resources. Attributes are:

  • size : total size of the buffer
  • chunk-size : size of data chunks read from the FIFO and served to the client

Values may be tuned according to your setting, to smoothen playback or optimize server resource consumption.

Below a sample transcoder configuration (see svn for the source code for the given bash_memcoder_srt2mpeg command: it takes a srt file, accompanying a video file, and transcode it to mpeg embedding the subtitles).

<transcoder>
  <pipeline>misc/transcoders/bash_memcoder_srt2mpeg %uri %output</pipeline>
  <type>process</type>
  <name>srt2video</name>
  <target>video/mpeg</target>
  <!--<buffer size="5242880" chunk-size="8192"/>-->
  <source mimetype="application/x-srt"/>
  <priority>0</priority>
</transcoder>