libpromeki 1.0.0-alpha
PROfessional MEdia toolKIt
 
Loading...
Searching...
No Matches
jpeggeometryprobe.h
Go to the documentation of this file.
1
8#pragma once
9
10
11#include <promeki/config.h>
12#if PROMEKI_ENABLE_PROAV
13#include <cstdint>
14#include <promeki/buffer.h>
15#include <promeki/imagedesc.h>
16#include <promeki/namespace.h>
17#include <promeki/pixelformat.h>
18#include <promeki/size2d.h>
19#include <promeki/string.h>
20
21PROMEKI_NAMESPACE_BEGIN
22
61class JpegGeometryProbe {
62 public:
70 struct SofData {
72 uint32_t width = 0;
74 uint32_t height = 0;
76 int nf = 0;
79 uint8_t ySf = 0;
80
83 bool isValid() const { return width > 0 && height > 0; }
84 };
85
92 struct Result {
95 bool valid = false;
97 Size2Du32 size;
101 PixelFormat pixelFormat;
106 bool is420 = false;
111 bool isRgb = false;
112
115 ImageDesc imageDesc() const {
116 return valid ? ImageDesc(size, pixelFormat) : ImageDesc();
117 }
118 };
119
120 JpegGeometryProbe() = default;
121
135 static SofData parseSof(const uint8_t *data, size_t size);
136
143 void reset();
144
149 bool hasGeometry() const { return _last.valid; }
150
156 const Result &lastResult() const { return _last; }
157
186 const Result &probe(const Buffer &reassembled, uint8_t rfc2435Type,
187 const String &fmtp);
188
189 private:
190 Result _last;
191 // Cache keys — used to skip the full PixelFormat
192 // resolution when nothing the resolution depends on
193 // has changed since the last probe call.
194 uint32_t _cachedWidth = 0;
195 uint32_t _cachedHeight = 0;
196 int _cachedNf = 0;
197 uint8_t _cachedYsf = 0;
198 uint8_t _cachedRfc2435Type = 0xFFu;
199 String _cachedFmtp;
200 bool _hasCacheKey = false;
201};
202
203PROMEKI_NAMESPACE_END
204
205#endif // PROMEKI_ENABLE_PROAV