36 static const u8 raw_vbi_sav_rp[2] = { 0x20, 0x60 };
37 static const u8 sliced_vbi_eav_rp[2] = { 0xb0, 0xf0 };
39 static void copy_vbi_data(
struct cx18 *
cx,
int lines,
u32 pts_stamp)
45 static const u8 mpeg_hdr_data[] = {
47 0x00, 0x00, 0x01, 0xba,
48 0x44, 0x00, 0x0c, 0x66, 0x24, 0x01,
52 0x00, 0x00, 0x01, 0xbd,
55 0x21, 0x00, 0x5d, 0x63, 0xa7,
58 const int sd =
sizeof(mpeg_hdr_data);
62 for (i = 0; i < lines; i++) {
74 linemask[0] |= (1 <<
l);
76 linemask[1] |= (1 << (l - 32));
78 memcpy(dst + sd + 12 + line * 43 + 1, sdata->
data, 42);
81 memcpy(dst, mpeg_hdr_data,
sizeof(mpeg_hdr_data));
86 memcpy(dst + sd,
"ITV0", 4);
87 memcpy(dst + sd + 4, dst + sd + 12, line * 43);
88 size = 4 + ((43 * line + 3) & ~3);
90 memcpy(dst + sd,
"itv0", 4);
93 memcpy(dst + sd + 4, &linemask[0], 8);
94 size = 12 + ((43 * line + 3) & ~3);
96 dst[4+16] = (size + 10) >> 8;
97 dst[5+16] = (size + 10) & 0xff;
98 dst[9+16] = 0x21 | ((pts_stamp >> 29) & 0x6);
99 dst[10+16] = (pts_stamp >> 22) & 0xff;
100 dst[11+16] = 1 | ((pts_stamp >> 14) & 0xff);
101 dst[12+16] = (pts_stamp >> 7) & 0xff;
102 dst[13+16] = 1 | ((pts_stamp & 0x7f) << 1);
111 u32 line_size = vbi_active_samples;
112 u32 lines = cx->
vbi.count * 2;
120 for (i = 0; i < lines; i++) {
121 p = buf + i * line_size;
124 if (p[0] != 0xff || p[1] || p[2] ||
125 (p[3] != raw_vbi_sav_rp[0] &&
126 p[3] != raw_vbi_sav_rp[1]))
128 if (i == lines - 1) {
130 memcpy(q, p + 4, line_size - 4 - hdr_size);
132 p += line_size - hdr_size - 1;
133 memset(q, (
int) *p, hdr_size);
135 memcpy(q, p + 4, line_size - 4);
139 return lines * (line_size - 4);
142 static u32 compress_sliced_buf(
struct cx18 *cx,
u8 *buf,
u32 size,
148 u32 line_size = cx->
is_60hz ? vbi_hblank_samples_60Hz
149 : vbi_hblank_samples_50Hz;
152 for (i = hdr_size, buf += hdr_size; i <
size; i++, buf++) {
153 if (buf[0] == 0xff && !buf[1] && !buf[2] &&
154 (buf[3] == sliced_vbi_eav_rp[0] ||
155 buf[3] == sliced_vbi_eav_rp[1]))
165 if (size < line_size)
168 for (i = 0; i < size / line_size; i++) {
169 u8 *p = buf + i * line_size;
172 if (p[0] != 0xff || p[1] || p[2] ||
173 (p[3] != sliced_vbi_eav_rp[0] &&
174 p[3] != sliced_vbi_eav_rp[1]))
179 cx->
vbi.sliced_data[
line].id = vbi.type;
180 cx->
vbi.sliced_data[
line].field = vbi.is_second_field;
181 cx->
vbi.sliced_data[
line].line = vbi.line;
182 memcpy(cx->
vbi.sliced_data[line].data, vbi.p, 42);
189 static void _cx18_process_vbi_data(
struct cx18 *cx,
struct cx18_buffer *buf)
195 struct vbi_data_hdr {
199 } *
hdr = (
struct vbi_data_hdr *) buf->
buf;
214 if (cx18_raw_vbi(cx)) {
217 compress_raw_buf(cx, p, size,
sizeof(
struct vbi_data_hdr));
234 lines = compress_sliced_buf(cx, p, size,
sizeof(
struct vbi_data_hdr));
238 cx->
vbi.sliced_data[0].id = 0;
239 cx->
vbi.sliced_data[0].line = 0;
240 cx->
vbi.sliced_data[0].field = 0;
243 buf->
bytesused = size = lines *
sizeof(cx->
vbi.sliced_data[0]);
244 memcpy(p, &cx->
vbi.sliced_data[0], size);
246 if (cx->
vbi.insert_mpeg)
247 copy_vbi_data(cx, lines, pts);
274 _cx18_process_vbi_data(cx, buf);