11#include <promeki/config.h>
12#if PROMEKI_ENABLE_PROAV
23PROMEKI_NAMESPACE_BEGIN
138 PROMEKI_DATATYPE(SdiVpid, DataTypeSdiVpid, 1)
141 using ByteArray = ::promeki::Array<uint8_t, 4>;
148 static constexpr uint8_t Byte1_Unknown = 0x00;
166 static constexpr uint8_t Byte1_AnnexC_BT601 = 0x01;
169 static constexpr uint8_t Byte1_AnnexC_BT1358 = 0x02;
172 static constexpr uint8_t Byte1_AnnexC_ST347 = 0x03;
175 static constexpr uint8_t Byte1_AnnexC_ST274 = 0x04;
178 static constexpr uint8_t Byte1_AnnexC_ST296 = 0x05;
181 static constexpr uint8_t Byte1_AnnexC_ST349 = 0x06;
184 static constexpr uint8_t Byte1_SL_SD = 0x81;
186 static constexpr uint8_t Byte1_SL_HD_720 = 0x84;
188 static constexpr uint8_t Byte1_SL_HD_1080 = 0x85;
190 static constexpr uint8_t Byte1_DL_HD = 0x87;
192 static constexpr uint8_t Byte1_SL_3GA_720 = 0x88;
194 static constexpr uint8_t Byte1_SL_3GA_1080 = 0x89;
197 static constexpr uint8_t Byte1_SL_3GB = 0x8A;
200 static constexpr uint8_t Byte1_SL_6G_2160 = 0xC0;
203 static constexpr uint8_t Byte1_SL_6G_1080 = 0xC1;
206 static constexpr uint8_t Byte1_SL_12G_2160 = 0xCE;
209 static constexpr uint8_t Byte1_SL_12G_1080 = 0xCF;
216 static constexpr uint8_t Rate_Unknown = 0x0;
219 static constexpr uint8_t Rate_95_90 = 0x1;
221 static constexpr uint8_t Rate_23_98 = 0x2;
223 static constexpr uint8_t Rate_24 = 0x3;
225 static constexpr uint8_t Rate_47_95 = 0x4;
227 static constexpr uint8_t Rate_25 = 0x5;
229 static constexpr uint8_t Rate_29_97 = 0x6;
231 static constexpr uint8_t Rate_30 = 0x7;
233 static constexpr uint8_t Rate_48 = 0x8;
235 static constexpr uint8_t Rate_50 = 0x9;
237 static constexpr uint8_t Rate_59_94 = 0xA;
239 static constexpr uint8_t Rate_60 = 0xB;
241 static constexpr uint8_t Rate_96 = 0xC;
243 static constexpr uint8_t Rate_100 = 0xD;
246 static constexpr uint8_t Rate_119_88 = 0xE;
248 static constexpr uint8_t Rate_120 = 0xF;
280 static constexpr uint8_t BitDepth_8 = 0x0;
285 static constexpr uint8_t BitDepth_10_Full = 0x0;
287 static constexpr uint8_t BitDepth_10 = 0x1;
289 static constexpr uint8_t BitDepth_12 = 0x2;
293 static constexpr uint8_t BitDepth_12_Full = 0x3;
302 static constexpr uint8_t Transfer_SDR = 0x0;
304 static constexpr uint8_t Transfer_HLG = 0x1;
307 static constexpr uint8_t Transfer_PQ = 0x2;
311 static constexpr uint8_t Transfer_Unspecified = 0x3;
320 static constexpr uint8_t Colorimetry_Rec709 = 0x0;
323 static constexpr uint8_t Colorimetry_VANC = 0x1;
325 static constexpr uint8_t Colorimetry_UHDTV = 0x2;
327 static constexpr uint8_t Colorimetry_Unknown = 0x3;
349 SdiVpid(uint8_t b1, uint8_t b2, uint8_t b3, uint8_t b4);
354 explicit SdiVpid(const ByteArray &bytes);
373 bool isValid() const;
390 bool isCurrentVersion()
const {
return (_bytes[0] & 0x80) != 0; }
405 bool isAnnexC()
const;
429 Error validate()
const;
432 uint8_t byte1()
const {
return _bytes[0]; }
434 uint8_t byte2()
const {
return _bytes[1]; }
436 uint8_t byte3()
const {
return _bytes[2]; }
438 uint8_t byte4()
const {
return _bytes[3]; }
441 const ByteArray &bytes()
const {
return _bytes; }
444 void setByte1(uint8_t b) { _bytes[0] = b; }
446 void setByte2(uint8_t b) { _bytes[1] = b; }
448 void setByte3(uint8_t b) { _bytes[2] = b; }
450 void setByte4(uint8_t b) { _bytes[3] = b; }
468 SdiLinkStandard linkStandard()
const;
483 String payloadDescription()
const;
504 SdiWireFormat wireFormat()
const;
511 uint8_t pictureRateCode()
const {
return static_cast<uint8_t
>(_bytes[1] & 0x0F); }
528 FrameRate pictureRate()
const;
540 bool isProgressiveTransport()
const {
return (_bytes[1] & 0x80) != 0; }
554 bool isProgressivePicture()
const {
return (_bytes[1] & 0x40) != 0; }
568 bool isSdSchema()
const {
return _bytes[0] == Byte1_SL_SD; }
582 bool sdHas960Samples()
const {
return (_bytes[2] & 0x40) != 0; }
595 bool has2048Samples()
const {
return (_bytes[2] & 0x40) != 0; }
601 bool is16x9()
const {
return (_bytes[2] & 0x80) != 0; }
617 VideoScanMode videoScanMode()
const;
626 uint8_t samplingCode()
const {
return static_cast<uint8_t
>(_bytes[2] & 0x0F); }
638 VpidSampling sampling()
const;
651 void setSampling(
const VpidSampling &sampling);
666 uint8_t bitDepthCode()
const {
return static_cast<uint8_t
>(_bytes[3] & 0x03); }
677 int bitDepth()
const;
690 bool isFullRange()
const;
704 bool isExtendedSchema()
const;
718 uint8_t transferCode()
const {
return static_cast<uint8_t
>((_bytes[1] >> 4) & 0x03); }
733 TransferCharacteristics transferCharacteristic()
const;
743 uint8_t colorimetryCode()
const {
return static_cast<uint8_t
>((_bytes[2] >> 4) & 0x03); }
758 ColorPrimaries colorimetry()
const;
769 bool isIctcp()
const {
return (_bytes[3] & 0x10) != 0; }
776 uint8_t channelAssignment()
const {
return static_cast<uint8_t
>((_bytes[3] >> 5) & 0x07); }
791 void setChannelAssignment(uint8_t ch) {
792 _bytes[3] =
static_cast<uint8_t
>((_bytes[3] & 0x1F) | ((ch & 0x07) << 5));
804 void setTransferCode(uint8_t code) {
805 _bytes[1] =
static_cast<uint8_t
>((_bytes[1] & 0xCF) | ((code & 0x03) << 4));
812 void setColorimetryCode(uint8_t code) {
813 _bytes[2] =
static_cast<uint8_t
>((_bytes[2] & 0xCF) | ((code & 0x03) << 4));
820 void setIctcp(
bool ictcp) {
821 if (ictcp) _bytes[3] =
static_cast<uint8_t
>(_bytes[3] | 0x10);
822 else _bytes[3] =
static_cast<uint8_t
>(_bytes[3] & ~0x10);
829 void setBitDepthCode(uint8_t code) {
830 _bytes[3] =
static_cast<uint8_t
>((_bytes[3] & 0xFC) | (code & 0x03));
870 static SdiVpid encode(
const VideoFormat &videoFormat,
871 const SdiWireFormat &wireFormat,
872 const SdiLinkStandard &standard);
893 static SdiVpid encode(
const VideoFormat &videoFormat,
894 const SdiWireFormat &wireFormat,
895 const SdiLinkStandard &standard,
904 static uint8_t encodePictureRateCode(
const FrameRate &rate);
919 uint32_t toUint32BE()
const;
927 static SdiVpid fromUint32BE(uint32_t v);
961 St291Packet toSt291Packet(uint16_t line = 0,
bool fieldB =
false,
bool cBit =
false)
const;
981 static Result<SdiVpid> fromSt291Packet(
const St291Packet &pkt);
1018 static int recommendedAncLine(
const VideoFormat &fmt,
int field = 1);
1027 String toString()
const;
1038 static Result<SdiVpid> fromString(
const String &s);
1041 bool operator==(
const SdiVpid &other)
const {
return _bytes == other._bytes; }
1044 bool operator!=(
const SdiVpid &other)
const {
return !(*
this == other); }
1052 Error writeToStream(DataStream &s)
const;
1058 template <u
int32_t V>
static Result<SdiVpid> readFromStream(DataStream &s);
1064PROMEKI_NAMESPACE_END