Commit graph

5620 commits

Author SHA1 Message Date
Niklas Söderlund
8b27416267 cam: Add option to write raw frames to disk
Use the helper BufferWriter to optionally write frames to disk as they
are captured.

Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2019-02-06 08:03:03 +02:00
Niklas Söderlund
46ca8eeca0 cam: Add BufferWriter helper
Add a simpler helper to allow the cam application to write raw captured
frames to disk.

Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2019-02-06 08:03:03 +02:00
Niklas Söderlund
dbe7a28377 cam: Add capture operation
Add an option to capture frames from a camera and keep it running until
the user terminates by sending SIGINT.

Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2019-02-06 08:03:03 +02:00
Jacopo Mondi
edfdace1d5 libcamera: pipeline: ipu3: Implement capture support
Replace the buffer allocation, capture start/stop and request queue
stubs with real implementations.

Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2019-02-06 08:03:03 +02:00
Jacopo Mondi
7da6b95283 libcamera: pipeline: ipu3: Create video devices and subdevices
Create the video devices and subdevices associated with an IPU3 camera.
While at there, move the IPU3 pipeline handler class definition and the
associated IPU3CameraData to a separate header as the class has now
grown enough.

Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2019-02-06 08:03:03 +02:00
Niklas Söderlund
8cbe8fe650 libcamera: pipeline: vimc: Implement capture support
Replace the buffer allocation, capture start/stop and request queue
stubs with real implementations.

Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2019-02-06 08:03:03 +02:00
Niklas Söderlund
bbbf76a6c5 libcamera: pipeline: vimc: Set a default format
Pick a default format for the one stream in a vimc camera. This is
just a starting point to define a good default format for the vimc
camera, and is expected to evolve over time as the capabilities of the
library grows.

Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2019-02-06 08:03:03 +02:00
Kieran Bingham
17ae772e8d libcamera: pipeline: uvcvideo: Implement capture support
Replace the buffer allocation, capture start/stop and request queue
stubs with real implementations.

Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2019-02-06 08:03:03 +02:00
Niklas Söderlund
bd38112b77 libcamera: camera: Extend the interface to support capture
In order to support capture, the camera needs methods to allocate and
free buffers, to start and stop the capture and to queue requests.
Define those interfaces in the Camera class and implement them to call
the corresponding pipeline handler methods.

Once a camera is started the pipeline handler of the camera will begin
processing requests queued to the camera by the application until it
gets stopped.

Once a request is created it can be queued to the camera and the
application will be notified asynchronously once the request is
completed and be able to process all the buffers involved in the
request.

At this point the request objects don't support controls. This will be
extended in the future.

Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2019-02-06 07:41:51 +02:00
Niklas Söderlund
98edf29e01 libcamera: camera: Cache the stream configuration in the stream object
The API towards the application and pipeline handler can be simplified
if the camera caches which streams have been selected and their
respective configuration.

Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2019-02-06 07:41:51 +02:00
Niklas Söderlund
31bb25ae8d libcamera: camera: Add helper to check for exclusive access
Some operations on the camera requires the application to have exclusive
access to the camera. To help check for this in these operations add a
helper.

Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2019-02-06 07:41:51 +02:00
Niklas Söderlund
5239f6e656 libcamera: pipeline_handler: Extend the interface to support capture
In order to support capture, the pipeline handler needs methods to
allocate and free buffers, to start and stop the capture and to queue
requests. Define those interfaces in the PipelineHandler class and
implement them as stubs in the existing pipeline handlers.

This initial implementation only considers the allocation of new
buffers. Future work would need to expand this to also cover importing
buffers from an external source.

Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2019-02-06 07:41:51 +02:00
Jacopo Mondi
5aef825764 libcamera: Provide a Request object
Implement a Request object used by applications to queue image capture
requests to a camera.

Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
2019-02-06 07:41:51 +02:00
Niklas Söderlund
1d7b6297f2 libcamera: stream: Add stream configuration to the stream object
Add a cache of the active stream configuration to the stream object.
This cache is to be updated from the Camera object and can be accessed
read only from both the application and pipeline handlers.

Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2019-02-06 07:41:51 +02:00
Kieran Bingham
1b7051b492 libcamera: stream: Construct a stream
Construct a stream object with a default internal pool.

Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
2019-02-06 07:41:51 +02:00
Jacopo Mondi
468176fa07 libcamera: Add V4L2Subdevice
Add V4L2Subdevice class that provides an interface to interact with
V4L2 defined sub-devices.

Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2019-02-06 07:41:50 +02:00
Jacopo Mondi
8dbc203bb2 libcamera: Add geometry.h
Add geometry-related definitions in the geometry.h internal header.

Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2019-02-06 07:41:48 +02:00
Jacopo Mondi
8628b1e560 libcamera: v4l2_device: Add comments to method parameters
Add missing parameter documentation for set and get format methods.

Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2019-02-06 07:41:39 +02:00
Niklas Söderlund
e94e52c0cb libcamera: v4l2_device: Update dequeued buffer information
Copy the information from the struct v4l2_buffer when dequeueing the
buffer as applications need this information to make sense of the
captured data.

Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2019-02-06 06:49:45 +02:00
Kieran Bingham
ba4dfa7471 test: v4l2_device: Provide asynchronous capture test
Utilise the event_dispatcher to create a default event loop, and process
asynchronous buffer receive events.

