[libcamera-devel,v2,15/16] cam: Add --info option to print information about stream(s)

Message ID 20190612004359.15772-16-niklas.soderlund@ragnatech.se
State Superseded
Headers show
Series
  • libcamera: Add support for format information and validation
Related show

Commit Message

Niklas Söderlund June 12, 2019, 12:43 a.m. UTC
Add a new option to the cam tool that prints information about the
configuration supplied by the user. If the option is specified,
information about the configuration is printed after the configuration
has been verified possibly adjusted by the camera.

Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
---
 src/cam/info.cpp    | 37 +++++++++++++++++++++++++++++++++++++
 src/cam/info.h      | 14 ++++++++++++++
 src/cam/main.cpp    |  6 ++++++
 src/cam/main.h      |  1 +
 src/cam/meson.build |  1 +
 5 files changed, 59 insertions(+)
 create mode 100644 src/cam/info.cpp
 create mode 100644 src/cam/info.h

Comments

Jacopo Mondi June 13, 2019, 5:09 p.m. UTC | #1
Hi Niklas,

On Wed, Jun 12, 2019 at 02:43:58AM +0200, Niklas Söderlund wrote:
> Add a new option to the cam tool that prints information about the
> configuration supplied by the user. If the option is specified,
> information about the configuration is printed after the configuration
> has been verified possibly adjusted by the camera.
>

Sorry, I don't get it, how is cam supposed to be launched to print the
stream informations?

Just running
$ cam -I
segfaults for me...

I tried passing a few arguments, like some permutation of the
following:
$ ./src/cam/cam -I width=1920,height=1080,role=viewfinder
but I still get a segfault...

What am I doing wrong?

> Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
> ---
>  src/cam/info.cpp    | 37 +++++++++++++++++++++++++++++++++++++
>  src/cam/info.h      | 14 ++++++++++++++
>  src/cam/main.cpp    |  6 ++++++
>  src/cam/main.h      |  1 +
>  src/cam/meson.build |  1 +
>  5 files changed, 59 insertions(+)
>  create mode 100644 src/cam/info.cpp
>  create mode 100644 src/cam/info.h
>
> diff --git a/src/cam/info.cpp b/src/cam/info.cpp
> new file mode 100644
> index 0000000000000000..fe32ceb614e85794
> --- /dev/null
> +++ b/src/cam/info.cpp
> @@ -0,0 +1,37 @@
> +/* SPDX-License-Identifier: GPL-2.0-or-later */
> +/*
> + * Copyright (C) 2019, Google Inc.
> + *
> + * info.cpp - Display stream information
> + */
> +
> +#include <iomanip>
> +#include <iostream>
> +
> +#include "info.h"
> +
> +using namespace libcamera;
> +
> +int infoConfiguration(const libcamera::CameraConfiguration &config)
> +{
> +	unsigned int index = 0;
> +	for (const StreamConfiguration &cfg : config) {
> +		std::cout << index << ": " << cfg.toString() << std::endl;
> +
> +		const StreamFormats &formats = cfg.formats();
> +		for (unsigned int pixelformat : formats.pixelformats()) {
> +			std::cout << " * Pixelformat: 0x" << std::hex
> +				  << std::setw(8) << pixelformat << " "
> +				  << formats.range(pixelformat).toString()
> +				  << std::endl;
> +
> +			for (const Size &size : formats.sizes(pixelformat))
> +				std::cout << "  - " << size.toString()
> +					  << std::endl;
> +		}
> +
> +		index++;
> +	}
> +
> +	return 0;
> +}
> diff --git a/src/cam/info.h b/src/cam/info.h
> new file mode 100644
> index 0000000000000000..d4b4fc7e73d261b6
> --- /dev/null
> +++ b/src/cam/info.h
> @@ -0,0 +1,14 @@
> +/* SPDX-License-Identifier: GPL-2.0-or-later */
> +/*
> + * Copyright (C) 2019, Google Inc.
> + *
> + * info.h - Displat stream information

display

> + */
> +#ifndef __CAM_INFO_H__
> +#define __CAM_INFO_H__
> +
> +#include <libcamera/camera.h>
> +
> +int infoConfiguration(const libcamera::CameraConfiguration &config);
> +
> +#endif /* __CAM_INFO_H__ */
> diff --git a/src/cam/main.cpp b/src/cam/main.cpp
> index 191fef3a3c8a2b64..c0a5601316d1959d 100644
> --- a/src/cam/main.cpp
> +++ b/src/cam/main.cpp
> @@ -13,6 +13,7 @@
>
>  #include "capture.h"
>  #include "event_loop.h"
> +#include "info.h"
>  #include "main.h"
>  #include "options.h"
>
> @@ -162,6 +163,8 @@ int CamApp::parseOptions(int argc, char *argv[])
>  			 "Set configuration of a camera stream", "stream", true);
>  	parser.addOption(OptHelp, OptionNone, "Display this help message",
>  			 "help");
> +	parser.addOption(OptInfo, OptionNone,
> +			 "Display information about stream(s)", "info");
>  	parser.addOption(OptList, OptionNone, "List all cameras", "list");
>
>  	options_ = parser.parse(argc, argv);
> @@ -259,6 +262,9 @@ int CamApp::run()
>  			std::cout << "- " << cam->name() << std::endl;
>  	}
>
> +	if (options_.isSet(OptInfo))
> +		infoConfiguration(*config_.get());
> +
>  	if (options_.isSet(OptCapture)) {
>  		Capture capture(camera_.get(), config_.get());
>  		return capture.run(loop_, options_);
> diff --git a/src/cam/main.h b/src/cam/main.h
> index fff81b1f6c860b57..0997476bb335e446 100644
> --- a/src/cam/main.h
> +++ b/src/cam/main.h
> @@ -12,6 +12,7 @@ enum {
>  	OptCapture = 'C',
>  	OptFile = 'F',
>  	OptHelp = 'h',
> +	OptInfo = 'I',
>  	OptList = 'l',
>  	OptStream = 's',
>  };
> diff --git a/src/cam/meson.build b/src/cam/meson.build
> index 478346c59590631d..ee5b28421e4c1235 100644
> --- a/src/cam/meson.build
> +++ b/src/cam/meson.build
> @@ -2,6 +2,7 @@ cam_sources = files([
>      'buffer_writer.cpp',
>      'capture.cpp',
>      'event_loop.cpp',
> +    'info.cpp',
>      'main.cpp',
>      'options.cpp',
>  ])
> --
> 2.21.0
>
> _______________________________________________
> libcamera-devel mailing list
> libcamera-devel@lists.libcamera.org
> https://lists.libcamera.org/listinfo/libcamera-devel
Niklas Söderlund June 16, 2019, 1:19 p.m. UTC | #2
Hi Jacopo,

Thanks for your feedback and great catch.

On 2019-06-13 19:09:39 +0200, Jacopo Mondi wrote:
> Hi Niklas,
> 
> On Wed, Jun 12, 2019 at 02:43:58AM +0200, Niklas Söderlund wrote:
> > Add a new option to the cam tool that prints information about the
> > configuration supplied by the user. If the option is specified,
> > information about the configuration is printed after the configuration
> > has been verified possibly adjusted by the camera.
> >
> 
> Sorry, I don't get it, how is cam supposed to be launched to print the
> stream informations?
> 
> Just running
> $ cam -I
> segfaults for me...
> 
> I tried passing a few arguments, like some permutation of the
> following:
> $ ./src/cam/cam -I width=1920,height=1080,role=viewfinder
> but I still get a segfault...

The idea is to print information about a camera

    $ ./cam -c "Venus USB2.0 Camera: Venus USB2" -I
    [123:40:14.524077360]   ERR IPAManager ipa_manager.cpp:96 Invalid path /usr/local/lib/libcamera for IPA modules: No such file or directory
    [123:40:14.524167583]  WARN VIMC vimc.cpp:258 no matching IPA found
    Using camera Venus USB2.0 Camera: Venus USB2
    0: 1600x1200-0x47504a4d
     * Pixelformat: 0x47504a4d (160x120)-(1600x1200)/(+0,+0)
      - 160x120
      - 176x144
      - 320x240
      - 352x288
      - 640x480
      - 800x600
      - 1280x960
      - 1280x1024
      - 1600x1200
     * Pixelformat: 0x56595559 (160x120)-(1600x1200)/(+0,+0)
      - 160x120
      - 176x144
      - 320x240
      - 352x288
      - 640x480
      - 800x600
      - 1280x960
      - 1280x1024
      - 1600x120

But you finding this segfault was really nice, I will fix it for v3.

> 
> What am I doing wrong?
> 
> > Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
> > ---
> >  src/cam/info.cpp    | 37 +++++++++++++++++++++++++++++++++++++
> >  src/cam/info.h      | 14 ++++++++++++++
> >  src/cam/main.cpp    |  6 ++++++
> >  src/cam/main.h      |  1 +
> >  src/cam/meson.build |  1 +
> >  5 files changed, 59 insertions(+)
> >  create mode 100644 src/cam/info.cpp
> >  create mode 100644 src/cam/info.h
> >
> > diff --git a/src/cam/info.cpp b/src/cam/info.cpp
> > new file mode 100644
> > index 0000000000000000..fe32ceb614e85794
> > --- /dev/null
> > +++ b/src/cam/info.cpp
> > @@ -0,0 +1,37 @@
> > +/* SPDX-License-Identifier: GPL-2.0-or-later */
> > +/*
> > + * Copyright (C) 2019, Google Inc.
> > + *
> > + * info.cpp - Display stream information
> > + */
> > +
> > +#include <iomanip>
> > +#include <iostream>
> > +
> > +#include "info.h"
> > +
> > +using namespace libcamera;
> > +
> > +int infoConfiguration(const libcamera::CameraConfiguration &config)
> > +{
> > +	unsigned int index = 0;
> > +	for (const StreamConfiguration &cfg : config) {
> > +		std::cout << index << ": " << cfg.toString() << std::endl;
> > +
> > +		const StreamFormats &formats = cfg.formats();
> > +		for (unsigned int pixelformat : formats.pixelformats()) {
> > +			std::cout << " * Pixelformat: 0x" << std::hex
> > +				  << std::setw(8) << pixelformat << " "
> > +				  << formats.range(pixelformat).toString()
> > +				  << std::endl;
> > +
> > +			for (const Size &size : formats.sizes(pixelformat))
> > +				std::cout << "  - " << size.toString()
> > +					  << std::endl;
> > +		}
> > +
> > +		index++;
> > +	}
> > +
> > +	return 0;
> > +}
> > diff --git a/src/cam/info.h b/src/cam/info.h
> > new file mode 100644
> > index 0000000000000000..d4b4fc7e73d261b6
> > --- /dev/null
> > +++ b/src/cam/info.h
> > @@ -0,0 +1,14 @@
> > +/* SPDX-License-Identifier: GPL-2.0-or-later */
> > +/*
> > + * Copyright (C) 2019, Google Inc.
> > + *
> > + * info.h - Displat stream information
> 
> display
> 
> > + */
> > +#ifndef __CAM_INFO_H__
> > +#define __CAM_INFO_H__
> > +
> > +#include <libcamera/camera.h>
> > +
> > +int infoConfiguration(const libcamera::CameraConfiguration &config);
> > +
> > +#endif /* __CAM_INFO_H__ */
> > diff --git a/src/cam/main.cpp b/src/cam/main.cpp
> > index 191fef3a3c8a2b64..c0a5601316d1959d 100644
> > --- a/src/cam/main.cpp
> > +++ b/src/cam/main.cpp
> > @@ -13,6 +13,7 @@
> >
> >  #include "capture.h"
> >  #include "event_loop.h"
> > +#include "info.h"
> >  #include "main.h"
> >  #include "options.h"
> >
> > @@ -162,6 +163,8 @@ int CamApp::parseOptions(int argc, char *argv[])
> >  			 "Set configuration of a camera stream", "stream", true);
> >  	parser.addOption(OptHelp, OptionNone, "Display this help message",
> >  			 "help");
> > +	parser.addOption(OptInfo, OptionNone,
> > +			 "Display information about stream(s)", "info");
> >  	parser.addOption(OptList, OptionNone, "List all cameras", "list");
> >
> >  	options_ = parser.parse(argc, argv);
> > @@ -259,6 +262,9 @@ int CamApp::run()
> >  			std::cout << "- " << cam->name() << std::endl;
> >  	}
> >
> > +	if (options_.isSet(OptInfo))
> > +		infoConfiguration(*config_.get());
> > +
> >  	if (options_.isSet(OptCapture)) {
> >  		Capture capture(camera_.get(), config_.get());
> >  		return capture.run(loop_, options_);
> > diff --git a/src/cam/main.h b/src/cam/main.h
> > index fff81b1f6c860b57..0997476bb335e446 100644
> > --- a/src/cam/main.h
> > +++ b/src/cam/main.h
> > @@ -12,6 +12,7 @@ enum {
> >  	OptCapture = 'C',
> >  	OptFile = 'F',
> >  	OptHelp = 'h',
> > +	OptInfo = 'I',
> >  	OptList = 'l',
> >  	OptStream = 's',
> >  };
> > diff --git a/src/cam/meson.build b/src/cam/meson.build
> > index 478346c59590631d..ee5b28421e4c1235 100644
> > --- a/src/cam/meson.build
> > +++ b/src/cam/meson.build
> > @@ -2,6 +2,7 @@ cam_sources = files([
> >      'buffer_writer.cpp',
> >      'capture.cpp',
> >      'event_loop.cpp',
> > +    'info.cpp',
> >      'main.cpp',
> >      'options.cpp',
> >  ])
> > --
> > 2.21.0
> >
> > _______________________________________________
> > libcamera-devel mailing list
> > libcamera-devel@lists.libcamera.org
> > https://lists.libcamera.org/listinfo/libcamera-devel

Patch

diff --git a/src/cam/info.cpp b/src/cam/info.cpp
new file mode 100644
index 0000000000000000..fe32ceb614e85794
--- /dev/null
+++ b/src/cam/info.cpp
@@ -0,0 +1,37 @@ 
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/*
+ * Copyright (C) 2019, Google Inc.
+ *
+ * info.cpp - Display stream information
+ */
+
+#include <iomanip>
+#include <iostream>
+
+#include "info.h"
+
+using namespace libcamera;
+
+int infoConfiguration(const libcamera::CameraConfiguration &config)
+{
+	unsigned int index = 0;
+	for (const StreamConfiguration &cfg : config) {
+		std::cout << index << ": " << cfg.toString() << std::endl;
+
+		const StreamFormats &formats = cfg.formats();
+		for (unsigned int pixelformat : formats.pixelformats()) {
+			std::cout << " * Pixelformat: 0x" << std::hex
+				  << std::setw(8) << pixelformat << " "
+				  << formats.range(pixelformat).toString()
+				  << std::endl;
+
+			for (const Size &size : formats.sizes(pixelformat))
+				std::cout << "  - " << size.toString()
+					  << std::endl;
+		}
+
+		index++;
+	}
+
+	return 0;
+}
diff --git a/src/cam/info.h b/src/cam/info.h
new file mode 100644
index 0000000000000000..d4b4fc7e73d261b6
--- /dev/null
+++ b/src/cam/info.h
@@ -0,0 +1,14 @@ 
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/*
+ * Copyright (C) 2019, Google Inc.
+ *
+ * info.h - Displat stream information
+ */
+#ifndef __CAM_INFO_H__
+#define __CAM_INFO_H__
+
+#include <libcamera/camera.h>
+
+int infoConfiguration(const libcamera::CameraConfiguration &config);
+
+#endif /* __CAM_INFO_H__ */
diff --git a/src/cam/main.cpp b/src/cam/main.cpp
index 191fef3a3c8a2b64..c0a5601316d1959d 100644
--- a/src/cam/main.cpp
+++ b/src/cam/main.cpp
@@ -13,6 +13,7 @@ 
 
 #include "capture.h"
 #include "event_loop.h"
+#include "info.h"
 #include "main.h"
 #include "options.h"
 
@@ -162,6 +163,8 @@  int CamApp::parseOptions(int argc, char *argv[])
 			 "Set configuration of a camera stream", "stream", true);
 	parser.addOption(OptHelp, OptionNone, "Display this help message",
 			 "help");
