V4L/DVB (9806): cx18: Enable raw VBI capture
authorAndy Walls <awalls@radix.net>
Fri, 12 Dec 2008 23:00:29 +0000 (20:00 -0300)
committerMauro Carvalho Chehab <mchehab@redhat.com>
Tue, 30 Dec 2008 11:38:33 +0000 (09:38 -0200)
A combined authorship patch from Hans Verkuil and Andy Walls.  Raw
VBI can now be captured but requires a video capture to be in progress as well.

Signed-off-by: Andy Walls <awalls@radix.net>
Signed-off-by: Hans Verkuil <hverkuil@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
drivers/media/video/cx18/cx18-cards.c
drivers/media/video/cx18/cx18-cards.h
drivers/media/video/cx18/cx18-driver.c
drivers/media/video/cx18/cx18-fileops.c
drivers/media/video/cx18/cx18-streams.c
drivers/media/video/cx18/cx18-vbi.c

index fb9120d95f98ab6c593b8eaffa2d64977aa9e489..e274043657ddb01638b0c2155d1e4bb8ba84e7ee 100644 (file)
@@ -51,7 +51,7 @@ static struct cx18_card_tuner_i2c cx18_i2c_std = {
 static const struct cx18_card cx18_card_hvr1600_esmt = {
        .type = CX18_CARD_HVR_1600_ESMT,
        .name = "Hauppauge HVR-1600",
-       .comment = "VBI is not yet supported\n",
+       .comment = "Raw VBI supported; Sliced VBI is not yet supported\n",
        .v4l2_capabilities = CX18_CAP_ENCODER,
        .hw_audio_ctrl = CX18_HW_CX23418,
        .hw_muxer = CX18_HW_CS5345,
@@ -97,7 +97,7 @@ static const struct cx18_card cx18_card_hvr1600_esmt = {
 static const struct cx18_card cx18_card_hvr1600_samsung = {
        .type = CX18_CARD_HVR_1600_SAMSUNG,
        .name = "Hauppauge HVR-1600 (Preproduction)",
-       .comment = "VBI is not yet supported\n",
+       .comment = "Raw VBI supported; Sliced VBI is not yet supported\n",
        .v4l2_capabilities = CX18_CAP_ENCODER,
        .hw_audio_ctrl = CX18_HW_CX23418,
        .hw_muxer = CX18_HW_CS5345,
@@ -152,7 +152,7 @@ static const struct cx18_card_pci_info cx18_pci_h900[] = {
 static const struct cx18_card cx18_card_h900 = {
        .type = CX18_CARD_COMPRO_H900,
        .name = "Compro VideoMate H900",
-       .comment = "VBI is not yet supported\n",
+       .comment = "Raw VBI supported; Sliced VBI is not yet supported\n",
        .v4l2_capabilities = CX18_CAP_ENCODER,
        .hw_audio_ctrl = CX18_HW_CX23418,
        .hw_all = CX18_HW_TUNER,
@@ -249,7 +249,7 @@ static const struct cx18_card_pci_info cx18_pci_cnxt_raptor_pal[] = {
 static const struct cx18_card cx18_card_cnxt_raptor_pal = {
        .type = CX18_CARD_CNXT_RAPTOR_PAL,
        .name = "Conexant Raptor PAL/SECAM",
-       .comment = "VBI is not yet supported\n",
+       .comment = "Raw VBI supported; Sliced VBI is not yet supported\n",
        .v4l2_capabilities = CX18_CAP_ENCODER,
        .hw_audio_ctrl = CX18_HW_CX23418,
        .hw_muxer = CX18_HW_GPIO,
index a54aae9ed702cca8c582db5fa79d1966733c56d0..6fa7bcb42dded2376e8b6ade7d29efba1d4c5de9 100644 (file)
@@ -48,8 +48,9 @@
 
 /* V4L2 capability aliases */
 #define CX18_CAP_ENCODER (V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_TUNER | \
-                         V4L2_CAP_AUDIO | V4L2_CAP_READWRITE)
-/* | V4L2_CAP_VBI_CAPTURE | V4L2_CAP_SLICED_VBI_CAPTURE) not yet */
+                         V4L2_CAP_AUDIO | V4L2_CAP_READWRITE | \
+                         V4L2_CAP_VBI_CAPTURE)
+/* | V4L2_CAP_SLICED_VBI_CAPTURE) not yet */
 
 struct cx18_card_video_input {
        u8  video_type;         /* video input type */
index e845cd653bb87964ab609b688f8e21ddc33f58d3..863ebf06a829e44630fa62e171bf4dffd6ccbaa4 100644 (file)
@@ -596,13 +596,47 @@ static int __devinit cx18_init_struct1(struct cx18 *cx)
        /* VBI */
        cx->vbi.in.type = V4L2_BUF_TYPE_VBI_CAPTURE;
        cx->vbi.sliced_in = &cx->vbi.in.fmt.sliced;
-       cx->vbi.raw_size = 1456;
-       cx->vbi.raw_decoder_line_size = 1456;
-       cx->vbi.raw_decoder_sav_odd_field = 0x20;
-       cx->vbi.raw_decoder_sav_even_field = 0x60;
-       cx->vbi.sliced_decoder_line_size = 272;
-       cx->vbi.sliced_decoder_sav_odd_field = 0xB0;
-       cx->vbi.sliced_decoder_sav_even_field = 0xF0;
+
+       /*
+        * The VBI line sizes depend on the pixel clock and the horiz rate
+        *
+        * (1/Fh)*(2*Fp) = Samples/line
+        *     = 4 bytes EAV + Anc data in hblank + 4 bytes SAV + active samples
+        *
+        *  Sliced VBI is sent as ancillary data during horizontal blanking
+        *  Raw VBI is sent as active video samples during vertcal blanking
+        *
+        *  We use a  BT.656 pxiel clock of 13.5 MHz and a BT.656 active line
+        *  length of 720 pixels @ 4:2:2 sampling.  Thus...
+        *
+        *  For NTSC:
+        *
+        *  (1/15,734 kHz) * 2 * 13.5 MHz = 1716 samples/line =
+        *  4 bytes SAV + 268 bytes anc data + 4 bytes SAV + 1440 active samples
+        *
+        *  For PAL:
+        *
+        *  (1/15,625 kHz) * 2 * 13.5 MHz = 1728 samples/line =
+        *  4 bytes SAV + 280 bytes anc data + 4 bytes SAV + 1440 active samples
+        *
+        */
+
+       /* CX18-AV-Core number of VBI samples output per horizontal line */
+       cx->vbi.raw_decoder_line_size = 1444;   /* 4 byte SAV + 2 * 720 */
+       cx->vbi.sliced_decoder_line_size = 272; /* 60 Hz: 268+4, 50 Hz: 280+4 */
+
+       /* CX18-AV-Core VBI samples/line possibly rounded up */
+       cx->vbi.raw_size = 1444;   /* Real max size is 1444 */
+       cx->vbi.sliced_size = 284; /* Real max size is  284 */
+
+       /*
+        * CX18-AV-Core SAV/EAV RP codes in VIP 1.x mode
+        * Task Field VerticalBlank HorizontalBlank 0 0 0 0
+        */
+       cx->vbi.raw_decoder_sav_odd_field = 0x20;     /*   V  */
+       cx->vbi.raw_decoder_sav_even_field = 0x60;    /*  FV  */
+       cx->vbi.sliced_decoder_sav_odd_field = 0xB0;  /* T VH - actually EAV */
+       cx->vbi.sliced_decoder_sav_even_field = 0xF0; /* TFVH - actually EAV */
        return 0;
 }
 
@@ -635,6 +669,7 @@ static void __devinit cx18_init_struct2(struct cx18 *cx)
        cx->av_state.aud_input = CX18_AV_AUDIO8;
        cx->av_state.audclk_freq = 48000;
        cx->av_state.audmode = V4L2_TUNER_MODE_LANG1;
+       /* FIXME - 8 is NTSC value, investigate */
        cx->av_state.vbi_line_offset = 8;
 }
 
index 1856d59e0cf62791ce18be9525c4f661a5effaa6..425271a29517e91534e6762163ced38f61a0cbe7 100644 (file)
@@ -185,7 +185,9 @@ static struct cx18_buffer *cx18_get_buffer(struct cx18_stream *s, int non_block,
                            !test_bit(CX18_F_S_APPL_IO, &s_vbi->s_flags)) {
                                while ((buf = cx18_dequeue(s_vbi, &s_vbi->q_full))) {
                                        /* byteswap and process VBI data */
-/*                                     cx18_process_vbi_data(cx, buf, s_vbi->dma_pts, s_vbi->type); */
+                                       cx18_process_vbi_data(cx, buf,
+                                                             s_vbi->dma_pts,
+                                                             s_vbi->type);
                                        cx18_stream_put_buf_fw(s_vbi, buf);
                                }
                        }
index c87cd5369a4f228e0ead53cb08e18b193a9ce83d..985bad89f31142d39b034d7a4117b8d95c05d7ad 100644 (file)
@@ -358,8 +358,7 @@ static void cx18_vbi_setup(struct cx18_stream *s)
        cx18_av_cmd(cx, VIDIOC_S_FMT, &cx->vbi.in);
 
        /* determine number of lines and total number of VBI bytes.
-          A raw line takes 1443 bytes: 2 * 720 + 4 byte frame header - 1
-          The '- 1' byte is probably an unused U or V byte. Or something...
+          A raw line takes 1444 bytes: 4 byte SAV code + 2 * 720
           A sliced line takes 51 bytes: 4 byte frame header, 4 byte internal
           header, 42 data bytes + checksum (to be confirmed) */
        if (raw) {
@@ -377,14 +376,15 @@ static void cx18_vbi_setup(struct cx18_stream *s)
        /* Lines per field */
        data[1] = (lines / 2) | ((lines / 2) << 16);
        /* bytes per line */
-       data[2] = (raw ? cx->vbi.raw_size : cx->vbi.sliced_size);
+       data[2] = (raw ? cx->vbi.raw_decoder_line_size
+                      : cx->vbi.sliced_decoder_line_size);
        /* Every X number of frames a VBI interrupt arrives
           (frames as in 25 or 30 fps) */
        data[3] = 1;
        /* Setup VBI for the cx25840 digitizer */
        if (raw) {
                data[4] = 0x20602060;
-               data[5] = 0x30703070;
+               data[5] = 0x307090d0;
        } else {
                data[4] = 0xB0F0B0F0;
                data[5] = 0xA0E0A0E0;
index 03f0e81307fa2eb1dd34906f344be59a83985c63..fb595bd548e898f80d29f6d98982c3dfe8b91def 100644 (file)
@@ -165,6 +165,9 @@ void cx18_process_vbi_data(struct cx18 *cx, struct cx18_buffer *buf,
 
                cx18_buf_swap(buf);
 
+               /* Skip 12 bytes of header that gets stuffed in */
+               size -= 12;
+               memcpy(p, &buf->buf[12], size);
                type = p[3];
 
                size = buf->bytesused = compress_raw_buf(cx, p, size);