[pvrusb2] Device naming

Pantelis pakt223 at freemail.gr
Fri Jan 19 04:56:09 CST 2007


Στις Παρασκευή 19 Ιανουάριος 2007 05:37, ο/η Mike Isely έγραψε:
> On Thu, 18 Jan 2007, Rafi Rubin wrote:
> > I'm playing with different tuners and have been thinking about the
> > confusion of using mythtv with non-equivalent devices.  And so I was
> > thinking it would be nice to have something generate symlinks or
> > something to provide device names that are a bit more specific than
> > "video0", particularly since I may not be able to garuntee the order the
> > devices are plugged in.
> >
> > Do any of you have any experience with this sort of thing?
> >
> > Here's an nice example.  I'm not entirely sure if the /dev/disk tree is
> > generated by the kernel, hal, udev, or some weird combination.  The
> > point is, you get a canonical name which is specific to that particular
> > device or partition.
> >
> > $ ls /dev/disk
> > by-id  by-label  by-path  by-uuid
> > $ ls /dev/disk/by-id
> > ata-IC25N080ATMR04-0_MRG489K4JT6LHH
> > ata-IC25N080ATMR04-0_MRG489K4JT6LHH-part1
> > ata-IC25N080ATMR04-0_MRG489K4JT6LHH-part2
> > ata-IC25N080ATMR04-0_MRG489K4JT6LHH-part3
> > ata-IC25N080ATMR04-0_MRG489K4JT6LHH-part4
> > $ ls /dev/disk/by-label
> > main  spare
>
> Everything under /dev is generated by udev, using information gathered
> about the underlying device.  In theory you can reprogram udev to nearly
> any scheme imaginable.
>
> However the problem here is that you would need some way for udev to
> discriminate some characteristic about a "pvr" V4L device versus say a
> dumb frame buffer device.  And unfortunately all that udev can know
> about the to-be-created device in the case of V4L is that it's just a
> V4L device.  The pvrusb2 device driver doesn't itself manage the device
> mapping; it is done by the V4L core as part of the operation of any V4L
> driver registering with the V4L subsystem.  So while you can do a lot
> with udev to make it create all sorts of interesting device names, it
> only works if there is some attribute that udev can key off of, and I
> don't think such a thing is available here.
>
> Somebody correct me if this is wrong.  I think the idea here is a good
> one, but I don't think it is possible for V4L devices.
>
>   -Mike

In short, It *is* doable, just not straightforward. The key thing is to 
understand how udev works (LFS teaches you that kind of stuff more
than you can imagine ;-)

The problem is that for some things, the uevent that the kernel sends
to udev does not have all the information that one may want to know
for a device and perhaps to use as a key for its name. So, udev has
these little "helper" applications that can do some interrogation of
the device *afterwards* and use the extra nifty pieces of information
it gets to set additional, specialized symlinks (like those you describe).

So, how should you go about this? It depends on your specific needs
unfortunately, since mpeg streaming support is still a bit young regarding
the interfaces.

If you just have multiple pvrusb2 devices, you can use the handy sysfs
interface that mike has provided us with :-)  If your device shows its
serial number (if it does you should have a directory looking like 
this /sys/class/pvrusb2/sn-6598952/ - the number of course will be
different).

Then, you can use the v4l_minor_number and v4l_radio_minor_number
attributes from inside this directory to know which video/radio devices
correspond to this serial number and use them to set symlinks like
/dev/sn-6598952-video -> /dev/video1.
/dev/sn-6598952-radio -> /dev/radio0

If you have a number of different usb tuners with different underlying
drivers (say some ivtv - if it supports any usb devices -, some pvrusb2),
then you should write a small C program (please call it v4l2_id and send
it to the udev maintainer) that in essence does a 

ctrls.ctrl_class = V4L2_CTRL_CLASS_MPEG;
ctrls.count = 0;
ctrls.controls = NULL;
ioctl(device,VIDIOC_G_EXT_CTRLS, ctrls);

to every videoX device. if that returns 0, then you know the device
supports mpeg, otherwise it is either a dumb framegrabber or it
doesn 't support hans' new mpeg API appropriately. This way of
detection is at least supported in ivtv and thanks to recent work by mike
and me, it is also supported in pvrusb2 (get the latest snapshot though!).

This information can be used to setup links like:

pvr_video0 -> video1
pvr_radio0 -> radio0

You still have to figure out how to tie these all together via udev rules,
but you can see how your distro does the /dev/disk thing and copy
that, this part shouldn 't be that hard ;-)

I know it is a bit involved, but at least you are limited only by the amount
of time you can put into this and not by any hairbrained "marketing" guy
who decides your feature doesn 't add any value to their "bottom line" :-)

-Pantelis

P.S., note that this all is off the top of my head, it could very well be
inaccurate somewhere, but I figured better that than being completely
in the dark :-)


More information about the pvrusb2 mailing list