glogglog

Got Motorola E6 camera works in skype

What?

I made a uvcvideo patch to make Motorola E6 camera works in skype in 320x240 mode.

Why?

I have a Motorola E6 cellphone, which has a 2.0M pixel camera. If you set USB mode as "Webcamera", after connecting to PC, this cellphone can act as a webcamera. It works fine in 640x480 mode, but in lower resolutions like 320x240, the video overlaps. The problem is skype, which I used for video chatting with my gf, only send 320x240 resolution. So I cannot use cellphone as webcamera and have to carry an extra webcamera during every trip.

Somebody suggested that a hack to skype config.xml will make skype call with high resolution, but it seems only works in Windows, at least not worked in my Ubuntu9.04 Skype 2.1.0.47.

Indeed, Moto E6 camera(22b8:6006) is a USB video class device. The uvcvideo is in charge to drive this device. But because some issues, when uvcvideo changed the resolution to lower, the hardware didn't change, it send a whole 640x480 frame even when the driver expects a lower resolution

If Skype set resolution to 320x240, the driver malloc a shorter buffer, the length of which is 1/4 of the 640x480 buffer length. When hardware send data to driver, the driver keep complaining "Frame complete (overflow).", that's because the driver buffer is full but hardware keep sending the later 3/4 (640x480)frame. The video is overlapped that's because the driver treat the upper 1/4 of (640x480) frame data as one 320x240 frame data, the first row of 640x480 frame converted to the first and the second row in 320x240 frame. The left part converted to the first row, the right part converted to the second row. So the result is the left part and the right part of the upper 1/4 of (640x480) video, overlaped in 320x240 video, the lower 3/4 video just gone. Here is the snapshot of the videos.

From uvc

And this script verified my guess.

How?

But it seems no solution for this problem. Windows driver maybe works fine, but I have no Windows system at hand. And this thread gave me an idea. It's pretty simple: it store the (640x480) frame data to somewhere and convert them to (320x240) frame data when the last piece of package arrived.

At first, I treat the frame data as bitmap, two bytes is a pixel, and compress it to 1/4. The result looks ugly.

From uvc

Then I found the frame data is in YUYV format, in which 2 pixels will be defined in each macropixel (four bytes). I realized that my previous method make video lost some components. The second solution is: only keep the even(th) rows pixels of the original frame, in each row only keep the 2*even(th) cols pixels. That's is, in one row, copy 2 pixel(4byte), and skip 2 pixel(4byte), copy 2 pixel, skip 2 pixel....etc. This method have an advantage of avoiding compute YUV components of each pixel, disadvantage is obvious: heavy sawtooth

From uvc

So the anti-aliasing is needed, the final solution is to compute the nearby 4 pixel to get the result 1 pixel.

From uvc

Usage

1. Get the source from uvcvideo(install mercurial if needed):

 

hg clone http://linuxtv.org/hg/~pinchartl/uvcvideo/

 

2. Download this patch file to uvcvideo directory and apply the patch. (Warning this path is based on 12393:756ad91a832e)

cd uvcvideo && wget http://sevenever.googlecode.com/svn/trunk/misc/patch_MOTO_E6_to320.patch && patch < patch_MOTO_E6_to320.patch 

3. Make

make

4. Test

 

sudo rmmod uvcvideo ;sudo rmmod videodev;sudo rmmod v4l1_compat 

sudo insmod v4l1-compat.ko; sudo insmod videodev.ko; sudo insmod uvcvideo.ko to320=1

I have add a module parameter "to320" to uvcvideo.ko, if this parameter is 0, the patch will not work. Command to change this parameter is "echo 1 | sudo tee /sys/module/uvcvideo/parameters/to320".

now plugin cellphone and launch skype.

5. if everything is OK, you can install this module.

mv v4l/v4l1-compat.ko /lib/modules/`uname -r`/kernel/drivers/media/video/.

mv v4l/videodev.ko /lib/modules/`uname -r`/kernel/drivers/media/video/.

mv v4l/uvcvideo.ko /lib/modules/`uname -r`/kernel/drivers/media/video/uvc/.

run modconf to reload uvcvideo and append parameter "to320=1"

Better solution

If this camera works fine in Windows, probably there some issues about the uvc driver. Later after I come back to Shanghai, a USB traffic dump is scheduled. If I can confirm that hardware has no problem, this dirty hack is not needed.

End

Thank you for reading up this post and be patient to my poor English, here is my little gift:

From uvc



Tags: uvcvideo | E6 | camera | linux |
sevenever@gmail.com
Copyright © 2008. All rights reserved.