/* SPDX-License-Identifier: LGPL-2.1-or-later */
/*
* Copyright (C) 2018, Google Inc.
*
* media_device.cpp - Media device handler
*/
#include "media_device.h"
#include <errno.h>
#include <fcntl.h>
#include <string.h>
#include <sys/ioctl.h>
#include <unistd.h>
#include <string>
#include <vector>
#include <linux/media.h>
#include "log.h"
/**
* \file media_device.h
* \brief Provide a representation of a Linux kernel Media Controller device
* that exposes the full graph topology.
*/
namespace libcamera {
LOG_DEFINE_CATEGORY(MediaDevice)
/**
* \class MediaDevice
* \brief The MediaDevice represents a Media Controller device with its full
* graph of connected objects.
*
* A MediaDevice instance is associated with a media controller device node when
* created, and that association is kept for the lifetime of the MediaDevice
* instance.
*
* The instance is created with an empty media graph. Before performing any
* other operation, it must be populate by calling populate(). Instances of
* MediaEntity, MediaPad and MediaLink are created to model the media graph,
* and stored in a map indexed by object id.
*
* The graph is valid once successfully populated, as reported by the valid()
* function. It can be queried to list all entities(), or entities can be
* looked up by name with getEntityByName(). The graph can be traversed from
* entity to entity through pads and links as exposed by the corresponding
* classes.
*
* Media device can be claimed for exclusive use with acquire(), released with
* release() and tested with busy(). This mechanism is aimed at pipeline
* managers to claim media devices they support during enumeration.
*/
/**
* \brief Construct a MediaDevice
* \param[in] deviceNode The media device node path
*
* Once constructed the media device is invalid, and must be populated with
* populate() before the media graph can be queried.
*/
MediaDevice::MediaDevice(const std::string &deviceNode)
: deviceNode_(deviceNode), fd_(-1), valid_(false), acquired_(false),
lockOwner_(false)
{
}
MediaDevice::~MediaDevice()
{
if (fd_ != -1)
::close(fd_);
clear();
}
/**
* \brief Claim a device for exclusive use
*
* The device claiming mechanism offers simple media device access arbitration
|