If no frames are captured in 5 seconds, the test will fail.
It will also fail if less than 30 frames have been captured in the same
timeout period.

Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
2019-02-06 06:49:43 +02:00
Kieran Bingham
d2046d863b test: v4l2_device: Add StreamOn/StreamOff test
Provide a small test to exercise the streamOn() and streamOff() calls.
8 buffers are requested locally.

Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
2019-02-06 06:49:41 +02:00
Kieran Bingham
374673f84a libcamera: v4l2_device: Implement stream{On,Off}
Support starting and stopping a stream on a V4L2 device. Buffers must be
queued before the stream is started.

Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
2019-02-06 06:49:38 +02:00
Kieran Bingham
dffbde33b8 libcamera: v4l2_device: Implement queue/dequeue operations
Provide queueBuffer() and dequeueBuffer() methods to interact with the
V4L2Device.

Buffers will be directly referenced from the bufferPool of the
V4L2Device based on the index in the pool.

The V4L2Device is now opened in non-blocking mode in order to avoid
blocking the dequeueBuffer() method. A signal is emitted when a buffer
is ready and has been dequeued.

Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
2019-02-06 06:49:35 +02:00
Kieran Bingham
2843f951d5 test: v4l2_device: Add request_buffers test
Add a utility to the test suite to request and allocate buffers from
a V4L2Device to ensure it functions correctly.

Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
2019-02-06 06:49:31 +02:00
Kieran Bingham
771befc6dc libcamera: v4l2_device: Request buffers from the device
Provide an exportBuffers() function which allocates buffers with the MMAP
method, exports them using the dmabuf API and populates the given BufferPool.

Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
2019-02-06 06:49:29 +02:00
Kieran Bingham
93ec63b867 test: v4l2_device: Use DeviceEnumerator to find a UVCVideo
Utilise the existing DeviceEnumerator system to identify a suitable
V4L2Device for testing.

Specifically target these tests at a uvcvideo driver based device as a known
supported target.

Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
2019-02-06 06:49:25 +02:00
Kieran Bingham
83148ce8be libcamera: Add Buffer Management
Provide classes that represent frame buffers and pools of frame buffers.

An image within the system may use one or more Plane objects to track each
plane in the case of multi-planar image formats. The Buffer class manages all
of the data required to render or interpret the raw image data.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
2019-02-06 06:49:19 +02:00
Jacopo Mondi
ccf7464a6e libcamera: v4l2_device: Improve documentation
Improve the V4L2DeviceFormat documentation as suggested during patches
review.

Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
2019-02-05 14:08:12 +01:00
Jacopo Mondi
cbbc315fe9 libcamera: v4l2_device: s_format: Return the device format
Return the device format actually applied to the device on setFormat().

Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
2019-02-05 14:08:03 +01:00
Jacopo Mondi
f7e75d9e70 libcamera: v4l2_device: Construct from MediaEntity*
The V4L2Device constructor wants a "const MediaEntity &", while
entities are usually retrieved by pointer before being used to construct
a V4L2Device. Change the constructor argument to "const MediaEntity *".

Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
2019-02-05 14:03:16 +01:00
Niklas Söderlund
dd45866ea4 libcamera: pipeline: uvcvideo: set a default format
Pick a default format for the UVC one stream in a UVC camera. This is
just a starting point to define a good default format for the UVC camera
it's expected to evolve over time as the capabilities of the library
grows.

Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2019-02-04 20:21:37 +01:00
Niklas Söderlund
4a5febd7dd libcamera: streams: extend stream configuration with buffer count
The camera needs to be configured with the number of buffers required to
satisfy the applications use case. While the application can request any
number of buffers, the pipeline must take the constraints of the Linux
driver into consideration.

Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2019-02-04 20:21:19 +01:00
Niklas Söderlund
08c31d2a86 libcamera: pipeline: vimc: create camera for Sensor B
Create a camera for Sensor B of the vimc pipeline. At this stage only
Sensor B is exposed while the are in total two sensors in the graph.
Going forward Sensor A should also be exposed as another camera. Sensor
B was chosen since the graph is configured correctly for it out of the
box. As we lack control over sub devices formats it's not really
possible to use Sensor A yet with the library.

