Marcus Glocker said:
> Sometimes I just would like to query a video device for it's properties
> without starting a stream to see what's supported and evt. make a
> decision afterwards how to start the stream.
> 
> This diff adds the 'q' option to video(1) for this purpose to just
> query the device, display the results, and quit.
> 
> Anyone else find this useful?

I had this in my plans.

Tested on amd64 with Ricoh laptop camera (5986:03b4).  OK czarkoff@.

> Index: video.1
> ===================================================================
> RCS file: /cvs/xenocara/app/video/video.1,v
> retrieving revision 1.12
> diff -u -p -u -p -r1.12 video.1
> --- video.1   31 May 2016 06:47:12 -0000      1.12
> +++ video.1   3 Jun 2016 12:21:59 -0000
> @@ -25,7 +25,7 @@
>  .Sh SYNOPSIS
>  .Nm
>  .Bk -words
> -.Op Fl \&gRv
> +.Op Fl \&gqRv
>  .Op Fl a Ar adaptor
>  .Op Fl e Ar encoding
>  .Op Fl f Ar file
> @@ -133,6 +133,9 @@ If
>  is
>  .Ql - ,
>  frames will be written to standard output.
> +.It Fl q
> +Query for encodings, frame sizes/rates, and controls.
> +Display them and quit.
>  .It Fl R
>  Disable frame rate adjustment.
>  .It Fl r Ar rate
> Index: video.c
> ===================================================================
> RCS file: /cvs/xenocara/app/video/video.c,v
> retrieving revision 1.16
> diff -u -p -u -p -r1.16 video.c
> --- video.c   2 Jun 2016 08:53:32 -0000       1.16
> +++ video.c   3 Jun 2016 12:21:59 -0000
> @@ -169,6 +169,7 @@ struct video {
>  #define M_OUT_XV     0x2
>  #define M_IN_FILE    0x4
>  #define M_OUT_FILE   0x8
> +#define M_QUERY              0x10
>       int              mode;
>       int              verbose;
>  };
> @@ -186,6 +187,7 @@ int dev_get_sizes(struct video *);
>  int dev_get_rates(struct video *);
>  int dev_get_ctrls(struct video *);
>  void dev_dump_info(struct video *);
> +void dev_dump_query(struct video *);
>  int dev_init(struct video *);
>  void dev_set_ctrl(struct video *, int, int);
>  void dev_reset_ctrls(struct video *);
> @@ -213,7 +215,7 @@ extern char *__progname;
>  void
>  usage(void)
>  {
> -     fprintf(stderr, "usage: %s [-gRv] "
> +     fprintf(stderr, "usage: %s [-gqRv] "
>           "[-a adaptor] [-e encoding] [-f file] [-i input] [-O output]\n"
>           "       %*s [-o output] [-r rate] [-s size]\n", __progname,
>           (int)strlen(__progname), "");
> @@ -1024,6 +1026,24 @@ dev_dump_info(struct video *vid)
>       fprintf(stderr, "\n");
>  }
>  
> +void
> +dev_dump_query(struct video *vid)
> +{
> +     if (!dev_check_caps(vid))
> +             return;
> +     if (!dev_get_encs(vid))
> +             return;
> +     if (!choose_enc(vid))
> +             return;
> +     if (!dev_get_sizes(vid))
> +             return;
> +     if (!dev_get_rates(vid))
> +             return;
> +     if (!dev_get_ctrls(vid))
> +             return;
> +     dev_dump_info(vid);
> +}
> +
>  int
>  dev_init(struct video *vid)
>  {
> @@ -1757,7 +1777,7 @@ main(int argc, char *argv[])
>       vid.mmap_on = 1; /* mmap method is default */
>       wout = 1;
>  
> -     while ((ch = getopt(argc, argv, "gvRa:e:f:i:O:o:r:s:")) != -1) {
> +     while ((ch = getopt(argc, argv, "gqRva:e:f:i:O:o:r:s:")) != -1) {
>               switch (ch) {
>               case 'a':
>                       x->cur_adap = strtonum(optarg, 0, 4, &errstr);
> @@ -1802,6 +1822,10 @@ main(int argc, char *argv[])
>                                   optarg);
>                       }
>                       break;
> +             case 'q':
> +                     vid.mode |= M_QUERY;
> +                     vid.mode &= ~M_OUT_XV;
> +                     break;
>               case 'R':
>                       vid.nofps = 1;
>                       break;
> @@ -1831,6 +1855,11 @@ main(int argc, char *argv[])
>       }
>       argc -= optind;
>       argv += optind;
> +
> +     if (vid.mode & M_QUERY) {
> +             dev_dump_query(&vid);
> +             cleanup(&vid, 0);
> +     }
>  
>       if (vid.fps == 0)
>               vid.nofps = 1;
> 

-- 
Dmitrij D. Czarkoff

Reply via email to