libcamera  v0.0.0
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 
8 #pragma once
9 
10 #include <assert.h>
11 #include <limits>
12 #include <memory>
13 #include <stdint.h>
14 #include <vector>
15 
16 #include <libcamera/base/class.h>
18 #include <libcamera/base/span.h>
19 
20 namespace libcamera {
21 
22 class Fence;
23 class Request;
24 
25 struct FrameMetadata {
26  enum Status {
30  };
31 
32  struct Plane {
33  unsigned int bytesused;
34  };
35 
37  unsigned int sequence;
38  uint64_t timestamp;
39 
40  Span<Plane> planes() { return planes_; }
41  Span<const Plane> planes() const { return planes_; }
42 
43 private:
44  friend class FrameBuffer;
45 
46  std::vector<Plane> planes_;
47 };
48 
49 class FrameBuffer final : public Extensible
50 {
52 
53 public:
54  struct Plane {
55  static constexpr unsigned int kInvalidOffset = std::numeric_limits<unsigned int>::max();
57  unsigned int offset = kInvalidOffset;
58  unsigned int length;
59  };
60 
61  FrameBuffer(const std::vector<Plane> &planes, unsigned int cookie = 0);
62  FrameBuffer(std::unique_ptr<Private> d,
63  const std::vector<Plane> &planes, unsigned int cookie = 0);
64 
65  const std::vector<Plane> &planes() const { return planes_; }
66  Request *request() const;
67  const FrameMetadata &metadata() const { return metadata_; }
68 
69  uint64_t cookie() const { return cookie_; }
70  void setCookie(uint64_t cookie) { cookie_ = cookie; }
71 
72  std::unique_ptr<Fence> releaseFence();
73 
74 private:
76 
77  friend class V4L2VideoDevice; /* Needed to update metadata_. */
78 
79  std::vector<Plane> planes_;
80 
81  FrameMetadata metadata_;
82 
83  uint64_t cookie_;
84 };
85 
86 } /* namespace libcamera */
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
Frame buffer data and its associated dynamic metadata.
Definition: framebuffer.h:50
void setCookie(uint64_t cookie)
Set the cookie.
Definition: framebuffer.h:70
const std::vector< Plane > & planes() const
Retrieve the static plane descriptors.
Definition: framebuffer.h:65
uint64_t cookie() const
Retrieve the cookie.
Definition: framebuffer.h:69
Request * request() const
Retrieve the request this buffer belongs to.
Definition: framebuffer.cpp:365
std::unique_ptr< Fence > releaseFence()
Extract the Fence associated with this Framebuffer.
Definition: framebuffer.cpp:413
FrameBuffer(const std::vector< Plane > &planes, unsigned int cookie=0)
Construct a FrameBuffer with an array of planes.
Definition: framebuffer.cpp:293
const FrameMetadata & metadata() const
Retrieve the dynamic metadata.
Definition: framebuffer.h:67
A frame capture request.
Definition: request.h:31
RAII-style wrapper for file descriptors.
Definition: shared_fd.h:17
V4L2VideoDevice object and API.
Definition: v4l2_videodevice.h:188
Top-level libcamera namespace.
Definition: backtrace.h:17
File descriptor wrapper.
A memory region to store a single plane of a frame.
Definition: framebuffer.h:54
unsigned int length
The plane length in bytes.
Definition: framebuffer.h:58
unsigned int offset
The plane offset in bytes.
Definition: framebuffer.h:57
static constexpr unsigned int kInvalidOffset
Invalid offset value, to identify uninitialized planes.
Definition: framebuffer.h:55
SharedFD fd
The dmabuf file descriptor.
Definition: framebuffer.h:56
Per-plane frame metadata.
Definition: framebuffer.h:32
unsigned int bytesused
Number of bytes occupied by the data in the plane, including line padding.
Definition: framebuffer.h:33
Metadata related to a captured frame.
Definition: framebuffer.h:25
uint64_t timestamp
Time when the frame was captured.
Definition: framebuffer.h:38
Status
Define the frame completion status.
Definition: framebuffer.h:26
@ FrameCancelled
Definition: framebuffer.h:29
@ FrameError
Definition: framebuffer.h:28
@ FrameSuccess
Definition: framebuffer.h:27
unsigned int sequence
Frame sequence number.
Definition: framebuffer.h:37
Span< const Plane > planes() const
Retrieve the array of per-plane metadata.
Definition: framebuffer.h:41
Span< Plane > planes()
Retrieve the array of per-plane metadata.
Definition: framebuffer.h:40
Status status
Status of the frame.
Definition: framebuffer.h:36