libpromeki 1.0.0-alpha
PROfessional MEdia toolKIt
 
Loading...
Searching...
No Matches
klvframe.h
Go to the documentation of this file.
1
8#pragma once
9
10
11#include <promeki/config.h>
12#if PROMEKI_ENABLE_NETWORK
13#include <cstddef>
14#include <cstdint>
15#include <promeki/namespace.h>
16#include <promeki/fourcc.h>
17#include <promeki/buffer.h>
18#include <promeki/error.h>
19
20PROMEKI_NAMESPACE_BEGIN
21
22class IODevice;
23
61class KlvFrame {
62 public:
64 static constexpr uint32_t DefaultMaxValueBytes = 64u * 1024u * 1024u;
65
67 FourCC key;
68
70 Buffer value;
71
73 KlvFrame() : key(0, 0, 0, 0) {}
74
80 KlvFrame(FourCC k, const Buffer &buf) : key(k), value(buf) {}
81};
82
96class KlvReader {
97 public:
102 explicit KlvReader(IODevice *device) : _device(device) {}
103
115 Error readHeader(FourCC &key, uint32_t &valueSize);
116
127 Error readValue(void *buf, uint32_t size);
128
137 Error skipValue(uint32_t size);
138
153 Error readFrame(KlvFrame &out, uint32_t maxValueBytes = KlvFrame::DefaultMaxValueBytes);
154
155 private:
156 IODevice *_device = nullptr;
157};
158
168class KlvWriter {
169 public:
174 explicit KlvWriter(IODevice *device) : _device(device) {}
175
186 Error writeHeader(FourCC key, uint32_t valueSize);
187
198 Error writeValue(const void *buf, uint32_t size);
199
208 Error writeFrame(FourCC key, const void *value, uint32_t size);
209
211 Error writeFrame(FourCC key);
212
214 Error writeFrame(FourCC key, const Buffer &value);
215
217 Error writeFrame(const KlvFrame &frame) { return writeFrame(frame.key, frame.value); }
218
219 private:
220 IODevice *_device = nullptr;
221};
222
223PROMEKI_NAMESPACE_END
224
225#endif // PROMEKI_ENABLE_NETWORK