libklvanc
vanc.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2016-2017 Kernel Labs Inc. All Rights Reserved
3  *
4  * Address: Kernel Labs Inc., PO Box 745, St James, NY. 11780
5  * Contact: sales@kernellabs.com
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21 
35 #ifndef _VANC_H
36 #define _VANC_H
37 
38 #include <stdint.h>
39 #include <stdarg.h>
40 #include <sys/errno.h>
41 #include <sys/errno.h>
43 
44 #ifdef __cplusplus
45 extern "C" {
46 #endif
47 
48 /* A series of callbacks used by the VANC library to inform user applications
49  * that certain messages have been fully decoded.
50  */
51 
56 
60 struct klvanc_packet_afd_s;
61 
66 
71 
76 
80 struct klvanc_packet_sdp_s;
81 
85 struct klvanc_context_s;
86 
91 
96 
101 {
102  int (*afd)(void *user_context, struct klvanc_context_s *, struct klvanc_packet_afd_s *);
103  int (*eia_708b)(void *user_context, struct klvanc_context_s *, struct klvanc_packet_eia_708b_s *);
104  int (*eia_608)(void *user_context, struct klvanc_context_s *, struct klvanc_packet_eia_608_s *);
105  int (*scte_104)(void *user_context, struct klvanc_context_s *, struct klvanc_packet_scte_104_s *);
106  int (*all)(void *user_context, struct klvanc_context_s *, struct klvanc_packet_header_s *);
107  int (*kl_i64le_counter)(void *user_context, struct klvanc_context_s *, struct klvanc_packet_kl_u64le_counter_s *);
108  int (*sdp)(void *user_context, struct klvanc_context_s *, struct klvanc_packet_sdp_s *);
109  int (*smpte_12_2)(void *user_context, struct klvanc_context_s *, struct klvanc_packet_smpte_12_2_s *);
110 };
111 
112 struct klvanc_cache_s;
113 
119 {
120  int verbose;
122  struct klvanc_callbacks_s *callbacks;
123  void *callback_context;
126  void (*log_cb)(void *p, int level, const char *fmt, ...);
127 
128  /* Internal use by the library */
129  void *priv;
130  struct klrestricted_code_path_block_s rcp_failedToDecode;
131  unsigned int checksum_failures;
132 
133  /* Optional: A cache of VANC lines we've detected in the stream.
134  * see klvanc_context_enable_monitor().
135  * A static array of structs, for did/sdid rapid lookups.
136  * Where DD and SD range from 00..FF.
137  * This contains an array of structs, each containing a set of lines,
138  * optimized for update/query. The structures are typically used by
139  * applications that want to keep tabs on what messages have been
140  * seen in the stream, per line. Its important to understand that
141  * for every message, we cache it, and the same message (same line)
142  * overwrites our previous cached message.
143  */
144  struct klvanc_cache_s *cacheLines;
145 
146  /* SCTE104 messages can be fragmented across multiple VANC packets.
147  * See ST2010-2008 Section 5 "Format of VANC Data Packets"
148  * Create a container for multiple vanc packets to be parsed consecutively.
149  * Create storage for 10 packets, track them, free them etc.
150  * Maintain a count of how many are in the list.
151  */
152 #define LIBKLVANC_SCTE104_MAX_FRAGMENTS (10)
153  struct klvanc_packet_header_s *scte104_fragments[LIBKLVANC_SCTE104_MAX_FRAGMENTS];
154  int scte104_fragment_count;
155 };
156 
157 #define LIBKLVANC_LOGLEVEL_ERR 0
158 #define LIBKLVANC_LOGLEVEL_WARN 1
159 #define LIBKLVANC_LOGLEVEL_INFO 2
160 #define LIBKLVANC_LOGLEVEL_DEBUG 3
161 
169 int klvanc_context_create(struct klvanc_context_s **ctx);
170 
178 
185 int klvanc_context_dump(struct klvanc_context_s *ctx);
186 
198 int klvanc_packet_parse(struct klvanc_context_s *ctx, unsigned int lineNr, const unsigned short *words, unsigned int wordCount);
199 
207 void klvanc_dump_words_console(struct klvanc_context_s *ctx, uint16_t *vanc, int maxlen, unsigned int linenr, int onlyvalid);
208 
209 #include <libklvanc/vanc-afd.h>
210 #include <libklvanc/vanc-eia_708b.h>
211 #include <libklvanc/vanc-eia_608.h>
212 #include <libklvanc/vanc-scte_104.h>
214 #include <libklvanc/did.h>
215 #include <libklvanc/pixels.h>
216 #include <libklvanc/vanc-checksum.h>
217 #include <libklvanc/smpte2038.h>
218 #include <libklvanc/cache.h>
220 #include <libklvanc/vanc-sdp.h>
221 
236 int klvanc_sdi_create_payload(uint8_t sdid, uint8_t did,
237  const uint8_t *src, uint16_t srcByteCount,
238  uint16_t **dst, uint16_t *dstWordCount,
239  uint32_t bitDepth);
240 
247 
254 
263  struct klvanc_packet_header_s *src);
264 
284 int klvanc_packet_save(const char *dir, const struct klvanc_packet_header_s *pkt,
285  int lineNr, int did);
286 
292 
297 int klvanc_packet_payload_append(struct klvanc_packet_header_s *dst, struct klvanc_packet_header_s *src, int srcOffset);
298 
299 #ifdef __cplusplus
300 };
301 #endif
302 
303 #endif /* _VANC_H */
klvanc_packet_type_e
TODO - Brief description goes here.
Definition: vanc-packets.h:42
VANC counter library used for diagnostics/debugging.
SCTE-104 Automation System to Compression System Communications Applications Program Interface...
SMPTE ST 12-2 Timecode over VANC.
TODO - Brief description goes here.
Definition: vanc-packets.h:57
int klvanc_sdi_create_payload(uint8_t sdid, uint8_t did, const uint8_t *src, uint16_t srcByteCount, uint16_t **dst, uint16_t *dstWordCount, uint32_t bitDepth)
Take an array of payload, create a fully formed VANC message. bitDepth of 10 is the only valid input ...
int klvanc_packet_parse(struct klvanc_context_s *ctx, unsigned int lineNr, const unsigned short *words, unsigned int wordCount)
Parse a line of payload, trigger callbacks as necessary. lineNr is passed around and only used for r...
int klvanc_packet_save(const char *dir, const struct klvanc_packet_header_s *pkt, int lineNr, int did)
Write the packet to disk, in a debug friendly format that can be used by other offline tools...
const char * klvanc_lookupDescriptionByType(enum klvanc_packet_type_e type)
TODO - Brief description goes here.
int klvanc_context_dump(struct klvanc_context_s *ctx)
Generate user visible context details to the console.
int warn_on_decode_failure
Definition: vanc.h:124
SMPTE 2016-3 Vertical Ancillary Data Mapping of Active Format Description and Bar Data...
int klvanc_packet_copy(struct klvanc_packet_header_s **dst, struct klvanc_packet_header_s *src)
Create a copy of a packet header.
Lookup functions that translate did/sdid into printable strings.
unsigned int lineNr
Definition: vanc-packets.h:68
VANC checksum routines.
int klvanc_context_destroy(struct klvanc_context_s *ctx)
Deallocate and destroy a context. See klvanc_context_create()
int allow_bad_checksums
Definition: vanc.h:121
EIA/CEA-608 Closed Captions.
VANC Caching functionality.
Common colorspace conversion functions for VANC.
TODO - Brief description goes here.
Definition: vanc-kl_u64le_counter.h:41
Generic code to limit the running of certain code to N times per second. Primary use case is to preve...
void klvanc_dump_words_console(struct klvanc_context_s *ctx, uint16_t *vanc, int maxlen, unsigned int linenr, int onlyvalid)
TODO - Brief description goes here.
TODO - Brief description goes here.
Definition: vanc-eia_608.h:41
Application specific context, the library allocates and stores user specific instance information...
Definition: vanc.h:118
int klvanc_packet_payload_append(struct klvanc_packet_header_s *dst, struct klvanc_packet_header_s *src, int srcOffset)
Append the payload words from srd to dst. Start copying from srcOffset position.
TODO - Brief description goes here.
Definition: vanc.h:100
TODO - Brief description goes here.
Definition: vanc-afd.h:75
TODO - Brief description goes here.
Definition: vanc-smpte_12_2.h:54
Definition: cache.h:46
CEA-708 Closed Captions.
Functions to parse, create and inspect SMPTE2038 formatted packets.
Definition: klrestricted_code_path.h:54
TODO - Brief description goes here.
Definition: vanc-scte_104.h:283
const char * klvanc_lookupSpecificationByType(enum klvanc_packet_type_e type)
TODO - Brief description goes here.
void klvanc_packet_free(struct klvanc_packet_header_s *src)
TODO - Brief description goes here.
Definition: vanc-sdp.h:22
int klvanc_context_create(struct klvanc_context_s **ctx)
Create or destroy some basic application/library context. The context is considered private and is l...
TODO - Brief description goes here.
Definition: vanc-eia_708b.h:120