Dec 4, 2011

PS3 Eye Driver Framerate Patch

The PS3 eye driver has a fixed default videomode and framerate. If you want to change the framerate of your PS3 eye in linux you usually have to unload the module and load it again. We modified bear24rw's patch to include the posibility to change the framerate form your favorite viewer like GUVCview or from your own code like openFrameworks...



The following steps are reproduced form bear24rw tutorial, which includes his useful patched driver ov534.c (initially patched by kaswy and now including our modification), but we also included two more files we had to modify: gspca.c and gspca.h




Just follow these instructions to install the modified driver, at your own risk. (Note: each time you or the system updates your kernel you will have to repeat instructions 4-7).



To apply: 


1) Install necessary packages: 
$ sudo apt-get install kernel-package libncurses5-dev wget bzip2 build-essential linux-source


2) Extract kernel source code: 
$ sudo su
$ cd /usr/src
$ tar --bzip2 -xvf linux-source-2.6.(your version).tar.bz2
$ ln -s linux-source-2.6.(your version) linux


3) Replace driver: 
$ cd linux
$ wget  www.dasaki.com/downloads/ov534/ov534.c www.dasaki.com/downloads/ov534/gspca.h  www.dasaki.com/downloads/ov534/gspca.c
$ mv drivers/media/video/gspca/ov534.c drivers/media/video/gspca/ov534.c.bak
$ mv drivers/media/video/gspca/gspca.h drivers/media/video/gspca/gspca.h.bak
$ mv drivers/media/video/gspca/gspca.c drivers/media/video/gspca/gspca.c.bak


$ mv ov534.c drivers/media/video/gspca/
$ mv gspca.h drivers/media/video/gspca/
$ mv gspca.c drivers/media/video/gspca/

4) Recompile driver: 
$ cp /usr/src/linux-headers-$(uname -r)/Module.symvers /usr/src/linux
$ make clean
$ make oldconfig
$ make modules_prepare
$ make SUBDIRS=drivers/media/video/gspca modules


5) Install new driver: 
$ cp drivers/media/video/gspca/gspca_ov534.ko /lib/modules/$(uname -r)/kernel/drivers/media/video/gspca
$ cp drivers/media/video/gspca/gspca_main.ko /lib/modules/$(uname -r)/kernel/drivers/media/video/gspca
$ depmod


6) Check to make sure it installed: 
$ modinfo gspca-ov534


description:    GSPCA/OV534 USB Camera Driver(kaswy mod for MT use V0.5 / bear24rw patch V0.1 / theRANDOMlab patch V0.1)
author:         Antonio Ospite
srcversion:     E412C43D4DAADEA0D3EE5C3
alias:          usb:v1415p2000d*dc*dsc*dp*ic*isc*ip*
depends:        gspca_main
vermagic:       2.6.32.27+drm33.12 SMP mod_unload modversions 586 
parm:           videomode: = xx //Set the videomode(see doc) (int)
parm:           autogain: = [0|1] //Autogain (agc,aec,awb) (bool)
parm:           gain: = [0..63] //main gain (int)
parm:           awb: = [0|1] //Auto White Balance (bool)
parm:           exposure: = [0..255] //Exposure (int)
parm:           brightness: = [0..255] //Brightness (int)
parm:           contrast: = [0..255] //Contrast (int)
parm:           redblc: = [0..255] //Red Balance (int)
parm:           blueblc: = [0..255] //Blue Balance (int)
parm:           hue: = [0..255] //Hue (int)
parm:           sharpness: = [0..63] //Sharpness (int)
parm:           vflip: = [0|1] //Vertical flip (bool)
parm:           hflip: = [0|1] //Horizontal mirror (bool)

7) Now we can remove the one currently in use and load our new one: 
$ modprobe -r gspca-ov534
$ modprobe -r gspca-main
$ modprobe gspca-main
$ modprobe gspca-ov534 videomode=10


The available video modes are: 
00: 640x480@15
01: 640x480@30
02: 640x480@40
03: 640x480@50
04: 640x480@60
10: 320x240@30
11: 320x240@40
12: 320x240@50
13: 320x240@60
14: 320x240@75
15: 320x240@100
16: 320x240@125



You can adjust the image using guvcview 
$ sudo apt-get install guvcview
$ guvcview

