-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathbuffer.hpp
More file actions
73 lines (58 loc) · 1.25 KB
/
buffer.hpp
File metadata and controls
73 lines (58 loc) · 1.25 KB
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
/* SPDX-License-Identifier: BSD-2-Clause */
/*
* Copyright (C) 2025 Raspberry Pi Ltd
*
* buffer.hpp - PiSP V4L2 Buffer and Sync (included by v4l2_device.hpp)
* No includes - must be included after <array>, <functional>, <stdint.h>.
*/
#pragma once
#include <array>
#include <functional>
#include <stdint.h>
namespace libpisp::helpers
{
struct Buffer
{
public:
Buffer();
Buffer(const Buffer &other);
Buffer(Buffer &&other);
Buffer(const std::array<int, 3> &fd, const std::array<size_t, 3> &size);
~Buffer();
bool operator==(const Buffer &other) const;
Buffer &operator=(const Buffer &other);
Buffer &operator=(Buffer &&);
const std::array<size_t, 3> &Size() const
{
return size;
}
const std::array<int, 3> &Fd() const
{
return fd;
}
struct Sync;
private:
void release();
void mmap() const;
std::array<size_t, 3> size;
mutable std::array<uint8_t *, 3> mem;
std::array<int, 3> fd;
};
using BufferRef = std::reference_wrapper<const Buffer>;
struct Buffer::Sync
{
enum class Access
{
Read,
Write,
ReadWrite
};
Sync(BufferRef buffer, Access access);
~Sync();
const std::array<uint8_t *, 3> &Get() const;
const std::array<size_t, 3> &Size() const;
private:
BufferRef buffer_;
Access access_;
};
} // namespace libpisp::helpers