Hi,

I've been using luvcview to debug and bring up my cam (successfully
:-)), but have some improvements to suggest:

On Sun, Mar 16, 2008 at 10:30:38 -0400, Jerry wrote:
> Unable to start capture: 71.

I can't help with Jerry's problem, but I have some suggestions for code
improvements, e.g. to be able to tell Jerry that the above (71) is a
"protocol error".

The function perror() is being used in a few places, and
strerror[errno] in a few others, but not consequently throughout. I'm
attaching a patch which makes more use of perror(), hopefully appending
useful strings to all error messages. I know it has helped me in using
luvcview. The patch also removes the trailing "\n"s from perror(),
which mess up its display.

A second patch removes all whitespace at line ends. Admittedly, this is
purely cosmetic ;), but was an initial result of my cleanup of perror()
as mentioned above.

Oh, and since the changelog mentions the version 0.2.2, I thought it
might be okay to bump the version string in the Makefile as well. :)

If you think these patches are useful, feel free to integrate them into
its source.

Just to let you know,
thanks for listening and thanks for the tool!
Moritz
diff -ur luvcview-20070512/v4l2uvc.c luvcview-20070512-perror/v4l2uvc.c
--- luvcview-20070512/v4l2uvc.c 2007-05-08 17:39:40.000000000 +0200
+++ luvcview-20070512-perror/v4l2uvc.c  2008-03-16 19:47:44.000000000 +0100
@@ -41,7 +41,7 @@
        snprintf(vd->videodevice, 12, "%s", device);
     printf("video %s \n", vd->videodevice);
     if ((vd->fd = open(vd->videodevice, O_RDWR)) == -1) {
-       perror("ERROR opening V4L interface \n");
+       perror("ERROR opening V4L interface");
        exit(1);
     }
     memset(&vd->cap, 0, sizeof(struct v4l2_capability));
@@ -195,7 +195,7 @@
     } else {
       if (errno == EINVAL)
         continue;
-      printf ("error getting base controls");
+      perror ("error getting base controls");
       goto fatal_controls;
     }
   }
