libcamera  v0.0.0+3-3b6e2d50-dirty (2022-01-27T16:18:04+08:00)
Supporting cameras in Linux since 2019
framebuffer.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
2 /*
3  * Copyright (C) 2019, Google Inc.
4  *
5  * framebuffer.h - Frame buffer handling
6  */
7 #ifndef __LIBCAMERA_FRAMEBUFFER_H__
8 #define __LIBCAMERA_FRAMEBUFFER_H__
9 
10 #include <assert.h>
11 #include <limits>
12 #include <stdint.h>
13 #include <vector>
14 
15 #include <libcamera/base/class.h>
16 #include <libcamera/base/span.h>
17 
19 
20 namespace libcamera {
21 
22 class Request;
23 
24 struct FrameMetadata {
25  enum Status {
29  };
30 
31  struct Plane {
32  unsigned int bytesused;
33  };
34 
36  unsigned int sequence;
37  uint64_t timestamp;
38 
39  Span<Plane> planes() { return planes_; }
40  Span<const Plane> planes() const { return planes_; }
41 
42 private:
43  friend class FrameBuffer;
44 
45  std::vector<Plane> planes_;
46 };
47 
48 class FrameBuffer final : public Extensible
49 {
51 
52 public:
53  struct Plane {
54  static constexpr unsigned int kInvalidOffset = std::numeric_limits<unsigned int>::max();
56  unsigned int offset = kInvalidOffset;
57  unsigned int length;
58  };
59 
60  FrameBuffer(const std::vector<Plane> &planes, unsigned int cookie = 0);
61 
62  const std::vector<Plane> &planes() const { return planes_; }
63  Request *request() const;
64  const FrameMetadata &metadata() const { return metadata_; }
65 
66  unsigned int cookie() const { return cookie_; }
67  void setCookie(unsigned int cookie) { cookie_ = cookie; }
68 
70 
71 private:
73 
74  friend class V4L2VideoDevice; /* Needed to update metadata_. */
75 
76  std::vector<Plane> planes_;
77 
78  FrameMetadata metadata_;
79 
80  unsigned int cookie_;
81 };
82 
83 } /* namespace libcamera */
84 
85 #endif /* __LIBCAMERA_FRAMEBUFFER_H__ */
Utilities to help constructing class interfaces.
#define LIBCAMERA_DECLARE_PRIVATE()
Declare private data for a public class.
#define LIBCAMERA_DISABLE_COPY_AND_MOVE(klass)
Disable copy and move construction and assignment of the klass.
Base class to manage private data through a d-pointer.
Definition: class.h:62
RAII-style wrapper for file descriptors.
Definition: file_descriptor.h:16
Frame buffer data and its associated dynamic metadata.
Definition: framebuffer.h:49
const std::vector< Plane > & planes() const
Retrieve the static plane descriptors.
Definition: framebuffer.h:62
unsigned int cookie() const
Retrieve the cookie.
Definition: framebuffer.h:66
Request * request() const
Retrieve the request this buffer belongs to.
Definition: framebuffer.cpp:274
FrameBuffer(const std::vector< Plane > &planes, unsigned int cookie=0)
Construct a FrameBuffer with an array of planes.
Definition: framebuffer.cpp:215
void cancel()
Marks the buffer as cancelled.
Definition: framebuffer.h:69
void setCookie(unsigned int cookie)
Set the cookie.
Definition: framebuffer.h:67
const FrameMetadata & metadata() const
Retrieve the dynamic metadata.
Definition: framebuffer.h:64
A frame capture request.
Definition: request.h:29
V4L2VideoDevice object and API.
Definition: v4l2_videodevice.h:174
File descriptor wrapper.
Top-level libcamera namespace.
Definition: bound_method.h:15
A memory region to store a single plane of a frame.
Definition: framebuffer.h:53
unsigned int length
The plane length in bytes.
Definition: framebuffer.h:57
unsigned int offset
The plane offset in bytes.
Definition: framebuffer.h:56
static constexpr unsigned int kInvalidOffset
Invalid offset value, to identify uninitialized planes.
Definition: framebuffer.h:54
FileDescriptor fd
The dmabuf file descriptor.
Definition: framebuffer.h:55
Per-plane frame metadata.
Definition: framebuffer.h:31
unsigned int bytesused
Number of bytes occupied by the data in the plane, including line padding.
Definition: framebuffer.h:32
Metadata related to a captured frame.
Definition: framebuffer.h:24
uint64_t timestamp
Time when the frame was captured.
Definition: framebuffer.h:37
Status
Define the frame completion status.
Definition: framebuffer.h:25
@ FrameCancelled
Definition: framebuffer.h:28
@ FrameError
Definition: framebuffer.h:27
@ FrameSuccess
Definition: framebuffer.h:26
unsigned int sequence
Frame sequence number.
Definition: framebuffer.h:36
Span< const Plane > planes() const
Retrieve the array of per-plane metadata.
Definition: framebuffer.h:40
Span< Plane > planes()
Retrieve the array of per-plane metadata.
Definition: framebuffer.h:39
Status status
Status of the frame.
Definition: framebuffer.h:35