Managing USB DVB tuners in Mythtv 32.0 on Ubuntu 22.04.1

For discussion of topics specific to MythTV on linux
Post Reply
rshooter
Newcomer
Posts: 4
Joined: Tue Aug 30, 2022 10:55 am
Great Britain

Managing USB DVB tuners in Mythtv 32.0 on Ubuntu 22.04.1

Post by rshooter »

This is a quick note on how USB DVB tuners appear to work in Mythtv 32.0 on Ubuntu 22.04.01. The fundamental issue is that if you have more than one type of tuner the devices assigned may differ after reboots (a perenial issue) - e.g.

Code: Select all

    /dev/dvb/adapter0 dvb T2
    /dev/dvb/adapter1 dvb S2
Reboot and the cards could be reversed (I have two identical S2 tuners and two different T2 tuners) so this is a bind, i.e. using the card fails.

Code: Select all

    /dev/dvb/adapter0 dvb S2
    /dev/dvb/adapter1 dvb T2
TLDR create a symbolic link

Code: Select all

    /dev/dvb/adapterANYTHING -> /dev/dvb/adapterN
    
where N is where your card is currently mapped (0..9) and ANYTHING is not 0..9 seems to work well, in mythtv-setup select /dev/dvb/adapterANYTHING (it will be auto-detected). If you can provide the details of how to achieve this directly from UDEV I'd be most grateful.


A long winded way of achieving this:

The first thing to note is that Mythtv 32 is aware of the /dev/dvb/adapterX naming scheme. The best (possibly correct) method I have found is to ensure that the 'permanent' or 'consistent' devices live in directory structures with that naming scheme. I chose to add new /dev/dvb/adapterXXXX names where I used alpha numerics which should prevent naming clashes.

Code: Select all

    ls /dev/dvb/
    adapter0  adapter1  adapter2  adapter3  adapterS960-1  adapterS960-2  adapterT2o  adapterT2u
so 0..3 are the default names which may map to different cards on each reboot, the S960-1, S960-2, T20 and T2u are chosen as they shouldn't clash with the default naming and are meaningful for me. The 'consistent' directories are in fact symbolic links:

Code: Select all

    root@i3nuc:/home/rshooter# ls -l /dev/dvb/
    total 0
    drwxr-xr-x 2 root root 120 Sep  5 21:26 adapter0
    drwxr-xr-x 2 root root 120 Sep  5 21:26 adapter1
    drwxr-xr-x 2 root root 120 Sep  5 21:26 adapter2
    drwxr-xr-x 2 root root 120 Sep  5 21:26 adapter3
    lrwxrwxrwx 1 root root  10 Sep  5 21:26 adapterS960-1 -> ./adapter2
    lrwxrwxrwx 1 root root  10 Sep  5 21:26 adapterS960-2 -> ./adapter3
    lrwxrwxrwx 1 root root  10 Sep  5 21:26 adapterT2o -> ./adapter1
    lrwxrwxrwx 1 root root  10 Sep  5 21:26 adapterT2u -> ./adapter0
This seems to work nicely with mythtv - the 'consistent' devices are listed alongside the originals in mythtv-setup and it detects that some of the devices are the same and warns against their use (and records it in a DB table).

I created a script (/home/mythtv/createDVBDirLink.sh) which takes two arguments - an alias (UDEV SYMLINK) for the frontend0 of a device and the name of the /etc/dvb/adapterXXX to create based on that file. The frontend0 is in the /dev/dvb/adapterN I want.

Code: Select all

#!/bin/bash

# format is dvb/adapterX/frontend0
# we want adapterX
#
TGT=`readlink $1`
DR1=`dirname $TGT`
DR2=`basename $DR1`
ln -s ./${DR2} $2
Examples would be

Code: Select all

    /home/mythtv/createDVBDirLink.sh /dev/otherDVBT2 /dev/dvb/adapterT2o
    /home/mythtv/createDVBDirLink.sh /dev/uSoftDVBT2 /dev/dvb/adapterT2u