32 comments:

  1. Great work, thanks! Please submit the patch upstream and fight hard to get it into mainline kernel as soon as possible, it could give mankind the long-awaited chance to use PS3 Eye for motion-triggered recording in 640x800 on 500 MHz AMD Geode CPU without overburdening even in the grainiest moments.

    ReplyDelete
  2. David,
    Thank you for posting your article! I'm trying to use my ps3 eye on a Pandaboard and found the 320x240 resolution to be poor. I've followed your steps up to the first step in 4) Recompile driver: and am getting this error: "cp: cannot stat '/usr/src/linux-headers-3.0.0-1210-omap4/Module.symvers": No such file or directory". I'm more or less a noob to Linux and not a coder, so I'm a bit lost as to a solution. Any suggestions?

    Thank you,
    Cris

    ReplyDelete
    Replies
    1. Are your headers installed?

      sudo apt-get install linux-headers-`uname-r`

      If so, have a look at this answer: http://unix.stackexchange.com/questions/24704/how-to-generate-module-symvers

      I'd try to run 'make modules' at the sources directory, then see if that generated the Module.symvers file:

      sudo updatedb
      locate Module.symvers

      Cheers,

      David

      Delete
  3. The out-of the-box support for PS3Eye in Linux 3.2.0 is not very good. It looks as if the actual capture res was fixed at 160x120, and then upscaled to the resolution requested by an application. There is an occasional flickering and FPS in 640x480 is stuttering at about 20. And this all on a quad-core CPU and Nvidia8600. I thus followed the steps in this post, but got compilation errors, though. I attach some of them at the end of this comment.


    It looks, thus, that the better driver is incompatible with 3.2.0, and the camera is in effect useless currently for me.

    Any chance on updating the driver and putting it into the mainline?

    compile log:

    drivers/media/video/gspca/benq.c: In function ‘reg_w’:
    drivers/media/video/gspca/benq.c:56:15: error: ‘struct gspca_dev’ has no member named ‘usb_err’
    drivers/media/video/gspca/benq.c:68:12: error: ‘struct gspca_dev’ has no member named ‘usb_err’
    drivers/media/video/gspca/benq.c: In function ‘sd_config’:
    drivers/media/video/gspca/benq.c:78:16: error: ‘struct cam’ has no member named ‘no_urb_create’
    drivers/media/video/gspca/benq.c:79:16: error: ‘struct cam’ has no member named ‘reverse_alts’
    drivers/media/video/gspca/benq.c: In function ‘sd_start’:
    drivers/media/video/gspca/benq.c:133:18: error: ‘struct gspca_dev’ has no member named ‘usb_err’

    ...

    ReplyDelete
    Replies
    1. Hi ithinu,

      Looks to me that the files gspca.c and gspca.h in the sources of your kernel are a newer version.
      I don't have the 3.2 kernel yet, I'm waiting for Ubuntu 12.04.1
      If you want to try, you can do the same I did with the version available in this post:

      Edit your kernel's original gspca.c and gspca.h, and compare them to the ones you downloaded from here. Try to copy the part related to the PS3eye from my files into your original files and use these for the compilation.

      Delete
    2. It appears that gspca from the 3.2 kernel does not need any modifications to support the patched module. The module, though, requires some changes to support the newer video interface. I did these changes, and now I have a smooth 60fps 640x480 without any upscaling, but noticed something strange -- the patched module ignores the param videomode, and lists 640x480 as the only available format. So, I made the module to support both 320x240 and 640x480, but 320x240 looks like upscaled 160x120, as once 640x480 did.

      Have no idea where is the problem, perhaps the low-level chip resolution setting is buggy.

      Delete
    3. I installed the stock 3.2 ov534 again to compare. As of the true resolution, 320x240 is wrong, but 640x480 is ok. I recall that once 640x480 looked like 160x120, as I wrote. Now I do not know if I was mistaken or the is another factor. Colors are off, though, as soon as you tinker with settings, so the stock driver is still unusable.

      The stuttering 20fps I wrote about was due to some inefficient viewer application, guvcview works fine.

      Interesingly, the driver says, that the Kaswy patches are in.

      As of the framerate, no version of the module sets more that 60fps, despite of what it declares. The switch in the code simply does not take into account fps>60.

      So, all in all, we'd have out--of--the box PS3 Eye in 640x480x60 at least, were there no some color bug in the 3.2 module, that is absent in the module linked in David's post. Unless 640x480 sometimes looks like 160x120 for whatever reason...

      Delete
    4. That is all good to know. As Ubuntu 12.04.1 release will be soon, I'll have a deeper look then, and try to make every parameter and framerate (including 320x240@125fps) work and be selectable via software.
      Colors have been sometimes strange with this camera in the past. It seems to do some kind of strange balance. Then if you play with the settings (select defaults, etc.) eventually corrects itself. If that does not work, you can also have a look also at the color order/space RGB, BGR,... in the driver's code.

      Delete
    5. I've just compiled the original module from http://packages.ubuntu.com/oneiric/all/linux-source-3.0.0/download

      It works with issues in guvcview. It freezes when changing the framerate but then, next time you start guvcview and select the camera it work with the new framerate you selected.
      From my own code, using openframeworks (wich uses gstreamer), the driver doesn't let you select the framerate/resolution. It throws an error and you have to plug/unplug the camera to make it work again.

      Delete
  4. A true module zoo...

    There is yet another driver, one that indeed sets >60fps modes in the code... http://wiki.tekkotsu.org/index.php/Sony_PlayStation_Eye_driver_install_instructions but they do not work on my camera. And this is the only driver without the color issue -- yes, the one from this site sometimes has wrong colors as well.

    But none of the drivers sets properly 320x240 on my device.

    ReplyDelete
  5. I have found a version of the driver that seems to have no problem with colors: http://wiki.tekkotsu.org/index.php/Sony_PlayStation_Eye_driver_install_instructions, perhaps because it has some color management.

    It also has some code for >60fps framerates, that do not work on my camera, though. And 320x240 is still really 160x120.

    I wonder, if there are different versions of ps3 eye on the market. Does your camera provide crisp 320x240?

    ReplyDelete
    Replies
    1. This is what I get with the original linux-source-3.0.0 driver:

      320x240@125fps
      http://imageshack.us/photo/my-images/824/pantallazo320.png

      640x480@60fps
      http://imageshack.us/photo/my-images/843/pantallazo1ur.png

      Delete
    2. This is what I get, too. Not quite 320x240, look at the upper edge of the window shades for example. I just checked the windows driver, the blockiness is there, too, but hidden by a quite strong blurring.

      Don't know if this is the camera's property, or if simply both Linux and Windows drivers are faulty. The are both back-engineered probably.

      Fortunately, 640x480 is much crisper, which is strange, as for many cameras the hi-res modes are worse than the low-res ones at the level of a single pixel, due to the Bayes matrix interpolation.

      Still, a nice camera at 60fps, thanks to the lack of CPU-swamping compression.

      Delete
  6. Hi David, i want to know which Ubuntu version you are using in this post. Ubuntu 11.10? Thanks.

    ReplyDelete
  7. Hi Winson, the instructions and patches were tested on Ubuntu 10.04 with kernel 2.6.xx, probably 2.6.30 or so.
    I'm currently on the same 10.04, but with backported kernel 3.0.0.21. It seems newer kernels do not need the changes I made to gspca.h and gspca.c

    ReplyDelete
    Replies
    1. I am running ubuntu 11.04 with kernel vesion 2.6.38
      I get
      "error: too few arguments to function ‘gspca_frame_add’"
      during following step:
      "make SUBDIRS=drivers/media/video/gspca modules"

      Delete
  8. Are you using the original gspca.c and gspca.h or the patched ones?

    The calls to the function gspca_frame_add() made from inside ov534.c have to match the definition of that function in gspca.h, You need to pass the right arguments to the function.

    I've seen two variants:

    struct gspca_frame *gspca_frame_add(struct gspca_dev *gspca_dev,
    enum gspca_packet_type packet_type,
    struct gspca_frame *frame,
    const __u8 *data,
    int len);

    void gspca_frame_add(struct gspca_dev *gspca_dev,
    enum gspca_packet_type packet_type,
    const u8 *data,
    int len);

    ReplyDelete
    Replies
    1. I did follow all your steps including using your gspca.c,gspca.h,ov534.c files but still failed, i will try to looking into this problem.

      Delete
    2. This comment has been removed by a blog administrator.

      Delete
  9. Hola David,
    I wonder if you ever got to try this driver in 12.04...
    ithinu, could you post the one that did work?
    best,
    J

    ReplyDelete
    Replies
    1. Hola! :)

      I haven't installed 12.04 yet. But will upgrade in July, whit the release of 12.04.1

      Then I will try to make it work again.

      Best,

      David

      Delete
    2. http://ithinu.wordpress.com/2012/06/29/a-ps3-eye-driver-patched-to-work-with-3-0-2/

      Delete
    3. I've just tried that and that does not compile with my 3.0 kernel source :/

      Delete
    4. it turns out, the wordpress software "prettified" the source with things like left/right quote and now it does not compile of course...

      worse yet, I have overwritten the original patched module

      anyway, it is very easy to update the module: remove the parameter "frame" from calls to gspca_frame_add, remove "frame" from the declaration of sd_pkt_scan, replace ints with voids in some two methods, which otherwise will cause a type mismatch error, remove return statements from these two methods, and that's perhaps all

      very straightforward -- just look for compile errors and correct them

      also, as you said, no need to patch gspca.[ch] in newer kernels

      Delete
  10. http://ithinu.wordpress.com/2012/06/29/a-ps3-eye-driver-patched-to-work-with-3-0-2/

    ReplyDelete
  11. After installing the driver, I just get a lot of this in the console:

    Could not grab image (select timeout): Resource temporarily unavailable

    Any ideas?

    ReplyDelete
  12. Some googling suggested to try point 7 at: https://help.ubuntu.com/community/Webcam/Troubleshooting

    If you are on a desktop, plug the camera directly into one of the rear usb connectors.

    ReplyDelete
  13. Hola David,

    Back in my 12.04 machine and wondering if you did install this version and tested your driver...

    best,
    Jaime

    ReplyDelete
  14. Hola!

    I've just done a fresh 12.04 install and the PS3 Eye seems to works out of the box with framerate change support.

    ReplyDelete
  15. Indeed it does.

    The reason why I wanted to try out your code is that I have a working system in Pd/GEM running on fedora 11 using Kaswy's driver, which was far simpler than current ones.

    That exact same system, on a different machine running ubuntu 12.04 crashes. I am setting the driver parameters through guvcview.

    I am at a loss as to what might be causing this, so I was thinking of trying other drivers/versions.

    best,

    J

    ReplyDelete
  16. I have tested pix_video without problems, parameted "dimen" works fine also. I used this pd-extended:

    http://www.mail-archive.com/pd-list@iem.at/msg51542.html

    ReplyDelete