Bug 1203 - RGB webcams
: RGB webcams
Status: NEW
: Node Management Software
Video Producer Service
: 2.3
: PC Linux
: P2 normal (vote)
: ---
Assigned To:
:
:
:
  Show dependency treegraph
 
Reported: 2004-10-28 21:54 by
Modified: 2004-11-18 02:27 (History)


Attachments
Falls back to RGB if YUV fails (1.97 KB, patch)
2004-10-28 21:55, Nigel Sim
Details
new RGB24 patch (3.00 KB, patch)
2004-11-18 02:27, Douglas Kosovic
Details


Note

You need to log in before you can comment on or make changes to this bug.


Description From 2004-10-28 21:54:48
My webcam (Kensington 67014) which uses the SE401 driver only produces RGB24
frames. I've patched vic to make it check if YUV production is supported, and if
not it falls back to RGB24. The patch to video/grabber-video4linux.cpp follows:

Index: grabber-video4linux.cpp
===================================================================
RCS file: /cvs/fl/ag-media/vic/video/grabber-video4linux.cpp,v
retrieving revision 1.2
diff -r1.2 grabber-video4linux.cpp
47a48,49
> #include "rgb-converter.h"
> 
71a74
> #define CF_RGB24 3
313a317
>     bool force_rgb24 = false;
352a357,361
>     vid_mmap.format = VIDEO_PALETTE_YUV422;
>     if (-1 == ioctl(fd_, VIDIOCMCAPTURE, &vid_mmap)){
>         force_rgb24 = true;
>     }
>         
408,409d416
<  
<  
417c424,426
<     
---
>     if(force_rgb24)
>         cformat_ = CF_RGB24;
> 
569,571c578,580
< 	if (-1 == ioctl(fd_, VIDIOCMCAPTURE, &gb_even))
< 	    perror("ioctl VIDIOCMCAPTURE even");
< 	else
---
> 	if (-1 == ioctl(fd_, VIDIOCMCAPTURE, &gb_even)){
> 	    perror("V4lGrabber::start() ioctl VIDIOCMCAPTURE even");
> 	} else
574,576c583,585
< 	if (-1 == ioctl(fd_, VIDIOCMCAPTURE, &gb_odd))
< 	    perror("ioctl VIDIOCMCAPTURE odd");
< 	else
---
> 	if (-1 == ioctl(fd_, VIDIOCMCAPTURE, &gb_odd)){
> 	    perror("V4lGrabber::start() ioctl VIDIOCMCAPTURE odd");
> 	}else
609c618
< 	    perror("ioctl VIDIOCSYNC");
---
> 	    perror("V4lGrabber::grab() ioctl VIDIOCSYNC");
632a642,647
>     
>     case CF_RGB24:
>         RGB_Converter *converter = new RGB_Converter_411(24,NULL,0);
>         converter->convert((u_int8_t*)fr, width_,
height_,(u_int8_t*)frame_,width_,height_,0);
>         delete converter;
>         break;
634c649
< 
---
> 	
637,639c652,654
< 			(grab_count % 2) ? &gb_odd : &gb_even))
< 	    perror("ioctl VIDIOMCAPTURE");
< 	else
---
> 			(grab_count % 2) ? &gb_odd : &gb_even)){
> 	    perror("V4lGrabber::grab() ioctl VIDIOMCAPTURE");
> 	}else
816c831,835
<     v4lformat_=VIDEO_PALETTE_YUV422;
---
>     if (cformat_ == CF_RGB24) {
>         v4lformat_= VIDEO_PALETTE_RGB24;
>     } else {
>         v4lformat_ = VIDEO_PALETTE_YUV422;
>     }
840a860,863
>     case CF_RGB24:
>         set_size_411(width_, height_);
>         DEBUG(fprintf(stderr," RGB24"));
> 		break;
841a865
>
------- Comment #1 From 2004-10-28 21:55:37 -------
Created an attachment (id=86) [details]
Falls back to RGB if YUV fails
------- Comment #2 From 2004-11-16 17:24:59 -------
The patch breaks webcams based on the pwc driver (or more generally devices 
that only support YUV420).

I think the following code in the patch:

    vid_mmap.format = VIDEO_PALETTE_YUV422;
    if (-1 == ioctl(fd_, VIDIOCMCAPTURE, &vid_mmap)){
        force_rgb24 = true;
    }

should be:

    vid_mmap.format = VIDEO_PALETTE_RGB24;
    if (-1 != ioctl(fd_, VIDIOCMCAPTURE, &vid_mmap)){
        force_rgb24 = true;
    }

Which makes the pwc based webcams work once again.

I would also recommend that the converter local variable in the following code 
be a member variable of the V4lGrabber class, to avoid C++ overheads of 
calling the RGB_Converter_411 C++ constructor and destructor up to 30 times a 
second:

int V4lGrabber::grab()
{
...
    case CF_RGB24:
        RGB_Converter *converter = new RGB_Converter_411(24,NULL,0);
        converter->convert((u_int8_t*)fr, width_, 
height_,(u_int8_t*)frame_,width_,height_,0);
        delete converter;
        break;
    }
...
}


Doug
------- Comment #3 From 2004-11-16 18:15:21 -------
If this code is used:
    vid_mmap.format = VIDEO_PALETTE_RGB24;
    if (-1 != ioctl(fd_, VIDIOCMCAPTURE, &vid_mmap)){
        force_rgb24 = true;
    }

It would mean that if the camera FAILS to work in RGB24 mode, then force it into
RGB24 mode. The reason I checked against VIDEO_PALETTE_YUV422 is so that if it
failed then it would fall back. Unfortunately I don't have multiple cameras so I
can't really test this patch as much as I would like. 
------- Comment #4 From 2004-11-16 18:30:36 -------
I think the logic is the other way around, as I changed it from == -1 to != -1 
in the ioctl test, so it should only be set to RGB24 if the ioctl test for 
RGB24 doesn't fail.

Doug
------- Comment #5 From 2004-11-18 02:27:03 -------
Created an attachment (id=87) [details]
new RGB24 patch

The attached patch is a combination of both, it will only force RGB24 if
supported and then only if YUV422 isn't.

It should hopefully be a suitable solution.