Why the weird script? because I thought that having a consistent name for the frontend0 was sufficient so I made a UDEV rules file to create those. The script can be called from udev after it has created some 'consistent' SYMLINKs for the DVB cards.

Taking this one step at a time, the first step is to create a UDEV rule to select your card, Start by creating a rule which creates a SYMLINK for one of the DVB device files (I used frontend0), for example using the udevadm command to get the information needed from the /sys/class/dvb/... devices

Code: Select all

rshooter@i3nuc:~$ udevadm info -a /sys/class/dvb/dvb0.frontend0

Udevadm info starts with the device specified by the devpath and then
walks up the chain of parent devices. It prints for every device
found, all possible attributes in the udev rules key format.
A rule to match, can be composed by the attributes of the device
and the attributes from one single parent device.

  looking at device '/devices/pci0000:00/0000:00:14.0/usb2/2-1/dvb/dvb0.frontend0':
    KERNEL=="dvb0.frontend0"
    SUBSYSTEM=="dvb"
    DRIVER==""
    ATTR{power/async}=="disabled"
    ATTR{power/control}=="auto"
    ATTR{power/runtime_active_kids}=="0"
    ATTR{power/runtime_active_time}=="0"
    ATTR{power/runtime_enabled}=="disabled"
    ATTR{power/runtime_status}=="unsupported"
    ATTR{power/runtime_suspended_time}=="0"
    ATTR{power/runtime_usage}=="0"

  looking at parent device '/devices/pci0000:00/0000:00:14.0/usb2/2-1':
    KERNELS=="2-1"
    SUBSYSTEMS=="usb"
    DRIVERS=="usb"
    ATTRS{authorized}=="1"
    ATTRS{avoid_reset_quirk}=="0"
    ATTRS{bConfigurationValue}=="1"
    ATTRS{bDeviceClass}=="00"
    ATTRS{bDeviceProtocol}=="00"
    ATTRS{bDeviceSubClass}=="00"
    ATTRS{bMaxPacketSize0}=="64"
    ATTRS{bMaxPower}=="500mA"
    ATTRS{bNumConfigurations}=="1"
    ATTRS{bNumInterfaces}==" 1"
    ATTRS{bcdDevice}=="0110"
    ATTRS{bmAttributes}=="a0"
    ATTRS{busnum}=="2"
    ATTRS{configuration}==""
    ATTRS{devnum}=="2"
    ATTRS{devpath}=="1"
I USED THIS
    ATTRS{idProduct}=="02d5"
I USED THIS
    ATTRS{idVendor}=="045e"
    ATTRS{ltm_capable}=="no"
I USED THIS
  ATTRS{manufacturer}=="Microsoft Corp."
    ATTRS{maxchild}=="0"
    ATTRS{power/active_duration}=="5015496"
    ATTRS{power/async}=="enabled"
    ATTRS{power/autosuspend}=="2"
    ATTRS{power/autosuspend_delay_ms}=="2000"
    ATTRS{power/connected_duration}=="5015496"
    ATTRS{power/control}=="on"
    ATTRS{power/level}=="on"
    ATTRS{power/persist}=="1"
    ATTRS{power/runtime_active_kids}=="1"
    ATTRS{power/runtime_active_time}=="5015218"
    ATTRS{power/runtime_enabled}=="forbidden"
    ATTRS{power/runtime_status}=="active"
    ATTRS{power/runtime_suspended_time}=="0"
    ATTRS{power/runtime_usage}=="1"
    ATTRS{power/wakeup}=="disabled"
    ATTRS{power/wakeup_abort_count}==""
    ATTRS{power/wakeup_active}==""
    ATTRS{power/wakeup_active_count}==""
    ATTRS{power/wakeup_count}==""
    ATTRS{power/wakeup_expire_count}==""
    ATTRS{power/wakeup_last_time_ms}==""
    ATTRS{power/wakeup_max_time_ms}==""
    ATTRS{power/wakeup_total_time_ms}==""
    ATTRS{product}=="Xbox USB Tuner"
    ATTRS{quirks}=="0x0"
    ATTRS{removable}=="removable"
    ATTRS{rx_lanes}=="1"
    ATTRS{serial}=="002378290915"
    ATTRS{speed}=="480"
    ATTRS{tx_lanes}=="1"
    ATTRS{urbnum}=="290523"
    ATTRS{version}==" 2.00"

