diff options
author | Andy Walls <awalls@radix.net> | 2009-01-30 22:33:02 -0500 |
---|---|---|
committer | Mauro Carvalho Chehab <mchehab@redhat.com> | 2009-03-30 11:42:38 -0400 |
commit | 302df9702192a68578916ef922c33370cbba350d (patch) | |
tree | eab3173a4b82ec26c89b82c50e9bfb0fe2477953 /drivers/media/video/cx18/cx18-fileops.c | |
parent | 4325dff220918c2ced82d16c3475d9a5afb1cab3 (diff) |
V4L/DVB (10439): cx18: Clean-up and enable sliced VBI handling
Removed legacy ivtv state variables, added comments, and cleaned
up sliced VBI related code. Enabled sliced VBI.
Signed-off-by: Andy Walls <awalls@radix.net>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
Diffstat (limited to 'drivers/media/video/cx18/cx18-fileops.c')
-rw-r--r-- | drivers/media/video/cx18/cx18-fileops.c | 54 |
1 files changed, 43 insertions, 11 deletions
diff --git a/drivers/media/video/cx18/cx18-fileops.c b/drivers/media/video/cx18/cx18-fileops.c index 23006f7d9159..0b1dbc67e1ab 100644 --- a/drivers/media/video/cx18/cx18-fileops.c +++ b/drivers/media/video/cx18/cx18-fileops.c | |||
@@ -176,6 +176,8 @@ static struct cx18_buffer *cx18_get_buffer(struct cx18_stream *s, int non_block, | |||
176 | *err = 0; | 176 | *err = 0; |
177 | while (1) { | 177 | while (1) { |
178 | if (s->type == CX18_ENC_STREAM_TYPE_MPG) { | 178 | if (s->type == CX18_ENC_STREAM_TYPE_MPG) { |
179 | /* Process pending program info updates and pending | ||
180 | VBI data */ | ||
179 | 181 | ||
180 | if (time_after(jiffies, cx->dualwatch_jiffies + msecs_to_jiffies(1000))) { | 182 | if (time_after(jiffies, cx->dualwatch_jiffies + msecs_to_jiffies(1000))) { |
181 | cx->dualwatch_jiffies = jiffies; | 183 | cx->dualwatch_jiffies = jiffies; |
@@ -260,6 +262,20 @@ static size_t cx18_copy_buf_to_user(struct cx18_stream *s, | |||
260 | len = ucount; | 262 | len = ucount; |
261 | if (cx->vbi.insert_mpeg && s->type == CX18_ENC_STREAM_TYPE_MPG && | 263 | if (cx->vbi.insert_mpeg && s->type == CX18_ENC_STREAM_TYPE_MPG && |
262 | !cx18_raw_vbi(cx) && buf != &cx->vbi.sliced_mpeg_buf) { | 264 | !cx18_raw_vbi(cx) && buf != &cx->vbi.sliced_mpeg_buf) { |
265 | /* | ||
266 | * Try to find a good splice point in the PS, just before | ||
267 | * an MPEG-2 Program Pack start code, and provide only | ||
268 | * up to that point to the user, so it's easy to insert VBI data | ||
269 | * the next time around. | ||
270 | */ | ||
271 | /* FIXME - This only works for an MPEG-2 PS, not a TS */ | ||
272 | /* | ||
273 | * An MPEG-2 Program Stream (PS) is a series of | ||
274 | * MPEG-2 Program Packs terminated by an | ||
275 | * MPEG Program End Code after the last Program Pack. | ||
276 | * A Program Pack may hold a PS System Header packet and any | ||
277 | * number of Program Elementary Stream (PES) Packets | ||
278 | */ | ||
263 | const char *start = buf->buf + buf->readpos; | 279 | const char *start = buf->buf + buf->readpos; |
264 | const char *p = start + 1; | 280 | const char *p = start + 1; |
265 | const u8 *q; | 281 | const u8 *q; |
@@ -267,38 +283,54 @@ static size_t cx18_copy_buf_to_user(struct cx18_stream *s, | |||
267 | int stuffing, i; | 283 | int stuffing, i; |
268 | 284 | ||
269 | while (start + len > p) { | 285 | while (start + len > p) { |
286 | /* Scan for a 0 to find a potential MPEG-2 start code */ | ||
270 | q = memchr(p, 0, start + len - p); | 287 | q = memchr(p, 0, start + len - p); |
271 | if (q == NULL) | 288 | if (q == NULL) |
272 | break; | 289 | break; |
273 | p = q + 1; | 290 | p = q + 1; |
291 | /* | ||
292 | * Keep looking if not a | ||
293 | * MPEG-2 Pack header start code: 0x00 0x00 0x01 0xba | ||
294 | * or MPEG-2 video PES start code: 0x00 0x00 0x01 0xe0 | ||
295 | */ | ||
274 | if ((char *)q + 15 >= buf->buf + buf->bytesused || | 296 | if ((char *)q + 15 >= buf->buf + buf->bytesused || |
275 | q[1] != 0 || q[2] != 1 || q[3] != ch) | 297 | q[1] != 0 || q[2] != 1 || q[3] != ch) |
276 | continue; | 298 | continue; |
299 | |||
300 | /* If expecting the primary video PES */ | ||
277 | if (!cx->search_pack_header) { | 301 | if (!cx->search_pack_header) { |
302 | /* Continue if it couldn't be a PES packet */ | ||
278 | if ((q[6] & 0xc0) != 0x80) | 303 | if ((q[6] & 0xc0) != 0x80) |
279 | continue; | 304 | continue; |
280 | if (((q[7] & 0xc0) == 0x80 && | 305 | /* Check if a PTS or PTS & DTS follow */ |
281 | (q[9] & 0xf0) == 0x20) || | 306 | if (((q[7] & 0xc0) == 0x80 && /* PTS only */ |
282 | ((q[7] & 0xc0) == 0xc0 && | 307 | (q[9] & 0xf0) == 0x20) || /* PTS only */ |
283 | (q[9] & 0xf0) == 0x30)) { | 308 | ((q[7] & 0xc0) == 0xc0 && /* PTS & DTS */ |
284 | ch = 0xba; | 309 | (q[9] & 0xf0) == 0x30)) { /* DTS follows */ |
310 | /* Assume we found the video PES hdr */ | ||
311 | ch = 0xba; /* next want a Program Pack*/ | ||
285 | cx->search_pack_header = 1; | 312 | cx->search_pack_header = 1; |
286 | p = q + 9; | 313 | p = q + 9; /* Skip this video PES hdr */ |
287 | } | 314 | } |
288 | continue; | 315 | continue; |
289 | } | 316 | } |
317 | |||
318 | /* We may have found a Program Pack start code */ | ||
319 | |||
320 | /* Get the count of stuffing bytes & verify them */ | ||
290 | stuffing = q[13] & 7; | 321 | stuffing = q[13] & 7; |
291 | /* all stuffing bytes must be 0xff */ | 322 | /* all stuffing bytes must be 0xff */ |
292 | for (i = 0; i < stuffing; i++) | 323 | for (i = 0; i < stuffing; i++) |
293 | if (q[14 + i] != 0xff) | 324 | if (q[14 + i] != 0xff) |
294 | break; | 325 | break; |
295 | if (i == stuffing && | 326 | if (i == stuffing && /* right number of stuffing bytes*/ |
296 | (q[4] & 0xc4) == 0x44 && | 327 | (q[4] & 0xc4) == 0x44 && /* marker check */ |
297 | (q[12] & 3) == 3 && | 328 | (q[12] & 3) == 3 && /* marker check */ |
298 | q[14 + stuffing] == 0 && | 329 | q[14 + stuffing] == 0 && /* PES Pack or Sys Hdr */ |
299 | q[15 + stuffing] == 0 && | 330 | q[15 + stuffing] == 0 && |
300 | q[16 + stuffing] == 1) { | 331 | q[16 + stuffing] == 1) { |
301 | cx->search_pack_header = 0; | 332 | /* We declare we actually found a Program Pack*/ |
333 | cx->search_pack_header = 0; /* expect vid PES */ | ||
302 | len = (char *)q - start; | 334 | len = (char *)q - start; |
303 | cx18_setup_sliced_vbi_buf(cx); | 335 | cx18_setup_sliced_vbi_buf(cx); |
304 | break; | 336 | break; |