annotate stream/tvi_vbi.c @ 23964:918dd2856cb6

Added FIXME skeletons for missing lavc options.
author diego
date Wed, 01 Aug 2007 08:45:46 +0000
parents c6becdb359d7
children d517c397de7d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
23899
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1 /*
34532db868ba Teletext support.
voroshil
parents:
diff changeset
2 * Teletext support
34532db868ba Teletext support.
voroshil
parents:
diff changeset
3 * Copyright (C) 2007 Vladimir Voroshilov <voroshil@gmail.com>
34532db868ba Teletext support.
voroshil
parents:
diff changeset
4 *
34532db868ba Teletext support.
voroshil
parents:
diff changeset
5 * This file is part of MPlayer.
34532db868ba Teletext support.
voroshil
parents:
diff changeset
6 *
34532db868ba Teletext support.
voroshil
parents:
diff changeset
7 * MPlayer is free software; you can redistribute it and/or modify
34532db868ba Teletext support.
voroshil
parents:
diff changeset
8 * it under the terms of the GNU General Public License as published by
34532db868ba Teletext support.
voroshil
parents:
diff changeset
9 * the Free Software Foundation; either version 2 of the License, or
34532db868ba Teletext support.
voroshil
parents:
diff changeset
10 * (at your option) any later version.
34532db868ba Teletext support.
voroshil
parents:
diff changeset
11 *
34532db868ba Teletext support.
voroshil
parents:
diff changeset
12 * MPlayer is distributed in the hope that it will be useful,
34532db868ba Teletext support.
voroshil
parents:
diff changeset
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
34532db868ba Teletext support.
voroshil
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
34532db868ba Teletext support.
voroshil
parents:
diff changeset
15 * GNU General Public License for more details.
34532db868ba Teletext support.
voroshil
parents:
diff changeset
16 *
34532db868ba Teletext support.
voroshil
parents:
diff changeset
17 * You should have received a copy of the GNU General Public License
34532db868ba Teletext support.
voroshil
parents:
diff changeset
18 * along with MPlayer; if not, write to the Free Software
34532db868ba Teletext support.
voroshil
parents:
diff changeset
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
34532db868ba Teletext support.
voroshil
parents:
diff changeset
20 *
34532db868ba Teletext support.
voroshil
parents:
diff changeset
21 *
34532db868ba Teletext support.
voroshil
parents:
diff changeset
22 * Based on Attila Otvos' teletext patch, Michael Niedermayer's
34532db868ba Teletext support.
voroshil
parents:
diff changeset
23 * proof-of-concept teletext capture utility and some parts
34532db868ba Teletext support.
voroshil
parents:
diff changeset
24 * (decode_raw_line_runin,pll_add,pll_reset) of MythTV project.
34532db868ba Teletext support.
voroshil
parents:
diff changeset
25 *
34532db868ba Teletext support.
voroshil
parents:
diff changeset
26 *
34532db868ba Teletext support.
voroshil
parents:
diff changeset
27 * Some implementation details:
34532db868ba Teletext support.
voroshil
parents:
diff changeset
28 * How to port teletext to another tvi_* driver (see tvi_v4l2.c for example):
34532db868ba Teletext support.
voroshil
parents:
diff changeset
29 *
34532db868ba Teletext support.
voroshil
parents:
diff changeset
30 * 1. Implement TVI_CONTROL_VBI_INIT (initialize driver-related vbi subsystem,
34532db868ba Teletext support.
voroshil
parents:
diff changeset
31 * start grabbing thread)
34532db868ba Teletext support.
voroshil
parents:
diff changeset
32 * input data: vbi device name.
34532db868ba Teletext support.
voroshil
parents:
diff changeset
33 * (driver should also call TV_VBI_CONTROL_START for common vbi subsystem initialization
34532db868ba Teletext support.
voroshil
parents:
diff changeset
34 * with pointer to initialized tt_stream_properties structure.
34532db868ba Teletext support.
voroshil
parents:
diff changeset
35 * After ioctl call variable will contain pointer to initialized priv_vbi_t structure.
34532db868ba Teletext support.
voroshil
parents:
diff changeset
36 *
34532db868ba Teletext support.
voroshil
parents:
diff changeset
37 * 2. After receiving next chunk of raw vbi data call TV_VBI_CONTROL_DECODE_PAGE
34532db868ba Teletext support.
voroshil
parents:
diff changeset
38 * ioctl with pointer to data buffer
34532db868ba Teletext support.
voroshil
parents:
diff changeset
39 * 3. pass all other VBI related ioctl cmds to teletext_control routine
34532db868ba Teletext support.
voroshil
parents:
diff changeset
40 *
34532db868ba Teletext support.
voroshil
parents:
diff changeset
41 * Page displaying process consist of following stages:
34532db868ba Teletext support.
voroshil
parents:
diff changeset
42 *
34532db868ba Teletext support.
voroshil
parents:
diff changeset
43 * ---grabbing stage---
34532db868ba Teletext support.
voroshil
parents:
diff changeset
44 * 0. stream/tvi_*.c: vbi_grabber(...)
34532db868ba Teletext support.
voroshil
parents:
diff changeset
45 * getting vbi data from video device
34532db868ba Teletext support.
voroshil
parents:
diff changeset
46 * ---decoding stage---
34532db868ba Teletext support.
voroshil
parents:
diff changeset
47 * 1. stream/tvi_vbi.c: decode_raw_line_runin(...) or decode_raw_line_sine(...)
34532db868ba Teletext support.
voroshil
parents:
diff changeset
48 * decode raw vbi data into sliced 45(?) bytes long packets
34532db868ba Teletext support.
voroshil
parents:
diff changeset
49 * 2. stream/tvi_vbi.c: decode_pkt0(...), decode_pkt_page(...)
34532db868ba Teletext support.
voroshil
parents:
diff changeset
50 * packets processing (header analyzing, storing complete page in cache,
34532db868ba Teletext support.
voroshil
parents:
diff changeset
51 * only raw member of tt_char is filled at this stage)
34532db868ba Teletext support.
voroshil
parents:
diff changeset
52 * 3. stream/tvi_vbi.c: decode_page(...)
34532db868ba Teletext support.
voroshil
parents:
diff changeset
53 * page decoding. filling unicode,gfx,ctl,etc members of tt_char structure
34532db868ba Teletext support.
voroshil
parents:
diff changeset
54 * with appropriate values according to teletext control chars, converting
34532db868ba Teletext support.
voroshil
parents:
diff changeset
55 * text to utf8.
34532db868ba Teletext support.
voroshil
parents:
diff changeset
56 * ---rendering stage---
34532db868ba Teletext support.
voroshil
parents:
diff changeset
57 * 4. stream/tvi_vbi.c: prepare_visible_page(...)
34532db868ba Teletext support.
voroshil
parents:
diff changeset
58 * processing page. adding number of just received by background process
34532db868ba Teletext support.
voroshil
parents:
diff changeset
59 * teletext page, adding current time,etc.
34532db868ba Teletext support.
voroshil
parents:
diff changeset
60 * 5. libvo/sub.c: vo_update_text_teletext(...)
34532db868ba Teletext support.
voroshil
parents:
diff changeset
61 * rendering displayable osd with text and graphics
34532db868ba Teletext support.
voroshil
parents:
diff changeset
62 *
34532db868ba Teletext support.
voroshil
parents:
diff changeset
63 * TODO:
34532db868ba Teletext support.
voroshil
parents:
diff changeset
64 * v4lv1,bktr support
34532db868ba Teletext support.
voroshil
parents:
diff changeset
65 * spu rendering
34532db868ba Teletext support.
voroshil
parents:
diff changeset
66 * is better quality on poor signal possible ?
34532db868ba Teletext support.
voroshil
parents:
diff changeset
67 * link support
34532db868ba Teletext support.
voroshil
parents:
diff changeset
68 * font autoscale
34532db868ba Teletext support.
voroshil
parents:
diff changeset
69 * greyscale osd
34532db868ba Teletext support.
voroshil
parents:
diff changeset
70 * slave command for dumping pages
34532db868ba Teletext support.
voroshil
parents:
diff changeset
71 * fix bcd<->dec as suggested my Michael
34532db868ba Teletext support.
voroshil
parents:
diff changeset
72 *
34532db868ba Teletext support.
voroshil
parents:
diff changeset
73 * BUGS:
34532db868ba Teletext support.
voroshil
parents:
diff changeset
74 * wrong colors in debug dump
34532db868ba Teletext support.
voroshil
parents:
diff changeset
75 * blinking when visible page was just updated
34532db868ba Teletext support.
voroshil
parents:
diff changeset
76 */
34532db868ba Teletext support.
voroshil
parents:
diff changeset
77
34532db868ba Teletext support.
voroshil
parents:
diff changeset
78 #include "config.h"
34532db868ba Teletext support.
voroshil
parents:
diff changeset
79
34532db868ba Teletext support.
voroshil
parents:
diff changeset
80 #include <stdlib.h>
34532db868ba Teletext support.
voroshil
parents:
diff changeset
81 #include <string.h>
34532db868ba Teletext support.
voroshil
parents:
diff changeset
82 #include <unistd.h>
34532db868ba Teletext support.
voroshil
parents:
diff changeset
83 #include <errno.h>
34532db868ba Teletext support.
voroshil
parents:
diff changeset
84 #include <math.h>
34532db868ba Teletext support.
voroshil
parents:
diff changeset
85 #include <stdio.h>
34532db868ba Teletext support.
voroshil
parents:
diff changeset
86
34532db868ba Teletext support.
voroshil
parents:
diff changeset
87 #include <pthread.h>
34532db868ba Teletext support.
voroshil
parents:
diff changeset
88
34532db868ba Teletext support.
voroshil
parents:
diff changeset
89 #include "tv.h"
34532db868ba Teletext support.
voroshil
parents:
diff changeset
90 #include "mp_msg.h"
34532db868ba Teletext support.
voroshil
parents:
diff changeset
91 #include "help_mp.h"
34532db868ba Teletext support.
voroshil
parents:
diff changeset
92 #include "libmpcodecs/img_format.h"
34532db868ba Teletext support.
voroshil
parents:
diff changeset
93 #include "libavutil/common.h"
34532db868ba Teletext support.
voroshil
parents:
diff changeset
94 #include "input/input.h"
34532db868ba Teletext support.
voroshil
parents:
diff changeset
95
34532db868ba Teletext support.
voroshil
parents:
diff changeset
96 //#define DEBUG_DUMP 1
34532db868ba Teletext support.
voroshil
parents:
diff changeset
97
34532db868ba Teletext support.
voroshil
parents:
diff changeset
98 /// page magazine entry structure
34532db868ba Teletext support.
voroshil
parents:
diff changeset
99 typedef struct mag_s{
34532db868ba Teletext support.
voroshil
parents:
diff changeset
100 tt_page* pt;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
101 int order;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
102 int lang;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
103 } mag_t;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
104
34532db868ba Teletext support.
voroshil
parents:
diff changeset
105 typedef struct {
34532db868ba Teletext support.
voroshil
parents:
diff changeset
106 int on; ///< teletext on/off
34532db868ba Teletext support.
voroshil
parents:
diff changeset
107 int pagenum; ///< seek page number
34532db868ba Teletext support.
voroshil
parents:
diff changeset
108 int subpagenum; ///< seek subpage
34532db868ba Teletext support.
voroshil
parents:
diff changeset
109 int curr_pagenum; ///< current page number
34532db868ba Teletext support.
voroshil
parents:
diff changeset
110 int pagenumdec; ///< set page num with dec
34532db868ba Teletext support.
voroshil
parents:
diff changeset
111
34532db868ba Teletext support.
voroshil
parents:
diff changeset
112 teletext_format tformat; ///< see teletext_format enum
34532db868ba Teletext support.
voroshil
parents:
diff changeset
113 teletext_zoom zoom; ///< see teletext_zoom enum
34532db868ba Teletext support.
voroshil
parents:
diff changeset
114 mag_t* mag; ///< pages magazine (has 8 entities)
34532db868ba Teletext support.
voroshil
parents:
diff changeset
115 /// Currently displayed page (with additional info, e.g current time)
34532db868ba Teletext support.
voroshil
parents:
diff changeset
116 tt_char display_page[VBI_ROWS*VBI_COLUMNS];
34532db868ba Teletext support.
voroshil
parents:
diff changeset
117 /// number of raw bytes between two subsequent encoded bits
34532db868ba Teletext support.
voroshil
parents:
diff changeset
118 int bpb;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
119 /// clock run-in sequence will be searched in buffer in [soc:eoc] bytes range
34532db868ba Teletext support.
voroshil
parents:
diff changeset
120 int soc;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
121 int eoc;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
122 /// minimum number of raw vbi bytes wich can be decoded into 8 data bits
34532db868ba Teletext support.
voroshil
parents:
diff changeset
123 int bp8bl;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
124 /// maximum number of raw vbi bytes wich can be decoded into 8 data bits
34532db868ba Teletext support.
voroshil
parents:
diff changeset
125 int bp8bh;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
126
34532db868ba Teletext support.
voroshil
parents:
diff changeset
127 int pll_adj;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
128 int pll_dir;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
129 int pll_cnt;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
130 int pll_err;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
131 int pll_lerr;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
132 int pll_fixed;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
133 /// vbi stream properties (buffer size,bytes per line, etc)
34532db868ba Teletext support.
voroshil
parents:
diff changeset
134 tt_stream_props* ptsp;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
135 pthread_mutex_t buffer_mutex;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
136
34532db868ba Teletext support.
voroshil
parents:
diff changeset
137 tt_page** ptt_cache;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
138 unsigned char* ptt_cache_first_subpage;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
139 } priv_vbi_t;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
140
34532db868ba Teletext support.
voroshil
parents:
diff changeset
141 static unsigned char fixParity[256];
34532db868ba Teletext support.
voroshil
parents:
diff changeset
142
34532db868ba Teletext support.
voroshil
parents:
diff changeset
143 static tt_char tt_space={0x20,7,0,0,0,0,0x20};
34532db868ba Teletext support.
voroshil
parents:
diff changeset
144 static tt_char tt_error={'?',1,0,0,0,0,'?'}; // Red '?' on black background
34532db868ba Teletext support.
voroshil
parents:
diff changeset
145 static double si[12];
34532db868ba Teletext support.
voroshil
parents:
diff changeset
146 static double co[12];
34532db868ba Teletext support.
voroshil
parents:
diff changeset
147
34532db868ba Teletext support.
voroshil
parents:
diff changeset
148 #define VBI_FORMAT(priv) (*(priv->ptsp))
34532db868ba Teletext support.
voroshil
parents:
diff changeset
149
34532db868ba Teletext support.
voroshil
parents:
diff changeset
150 #define FIXP_SH 16
34532db868ba Teletext support.
voroshil
parents:
diff changeset
151 #define ONE_FIXP (1<<FIXP_SH)
34532db868ba Teletext support.
voroshil
parents:
diff changeset
152 #define FIXP2INT(a) ((a)>>FIXP_SH)
34532db868ba Teletext support.
voroshil
parents:
diff changeset
153 #define ANY2FIXP(a) ((int)((a)*ONE_FIXP))
34532db868ba Teletext support.
voroshil
parents:
diff changeset
154
34532db868ba Teletext support.
voroshil
parents:
diff changeset
155 static const unsigned char corrHamm48[256]={
34532db868ba Teletext support.
voroshil
parents:
diff changeset
156 0x01, 0xff, 0x01, 0x01, 0xff, 0x00, 0x01, 0xff,
34532db868ba Teletext support.
voroshil
parents:
diff changeset
157 0xff, 0x02, 0x01, 0xff, 0x0a, 0xff, 0xff, 0x07,
34532db868ba Teletext support.
voroshil
parents:
diff changeset
158 0xff, 0x00, 0x01, 0xff, 0x00, 0x00, 0xff, 0x00,
34532db868ba Teletext support.
voroshil
parents:
diff changeset
159 0x06, 0xff, 0xff, 0x0b, 0xff, 0x00, 0x03, 0xff,
34532db868ba Teletext support.
voroshil
parents:
diff changeset
160 0xff, 0x0c, 0x01, 0xff, 0x04, 0xff, 0xff, 0x07,
34532db868ba Teletext support.
voroshil
parents:
diff changeset
161 0x06, 0xff, 0xff, 0x07, 0xff, 0x07, 0x07, 0x07,
34532db868ba Teletext support.
voroshil
parents:
diff changeset
162 0x06, 0xff, 0xff, 0x05, 0xff, 0x00, 0x0d, 0xff,
34532db868ba Teletext support.
voroshil
parents:
diff changeset
163 0x06, 0x06, 0x06, 0xff, 0x06, 0xff, 0xff, 0x07,
34532db868ba Teletext support.
voroshil
parents:
diff changeset
164 0xff, 0x02, 0x01, 0xff, 0x04, 0xff, 0xff, 0x09,
34532db868ba Teletext support.
voroshil
parents:
diff changeset
165 0x02, 0x02, 0xff, 0x02, 0xff, 0x02, 0x03, 0xff,
34532db868ba Teletext support.
voroshil
parents:
diff changeset
166 0x08, 0xff, 0xff, 0x05, 0xff, 0x00, 0x03, 0xff,
34532db868ba Teletext support.
voroshil
parents:
diff changeset
167 0xff, 0x02, 0x03, 0xff, 0x03, 0xff, 0x03, 0x03,
34532db868ba Teletext support.
voroshil
parents:
diff changeset
168 0x04, 0xff, 0xff, 0x05, 0x04, 0x04, 0x04, 0xff,
34532db868ba Teletext support.
voroshil
parents:
diff changeset
169 0xff, 0x02, 0x0f, 0xff, 0x04, 0xff, 0xff, 0x07,
34532db868ba Teletext support.
voroshil
parents:
diff changeset
170 0xff, 0x05, 0x05, 0x05, 0x04, 0xff, 0xff, 0x05,
34532db868ba Teletext support.
voroshil
parents:
diff changeset
171 0x06, 0xff, 0xff, 0x05, 0xff, 0x0e, 0x03, 0xff,
34532db868ba Teletext support.
voroshil
parents:
diff changeset
172 0xff, 0x0c, 0x01, 0xff, 0x0a, 0xff, 0xff, 0x09,
34532db868ba Teletext support.
voroshil
parents:
diff changeset
173 0x0a, 0xff, 0xff, 0x0b, 0x0a, 0x0a, 0x0a, 0xff,
34532db868ba Teletext support.
voroshil
parents:
diff changeset
174 0x08, 0xff, 0xff, 0x0b, 0xff, 0x00, 0x0d, 0xff,
34532db868ba Teletext support.
voroshil
parents:
diff changeset
175 0xff, 0x0b, 0x0b, 0x0b, 0x0a, 0xff, 0xff, 0x0b,
34532db868ba Teletext support.
voroshil
parents:
diff changeset
176 0x0c, 0x0c, 0xff, 0x0c, 0xff, 0x0c, 0x0d, 0xff,
34532db868ba Teletext support.
voroshil
parents:
diff changeset
177 0xff, 0x0c, 0x0f, 0xff, 0x0a, 0xff, 0xff, 0x07,
34532db868ba Teletext support.
voroshil
parents:
diff changeset
178 0xff, 0x0c, 0x0d, 0xff, 0x0d, 0xff, 0x0d, 0x0d,
34532db868ba Teletext support.
voroshil
parents:
diff changeset
179 0x06, 0xff, 0xff, 0x0b, 0xff, 0x0e, 0x0d, 0xff,
34532db868ba Teletext support.
voroshil
parents:
diff changeset
180 0x08, 0xff, 0xff, 0x09, 0xff, 0x09, 0x09, 0x09,
34532db868ba Teletext support.
voroshil
parents:
diff changeset
181 0xff, 0x02, 0x0f, 0xff, 0x0a, 0xff, 0xff, 0x09,
34532db868ba Teletext support.
voroshil
parents:
diff changeset
182 0x08, 0x08, 0x08, 0xff, 0x08, 0xff, 0xff, 0x09,
34532db868ba Teletext support.
voroshil
parents:
diff changeset
183 0x08, 0xff, 0xff, 0x0b, 0xff, 0x0e, 0x03, 0xff,
34532db868ba Teletext support.
voroshil
parents:
diff changeset
184 0xff, 0x0c, 0x0f, 0xff, 0x04, 0xff, 0xff, 0x09,
34532db868ba Teletext support.
voroshil
parents:
diff changeset
185 0x0f, 0xff, 0x0f, 0x0f, 0xff, 0x0e, 0x0f, 0xff,
34532db868ba Teletext support.
voroshil
parents:
diff changeset
186 0x08, 0xff, 0xff, 0x05, 0xff, 0x0e, 0x0d, 0xff,
34532db868ba Teletext support.
voroshil
parents:
diff changeset
187 0xff, 0x0e, 0x0f, 0xff, 0x0e, 0x0e, 0xff, 0x0e };
34532db868ba Teletext support.
voroshil
parents:
diff changeset
188
34532db868ba Teletext support.
voroshil
parents:
diff changeset
189
34532db868ba Teletext support.
voroshil
parents:
diff changeset
190 enum {
34532db868ba Teletext support.
voroshil
parents:
diff changeset
191 LAT_UNI=0,
34532db868ba Teletext support.
voroshil
parents:
diff changeset
192 RUS_UNI,
34532db868ba Teletext support.
voroshil
parents:
diff changeset
193 LANGS
34532db868ba Teletext support.
voroshil
parents:
diff changeset
194 };
34532db868ba Teletext support.
voroshil
parents:
diff changeset
195
34532db868ba Teletext support.
voroshil
parents:
diff changeset
196 // conversion table for chars 0x20-0x7F (UTF8)
34532db868ba Teletext support.
voroshil
parents:
diff changeset
197 // TODO: add another languages
34532db868ba Teletext support.
voroshil
parents:
diff changeset
198 static unsigned int lang_chars[LANGS][0x60]={
34532db868ba Teletext support.
voroshil
parents:
diff changeset
199 {
34532db868ba Teletext support.
voroshil
parents:
diff changeset
200 //Latin
34532db868ba Teletext support.
voroshil
parents:
diff changeset
201 0x20,0x21,0x22,0x23,0x24,0x25,0x26,0x27,
34532db868ba Teletext support.
voroshil
parents:
diff changeset
202 0x28,0x29,0x2a,0x2b,0x2c,0x2d,0x2e,0x2f,
34532db868ba Teletext support.
voroshil
parents:
diff changeset
203 0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,
34532db868ba Teletext support.
voroshil
parents:
diff changeset
204 0x38,0x39,0x3a,0x3b,0x3c,0x3d,0x3e,0x3f,
34532db868ba Teletext support.
voroshil
parents:
diff changeset
205 0x40,0x41,0x42,0x43,0x44,0x45,0x46,0x47,
34532db868ba Teletext support.
voroshil
parents:
diff changeset
206 0x48,0x49,0x4a,0x4b,0x4c,0x4d,0x4e,0x4f,
34532db868ba Teletext support.
voroshil
parents:
diff changeset
207 0x50,0x51,0x52,0x53,0x54,0x55,0x56,0x57,
34532db868ba Teletext support.
voroshil
parents:
diff changeset
208 0x58,0x59,0x5a,0x5b,0x5c,0x5d,0x5e,0x5f,
34532db868ba Teletext support.
voroshil
parents:
diff changeset
209 0x60,0x61,0x62,0x63,0x64,0x65,0x66,0x67,
34532db868ba Teletext support.
voroshil
parents:
diff changeset
210 0x68,0x69,0x6a,0x6b,0x6c,0x6d,0x6e,0x6f,
34532db868ba Teletext support.
voroshil
parents:
diff changeset
211 0x70,0x71,0x72,0x73,0x74,0x75,0x76,0x77,
34532db868ba Teletext support.
voroshil
parents:
diff changeset
212 0x78,0x79,0x7a,0x7b,0x7c,0x7d,0x7e,0x7f
34532db868ba Teletext support.
voroshil
parents:
diff changeset
213 },
34532db868ba Teletext support.
voroshil
parents:
diff changeset
214 {
34532db868ba Teletext support.
voroshil
parents:
diff changeset
215 //Russian
34532db868ba Teletext support.
voroshil
parents:
diff changeset
216 0x20,0x21,0x22,0x23,0x24,0x25,0x044b,0x27,
34532db868ba Teletext support.
voroshil
parents:
diff changeset
217 0x28,0x29,0x2a,0x2b,0x2c,0x2d,0x2e,0x2f,
34532db868ba Teletext support.
voroshil
parents:
diff changeset
218 0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,
34532db868ba Teletext support.
voroshil
parents:
diff changeset
219 0x38,0x39,0x3a,0x3b,0x3c,0x3d,0x3e,0x3f,
34532db868ba Teletext support.
voroshil
parents:
diff changeset
220 0x042e,0x0410,0x0411,0x0426,0x0414,0x0415,0x0424,0x0413,
34532db868ba Teletext support.
voroshil
parents:
diff changeset
221 0x0425,0x0418,0x0419,0x041a,0x041b,0x041c,0x041d,0x041e,
34532db868ba Teletext support.
voroshil
parents:
diff changeset
222 0x041f,0x042f,0x0420,0x0421,0x0422,0x0423,0x0416,0x0412,
34532db868ba Teletext support.
voroshil
parents:
diff changeset
223 0x042c,0x042a,0x0417,0x0428,0x042d,0x0429,0x0427,0x042b,
34532db868ba Teletext support.
voroshil
parents:
diff changeset
224 0x044e,0x0430,0x0431,0x0446,0x0434,0x0435,0x0444,0x0433,
34532db868ba Teletext support.
voroshil
parents:
diff changeset
225 0x0445,0x0438,0x0439,0x043a,0x043b,0x043c,0x043d,0x043e,
34532db868ba Teletext support.
voroshil
parents:
diff changeset
226 0x043f,0x044f,0x0440,0x0441,0x0442,0x0443,0x0436,0x0432,
34532db868ba Teletext support.
voroshil
parents:
diff changeset
227 0x044c,0x044a,0x0437,0x0448,0x044d,0x0449,0x0447,0x044b
34532db868ba Teletext support.
voroshil
parents:
diff changeset
228 }
34532db868ba Teletext support.
voroshil
parents:
diff changeset
229 };
34532db868ba Teletext support.
voroshil
parents:
diff changeset
230
34532db868ba Teletext support.
voroshil
parents:
diff changeset
231 static int lang2id (int lang){
34532db868ba Teletext support.
voroshil
parents:
diff changeset
232 switch(lang){
34532db868ba Teletext support.
voroshil
parents:
diff changeset
233 case 0:
34532db868ba Teletext support.
voroshil
parents:
diff changeset
234 return LAT_UNI;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
235 case 3: /* Stub. My teletext provider (1TV, Russia) sets this this language
34532db868ba Teletext support.
voroshil
parents:
diff changeset
236 code for russian teletext pages
34532db868ba Teletext support.
voroshil
parents:
diff changeset
237 TODO: make this configurable
34532db868ba Teletext support.
voroshil
parents:
diff changeset
238 */
34532db868ba Teletext support.
voroshil
parents:
diff changeset
239 return RUS_UNI;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
240 default:
34532db868ba Teletext support.
voroshil
parents:
diff changeset
241 return LAT_UNI;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
242 }
34532db868ba Teletext support.
voroshil
parents:
diff changeset
243 }
34532db868ba Teletext support.
voroshil
parents:
diff changeset
244
34532db868ba Teletext support.
voroshil
parents:
diff changeset
245 /**
34532db868ba Teletext support.
voroshil
parents:
diff changeset
246 * \brief convert chars from curent teletext codepage into MPlayer charset
34532db868ba Teletext support.
voroshil
parents:
diff changeset
247 * \param p raw teletext char to decode
34532db868ba Teletext support.
voroshil
parents:
diff changeset
248 * \param lang teletext internal language code (see lang2id)
34532db868ba Teletext support.
voroshil
parents:
diff changeset
249 * \return UTF8 char
34532db868ba Teletext support.
voroshil
parents:
diff changeset
250 *
34532db868ba Teletext support.
voroshil
parents:
diff changeset
251 * \remarks
34532db868ba Teletext support.
voroshil
parents:
diff changeset
252 * routine will analyze raw member of given tt_char structure and
34532db868ba Teletext support.
voroshil
parents:
diff changeset
253 * fill unicode member of the same struct with appropriate utf8 code.
34532db868ba Teletext support.
voroshil
parents:
diff changeset
254 */
34532db868ba Teletext support.
voroshil
parents:
diff changeset
255 static unsigned int conv2uni(unsigned int p,int lang)
34532db868ba Teletext support.
voroshil
parents:
diff changeset
256 {
34532db868ba Teletext support.
voroshil
parents:
diff changeset
257 if(p<0x80 && p>=0x20){
34532db868ba Teletext support.
voroshil
parents:
diff changeset
258 return lang_chars[lang][p-0x20];
34532db868ba Teletext support.
voroshil
parents:
diff changeset
259 }else
34532db868ba Teletext support.
voroshil
parents:
diff changeset
260 return 0x20;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
261 }
34532db868ba Teletext support.
voroshil
parents:
diff changeset
262
34532db868ba Teletext support.
voroshil
parents:
diff changeset
263 static void init_vbi_consts(priv_vbi_t* priv){
34532db868ba Teletext support.
voroshil
parents:
diff changeset
264 int i,j;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
265 double ang;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
266 for(i=0; i<256; i++){
34532db868ba Teletext support.
voroshil
parents:
diff changeset
267 j=i&0x7F;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
268 j^= j+j;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
269 j^= j<<2;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
270 j^= j<<4;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
271 fixParity[i]= i ^ (j&0x80) ^ 0x80;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
272 }
34532db868ba Teletext support.
voroshil
parents:
diff changeset
273
34532db868ba Teletext support.
voroshil
parents:
diff changeset
274 for(i=0,ang=0; i<12; i++,ang+=M_PI/priv->bpb){
34532db868ba Teletext support.
voroshil
parents:
diff changeset
275 si[i]= sin(ang);
34532db868ba Teletext support.
voroshil
parents:
diff changeset
276 co[i]= cos(ang);
34532db868ba Teletext support.
voroshil
parents:
diff changeset
277 }
34532db868ba Teletext support.
voroshil
parents:
diff changeset
278
34532db868ba Teletext support.
voroshil
parents:
diff changeset
279 priv->bpb=(priv->ptsp->sampling_rate/6937500.0)*ONE_FIXP+0.5;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
280 //FIXME: STUBS!!!!
34532db868ba Teletext support.
voroshil
parents:
diff changeset
281 priv->soc=0;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
282 priv->eoc=92;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
283 //END STUBS!!!
34532db868ba Teletext support.
voroshil
parents:
diff changeset
284 priv->bp8bl=0.97*8*priv->bpb/ONE_FIXP; // -3% tolerance
34532db868ba Teletext support.
voroshil
parents:
diff changeset
285 priv->bp8bh=1.03*8*priv->bpb/ONE_FIXP; // +3% tolerance
34532db868ba Teletext support.
voroshil
parents:
diff changeset
286 }
34532db868ba Teletext support.
voroshil
parents:
diff changeset
287 /**
34532db868ba Teletext support.
voroshil
parents:
diff changeset
288 * \brief calculate increased/decreased by given value page number
34532db868ba Teletext support.
voroshil
parents:
diff changeset
289 * \param curr current page number in hexadecimal for
34532db868ba Teletext support.
voroshil
parents:
diff changeset
290 * \param direction decimal value (can be negative) to add to value
34532db868ba Teletext support.
voroshil
parents:
diff changeset
291 * of curr parameter
34532db868ba Teletext support.
voroshil
parents:
diff changeset
292 * \return new page number in hexadecimal form
34532db868ba Teletext support.
voroshil
parents:
diff changeset
293 *
34532db868ba Teletext support.
voroshil
parents:
diff changeset
294 * VBI page numbers are represented in special hexadecimal form, e.g.
34532db868ba Teletext support.
voroshil
parents:
diff changeset
295 * page with number 123 (as seen by user) internally has number 0x123.
34532db868ba Teletext support.
voroshil
parents:
diff changeset
296 * and equation 0x123+8 should be equal to 0x131 instead of regular 0x12b.
34532db868ba Teletext support.
voroshil
parents:
diff changeset
297 *
34532db868ba Teletext support.
voroshil
parents:
diff changeset
298 *
34532db868ba Teletext support.
voroshil
parents:
diff changeset
299 * Page numbers 0xYYY (where Y is not belongs to (0..9).
34532db868ba Teletext support.
voroshil
parents:
diff changeset
300 * Page number belongs to [0x000,0x799] or [0x100:0x899] (first 0 can be
34532db868ba Teletext support.
voroshil
parents:
diff changeset
301 * treated as '8')
34532db868ba Teletext support.
voroshil
parents:
diff changeset
302 */
34532db868ba Teletext support.
voroshil
parents:
diff changeset
303 static int steppage(int p, int direction, int skip_hidden)
34532db868ba Teletext support.
voroshil
parents:
diff changeset
304 {
34532db868ba Teletext support.
voroshil
parents:
diff changeset
305 if(skip_hidden)
34532db868ba Teletext support.
voroshil
parents:
diff changeset
306 p=(p&15)+((p>>4)&15)*10+(p>>8)*100;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
307 p+=direction;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
308 if(skip_hidden){
34532db868ba Teletext support.
voroshil
parents:
diff changeset
309 p=(p+800)%800;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
310 p=(p%10)+((p/10)%10)*16+(p/100)*256;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
311 }
34532db868ba Teletext support.
voroshil
parents:
diff changeset
312
34532db868ba Teletext support.
voroshil
parents:
diff changeset
313 return p&0x7ff;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
314 }
34532db868ba Teletext support.
voroshil
parents:
diff changeset
315
34532db868ba Teletext support.
voroshil
parents:
diff changeset
316 /*
34532db868ba Teletext support.
voroshil
parents:
diff changeset
317 ------------------------------------------------------------------
34532db868ba Teletext support.
voroshil
parents:
diff changeset
318 Cache stuff
34532db868ba Teletext support.
voroshil
parents:
diff changeset
319 ------------------------------------------------------------------
34532db868ba Teletext support.
voroshil
parents:
diff changeset
320 */
34532db868ba Teletext support.
voroshil
parents:
diff changeset
321
34532db868ba Teletext support.
voroshil
parents:
diff changeset
322 /**
34532db868ba Teletext support.
voroshil
parents:
diff changeset
323 * \brief add/update entry in cache
34532db868ba Teletext support.
voroshil
parents:
diff changeset
324 * \param priv private data structure
34532db868ba Teletext support.
voroshil
parents:
diff changeset
325 * \param pg page to store in cache
34532db868ba Teletext support.
voroshil
parents:
diff changeset
326 * \param line line to update (value below 0 means update entire page)
34532db868ba Teletext support.
voroshil
parents:
diff changeset
327 */
34532db868ba Teletext support.
voroshil
parents:
diff changeset
328 static void put_to_cache(priv_vbi_t* priv,tt_page* pg,int line){
34532db868ba Teletext support.
voroshil
parents:
diff changeset
329 tt_page* pgc; //page in cache
34532db868ba Teletext support.
voroshil
parents:
diff changeset
330 int i,count;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
331
34532db868ba Teletext support.
voroshil
parents:
diff changeset
332 if(line<0){
34532db868ba Teletext support.
voroshil
parents:
diff changeset
333 i=0;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
334 count=VBI_ROWS*VBI_COLUMNS;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
335 }else if(line<VBI_ROWS){
34532db868ba Teletext support.
voroshil
parents:
diff changeset
336 i=line*VBI_COLUMNS;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
337 count=(line+1)*VBI_COLUMNS;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
338 }else
34532db868ba Teletext support.
voroshil
parents:
diff changeset
339 return;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
340
34532db868ba Teletext support.
voroshil
parents:
diff changeset
341 pthread_mutex_lock(&(priv->buffer_mutex));
34532db868ba Teletext support.
voroshil
parents:
diff changeset
342
34532db868ba Teletext support.
voroshil
parents:
diff changeset
343 if(!priv->ptt_cache[pg->pagenum]){
34532db868ba Teletext support.
voroshil
parents:
diff changeset
344 priv->ptt_cache[pg->pagenum]=calloc(1,sizeof(tt_page));
34532db868ba Teletext support.
voroshil
parents:
diff changeset
345 pgc=priv->ptt_cache[pg->pagenum];
34532db868ba Teletext support.
voroshil
parents:
diff changeset
346 }else{
34532db868ba Teletext support.
voroshil
parents:
diff changeset
347 pgc=priv->ptt_cache[pg->pagenum];
34532db868ba Teletext support.
voroshil
parents:
diff changeset
348 while(pgc->next_subpage && pgc->subpagenum!=pg->subpagenum)
34532db868ba Teletext support.
voroshil
parents:
diff changeset
349 pgc=pgc->next_subpage;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
350
34532db868ba Teletext support.
voroshil
parents:
diff changeset
351 if(pgc->subpagenum!=pg->subpagenum){
34532db868ba Teletext support.
voroshil
parents:
diff changeset
352 pgc->next_subpage=calloc(1,sizeof(tt_page));
34532db868ba Teletext support.
voroshil
parents:
diff changeset
353 pgc=pgc->next_subpage;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
354 }
34532db868ba Teletext support.
voroshil
parents:
diff changeset
355 }
34532db868ba Teletext support.
voroshil
parents:
diff changeset
356 pgc->pagenum=pg->pagenum;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
357 pgc->subpagenum=pg->subpagenum;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
358 pgc->lang=pg->lang;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
359 pgc->flags=pg->flags;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
360 //instead of copying entire page into cache, copy only undamaged
34532db868ba Teletext support.
voroshil
parents:
diff changeset
361 //symbols into cache
34532db868ba Teletext support.
voroshil
parents:
diff changeset
362 for(;i<count;i++){
34532db868ba Teletext support.
voroshil
parents:
diff changeset
363 if(!(pg->raw[i]&0x80))
34532db868ba Teletext support.
voroshil
parents:
diff changeset
364 pgc->raw[i]=pg->raw[i];
34532db868ba Teletext support.
voroshil
parents:
diff changeset
365 else
34532db868ba Teletext support.
voroshil
parents:
diff changeset
366 mp_msg(MSGT_TV,MSGL_DBG3,"char error. pg:%x, c[%d]=0x%x\n",
34532db868ba Teletext support.
voroshil
parents:
diff changeset
367 pg->pagenum,i,pg->raw[i]);
34532db868ba Teletext support.
voroshil
parents:
diff changeset
368 }
34532db868ba Teletext support.
voroshil
parents:
diff changeset
369 pgc->active=1;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
370 pthread_mutex_unlock(&(priv->buffer_mutex));
34532db868ba Teletext support.
voroshil
parents:
diff changeset
371 }
34532db868ba Teletext support.
voroshil
parents:
diff changeset
372
34532db868ba Teletext support.
voroshil
parents:
diff changeset
373 /**
34532db868ba Teletext support.
voroshil
parents:
diff changeset
374 * \brief get any subpage number of given page
34532db868ba Teletext support.
voroshil
parents:
diff changeset
375 * \param priv private data structure
34532db868ba Teletext support.
voroshil
parents:
diff changeset
376 * \param pagenum page number to search subpages in
34532db868ba Teletext support.
voroshil
parents:
diff changeset
377 *
34532db868ba Teletext support.
voroshil
parents:
diff changeset
378 * \return subpage number of first found subpage which belongs to
34532db868ba Teletext support.
voroshil
parents:
diff changeset
379 * given page number
34532db868ba Teletext support.
voroshil
parents:
diff changeset
380 *
34532db868ba Teletext support.
voroshil
parents:
diff changeset
381 * \note page itself is subpage too (and usually has subpage number 0)
34532db868ba Teletext support.
voroshil
parents:
diff changeset
382 */
34532db868ba Teletext support.
voroshil
parents:
diff changeset
383 static inline int get_subpagenum_from_cache(priv_vbi_t* priv, int pagenum){
34532db868ba Teletext support.
voroshil
parents:
diff changeset
384 if (!priv->ptt_cache[pagenum])
34532db868ba Teletext support.
voroshil
parents:
diff changeset
385 return -1;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
386 else
34532db868ba Teletext support.
voroshil
parents:
diff changeset
387 return priv->ptt_cache[pagenum]->subpagenum;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
388 }
34532db868ba Teletext support.
voroshil
parents:
diff changeset
389
34532db868ba Teletext support.
voroshil
parents:
diff changeset
390 /**
34532db868ba Teletext support.
voroshil
parents:
diff changeset
391 * \brief get page from cache by it page and subpage number
34532db868ba Teletext support.
voroshil
parents:
diff changeset
392 * \param priv private data structure
34532db868ba Teletext support.
voroshil
parents:
diff changeset
393 * \param pagenum page number
34532db868ba Teletext support.
voroshil
parents:
diff changeset
394 * \param subpagenum subpage number
34532db868ba Teletext support.
voroshil
parents:
diff changeset
395 *
34532db868ba Teletext support.
voroshil
parents:
diff changeset
396 * \return pointer to tt_page structure if requested page is found
34532db868ba Teletext support.
voroshil
parents:
diff changeset
397 * and NULL otherwise
34532db868ba Teletext support.
voroshil
parents:
diff changeset
398 */
34532db868ba Teletext support.
voroshil
parents:
diff changeset
399 static inline tt_page* get_from_cache(priv_vbi_t* priv, int pagenum,int subpagenum){
34532db868ba Teletext support.
voroshil
parents:
diff changeset
400 tt_page* tp=priv->ptt_cache[pagenum];
34532db868ba Teletext support.
voroshil
parents:
diff changeset
401
34532db868ba Teletext support.
voroshil
parents:
diff changeset
402 while(tp && tp->subpagenum!=subpagenum)
34532db868ba Teletext support.
voroshil
parents:
diff changeset
403 tp=tp->next_subpage;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
404 return tp;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
405 }
34532db868ba Teletext support.
voroshil
parents:
diff changeset
406
34532db868ba Teletext support.
voroshil
parents:
diff changeset
407 /**
34532db868ba Teletext support.
voroshil
parents:
diff changeset
408 * \brief clears cache
34532db868ba Teletext support.
voroshil
parents:
diff changeset
409 * \param priv private data structure
34532db868ba Teletext support.
voroshil
parents:
diff changeset
410 *
34532db868ba Teletext support.
voroshil
parents:
diff changeset
411 * Deletes all tt_page structures from cache and frees allocated memory.
34532db868ba Teletext support.
voroshil
parents:
diff changeset
412 * Only zero-filled array of pointers remains in memory
34532db868ba Teletext support.
voroshil
parents:
diff changeset
413 */
34532db868ba Teletext support.
voroshil
parents:
diff changeset
414 static void clear_cache(priv_vbi_t* priv){
34532db868ba Teletext support.
voroshil
parents:
diff changeset
415 int i;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
416 tt_page* tp;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
417 for(i=0;i<VBI_MAX_PAGES;i++){
34532db868ba Teletext support.
voroshil
parents:
diff changeset
418 while(priv->ptt_cache[i]){
34532db868ba Teletext support.
voroshil
parents:
diff changeset
419 tp=priv->ptt_cache[i];
34532db868ba Teletext support.
voroshil
parents:
diff changeset
420 priv->ptt_cache[i]=tp->next_subpage;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
421 free(tp);
34532db868ba Teletext support.
voroshil
parents:
diff changeset
422 }
34532db868ba Teletext support.
voroshil
parents:
diff changeset
423 }
34532db868ba Teletext support.
voroshil
parents:
diff changeset
424 }
34532db868ba Teletext support.
voroshil
parents:
diff changeset
425
34532db868ba Teletext support.
voroshil
parents:
diff changeset
426 /**
34532db868ba Teletext support.
voroshil
parents:
diff changeset
427 * \brief cache initialization
34532db868ba Teletext support.
voroshil
parents:
diff changeset
428 * \param priv private data structure
34532db868ba Teletext support.
voroshil
parents:
diff changeset
429 *
34532db868ba Teletext support.
voroshil
parents:
diff changeset
430 * \note Has to be called before any cache operations!
34532db868ba Teletext support.
voroshil
parents:
diff changeset
431 */
34532db868ba Teletext support.
voroshil
parents:
diff changeset
432 static void init_cache(priv_vbi_t* priv){
34532db868ba Teletext support.
voroshil
parents:
diff changeset
433 priv->ptt_cache=calloc(VBI_MAX_PAGES,sizeof(tt_page*));
34532db868ba Teletext support.
voroshil
parents:
diff changeset
434 }
34532db868ba Teletext support.
voroshil
parents:
diff changeset
435
34532db868ba Teletext support.
voroshil
parents:
diff changeset
436 /**
34532db868ba Teletext support.
voroshil
parents:
diff changeset
437 * \brief destroys cache
34532db868ba Teletext support.
voroshil
parents:
diff changeset
438 * \param priv private data structure
34532db868ba Teletext support.
voroshil
parents:
diff changeset
439 *
34532db868ba Teletext support.
voroshil
parents:
diff changeset
440 * Frees all memory allocated for cache (including array of pointers).
34532db868ba Teletext support.
voroshil
parents:
diff changeset
441 * It is safe to call this routine multiple times
34532db868ba Teletext support.
voroshil
parents:
diff changeset
442 */
34532db868ba Teletext support.
voroshil
parents:
diff changeset
443 static void destroy_cache(priv_vbi_t* priv){
34532db868ba Teletext support.
voroshil
parents:
diff changeset
444 if(priv->ptt_cache){
34532db868ba Teletext support.
voroshil
parents:
diff changeset
445 clear_cache(priv);
34532db868ba Teletext support.
voroshil
parents:
diff changeset
446 free(priv->ptt_cache);
34532db868ba Teletext support.
voroshil
parents:
diff changeset
447 priv->ptt_cache=NULL;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
448 }
34532db868ba Teletext support.
voroshil
parents:
diff changeset
449 }
34532db868ba Teletext support.
voroshil
parents:
diff changeset
450
34532db868ba Teletext support.
voroshil
parents:
diff changeset
451 /*
34532db868ba Teletext support.
voroshil
parents:
diff changeset
452 ------------------------------------------------------------------
34532db868ba Teletext support.
voroshil
parents:
diff changeset
453 Decoder stuff
34532db868ba Teletext support.
voroshil
parents:
diff changeset
454 ------------------------------------------------------------------
34532db868ba Teletext support.
voroshil
parents:
diff changeset
455 */
34532db868ba Teletext support.
voroshil
parents:
diff changeset
456 /**
34532db868ba Teletext support.
voroshil
parents:
diff changeset
457 * \brief converts raw teletext page into useful format (1st rendering stage)
34532db868ba Teletext support.
voroshil
parents:
diff changeset
458 * \param pg page to decode
34532db868ba Teletext support.
voroshil
parents:
diff changeset
459 *
34532db868ba Teletext support.
voroshil
parents:
diff changeset
460 * Routine fills tt_char structure of each teletext_page character with proper
34532db868ba Teletext support.
voroshil
parents:
diff changeset
461 * info about foreground and background colors, character
34532db868ba Teletext support.
voroshil
parents:
diff changeset
462 * type (graphics/control/text).
34532db868ba Teletext support.
voroshil
parents:
diff changeset
463 */
34532db868ba Teletext support.
voroshil
parents:
diff changeset
464 static void decode_page(tt_char* p,int lang,unsigned char* raw)
34532db868ba Teletext support.
voroshil
parents:
diff changeset
465 {
34532db868ba Teletext support.
voroshil
parents:
diff changeset
466 int c,gfx=0,lat=0;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
467 int i=0;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
468 int fg_color=0;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
469 int bg_color=0;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
470 int row,col;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
471 int separated=0;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
472
34532db868ba Teletext support.
voroshil
parents:
diff changeset
473 for(row=0;row<VBI_ROWS;row++) {
34532db868ba Teletext support.
voroshil
parents:
diff changeset
474 lat=(lang==0);
34532db868ba Teletext support.
voroshil
parents:
diff changeset
475 gfx=0;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
476 fg_color=7;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
477 bg_color=0;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
478 separated=0;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
479 for(col=0;col<VBI_COLUMNS;col++){
34532db868ba Teletext support.
voroshil
parents:
diff changeset
480 i=row*VBI_COLUMNS+col;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
481 c=raw[i];
34532db868ba Teletext support.
voroshil
parents:
diff changeset
482 p[i].raw=c;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
483 if(c&0x80){ //damaged char
34532db868ba Teletext support.
voroshil
parents:
diff changeset
484 p[i]=tt_error;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
485 continue;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
486 }
34532db868ba Teletext support.
voroshil
parents:
diff changeset
487 p[i].gfx=gfx?(separated?2:1):0;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
488 p[i].lng=lat?0:lang;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
489 p[i].ctl=(c&0x60)==0?1:0;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
490 p[i].fg=fg_color;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
491 p[i].bg=bg_color;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
492
34532db868ba Teletext support.
voroshil
parents:
diff changeset
493 if ((c&0x60)==0){ //control chars
34532db868ba Teletext support.
voroshil
parents:
diff changeset
494 if(c>=0x08 && c<=0x0f){
34532db868ba Teletext support.
voroshil
parents:
diff changeset
495 }else if (c<=0x17){ //colors
34532db868ba Teletext support.
voroshil
parents:
diff changeset
496 fg_color=c&0x0f;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
497 gfx=c>>4;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
498 }else if (c<=0x18){
34532db868ba Teletext support.
voroshil
parents:
diff changeset
499 }else if (c<=0x1a){ //Contiguous/Separated gfx
34532db868ba Teletext support.
voroshil
parents:
diff changeset
500 separated=!(c&1);
34532db868ba Teletext support.
voroshil
parents:
diff changeset
501 }else if (c<=0x1b){
34532db868ba Teletext support.
voroshil
parents:
diff changeset
502 lat=!lat;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
503 }else if (c<=0x1d){
34532db868ba Teletext support.
voroshil
parents:
diff changeset
504 bg_color=(c&1)?fg_color:0;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
505 p[i].bg=bg_color;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
506 }
34532db868ba Teletext support.
voroshil
parents:
diff changeset
507 p[i].ctl=1;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
508 p[i].unicode=p[i].gfx?0:' ';
34532db868ba Teletext support.
voroshil
parents:
diff changeset
509 continue;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
510 }
34532db868ba Teletext support.
voroshil
parents:
diff changeset
511
34532db868ba Teletext support.
voroshil
parents:
diff changeset
512 if(gfx){
34532db868ba Teletext support.
voroshil
parents:
diff changeset
513 p[i].unicode=c-0x20;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
514 if (p[i].unicode>0x3f) p[i].unicode-=0x20;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
515 }else
34532db868ba Teletext support.
voroshil
parents:
diff changeset
516 p[i].unicode=conv2uni(c,lang2id(p[i].lng));
34532db868ba Teletext support.
voroshil
parents:
diff changeset
517
34532db868ba Teletext support.
voroshil
parents:
diff changeset
518 p[i].fg=fg_color;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
519 p[i].bg=bg_color;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
520 }
34532db868ba Teletext support.
voroshil
parents:
diff changeset
521 }
34532db868ba Teletext support.
voroshil
parents:
diff changeset
522 }
34532db868ba Teletext support.
voroshil
parents:
diff changeset
523
34532db868ba Teletext support.
voroshil
parents:
diff changeset
524 /**
34532db868ba Teletext support.
voroshil
parents:
diff changeset
525 * \brief prepares current page for displaying
34532db868ba Teletext support.
voroshil
parents:
diff changeset
526 * \param priv_vbi private data structure
34532db868ba Teletext support.
voroshil
parents:
diff changeset
527 *
34532db868ba Teletext support.
voroshil
parents:
diff changeset
528 * Routine adds some useful info (time and page number of page, grabbed by
34532db868ba Teletext support.
voroshil
parents:
diff changeset
529 * background thread to top line of current page). Displays "No teletext"
34532db868ba Teletext support.
voroshil
parents:
diff changeset
530 * string if no vbi data available.
34532db868ba Teletext support.
voroshil
parents:
diff changeset
531 */
23908
39b21ffcee44 Subtraction should be done after & operation.
voroshil
parents: 23907
diff changeset
532 #define PRINT_HEX(dp,i,h) dp[i].unicode=((h)&0xf)>9?'A'+((h)&0xf)-10:'0'+((h)&0xf)
23899
34532db868ba Teletext support.
voroshil
parents:
diff changeset
533 static void prepare_visible_page(priv_vbi_t* priv){
34532db868ba Teletext support.
voroshil
parents:
diff changeset
534 tt_page *pg,*curr_pg;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
535 unsigned char *p;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
536 int i;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
537
34532db868ba Teletext support.
voroshil
parents:
diff changeset
538 pthread_mutex_lock(&(priv->buffer_mutex));
34532db868ba Teletext support.
voroshil
parents:
diff changeset
539 mp_msg(MSGT_TV,MSGL_DBG3,"tvi_vbi: prepare_visible_page pg:0x%x, sub:0x%x\n",
34532db868ba Teletext support.
voroshil
parents:
diff changeset
540 priv->pagenum,priv->subpagenum);
34532db868ba Teletext support.
voroshil
parents:
diff changeset
541 if(priv->subpagenum==-1) //no page yet
34532db868ba Teletext support.
voroshil
parents:
diff changeset
542 priv->subpagenum=get_subpagenum_from_cache(priv,priv->pagenum);
34532db868ba Teletext support.
voroshil
parents:
diff changeset
543
34532db868ba Teletext support.
voroshil
parents:
diff changeset
544 pg=get_from_cache(priv,priv->pagenum,priv->subpagenum);
34532db868ba Teletext support.
voroshil
parents:
diff changeset
545 mp_dbg(MSGT_TV,MSGL_DBG3,"tvi_vbi: prepare_vibible_page2 pg:0x%x, sub:0x%x\n",
34532db868ba Teletext support.
voroshil
parents:
diff changeset
546 priv->pagenum,priv->subpagenum);
34532db868ba Teletext support.
voroshil
parents:
diff changeset
547
34532db868ba Teletext support.
voroshil
parents:
diff changeset
548 curr_pg=get_from_cache(priv,priv->curr_pagenum,
34532db868ba Teletext support.
voroshil
parents:
diff changeset
549 get_subpagenum_from_cache(priv,priv->curr_pagenum));
34532db868ba Teletext support.
voroshil
parents:
diff changeset
550 if (!pg && !curr_pg){
34532db868ba Teletext support.
voroshil
parents:
diff changeset
551 p=MSGTR_TV_NoTeletext;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
552 for(i=0;i<VBI_COLUMNS && *p;i++){
34532db868ba Teletext support.
voroshil
parents:
diff changeset
553 GET_UTF8(priv->display_page[i].unicode,*p++,break;);
34532db868ba Teletext support.
voroshil
parents:
diff changeset
554 }
34532db868ba Teletext support.
voroshil
parents:
diff changeset
555 for(;i<VBI_ROWS*VBI_COLUMNS;i++)
34532db868ba Teletext support.
voroshil
parents:
diff changeset
556 priv->display_page[i]=tt_space;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
557 pthread_mutex_unlock(&(priv->buffer_mutex));
34532db868ba Teletext support.
voroshil
parents:
diff changeset
558 return;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
559 }
34532db868ba Teletext support.
voroshil
parents:
diff changeset
560
34532db868ba Teletext support.
voroshil
parents:
diff changeset
561 if (!pg || !pg->active){
34532db868ba Teletext support.
voroshil
parents:
diff changeset
562 for(i=0;i<VBI_ROWS*VBI_COLUMNS;i++){
34532db868ba Teletext support.
voroshil
parents:
diff changeset
563 priv->display_page[i]=tt_space;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
564 }
34532db868ba Teletext support.
voroshil
parents:
diff changeset
565 }else{
34532db868ba Teletext support.
voroshil
parents:
diff changeset
566 decode_page(priv->display_page,pg->lang,pg->raw);
34532db868ba Teletext support.
voroshil
parents:
diff changeset
567 mp_msg(MSGT_TV,MSGL_DBG3,"page #%x was decoded!\n",pg->pagenum);
34532db868ba Teletext support.
voroshil
parents:
diff changeset
568 }
34532db868ba Teletext support.
voroshil
parents:
diff changeset
569
34532db868ba Teletext support.
voroshil
parents:
diff changeset
570 PRINT_HEX(priv->display_page,0,(priv->curr_pagenum&0x700)?priv->curr_pagenum>>8:8);
34532db868ba Teletext support.
voroshil
parents:
diff changeset
571 PRINT_HEX(priv->display_page,1,priv->curr_pagenum>>4);
34532db868ba Teletext support.
voroshil
parents:
diff changeset
572 PRINT_HEX(priv->display_page,2,priv->curr_pagenum);
34532db868ba Teletext support.
voroshil
parents:
diff changeset
573 priv->display_page[3].unicode=' ';
34532db868ba Teletext support.
voroshil
parents:
diff changeset
574 priv->display_page[4].unicode=' ';
34532db868ba Teletext support.
voroshil
parents:
diff changeset
575 switch(priv->pagenumdec>>12){
34532db868ba Teletext support.
voroshil
parents:
diff changeset
576 case 1:
34532db868ba Teletext support.
voroshil
parents:
diff changeset
577 priv->display_page[5].unicode='_';
34532db868ba Teletext support.
voroshil
parents:
diff changeset
578 priv->display_page[6].unicode='_';
34532db868ba Teletext support.
voroshil
parents:
diff changeset
579 PRINT_HEX(priv->display_page,7,priv->pagenumdec);
34532db868ba Teletext support.
voroshil
parents:
diff changeset
580 break;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
581 case 2:
34532db868ba Teletext support.
voroshil
parents:
diff changeset
582 priv->display_page[5].unicode='_';
34532db868ba Teletext support.
voroshil
parents:
diff changeset
583 PRINT_HEX(priv->display_page,6,priv->pagenumdec>>4);
34532db868ba Teletext support.
voroshil
parents:
diff changeset
584 PRINT_HEX(priv->display_page,7,priv->pagenumdec);
34532db868ba Teletext support.
voroshil
parents:
diff changeset
585 break;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
586 default:
34532db868ba Teletext support.
voroshil
parents:
diff changeset
587 PRINT_HEX(priv->display_page,5,(priv->pagenum&0x700)?priv->pagenum>>8:8);
34532db868ba Teletext support.
voroshil
parents:
diff changeset
588 PRINT_HEX(priv->display_page,6,priv->pagenum>>4);
34532db868ba Teletext support.
voroshil
parents:
diff changeset
589 PRINT_HEX(priv->display_page,7,priv->pagenum);
34532db868ba Teletext support.
voroshil
parents:
diff changeset
590 }
34532db868ba Teletext support.
voroshil
parents:
diff changeset
591 if(priv->subpagenum!=-1){
34532db868ba Teletext support.
voroshil
parents:
diff changeset
592 priv->display_page[8].unicode='.';
34532db868ba Teletext support.
voroshil
parents:
diff changeset
593 PRINT_HEX(priv->display_page,9,priv->subpagenum>>4);
34532db868ba Teletext support.
voroshil
parents:
diff changeset
594 PRINT_HEX(priv->display_page,10,priv->subpagenum);
34532db868ba Teletext support.
voroshil
parents:
diff changeset
595 }else{
34532db868ba Teletext support.
voroshil
parents:
diff changeset
596 priv->display_page[8].unicode=' ';
34532db868ba Teletext support.
voroshil
parents:
diff changeset
597 priv->display_page[9].unicode=' ';
34532db868ba Teletext support.
voroshil
parents:
diff changeset
598 priv->display_page[10].unicode=' ';
34532db868ba Teletext support.
voroshil
parents:
diff changeset
599 }
34532db868ba Teletext support.
voroshil
parents:
diff changeset
600 priv->display_page[11].unicode=' ';
34532db868ba Teletext support.
voroshil
parents:
diff changeset
601 for(i=VBI_TIME_LINEPOS;i<VBI_COLUMNS;i++){
34532db868ba Teletext support.
voroshil
parents:
diff changeset
602 priv->display_page[i].unicode=curr_pg->raw[i];
34532db868ba Teletext support.
voroshil
parents:
diff changeset
603 }
34532db868ba Teletext support.
voroshil
parents:
diff changeset
604 pthread_mutex_unlock(&(priv->buffer_mutex));
34532db868ba Teletext support.
voroshil
parents:
diff changeset
605 }
34532db868ba Teletext support.
voroshil
parents:
diff changeset
606 /*
34532db868ba Teletext support.
voroshil
parents:
diff changeset
607 ------------------------------------------------------------------
34532db868ba Teletext support.
voroshil
parents:
diff changeset
608 Renderer stuff
34532db868ba Teletext support.
voroshil
parents:
diff changeset
609 ------------------------------------------------------------------
34532db868ba Teletext support.
voroshil
parents:
diff changeset
610 */
34532db868ba Teletext support.
voroshil
parents:
diff changeset
611 #ifdef DEBUG_DUMP
34532db868ba Teletext support.
voroshil
parents:
diff changeset
612 /**
34532db868ba Teletext support.
voroshil
parents:
diff changeset
613 * \brief renders teletext page into given file
34532db868ba Teletext support.
voroshil
parents:
diff changeset
614 * \param pt page to render
34532db868ba Teletext support.
voroshil
parents:
diff changeset
615 * \param f opened file descriptor
34532db868ba Teletext support.
voroshil
parents:
diff changeset
616 * \param pagenum which page to render
34532db868ba Teletext support.
voroshil
parents:
diff changeset
617 * \param colored use colors not implementede yet)
34532db868ba Teletext support.
voroshil
parents:
diff changeset
618 *
34532db868ba Teletext support.
voroshil
parents:
diff changeset
619 * Text will be UTF8 encoded
34532db868ba Teletext support.
voroshil
parents:
diff changeset
620 */
34532db868ba Teletext support.
voroshil
parents:
diff changeset
621 static void render2text(tt_page* pt,FILE* f,int colored){
34532db868ba Teletext support.
voroshil
parents:
diff changeset
622 int i,j;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
623 unsigned int u;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
624 unsigned char buf[8];
34532db868ba Teletext support.
voroshil
parents:
diff changeset
625 unsigned char tmp;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
626 int pos;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
627 tt_char dp[VBI_ROWS*VBI_COLUMNS];
34532db868ba Teletext support.
voroshil
parents:
diff changeset
628 int color=0;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
629 int bkg=0;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
630 int c1,b1;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
631 if(!pt)
34532db868ba Teletext support.
voroshil
parents:
diff changeset
632 return;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
633 fprintf(f,"+========================================+\n");
34532db868ba Teletext support.
voroshil
parents:
diff changeset
634 fprintf(f,"| lang:%d pagenum:0x%x subpagenum:%d flags:0x%x|\n",
34532db868ba Teletext support.
voroshil
parents:
diff changeset
635 pt->lang,
34532db868ba Teletext support.
voroshil
parents:
diff changeset
636 pt->pagenum,
34532db868ba Teletext support.
voroshil
parents:
diff changeset
637 pt->subpagenum,
34532db868ba Teletext support.
voroshil
parents:
diff changeset
638 0);
34532db868ba Teletext support.
voroshil
parents:
diff changeset
639 fprintf(f,"+----------------------------------------+\n");
34532db868ba Teletext support.
voroshil
parents:
diff changeset
640
34532db868ba Teletext support.
voroshil
parents:
diff changeset
641 decode_page(dp,pt->lang,pt->raw);
34532db868ba Teletext support.
voroshil
parents:
diff changeset
642 for(i=0;i<VBI_ROWS;i++){
34532db868ba Teletext support.
voroshil
parents:
diff changeset
643 fprintf(f,"|");
34532db868ba Teletext support.
voroshil
parents:
diff changeset
644 if(colored) fprintf(f,"\033[40m");
34532db868ba Teletext support.
voroshil
parents:
diff changeset
645 for(j=0;j<VBI_COLUMNS;j++)
34532db868ba Teletext support.
voroshil
parents:
diff changeset
646 {
34532db868ba Teletext support.
voroshil
parents:
diff changeset
647 u=dp[i*VBI_COLUMNS+j].unicode;
23928
c6becdb359d7 remove GNUism (case range)
ivo
parents: 23908
diff changeset
648 if(dp[i*VBI_COLUMNS+j].fg <= 7)
23899
34532db868ba Teletext support.
voroshil
parents:
diff changeset
649 c1=30+dp[i*VBI_COLUMNS+j].fg;
23928
c6becdb359d7 remove GNUism (case range)
ivo
parents: 23908
diff changeset
650 else
23899
34532db868ba Teletext support.
voroshil
parents:
diff changeset
651 c1=38;
23928
c6becdb359d7 remove GNUism (case range)
ivo
parents: 23908
diff changeset
652 if(dp[i*VBI_COLUMNS+j].bg <= 7)
23899
34532db868ba Teletext support.
voroshil
parents:
diff changeset
653 b1=40+dp[i*VBI_COLUMNS+j].bg;
23928
c6becdb359d7 remove GNUism (case range)
ivo
parents: 23908
diff changeset
654 else
23899
34532db868ba Teletext support.
voroshil
parents:
diff changeset
655 b1=40;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
656 if (b1!=bkg && colored){
34532db868ba Teletext support.
voroshil
parents:
diff changeset
657 fprintf(f,"\033[%dm",b1);
34532db868ba Teletext support.
voroshil
parents:
diff changeset
658 bkg=b1;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
659 }
34532db868ba Teletext support.
voroshil
parents:
diff changeset
660 if(c1!=color && colored){
34532db868ba Teletext support.
voroshil
parents:
diff changeset
661 fprintf(f,"\033[%dm",c1);
34532db868ba Teletext support.
voroshil
parents:
diff changeset
662 color=c1;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
663 }
34532db868ba Teletext support.
voroshil
parents:
diff changeset
664 if(dp[i*VBI_COLUMNS+j].gfx){
34532db868ba Teletext support.
voroshil
parents:
diff changeset
665 fprintf(f,"*");
34532db868ba Teletext support.
voroshil
parents:
diff changeset
666 }else{
34532db868ba Teletext support.
voroshil
parents:
diff changeset
667 pos=0;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
668 PUT_UTF8(u,tmp,if(pos<7) buf[pos++]=tmp;);
34532db868ba Teletext support.
voroshil
parents:
diff changeset
669 buf[pos]='\0';
34532db868ba Teletext support.
voroshil
parents:
diff changeset
670 fprintf(f,"%s",buf);
34532db868ba Teletext support.
voroshil
parents:
diff changeset
671 }
34532db868ba Teletext support.
voroshil
parents:
diff changeset
672 }
34532db868ba Teletext support.
voroshil
parents:
diff changeset
673
34532db868ba Teletext support.
voroshil
parents:
diff changeset
674 if (colored) fprintf(f,"\033[0m");
34532db868ba Teletext support.
voroshil
parents:
diff changeset
675 color=-1;bkg=-1;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
676 fprintf(f,"|\n");
34532db868ba Teletext support.
voroshil
parents:
diff changeset
677 }
34532db868ba Teletext support.
voroshil
parents:
diff changeset
678 #if 1
34532db868ba Teletext support.
voroshil
parents:
diff changeset
679 //for debug
34532db868ba Teletext support.
voroshil
parents:
diff changeset
680 fprintf(f,"+====================raw=================+\n");
34532db868ba Teletext support.
voroshil
parents:
diff changeset
681 for(i=0;i<VBI_ROWS;i++){
34532db868ba Teletext support.
voroshil
parents:
diff changeset
682 for(j=0;j<VBI_COLUMNS;j++)
34532db868ba Teletext support.
voroshil
parents:
diff changeset
683 fprintf(f,"%02x ",dp[i*VBI_COLUMNS+j].raw);
34532db868ba Teletext support.
voroshil
parents:
diff changeset
684 fprintf(f,"\n");
34532db868ba Teletext support.
voroshil
parents:
diff changeset
685 }
34532db868ba Teletext support.
voroshil
parents:
diff changeset
686 fprintf(f,"+====================lng=================+\n");
34532db868ba Teletext support.
voroshil
parents:
diff changeset
687 for(i=0;i<VBI_ROWS;i++){
34532db868ba Teletext support.
voroshil
parents:
diff changeset
688 for(j=0;j<VBI_COLUMNS;j++)
34532db868ba Teletext support.
voroshil
parents:
diff changeset
689 fprintf(f,"%02x ",dp[i*VBI_COLUMNS+j].lng);
34532db868ba Teletext support.
voroshil
parents:
diff changeset
690 fprintf(f,"\n");
34532db868ba Teletext support.
voroshil
parents:
diff changeset
691 }
34532db868ba Teletext support.
voroshil
parents:
diff changeset
692 #endif
34532db868ba Teletext support.
voroshil
parents:
diff changeset
693 fprintf(f,"+========================================+\n");
34532db868ba Teletext support.
voroshil
parents:
diff changeset
694 }
34532db868ba Teletext support.
voroshil
parents:
diff changeset
695
34532db868ba Teletext support.
voroshil
parents:
diff changeset
696 /**
34532db868ba Teletext support.
voroshil
parents:
diff changeset
697 * \brief dump page into pgXXX.txt file in vurrent directory
34532db868ba Teletext support.
voroshil
parents:
diff changeset
698 * \param pt page to dump
34532db868ba Teletext support.
voroshil
parents:
diff changeset
699 *
34532db868ba Teletext support.
voroshil
parents:
diff changeset
700 * \note XXX in filename is page number
34532db868ba Teletext support.
voroshil
parents:
diff changeset
701 * \note use only for debug purposes
34532db868ba Teletext support.
voroshil
parents:
diff changeset
702 */
34532db868ba Teletext support.
voroshil
parents:
diff changeset
703 static void dump_page(tt_page* pt)
34532db868ba Teletext support.
voroshil
parents:
diff changeset
704 {
34532db868ba Teletext support.
voroshil
parents:
diff changeset
705 FILE*f;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
706 char name[100];
34532db868ba Teletext support.
voroshil
parents:
diff changeset
707 snprintf(name,99,"pg%x.txt",pt->pagenum);
34532db868ba Teletext support.
voroshil
parents:
diff changeset
708 f=fopen(name,"wb");
34532db868ba Teletext support.
voroshil
parents:
diff changeset
709 render2text(pt,f,1);
34532db868ba Teletext support.
voroshil
parents:
diff changeset
710 fclose(f);
34532db868ba Teletext support.
voroshil
parents:
diff changeset
711 }
34532db868ba Teletext support.
voroshil
parents:
diff changeset
712 #endif //DEBUG_DUMP
34532db868ba Teletext support.
voroshil
parents:
diff changeset
713
34532db868ba Teletext support.
voroshil
parents:
diff changeset
714
34532db868ba Teletext support.
voroshil
parents:
diff changeset
715 /**
34532db868ba Teletext support.
voroshil
parents:
diff changeset
716 * \brief checks whether page is ready and copies it into cache array if so
34532db868ba Teletext support.
voroshil
parents:
diff changeset
717 * \param priv private data structure
34532db868ba Teletext support.
voroshil
parents:
diff changeset
718 * \param magAddr page's magazine address (0-7)
34532db868ba Teletext support.
voroshil
parents:
diff changeset
719 *
34532db868ba Teletext support.
voroshil
parents:
diff changeset
720 * Routine also calls decode_page to perform 1st stage of rendering
34532db868ba Teletext support.
voroshil
parents:
diff changeset
721 */
34532db868ba Teletext support.
voroshil
parents:
diff changeset
722 static void store_in_cache(priv_vbi_t* priv, int magAddr, int line){
34532db868ba Teletext support.
voroshil
parents:
diff changeset
723 mp_msg(MSGT_TV,MSGL_DBG2,"store_in_cache(%d): pagenum:%x\n",
34532db868ba Teletext support.
voroshil
parents:
diff changeset
724 priv->mag[magAddr].order,
34532db868ba Teletext support.
voroshil
parents:
diff changeset
725 priv->mag[magAddr].pt->pagenum);
34532db868ba Teletext support.
voroshil
parents:
diff changeset
726
34532db868ba Teletext support.
voroshil
parents:
diff changeset
727 put_to_cache(priv,priv->mag[magAddr].pt,line);
34532db868ba Teletext support.
voroshil
parents:
diff changeset
728 priv->curr_pagenum=priv->mag[magAddr].pt->pagenum;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
729
34532db868ba Teletext support.
voroshil
parents:
diff changeset
730 #ifdef DEBUG_DUMP
34532db868ba Teletext support.
voroshil
parents:
diff changeset
731 dump_page(get_from_cache(priv,
34532db868ba Teletext support.
voroshil
parents:
diff changeset
732 priv->mag[magAddr].pt->pagenum,
34532db868ba Teletext support.
voroshil
parents:
diff changeset
733 priv->mag[magAddr].pt->subpagenum));
34532db868ba Teletext support.
voroshil
parents:
diff changeset
734 #endif
34532db868ba Teletext support.
voroshil
parents:
diff changeset
735 }
34532db868ba Teletext support.
voroshil
parents:
diff changeset
736
34532db868ba Teletext support.
voroshil
parents:
diff changeset
737
34532db868ba Teletext support.
voroshil
parents:
diff changeset
738 /*
34532db868ba Teletext support.
voroshil
parents:
diff changeset
739 ------------------------------------------------------------------
34532db868ba Teletext support.
voroshil
parents:
diff changeset
740 Grabber stuff
34532db868ba Teletext support.
voroshil
parents:
diff changeset
741 ------------------------------------------------------------------
34532db868ba Teletext support.
voroshil
parents:
diff changeset
742 */
34532db868ba Teletext support.
voroshil
parents:
diff changeset
743 #define PLL_SAMPLES 4
34532db868ba Teletext support.
voroshil
parents:
diff changeset
744 #define PLL_ERROR 4
34532db868ba Teletext support.
voroshil
parents:
diff changeset
745 #define PLL_ADJUST 4
34532db868ba Teletext support.
voroshil
parents:
diff changeset
746
34532db868ba Teletext support.
voroshil
parents:
diff changeset
747 /**
34532db868ba Teletext support.
voroshil
parents:
diff changeset
748 * \brief adjust current phase for better signal decoding
34532db868ba Teletext support.
voroshil
parents:
diff changeset
749 * \param n count of bytes processed (?)
34532db868ba Teletext support.
voroshil
parents:
diff changeset
750 * \param err count of error bytes (?)
34532db868ba Teletext support.
voroshil
parents:
diff changeset
751 *
34532db868ba Teletext support.
voroshil
parents:
diff changeset
752 * \remarks code was got from MythTV project
34532db868ba Teletext support.
voroshil
parents:
diff changeset
753 */
34532db868ba Teletext support.
voroshil
parents:
diff changeset
754 static void pll_add(priv_vbi_t* priv,int n,int err){
34532db868ba Teletext support.
voroshil
parents:
diff changeset
755 if(priv->pll_fixed)
34532db868ba Teletext support.
voroshil
parents:
diff changeset
756 return;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
757 if(err>PLL_ERROR*2/3)
34532db868ba Teletext support.
voroshil
parents:
diff changeset
758 err=PLL_ERROR*2/3;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
759 priv->pll_err+=err;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
760 priv->pll_cnt+=n;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
761 if(priv->pll_cnt<PLL_SAMPLES)
34532db868ba Teletext support.
voroshil
parents:
diff changeset
762 return;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
763 if(priv->pll_err>PLL_ERROR)
34532db868ba Teletext support.
voroshil
parents:
diff changeset
764 {
34532db868ba Teletext support.
voroshil
parents:
diff changeset
765 if(priv->pll_err>priv->pll_lerr)
34532db868ba Teletext support.
voroshil
parents:
diff changeset
766 priv->pll_dir= -priv->pll_dir;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
767 priv->pll_lerr=priv->pll_err;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
768 priv->pll_adj+=priv->pll_dir;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
769 if (priv->pll_adj<-PLL_ADJUST || priv->pll_adj>PLL_ADJUST)
34532db868ba Teletext support.
voroshil
parents:
diff changeset
770 {
34532db868ba Teletext support.
voroshil
parents:
diff changeset
771 priv->pll_adj=0;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
772 priv->pll_dir=-1;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
773 priv->pll_lerr=0;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
774 }
34532db868ba Teletext support.
voroshil
parents:
diff changeset
775 mp_msg(MSGT_TV,MSGL_DBG3,"vbi: pll_adj=%2d\n",priv->pll_adj);
34532db868ba Teletext support.
voroshil
parents:
diff changeset
776 }
34532db868ba Teletext support.
voroshil
parents:
diff changeset
777 priv->pll_cnt=0;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
778 priv->pll_err=0;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
779 }
34532db868ba Teletext support.
voroshil
parents:
diff changeset
780
34532db868ba Teletext support.
voroshil
parents:
diff changeset
781 /**
34532db868ba Teletext support.
voroshil
parents:
diff changeset
782 * \brief reset error correction
34532db868ba Teletext support.
voroshil
parents:
diff changeset
783 * \param priv private data structure
34532db868ba Teletext support.
voroshil
parents:
diff changeset
784 * \param fine_tune shift value for adjusting
34532db868ba Teletext support.
voroshil
parents:
diff changeset
785 *
34532db868ba Teletext support.
voroshil
parents:
diff changeset
786 * \remarks code was got from MythTV project
34532db868ba Teletext support.
voroshil
parents:
diff changeset
787 */
34532db868ba Teletext support.
voroshil
parents:
diff changeset
788 static void pll_reset(priv_vbi_t* priv,int fine_tune){
34532db868ba Teletext support.
voroshil
parents:
diff changeset
789 priv->pll_fixed=fine_tune >= -PLL_ADJUST && fine_tune <= PLL_ADJUST;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
790
34532db868ba Teletext support.
voroshil
parents:
diff changeset
791 priv->pll_err=0;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
792 priv->pll_lerr=0;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
793 priv->pll_cnt=0;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
794 priv->pll_dir=-1;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
795 priv->pll_adj=0;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
796 if(priv->pll_fixed)
34532db868ba Teletext support.
voroshil
parents:
diff changeset
797 priv->pll_adj=fine_tune;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
798 if(priv->pll_fixed)
34532db868ba Teletext support.
voroshil
parents:
diff changeset
799 mp_msg(MSGT_TV,MSGL_DBG3,"pll_reset (fixed@%2d)\n",priv->pll_adj);
34532db868ba Teletext support.
voroshil
parents:
diff changeset
800 else
34532db868ba Teletext support.
voroshil
parents:
diff changeset
801 mp_msg(MSGT_TV,MSGL_DBG3,"pll_reset (auto)\n");
34532db868ba Teletext support.
voroshil
parents:
diff changeset
802
34532db868ba Teletext support.
voroshil
parents:
diff changeset
803 }
34532db868ba Teletext support.
voroshil
parents:
diff changeset
804 /**
34532db868ba Teletext support.
voroshil
parents:
diff changeset
805 * \brief decode packet 0 (teletext page header)
34532db868ba Teletext support.
voroshil
parents:
diff changeset
806 * \param priv private data structure
34532db868ba Teletext support.
voroshil
parents:
diff changeset
807 * \param data raw teletext data (with not applied hamm correction yet)
34532db868ba Teletext support.
voroshil
parents:
diff changeset
808 * \param magAddr teletext page's magazine address
34532db868ba Teletext support.
voroshil
parents:
diff changeset
809 *
34532db868ba Teletext support.
voroshil
parents:
diff changeset
810 * \remarks
34532db868ba Teletext support.
voroshil
parents:
diff changeset
811 * data buffer was shifted by 6 and now contains:
34532db868ba Teletext support.
voroshil
parents:
diff changeset
812 * 0..1 page number
34532db868ba Teletext support.
voroshil
parents:
diff changeset
813 * 2..5 sub-code
34532db868ba Teletext support.
voroshil
parents:
diff changeset
814 * 6..7 control codes
34532db868ba Teletext support.
voroshil
parents:
diff changeset
815 * 8..39 display data
34532db868ba Teletext support.
voroshil
parents:
diff changeset
816 *
34532db868ba Teletext support.
voroshil
parents:
diff changeset
817 * only first 8 bytes protected by Hamm 8/4 code
34532db868ba Teletext support.
voroshil
parents:
diff changeset
818 */
34532db868ba Teletext support.
voroshil
parents:
diff changeset
819 static int decode_pkt0(priv_vbi_t* priv,unsigned char* data,int magAddr)
34532db868ba Teletext support.
voroshil
parents:
diff changeset
820 {
34532db868ba Teletext support.
voroshil
parents:
diff changeset
821 int d[8];
34532db868ba Teletext support.
voroshil
parents:
diff changeset
822 int i,err;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
823
34532db868ba Teletext support.
voroshil
parents:
diff changeset
824 if (magAddr<0 || magAddr>7)
34532db868ba Teletext support.
voroshil
parents:
diff changeset
825 return 0;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
826 for(i=0;i<8;i++){
34532db868ba Teletext support.
voroshil
parents:
diff changeset
827 d[i]= corrHamm48[ data[i] ];
34532db868ba Teletext support.
voroshil
parents:
diff changeset
828 if(d[i]&0x80){
34532db868ba Teletext support.
voroshil
parents:
diff changeset
829 pll_add(priv,2,4);
34532db868ba Teletext support.
voroshil
parents:
diff changeset
830
34532db868ba Teletext support.
voroshil
parents:
diff changeset
831 if(priv->mag[magAddr].pt)
34532db868ba Teletext support.
voroshil
parents:
diff changeset
832 free(priv->mag[magAddr].pt);
34532db868ba Teletext support.
voroshil
parents:
diff changeset
833 priv->mag[magAddr].pt=NULL;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
834 priv->mag[magAddr].order=0;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
835 return 0;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
836 }
34532db868ba Teletext support.
voroshil
parents:
diff changeset
837 }
34532db868ba Teletext support.
voroshil
parents:
diff changeset
838 if (!priv->mag[magAddr].pt)
34532db868ba Teletext support.
voroshil
parents:
diff changeset
839 priv->mag[magAddr].pt= malloc(sizeof(tt_page));
34532db868ba Teletext support.
voroshil
parents:
diff changeset
840
34532db868ba Teletext support.
voroshil
parents:
diff changeset
841 priv->mag[magAddr].lang= d[7] & 0x7;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
842 priv->mag[magAddr].pt->lang=priv->mag[magAddr].lang;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
843 priv->mag[magAddr].pt->subpagenum=(d[2]|(d[3]<<4)|(d[4]<<8)|(d[5]<<12))&0x3f7f;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
844 priv->mag[magAddr].pt->pagenum=(magAddr<<8) | d[0] | (d[1]<<4);
34532db868ba Teletext support.
voroshil
parents:
diff changeset
845 priv->mag[magAddr].pt->flags=( d[6] | (d[7]<<4));
34532db868ba Teletext support.
voroshil
parents:
diff changeset
846
34532db868ba Teletext support.
voroshil
parents:
diff changeset
847 memset(priv->mag[magAddr].pt->raw, 0x00, VBI_COLUMNS*VBI_ROWS);
34532db868ba Teletext support.
voroshil
parents:
diff changeset
848 priv->mag[magAddr].order=0;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
849
34532db868ba Teletext support.
voroshil
parents:
diff changeset
850 for(i=0;i<8;i++){
34532db868ba Teletext support.
voroshil
parents:
diff changeset
851 priv->mag[magAddr].pt->raw[i]=0x20;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
852 }
34532db868ba Teletext support.
voroshil
parents:
diff changeset
853 err=0;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
854 for(i=8; i<VBI_COLUMNS; i++){
34532db868ba Teletext support.
voroshil
parents:
diff changeset
855 data[i]= fixParity[data[i]];
34532db868ba Teletext support.
voroshil
parents:
diff changeset
856 priv->mag[magAddr].pt->raw[i]=data[i];
34532db868ba Teletext support.
voroshil
parents:
diff changeset
857 if(data[i]&0x80) //Error
34532db868ba Teletext support.
voroshil
parents:
diff changeset
858 err++;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
859 pll_add(priv,1,err);
34532db868ba Teletext support.
voroshil
parents:
diff changeset
860 }
34532db868ba Teletext support.
voroshil
parents:
diff changeset
861
34532db868ba Teletext support.
voroshil
parents:
diff changeset
862 store_in_cache(priv,magAddr,0);
34532db868ba Teletext support.
voroshil
parents:
diff changeset
863
34532db868ba Teletext support.
voroshil
parents:
diff changeset
864 return 1;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
865 }
34532db868ba Teletext support.
voroshil
parents:
diff changeset
866
34532db868ba Teletext support.
voroshil
parents:
diff changeset
867 /**
34532db868ba Teletext support.
voroshil
parents:
diff changeset
868 * \brief decode packets 1..24 (teletext page header)
34532db868ba Teletext support.
voroshil
parents:
diff changeset
869 * \param priv private data structure
34532db868ba Teletext support.
voroshil
parents:
diff changeset
870 * \param data raw teletext data
34532db868ba Teletext support.
voroshil
parents:
diff changeset
871 * \param magAddr teletext page's magazine address
34532db868ba Teletext support.
voroshil
parents:
diff changeset
872 * \param rowAddr teletext page's row number
34532db868ba Teletext support.
voroshil
parents:
diff changeset
873 *
34532db868ba Teletext support.
voroshil
parents:
diff changeset
874 * \remarks
34532db868ba Teletext support.
voroshil
parents:
diff changeset
875 * data buffer was shifted by 6 and now contains 40 bytes of display data:
34532db868ba Teletext support.
voroshil
parents:
diff changeset
876 * this type of packet is not proptected by Hamm 8/4 code
34532db868ba Teletext support.
voroshil
parents:
diff changeset
877 */
34532db868ba Teletext support.
voroshil
parents:
diff changeset
878 static void decode_pkt_page(priv_vbi_t* priv,unsigned char*data,int magAddr,int rowAddr){
34532db868ba Teletext support.
voroshil
parents:
diff changeset
879 int i,err;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
880 if (!priv->mag[magAddr].pt)
34532db868ba Teletext support.
voroshil
parents:
diff changeset
881 return;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
882
34532db868ba Teletext support.
voroshil
parents:
diff changeset
883 priv->mag[magAddr].order=rowAddr;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
884
34532db868ba Teletext support.
voroshil
parents:
diff changeset
885 err=0;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
886 for(i=0; i<VBI_COLUMNS; i++){
34532db868ba Teletext support.
voroshil
parents:
diff changeset
887 data[i]= fixParity[ data[i] ];
34532db868ba Teletext support.
voroshil
parents:
diff changeset
888 priv->mag[magAddr].pt->raw[i+rowAddr*VBI_COLUMNS]=data[i];
34532db868ba Teletext support.
voroshil
parents:
diff changeset
889 if( data[i]&0x80) //HammError
34532db868ba Teletext support.
voroshil
parents:
diff changeset
890 err++;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
891 }
34532db868ba Teletext support.
voroshil
parents:
diff changeset
892 pll_add(priv,1,err);
34532db868ba Teletext support.
voroshil
parents:
diff changeset
893
34532db868ba Teletext support.
voroshil
parents:
diff changeset
894 store_in_cache(priv,magAddr,rowAddr);
34532db868ba Teletext support.
voroshil
parents:
diff changeset
895 }
34532db868ba Teletext support.
voroshil
parents:
diff changeset
896
34532db868ba Teletext support.
voroshil
parents:
diff changeset
897 /**
34532db868ba Teletext support.
voroshil
parents:
diff changeset
898 * \brief decodes raw vbi data (signal amplitudes) into sequence of bytes
34532db868ba Teletext support.
voroshil
parents:
diff changeset
899 * \param priv private data structure
34532db868ba Teletext support.
voroshil
parents:
diff changeset
900 * \param buf raw vbi data (one line of frame)
34532db868ba Teletext support.
voroshil
parents:
diff changeset
901 * \param data output buffer for decoded bytes (at least 45 bytes long)
34532db868ba Teletext support.
voroshil
parents:
diff changeset
902 *
34532db868ba Teletext support.
voroshil
parents:
diff changeset
903 * Used XawTV's algorithm. Signal phase is calculated with help of starting clock
34532db868ba Teletext support.
voroshil
parents:
diff changeset
904 * run-in sequence (min/max values and bit distance values are calculated)
34532db868ba Teletext support.
voroshil
parents:
diff changeset
905 */
34532db868ba Teletext support.
voroshil
parents:
diff changeset
906 static int decode_raw_line_runin(priv_vbi_t* priv,unsigned char* buf,unsigned char* data){
34532db868ba Teletext support.
voroshil
parents:
diff changeset
907 const int magic= 0x27; // reversed 1110010
34532db868ba Teletext support.
voroshil
parents:
diff changeset
908 int dt[256],hi[6],lo[6];
34532db868ba Teletext support.
voroshil
parents:
diff changeset
909 int i,x,r;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
910 int decoded;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
911 int sync;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
912 unsigned char min,max;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
913 int thr=0; //threshold
34532db868ba Teletext support.
voroshil
parents:
diff changeset
914
34532db868ba Teletext support.
voroshil
parents:
diff changeset
915 //stubs
34532db868ba Teletext support.
voroshil
parents:
diff changeset
916 int soc=0;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
917 int eoc=92;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
918
34532db868ba Teletext support.
voroshil
parents:
diff changeset
919 for(i=soc;i<eoc;i++)
34532db868ba Teletext support.
voroshil
parents:
diff changeset
920 dt[i]=buf[i+priv->bpb/ONE_FIXP]-buf[i]; // amplifies the edges best.
34532db868ba Teletext support.
voroshil
parents:
diff changeset
921 /* set barrier */
34532db868ba Teletext support.
voroshil
parents:
diff changeset
922 for (i=eoc; i<eoc+16; i+=2)
34532db868ba Teletext support.
voroshil
parents:
diff changeset
923 dt[i]=100, dt[i+1]=-100;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
924
34532db868ba Teletext support.
voroshil
parents:
diff changeset
925 /* find 6 rising and falling edges */
34532db868ba Teletext support.
voroshil
parents:
diff changeset
926 for (i=soc, x=0; x<6; ++x)
34532db868ba Teletext support.
voroshil
parents:
diff changeset
927 {
34532db868ba Teletext support.
voroshil
parents:
diff changeset
928 while (dt[i]<32)
34532db868ba Teletext support.
voroshil
parents:
diff changeset
929 i++;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
930 hi[x]=i;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
931 while (dt[i]>-32)
34532db868ba Teletext support.
voroshil
parents:
diff changeset
932 i++;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
933 lo[x]=i;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
934 }
34532db868ba Teletext support.
voroshil
parents:
diff changeset
935 if (i>=eoc)
34532db868ba Teletext support.
voroshil
parents:
diff changeset
936 {
34532db868ba Teletext support.
voroshil
parents:
diff changeset
937 return 0; // not enough periods found
34532db868ba Teletext support.
voroshil
parents:
diff changeset
938 }
34532db868ba Teletext support.
voroshil
parents:
diff changeset
939 i=hi[5]-hi[1]; // length of 4 periods (8 bits)
34532db868ba Teletext support.
voroshil
parents:
diff changeset
940 if (i<priv->bp8bl || i>priv->bp8bh)
34532db868ba Teletext support.
voroshil
parents:
diff changeset
941 {
34532db868ba Teletext support.
voroshil
parents:
diff changeset
942 mp_msg(MSGT_TV,MSGL_DBG3,"vbi: wrong freq %d (%d,%d)\n",
34532db868ba Teletext support.
voroshil
parents:
diff changeset
943 i,priv->bp8bl,priv->bp8bh);
34532db868ba Teletext support.
voroshil
parents:
diff changeset
944 return 0; // bad frequency
34532db868ba Teletext support.
voroshil
parents:
diff changeset
945 }
34532db868ba Teletext support.
voroshil
parents:
diff changeset
946 /* AGC and sync-reference */
34532db868ba Teletext support.
voroshil
parents:
diff changeset
947 min=255, max=0, sync=0;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
948 for (i=hi[4]; i<hi[5]; ++i)
34532db868ba Teletext support.
voroshil
parents:
diff changeset
949 if (buf[i]>max)
34532db868ba Teletext support.
voroshil
parents:
diff changeset
950 max=buf[i], sync=i;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
951 for (i=lo[4]; i<lo[5]; ++i)
34532db868ba Teletext support.
voroshil
parents:
diff changeset
952 if (buf[i]<min)
34532db868ba Teletext support.
voroshil
parents:
diff changeset
953 min=buf[i];
34532db868ba Teletext support.
voroshil
parents:
diff changeset
954 thr=(min+max)/2;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
955
34532db868ba Teletext support.
voroshil
parents:
diff changeset
956 buf+=sync;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
957 // searching for '11'
34532db868ba Teletext support.
voroshil
parents:
diff changeset
958 for(i=priv->pll_adj*priv->bpb/10;i<16*priv->bpb;i+=priv->bpb)
34532db868ba Teletext support.
voroshil
parents:
diff changeset
959 if(buf[FIXP2INT(i)]>thr && buf[FIXP2INT(i+priv->bpb)]>thr)
34532db868ba Teletext support.
voroshil
parents:
diff changeset
960 break;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
961 r=0;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
962 for(decoded=1; decoded<= (VBI_COLUMNS+3)<<3;decoded++){
34532db868ba Teletext support.
voroshil
parents:
diff changeset
963 r>>=1;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
964 if(buf[FIXP2INT(i)]>thr) r|=0x80;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
965 if(!(decoded & 0x07)){
34532db868ba Teletext support.
voroshil
parents:
diff changeset
966 data[(decoded>>3) - 1]=r;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
967 r=0;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
968 }
34532db868ba Teletext support.
voroshil
parents:
diff changeset
969 i+=priv->bpb;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
970 }
34532db868ba Teletext support.
voroshil
parents:
diff changeset
971 if(data[0]!=magic)
34532db868ba Teletext support.
voroshil
parents:
diff changeset
972 return 0; //magic not found
34532db868ba Teletext support.
voroshil
parents:
diff changeset
973
34532db868ba Teletext support.
voroshil
parents:
diff changeset
974 //stub
34532db868ba Teletext support.
voroshil
parents:
diff changeset
975 for(i=0;i<43;i++){
34532db868ba Teletext support.
voroshil
parents:
diff changeset
976 data[i]=data[i+1];
34532db868ba Teletext support.
voroshil
parents:
diff changeset
977 }
34532db868ba Teletext support.
voroshil
parents:
diff changeset
978 mp_msg(MSGT_TV,MSGL_DBG3,"thr:%d sync:%d ",thr,sync);
34532db868ba Teletext support.
voroshil
parents:
diff changeset
979
34532db868ba Teletext support.
voroshil
parents:
diff changeset
980 return 1;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
981 }
34532db868ba Teletext support.
voroshil
parents:
diff changeset
982
34532db868ba Teletext support.
voroshil
parents:
diff changeset
983 /**
34532db868ba Teletext support.
voroshil
parents:
diff changeset
984 * \brief decodes raw vbi data (signal amplitudes) into sequence of bytes
34532db868ba Teletext support.
voroshil
parents:
diff changeset
985 * \param priv private data structure
34532db868ba Teletext support.
voroshil
parents:
diff changeset
986 * \param buf raw vbi data (one line of frame)
34532db868ba Teletext support.
voroshil
parents:
diff changeset
987 * \param data output buffer for decoded bytes (at least 45 bytes long)
34532db868ba Teletext support.
voroshil
parents:
diff changeset
988 *
34532db868ba Teletext support.
voroshil
parents:
diff changeset
989 * Used Michael Niedermayer's algorithm.
34532db868ba Teletext support.
voroshil
parents:
diff changeset
990 * Signal phase is calculated using correlation between given samples data and
34532db868ba Teletext support.
voroshil
parents:
diff changeset
991 * pure sine
34532db868ba Teletext support.
voroshil
parents:
diff changeset
992 */
34532db868ba Teletext support.
voroshil
parents:
diff changeset
993 static int decode_raw_line_sine(priv_vbi_t* priv,unsigned char* buf,unsigned char* data){
34532db868ba Teletext support.
voroshil
parents:
diff changeset
994 int i,x,r,amp,xFixp;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
995 int avg=0;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
996 double sin_sum=0, cos_sum=0;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
997
34532db868ba Teletext support.
voroshil
parents:
diff changeset
998 for(x=0; x< FIXP2INT(10*priv->bpb); x++)
34532db868ba Teletext support.
voroshil
parents:
diff changeset
999 avg+=buf[x];
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1000
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1001 avg/=FIXP2INT(10*priv->bpb);
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1002
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1003 for(x=0; x<12; x++){
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1004 amp= buf[x<<1];
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1005 sin_sum+= si[x]*(amp-avg);
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1006 cos_sum+= co[x]*(amp-avg);
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1007 }
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1008 //this is always zero. Why ?
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1009 xFixp= atan(sin_sum/cos_sum)*priv->bpb/M_PI;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1010
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1011 //Without this line the result is full of errors
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1012 //and routine is unable to find magic sequence
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1013 buf+=FIXP2INT(10*priv->bpb);
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1014
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1015 r=0;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1016 for(x=FIXP2INT(xFixp);x<70;x=FIXP2INT(xFixp)){
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1017 r=(r<<1) & 0xFFFF;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1018 if(buf[x]>avg) r|=1;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1019 xFixp+=priv->bpb;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1020 if(r==0xAAE4) break;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1021 }
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1022
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1023 //this is not teletext
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1024 if (r!=0xaae4) return 0;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1025
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1026 //Decode remaining 45-2(clock run-in)-1(framing code)=42 bytes
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1027 for(i=1; i<=(42<<3); i++){
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1028 r>>=1;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1029 x=FIXP2INT(xFixp);
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1030 if(buf[x]> avg)
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1031 r|=0x80;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1032
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1033 if(!(i & 0x07)){
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1034 data[(i>>3)-1]=r;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1035 r=0;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1036 }
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1037 xFixp+=priv->bpb;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1038 }
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1039
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1040 return 1;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1041 }
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1042
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1043 /**
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1044 * \brief decodes all vbi lines from one video frame
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1045 * \param priv private data structure
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1046 * \param buf buffer with raw vbi data in it
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1047 *
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1048 * \note buffer size have to be at least priv->ptsp->bufsize bytes
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1049 */
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1050 static void vbi_decode(priv_vbi_t* priv,unsigned char*buf){
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1051 int magAddr;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1052 int pkt;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1053 unsigned char data[64];
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1054 unsigned char* linep;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1055 int d0,d1;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1056 int i=0;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1057 mp_msg(MSGT_TV,MSGL_DBG3,"vbi: vbi_decode\n");
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1058 for(linep=buf; linep<buf+priv->ptsp->bufsize; linep+=priv->ptsp->samples_per_line,i++){
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1059 #if 0
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1060 /*
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1061 This routine is alternative implementation of raw VBI data decoding.
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1062 Unfortunately, it detects only about 20% of incoming data,
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1063 but Michael says that this algorithm is better, and he wants to fix it.
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1064 */
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1065 if(decode_raw_line_sine(priv,linep,data)<=0){
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1066 #endif
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1067 if(decode_raw_line_runin(priv,linep,data)<=0){
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1068 continue; //this is not valid teletext line
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1069 }
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1070 d0= corrHamm48[ data[0] ];
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1071 d1= corrHamm48[ data[1] ];
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1072
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1073 if(d0&0x80 || d1&0x80){
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1074 pll_add(priv,2,4);
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1075 mp_msg(MSGT_TV,MSGL_V,"vbi_decode(%d):HammErr after decode_raw_line\n",i);
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1076
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1077 continue; //hamError
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1078 }
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1079 magAddr=d0 & 0x7;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1080 pkt=(d0>>3)|(d1<<1);
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1081 mp_msg(MSGT_TV,MSGL_DBG3,"vbi_decode(%d):%x %x (mag:%x, pkt:%d)\n",
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1082 i,d0,d1,magAddr,pkt);
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1083 if(!pkt){
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1084 decode_pkt0(priv,data+2,magAddr); //skip MRGA
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1085 }else if(pkt>0 && pkt<VBI_ROWS){
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1086 if(!priv->mag[magAddr].pt) continue;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1087 decode_pkt_page(priv,data+2,magAddr,pkt);//skip MRGA
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1088 } else {
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1089 mp_msg(MSGT_TV,MSGL_DBG3,"unsupported packet:%d\n",pkt);
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1090 }
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1091 }
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1092
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1093 }
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1094
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1095 /*
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1096 ---------------------------------------------------------------------------------
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1097 Public routines
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1098 ---------------------------------------------------------------------------------
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1099 */
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1100
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1101 /**
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1102 * \brief toggles teletext page displaying format
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1103 * \param priv_vbi private data structure
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1104 * \param flag new format
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1105 * \return
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1106 * TVI_CONTROL_TRUE is success,
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1107 * TVI_CONTROL_FALSE otherwise
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1108 *
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1109 * flag:
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1110 * 0 - opaque
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1111 * 1 - transparent
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1112 * 2 - opaque with black foreground color (only in bw mode)
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1113 * 3 - transparent with black foreground color (only in bw mode)
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1114 */
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1115 static int teletext_set_format(priv_vbi_t * priv, teletext_format flag)
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1116 {
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1117 flag&=3;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1118
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1119 mp_msg(MSGT_TV,MSGL_DBG3,"teletext_set_format_is called. mode:%d\n",flag);
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1120 pthread_mutex_lock(&(priv->buffer_mutex));
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1121
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1122 priv->tformat=flag;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1123
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1124 priv->pagenumdec=0;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1125
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1126 pthread_mutex_unlock(&(priv->buffer_mutex));
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1127 return TVI_CONTROL_TRUE;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1128 }
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1129
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1130 /**
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1131 * \brief append just entered digit to editing page number
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1132 * \param priv_vbi private data structure
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1133 * \param dec decimal digit to append
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1134 *
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1135 * dec:
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1136 * '0'..'9' append digit
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1137 * '-' remove last digit (backspace emulation)
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1138 *
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1139 * This routine allows user to jump to arbitrary page.
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1140 * It implements simple page number editing algorithm.
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1141 *
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1142 * Subsystem can be on one of two modes: normal and page number edit mode.
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1143 * Zero value of priv->pagenumdec means normal mode
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1144 * Non-zero value means page number edit mode and equals to packed
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1145 * decimal number of already entered part of page number.
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1146 *
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1147 * How this works.
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1148 * Let's assume that current mode is normal (pagenumdec is zero), teletext page
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1149 * 100 are displayed as usual. topmost left corner of page contains page number.
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1150 * Then vbi_add_dec is sequentially called (through slave
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1151 * command of course) with 1,4,-,2,3 * values of dec parameter.
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1152 *
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1153 * +-----+------------+------------------+
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1154 * | dec | pagenumdec | displayed number |
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1155 * +-----+------------+------------------+
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1156 * | | 0x000 | 100 |
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1157 * +-----+------------+------------------+
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1158 * | 1 | 0x001 | __1 |
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1159 * +-----+------------+------------------+
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1160 * | 4 | 0x014 | _14 |
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1161 * +-----+------------+------------------+
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1162 * | - | 0x001 | __1 |
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1163 * +-----+------------+------------------+
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1164 * | 2 | 0x012 | _12 |
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1165 * +-----+------------+------------------+
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1166 * | 3 | 0x123 | 123 |
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1167 * +-----+------------+------------------+
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1168 * | | 0x000 | 123 |
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1169 * +-----+------------+------------------+
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1170 *
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1171 * pagenumdec will automatically receive zero value after third digit of page
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1172 * number is entered and current page will be switched to another one with
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1173 * entered page number.
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1174 */
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1175 static void vbi_add_dec(priv_vbi_t * priv, char *dec)
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1176 {
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1177 int count, shift;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1178 if (!dec)
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1179 return;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1180 if (!priv->on)
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1181 return;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1182 if ((*dec<'0' || *dec>'9') && *dec!='-')
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1183 return;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1184 if (!priv->pagenumdec) //first digit cannot be '0','9' or '-'
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1185 if(*dec=='-' || *dec=='0' || *dec=='9')
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1186 return;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1187 pthread_mutex_lock(&(priv->buffer_mutex));
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1188 count=(priv->pagenumdec>>12)&0xf;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1189 if (*dec=='-') {
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1190 count--;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1191 if (count)
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1192 priv->pagenumdec=((priv->pagenumdec>>4)&0xfff)|(count<<12);
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1193 else
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1194 priv->pagenumdec=0;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1195 } else {
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1196 shift = count * 4;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1197 count++;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1198 priv->pagenumdec=
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1199 (((priv->pagenumdec)<<4|(*dec-'0'))&0xfff)|(count<<12);
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1200 if (count==3) {
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1201 priv->pagenum=priv->pagenumdec&0x7ff;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1202 priv->subpagenum=get_subpagenum_from_cache(priv,priv->pagenum);
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1203 priv->pagenumdec=0;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1204 }
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1205 }
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1206 pthread_mutex_unlock(&(priv->buffer_mutex));
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1207 }
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1208
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1209
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1210 /**
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1211 * \brief Teletext control routine
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1212 * \param priv_vbi private data structure
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1213 * \param cmd command
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1214 * \param arg command parameter (has to be not null)
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1215 */
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1216 int teletext_control(void* p, int cmd, void *arg)
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1217 {
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1218 int fine_tune=99;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1219 priv_vbi_t* priv=(priv_vbi_t*)p;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1220
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1221 if (!priv && cmd!=TV_VBI_CONTROL_START)
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1222 return TVI_CONTROL_FALSE;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1223 if (!arg && cmd!=TV_VBI_CONTROL_STOP)
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1224 return TVI_CONTROL_FALSE;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1225
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1226 switch (cmd) {
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1227 case TV_VBI_CONTROL_RESET:
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1228 {
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1229 tv_param_t* tv_param=arg;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1230 pthread_mutex_lock(&(priv->buffer_mutex));
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1231 priv->pagenumdec=0;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1232 clear_cache(priv);
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1233 priv->pagenum=steppage(0,tv_param->tpage&0x7ff,1);
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1234 priv->tformat=tv_param->tformat;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1235 priv->subpagenum=0;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1236 pll_reset(priv,fine_tune);
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1237 pthread_mutex_unlock(&(priv->buffer_mutex));
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1238 return TVI_CONTROL_TRUE;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1239 }
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1240 case TV_VBI_CONTROL_START:
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1241 {
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1242 int i;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1243 tt_stream_props* ptsp=*(tt_stream_props**)arg;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1244
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1245 if(!ptsp)
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1246 return TVI_CONTROL_FALSE;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1247
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1248 priv=calloc(1,sizeof(priv_vbi_t));
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1249
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1250 priv->ptsp=malloc(sizeof(tt_stream_props));
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1251 memcpy(priv->ptsp,ptsp,sizeof(tt_stream_props));
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1252 *(priv_vbi_t**)arg=priv;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1253
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1254 priv->subpagenum=0;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1255 pthread_mutex_init(&priv->buffer_mutex, NULL);
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1256 priv->pagenumdec=0;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1257 for(i=0;i<VBI_ROWS*VBI_COLUMNS;i++)
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1258 priv->display_page[i]=tt_space;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1259
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1260 priv->mag=calloc(8,sizeof(mag_t));
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1261 init_cache(priv);
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1262 init_vbi_consts(priv);
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1263 pll_reset(priv,fine_tune);
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1264 return TVI_CONTROL_TRUE;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1265 }
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1266 case TV_VBI_CONTROL_STOP:
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1267 {
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1268 if(priv->mag)
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1269 free(priv->mag);
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1270 if(priv->ptsp)
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1271 free(priv->ptsp);
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1272 destroy_cache(priv);
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1273 free(priv);
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1274 return TVI_CONTROL_TRUE;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1275 }
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1276 case TV_VBI_CONTROL_SET_MODE:
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1277 priv->on=(*(int*)arg%2);
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1278 return TVI_CONTROL_TRUE;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1279 case TV_VBI_CONTROL_GET_MODE:
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1280 *(int*)arg=priv->on;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1281 return TVI_CONTROL_TRUE;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1282 case TV_VBI_CONTROL_SET_FORMAT:
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1283 return teletext_set_format(priv, *(int *) arg);
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1284 case TV_VBI_CONTROL_GET_FORMAT:
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1285 pthread_mutex_lock(&(priv->buffer_mutex));
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1286 *(int*)arg=priv->tformat;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1287 pthread_mutex_unlock(&(priv->buffer_mutex));
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1288 return TVI_CONTROL_TRUE;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1289 case TV_VBI_CONTROL_GET_HALF_PAGE:
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1290 if(!priv->on)
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1291 return TVI_CONTROL_FALSE;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1292 *(int *)arg=priv->zoom;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1293 return TVI_CONTROL_TRUE;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1294 case TV_VBI_CONTROL_SET_HALF_PAGE:
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1295 {
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1296 int val=*(int*)arg;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1297 val%=3;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1298 if(val<0)
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1299 val+=3;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1300 pthread_mutex_lock(&(priv->buffer_mutex));
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1301 priv->zoom=val;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1302 pthread_mutex_unlock(&(priv->buffer_mutex));
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1303 return TVI_CONTROL_TRUE;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1304 }
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1305 case TV_VBI_CONTROL_SET_PAGE:
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1306 {
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1307 int val=*(int *) arg;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1308 if(val<100 || val>0x899)
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1309 return TVI_CONTROL_FALSE;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1310 pthread_mutex_lock(&(priv->buffer_mutex));
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1311 priv->pagenum=val&0x7ff;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1312 priv->subpagenum=get_subpagenum_from_cache(priv,priv->pagenum);
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1313 priv->pagenumdec=0;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1314 pthread_mutex_unlock(&(priv->buffer_mutex));
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1315 return TVI_CONTROL_TRUE;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1316 }
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1317 case TV_VBI_CONTROL_STEP_PAGE:
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1318 {
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1319 int direction=*(int *) arg;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1320 pthread_mutex_lock(&(priv->buffer_mutex));
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1321 priv->pagenum=steppage(priv->pagenum, direction,1);
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1322 priv->subpagenum=get_subpagenum_from_cache(priv,priv->pagenum);
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1323 priv->pagenumdec=0;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1324 pthread_mutex_unlock(&(priv->buffer_mutex));
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1325 return TVI_CONTROL_TRUE;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1326 }
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1327 case TV_VBI_CONTROL_GET_PAGE:
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1328 *(int*)arg=((priv->pagenum+0x700)&0x7ff)+0x100;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1329 return TVI_CONTROL_TRUE;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1330 case TV_VBI_CONTROL_SET_SUBPAGE:
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1331 pthread_mutex_lock(&(priv->buffer_mutex));
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1332 priv->pagenumdec=0;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1333 priv->subpagenum=*(int*)arg;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1334 if(priv->subpagenum<0)
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1335 priv->subpagenum=0;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1336 if(priv->subpagenum>=VBI_MAX_SUBPAGES)
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1337 priv->subpagenum=VBI_MAX_SUBPAGES-1;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1338 pthread_mutex_unlock(&(priv->buffer_mutex));
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1339 return TVI_CONTROL_TRUE;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1340 case TV_VBI_CONTROL_GET_SUBPAGE:
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1341 *(int*)arg=priv->subpagenum;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1342 return TVI_CONTROL_TRUE;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1343 case TV_VBI_CONTROL_ADD_DEC:
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1344 vbi_add_dec(priv, *(char **) arg);
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1345 return TVI_CONTROL_TRUE;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1346 case TV_VBI_CONTROL_DECODE_PAGE:
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1347 vbi_decode(priv,*(unsigned char**)arg);
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1348 return TVI_CONTROL_TRUE;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1349 case TV_VBI_CONTROL_GET_VBIPAGE:
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1350 if(!priv->on)
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1351 return TVI_CONTROL_FALSE;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1352 prepare_visible_page(priv);
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1353 *(void **)arg=priv->display_page;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1354 return TVI_CONTROL_TRUE;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1355 }
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1356 return TVI_CONTROL_UNKNOWN;
34532db868ba Teletext support.
voroshil
parents:
diff changeset
1357 }