libcamera  v0.0.0
Supporting cameras in Linux since 2019
buffer.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  * buffer.h - Buffer handling
6  */
7 #ifndef __LIBCAMERA_BUFFER_H__
8 #define __LIBCAMERA_BUFFER_H__
9 
10 #include <stdint.h>
11 #include <vector>
12 
14 
15 namespace libcamera {
16 
17 class Request;
18 
19 struct FrameMetadata {
20  enum Status {
24  };
25 
26  struct Plane {
27  unsigned int bytesused;
28  };
29 
31  unsigned int sequence;
32  uint64_t timestamp;
33  std::vector<Plane> planes;
34 };
35 
36 class FrameBuffer final
37 {
38 public:
39  struct Plane {
41  unsigned int length;
42  };
43 
44  FrameBuffer(const std::vector<Plane> &planes, unsigned int cookie = 0);
45 
46  FrameBuffer(const FrameBuffer &) = delete;
47  FrameBuffer(FrameBuffer &&) = delete;
48 
49  FrameBuffer &operator=(const FrameBuffer &) = delete;
50  FrameBuffer &operator=(FrameBuffer &&) = delete;
51 
52  const std::vector<Plane> &planes() const { return planes_; }
53 
54  Request *request() const { return request_; }
55  void setRequest(Request *request) { request_ = request; }
56  const FrameMetadata &metadata() const { return metadata_; }
57 
58  unsigned int cookie() const { return cookie_; }
59  void setCookie(unsigned int cookie) { cookie_ = cookie; }
60 
61  int copyFrom(const FrameBuffer *src);
62 private:
63  friend class Request; /* Needed to update request_. */
64  friend class V4L2VideoDevice; /* Needed to update metadata_. */
65 
66  std::vector<Plane> planes_;
67 
68  Request *request_;
69  FrameMetadata metadata_;
70 
71  unsigned int cookie_;
72 };
73 
74 } /* namespace libcamera */
75 
76 #endif /* __LIBCAMERA_BUFFER_H__ */
RAII-style wrapper for file descriptors.
Definition: file_descriptor.h:15
Frame buffer data and its associated dynamic metadata.
Definition: buffer.h:37
const std::vector< Plane > & planes() const
Retrieve the static plane descriptors.
Definition: buffer.h:52
int copyFrom(const FrameBuffer *src)
Copy the contents from another buffer.
Definition: buffer.cpp:244
void setRequest(Request *request)
Set the request this buffer belongs to.
Definition: buffer.h:55
unsigned int cookie() const
Retrieve the cookie.
Definition: buffer.h:58
Request * request() const
Retrieve the request this buffer belongs to.
Definition: buffer.h:54
FrameBuffer(const std::vector< Plane > &planes, unsigned int cookie=0)
Construct a FrameBuffer with an array of planes.
Definition: buffer.cpp:159
void setCookie(unsigned int cookie)
Set the cookie.
Definition: buffer.h:59
const FrameMetadata & metadata() const
Retrieve the dynamic metadata.
Definition: buffer.h:56
A frame capture request.
Definition: request.h:26
V4L2VideoDevice object and API.
Definition: v4l2_videodevice.h:169
File descriptor wrapper.
A memory region to store a single plane of a frame.
Definition: buffer.h:39
unsigned int length
The plane length in bytes.
Definition: buffer.h:41
FileDescriptor fd
The dmabuf file descriptor.
Definition: buffer.h:40
Per-plane frame metadata.
Definition: buffer.h:26
unsigned int bytesused
Number of bytes occupied by the data in the plane, including line padding.
Definition: buffer.h:27
Metadata related to a captured frame.
Definition: buffer.h:19
uint64_t timestamp
Time when the frame was captured.
Definition: buffer.h:32
Status
Define the frame completion status.
Definition: buffer.h:20
@ FrameCancelled
Definition: buffer.h:23
@ FrameError
Definition: buffer.h:22
@ FrameSuccess
Definition: buffer.h:21
unsigned int sequence
Frame sequence number.
Definition: buffer.h:31
std::vector< Plane > planes
Array of per-plane metadata.
Definition: buffer.h:33
Status status
Status of the frame.
Definition: buffer.h:30