@@ -235,7 +235,7 @@
   memset (&control_s, 0, sizeof (control_s));
   configfile = fopen("luvcview.cfg", "w");
   if ( configfile == NULL) {
-    printf( "saving configfile luvcview.cfg failed, errno = %d (%s)\n", errno, 
strerror( errno));
+    perror("saving configfile luvcview.cfg failed");
   }
   else {
     fprintf(configfile, "id         value      # luvcview control settings 
configuration file\n");
@@ -292,7 +292,7 @@
   memset (&control, 0, sizeof (control));
   configfile = fopen("luvcview.cfg", "r");
   if ( configfile == NULL) {
-    printf( "configfile luvcview.cfg open failed, errno = %d (%s)\n", errno, 
strerror( errno));
+    perror("configfile luvcview.cfg open failed");
   }
   else {
     printf("loading controls from luvcview.cfg \n");
@@ -317,7 +317,7 @@
     int ret = 0;
 
     if ((vd->fd = open(vd->videodevice, O_RDWR)) == -1) {
-       perror("ERROR opening V4L interface \n");
+       perror("ERROR opening V4L interface");
        exit(1);
     }
     memset(&vd->cap, 0, sizeof(struct v4l2_capability));
@@ -353,7 +353,7 @@
     vd->fmt.fmt.pix.field = V4L2_FIELD_ANY;
     ret = ioctl(vd->fd, VIDIOC_S_FMT, &vd->fmt);
     if (ret < 0) {
-       printf("Unable to set format: %d.\n", errno);
+       perror("Unable to set format");
        goto fatal;
     }
     if ((vd->fmt.fmt.pix.width != vd->width) ||
@@ -383,7 +383,7 @@
 
     ret = ioctl(vd->fd, VIDIOC_REQBUFS, &vd->rb);
     if (ret < 0) {
-       printf("Unable to allocate buffers: %d.\n", errno);
+       perror("Unable to allocate buffers");
        goto fatal;
     }
     /* map the buffers */
@@ -394,7 +394,7 @@
        vd->buf.memory = V4L2_MEMORY_MMAP;
        ret = ioctl(vd->fd, VIDIOC_QUERYBUF, &vd->buf);
        if (ret < 0) {
-           printf("Unable to query buffer (%d).\n", errno);
+           perror("Unable to query buffer");
            goto fatal;
        }
        if (debug)
@@ -404,7 +404,7 @@
                          vd->buf.length, PROT_READ, MAP_SHARED, vd->fd,
                          vd->buf.m.offset);
        if (vd->mem[i] == MAP_FAILED) {
-           printf("Unable to map buffer (%d)\n", errno);
+           perror("Unable to map buffer");
            goto fatal;
        }
        if (debug)
@@ -418,7 +418,7 @@
        vd->buf.memory = V4L2_MEMORY_MMAP;
        ret = ioctl(vd->fd, VIDIOC_QBUF, &vd->buf);
        if (ret < 0) {
-           printf("Unable to queue buffer (%d).\n", errno);
+           perror("Unable to queue buffer");
            goto fatal;;
        }
     }
@@ -435,7 +435,7 @@
 
     ret = ioctl(vd->fd, VIDIOC_STREAMON, &type);
     if (ret < 0) {
-       printf("Unable to %s capture: %d.\n", "start", errno);
+       perror("Unable to start capture");
        return ret;
     }
     vd->isstreaming = 1;
@@ -449,7 +449,7 @@
 
     ret = ioctl(vd->fd, VIDIOC_STREAMOFF, &type);
     if (ret < 0) {
-       printf("Unable to %s capture: %d.\n", "stop", errno);
+       perror("Unable to stop capture");
        return ret;
     }
     vd->isstreaming = 0;
@@ -470,7 +470,7 @@
     vd->buf.memory = V4L2_MEMORY_MMAP;
     ret = ioctl(vd->fd, VIDIOC_DQBUF, &vd->buf);
     if (ret < 0) {
-       printf("Unable to dequeue buffer (%d).\n", errno);
+       perror("Unable to dequeue buffer");
        goto err;
     }
 
@@ -585,7 +585,7 @@
     }
     ret = ioctl(vd->fd, VIDIOC_QBUF, &vd->buf);
     if (ret < 0) {
-       printf("Unable to requeue buffer (%d).\n", errno);
+       perror("Unable to requeue buffer");
        goto err;
     }
 
@@ -618,7 +618,7 @@
 int err =0;
     queryctrl->id = control;
     if ((err= ioctl(vd->fd, VIDIOC_QUERYCTRL, queryctrl)) < 0) {
-       printf("ioctl querycontrol error %d \n",errno);
+       perror("ioctl querycontrol error");
     } else if (queryctrl->flags & V4L2_CTRL_FLAG_DISABLED) {
        printf("control %s disabled \n", (char *) queryctrl->name);
     } else if (queryctrl->flags & V4L2_CTRL_TYPE_BOOLEAN) {
@@ -948,7 +948,7 @@
        }
        printf("\n");
        if (ret != 0 && errno != EINVAL) {
-               printf("ERROR enumerating frame intervals: %d\n", errno);
+               perror("ERROR enumerating frame intervals");
                return errno;
        }
 
@@ -990,7 +990,7 @@
                fsize.index++;
        }
        if (ret != 0 && errno != EINVAL) {
-               printf("ERROR enumerating frame sizes: %d\n", errno);
+               perror("ERROR enumerating frame sizes");
                return errno;
        }
 
@@ -1016,7 +1016,7 @@
                        printf("  Unable to enumerate frame sizes.\n");
        }
        if (errno != EINVAL) {
-               printf("ERROR enumerating frame formats: %d\n", errno);
+               perror("ERROR enumerating frame formats");
                return errno;
        }
 
diff -ur luvcview-20070512/avilib.c luvcview-20070512-whitespace/avilib.c
--- luvcview-20070512/avilib.c  2006-09-20 17:47:36.000000000 +0200
+++ luvcview-20070512-whitespace/avilib.c       2008-03-16 19:37:43.000000000 
+0100
@@ -616,7 +616,7 @@
       readable in the most cases */
 
    idxerror = 0;
