summaryrefslogtreecommitdiff
path: root/src/libcamera/media_device.cpp
AgeCommit message (Collapse)Author
2021-03-11libcamera: media_device: Add hwRevision methodDafna Hirschfeld
Add a method 'hwRevision' to return the info.hw_version reported by the driver. Signed-off-by: Dafna Hirschfeld <dafna.hirschfeld@collabora.com> Reviewed-by: Paul Elder <paul.elder@ideasonboard.com> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2021-03-05libcamera: media_device: Fix typoLaurent Pinchart
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Paul Elder <paul.elder@ideasonboard.com> Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
2020-05-16libcamera: Move internal headers to include/libcamera/internal/Laurent Pinchart
The libcamera internal headers are located in src/libcamera/include/. The directory is added to the compiler headers search path with a meson include_directories() directive, and internal headers are included with (e.g. for the internal semaphore.h header) #include "semaphore.h" All was well, until libcxx decided to implement the C++20 synchronization library. The __threading_support header gained a #include <semaphore.h> to include the pthread's semaphore support. As include_directories() adds src/libcamera/include/ to the compiler search path with -I, the internal semaphore.h is included instead of the pthread version. Needless to say, the compiler isn't happy. Three options have been considered to fix this issue: - Use -iquote instead of -I. The -iquote option instructs gcc to only consider the header search path for headers included with the "" version. Meson unfortunately doesn't support this option. - Rename the internal semaphore.h header. This was deemed to be the beginning of a long whack-a-mole game, where namespace clashes with system libraries would appear over time (possibly dependent on particular system configurations) and would need to be constantly fixed. - Move the internal headers to another directory to create a unique namespace through path components. This causes lots of churn in all the existing source files through the all project. The first option would be best, but isn't available to us due to missing support in meson. Even if -iquote support was added, we would need to fix the problem before a new version of meson containing the required support would be released. The third option is thus the only practical solution available. Bite the bullet, and do it, moving headers to include/libcamera/internal/. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Acked-by: Jacopo Mondi <jacopo@jmondi.org>
2020-05-02libcamera: media_device: Expose media device API version numberLaurent Pinchart
Add a MediaDevice::version() function to expose the media device API version number. This can be useful to support driver API changes in pipeline handlers. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
2020-02-19libcamera: media_device: Use Loggable interfaceKieran Bingham
Extend MediaDevice to inherit from the Loggable interface to support a logPrefix which presents the device node path, and the driver name. Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2020-02-19libcamera: media_device: prevent sign extension on castsKieran Bingham
The conversion of pointers to integers is implementation defined and differs between g++ and clang++ when utilising a uint64_t type. #include <iostream> int main(int argc, char **argv) { void *ptr = reinterpret_cast<void *>(0xf1234567); uint64_t u64 = reinterpret_cast<uint64_t>(ptr); uint64_t uint64 = reinterpret_cast<uintptr_t>(ptr); std::cout << "ptr " << ptr << " ptr -> u64 0x" << std::hex << u64 << " ptr -> uintptr_t -> u64 0x" << std::hex << uint64 << std::endl; return 0; } When compiled with g++ for a 32-bit platform produces the following unexpected output: ptr 0xf1234567 ptr -> u64 0xfffffffff1234567 ptr -> uintptr_t -> u64 0xf1234567 The standards states: "A pointer can be explicitly converted to any integral type large enough to hold all values of its type. The mapping function is implementation-defined. [Note: It is intended to be unsurprising to those who know the addressing structure of the underlying machine. — end note]" And as such the g++ implementation appears to be little more surprising than expected in this situation. The MediaDevice passes pointers to the kernel via the struct media_v2_topology in which pointers are cast using a uint64 type (__u64), which is affected by the sign extension described above when BIT(32) is set and causes an invalid address to be given to the kernel. Ensure that we cast using uintptr_t which is not affected by the sign extension issue. Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2019-11-18libcamera: Remove space between empty curly bracketsLaurent Pinchart
Remove spaces between empty curly brackets (replacing { } with {}) to comply with the coding style. Fix one other coding style violation on the lines touched by those fixes. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
2019-10-23libcamera: Standardise on C compatibility headersLaurent Pinchart
Now that our usage of C compatibility header is documented, use them consistently through the source code. While at it, group the C and C++ include statements as defined in the coding style, and fix a handful of #include ordering issues. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
2019-05-17libcamera: media_device: Add functions to lock device for other processesNiklas Söderlund
Add lock() and unlock() which are backed by lockf() and allow an instance of libcamera to claim exclusive access to a media device. These functions are the base of allowing multiple user of libcamera to coexist in the system without stepping on each other's toes. Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2019-05-17libcamera: media_device: Make open() and close() privateNiklas Söderlund
All external callers to open() and close() have been refactored and there is no need to expose these functions anymore, make them private. Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2019-05-17libcamera: media_device: Handle media device fd in acquire() and release()Niklas Söderlund
To gain better control of when a file descriptor is open to the media device and reduce the work needed in pipeline handler implementations, handle the file descriptor in acquire() and release(). This changes the current behavior where a file descriptor is only open when requested by the pipeline handler to that one is always open as long a media device is acquired. This new behavior is desired to allow implementing exclusive access to a pipeline handler between processes. Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2019-05-17libcamera: media_device: Only read device information in populate()Niklas Söderlund
There is no reason to reread the MEDIA_IOC_DEVICE_INFO information every time the media device is opened. Move it populate() where it will be read once together the other information about the media device. Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2019-05-17libcamera: media_device: Open and close media device inside populate()Niklas Söderlund
Remove the need for the caller to open and close the media device when populating the MediaDevice. This is done as an effort to make the usage of the MediaDevice less error prone and the interface stricter. The rework also revealed and fixes a potential memory leak in MediaDevice::populate() where resources would not be deleted if the second MEDIA_IOC_G_TOPOLOGY would fail. Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
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-03-20libcamera: media_device: Initialise local variableKieran Bingham
The local variable ifaceId generates a compiler warning that it is used without initialisation. The loop, and check against the loop iterator, and the topology.num_interfaces actually ensures that this isn't the case, and that ifaceId can only be used when set to a valid ID. The media_v2_interface.id field documents the ID as simply "Unique ID for the interface" but does not specify if zero is a valid ID or not. As such we don't further check the pre-initialised ID for validity and keep the existing check on the iterator count to determine if the ID had been discovered successfully. Fixes: d4af90d72901 ("libcamera: media_device: Create entities with major and minor numbers") Acked-by: Jacopo Mondi <jacopo@jmondi.org> Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
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-01-26libcamera: media_device: Fallback to legacy ioctls on older kernelsLaurent Pinchart
Prior to kernel v4.19, the MEDIA_IOC_G_TOPOLOGY ioctl didn't expose entity flags. Fallback to calling MEDIA_IOC_ENUM_ENTITIES for each entity to retrieve the flags in that case. Fixes: 67d313240c9b ("libcamera: pipeline: uvcvideo: create a V4L2Device for the default video entity") Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2019-01-24libcamera: media_device: Add disconnected signalLaurent Pinchart
The signal is emitted when the hardware device corresponding to the media device is unplugged. This will trigger the full unplug handling chain. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
2019-01-22libcamera: media_device: fix typo in documentation for MediaDevice::deviceNode()Niklas Söderlund
Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com> Acked-by: Jacopo Mondi <jacopo@jmondi.org>
2019-01-22libcamera: media_device: expose media graph model nameNiklas Söderlund
Pipeline handlers such as the upcoming ucvideo handler need the model name to properly name the Camera objects they create. Store the model name when querying the media device info and handle it in a similar fashion as the driver name which is already retrieved. Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2019-01-22libcamera: Global s/devnode/deviceNode renameJacopo Mondi
Do not use the abreviated version for members, variables and getter methods. Library-wise rename, no intended functional changes. 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-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-09libcamera: Add link handling functionsJacopo Mondi
Add a function to the MediaLink class to set the state of a link to enabled or disabled. The function makes use of an internal MediaDevice method, which is defined private and only accessible by the MediaLink setEnabled() function itself. Also add to MediaDevice a function to reset all links registered in the media graph. Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
2019-01-08libcamera: media_device: Add functions to get a MediaLinkJacopo Mondi
Add three overloaded functions 'link()' to retrieve a link between two pads. Each overloaded implementation exposes a different method to identify the source and sink pads. Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
2019-01-08libcamera: Add pointer to MediaDevice to MediaObjectJacopo Mondi
Add a MediaDevice member field to the MediaObject class hierarcy. Each media object now has a reference to the media device it belongs to, and which it has been created by. 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-03libcamera: Use 'struct' for structure typesJacopo Mondi
Add back the 'struct' keyword for structure types. C++ allows omitting the 'struct' keywork. Add it back to make clear we're dealing with structures and not class types. While at there re-sort fields of media_v2_* type in populate() function to reflect the declaration order in the kernel headers. Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
2019-01-03libcamera: media_device: Minor cleanup in findInterface()Jacopo Mondi
Do not compare an usigned int with -1 to avoid going through cast. Also align function parameters and long assignement lines while at there. Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se> Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
2019-01-02libcamera: media_device: Zero media graph arrays when querying topologyLaurent Pinchart
This silences valgrind that otherwise warns about usage of uninitialized values. While not strictly required as the kernel should fill the whole arrays in MEDIA_IOC_G_TOPOLOGY, the extra cost, in a non-critical path, is negligible compared to the ability to run without valgrind warnings. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2019-01-02libcamera: media_device: Make getEntityByName() constJacopo Mondi
The function does not modify the instance state. Mark it as const. Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
2019-01-02libcamera: media_device: Tiny valid() documentation improvementJacopo Mondi
Mention in the valid() method documentation, that a media graph has to be populated to be valid. Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
2019-01-02libcamera: media_device: Create entities with major and minor numbersJacopo Mondi
Extend the MediaEntity object with device node major and minor numbers, and retrieve them from the media graph using interfaces. They will be used by the DeviceEnumerator to retrieve the devnode path. Signed-off-by: Jacopo Mondi <jacopo@jmondi.org> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2019-01-02libcamera: media_device: Add DeviceInfo featuresJacopo Mondi
Add the features of the DeviceInfo class needed to replace it with MediaDevice. Signed-off-by: Jacopo Mondi <jacopo@jmondi.org> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2019-01-02libcamera: mediadevice: Improve documentationLaurent Pinchart
Improve the documentation of the media device operation, including how it handles the lifetime of media objects. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2019-01-02libcamera: mediadevice: Reorder functions in declaration orderLaurent Pinchart
In order to simplify navigation in the .cpp file, order functions in the declaration order in the .h file. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Acked-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2019-01-02libcamera: mediadevice: Fix graph parsing error handlingLaurent Pinchart
Most errors recorded during graph parsing are logged but not propagated to the caller. Fix this and delete objects that are created but not successfully added to the graph to avoid memory leaks. As the error code returned from the addObject() and populate*() functions doesn't matter much, turn them into bool functions. Additionally, add a way to query whether the media graph was valid, and clear objects before populating the graph to avoid leaking them. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2018-12-31libcamera: Add MediaDevice classJacopo Mondi
The MediaDevice object implements handling and configuration of the media graph associated with a media device. The class allows enumeration of all pads, links and entities registered in the media graph. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>