v4l2: v4l2_camera_file: Add V4L2CameraFile to model the opened camera file
With relation to opening files, the kernel has three objects related to files: - inodes, that represent files on disk - file objects, that are allocated at open() time and store all data related to the open file - file descriptors, that are integers that map to a file In the V4L2 compatibility layer, V4L2CameraProxy, which wraps a single libcamera camera via V4L2Camera, is more or less equivalent to the inode. We also already have file descriptors (that are really eventfds) that mirror the file descriptors. Here we create a V4L2CameraFile to model the file objects, to contain information related to the open file, namely if the file has been opened as non-blocking, and the V4L2 priority (to support VIDIOC_G/S_PRIORITY later on). This new class allows us to more cleanly support multiple open later on, since we can move out of V4L2CameraProxy the handling of mapping the fd to the open file information. Signed-off-by: Paul Elder <paul.elder@ideasonboard.com> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
This commit is contained in:
parent
58732e4b49
commit
d37ec82515
3 changed files with 64 additions and 0 deletions
|
@ -2,6 +2,7 @@
|
|||
|
||||
v4l2_compat_sources = files([
|
||||
'v4l2_camera.cpp',
|
||||
'v4l2_camera_file.cpp',
|
||||
'v4l2_camera_proxy.cpp',
|
||||
'v4l2_compat.cpp',
|
||||
'v4l2_compat_manager.cpp',
|
||||
|
|
26
src/v4l2/v4l2_camera_file.cpp
Normal file
26
src/v4l2/v4l2_camera_file.cpp
Normal file
|
@ -0,0 +1,26 @@
|
|||
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
||||
/*
|
||||
* Copyright (C) 2020, Google Inc.
|
||||
*
|
||||
* v4l2_camera_file.h - V4L2 compatibility camera file information
|
||||
*/
|
||||
|
||||
#include "v4l2_camera_file.h"
|
||||
|
||||
#include <linux/videodev2.h>
|
||||
|
||||
#include "v4l2_camera_proxy.h"
|
||||
|
||||
using namespace libcamera;
|
||||
|
||||
V4L2CameraFile::V4L2CameraFile(int efd, bool nonBlocking, V4L2CameraProxy *proxy)
|
||||
: proxy_(proxy), nonBlocking_(nonBlocking), efd_(efd),
|
||||
priority_(V4L2_PRIORITY_DEFAULT)
|
||||
{
|
||||
proxy_->open(nonBlocking);
|
||||
}
|
||||
|
||||
V4L2CameraFile::~V4L2CameraFile()
|
||||
{
|
||||
proxy_->close();
|
||||
}
|
37
src/v4l2/v4l2_camera_file.h
Normal file
37
src/v4l2/v4l2_camera_file.h
Normal file
|
@ -0,0 +1,37 @@
|
|||
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
||||
/*
|
||||
* Copyright (C) 2020, Google Inc.
|
||||
*
|
||||
* v4l2_camera_file.h - V4L2 compatibility camera file information
|
||||
*/
|
||||
|
||||
#ifndef __V4L2_CAMERA_FILE_H__
|
||||
#define __V4L2_CAMERA_FILE_H__
|
||||
|
||||
#include <linux/videodev2.h>
|
||||
|
||||
class V4L2CameraProxy;
|
||||
|
||||
class V4L2CameraFile
|
||||
{
|
||||
public:
|
||||
V4L2CameraFile(int efd, bool nonBlocking, V4L2CameraProxy *proxy);
|
||||
~V4L2CameraFile();
|
||||
|
||||
V4L2CameraProxy *proxy() const { return proxy_; }
|
||||
|
||||
bool nonBlocking() const { return nonBlocking_; }
|
||||
int efd() const { return efd_; }
|
||||
|
||||
enum v4l2_priority priority() const { return priority_; }
|
||||
void setPriority(enum v4l2_priority priority) { priority_ = priority; }
|
||||
|
||||
private:
|
||||
V4L2CameraProxy *proxy_;
|
||||
|
||||
bool nonBlocking_;
|
||||
int efd_;
|
||||
enum v4l2_priority priority_;
|
||||
};
|
||||
|
||||
#endif /* __V4L2_CAMERA_FILE_H__ */
|
Loading…
Add table
Add a link
Reference in a new issue