11#include <promeki/config.h>
12#if PROMEKI_ENABLE_PROAV
22PROMEKI_NAMESPACE_BEGIN
137 PROMEKI_DATATYPE(SdiVpid, DataTypeSdiVpid, 1)
140 using ByteArray = ::promeki::Array<uint8_t, 4>;
147 static constexpr uint8_t Byte1_Unknown = 0x00;
165 static constexpr uint8_t Byte1_AnnexC_BT601 = 0x01;
168 static constexpr uint8_t Byte1_AnnexC_BT1358 = 0x02;
171 static constexpr uint8_t Byte1_AnnexC_ST347 = 0x03;
174 static constexpr uint8_t Byte1_AnnexC_ST274 = 0x04;
177 static constexpr uint8_t Byte1_AnnexC_ST296 = 0x05;
180 static constexpr uint8_t Byte1_AnnexC_ST349 = 0x06;
183 static constexpr uint8_t Byte1_SL_SD = 0x81;
185 static constexpr uint8_t Byte1_SL_HD_720 = 0x84;
187 static constexpr uint8_t Byte1_SL_HD_1080 = 0x85;
189 static constexpr uint8_t Byte1_DL_HD = 0x87;
191 static constexpr uint8_t Byte1_SL_3GA_720 = 0x88;
193 static constexpr uint8_t Byte1_SL_3GA_1080 = 0x89;
196 static constexpr uint8_t Byte1_SL_3GB = 0x8A;
199 static constexpr uint8_t Byte1_SL_6G_2160 = 0xC0;
202 static constexpr uint8_t Byte1_SL_6G_1080 = 0xC1;
205 static constexpr uint8_t Byte1_SL_12G_2160 = 0xCE;
208 static constexpr uint8_t Byte1_SL_12G_1080 = 0xCF;
215 static constexpr uint8_t Rate_Unknown = 0x0;
218 static constexpr uint8_t Rate_95_90 = 0x1;
220 static constexpr uint8_t Rate_23_98 = 0x2;
222 static constexpr uint8_t Rate_24 = 0x3;
224 static constexpr uint8_t Rate_47_95 = 0x4;
226 static constexpr uint8_t Rate_25 = 0x5;
228 static constexpr uint8_t Rate_29_97 = 0x6;
230 static constexpr uint8_t Rate_30 = 0x7;
232 static constexpr uint8_t Rate_48 = 0x8;
234 static constexpr uint8_t Rate_50 = 0x9;
236 static constexpr uint8_t Rate_59_94 = 0xA;
238 static constexpr uint8_t Rate_60 = 0xB;
240 static constexpr uint8_t Rate_96 = 0xC;
242 static constexpr uint8_t Rate_100 = 0xD;
245 static constexpr uint8_t Rate_119_88 = 0xE;
247 static constexpr uint8_t Rate_120 = 0xF;
254 static constexpr uint8_t Sampling_YCbCr_422 = 0x0;
256 static constexpr uint8_t Sampling_YCbCr_444 = 0x1;
258 static constexpr uint8_t Sampling_RGB_444 = 0x2;
260 static constexpr uint8_t Sampling_YCbCr_420 = 0x3;
262 static constexpr uint8_t Sampling_YCbCrA_4224 = 0x4;
264 static constexpr uint8_t Sampling_YCbCrA_4444 = 0x5;
266 static constexpr uint8_t Sampling_RGBA_4444 = 0x6;
288 static constexpr uint8_t BitDepth_8 = 0x0;
293 static constexpr uint8_t BitDepth_10_Full = 0x0;
295 static constexpr uint8_t BitDepth_10 = 0x1;
297 static constexpr uint8_t BitDepth_12 = 0x2;
301 static constexpr uint8_t BitDepth_12_Full = 0x3;
310 static constexpr uint8_t Transfer_SDR = 0x0;
312 static constexpr uint8_t Transfer_HLG = 0x1;
315 static constexpr uint8_t Transfer_PQ = 0x2;
319 static constexpr uint8_t Transfer_Unspecified = 0x3;
328 static constexpr uint8_t Colorimetry_Rec709 = 0x0;
331 static constexpr uint8_t Colorimetry_VANC = 0x1;
333 static constexpr uint8_t Colorimetry_UHDTV = 0x2;
335 static constexpr uint8_t Colorimetry_Unknown = 0x3;
357 SdiVpid(uint8_t b1, uint8_t b2, uint8_t b3, uint8_t b4);
362 explicit SdiVpid(const ByteArray &bytes);
381 bool isValid() const;
398 bool isCurrentVersion()
const {
return (_bytes[0] & 0x80) != 0; }
413 bool isAnnexC()
const;
437 Error validate()
const;
440 uint8_t byte1()
const {
return _bytes[0]; }
442 uint8_t byte2()
const {
return _bytes[1]; }
444 uint8_t byte3()
const {
return _bytes[2]; }
446 uint8_t byte4()
const {
return _bytes[3]; }
449 const ByteArray &bytes()
const {
return _bytes; }
452 void setByte1(uint8_t b) { _bytes[0] = b; }
454 void setByte2(uint8_t b) { _bytes[1] = b; }
456 void setByte3(uint8_t b) { _bytes[2] = b; }
458 void setByte4(uint8_t b) { _bytes[3] = b; }
476 SdiLinkStandard linkStandard()
const;
497 SdiWireFormat wireFormat()
const;
504 uint8_t pictureRateCode()
const {
return static_cast<uint8_t
>(_bytes[1] & 0x0F); }
521 FrameRate pictureRate()
const;
533 bool isProgressiveTransport()
const {
return (_bytes[1] & 0x80) != 0; }
547 bool isProgressivePicture()
const {
return (_bytes[1] & 0x40) != 0; }
561 bool isSdSchema()
const {
return _bytes[0] == Byte1_SL_SD; }
575 bool sdHas960Samples()
const {
return (_bytes[2] & 0x40) != 0; }
588 bool has2048Samples()
const {
return (_bytes[2] & 0x40) != 0; }
594 bool is16x9()
const {
return (_bytes[2] & 0x80) != 0; }
610 VideoScanMode videoScanMode()
const;
617 uint8_t samplingCode()
const {
return static_cast<uint8_t
>(_bytes[2] & 0x0F); }
632 uint8_t bitDepthCode()
const {
return static_cast<uint8_t
>(_bytes[3] & 0x03); }
643 int bitDepth()
const;
656 bool isFullRange()
const;
670 bool isExtendedSchema()
const;
684 uint8_t transferCode()
const {
return static_cast<uint8_t
>((_bytes[1] >> 4) & 0x03); }
699 TransferCharacteristics transferCharacteristic()
const;
709 uint8_t colorimetryCode()
const {
return static_cast<uint8_t
>((_bytes[2] >> 4) & 0x03); }
724 ColorPrimaries colorimetry()
const;
735 bool isIctcp()
const {
return (_bytes[3] & 0x10) != 0; }
742 uint8_t channelAssignment()
const {
return static_cast<uint8_t
>((_bytes[3] >> 5) & 0x07); }
757 void setChannelAssignment(uint8_t ch) {
758 _bytes[3] =
static_cast<uint8_t
>((_bytes[3] & 0x1F) | ((ch & 0x07) << 5));
770 void setTransferCode(uint8_t code) {
771 _bytes[1] =
static_cast<uint8_t
>((_bytes[1] & 0xCF) | ((code & 0x03) << 4));
778 void setColorimetryCode(uint8_t code) {
779 _bytes[2] =
static_cast<uint8_t
>((_bytes[2] & 0xCF) | ((code & 0x03) << 4));
786 void setIctcp(
bool ictcp) {
787 if (ictcp) _bytes[3] =
static_cast<uint8_t
>(_bytes[3] | 0x10);
788 else _bytes[3] =
static_cast<uint8_t
>(_bytes[3] & ~0x10);
795 void setBitDepthCode(uint8_t code) {
796 _bytes[3] =
static_cast<uint8_t
>((_bytes[3] & 0xFC) | (code & 0x03));
836 static SdiVpid encode(
const VideoFormat &videoFormat,
837 const SdiWireFormat &wireFormat,
838 const SdiLinkStandard &standard);
859 static SdiVpid encode(
const VideoFormat &videoFormat,
860 const SdiWireFormat &wireFormat,
861 const SdiLinkStandard &standard,
870 static uint8_t encodePictureRateCode(
const FrameRate &rate);
885 uint32_t toUint32BE()
const;
893 static SdiVpid fromUint32BE(uint32_t v);
927 St291Packet toSt291Packet(uint16_t line = 0,
bool fieldB =
false,
bool cBit =
false)
const;
947 static Result<SdiVpid> fromSt291Packet(
const St291Packet &pkt);
984 static int recommendedAncLine(
const VideoFormat &fmt,
int field = 1);
993 String toString()
const;
1004 static Result<SdiVpid> fromString(
const String &s);
1007 bool operator==(
const SdiVpid &other)
const {
return _bytes == other._bytes; }
1010 bool operator!=(
const SdiVpid &other)
const {
return !(*
this == other); }
1018 Error writeToStream(DataStream &s)
const;
1024 template <u
int32_t V>
static Result<SdiVpid> readFromStream(DataStream &s);
1030PROMEKI_NAMESPACE_END