[mythtv] Re: Teletext [PATCH]

Martin Moeller martin at martinm-76.dk
Fri Jul 25 16:06:14 EDT 2003


Okay folks,

Here is take one of the teletext reanimation.
I am currently operation on the assumption that the memory issues are
driver related and not a part of the code in MythTV. Hopefully someone
with a bttv supported card can test this?

I have included two versions of the patch, one which prints out when it
finds a subtitle page and one that does not.

I have yet to see the result of actual captured data, but the
preliminary tests indicate that is should work.

Many thanks to Erik Arendse for all his help and the generalt good
fortune that made it possible for me to do this knowing almost nothing
about C/C++..

Feedback would be a very nice thing, even if I may not be able to solve
problems. Please report if this works/doesn't work for you (if
applicable).

/Martin.
-- 
Martin Moeller <martin at martinm-76.dk>
-------------- next part --------------
? programs/menutest/Makefile
? programs/menutest/menutest
Index: libs/libmythtv/NuppelVideoRecorder.cpp
===================================================================
RCS file: /var/lib/mythcvs/mythtv/libs/libmythtv/NuppelVideoRecorder.cpp,v
retrieving revision 1.128
diff -u -w -r1.128 NuppelVideoRecorder.cpp
--- libs/libmythtv/NuppelVideoRecorder.cpp	18 Jul 2003 20:10:58 -0000	1.128
+++ libs/libmythtv/NuppelVideoRecorder.cpp	25 Jul 2003 12:59:32 -0000
@@ -2100,9 +2100,10 @@
        case EV_PAGE:
        {
             struct vt_page *vtp = (struct vt_page *) ev->p1;
+                //printf("subtitle page %x.%x\n", vtp->pgno, vtp->subno); /* Super debug: If teletext working at all? */
             if (vtp->flags & PG_SUBTITLE)
             {
-                //printf("subtitle page %x.%x\n", vtp->pgno, vtp->subno);
+                //printf("subtitle page %x.%x\n", vtp->pgno, vtp->subno); /* Debug: Are we getting any subtitles? */
                 data->foundteletextpage = true;
                 memcpy(&(data->teletextpage), vtp, sizeof(vt_page));
             }
Index: libs/libmythtv/recorderbase.cpp
===================================================================
RCS file: /var/lib/mythcvs/mythtv/libs/libmythtv/recorderbase.cpp,v
retrieving revision 1.6
diff -u -w -r1.6 recorderbase.cpp
--- libs/libmythtv/recorderbase.cpp	6 Jun 2003 15:41:29 -0000	1.6
+++ libs/libmythtv/recorderbase.cpp	25 Jul 2003 12:59:32 -0000
@@ -85,9 +85,9 @@
     }
     else if (name == "vbiformat")
     {
-        //if (value.lower() == "pal teletext")
-        //    vbimode = 1;
-        //else 
+        if (value.lower() == "pal teletext")
+            vbimode = 1;
+        else 
         if (value.lower().left(4) == "ntsc")
             vbimode = 2;
         else
Index: libs/libvbitext/dllist.h
===================================================================
RCS file: /var/lib/mythcvs/mythtv/libs/libvbitext/dllist.h,v
retrieving revision 1.1
diff -u -w -r1.1 dllist.h
--- libs/libvbitext/dllist.h	31 Jan 2003 14:35:48 -0000	1.1
+++ libs/libvbitext/dllist.h	25 Jul 2003 12:59:32 -0000
@@ -51,4 +51,3 @@
 #define dl_remove_last(h)       dl_remove((h)->last) // mustn't be empty!
 
 #endif /* DLLIST_H */
-
Index: libs/libvbitext/vbi.c
===================================================================
RCS file: /var/lib/mythcvs/mythtv/libs/libvbitext/vbi.c,v
retrieving revision 1.1
diff -u -w -r1.1 vbi.c
--- libs/libvbitext/vbi.c	31 Jan 2003 14:35:49 -0000	1.1
+++ libs/libvbitext/vbi.c	25 Jul 2003 12:59:33 -0000
@@ -6,7 +6,9 @@
 #include <sys/ioctl.h>
 //#include "os.h"
 #include "vt.h"
+//#include "misc.h"
 #include "vbi.h"
+//#include "fdset.h"
 #include "hamm.h"
 //#include "lang.h"
 
@@ -24,13 +26,24 @@
 
 /***** v4l2 vbi-api *****/
 
+/* #include "/usr/src/linux/include/linux/videodev2.h" */
+
+enum v4l2_buf_type {
+	V4L2_BUF_TYPE_VIDEO_CAPTURE  = 1,
+	V4L2_BUF_TYPE_VIDEO_OUTPUT   = 2,
+	V4L2_BUF_TYPE_VIDEO_OVERLAY  = 3,
+	V4L2_BUF_TYPE_VBI_CAPTURE    = 4,
+	V4L2_BUF_TYPE_VBI_OUTPUT     = 5,
+	V4L2_BUF_TYPE_PRIVATE        = 0x80,
+};
+
 struct v4l2_vbi_format
 {
     unsigned int sampling_rate;                /* in 1 Hz */
     unsigned int offset;                       /* sampling starts # samples after rising hs */
     unsigned int samples_per_line;
     unsigned int sample_format;                /* V4L2_VBI_SF_* */
-    int start[2];
+    signed int start[2];
     unsigned int count[2];
     unsigned int flags;                        /* V4L2_VBI_* */
     unsigned int reserved2;            /* must be zero */
@@ -38,7 +51,7 @@
 
 struct v4l2_format
 {
-    unsigned int       type;                   /* V4L2_BUF_TYPE_* */
+    enum v4l2_buf_type type;            /* V4L2_BUF_TYPE_* */
     union
     {
        struct v4l2_vbi_format vbi;     /*  VBI data  */
@@ -46,8 +59,7 @@
     } fmt;
 };
 
-#define V4L2_VBI_SF_UBYTE      1
-#define V4L2_BUF_TYPE_VBI       0x00000009
+#define V4L2_PIX_FMT_GREY     0x59455247 /* v4l2_fourcc('G','R','E','Y') *//*  8  Greyscale     */
 #define VIDIOC_G_FMT           _IOWR('V',  4, struct v4l2_format)
 
 /***** end of api definitions *****/
@@ -138,10 +150,6 @@
            vbi->pll_dir = -1;
            vbi->pll_lerr = 0;
        }
-
-#ifdef DEBUG
-           printf("pll_adj = %2d\n", vbi->pll_adj);
-#endif
     }
     vbi->pll_cnt = 0;
     vbi->pll_err = 0;
