27 static void ivtv_set_vps(
struct ivtv *itv,
int enabled)
35 data.line = enabled ? 16 : 0;
36 data.data[2] = itv->
vbi.vps_payload.data[0];
37 data.data[8] = itv->
vbi.vps_payload.data[1];
38 data.data[9] = itv->
vbi.vps_payload.data[2];
39 data.data[10] = itv->
vbi.vps_payload.data[3];
40 data.data[11] = itv->
vbi.vps_payload.data[4];
52 data.line = (mode & 1) ? 21 : 0;
57 data.line = (mode & 2) ? 21 : 0;
63 static void ivtv_set_wss(
struct ivtv *itv,
int enabled,
int mode)
80 data.line = enabled ? 23 : 0;
81 data.data[0] = mode & 0xff;
82 data.data[1] = (mode >> 8) & 0xff;
86 static int odd_parity(
u8 c)
95 static void ivtv_write_vbi_line(
struct ivtv *itv,
97 struct vbi_cc *cc,
int *found_cc)
114 vps.data[1] = d->
data[8];
115 vps.data[2] = d->
data[9];
116 vps.data[3] = d->
data[10];
117 vps.data[4] = d->
data[11];
124 int wss = d->
data[0] | d->
data[1] << 8;
133 static void ivtv_write_vbi_cc_lines(
struct ivtv *itv,
const struct vbi_cc *cc)
145 static void ivtv_write_vbi(
struct ivtv *itv,
149 struct vbi_cc cc = { .
odd = { 0x80, 0x80 }, .even = { 0x80, 0x80 } };
153 for (i = 0; i <
cnt; i++)
154 ivtv_write_vbi_line(itv, sliced + i, &cc, &found_cc);
157 ivtv_write_vbi_cc_lines(itv, &cc);
165 struct vbi_cc cc = { .
odd = { 0x80, 0x80 }, .even = { 0x80, 0x80 } };
171 for (i = 0; i <
cnt; i++) {
177 ivtv_write_vbi_line(itv, &d, &cc, &found_cc);
181 ivtv_write_vbi_cc_lines(itv, &cc);
186 static void copy_vbi_data(
struct ivtv *itv,
int lines,
u32 pts_stamp)
192 static const u8 mpeg_hdr_data[] = {
193 0x00, 0x00, 0x01, 0xba, 0x44, 0x00, 0x0c, 0x66,
194 0x24, 0x01, 0x01, 0xd1, 0xd3, 0xfa, 0xff, 0xff,
195 0x00, 0x00, 0x01, 0xbd, 0x00, 0x1a, 0x84, 0x80,
196 0x07, 0x21, 0x00, 0x5d, 0x63, 0xa7, 0xff, 0xff
198 const int sd =
sizeof(mpeg_hdr_data);
202 for (i = 0; i < lines; i++) {
205 if (itv->
vbi.sliced_data[i].id == 0)
208 l = itv->
vbi.sliced_data[
i].line - 6;
209 f = itv->
vbi.sliced_data[
i].field;
213 linemask[0] |= (1 <<
l);
215 linemask[1] |= (1 << (l - 32));
216 dst[sd + 12 + line * 43] =
218 memcpy(dst + sd + 12 + line * 43 + 1, itv->
vbi.sliced_data[i].data, 42);
221 memcpy(dst, mpeg_hdr_data,
sizeof(mpeg_hdr_data));
226 memcpy(dst + sd,
"ITV0", 4);
227 memcpy(dst + sd + 4, dst + sd + 12, line * 43);
228 size = 4 + ((43 * line + 3) & ~3);
230 memcpy(dst + sd,
"itv0", 4);
233 memcpy(dst + sd + 4, &linemask[0], 8);
234 size = 12 + ((43 * line + 3) & ~3);
236 dst[4+16] = (size + 10) >> 8;
237 dst[5+16] = (size + 10) & 0xff;
238 dst[9+16] = 0x21 | ((pts_stamp >> 29) & 0x6);
239 dst[10+16] = (pts_stamp >> 22) & 0xff;
240 dst[11+16] = 1 | ((pts_stamp >> 14) & 0xff);
241 dst[12+16] = (pts_stamp >> 7) & 0xff;
242 dst[13+16] = 1 | ((pts_stamp & 0x7f) << 1);
246 static int ivtv_convert_ivtv_vbi(
struct ivtv *itv,
u8 *
p)
252 if (!
memcmp(p,
"itv0", 4)) {
253 memcpy(linemask, p + 4, 8);
255 }
else if (!
memcmp(p,
"ITV0", 4)) {
256 linemask[0] = 0xffffffff;
261 linemask[0] = linemask[1] = 0;
263 for (i = 0; i < 36; i++) {
266 if (i < 32 && !(linemask[0] & (1 << i)))
268 if (i >= 32 && !(linemask[1] & (1 << (i - 32))))
277 err = !odd_parity(p[1]) || !odd_parity(p[2]);
290 l = (i < 18) ? i + 6 : i - 18 + 6;
291 itv->
vbi.sliced_dec_data[
line].line =
l;
292 itv->
vbi.sliced_dec_data[
line].field = i >= 18;
294 memcpy(itv->
vbi.sliced_dec_data[line].data, p + 1, 42);
300 itv->
vbi.sliced_dec_data[
line].id = 0;
301 itv->
vbi.sliced_dec_data[
line].line = 0;
302 itv->
vbi.sliced_dec_data[
line].field = 0;
305 return line *
sizeof(itv->
vbi.sliced_dec_data[0]);
313 u32 line_size = itv->
vbi.raw_decoder_line_size;
314 u32 lines = itv->
vbi.count;
315 u8 sav1 = itv->
vbi.raw_decoder_sav_odd_field;
316 u8 sav2 = itv->
vbi.raw_decoder_sav_even_field;
321 for (i = 0; i < lines; i++) {
322 p = buf + i * line_size;
325 if (p[0] != 0xff || p[1] || p[2] || (p[3] != sav1 && p[3] != sav2)) {
328 memcpy(q, p + 4, line_size - 4);
331 return lines * (line_size - 4);
339 u32 line_size = itv->
vbi.sliced_decoder_line_size;
345 for (i = 0; i <
size; i++, buf++) {
346 if (buf[0] == 0xff && !buf[1] && !buf[2] && buf[3] == sav)
351 if (size < line_size) {
354 for (i = 0; i < size / line_size; i++) {
355 u8 *p = buf + i * line_size;
358 if (p[0] != 0xff || p[1] || p[2] || p[3] != sav) {
363 if (vbi.type && !(lines & (1 << vbi.line))) {
364 lines |= 1 << vbi.line;
365 itv->
vbi.sliced_data[
line].id = vbi.type;
366 itv->
vbi.sliced_data[
line].field = vbi.is_second_field;
367 itv->
vbi.sliced_data[
line].line = vbi.line;
368 memcpy(itv->
vbi.sliced_data[line].data, vbi.p, 42);
376 u64 pts_stamp,
int streamtype)
390 size = buf->
bytesused = compress_raw_buf(itv, p, size);
393 if (type == itv->
vbi.raw_decoder_sav_even_field) {
410 lines = compress_sliced_buf(itv, 0, p, size / 2,
411 itv->
vbi.sliced_decoder_sav_odd_field);
415 lines = compress_sliced_buf(itv, lines, p + size / 2 - 32, size / 2 + 32,
416 itv->
vbi.sliced_decoder_sav_even_field);
419 itv->
vbi.sliced_data[0].id = 0;
420 itv->
vbi.sliced_data[0].line = 0;
421 itv->
vbi.sliced_data[0].field = 0;
424 buf->
bytesused = size = lines *
sizeof(itv->
vbi.sliced_data[0]);
425 memcpy(p, &itv->
vbi.sliced_data[0], size);
427 if (itv->
vbi.insert_mpeg) {
428 copy_vbi_data(itv, lines, pts_stamp);
450 for (
y = 0;
y <
size;
y += 4) {
454 cnt = ivtv_convert_ivtv_vbi(itv, p + offset);
458 ivtv_write_vbi(itv, itv->
vbi.sliced_dec_data,
459 cnt /
sizeof(itv->
vbi.sliced_dec_data[0]));
466 struct vbi_cc cc = { .
odd = { 0x80, 0x80 }, .even = { 0x80, 0x80 } };
469 ivtv_set_cc(itv, 0, &cc);
470 itv->
vbi.cc_payload_idx = 0;
478 struct vbi_cc cc = { .
odd = { 0x80, 0x80 }, .even = { 0x80, 0x80 } };
487 ivtv_set_wss(itv, 1, data.
data[0] & 0xf);
490 ivtv_set_wss(itv, 1, 0x8);
513 ivtv_set_cc(itv, mode, &cc);
515 ivtv_set_cc(itv, 0, &cc);
530 ivtv_set_cc(itv, 3, &cc);
541 ivtv_set_cc(itv, 3, &cc);
547 ivtv_set_vps(itv, 1);