libpromeki 1.0.0-alpha
PROfessional MEdia toolKIt
 
Loading...
Searching...
No Matches
imagedesc.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 <promeki/namespace.h>
14#include <promeki/string.h>
15#include <promeki/sharedptr.h>
16#include <promeki/size2d.h>
17#include <promeki/pixelformat.h>
18#include <promeki/metadata.h>
19#include <promeki/enums.h>
20
21PROMEKI_NAMESPACE_BEGIN
22
23class SdpMediaDescription;
24
46class ImageDesc {
47 PROMEKI_SHARED_FINAL(ImageDesc)
48 public:
50 using Ptr = SharedPtr<ImageDesc>;
51
53 using List = ::promeki::List<ImageDesc>;
54
56 using PtrList = ::promeki::List<Ptr>;
57
59 ImageDesc() {}
60
66 ImageDesc(const Size2Du32 &sz, const PixelFormat &pd) : _size(sz), _pixelFormat(pd) {}
67
74 ImageDesc(size_t w, size_t h, const PixelFormat &pd) : _size(Size2Du32(w, h)), _pixelFormat(pd) {}
75
115 static ImageDesc fromSdp(const SdpMediaDescription &md);
116
134 static PixelFormat::ID jpegPixelFormatFromSdp(const String &colorimetry, const String &range,
135 bool is420, bool isRgb);
136
166 SdpMediaDescription toSdp(uint8_t payloadType) const;
167
172 bool isValid() const { return _size.isValid() && _pixelFormat.isValid(); }
173
178 const PixelFormat &pixelFormat() const { return _pixelFormat; }
179
184 void setPixelFormat(const PixelFormat &pd) { _pixelFormat = pd; }
185
190 const PixelMemLayout &memLayout() const { return _pixelFormat.memLayout(); }
191
196 const ColorModel &colorModel() const { return _pixelFormat.colorModel(); }
197
202 const Size2Du32 &size() const { return _size; }
203
208 size_t width() const { return _size.width(); }
209
214 size_t height() const { return _size.height(); }
215
220 void setSize(const Size2Du32 &val) {
221 _size = val;
222 return;
223 }
224
230 void setSize(int width, int height) {
231 _size.set(width, height);
232 return;
233 }
234
239 size_t linePad() const { return _linePad; }
240
245 void setLinePad(size_t val) {
246 _linePad = val;
247 return;
248 }
249
254 size_t lineAlign() const { return _lineAlign; }
255
260 void setLineAlign(size_t val) {
261 _lineAlign = val;
262 return;
263 }
264
275 VideoScanMode videoScanMode() const { return _videoScanMode; }
276
281 void setVideoScanMode(const VideoScanMode &mode) {
282 _videoScanMode = mode;
283 return;
284 }
285
287 const Metadata &metadata() const { return _metadata; }
288
290 Metadata &metadata() { return _metadata; }
291
296 int planeCount() const { return _pixelFormat.planeCount(); }
297
302 String toString() const {
303 String ret = _size.toString();
304 if (_pixelFormat.isValid()) {
305 ret += ' ';
306 ret += _pixelFormat.name();
307 }
308 return ret;
309 }
310
312 operator String() const { return toString(); }
313
315 bool operator==(const ImageDesc &other) const {
316 return formatEquals(other) && _metadata == other._metadata;
317 }
318
320 bool operator!=(const ImageDesc &other) const { return !(*this == other); }
321
336 bool formatEquals(const ImageDesc &other) const {
337 return _size == other._size && _linePad == other._linePad && _lineAlign == other._lineAlign &&
338 _videoScanMode == other._videoScanMode && _pixelFormat == other._pixelFormat;
339 }
340
341 private:
342 Size2Du32 _size;
343 size_t _linePad = 0;
344 size_t _lineAlign = 1;
345 VideoScanMode _videoScanMode = VideoScanMode::Unknown;
346 PixelFormat _pixelFormat;
347 Metadata _metadata;
348};
349
357inline DataStream &operator<<(DataStream &stream, const ImageDesc &desc) {
358 stream.beginFrame(DataTypeImageDesc, 1);
359 stream << desc.size();
360 stream << desc.pixelFormat();
361 stream << static_cast<uint64_t>(desc.linePad());
362 stream << static_cast<uint64_t>(desc.lineAlign());
363 stream << static_cast<uint32_t>(desc.videoScanMode().value());
364 stream << desc.metadata();
365 stream.endFrame();
366 return stream;
367}
368
375inline DataStream &operator>>(DataStream &stream, ImageDesc &desc) {
376 if (!stream.readFrame(DataTypeImageDesc)) {
377 desc = ImageDesc();
378 return stream;
379 }
380 Size2Du32 size;
381 PixelFormat pd;
382 uint64_t linePad = 0, lineAlign = 1;
383 uint32_t scanValue = 0;
384 Metadata meta;
385 stream >> size >> pd >> linePad >> lineAlign >> scanValue >> meta;
386 if (stream.status() != DataStream::Ok) {
387 desc = ImageDesc();
388 return stream;
389 }
390 desc = ImageDesc(size, pd);
391 desc.setLinePad(static_cast<size_t>(linePad));
392 desc.setLineAlign(static_cast<size_t>(lineAlign));
393 desc.setVideoScanMode(VideoScanMode{static_cast<int>(scanValue)});
394 desc.metadata() = std::move(meta);
395 return stream;
396}
397
398PROMEKI_NAMESPACE_END
399
400PROMEKI_FORMAT_VIA_TOSTRING(promeki::ImageDesc);
401
402#endif // PROMEKI_ENABLE_PROAV