@@ -159,12 +167,7 @@
     vbi->pll_adj = 0;
     if (vbi->pll_fixed)
        vbi->pll_adj = fine_tune;
-#ifdef DEBUG
-       if (vbi->pll_fixed)
-           printf("pll_reset (fixed@%d)\n", vbi->pll_adj);
-       else
            printf("pll_reset (auto)\n");
-#endif
 }
 
 // process one videotext packet
@@ -253,7 +256,6 @@
            if (~cvtp->flags & PG_ACTIVE)
                return 0;
 
-
            d = hamm8(p, &err);
            if (err & 0xf000)
                return 4;
@@ -424,8 +426,19 @@
     vbi->seq = seq;
 
     if (seq > 1)       // the first may contain data from prev channel
+    {
+#if 1
        for (i = 0; i+vbi->bpl <= n; i += vbi->bpl)
            vbi_line(vbi, rawbuf + i);
+#else
+        /* work-around for old saa7134 driver versions (prior 0.2.6) */
+	for (i = 16 * vbi->bpl; i + vbi->bpl <= n; i += vbi->bpl)
+	    vbi_line(vbi, rawbuf + i);
+
+	for (i = 0; i + vbi->bpl <= 16 * vbi->bpl; i += vbi->bpl)
+	    vbi_line(vbi, rawbuf + i);
+#endif
+    }
 }
 
 
@@ -469,8 +482,9 @@
     int soc, eoc;      // start/end of clock run-in
     int bpl;           // bytes per line
 
-    if (p->sample_format != V4L2_VBI_SF_UBYTE)
+    if (p->sample_format != V4L2_PIX_FMT_GREY)
     {
+        fprintf(stderr, "got pix fmt %x\n", p->sample_format);
        error("v4l2: unsupported vbi data format");
        return -1;
     }
@@ -527,13 +541,15 @@
     struct v4l2_format v4l2_format[1];
     struct v4l2_vbi_format *vbifmt = &v4l2_format->fmt.vbi;
 
-    if (ioctl(vbi->fd, VIDIOC_G_FMT, v4l2_format) == -1
-       || v4l2_format->type != V4L2_BUF_TYPE_VBI)
+    memset(&v4l2_format, 0, sizeof(v4l2_format));
+    v4l2_format->type = V4L2_BUF_TYPE_VBI_CAPTURE;
+    if (ioctl(vbi->fd, VIDIOC_G_FMT, v4l2_format) == -1)
     {
        // not a v4l2 device.  assume bttv and create a standard fmt-struct.
        int size;
+        perror("ioctl VIDIOC_G_FMT");
 
-       vbifmt->sample_format = V4L2_VBI_SF_UBYTE;
+	vbifmt->sample_format = V4L2_PIX_FMT_GREY;
        vbifmt->sampling_rate = 35468950;
        vbifmt->samples_per_line = 2048;
        vbifmt->offset = 244;
@@ -663,4 +679,3 @@
 //     vbi->cache->op->reset(vbi->cache);
     vbi_send(vbi, EV_RESET, 0, 0, 0, 0);
 }