+	parser.addOption(OptInfo, OptionNone,
+			 "Display information about stream(s)", "info");
 	parser.addOption(OptList, OptionNone, "List all cameras", "list");
 
 	options_ = parser.parse(argc, argv);
@@ -259,6 +262,9 @@  int CamApp::run()
 			std::cout << "- " << cam->name() << std::endl;
 	}
 
+	if (options_.isSet(OptInfo))
+		infoConfiguration(*config_.get());
+
 	if (options_.isSet(OptCapture)) {
 		Capture capture(camera_.get(), config_.get());
 		return capture.run(loop_, options_);
diff --git a/src/cam/main.h b/src/cam/main.h
index fff81b1f6c860b57..0997476bb335e446 100644
--- a/src/cam/main.h
+++ b/src/cam/main.h
@@ -12,6 +12,7 @@  enum {
 	OptCapture = 'C',
 	OptFile = 'F',
 	OptHelp = 'h',
+	OptInfo = 'I',
 	OptList = 'l',
 	OptStream = 's',
 };
diff --git a/src/cam/meson.build b/src/cam/meson.build
index 478346c59590631d..ee5b28421e4c1235 100644
--- a/src/cam/meson.build
+++ b/src/cam/meson.build
@@ -2,6 +2,7 @@  cam_sources = files([
     'buffer_writer.cpp',
     'capture.cpp',
     'event_loop.cpp',
+    'info.cpp',
     'main.cpp',
     'options.cpp',
 ])