Log in

Bekijk de volledige versie : [Howto] Build (compile) uvcdyncontrol on the router



ecaddict
31-08-2011, 14:59
I use 1.9.2.7-rtn-r3158 version of the firmware on my RT-N16.
I have a Logitech Webcam Pro 9000 webcam connected to the router.
It works very well "out of the box", however I'm missing some extra controls so I've decided to compile uvcdynctrl for the router based on:
http://www.quickcamteam.net/documentation/how-to/how-to-install-the-webcam-tools
(http://www.quickcamteam.net/documentation/how-to/how-to-install-the-webcam-tools)
Beeing not too experienced with this I've used also some tips from here:
http://plone.jcu.edu.au/dimsim/Members/gillesgigan/gumstix/compiling-uvcvideo-and-installing-uvcdynctrl.html (I've also built the libxml2).

It runs OK:

uvcdynctrl
uvcdynctrl 0.2.0

Manage dynamic controls in uvcvideo

Usage: uvcdynctrl [OPTIONS]... [VALUES]...

-h, --help Print help and exit
-V, --version Print version and exit
-l, --list List available cameras
-i, --import=filename Import dynamic controls from an XML file
-v, --verbose Enable verbose output (default=off)
-d, --device=devicename Specify the device to use (default=`video0')
-c, --clist List available controls
-g, --get=control Retrieve the current control value
-s, --set=control Set a new control value
(For negative values: -s 'My Control' -- -42)
-f, --formats List available frame formats

however when I tried to import the logitech.xml downloaded here:
http://svn.quickcamteam.net/svn/qct/webcam-tools/trunk/uvcdynctrl/data/046d/logitech.xml

I've got the following error (also the annoying "Unknown V4L2 private control ID encountered" is always there):

[libwebcam] Unknown V4L2 private control ID encountered: 0x0A046D04 (V4L2_CID_PRIVATE_BASE + 33844484)
Importing dynamic controls from file logitech.xml.
ERROR: Unable to import dynamic controls: Invalid device or device cannot be opened. (Code: 5)
logitech.xml: error: device 'video0' skipped because the driver 'uvcvideo' behind it does not seem to support dynamic controls.


So it seems that dynamic control support is missing from the uvcvideo driver?

Is that really the case (or do I have compile error)? If missing indeed, could it be added?


uvcdynctrl -l
[libwebcam] Unknown V4L2 private control ID encountered: 0x0A046D04 (V4L2_CID_PRIVATE_BASE + 33844484)
Listing available devices:
video0 UVC Camera (046d:0809)



uvcdynctrl -f
[libwebcam] Unknown V4L2 private control ID encountered: 0x0A046D04 (V4L2_CID_PRIVATE_BASE + 33844484)
Listing available frame formats for device video0:
Pixel format: YUYV (YUV 4:2:2 (YUYV); MIME type: video/x-raw-yuv)
Frame size: 640x480
Frame rates: 30, 25, 20, 15, 10, 5
Frame size: 160x120
Frame rates: 30, 25, 20, 15, 10, 5
Frame size: 176x144
Frame rates: 30, 25, 20, 15, 10, 5
Frame size: 320x240
Frame rates: 30, 25, 20, 15, 10, 5
Frame size: 352x288
Frame rates: 30, 25, 20, 15, 10, 5
Frame size: 640x360
Frame rates: 30, 25, 20, 15, 10, 5
Frame size: 640x400
Frame rates: 30, 25, 20, 15, 10, 5
Frame size: 768x480
Frame rates: 25, 20, 15, 10, 5
Frame size: 800x456
Frame rates: 25, 20, 15, 10, 5
Frame size: 800x504
Frame rates: 25, 20, 15, 10, 5
Frame size: 800x600
Frame rates: 25, 20, 15, 10, 5
Frame size: 864x480
Frame rates: 25, 20, 15, 10, 5
Frame size: 960x720
Frame rates: 15, 10, 5
Frame size: 1280x720
Frame intervals: 2/15, 1/5
Frame size: 1280x800
Frame intervals: 2/15, 1/5
Frame size: 1600x904
Frame rates: 5
Frame size: 1600x1000
Frame rates: 5
Frame size: 1600x1200
Frame rates: 5
Pixel format: MJPG (MJPEG; MIME type: image/jpeg)
Frame size: 640x480
Frame rates: 30, 25, 20, 15, 10, 5
Frame size: 160x120
Frame rates: 30, 25, 20, 15, 10, 5
Frame size: 176x144
Frame rates: 30, 25, 20, 15, 10, 5
Frame size: 320x240
Frame rates: 30, 25, 20, 15, 10, 5
Frame size: 352x288
Frame rates: 30, 25, 20, 15, 10, 5
Frame size: 640x360
Frame rates: 30, 25, 20, 15, 10, 5
Frame size: 640x400
Frame rates: 30, 25, 20, 15, 10, 5
Frame size: 768x480
Frame rates: 30, 25, 20, 15, 10, 5
Frame size: 800x456
Frame rates: 30, 25, 20, 15, 10, 5
Frame size: 800x504
Frame rates: 30, 25, 20, 15, 10, 5
Frame size: 800x600
Frame rates: 30, 25, 20, 15, 10, 5
Frame size: 864x480
Frame rates: 30, 25, 20, 15, 10, 5
Frame size: 960x720
Frame rates: 30, 25, 20, 15, 10, 5
Frame size: 1280x720
Frame rates: 30, 25, 20, 15, 10, 5
Frame size: 1280x800
Frame rates: 25, 20, 15, 10, 5
Frame size: 1600x904
Frame rates: 10, 5
Frame size: 1600x1000
Frame rates: 10, 5
Frame size: 1600x1200
Frame rates: 10, 5


uvcdynctrl -c
[libwebcam] Unknown V4L2 private control ID encountered: 0x0A046D04 (V4L2_CID_PRIVATE_BASE + 33844484)
Listing available controls for device video0:
LED1 Frequency
LED1 Mode
Focus (absolute)
Tilt (Absolute)
Pan (Absolute)
Exposure, Auto Priority
Exposure (Absolute)
Exposure, Auto
Backlight Compensation
Sharpness
White Balance Temperature
Power Line Frequency
Gain
White Balance Temperature, Auto
Saturation
Contrast
Brightness

Most controls seem to be accepted, others not.

Accepted:

uvcdynctrl -s 'LED1 Mode' 0
[libwebcam] Unknown V4L2 private control ID encountered: 0x0A046D04 (V4L2_CID_PRIVATE_BASE + 33844484)
uvcdynctrl -g 'LED1 Mode'
[libwebcam] Unknown V4L2 private control ID encountered: 0x0A046D04 (V4L2_CID_PRIVATE_BASE + 33844484)
0
uvcdynctrl -s 'LED1 Mode' 1
[libwebcam] Unknown V4L2 private control ID encountered: 0x0A046D04 (V4L2_CID_PRIVATE_BASE + 33844484)
uvcdynctrl -g 'LED1 Mode'
[libwebcam] Unknown V4L2 private control ID encountered: 0x0A046D04 (V4L2_CID_PRIVATE_BASE + 33844484)
1
uvcdynctrl -g 'Gain'
[libwebcam] Unknown V4L2 private control ID encountered: 0x0A046D04 (V4L2_CID_PRIVATE_BASE + 33844484)
0
uvcdynctrl -g 'Brightness'
[libwebcam] Unknown V4L2 private control ID encountered: 0x0A046D04 (V4L2_CID_PRIVATE_BASE + 33844484)
128
uvcdynctrl -s 'Brightness' 129
[libwebcam] Unknown V4L2 private control ID encountered: 0x0A046D04 (V4L2_CID_PRIVATE_BASE + 33844484)
uvcdynctrl -g 'Brightness'
[libwebcam] Unknown V4L2 private control ID encountered: 0x0A046D04 (V4L2_CID_PRIVATE_BASE + 33844484)
129
uvcdynctrl -g 'Tilt (Absolute)'
[libwebcam] Unknown V4L2 private control ID encountered: 0x0A046D04 (V4L2_CID_PRIVATE_BASE + 33844484)
0
/uvcdynctrl -g 'Pan (Absolute)'
[libwebcam] Unknown V4L2 private control ID encountered: 0x0A046D04 (V4L2_CID_PRIVATE_BASE + 33844484)
0
uvcdynctrl -g 'Exposure, Auto Priority'
[libwebcam] Unknown V4L2 private control ID encountered: 0x0A046D04 (V4L2_CID_PRIVATE_BASE + 33844484)
1
uvcdynctrl -g 'Exposure (Absolute)'
[libwebcam] Unknown V4L2 private control ID encountered: 0x0A046D04 (V4L2_CID_PRIVATE_BASE + 33844484)
166
uvcdynctrl -g 'Exposure, Auto'
[libwebcam] Unknown V4L2 private control ID encountered: 0x0A046D04 (V4L2_CID_PRIVATE_BASE + 33844484)
3
uvcdynctrl -g 'Backlight Compensation'
[libwebcam] Unknown V4L2 private control ID encountered: 0x0A046D04 (V4L2_CID_PRIVATE_BASE + 33844484)
1
uvcdynctrl -g 'Sharpness'
[libwebcam] Unknown V4L2 private control ID encountered: 0x0A046D04 (V4L2_CID_PRIVATE_BASE + 33844484)
191
uvcdynctrl -g 'White Balance Temperature'
[libwebcam] Unknown V4L2 private control ID encountered: 0x0A046D04 (V4L2_CID_PRIVATE_BASE + 33844484)
9760
uvcdynctrl -g 'Power Line Frequency'
[libwebcam] Unknown V4L2 private control ID encountered: 0x0A046D04 (V4L2_CID_PRIVATE_BASE + 33844484)
2
uvcdynctrl -g 'Gain'
[libwebcam] Unknown V4L2 private control ID encountered: 0x0A046D04 (V4L2_CID_PRIVATE_BASE + 33844484)
0
uvcdynctrl -g 'White Balance Temperature, Auto'
[libwebcam] Unknown V4L2 private control ID encountered: 0x0A046D04 (V4L2_CID_PRIVATE_BASE + 33844484)
1
uvcdynctrl -g 'Saturation'
[libwebcam] Unknown V4L2 private control ID encountered: 0x0A046D04 (V4L2_CID_PRIVATE_BASE + 33844484)
28
uvcdynctrl -g 'Contrast'
[libwebcam] Unknown V4L2 private control ID encountered: 0x0A046D04 (V4L2_CID_PRIVATE_BASE + 33844484)
32
uvcdynctrl -g 'Brightness'
[libwebcam] Unknown V4L2 private control ID encountered: 0x0A046D04 (V4L2_CID_PRIVATE_BASE + 33844484)
129

Not accepted:

uvcdynctrl -g 'Focus'
[libwebcam] Unknown V4L2 private control ID encountered: 0x0A046D04 (V4L2_CID_PRIVATE_BASE + 33844484)
ERROR: Unknown control specified.
uvcdynctrl -g 'Focus (absolute)'
[libwebcam] Unknown V4L2 private control ID encountered: 0x0A046D04 (V4L2_CID_PRIVATE_BASE + 33844484)
ERROR: Unable to retrieve control value: A Video4Linux2 API call returned an unexpected error 22. (Code: 12)

lly
01-09-2011, 11:18
So it seems that dynamic control support is missing from the uvcvideo driver?



uvcdynctrl -f
[libwebcam] Unknown V4L2 private control ID encountered: 0x0A046D04 (V4L2_CID_PRIVATE_BASE + 33844484)




Generally, dynamic controls supported in uvcvideo driver (kernel 2.6.22 + backports from 2.6.32).

But support of private controls seems to be incomplete. Probably we will have some time in future to dig through this bug and make backport needed. As usual, if someone can help us (find exact broken ioctls functions, upstream kernel commits, etc.), solution will be faster.

ecaddict
02-09-2011, 14:43
Yes, on the router but why?
It can be built also on PC via using the cross compiler used to build the firmware: http://code.google.com/p/wl500g/wiki/CompilingCustomFirmware, however it's a pain.
The reason is that the libraries (e.g. libxml2, libz) are not part of the tool chain so it has to be extracted on PC that are directly available on the router.

Why is it required at all?
I have a nice webcam called Logitech webcam Pro9000 (for UVC compatible devices refer to here: http://www.ideasonboard.org/uvc/#devices).
Unfortunately (or luckily) it has controls over what's available in mjpg_streamer.
Check mjpg_streamer help:

mjpg_streamer --help
mjpg_streamer --output "output_http.so --help"
mjpg_streamer --output "output_file.so --help"
mjpg_streamer --input "input_uvc.so --help"

In particular the input help:

mjpg_streamer --input "input_uvc.so --help"
MJPG Streamer Version.: 2.0
---------------------------------------------------------------
Help for input plugin..: UVC webcam grabber
---------------------------------------------------------------
The following parameters can be passed to this plugin:

[-d | --device ].......: video device to open (your camera)
[-r | --resolution ]...: the resolution of the video device,
can be one of the following strings:
QSIF QCIF CGA QVGA CIF VGA
SVGA XGA SXGA
or a custom value like the following
example: 640x480
[-f | --fps ]..........: frames per second
[-y | --yuv ]..........: enable YUYV format and disable MJPEG mode
[-q | --quality ]......: JPEG compression quality in percent
(activates YUYV format, disables MJPEG)
[-m | --minimum_size ].: drop frames smaller then this limit, useful
if the webcam produces small-sized garbage frames
may happen under low light conditions
[-n | --no_dynctrl ]...: do not initalize dynctrls of Linux-UVC driver
[-l | --led ]..........: switch the LED "on", "off", let it "blink" or leave
it up to the driver using the value "auto"
---------------------------------------------------------------
Not all of them are working, e.g. I could not figure out how to switch off the LED on the webcam. (It has though nice high level controls e.g. you can check your webcam over http and send to file the jpgs at the same time).

What's required on the router (I've used RT-N16 and Oleg firmware)?
Development environment, packages. Easy to take care of (I may have missed some, so install as needed):

ipkg update
ipkg install optware-devel
ipkg install libxml2
ipkg install zlib

And of course the source code that can be obtained via svn:
http://www.quickcamteam.net/documentation/how-to/how-to-install-the-webcam-tools

First issue is that it's using cmake for the build. I could not find one for the router so I've decided to copy all files to a directory and ignore the original make files.
The following files are needed:

ls
build.sh cmdline.h config.h controls.h dynctrl.c libwebcam.h webcam.h
cmdline.c compat.h controls.c dynctrl-logitech.h libwebcam.c main.c

All of them can be fetched from the above link except the build.sh which I've created and you have to create as well if you want to build it (don't forget chmod u+x build.sh after creation):

#!/bin/sh

KVER=2.6.39.4
XVER=2.7.8
KFAM=${KVER%.*.*}

! [ -f "linux-${KVER}.tar.bz2" ] && wget http://www.kernel.org/pub/linux/kernel/v${KFAM}/linux-${KVER}.tar.bz2 && tar -jxvf linux-${KVER}.tar.bz2
! [ -f "libxml2-${XVER}.tar.gz" ] && wget http://xmlsoft.org/sources/libxml2-${XVER}.tar.gz && tar -zxvf libxml2-${XVER}.tar.gz

gcc -c -D'VERSION="0.2.0"' -I`pwd` -I`pwd`/linux-${KVER}/include/ -I`pwd`/linux-${KVER}/drivers/media/video/uvc/ -I`pwd`/libxml2-${XVER}/include cmdline.c libwebcam.c dynctrl.c
sed -i 's/CControlId id = 0;/CControlId id = (CControlId)0;/' controls.c
sed -i 's/info = { 0 };/info; memset(\&info,0,sizeof(info));/' main.c
sed -i 's/|= CD_RETRIEVE_META_INFO/=(CDynctrlFlags)(CD_REPORT_ERRORS|CD_RETRIEVE_META _INFO)/' main.c
g++ -I`pwd` main.c controls.c libwebcam.o cmdline.o dynctrl.o /opt/lib/libxml2.so -o uvcdynctrl

The script fetches and unpacks the entire linux kernel, only from a few files are needed so feel free to make some optimization if you'd like to save some space.
Actually, if you prefer, you don't have to build it as I've uploaded it here: 8264 (nice place could be to copy it after unpacking e.g. /opt/bin)

So what can it do for you? It prints the options if you start without any arguments:

uvcdynctrl
uvcdynctrl 0.2.0

Manage dynamic controls in uvcvideo

Usage: uvcdynctrl [OPTIONS]... [VALUES]...

-h, --help Print help and exit
-V, --version Print version and exit
-l, --list List available cameras
-i, --import=filename Import dynamic controls from an XML file
-v, --verbose Enable verbose output (default=off)
-d, --device=devicename Specify the device to use (default=`video0')
-c, --clist List available controls
-g, --get=control Retrieve the current control value
-s, --set=control Set a new control value
(For negative values: -s 'My Control' -- -42)
-f, --formats List available frame formats

list the devices:

uvcdynctrl -lv
Listing available devices:
video0 UVC Camera (046d:0809) [uvcvideo, usb-0000:00:04.1-2]

The control options:

uvcdynctrl -c
[libwebcam] Unknown V4L2 private control ID encountered: 0x0A046D04 (V4L2_CID_PRIVATE_BASE + 33844484)
Listing available controls for device video0:
LED1 Frequency
LED1 Mode
Focus (absolute)
Tilt (Absolute)
Pan (Absolute)
Exposure, Auto Priority
Exposure (Absolute)
Exposure, Auto
Backlight Compensation
Sharpness
White Balance Temperature
Power Line Frequency
Gain
White Balance Temperature, Auto
Saturation
Contrast
Brightness


You may also try uvcdynctrl -cv but it will be a long list.
Unfortunately at the moment not all of them are working (and you may also get some Unknown V4L2 private control ID) but e.g. you can switch off the led with uvcdynctrl -s 'LED1 Mode' 0, or on uvcdynctrl -s 'LED1 Mode' 1.

You can monitor the impact via http://192.168.1.1:8081/?action=stream (or take a snapshot http://192.168.1.1:8081/?action=snapshot) assuming that you configured port 8081 in the command line (e.g. mjpg_streamer -b -i "input_uvc.so -d /dev/video0" -o "output_http.so -p 8081 -w /mnt/cgi-bin/webcam") or in the web interface of the firmware.

If you prefer seeing the webcam picture via lighttpd, please add the following lines to /opt/etc/lighttpd/lighttpd.conf (adjust the port again as needed):

$HTTP["querystring"] =~ "action=(snapshot|stream)$" {
proxy.server = (
"" => (
(
"host" => "127.0.0.1",
"port" => 8081
)
)
)
}

(You need to restart lighttpd the changes to take effect: /opt/etc/init.d/S80lighttpd restart)

You can use now (replace IP with your WAN IP):
https://192.168.1.1/?action=stream
https://192.168.1.1/?action=snapshot


If you did not enable the webcam in the web interface you may need to insert the modules like:

insmod videodev
insmod input-core
insmod uvcvideo
insmod v4l2-common

My webcam supports e.g. the following MJPG Formats:

uvcdynctrl -f
Listing available frame formats for device video0:
Pixel format: YUYV (YUV 4:2:2 (YUYV); MIME type: video/x-raw-yuv)
...
Pixel format: MJPG (MJPEG; MIME type: image/jpeg)
Frame size: 640x480
Frame rates: 30, 25, 20, 15, 10, 5
Frame size: 160x120
Frame rates: 30, 25, 20, 15, 10, 5
Frame size: 176x144
Frame rates: 30, 25, 20, 15, 10, 5
Frame size: 320x240
Frame rates: 30, 25, 20, 15, 10, 5
Frame size: 352x288
Frame rates: 30, 25, 20, 15, 10, 5
Frame size: 640x360
Frame rates: 30, 25, 20, 15, 10, 5
Frame size: 640x400
Frame rates: 30, 25, 20, 15, 10, 5
Frame size: 768x480
Frame rates: 30, 25, 20, 15, 10, 5
Frame size: 800x456
Frame rates: 30, 25, 20, 15, 10, 5
Frame size: 800x504
Frame rates: 30, 25, 20, 15, 10, 5
Frame size: 800x600
Frame rates: 30, 25, 20, 15, 10, 5
Frame size: 864x480
Frame rates: 30, 25, 20, 15, 10, 5
Frame size: 960x720
Frame rates: 30, 25, 20, 15, 10, 5
Frame size: 1280x720
Frame rates: 30, 25, 20, 15, 10, 5
Frame size: 1280x800
Frame rates: 25, 20, 15, 10, 5
Frame size: 1600x904
Frame rates: 10, 5
Frame size: 1600x1000
Frame rates: 10, 5
Frame size: 1600x1200
Frame rates: 10, 5

ecaddict
02-09-2011, 14:47
If so could you please write a summary?

I've created a tutorial for it: http://wl500g.info/showthread.php?t=27524

I cannot provide any quick help in that probably (unfortunately) ...