-
-------------- next part --------------
? programs/menutest/Makefile
? programs/menutest/menutest
Index: libs/libmythtv/NuppelVideoRecorder.cpp
===================================================================
RCS file: /var/lib/mythcvs/mythtv/libs/libmythtv/NuppelVideoRecorder.cpp,v
retrieving revision 1.128
diff -u -w -r1.128 NuppelVideoRecorder.cpp
--- libs/libmythtv/NuppelVideoRecorder.cpp	18 Jul 2003 20:10:58 -0000	1.128
+++ libs/libmythtv/NuppelVideoRecorder.cpp	25 Jul 2003 12:57:13 -0000
@@ -2100,9 +2100,10 @@
        case EV_PAGE:
        {
             struct vt_page *vtp = (struct vt_page *) ev->p1;
+                //printf("subtitle page %x.%x\n", vtp->pgno, vtp->subno); /* Super debug: If teletext working at all? */
             if (vtp->flags & PG_SUBTITLE)
             {
-                //printf("subtitle page %x.%x\n", vtp->pgno, vtp->subno);
+                printf("subtitle page %x.%x\n", vtp->pgno, vtp->subno); /* Debug: Are we getting any subtitles? */
                 data->foundteletextpage = true;
                 memcpy(&(data->teletextpage), vtp, sizeof(vt_page));
             }
Index: libs/libmythtv/recorderbase.cpp
===================================================================
RCS file: /var/lib/mythcvs/mythtv/libs/libmythtv/recorderbase.cpp,v
retrieving revision 1.6
diff -u -w -r1.6 recorderbase.cpp
--- libs/libmythtv/recorderbase.cpp	6 Jun 2003 15:41:29 -0000	1.6
+++ libs/libmythtv/recorderbase.cpp	25 Jul 2003 12:57:13 -0000
@@ -85,9 +85,9 @@
     }
     else if (name == "vbiformat")
     {
-        //if (value.lower() == "pal teletext")
-        //    vbimode = 1;
-        //else 
+        if (value.lower() == "pal teletext")
+            vbimode = 1;
+        else 
         if (value.lower().left(4) == "ntsc")
             vbimode = 2;
         else
Index: libs/libvbitext/dllist.h
===================================================================
RCS file: /var/lib/mythcvs/mythtv/libs/libvbitext/dllist.h,v
retrieving revision 1.1
diff -u -w -r1.1 dllist.h
--- libs/libvbitext/dllist.h	31 Jan 2003 14:35:48 -0000	1.1
+++ libs/libvbitext/dllist.h	25 Jul 2003 12:57:13 -0000
@@ -51,4 +51,3 @@
 #define dl_remove_last(h)       dl_remove((h)->last) // mustn't be empty!
 
 #endif /* DLLIST_H */
-
Index: libs/libvbitext/vbi.c
===================================================================
RCS file: /var/lib/mythcvs/mythtv/libs/libvbitext/vbi.c,v
retrieving revision 1.1
diff -u -w -r1.1 vbi.c
--- libs/libvbitext/vbi.c	31 Jan 2003 14:35:49 -0000	1.1
+++ libs/libvbitext/vbi.c	25 Jul 2003 12:57:14 -0000
@@ -6,7 +6,9 @@
 #include <sys/ioctl.h>
 //#include "os.h"
 #include "vt.h"
+//#include "misc.h"
 #include "vbi.h"
+//#include "fdset.h"
 #include "hamm.h"
 //#include "lang.h"
 
@@ -24,13 +26,24 @@
 
 /***** v4l2 vbi-api *****/
 
+/* #include "/usr/src/linux/include/linux/videodev2.h" */
+
+enum v4l2_buf_type {
+	V4L2_BUF_TYPE_VIDEO_CAPTURE  = 1,
+	V4L2_BUF_TYPE_VIDEO_OUTPUT   = 2,
+	V4L2_BUF_TYPE_VIDEO_OVERLAY  = 3,
+	V4L2_BUF_TYPE_VBI_CAPTURE    = 4,
+	V4L2_BUF_TYPE_VBI_OUTPUT     = 5,
+	V4L2_BUF_TYPE_PRIVATE        = 0x80,
+};
+
 struct v4l2_vbi_format
 {
     unsigned int sampling_rate;                /* in 1 Hz */
     unsigned int offset;                       /* sampling starts # samples after rising hs */
     unsigned int samples_per_line;
     unsigned int sample_format;                /* V4L2_VBI_SF_* */
-    int start[2];
+    signed int start[2];
     unsigned int count[2];
     unsigned int flags;                        /* V4L2_VBI_* */
     unsigned int reserved2;            /* must be zero */
@@ -38,7 +51,7 @@
 
 struct v4l2_format
 {
-    unsigned int       type;                   /* V4L2_BUF_TYPE_* */
+    enum v4l2_buf_type type;            /* V4L2_BUF_TYPE_* */
     union
     {
        struct v4l2_vbi_format vbi;     /*  VBI data  */
@@ -46,8 +59,7 @@
     } fmt;
 };
 
-#define V4L2_VBI_SF_UBYTE      1
-#define V4L2_BUF_TYPE_VBI       0x00000009
+#define V4L2_PIX_FMT_GREY     0x59455247 /* v4l2_fourcc('G','R','E','Y') *//*  8  Greyscale     */
 #define VIDIOC_G_FMT           _IOWR('V',  4, struct v4l2_format)
 
 /***** end of api definitions *****/
@@ -138,10 +150,6 @@
            vbi->pll_dir = -1;
            vbi->pll_lerr = 0;
        }
-
-#ifdef DEBUG
-           printf("pll_adj = %2d\n", vbi->pll_adj);
-#endif
     }
     vbi->pll_cnt = 0;
     vbi->pll_err = 0;
