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