diff --git a/gb.v4l/src/CWebcam.c b/gb.v4l/src/CWebcam.c index 0124dd671..efa1e77f0 100644 --- a/gb.v4l/src/CWebcam.c +++ b/gb.v4l/src/CWebcam.c @@ -608,6 +608,19 @@ BEGIN_PROPERTY(CWEBCAM_contrast_min) END_PROPERTY +BEGIN_PROPERTY(CWEBCAM_contrast_def) + + if( !THIS->is_v4l2 ) + GB.ReturnInteger(65536/2); + else { + if(!THIS->contrast_def) + GB.ReturnInteger((THIS->contrast_max-THIS->contrast_min)/2); + else GB.ReturnInteger(THIS->contrast_def); + } + +END_PROPERTY + + BEGIN_PROPERTY(CWEBCAM_colour) if( !THIS->is_v4l2 ) { @@ -645,6 +658,18 @@ BEGIN_PROPERTY(CWEBCAM_color_min) END_PROPERTY +BEGIN_PROPERTY(CWEBCAM_color_def) + + if( !THIS->is_v4l2 ) + GB.ReturnInteger(65536/2); + else { + if(!THIS->color_def) + GB.ReturnInteger((THIS->color_max-THIS->color_min)/2); + else GB.ReturnInteger(THIS->color_def); + } + +END_PROPERTY + BEGIN_PROPERTY(CWEBCAM_whiteness) if( !THIS->is_v4l2 ) { @@ -682,6 +707,14 @@ BEGIN_PROPERTY(CWEBCAM_whiteness_min) END_PROPERTY +BEGIN_PROPERTY(CWEBCAM_whiteness_def) + + if( !THIS->is_v4l2 ) + GB.ReturnInteger(65536/2); + else GB.ReturnInteger(THIS->whiteness_def); + +END_PROPERTY + BEGIN_PROPERTY(CWEBCAM_hue) if( !THIS->is_v4l2 ) { @@ -719,6 +752,14 @@ BEGIN_PROPERTY(CWEBCAM_hue_min) END_PROPERTY +BEGIN_PROPERTY(CWEBCAM_hue_def) + + if( !THIS->is_v4l2 ) + GB.ReturnInteger(65536/2); + else GB.ReturnInteger(THIS->hue_def); + +END_PROPERTY + BEGIN_PROPERTY(CWEBCAM_bright) if( !THIS->is_v4l2 ) { @@ -756,6 +797,18 @@ BEGIN_PROPERTY(CWEBCAM_bright_min) END_PROPERTY +BEGIN_PROPERTY(CWEBCAM_bright_def) + + if( !THIS->is_v4l2 ) + GB.ReturnInteger(65536/2); + else { + if(!THIS->bright_def) + GB.ReturnInteger((THIS->bright_max-THIS->bright_min)/2); + else GB.ReturnInteger(THIS->bright_def); + } + +END_PROPERTY + BEGIN_PROPERTY(CWEBCAM_width) if( THIS->is_v4l2 ) // ++ @@ -1581,20 +1634,36 @@ GB_DESC CWebcamDesc[] = GB_PROPERTY_READ("Height","i",CWEBCAM_height), GB_PROPERTY("Contrast","i",CWEBCAM_contrast), - GB_PROPERTY("Contrast_Max","i",CWEBCAM_contrast_max), - GB_PROPERTY("Contrast_Min","i",CWEBCAM_contrast_min), + GB_PROPERTY("ContrastMax","i",CWEBCAM_contrast_max), + GB_PROPERTY("ContrastMin","i",CWEBCAM_contrast_min), + GB_PROPERTY("ContrastDefault","i",CWEBCAM_contrast_def), GB_PROPERTY("Color","i",CWEBCAM_colour), - GB_PROPERTY("Color_Max","i",CWEBCAM_color_max), - GB_PROPERTY("Color_Min","i",CWEBCAM_color_min), + GB_PROPERTY("ColorMax","i",CWEBCAM_color_max), + GB_PROPERTY("ColorMin","i",CWEBCAM_color_min), + GB_PROPERTY("ColorDefault","i",CWEBCAM_color_def), GB_PROPERTY("Whiteness","i",CWEBCAM_whiteness), - GB_PROPERTY("Whiteness_Max","i",CWEBCAM_whiteness_max), - GB_PROPERTY("Whiteness_Min","i",CWEBCAM_whiteness_min), + GB_PROPERTY("WhitenessMax","i",CWEBCAM_whiteness_max), + GB_PROPERTY("WhitenessMin","i",CWEBCAM_whiteness_min), + GB_PROPERTY("WhitenessDefault","i",CWEBCAM_whiteness_def), GB_PROPERTY("Bright","i",CWEBCAM_bright), - GB_PROPERTY("Bright_Max","i",CWEBCAM_bright_max), - GB_PROPERTY("Bright_Min","i",CWEBCAM_bright_min), + GB_PROPERTY("BrightMax","i",CWEBCAM_bright_max), + GB_PROPERTY("BrightMin","i",CWEBCAM_bright_min), + GB_PROPERTY("BrightDefault","i",CWEBCAM_bright_def), GB_PROPERTY("Hue","i",CWEBCAM_hue), - GB_PROPERTY("Hue_Max","i",CWEBCAM_hue_max), - GB_PROPERTY("Hue_Min","i",CWEBCAM_hue_min), + GB_PROPERTY("HueMax","i",CWEBCAM_hue_max), + GB_PROPERTY("HueMin","i",CWEBCAM_hue_min), + GB_PROPERTY("HueDefault","i",CWEBCAM_hue_def), + + GB_PROPERTY_READ("Name","s",CFEATURES_name), + GB_PROPERTY_READ("Driver","s",CFEATURES_driver), + GB_PROPERTY_READ("Bus","s",CFEATURES_bus), + GB_PROPERTY_READ("Card","s",CFEATURES_card), // ++ V4L2 + GB_PROPERTY_READ("Version","s",CFEATURES_version), + GB_PROPERTY_READ("MaxWidth","i",CFEATURES_maxWidth), + GB_PROPERTY_READ("MinWidth","i",CFEATURES_minWidth), + GB_PROPERTY_READ("MaxHeight","i",CFEATURES_maxHeight), + GB_PROPERTY_READ("MinHeight","i",CFEATURES_minHeight), + //GB_PROPERTY_READ("MaxFrameRate","i",CFEATURES_maxRate), GB_PROPERTY("Image","Image",CWEBCAM_image), GB_PROPERTY("Debug","i",CWEBCAM_debug), diff --git a/gb.v4l/src/CWebcam.h b/gb.v4l/src/CWebcam.h index dce0ecb7e..42c480b7a 100644 --- a/gb.v4l/src/CWebcam.h +++ b/gb.v4l/src/CWebcam.h @@ -138,6 +138,12 @@ typedef struct int contrast_min; int whiteness_min; int color_min; + // + int bright_def; + int hue_def; + int contrast_def; + int whiteness_def; + int color_def; // -- } CWEBCAM; diff --git a/gb.v4l/src/gv4l2.c b/gb.v4l/src/gv4l2.c index c738a7016..13d291b2a 100644 --- a/gb.v4l/src/gv4l2.c +++ b/gb.v4l/src/gv4l2.c @@ -94,7 +94,7 @@ int gv4l2_xioctl( int fd,int request,void * arg) // // gv4l2_hue( THIS, value ) // -void gv4l2_camera_setup( CWEBCAM * _object , int id , int * min, int * max) +void gv4l2_camera_setup(CWEBCAM *_object,int id,int *min,int *max,int *def) { struct v4l2_queryctrl query; @@ -103,15 +103,16 @@ void gv4l2_camera_setup( CWEBCAM * _object , int id , int * min, int * max) if(gv4l2_xioctl(THIS->io,VIDIOC_QUERYCTRL,&query)==-1)return; - printf("Name=%s,Min=%d,Max=%d,Value=%d\n", - query.name, - query.minimum, - query.maximum, - query.default_value); - fflush(stdout); + //printf("Name=%s,Min=%d,Max=%d,Value=%d\n", + // query.name, + // query.minimum, + // query.maximum, + // query.default_value); + //fflush(stdout); *max = query.maximum; *min = query.minimum; + *def = query.default_value; } // int gv4l2_camera_get( CWEBCAM * _object , int id , int value ) @@ -137,7 +138,7 @@ int gv4l2_camera_get( CWEBCAM * _object , int id , int value ) void gv4l2_hue_setup( CWEBCAM * _object ) { gv4l2_camera_setup( THIS , - V4L2_CID_HUE , &THIS->hue_min , &THIS->hue_max ); + V4L2_CID_HUE , &THIS->hue_min , &THIS->hue_max ,&THIS->hue_def); } // int gv4l2_hue( CWEBCAM * _object , int value ) @@ -152,7 +153,7 @@ int gv4l2_hue( CWEBCAM * _object , int value ) void gv4l2_brightness_setup( CWEBCAM * _object ) { gv4l2_camera_setup( THIS, - V4L2_CID_BRIGHTNESS , &THIS->bright_min , &THIS->bright_max ); + V4L2_CID_BRIGHTNESS , &THIS->bright_min ,&THIS->bright_max,&THIS->bright_def); } int gv4l2_brightness( CWEBCAM * _object , int value ) @@ -167,7 +168,7 @@ int gv4l2_brightness( CWEBCAM * _object , int value ) void gv4l2_contrast_setup( CWEBCAM * _object ) { gv4l2_camera_setup( THIS , - V4L2_CID_CONTRAST, &THIS->contrast_min , &THIS->contrast_max); + V4L2_CID_CONTRAST, &THIS->contrast_min , &THIS->contrast_max,&THIS->contrast_def); } int gv4l2_contrast( CWEBCAM * _object , int value ) @@ -182,7 +183,7 @@ int gv4l2_contrast( CWEBCAM * _object , int value ) void gv4l2_color_setup( CWEBCAM * _object ) { gv4l2_camera_setup( THIS , - V4L2_CID_SATURATION, &THIS->color_min, &THIS->color_max ); + V4L2_CID_SATURATION, &THIS->color_min, &THIS->color_max,&THIS->color_def ); } int gv4l2_color( CWEBCAM * _object , int value ) @@ -197,7 +198,7 @@ int gv4l2_color( CWEBCAM * _object , int value ) void gv4l2_whiteness_setup( CWEBCAM * _object ) { gv4l2_camera_setup( THIS , - V4L2_CID_WHITENESS , &THIS->whiteness_min,&THIS->whiteness_max); + V4L2_CID_WHITENESS , &THIS->whiteness_min,&THIS->whiteness_max,&THIS->whiteness_def); } // int gv4l2_whiteness( CWEBCAM * _object , int value ) @@ -267,6 +268,7 @@ int gv4l2_init_device(CWEBCAM * _object , int width , int height ) { unsigned int min; static unsigned int n_buffers = 0; + int save; if ( gv4l2_xioctl (THIS->io, VIDIOC_QUERYCAP, &THIS->cap) == -1 ) { gv4l2_debug("VIDIOC_QUERYCAP error"); @@ -319,17 +321,32 @@ int gv4l2_init_device(CWEBCAM * _object , int width , int height ) THIS->fmt.fmt.pix.width = width; THIS->fmt.fmt.pix.height = height; THIS->fmt.fmt.pix.field = V4L2_FIELD_INTERLACED; + save = THIS->fmt.fmt.pix.pixelformat; // // Camera format should be picked up from VIDIOC_G_FMT above // FIXME:: do cameras support multiple formats and so we want // to be able to pick the format?? // + // Try the supported formats; + // a. YUYV + // b. YUV420 + // c. revert to whatever the camera was set to + // + THIS->fmt.fmt.pix.pixelformat = V4L2_PIX_FMT_YUYV; + if ( gv4l2_xioctl ( THIS->io, VIDIOC_S_FMT, &THIS->fmt) == -1) { + gv4l2_debug("VIDIOC_S_FMT, can't set YUYV, trying YUV 420"); + THIS->fmt.fmt.pix.pixelformat = V4L2_PIX_FMT_YUV420; + if ( gv4l2_xioctl ( THIS->io, VIDIOC_S_FMT, &THIS->fmt) == -1) { + gv4l2_debug("VIDIOC_S_FMT, can't set YUV420, defaulting "); + THIS->fmt.fmt.pix.pixelformat = save; + } + } //THIS->fmt.fmt.pix.pixelformat = V4L2_PIX_FMT_YUYV; - if ( gv4l2_xioctl ( THIS->io, VIDIOC_S_FMT, &THIS->fmt) == -1) { - gv4l2_debug("VIDIOC_S_FMT, unable to set format"); - return 0; - } + //if ( gv4l2_xioctl ( THIS->io, VIDIOC_S_FMT, &THIS->fmt) == -1) { + // gv4l2_debug("VIDIOC_S_FMT, unable to set format"); + // return 0; + //} // THIS->fmt.fmt.pix.pixelformat = V4L2_PIX_FMT_YUYV; // gv4l2_xioctl ( THIS->io, VIDIOC_S_FMT, &THIS->fmt); @@ -371,7 +388,7 @@ int gv4l2_init_device(CWEBCAM * _object , int width , int height ) struct v4l2_requestbuffers req; MCLEAR(req); - req.count = 4; + req.count = 2; req.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; req.memory = V4L2_MEMORY_MMAP;