Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@

#include <sys/ioctl.h>

// ANSI C headers
#include <math.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <stdarg.h>
// ANSI C++ headers
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <cstdarg>

#ifdef USING_V4L2
// HACK. Broken kernel headers < 2.6.25 fail compile in videodev2.h when
Expand All @@ -25,7 +25,7 @@
// vbitext headers
#include "vt.h"
#include "vbi.h"
#include "hamm.h"
#include "vbilut.h"

#define FAC (1<<16) // factor for fix-point arithmetic

Expand All @@ -49,6 +49,22 @@ error(const char *str, ...)
va_end(ap);
}


static int
chk_parity(uint8_t *p, int n)
{
int err = 0;

for (err = 0; n--; p++)
{
if (hamm24par[0][*p] & 32)
*p &= 0x7f;
else
*p = BAD_CHAR, err++;
}
return err;
}

static void
out_of_sync(struct vbi *vbi)
{
Expand All @@ -66,8 +82,8 @@ static void
vbi_send(struct vbi *vbi, int type, int i1, int i2, int i3, void *p1)
{
struct vt_event ev[1];
struct vbi_client *cl = NULL;
struct vbi_client *cln = NULL;
struct vbi_client *cl = nullptr;
struct vbi_client *cln = nullptr;

ev->resource = vbi;
ev->type = type;
Expand All @@ -76,8 +92,9 @@ vbi_send(struct vbi *vbi, int type, int i1, int i2, int i3, void *p1)
ev->i3 = i3;
ev->p1 = p1;

for (cl = (void*)vbi->clients->first; (cln = (void*)cl->node->next);
(cl = cln))
for (cl = static_cast<vbi_client *>((void*)vbi->clients[0].first);
(cln = static_cast<vbi_client *>((void*)cl->node->next)) != nullptr;
cl = cln)
cl->handler(cl->data, ev);
}

Expand All @@ -88,7 +105,7 @@ vbi_send_page(struct vbi *vbi, struct raw_page *rvtp, int page)
{
if (rvtp->page->pgno % 256 != page)
{
struct vt_page *cvtp = 0;
struct vt_page *cvtp = nullptr;
rvtp->page->flags &= ~PG_ACTIVE;
do_enhancements(rvtp->enh, rvtp->page);
// if (vbi->cache)
Expand Down Expand Up @@ -168,8 +185,8 @@ vbi_pll_reset(struct vbi *vbi, int fine_tune)
static int
vt_line(struct vbi *vbi, unsigned char *p)
{
struct vt_page *cvtp = NULL;
struct raw_page *rvtp = NULL;
struct vt_page *cvtp = nullptr;
struct raw_page *rvtp = nullptr;
int err = 0;

int hdr = hamm16(p, &err);
Expand Down Expand Up @@ -442,11 +459,11 @@ vbi_handler(struct vbi *vbi, int fd)


int
vbi_add_handler(struct vbi *vbi, void *handler, void *data)
vbi_add_handler(struct vbi *vbi, vbic_handler handler, void *data)
{
struct vbi_client *cl = NULL;
struct vbi_client *cl = nullptr;

if (!(cl = malloc(sizeof(*cl))))
if (!(cl = static_cast<vbi_client*>(malloc(sizeof(*cl)))))
return -1;
cl->handler = handler;
cl->data = data;
Expand All @@ -460,11 +477,13 @@ vbi_add_handler(struct vbi *vbi, void *handler, void *data)


void
vbi_del_handler(struct vbi *vbi, void *handler, void *data)
vbi_del_handler(struct vbi *vbi, vbic_handler handler, void *data)
{
struct vbi_client *cl = NULL;
struct vbi_client *cl = nullptr;

for (cl = (void*) vbi->clients->first; cl->node->next; cl = (void*) cl->node->next)
for (cl = static_cast<vbi_client*>((void*)vbi->clients->first);
cl->node->next != nullptr;
cl = static_cast<vbi_client*>((void*)cl->node->next))
{
if (cl->handler == handler && cl->data == data)
{
Expand Down Expand Up @@ -535,7 +554,7 @@ static int
setup_dev(struct vbi *vbi)
{
#ifdef USING_V4L2
struct v4l2_format v4l2_format;
struct v4l2_format v4l2_format {};
struct v4l2_vbi_format *vbifmt = &v4l2_format.fmt.vbi;

memset(&v4l2_format, 0, sizeof(v4l2_format));
Expand Down Expand Up @@ -588,8 +607,10 @@ setup_dev(struct vbi *vbi)
{
if (rawbuf)
free(rawbuf);
if (!(rawbuf = malloc(rawbuf_size = vbi->bufsize)))
if (!(rawbuf = static_cast<u_char*>(malloc(rawbuf_size = vbi->bufsize))))
{
error("malloc refused in setup_dev()\n");
}
}

return 0;
Expand All @@ -605,15 +626,16 @@ struct vbi *
vbi_open(const char *vbi_dev_name, struct cache *ca, int fine_tune, int big_buf)
{
static int s_inited = 0;
struct vbi *vbi = 0;
struct vbi *vbi = nullptr;

(void)ca;

if (! s_inited)
lang_init();
s_inited = 1;

if (!(vbi = malloc(sizeof(*vbi))))
vbi = static_cast<struct vbi *>(malloc(sizeof(*vbi)));
if (vbi == nullptr)
{
error("out of memory");
goto fail1;
Expand Down Expand Up @@ -647,7 +669,7 @@ vbi_open(const char *vbi_dev_name, struct cache *ca, int fine_tune, int big_buf)
fail2:
free(vbi);
fail1:
return 0;
return nullptr;
}


Expand Down Expand Up @@ -686,7 +708,7 @@ vbi_query_page(struct vbi *vbi, int pgno, int subno)
(void)vbi;
(void)pgno;
(void)subno;
return NULL;
return nullptr;
#endif
}

Expand All @@ -695,6 +717,6 @@ vbi_reset(struct vbi *vbi)
{
// if (vbi->cache)
// vbi->cache->op->reset(vbi->cache);
vbi_send(vbi, EV_RESET, 0, 0, 0, 0);
vbi_send(vbi, EV_RESET, 0, 0, 0, nullptr);
}

16 changes: 5 additions & 11 deletions mythtv/libs/libmythtv/recorders/vbitext/vbi.h
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
#ifndef VBI_H
#define VBI_H

#ifdef __cplusplus
extern "C" {
#endif

#include "vt.h"
#include "dllist.h"
#include "lang.h"
Expand Down Expand Up @@ -42,27 +38,25 @@ struct vbi
int soc, eoc; // start/end of clock run-in
};

using vbic_handler = void (*)(void *data, struct vt_event *ev);

struct vbi_client
{
struct dl_node node[1];
void (*handler)(void *data, struct vt_event *ev);
vbic_handler handler;
void *data;
};

struct vbi *vbi_open(const char *vbi_dev_name, struct cache *ca, int fine_tune,
int big_buf);
void vbi_close(struct vbi *vbi);
void vbi_reset(struct vbi *vbi);
int vbi_add_handler(struct vbi *vbi, void *handler, void *data);
void vbi_del_handler(struct vbi *vbi, void *handler, void *data);
int vbi_add_handler(struct vbi *vbi, vbic_handler handler, void *data);
void vbi_del_handler(struct vbi *vbi, vbic_handler handler, void *data);
struct vt_page *vbi_query_page(struct vbi *vbi, int pgno, int subno);
void vbi_pll_reset(struct vbi *vbi, int fine_tune);

void vbi_handler(struct vbi *vbi, int fd);

#ifdef __cplusplus
}
#endif

#endif

11 changes: 9 additions & 2 deletions mythtv/libs/libmythtv/vbilut.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#include <vbilut.h>

extern "C" {
const unsigned char lang_chars[1+8+8][16] =
{
{ 0, 0x23,0x24,0x40,0x5b,0x5c,0x5d,0x5e,0x5f,0x60,0x7b,0x7c,0x7d,0x7e },
Expand Down Expand Up @@ -41,7 +40,6 @@ const unsigned char lang_chars[1+8+8][16] =
// Rumanian (95%)
{ 0, 0x23,0xa2,0xde,0xc2,0xaa,0xc3,0xce,0x69,0xfe,0xe2,0xba,0xe3,0xee }, // #¢ÞªÃÎiþâºãî
};
}

// TODO - Add the rest...page 107
const unsigned char chartab_original[13] =
Expand Down Expand Up @@ -350,3 +348,12 @@ int hamm16(const uint8_t *p, int *err)
*err += b;
return (a & 15) | (b & 15) * 16;
}

int hamm24(const uint8_t *p, int *err)
{
int e = hamm24par[0][p[0]] ^ hamm24par[1][p[1]] ^ hamm24par[2][p[2]];
int x = hamm24val[p[0]] + p[1] % 128 * 16 + p[2] % 128 * 2048;

*err += hamm24err[e];
return x ^ hamm24cor[e];
}
3 changes: 2 additions & 1 deletion mythtv/libs/libmythtv/vbilut.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

#include <cstdint>

extern "C" const unsigned char lang_chars[][16];
extern const unsigned char lang_chars[][16];
extern const unsigned char chartab_original[];
extern const char chartab_swedish[];
extern const unsigned short hammtab[];
Expand All @@ -27,5 +27,6 @@ enum vbimode
int hamm8(const uint8_t *p, int *err);
int hamm84(const uint8_t *p, int *err);
int hamm16(const uint8_t *p, int *err);
int hamm24(const uint8_t *p, int *err);

#endif // _VBILUT_H_