From 30fdea374798ced9b651b1377693f07f15c8df5c Mon Sep 17 00:00:00 2001 From: Kieran Kunhya Date: Tue, 15 Jul 2014 20:30:37 +0100 Subject: [PATCH] Add support for SMPTE 2022-1 Forward Error Correction --- smpte/2022_1_fec.h | 157 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 157 insertions(+) create mode 100644 smpte/2022_1_fec.h diff --git a/smpte/2022_1_fec.h b/smpte/2022_1_fec.h new file mode 100644 index 0000000..dc10e27 --- /dev/null +++ b/smpte/2022_1_fec.h @@ -0,0 +1,157 @@ +/***************************************************************************** + * 2022_1_fec.h + ***************************************************************************** + * Copyright (C) 2014 Open Broadcast Systems Ltd + * + * Authors: Kieran Kunhya /* uint8_t, uint16_t, etc... */ +#include /* bool */ + +#ifdef __cplusplus +extern "C" +{ +#endif + +/* + * Reminder : FEC Header + 0 1 2 3 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + | SNBase low bits | Length Recovery | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + |E| PT recovery | Mask | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + | TS recovery | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + |N|D|type |index| Offset | NA |SNBase ext bits| + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + */ + +static inline void smpte_fec_set_snbase_low(uint8_t *p_fec, uint16_t snbase_low) +{ + p_fec[0] = snbase_low >> 8; + p_fec[1] = snbase_low & 0xff; +} + +static inline uint16_t smpte_fec_get_snbase_low(const uint8_t *p_fec) +{ + return (p_fec[0] << 8) | p_fec[1]; +} + +static inline void smpte_fec_set_length_rec(uint8_t *p_fec, uint16_t length_rec) +{ + p_fec[2] = length_rec >> 8; + p_fec[3] = length_rec & 0xff; +} + +static inline uint16_t smpte_fec_get_length_rec(const uint8_t *p_fec) +{ + return (p_fec[2] << 8) | p_fec[3]; +} + +static inline void smpte_fec_set_extension(uint8_t *p_fec) +{ + p_fec[4] |= 0x80; +} + +static inline bool smpte_fec_check_extension(const uint8_t *p_fec) +{ + return !!(p_fec[4] & 0x80); +} + +static inline void smpte_fec_set_pt_recovery(uint8_t *p_fec, uint8_t pt_recovery) +{ + p_fec[4] |= pt_recovery & 0x7f; +} + +static inline uint8_t smpte_fec_get_pt_recovery(const uint8_t *p_fec) +{ + return p_fec[4] & 0x7f; +} + +static inline void smpte_fec_set_ts_recovery(uint8_t *p_fec, uint32_t snbase) +{ + p_fec[8] = snbase >> 24; + p_fec[9] = snbase >> 16; + p_fec[10] = snbase >> 8; + p_fec[11] = snbase & 0xff; +} + +static inline uint32_t smpte_fec_get_ts_recovery(const uint8_t *p_fec) +{ + return (p_fec[8] << 24) | (p_fec[9] << 16) | (p_fec[10] << 8) | p_fec[11]; +} + +static inline void smpte_fec_set_d(uint8_t *p_fec) +{ + p_fec[12] |= 0x40; +} + +static inline bool smpte_fec_check_d(const uint8_t *p_fec) +{ + return !!(p_fec[12] & 0x40); +} + +static inline void smpte_fec_set_offset(uint8_t *p_fec, uint8_t offset) +{ + p_fec[13] = offset; +} + +static inline uint8_t smpte_fec_get_offset(const uint8_t *p_fec) +{ + return p_fec[13]; +} + +static inline void smpte_fec_set_na(uint8_t *p_fec, uint8_t na) +{ + p_fec[14] = na; +} + +static inline uint8_t smpte_fec_get_na(const uint8_t *p_fec) +{ + return p_fec[14]; +} + +static inline void smpte_fec_set_snbase_ext(uint8_t *p_fec, uint8_t snbase_ext) +{ + p_fec[15] = snbase_ext; +} + +static inline uint8_t smpte_fec_get_snbase_ext(const uint8_t *p_fec) +{ + return p_fec[15]; +} + +#ifdef __cplusplus +} +#endif + +#endif