libpromeki 1.0.0-alpha
PROfessional MEdia toolKIt
 
Loading...
Searching...
No Matches
asyncbufferqueue.h
Go to the documentation of this file.
1
8#pragma once
9
10
11#include <promeki/config.h>
12#if PROMEKI_ENABLE_CORE
13#include <promeki/namespace.h>
14#include <promeki/buffer.h>
15#include <promeki/iodevice.h>
16#include <promeki/list.h>
17#include <promeki/mutex.h>
18
19PROMEKI_NAMESPACE_BEGIN
20
69class AsyncBufferQueue : public IODevice {
70 PROMEKI_OBJECT(AsyncBufferQueue, IODevice)
71 public:
73 explicit AsyncBufferQueue(ObjectBase *parent = nullptr);
74
76 ~AsyncBufferQueue() override;
77
84 Error open(OpenMode mode) override;
85
94 Error close() override;
95
97 bool isOpen() const override;
98
100 int64_t read(void *data, int64_t maxSize) override;
101
112 int64_t write(const void *data, int64_t maxSize) override;
113
115 int64_t bytesAvailable() const override;
116
118 bool isSequential() const override;
119
127 Error seek(int64_t pos) override;
128
130 int64_t pos() const override;
131
140 Result<int64_t> size() const override;
141
150 bool atEnd() const override;
151
152 // ----------------------------------------------------
153 // Producer-side API (thread-safe)
154 // ----------------------------------------------------
155
170 Error enqueue(const Buffer &segment);
171
182 void closeWriting();
183
185 bool isWritingClosed() const;
186
188 size_t segmentCount() const;
189
190 private:
191 struct Segment {
192 Buffer buffer;
193 size_t offset = 0;
194 };
195
196 mutable Mutex _mutex;
197 List<Segment> _segments;
198 int64_t _queuedBytes = 0;
199 int64_t _readPos = 0;
200 bool _writingClosed = false;
201};
202
203PROMEKI_NAMESPACE_END
204
205#endif // PROMEKI_ENABLE_CORE