-   //   fprintf(stderr, "pos=%lu, index_len=%ld             \n", AVI->pos, 
AVI->n_idx*16);
+   //   fprintf(stderr, "pos=%lu, index_len=%ld\n", AVI->pos, AVI->n_idx*16);
    ret = avi_add_chunk(AVI, (unsigned char *)"idx1", (unsigned char 
*)AVI->idx, AVI->n_idx*16);
    hasIndex = (ret==0);
    //fprintf(stderr, "pos=%lu, index_len=%d\n", AVI->pos, hasIndex);
diff -ur luvcview-20070512/luvcview.c luvcview-20070512-whitespace/luvcview.c
--- luvcview-20070512/luvcview.c        2007-05-12 12:03:14.000000000 +0200
+++ luvcview-20070512-whitespace/luvcview.c     2008-03-16 19:37:43.000000000 
+0100
@@ -238,7 +238,7 @@
 
 
 
-    printf("luvcview version %s \n", version);
+    printf("luvcview version %s\n", version);
     for (i = 1; i < argc; i++) {
        /* skip bad arguments */
        if (argv[i] == NULL || *argv[i] == 0 || *argv[i] != '-') {
@@ -287,24 +287,24 @@
 
            width = strtoul(sizestring, &separateur, 10);
            if (*separateur != 'x') {
-               printf("Error in size use -s widthxheight \n");
+               printf("Error in size use -s widthxheight\n");
                exit(1);
            } else {
                ++separateur;
                height = strtoul(separateur, &separateur, 10);
                if (*separateur != 0)
-                   printf("hmm.. dont like that!! trying this height \n");
-               printf(" size width: %d height: %d \n", width, height);
+                   printf("hmm.. dont like that!! trying this height\n");
+               printf(" size width: %d height: %d\n", width, height);
            }
        }
        if (strcmp(argv[i], "-i") == 0){
          if (i + 1 >= argc) {
-           printf("No parameter specified with -i, aborting. \n");
+           printf("No parameter specified with -i, aborting.\n");
            exit(1);
          }
          fpsstring = strdup(argv[i + 1]);
          fps = strtoul(fpsstring, &separateur, 10);
-         printf(" interval: %d fps \n", fps);
+         printf(" interval: %d fps\n", fps);
        }
        if (strcmp(argv[i], "-S") == 0) {
            /* Enable raw stream capture from the start */
@@ -340,14 +340,14 @@
            readconfigfile = 1;
        }
        if (strcmp(argv[i], "-h") == 0) {
-           printf("usage: uvcview [-h -d -g -f -s -i -c -o -C -S -L -l -r] 
\n");
-           printf("-h  print this message \n");
+           printf("usage: uvcview [-h -d -g -f -s -i -c -o -C -S -L -l -r]\n");
+           printf("-h  print this message\n");
            printf("-d  /dev/videoX       use videoX device\n");
-           printf("-g  use read method for grab instead mmap \n");
-           printf("-w  disable SDL hardware accel. \n");
-           printf("-f  video format  default jpg  others options are yuv jpg 
\n");
-           printf("-i  fps           use specified frame interval \n");
-           printf("-s  widthxheight      use specified input size \n");
+           printf("-g  use read method for grab instead mmap\n");
+           printf("-w  disable SDL hardware accel.\n");
+           printf("-f  video format  default jpg  others options are yuv 
jpg\n");
+           printf("-i  fps           use specified frame interval\n");
+           printf("-s  widthxheight      use specified input size\n");
            printf("-c  enable raw frame capturing for the first frame\n");
            printf("-C  enable raw frame stream capturing from the start\n");
            printf("-S  enable raw stream capturing from the start\n");
@@ -487,7 +487,7 @@
        }
        lasttime = currtime;
        if (uvcGrab(videoIn) < 0) {
-           printf("Error grabbing \n");
+           printf("Error grabbing\n");
            break;
        }
 
@@ -540,7 +540,7 @@
     free(videoIn);
     destroyButt();
     freeLut();
-    printf(" Clean Up done Quit \n");
+    printf(" Clean Up done Quit\n");
     SDL_Quit();
 }
 
@@ -640,7 +640,7 @@
        case A_CONTRAST_UP:
                if ((value =
                     v4l2UpControl(videoIn, V4L2_CID_CONTRAST)) < 0)
-                   printf("Set Contrast up error \n");
+                   printf("Set Contrast up error\n");
            break;
        case A_SATURATION_UP:
                if ((value =
@@ -822,7 +822,7 @@
             if ((value = ioctl(videoIn->fd, VIDIOC_S_CTRL, &control)) < 0)
               printf("Set Auto Exposure on error\n");
             else
-              printf("Auto Exposure set to %d \n", control.value);
+              printf("Auto Exposure set to %d\n", control.value);
             break;
           case A_EXPOSURE_OFF:
             control.id    =V4L2_CID_EXPOSURE_AUTO;
@@ -830,7 +830,7 @@
             if ((value = ioctl(videoIn->fd, VIDIOC_S_CTRL, &control)) < 0)
               printf("Set Auto Exposure off error\n");
             else
-              printf("Auto Exposure set to %d \n", control.value);
+              printf("Auto Exposure set to %d\n", control.value);
             break;
           case A_BALANCE_UP:
             if ((value = v4l2UpControl(videoIn, 
V4L2_CID_WHITE_BALANCE_TEMPERATURE)) < 0)
@@ -846,7 +846,7 @@
             if ((value = ioctl(videoIn->fd, VIDIOC_S_CTRL, &control)) < 0)
               printf("Set Auto Balance on error\n");
             else
-              printf("Auto Balance set to %d \n", control.value);
+              printf("Auto Balance set to %d\n", control.value);
             break;
           case A_BALANCE_OFF:
             control.id    =V4L2_CID_WHITE_BALANCE_TEMPERATURE_AUTO;
@@ -854,14 +854,14 @@
             if ((value = ioctl(videoIn->fd, VIDIOC_S_CTRL, &control)) < 0)
               printf("Set Auto Balance off error\n");
             else
-              printf("Auto Balance set to %d \n", control.value);
+              printf("Auto Balance set to %d\n", control.value);
             break;
           case A_SAVE:
-          printf("Save controls \n");
+          printf("Save controls\n");
             save_controls(videoIn->fd);
             break;
           case A_LOAD:
-          printf("load controls \n");
+          printf("load controls\n");
             load_controls(videoIn->fd);
           break;
        default:
@@ -881,7 +881,7 @@
        
        }
        SDL_Delay(50);
-       //printf("fp/s %d \n",frmrate);
+       //printf("fp/s %d\n",frmrate);
     }                          //end main loop
 
        /* Close the stream capture file */
diff -ur luvcview-20070512/utils.c luvcview-20070512-whitespace/utils.c
--- luvcview-20070512/utils.c   2007-05-12 12:13:11.000000000 +0200
+++ luvcview-20070512-whitespace/utils.c        2008-03-16 19:37:43.000000000 
+0100
@@ -191,7 +191,7 @@
            return 0;
 
        case M_DQT:
-       //printf("find DQT \n");
+       //printf("find DQT\n");
            lq = getword();
            while (lq > 2) {
                pq = getbyte();
@@ -208,7 +208,7 @@
            break;
 
        case M_DHT:
-       //printf("find DHT \n");
+       //printf("find DHT\n");
            l = getword();
            while (l > 2) {
                int hufflen[16], k;
@@ -235,7 +235,7 @@
            break;
 
        case M_DRI:
-       printf("find DRI \n");
+       printf("find DRI\n");
            l = getword();
            info.dri = getword();
            break;
@@ -385,7 +385,7 @@
     if (i != 0 || j != 63 || m != 0) {
        printf("hmm FW error,not seq DCT ??\n");
     }
-   // printf("ext huffman table %d \n",isInitHuffman);
+   // printf("ext huffman table %d\n",isInitHuffman);
     if(!isInitHuffman) {
        if(huffman_init() < 0)
                return -ERR_BAD_TABLES;
@@ -1250,7 +1250,7 @@
 if(picture){
        Pyuv422torgb24(buf, picture, width, height);
 }else{
-       printf(" no room to take a picture \n");
+       printf(" no room to take a picture\n");
        return 0;
 }
 if(name){
diff -ur luvcview-20070512/v4l2uvc.c luvcview-20070512-whitespace/v4l2uvc.c
--- luvcview-20070512/v4l2uvc.c 2007-05-08 17:39:40.000000000 +0200
+++ luvcview-20070512-whitespace/v4l2uvc.c      2008-03-16 19:53:00.000000000 
+0100
@@ -39,7 +39,7 @@
        return -1;
        vd->videodevice = (char *) calloc(1, 16 * sizeof(char));
        snprintf(vd->videodevice, 12, "%s", device);
-    printf("video %s \n", vd->videodevice);
+    printf("video %s\n", vd->videodevice);
     if ((vd->fd = open(vd->videodevice, O_RDWR)) == -1) {
        perror("ERROR opening V4L interface \n");
        exit(1);
@@ -86,7 +86,7 @@
     vd->status = (char *) calloc(1, 100 * sizeof(char));
     vd->pictName = (char *) calloc(1, 80 * sizeof(char));
     snprintf(vd->videodevice, 12, "%s", device);
-    printf("video %s \n", vd->videodevice);
+    printf("video %s\n", vd->videodevice);
     vd->toggleAvi = 0;
     vd->avifile = NULL;
     vd->avifilename = avifilename;
@@ -108,7 +108,7 @@
     vd->bytesWritten = 0;
     vd->framesWritten = 0;
     if (init_v4l2(vd) < 0) {
-       printf(" Init v4L2 failed !! exit fatal \n");
+       printf(" Init v4L2 failed !! exit fatal\n");
        goto error;;
     }
     /* alloc a temp buffer to reconstruct the pict */
@@ -187,7 +187,7 @@
       control_s.id=queryctrl.id;
       ioctl(vd, VIDIOC_G_CTRL, &control_s);
       SDL_Delay(10);
-      printf (" index:%-10d name:%-32s type:%d min:%-5d max:%-5d step:%-5d 
def:%-5d now:%d \n",
+      printf (" index:%-10d name:%-32s type:%d min:%-5d max:%-5d step:%-5d 
def:%-5d now:%d\n",
               queryctrl.id, queryctrl.name, queryctrl.type, queryctrl.minimum,
               queryctrl.maximum, queryctrl.step, queryctrl.default_value, 
control_s.value);
       if (queryctrl.type == V4L2_CTRL_TYPE_MENU)
@@ -210,7 +210,7 @@
       control_s.id=queryctrl.id;
       ioctl(vd, VIDIOC_G_CTRL, &control_s);
       SDL_Delay(20);
-      printf (" index:%-10d name:%-32s type:%d min:%-5d max:%-5d step:%-5d 
def:%-5d now:%d \n",
+      printf (" index:%-10d name:%-32s type:%d min:%-5d max:%-5d step:%-5d 
def:%-5d now:%d\n",
               queryctrl.id, queryctrl.name, queryctrl.type, queryctrl.minimum,
               queryctrl.maximum, queryctrl.step, queryctrl.default_value, 
control_s.value);
       if (queryctrl.type == V4L2_CTRL_TYPE_MENU)
@@ -295,16 +295,16 @@
     printf( "configfile luvcview.cfg open failed, errno = %d (%s)\n", errno, 
strerror( errno));
   }
   else {
-    printf("loading controls from luvcview.cfg \n");
+    printf("loading controls from luvcview.cfg\n");
     char buffer[512]; 
     fgets(buffer, sizeof(buffer), configfile);
     while (NULL !=fgets(buffer, sizeof(buffer), configfile) )
       {
         sscanf(buffer, "%i%i", &control.id, &control.value);
         if (ioctl(vd, VIDIOC_S_CTRL, &control))
-          printf("ERROR id:%d val:%d \n", control.id, control.value);
+          printf("ERROR id:%d val:%d\n", control.id, control.value);
         else
-          printf("OK    id:%d val:%d \n", control.id, control.value);
+          printf("OK    id:%d val:%d\n", control.id, control.value);
         SDL_Delay(20);
       }   
     fclose(configfile);
@@ -358,7 +358,7 @@
     }
     if ((vd->fmt.fmt.pix.width != vd->width) ||
        (vd->fmt.fmt.pix.height != vd->height)) {
-       printf(" format asked unavailable get width %d height %d \n",
+       printf(" format asked unavailable get width %d height %d\n",
               vd->fmt.fmt.pix.width, vd->fmt.fmt.pix.height);
        vd->width = vd->fmt.fmt.pix.width;
        vd->height = vd->fmt.fmt.pix.height;
@@ -569,7 +569,7 @@
            goto err;
        }
        if (debug)
-           printf("bytes in used %d \n", vd->buf.bytesused);
+           printf("bytes in used %d\n", vd->buf.bytesused);
        break;
     case V4L2_PIX_FMT_YUYV:
        if (vd->buf.bytesused > vd->framesizeIn)
@@ -620,13 +620,13 @@
     if ((err= ioctl(vd->fd, VIDIOC_QUERYCTRL, queryctrl)) < 0) {
        printf("ioctl querycontrol error %d \n",errno);
     } else if (queryctrl->flags & V4L2_CTRL_FLAG_DISABLED) {
-       printf("control %s disabled \n", (char *) queryctrl->name);
+       printf("control %s disabled\n", (char *) queryctrl->name);
     } else if (queryctrl->flags & V4L2_CTRL_TYPE_BOOLEAN) {
        return 1;
     } else if (queryctrl->type & V4L2_CTRL_TYPE_INTEGER) {
        return 0;
     } else {
-       printf("contol %s unsupported  \n", (char *) queryctrl->name);
+       printf("contol %s unsupported\n", (char *) queryctrl->name);
     }
     return -1;
 }
@@ -683,7 +683,7 @@
     val_def = queryctrl.default_value;
     current = v4l2GetControl(vd, control);
     current += step;
-    printf("max %d, min %d, step %d, default %d ,current %d 
\n",max,min,step,val_def,current);
+    printf("max %d, min %d, step %d, default %d ,current 
%d\n",max,min,step,val_def,current);
     if (current <= max) {
        control_s.id = control;
        control_s.value = current;
@@ -693,7 +693,7 @@
        }            
         printf ("Control name:%s set to value:%d\n", queryctrl.name, 
control_s.value);
     } else {
-      printf ("Control name:%s already has max value:%d \n", queryctrl.name, 
max); 
+      printf ("Control name:%s already has max value:%d\n", queryctrl.name, 
max); 
     }
      return control_s.value;
 }
@@ -711,7 +711,7 @@
     val_def = queryctrl.default_value;
     current = v4l2GetControl(vd, control);
     current -= step;
-    printf("max %d, min %d, step %d, default %d ,current %d 
\n",max,min,step,val_def,current);
+    printf("max %d, min %d, step %d, default %d ,current 
%d\n",max,min,step,val_def,current);
     if (current >= min) {
        control_s.id = control;
        control_s.value = current;
@@ -722,7 +722,7 @@
     printf ("Control name:%s set to value:%d\n", queryctrl.name, 
control_s.value);
     }
     else {
-      printf ("Control name:%s already has min value:%d \n", queryctrl.name, 
min); 
+      printf ("Control name:%s already has min value:%d\n", queryctrl.name, 
min); 
     }
     return control_s.value;
 }
diff -ur luvcview-20070512/Makefile luvcview-20070512-version/Makefile
--- luvcview-20070512/Makefile  2007-05-12 11:57:17.000000000 +0200
+++ luvcview-20070512-version/Makefile  2008-02-24 01:23:02.000000000 +0100
@@ -12,7 +12,7 @@
 SDLLIBS = $(shell sdl-config --libs) 
 SDLFLAGS = $(shell sdl-config --cflags)
 #LIBX11FLAGS= -I/usr/X11R6/include -L/usr/X11R6/lib
-VERSION = 0.2.1
+VERSION = 0.2.2
 
 #WARNINGS = -Wall \
 #           -Wundef -Wpointer-arith -Wbad-function-cast \
_______________________________________________
Linux-uvc-devel mailing list
[email protected]
https://lists.berlios.de/mailman/listinfo/linux-uvc-devel

Reply via email to