@@ -159,12 +167,7 @@
     vbi->pll_adj = 0;
     if (vbi->pll_fixed)
        vbi->pll_adj = fine_tune;
-#ifdef DEBUG
-       if (vbi->pll_fixed)
-           printf("pll_reset (fixed@%d)\n", vbi->pll_adj);
-       else
            printf("pll_reset (auto)\n");
-#endif
 }
 
 // process one videotext packet
@@ -253,7 +256,6 @@
            if (~cvtp->flags & PG_ACTIVE)
                return 0;
 
-
            d = hamm8(p, &err);
            if (err & 0xf000)
                return 4;
@@ -424,8 +426,19 @@
     vbi->seq = seq;
 
     if (seq > 1)       // the first may contain data from prev channel
+    {
+#if 1
        for (i = 0; i+vbi->bpl <= n; i += vbi->bpl)
            vbi_line(vbi, rawbuf + i);
+#else
+        /* work-around for old saa7134 driver versions (prior 0.2.6) */
+	for (i = 16 * vbi->bpl; i + vbi->bpl <= n; i += vbi->bpl)
+	    vbi_line(vbi, rawbuf + i);
+
+	for (i = 0; i + vbi->bpl <= 16 * vbi->bpl; i += vbi->bpl)
+	    vbi_line(vbi, rawbuf + i);
+#endif
+    }
 }
 
 
@@ -469,8 +482,9 @@
     int soc, eoc;      // start/end of clock run-in
     int bpl;           // bytes per line
 
-    if (p->sample_format != V4L2_VBI_SF_UBYTE)
+    if (p->sample_format != V4L2_PIX_FMT_GREY)
     {
+        fprintf(stderr, "got pix fmt %x\n", p->sample_format);
        error("v4l2: unsupported vbi data format");
        return -1;
     }
@@ -527,13 +541,15 @@
     struct v4l2_format v4l2_format[1];
     struct v4l2_vbi_format *vbifmt = &v4l2_format->fmt.vbi;
 
-    if (ioctl(vbi->fd, VIDIOC_G_FMT, v4l2_format) == -1
-       || v4l2_format->type != V4L2_BUF_TYPE_VBI)
+    memset(&v4l2_format, 0, sizeof(v4l2_format));
+    v4l2_format->type = V4L2_BUF_TYPE_VBI_CAPTURE;
+    if (ioctl(vbi->fd, VIDIOC_G_FMT, v4l2_format) == -1)
     {
        // not a v4l2 device.  assume bttv and create a standard fmt-struct.
        int size;
+        perror("ioctl VIDIOC_G_FMT");
 
-       vbifmt->sample_format = V4L2_VBI_SF_UBYTE;
+	vbifmt->sample_format = V4L2_PIX_FMT_GREY;
        vbifmt->sampling_rate = 35468950;
        vbifmt->samples_per_line = 2048;
        vbifmt->offset = 244;
@@ -663,4 +679,3 @@
 //     vbi->cache->op->reset(vbi->cache);
     vbi_send(vbi, EV_RESET, 0, 0, 0, 0);
 }
-


More information about the mythtv-dev mailing list