CDI SDK
SDK for transporting chunks of data reliably and with low latency using a polled mode network driver.
Loading...
Searching...
No Matches
anc_payloads.h
Go to the documentation of this file.
1// -------------------------------------------------------------------------------------------
2// Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
3// This file is part of the AWS CDI-SDK, licensed under the BSD 2-Clause "Simplified" License.
4// License details at: https://github.com/aws/aws-cdi-sdk/blob/mainline/LICENSE
5// -------------------------------------------------------------------------------------------
6
19#ifndef ANC_PAYLOADS_H__
20#define ANC_PAYLOADS_H__
21
23
24#include <stdint.h>
25#include <stdbool.h>
26
27//*********************************************************************************************************************
28//***************************************** START OF DEFINITIONS AND TYPES ********************************************
29//*********************************************************************************************************************
30
34{
38 unsigned line_number:11;
40 unsigned horizontal_offset:12;
46 uint8_t did;
48 uint8_t sdid;
50 uint8_t data_count;
52 uint16_t user_data[255 + 4];
53};
54
65
74
75//*********************************************************************************************************************
76//******************************************* START OF PUBLIC FUNCTIONS ***********************************************
77//*********************************************************************************************************************
78
86inline static bool Parity8(uint8_t value)
87{
88 // From https://graphics.stanford.edu/~seander/bithacks.html#ParityParallel
89 unsigned v = value;
90 v ^= v >> 4;
91 v &= 0xf;
92 return (0x6996 >> v) & 1;
93}
94
102inline static uint16_t WithParityBits(uint8_t value)
103{
104 uint16_t parity = Parity8(value);
105 return (!parity << 9) + (parity << 8) + value;
106}
107
116inline static uint8_t CheckParityBits(uint16_t raw_word, int* parity_errors_ptr)
117{
118 uint16_t parity = Parity8(raw_word);
119 if ((raw_word & 0x100) >> 8 != parity || (raw_word & 0x200) >> 9 == parity) {
120 (*parity_errors_ptr)++;
121 }
122 return 0xff & raw_word;
123}
124
132void ParseAncillaryDataPayloadHeader(const uint32_t* payload_net_data_ptr, uint16_t* packet_count_ptr,
133 CdiFieldKind* field_kind_ptr);
134
144void ParseAncillaryDataPacketHeader(const uint32_t* packet_net_data_ptr, struct AncillaryDataPacket* packet_ptr,
145 struct AncillaryDataPayloadErrors* payload_errors);
146
156int ParseAncillaryDataPacket(const uint32_t* packet_net_data_ptr, struct AncillaryDataPacket* packet_ptr,
157 struct AncillaryDataPayloadErrors* payload_errors_ptr);
158
166int GetAncillaryDataPacketSize(int data_count);
167
175void WriteAncillaryDataPayloadHeader(uint32_t* payload_net_data_ptr, uint16_t packet_count, CdiFieldKind field_kind);
176
184void WriteAncillaryDataPacketHeader(uint32_t* packet_net_data_ptr, const struct AncillaryDataPacket* packet_ptr,
185 uint32_t* checksum_ptr);
186
195int WriteAncillaryDataPacket(uint32_t* packet_net_data_ptr, const struct AncillaryDataPacket* packet_ptr);
196
197#endif // ANC_PAYLOADS_H__
static uint8_t CheckParityBits(uint16_t raw_word, int *parity_errors_ptr)
Definition anc_payloads.h:116
int ParseAncillaryDataPacket(const uint32_t *packet_net_data_ptr, struct AncillaryDataPacket *packet_ptr, struct AncillaryDataPayloadErrors *payload_errors_ptr)
Definition anc_payloads.c:489
void WriteAncillaryDataPayloadHeader(uint32_t *payload_net_data_ptr, uint16_t packet_count, CdiFieldKind field_kind)
Definition anc_payloads.c:523
void ParseAncillaryDataPacketHeader(const uint32_t *packet_net_data_ptr, struct AncillaryDataPacket *packet_ptr, struct AncillaryDataPayloadErrors *payload_errors)
Definition anc_payloads.c:452
int WriteAncillaryDataPacket(uint32_t *packet_net_data_ptr, const struct AncillaryDataPacket *packet_ptr)
Definition anc_payloads.c:574
static uint16_t WithParityBits(uint8_t value)
Definition anc_payloads.h:102
void WriteAncillaryDataPacketHeader(uint32_t *packet_net_data_ptr, const struct AncillaryDataPacket *packet_ptr, uint32_t *checksum_ptr)
Definition anc_payloads.c:535
int GetAncillaryDataPacketSize(int data_count)
Definition anc_payloads.c:514
static bool Parity8(uint8_t value)
Definition anc_payloads.h:86
void ParseAncillaryDataPayloadHeader(const uint32_t *payload_net_data_ptr, uint16_t *packet_count_ptr, CdiFieldKind *field_kind_ptr)
Definition anc_payloads.c:439
This file declares the public API data types, structures and functions that facilitate parsing and sy...
CdiFieldKind
Definition cdi_avm_payloads_api.h:34
The ANC data packet. See https://datatracker.ietf.org/doc/html/rfc8331#section-2.1 for details.
Definition anc_payloads.h:34
unsigned source_stream_number
Source stream number.
Definition anc_payloads.h:44
bool is_valid_source_stream_number
True when the source_stream_number value is set.
Definition anc_payloads.h:42
bool is_color_difference_channel
True when the ANC data corresponds to the color-difference data channel.
Definition anc_payloads.h:36
unsigned line_number
The digital interface line number.
Definition anc_payloads.h:38
uint16_t user_data[255+4]
The packet's user data words (up to 255). Must contain 10-bit values.
Definition anc_payloads.h:52
unsigned horizontal_offset
The horizontal offset in an SDI raster relative to the start of active video.
Definition anc_payloads.h:40
uint8_t did
Data identification number.
Definition anc_payloads.h:46
uint8_t data_count
Number of user data words in packet.
Definition anc_payloads.h:50
uint8_t sdid
Secondary data identification number.
Definition anc_payloads.h:48
Counters for keeping track of errors observed when parsing ANC payloads.
Definition anc_payloads.h:57
int checksum_errors
Count of the number of checkum errors observed (at most one per ANC packet).
Definition anc_payloads.h:61
uint32_t checksum
Running checksum, used by ParseAncillaryDataPacket.
Definition anc_payloads.h:59
int parity_errors
Count of the number of parity errors observed.
Definition anc_payloads.h:63
The ANC payload header.
Definition anc_payloads.h:68
CdiFieldKind field_kind
Field kind of the associated video payload.
Definition anc_payloads.h:72
uint16_t ancillary_data_packet_count
The number of ANC packets in the payload.
Definition anc_payloads.h:70