Hans,

Since you're going to release a new ivtv-utils soon: could you include
the functionality in the attached patches?

The *patch2 file is just a stripped down and renamed videodev2.h header
file for the ivtv VBI private packet payload definitions.  If you're
fixing up the types so videodev2.h can be included without the compile
errors, then this custom header may not be needed.

Thanks.

Regards,
Andy
--- ivtv-utils-1.3.0/test/ps-analyzer.cpp.orig	2008-08-19 16:06:31.000000000 -0400
+++ ivtv-utils-1.3.0/test/ps-analyzer.cpp	2009-05-15 11:29:02.000000000 -0400
@@ -4,6 +4,9 @@
 #
 # Copyright (C) 2001-2003 Kees Cook
 # [email protected], http://outflux.net/
+#
+# Sliced VBI decoding and conversion of scr, pts and dts to seconds is ...
+# Copyright (C) 2009 Andy Walls
 # 
 # This program is free software; you can redistribute it and/or
 # modify it under the terms of the GNU General Public License
@@ -39,6 +42,7 @@
 #include <string.h>
 #include <errno.h>
 #include "mpeg2structs.h"
+#include "ivtv-vbi-fmt.h"
 
 typedef unsigned long long u64;
 typedef unsigned int u32;
@@ -93,17 +97,83 @@
     return (buf[0] << 8) | buf[1];
 }
 
