libpromeki 1.0.0-alpha
PROfessional MEdia toolKIt
 
Loading...
Searching...
No Matches
dmabufbufferimpl.h
Go to the documentation of this file.
1
8#pragma once
9
10
11#include <promeki/config.h>
12#if PROMEKI_ENABLE_DMABUF
13#include <cstdint>
14#include <promeki/namespace.h>
15#include <promeki/bufferimpl.h>
17#include <promeki/mutex.h>
18#include <promeki/error.h>
19
20PROMEKI_NAMESPACE_BEGIN
21
31enum class DmabufFdOwnership {
42 Dup,
51 Adopt,
52};
53
108class DmabufBufferImpl : public BufferImpl {
109 public:
110 PROMEKI_SHARED_DERIVED(DmabufBufferImpl)
111
112
128 DmabufBufferImpl(const MemSpace &ms, int fd, size_t bytes, size_t align, DmabufFdOwnership ownership);
129
131 ~DmabufBufferImpl() override;
132
133 MemSpace memSpace() const override { return _memSpace; }
134 size_t allocSize() const override { return _allocSize; }
135 size_t align() const override { return _align; }
136
145 int dmabufFd() const { return _fd; }
146
148 void *mappedHostData() const override { return _hostMap; }
149
150 BufferRequest mapAcquire(MemDomain domain, MapFlags flags) override;
151 BufferRequest mapRelease(MemDomain domain) override;
152
154 Error fill(char value, size_t offset, size_t bytes) override;
155
157 Error copyFromHost(const void *src, size_t bytes, size_t offset) override;
158
160 bool canClone() const override { return false; }
161
162 private:
169 void dmabufSync(uint64_t syncFlags) const;
170
171 int _fd = -1;
172 size_t _allocSize = 0;
173 size_t _align = 0;
174 MemSpace _memSpace;
175
176 // Guards the lazy host mmap and the Host-domain refcount
177 // 0<->1 transitions so mmap/munmap happen exactly once.
178 mutable Mutex _hostMutex;
179 void *_hostMap = nullptr;
180 uint64_t _hostSyncFlags = 0; // DMA_BUF_SYNC_READ/WRITE bits in effect
181};
182
183PROMEKI_NAMESPACE_END
184
185#endif // PROMEKI_ENABLE_DMABUF