summaryrefslogtreecommitdiff
path: root/include/libcamera/buffer.h
blob: 21a1ec4c574e1ee2b9f9cf56f20ee47c4c4d65b4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/* SPDX-License-Identifier: LGPL-2.1-or-later */
/*
 * Copyright (C) 2019, Google Inc.
 *
 * buffer.h - Buffer handling
 */
#ifndef __LIBCAMERA_BUFFER_H__
#define __LIBCAMERA_BUFFER_H__

#include <vector>

#include <libcamera/signal.h>

namespace libcamera {

class BufferPool;

class Plane final
{
public:
	Plane();
	~Plane();

	int dmabuf() const { return fd_; }
	int setDmabuf(int fd, unsigned int length);

	void *mem();
	unsigned int length() const { return length_; }

private:
	int mmap();
	int munmap();

	int fd_;
	unsigned int length_;
	void *mem_;
};

class Buffer final
{
public:
	Buffer();

	unsigned int index() const { return index_; }
	std::vector<Plane> &planes() { return planes_; }

	Signal<Buffer *> completed;

private:
	friend class BufferPool;

	unsigned int index_;

	std::vector<Plane> planes_;
};

class BufferPool final
{
public:
	~BufferPool();

	void createBuffers(unsigned int count);
	void destroyBuffers();

	unsigned int count() const { return buffers_.size(); }
	std::vector<Buffer> &buffers() { return buffers_; }

private:
	std::vector<Buffer> buffers_;
};

} /* namespace libcamera */

#endif /* __LIBCAMERA_BUFFER_H__ */