summaryrefslogtreecommitdiff
path: root/src/libcamera/pipeline_handler.cpp
AgeCommit message (Collapse)Author
2019-05-23libcamera: Refactor the camera configuration storage and APILaurent Pinchart
Refactor the CameraConfiguration structure to not rely on Stream instances. This is a step towards making the camera configuration object more powerful with configuration validation using "try" semantics. The CameraConfiguration now exposes a simple vector-like API to access the contained stream configurations. Both operator[]() and at() are provided to access elements. The isEmpty() method is renamed to empty() and the methods reordered to match the std::vector class. As applications need access to the Stream instances associated with the configuration entries in order to associate buffers with streams when creating requests, expose the stream selected by the pipeline handler through a new StreamConfiguration::stream(). Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se> Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
2019-05-23libcamera: Use stream roles directly instead of StreamUsageLaurent Pinchart
In order to prepare for an API overhall of the camera configuration generation, remove the StreamUsage class and replace its uses by stream roles. The size hints can't be specified anymore, and will be replaced with an API on the StreamConfiguration to negotiate configuration parameters with cameras. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se> Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
2019-05-23libcamera: camera: Rename configureStreams() and streamConfiguration()Laurent Pinchart
Rename the configureStreams() and streamConfiguration() methods to configure() and generateConfiguration() respectively in order to clarify the API. Both methods deal with CameraConfiguration objects, and are thus not limited to streams, even if a CameraConfiguration currently contains streams only. While at it, remove the qcam MainWindow::configureStreams() method that is declared but never defined or used. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se> Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
2019-05-17libcamera: pipeline_handler: Add functions to lock a whole pipelineNiklas Söderlund
Add lock() and unlock() which are backed by the MediaDevice implementation and lock all media devices claimed by a pipeline handler instance. Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2019-05-17libcamera: pipeline_handler: Keep track of MediaDeviceNiklas Söderlund
Instead of requiring each pipeline handle implementation to keep track of calling release() on its media devices upon deletion, keep track of them in the base class. Add a helper that pipeline handlers shall use to acquire a media device instead of directly interacting with the DeviceEnumerator. This also means that pipeline handler implementations do no need to keep a shared_ptr<> reference to the media devices they store locally as the PipelineHandler base class will keep a shared_ptr<> reference to all media devices consumed for the entire lifetime of the pipeline handler implementation. Centrally keeping track of media devices will also be beneficial to implement exclusive access to pipelines across processes. Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2019-04-30libcamera: pipeline: Unify naming of configurations in pipeline handlersLaurent Pinchart
Name all instances of CameraConfiguration "config", and all instances of StreamConfiguration "cfg" accross all pipeline handlers. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
2019-04-19libcamera: Include header related to source file firstLaurent Pinchart
Include the header file corresponding to the source file in the very first position. This complies with the Google C++ coding style guideliens, and helps ensuring that the headers are self-contained. Three bugs are already caught by this change (missing includes or forward declarations) in device_enumerator.h, event_dispatcher_poll.h and pipeline_handler.h. Fix them. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
2019-04-19libcamera: Document documentation style and update the code accordinglyLaurent Pinchart
The documentation style for the Doxygen comment blocks is inconsistent in the library. Document the expectations and update all existing comment blocks to match. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Acked-by: Jacopo Mondi <jacopo@jmondi.org>
2019-04-17libcamera: camera: Pass the stream set to allocate/freeBuffers()Jacopo Mondi
Pipeline handlers might need to perform allocation of internal buffers, setup operations, or simple sanity check before going into the per-stream buffer allocation. As of now, PipelineHandler::allocateBuffers() is called once for each active stream, leaving no space for stream-independent configuration. Change this by providing to the pipeline handlers the full set of active streams, and ask them to loop over them to perform per-streams memory allocations and freeing. Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
2019-04-09libcamera: Switch to CameraConfigurationNiklas Söderlund
Implement the camera configuration thru out the library, tests, cam and qcam tools. Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2019-04-05libcamera: camera: Add support for stream usagesNiklas Söderlund
Instead of requesting the default configuration for a set of streams where the application has to figure out which streams provided by the camera is best suited for its intended usage, have the library figure this out by using stream usages. The application asks the library for a list of streams and a suggested default configuration for them by supplying a list of stream usages. Once the list is retrieved the application can fine-tune the returned configuration and then try to apply it to the camera. Currently no pipeline handler is prepared to handle stream usages but nor did it make use of the list of Stream IDs which was the previous interface. The main reason for this is that all cameras currently only provide one stream each. This will still be the case but the API will be prepared to expand both pipeline handlers and applications to support streams usages. Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2019-03-01libcamera: Handle request completion explicitly in pipeline handlersLaurent Pinchart
Request complete by themselves when all the buffers they contain have completed, connecting the buffer's completed signal to be notified of buffer completion. While this works for now, it prevents pipelines from delaying request completion until all metadata is available, and makes it impossible to ensure that requests complete in the order they are queued. To fix this, make request completion handling explicit in pipeline handlers. The base PipelineHandler class is extended with implementations of the queueRequest() and stop() methods and gets new completeBuffer() and completeRequest() methods to help pipeline handlers tracking requests and buffers. The three existing pipeline handlers connect the bufferReady signal of their capture video node to a slot of their respective camera data instance, where they use the PipelineHandler helpers to notify buffer and request completion. Request completion is handled synchronously with buffer completion as the pipeline handlers don't need to support more advanced use cases, but this paves the road for future work. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
2019-03-01libcamera: pipeline_handler: Make pipeline-specific data mandatoryLaurent Pinchart
Mandate creationg of pipeline-specific data by pipeline handlers. This allows simplifying the API by passing the pipeline-specific data to the registerCamera() method and removing the separate setCameraData() method. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
2019-03-01libcamera: pipeline_handler: Store pipe and camera in CameraDataLaurent Pinchart
Extend the CameraData class with two member variables pipe_ and camera_ that store pointers to the pipeline handler and camera that the CameraData instance is related to. This will be used by pipeline handlers to access the camera and the pipeline in member methods of their CameraData derived classes. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
2019-02-27libcamera: align the documentation for numeric error codesNiklas Söderlund
Rapid growth of the library have resulted in slightly different wording to document that a function returns 0 on success or a negative error code otherwise. Align all different variations. Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se> Reviewed-by: Jacopo Mondi <jacopo@jmondi.org> Acked-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2019-02-25libcamera: pipeline_handler: extend documentation for configureStreams()Niklas Söderlund
Extend the documentation to explicitly state that the pipeline handler implementations are responsible for validating that the requested configuration can be exactly satisfied by the hardware. Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2019-02-13libcamera: pipeline_handler: Disconnect MediaDevice::disconnected signalLaurent Pinchart
The pipeline handler connects the disconnected signal of MediaDevice instances registered for hotplug handling to a member slot. Disconnect the signal when the slot is called, as the pipeline handler will be deleted. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
2019-02-11libcamera: pipeline_handler: Reorder member declaration orderLaurent Pinchart
Reorder the member declaration order in the PipelineHandler class to match the control flow order, and to declare variables after methods according to the coding style. Update the documentation accordingly, preserving the order within the public, protected and private sections, but grouping related methods together between the sections. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
2019-02-06libcamera: pipeline_handler: Extend the interface to support captureNiklas Söderlund
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-01libcamera: pipeline: extend pipelines to support stream configurationNiklas Söderlund
All streams which are to be used for capture need to be configured at the same time. This allows the pipeline handler to take any dependencies between the different streams and their configuration into account when setting up the hardware. Extend the pipeline API and all pipeline implementations with two new functions, one to read a default configuration and one to set a new configuration. Both functions operate on a group of streams which the pipeline handler should consider when performing the operations. In the current implemented pipelines this is rather easy as they only have one stream each per camera. Furthermore as there is yet no way for the pipeline handlers to interact with the hardware all they do is return a null format, log that a default configuration has been requested and log that a new configuration has been set. Future work based on more components are needed to make the pipelines return a good default format and actually interact with the hardware. Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2019-01-26libcamera: pipeline: Refuse to substitute camera dataJacopo Mondi
Once a pipeline-specific data has been associated with a camera, refuse to update it in order to avoid invalidating the previously set reference, which might still be owned by the caller. Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
2019-01-26libcamera: pipeline: Misc comments updateJacopo Mondi
Apply some comments improvements pointed out during review. Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
2019-01-26libcamera: pipeline: Rework class destructorJacopo Mondi
Remove comment and do not delete a class member, as it will be destroyed already with the instance that contains it. Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
2019-01-26libcamera: pipeline: Remove duplicated includeJacopo Mondi
Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
2019-01-25libcamera: pipeline_handler: Add CameraDataJacopo Mondi
Add class definition and methods to associate a Camera with specific data in the pipeline_handler base class. Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se> Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
2019-01-25libcamera: pipeline_handler: Add camera disconnection supportNiklas Söderlund
Pipeline handlers are responsible for creating camera instances, but also for destroying them when devices are unplugged. As camera objects are reference-counted this isn't a straightforward operation and involves the camera manager and camera object itself. Add two helper methods in the PipelineHandler base class to register a camera and to register a media device with the pipeline handler. When registering a camera, the registerCamera() helper method will add it to the camera manager. When registering a media device, the registerMediaDevice() helper method will listen to device disconnection events, and disconnect all cameras created by the pipeline handler as a response. Under the hood the PipelineHandler class needs to keep track of registered cameras in order to handle disconnection. They can't be stored as shared pointers as this would create a circular dependency (the Camera class owns a shared pointer to the pipeline handler). Store them as weak pointers instead. This is safe as a reference to the camera is stored in the camera manager, and doesn't get removed until the camera is unregistered from the manager by the PipelineHandler. Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2019-01-24libcamera: camera: Associate cameras with their pipeline handlerNiklas Söderlund
The PipelineHandler which creates a Camera is responsible for serving any operation requested by the user. In order forward the public API calls, the camera needs to store a reference to its pipeline handler. Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> --- Changes since v1: - Create pipeline handlers is shared pointers, make them inherit from std::enable_shared_from_this<> and stored them in shared pointers.
2019-01-24libcamera: pipeline_handler: Store the camera manager pointerLaurent Pinchart
Instead of passing the camera manager pointer to the match() function, and later to more PipelineHandler functions, store it in the PipelineHandler::manager_ member variable at construction time and access it from there. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
2019-01-21libcamera: Use log categoriesLaurent Pinchart
Use log categories in the whole existing code base. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2019-01-21libcamera: camera_manager: Register cameras with the camera managerLaurent Pinchart
Cameras are listed through a double indirection, first iterating over all available pipeline handlers, and then listing the cameras they each support. To simplify the API make the pipeline handlers register the cameras with the camera manager directly, which lets the camera manager easily expose the list of all available cameras. The PipelineHandler API gets simplified as the handlers don't need to expose the list of cameras they have created. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se> Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
2019-01-16libcamera: pipeline_handler: Rename handlers() method to factories()Laurent Pinchart
The PipelineHandlerFactory::handlers() static method returns a list of factories, not a list of handlers. Rename it accordingly. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
2019-01-16libcamera: pipeline_handler: Don't index factories by nameLaurent Pinchart
Pipeline handler factories are register in a map indexed by their name, and the list of names is used to expose the factories and look them up. This is unnecessary cumbersome, we can instead store factories in a vector and expose it directly. The pipeline factory users will still have access to the factory names through the factory name() function. The PipelineHandlerFactory::create() method becomes so simple that it can be inlined in its single caller, removing the unneeded usage of the DeviceEnumerator in the factory. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Jacopo Mondi <jacopo@jmondi.org> Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
2019-01-15libcamera: Debug printouts fixesJacopo Mondi
Address a few issues I missed during patch review. Minor cosmetic change. Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
2019-01-15libcamera: Add debug printoutsJacopo Mondi
Add a few debug printouts that help follow the library intialization process: what pipeline handlers are registered, what media devices are created, and which pipeline manager gets matches with the current system. The resulting output is the following, on IPU3 devices: DBG pipeline_handler.cpp:119 Pipeline handler: "PipeHandlerVimc" registered DBG pipeline_handler.cpp:119 Pipeline handler: "PipelineHandlerIPU3" registered DBG device_enumerator.cpp:214 New media device: ipu3-imgu created from: /dev/media0 DBG device_enumerator.cpp:214 New media device: ipu3-cio2 created from: /dev/media1 DBG device_enumerator.cpp:255 Succesfull match for media device: ipu3-cio2 DBG device_enumerator.cpp:255 Succesfull match for media device: ipu3-imgu DBG pipeline_handler.cpp:150 Pipeline handler: "PipelineHandlerIPU3" matched Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
2019-01-10libcamera: Document missing parameters and return valuesLaurent Pinchart
Several functions are missing documentation for some of them parameters and/or for their return value. Fix this. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
2019-01-04libcamera: pipeline_handler: Improve documentationLaurent Pinchart
Miscellaneous documentation improvements for the PipelineHandler and related classes. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Jacopo Mondi <jacopo@jmondi.org> Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
2018-12-31libcamera: pipeline_handler: add PipelineHandler classNiklas Söderlund
Provide a PipelineHandler which represents a handler for one or more media devices and provides one or more cameras. Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>