1 /*
2  *  libzvbi -- VBI decoding library
3  *
4  *  Copyright (C) 2000, 2001, 2002 Michael H. Schimek
5  *  Copyright (C) 2000, 2001 I�aki Garc�a Etxebarria
6  *
7  *  Originally based on AleVT 1.5.1 by Edgar Toernig
8  *
9  *  This library is free software; you can redistribute it and/or
10  *  modify it under the terms of the GNU Library General Public
11  *  License as published by the Free Software Foundation; either
12  *  version 2 of the License, or (at your option) any later version.
13  *
14  *  This library is distributed in the hope that it will be useful,
15  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17  *  Library General Public License for more details.
18  *
19  *  You should have received a copy of the GNU Library General Public
20  *  License along with this library; if not, write to the
21  *  Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
22  *  Boston, MA  02110-1301  USA.
23  */
24 
25 /* Generated file, do not edit! */
26 
27 #ifndef __LIBZVBI_H__
28 #define __LIBZVBI_H__
29 
30 #define VBI_VERSION_MAJOR 0
31 #define VBI_VERSION_MINOR 2
32 #define VBI_VERSION_MICRO 35
33 
34 #ifdef __cplusplus
35 extern "C" {
36 #endif
37 
38 
39 typedef struct vbi_decoder vbi_decoder;
40 
41 /* macros.h */
42 
43 #if __GNUC__ >= 4
44 #  define _vbi_sentinel __attribute__ ((__sentinel__(0)))
45 #  define _vbi_deprecated __attribute__ ((__deprecated__))
46 #else
47 #  define _vbi_sentinel
48 #  define _vbi_deprecated
49 #  define __restrict__
50 #endif
51 
52 #if (__GNUC__ == 3 && __GNUC_MINOR__ >= 3) || __GNUC__ >= 4
53 #  define _vbi_nonnull(params) __attribute__ ((__nonnull__ params))
54 #  define _vbi_format(params) __attribute__ ((__format__ params))
55 #else
56 #  define _vbi_nonnull(params)
57 #  define _vbi_format(params)
58 #endif
59 
60 #if __GNUC__ >= 3
61 #  define _vbi_pure __attribute__ ((__pure__))
62 #  define _vbi_alloc __attribute__ ((__malloc__))
63 #else
64 #  define _vbi_pure
65 #  define _vbi_alloc
66 #endif
67 
68 #if __GNUC__ >= 2
69 #  define _vbi_unused __attribute__ ((__unused__))
70 #  define _vbi_const __attribute__ ((__const__))
71 #  define _vbi_inline static __inline__
72 #else
73 #  define _vbi_unused
74 #  define _vbi_const
75 #  define _vbi_inline static
76 #endif
77 
78 #ifndef TRUE
79 #  define TRUE 1
80 #endif
81 #ifndef FALSE
82 #  define FALSE 0
83 #endif
84 
85 typedef int vbi_bool;
86 
87 
88 #ifndef NULL
89 #  ifdef __cplusplus
90 #    define NULL (0L)
91 #  else
92 #    define NULL ((void *) 0)
93 #  endif
94 #endif
95 
96 /* XXX Document me - for variadic funcs. */
97 #define VBI_END ((void *) 0)
98 
99 #if 0
100 typedef void
101 vbi_lock_fn			(void *			user_data);
102 typedef void
103 vbi_unlock_fn			(void *			user_data);
104 #endif
105 
106 typedef enum {
107 
108 	VBI_LOG_ERROR		= 1 << 3,
109 
110 	VBI_LOG_WARNING		= 1 << 4,
111 
112 	VBI_LOG_NOTICE		= 1 << 5,
113 
114 
115 	VBI_LOG_INFO		= 1 << 6,
116 
117 
118 	VBI_LOG_DEBUG		= 1 << 7,
119 
120 
121 	VBI_LOG_DRIVER		= 1 << 8,
122 
123 
124 	VBI_LOG_DEBUG2		= 1 << 9,
125 	VBI_LOG_DEBUG3		= 1 << 10
126 } vbi_log_mask;
127 
128 typedef void
129 vbi_log_fn			(vbi_log_mask		level,
130 				 const char *		context,
131 				 const char *		message,
132 				 void *			user_data);
133 
134 extern vbi_log_fn		vbi_log_on_stderr;
135 
136 
137 /* bcd.h */
138 
139 /* XXX unsigned? */
140 typedef int vbi_pgno;
141 
142 typedef int vbi_subno;
143 
144 #define VBI_ANY_SUBNO 0x3F7F
145 #define VBI_NO_SUBNO 0x3F7F
146 
147 _vbi_inline unsigned int
vbi_dec2bcd(unsigned int dec)148 vbi_dec2bcd(unsigned int dec)
149 {
150 	return (dec % 10) + ((dec / 10) % 10) * 16 + ((dec / 100) % 10) * 256;
151 }
152 
153 #define vbi_bin2bcd(n) vbi_dec2bcd(n)
154 
155 _vbi_inline unsigned int
vbi_bcd2dec(unsigned int bcd)156 vbi_bcd2dec(unsigned int bcd)
157 {
158 	return (bcd & 15) + ((bcd >> 4) & 15) * 10 + ((bcd >> 8) & 15) * 100;
159 }
160 
161 #define vbi_bcd2bin(n) vbi_bcd2dec(n)
162 
163 _vbi_inline unsigned int
vbi_add_bcd(unsigned int a,unsigned int b)164 vbi_add_bcd(unsigned int a, unsigned int b)
165 {
166 	unsigned int t;
167 
168 	a += 0x06666666;
169 	t  = a + b;
170 	b ^= a ^ t;
171 	b  = (~b & 0x11111110) >> 3;
172 	b |= b * 2;
173 
174 	return t - b;
175 }
176 
177 _vbi_inline vbi_bool
vbi_is_bcd(unsigned int bcd)178 vbi_is_bcd(unsigned int bcd)
179 {
180 	static const unsigned int x = 0x06666666;
181 
182 	return (((bcd + x) ^ (bcd ^ x)) & 0x11111110) == 0;
183 }
184 
185 _vbi_inline vbi_bool
vbi_bcd_digits_greater(unsigned int bcd,unsigned int maximum)186 vbi_bcd_digits_greater		(unsigned int		bcd,
187 				 unsigned int		maximum)
188 {
189 	maximum ^= ~0;
190 
191 	return 0 != (((bcd + maximum) ^ bcd ^ maximum) & 0x11111110);
192 }
193 
194 /* conv.h */
195 
196 #include <stdio.h>
197 #include <inttypes.h>		/* uint16_t */
198 
199 
200 #define VBI_NUL_TERMINATED -1
201 
202 extern unsigned long
203 vbi_strlen_ucs2			(const uint16_t *	src);
204 extern char *
205 vbi_strndup_iconv		(const char *		dst_codeset,
206 				 const char *		src_codeset,
207 				 const char *		src,
208 				 unsigned long		src_size,
209 				 int			repl_char)
210   _vbi_alloc;
211 extern char *
212 vbi_strndup_iconv_ucs2		(const char *		dst_codeset,
213 				 const uint16_t *	src,
214 				 long			src_length,
215 				 int			repl_char)
216   _vbi_alloc;
217 extern char *
218 vbi_strndup_iconv_caption	(const char *		dst_codeset,
219 				 const char *		src,
220 				 long			src_length,
221 				 int			repl_char)
222   _vbi_alloc;
223 #if 3 == VBI_VERSION_MINOR
224 extern char *
225 vbi_strndup_iconv_teletext	(const char *		dst_codeset,
226 				 const vbi_ttx_charset *cs,
227 				 const uint8_t *	src,
228 				 long			src_length,
229 				 int			repl_char)
230   _vbi_alloc _vbi_nonnull ((2));
231 #endif
232 extern vbi_bool
233 vbi_fputs_iconv			(FILE *			fp,
234 				 const char *		dst_codeset,
235 				 const char *		src_codeset,
236 				 const char *		src,
237 				 unsigned long		src_size,
238 				 int			repl_char)
239   _vbi_nonnull ((1));
240 extern vbi_bool
241 vbi_fputs_iconv_ucs2		(FILE *			fp,
242 				 const char *		dst_codeset,
243 				 const uint16_t *	src,
244 				 long			src_length,
245 				 int			repl_char)
246   _vbi_nonnull ((1));
247 extern const char *
248 vbi_locale_codeset		(void);
249 
250 
251 
252 /* network.h */
253 
254 typedef enum {
255 	VBI_CNI_TYPE_NONE,
256 	VBI_CNI_TYPE_UNKNOWN = VBI_CNI_TYPE_NONE,
257 
258 	VBI_CNI_TYPE_VPS,
259 
260 	VBI_CNI_TYPE_8301,
261 
262 	VBI_CNI_TYPE_8302,
263 
264 	VBI_CNI_TYPE_PDC_A,
265 
266 	VBI_CNI_TYPE_PDC_B
267 } vbi_cni_type;
268 
269 /* pdc.h */
270 
271 #include <time.h>		/* time_t */
272 
273 
274 typedef unsigned int vbi_pil;
275 
276 #define VBI_PIL(month, day, hour, minute)				\
277 	(((day) << 15) | ((month) << 11) | ((hour) << 6) | (minute))
278 
279 
280 #define VBI_PIL_MONTH(pil)	(((pil) >> 11) & 15)
281 
282 
283 #define VBI_PIL_DAY(pil)	(((pil) >> 15) & 31)
284 
285 
286 #define VBI_PIL_HOUR(pil)	(((pil) >> 6) & 31)
287 
288 
289 #define VBI_PIL_MINUTE(pil)	((pil) & 63)
290 
291 enum {
292 	VBI_PIL_TIMER_CONTROL		= VBI_PIL (15, 0, 31, 63),
293 
294 	VBI_PIL_INHIBIT_TERMINATE	= VBI_PIL (15, 0, 30, 63),
295 
296 	VBI_PIL_INTERRUPTION		= VBI_PIL (15, 0, 29, 63),
297 
298 	VBI_PIL_CONTINUE		= VBI_PIL (15, 0, 28, 63),
299 
300 	VBI_PIL_NSPV			= VBI_PIL (15, 15, 31, 63),
301 
302 	VBI_PIL_END			= VBI_PIL (15, 15, 31, 63)
303 };
304 
305 extern vbi_bool
306 vbi_pil_is_valid_date		(vbi_pil		pil);
307 extern time_t
308 vbi_pil_to_time			(vbi_pil		pil,
309 				 time_t			start,
310 				 const char *		tz);
311 extern time_t
312 vbi_pil_lto_to_time		(vbi_pil		pil,
313 				 time_t			start,
314 				 int			seconds_east);
315 extern vbi_bool
316 vbi_pty_validity_window		(time_t *		begin,
317 				 time_t *		end,
318 				 time_t			time,
319 				 const char *		tz)
320 #ifndef DOXYGEN_SHOULD_SKIP_THIS
321   _vbi_nonnull ((1, 2))
322 #endif
323 ;
324 extern vbi_bool
325 vbi_pil_validity_window		(time_t *		begin,
326 				 time_t *		end,
327 				 vbi_pil		pil,
328 				 time_t			start,
329 				 const char *		tz)
330 #ifndef DOXYGEN_SHOULD_SKIP_THIS
331   _vbi_nonnull ((1, 2))
332 #endif
333 ;
334 extern vbi_bool
335 vbi_pil_lto_validity_window	(time_t *		begin,
336 				 time_t *		end,
337 				 vbi_pil		pil,
338 				 time_t			start,
339 				 int			seconds_east)
340 #ifndef DOXYGEN_SHOULD_SKIP_THIS
341   _vbi_nonnull ((1, 2))
342 #endif
343 ;
344 
345 
346 typedef enum {
347 	VBI_PID_CHANNEL_LCI_0 = 0,
348 
349 
350 	VBI_PID_CHANNEL_LCI_1,
351 
352 
353 	VBI_PID_CHANNEL_LCI_2,
354 
355 
356 	VBI_PID_CHANNEL_LCI_3,
357 
358 	VBI_PID_CHANNEL_VPS,
359 
360 	VBI_PID_CHANNEL_PDC_DESCRIPTOR,
361 
362 	VBI_PID_CHANNEL_XDS_CURRENT,
363 
364 	VBI_PID_CHANNEL_XDS_FUTURE,
365 
366 
367 	VBI_MAX_PID_CHANNELS
368 } vbi_pid_channel;
369 
370 typedef enum {
371 
372 	VBI_PCS_AUDIO_UNKNOWN = 0,
373 
374 
375 	VBI_PCS_AUDIO_MONO,
376 
377 
378 	VBI_PCS_AUDIO_STEREO,
379 
380 
381 	VBI_PCS_AUDIO_BILINGUAL
382 } vbi_pcs_audio;
383 
384 typedef struct {
385 
386 	vbi_pid_channel			channel;
387 
388 	vbi_cni_type			cni_type;
389 
390 	unsigned int			cni;
391 
392 	vbi_pil				pil;
393 
394 	vbi_bool			luf;
395 
396 	vbi_bool			mi;
397 
398 	vbi_bool			prf;
399 
400 
401 	vbi_pcs_audio			pcs_audio;
402 
403 	unsigned int			pty;
404 
405 	vbi_bool			tape_delayed;
406 
407 	void *				_reserved2[2];
408 	int				_reserved3[4];
409 } vbi_program_id;
410 
411 
412 
413 /* event.h */
414 
415 #include <inttypes.h>
416 
417 
418 typedef unsigned int vbi_nuid;
419 
420 typedef struct {
421 	vbi_nuid		nuid;
422 
423 	signed char		name[64];
424 
425 	signed char		call[40];
426 
427 	int			tape_delay;
428 
429 	int			cni_vps;
430 
431 	int			cni_8301;
432 
433 	int			cni_8302;
434 
435 	int			reserved;
436 
437 
438 	int			cycle;
439 } vbi_network;
440 
441 /*
442  *  Link
443  */
444 
445 typedef enum {
446 	VBI_LINK_NONE = 0,
447 	VBI_LINK_MESSAGE,
448 	VBI_LINK_PAGE,
449 	VBI_LINK_SUBPAGE,
450 	VBI_LINK_HTTP,
451 	VBI_LINK_FTP,
452 	VBI_LINK_EMAIL,
453 
454 	VBI_LINK_LID,
455 
456 	VBI_LINK_TELEWEB
457 } vbi_link_type;
458 
459 typedef enum {
460 	VBI_WEBLINK_UNKNOWN = 0,
461 	VBI_WEBLINK_PROGRAM_RELATED,
462 	VBI_WEBLINK_NETWORK_RELATED,
463 	VBI_WEBLINK_STATION_RELATED,
464 	VBI_WEBLINK_SPONSOR_MESSAGE,
465 	VBI_WEBLINK_OPERATOR
466 } vbi_itv_type;
467 
468 typedef struct vbi_link {
469 	vbi_link_type			type;
470 	vbi_bool			eacem;
471 	signed char 			name[80];
472 	signed char			url[256];
473 	signed char			script[256];
474 	vbi_nuid			nuid;
475 	vbi_pgno			pgno;
476 	vbi_subno			subno;
477 	double				expires;
478 	vbi_itv_type			itv_type;
479 	int				priority;
480 	vbi_bool			autoload;
481 } vbi_link;
482 
483 /*
484  *  Aspect ratio information.
485  */
486 
487 typedef enum {
488 	VBI_SUBT_NONE,
489 	VBI_SUBT_ACTIVE,
490 	VBI_SUBT_MATTE,
491 	VBI_SUBT_UNKNOWN
492 } vbi_subt;
493 
494 typedef struct {
495  	int			first_line;
496 	int			last_line;
497 	double			ratio;
498  	vbi_bool		film_mode;
499 	vbi_subt		open_subtitles;
500 } vbi_aspect_ratio;
501 
502 /*
503  *  Program Info
504  *
505  *  ATTN this is new stuff and subject to change
506  */
507 
508 typedef enum {
509 	VBI_RATING_AUTH_NONE = 0,
510 	VBI_RATING_AUTH_MPAA,
511 	VBI_RATING_AUTH_TV_US,
512 	VBI_RATING_AUTH_TV_CA_EN,
513 	VBI_RATING_AUTH_TV_CA_FR
514 } vbi_rating_auth;
515 
516 #define VBI_RATING_D 0x08
517 #define VBI_RATING_L 0x04
518 #define VBI_RATING_S 0x02
519 #define VBI_RATING_V 0x01
520 
521 
522 extern const char *	vbi_rating_string(vbi_rating_auth auth, int id);
523 
524 typedef enum {
525 	VBI_PROG_CLASSF_NONE = 0,
526 	VBI_PROG_CLASSF_EIA_608,
527 	VBI_PROG_CLASSF_ETS_300231
528 } vbi_prog_classf;
529 
530 extern const char *	vbi_prog_type_string(vbi_prog_classf classf, int id);
531 
532 
533 /* code depends on order, don't change */
534 typedef enum {
535 	VBI_AUDIO_MODE_NONE = 0,
536 	VBI_AUDIO_MODE_MONO,
537 	VBI_AUDIO_MODE_STEREO,
538 	VBI_AUDIO_MODE_STEREO_SURROUND,
539 	VBI_AUDIO_MODE_SIMULATED_STEREO,
540 	VBI_AUDIO_MODE_VIDEO_DESCRIPTIONS,
541 	VBI_AUDIO_MODE_NON_PROGRAM_AUDIO,
542 
543 	VBI_AUDIO_MODE_SPECIAL_EFFECTS,
544 	VBI_AUDIO_MODE_DATA_SERVICE,
545 	VBI_AUDIO_MODE_UNKNOWN
546 } vbi_audio_mode;
547 
548 typedef struct vbi_program_info {
549 	/*
550 	 *  Refers to the current or next program.
551 	 *  (No [2] to allow clients filtering current data more easily.)
552 	 */
553 	unsigned int		future : 1;
554 
555 	/* 01 Program Identification Number */
556 
557 	/* If unknown all these fields are -1 */
558 	signed char		month;		/* 0 ... 11 */
559 	signed char		day;		/* 0 ... 30 */
560 	signed char		hour;		/* 0 ... 23 */
561 	signed char		min;		/* 0 ... 59 */
562 
563 	/*
564 	 *  VD: "T indicates if a program is routinely tape delayed for the
565 	 *  Mountain and Pacific time zones."
566 	 */
567 	signed char		tape_delayed;
568 
569 	/* 02 Program Length */
570 
571 	/* If unknown all these fields are -1 */
572 	signed char		length_hour;	/* 0 ... 63 */
573 	signed char		length_min;	/* 0 ... 59 */
574 
575 	signed char		elapsed_hour;	/* 0 ... 63 */
576 	signed char		elapsed_min;	/* 0 ... 59 */
577 	signed char		elapsed_sec;	/* 0 ... 59 */
578 
579 	/* 03 Program name */
580 
581 	/* If unknown title[0] == 0 */
582 	signed char		title[64];	/* ASCII + '\0' */
583 
584 	/* 04 Program type */
585 
586 	/*
587 	 *  If unknown type_classf == VBI_PROG_CLASSF_NONE.
588 	 *  VBI_PROG_CLASSF_EIA_608 can have up to 32 tags
589 	 *  identifying 96 keywords. Their numerical value
590 	 *  is given here instead of composing a string for
591 	 *  easier filtering. Use vbi_prog_type_str_by_id to
592 	 *  get the keywords. A zero marks the end.
593 	 */
594 	vbi_prog_classf		type_classf;
595 	int			type_id[33];
596 
597 	/* 05 Program rating */
598 
599 	/*
600 	 *  For details STFW for "v-chip"
601 	 *  If unknown rating_auth == VBI_RATING_NONE
602 	 */
603 	vbi_rating_auth		rating_auth;
604 	int			rating_id;
605 
606 	/* Only valid when auth == VBI_RATING_TV_US */
607 	int			rating_dlsv;
608 
609 	/* 06 Program Audio Services */
610 
611 	/*
612 	 *  BTSC audio (two independent tracks) is flagged according to XDS,
613 	 *  Zweiton/NICAM/EIA-J audio is flagged mono/none, stereo/none or
614 	 *  mono/mono for bilingual transmissions.
615 	 */
616 	struct {
617 		/* If unknown mode == VBI_AUDIO_MODE_UNKNOWN */
618 		vbi_audio_mode		mode;
619 		/* If unknown language == NULL */
620 		unsigned char *		language; /* Latin-1 */
621 	}			audio[2];	/* primary and secondary */
622 
623 	/* 07 Program Caption Services */
624 
625 	/*
626 	 *  Bits 0...7 corresponding to Caption page 1...8.
627 	 *  Note for the current program this information is also
628 	 *  available via vbi_classify_page().
629 	 *
630 	 *  If unknown caption_services == -1, _language[] = NULL
631 	 */
632 	int			caption_services;
633 	unsigned char *		caption_language[8]; /* Latin-1 */
634 
635 	/* 08 Copy Generation Management System */
636 
637 	/* If unknown cgms_a == -1 */
638 	int			cgms_a; /* XXX */
639 
640 	/* 09 Aspect Ratio */
641 
642 	/*
643 	 *  Note for the current program this information is also
644 	 *  available via VBI_EVENT_ASPECT.
645 	 *
646 	 *  If unknown first_line == last_line == -1, ratio == 0.0
647 	 */
648 	vbi_aspect_ratio	aspect;
649 
650 	/* 10 - 17 Program Description */
651 
652 	/*
653 	 *  8 rows of 0...32 ASCII chars + '\0',
654 	 *  if unknown description[0...7][0] == 0
655 	 */
656 	signed char		description[8][33];
657 } vbi_program_info;
658 
659 extern void		vbi_reset_prog_info(vbi_program_info *pi);
660 
661 
662 
663 #define VBI_EVENT_NONE		0x0000
664 #define	VBI_EVENT_CLOSE		0x0001
665 #define	VBI_EVENT_TTX_PAGE	0x0002
666 #define VBI_EVENT_CAPTION	0x0004
667 #define	VBI_EVENT_NETWORK	0x0008
668 #define	VBI_EVENT_TRIGGER	0x0010
669 #define	VBI_EVENT_ASPECT	0x0040
670 #define	VBI_EVENT_PROG_INFO	0x0080
671 #define	VBI_EVENT_NETWORK_ID	0x0100
672 #define VBI_EVENT_LOCAL_TIME	0x0400
673 #define VBI_EVENT_PROG_ID	0x0800
674 
675 
676 typedef enum {
677 
678 	VBI_DST_UNKNOWN = 0,
679 
680 	VBI_DST_INCLUDED,
681 
682 
683 	VBI_DST_INACTIVE,
684 
685 	VBI_DST_ACTIVE
686 } vbi_dst_state;
687 
688 typedef struct {
689 
690 	time_t			time;
691 
692 	int			seconds_east;
693 
694 
695 	vbi_bool		seconds_east_valid;
696 
697 	vbi_dst_state		dst_state;
698 } vbi_local_time;
699 
700 /* Experimental CC608 decoder. */
701 #define _VBI_EVENT_CC608 0x1000
702 #define _VBI_EVENT_CC608_STREAM 0x2000
703 struct _vbi_event_cc608_page;
704 struct _vbi_event_cc608_stream;
705 
706 
707 #include <inttypes.h>
708 
709 /* XXX network, aspect, prog_info: should only notify about
710  * changes and provide functions to query current value.
711  */
712 typedef struct vbi_event {
713 	int			type;
714 	union {
715 		struct {
716 		        int			pgno;
717 		        int			subno;
718 			uint8_t *		raw_header;
719 			int			pn_offset;
720 			unsigned int		roll_header : 1;
721 		        unsigned int		header_update : 1;
722 			unsigned int		clock_update : 1;
723 	        }			ttx_page;
724 		struct {
725 			int			pgno;
726 		}			caption;
727 		vbi_network		network;
728                 vbi_link *		trigger;
729                 vbi_aspect_ratio	aspect;
730 		vbi_program_info *	prog_info;
731 		vbi_local_time *	local_time;
732 		vbi_program_id *	prog_id;
733 
734 		/* Experimental. */
735 		struct _vbi_event_cc608_page *		_cc608;
736 		struct _vbi_event_cc608_stream *	_cc608_stream;
737 	}			ev;
738 } vbi_event;
739 
740 typedef void (* vbi_event_handler)(vbi_event *event, void *user_data);
741 
742 extern vbi_bool		vbi_event_handler_add(vbi_decoder *vbi, int event_mask,
743 					      vbi_event_handler handler,
744 					      void *user_data);
745 extern void		vbi_event_handler_remove(vbi_decoder *vbi,
746 						 vbi_event_handler handler);
747 extern vbi_bool		vbi_event_handler_register(vbi_decoder *vbi, int event_mask,
748 						   vbi_event_handler handler,
749 						   void *user_data);
750 extern void		vbi_event_handler_unregister(vbi_decoder *vbi,
751 						     vbi_event_handler handler,
752 						     void *user_data);
753 
754 
755 /* format.h */
756 
757 #include <inttypes.h>
758 
759 
760 /* Code depends on order, don't change. */
761 typedef enum {
762 	VBI_BLACK,
763 	VBI_RED,
764 	VBI_GREEN,
765 	VBI_YELLOW,
766 	VBI_BLUE,
767 	VBI_MAGENTA,
768 	VBI_CYAN,
769 	VBI_WHITE
770 } vbi_color;
771 
772 typedef uint32_t vbi_rgba;
773 
774 
775 typedef enum {
776 	VBI_TRANSPARENT_SPACE,
777 	VBI_TRANSPARENT_FULL,
778 	VBI_SEMI_TRANSPARENT,
779 	VBI_OPAQUE
780 } vbi_opacity;
781 
782 /* Code depends on order, don't change. */
783 typedef enum {
784 	VBI_NORMAL_SIZE, VBI_DOUBLE_WIDTH, VBI_DOUBLE_HEIGHT, VBI_DOUBLE_SIZE,
785 	VBI_OVER_TOP, VBI_OVER_BOTTOM, VBI_DOUBLE_HEIGHT2, VBI_DOUBLE_SIZE2
786 } vbi_size;
787 
788 typedef struct vbi_char {
789 	unsigned	underline	: 1;
790 	unsigned	bold		: 1;
791 	unsigned	italic		: 1;
792 	unsigned	flash		: 1;
793 	unsigned	conceal		: 1;
794 	unsigned	proportional	: 1;
795 	unsigned	link		: 1;
796 	unsigned	reserved	: 1;
797 	unsigned	size		: 8;
798 	unsigned	opacity		: 8;
799 	unsigned	foreground	: 8;
800 	unsigned	background	: 8;
801 	unsigned	drcs_clut_offs	: 8;
802 	unsigned	unicode		: 16;
803 } vbi_char;
804 
805 struct vbi_font_descr;
806 
807 typedef struct vbi_page {
808 	vbi_decoder *		vbi;
809 
810         vbi_nuid	       	nuid;
811 	/* FIXME this shouldn't be int */
812  	int			pgno;
813 	/* FIXME this shouldn't be int */
814 	int			subno;
815 	int			rows;
816 	int			columns;
817 	vbi_char		text[1056];
818 
819 	struct {
820 	     /* int			x0, x1; */
821 		int			y0, y1;
822 		int			roll;
823 	}			dirty;
824 
825 	vbi_color		screen_color;
826 	vbi_opacity		screen_opacity;
827 	vbi_rgba 		color_map[40];
828 
829 	uint8_t *		drcs_clut;		/* 64 entries */
830 	uint8_t *		drcs[32];
831 
832 	struct {
833 		int			pgno, subno;
834 	}			nav_link[6];
835 	char			nav_index[64];
836 
837 	struct vbi_font_descr *	font[2];
838 	unsigned int		double_height_lower;	/* legacy */
839 
840 	vbi_opacity		page_opacity[2];
841 	vbi_opacity		boxed_opacity[2];
842 } vbi_page;
843 
844 /* lang.h */
845 
846 typedef struct vbi_font_descr vbi_font_descr;
847 
848 _vbi_inline vbi_bool
vbi_is_print(unsigned int unicode)849 vbi_is_print(unsigned int unicode)
850 {
851 	return unicode < 0xE600;
852 }
853 
854 _vbi_inline vbi_bool
vbi_is_gfx(unsigned int unicode)855 vbi_is_gfx(unsigned int unicode)
856 {
857 	return unicode >= 0xEE00 && unicode <= 0xEFFF;
858 }
859 
860 _vbi_inline vbi_bool
vbi_is_drcs(unsigned int unicode)861 vbi_is_drcs(unsigned int unicode)
862 {
863 	return unicode >= 0xF000;
864 }
865 
866 extern unsigned int
867 vbi_caption_unicode		(unsigned int		c,
868 				 vbi_bool		to_upper);
869 
870 /* export.h */
871 
872 #include <stdio.h> /* FILE */
873 #include <sys/types.h> /* size_t, ssize_t */
874 
875 typedef struct vbi_export vbi_export;
876 
877 typedef struct vbi_export_info {
878 	char *			keyword;
879 	char *			label;
880 	char *			tooltip;
881 	char *			mime_type;
882 	char *			extension;
883 } vbi_export_info;
884 
885 typedef enum {
886 	VBI_OPTION_BOOL = 1,
887 
888 	VBI_OPTION_INT,
889 
890 	VBI_OPTION_REAL,
891 
892 	VBI_OPTION_STRING,
893 
894 	VBI_OPTION_MENU
895 } vbi_option_type;
896 
897 typedef union {
898 	int			num;
899 	double			dbl;
900 	char *			str;
901 } vbi_option_value;
902 
903 typedef union {
904 	int *			num;
905 	double *		dbl;
906 	char **			str;
907 } vbi_option_value_ptr;
908 
909 typedef struct {
910   	vbi_option_type		type;
911 
912 	char *			keyword;
913 
914 	char *			label;
915 
916 	vbi_option_value	def;
917 	vbi_option_value	min;
918 	vbi_option_value	max;
919 	vbi_option_value	step;
920 	vbi_option_value_ptr	menu;
921 
922 	char *			tooltip;
923 } vbi_option_info;
924 
925 extern vbi_export_info *	vbi_export_info_enum(int index);
926 extern vbi_export_info *	vbi_export_info_keyword(const char *keyword);
927 extern vbi_export_info *	vbi_export_info_export(vbi_export *);
928 
929 extern vbi_export *		vbi_export_new(const char *keyword, char **errstr);
930 extern void			vbi_export_delete(vbi_export *);
931 
932 extern vbi_option_info *	vbi_export_option_info_enum(vbi_export *, int index);
933 extern vbi_option_info *	vbi_export_option_info_keyword(vbi_export *, const char *keyword);
934 
935 extern vbi_bool			vbi_export_option_set(vbi_export *, const char *keyword, ...);
936 extern vbi_bool			vbi_export_option_get(vbi_export *, const char *keyword,
937 						      vbi_option_value *value);
938 extern vbi_bool			vbi_export_option_menu_set(vbi_export *, const char *keyword, int entry);
939 extern vbi_bool			vbi_export_option_menu_get(vbi_export *, const char *keyword, int *entry);
940 
941 extern ssize_t
942 vbi_export_mem			(vbi_export *		e,
943 				 void *			buffer,
944 				 size_t			buffer_size,
945 				 const vbi_page *	pg)
946   _vbi_nonnull ((1)); /* sic */
947 extern void *
948 vbi_export_alloc		(vbi_export *		e,
949 				 void **		buffer,
950 				 size_t *		buffer_size,
951 				 const vbi_page *	pg)
952   _vbi_nonnull ((1)); /* sic */
953 extern vbi_bool			vbi_export_stdio(vbi_export *, FILE *fp, vbi_page *pg);
954 extern vbi_bool			vbi_export_file(vbi_export *, const char *name, vbi_page *pg);
955 
956 extern char *			vbi_export_errstr(vbi_export *);
957 
958 
959 /* cache.h */
960 
961 extern void             vbi_unref_page(vbi_page *pg);
962 extern int              vbi_is_cached(vbi_decoder *, int pgno, int subno);
963 extern int              vbi_cache_hi_subno(vbi_decoder *vbi, int pgno);
964 
965 
966 /* search.h */
967 
968 typedef enum {
969 	VBI_SEARCH_ERROR = -3,
970 	VBI_SEARCH_CACHE_EMPTY,
971 	VBI_SEARCH_CANCELED,
972 	VBI_SEARCH_NOT_FOUND = 0,
973 	VBI_SEARCH_SUCCESS
974 } vbi_search_status;
975 
976 typedef struct vbi_search vbi_search;
977 
978 extern vbi_search *	vbi_search_new(vbi_decoder *vbi,
979 				       vbi_pgno pgno, vbi_subno subno,
980 				       uint16_t *pattern,
981 				       vbi_bool casefold, vbi_bool regexp,
982 				       int (* progress)(vbi_page *pg));
983 extern void		vbi_search_delete(vbi_search *search);
984 extern vbi_search_status vbi_search_next(vbi_search *search, vbi_page **pg, int dir);
985 
986 
987 /* sliced.h */
988 
989 #include <inttypes.h>
990 
991 
992 
993 #define VBI_SLICED_NONE			0
994 
995 #define VBI_SLICED_UNKNOWN              0
996 
997 #define VBI_SLICED_ANTIOPE              0x00002000
998 #define VBI_SLICED_TELETEXT_A           0x00002000
999 
1000 #define VBI_SLICED_TELETEXT_B_L10_625	0x00000001
1001 #define VBI_SLICED_TELETEXT_B_L25_625	0x00000002
1002 #define VBI_SLICED_TELETEXT_B		(VBI_SLICED_TELETEXT_B_L10_625 | \
1003 					 VBI_SLICED_TELETEXT_B_L25_625)
1004 #define VBI_SLICED_TELETEXT_B_625	VBI_SLICED_TELETEXT_B
1005 
1006 #define VBI_SLICED_TELETEXT_C_625       0x00004000
1007 
1008 #define VBI_SLICED_TELETEXT_D_625       0x00008000
1009 
1010 #define VBI_SLICED_VPS                  0x00000004
1011 
1012 #define VBI_SLICED_VPS_F2               0x00001000
1013 
1014 #define VBI_SLICED_CAPTION_625_F1       0x00000008
1015 #define VBI_SLICED_CAPTION_625_F2       0x00000010
1016 #define VBI_SLICED_CAPTION_625		(VBI_SLICED_CAPTION_625_F1 | \
1017                                          VBI_SLICED_CAPTION_625_F2)
1018 
1019 #define VBI_SLICED_WSS_625              0x00000400
1020 
1021 #define VBI_SLICED_CAPTION_525_F1	0x00000020
1022 #define VBI_SLICED_CAPTION_525_F2	0x00000040
1023 #define VBI_SLICED_CAPTION_525		(VBI_SLICED_CAPTION_525_F1 | \
1024 					 VBI_SLICED_CAPTION_525_F2)
1025 #define VBI_SLICED_2xCAPTION_525	0x00000080
1026 
1027 #define VBI_SLICED_TELETEXT_B_525       0x00010000
1028 
1029 #define VBI_SLICED_NABTS                0x00000100
1030 
1031 #define VBI_SLICED_TELETEXT_C_525       0x00000100
1032 
1033 #define VBI_SLICED_TELETEXT_BD_525	0x00000200
1034 
1035 #define VBI_SLICED_TELETEXT_D_525       0x00020000
1036 
1037 
1038 #define VBI_SLICED_WSS_CPR1204		0x00000800
1039 
1040 #define VBI_SLICED_VBI_625		0x20000000
1041 
1042 #define VBI_SLICED_VBI_525		0x40000000
1043 
1044 
1045 
1046 typedef unsigned int vbi_service_set;
1047 
1048 typedef struct {
1049 	uint32_t		id;
1050 	uint32_t		line;
1051 	uint8_t			data[56];
1052 } vbi_sliced;
1053 
1054 extern const char *
1055 vbi_sliced_name			(vbi_service_set	service)
1056   _vbi_const;
1057 extern unsigned int
1058 vbi_sliced_payload_bits		(vbi_service_set	service)
1059   _vbi_const;
1060 
1061 
1062 /* decoder.h */
1063 
1064 #include <pthread.h>
1065 
1066 /* Bit slicer */
1067 
1068 /* Attn: keep this in sync with rte, don't change order */
1069 typedef enum {
1070 	VBI_PIXFMT_YUV420 = 1,
1071 	VBI_PIXFMT_YUYV,
1072 	VBI_PIXFMT_YVYU,
1073 	VBI_PIXFMT_UYVY,
1074 	VBI_PIXFMT_VYUY,
1075         VBI_PIXFMT_PAL8,
1076 	VBI_PIXFMT_RGBA32_LE = 32,
1077 	VBI_PIXFMT_RGBA32_BE,
1078 	VBI_PIXFMT_BGRA32_LE,
1079 	VBI_PIXFMT_BGRA32_BE,
1080 	VBI_PIXFMT_ABGR32_BE = 32, /* synonyms */
1081 	VBI_PIXFMT_ABGR32_LE,
1082 	VBI_PIXFMT_ARGB32_BE,
1083 	VBI_PIXFMT_ARGB32_LE,
1084 	VBI_PIXFMT_RGB24,
1085 	VBI_PIXFMT_BGR24,
1086 	VBI_PIXFMT_RGB16_LE,
1087 	VBI_PIXFMT_RGB16_BE,
1088 	VBI_PIXFMT_BGR16_LE,
1089 	VBI_PIXFMT_BGR16_BE,
1090 	VBI_PIXFMT_RGBA15_LE,
1091 	VBI_PIXFMT_RGBA15_BE,
1092 	VBI_PIXFMT_BGRA15_LE,
1093 	VBI_PIXFMT_BGRA15_BE,
1094 	VBI_PIXFMT_ARGB15_LE,
1095 	VBI_PIXFMT_ARGB15_BE,
1096 	VBI_PIXFMT_ABGR15_LE,
1097 	VBI_PIXFMT_ABGR15_BE
1098 } vbi_pixfmt;
1099 
1100 
1101 typedef enum {
1102 	VBI_MODULATION_NRZ_LSB,
1103 	VBI_MODULATION_NRZ_MSB,
1104 	VBI_MODULATION_BIPHASE_LSB,
1105 	VBI_MODULATION_BIPHASE_MSB
1106 } vbi_modulation;
1107 
1108 typedef struct vbi_bit_slicer {
1109 	vbi_bool	(* func)(struct vbi_bit_slicer *slicer,
1110 				 uint8_t *raw, uint8_t *buf);
1111 	unsigned int	cri;
1112 	unsigned int	cri_mask;
1113 	int		thresh;
1114 	int		cri_bytes;
1115 	int		cri_rate;
1116 	int		oversampling_rate;
1117 	int		phase_shift;
1118 	int		step;
1119 	unsigned int	frc;
1120 	int		frc_bits;
1121 	int		payload;
1122 	int		endian;
1123 	int		skip;
1124 } vbi_bit_slicer;
1125 
1126 extern void		vbi_bit_slicer_init(vbi_bit_slicer *slicer,
1127 					    int raw_samples, int sampling_rate,
1128 					    int cri_rate, int bit_rate,
1129 					    unsigned int cri_frc, unsigned int cri_mask,
1130 					    int cri_bits, int frc_bits, int payload,
1131 					    vbi_modulation modulation, vbi_pixfmt fmt);
1132 _vbi_inline vbi_bool
vbi_bit_slice(vbi_bit_slicer * slicer,uint8_t * raw,uint8_t * buf)1133 vbi_bit_slice(vbi_bit_slicer *slicer, uint8_t *raw, uint8_t *buf)
1134 {
1135 	return slicer->func(slicer, raw, buf);
1136 }
1137 
1138 
1139 typedef struct vbi_raw_decoder {
1140 	/* Sampling parameters */
1141 
1142 	int			scanning;
1143 	vbi_pixfmt		sampling_format;
1144 	int			sampling_rate;		/* Hz */
1145 	int			bytes_per_line;
1146 	int			offset;			/* 0H, samples */
1147 	int			start[2];		/* ITU-R numbering */
1148 	int			count[2];		/* field lines */
1149 	vbi_bool		interlaced;
1150 	vbi_bool		synchronous;
1151 
1152 	/*< private >*/
1153 
1154 	pthread_mutex_t		mutex;
1155 
1156 	unsigned int		services;
1157 	int			num_jobs;
1158 
1159 	int8_t *		pattern;
1160 	struct _vbi_raw_decoder_job {
1161 		unsigned int		id;
1162 		int			offset;
1163 		vbi_bit_slicer		slicer;
1164 	}			jobs[8];
1165 } vbi_raw_decoder;
1166 
1167 extern void		vbi_raw_decoder_init(vbi_raw_decoder *rd);
1168 extern void		vbi_raw_decoder_reset(vbi_raw_decoder *rd);
1169 extern void		vbi_raw_decoder_destroy(vbi_raw_decoder *rd);
1170 extern unsigned int	vbi_raw_decoder_add_services(vbi_raw_decoder *rd,
1171 						     unsigned int services,
1172 						     int strict);
1173 extern unsigned int     vbi_raw_decoder_check_services(vbi_raw_decoder *rd,
1174 						     unsigned int services, int strict);
1175 extern unsigned int	vbi_raw_decoder_remove_services(vbi_raw_decoder *rd,
1176 							unsigned int services);
1177 extern void             vbi_raw_decoder_resize( vbi_raw_decoder *rd,
1178 						int * start, unsigned int * count );
1179 extern unsigned int	vbi_raw_decoder_parameters(vbi_raw_decoder *rd, unsigned int services,
1180 						   int scanning, int *max_rate);
1181 extern int		vbi_raw_decode(vbi_raw_decoder *rd, uint8_t *raw, vbi_sliced *out);
1182 
1183 
1184 /* sampling_par.h */
1185 
1186 typedef vbi_raw_decoder vbi_sampling_par;
1187 
1188 #define VBI_VIDEOSTD_SET_EMPTY 0
1189 #define VBI_VIDEOSTD_SET_PAL_BG 1
1190 #define VBI_VIDEOSTD_SET_625_50 1
1191 #define VBI_VIDEOSTD_SET_525_60 2
1192 #define VBI_VIDEOSTD_SET_ALL 3
1193 typedef uint64_t vbi_videostd_set;
1194 
1195 /* dvb_demux.h */
1196 
1197 
1198 typedef struct _vbi_dvb_demux vbi_dvb_demux;
1199 
1200 typedef vbi_bool
1201 vbi_dvb_demux_cb		(vbi_dvb_demux *	dx,
1202 				 void *			user_data,
1203 				 const vbi_sliced *	sliced,
1204 				 unsigned int		sliced_lines,
1205 				 int64_t		pts);
1206 
1207 extern void
1208 vbi_dvb_demux_reset		(vbi_dvb_demux *	dx);
1209 extern unsigned int
1210 vbi_dvb_demux_cor		(vbi_dvb_demux *	dx,
1211 				 vbi_sliced *		sliced,
1212 				 unsigned int 		sliced_lines,
1213 				 int64_t *		pts,
1214 				 const uint8_t **	buffer,
1215 				 unsigned int *		buffer_left);
1216 extern vbi_bool
1217 vbi_dvb_demux_feed		(vbi_dvb_demux *	dx,
1218 				 const uint8_t *	buffer,
1219 				 unsigned int		buffer_size);
1220 extern void
1221 vbi_dvb_demux_set_log_fn	(vbi_dvb_demux *	dx,
1222 				 vbi_log_mask		mask,
1223 				 vbi_log_fn *		log_fn,
1224 				 void *			user_data);
1225 extern void
1226 vbi_dvb_demux_delete		(vbi_dvb_demux *	dx);
1227 extern vbi_dvb_demux *
1228 vbi_dvb_pes_demux_new		(vbi_dvb_demux_cb *	callback,
1229 				 void *			user_data);
1230 
1231 
1232 
1233 /* dvb_mux.h */
1234 
1235 
1236 extern vbi_bool
1237 vbi_dvb_multiplex_sliced	(uint8_t **		packet,
1238 				 unsigned int *		packet_left,
1239 				 const vbi_sliced **	sliced,
1240 				 unsigned int *		sliced_left,
1241 				 vbi_service_set	service_mask,
1242 				 unsigned int		data_identifier,
1243 				 vbi_bool		stuffing)
1244 #ifndef DOXYGEN_SHOULD_SKIP_THIS
1245   _vbi_nonnull ((1, 2, 3, 4))
1246 #endif
1247   ;
1248 extern vbi_bool
1249 vbi_dvb_multiplex_raw		(uint8_t **		packet,
1250 				 unsigned int *		packet_left,
1251 				 const uint8_t **	raw,
1252 				 unsigned int *		raw_left,
1253 				 unsigned int		data_identifier,
1254 				 vbi_videostd_set	videostd_set,
1255 				 unsigned int		line,
1256 				 unsigned int		first_pixel_position,
1257 				 unsigned int		n_pixels_total,
1258 				 vbi_bool		stuffing)
1259 #ifndef DOXYGEN_SHOULD_SKIP_THIS
1260   _vbi_nonnull ((1, 2, 3, 4))
1261 #endif
1262   ;
1263 
1264 typedef struct _vbi_dvb_mux vbi_dvb_mux;
1265 
1266 typedef vbi_bool
1267 vbi_dvb_mux_cb			(vbi_dvb_mux *		mx,
1268 				 void *			user_data,
1269 				 const uint8_t *	packet,
1270 				 unsigned int		packet_size);
1271 
1272 extern void
1273 vbi_dvb_mux_reset		(vbi_dvb_mux *		mx)
1274   _vbi_nonnull ((1));
1275 extern vbi_bool
1276 vbi_dvb_mux_cor		(vbi_dvb_mux *		mx,
1277 				 uint8_t **		buffer,
1278 				 unsigned int *		buffer_left,
1279 				 const vbi_sliced **	sliced,
1280 				 unsigned int *		sliced_lines,
1281 				 vbi_service_set	service_mask,
1282 				 const uint8_t *	raw,
1283 				 const vbi_sampling_par *sampling_par,
1284 				 int64_t		pts)
1285 #ifndef DOXYGEN_SHOULD_SKIP_THIS
1286   _vbi_nonnull ((1, 2, 3, 4, 5))
1287 #endif
1288   ;
1289 extern vbi_bool
1290 vbi_dvb_mux_feed		(vbi_dvb_mux *		mx,
1291 				 const vbi_sliced *	sliced,
1292 				 unsigned int		sliced_lines,
1293 				 vbi_service_set	service_mask,
1294 				 const uint8_t *	raw,
1295 				 const vbi_sampling_par *sampling_par,
1296 				 int64_t		pts)
1297   _vbi_nonnull ((1));
1298 extern unsigned int
1299 vbi_dvb_mux_get_data_identifier (const vbi_dvb_mux *	mx)
1300   _vbi_nonnull ((1));
1301 extern vbi_bool
1302 vbi_dvb_mux_set_data_identifier (vbi_dvb_mux *	mx,
1303 				  unsigned int		data_identifier)
1304   _vbi_nonnull ((1));
1305 extern unsigned int
1306 vbi_dvb_mux_get_min_pes_packet_size
1307 				(vbi_dvb_mux *		mx)
1308   _vbi_nonnull ((1));
1309 extern unsigned int
1310 vbi_dvb_mux_get_max_pes_packet_size
1311 				(vbi_dvb_mux *		mx)
1312   _vbi_nonnull ((1));
1313 extern vbi_bool
1314 vbi_dvb_mux_set_pes_packet_size (vbi_dvb_mux *	mx,
1315 				  unsigned int		min_size,
1316 				  unsigned int		max_size)
1317   _vbi_nonnull ((1));
1318 extern void
1319 vbi_dvb_mux_delete		(vbi_dvb_mux *		mx);
1320 extern vbi_dvb_mux *
1321 vbi_dvb_pes_mux_new		(vbi_dvb_mux_cb *	callback,
1322 				 void *			user_data)
1323   _vbi_alloc;
1324 extern vbi_dvb_mux *
1325 vbi_dvb_ts_mux_new		(unsigned int		pid,
1326 				 vbi_dvb_mux_cb *	callback,
1327 				 void *			user_data)
1328   _vbi_alloc;
1329 
1330 
1331 
1332 /* idl_demux.h */
1333 
1334 
1335 typedef struct _vbi_idl_demux vbi_idl_demux;
1336 
1337 
1338 
1339 #define VBI_IDL_DATA_LOST	(1 << 0)
1340 
1341 #define VBI_IDL_DEPENDENT	(1 << 3)
1342 
1343 
1344 
1345 
1346 typedef vbi_bool
1347 vbi_idl_demux_cb		(vbi_idl_demux *	dx,
1348 				 const uint8_t *	buffer,
1349 				 unsigned int		n_bytes,
1350 				 unsigned int		flags,
1351 				 void *			user_data);
1352 
1353 extern void
1354 vbi_idl_demux_reset		(vbi_idl_demux *	dx)
1355   _vbi_nonnull ((1));
1356 extern vbi_bool
1357 vbi_idl_demux_feed		(vbi_idl_demux *	dx,
1358 				 const uint8_t		buffer[42])
1359 #ifndef DOXYGEN_SHOULD_SKIP_THIS
1360   _vbi_nonnull ((1, 2))
1361 #endif
1362   ;
1363 extern vbi_bool
1364 vbi_idl_demux_feed_frame	(vbi_idl_demux *	dx,
1365 				 const vbi_sliced *	sliced,
1366 				 unsigned int		n_lines)
1367 #ifndef DOXYGEN_SHOULD_SKIP_THIS
1368   _vbi_nonnull ((1, 2))
1369 #endif
1370   ;
1371 extern void
1372 vbi_idl_demux_delete		(vbi_idl_demux *	dx);
1373 extern vbi_idl_demux *
1374 vbi_idl_a_demux_new		(unsigned int		channel,
1375 				 unsigned int		address,
1376 				 vbi_idl_demux_cb *	callback,
1377 				 void *			user_data)
1378 #ifndef DOXYGEN_SHOULD_SKIP_THIS
1379   _vbi_alloc _vbi_nonnull ((3))
1380 #endif
1381   ;
1382 
1383 
1384 
1385 /* pfc_demux.h */
1386 
1387 
1388 typedef struct {
1389 
1390 	vbi_pgno		pgno;
1391 
1392 
1393 	unsigned int		stream;
1394 
1395 
1396 	unsigned int		application_id;
1397 
1398 
1399 	unsigned int		block_size;
1400 
1401 
1402 	uint8_t			block[2048];
1403 } vbi_pfc_block;
1404 
1405 typedef struct _vbi_pfc_demux vbi_pfc_demux;
1406 
1407 typedef vbi_bool
1408 vbi_pfc_demux_cb		(vbi_pfc_demux *	dx,
1409 				 void *			user_data,
1410 				 const vbi_pfc_block *	block);
1411 
1412 extern void
1413 vbi_pfc_demux_reset		(vbi_pfc_demux *	dx)
1414   _vbi_nonnull ((1));
1415 extern vbi_bool
1416 vbi_pfc_demux_feed		(vbi_pfc_demux *	dx,
1417 				 const uint8_t		buffer[42])
1418 #ifndef DOXYGEN_SHOULD_SKIP_THIS
1419   _vbi_nonnull ((1, 2))
1420 #endif
1421   ;
1422 extern vbi_bool
1423 vbi_pfc_demux_feed_frame	(vbi_pfc_demux *	dx,
1424 				 const vbi_sliced *	sliced,
1425 				 unsigned int		n_lines)
1426 #ifndef DOXYGEN_SHOULD_SKIP_THIS
1427   _vbi_nonnull ((1, 2))
1428 #endif
1429   ;
1430 extern void
1431 vbi_pfc_demux_delete		(vbi_pfc_demux *	dx);
1432 extern vbi_pfc_demux *
1433 vbi_pfc_demux_new		(vbi_pgno		pgno,
1434 				 unsigned int		stream,
1435 				 vbi_pfc_demux_cb *	callback,
1436 				 void *			user_data)
1437 #ifndef DOXYGEN_SHOULD_SKIP_THIS
1438   _vbi_alloc _vbi_nonnull ((3))
1439 #endif
1440   ;
1441 
1442 
1443 
1444 /* xds_demux.h */
1445 
1446 
1447 typedef enum {
1448 	VBI_XDS_CLASS_CURRENT = 0x00,
1449 	VBI_XDS_CLASS_FUTURE,
1450 	VBI_XDS_CLASS_CHANNEL,
1451 	VBI_XDS_CLASS_MISC,
1452 	VBI_XDS_CLASS_PUBLIC_SERVICE,
1453 	VBI_XDS_CLASS_RESERVED,
1454 	VBI_XDS_CLASS_UNDEFINED
1455 } vbi_xds_class;
1456 
1457 #define VBI_XDS_MAX_CLASSES (VBI_XDS_CLASS_UNDEFINED + 1)
1458 
1459 typedef enum {
1460 	VBI_XDS_PROGRAM_ID = 0x01,
1461 	VBI_XDS_PROGRAM_LENGTH,
1462 	VBI_XDS_PROGRAM_NAME,
1463 	VBI_XDS_PROGRAM_TYPE,
1464 	VBI_XDS_PROGRAM_RATING,
1465 	VBI_XDS_PROGRAM_AUDIO_SERVICES,
1466 	VBI_XDS_PROGRAM_CAPTION_SERVICES,
1467 	VBI_XDS_PROGRAM_CGMS,
1468 	VBI_XDS_PROGRAM_ASPECT_RATIO,
1469 
1470 	VBI_XDS_PROGRAM_DATA = 0x0C,
1471 
1472 	VBI_XDS_PROGRAM_MISC_DATA,
1473 	VBI_XDS_PROGRAM_DESCRIPTION_BEGIN = 0x10,
1474 	VBI_XDS_PROGRAM_DESCRIPTION_END = 0x18
1475 } vbi_xds_subclass_program;
1476 
1477 
1478 typedef enum {
1479 	VBI_XDS_CHANNEL_NAME = 0x01,
1480 	VBI_XDS_CHANNEL_CALL_LETTERS,
1481 	VBI_XDS_CHANNEL_TAPE_DELAY,
1482 
1483 	VBI_XDS_CHANNEL_TSID
1484 } vbi_xds_subclass_channel;
1485 
1486 
1487 typedef enum {
1488 	VBI_XDS_TIME_OF_DAY = 0x01,
1489 	VBI_XDS_IMPULSE_CAPTURE_ID,
1490 	VBI_XDS_SUPPLEMENTAL_DATA_LOCATION,
1491 	VBI_XDS_LOCAL_TIME_ZONE,
1492 
1493 	VBI_XDS_OUT_OF_BAND_CHANNEL = 0x40,
1494 
1495 	VBI_XDS_CHANNEL_MAP_POINTER,
1496 
1497 	VBI_XDS_CHANNEL_MAP_HEADER,
1498 
1499 	VBI_XDS_CHANNEL_MAP
1500 } vbi_xds_subclass_misc;
1501 
1502 #ifndef DOXYGEN_SHOULD_SKIP_THIS
1503 
1504 /* Compatibility. */
1505 #define VBI_XDS_MISC_TIME_OF_DAY VBI_XDS_TIME_OF_DAY
1506 #define VBI_XDS_MISC_IMPULSE_CAPTURE_ID VBI_XDS_IMPULSE_CAPTURE_ID
1507 #define VBI_XDS_MISC_SUPPLEMENTAL_DATA_LOCATION \
1508 	VBI_XDS_SUPPLEMENTAL_DATA_LOCATION
1509 #define VBI_XDS_MISC_LOCAL_TIME_ZONE VBI_XDS_LOCAL_TIME_ZONE
1510 
1511 #endif /* DOXYGEN_SHOULD_SKIP_THIS */
1512 
1513 typedef enum {
1514 	VBI_XDS_WEATHER_BULLETIN = 0x01,
1515 	VBI_XDS_WEATHER_MESSAGE
1516 } vbi_xds_subclass_public_service;
1517 
1518 #define VBI_XDS_MAX_SUBCLASSES (0x18)
1519 
1520 typedef unsigned int vbi_xds_subclass;
1521 
1522 typedef struct {
1523 	vbi_xds_class		xds_class;
1524 	vbi_xds_subclass	xds_subclass;
1525 
1526 
1527 	unsigned int		buffer_size;
1528 
1529 	uint8_t			buffer[36];
1530 } vbi_xds_packet;
1531 
1532 
1533 
1534 extern void
1535 _vbi_xds_packet_dump		(const vbi_xds_packet *	xp,
1536 				 FILE *			fp);
1537 
1538 
1539 typedef struct _vbi_xds_demux vbi_xds_demux;
1540 
1541 typedef vbi_bool
1542 vbi_xds_demux_cb		(vbi_xds_demux *	xd,
1543 				 const vbi_xds_packet *	xp,
1544 				 void *			user_data);
1545 
1546 extern void
1547 vbi_xds_demux_reset		(vbi_xds_demux *	xd);
1548 extern vbi_bool
1549 vbi_xds_demux_feed		(vbi_xds_demux *	xd,
1550 				 const uint8_t		buffer[2]);
1551 extern vbi_bool
1552 vbi_xds_demux_feed_frame	(vbi_xds_demux *	xd,
1553 				 const vbi_sliced *	sliced,
1554 				 unsigned int		n_lines);
1555 extern void
1556 vbi_xds_demux_delete		(vbi_xds_demux *	xd);
1557 extern vbi_xds_demux *
1558 vbi_xds_demux_new		(vbi_xds_demux_cb *	callback,
1559 				 void *			user_data)
1560   _vbi_alloc;
1561 
1562 
1563 
1564 /* io.h */
1565 
1566 #include <sys/time.h> /* struct timeval */
1567 
1568 typedef struct vbi_capture_buffer {
1569 	void *			data;
1570 	int			size;
1571 	double			timestamp;
1572 } vbi_capture_buffer;
1573 
1574 typedef struct vbi_capture vbi_capture;
1575 
1576 typedef enum {
1577         VBI_FD_HAS_SELECT  = 1<<0,
1578         VBI_FD_HAS_MMAP    = 1<<1,
1579         VBI_FD_IS_DEVICE   = 1<<2
1580 } VBI_CAPTURE_FD_FLAGS;
1581 
1582 extern vbi_capture *	vbi_capture_v4l2_new(const char *dev_name, int buffers,
1583 					     unsigned int *services, int strict,
1584 					     char **errorstr, vbi_bool trace);
1585 extern vbi_capture *	vbi_capture_v4l2k_new(const char *	dev_name,
1586 					      int		fd,
1587 					      int		buffers,
1588 					      unsigned int *	services,
1589 					      int		strict,
1590 					      char **		errorstr,
1591 					      vbi_bool		trace);
1592 extern vbi_capture *	vbi_capture_v4l_new(const char *dev_name, int scanning,
1593 					    unsigned int *services, int strict,
1594 					    char **errorstr, vbi_bool trace);
1595 extern vbi_capture *	vbi_capture_v4l_sidecar_new(const char *dev_name, int given_fd,
1596 						    unsigned int *services,
1597 						    int strict, char **errorstr,
1598 						    vbi_bool trace);
1599 extern vbi_capture *	vbi_capture_bktr_new (const char *	dev_name,
1600 					      int		scanning,
1601 					      unsigned int *	services,
1602 					      int		strict,
1603 					      char **		errstr,
1604 					      vbi_bool		trace);
1605 extern int		vbi_capture_dvb_filter(vbi_capture *cap, int pid);
1606 
1607 /* This function is deprecated. Use vbi_capture_dvb_new2() instead.
1608    See io-dvb.c or the Doxygen documentation for details. */
1609 extern vbi_capture *
1610 vbi_capture_dvb_new		(char *			dev,
1611 				 int			scanning,
1612 				 unsigned int *		services,
1613 				 int			strict,
1614 				 char **		errstr,
1615 				 vbi_bool		trace)
1616   _vbi_deprecated;
1617 
1618 extern int64_t
1619 vbi_capture_dvb_last_pts	(const vbi_capture *	cap);
1620 extern vbi_capture *
1621 vbi_capture_dvb_new2		(const char *		device_name,
1622 				 unsigned int		pid,
1623 				 char **		errstr,
1624 				 vbi_bool		trace);
1625 
1626 struct vbi_proxy_client;
1627 
1628 extern vbi_capture *
1629 vbi_capture_proxy_new( struct vbi_proxy_client * vpc,
1630                         int buffers, int scanning,
1631                         unsigned int *p_services, int strict,
1632                         char **pp_errorstr );
1633 
1634 extern int		vbi_capture_read_raw(vbi_capture *capture, void *data,
1635 					     double *timestamp, struct timeval *timeout);
1636 extern int		vbi_capture_read_sliced(vbi_capture *capture, vbi_sliced *data, int *lines,
1637 						double *timestamp, struct timeval *timeout);
1638 extern int		vbi_capture_read(vbi_capture *capture, void *raw_data,
1639 					 vbi_sliced *sliced_data, int *lines,
1640 					 double *timestamp, struct timeval *timeout);
1641 extern int		vbi_capture_pull_raw(vbi_capture *capture, vbi_capture_buffer **buffer,
1642 					     struct timeval *timeout);
1643 extern int		vbi_capture_pull_sliced(vbi_capture *capture, vbi_capture_buffer **buffer,
1644 						struct timeval *timeout);
1645 extern int		vbi_capture_pull(vbi_capture *capture, vbi_capture_buffer **raw_buffer,
1646 					 vbi_capture_buffer **sliced_buffer, struct timeval *timeout);
1647 extern vbi_raw_decoder *vbi_capture_parameters(vbi_capture *capture);
1648 extern int		vbi_capture_fd(vbi_capture *capture);
1649 extern unsigned int     vbi_capture_update_services(vbi_capture *capture,
1650                                                     vbi_bool reset, vbi_bool commit,
1651                                                     unsigned int services, int strict,
1652                                                     char ** errorstr);
1653 extern int              vbi_capture_get_scanning(vbi_capture *capture);
1654 extern void             vbi_capture_flush(vbi_capture *capture);
1655 extern void		vbi_capture_delete(vbi_capture *capture);
1656 
1657 extern vbi_bool         vbi_capture_set_video_path(vbi_capture *capture, const char * p_dev_video);
1658 extern VBI_CAPTURE_FD_FLAGS vbi_capture_get_fd_flags(vbi_capture *capture);
1659 
1660 
1661 /* io-sim.h */
1662 
1663 extern vbi_bool
1664 vbi_raw_video_image		(uint8_t *		raw,
1665 				 unsigned long		raw_size,
1666 				 const vbi_sampling_par *sp,
1667 				 int			blank_level,
1668 				 int			black_level,
1669 				 int			white_level,
1670 				 unsigned int		pixel_mask,
1671 				 vbi_bool		swap_fields,
1672 				 const vbi_sliced *	sliced,
1673 				 unsigned int		n_sliced_lines);
1674 extern vbi_bool
1675 vbi_raw_add_noise		(uint8_t *		raw,
1676 				 const vbi_sampling_par *sp,
1677 				 unsigned int		min_freq,
1678 				 unsigned int		max_freq,
1679 				 unsigned int		amplitude,
1680 				 unsigned int		seed);
1681 extern vbi_bool
1682 vbi_raw_vbi_image		(uint8_t *		raw,
1683 				 unsigned long		raw_size,
1684 				 const vbi_sampling_par *sp,
1685 				 int			blank_level,
1686 				 int			white_level,
1687 				 vbi_bool		swap_fields,
1688 				 const vbi_sliced *	sliced,
1689 				 unsigned int		n_sliced_lines);
1690 
1691 extern void
1692 vbi_capture_sim_add_noise	(vbi_capture *		cap,
1693 				 unsigned int		min_freq,
1694 				 unsigned int		max_freq,
1695 				 unsigned int		amplitude);
1696 extern vbi_bool
1697 vbi_capture_sim_load_caption	(vbi_capture *		cap,
1698 				 const char *		stream,
1699 				 vbi_bool		append);
1700 #if 3 == VBI_VERSION_MINOR
1701 extern vbi_bool
1702 vbi_capture_sim_load_vps	(vbi_capture *		cap,
1703 				 const vbi_program_id *pid);
1704 extern vbi_bool
1705 vbi_capture_sim_load_wss_625	(vbi_capture *		cap,
1706 				 const vbi_aspect_ratio *ar);
1707 #endif
1708 extern void
1709 vbi_capture_sim_decode_raw	(vbi_capture *		cap,
1710 				 vbi_bool		enable);
1711 extern vbi_capture *
1712 vbi_capture_sim_new		(int			scanning,
1713 				 unsigned int *		services,
1714 				 vbi_bool		interlaced,
1715 				 vbi_bool		synchronous);
1716 
1717 
1718 /* proxy-msg.h */
1719 
1720 typedef enum
1721 {
1722 	VBI_CHN_PRIO_BACKGROUND  = 1,
1723 	VBI_CHN_PRIO_INTERACTIVE = 2,
1724 	VBI_CHN_PRIO_DEFAULT     = VBI_CHN_PRIO_INTERACTIVE,
1725 	VBI_CHN_PRIO_RECORD      = 3
1726 
1727 } VBI_CHN_PRIO;
1728 
1729 typedef enum
1730 {
1731 	VBI_CHN_SUBPRIO_MINIMAL  = 0x00,
1732 	VBI_CHN_SUBPRIO_CHECK    = 0x10,
1733 	VBI_CHN_SUBPRIO_UPDATE   = 0x20,
1734 	VBI_CHN_SUBPRIO_INITIAL  = 0x30,
1735 	VBI_CHN_SUBPRIO_VPS_PDC  = 0x40
1736 
1737 } VBI_CHN_SUBPRIO;
1738 
1739 typedef struct
1740 {
1741 	uint8_t			is_valid;
1742 	uint8_t			sub_prio;
1743 	uint8_t			allow_suspend;
1744 
1745 	uint8_t			reserved0;
1746 	time_t			min_duration;
1747 	time_t			exp_duration;
1748 
1749 	uint8_t			reserved1[16];
1750 } vbi_channel_profile;
1751 
1752 typedef enum
1753 {
1754         VBI_PROXY_DAEMON_NO_TIMEOUTS   = 1<<0
1755 
1756 } VBI_PROXY_DAEMON_FLAGS;
1757 
1758 typedef enum
1759 {
1760         VBI_PROXY_CLIENT_NO_TIMEOUTS   = 1<<0,
1761         VBI_PROXY_CLIENT_NO_STATUS_IND = 1<<1
1762 
1763 } VBI_PROXY_CLIENT_FLAGS;
1764 
1765 typedef enum
1766 {
1767         VBI_PROXY_CHN_RELEASE = 1<<0,
1768         VBI_PROXY_CHN_TOKEN   = 1<<1,
1769         VBI_PROXY_CHN_FLUSH   = 1<<2,
1770         VBI_PROXY_CHN_NORM    = 1<<3,
1771         VBI_PROXY_CHN_FAIL    = 1<<4,
1772 
1773         VBI_PROXY_CHN_NONE    = 0
1774 
1775 } VBI_PROXY_CHN_FLAGS;
1776 
1777 typedef enum
1778 {
1779         VBI_API_UNKNOWN,
1780         VBI_API_V4L1,
1781         VBI_API_V4L2,
1782         VBI_API_BKTR
1783 } VBI_DRIVER_API_REV;
1784 
1785 #define VBIPROXY_VERSION                   0x00000100
1786 #define VBIPROXY_COMPAT_VERSION            0x00000100
1787 
1788 /* proxy-client.h */
1789 
1790 #include <sys/time.h> /* struct timeval */
1791 
1792 typedef struct vbi_proxy_client vbi_proxy_client;
1793 
1794 typedef enum
1795 {
1796    VBI_PROXY_EV_CHN_GRANTED   = 1<<0,
1797    VBI_PROXY_EV_CHN_CHANGED   = 1<<1,
1798    VBI_PROXY_EV_NORM_CHANGED  = 1<<2,
1799    VBI_PROXY_EV_CHN_RECLAIMED = 1<<3,
1800    VBI_PROXY_EV_NONE          = 0
1801 } VBI_PROXY_EV_TYPE;
1802 
1803 typedef void VBI_PROXY_CLIENT_CALLBACK ( void * p_client_data,
1804                                          VBI_PROXY_EV_TYPE ev_mask );
1805 
1806 /* forward declaration from io.h */
1807 struct vbi_capture_buffer;
1808 
1809 extern vbi_proxy_client *
1810 vbi_proxy_client_create( const char *dev_name,
1811                          const char *p_client_name,
1812                          VBI_PROXY_CLIENT_FLAGS client_flags,
1813                          char **pp_errorstr,
1814                          int trace_level );
1815 
1816 extern void
1817 vbi_proxy_client_destroy( vbi_proxy_client * vpc );
1818 
1819 extern vbi_capture *
1820 vbi_proxy_client_get_capture_if( vbi_proxy_client * vpc );
1821 
1822 extern VBI_PROXY_CLIENT_CALLBACK *
1823 vbi_proxy_client_set_callback( vbi_proxy_client * vpc,
1824                                VBI_PROXY_CLIENT_CALLBACK * p_callback,
1825                                void * p_data );
1826 
1827 extern VBI_DRIVER_API_REV
1828 vbi_proxy_client_get_driver_api( vbi_proxy_client * vpc );
1829 
1830 extern int
1831 vbi_proxy_client_channel_request( vbi_proxy_client * vpc,
1832                                   VBI_CHN_PRIO chn_prio,
1833                                   vbi_channel_profile * chn_profile );
1834 
1835 extern int
1836 vbi_proxy_client_channel_notify( vbi_proxy_client * vpc,
1837                                  VBI_PROXY_CHN_FLAGS notify_flags,
1838                                  unsigned int scanning );
1839 
1840 typedef enum
1841 {
1842    VBI_PROXY_SUSPEND_START,
1843    VBI_PROXY_SUSPEND_STOP
1844 } VBI_PROXY_SUSPEND;
1845 
1846 extern int
1847 vbi_proxy_client_channel_suspend( vbi_proxy_client * vpc,
1848                                   VBI_PROXY_SUSPEND cmd );
1849 
1850 int
1851 vbi_proxy_client_device_ioctl( vbi_proxy_client * vpc,
1852                                int request,
1853                                void * p_arg );
1854 
1855 extern int
1856 vbi_proxy_client_get_channel_desc( vbi_proxy_client * vpc,
1857                                    unsigned int * p_scanning,
1858                                    vbi_bool * p_granted );
1859 
1860 extern vbi_bool
1861 vbi_proxy_client_has_channel_control( vbi_proxy_client * vpc );
1862 
1863 
1864 
1865 /* exp-gfx.h */
1866 
1867 extern void		vbi_draw_vt_page_region(vbi_page *pg, vbi_pixfmt fmt,
1868 						void *canvas, int rowstride,
1869 						int column, int row,
1870 						int width, int height,
1871 						int reveal, int flash_on);
1872 _vbi_inline void
vbi_draw_vt_page(vbi_page * pg,vbi_pixfmt fmt,void * canvas,int reveal,int flash_on)1873 vbi_draw_vt_page(vbi_page *pg, vbi_pixfmt fmt, void *canvas,
1874 		 int reveal, int flash_on)
1875 {
1876 	vbi_draw_vt_page_region(pg, fmt, canvas, -1, 0, 0,
1877 				pg->columns, pg->rows, reveal, flash_on);
1878 }
1879 
1880 extern void		vbi_draw_cc_page_region(vbi_page *pg, vbi_pixfmt fmt,
1881 						void *canvas, int rowstride,
1882 						int column, int row,
1883 						int width, int height);
1884 
1885 _vbi_inline void
vbi_draw_cc_page(vbi_page * pg,vbi_pixfmt fmt,void * canvas)1886 vbi_draw_cc_page(vbi_page *pg, vbi_pixfmt fmt, void *canvas)
1887 {
1888 	vbi_draw_cc_page_region(pg, fmt, canvas, -1, 0, 0, pg->columns, pg->rows);
1889 }
1890 
1891 extern void vbi_get_max_rendered_size(int *w, int *h);
1892 extern void vbi_get_vt_cell_size(int *w, int *h);
1893 
1894 
1895 /* exp-txt.h */
1896 
1897 extern int		vbi_print_page_region(vbi_page *pg, char *buf, int size,
1898 					      const char *format, vbi_bool table, vbi_bool ltr,
1899 					      int column, int row, int width, int height);
1900 
1901 _vbi_inline int
vbi_print_page(vbi_page * pg,char * buf,int size,const char * format,vbi_bool table,vbi_bool ltr)1902 vbi_print_page(vbi_page *pg, char *buf, int size,
1903 	       const char *format, vbi_bool table, vbi_bool ltr)
1904 {
1905 	return vbi_print_page_region(pg, buf, size,
1906 				     format, table, ltr,
1907 				     0, 0, pg->columns, pg->rows);
1908 }
1909 
1910 
1911 /* hamm.h */
1912 
1913 extern const uint8_t		_vbi_bit_reverse [256];
1914 extern const uint8_t		_vbi_hamm8_fwd [16];
1915 extern const int8_t		_vbi_hamm8_inv [256];
1916 extern const int8_t		_vbi_hamm24_inv_par [3][256];
1917 
1918 
1919 _vbi_inline unsigned int
vbi_rev8(unsigned int c)1920 vbi_rev8			(unsigned int		c)
1921 {
1922 	return _vbi_bit_reverse[(uint8_t) c];
1923 }
1924 
1925 _vbi_inline unsigned int
vbi_rev16(unsigned int c)1926 vbi_rev16			(unsigned int		c)
1927 {
1928 	return _vbi_bit_reverse[(uint8_t) c] * 256
1929 		+ _vbi_bit_reverse[(uint8_t)(c >> 8)];
1930 }
1931 
1932 _vbi_inline unsigned int
vbi_rev16p(const uint8_t * p)1933 vbi_rev16p			(const uint8_t *	p)
1934 {
1935 	return _vbi_bit_reverse[p[0]] * 256
1936 		+ _vbi_bit_reverse[p[1]];
1937 }
1938 
1939 _vbi_inline unsigned int
vbi_par8(unsigned int c)1940 vbi_par8			(unsigned int		c)
1941 {
1942 	c &= 255;
1943 
1944 	/* if 0 == (inv_par[] & 32) change bit 7 of c. */
1945 	c ^= 128 & ~(_vbi_hamm24_inv_par[0][c] << 2);
1946 
1947 	return c;
1948 }
1949 
1950 _vbi_inline int
vbi_unpar8(unsigned int c)1951 vbi_unpar8			(unsigned int		c)
1952 {
1953 /* Disabled until someone finds a reliable way
1954    to test for cmov support at compile time. */
1955 #if 0
1956 	int r = c & 127;
1957 
1958 	/* This saves cache flushes and an explicit branch. */
1959 	__asm__ (" testb	%1,%1\n"
1960 		 " cmovp	%2,%0\n"
1961 		 : "+&a" (r) : "c" (c), "rm" (-1));
1962 	return r;
1963 #endif
1964 	if (_vbi_hamm24_inv_par[0][(uint8_t) c] & 32) {
1965 		return c & 127;
1966 	} else {
1967 		/* The idea is to OR results together to find a parity
1968 		   error in a sequence, rather than a test and branch on
1969 		   each byte. */
1970 		return -1;
1971 	}
1972 }
1973 
1974 extern void
1975 vbi_par				(uint8_t *		p,
1976 				 unsigned int		n);
1977 extern int
1978 vbi_unpar			(uint8_t *		p,
1979 				 unsigned int		n);
1980 
1981 _vbi_inline unsigned int
vbi_ham8(unsigned int c)1982 vbi_ham8			(unsigned int		c)
1983 {
1984 	return _vbi_hamm8_fwd[c & 15];
1985 }
1986 
1987 _vbi_inline int
vbi_unham8(unsigned int c)1988 vbi_unham8			(unsigned int		c)
1989 {
1990 	return _vbi_hamm8_inv[(uint8_t) c];
1991 }
1992 
1993 _vbi_inline int
vbi_unham16p(const uint8_t * p)1994 vbi_unham16p			(const uint8_t *	p)
1995 {
1996 	return ((int) _vbi_hamm8_inv[p[0]])
1997 	  | (((int) _vbi_hamm8_inv[p[1]]) << 4);
1998 }
1999 
2000 extern void
2001 vbi_ham24p			(uint8_t *		p,
2002 				 unsigned int		c);
2003 extern int
2004 vbi_unham24p			(const uint8_t *	p)
2005   _vbi_pure;
2006 
2007 
2008 
2009 /* cc.h */
2010 
2011 extern vbi_bool		vbi_fetch_cc_page(vbi_decoder *vbi, vbi_page *pg,
2012 					  vbi_pgno pgno, vbi_bool reset);
2013 
2014 
2015 /* teletext_decoder.h */
2016 
2017 typedef enum {
2018 	VBI_WST_LEVEL_1,
2019 	VBI_WST_LEVEL_1p5,
2020 	VBI_WST_LEVEL_2p5,
2021 	VBI_WST_LEVEL_3p5
2022 } vbi_wst_level;
2023 
2024 
2025 extern void		vbi_teletext_set_default_region(vbi_decoder *vbi, int default_region);
2026 extern void		vbi_teletext_set_level(vbi_decoder *vbi, int level);
2027 
2028 extern vbi_bool		vbi_fetch_vt_page(vbi_decoder *vbi, vbi_page *pg,
2029 					  vbi_pgno pgno, vbi_subno subno,
2030 					  vbi_wst_level max_level, int display_rows,
2031 					  vbi_bool navigation);
2032 extern int		vbi_page_title(vbi_decoder *vbi, int pgno, int subno, char *buf);
2033 
2034 extern void		vbi_resolve_link(vbi_page *pg, int column, int row,
2035 					 vbi_link *ld);
2036 extern void		vbi_resolve_home(vbi_page *pg, vbi_link *ld);
2037 
2038 
2039 /* tables.h */
2040 
2041 extern const char *	vbi_rating_string(vbi_rating_auth auth, int id);
2042 extern const char *	vbi_prog_type_string(vbi_prog_classf classf, int id);
2043 
2044 
2045 /* packet-830.h */
2046 
2047 extern vbi_bool
2048 vbi_decode_teletext_8301_cni	(unsigned int *		cni,
2049 				 const uint8_t		buffer[42])
2050 #ifndef DOXYGEN_SHOULD_SKIP_THIS
2051   _vbi_nonnull ((1, 2))
2052 #endif
2053   ;
2054 extern vbi_bool
2055 vbi_decode_teletext_8301_local_time
2056 				(time_t *		utc_time,
2057 				 int *			seconds_east,
2058 				 const uint8_t		buffer[42])
2059 #ifndef DOXYGEN_SHOULD_SKIP_THIS
2060   _vbi_nonnull ((1, 2, 3))
2061 #endif
2062   ;
2063 extern vbi_bool
2064 vbi_decode_teletext_8302_cni	(unsigned int *		cni,
2065 				 const uint8_t		buffer[42])
2066 #ifndef DOXYGEN_SHOULD_SKIP_THIS
2067   _vbi_nonnull ((1, 2))
2068 #endif
2069   ;
2070 extern vbi_bool
2071 vbi_decode_teletext_8302_pdc	(vbi_program_id *	pid,
2072 				 const uint8_t		buffer[42])
2073 #ifndef DOXYGEN_SHOULD_SKIP_THIS
2074   _vbi_nonnull ((1, 2))
2075 #endif
2076   ;
2077 
2078 
2079 /* vps.h */
2080 
2081 extern vbi_bool
2082 vbi_decode_vps_cni		(unsigned int *		cni,
2083 				 const uint8_t		buffer[13])
2084 #ifndef DOXYGEN_SHOULD_SKIP_THIS
2085   _vbi_nonnull ((1, 2))
2086 #endif
2087   ;
2088 extern vbi_bool
2089 vbi_encode_vps_cni		(uint8_t		buffer[13],
2090 				 unsigned int		cni)
2091   _vbi_nonnull ((1));
2092 extern vbi_bool
2093 vbi_decode_vps_pdc		(vbi_program_id *	pid,
2094 				 const uint8_t		buffer[13])
2095 #ifndef DOXYGEN_SHOULD_SKIP_THIS
2096   _vbi_nonnull ((1, 2))
2097 #endif
2098   ;
2099 extern vbi_bool
2100 vbi_encode_vps_pdc		(uint8_t		buffer[13],
2101 				 const vbi_program_id *	pid)
2102 #ifndef DOXYGEN_SHOULD_SKIP_THIS
2103   _vbi_nonnull ((1, 2))
2104 #endif
2105   ;
2106 vbi_bool
2107 vbi_decode_dvb_pdc_descriptor	(vbi_program_id *	pid,
2108 				 const uint8_t		buffer[5])
2109 #ifndef DOXYGEN_SHOULD_SKIP_THIS
2110   _vbi_nonnull ((1, 2))
2111 #endif
2112   ;
2113 vbi_bool
2114 vbi_encode_dvb_pdc_descriptor	(uint8_t		buffer[5],
2115 				 const vbi_program_id *	pid)
2116 #ifndef DOXYGEN_SHOULD_SKIP_THIS
2117   _vbi_nonnull ((1, 2))
2118 #endif
2119   ;
2120 
2121 
2122 
2123 /* vbi.h */
2124 
2125 typedef enum {
2126 	VBI_NO_PAGE = 0x00,
2127 	VBI_NORMAL_PAGE = 0x01,
2128 	VBI_SUBTITLE_PAGE = 0x70,
2129 	VBI_SUBTITLE_INDEX = 0x78,
2130 	VBI_NONSTD_SUBPAGES = 0x79,
2131 	VBI_PROGR_WARNING = 0x7A,
2132 	VBI_CURRENT_PROGR = 0x7C,
2133 	VBI_NOW_AND_NEXT = 0x7D,
2134 	VBI_PROGR_INDEX = 0x7F,
2135 	VBI_PROGR_SCHEDULE = 0x81,
2136 	VBI_UNKNOWN_PAGE = 0xFF
2137 } vbi_page_type;
2138 
2139 extern void		vbi_set_brightness(vbi_decoder *vbi, int brightness);
2140 extern void		vbi_set_contrast(vbi_decoder *vbi, int contrast);
2141 
2142 
2143 extern vbi_decoder *	vbi_decoder_new(void);
2144 extern void		vbi_decoder_delete(vbi_decoder *vbi);
2145 extern void		vbi_decode(vbi_decoder *vbi, vbi_sliced *sliced,
2146 				   int lines, double timestamp);
2147 extern void             vbi_channel_switched(vbi_decoder *vbi, vbi_nuid nuid);
2148 extern vbi_page_type	vbi_classify_page(vbi_decoder *vbi, vbi_pgno pgno,
2149 					  vbi_subno *subno, char **language);
2150 extern void		vbi_version(unsigned int *major, unsigned int *minor, unsigned int *micro);
2151 extern void
2152 vbi_set_log_fn			(vbi_log_mask		mask,
2153 				 vbi_log_fn *		log_fn,
2154 				 void *			user_data);
2155 
2156 
2157 
2158 #ifdef __cplusplus
2159 }
2160 #endif
2161 
2162 #endif /* __LIBZVBI_H__ */
2163