11#include <promeki/config.h>
12#if PROMEKI_ENABLE_PROAV
21PROMEKI_NAMESPACE_BEGIN
23class SdpMediaDescription;
47 PROMEKI_SHARED_FINAL(ImageDesc)
50 using Ptr = SharedPtr<ImageDesc>;
53 using List = ::promeki::List<ImageDesc>;
56 using PtrList = ::promeki::List<Ptr>;
66 ImageDesc(
const Size2Du32 &sz,
const PixelFormat &pd) : _size(sz), _pixelFormat(pd) {}
74 ImageDesc(
size_t w,
size_t h,
const PixelFormat &pd) : _size(Size2Du32(w, h)), _pixelFormat(pd) {}
115 static ImageDesc fromSdp(
const SdpMediaDescription &md);
134 static PixelFormat::ID jpegPixelFormatFromSdp(
const String &colorimetry,
const String &range,
135 bool is420,
bool isRgb);
166 SdpMediaDescription toSdp(uint8_t payloadType)
const;
172 bool isValid()
const {
return _size.isValid() && _pixelFormat.isValid(); }
178 const PixelFormat &pixelFormat()
const {
return _pixelFormat; }
184 void setPixelFormat(
const PixelFormat &pd) { _pixelFormat = pd; }
190 const PixelMemLayout &memLayout()
const {
return _pixelFormat.memLayout(); }
196 const ColorModel &colorModel()
const {
return _pixelFormat.colorModel(); }
202 const Size2Du32 &size()
const {
return _size; }
208 size_t width()
const {
return _size.width(); }
214 size_t height()
const {
return _size.height(); }
220 void setSize(
const Size2Du32 &val) {
230 void setSize(
int width,
int height) {
231 _size.set(width, height);
239 size_t linePad()
const {
return _linePad; }
245 void setLinePad(
size_t val) {
254 size_t lineAlign()
const {
return _lineAlign; }
260 void setLineAlign(
size_t val) {
275 VideoScanMode videoScanMode()
const {
return _videoScanMode; }
281 void setVideoScanMode(
const VideoScanMode &mode) {
282 _videoScanMode = mode;
287 const Metadata &metadata()
const {
return _metadata; }
290 Metadata &metadata() {
return _metadata; }
296 int planeCount()
const {
return _pixelFormat.planeCount(); }
302 String toString()
const {
303 String ret = _size.toString();
304 if (_pixelFormat.isValid()) {
306 ret += _pixelFormat.name();
312 operator String()
const {
return toString(); }
315 bool operator==(
const ImageDesc &other)
const {
316 return formatEquals(other) && _metadata == other._metadata;
320 bool operator!=(
const ImageDesc &other)
const {
return !(*
this == other); }
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;
344 size_t _lineAlign = 1;
345 VideoScanMode _videoScanMode = VideoScanMode::Unknown;
346 PixelFormat _pixelFormat;
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();
375inline DataStream &operator>>(DataStream &stream, ImageDesc &desc) {
376 if (!stream.readFrame(DataTypeImageDesc)) {
382 uint64_t linePad = 0, lineAlign = 1;
383 uint32_t scanValue = 0;
385 stream >> size >> pd >> linePad >> lineAlign >> scanValue >> meta;
386 if (stream.status() != DataStream::Ok) {
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);
400PROMEKI_FORMAT_VIA_TOSTRING(promeki::ImageDesc);