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