annotate stream/tvi_vbi.c @ 27798:a73e2f6b5fad

Remove reference to containers.xml, which was removed.
author diego
date Sun, 26 Oct 2008 09:44:32 +0000
parents a26e50cae389
children 0f1b5b68af32
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
23899
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1 /*
34532db868ba Teletext support.
voroshil
parents:
diff changeset
2 * Teletext support
26737
a26e50cae389 Use standard license headers with standard formatting.
diego
parents: 25245
diff changeset
3 *
23899
34532db868ba Teletext support.
voroshil
parents:
diff changeset
4 * Copyright (C) 2007 Vladimir Voroshilov <voroshil@gmail.com>
34532db868ba Teletext support.
voroshil
parents:
diff changeset
5 *
34532db868ba Teletext support.
voroshil
parents:
diff changeset
6 * This file is part of MPlayer.
34532db868ba Teletext support.
voroshil
parents:
diff changeset
7 *
34532db868ba Teletext support.
voroshil
parents:
diff changeset
8 * MPlayer is free software; you can redistribute it and/or modify
34532db868ba Teletext support.
voroshil
parents:
diff changeset
9 * it under the terms of the GNU General Public License as published by
34532db868ba Teletext support.
voroshil
parents:
diff changeset
10 * the Free Software Foundation; either version 2 of the License, or
34532db868ba Teletext support.
voroshil
parents:
diff changeset
11 * (at your option) any later version.
34532db868ba Teletext support.
voroshil
parents:
diff changeset
12 *
34532db868ba Teletext support.
voroshil
parents:
diff changeset
13 * MPlayer is distributed in the hope that it will be useful,
34532db868ba Teletext support.
voroshil
parents:
diff changeset
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
34532db868ba Teletext support.
voroshil
parents:
diff changeset
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
34532db868ba Teletext support.
voroshil
parents:
diff changeset
16 * GNU General Public License for more details.
34532db868ba Teletext support.
voroshil
parents:
diff changeset
17 *
26737
a26e50cae389 Use standard license headers with standard formatting.
diego
parents: 25245
diff changeset
18 * You should have received a copy of the GNU General Public License along
a26e50cae389 Use standard license headers with standard formatting.
diego
parents: 25245
diff changeset
19 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
a26e50cae389 Use standard license headers with standard formatting.
diego
parents: 25245
diff changeset
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23899
34532db868ba Teletext support.
voroshil
parents:
diff changeset
21 *
34532db868ba Teletext support.
voroshil
parents:
diff changeset
22 *
34532db868ba Teletext support.
voroshil
parents:
diff changeset
23 * Based on Attila Otvos' teletext patch, Michael Niedermayer's
34532db868ba Teletext support.
voroshil
parents:
diff changeset
24 * proof-of-concept teletext capture utility and some parts
34532db868ba Teletext support.
voroshil
parents:
diff changeset
25 * (decode_raw_line_runin,pll_add,pll_reset) of MythTV project.
24099
d517c397de7d Fix [soc:eoc] stubs.
voroshil
parents: 23928
diff changeset
26 * Code for calculating [soc:eoc] is based on aletv of Edgar Toernig.
23899
34532db868ba Teletext support.
voroshil
parents:
diff changeset
27 *
24186
c00a882a3adc Add teletext specification reference
voroshil
parents: 24185
diff changeset
28 * Teletext system is described in
c00a882a3adc Add teletext specification reference
voroshil
parents: 24185
diff changeset
29 * ETS 300 706 "Enhanced Teletext specification" : May 1997
c00a882a3adc Add teletext specification reference
voroshil
parents: 24185
diff changeset
30 * http://www.themm.net/~mihu/linux/saa7146/specs/ets_300706e01p.pdf
23899
34532db868ba Teletext support.
voroshil
parents:
diff changeset
31 *
34532db868ba Teletext support.
voroshil
parents:
diff changeset
32 * Some implementation details:
34532db868ba Teletext support.
voroshil
parents:
diff changeset
33 * How to port teletext to another tvi_* driver (see tvi_v4l2.c for example):
34532db868ba Teletext support.
voroshil
parents:
diff changeset
34 *
34532db868ba Teletext support.
voroshil
parents:
diff changeset
35 * 1. Implement TVI_CONTROL_VBI_INIT (initialize driver-related vbi subsystem,
34532db868ba Teletext support.
voroshil
parents:
diff changeset
36 * start grabbing thread)
34532db868ba Teletext support.
voroshil
parents:
diff changeset
37 * input data: vbi device name.
34532db868ba Teletext support.
voroshil
parents:
diff changeset
38 * (driver should also call TV_VBI_CONTROL_START for common vbi subsystem initialization
34532db868ba Teletext support.
voroshil
parents:
diff changeset
39 * with pointer to initialized tt_stream_properties structure.
34532db868ba Teletext support.
voroshil
parents:
diff changeset
40 * After ioctl call variable will contain pointer to initialized priv_vbi_t structure.
34532db868ba Teletext support.
voroshil
parents:
diff changeset
41 *
34532db868ba Teletext support.
voroshil
parents:
diff changeset
42 * 2. After receiving next chunk of raw vbi data call TV_VBI_CONTROL_DECODE_PAGE
34532db868ba Teletext support.
voroshil
parents:
diff changeset
43 * ioctl with pointer to data buffer
34532db868ba Teletext support.
voroshil
parents:
diff changeset
44 * 3. pass all other VBI related ioctl cmds to teletext_control routine
34532db868ba Teletext support.
voroshil
parents:
diff changeset
45 *
34532db868ba Teletext support.
voroshil
parents:
diff changeset
46 * Page displaying process consist of following stages:
34532db868ba Teletext support.
voroshil
parents:
diff changeset
47 *
34532db868ba Teletext support.
voroshil
parents:
diff changeset
48 * ---grabbing stage---
34532db868ba Teletext support.
voroshil
parents:
diff changeset
49 * 0. stream/tvi_*.c: vbi_grabber(...)
34532db868ba Teletext support.
voroshil
parents:
diff changeset
50 * getting vbi data from video device
34532db868ba Teletext support.
voroshil
parents:
diff changeset
51 * ---decoding stage---
34532db868ba Teletext support.
voroshil
parents:
diff changeset
52 * 1. stream/tvi_vbi.c: decode_raw_line_runin(...) or decode_raw_line_sine(...)
34532db868ba Teletext support.
voroshil
parents:
diff changeset
53 * decode raw vbi data into sliced 45(?) bytes long packets
34532db868ba Teletext support.
voroshil
parents:
diff changeset
54 * 2. stream/tvi_vbi.c: decode_pkt0(...), decode_pkt_page(...)
34532db868ba Teletext support.
voroshil
parents:
diff changeset
55 * packets processing (header analyzing, storing complete page in cache,
34532db868ba Teletext support.
voroshil
parents:
diff changeset
56 * only raw member of tt_char is filled at this stage)
34532db868ba Teletext support.
voroshil
parents:
diff changeset
57 * 3. stream/tvi_vbi.c: decode_page(...)
34532db868ba Teletext support.
voroshil
parents:
diff changeset
58 * page decoding. filling unicode,gfx,ctl,etc members of tt_char structure
34532db868ba Teletext support.
voroshil
parents:
diff changeset
59 * with appropriate values according to teletext control chars, converting
34532db868ba Teletext support.
voroshil
parents:
diff changeset
60 * text to utf8.
34532db868ba Teletext support.
voroshil
parents:
diff changeset
61 * ---rendering stage---
34532db868ba Teletext support.
voroshil
parents:
diff changeset
62 * 4. stream/tvi_vbi.c: prepare_visible_page(...)
34532db868ba Teletext support.
voroshil
parents:
diff changeset
63 * processing page. adding number of just received by background process
34532db868ba Teletext support.
voroshil
parents:
diff changeset
64 * teletext page, adding current time,etc.
34532db868ba Teletext support.
voroshil
parents:
diff changeset
65 * 5. libvo/sub.c: vo_update_text_teletext(...)
34532db868ba Teletext support.
voroshil
parents:
diff changeset
66 * rendering displayable osd with text and graphics
34532db868ba Teletext support.
voroshil
parents:
diff changeset
67 *
34532db868ba Teletext support.
voroshil
parents:
diff changeset
68 * TODO:
34532db868ba Teletext support.
voroshil
parents:
diff changeset
69 * v4lv1,bktr support
34532db868ba Teletext support.
voroshil
parents:
diff changeset
70 * spu rendering
34532db868ba Teletext support.
voroshil
parents:
diff changeset
71 * is better quality on poor signal possible ?
34532db868ba Teletext support.
voroshil
parents:
diff changeset
72 * link support
34532db868ba Teletext support.
voroshil
parents:
diff changeset
73 * font autoscale
34532db868ba Teletext support.
voroshil
parents:
diff changeset
74 * greyscale osd
34532db868ba Teletext support.
voroshil
parents:
diff changeset
75 * slave command for dumping pages
34532db868ba Teletext support.
voroshil
parents:
diff changeset
76 * fix bcd<->dec as suggested my Michael
34532db868ba Teletext support.
voroshil
parents:
diff changeset
77 *
34532db868ba Teletext support.
voroshil
parents:
diff changeset
78 * BUGS:
34532db868ba Teletext support.
voroshil
parents:
diff changeset
79 * wrong colors in debug dump
34532db868ba Teletext support.
voroshil
parents:
diff changeset
80 * blinking when visible page was just updated
34532db868ba Teletext support.
voroshil
parents:
diff changeset
81 */
34532db868ba Teletext support.
voroshil
parents:
diff changeset
82
34532db868ba Teletext support.
voroshil
parents:
diff changeset
83 #include "config.h"
34532db868ba Teletext support.
voroshil
parents:
diff changeset
84
34532db868ba Teletext support.
voroshil
parents:
diff changeset
85 #include <stdlib.h>
34532db868ba Teletext support.
voroshil
parents:
diff changeset
86 #include <string.h>
34532db868ba Teletext support.
voroshil
parents:
diff changeset
87 #include <unistd.h>
34532db868ba Teletext support.
voroshil
parents:
diff changeset
88 #include <errno.h>
34532db868ba Teletext support.
voroshil
parents:
diff changeset
89 #include <math.h>
34532db868ba Teletext support.
voroshil
parents:
diff changeset
90 #include <stdio.h>
34532db868ba Teletext support.
voroshil
parents:
diff changeset
91
34532db868ba Teletext support.
voroshil
parents:
diff changeset
92 #include <pthread.h>
34532db868ba Teletext support.
voroshil
parents:
diff changeset
93
34532db868ba Teletext support.
voroshil
parents:
diff changeset
94 #include "tv.h"
34532db868ba Teletext support.
voroshil
parents:
diff changeset
95 #include "mp_msg.h"
34532db868ba Teletext support.
voroshil
parents:
diff changeset
96 #include "help_mp.h"
34532db868ba Teletext support.
voroshil
parents:
diff changeset
97 #include "libmpcodecs/img_format.h"
34532db868ba Teletext support.
voroshil
parents:
diff changeset
98 #include "libavutil/common.h"
34532db868ba Teletext support.
voroshil
parents:
diff changeset
99 #include "input/input.h"
24342
8873c972c6aa Decrease teletext page rendering frequency from 1/frame to about 4/sec.
voroshil
parents: 24316
diff changeset
100 #include "osdep/timer.h"
23899
34532db868ba Teletext support.
voroshil
parents:
diff changeset
101
34532db868ba Teletext support.
voroshil
parents:
diff changeset
102 //#define DEBUG_DUMP 1
34532db868ba Teletext support.
voroshil
parents:
diff changeset
103
34532db868ba Teletext support.
voroshil
parents:
diff changeset
104 /// page magazine entry structure
34532db868ba Teletext support.
voroshil
parents:
diff changeset
105 typedef struct mag_s{
34532db868ba Teletext support.
voroshil
parents:
diff changeset
106 tt_page* pt;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
107 int order;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
108 } mag_t;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
109
34532db868ba Teletext support.
voroshil
parents:
diff changeset
110 typedef struct {
34532db868ba Teletext support.
voroshil
parents:
diff changeset
111 int on; ///< teletext on/off
34532db868ba Teletext support.
voroshil
parents:
diff changeset
112 int pagenum; ///< seek page number
34532db868ba Teletext support.
voroshil
parents:
diff changeset
113 int subpagenum; ///< seek subpage
34532db868ba Teletext support.
voroshil
parents:
diff changeset
114 int curr_pagenum; ///< current page number
34532db868ba Teletext support.
voroshil
parents:
diff changeset
115 int pagenumdec; ///< set page num with dec
34532db868ba Teletext support.
voroshil
parents:
diff changeset
116
34532db868ba Teletext support.
voroshil
parents:
diff changeset
117 teletext_format tformat; ///< see teletext_format enum
34532db868ba Teletext support.
voroshil
parents:
diff changeset
118 teletext_zoom zoom; ///< see teletext_zoom enum
34532db868ba Teletext support.
voroshil
parents:
diff changeset
119 mag_t* mag; ///< pages magazine (has 8 entities)
24290
ca7ee5c1b88d Support for selecting language via packet 28.
voroshil
parents: 24280
diff changeset
120 int primary_language; ///< primary character set
ca7ee5c1b88d Support for selecting language via packet 28.
voroshil
parents: 24280
diff changeset
121 int secondary_language; ///< secondary character set
23899
34532db868ba Teletext support.
voroshil
parents:
diff changeset
122 /// Currently displayed page (with additional info, e.g current time)
34532db868ba Teletext support.
voroshil
parents:
diff changeset
123 tt_char display_page[VBI_ROWS*VBI_COLUMNS];
34532db868ba Teletext support.
voroshil
parents:
diff changeset
124 /// number of raw bytes between two subsequent encoded bits
34532db868ba Teletext support.
voroshil
parents:
diff changeset
125 int bpb;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
126 /// clock run-in sequence will be searched in buffer in [soc:eoc] bytes range
34532db868ba Teletext support.
voroshil
parents:
diff changeset
127 int soc;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
128 int eoc;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
129 /// minimum number of raw vbi bytes wich can be decoded into 8 data bits
34532db868ba Teletext support.
voroshil
parents:
diff changeset
130 int bp8bl;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
131 /// maximum number of raw vbi bytes wich can be decoded into 8 data bits
34532db868ba Teletext support.
voroshil
parents:
diff changeset
132 int bp8bh;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
133
34532db868ba Teletext support.
voroshil
parents:
diff changeset
134 int pll_adj;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
135 int pll_dir;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
136 int pll_cnt;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
137 int pll_err;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
138 int pll_lerr;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
139 int pll_fixed;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
140 /// vbi stream properties (buffer size,bytes per line, etc)
34532db868ba Teletext support.
voroshil
parents:
diff changeset
141 tt_stream_props* ptsp;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
142 pthread_mutex_t buffer_mutex;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
143
34532db868ba Teletext support.
voroshil
parents:
diff changeset
144 tt_page** ptt_cache;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
145 unsigned char* ptt_cache_first_subpage;
24232
d0290b80e612 Implement 8/30 format 1 teletext packet decoding
voroshil
parents: 24197
diff changeset
146 /// network info
d0290b80e612 Implement 8/30 format 1 teletext packet decoding
voroshil
parents: 24197
diff changeset
147 unsigned char initialpage;
d0290b80e612 Implement 8/30 format 1 teletext packet decoding
voroshil
parents: 24197
diff changeset
148 unsigned int initialsubpage;
d0290b80e612 Implement 8/30 format 1 teletext packet decoding
voroshil
parents: 24197
diff changeset
149 unsigned int networkid;
d0290b80e612 Implement 8/30 format 1 teletext packet decoding
voroshil
parents: 24197
diff changeset
150 int timeoffset; // timeoffset=realoffset*2
d0290b80e612 Implement 8/30 format 1 teletext packet decoding
voroshil
parents: 24197
diff changeset
151 unsigned int juliandate;
d0290b80e612 Implement 8/30 format 1 teletext packet decoding
voroshil
parents: 24197
diff changeset
152 unsigned int universaltime;
d0290b80e612 Implement 8/30 format 1 teletext packet decoding
voroshil
parents: 24197
diff changeset
153 unsigned char networkname[21];
24301
15d547dfa66b Make sure that no pages will left in cache during
voroshil
parents: 24296
diff changeset
154 int cache_reset;
24342
8873c972c6aa Decrease teletext page rendering frequency from 1/frame to about 4/sec.
voroshil
parents: 24316
diff changeset
155 /// "page changed" flag: 0-unchanged, 1-entire page, 3-only header
8873c972c6aa Decrease teletext page rendering frequency from 1/frame to about 4/sec.
voroshil
parents: 24316
diff changeset
156 int page_changed;
24345
388ac5e95da1 More accurate calculating of teletext
voroshil
parents: 24344
diff changeset
157 int last_rendered;
23899
34532db868ba Teletext support.
voroshil
parents:
diff changeset
158 } priv_vbi_t;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
159
34532db868ba Teletext support.
voroshil
parents:
diff changeset
160 static unsigned char fixParity[256];
34532db868ba Teletext support.
voroshil
parents:
diff changeset
161
25245
157aafb33efe Add a few forgotten static/const attributes in tvi_vbi.c
reimar
parents: 24788
diff changeset
162 static const tt_char tt_space={0x20,7,0,0,0,0,0,0,0x20};
157aafb33efe Add a few forgotten static/const attributes in tvi_vbi.c
reimar
parents: 24788
diff changeset
163 static const tt_char tt_error={'?',1,0,0,0,0,0,0,'?'}; // Red '?' on black background
23899
34532db868ba Teletext support.
voroshil
parents:
diff changeset
164 static double si[12];
34532db868ba Teletext support.
voroshil
parents:
diff changeset
165 static double co[12];
34532db868ba Teletext support.
voroshil
parents:
diff changeset
166
34532db868ba Teletext support.
voroshil
parents:
diff changeset
167 #define VBI_FORMAT(priv) (*(priv->ptsp))
34532db868ba Teletext support.
voroshil
parents:
diff changeset
168
34532db868ba Teletext support.
voroshil
parents:
diff changeset
169 #define FIXP_SH 16
34532db868ba Teletext support.
voroshil
parents:
diff changeset
170 #define ONE_FIXP (1<<FIXP_SH)
34532db868ba Teletext support.
voroshil
parents:
diff changeset
171 #define FIXP2INT(a) ((a)>>FIXP_SH)
34532db868ba Teletext support.
voroshil
parents:
diff changeset
172 #define ANY2FIXP(a) ((int)((a)*ONE_FIXP))
34532db868ba Teletext support.
voroshil
parents:
diff changeset
173
34532db868ba Teletext support.
voroshil
parents:
diff changeset
174 static const unsigned char corrHamm48[256]={
34532db868ba Teletext support.
voroshil
parents:
diff changeset
175 0x01, 0xff, 0x01, 0x01, 0xff, 0x00, 0x01, 0xff,
34532db868ba Teletext support.
voroshil
parents:
diff changeset
176 0xff, 0x02, 0x01, 0xff, 0x0a, 0xff, 0xff, 0x07,
34532db868ba Teletext support.
voroshil
parents:
diff changeset
177 0xff, 0x00, 0x01, 0xff, 0x00, 0x00, 0xff, 0x00,
34532db868ba Teletext support.
voroshil
parents:
diff changeset
178 0x06, 0xff, 0xff, 0x0b, 0xff, 0x00, 0x03, 0xff,
34532db868ba Teletext support.
voroshil
parents:
diff changeset
179 0xff, 0x0c, 0x01, 0xff, 0x04, 0xff, 0xff, 0x07,
34532db868ba Teletext support.
voroshil
parents:
diff changeset
180 0x06, 0xff, 0xff, 0x07, 0xff, 0x07, 0x07, 0x07,
34532db868ba Teletext support.
voroshil
parents:
diff changeset
181 0x06, 0xff, 0xff, 0x05, 0xff, 0x00, 0x0d, 0xff,
34532db868ba Teletext support.
voroshil
parents:
diff changeset
182 0x06, 0x06, 0x06, 0xff, 0x06, 0xff, 0xff, 0x07,
34532db868ba Teletext support.
voroshil
parents:
diff changeset
183 0xff, 0x02, 0x01, 0xff, 0x04, 0xff, 0xff, 0x09,
34532db868ba Teletext support.
voroshil
parents:
diff changeset
184 0x02, 0x02, 0xff, 0x02, 0xff, 0x02, 0x03, 0xff,
34532db868ba Teletext support.
voroshil
parents:
diff changeset
185 0x08, 0xff, 0xff, 0x05, 0xff, 0x00, 0x03, 0xff,
34532db868ba Teletext support.
voroshil
parents:
diff changeset
186 0xff, 0x02, 0x03, 0xff, 0x03, 0xff, 0x03, 0x03,
34532db868ba Teletext support.
voroshil
parents:
diff changeset
187 0x04, 0xff, 0xff, 0x05, 0x04, 0x04, 0x04, 0xff,
34532db868ba Teletext support.
voroshil
parents:
diff changeset
188 0xff, 0x02, 0x0f, 0xff, 0x04, 0xff, 0xff, 0x07,
34532db868ba Teletext support.
voroshil
parents:
diff changeset
189 0xff, 0x05, 0x05, 0x05, 0x04, 0xff, 0xff, 0x05,
34532db868ba Teletext support.
voroshil
parents:
diff changeset
190 0x06, 0xff, 0xff, 0x05, 0xff, 0x0e, 0x03, 0xff,
34532db868ba Teletext support.
voroshil
parents:
diff changeset
191 0xff, 0x0c, 0x01, 0xff, 0x0a, 0xff, 0xff, 0x09,
34532db868ba Teletext support.
voroshil
parents:
diff changeset
192 0x0a, 0xff, 0xff, 0x0b, 0x0a, 0x0a, 0x0a, 0xff,
34532db868ba Teletext support.
voroshil
parents:
diff changeset
193 0x08, 0xff, 0xff, 0x0b, 0xff, 0x00, 0x0d, 0xff,
34532db868ba Teletext support.
voroshil
parents:
diff changeset
194 0xff, 0x0b, 0x0b, 0x0b, 0x0a, 0xff, 0xff, 0x0b,
34532db868ba Teletext support.
voroshil
parents:
diff changeset
195 0x0c, 0x0c, 0xff, 0x0c, 0xff, 0x0c, 0x0d, 0xff,
34532db868ba Teletext support.
voroshil
parents:
diff changeset
196 0xff, 0x0c, 0x0f, 0xff, 0x0a, 0xff, 0xff, 0x07,
34532db868ba Teletext support.
voroshil
parents:
diff changeset
197 0xff, 0x0c, 0x0d, 0xff, 0x0d, 0xff, 0x0d, 0x0d,
34532db868ba Teletext support.
voroshil
parents:
diff changeset
198 0x06, 0xff, 0xff, 0x0b, 0xff, 0x0e, 0x0d, 0xff,
34532db868ba Teletext support.
voroshil
parents:
diff changeset
199 0x08, 0xff, 0xff, 0x09, 0xff, 0x09, 0x09, 0x09,
34532db868ba Teletext support.
voroshil
parents:
diff changeset
200 0xff, 0x02, 0x0f, 0xff, 0x0a, 0xff, 0xff, 0x09,
34532db868ba Teletext support.
voroshil
parents:
diff changeset
201 0x08, 0x08, 0x08, 0xff, 0x08, 0xff, 0xff, 0x09,
34532db868ba Teletext support.
voroshil
parents:
diff changeset
202 0x08, 0xff, 0xff, 0x0b, 0xff, 0x0e, 0x03, 0xff,
34532db868ba Teletext support.
voroshil
parents:
diff changeset
203 0xff, 0x0c, 0x0f, 0xff, 0x04, 0xff, 0xff, 0x09,
34532db868ba Teletext support.
voroshil
parents:
diff changeset
204 0x0f, 0xff, 0x0f, 0x0f, 0xff, 0x0e, 0x0f, 0xff,
34532db868ba Teletext support.
voroshil
parents:
diff changeset
205 0x08, 0xff, 0xff, 0x05, 0xff, 0x0e, 0x0d, 0xff,
34532db868ba Teletext support.
voroshil
parents:
diff changeset
206 0xff, 0x0e, 0x0f, 0xff, 0x0e, 0x0e, 0xff, 0x0e };
34532db868ba Teletext support.
voroshil
parents:
diff changeset
207
34532db868ba Teletext support.
voroshil
parents:
diff changeset
208
34532db868ba Teletext support.
voroshil
parents:
diff changeset
209 enum {
24271
c0474098f1a5 Make charset constants naming consistant
voroshil
parents: 24256
diff changeset
210 LATIN=0,
24256
587555a43c76 Fix compilation by adding forgotten comma.
iive
parents: 24255
diff changeset
211 CYRILLIC1,
24271
c0474098f1a5 Make charset constants naming consistant
voroshil
parents: 24256
diff changeset
212 CYRILLIC2,
24255
d6b310ab40c8 Conversion tables for Serbian/Croatian, Ukrainian and Greek charsets.
voroshil
parents: 24244
diff changeset
213 CYRILLIC3,
d6b310ab40c8 Conversion tables for Serbian/Croatian, Ukrainian and Greek charsets.
voroshil
parents: 24244
diff changeset
214 GREEK,
23899
34532db868ba Teletext support.
voroshil
parents:
diff changeset
215 LANGS
34532db868ba Teletext support.
voroshil
parents:
diff changeset
216 };
34532db868ba Teletext support.
voroshil
parents:
diff changeset
217
34532db868ba Teletext support.
voroshil
parents:
diff changeset
218 // conversion table for chars 0x20-0x7F (UTF8)
34532db868ba Teletext support.
voroshil
parents:
diff changeset
219 // TODO: add another languages
25245
157aafb33efe Add a few forgotten static/const attributes in tvi_vbi.c
reimar
parents: 24788
diff changeset
220 static const unsigned int lang_chars[LANGS][0x60]={
23899
34532db868ba Teletext support.
voroshil
parents:
diff changeset
221 {
34532db868ba Teletext support.
voroshil
parents:
diff changeset
222 //Latin
34532db868ba Teletext support.
voroshil
parents:
diff changeset
223 0x20,0x21,0x22,0x23,0x24,0x25,0x26,0x27,
34532db868ba Teletext support.
voroshil
parents:
diff changeset
224 0x28,0x29,0x2a,0x2b,0x2c,0x2d,0x2e,0x2f,
34532db868ba Teletext support.
voroshil
parents:
diff changeset
225 0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,
34532db868ba Teletext support.
voroshil
parents:
diff changeset
226 0x38,0x39,0x3a,0x3b,0x3c,0x3d,0x3e,0x3f,
34532db868ba Teletext support.
voroshil
parents:
diff changeset
227 0x40,0x41,0x42,0x43,0x44,0x45,0x46,0x47,
34532db868ba Teletext support.
voroshil
parents:
diff changeset
228 0x48,0x49,0x4a,0x4b,0x4c,0x4d,0x4e,0x4f,
34532db868ba Teletext support.
voroshil
parents:
diff changeset
229 0x50,0x51,0x52,0x53,0x54,0x55,0x56,0x57,
34532db868ba Teletext support.
voroshil
parents:
diff changeset
230 0x58,0x59,0x5a,0x5b,0x5c,0x5d,0x5e,0x5f,
34532db868ba Teletext support.
voroshil
parents:
diff changeset
231 0x60,0x61,0x62,0x63,0x64,0x65,0x66,0x67,
34532db868ba Teletext support.
voroshil
parents:
diff changeset
232 0x68,0x69,0x6a,0x6b,0x6c,0x6d,0x6e,0x6f,
34532db868ba Teletext support.
voroshil
parents:
diff changeset
233 0x70,0x71,0x72,0x73,0x74,0x75,0x76,0x77,
34532db868ba Teletext support.
voroshil
parents:
diff changeset
234 0x78,0x79,0x7a,0x7b,0x7c,0x7d,0x7e,0x7f
34532db868ba Teletext support.
voroshil
parents:
diff changeset
235 },
34532db868ba Teletext support.
voroshil
parents:
diff changeset
236 {
24255
d6b310ab40c8 Conversion tables for Serbian/Croatian, Ukrainian and Greek charsets.
voroshil
parents: 24244
diff changeset
237 //Cyrillic-1 (Serbian/Croatian)
d6b310ab40c8 Conversion tables for Serbian/Croatian, Ukrainian and Greek charsets.
voroshil
parents: 24244
diff changeset
238 0x20,0x21,0x22,0x23,0x24,0x25,0x044b,0x27,
d6b310ab40c8 Conversion tables for Serbian/Croatian, Ukrainian and Greek charsets.
voroshil
parents: 24244
diff changeset
239 0x28,0x29,0x2a,0x2b,0x2c,0x2d,0x2e,0x2f,
d6b310ab40c8 Conversion tables for Serbian/Croatian, Ukrainian and Greek charsets.
voroshil
parents: 24244
diff changeset
240 0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,
d6b310ab40c8 Conversion tables for Serbian/Croatian, Ukrainian and Greek charsets.
voroshil
parents: 24244
diff changeset
241 0x38,0x39,0x3a,0x3b,0x3c,0x3d,0x3e,0x3f,
d6b310ab40c8 Conversion tables for Serbian/Croatian, Ukrainian and Greek charsets.
voroshil
parents: 24244
diff changeset
242 0x0427,0x0410,0x0411,0x0426,0x0414,0x0415,0x0424,0x0413,
d6b310ab40c8 Conversion tables for Serbian/Croatian, Ukrainian and Greek charsets.
voroshil
parents: 24244
diff changeset
243 0x0425,0x0418,0x0408,0x041a,0x041b,0x041c,0x041d,0x041e,
d6b310ab40c8 Conversion tables for Serbian/Croatian, Ukrainian and Greek charsets.
voroshil
parents: 24244
diff changeset
244 0x041f,0x040c,0x0420,0x0421,0x0422,0x0423,0x0412,0x0403,
d6b310ab40c8 Conversion tables for Serbian/Croatian, Ukrainian and Greek charsets.
voroshil
parents: 24244
diff changeset
245 0x0409,0x040a,0x0417,0x040b,0x0416,0x0402,0x0428,0x040f,
d6b310ab40c8 Conversion tables for Serbian/Croatian, Ukrainian and Greek charsets.
voroshil
parents: 24244
diff changeset
246 0x0447,0x0430,0x0431,0x0446,0x0434,0x0435,0x0444,0x0433,
d6b310ab40c8 Conversion tables for Serbian/Croatian, Ukrainian and Greek charsets.
voroshil
parents: 24244
diff changeset
247 0x0445,0x0438,0x0428,0x043a,0x043b,0x043c,0x043d,0x043e,
d6b310ab40c8 Conversion tables for Serbian/Croatian, Ukrainian and Greek charsets.
voroshil
parents: 24244
diff changeset
248 0x043f,0x042c,0x0440,0x0441,0x0442,0x0443,0x0432,0x0423,
d6b310ab40c8 Conversion tables for Serbian/Croatian, Ukrainian and Greek charsets.
voroshil
parents: 24244
diff changeset
249 0x0429,0x042a,0x0437,0x042b,0x0436,0x0422,0x0448,0x042f
d6b310ab40c8 Conversion tables for Serbian/Croatian, Ukrainian and Greek charsets.
voroshil
parents: 24244
diff changeset
250 },
d6b310ab40c8 Conversion tables for Serbian/Croatian, Ukrainian and Greek charsets.
voroshil
parents: 24244
diff changeset
251 {
d6b310ab40c8 Conversion tables for Serbian/Croatian, Ukrainian and Greek charsets.
voroshil
parents: 24244
diff changeset
252 //Cyrillic-2 (Russian/Bulgarian)
23899
34532db868ba Teletext support.
voroshil
parents:
diff changeset
253 0x20,0x21,0x22,0x23,0x24,0x25,0x044b,0x27,
34532db868ba Teletext support.
voroshil
parents:
diff changeset
254 0x28,0x29,0x2a,0x2b,0x2c,0x2d,0x2e,0x2f,
34532db868ba Teletext support.
voroshil
parents:
diff changeset
255 0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,
34532db868ba Teletext support.
voroshil
parents:
diff changeset
256 0x38,0x39,0x3a,0x3b,0x3c,0x3d,0x3e,0x3f,
34532db868ba Teletext support.
voroshil
parents:
diff changeset
257 0x042e,0x0410,0x0411,0x0426,0x0414,0x0415,0x0424,0x0413,
34532db868ba Teletext support.
voroshil
parents:
diff changeset
258 0x0425,0x0418,0x0419,0x041a,0x041b,0x041c,0x041d,0x041e,
34532db868ba Teletext support.
voroshil
parents:
diff changeset
259 0x041f,0x042f,0x0420,0x0421,0x0422,0x0423,0x0416,0x0412,
34532db868ba Teletext support.
voroshil
parents:
diff changeset
260 0x042c,0x042a,0x0417,0x0428,0x042d,0x0429,0x0427,0x042b,
34532db868ba Teletext support.
voroshil
parents:
diff changeset
261 0x044e,0x0430,0x0431,0x0446,0x0434,0x0435,0x0444,0x0433,
34532db868ba Teletext support.
voroshil
parents:
diff changeset
262 0x0445,0x0438,0x0439,0x043a,0x043b,0x043c,0x043d,0x043e,
34532db868ba Teletext support.
voroshil
parents:
diff changeset
263 0x043f,0x044f,0x0440,0x0441,0x0442,0x0443,0x0436,0x0432,
34532db868ba Teletext support.
voroshil
parents:
diff changeset
264 0x044c,0x044a,0x0437,0x0448,0x044d,0x0449,0x0447,0x044b
24255
d6b310ab40c8 Conversion tables for Serbian/Croatian, Ukrainian and Greek charsets.
voroshil
parents: 24244
diff changeset
265 },
d6b310ab40c8 Conversion tables for Serbian/Croatian, Ukrainian and Greek charsets.
voroshil
parents: 24244
diff changeset
266 {
d6b310ab40c8 Conversion tables for Serbian/Croatian, Ukrainian and Greek charsets.
voroshil
parents: 24244
diff changeset
267 //Cyrillic-3 (Ukrainian)
d6b310ab40c8 Conversion tables for Serbian/Croatian, Ukrainian and Greek charsets.
voroshil
parents: 24244
diff changeset
268 0x20,0x21,0x22,0x23,0x24,0x25,0xef,0x27,
d6b310ab40c8 Conversion tables for Serbian/Croatian, Ukrainian and Greek charsets.
voroshil
parents: 24244
diff changeset
269 0x28,0x29,0x2a,0x2b,0x2c,0x2d,0x2e,0x2f,
d6b310ab40c8 Conversion tables for Serbian/Croatian, Ukrainian and Greek charsets.
voroshil
parents: 24244
diff changeset
270 0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,
d6b310ab40c8 Conversion tables for Serbian/Croatian, Ukrainian and Greek charsets.
voroshil
parents: 24244
diff changeset
271 0x38,0x39,0x3a,0x3b,0x3c,0x3d,0x3e,0x3f,
d6b310ab40c8 Conversion tables for Serbian/Croatian, Ukrainian and Greek charsets.
voroshil
parents: 24244
diff changeset
272 0x042e,0x0410,0x0411,0x0426,0x0414,0x0415,0x0424,0x0413,
d6b310ab40c8 Conversion tables for Serbian/Croatian, Ukrainian and Greek charsets.
voroshil
parents: 24244
diff changeset
273 0x0425,0x0418,0x0419,0x041a,0x041b,0x041c,0x041d,0x041e,
d6b310ab40c8 Conversion tables for Serbian/Croatian, Ukrainian and Greek charsets.
voroshil
parents: 24244
diff changeset
274 0x041f,0x042f,0x0420,0x0421,0x0422,0x0423,0x0416,0x0412,
d6b310ab40c8 Conversion tables for Serbian/Croatian, Ukrainian and Greek charsets.
voroshil
parents: 24244
diff changeset
275 0x042c,0x49,0x0417,0x0428,0x042d,0x0429,0x0427,0xcf,
d6b310ab40c8 Conversion tables for Serbian/Croatian, Ukrainian and Greek charsets.
voroshil
parents: 24244
diff changeset
276 0x044e,0x0430,0x0431,0x0446,0x0434,0x0435,0x0444,0x0433,
d6b310ab40c8 Conversion tables for Serbian/Croatian, Ukrainian and Greek charsets.
voroshil
parents: 24244
diff changeset
277 0x0445,0x0438,0x0439,0x043a,0x043b,0x043c,0x043d,0x043e,
d6b310ab40c8 Conversion tables for Serbian/Croatian, Ukrainian and Greek charsets.
voroshil
parents: 24244
diff changeset
278 0x043f,0x044f,0x0440,0x0441,0x0442,0x0443,0x0436,0x0432,
d6b310ab40c8 Conversion tables for Serbian/Croatian, Ukrainian and Greek charsets.
voroshil
parents: 24244
diff changeset
279 0x044c,0x69,0x0437,0x0448,0x044d,0x0449,0x0447,0xFF
d6b310ab40c8 Conversion tables for Serbian/Croatian, Ukrainian and Greek charsets.
voroshil
parents: 24244
diff changeset
280 },
d6b310ab40c8 Conversion tables for Serbian/Croatian, Ukrainian and Greek charsets.
voroshil
parents: 24244
diff changeset
281 {
d6b310ab40c8 Conversion tables for Serbian/Croatian, Ukrainian and Greek charsets.
voroshil
parents: 24244
diff changeset
282 //Greek
d6b310ab40c8 Conversion tables for Serbian/Croatian, Ukrainian and Greek charsets.
voroshil
parents: 24244
diff changeset
283 0x20,0x21,0x22,0x23,0x24,0x25,0x26,0x27,
d6b310ab40c8 Conversion tables for Serbian/Croatian, Ukrainian and Greek charsets.
voroshil
parents: 24244
diff changeset
284 0x28,0x29,0x2a,0x2b,0x2c,0x2d,0x2e,0x2f,
d6b310ab40c8 Conversion tables for Serbian/Croatian, Ukrainian and Greek charsets.
voroshil
parents: 24244
diff changeset
285 0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,
d6b310ab40c8 Conversion tables for Serbian/Croatian, Ukrainian and Greek charsets.
voroshil
parents: 24244
diff changeset
286 0x38,0x39,0x3a,0x3b,0x3c,0x3d,0x3e,0x3f,
d6b310ab40c8 Conversion tables for Serbian/Croatian, Ukrainian and Greek charsets.
voroshil
parents: 24244
diff changeset
287 0x0390,0x0391,0x0392,0x0393,0x0394,0x0395,0x0396,0x0397,
d6b310ab40c8 Conversion tables for Serbian/Croatian, Ukrainian and Greek charsets.
voroshil
parents: 24244
diff changeset
288 0x0398,0x0399,0x039a,0x039b,0x039c,0x039d,0x039e,0x039f,
d6b310ab40c8 Conversion tables for Serbian/Croatian, Ukrainian and Greek charsets.
voroshil
parents: 24244
diff changeset
289 0x03a0,0x03a1,0x03a2,0x03a3,0x03a4,0x03a5,0x03a6,0x03a7,
d6b310ab40c8 Conversion tables for Serbian/Croatian, Ukrainian and Greek charsets.
voroshil
parents: 24244
diff changeset
290 0x03a8,0x03a9,0x03aa,0x03ab,0x03ac,0x03ad,0x03ae,0x03af,
d6b310ab40c8 Conversion tables for Serbian/Croatian, Ukrainian and Greek charsets.
voroshil
parents: 24244
diff changeset
291 0x03b0,0x03b1,0x03b2,0x03b3,0x03b4,0x03b5,0x03b6,0x03b7,
d6b310ab40c8 Conversion tables for Serbian/Croatian, Ukrainian and Greek charsets.
voroshil
parents: 24244
diff changeset
292 0x03b8,0x03b9,0x03ba,0x03bb,0x03bc,0x03bd,0x03be,0x03bf,
d6b310ab40c8 Conversion tables for Serbian/Croatian, Ukrainian and Greek charsets.
voroshil
parents: 24244
diff changeset
293 0x03c0,0x03c1,0x03c2,0x03c3,0x03c4,0x03c5,0x03c6,0x03c7,
d6b310ab40c8 Conversion tables for Serbian/Croatian, Ukrainian and Greek charsets.
voroshil
parents: 24244
diff changeset
294 0x03c8,0x03c9,0x03ca,0x03cb,0x03cc,0x03cd,0x03ce,0x03cf
23899
34532db868ba Teletext support.
voroshil
parents:
diff changeset
295 }
34532db868ba Teletext support.
voroshil
parents:
diff changeset
296 };
34532db868ba Teletext support.
voroshil
parents:
diff changeset
297
24184
337fbf5709ab Add support for Latin National Option Sub-Sets
voroshil
parents: 24169
diff changeset
298 /**
337fbf5709ab Add support for Latin National Option Sub-Sets
voroshil
parents: 24169
diff changeset
299 * Latin National Option Sub-Sets
337fbf5709ab Add support for Latin National Option Sub-Sets
voroshil
parents: 24169
diff changeset
300 * see Table 36 of ETS specification for details.
337fbf5709ab Add support for Latin National Option Sub-Sets
voroshil
parents: 24169
diff changeset
301 *
337fbf5709ab Add support for Latin National Option Sub-Sets
voroshil
parents: 24169
diff changeset
302 * 00: £ $ @ « ½ » ¬ # ­ ¼ ¦ ¾ ÷ English
337fbf5709ab Add support for Latin National Option Sub-Sets
voroshil
parents: 24169
diff changeset
303 * 01: é ï à ë ê ù î # è â ô û ç French
337fbf5709ab Add support for Latin National Option Sub-Sets
voroshil
parents: 24169
diff changeset
304 * 02: # ¤ É Ä Ö Å Ü _ é ä ö å ü Swedish/Finnish/Hungarian
24788
c0672ecc6bca czech/slovak character set fixes:
voroshil
parents: 24345
diff changeset
305 * 03: # ů č ť ž ý í ř é á ě ú š Czech/Slovak
24184
337fbf5709ab Add support for Latin National Option Sub-Sets
voroshil
parents: 24169
diff changeset
306 * 04: # $ § Ä Ö Ü ^ _ ° ä ö ü ß German
337fbf5709ab Add support for Latin National Option Sub-Sets
voroshil
parents: 24169
diff changeset
307 * 05: ç $ ¡ á é í ó ú ¿ ü ñ è à Portuguese/Spanish
337fbf5709ab Add support for Latin National Option Sub-Sets
voroshil
parents: 24169
diff changeset
308 * 06: £ $ é ° ç » ¬ # ù à ò è ì Italian
337fbf5709ab Add support for Latin National Option Sub-Sets
voroshil
parents: 24169
diff changeset
309 *
337fbf5709ab Add support for Latin National Option Sub-Sets
voroshil
parents: 24169
diff changeset
310 */
25245
157aafb33efe Add a few forgotten static/const attributes in tvi_vbi.c
reimar
parents: 24788
diff changeset
311 static const unsigned int latin_subchars[8][13]={
24184
337fbf5709ab Add support for Latin National Option Sub-Sets
voroshil
parents: 24169
diff changeset
312 // English
337fbf5709ab Add support for Latin National Option Sub-Sets
voroshil
parents: 24169
diff changeset
313 {0xa3,0x24,0x40,0xab,0xbd,0xbb,0xac,0x23,0xad,0xbc,0xa6,0xbe,0xf7},
337fbf5709ab Add support for Latin National Option Sub-Sets
voroshil
parents: 24169
diff changeset
314 // French
337fbf5709ab Add support for Latin National Option Sub-Sets
voroshil
parents: 24169
diff changeset
315 {0xe9,0xef,0xe0,0xeb,0xea,0xf9,0xee,0x23,0xe8,0xe2,0xf4,0xfb,0xe7},
337fbf5709ab Add support for Latin National Option Sub-Sets
voroshil
parents: 24169
diff changeset
316 // Swedish/Finnish/Hungarian
337fbf5709ab Add support for Latin National Option Sub-Sets
voroshil
parents: 24169
diff changeset
317 {0x23,0xa4,0xc9,0xc4,0xd6,0xc5,0xdc,0x5f,0xe9,0xe4,0xf6,0xe5,0xfc},
337fbf5709ab Add support for Latin National Option Sub-Sets
voroshil
parents: 24169
diff changeset
318 // Czech/Slovak
24788
c0672ecc6bca czech/slovak character set fixes:
voroshil
parents: 24345
diff changeset
319 {0x23,0x16f,0x10d,0x165,0x17e,0xfd,0xed,0x159,0xe9,0xe1,0x11b,0xfa,0x161},
24184
337fbf5709ab Add support for Latin National Option Sub-Sets
voroshil
parents: 24169
diff changeset
320 // German
337fbf5709ab Add support for Latin National Option Sub-Sets
voroshil
parents: 24169
diff changeset
321 {0x23,0x24,0xa7,0xc4,0xd6,0xdc,0x5e,0x5f,0xb0,0xe4,0xf6,0xfc,0xdf},
337fbf5709ab Add support for Latin National Option Sub-Sets
voroshil
parents: 24169
diff changeset
322 // Portuguese/Spanish
337fbf5709ab Add support for Latin National Option Sub-Sets
voroshil
parents: 24169
diff changeset
323 {0xe7,0x24,0xa1,0xe1,0xe9,0xed,0xf3,0xfa,0xbf,0xfc,0xf1,0xe8,0xe0},
337fbf5709ab Add support for Latin National Option Sub-Sets
voroshil
parents: 24169
diff changeset
324 // Italian
337fbf5709ab Add support for Latin National Option Sub-Sets
voroshil
parents: 24169
diff changeset
325 {0xa3,0x24,0xe9,0xb0,0xe7,0xbb,0xac,0x23,0xf9,0xe0,0xf2,0xe8,0xec},
337fbf5709ab Add support for Latin National Option Sub-Sets
voroshil
parents: 24169
diff changeset
326 // Reserved
337fbf5709ab Add support for Latin National Option Sub-Sets
voroshil
parents: 24169
diff changeset
327 {0x23,0x24,0x40,0x5b,0x5c,0x5d,0x5e,0x5f,0x60,0x7b,0x7c,0x7d,0x7e}
337fbf5709ab Add support for Latin National Option Sub-Sets
voroshil
parents: 24169
diff changeset
328 };
337fbf5709ab Add support for Latin National Option Sub-Sets
voroshil
parents: 24169
diff changeset
329
24290
ca7ee5c1b88d Support for selecting language via packet 28.
voroshil
parents: 24280
diff changeset
330 /**
ca7ee5c1b88d Support for selecting language via packet 28.
voroshil
parents: 24280
diff changeset
331 * List of supported languages.
ca7ee5c1b88d Support for selecting language via packet 28.
voroshil
parents: 24280
diff changeset
332 *
ca7ee5c1b88d Support for selecting language via packet 28.
voroshil
parents: 24280
diff changeset
333 * lang_code bits for primary Language:
ca7ee5c1b88d Support for selecting language via packet 28.
voroshil
parents: 24280
diff changeset
334 * bits 7-4 corresponds to bits 14-11 of 28 packet's first triplet
ca7ee5c1b88d Support for selecting language via packet 28.
voroshil
parents: 24280
diff changeset
335 * bits 3-1 corresponds to bits C12-C14 of packet 0 (lang)
ca7ee5c1b88d Support for selecting language via packet 28.
voroshil
parents: 24280
diff changeset
336 *
ca7ee5c1b88d Support for selecting language via packet 28.
voroshil
parents: 24280
diff changeset
337 * lang_code bits for secondary Language:
ca7ee5c1b88d Support for selecting language via packet 28.
voroshil
parents: 24280
diff changeset
338 * bits 7-5 corresponds to bits 3-1 of 28 packet's second triplet
ca7ee5c1b88d Support for selecting language via packet 28.
voroshil
parents: 24280
diff changeset
339 * bits 4,2 corresponds to bits 18,16 of 28 packet's first triplet
ca7ee5c1b88d Support for selecting language via packet 28.
voroshil
parents: 24280
diff changeset
340 * bits 3,1 corresponds to bits 15,17 of 28 packet's first triplet
ca7ee5c1b88d Support for selecting language via packet 28.
voroshil
parents: 24280
diff changeset
341 *
ca7ee5c1b88d Support for selecting language via packet 28.
voroshil
parents: 24280
diff changeset
342 * For details see Tables 32 and 33 of specification (subclause 15.2)
ca7ee5c1b88d Support for selecting language via packet 28.
voroshil
parents: 24280
diff changeset
343 */
ca7ee5c1b88d Support for selecting language via packet 28.
voroshil
parents: 24280
diff changeset
344 struct {
ca7ee5c1b88d Support for selecting language via packet 28.
voroshil
parents: 24280
diff changeset
345 unsigned char lang_code;
ca7ee5c1b88d Support for selecting language via packet 28.
voroshil
parents: 24280
diff changeset
346 unsigned char charset;
25245
157aafb33efe Add a few forgotten static/const attributes in tvi_vbi.c
reimar
parents: 24788
diff changeset
347 const char* lang_name;
157aafb33efe Add a few forgotten static/const attributes in tvi_vbi.c
reimar
parents: 24788
diff changeset
348 } const tt_languages[]=
24290
ca7ee5c1b88d Support for selecting language via packet 28.
voroshil
parents: 24280
diff changeset
349 {
ca7ee5c1b88d Support for selecting language via packet 28.
voroshil
parents: 24280
diff changeset
350 { 0x01, LATIN, "French"},
ca7ee5c1b88d Support for selecting language via packet 28.
voroshil
parents: 24280
diff changeset
351 { 0x02, LATIN, "Swedish/Finnish/Hungarian"},
ca7ee5c1b88d Support for selecting language via packet 28.
voroshil
parents: 24280
diff changeset
352 { 0x03, LATIN, "Czech/Slovak"},
ca7ee5c1b88d Support for selecting language via packet 28.
voroshil
parents: 24280
diff changeset
353 { 0x04, LATIN, "German"},
ca7ee5c1b88d Support for selecting language via packet 28.
voroshil
parents: 24280
diff changeset
354 { 0x05, LATIN, "Portuguese/Spanish"},
ca7ee5c1b88d Support for selecting language via packet 28.
voroshil
parents: 24280
diff changeset
355 { 0x06, LATIN, "Italian"},
ca7ee5c1b88d Support for selecting language via packet 28.
voroshil
parents: 24280
diff changeset
356
ca7ee5c1b88d Support for selecting language via packet 28.
voroshil
parents: 24280
diff changeset
357 { 0x08, LATIN, "Polish"},
ca7ee5c1b88d Support for selecting language via packet 28.
voroshil
parents: 24280
diff changeset
358 { 0x09, LATIN, "French"},
ca7ee5c1b88d Support for selecting language via packet 28.
voroshil
parents: 24280
diff changeset
359 { 0x0a, LATIN, "Swedish/Finnish/Hungarian"},
ca7ee5c1b88d Support for selecting language via packet 28.
voroshil
parents: 24280
diff changeset
360 { 0x0b, LATIN, "Czech/Slovak"},
ca7ee5c1b88d Support for selecting language via packet 28.
voroshil
parents: 24280
diff changeset
361 { 0x0c, LATIN, "German"},
ca7ee5c1b88d Support for selecting language via packet 28.
voroshil
parents: 24280
diff changeset
362 { 0x0e, LATIN, "Italian"},
ca7ee5c1b88d Support for selecting language via packet 28.
voroshil
parents: 24280
diff changeset
363
ca7ee5c1b88d Support for selecting language via packet 28.
voroshil
parents: 24280
diff changeset
364 { 0x10, LATIN, "English"},
ca7ee5c1b88d Support for selecting language via packet 28.
voroshil
parents: 24280
diff changeset
365 { 0x11, LATIN, "French"},
ca7ee5c1b88d Support for selecting language via packet 28.
voroshil
parents: 24280
diff changeset
366 { 0x12, LATIN, "Swedish/Finnish/Hungarian"},
ca7ee5c1b88d Support for selecting language via packet 28.
voroshil
parents: 24280
diff changeset
367 { 0x13, LATIN, "Turkish"},
ca7ee5c1b88d Support for selecting language via packet 28.
voroshil
parents: 24280
diff changeset
368 { 0x14, LATIN, "German"},
ca7ee5c1b88d Support for selecting language via packet 28.
voroshil
parents: 24280
diff changeset
369 { 0x15, LATIN, "Portuguese/Spanish"},
ca7ee5c1b88d Support for selecting language via packet 28.
voroshil
parents: 24280
diff changeset
370 { 0x16, LATIN, "Italian"},
ca7ee5c1b88d Support for selecting language via packet 28.
voroshil
parents: 24280
diff changeset
371
ca7ee5c1b88d Support for selecting language via packet 28.
voroshil
parents: 24280
diff changeset
372 { 0x1d, LATIN, "Serbian/Croatian/Slovenian (Latin)"},
ca7ee5c1b88d Support for selecting language via packet 28.
voroshil
parents: 24280
diff changeset
373
ca7ee5c1b88d Support for selecting language via packet 28.
voroshil
parents: 24280
diff changeset
374 { 0x20, CYRILLIC1, "Serbian/Croatian (Cyrillic)"},
ca7ee5c1b88d Support for selecting language via packet 28.
voroshil
parents: 24280
diff changeset
375 { 0x21, CYRILLIC2, "Russian, Bulgarian"},
ca7ee5c1b88d Support for selecting language via packet 28.
voroshil
parents: 24280
diff changeset
376 { 0x22, LATIN, "Estonian"},
ca7ee5c1b88d Support for selecting language via packet 28.
voroshil
parents: 24280
diff changeset
377 { 0x23, LATIN, "Czech/Slovak"},
ca7ee5c1b88d Support for selecting language via packet 28.
voroshil
parents: 24280
diff changeset
378 { 0x24, LATIN, "German"},
ca7ee5c1b88d Support for selecting language via packet 28.
voroshil
parents: 24280
diff changeset
379 { 0x25, CYRILLIC3, "Ukrainian"},
ca7ee5c1b88d Support for selecting language via packet 28.
voroshil
parents: 24280
diff changeset
380 { 0x26, LATIN, "Lettish/Lithuanian"},
ca7ee5c1b88d Support for selecting language via packet 28.
voroshil
parents: 24280
diff changeset
381
ca7ee5c1b88d Support for selecting language via packet 28.
voroshil
parents: 24280
diff changeset
382 { 0x33, LATIN, "Turkish"},
ca7ee5c1b88d Support for selecting language via packet 28.
voroshil
parents: 24280
diff changeset
383 { 0x37, GREEK, "Greek"},
ca7ee5c1b88d Support for selecting language via packet 28.
voroshil
parents: 24280
diff changeset
384
ca7ee5c1b88d Support for selecting language via packet 28.
voroshil
parents: 24280
diff changeset
385 { 0x40, LATIN, "English"},
ca7ee5c1b88d Support for selecting language via packet 28.
voroshil
parents: 24280
diff changeset
386 { 0x41, LATIN, "French"},
ca7ee5c1b88d Support for selecting language via packet 28.
voroshil
parents: 24280
diff changeset
387 // { 0x47, ARABIC, "Arabic"},
ca7ee5c1b88d Support for selecting language via packet 28.
voroshil
parents: 24280
diff changeset
388
ca7ee5c1b88d Support for selecting language via packet 28.
voroshil
parents: 24280
diff changeset
389 // { 0x55, HEBREW, "Hebrew"},
ca7ee5c1b88d Support for selecting language via packet 28.
voroshil
parents: 24280
diff changeset
390 // { 0x57, ARABIC, "Arabic"},
ca7ee5c1b88d Support for selecting language via packet 28.
voroshil
parents: 24280
diff changeset
391
ca7ee5c1b88d Support for selecting language via packet 28.
voroshil
parents: 24280
diff changeset
392 { 0x00, LATIN, "English"},
ca7ee5c1b88d Support for selecting language via packet 28.
voroshil
parents: 24280
diff changeset
393 };
ca7ee5c1b88d Support for selecting language via packet 28.
voroshil
parents: 24280
diff changeset
394
ca7ee5c1b88d Support for selecting language via packet 28.
voroshil
parents: 24280
diff changeset
395 /**
ca7ee5c1b88d Support for selecting language via packet 28.
voroshil
parents: 24280
diff changeset
396 * \brief 24/18 Hamming code decoding
ca7ee5c1b88d Support for selecting language via packet 28.
voroshil
parents: 24280
diff changeset
397 * \param data bytes with hamming code (array must be at least 3 bytes long)
ca7ee5c1b88d Support for selecting language via packet 28.
voroshil
parents: 24280
diff changeset
398 * \return -1 if multiple bit error occured, D1-DI data bits - otherwise
ca7ee5c1b88d Support for selecting language via packet 28.
voroshil
parents: 24280
diff changeset
399 *
ca7ee5c1b88d Support for selecting language via packet 28.
voroshil
parents: 24280
diff changeset
400 * \note Bits must be correctly ordered, that is for 24/18 (lowest bit first)
ca7ee5c1b88d Support for selecting language via packet 28.
voroshil
parents: 24280
diff changeset
401 * P1 P2 D1 P3 D2 D3 D4 P4 D5 D6 D7 D8 D9 DA DB P5 DC DD DE DF DG DH DI P6
ca7ee5c1b88d Support for selecting language via packet 28.
voroshil
parents: 24280
diff changeset
402 */
25245
157aafb33efe Add a few forgotten static/const attributes in tvi_vbi.c
reimar
parents: 24788
diff changeset
403 static int corrHamm24(unsigned char *data){
24290
ca7ee5c1b88d Support for selecting language via packet 28.
voroshil
parents: 24280
diff changeset
404 unsigned char syndrom=0;
ca7ee5c1b88d Support for selecting language via packet 28.
voroshil
parents: 24280
diff changeset
405 int cw=data[0] | (data[1]<<8) | (data[2]<<16);
ca7ee5c1b88d Support for selecting language via packet 28.
voroshil
parents: 24280
diff changeset
406 int i;
ca7ee5c1b88d Support for selecting language via packet 28.
voroshil
parents: 24280
diff changeset
407
ca7ee5c1b88d Support for selecting language via packet 28.
voroshil
parents: 24280
diff changeset
408 for(i=0;i<23;i++)
ca7ee5c1b88d Support for selecting language via packet 28.
voroshil
parents: 24280
diff changeset
409 syndrom^=((cw>>i)&1)*(i+33);
ca7ee5c1b88d Support for selecting language via packet 28.
voroshil
parents: 24280
diff changeset
410
ca7ee5c1b88d Support for selecting language via packet 28.
voroshil
parents: 24280
diff changeset
411 syndrom^=(cw>>11)&32;
ca7ee5c1b88d Support for selecting language via packet 28.
voroshil
parents: 24280
diff changeset
412
ca7ee5c1b88d Support for selecting language via packet 28.
voroshil
parents: 24280
diff changeset
413 if(syndrom&31){
ca7ee5c1b88d Support for selecting language via packet 28.
voroshil
parents: 24280
diff changeset
414 if(syndrom < 32 || syndrom > 55)
ca7ee5c1b88d Support for selecting language via packet 28.
voroshil
parents: 24280
diff changeset
415 return -1;
ca7ee5c1b88d Support for selecting language via packet 28.
voroshil
parents: 24280
diff changeset
416 cw ^= 1<<((syndrom&31)-1);
ca7ee5c1b88d Support for selecting language via packet 28.
voroshil
parents: 24280
diff changeset
417 }
ca7ee5c1b88d Support for selecting language via packet 28.
voroshil
parents: 24280
diff changeset
418
ca7ee5c1b88d Support for selecting language via packet 28.
voroshil
parents: 24280
diff changeset
419 return (cw&4)>>2 |
ca7ee5c1b88d Support for selecting language via packet 28.
voroshil
parents: 24280
diff changeset
420 (cw&0x70)>>3 |
ca7ee5c1b88d Support for selecting language via packet 28.
voroshil
parents: 24280
diff changeset
421 (cw&0x3f00)>>4 |
ca7ee5c1b88d Support for selecting language via packet 28.
voroshil
parents: 24280
diff changeset
422 (cw&0x3f0000)>>5;
ca7ee5c1b88d Support for selecting language via packet 28.
voroshil
parents: 24280
diff changeset
423 }
ca7ee5c1b88d Support for selecting language via packet 28.
voroshil
parents: 24280
diff changeset
424
ca7ee5c1b88d Support for selecting language via packet 28.
voroshil
parents: 24280
diff changeset
425 /**
ca7ee5c1b88d Support for selecting language via packet 28.
voroshil
parents: 24280
diff changeset
426 * \brief converts language bits to charset index
ca7ee5c1b88d Support for selecting language via packet 28.
voroshil
parents: 24280
diff changeset
427 * \param lang language bits
ca7ee5c1b88d Support for selecting language via packet 28.
voroshil
parents: 24280
diff changeset
428 * \return charset index in lang_chars array
ca7ee5c1b88d Support for selecting language via packet 28.
voroshil
parents: 24280
diff changeset
429 */
ca7ee5c1b88d Support for selecting language via packet 28.
voroshil
parents: 24280
diff changeset
430 static int lang2charset (int lang){
ca7ee5c1b88d Support for selecting language via packet 28.
voroshil
parents: 24280
diff changeset
431 int i;
ca7ee5c1b88d Support for selecting language via packet 28.
voroshil
parents: 24280
diff changeset
432 for(i=0;tt_languages[i].lang_code;i++)
ca7ee5c1b88d Support for selecting language via packet 28.
voroshil
parents: 24280
diff changeset
433 if(tt_languages[i].lang_code==lang)
ca7ee5c1b88d Support for selecting language via packet 28.
voroshil
parents: 24280
diff changeset
434 break;
ca7ee5c1b88d Support for selecting language via packet 28.
voroshil
parents: 24280
diff changeset
435
ca7ee5c1b88d Support for selecting language via packet 28.
voroshil
parents: 24280
diff changeset
436 return tt_languages[i].charset;
23899
34532db868ba Teletext support.
voroshil
parents:
diff changeset
437 }
34532db868ba Teletext support.
voroshil
parents:
diff changeset
438
34532db868ba Teletext support.
voroshil
parents:
diff changeset
439 /**
34532db868ba Teletext support.
voroshil
parents:
diff changeset
440 * \brief convert chars from curent teletext codepage into MPlayer charset
34532db868ba Teletext support.
voroshil
parents:
diff changeset
441 * \param p raw teletext char to decode
24290
ca7ee5c1b88d Support for selecting language via packet 28.
voroshil
parents: 24280
diff changeset
442 * \param charset index on lang_chars
ca7ee5c1b88d Support for selecting language via packet 28.
voroshil
parents: 24280
diff changeset
443 * \param lang index in substitution array (latin charset only)
23899
34532db868ba Teletext support.
voroshil
parents:
diff changeset
444 * \return UTF8 char
34532db868ba Teletext support.
voroshil
parents:
diff changeset
445 *
34532db868ba Teletext support.
voroshil
parents:
diff changeset
446 * \remarks
34532db868ba Teletext support.
voroshil
parents:
diff changeset
447 * routine will analyze raw member of given tt_char structure and
34532db868ba Teletext support.
voroshil
parents:
diff changeset
448 * fill unicode member of the same struct with appropriate utf8 code.
34532db868ba Teletext support.
voroshil
parents:
diff changeset
449 */
24290
ca7ee5c1b88d Support for selecting language via packet 28.
voroshil
parents: 24280
diff changeset
450 static unsigned int conv2uni(unsigned int p,int charset,int lang)
23899
34532db868ba Teletext support.
voroshil
parents:
diff changeset
451 {
24290
ca7ee5c1b88d Support for selecting language via packet 28.
voroshil
parents: 24280
diff changeset
452
23899
34532db868ba Teletext support.
voroshil
parents:
diff changeset
453 if(p<0x80 && p>=0x20){
24271
c0474098f1a5 Make charset constants naming consistant
voroshil
parents: 24256
diff changeset
454 if(charset==LATIN){
24290
ca7ee5c1b88d Support for selecting language via packet 28.
voroshil
parents: 24280
diff changeset
455 lang&=7;
24184
337fbf5709ab Add support for Latin National Option Sub-Sets
voroshil
parents: 24169
diff changeset
456 if (p>=0x23 && p<=0x24){
337fbf5709ab Add support for Latin National Option Sub-Sets
voroshil
parents: 24169
diff changeset
457 return latin_subchars[lang][p-0x23];
337fbf5709ab Add support for Latin National Option Sub-Sets
voroshil
parents: 24169
diff changeset
458 }else if (p==0x40){
337fbf5709ab Add support for Latin National Option Sub-Sets
voroshil
parents: 24169
diff changeset
459 return latin_subchars[lang][2];
337fbf5709ab Add support for Latin National Option Sub-Sets
voroshil
parents: 24169
diff changeset
460 }else if (p>=0x5b && p<=0x60){
24190
8325604af21e Fix typo
voroshil
parents: 24186
diff changeset
461 return latin_subchars[lang][p-0x5b+3];
24184
337fbf5709ab Add support for Latin National Option Sub-Sets
voroshil
parents: 24169
diff changeset
462 }else if (p>=0x7b && p<=0x7e){
337fbf5709ab Add support for Latin National Option Sub-Sets
voroshil
parents: 24169
diff changeset
463 return latin_subchars[lang][p-0x7b+9];
24278
2f47e955fa13 (cosmetics) replace tabs with spaces
voroshil
parents: 24277
diff changeset
464 }
2f47e955fa13 (cosmetics) replace tabs with spaces
voroshil
parents: 24277
diff changeset
465 }
24184
337fbf5709ab Add support for Latin National Option Sub-Sets
voroshil
parents: 24169
diff changeset
466 return lang_chars[charset][p-0x20];
23899
34532db868ba Teletext support.
voroshil
parents:
diff changeset
467 }else
34532db868ba Teletext support.
voroshil
parents:
diff changeset
468 return 0x20;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
469 }
34532db868ba Teletext support.
voroshil
parents:
diff changeset
470
34532db868ba Teletext support.
voroshil
parents:
diff changeset
471 static void init_vbi_consts(priv_vbi_t* priv){
34532db868ba Teletext support.
voroshil
parents:
diff changeset
472 int i,j;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
473 double ang;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
474 for(i=0; i<256; i++){
34532db868ba Teletext support.
voroshil
parents:
diff changeset
475 j=i&0x7F;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
476 j^= j+j;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
477 j^= j<<2;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
478 j^= j<<4;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
479 fixParity[i]= i ^ (j&0x80) ^ 0x80;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
480 }
34532db868ba Teletext support.
voroshil
parents:
diff changeset
481
34532db868ba Teletext support.
voroshil
parents:
diff changeset
482 for(i=0,ang=0; i<12; i++,ang+=M_PI/priv->bpb){
34532db868ba Teletext support.
voroshil
parents:
diff changeset
483 si[i]= sin(ang);
34532db868ba Teletext support.
voroshil
parents:
diff changeset
484 co[i]= cos(ang);
34532db868ba Teletext support.
voroshil
parents:
diff changeset
485 }
34532db868ba Teletext support.
voroshil
parents:
diff changeset
486
34532db868ba Teletext support.
voroshil
parents:
diff changeset
487 priv->bpb=(priv->ptsp->sampling_rate/6937500.0)*ONE_FIXP+0.5;
24099
d517c397de7d Fix [soc:eoc] stubs.
voroshil
parents: 23928
diff changeset
488 priv->soc=FFMAX(9.2e-6*priv->ptsp->sampling_rate-priv->ptsp->offset, 0);
d517c397de7d Fix [soc:eoc] stubs.
voroshil
parents: 23928
diff changeset
489 priv->eoc=FFMIN(12.9e-6*priv->ptsp->sampling_rate-priv->ptsp->offset,
d517c397de7d Fix [soc:eoc] stubs.
voroshil
parents: 23928
diff changeset
490 priv->ptsp->samples_per_line-43*8*priv->bpb/ONE_FIXP);
d517c397de7d Fix [soc:eoc] stubs.
voroshil
parents: 23928
diff changeset
491 if (priv->eoc - priv->soc<16*priv->bpb/ONE_FIXP){ // invalid [soc:eoc]
d517c397de7d Fix [soc:eoc] stubs.
voroshil
parents: 23928
diff changeset
492 priv->soc=0;
d517c397de7d Fix [soc:eoc] stubs.
voroshil
parents: 23928
diff changeset
493 priv->eoc=92;
24197
7b3abda49409 (cosmetics) remove unnecessary ';'
voroshil
parents: 24190
diff changeset
494 }
23899
34532db868ba Teletext support.
voroshil
parents:
diff changeset
495 priv->bp8bl=0.97*8*priv->bpb/ONE_FIXP; // -3% tolerance
34532db868ba Teletext support.
voroshil
parents:
diff changeset
496 priv->bp8bh=1.03*8*priv->bpb/ONE_FIXP; // +3% tolerance
34532db868ba Teletext support.
voroshil
parents:
diff changeset
497 }
34532db868ba Teletext support.
voroshil
parents:
diff changeset
498 /**
34532db868ba Teletext support.
voroshil
parents:
diff changeset
499 * \brief calculate increased/decreased by given value page number
34532db868ba Teletext support.
voroshil
parents:
diff changeset
500 * \param curr current page number in hexadecimal for
34532db868ba Teletext support.
voroshil
parents:
diff changeset
501 * \param direction decimal value (can be negative) to add to value
34532db868ba Teletext support.
voroshil
parents:
diff changeset
502 * of curr parameter
34532db868ba Teletext support.
voroshil
parents:
diff changeset
503 * \return new page number in hexadecimal form
34532db868ba Teletext support.
voroshil
parents:
diff changeset
504 *
34532db868ba Teletext support.
voroshil
parents:
diff changeset
505 * VBI page numbers are represented in special hexadecimal form, e.g.
34532db868ba Teletext support.
voroshil
parents:
diff changeset
506 * page with number 123 (as seen by user) internally has number 0x123.
34532db868ba Teletext support.
voroshil
parents:
diff changeset
507 * and equation 0x123+8 should be equal to 0x131 instead of regular 0x12b.
34532db868ba Teletext support.
voroshil
parents:
diff changeset
508 *
34532db868ba Teletext support.
voroshil
parents:
diff changeset
509 *
34532db868ba Teletext support.
voroshil
parents:
diff changeset
510 * Page numbers 0xYYY (where Y is not belongs to (0..9).
34532db868ba Teletext support.
voroshil
parents:
diff changeset
511 * Page number belongs to [0x000,0x799] or [0x100:0x899] (first 0 can be
34532db868ba Teletext support.
voroshil
parents:
diff changeset
512 * treated as '8')
34532db868ba Teletext support.
voroshil
parents:
diff changeset
513 */
34532db868ba Teletext support.
voroshil
parents:
diff changeset
514 static int steppage(int p, int direction, int skip_hidden)
34532db868ba Teletext support.
voroshil
parents:
diff changeset
515 {
34532db868ba Teletext support.
voroshil
parents:
diff changeset
516 if(skip_hidden)
34532db868ba Teletext support.
voroshil
parents:
diff changeset
517 p=(p&15)+((p>>4)&15)*10+(p>>8)*100;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
518 p+=direction;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
519 if(skip_hidden){
34532db868ba Teletext support.
voroshil
parents:
diff changeset
520 p=(p+800)%800;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
521 p=(p%10)+((p/10)%10)*16+(p/100)*256;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
522 }
34532db868ba Teletext support.
voroshil
parents:
diff changeset
523
34532db868ba Teletext support.
voroshil
parents:
diff changeset
524 return p&0x7ff;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
525 }
34532db868ba Teletext support.
voroshil
parents:
diff changeset
526
34532db868ba Teletext support.
voroshil
parents:
diff changeset
527 /*
34532db868ba Teletext support.
voroshil
parents:
diff changeset
528 ------------------------------------------------------------------
34532db868ba Teletext support.
voroshil
parents:
diff changeset
529 Cache stuff
34532db868ba Teletext support.
voroshil
parents:
diff changeset
530 ------------------------------------------------------------------
34532db868ba Teletext support.
voroshil
parents:
diff changeset
531 */
34532db868ba Teletext support.
voroshil
parents:
diff changeset
532
34532db868ba Teletext support.
voroshil
parents:
diff changeset
533 /**
34532db868ba Teletext support.
voroshil
parents:
diff changeset
534 * \brief add/update entry in cache
34532db868ba Teletext support.
voroshil
parents:
diff changeset
535 * \param priv private data structure
34532db868ba Teletext support.
voroshil
parents:
diff changeset
536 * \param pg page to store in cache
34532db868ba Teletext support.
voroshil
parents:
diff changeset
537 * \param line line to update (value below 0 means update entire page)
34532db868ba Teletext support.
voroshil
parents:
diff changeset
538 */
34532db868ba Teletext support.
voroshil
parents:
diff changeset
539 static void put_to_cache(priv_vbi_t* priv,tt_page* pg,int line){
34532db868ba Teletext support.
voroshil
parents:
diff changeset
540 tt_page* pgc; //page in cache
24244
e446bad0872c Implement X/27/0 packet decoding.
voroshil
parents: 24232
diff changeset
541 int i,j,count;
23899
34532db868ba Teletext support.
voroshil
parents:
diff changeset
542
34532db868ba Teletext support.
voroshil
parents:
diff changeset
543 if(line<0){
34532db868ba Teletext support.
voroshil
parents:
diff changeset
544 i=0;
24278
2f47e955fa13 (cosmetics) replace tabs with spaces
voroshil
parents: 24277
diff changeset
545 count=VBI_ROWS*VBI_COLUMNS;
23899
34532db868ba Teletext support.
voroshil
parents:
diff changeset
546 }else if(line<VBI_ROWS){
34532db868ba Teletext support.
voroshil
parents:
diff changeset
547 i=line*VBI_COLUMNS;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
548 count=(line+1)*VBI_COLUMNS;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
549 }else
34532db868ba Teletext support.
voroshil
parents:
diff changeset
550 return;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
551
34532db868ba Teletext support.
voroshil
parents:
diff changeset
552 pthread_mutex_lock(&(priv->buffer_mutex));
34532db868ba Teletext support.
voroshil
parents:
diff changeset
553
34532db868ba Teletext support.
voroshil
parents:
diff changeset
554 if(!priv->ptt_cache[pg->pagenum]){
34532db868ba Teletext support.
voroshil
parents:
diff changeset
555 priv->ptt_cache[pg->pagenum]=calloc(1,sizeof(tt_page));
34532db868ba Teletext support.
voroshil
parents:
diff changeset
556 pgc=priv->ptt_cache[pg->pagenum];
34532db868ba Teletext support.
voroshil
parents:
diff changeset
557 }else{
34532db868ba Teletext support.
voroshil
parents:
diff changeset
558 pgc=priv->ptt_cache[pg->pagenum];
34532db868ba Teletext support.
voroshil
parents:
diff changeset
559 while(pgc->next_subpage && pgc->subpagenum!=pg->subpagenum)
34532db868ba Teletext support.
voroshil
parents:
diff changeset
560 pgc=pgc->next_subpage;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
561
34532db868ba Teletext support.
voroshil
parents:
diff changeset
562 if(pgc->subpagenum!=pg->subpagenum){
34532db868ba Teletext support.
voroshil
parents:
diff changeset
563 pgc->next_subpage=calloc(1,sizeof(tt_page));
34532db868ba Teletext support.
voroshil
parents:
diff changeset
564 pgc=pgc->next_subpage;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
565 }
34532db868ba Teletext support.
voroshil
parents:
diff changeset
566 }
34532db868ba Teletext support.
voroshil
parents:
diff changeset
567 pgc->pagenum=pg->pagenum;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
568 pgc->subpagenum=pg->subpagenum;
24290
ca7ee5c1b88d Support for selecting language via packet 28.
voroshil
parents: 24280
diff changeset
569 pgc->primary_lang=pg->primary_lang;
ca7ee5c1b88d Support for selecting language via packet 28.
voroshil
parents: 24280
diff changeset
570 pgc->secondary_lang=pg->secondary_lang;
23899
34532db868ba Teletext support.
voroshil
parents:
diff changeset
571 pgc->flags=pg->flags;
24244
e446bad0872c Implement X/27/0 packet decoding.
voroshil
parents: 24232
diff changeset
572 for(j=0;j<6;++j)
e446bad0872c Implement X/27/0 packet decoding.
voroshil
parents: 24232
diff changeset
573 pgc->links[j]=pg->links[j];
23899
34532db868ba Teletext support.
voroshil
parents:
diff changeset
574 //instead of copying entire page into cache, copy only undamaged
34532db868ba Teletext support.
voroshil
parents:
diff changeset
575 //symbols into cache
34532db868ba Teletext support.
voroshil
parents:
diff changeset
576 for(;i<count;i++){
34532db868ba Teletext support.
voroshil
parents:
diff changeset
577 if(!(pg->raw[i]&0x80))
34532db868ba Teletext support.
voroshil
parents:
diff changeset
578 pgc->raw[i]=pg->raw[i];
34532db868ba Teletext support.
voroshil
parents:
diff changeset
579 else
34532db868ba Teletext support.
voroshil
parents:
diff changeset
580 mp_msg(MSGT_TV,MSGL_DBG3,"char error. pg:%x, c[%d]=0x%x\n",
34532db868ba Teletext support.
voroshil
parents:
diff changeset
581 pg->pagenum,i,pg->raw[i]);
34532db868ba Teletext support.
voroshil
parents:
diff changeset
582 }
34532db868ba Teletext support.
voroshil
parents:
diff changeset
583 pgc->active=1;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
584 pthread_mutex_unlock(&(priv->buffer_mutex));
34532db868ba Teletext support.
voroshil
parents:
diff changeset
585 }
34532db868ba Teletext support.
voroshil
parents:
diff changeset
586
34532db868ba Teletext support.
voroshil
parents:
diff changeset
587 /**
34532db868ba Teletext support.
voroshil
parents:
diff changeset
588 * \brief get any subpage number of given page
34532db868ba Teletext support.
voroshil
parents:
diff changeset
589 * \param priv private data structure
34532db868ba Teletext support.
voroshil
parents:
diff changeset
590 * \param pagenum page number to search subpages in
34532db868ba Teletext support.
voroshil
parents:
diff changeset
591 *
34532db868ba Teletext support.
voroshil
parents:
diff changeset
592 * \return subpage number of first found subpage which belongs to
34532db868ba Teletext support.
voroshil
parents:
diff changeset
593 * given page number
34532db868ba Teletext support.
voroshil
parents:
diff changeset
594 *
34532db868ba Teletext support.
voroshil
parents:
diff changeset
595 * \note page itself is subpage too (and usually has subpage number 0)
34532db868ba Teletext support.
voroshil
parents:
diff changeset
596 */
34532db868ba Teletext support.
voroshil
parents:
diff changeset
597 static inline int get_subpagenum_from_cache(priv_vbi_t* priv, int pagenum){
34532db868ba Teletext support.
voroshil
parents:
diff changeset
598 if (!priv->ptt_cache[pagenum])
24294
68b413a3ce51 Fix missed -1 -> 0x3f7f changes for subpage number.
voroshil
parents: 24293
diff changeset
599 return 0x3f7f;
23899
34532db868ba Teletext support.
voroshil
parents:
diff changeset
600 else
34532db868ba Teletext support.
voroshil
parents:
diff changeset
601 return priv->ptt_cache[pagenum]->subpagenum;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
602 }
34532db868ba Teletext support.
voroshil
parents:
diff changeset
603
34532db868ba Teletext support.
voroshil
parents:
diff changeset
604 /**
34532db868ba Teletext support.
voroshil
parents:
diff changeset
605 * \brief get page from cache by it page and subpage number
34532db868ba Teletext support.
voroshil
parents:
diff changeset
606 * \param priv private data structure
34532db868ba Teletext support.
voroshil
parents:
diff changeset
607 * \param pagenum page number
34532db868ba Teletext support.
voroshil
parents:
diff changeset
608 * \param subpagenum subpage number
34532db868ba Teletext support.
voroshil
parents:
diff changeset
609 *
34532db868ba Teletext support.
voroshil
parents:
diff changeset
610 * \return pointer to tt_page structure if requested page is found
34532db868ba Teletext support.
voroshil
parents:
diff changeset
611 * and NULL otherwise
34532db868ba Teletext support.
voroshil
parents:
diff changeset
612 */
34532db868ba Teletext support.
voroshil
parents:
diff changeset
613 static inline tt_page* get_from_cache(priv_vbi_t* priv, int pagenum,int subpagenum){
34532db868ba Teletext support.
voroshil
parents:
diff changeset
614 tt_page* tp=priv->ptt_cache[pagenum];
34532db868ba Teletext support.
voroshil
parents:
diff changeset
615
34532db868ba Teletext support.
voroshil
parents:
diff changeset
616 while(tp && tp->subpagenum!=subpagenum)
34532db868ba Teletext support.
voroshil
parents:
diff changeset
617 tp=tp->next_subpage;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
618 return tp;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
619 }
34532db868ba Teletext support.
voroshil
parents:
diff changeset
620
34532db868ba Teletext support.
voroshil
parents:
diff changeset
621 /**
34532db868ba Teletext support.
voroshil
parents:
diff changeset
622 * \brief clears cache
34532db868ba Teletext support.
voroshil
parents:
diff changeset
623 * \param priv private data structure
34532db868ba Teletext support.
voroshil
parents:
diff changeset
624 *
34532db868ba Teletext support.
voroshil
parents:
diff changeset
625 * Deletes all tt_page structures from cache and frees allocated memory.
34532db868ba Teletext support.
voroshil
parents:
diff changeset
626 * Only zero-filled array of pointers remains in memory
34532db868ba Teletext support.
voroshil
parents:
diff changeset
627 */
34532db868ba Teletext support.
voroshil
parents:
diff changeset
628 static void clear_cache(priv_vbi_t* priv){
34532db868ba Teletext support.
voroshil
parents:
diff changeset
629 int i;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
630 tt_page* tp;
24301
15d547dfa66b Make sure that no pages will left in cache during
voroshil
parents: 24296
diff changeset
631
24305
414b72437fe3 Increase number of skipped buffers to 5 to avoid mixing teletext pages from
voroshil
parents: 24301
diff changeset
632 /*
414b72437fe3 Increase number of skipped buffers to 5 to avoid mixing teletext pages from
voroshil
parents: 24301
diff changeset
633 Skip next 5 buffers to avoid mixing teletext pages from different
414b72437fe3 Increase number of skipped buffers to 5 to avoid mixing teletext pages from
voroshil
parents: 24301
diff changeset
634 channels during channel switch
414b72437fe3 Increase number of skipped buffers to 5 to avoid mixing teletext pages from
voroshil
parents: 24301
diff changeset
635 */
414b72437fe3 Increase number of skipped buffers to 5 to avoid mixing teletext pages from
voroshil
parents: 24301
diff changeset
636 priv->cache_reset=5;
23899
34532db868ba Teletext support.
voroshil
parents:
diff changeset
637 for(i=0;i<VBI_MAX_PAGES;i++){
34532db868ba Teletext support.
voroshil
parents:
diff changeset
638 while(priv->ptt_cache[i]){
34532db868ba Teletext support.
voroshil
parents:
diff changeset
639 tp=priv->ptt_cache[i];
34532db868ba Teletext support.
voroshil
parents:
diff changeset
640 priv->ptt_cache[i]=tp->next_subpage;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
641 free(tp);
34532db868ba Teletext support.
voroshil
parents:
diff changeset
642 }
34532db868ba Teletext support.
voroshil
parents:
diff changeset
643 }
24232
d0290b80e612 Implement 8/30 format 1 teletext packet decoding
voroshil
parents: 24197
diff changeset
644 priv->initialsubpage=priv->networkid=0;
d0290b80e612 Implement 8/30 format 1 teletext packet decoding
voroshil
parents: 24197
diff changeset
645 priv->timeoffset=0;
d0290b80e612 Implement 8/30 format 1 teletext packet decoding
voroshil
parents: 24197
diff changeset
646 priv->juliandate=priv->universaltime=0;
d0290b80e612 Implement 8/30 format 1 teletext packet decoding
voroshil
parents: 24197
diff changeset
647 memset(priv->networkname,0,21);
23899
34532db868ba Teletext support.
voroshil
parents:
diff changeset
648 }
34532db868ba Teletext support.
voroshil
parents:
diff changeset
649
34532db868ba Teletext support.
voroshil
parents:
diff changeset
650 /**
34532db868ba Teletext support.
voroshil
parents:
diff changeset
651 * \brief cache initialization
34532db868ba Teletext support.
voroshil
parents:
diff changeset
652 * \param priv private data structure
34532db868ba Teletext support.
voroshil
parents:
diff changeset
653 *
34532db868ba Teletext support.
voroshil
parents:
diff changeset
654 * \note Has to be called before any cache operations!
34532db868ba Teletext support.
voroshil
parents:
diff changeset
655 */
34532db868ba Teletext support.
voroshil
parents:
diff changeset
656 static void init_cache(priv_vbi_t* priv){
34532db868ba Teletext support.
voroshil
parents:
diff changeset
657 priv->ptt_cache=calloc(VBI_MAX_PAGES,sizeof(tt_page*));
34532db868ba Teletext support.
voroshil
parents:
diff changeset
658 }
34532db868ba Teletext support.
voroshil
parents:
diff changeset
659
34532db868ba Teletext support.
voroshil
parents:
diff changeset
660 /**
34532db868ba Teletext support.
voroshil
parents:
diff changeset
661 * \brief destroys cache
34532db868ba Teletext support.
voroshil
parents:
diff changeset
662 * \param priv private data structure
34532db868ba Teletext support.
voroshil
parents:
diff changeset
663 *
34532db868ba Teletext support.
voroshil
parents:
diff changeset
664 * Frees all memory allocated for cache (including array of pointers).
34532db868ba Teletext support.
voroshil
parents:
diff changeset
665 * It is safe to call this routine multiple times
34532db868ba Teletext support.
voroshil
parents:
diff changeset
666 */
34532db868ba Teletext support.
voroshil
parents:
diff changeset
667 static void destroy_cache(priv_vbi_t* priv){
34532db868ba Teletext support.
voroshil
parents:
diff changeset
668 if(priv->ptt_cache){
34532db868ba Teletext support.
voroshil
parents:
diff changeset
669 clear_cache(priv);
34532db868ba Teletext support.
voroshil
parents:
diff changeset
670 free(priv->ptt_cache);
34532db868ba Teletext support.
voroshil
parents:
diff changeset
671 priv->ptt_cache=NULL;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
672 }
34532db868ba Teletext support.
voroshil
parents:
diff changeset
673 }
34532db868ba Teletext support.
voroshil
parents:
diff changeset
674
34532db868ba Teletext support.
voroshil
parents:
diff changeset
675 /*
34532db868ba Teletext support.
voroshil
parents:
diff changeset
676 ------------------------------------------------------------------
34532db868ba Teletext support.
voroshil
parents:
diff changeset
677 Decoder stuff
34532db868ba Teletext support.
voroshil
parents:
diff changeset
678 ------------------------------------------------------------------
34532db868ba Teletext support.
voroshil
parents:
diff changeset
679 */
34532db868ba Teletext support.
voroshil
parents:
diff changeset
680 /**
34532db868ba Teletext support.
voroshil
parents:
diff changeset
681 * \brief converts raw teletext page into useful format (1st rendering stage)
34532db868ba Teletext support.
voroshil
parents:
diff changeset
682 * \param pg page to decode
24290
ca7ee5c1b88d Support for selecting language via packet 28.
voroshil
parents: 24280
diff changeset
683 * \param raw raw data to decode page from
ca7ee5c1b88d Support for selecting language via packet 28.
voroshil
parents: 24280
diff changeset
684 * \param primary_lang primary language code
ca7ee5c1b88d Support for selecting language via packet 28.
voroshil
parents: 24280
diff changeset
685 * \param secondary_lang secondary language code
ca7ee5c1b88d Support for selecting language via packet 28.
voroshil
parents: 24280
diff changeset
686 *
23899
34532db868ba Teletext support.
voroshil
parents:
diff changeset
687 * Routine fills tt_char structure of each teletext_page character with proper
34532db868ba Teletext support.
voroshil
parents:
diff changeset
688 * info about foreground and background colors, character
34532db868ba Teletext support.
voroshil
parents:
diff changeset
689 * type (graphics/control/text).
34532db868ba Teletext support.
voroshil
parents:
diff changeset
690 */
24344
09d402672398 Implement boxes for subtitle teletext pages.
voroshil
parents: 24342
diff changeset
691 static void decode_page(tt_char* p,unsigned char* raw,int primary_lang,int secondary_lang,int flags)
23899
34532db868ba Teletext support.
voroshil
parents:
diff changeset
692 {
34532db868ba Teletext support.
voroshil
parents:
diff changeset
693 int row,col;
24290
ca7ee5c1b88d Support for selecting language via packet 28.
voroshil
parents: 24280
diff changeset
694 int prim_charset=lang2charset(primary_lang);
ca7ee5c1b88d Support for selecting language via packet 28.
voroshil
parents: 24280
diff changeset
695 int sec_charset=lang2charset(secondary_lang);
23899
34532db868ba Teletext support.
voroshil
parents:
diff changeset
696
34532db868ba Teletext support.
voroshil
parents:
diff changeset
697 for(row=0;row<VBI_ROWS;row++) {
24290
ca7ee5c1b88d Support for selecting language via packet 28.
voroshil
parents: 24280
diff changeset
698 int prim_lang=1;
24280
c1d941c2d9a0 Small code simplification as suggested by Reimar:
voroshil
parents: 24279
diff changeset
699 int gfx=0;
c1d941c2d9a0 Small code simplification as suggested by Reimar:
voroshil
parents: 24279
diff changeset
700 int fg_color=7;
c1d941c2d9a0 Small code simplification as suggested by Reimar:
voroshil
parents: 24279
diff changeset
701 int bg_color=0;
c1d941c2d9a0 Small code simplification as suggested by Reimar:
voroshil
parents: 24279
diff changeset
702 int separated=0;
c1d941c2d9a0 Small code simplification as suggested by Reimar:
voroshil
parents: 24279
diff changeset
703 int conceal=0;
c1d941c2d9a0 Small code simplification as suggested by Reimar:
voroshil
parents: 24279
diff changeset
704 int hold=0;
24292
ca146808e926 Proper support for flashing chars in teletext pages.
voroshil
parents: 24290
diff changeset
705 int flash=0;
24344
09d402672398 Implement boxes for subtitle teletext pages.
voroshil
parents: 24342
diff changeset
706 int box=0;
09d402672398 Implement boxes for subtitle teletext pages.
voroshil
parents: 24342
diff changeset
707
24280
c1d941c2d9a0 Small code simplification as suggested by Reimar:
voroshil
parents: 24279
diff changeset
708 tt_char tt_held=tt_space;
23899
34532db868ba Teletext support.
voroshil
parents:
diff changeset
709 for(col=0;col<VBI_COLUMNS;col++){
24280
c1d941c2d9a0 Small code simplification as suggested by Reimar:
voroshil
parents: 24279
diff changeset
710 int i=row*VBI_COLUMNS+col;
c1d941c2d9a0 Small code simplification as suggested by Reimar:
voroshil
parents: 24279
diff changeset
711 int c=raw[i];
23899
34532db868ba Teletext support.
voroshil
parents:
diff changeset
712 p[i].raw=c;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
713 if(c&0x80){ //damaged char
34532db868ba Teletext support.
voroshil
parents:
diff changeset
714 p[i]=tt_error;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
715 continue;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
716 }
24344
09d402672398 Implement boxes for subtitle teletext pages.
voroshil
parents: 24342
diff changeset
717 if((flags&TT_PGFL_SUBTITLE) || (flags&TT_PGFL_NEWFLASH))
09d402672398 Implement boxes for subtitle teletext pages.
voroshil
parents: 24342
diff changeset
718 p[i].hidden=!box;
09d402672398 Implement boxes for subtitle teletext pages.
voroshil
parents: 24342
diff changeset
719 else
09d402672398 Implement boxes for subtitle teletext pages.
voroshil
parents: 24342
diff changeset
720 p[i].hidden=0;
23899
34532db868ba Teletext support.
voroshil
parents:
diff changeset
721 p[i].gfx=gfx?(separated?2:1):0;
24290
ca7ee5c1b88d Support for selecting language via packet 28.
voroshil
parents: 24280
diff changeset
722 p[i].lng=prim_lang;
23899
34532db868ba Teletext support.
voroshil
parents:
diff changeset
723 p[i].ctl=(c&0x60)==0?1:0;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
724 p[i].fg=fg_color;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
725 p[i].bg=bg_color;
24292
ca146808e926 Proper support for flashing chars in teletext pages.
voroshil
parents: 24290
diff changeset
726 p[i].flh=flash;
24275
a12f357e8bd0 Implement Flash/Steady (swapping foreground/background colors)
voroshil
parents: 24271
diff changeset
727
23899
34532db868ba Teletext support.
voroshil
parents:
diff changeset
728 if ((c&0x60)==0){ //control chars
24275
a12f357e8bd0 Implement Flash/Steady (swapping foreground/background colors)
voroshil
parents: 24271
diff changeset
729 if(c>=0x08 && c<=0x09){//Flash/Steady
24292
ca146808e926 Proper support for flashing chars in teletext pages.
voroshil
parents: 24290
diff changeset
730 flash=c==0x08;
ca146808e926 Proper support for flashing chars in teletext pages.
voroshil
parents: 24290
diff changeset
731 p[i].flh=flash;
24275
a12f357e8bd0 Implement Flash/Steady (swapping foreground/background colors)
voroshil
parents: 24271
diff changeset
732 if(c==0x09){
a12f357e8bd0 Implement Flash/Steady (swapping foreground/background colors)
voroshil
parents: 24271
diff changeset
733 p[i].fg=fg_color;
a12f357e8bd0 Implement Flash/Steady (swapping foreground/background colors)
voroshil
parents: 24271
diff changeset
734 p[i].bg=bg_color;
a12f357e8bd0 Implement Flash/Steady (swapping foreground/background colors)
voroshil
parents: 24271
diff changeset
735 }
24344
09d402672398 Implement boxes for subtitle teletext pages.
voroshil
parents: 24342
diff changeset
736 }else if(c>=0x0a && c<=0x0b){
09d402672398 Implement boxes for subtitle teletext pages.
voroshil
parents: 24342
diff changeset
737 box=c&1;
09d402672398 Implement boxes for subtitle teletext pages.
voroshil
parents: 24342
diff changeset
738 }else if(c>=0x0c && c<=0x0f){
23899
34532db868ba Teletext support.
voroshil
parents:
diff changeset
739 }else if (c<=0x17){ //colors
34532db868ba Teletext support.
voroshil
parents:
diff changeset
740 fg_color=c&0x0f;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
741 gfx=c>>4;
24275
a12f357e8bd0 Implement Flash/Steady (swapping foreground/background colors)
voroshil
parents: 24271
diff changeset
742 conceal=0;
24276
e8b635a55781 Implement Hold/Release graphics (showing control chars as
voroshil
parents: 24275
diff changeset
743 if(!gfx) hold=0;
23899
34532db868ba Teletext support.
voroshil
parents:
diff changeset
744 }else if (c<=0x18){
24275
a12f357e8bd0 Implement Flash/Steady (swapping foreground/background colors)
voroshil
parents: 24271
diff changeset
745 conceal=1;
23899
34532db868ba Teletext support.
voroshil
parents:
diff changeset
746 }else if (c<=0x1a){ //Contiguous/Separated gfx
34532db868ba Teletext support.
voroshil
parents:
diff changeset
747 separated=!(c&1);
34532db868ba Teletext support.
voroshil
parents:
diff changeset
748 }else if (c<=0x1b){
24290
ca7ee5c1b88d Support for selecting language via packet 28.
voroshil
parents: 24280
diff changeset
749 prim_lang=!prim_lang;
23899
34532db868ba Teletext support.
voroshil
parents:
diff changeset
750 }else if (c<=0x1d){
34532db868ba Teletext support.
voroshil
parents:
diff changeset
751 bg_color=(c&1)?fg_color:0;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
752 p[i].bg=bg_color;
24276
e8b635a55781 Implement Hold/Release graphics (showing control chars as
voroshil
parents: 24275
diff changeset
753 }else{ //Hold/Release Graphics
e8b635a55781 Implement Hold/Release graphics (showing control chars as
voroshil
parents: 24275
diff changeset
754 hold=!(c&1);
23899
34532db868ba Teletext support.
voroshil
parents:
diff changeset
755 }
34532db868ba Teletext support.
voroshil
parents:
diff changeset
756 p[i].ctl=1;
24276
e8b635a55781 Implement Hold/Release graphics (showing control chars as
voroshil
parents: 24275
diff changeset
757 if(hold || c==0x1f){
e8b635a55781 Implement Hold/Release graphics (showing control chars as
voroshil
parents: 24275
diff changeset
758 p[i]=tt_held;
e8b635a55781 Implement Hold/Release graphics (showing control chars as
voroshil
parents: 24275
diff changeset
759 p[i].fg=fg_color;
e8b635a55781 Implement Hold/Release graphics (showing control chars as
voroshil
parents: 24275
diff changeset
760 p[i].bg=bg_color;
e8b635a55781 Implement Hold/Release graphics (showing control chars as
voroshil
parents: 24275
diff changeset
761 }else
24277
298578b37f21 (cosmetics) fix indentation of previous commit
voroshil
parents: 24276
diff changeset
762 p[i].unicode=p[i].gfx?0:' ';
23899
34532db868ba Teletext support.
voroshil
parents:
diff changeset
763 continue;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
764 }
34532db868ba Teletext support.
voroshil
parents:
diff changeset
765
24275
a12f357e8bd0 Implement Flash/Steady (swapping foreground/background colors)
voroshil
parents: 24271
diff changeset
766 if(conceal){
a12f357e8bd0 Implement Flash/Steady (swapping foreground/background colors)
voroshil
parents: 24271
diff changeset
767 p[i].gfx=0;
a12f357e8bd0 Implement Flash/Steady (swapping foreground/background colors)
voroshil
parents: 24271
diff changeset
768 p[i].unicode=' ';
a12f357e8bd0 Implement Flash/Steady (swapping foreground/background colors)
voroshil
parents: 24271
diff changeset
769 }else if(gfx){
23899
34532db868ba Teletext support.
voroshil
parents:
diff changeset
770 p[i].unicode=c-0x20;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
771 if (p[i].unicode>0x3f) p[i].unicode-=0x20;
24276
e8b635a55781 Implement Hold/Release graphics (showing control chars as
voroshil
parents: 24275
diff changeset
772 tt_held=p[i];
24290
ca7ee5c1b88d Support for selecting language via packet 28.
voroshil
parents: 24280
diff changeset
773 }else{
ca7ee5c1b88d Support for selecting language via packet 28.
voroshil
parents: 24280
diff changeset
774 if(p[i].lng){
ca7ee5c1b88d Support for selecting language via packet 28.
voroshil
parents: 24280
diff changeset
775 p[i].unicode=conv2uni(c,prim_charset,primary_lang&7);
ca7ee5c1b88d Support for selecting language via packet 28.
voroshil
parents: 24280
diff changeset
776 }else{
ca7ee5c1b88d Support for selecting language via packet 28.
voroshil
parents: 24280
diff changeset
777 p[i].unicode=conv2uni(c,sec_charset,secondary_lang&7);
ca7ee5c1b88d Support for selecting language via packet 28.
voroshil
parents: 24280
diff changeset
778 }
ca7ee5c1b88d Support for selecting language via packet 28.
voroshil
parents: 24280
diff changeset
779 }
23899
34532db868ba Teletext support.
voroshil
parents:
diff changeset
780 p[i].fg=fg_color;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
781 p[i].bg=bg_color;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
782 }
34532db868ba Teletext support.
voroshil
parents:
diff changeset
783 }
34532db868ba Teletext support.
voroshil
parents:
diff changeset
784 }
34532db868ba Teletext support.
voroshil
parents:
diff changeset
785
34532db868ba Teletext support.
voroshil
parents:
diff changeset
786 /**
34532db868ba Teletext support.
voroshil
parents:
diff changeset
787 * \brief prepares current page for displaying
34532db868ba Teletext support.
voroshil
parents:
diff changeset
788 * \param priv_vbi private data structure
34532db868ba Teletext support.
voroshil
parents:
diff changeset
789 *
34532db868ba Teletext support.
voroshil
parents:
diff changeset
790 * Routine adds some useful info (time and page number of page, grabbed by
34532db868ba Teletext support.
voroshil
parents:
diff changeset
791 * background thread to top line of current page). Displays "No teletext"
34532db868ba Teletext support.
voroshil
parents:
diff changeset
792 * string if no vbi data available.
34532db868ba Teletext support.
voroshil
parents:
diff changeset
793 */
23908
39b21ffcee44 Subtraction should be done after & operation.
voroshil
parents: 23907
diff changeset
794 #define PRINT_HEX(dp,i,h) dp[i].unicode=((h)&0xf)>9?'A'+((h)&0xf)-10:'0'+((h)&0xf)
23899
34532db868ba Teletext support.
voroshil
parents:
diff changeset
795 static void prepare_visible_page(priv_vbi_t* priv){
34532db868ba Teletext support.
voroshil
parents:
diff changeset
796 tt_page *pg,*curr_pg;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
797 unsigned char *p;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
798 int i;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
799
34532db868ba Teletext support.
voroshil
parents:
diff changeset
800 pthread_mutex_lock(&(priv->buffer_mutex));
34532db868ba Teletext support.
voroshil
parents:
diff changeset
801 mp_msg(MSGT_TV,MSGL_DBG3,"tvi_vbi: prepare_visible_page pg:0x%x, sub:0x%x\n",
34532db868ba Teletext support.
voroshil
parents:
diff changeset
802 priv->pagenum,priv->subpagenum);
24293
c561d092b642 Fix displaying start page when it has subpages.
voroshil
parents: 24292
diff changeset
803 if(priv->subpagenum==0x3f7f) //no page yet
23899
34532db868ba Teletext support.
voroshil
parents:
diff changeset
804 priv->subpagenum=get_subpagenum_from_cache(priv,priv->pagenum);
34532db868ba Teletext support.
voroshil
parents:
diff changeset
805
34532db868ba Teletext support.
voroshil
parents:
diff changeset
806 pg=get_from_cache(priv,priv->pagenum,priv->subpagenum);
34532db868ba Teletext support.
voroshil
parents:
diff changeset
807 mp_dbg(MSGT_TV,MSGL_DBG3,"tvi_vbi: prepare_vibible_page2 pg:0x%x, sub:0x%x\n",
34532db868ba Teletext support.
voroshil
parents:
diff changeset
808 priv->pagenum,priv->subpagenum);
34532db868ba Teletext support.
voroshil
parents:
diff changeset
809
34532db868ba Teletext support.
voroshil
parents:
diff changeset
810 curr_pg=get_from_cache(priv,priv->curr_pagenum,
34532db868ba Teletext support.
voroshil
parents:
diff changeset
811 get_subpagenum_from_cache(priv,priv->curr_pagenum));
34532db868ba Teletext support.
voroshil
parents:
diff changeset
812 if (!pg && !curr_pg){
34532db868ba Teletext support.
voroshil
parents:
diff changeset
813 p=MSGTR_TV_NoTeletext;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
814 for(i=0;i<VBI_COLUMNS && *p;i++){
34532db868ba Teletext support.
voroshil
parents:
diff changeset
815 GET_UTF8(priv->display_page[i].unicode,*p++,break;);
34532db868ba Teletext support.
voroshil
parents:
diff changeset
816 }
34532db868ba Teletext support.
voroshil
parents:
diff changeset
817 for(;i<VBI_ROWS*VBI_COLUMNS;i++)
34532db868ba Teletext support.
voroshil
parents:
diff changeset
818 priv->display_page[i]=tt_space;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
819 pthread_mutex_unlock(&(priv->buffer_mutex));
34532db868ba Teletext support.
voroshil
parents:
diff changeset
820 return;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
821 }
34532db868ba Teletext support.
voroshil
parents:
diff changeset
822
34532db868ba Teletext support.
voroshil
parents:
diff changeset
823 if (!pg || !pg->active){
34532db868ba Teletext support.
voroshil
parents:
diff changeset
824 for(i=0;i<VBI_ROWS*VBI_COLUMNS;i++){
34532db868ba Teletext support.
voroshil
parents:
diff changeset
825 priv->display_page[i]=tt_space;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
826 }
34532db868ba Teletext support.
voroshil
parents:
diff changeset
827 }else{
24344
09d402672398 Implement boxes for subtitle teletext pages.
voroshil
parents: 24342
diff changeset
828 decode_page(priv->display_page,pg->raw,pg->primary_lang,pg->secondary_lang,pg->flags);
23899
34532db868ba Teletext support.
voroshil
parents:
diff changeset
829 mp_msg(MSGT_TV,MSGL_DBG3,"page #%x was decoded!\n",pg->pagenum);
34532db868ba Teletext support.
voroshil
parents:
diff changeset
830 }
34532db868ba Teletext support.
voroshil
parents:
diff changeset
831
34532db868ba Teletext support.
voroshil
parents:
diff changeset
832 PRINT_HEX(priv->display_page,0,(priv->curr_pagenum&0x700)?priv->curr_pagenum>>8:8);
34532db868ba Teletext support.
voroshil
parents:
diff changeset
833 PRINT_HEX(priv->display_page,1,priv->curr_pagenum>>4);
34532db868ba Teletext support.
voroshil
parents:
diff changeset
834 PRINT_HEX(priv->display_page,2,priv->curr_pagenum);
34532db868ba Teletext support.
voroshil
parents:
diff changeset
835 priv->display_page[3].unicode=' ';
34532db868ba Teletext support.
voroshil
parents:
diff changeset
836 priv->display_page[4].unicode=' ';
34532db868ba Teletext support.
voroshil
parents:
diff changeset
837 switch(priv->pagenumdec>>12){
34532db868ba Teletext support.
voroshil
parents:
diff changeset
838 case 1:
34532db868ba Teletext support.
voroshil
parents:
diff changeset
839 priv->display_page[5].unicode='_';
34532db868ba Teletext support.
voroshil
parents:
diff changeset
840 priv->display_page[6].unicode='_';
34532db868ba Teletext support.
voroshil
parents:
diff changeset
841 PRINT_HEX(priv->display_page,7,priv->pagenumdec);
34532db868ba Teletext support.
voroshil
parents:
diff changeset
842 break;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
843 case 2:
34532db868ba Teletext support.
voroshil
parents:
diff changeset
844 priv->display_page[5].unicode='_';
34532db868ba Teletext support.
voroshil
parents:
diff changeset
845 PRINT_HEX(priv->display_page,6,priv->pagenumdec>>4);
34532db868ba Teletext support.
voroshil
parents:
diff changeset
846 PRINT_HEX(priv->display_page,7,priv->pagenumdec);
34532db868ba Teletext support.
voroshil
parents:
diff changeset
847 break;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
848 default:
34532db868ba Teletext support.
voroshil
parents:
diff changeset
849 PRINT_HEX(priv->display_page,5,(priv->pagenum&0x700)?priv->pagenum>>8:8);
34532db868ba Teletext support.
voroshil
parents:
diff changeset
850 PRINT_HEX(priv->display_page,6,priv->pagenum>>4);
34532db868ba Teletext support.
voroshil
parents:
diff changeset
851 PRINT_HEX(priv->display_page,7,priv->pagenum);
34532db868ba Teletext support.
voroshil
parents:
diff changeset
852 }
24294
68b413a3ce51 Fix missed -1 -> 0x3f7f changes for subpage number.
voroshil
parents: 24293
diff changeset
853 if(priv->subpagenum!=0x3f7f){
23899
34532db868ba Teletext support.
voroshil
parents:
diff changeset
854 priv->display_page[8].unicode='.';
34532db868ba Teletext support.
voroshil
parents:
diff changeset
855 PRINT_HEX(priv->display_page,9,priv->subpagenum>>4);
34532db868ba Teletext support.
voroshil
parents:
diff changeset
856 PRINT_HEX(priv->display_page,10,priv->subpagenum);
34532db868ba Teletext support.
voroshil
parents:
diff changeset
857 }else{
34532db868ba Teletext support.
voroshil
parents:
diff changeset
858 priv->display_page[8].unicode=' ';
34532db868ba Teletext support.
voroshil
parents:
diff changeset
859 priv->display_page[9].unicode=' ';
34532db868ba Teletext support.
voroshil
parents:
diff changeset
860 priv->display_page[10].unicode=' ';
34532db868ba Teletext support.
voroshil
parents:
diff changeset
861 }
34532db868ba Teletext support.
voroshil
parents:
diff changeset
862 priv->display_page[11].unicode=' ';
24296
1980e76f4482 Drop out control chars from page header in time position.
voroshil
parents: 24294
diff changeset
863 for(i=VBI_COLUMNS;i>VBI_TIME_LINEPOS ||
1980e76f4482 Drop out control chars from page header in time position.
voroshil
parents: 24294
diff changeset
864 ((curr_pg->raw[i]&0x60) && curr_pg->raw[i]!=0x20 && i>11);
1980e76f4482 Drop out control chars from page header in time position.
voroshil
parents: 24294
diff changeset
865 --i)
1980e76f4482 Drop out control chars from page header in time position.
voroshil
parents: 24294
diff changeset
866 if(curr_pg->raw[i]&0x60)
1980e76f4482 Drop out control chars from page header in time position.
voroshil
parents: 24294
diff changeset
867 priv->display_page[i].unicode=curr_pg->raw[i];
1980e76f4482 Drop out control chars from page header in time position.
voroshil
parents: 24294
diff changeset
868 else
1980e76f4482 Drop out control chars from page header in time position.
voroshil
parents: 24294
diff changeset
869 priv->display_page[i].unicode=' ';
23899
34532db868ba Teletext support.
voroshil
parents:
diff changeset
870 pthread_mutex_unlock(&(priv->buffer_mutex));
34532db868ba Teletext support.
voroshil
parents:
diff changeset
871 }
34532db868ba Teletext support.
voroshil
parents:
diff changeset
872 /*
34532db868ba Teletext support.
voroshil
parents:
diff changeset
873 ------------------------------------------------------------------
34532db868ba Teletext support.
voroshil
parents:
diff changeset
874 Renderer stuff
34532db868ba Teletext support.
voroshil
parents:
diff changeset
875 ------------------------------------------------------------------
34532db868ba Teletext support.
voroshil
parents:
diff changeset
876 */
34532db868ba Teletext support.
voroshil
parents:
diff changeset
877 #ifdef DEBUG_DUMP
34532db868ba Teletext support.
voroshil
parents:
diff changeset
878 /**
34532db868ba Teletext support.
voroshil
parents:
diff changeset
879 * \brief renders teletext page into given file
34532db868ba Teletext support.
voroshil
parents:
diff changeset
880 * \param pt page to render
34532db868ba Teletext support.
voroshil
parents:
diff changeset
881 * \param f opened file descriptor
34532db868ba Teletext support.
voroshil
parents:
diff changeset
882 * \param pagenum which page to render
34532db868ba Teletext support.
voroshil
parents:
diff changeset
883 * \param colored use colors not implementede yet)
34532db868ba Teletext support.
voroshil
parents:
diff changeset
884 *
34532db868ba Teletext support.
voroshil
parents:
diff changeset
885 * Text will be UTF8 encoded
34532db868ba Teletext support.
voroshil
parents:
diff changeset
886 */
34532db868ba Teletext support.
voroshil
parents:
diff changeset
887 static void render2text(tt_page* pt,FILE* f,int colored){
34532db868ba Teletext support.
voroshil
parents:
diff changeset
888 int i,j;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
889 unsigned int u;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
890 unsigned char buf[8];
34532db868ba Teletext support.
voroshil
parents:
diff changeset
891 unsigned char tmp;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
892 int pos;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
893 tt_char dp[VBI_ROWS*VBI_COLUMNS];
34532db868ba Teletext support.
voroshil
parents:
diff changeset
894 int color=0;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
895 int bkg=0;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
896 int c1,b1;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
897 if(!pt)
34532db868ba Teletext support.
voroshil
parents:
diff changeset
898 return;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
899 fprintf(f,"+========================================+\n");
34532db868ba Teletext support.
voroshil
parents:
diff changeset
900 fprintf(f,"| lang:%d pagenum:0x%x subpagenum:%d flags:0x%x|\n",
34532db868ba Teletext support.
voroshil
parents:
diff changeset
901 pt->lang,
34532db868ba Teletext support.
voroshil
parents:
diff changeset
902 pt->pagenum,
34532db868ba Teletext support.
voroshil
parents:
diff changeset
903 pt->subpagenum,
34532db868ba Teletext support.
voroshil
parents:
diff changeset
904 0);
34532db868ba Teletext support.
voroshil
parents:
diff changeset
905 fprintf(f,"+----------------------------------------+\n");
34532db868ba Teletext support.
voroshil
parents:
diff changeset
906
24344
09d402672398 Implement boxes for subtitle teletext pages.
voroshil
parents: 24342
diff changeset
907 decode_page(dp,pt->raw,pt->primary_lang,pt->secondary_lang,pt->flags);
23899
34532db868ba Teletext support.
voroshil
parents:
diff changeset
908 for(i=0;i<VBI_ROWS;i++){
34532db868ba Teletext support.
voroshil
parents:
diff changeset
909 fprintf(f,"|");
34532db868ba Teletext support.
voroshil
parents:
diff changeset
910 if(colored) fprintf(f,"\033[40m");
34532db868ba Teletext support.
voroshil
parents:
diff changeset
911 for(j=0;j<VBI_COLUMNS;j++)
34532db868ba Teletext support.
voroshil
parents:
diff changeset
912 {
34532db868ba Teletext support.
voroshil
parents:
diff changeset
913 u=dp[i*VBI_COLUMNS+j].unicode;
23928
c6becdb359d7 remove GNUism (case range)
ivo
parents: 23908
diff changeset
914 if(dp[i*VBI_COLUMNS+j].fg <= 7)
23899
34532db868ba Teletext support.
voroshil
parents:
diff changeset
915 c1=30+dp[i*VBI_COLUMNS+j].fg;
23928
c6becdb359d7 remove GNUism (case range)
ivo
parents: 23908
diff changeset
916 else
23899
34532db868ba Teletext support.
voroshil
parents:
diff changeset
917 c1=38;
23928
c6becdb359d7 remove GNUism (case range)
ivo
parents: 23908
diff changeset
918 if(dp[i*VBI_COLUMNS+j].bg <= 7)
23899
34532db868ba Teletext support.
voroshil
parents:
diff changeset
919 b1=40+dp[i*VBI_COLUMNS+j].bg;
23928
c6becdb359d7 remove GNUism (case range)
ivo
parents: 23908
diff changeset
920 else
23899
34532db868ba Teletext support.
voroshil
parents:
diff changeset
921 b1=40;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
922 if (b1!=bkg && colored){
34532db868ba Teletext support.
voroshil
parents:
diff changeset
923 fprintf(f,"\033[%dm",b1);
34532db868ba Teletext support.
voroshil
parents:
diff changeset
924 bkg=b1;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
925 }
34532db868ba Teletext support.
voroshil
parents:
diff changeset
926 if(c1!=color && colored){
34532db868ba Teletext support.
voroshil
parents:
diff changeset
927 fprintf(f,"\033[%dm",c1);
34532db868ba Teletext support.
voroshil
parents:
diff changeset
928 color=c1;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
929 }
34532db868ba Teletext support.
voroshil
parents:
diff changeset
930 if(dp[i*VBI_COLUMNS+j].gfx){
34532db868ba Teletext support.
voroshil
parents:
diff changeset
931 fprintf(f,"*");
34532db868ba Teletext support.
voroshil
parents:
diff changeset
932 }else{
34532db868ba Teletext support.
voroshil
parents:
diff changeset
933 pos=0;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
934 PUT_UTF8(u,tmp,if(pos<7) buf[pos++]=tmp;);
34532db868ba Teletext support.
voroshil
parents:
diff changeset
935 buf[pos]='\0';
34532db868ba Teletext support.
voroshil
parents:
diff changeset
936 fprintf(f,"%s",buf);
34532db868ba Teletext support.
voroshil
parents:
diff changeset
937 }
34532db868ba Teletext support.
voroshil
parents:
diff changeset
938 }
34532db868ba Teletext support.
voroshil
parents:
diff changeset
939
34532db868ba Teletext support.
voroshil
parents:
diff changeset
940 if (colored) fprintf(f,"\033[0m");
34532db868ba Teletext support.
voroshil
parents:
diff changeset
941 color=-1;bkg=-1;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
942 fprintf(f,"|\n");
34532db868ba Teletext support.
voroshil
parents:
diff changeset
943 }
34532db868ba Teletext support.
voroshil
parents:
diff changeset
944 #if 1
34532db868ba Teletext support.
voroshil
parents:
diff changeset
945 //for debug
34532db868ba Teletext support.
voroshil
parents:
diff changeset
946 fprintf(f,"+====================raw=================+\n");
34532db868ba Teletext support.
voroshil
parents:
diff changeset
947 for(i=0;i<VBI_ROWS;i++){
34532db868ba Teletext support.
voroshil
parents:
diff changeset
948 for(j=0;j<VBI_COLUMNS;j++)
34532db868ba Teletext support.
voroshil
parents:
diff changeset
949 fprintf(f,"%02x ",dp[i*VBI_COLUMNS+j].raw);
34532db868ba Teletext support.
voroshil
parents:
diff changeset
950 fprintf(f,"\n");
34532db868ba Teletext support.
voroshil
parents:
diff changeset
951 }
34532db868ba Teletext support.
voroshil
parents:
diff changeset
952 fprintf(f,"+====================lng=================+\n");
34532db868ba Teletext support.
voroshil
parents:
diff changeset
953 for(i=0;i<VBI_ROWS;i++){
34532db868ba Teletext support.
voroshil
parents:
diff changeset
954 for(j=0;j<VBI_COLUMNS;j++)
34532db868ba Teletext support.
voroshil
parents:
diff changeset
955 fprintf(f,"%02x ",dp[i*VBI_COLUMNS+j].lng);
34532db868ba Teletext support.
voroshil
parents:
diff changeset
956 fprintf(f,"\n");
34532db868ba Teletext support.
voroshil
parents:
diff changeset
957 }
34532db868ba Teletext support.
voroshil
parents:
diff changeset
958 #endif
34532db868ba Teletext support.
voroshil
parents:
diff changeset
959 fprintf(f,"+========================================+\n");
34532db868ba Teletext support.
voroshil
parents:
diff changeset
960 }
34532db868ba Teletext support.
voroshil
parents:
diff changeset
961
34532db868ba Teletext support.
voroshil
parents:
diff changeset
962 /**
34532db868ba Teletext support.
voroshil
parents:
diff changeset
963 * \brief dump page into pgXXX.txt file in vurrent directory
34532db868ba Teletext support.
voroshil
parents:
diff changeset
964 * \param pt page to dump
34532db868ba Teletext support.
voroshil
parents:
diff changeset
965 *
34532db868ba Teletext support.
voroshil
parents:
diff changeset
966 * \note XXX in filename is page number
34532db868ba Teletext support.
voroshil
parents:
diff changeset
967 * \note use only for debug purposes
34532db868ba Teletext support.
voroshil
parents:
diff changeset
968 */
34532db868ba Teletext support.
voroshil
parents:
diff changeset
969 static void dump_page(tt_page* pt)
34532db868ba Teletext support.
voroshil
parents:
diff changeset
970 {
34532db868ba Teletext support.
voroshil
parents:
diff changeset
971 FILE*f;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
972 char name[100];
34532db868ba Teletext support.
voroshil
parents:
diff changeset
973 snprintf(name,99,"pg%x.txt",pt->pagenum);
34532db868ba Teletext support.
voroshil
parents:
diff changeset
974 f=fopen(name,"wb");
34532db868ba Teletext support.
voroshil
parents:
diff changeset
975 render2text(pt,f,1);
34532db868ba Teletext support.
voroshil
parents:
diff changeset
976 fclose(f);
34532db868ba Teletext support.
voroshil
parents:
diff changeset
977 }
34532db868ba Teletext support.
voroshil
parents:
diff changeset
978 #endif //DEBUG_DUMP
34532db868ba Teletext support.
voroshil
parents:
diff changeset
979
34532db868ba Teletext support.
voroshil
parents:
diff changeset
980
34532db868ba Teletext support.
voroshil
parents:
diff changeset
981 /**
34532db868ba Teletext support.
voroshil
parents:
diff changeset
982 * \brief checks whether page is ready and copies it into cache array if so
34532db868ba Teletext support.
voroshil
parents:
diff changeset
983 * \param priv private data structure
34532db868ba Teletext support.
voroshil
parents:
diff changeset
984 * \param magAddr page's magazine address (0-7)
34532db868ba Teletext support.
voroshil
parents:
diff changeset
985 *
34532db868ba Teletext support.
voroshil
parents:
diff changeset
986 * Routine also calls decode_page to perform 1st stage of rendering
34532db868ba Teletext support.
voroshil
parents:
diff changeset
987 */
34532db868ba Teletext support.
voroshil
parents:
diff changeset
988 static void store_in_cache(priv_vbi_t* priv, int magAddr, int line){
34532db868ba Teletext support.
voroshil
parents:
diff changeset
989 mp_msg(MSGT_TV,MSGL_DBG2,"store_in_cache(%d): pagenum:%x\n",
34532db868ba Teletext support.
voroshil
parents:
diff changeset
990 priv->mag[magAddr].order,
34532db868ba Teletext support.
voroshil
parents:
diff changeset
991 priv->mag[magAddr].pt->pagenum);
34532db868ba Teletext support.
voroshil
parents:
diff changeset
992
34532db868ba Teletext support.
voroshil
parents:
diff changeset
993 put_to_cache(priv,priv->mag[magAddr].pt,line);
34532db868ba Teletext support.
voroshil
parents:
diff changeset
994 priv->curr_pagenum=priv->mag[magAddr].pt->pagenum;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
995
34532db868ba Teletext support.
voroshil
parents:
diff changeset
996 #ifdef DEBUG_DUMP
34532db868ba Teletext support.
voroshil
parents:
diff changeset
997 dump_page(get_from_cache(priv,
34532db868ba Teletext support.
voroshil
parents:
diff changeset
998 priv->mag[magAddr].pt->pagenum,
34532db868ba Teletext support.
voroshil
parents:
diff changeset
999 priv->mag[magAddr].pt->subpagenum));
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1000 #endif
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1001 }
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1002
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1003
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1004 /*
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1005 ------------------------------------------------------------------
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1006 Grabber stuff
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1007 ------------------------------------------------------------------
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1008 */
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1009 #define PLL_SAMPLES 4
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1010 #define PLL_ERROR 4
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1011 #define PLL_ADJUST 4
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1012
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1013 /**
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1014 * \brief adjust current phase for better signal decoding
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1015 * \param n count of bytes processed (?)
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1016 * \param err count of error bytes (?)
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1017 *
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1018 * \remarks code was got from MythTV project
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1019 */
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1020 static void pll_add(priv_vbi_t* priv,int n,int err){
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1021 if(priv->pll_fixed)
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1022 return;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1023 if(err>PLL_ERROR*2/3)
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1024 err=PLL_ERROR*2/3;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1025 priv->pll_err+=err;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1026 priv->pll_cnt+=n;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1027 if(priv->pll_cnt<PLL_SAMPLES)
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1028 return;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1029 if(priv->pll_err>PLL_ERROR)
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1030 {
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1031 if(priv->pll_err>priv->pll_lerr)
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1032 priv->pll_dir= -priv->pll_dir;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1033 priv->pll_lerr=priv->pll_err;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1034 priv->pll_adj+=priv->pll_dir;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1035 if (priv->pll_adj<-PLL_ADJUST || priv->pll_adj>PLL_ADJUST)
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1036 {
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1037 priv->pll_adj=0;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1038 priv->pll_dir=-1;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1039 priv->pll_lerr=0;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1040 }
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1041 mp_msg(MSGT_TV,MSGL_DBG3,"vbi: pll_adj=%2d\n",priv->pll_adj);
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1042 }
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1043 priv->pll_cnt=0;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1044 priv->pll_err=0;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1045 }
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1046
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1047 /**
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1048 * \brief reset error correction
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1049 * \param priv private data structure
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1050 * \param fine_tune shift value for adjusting
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1051 *
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1052 * \remarks code was got from MythTV project
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1053 */
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1054 static void pll_reset(priv_vbi_t* priv,int fine_tune){
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1055 priv->pll_fixed=fine_tune >= -PLL_ADJUST && fine_tune <= PLL_ADJUST;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1056
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1057 priv->pll_err=0;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1058 priv->pll_lerr=0;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1059 priv->pll_cnt=0;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1060 priv->pll_dir=-1;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1061 priv->pll_adj=0;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1062 if(priv->pll_fixed)
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1063 priv->pll_adj=fine_tune;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1064 if(priv->pll_fixed)
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1065 mp_msg(MSGT_TV,MSGL_DBG3,"pll_reset (fixed@%2d)\n",priv->pll_adj);
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1066 else
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1067 mp_msg(MSGT_TV,MSGL_DBG3,"pll_reset (auto)\n");
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1068
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1069 }
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1070 /**
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1071 * \brief decode packet 0 (teletext page header)
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1072 * \param priv private data structure
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1073 * \param data raw teletext data (with not applied hamm correction yet)
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1074 * \param magAddr teletext page's magazine address
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1075 *
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1076 * \remarks
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1077 * data buffer was shifted by 6 and now contains:
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1078 * 0..1 page number
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1079 * 2..5 sub-code
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1080 * 6..7 control codes
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1081 * 8..39 display data
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1082 *
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1083 * only first 8 bytes protected by Hamm 8/4 code
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1084 */
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1085 static int decode_pkt0(priv_vbi_t* priv,unsigned char* data,int magAddr)
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1086 {
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1087 int d[8];
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1088 int i,err;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1089
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1090 if (magAddr<0 || magAddr>7)
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1091 return 0;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1092 for(i=0;i<8;i++){
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1093 d[i]= corrHamm48[ data[i] ];
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1094 if(d[i]&0x80){
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1095 pll_add(priv,2,4);
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1096
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1097 if(priv->mag[magAddr].pt)
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1098 free(priv->mag[magAddr].pt);
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1099 priv->mag[magAddr].pt=NULL;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1100 priv->mag[magAddr].order=0;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1101 return 0;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1102 }
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1103 }
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1104 if (!priv->mag[magAddr].pt)
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1105 priv->mag[magAddr].pt= malloc(sizeof(tt_page));
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1106
24290
ca7ee5c1b88d Support for selecting language via packet 28.
voroshil
parents: 24280
diff changeset
1107 if(priv->primary_language)
ca7ee5c1b88d Support for selecting language via packet 28.
voroshil
parents: 24280
diff changeset
1108 priv->mag[magAddr].pt->primary_lang=priv->primary_language;
ca7ee5c1b88d Support for selecting language via packet 28.
voroshil
parents: 24280
diff changeset
1109 else
ca7ee5c1b88d Support for selecting language via packet 28.
voroshil
parents: 24280
diff changeset
1110 priv->mag[magAddr].pt->primary_lang= (d[7]&7)>>1;
ca7ee5c1b88d Support for selecting language via packet 28.
voroshil
parents: 24280
diff changeset
1111 priv->mag[magAddr].pt->secondary_lang=priv->secondary_language;
23899
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1112 priv->mag[magAddr].pt->subpagenum=(d[2]|(d[3]<<4)|(d[4]<<8)|(d[5]<<12))&0x3f7f;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1113 priv->mag[magAddr].pt->pagenum=(magAddr<<8) | d[0] | (d[1]<<4);
24344
09d402672398 Implement boxes for subtitle teletext pages.
voroshil
parents: 24342
diff changeset
1114 priv->mag[magAddr].pt->flags=((d[7]&1)<<7) | ((d[3]&8)<<3) | ((d[5]&12)<<2) | d[6];
23899
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1115
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1116 memset(priv->mag[magAddr].pt->raw, 0x00, VBI_COLUMNS*VBI_ROWS);
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1117 priv->mag[magAddr].order=0;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1118
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1119 for(i=0;i<8;i++){
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1120 priv->mag[magAddr].pt->raw[i]=0x20;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1121 }
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1122 err=0;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1123 for(i=8; i<VBI_COLUMNS; i++){
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1124 data[i]= fixParity[data[i]];
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1125 priv->mag[magAddr].pt->raw[i]=data[i];
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1126 if(data[i]&0x80) //Error
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1127 err++;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1128 pll_add(priv,1,err);
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1129 }
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1130
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1131 store_in_cache(priv,magAddr,0);
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1132
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1133 return 1;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1134 }
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1135
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1136 /**
24232
d0290b80e612 Implement 8/30 format 1 teletext packet decoding
voroshil
parents: 24197
diff changeset
1137 * \brief decode teletext 8/30 Format 1 packet
d0290b80e612 Implement 8/30 format 1 teletext packet decoding
voroshil
parents: 24197
diff changeset
1138 * \param priv private data structure
d0290b80e612 Implement 8/30 format 1 teletext packet decoding
voroshil
parents: 24197
diff changeset
1139 * \param data raw teletext data (with not applied hamm correction yet)
d0290b80e612 Implement 8/30 format 1 teletext packet decoding
voroshil
parents: 24197
diff changeset
1140 * \param magAddr teletext page's magazine address
d0290b80e612 Implement 8/30 format 1 teletext packet decoding
voroshil
parents: 24197
diff changeset
1141 *
d0290b80e612 Implement 8/30 format 1 teletext packet decoding
voroshil
parents: 24197
diff changeset
1142 * \remarks
d0290b80e612 Implement 8/30 format 1 teletext packet decoding
voroshil
parents: 24197
diff changeset
1143 * packet contains:
d0290b80e612 Implement 8/30 format 1 teletext packet decoding
voroshil
parents: 24197
diff changeset
1144 * 0 designation code
d0290b80e612 Implement 8/30 format 1 teletext packet decoding
voroshil
parents: 24197
diff changeset
1145 * 1..2 initial page
d0290b80e612 Implement 8/30 format 1 teletext packet decoding
voroshil
parents: 24197
diff changeset
1146 * 3..6 initial subpage & magazine address
d0290b80e612 Implement 8/30 format 1 teletext packet decoding
voroshil
parents: 24197
diff changeset
1147 * 7..8 network id
d0290b80e612 Implement 8/30 format 1 teletext packet decoding
voroshil
parents: 24197
diff changeset
1148 * 9 time offset
d0290b80e612 Implement 8/30 format 1 teletext packet decoding
voroshil
parents: 24197
diff changeset
1149 * 10..12 julian date
d0290b80e612 Implement 8/30 format 1 teletext packet decoding
voroshil
parents: 24197
diff changeset
1150 * 13..15 universal time
d0290b80e612 Implement 8/30 format 1 teletext packet decoding
voroshil
parents: 24197
diff changeset
1151 * 20..40 network name
d0290b80e612 Implement 8/30 format 1 teletext packet decoding
voroshil
parents: 24197
diff changeset
1152 *
d0290b80e612 Implement 8/30 format 1 teletext packet decoding
voroshil
parents: 24197
diff changeset
1153 * First 7 bytes are protected by Hamm 8/4 code.
d0290b80e612 Implement 8/30 format 1 teletext packet decoding
voroshil
parents: 24197
diff changeset
1154 * Bytes 20-40 has odd parity check.
d0290b80e612 Implement 8/30 format 1 teletext packet decoding
voroshil
parents: 24197
diff changeset
1155 *
d0290b80e612 Implement 8/30 format 1 teletext packet decoding
voroshil
parents: 24197
diff changeset
1156 * See subcaluse 9.8.1 of specification for details
d0290b80e612 Implement 8/30 format 1 teletext packet decoding
voroshil
parents: 24197
diff changeset
1157 */
d0290b80e612 Implement 8/30 format 1 teletext packet decoding
voroshil
parents: 24197
diff changeset
1158 static int decode_pkt30(priv_vbi_t* priv,unsigned char* data,int magAddr)
d0290b80e612 Implement 8/30 format 1 teletext packet decoding
voroshil
parents: 24197
diff changeset
1159 {
d0290b80e612 Implement 8/30 format 1 teletext packet decoding
voroshil
parents: 24197
diff changeset
1160 int d[8];
d0290b80e612 Implement 8/30 format 1 teletext packet decoding
voroshil
parents: 24197
diff changeset
1161 int i,err;
d0290b80e612 Implement 8/30 format 1 teletext packet decoding
voroshil
parents: 24197
diff changeset
1162
d0290b80e612 Implement 8/30 format 1 teletext packet decoding
voroshil
parents: 24197
diff changeset
1163 for(i=0;i<7;i++){
d0290b80e612 Implement 8/30 format 1 teletext packet decoding
voroshil
parents: 24197
diff changeset
1164 d[i]= corrHamm48[ data[i] ];
d0290b80e612 Implement 8/30 format 1 teletext packet decoding
voroshil
parents: 24197
diff changeset
1165 if(d[i]&0x80){
d0290b80e612 Implement 8/30 format 1 teletext packet decoding
voroshil
parents: 24197
diff changeset
1166 pll_add(priv,2,4);
d0290b80e612 Implement 8/30 format 1 teletext packet decoding
voroshil
parents: 24197
diff changeset
1167 return 0;
d0290b80e612 Implement 8/30 format 1 teletext packet decoding
voroshil
parents: 24197
diff changeset
1168 }
d0290b80e612 Implement 8/30 format 1 teletext packet decoding
voroshil
parents: 24197
diff changeset
1169 d[i]&=0xf;
d0290b80e612 Implement 8/30 format 1 teletext packet decoding
voroshil
parents: 24197
diff changeset
1170 }
d0290b80e612 Implement 8/30 format 1 teletext packet decoding
voroshil
parents: 24197
diff changeset
1171
d0290b80e612 Implement 8/30 format 1 teletext packet decoding
voroshil
parents: 24197
diff changeset
1172 err=0;
d0290b80e612 Implement 8/30 format 1 teletext packet decoding
voroshil
parents: 24197
diff changeset
1173 for(i=20; i<40; i++){
d0290b80e612 Implement 8/30 format 1 teletext packet decoding
voroshil
parents: 24197
diff changeset
1174 data[i]= fixParity[data[i]];
d0290b80e612 Implement 8/30 format 1 teletext packet decoding
voroshil
parents: 24197
diff changeset
1175 if(data[i]&0x80)//Unrecoverable error
d0290b80e612 Implement 8/30 format 1 teletext packet decoding
voroshil
parents: 24197
diff changeset
1176 err++;
d0290b80e612 Implement 8/30 format 1 teletext packet decoding
voroshil
parents: 24197
diff changeset
1177 pll_add(priv,1,err);
d0290b80e612 Implement 8/30 format 1 teletext packet decoding
voroshil
parents: 24197
diff changeset
1178 }
d0290b80e612 Implement 8/30 format 1 teletext packet decoding
voroshil
parents: 24197
diff changeset
1179 if (err) return 0;
d0290b80e612 Implement 8/30 format 1 teletext packet decoding
voroshil
parents: 24197
diff changeset
1180
d0290b80e612 Implement 8/30 format 1 teletext packet decoding
voroshil
parents: 24197
diff changeset
1181 if (d[0]&0xe) //This is not 8/30 Format 1 packet
d0290b80e612 Implement 8/30 format 1 teletext packet decoding
voroshil
parents: 24197
diff changeset
1182 return 1;
d0290b80e612 Implement 8/30 format 1 teletext packet decoding
voroshil
parents: 24197
diff changeset
1183
d0290b80e612 Implement 8/30 format 1 teletext packet decoding
voroshil
parents: 24197
diff changeset
1184 priv->initialpage=d[1] | d[2]<<4 | (d[6]&0xc)<<7 | (d[4]&1)<<8;
d0290b80e612 Implement 8/30 format 1 teletext packet decoding
voroshil
parents: 24197
diff changeset
1185 priv->initialsubpage=d[3] | d[4]<<4 | d[5]<<8 | d[6]<<12;
d0290b80e612 Implement 8/30 format 1 teletext packet decoding
voroshil
parents: 24197
diff changeset
1186 priv->networkid=data[7]<<8 | data[8];
d0290b80e612 Implement 8/30 format 1 teletext packet decoding
voroshil
parents: 24197
diff changeset
1187
d0290b80e612 Implement 8/30 format 1 teletext packet decoding
voroshil
parents: 24197
diff changeset
1188 priv->timeoffset=(data[9]>>1)&0xf;
d0290b80e612 Implement 8/30 format 1 teletext packet decoding
voroshil
parents: 24197
diff changeset
1189 if(data[9]&0x40)
d0290b80e612 Implement 8/30 format 1 teletext packet decoding
voroshil
parents: 24197
diff changeset
1190 priv->timeoffset=-priv->timeoffset;
d0290b80e612 Implement 8/30 format 1 teletext packet decoding
voroshil
parents: 24197
diff changeset
1191
d0290b80e612 Implement 8/30 format 1 teletext packet decoding
voroshil
parents: 24197
diff changeset
1192 priv->juliandate=(data[10]&0xf)<<16 | data[11]<<8 | data[12];
d0290b80e612 Implement 8/30 format 1 teletext packet decoding
voroshil
parents: 24197
diff changeset
1193 priv->juliandate-=0x11111;
d0290b80e612 Implement 8/30 format 1 teletext packet decoding
voroshil
parents: 24197
diff changeset
1194
d0290b80e612 Implement 8/30 format 1 teletext packet decoding
voroshil
parents: 24197
diff changeset
1195 priv->universaltime=data[13]<<16 | data[14]<<8 | data[15];
d0290b80e612 Implement 8/30 format 1 teletext packet decoding
voroshil
parents: 24197
diff changeset
1196 priv->universaltime-=0x111111;
d0290b80e612 Implement 8/30 format 1 teletext packet decoding
voroshil
parents: 24197
diff changeset
1197
d0290b80e612 Implement 8/30 format 1 teletext packet decoding
voroshil
parents: 24197
diff changeset
1198 snprintf(priv->networkname,21,"%s",data+20);
d0290b80e612 Implement 8/30 format 1 teletext packet decoding
voroshil
parents: 24197
diff changeset
1199
d0290b80e612 Implement 8/30 format 1 teletext packet decoding
voroshil
parents: 24197
diff changeset
1200 return 1;
d0290b80e612 Implement 8/30 format 1 teletext packet decoding
voroshil
parents: 24197
diff changeset
1201 }
d0290b80e612 Implement 8/30 format 1 teletext packet decoding
voroshil
parents: 24197
diff changeset
1202
d0290b80e612 Implement 8/30 format 1 teletext packet decoding
voroshil
parents: 24197
diff changeset
1203 /**
23899
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1204 * \brief decode packets 1..24 (teletext page header)
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1205 * \param priv private data structure
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1206 * \param data raw teletext data
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1207 * \param magAddr teletext page's magazine address
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1208 * \param rowAddr teletext page's row number
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1209 *
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1210 * \remarks
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1211 * data buffer was shifted by 6 and now contains 40 bytes of display data:
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1212 * this type of packet is not proptected by Hamm 8/4 code
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1213 */
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1214 static void decode_pkt_page(priv_vbi_t* priv,unsigned char*data,int magAddr,int rowAddr){
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1215 int i,err;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1216 if (!priv->mag[magAddr].pt)
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1217 return;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1218
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1219 priv->mag[magAddr].order=rowAddr;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1220
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1221 err=0;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1222 for(i=0; i<VBI_COLUMNS; i++){
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1223 data[i]= fixParity[ data[i] ];
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1224 priv->mag[magAddr].pt->raw[i+rowAddr*VBI_COLUMNS]=data[i];
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1225 if( data[i]&0x80) //HammError
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1226 err++;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1227 }
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1228 pll_add(priv,1,err);
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1229
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1230 store_in_cache(priv,magAddr,rowAddr);
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1231 }
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1232
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1233 /**
24244
e446bad0872c Implement X/27/0 packet decoding.
voroshil
parents: 24232
diff changeset
1234 * \brief decode packets 27 (teletext links)
e446bad0872c Implement X/27/0 packet decoding.
voroshil
parents: 24232
diff changeset
1235 * \param priv private data structure
e446bad0872c Implement X/27/0 packet decoding.
voroshil
parents: 24232
diff changeset
1236 * \param data raw teletext data
e446bad0872c Implement X/27/0 packet decoding.
voroshil
parents: 24232
diff changeset
1237 * \param magAddr teletext page's magazine address
e446bad0872c Implement X/27/0 packet decoding.
voroshil
parents: 24232
diff changeset
1238 */
e446bad0872c Implement X/27/0 packet decoding.
voroshil
parents: 24232
diff changeset
1239 static int decode_pkt27(priv_vbi_t* priv,unsigned char* data,int magAddr){
e446bad0872c Implement X/27/0 packet decoding.
voroshil
parents: 24232
diff changeset
1240 int i,hpg;
e446bad0872c Implement X/27/0 packet decoding.
voroshil
parents: 24232
diff changeset
1241
e446bad0872c Implement X/27/0 packet decoding.
voroshil
parents: 24232
diff changeset
1242 if (!priv->mag[magAddr].pt)
e446bad0872c Implement X/27/0 packet decoding.
voroshil
parents: 24232
diff changeset
1243 return 0;
e446bad0872c Implement X/27/0 packet decoding.
voroshil
parents: 24232
diff changeset
1244 for(i=0;i<38;++i)
e446bad0872c Implement X/27/0 packet decoding.
voroshil
parents: 24232
diff changeset
1245 if ((data[i] = corrHamm48[ data[i] ]) & 0x80){
e446bad0872c Implement X/27/0 packet decoding.
voroshil
parents: 24232
diff changeset
1246 pll_add(priv,2,4);
e446bad0872c Implement X/27/0 packet decoding.
voroshil
parents: 24232
diff changeset
1247 return 0;
e446bad0872c Implement X/27/0 packet decoding.
voroshil
parents: 24232
diff changeset
1248 }
e446bad0872c Implement X/27/0 packet decoding.
voroshil
parents: 24232
diff changeset
1249
e446bad0872c Implement X/27/0 packet decoding.
voroshil
parents: 24232
diff changeset
1250 /*
e446bad0872c Implement X/27/0 packet decoding.
voroshil
parents: 24232
diff changeset
1251 Not a X/27/0 Format 1 packet or
e446bad0872c Implement X/27/0 packet decoding.
voroshil
parents: 24232
diff changeset
1252 flag "show links on row 24" is not set.
e446bad0872c Implement X/27/0 packet decoding.
voroshil
parents: 24232
diff changeset
1253 */
e446bad0872c Implement X/27/0 packet decoding.
voroshil
parents: 24232
diff changeset
1254 if (data[0] || !(data[37] & 8))
e446bad0872c Implement X/27/0 packet decoding.
voroshil
parents: 24232
diff changeset
1255 return 1;
e446bad0872c Implement X/27/0 packet decoding.
voroshil
parents: 24232
diff changeset
1256 for(i=0;i<6;++i) {
e446bad0872c Implement X/27/0 packet decoding.
voroshil
parents: 24232
diff changeset
1257 hpg = (magAddr<<8) ^ ((data[4+i*6]&0x8)<<5 | (data[6+i*6]&0xc)<<7);
e446bad0872c Implement X/27/0 packet decoding.
voroshil
parents: 24232
diff changeset
1258 if (!hpg) hpg=0x800;
e446bad0872c Implement X/27/0 packet decoding.
voroshil
parents: 24232
diff changeset
1259 priv->mag[magAddr].pt->links[i].pagenum = (data[1+i*6] & 0xf) |
e446bad0872c Implement X/27/0 packet decoding.
voroshil
parents: 24232
diff changeset
1260 ((data[2+i*6] & 0xf) << 4) | hpg;
e446bad0872c Implement X/27/0 packet decoding.
voroshil
parents: 24232
diff changeset
1261 priv->mag[magAddr].pt->links[i].subpagenum = ((data[3+i*6] & 0xf) |
e446bad0872c Implement X/27/0 packet decoding.
voroshil
parents: 24232
diff changeset
1262 (data[4+i*6] & 0xf) << 4 | (data[5+i*6] & 0xf) << 8 |
e446bad0872c Implement X/27/0 packet decoding.
voroshil
parents: 24232
diff changeset
1263 (data[6+i*6] & 0xf) << 12) & 0x3f7f;
e446bad0872c Implement X/27/0 packet decoding.
voroshil
parents: 24232
diff changeset
1264 }
e446bad0872c Implement X/27/0 packet decoding.
voroshil
parents: 24232
diff changeset
1265 put_to_cache(priv,priv->mag[magAddr].pt,-1);
e446bad0872c Implement X/27/0 packet decoding.
voroshil
parents: 24232
diff changeset
1266 return 1;
e446bad0872c Implement X/27/0 packet decoding.
voroshil
parents: 24232
diff changeset
1267 }
e446bad0872c Implement X/27/0 packet decoding.
voroshil
parents: 24232
diff changeset
1268
e446bad0872c Implement X/27/0 packet decoding.
voroshil
parents: 24232
diff changeset
1269 /**
24290
ca7ee5c1b88d Support for selecting language via packet 28.
voroshil
parents: 24280
diff changeset
1270 * \brief Decode teletext X/28/0 Format 1 packet
ca7ee5c1b88d Support for selecting language via packet 28.
voroshil
parents: 24280
diff changeset
1271 * \param priv private data structure
ca7ee5c1b88d Support for selecting language via packet 28.
voroshil
parents: 24280
diff changeset
1272 * \param data raw teletext data
ca7ee5c1b88d Support for selecting language via packet 28.
voroshil
parents: 24280
diff changeset
1273 *
ca7ee5c1b88d Support for selecting language via packet 28.
voroshil
parents: 24280
diff changeset
1274 * Primary G0 charset is transmitted in bits 14-8 of Triplet 1
ca7ee5c1b88d Support for selecting language via packet 28.
voroshil
parents: 24280
diff changeset
1275 * See Table 32 of specification for details.
ca7ee5c1b88d Support for selecting language via packet 28.
voroshil
parents: 24280
diff changeset
1276 *
ca7ee5c1b88d Support for selecting language via packet 28.
voroshil
parents: 24280
diff changeset
1277 * Secondary G0 charset is transmitted in bits 3-1 of Triplet 2 and
ca7ee5c1b88d Support for selecting language via packet 28.
voroshil
parents: 24280
diff changeset
1278 * bits 18-15 of Triplet 1
ca7ee5c1b88d Support for selecting language via packet 28.
voroshil
parents: 24280
diff changeset
1279 * See Table 33 of specification for details.
ca7ee5c1b88d Support for selecting language via packet 28.
voroshil
parents: 24280
diff changeset
1280 *
ca7ee5c1b88d Support for selecting language via packet 28.
voroshil
parents: 24280
diff changeset
1281 */
ca7ee5c1b88d Support for selecting language via packet 28.
voroshil
parents: 24280
diff changeset
1282 static void decode_pkt28(priv_vbi_t* priv,unsigned char*data){
ca7ee5c1b88d Support for selecting language via packet 28.
voroshil
parents: 24280
diff changeset
1283 int d;
ca7ee5c1b88d Support for selecting language via packet 28.
voroshil
parents: 24280
diff changeset
1284 int t1,t2;
ca7ee5c1b88d Support for selecting language via packet 28.
voroshil
parents: 24280
diff changeset
1285 d=corrHamm48[ data[0] ];
ca7ee5c1b88d Support for selecting language via packet 28.
voroshil
parents: 24280
diff changeset
1286 if(d) return; //this is not X/28/0 Format 1 packet or error occured
ca7ee5c1b88d Support for selecting language via packet 28.
voroshil
parents: 24280
diff changeset
1287
ca7ee5c1b88d Support for selecting language via packet 28.
voroshil
parents: 24280
diff changeset
1288 t1=corrHamm24(data+1);
ca7ee5c1b88d Support for selecting language via packet 28.
voroshil
parents: 24280
diff changeset
1289 t2=corrHamm24(data+4);
ca7ee5c1b88d Support for selecting language via packet 28.
voroshil
parents: 24280
diff changeset
1290 if (t1<0 || t2<0){
ca7ee5c1b88d Support for selecting language via packet 28.
voroshil
parents: 24280
diff changeset
1291 pll_add(priv,1,4);
ca7ee5c1b88d Support for selecting language via packet 28.
voroshil
parents: 24280
diff changeset
1292 return;
ca7ee5c1b88d Support for selecting language via packet 28.
voroshil
parents: 24280
diff changeset
1293 }
ca7ee5c1b88d Support for selecting language via packet 28.
voroshil
parents: 24280
diff changeset
1294
ca7ee5c1b88d Support for selecting language via packet 28.
voroshil
parents: 24280
diff changeset
1295 priv->primary_language=(t1>>7)&0x7f;
ca7ee5c1b88d Support for selecting language via packet 28.
voroshil
parents: 24280
diff changeset
1296 priv->secondary_language=((t2<<4) | (t1>>14))&0x7f;
ca7ee5c1b88d Support for selecting language via packet 28.
voroshil
parents: 24280
diff changeset
1297 if (priv->secondary_language==0x7f)
ca7ee5c1b88d Support for selecting language via packet 28.
voroshil
parents: 24280
diff changeset
1298 //No secondary language required
ca7ee5c1b88d Support for selecting language via packet 28.
voroshil
parents: 24280
diff changeset
1299 priv->secondary_language=priv->primary_language;
ca7ee5c1b88d Support for selecting language via packet 28.
voroshil
parents: 24280
diff changeset
1300 else // Swapping bits 1 and 3
ca7ee5c1b88d Support for selecting language via packet 28.
voroshil
parents: 24280
diff changeset
1301 priv->secondary_language=(priv->secondary_language&0x7a) |
ca7ee5c1b88d Support for selecting language via packet 28.
voroshil
parents: 24280
diff changeset
1302 (priv->secondary_language&4)>>2 |
ca7ee5c1b88d Support for selecting language via packet 28.
voroshil
parents: 24280
diff changeset
1303 (priv->secondary_language&1)<<2;
ca7ee5c1b88d Support for selecting language via packet 28.
voroshil
parents: 24280
diff changeset
1304
ca7ee5c1b88d Support for selecting language via packet 28.
voroshil
parents: 24280
diff changeset
1305 mp_msg(MSGT_TV,MSGL_DBG2,"pkt28: language: primary=%02x secondary=0x%02x\n",
ca7ee5c1b88d Support for selecting language via packet 28.
voroshil
parents: 24280
diff changeset
1306 priv->primary_language,priv->secondary_language);
ca7ee5c1b88d Support for selecting language via packet 28.
voroshil
parents: 24280
diff changeset
1307 }
ca7ee5c1b88d Support for selecting language via packet 28.
voroshil
parents: 24280
diff changeset
1308
ca7ee5c1b88d Support for selecting language via packet 28.
voroshil
parents: 24280
diff changeset
1309 /**
23899
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1310 * \brief decodes raw vbi data (signal amplitudes) into sequence of bytes
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1311 * \param priv private data structure
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1312 * \param buf raw vbi data (one line of frame)
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1313 * \param data output buffer for decoded bytes (at least 45 bytes long)
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1314 *
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1315 * Used XawTV's algorithm. Signal phase is calculated with help of starting clock
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1316 * run-in sequence (min/max values and bit distance values are calculated)
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1317 */
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1318 static int decode_raw_line_runin(priv_vbi_t* priv,unsigned char* buf,unsigned char* data){
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1319 const int magic= 0x27; // reversed 1110010
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1320 int dt[256],hi[6],lo[6];
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1321 int i,x,r;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1322 int decoded;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1323 int sync;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1324 unsigned char min,max;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1325 int thr=0; //threshold
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1326
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1327 //stubs
24099
d517c397de7d Fix [soc:eoc] stubs.
voroshil
parents: 23928
diff changeset
1328 int soc=priv->soc;
d517c397de7d Fix [soc:eoc] stubs.
voroshil
parents: 23928
diff changeset
1329 int eoc=priv->eoc;
23899
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1330
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1331 for(i=soc;i<eoc;i++)
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1332 dt[i]=buf[i+priv->bpb/ONE_FIXP]-buf[i]; // amplifies the edges best.
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1333 /* set barrier */
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1334 for (i=eoc; i<eoc+16; i+=2)
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1335 dt[i]=100, dt[i+1]=-100;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1336
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1337 /* find 6 rising and falling edges */
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1338 for (i=soc, x=0; x<6; ++x)
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1339 {
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1340 while (dt[i]<32)
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1341 i++;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1342 hi[x]=i;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1343 while (dt[i]>-32)
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1344 i++;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1345 lo[x]=i;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1346 }
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1347 if (i>=eoc)
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1348 {
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1349 return 0; // not enough periods found
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1350 }
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1351 i=hi[5]-hi[1]; // length of 4 periods (8 bits)
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1352 if (i<priv->bp8bl || i>priv->bp8bh)
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1353 {
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1354 mp_msg(MSGT_TV,MSGL_DBG3,"vbi: wrong freq %d (%d,%d)\n",
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1355 i,priv->bp8bl,priv->bp8bh);
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1356 return 0; // bad frequency
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1357 }
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1358 /* AGC and sync-reference */
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1359 min=255, max=0, sync=0;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1360 for (i=hi[4]; i<hi[5]; ++i)
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1361 if (buf[i]>max)
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1362 max=buf[i], sync=i;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1363 for (i=lo[4]; i<lo[5]; ++i)
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1364 if (buf[i]<min)
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1365 min=buf[i];
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1366 thr=(min+max)/2;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1367
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1368 buf+=sync;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1369 // searching for '11'
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1370 for(i=priv->pll_adj*priv->bpb/10;i<16*priv->bpb;i+=priv->bpb)
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1371 if(buf[FIXP2INT(i)]>thr && buf[FIXP2INT(i+priv->bpb)]>thr)
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1372 break;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1373 r=0;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1374 for(decoded=1; decoded<= (VBI_COLUMNS+3)<<3;decoded++){
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1375 r>>=1;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1376 if(buf[FIXP2INT(i)]>thr) r|=0x80;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1377 if(!(decoded & 0x07)){
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1378 data[(decoded>>3) - 1]=r;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1379 r=0;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1380 }
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1381 i+=priv->bpb;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1382 }
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1383 if(data[0]!=magic)
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1384 return 0; //magic not found
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1385
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1386 //stub
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1387 for(i=0;i<43;i++){
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1388 data[i]=data[i+1];
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1389 }
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1390 mp_msg(MSGT_TV,MSGL_DBG3,"thr:%d sync:%d ",thr,sync);
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1391
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1392 return 1;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1393 }
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1394
24316
31dbcf68a706 Fix for:
voroshil
parents: 24305
diff changeset
1395 #if 0
31dbcf68a706 Fix for:
voroshil
parents: 24305
diff changeset
1396 //See comment in vbi_decode for a reason of commenting out this routine.
31dbcf68a706 Fix for:
voroshil
parents: 24305
diff changeset
1397
23899
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1398 /**
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1399 * \brief decodes raw vbi data (signal amplitudes) into sequence of bytes
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1400 * \param priv private data structure
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1401 * \param buf raw vbi data (one line of frame)
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1402 * \param data output buffer for decoded bytes (at least 45 bytes long)
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1403 *
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1404 * Used Michael Niedermayer's algorithm.
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1405 * Signal phase is calculated using correlation between given samples data and
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1406 * pure sine
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1407 */
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1408 static int decode_raw_line_sine(priv_vbi_t* priv,unsigned char* buf,unsigned char* data){
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1409 int i,x,r,amp,xFixp;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1410 int avg=0;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1411 double sin_sum=0, cos_sum=0;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1412
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1413 for(x=0; x< FIXP2INT(10*priv->bpb); x++)
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1414 avg+=buf[x];
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1415
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1416 avg/=FIXP2INT(10*priv->bpb);
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1417
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1418 for(x=0; x<12; x++){
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1419 amp= buf[x<<1];
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1420 sin_sum+= si[x]*(amp-avg);
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1421 cos_sum+= co[x]*(amp-avg);
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1422 }
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1423 //this is always zero. Why ?
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1424 xFixp= atan(sin_sum/cos_sum)*priv->bpb/M_PI;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1425
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1426 //Without this line the result is full of errors
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1427 //and routine is unable to find magic sequence
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1428 buf+=FIXP2INT(10*priv->bpb);
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1429
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1430 r=0;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1431 for(x=FIXP2INT(xFixp);x<70;x=FIXP2INT(xFixp)){
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1432 r=(r<<1) & 0xFFFF;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1433 if(buf[x]>avg) r|=1;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1434 xFixp+=priv->bpb;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1435 if(r==0xAAE4) break;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1436 }
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1437
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1438 //this is not teletext
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1439 if (r!=0xaae4) return 0;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1440
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1441 //Decode remaining 45-2(clock run-in)-1(framing code)=42 bytes
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1442 for(i=1; i<=(42<<3); i++){
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1443 r>>=1;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1444 x=FIXP2INT(xFixp);
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1445 if(buf[x]> avg)
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1446 r|=0x80;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1447
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1448 if(!(i & 0x07)){
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1449 data[(i>>3)-1]=r;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1450 r=0;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1451 }
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1452 xFixp+=priv->bpb;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1453 }
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1454
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1455 return 1;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1456 }
24316
31dbcf68a706 Fix for:
voroshil
parents: 24305
diff changeset
1457 #endif
23899
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1458
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1459 /**
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1460 * \brief decodes all vbi lines from one video frame
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1461 * \param priv private data structure
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1462 * \param buf buffer with raw vbi data in it
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1463 *
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1464 * \note buffer size have to be at least priv->ptsp->bufsize bytes
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1465 */
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1466 static void vbi_decode(priv_vbi_t* priv,unsigned char*buf){
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1467 int magAddr;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1468 int pkt;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1469 unsigned char data[64];
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1470 unsigned char* linep;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1471 int d0,d1;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1472 int i=0;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1473 mp_msg(MSGT_TV,MSGL_DBG3,"vbi: vbi_decode\n");
24301
15d547dfa66b Make sure that no pages will left in cache during
voroshil
parents: 24296
diff changeset
1474 for(linep=buf; !priv->cache_reset && linep<buf+priv->ptsp->bufsize; linep+=priv->ptsp->samples_per_line,i++){
23899
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1475 #if 0
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1476 /*
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1477 This routine is alternative implementation of raw VBI data decoding.
24278
2f47e955fa13 (cosmetics) replace tabs with spaces
voroshil
parents: 24277
diff changeset
1478 Unfortunately, it detects only about 20% of incoming data,
23899
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1479 but Michael says that this algorithm is better, and he wants to fix it.
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1480 */
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1481 if(decode_raw_line_sine(priv,linep,data)<=0){
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1482 #endif
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1483 if(decode_raw_line_runin(priv,linep,data)<=0){
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1484 continue; //this is not valid teletext line
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1485 }
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1486 d0= corrHamm48[ data[0] ];
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1487 d1= corrHamm48[ data[1] ];
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1488
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1489 if(d0&0x80 || d1&0x80){
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1490 pll_add(priv,2,4);
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1491 mp_msg(MSGT_TV,MSGL_V,"vbi_decode(%d):HammErr after decode_raw_line\n",i);
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1492
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1493 continue; //hamError
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1494 }
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1495 magAddr=d0 & 0x7;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1496 pkt=(d0>>3)|(d1<<1);
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1497 mp_msg(MSGT_TV,MSGL_DBG3,"vbi_decode(%d):%x %x (mag:%x, pkt:%d)\n",
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1498 i,d0,d1,magAddr,pkt);
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1499 if(!pkt){
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1500 decode_pkt0(priv,data+2,magAddr); //skip MRGA
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1501 }else if(pkt>0 && pkt<VBI_ROWS){
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1502 if(!priv->mag[magAddr].pt) continue;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1503 decode_pkt_page(priv,data+2,magAddr,pkt);//skip MRGA
24244
e446bad0872c Implement X/27/0 packet decoding.
voroshil
parents: 24232
diff changeset
1504 }else if(pkt==27) {
e446bad0872c Implement X/27/0 packet decoding.
voroshil
parents: 24232
diff changeset
1505 decode_pkt27(priv,data+2,magAddr);
24290
ca7ee5c1b88d Support for selecting language via packet 28.
voroshil
parents: 24280
diff changeset
1506 }else if(pkt==28){
ca7ee5c1b88d Support for selecting language via packet 28.
voroshil
parents: 24280
diff changeset
1507 decode_pkt28(priv,data+2);
24232
d0290b80e612 Implement 8/30 format 1 teletext packet decoding
voroshil
parents: 24197
diff changeset
1508 }else if(pkt==30){
d0290b80e612 Implement 8/30 format 1 teletext packet decoding
voroshil
parents: 24197
diff changeset
1509 decode_pkt30(priv,data+2,magAddr);
23899
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1510 } else {
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1511 mp_msg(MSGT_TV,MSGL_DBG3,"unsupported packet:%d\n",pkt);
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1512 }
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1513 }
24301
15d547dfa66b Make sure that no pages will left in cache during
voroshil
parents: 24296
diff changeset
1514 if (priv->cache_reset){
15d547dfa66b Make sure that no pages will left in cache during
voroshil
parents: 24296
diff changeset
1515 pthread_mutex_lock(&(priv->buffer_mutex));
24305
414b72437fe3 Increase number of skipped buffers to 5 to avoid mixing teletext pages from
voroshil
parents: 24301
diff changeset
1516 priv->cache_reset--;
24301
15d547dfa66b Make sure that no pages will left in cache during
voroshil
parents: 24296
diff changeset
1517 pthread_mutex_unlock(&(priv->buffer_mutex));
15d547dfa66b Make sure that no pages will left in cache during
voroshil
parents: 24296
diff changeset
1518 }
23899
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1519
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1520 }
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1521
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1522 /*
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1523 ---------------------------------------------------------------------------------
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1524 Public routines
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1525 ---------------------------------------------------------------------------------
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1526 */
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1527
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1528 /**
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1529 * \brief toggles teletext page displaying format
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1530 * \param priv_vbi private data structure
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1531 * \param flag new format
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1532 * \return
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1533 * TVI_CONTROL_TRUE is success,
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1534 * TVI_CONTROL_FALSE otherwise
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1535 *
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1536 * flag:
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1537 * 0 - opaque
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1538 * 1 - transparent
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1539 * 2 - opaque with black foreground color (only in bw mode)
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1540 * 3 - transparent with black foreground color (only in bw mode)
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1541 */
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1542 static int teletext_set_format(priv_vbi_t * priv, teletext_format flag)
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1543 {
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1544 flag&=3;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1545
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1546 mp_msg(MSGT_TV,MSGL_DBG3,"teletext_set_format_is called. mode:%d\n",flag);
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1547 pthread_mutex_lock(&(priv->buffer_mutex));
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1548
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1549 priv->tformat=flag;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1550
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1551 priv->pagenumdec=0;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1552
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1553 pthread_mutex_unlock(&(priv->buffer_mutex));
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1554 return TVI_CONTROL_TRUE;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1555 }
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1556
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1557 /**
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1558 * \brief append just entered digit to editing page number
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1559 * \param priv_vbi private data structure
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1560 * \param dec decimal digit to append
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1561 *
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1562 * dec:
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1563 * '0'..'9' append digit
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1564 * '-' remove last digit (backspace emulation)
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1565 *
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1566 * This routine allows user to jump to arbitrary page.
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1567 * It implements simple page number editing algorithm.
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1568 *
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1569 * Subsystem can be on one of two modes: normal and page number edit mode.
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1570 * Zero value of priv->pagenumdec means normal mode
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1571 * Non-zero value means page number edit mode and equals to packed
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1572 * decimal number of already entered part of page number.
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1573 *
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1574 * How this works.
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1575 * Let's assume that current mode is normal (pagenumdec is zero), teletext page
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1576 * 100 are displayed as usual. topmost left corner of page contains page number.
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1577 * Then vbi_add_dec is sequentially called (through slave
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1578 * command of course) with 1,4,-,2,3 * values of dec parameter.
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1579 *
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1580 * +-----+------------+------------------+
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1581 * | dec | pagenumdec | displayed number |
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1582 * +-----+------------+------------------+
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1583 * | | 0x000 | 100 |
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1584 * +-----+------------+------------------+
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1585 * | 1 | 0x001 | __1 |
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1586 * +-----+------------+------------------+
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1587 * | 4 | 0x014 | _14 |
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1588 * +-----+------------+------------------+
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1589 * | - | 0x001 | __1 |
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1590 * +-----+------------+------------------+
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1591 * | 2 | 0x012 | _12 |
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1592 * +-----+------------+------------------+
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1593 * | 3 | 0x123 | 123 |
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1594 * +-----+------------+------------------+
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1595 * | | 0x000 | 123 |
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1596 * +-----+------------+------------------+
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1597 *
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1598 * pagenumdec will automatically receive zero value after third digit of page
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1599 * number is entered and current page will be switched to another one with
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1600 * entered page number.
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1601 */
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1602 static void vbi_add_dec(priv_vbi_t * priv, char *dec)
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1603 {
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1604 int count, shift;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1605 if (!dec)
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1606 return;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1607 if (!priv->on)
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1608 return;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1609 if ((*dec<'0' || *dec>'9') && *dec!='-')
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1610 return;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1611 if (!priv->pagenumdec) //first digit cannot be '0','9' or '-'
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1612 if(*dec=='-' || *dec=='0' || *dec=='9')
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1613 return;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1614 pthread_mutex_lock(&(priv->buffer_mutex));
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1615 count=(priv->pagenumdec>>12)&0xf;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1616 if (*dec=='-') {
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1617 count--;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1618 if (count)
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1619 priv->pagenumdec=((priv->pagenumdec>>4)&0xfff)|(count<<12);
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1620 else
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1621 priv->pagenumdec=0;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1622 } else {
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1623 shift = count * 4;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1624 count++;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1625 priv->pagenumdec=
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1626 (((priv->pagenumdec)<<4|(*dec-'0'))&0xfff)|(count<<12);
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1627 if (count==3) {
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1628 priv->pagenum=priv->pagenumdec&0x7ff;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1629 priv->subpagenum=get_subpagenum_from_cache(priv,priv->pagenum);
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1630 priv->pagenumdec=0;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1631 }
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1632 }
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1633 pthread_mutex_unlock(&(priv->buffer_mutex));
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1634 }
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1635
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1636
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1637 /**
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1638 * \brief Teletext control routine
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1639 * \param priv_vbi private data structure
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1640 * \param cmd command
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1641 * \param arg command parameter (has to be not null)
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1642 */
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1643 int teletext_control(void* p, int cmd, void *arg)
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1644 {
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1645 int fine_tune=99;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1646 priv_vbi_t* priv=(priv_vbi_t*)p;
24244
e446bad0872c Implement X/27/0 packet decoding.
voroshil
parents: 24232
diff changeset
1647 tt_page* pgc;
23899
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1648
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1649 if (!priv && cmd!=TV_VBI_CONTROL_START)
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1650 return TVI_CONTROL_FALSE;
24342
8873c972c6aa Decrease teletext page rendering frequency from 1/frame to about 4/sec.
voroshil
parents: 24316
diff changeset
1651 if (!arg && cmd!=TV_VBI_CONTROL_STOP && cmd!=TV_VBI_CONTROL_MARK_UNCHANGED)
23899
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1652 return TVI_CONTROL_FALSE;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1653
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1654 switch (cmd) {
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1655 case TV_VBI_CONTROL_RESET:
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1656 {
24290
ca7ee5c1b88d Support for selecting language via packet 28.
voroshil
parents: 24280
diff changeset
1657 int i;
23899
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1658 tv_param_t* tv_param=arg;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1659 pthread_mutex_lock(&(priv->buffer_mutex));
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1660 priv->pagenumdec=0;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1661 clear_cache(priv);
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1662 priv->pagenum=steppage(0,tv_param->tpage&0x7ff,1);
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1663 priv->tformat=tv_param->tformat;
24293
c561d092b642 Fix displaying start page when it has subpages.
voroshil
parents: 24292
diff changeset
1664 priv->subpagenum=0x3f7f;
23899
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1665 pll_reset(priv,fine_tune);
24290
ca7ee5c1b88d Support for selecting language via packet 28.
voroshil
parents: 24280
diff changeset
1666 if(tv_param->tlang==-1){
ca7ee5c1b88d Support for selecting language via packet 28.
voroshil
parents: 24280
diff changeset
1667 mp_msg(MSGT_TV,MSGL_INFO,MSGTR_TV_TTSupportedLanguages);
ca7ee5c1b88d Support for selecting language via packet 28.
voroshil
parents: 24280
diff changeset
1668 for(i=0; tt_languages[i].lang_code; i++){
ca7ee5c1b88d Support for selecting language via packet 28.
voroshil
parents: 24280
diff changeset
1669 mp_msg(MSGT_TV,MSGL_INFO," %3d %s\n",
ca7ee5c1b88d Support for selecting language via packet 28.
voroshil
parents: 24280
diff changeset
1670 tt_languages[i].lang_code, tt_languages[i].lang_name);
ca7ee5c1b88d Support for selecting language via packet 28.
voroshil
parents: 24280
diff changeset
1671 }
ca7ee5c1b88d Support for selecting language via packet 28.
voroshil
parents: 24280
diff changeset
1672 mp_msg(MSGT_TV,MSGL_INFO," %3d %s\n",
ca7ee5c1b88d Support for selecting language via packet 28.
voroshil
parents: 24280
diff changeset
1673 tt_languages[i].lang_code, tt_languages[i].lang_name);
ca7ee5c1b88d Support for selecting language via packet 28.
voroshil
parents: 24280
diff changeset
1674 }else{
ca7ee5c1b88d Support for selecting language via packet 28.
voroshil
parents: 24280
diff changeset
1675 for(i=0; tt_languages[i].lang_code; i++){
ca7ee5c1b88d Support for selecting language via packet 28.
voroshil
parents: 24280
diff changeset
1676 if(tt_languages[i].lang_code==tv_param->tlang)
ca7ee5c1b88d Support for selecting language via packet 28.
voroshil
parents: 24280
diff changeset
1677 break;
ca7ee5c1b88d Support for selecting language via packet 28.
voroshil
parents: 24280
diff changeset
1678 }
ca7ee5c1b88d Support for selecting language via packet 28.
voroshil
parents: 24280
diff changeset
1679 if (priv->primary_language!=tt_languages[i].lang_code){
ca7ee5c1b88d Support for selecting language via packet 28.
voroshil
parents: 24280
diff changeset
1680 mp_msg(MSGT_TV,MSGL_INFO,MSGTR_TV_TTSelectedLanguage,
ca7ee5c1b88d Support for selecting language via packet 28.
voroshil
parents: 24280
diff changeset
1681 tt_languages[i].lang_name);
ca7ee5c1b88d Support for selecting language via packet 28.
voroshil
parents: 24280
diff changeset
1682 priv->primary_language=tt_languages[i].lang_code;
ca7ee5c1b88d Support for selecting language via packet 28.
voroshil
parents: 24280
diff changeset
1683 }
ca7ee5c1b88d Support for selecting language via packet 28.
voroshil
parents: 24280
diff changeset
1684 }
24342
8873c972c6aa Decrease teletext page rendering frequency from 1/frame to about 4/sec.
voroshil
parents: 24316
diff changeset
1685 priv->page_changed=1;
23899
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1686 pthread_mutex_unlock(&(priv->buffer_mutex));
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1687 return TVI_CONTROL_TRUE;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1688 }
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1689 case TV_VBI_CONTROL_START:
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1690 {
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1691 int i;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1692 tt_stream_props* ptsp=*(tt_stream_props**)arg;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1693
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1694 if(!ptsp)
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1695 return TVI_CONTROL_FALSE;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1696
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1697 priv=calloc(1,sizeof(priv_vbi_t));
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1698
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1699 priv->ptsp=malloc(sizeof(tt_stream_props));
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1700 memcpy(priv->ptsp,ptsp,sizeof(tt_stream_props));
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1701 *(priv_vbi_t**)arg=priv;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1702
24293
c561d092b642 Fix displaying start page when it has subpages.
voroshil
parents: 24292
diff changeset
1703 priv->subpagenum=0x3f7f;
23899
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1704 pthread_mutex_init(&priv->buffer_mutex, NULL);
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1705 priv->pagenumdec=0;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1706 for(i=0;i<VBI_ROWS*VBI_COLUMNS;i++)
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1707 priv->display_page[i]=tt_space;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1708
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1709 priv->mag=calloc(8,sizeof(mag_t));
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1710 init_cache(priv);
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1711 init_vbi_consts(priv);
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1712 pll_reset(priv,fine_tune);
24342
8873c972c6aa Decrease teletext page rendering frequency from 1/frame to about 4/sec.
voroshil
parents: 24316
diff changeset
1713 priv->page_changed=1;
23899
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1714 return TVI_CONTROL_TRUE;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1715 }
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1716 case TV_VBI_CONTROL_STOP:
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1717 {
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1718 if(priv->mag)
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1719 free(priv->mag);
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1720 if(priv->ptsp)
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1721 free(priv->ptsp);
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1722 destroy_cache(priv);
24342
8873c972c6aa Decrease teletext page rendering frequency from 1/frame to about 4/sec.
voroshil
parents: 24316
diff changeset
1723 priv->page_changed=1;
23899
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1724 free(priv);
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1725 return TVI_CONTROL_TRUE;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1726 }
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1727 case TV_VBI_CONTROL_SET_MODE:
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1728 priv->on=(*(int*)arg%2);
24342
8873c972c6aa Decrease teletext page rendering frequency from 1/frame to about 4/sec.
voroshil
parents: 24316
diff changeset
1729 priv->page_changed=1;
23899
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1730 return TVI_CONTROL_TRUE;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1731 case TV_VBI_CONTROL_GET_MODE:
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1732 *(int*)arg=priv->on;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1733 return TVI_CONTROL_TRUE;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1734 case TV_VBI_CONTROL_SET_FORMAT:
24342
8873c972c6aa Decrease teletext page rendering frequency from 1/frame to about 4/sec.
voroshil
parents: 24316
diff changeset
1735 priv->page_changed=1;
23899
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1736 return teletext_set_format(priv, *(int *) arg);
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1737 case TV_VBI_CONTROL_GET_FORMAT:
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1738 pthread_mutex_lock(&(priv->buffer_mutex));
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1739 *(int*)arg=priv->tformat;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1740 pthread_mutex_unlock(&(priv->buffer_mutex));
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1741 return TVI_CONTROL_TRUE;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1742 case TV_VBI_CONTROL_GET_HALF_PAGE:
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1743 if(!priv->on)
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1744 return TVI_CONTROL_FALSE;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1745 *(int *)arg=priv->zoom;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1746 return TVI_CONTROL_TRUE;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1747 case TV_VBI_CONTROL_SET_HALF_PAGE:
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1748 {
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1749 int val=*(int*)arg;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1750 val%=3;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1751 if(val<0)
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1752 val+=3;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1753 pthread_mutex_lock(&(priv->buffer_mutex));
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1754 priv->zoom=val;
24342
8873c972c6aa Decrease teletext page rendering frequency from 1/frame to about 4/sec.
voroshil
parents: 24316
diff changeset
1755 priv->page_changed=1;
23899
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1756 pthread_mutex_unlock(&(priv->buffer_mutex));
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1757 return TVI_CONTROL_TRUE;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1758 }
24244
e446bad0872c Implement X/27/0 packet decoding.
voroshil
parents: 24232
diff changeset
1759 case TV_VBI_CONTROL_GO_LINK:
e446bad0872c Implement X/27/0 packet decoding.
voroshil
parents: 24232
diff changeset
1760 {
e446bad0872c Implement X/27/0 packet decoding.
voroshil
parents: 24232
diff changeset
1761 int val=*(int *) arg;
e446bad0872c Implement X/27/0 packet decoding.
voroshil
parents: 24232
diff changeset
1762 if(val<1 || val>6)
e446bad0872c Implement X/27/0 packet decoding.
voroshil
parents: 24232
diff changeset
1763 return TVI_CONTROL_FALSE;
e446bad0872c Implement X/27/0 packet decoding.
voroshil
parents: 24232
diff changeset
1764 pthread_mutex_lock(&(priv->buffer_mutex));
e446bad0872c Implement X/27/0 packet decoding.
voroshil
parents: 24232
diff changeset
1765 if (!(pgc = priv->ptt_cache[priv->pagenum])) {
e446bad0872c Implement X/27/0 packet decoding.
voroshil
parents: 24232
diff changeset
1766 pthread_mutex_unlock(&(priv->buffer_mutex));
e446bad0872c Implement X/27/0 packet decoding.
voroshil
parents: 24232
diff changeset
1767 return TVI_CONTROL_FALSE;
e446bad0872c Implement X/27/0 packet decoding.
voroshil
parents: 24232
diff changeset
1768 }
e446bad0872c Implement X/27/0 packet decoding.
voroshil
parents: 24232
diff changeset
1769 if (!pgc->links[val-1].pagenum || pgc->links[val-1].pagenum>0x7ff) {
e446bad0872c Implement X/27/0 packet decoding.
voroshil
parents: 24232
diff changeset
1770 pthread_mutex_unlock(&(priv->buffer_mutex));
e446bad0872c Implement X/27/0 packet decoding.
voroshil
parents: 24232
diff changeset
1771 return TVI_CONTROL_FALSE;
e446bad0872c Implement X/27/0 packet decoding.
voroshil
parents: 24232
diff changeset
1772 }
e446bad0872c Implement X/27/0 packet decoding.
voroshil
parents: 24232
diff changeset
1773 priv->pagenum=pgc->links[val-1].pagenum;
e446bad0872c Implement X/27/0 packet decoding.
voroshil
parents: 24232
diff changeset
1774 if(pgc->links[val-1].subpagenum!=0x3f7f)
e446bad0872c Implement X/27/0 packet decoding.
voroshil
parents: 24232
diff changeset
1775 priv->subpagenum=pgc->links[val-1].subpagenum;
e446bad0872c Implement X/27/0 packet decoding.
voroshil
parents: 24232
diff changeset
1776 else
e446bad0872c Implement X/27/0 packet decoding.
voroshil
parents: 24232
diff changeset
1777 priv->subpagenum=get_subpagenum_from_cache(priv,priv->pagenum);
24342
8873c972c6aa Decrease teletext page rendering frequency from 1/frame to about 4/sec.
voroshil
parents: 24316
diff changeset
1778 priv->page_changed=1;
24244
e446bad0872c Implement X/27/0 packet decoding.
voroshil
parents: 24232
diff changeset
1779 pthread_mutex_unlock(&(priv->buffer_mutex));
e446bad0872c Implement X/27/0 packet decoding.
voroshil
parents: 24232
diff changeset
1780 return TVI_CONTROL_TRUE;
e446bad0872c Implement X/27/0 packet decoding.
voroshil
parents: 24232
diff changeset
1781 }
23899
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1782 case TV_VBI_CONTROL_SET_PAGE:
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1783 {
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1784 int val=*(int *) arg;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1785 if(val<100 || val>0x899)
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1786 return TVI_CONTROL_FALSE;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1787 pthread_mutex_lock(&(priv->buffer_mutex));
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1788 priv->pagenum=val&0x7ff;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1789 priv->subpagenum=get_subpagenum_from_cache(priv,priv->pagenum);
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1790 priv->pagenumdec=0;
24342
8873c972c6aa Decrease teletext page rendering frequency from 1/frame to about 4/sec.
voroshil
parents: 24316
diff changeset
1791 priv->page_changed=1;
23899
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1792 pthread_mutex_unlock(&(priv->buffer_mutex));
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1793 return TVI_CONTROL_TRUE;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1794 }
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1795 case TV_VBI_CONTROL_STEP_PAGE:
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1796 {
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1797 int direction=*(int *) arg;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1798 pthread_mutex_lock(&(priv->buffer_mutex));
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1799 priv->pagenum=steppage(priv->pagenum, direction,1);
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1800 priv->subpagenum=get_subpagenum_from_cache(priv,priv->pagenum);
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1801 priv->pagenumdec=0;
24342
8873c972c6aa Decrease teletext page rendering frequency from 1/frame to about 4/sec.
voroshil
parents: 24316
diff changeset
1802 priv->page_changed=1;
23899
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1803 pthread_mutex_unlock(&(priv->buffer_mutex));
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1804 return TVI_CONTROL_TRUE;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1805 }
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1806 case TV_VBI_CONTROL_GET_PAGE:
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1807 *(int*)arg=((priv->pagenum+0x700)&0x7ff)+0x100;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1808 return TVI_CONTROL_TRUE;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1809 case TV_VBI_CONTROL_SET_SUBPAGE:
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1810 pthread_mutex_lock(&(priv->buffer_mutex));
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1811 priv->pagenumdec=0;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1812 priv->subpagenum=*(int*)arg;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1813 if(priv->subpagenum<0)
24293
c561d092b642 Fix displaying start page when it has subpages.
voroshil
parents: 24292
diff changeset
1814 priv->subpagenum=0x3f7f;
23899
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1815 if(priv->subpagenum>=VBI_MAX_SUBPAGES)
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1816 priv->subpagenum=VBI_MAX_SUBPAGES-1;
24342
8873c972c6aa Decrease teletext page rendering frequency from 1/frame to about 4/sec.
voroshil
parents: 24316
diff changeset
1817 priv->page_changed=1;
23899
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1818 pthread_mutex_unlock(&(priv->buffer_mutex));
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1819 return TVI_CONTROL_TRUE;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1820 case TV_VBI_CONTROL_GET_SUBPAGE:
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1821 *(int*)arg=priv->subpagenum;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1822 return TVI_CONTROL_TRUE;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1823 case TV_VBI_CONTROL_ADD_DEC:
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1824 vbi_add_dec(priv, *(char **) arg);
24342
8873c972c6aa Decrease teletext page rendering frequency from 1/frame to about 4/sec.
voroshil
parents: 24316
diff changeset
1825 priv->page_changed=1;
23899
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1826 return TVI_CONTROL_TRUE;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1827 case TV_VBI_CONTROL_DECODE_PAGE:
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1828 vbi_decode(priv,*(unsigned char**)arg);
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1829 return TVI_CONTROL_TRUE;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1830 case TV_VBI_CONTROL_GET_VBIPAGE:
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1831 if(!priv->on)
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1832 return TVI_CONTROL_FALSE;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1833 prepare_visible_page(priv);
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1834 *(void **)arg=priv->display_page;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1835 return TVI_CONTROL_TRUE;
24232
d0290b80e612 Implement 8/30 format 1 teletext packet decoding
voroshil
parents: 24197
diff changeset
1836 case TV_VBI_CONTROL_GET_NETWORKNAME:
d0290b80e612 Implement 8/30 format 1 teletext packet decoding
voroshil
parents: 24197
diff changeset
1837 *(void **)arg=priv->networkname;
d0290b80e612 Implement 8/30 format 1 teletext packet decoding
voroshil
parents: 24197
diff changeset
1838 return TVI_CONTROL_TRUE;
24342
8873c972c6aa Decrease teletext page rendering frequency from 1/frame to about 4/sec.
voroshil
parents: 24316
diff changeset
1839 case TV_VBI_CONTROL_MARK_UNCHANGED:
8873c972c6aa Decrease teletext page rendering frequency from 1/frame to about 4/sec.
voroshil
parents: 24316
diff changeset
1840 priv->page_changed=0;
24345
388ac5e95da1 More accurate calculating of teletext
voroshil
parents: 24344
diff changeset
1841 priv->last_rendered=GetTimerMS();
24342
8873c972c6aa Decrease teletext page rendering frequency from 1/frame to about 4/sec.
voroshil
parents: 24316
diff changeset
1842 return TVI_CONTROL_TRUE;
8873c972c6aa Decrease teletext page rendering frequency from 1/frame to about 4/sec.
voroshil
parents: 24316
diff changeset
1843 case TV_VBI_CONTROL_IS_CHANGED:
24345
388ac5e95da1 More accurate calculating of teletext
voroshil
parents: 24344
diff changeset
1844 if(GetTimerMS()-priv->last_rendered> 250) //forcing page update every 1/4 sec
24342
8873c972c6aa Decrease teletext page rendering frequency from 1/frame to about 4/sec.
voroshil
parents: 24316
diff changeset
1845 priv->page_changed=3; //mark that header update is enough
8873c972c6aa Decrease teletext page rendering frequency from 1/frame to about 4/sec.
voroshil
parents: 24316
diff changeset
1846 *(int*)arg=priv->page_changed;
8873c972c6aa Decrease teletext page rendering frequency from 1/frame to about 4/sec.
voroshil
parents: 24316
diff changeset
1847 return TVI_CONTROL_TRUE;
23899
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1848 }
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1849 return TVI_CONTROL_UNKNOWN;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1850 }