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