gave me the information to create (you must use information from the same device/'stanza'):

Code: Select all

    KERNEL=="dvb?.frontend0", ATTRS{manufacturer}=="Microsoft Corp.", ATTRS{idProduct}=="02d5", ATTRS{idVendor}=="045e", SYMLINK+="uSoftDVBT2"
So that line when invoked will create a /dev/uSoftDVBT2 which points at wherever the device file /dev/adapterX/frontend0 happens to be - adding RUN+="/home/mythtv/createDVBDirLink.sh /dev/uSoftDVBT2 /dev/dvb/adapterT2u" to the end (note the comma) - gives

Code: Select all

 

    KERNEL=="dvb?.frontend0", ATTRS{manufacturer}=="Microsoft Corp.", ATTRS{idProduct}=="02d5", ATTRS{idVendor}=="045e", SYMLINK+="uSoftDVBT2", RUN+="/home/mythtv/createDVBDirLink.sh /dev/uSoftDVBT2 /dev/dvb/adapterT2u" 
which creates the SYMLINK for the directory

Code: Select all

 ls -l /dev/uSoftDVBT2
    lrwxrwxrwx 1 root root 22 Sep  5 21:26 /dev/uSoftDVBT2 -> dvb/adapter0/frontend0
and the directory link:

Code: Select all

 ls -l /dev/dvb
    lrwxrwxrwx 1 root root  10 Sep  5 21:26 adapterT2u -> ./adapter0
The non-uSoft adapter is handled using

Code: Select all

KERNEL=="dvb?.frontend0", ATTRS{idProduct}=="c688", ATTRS{idVendor}=="0572", SYMLINK="otherDVBT2", RUN+="/home/mythtv/createDVBDirLink.sh /dev/otherDVBT2 /dev/dvb/adapterT2o"
I have two identical S960 DVBS2 cards, they have the same serial number etc and hence can't be identified, I therefore just create two devices with known names, it doesn't matter that they switch.

This is the UDEV rules file I used, created at /etc/udev/rules.d/mythtv-devices.rules

Code: Select all

# udevadm info -a /sys/class/dvb/...
#
KERNEL=="dvb?.frontend0", ATTRS{idProduct}=="c688", ATTRS{idVendor}=="0572", SYMLINK="otherDVBT2", RUN+="/home/mythtv/createDVBDirLink.sh /dev/otherDVBT2 /dev/dvb/adapterT2o"
# uSoft
KERNEL=="dvb?.frontend0", ATTRS{manufacturer}=="Microsoft Corp.", ATTRS{idProduct}=="02d5", ATTRS{idVendor}=="045e", SYMLINK+="uSoftDVBT2", RUN+="/home/mythtv/createDVBDirLink.sh /dev/uSoftDVBT2 /dev/dvb/adapterT2u"
#
KERNEL=="dvb?.frontend0", ATTRS{product}=="S960", ATTRS{idProduct}=="6831", ATTRS{idVendor}=="0572",  PROGRAM="/bin/sh -c ' K=%k; K=$${K#dvb}; N=$${K#*.}; if [ ! -e /dev/S960-1 ] ; then  printf S960-1; else printf S960-2; fi ; exit 0'", SYMLINK+="%c", RUN+="/home/mythtv/createDVBDirLink.sh /dev/%c /dev/dvb/adapter%c"
Post Reply