This source file includes following definitions.
- copy_vbi_data
- compress_raw_buf
- compress_sliced_buf
- _cx18_process_vbi_data
- cx18_process_vbi_data
1
2
3
4
5
6
7
8
9
10 #include "cx18-driver.h"
11 #include "cx18-vbi.h"
12 #include "cx18-ioctl.h"
13 #include "cx18-queue.h"
14
15
16
17
18
19
20
21
22 static const u8 raw_vbi_sav_rp[2] = { 0x20, 0x60 };
23 static const u8 sliced_vbi_eav_rp[2] = { 0xb0, 0xf0 };
24
25 static void copy_vbi_data(struct cx18 *cx, int lines, u32 pts_stamp)
26 {
27 int line = 0;
28 int i;
29 u32 linemask[2] = { 0, 0 };
30 unsigned short size;
31 static const u8 mpeg_hdr_data[] = {
32
33 0x00, 0x00, 0x01, 0xba,
34 0x44, 0x00, 0x0c, 0x66, 0x24, 0x01,
35 0x01, 0xd1, 0xd3,
36 0xfa, 0xff, 0xff,
37
38 0x00, 0x00, 0x01, 0xbd,
39 0x00, 0x1a,
40 0x84, 0x80, 0x07,
41 0x21, 0x00, 0x5d, 0x63, 0xa7,
42 0xff, 0xff
43 };
44 const int sd = sizeof(mpeg_hdr_data);
45 int idx = cx->vbi.frame % CX18_VBI_FRAMES;
46 u8 *dst = &cx->vbi.sliced_mpeg_data[idx][0];
47
48 for (i = 0; i < lines; i++) {
49 struct v4l2_sliced_vbi_data *sdata = cx->vbi.sliced_data + i;
50 int f, l;
51
52 if (sdata->id == 0)
53 continue;
54
55 l = sdata->line - 6;
56 f = sdata->field;
57 if (f)
58 l += 18;
59 if (l < 32)
60 linemask[0] |= (1 << l);
61 else
62 linemask[1] |= (1 << (l - 32));
63 dst[sd + 12 + line * 43] = cx18_service2vbi(sdata->id);
64 memcpy(dst + sd + 12 + line * 43 + 1, sdata->data, 42);
65 line++;
66 }
67 memcpy(dst, mpeg_hdr_data, sizeof(mpeg_hdr_data));
68 if (line == 36) {
69
70
71
72 memcpy(dst + sd, "ITV0", 4);
73 memmove(dst + sd + 4, dst + sd + 12, line * 43);
74 size = 4 + ((43 * line + 3) & ~3);
75 } else {
76 memcpy(dst + sd, "itv0", 4);
77 cpu_to_le32s(&linemask[0]);
78 cpu_to_le32s(&linemask[1]);
79 memcpy(dst + sd + 4, &linemask[0], 8);
80 size = 12 + ((43 * line + 3) & ~3);
81 }
82 dst[4+16] = (size + 10) >> 8;
83 dst[5+16] = (size + 10) & 0xff;
84 dst[9+16] = 0x21 | ((pts_stamp >> 29) & 0x6);
85 dst[10+16] = (pts_stamp >> 22) & 0xff;
86 dst[11+16] = 1 | ((pts_stamp >> 14) & 0xff);
87 dst[12+16] = (pts_stamp >> 7) & 0xff;
88 dst[13+16] = 1 | ((pts_stamp & 0x7f) << 1);
89 cx->vbi.sliced_mpeg_size[idx] = sd + size;
90 }
91
92
93
94
95 static u32 compress_raw_buf(struct cx18 *cx, u8 *buf, u32 size, u32 hdr_size)
96 {
97 u32 line_size = VBI_ACTIVE_SAMPLES;
98 u32 lines = cx->vbi.count * 2;
99 u8 *q = buf;
100 u8 *p;
101 int i;
102
103
104 buf += hdr_size;
105
106 for (i = 0; i < lines; i++) {
107 p = buf + i * line_size;
108
109
110 if (p[0] != 0xff || p[1] || p[2] ||
111 (p[3] != raw_vbi_sav_rp[0] &&
112 p[3] != raw_vbi_sav_rp[1]))
113 break;
114 if (i == lines - 1) {
115
116 memcpy(q, p + 4, line_size - 4 - hdr_size);
117 q += line_size - 4 - hdr_size;
118 p += line_size - hdr_size - 1;
119 memset(q, (int) *p, hdr_size);
120 } else {
121 memcpy(q, p + 4, line_size - 4);
122 q += line_size - 4;
123 }
124 }
125 return lines * (line_size - 4);
126 }
127
128 static u32 compress_sliced_buf(struct cx18 *cx, u8 *buf, u32 size,
129 const u32 hdr_size)
130 {
131 struct v4l2_decode_vbi_line vbi;
132 int i;
133 u32 line = 0;
134 u32 line_size = cx->is_60hz ? VBI_HBLANK_SAMPLES_60HZ
135 : VBI_HBLANK_SAMPLES_50HZ;
136
137
138 for (i = hdr_size, buf += hdr_size; i < size; i++, buf++) {
139 if (buf[0] == 0xff && !buf[1] && !buf[2] &&
140 (buf[3] == sliced_vbi_eav_rp[0] ||
141 buf[3] == sliced_vbi_eav_rp[1]))
142 break;
143 }
144
145
146
147
148
149
150 size -= (i - hdr_size);
151 if (size < line_size)
152 return line;
153
154 for (i = 0; i < size / line_size; i++) {
155 u8 *p = buf + i * line_size;
156
157
158 if (p[0] != 0xff || p[1] || p[2] ||
159 (p[3] != sliced_vbi_eav_rp[0] &&
160 p[3] != sliced_vbi_eav_rp[1]))
161 continue;
162 vbi.p = p + 4;
163 v4l2_subdev_call(cx->sd_av, vbi, decode_vbi_line, &vbi);
164 if (vbi.type) {
165 cx->vbi.sliced_data[line].id = vbi.type;
166 cx->vbi.sliced_data[line].field = vbi.is_second_field;
167 cx->vbi.sliced_data[line].line = vbi.line;
168 memcpy(cx->vbi.sliced_data[line].data, vbi.p, 42);
169 line++;
170 }
171 }
172 return line;
173 }
174
175 static void _cx18_process_vbi_data(struct cx18 *cx, struct cx18_buffer *buf)
176 {
177
178
179
180
181 struct vbi_data_hdr {
182 __be32 magic;
183 __be32 unknown;
184 __be32 pts;
185 } *hdr = (struct vbi_data_hdr *) buf->buf;
186
187 u8 *p = (u8 *) buf->buf;
188 u32 size = buf->bytesused;
189 u32 pts;
190 int lines;
191
192
193
194
195
196
197 cx18_buf_swap(buf);
198
199
200 if (cx18_raw_vbi(cx)) {
201
202 size = buf->bytesused =
203 compress_raw_buf(cx, p, size, sizeof(struct vbi_data_hdr));
204
205
206
207
208
209 p += size - 4;
210 memcpy(p, &cx->vbi.frame, 4);
211 cx->vbi.frame++;
212 return;
213 }
214
215
216
217 pts = (be32_to_cpu(hdr->magic) == 0x3fffffff) ? be32_to_cpu(hdr->pts)
218 : 0;
219
220 lines = compress_sliced_buf(cx, p, size, sizeof(struct vbi_data_hdr));
221
222
223 if (lines == 0) {
224 cx->vbi.sliced_data[0].id = 0;
225 cx->vbi.sliced_data[0].line = 0;
226 cx->vbi.sliced_data[0].field = 0;
227 lines = 1;
228 }
229 buf->bytesused = size = lines * sizeof(cx->vbi.sliced_data[0]);
230 memcpy(p, &cx->vbi.sliced_data[0], size);
231
232 if (cx->vbi.insert_mpeg)
233 copy_vbi_data(cx, lines, pts);
234 cx->vbi.frame++;
235 }
236
237 void cx18_process_vbi_data(struct cx18 *cx, struct cx18_mdl *mdl,
238 int streamtype)
239 {
240 struct cx18_buffer *buf;
241 u32 orig_used;
242
243 if (streamtype != CX18_ENC_STREAM_TYPE_VBI)
244 return;
245
246
247
248
249
250
251
252
253
254
255
256 list_for_each_entry(buf, &mdl->buf_list, list) {
257 orig_used = buf->bytesused;
258 if (orig_used == 0)
259 break;
260 _cx18_process_vbi_data(cx, buf);
261 mdl->bytesused -= (orig_used - buf->bytesused);
262 }
263 }