Once both cameras are registered with the library they should be
extended to provide two streams each, one for the raw output and one for
the output which uses the shared scaler.

Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2019-02-04 16:52:50 +01:00
Kieran Bingham
8400bdd19a clang-format: Enable BreakBeforeTernaryOperators
This produces code with the ternary operators at the beginning instead of the
end of the line:

       return caps_.isMultiplanar() ? getFormatMultiplane(fmt)
                                    : getFormatSingleplane(fmt);

Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2019-02-04 16:43:09 +01:00
Kieran Bingham
b82fac15c4 libcamera: camera: Fix spelling error
Fix a small typo in the camera object documentation.

 cameera -> camera

Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2019-02-04 16:42:45 +01:00
Jacopo Mondi
acae9a9fd2 libcamera: v4l2_device: Set bytesperline in single plane S_FMT
The 'bytesperline' field of 'struct v4l2_pix_format' has to be set for
the single planar set format use case.

Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
2019-02-03 12:18:02 +01:00
Jacopo Mondi
f8c0c5817e libcamera: v4l2_device: Zero-initialize V4L2 format
Zero initialize v4l2_format structures used to set and get format on the
V4L2 device.

Fixes: ba8da0f2fc ("libcamera: v4l2_device: Add methods to get/set format")
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
2019-02-03 12:16:59 +01:00
Jacopo Mondi
a9f302dc05 libcamera: v4l2_device: Rename plane format fields
Rename the number of valid plane formats to 'planesCount' and the actual
per-plane size information array to 'planes'.

Acked-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
2019-02-03 12:16:27 +01:00
Jacopo Mondi
755644fe64 libcamera: v4l2_device: Rename parameters to s/g_fmt
Rename parameters to get and set format functions to expand 'fmt' to
'format'.

Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
2019-02-03 12:16:11 +01:00
Jacopo Mondi
2f516306a7 libcamera: v4l2_device: Fix getFormatSingleplane ioctl
The single plane getFormat() function wrongly used the VIDIOC_S_FMT ioctl.
Fix that by using the more opportune VIDIOC_G_FMT one.

Fixes: ba8da0f2fc ("libcamera: v4l2_device: Add methods to get/set format")
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
2019-02-03 12:14:46 +01:00
Jacopo Mondi
a78e56ecc2 libcamera: v4l2_device: Rename format() method to getFormat()
Rename format() to getFormat() to reflect the v4l2 API names more
closely.

Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
2019-02-03 12:14:05 +01:00
Laurent Pinchart
3fd5ade00c cam: options: Add explicit conversion methods to OptionValue
The OptionValue class defines operators to convert the variant to all
the supported option types. As a convenience, add explicit methods to
perform the same operations, avoiding the need to write long
static_cast<>() statements in the caller.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
2019-02-01 11:42:10 +02:00
Niklas Söderlund
86a7b45bdb cam: Add --format option to configure a stream
Add an option to configure the first stream of a camera from an argument
with options and parse the width, height and pixel format from that
list.

The pixel format is still specified as a integer which should correspond
to the kernels FOURCC identifiers. Going forward this should be turned
into a string representation and the cam parser should translate between
the two.

Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2019-02-01 11:42:06 +02:00
Niklas Söderlund
270eb0acc7 cam: options: Add a key=value parser
Some options passed to the cam utility need to be complex and specify a
list of key=value pairs. Add a new parser to deal with these options,
usable on its own to parse key=value pairs from any string.

Integrate the KeyValueParser into the existing OptionsParser. The cam
application can fully describe all its options in one location and
perform full parsing of all arguments in one go. The KeyValueParser also
integrates itself with the usage() printing of the OptionsParser.

Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2019-02-01 11:42:03 +02:00
Laurent Pinchart
c8c546fe99 cam: options: Add option type handling to options parser
Extend the options parser with support for option types. All options
must now specify the type of their argument, and the parser
automatically parses the argument and handles errors internally.
Available types are none, integer or string.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
2019-02-01 11:42:02 +02:00
Laurent Pinchart
6f3503981a cam: options: Store options in a list instead of a vector
When option are added to the parser, they are stored in the
OptionsParser::options_ vector, and a pointer to the option referencing
the vector entry is indexed in the OptionsParser::optionsMap_ map. When
the next option is added the vector may be resized, which invalidates
the pointers stored in the map.

Fix this by storing the options in an std::list<> instead of
std::vector<>.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
2019-02-01 11:42:00 +02:00
Niklas Söderlund
69be770715 cam: options: Return whether addOption() succeeds or not
To later extend the options handling to cover subparsing of arguments it
will be needed to know if the addition of the option itself was
successful or not. The information is already present in addOption()
this change just makes it available.

Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2019-02-01 11:41:59 +02:00
Niklas Söderlund
c6468e45d1 cam: options: Create a template class for options
In preparation to adding more parsers create a template class to hold
the parsed information. The rational for making it a template are that
different parsers can index the options using different data types.

The OptionsParser index its options using an int while the upcoming
KeyValyeParser will index its options using strings for example.

Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2019-02-01 11:41:55 +02:00
Laurent Pinchart
377516a084 cam: options: Move struct Option
The Option structure is declared within the OptionsParser, but will
later be needed by other parsers. Move it outside the OptionsParser
class.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
2019-02-01 11:41:54 +02:00
Niklas Söderlund
0b2822749e cam: options: Move enum OptionArgument
The enumeration of the different possibilities for arguments can be used
by other parser then OptionsParser. Move it outside the class to make it
ready to be used by other parsers.

Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2019-02-01 11:41:53 +02:00