11#include <promeki/config.h>
12#if PROMEKI_ENABLE_PROAV
22PROMEKI_NAMESPACE_BEGIN
44constexpr bool ancAtcIsPairHfrRate(uint32_t frameRateFps) {
45 return frameRateFps == 48u || frameRateFps == 50u || frameRateFps == 60u;
63constexpr bool ancAtcIsHfrtcRate(uint32_t frameRateFps) {
64 return frameRateFps == 72u || frameRateFps == 96u || frameRateFps == 100u ||
77constexpr bool ancAtcIsHfrRate(uint32_t frameRateFps) {
78 return ancAtcIsPairHfrRate(frameRateFps) || ancAtcIsHfrtcRate(frameRateFps);
119 PROMEKI_DATATYPE(AncAtc, DataTypeAncAtc, 2)
133 enum PayloadType : uint8_t {
143 bool duplicate =
false;
145 bool processed =
true;
150 uint8_t superFrameCount = 0;
158 explicit AncAtc(
const Timecode &tc) : _tc(tc) {}
163 const Timecode &timecode()
const {
return _tc; }
166 void setTimecode(
const Timecode &tc) { _tc = tc; }
177 uint8_t payloadType()
const {
return _payloadType; }
180 void setPayloadType(uint8_t v) { _payloadType = v; }
184 bool isHfrtcPayload()
const {
185 return _payloadType >= 0x80u && _payloadType <= 0x8Fu;
190 uint8_t hfrtcBitstream()
const {
191 return isHfrtcPayload() ?
static_cast<uint8_t
>(_payloadType & 0x0Fu) : uint8_t{0};
203 uint8_t dbb2()
const {
return _dbb2; }
206 void setDbb2(uint8_t v) { _dbb2 = v; }
216 static VitcDbb2 dbb2DecodeVitc(uint8_t b) {
218 r.line =
static_cast<uint8_t
>(b & 0x1Fu);
219 r.duplicate = (b & 0x20u) != 0u;
220 r.valid = (b & 0x40u) == 0u;
221 r.processed = (b & 0x80u) == 0u;
226 static uint8_t dbb2EncodeVitc(uint8_t line,
bool duplicate,
bool valid,
bool processed) {
227 uint8_t b =
static_cast<uint8_t
>(line & 0x1Fu);
228 if (duplicate) b =
static_cast<uint8_t
>(b | 0x20u);
229 if (!valid) b =
static_cast<uint8_t
>(b | 0x40u);
230 if (!processed) b =
static_cast<uint8_t
>(b | 0x80u);
241 static HfrtcDbb2 dbb2DecodeHfrtc(uint8_t b) {
243 r.n =
static_cast<uint8_t
>(b & 0x1Fu);
244 r.superFrameCount =
static_cast<uint8_t
>((b >> 5) & 0x03u);
249 static uint8_t dbb2EncodeHfrtc(uint8_t superFrameCount, uint8_t n) {
250 return static_cast<uint8_t
>(((superFrameCount & 0x03u) << 5) | (n & 0x1Fu));
256 bool operator==(
const AncAtc &o)
const {
257 return _tc == o._tc && _payloadType == o._payloadType && _dbb2 == o._dbb2;
261 bool operator!=(
const AncAtc &o)
const {
return !(*
this == o); }
266 String toString()
const;
269 JsonObject toJson()
const;
274 Error writeToStream(DataStream &s)
const;
277 template <u
int32_t V>
static Result<AncAtc> readFromStream(DataStream &s);
306 static int atcVitcFormatForFrame(uint32_t frameRateFps, uint64_t frameIndex);
310 uint8_t _payloadType = Ltc;