From afe8de9326ab57eece4e956ff9b18004469d2907 Mon Sep 17 00:00:00 2001 From: David Hampton Date: Sat, 11 Jan 2020 21:01:10 -0500 Subject: [PATCH] Compile vbitext using C++. The files vbilut.cpp and recorders/vbitext/hamm.c were almost identical. Move two functions from hamm.c to other files, and then delete hamm.c. Otherwise these changes were mostly removing "extern C" declarations, a couple of changes from "0/NULL" to "nullptr", and a couple of additional casts. Also added a typedef for a callback pointer. --- mythtv/libs/libmythtv/libmythtv.pro | 6 +- .../libs/libmythtv/recorders/v4lrecorder.cpp | 7 +- mythtv/libs/libmythtv/recorders/vbitext/cc.h | 8 - .../libs/libmythtv/recorders/vbitext/dllist.h | 6 +- .../libs/libmythtv/recorders/vbitext/hamm.c | 240 ------------------ .../libs/libmythtv/recorders/vbitext/hamm.h | 18 -- .../recorders/vbitext/{lang.c => lang.cpp} | 7 +- .../libs/libmythtv/recorders/vbitext/lang.h | 10 +- .../recorders/vbitext/{vbi.c => vbi.cpp} | 76 ++++-- mythtv/libs/libmythtv/recorders/vbitext/vbi.h | 16 +- mythtv/libs/libmythtv/vbilut.cpp | 11 +- mythtv/libs/libmythtv/vbilut.h | 3 +- 12 files changed, 76 insertions(+), 332 deletions(-) delete mode 100644 mythtv/libs/libmythtv/recorders/vbitext/hamm.c delete mode 100644 mythtv/libs/libmythtv/recorders/vbitext/hamm.h rename mythtv/libs/libmythtv/recorders/vbitext/{lang.c => lang.cpp} (98%) rename mythtv/libs/libmythtv/recorders/vbitext/{vbi.c => vbi.cpp} (91%) diff --git a/mythtv/libs/libmythtv/libmythtv.pro b/mythtv/libs/libmythtv/libmythtv.pro index 1e86c56e7d9..8f4fc6faa57 100644 --- a/mythtv/libs/libmythtv/libmythtv.pro +++ b/mythtv/libs/libmythtv/libmythtv.pro @@ -89,14 +89,12 @@ using_valgrind:DEFINES += USING_VALGRIND !mingw:!win32-msvc* { HEADERS += recorders/vbitext/cc.h HEADERS += recorders/vbitext/dllist.h - HEADERS += recorders/vbitext/hamm.h HEADERS += recorders/vbitext/lang.h HEADERS += recorders/vbitext/vbi.h HEADERS += recorders/vbitext/vt.h SOURCES += recorders/vbitext/cc.cpp - SOURCES += recorders/vbitext/vbi.c - SOURCES += recorders/vbitext/hamm.c - SOURCES += recorders/vbitext/lang.c + SOURCES += recorders/vbitext/vbi.cpp + SOURCES += recorders/vbitext/lang.cpp } #} diff --git a/mythtv/libs/libmythtv/recorders/v4lrecorder.cpp b/mythtv/libs/libmythtv/recorders/v4lrecorder.cpp index 8bcf5a65121..8d53875a199 100644 --- a/mythtv/libs/libmythtv/recorders/v4lrecorder.cpp +++ b/mythtv/libs/libmythtv/recorders/v4lrecorder.cpp @@ -68,8 +68,9 @@ void V4LRecorder::SetOption(const QString &name, const QString &value) DTVRecorder::SetOption(name, value); } -static void vbi_event(struct VBIData *data, struct vt_event *ev) +static void vbi_event(void *data_in, struct vt_event *ev) { + struct VBIData *data = static_cast(data_in); switch (ev->type) { case EV_PAGE: @@ -115,7 +116,7 @@ int V4LRecorder::OpenVBIDevice(void) vbi_cb = new VBIData; memset(vbi_cb, 0, sizeof(VBIData)); vbi_cb->nvr = this; - vbi_add_handler(pal_tt, (void*) vbi_event, vbi_cb); + vbi_add_handler(pal_tt, vbi_event, vbi_cb); } } else if (VBIMode::NTSC_CC == m_vbiMode) @@ -230,7 +231,7 @@ void V4LRecorder::CloseVBIDevice(void) if (m_palVbiTt) { - vbi_del_handler(m_palVbiTt, (void*) vbi_event, m_palVbiCb); + vbi_del_handler(m_palVbiTt, vbi_event, m_palVbiCb); vbi_close(m_palVbiTt); delete m_palVbiCb; m_palVbiCb = nullptr; diff --git a/mythtv/libs/libmythtv/recorders/vbitext/cc.h b/mythtv/libs/libmythtv/recorders/vbitext/cc.h index e296195ab2a..6520c784169 100644 --- a/mythtv/libs/libmythtv/recorders/vbitext/cc.h +++ b/mythtv/libs/libmythtv/recorders/vbitext/cc.h @@ -1,10 +1,6 @@ #ifndef CC_H #define CC_H -#ifdef __cplusplus -extern "C" { -#endif - #define CC_VBIBUFSIZE (65536*2) //cc is 32 columns per row, this allows for extra characters @@ -29,8 +25,4 @@ struct cc *cc_open(const char *vbi_name); void cc_close(struct cc *cc); void cc_handler(struct cc *cc); -#ifdef __cplusplus -} -#endif - #endif diff --git a/mythtv/libs/libmythtv/recorders/vbitext/dllist.h b/mythtv/libs/libmythtv/recorders/vbitext/dllist.h index f01c622309b..5c92441d9e5 100644 --- a/mythtv/libs/libmythtv/recorders/vbitext/dllist.h +++ b/mythtv/libs/libmythtv/recorders/vbitext/dllist.h @@ -22,11 +22,7 @@ static inline struct dl_head * dl_init(struct dl_head *h) { h->first = (struct dl_node *)&h->null; -#ifdef __cplusplus h->null = nullptr; -#else - h->null = NULL; -#endif h->last = (struct dl_node *)&h->first; return h; } @@ -49,7 +45,7 @@ dl_insert_after(struct dl_node *p, struct dl_node *n) return n; } -#define dl_empty(h) ((h)->first->next == 0) +#define dl_empty(h) ((h)->first->next == nullptr) #define dl_insert_before(p, n) dl_insert_after((p)->prev, (n)) #define dl_insert_first(h, n) ({ struct dl_node *_n = (n); \ dl_insert_before((h)->first, _n); }) diff --git a/mythtv/libs/libmythtv/recorders/vbitext/hamm.c b/mythtv/libs/libmythtv/recorders/vbitext/hamm.c deleted file mode 100644 index 712a4dd48bc..00000000000 --- a/mythtv/libs/libmythtv/recorders/vbitext/hamm.c +++ /dev/null @@ -1,240 +0,0 @@ -#include "vt.h" -#include "hamm.h" - -// table to decode hamm8/4 encoded bytes. -// the low 4 bits are the (corrected) data bits -// bit 8 is set if there was a single bit error -// bit 12 is set if there was an uncorrectable error - -// the idea: you may add up to 15 words and get the -// number of single bit errors in b8-b11 and the number -// of double errors in b12-b15 - -static unsigned short hammtab[256] = -{ - 0x0101, 0x100f, 0x0001, 0x0101, 0x100f, 0x0100, 0x0101, 0x100f, - 0x100f, 0x0102, 0x0101, 0x100f, 0x010a, 0x100f, 0x100f, 0x0107, - 0x100f, 0x0100, 0x0101, 0x100f, 0x0100, 0x0000, 0x100f, 0x0100, - 0x0106, 0x100f, 0x100f, 0x010b, 0x100f, 0x0100, 0x0103, 0x100f, - 0x100f, 0x010c, 0x0101, 0x100f, 0x0104, 0x100f, 0x100f, 0x0107, - 0x0106, 0x100f, 0x100f, 0x0107, 0x100f, 0x0107, 0x0107, 0x0007, - 0x0106, 0x100f, 0x100f, 0x0105, 0x100f, 0x0100, 0x010d, 0x100f, - 0x0006, 0x0106, 0x0106, 0x100f, 0x0106, 0x100f, 0x100f, 0x0107, - 0x100f, 0x0102, 0x0101, 0x100f, 0x0104, 0x100f, 0x100f, 0x0109, - 0x0102, 0x0002, 0x100f, 0x0102, 0x100f, 0x0102, 0x0103, 0x100f, - 0x0108, 0x100f, 0x100f, 0x0105, 0x100f, 0x0100, 0x0103, 0x100f, - 0x100f, 0x0102, 0x0103, 0x100f, 0x0103, 0x100f, 0x0003, 0x0103, - 0x0104, 0x100f, 0x100f, 0x0105, 0x0004, 0x0104, 0x0104, 0x100f, - 0x100f, 0x0102, 0x010f, 0x100f, 0x0104, 0x100f, 0x100f, 0x0107, - 0x100f, 0x0105, 0x0105, 0x0005, 0x0104, 0x100f, 0x100f, 0x0105, - 0x0106, 0x100f, 0x100f, 0x0105, 0x100f, 0x010e, 0x0103, 0x100f, - 0x100f, 0x010c, 0x0101, 0x100f, 0x010a, 0x100f, 0x100f, 0x0109, - 0x010a, 0x100f, 0x100f, 0x010b, 0x000a, 0x010a, 0x010a, 0x100f, - 0x0108, 0x100f, 0x100f, 0x010b, 0x100f, 0x0100, 0x010d, 0x100f, - 0x100f, 0x010b, 0x010b, 0x000b, 0x010a, 0x100f, 0x100f, 0x010b, - 0x010c, 0x000c, 0x100f, 0x010c, 0x100f, 0x010c, 0x010d, 0x100f, - 0x100f, 0x010c, 0x010f, 0x100f, 0x010a, 0x100f, 0x100f, 0x0107, - 0x100f, 0x010c, 0x010d, 0x100f, 0x010d, 0x100f, 0x000d, 0x010d, - 0x0106, 0x100f, 0x100f, 0x010b, 0x100f, 0x010e, 0x010d, 0x100f, - 0x0108, 0x100f, 0x100f, 0x0109, 0x100f, 0x0109, 0x0109, 0x0009, - 0x100f, 0x0102, 0x010f, 0x100f, 0x010a, 0x100f, 0x100f, 0x0109, - 0x0008, 0x0108, 0x0108, 0x100f, 0x0108, 0x100f, 0x100f, 0x0109, - 0x0108, 0x100f, 0x100f, 0x010b, 0x100f, 0x010e, 0x0103, 0x100f, - 0x100f, 0x010c, 0x010f, 0x100f, 0x0104, 0x100f, 0x100f, 0x0109, - 0x010f, 0x100f, 0x000f, 0x010f, 0x100f, 0x010e, 0x010f, 0x100f, - 0x0108, 0x100f, 0x100f, 0x0105, 0x100f, 0x010e, 0x010d, 0x100f, - 0x100f, 0x010e, 0x010f, 0x100f, 0x010e, 0x000e, 0x100f, 0x010e, -}; - - - -#if 0 // this information is contained in hamm24par bit 5 -// simple parity table (sum of 1 bits modulo 2) - -static char odd_parity[256] = -{ - 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0, - 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, - 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, - 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0, - 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, - 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0, - 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0, - 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, - 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, - 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0, - 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0, - 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, - 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0, - 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, - 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, - 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0 -}; -#endif - - - -// this table generates the parity checks for hamm24/18 decoding. -// bit 0 is for test A, 1 for B, ... -// thanks to R. Gancarz for this fine table *g* - -static char hamm24par[3][256] = -{ - { // parities of first byte - 0, 33, 34, 3, 35, 2, 1, 32, 36, 5, 6, 39, 7, 38, 37, 4, - 37, 4, 7, 38, 6, 39, 36, 5, 1, 32, 35, 2, 34, 3, 0, 33, - 38, 7, 4, 37, 5, 36, 39, 6, 2, 35, 32, 1, 33, 0, 3, 34, - 3, 34, 33, 0, 32, 1, 2, 35, 39, 6, 5, 36, 4, 37, 38, 7, - 39, 6, 5, 36, 4, 37, 38, 7, 3, 34, 33, 0, 32, 1, 2, 35, - 2, 35, 32, 1, 33, 0, 3, 34, 38, 7, 4, 37, 5, 36, 39, 6, - 1, 32, 35, 2, 34, 3, 0, 33, 37, 4, 7, 38, 6, 39, 36, 5, - 36, 5, 6, 39, 7, 38, 37, 4, 0, 33, 34, 3, 35, 2, 1, 32, - 40, 9, 10, 43, 11, 42, 41, 8, 12, 45, 46, 15, 47, 14, 13, 44, - 13, 44, 47, 14, 46, 15, 12, 45, 41, 8, 11, 42, 10, 43, 40, 9, - 14, 47, 44, 13, 45, 12, 15, 46, 42, 11, 8, 41, 9, 40, 43, 10, - 43, 10, 9, 40, 8, 41, 42, 11, 15, 46, 45, 12, 44, 13, 14, 47, - 15, 46, 45, 12, 44, 13, 14, 47, 43, 10, 9, 40, 8, 41, 42, 11, - 42, 11, 8, 41, 9, 40, 43, 10, 14, 47, 44, 13, 45, 12, 15, 46, - 41, 8, 11, 42, 10, 43, 40, 9, 13, 44, 47, 14, 46, 15, 12, 45, - 12, 45, 46, 15, 47, 14, 13, 44, 40, 9, 10, 43, 11, 42, 41, 8 - }, { // parities of second byte - 0, 41, 42, 3, 43, 2, 1, 40, 44, 5, 6, 47, 7, 46, 45, 4, - 45, 4, 7, 46, 6, 47, 44, 5, 1, 40, 43, 2, 42, 3, 0, 41, - 46, 7, 4, 45, 5, 44, 47, 6, 2, 43, 40, 1, 41, 0, 3, 42, - 3, 42, 41, 0, 40, 1, 2, 43, 47, 6, 5, 44, 4, 45, 46, 7, - 47, 6, 5, 44, 4, 45, 46, 7, 3, 42, 41, 0, 40, 1, 2, 43, - 2, 43, 40, 1, 41, 0, 3, 42, 46, 7, 4, 45, 5, 44, 47, 6, - 1, 40, 43, 2, 42, 3, 0, 41, 45, 4, 7, 46, 6, 47, 44, 5, - 44, 5, 6, 47, 7, 46, 45, 4, 0, 41, 42, 3, 43, 2, 1, 40, - 48, 25, 26, 51, 27, 50, 49, 24, 28, 53, 54, 31, 55, 30, 29, 52, - 29, 52, 55, 30, 54, 31, 28, 53, 49, 24, 27, 50, 26, 51, 48, 25, - 30, 55, 52, 29, 53, 28, 31, 54, 50, 27, 24, 49, 25, 48, 51, 26, - 51, 26, 25, 48, 24, 49, 50, 27, 31, 54, 53, 28, 52, 29, 30, 55, - 31, 54, 53, 28, 52, 29, 30, 55, 51, 26, 25, 48, 24, 49, 50, 27, - 50, 27, 24, 49, 25, 48, 51, 26, 30, 55, 52, 29, 53, 28, 31, 54, - 49, 24, 27, 50, 26, 51, 48, 25, 29, 52, 55, 30, 54, 31, 28, 53, - 28, 53, 54, 31, 55, 30, 29, 52, 48, 25, 26, 51, 27, 50, 49, 24 - }, { // parities of third byte - 63, 14, 13, 60, 12, 61, 62, 15, 11, 58, 57, 8, 56, 9, 10, 59, - 10, 59, 56, 9, 57, 8, 11, 58, 62, 15, 12, 61, 13, 60, 63, 14, - 9, 56, 59, 10, 58, 11, 8, 57, 61, 12, 15, 62, 14, 63, 60, 13, - 60, 13, 14, 63, 15, 62, 61, 12, 8, 57, 58, 11, 59, 10, 9, 56, - 8, 57, 58, 11, 59, 10, 9, 56, 60, 13, 14, 63, 15, 62, 61, 12, - 61, 12, 15, 62, 14, 63, 60, 13, 9, 56, 59, 10, 58, 11, 8, 57, - 62, 15, 12, 61, 13, 60, 63, 14, 10, 59, 56, 9, 57, 8, 11, 58, - 11, 58, 57, 8, 56, 9, 10, 59, 63, 14, 13, 60, 12, 61, 62, 15, - 31, 46, 45, 28, 44, 29, 30, 47, 43, 26, 25, 40, 24, 41, 42, 27, - 42, 27, 24, 41, 25, 40, 43, 26, 30, 47, 44, 29, 45, 28, 31, 46, - 41, 24, 27, 42, 26, 43, 40, 25, 29, 44, 47, 30, 46, 31, 28, 45, - 28, 45, 46, 31, 47, 30, 29, 44, 40, 25, 26, 43, 27, 42, 41, 24, - 40, 25, 26, 43, 27, 42, 41, 24, 28, 45, 46, 31, 47, 30, 29, 44, - 29, 44, 47, 30, 46, 31, 28, 45, 41, 24, 27, 42, 26, 43, 40, 25, - 30, 47, 44, 29, 45, 28, 31, 46, 42, 27, 24, 41, 25, 40, 43, 26, - 43, 26, 25, 40, 24, 41, 42, 27, 31, 46, 45, 28, 44, 29, 30, 47 - } -}; - - - -// table to extract the lower 4 bit from hamm24/18 encoded bytes - -static char hamm24val[256] = -{ - 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, - 2, 2, 2, 2, 3, 3, 3, 3, 2, 2, 2, 2, 3, 3, 3, 3, - 4, 4, 4, 4, 5, 5, 5, 5, 4, 4, 4, 4, 5, 5, 5, 5, - 6, 6, 6, 6, 7, 7, 7, 7, 6, 6, 6, 6, 7, 7, 7, 7, - 8, 8, 8, 8, 9, 9, 9, 9, 8, 8, 8, 8, 9, 9, 9, 9, - 10, 10, 10, 10, 11, 11, 11, 11, 10, 10, 10, 10, 11, 11, 11, 11, - 12, 12, 12, 12, 13, 13, 13, 13, 12, 12, 12, 12, 13, 13, 13, 13, - 14, 14, 14, 14, 15, 15, 15, 15, 14, 14, 14, 14, 15, 15, 15, 15, - 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, - 2, 2, 2, 2, 3, 3, 3, 3, 2, 2, 2, 2, 3, 3, 3, 3, - 4, 4, 4, 4, 5, 5, 5, 5, 4, 4, 4, 4, 5, 5, 5, 5, - 6, 6, 6, 6, 7, 7, 7, 7, 6, 6, 6, 6, 7, 7, 7, 7, - 8, 8, 8, 8, 9, 9, 9, 9, 8, 8, 8, 8, 9, 9, 9, 9, - 10, 10, 10, 10, 11, 11, 11, 11, 10, 10, 10, 10, 11, 11, 11, 11, - 12, 12, 12, 12, 13, 13, 13, 13, 12, 12, 12, 12, 13, 13, 13, 13, - 14, 14, 14, 14, 15, 15, 15, 15, 14, 14, 14, 14, 15, 15, 15, 15 -}; - - - -// mapping from parity checks made by table hamm24par to error -// results return by hamm24. -// (0 = no error, 0x0100 = single bit error, 0x1000 = double error) - -static short hamm24err[64] = -{ - 0x0000, 0x1000, 0x1000, 0x1000, 0x1000, 0x1000, 0x1000, 0x1000, - 0x1000, 0x1000, 0x1000, 0x1000, 0x1000, 0x1000, 0x1000, 0x1000, - 0x1000, 0x1000, 0x1000, 0x1000, 0x1000, 0x1000, 0x1000, 0x1000, - 0x1000, 0x1000, 0x1000, 0x1000, 0x1000, 0x1000, 0x1000, 0x1000, - 0x0100, 0x0100, 0x0100, 0x0100, 0x0100, 0x0100, 0x0100, 0x0100, - 0x0100, 0x0100, 0x0100, 0x0100, 0x0100, 0x0100, 0x0100, 0x0100, - 0x0100, 0x0100, 0x0100, 0x0100, 0x0100, 0x0100, 0x0100, 0x0100, - 0x1000, 0x1000, 0x1000, 0x1000, 0x1000, 0x1000, 0x1000, 0x1000, -}; - - - -// mapping from parity checks made by table hamm24par to faulty bit -// in the decoded 18 bit word. - -static int hamm24cor[64] = -{ - 0x00000, 0x00000, 0x00000, 0x00000, 0x00000, 0x00000, 0x00000, 0x00000, - 0x00000, 0x00000, 0x00000, 0x00000, 0x00000, 0x00000, 0x00000, 0x00000, - 0x00000, 0x00000, 0x00000, 0x00000, 0x00000, 0x00000, 0x00000, 0x00000, - 0x00000, 0x00000, 0x00000, 0x00000, 0x00000, 0x00000, 0x00000, 0x00000, - 0x00000, 0x00000, 0x00000, 0x00001, 0x00000, 0x00002, 0x00004, 0x00008, - 0x00000, 0x00010, 0x00020, 0x00040, 0x00080, 0x00100, 0x00200, 0x00400, - 0x00000, 0x00800, 0x01000, 0x02000, 0x04000, 0x08000, 0x10000, 0x20000, - 0x00000, 0x00000, 0x00000, 0x00000, 0x00000, 0x00000, 0x00000, 0x00000, -}; - - - -int -hamm8(const unsigned char *p, int *err) -{ - int a = hammtab[p[0]]; - *err += a; - return a & 15; -} - -int -hamm16(const unsigned char *p, int *err) -{ - int a = hammtab[p[0]]; - int b = hammtab[p[1]]; - *err += a; - *err += b; - return (a & 15) | (b & 15) * 16; -} - -int -hamm24(const unsigned char *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]; -} - -int -chk_parity(unsigned char *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; -} - diff --git a/mythtv/libs/libmythtv/recorders/vbitext/hamm.h b/mythtv/libs/libmythtv/recorders/vbitext/hamm.h deleted file mode 100644 index c5bae5a830e..00000000000 --- a/mythtv/libs/libmythtv/recorders/vbitext/hamm.h +++ /dev/null @@ -1,18 +0,0 @@ -#ifndef HAMM_H -#define HAMM_H - -#ifdef __cplusplus -extern "C" { -#endif - -int hamm8(const unsigned char *p, int *err); -int hamm16(const unsigned char *p, int *err); -int hamm24(const unsigned char *p, int *err); -int chk_parity(unsigned char *p, int n); - -#ifdef __cplusplus -} -#endif - -#endif - diff --git a/mythtv/libs/libmythtv/recorders/vbitext/lang.c b/mythtv/libs/libmythtv/recorders/vbitext/lang.cpp similarity index 98% rename from mythtv/libs/libmythtv/recorders/vbitext/lang.c rename to mythtv/libs/libmythtv/recorders/vbitext/lang.cpp index 3604a734638..ea71c2e6577 100644 --- a/mythtv/libs/libmythtv/recorders/vbitext/lang.c +++ b/mythtv/libs/libmythtv/recorders/vbitext/lang.cpp @@ -1,4 +1,4 @@ -#include +#include #include "vt.h" #include "lang.h" @@ -174,9 +174,8 @@ do_enhancements(struct enhance *eh, struct vt_page *vtp) if (adr < VT_WIDTH && row < VT_HEIGHT) { struct mark *mark = marks + (mode - 16); - char *x = NULL; - - if ((x = strchr(mark->m_g0, data))) + const char *x = std::strchr(mark->m_g0, data); + if (x != nullptr) { if (latin1) data = mark->m_latin1[x - mark->m_g0]; diff --git a/mythtv/libs/libmythtv/recorders/vbitext/lang.h b/mythtv/libs/libmythtv/recorders/vbitext/lang.h index 0282357e8b3..266ace63c70 100644 --- a/mythtv/libs/libmythtv/recorders/vbitext/lang.h +++ b/mythtv/libs/libmythtv/recorders/vbitext/lang.h @@ -1,14 +1,10 @@ #ifndef LANG_H #define LANG_H -#ifdef __cplusplus -extern "C" { -#endif - #include "vt.h" +#include "vbilut.h" extern int latin1; -extern const unsigned char lang_chars[][16]; /* from vbilut.cpp */ struct enhance { @@ -23,9 +19,5 @@ void init_enhance(struct enhance *eh); void add_enhance(struct enhance *eh, int dcode, unsigned int *data); void do_enhancements(struct enhance *eh, struct vt_page *vtp); -#ifdef __cplusplus -} -#endif - #endif // LANG_H diff --git a/mythtv/libs/libmythtv/recorders/vbitext/vbi.c b/mythtv/libs/libmythtv/recorders/vbitext/vbi.cpp similarity index 91% rename from mythtv/libs/libmythtv/recorders/vbitext/vbi.c rename to mythtv/libs/libmythtv/recorders/vbitext/vbi.cpp index 481b746a2c7..d2b3580e089 100644 --- a/mythtv/libs/libmythtv/recorders/vbitext/vbi.c +++ b/mythtv/libs/libmythtv/recorders/vbitext/vbi.cpp @@ -4,12 +4,12 @@ #include -// ANSI C headers -#include -#include -#include -#include -#include +// ANSI C++ headers +#include +#include +#include +#include +#include #ifdef USING_V4L2 // HACK. Broken kernel headers < 2.6.25 fail compile in videodev2.h when @@ -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 @@ -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) { @@ -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; @@ -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((void*)vbi->clients[0].first); + (cln = static_cast((void*)cl->node->next)) != nullptr; + cl = cln) cl->handler(cl->data, ev); } @@ -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) @@ -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); @@ -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(malloc(sizeof(*cl))))) return -1; cl->handler = handler; cl->data = data; @@ -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((void*)vbi->clients->first); + cl->node->next != nullptr; + cl = static_cast((void*)cl->node->next)) { if (cl->handler == handler && cl->data == data) { @@ -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)); @@ -588,8 +607,10 @@ setup_dev(struct vbi *vbi) { if (rawbuf) free(rawbuf); - if (!(rawbuf = malloc(rawbuf_size = vbi->bufsize))) + if (!(rawbuf = static_cast(malloc(rawbuf_size = vbi->bufsize)))) + { error("malloc refused in setup_dev()\n"); + } } return 0; @@ -605,7 +626,7 @@ 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; @@ -613,7 +634,8 @@ vbi_open(const char *vbi_dev_name, struct cache *ca, int fine_tune, int big_buf) lang_init(); s_inited = 1; - if (!(vbi = malloc(sizeof(*vbi)))) + vbi = static_cast(malloc(sizeof(*vbi))); + if (vbi == nullptr) { error("out of memory"); goto fail1; @@ -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; } @@ -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 } @@ -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); } diff --git a/mythtv/libs/libmythtv/recorders/vbitext/vbi.h b/mythtv/libs/libmythtv/recorders/vbitext/vbi.h index 4130d29ac0a..11bb2a2445d 100644 --- a/mythtv/libs/libmythtv/recorders/vbitext/vbi.h +++ b/mythtv/libs/libmythtv/recorders/vbitext/vbi.h @@ -1,10 +1,6 @@ #ifndef VBI_H #define VBI_H -#ifdef __cplusplus -extern "C" { -#endif - #include "vt.h" #include "dllist.h" #include "lang.h" @@ -42,10 +38,12 @@ 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; }; @@ -53,16 +51,12 @@ 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 diff --git a/mythtv/libs/libmythtv/vbilut.cpp b/mythtv/libs/libmythtv/vbilut.cpp index 0cc6948118b..df9079fa3e0 100644 --- a/mythtv/libs/libmythtv/vbilut.cpp +++ b/mythtv/libs/libmythtv/vbilut.cpp @@ -1,6 +1,5 @@ #include -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 }, @@ -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] = @@ -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]; +} diff --git a/mythtv/libs/libmythtv/vbilut.h b/mythtv/libs/libmythtv/vbilut.h index 288c848af9f..54d21195976 100644 --- a/mythtv/libs/libmythtv/vbilut.h +++ b/mythtv/libs/libmythtv/vbilut.h @@ -3,7 +3,7 @@ #include -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[]; @@ -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_