libcamera: v4l2_subdevice: Create device from entity name

Add a static method to V4L2Subdevice class to create a V4L2Subdevice
instance from a media entity name.

Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
This commit is contained in:
Jacopo Mondi
2019-03-22 12:21:16 +01:00
parent 69c97ec042
commit c5ef6310fd
2 changed files with 27 additions and 0 deletions

View File

@@ -18,6 +18,8 @@
namespace libcamera {
class MediaDevice;
struct V4L2SubdeviceFormat {
uint32_t mbus_code;
uint32_t width;
@@ -48,6 +50,9 @@ public:
int getFormat(unsigned int pad, V4L2SubdeviceFormat *format);
int setFormat(unsigned int pad, V4L2SubdeviceFormat *format);
static V4L2Subdevice *fromEntityName(const MediaDevice *media,
const std::string &entity);
protected:
std::string logPrefix() const;

View File

@@ -16,6 +16,7 @@
#include "geometry.h"
#include "log.h"
#include "media_device.h"
#include "media_object.h"
#include "v4l2_subdevice.h"
@@ -313,6 +314,27 @@ int V4L2Subdevice::setFormat(unsigned int pad, V4L2SubdeviceFormat *format)
return 0;
}
/**
* \brief Create a new video subdevice instance from \a entity in media device
* \a media
* \param[in] media The media device where the entity is registered
* \param[in] entity The media entity name
*
* Releasing memory of the newly created instance is responsibility of the
* caller of this function.
*
* \return A newly created V4L2Subdevice on success, nullptr otherwise
*/
V4L2Subdevice *V4L2Subdevice::fromEntityName(const MediaDevice *media,
const std::string &entity)
{
MediaEntity *mediaEntity = media->getEntityByName(entity);
if (!mediaEntity)
return nullptr;
return new V4L2Subdevice(mediaEntity);
}
std::string V4L2Subdevice::logPrefix() const
{
return "'" + entityName() + "'";