--- Makefile.orig Tue Aug 20 05:17:53 2002 +++ Makefile Fri Apr 9 16:00:16 2004 @@ -1,7 +1,8 @@ VER=1.6.1 -OPT=-O2 -s -#OPT=-O -g +#OPT=-O2 -s +OPT=-O -g DEFS=-DWITH_PNG +DEFS+=-DUSE_LIBZVBI FONT=vtxt # a smaller and thinner font #FONT=neep9 @@ -16,6 +17,10 @@ ifneq ($(findstring WITH_PNG,$(DEFS)),) EXPLIBS=-L/usr/local/lib -lpng -lz -lm endif +ifneq ($(findstring USE_LIBZVBI,$(DEFS)),) +ZVBILIB=-lzvbi -lpthread +EXPLIBS+=$(ZVBILIB) +endif all: alevt alevt-date alevt-cap alevt.1x alevt-date.1 alevt-cap.1 sync @@ -24,7 +29,7 @@ $(CC) $(OPT) $(OBJS) -o alevt -L/usr/X11R6/lib -lX11 $(EXPLIBS) alevt-date: $(TOBJS) - $(CC) $(OPT) $(TOBJS) -o alevt-date + $(CC) $(OPT) $(TOBJS) -o alevt-date $(ZVBILIB) alevt-cap: $(COBJS) $(CC) $(OPT) $(COBJS) -o alevt-cap $(EXPLIBS) --- vbi.c.orig 2001-03-03 19:14:03.000000000 +0100 +++ vbi.c 2006-01-07 20:42:05.130838200 +0100 @@ -12,12 +12,23 @@ #include "hamm.h" #include "lang.h" +#ifdef USE_LIBZVBI +# include +static vbi_capture * pZvbiCapt; +static vbi_raw_decoder * pZvbiRawDec; +static vbi_sliced * pZvbiData; +static vbi_proxy_client * pProxy; +# define ZVBI_BUFFER_COUNT 10 +# define ZVBI_TRACE 0 +#endif + #define FAC (1<<16) // factor for fix-point arithmetic static u8 *rawbuf; // one common buffer for raw vbi data. static int rawbuf_size; // its current size +#ifndef USE_LIBZVBI /***** bttv api *****/ #define BASE_VIDIOCPRIVATE 192 @@ -26,6 +37,17 @@ /***** 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 { u32 sampling_rate; /* in 1 Hz */ @@ -40,7 +62,7 @@ struct v4l2_format { - u32 type; /* V4L2_BUF_TYPE_* */ + enum v4l2_buf_type type; /* V4L2_BUF_TYPE_* */ union { struct v4l2_vbi_format vbi; /* VBI data */ @@ -48,11 +70,11 @@ } fmt; }; -#define V4L2_VBI_SF_UBYTE 1 -#define V4L2_BUF_TYPE_VBI 0x00000009 -#define VIDIOC_G_FMT _IOWR('V', 4, struct v4l2_format) +#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 *****/ +#endif // USE_LIBZVBI @@ -104,6 +126,7 @@ } } +#ifndef USE_LIBZVBI // fine tune pll // this routines tries to adjust the sampling point of the decoder. // it collects parity and hamming errors and moves the sampling point @@ -167,6 +190,17 @@ printf("pll_reset (auto)\n"); } +#else // USE_LIBZVBI +void +vbi_pll_reset(struct vbi *vbi, int fine_tune) +{ +} +static void +pll_add(struct vbi *vbi, int n, int err) +{ +} +#endif // USE_LIBZVBI + // process one videotext packet static int @@ -324,6 +358,7 @@ +#ifndef USE_LIBZVBI // process one raw vbi line static int @@ -394,7 +429,7 @@ } return -1; } - +#endif // USE_LIBZVBI // called when new vbi data is waiting @@ -402,6 +437,7 @@ static void vbi_handler(struct vbi *vbi, int fd) { +#ifndef USE_LIBZVBI int n, i; u32 seq; @@ -423,8 +459,35 @@ vbi->seq = seq; if (seq > 1) // the first may contain data from prev channel + { for (i = 0; i+vbi->bpl <= n; i += vbi->bpl) vbi_line(vbi, rawbuf + i); + } + +#else // USE_LIBZVBI + double timestamp; + struct timeval timeout; + int lineCount; + int line; + int res; + + timeout.tv_sec = 0; + timeout.tv_usec = 25000; + res = vbi_capture_read_sliced(pZvbiCapt, pZvbiData, &lineCount, ×tamp, &timeout); + if (res > 0) + { + for (line=0; line < lineCount; line++) + { // dump all TTX packets, even non-EPG ones + if ((pZvbiData[line].id & VBI_SLICED_TELETEXT_B) != 0) + { + vt_line(vbi, pZvbiData[line].data); + } + } + } + else if (res < 0) + { // I/O error + } +#endif // USE_LIBZVBI } @@ -459,6 +522,7 @@ } +#ifndef USE_LIBZVBI static int set_decode_parms(struct vbi *vbi, struct v4l2_vbi_format *p) @@ -468,8 +532,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; } @@ -526,13 +591,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; @@ -576,6 +643,7 @@ return 0; } +#endif // USE_LIBZVBI struct vbi * @@ -583,6 +651,10 @@ { static int inited = 0; struct vbi *vbi; +#ifdef USE_LIBZVBI + char * pErrStr; + int services; +#endif if (not inited) lang_init(); @@ -594,6 +666,7 @@ goto fail1; } +#ifndef USE_LIBZVBI if ((vbi->fd = open(vbi_name, O_RDONLY)) == -1) { ioerror(vbi_name); @@ -606,14 +679,58 @@ if (setup_dev(vbi) == -1) goto fail3; + vbi_pll_reset(vbi, fine_tune); + vbi->seq = 0; + +#else // USE_LIBZVBI + services = VBI_SLICED_TELETEXT_B; + pErrStr = NULL; + vbi->fd = -1; + + pProxy = vbi_proxy_client_create(vbi_name, "alevt", VBI_PROXY_CLIENT_NO_STATUS_IND, &pErrStr, ZVBI_TRACE); + if (pProxy != NULL) + { + pZvbiCapt = vbi_capture_proxy_new(pProxy, ZVBI_BUFFER_COUNT, 0, &services, 0, &pErrStr); + if (pZvbiCapt == NULL) + { + vbi_proxy_client_destroy(pProxy); + pProxy = NULL; + } + } + if (pZvbiCapt == NULL) + pZvbiCapt = vbi_capture_v4l2_new(vbi_name, ZVBI_BUFFER_COUNT, &services, 0, &pErrStr, ZVBI_TRACE); + if (pZvbiCapt == NULL) + pZvbiCapt = vbi_capture_v4l_new(vbi_name, 0, &services, 0, &pErrStr, ZVBI_TRACE); + + if (pZvbiCapt != NULL) + { + pZvbiRawDec = vbi_capture_parameters(pZvbiCapt); + if ((pZvbiRawDec != NULL) && ((services & VBI_SLICED_TELETEXT_B) != 0)) + { + pZvbiData = malloc((pZvbiRawDec->count[0] + pZvbiRawDec->count[1]) * sizeof(*pZvbiData)); + + vbi->fd = vbi_capture_fd(pZvbiCapt);; + } + else + vbi_capture_delete(pZvbiCapt); + } + + if (pErrStr != NULL) + { + fprintf(stderr, "libzvbi: %s\n", pErrStr); + free(pErrStr); + } + + if (vbi->fd == -1) + goto fail2; +#endif + vbi->cache = ca; dl_init(vbi->clients); - vbi->seq = 0; out_of_sync(vbi); vbi->ppage = vbi->rpage; - vbi_pll_reset(vbi, fine_tune); fdset_add_fd(fds, vbi->fd, vbi_handler, vbi); return vbi; @@ -633,7 +750,27 @@ fdset_del_fd(fds, vbi->fd); if (vbi->cache) vbi->cache->op->close(vbi->cache); + +#ifndef USE_LIBZVBI close(vbi->fd); + +#else // USE_LIBZVBI + if (pZvbiData != NULL) + free(pZvbiData); + pZvbiData = NULL; + + if (pZvbiCapt != NULL) + { + vbi_capture_delete(pZvbiCapt); + pZvbiCapt = NULL; + } + if (pProxy != NULL) + { + vbi_proxy_client_destroy(pProxy); + pProxy = NULL; + } +#endif + free(vbi); } @@ -661,4 +798,9 @@ if (vbi->cache) vbi->cache->op->reset(vbi->cache); vbi_send(vbi, EV_RESET, 0, 0, 0, 0); + +#ifdef USE_LIBZVBI + if (pZvbiRawDec != NULL) + vbi_raw_decoder_reset(pZvbiRawDec); +#endif }