-static void vbi_decode(u8 *buf, int length)
+static const char *vbi_line_id(u8 id)
 {
-	if (!memcmp(buf, "ITV0", 4)) {
-		printf("36 lines ");
-		return;
+	const char *ret;
+
+	switch (id) {
+	case V4L2_MPEG_VBI_IVTV_TELETEXT_B:
+		ret = "Teletext B";
+		break;
+	case V4L2_MPEG_VBI_IVTV_CAPTION_525:
+		ret = "Closed Caption (525 line system)";
+		break;
+	case V4L2_MPEG_VBI_IVTV_WSS_625:
+		ret = "Wide Screen Signalling (625 line system)";
+		break;
+	case V4L2_MPEG_VBI_IVTV_VPS:
+		ret = "Video Programming System";
+		break;
+	default:
+		ret = "unknown";
+		break;
 	}
-	if (memcmp(buf, "itv0", 4)) {
+	return ret;
+}
+
+static void vbi_decode(u8 *buf, int length)
+{
+	struct v4l2_mpeg_vbi_fmt_ivtv *vbi;
+	u32 linemask[2];
+	struct v4l2_mpeg_vbi_itv0_line *line;
+	int i, f, l; 
+
+	vbi = (struct v4l2_mpeg_vbi_fmt_ivtv *) buf;
+
+	if (!memcmp(vbi->magic,
+			V4L2_MPEG_VBI_IVTV_MAGIC1, sizeof(vbi->magic))) {
+		printf("36 lines:\n");
+		line = vbi->ITV0.line;
+		/* This only works for little endian machines */
+		linemask[0] = 0xffffffff;
+		linemask[1] = 0x0000000f;
+	} else if (!memcmp(vbi->magic,
+			V4L2_MPEG_VBI_IVTV_MAGIC0, sizeof(vbi->magic))) {
+		printf("<36 lines:\n");
+		line = vbi->itv0.line;
+		/* This only works for little endian machines */
+		linemask[0] = vbi->itv0.linemask[0];
+		linemask[1] = vbi->itv0.linemask[1];
+	} else {
 		printf("unknown ");
 		return;
 	}
-	printf("<36 lines ");
+
+	i = 0;
+	for (f = 1; f <= 2; f++) {
+		for (l = 6; l <= 23; l++) {
+			if (linemask[0] & 1) {
+				printf("\t\tfield %d, line %2d: %s\n",
+				       f, l, vbi_line_id(line[i].id));
+				i++;
+			}
+			linemask[0] >>= 1;
+		}
+		linemask[0] |= (linemask[1] << (32 - (23-6+1)));
+		linemask[1] = 0;
+	}
+	printf("\t\t");
+	return;
+}
+
+u64 scr2ns(u64 scr, unsigned scr_ext)
+{
+	return (300*scr + scr_ext)*1000/27;
+}
+
+u64 xts2us(u64 xts)
+{
+	return (100*xts)/9;
 }
 
 static void pack_header(int fh, u64 pos)
@@ -130,7 +200,7 @@
 	mux_rate |= hdr[7] << 7;
 	mux_rate |= (hdr[8] & 0xfe) >> 1;
 	if (g_verbose)
-		printf("%lld: pack scr=%lld scr_ext=%u mux_rate=%u\n", pos, scr, scr_ext, mux_rate);
+		printf("%lld: pack scr=%lld scr_ext=%3u scr=%lld ns mux_rate=%u\n", pos, scr, scr_ext, scr2ns(scr, scr_ext), mux_rate);
 
 	marker = psread_u32(fh);
 	if (marker != 0x000001bb) {
@@ -166,7 +236,8 @@
 	u64 pts = 0;
 	u64 dts = 0;
 
-	psread(fh, hdr, 13);
+	psread(fh, hdr, 3); /* flags, flags, PES header data length */
+	psread(fh, &(hdr[3]), hdr[2]);
 	if (hdr[1] & 0x80) {
 		pts = (u64)(hdr[3] & 0xe) << 29;
 		pts |= (u64)(hdr[4]) << 22;
@@ -189,10 +260,11 @@
 	}
 	else if (code == 0xbd) {
 		u8 buf[2048];
+		u16 remaining = length - (3 + hdr[2]);
 		printf("\t%lld: Private Packet ", pos);
-		if (length <= sizeof(buf) + 8) {
-			psread(fh, buf, length - 8);
-			vbi_decode(buf + 2, length - 10);
+		if (remaining <= sizeof(buf)) {
+			psread(fh, buf, remaining);
+			vbi_decode(buf, remaining);
 		}
 		g_vbi_count++;
 	}
@@ -203,9 +275,11 @@
 		g_last_vid_pts = pts;
 	}
 	if (dts)
-		printf("pts=%llu dts=%llu length=%d\n", pts, dts, length);
+		printf("pts=%llu (%llu us) dts=%llu (%llu us) length=%d\n",
+			pts, xts2us(pts), dts, xts2us(dts), length);
 	else
-		printf("pts=%llu length=%d\n", pts, length);
+		printf("pts=%llu (%lld us) length=%d\n",
+			pts, xts2us(pts), length);
 }
 
 int main(int argc, char *argv[])
--- /dev/null	2009-05-15 06:51:47.442133524 -0400
+++ ivtv-utils-1.3.0/test/ivtv-vbi-fmt.h	2009-05-15 10:05:03.000000000 -0400
@@ -0,0 +1,101 @@
+/*
+ *  Dervied from linux/include/linux/videodev2.h
+ *
+ *  Copyright (C) 1999-2007 the contributors
+ *  Copyright (C) 2009 Andy Walls <[email protected]>
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  Alternatively you can redistribute this file under the terms of the
+ *  BSD license as stated below:
+ *
+ *  Redistribution and use in source and binary forms, with or without
+ *  modification, are permitted provided that the following conditions
+ *  are met:
+ *  1. Redistributions of source code must retain the above copyright
+ *     notice, this list of conditions and the following disclaimer.
+ *  2. Redistributions in binary form must reproduce the above copyright
+ *     notice, this list of conditions and the following disclaimer in
+ *     the documentation and/or other materials provided with the
+ *     distribution.
+ *  3. The names of its contributors may not be used to endorse or promote
+ *     products derived from this software without specific prior written
+ *     permission.
+ *
+ *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ *  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ *  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
+ *  TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ *  PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ *  LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ *  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ *  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *	See http://linuxtv.org for more info
+ *
+ *	Author: Bill Dirks <[email protected]>
+ *		Justin Schoeman
+ *              Hans Verkuil <[email protected]>
+ *		et al.
+ */
+
+typedef unsigned int __le32; /* little endian 32 bits */
+typedef unsigned char __u8;
+
+/*
+ * Sliced VBI data inserted into MPEG Streams
+ */
+
+/*
+ * V4L2_MPEG_STREAM_VBI_FMT_IVTV:
+ *
+ * Structure of payload contained in an MPEG 2 Private Stream 1 PES Packet in an
+ * MPEG-2 Program Pack that contains V4L2_MPEG_STREAM_VBI_FMT_IVTV Sliced VBI
+ * data
+ *
+ * Note, the MPEG-2 Program Pack and Private Stream 1 PES packet header
+ * definitions are not included here.  See the MPEG-2 specifications for details
+ * on these headers.
+ */
+
+/* Line type IDs */
+#define V4L2_MPEG_VBI_IVTV_TELETEXT_B     (1)
+#define V4L2_MPEG_VBI_IVTV_CAPTION_525    (4)
+#define V4L2_MPEG_VBI_IVTV_WSS_625        (5)
+#define V4L2_MPEG_VBI_IVTV_VPS            (7)
+
+struct v4l2_mpeg_vbi_itv0_line {
+	__u8 id;	/* One of V4L2_MPEG_VBI_IVTV_* above */
+	__u8 data[42];	/* Sliced VBI data for the line */
+} __attribute__ ((packed));
+
+struct v4l2_mpeg_vbi_itv0 {
+	__le32 linemask[2]; /* Bitmasks of VBI service lines present */
+	struct v4l2_mpeg_vbi_itv0_line line[35];
+} __attribute__ ((packed));
+
+struct v4l2_mpeg_vbi_ITV0 {
+	struct v4l2_mpeg_vbi_itv0_line line[36];
+} __attribute__ ((packed));
+
+#define V4L2_MPEG_VBI_IVTV_MAGIC0	"itv0"
+#define V4L2_MPEG_VBI_IVTV_MAGIC1	"ITV0"
+
+struct v4l2_mpeg_vbi_fmt_ivtv {
+	__u8 magic[4];
+	union {
+		struct v4l2_mpeg_vbi_itv0 itv0;
+		struct v4l2_mpeg_vbi_ITV0 ITV0;
+	};
+} __attribute__ ((packed));
_______________________________________________
ivtv-devel mailing list
[email protected]
http://ivtvdriver.org/mailman/listinfo/ivtv-devel

Reply via email to