Skip to content

Commit

Permalink
Convert to std::array and std::string. (libmythtv/captions)
Browse files Browse the repository at this point in the history
  • Loading branch information
linuxdude42 committed Aug 28, 2020
1 parent ff59065 commit 2348f5d
Show file tree
Hide file tree
Showing 19 changed files with 145 additions and 137 deletions.
11 changes: 6 additions & 5 deletions mythtv/libs/libmythtv/captions/cc608decoder.cpp
Expand Up @@ -3,6 +3,7 @@
// Some of the XDS was inspired by code in TVTime. -- dtk 03/30/2006

#include <algorithm>
#include <vector>
using namespace std;

// Qt headers
Expand All @@ -18,7 +19,7 @@ using namespace std;

#define DEBUG_XDS 0

static void init_xds_program_type(QString xds_program_type[96]);
static void init_xds_program_type(CC608ProgramType& xds_program_type);

CC608Decoder::CC608Decoder(CC608Input *ccr)
: m_reader(ccr),
Expand Down Expand Up @@ -52,7 +53,7 @@ void CC608Decoder::FormatCC(int tc, int code1, int code2)
FormatCCField(tc, 1, code2);
}

void CC608Decoder::GetServices(uint seconds, bool seen[4]) const
void CC608Decoder::GetServices(uint seconds, CC608Seen seen) const
{
time_t now = time(nullptr);
time_t then = now - seconds;
Expand Down Expand Up @@ -880,7 +881,7 @@ void CC608Decoder::DecodeVPS(const unsigned char *buf)
if ((int8_t) c < 0)
{
m_vpsLabel[m_vpsL] = 0;
memcpy(m_vpsPrLabel, m_vpsLabel, sizeof(m_vpsPrLabel));
m_vpsPrLabel = m_vpsLabel;
m_vpsL = 0;
}
c &= 0x7F;
Expand All @@ -889,7 +890,7 @@ void CC608Decoder::DecodeVPS(const unsigned char *buf)

LOG(VB_VBI, LOG_INFO, QString("VPS: 3-10: %1 %2 %3 %4 %5 %6 %7 %8 (\"%9\")")
.arg(buf[0]).arg(buf[1]).arg(buf[2]).arg(buf[3]).arg(buf[4])
.arg(buf[5]).arg(buf[6]).arg(buf[7]).arg(m_vpsPrLabel));
.arg(buf[5]).arg(buf[6]).arg(buf[7]).arg(m_vpsPrLabel.data()));

int pcs = buf[2] >> 6;
int cni = + ((buf[10] & 3) << 10)
Expand Down Expand Up @@ -1442,7 +1443,7 @@ bool CC608Decoder::XDSPacketParseChannel(const vector<unsigned char> &xds_buf)
return handled;
}

static void init_xds_program_type(QString xds_program_type[96])
static void init_xds_program_type(CC608ProgramType& xds_program_type)
{
xds_program_type[0] = QCoreApplication::translate("(Categories)",
"Education");
Expand Down
72 changes: 39 additions & 33 deletions mythtv/libs/libmythtv/captions/cc608decoder.h
Expand Up @@ -6,6 +6,7 @@
#include <cstdint>
#include <ctime>

#include <array>
#include <vector>
using namespace std;

Expand All @@ -15,6 +16,11 @@ using namespace std;

#include "format.h"

using CC608Seen = std::array<bool,4>;
using CC608ProgramType = std::array<QString,96>;
using CC608PerField = std::array<int,2>;
using CC608PerMode = std::array<int,8>;

class CC608Input
{
public:
Expand Down Expand Up @@ -62,7 +68,7 @@ class CC608Decoder
QString GetXDS(const QString &key) const;

/// \return Services seen in last few seconds as specified.
void GetServices(uint seconds, bool seen[4]) const;
void GetServices(uint seconds, CC608Seen seen) const;

static QString ToASCII(const QString &cc608, bool suppress_unknown);

Expand All @@ -86,65 +92,65 @@ class CC608Decoder

bool m_ignoreTimeCode {false};

time_t m_lastSeen[4] {0};
std::array<time_t,4> m_lastSeen {0};

// per-field
int m_badVbi[2] { 0, 0};
int m_lastTc[2] { 0, 0};
int m_lastCode[2] {-1, -1};
int m_lastCodeTc[2] { 0, 0};
int m_ccMode[2] {-1, -1}; // 0=cc1/txt1, 1=cc2/txt2
int m_xds[2] { 0, 0};
int m_txtMode[4] { 0, 0, 0, 0};
CC608PerField m_badVbi { 0, 0};
CC608PerField m_lastTc { 0, 0};
CC608PerField m_lastCode {-1, -1};
CC608PerField m_lastCodeTc { 0, 0};
CC608PerField m_ccMode {-1, -1}; // 0=cc1/txt1, 1=cc2/txt2
CC608PerField m_xds { 0, 0};
std::array<int,4> m_txtMode { 0, 0, 0, 0};

// per-mode state
int m_lastRow[8] {0};
int m_newRow[8] {0};
int m_newCol[8] {0};
int m_newAttr[8] {0}; // color+italic+underline
int m_timeCode[8] {0};
int m_row[8] {0};
int m_col[8] {0};
int m_rowCount[8] {0};
int m_style[8] {0};
int m_lineCont[8] {0};
int m_resumeText[8] {0};
int m_lastClr[8] {0};
QString m_ccBuf[8];
CC608PerMode m_lastRow {0};
CC608PerMode m_newRow {0};
CC608PerMode m_newCol {0};
CC608PerMode m_newAttr {0}; // color+italic+underline
CC608PerMode m_timeCode {0};
CC608PerMode m_row {0};
CC608PerMode m_col {0};
CC608PerMode m_rowCount {0};
CC608PerMode m_style {0};
CC608PerMode m_lineCont {0};
CC608PerMode m_resumeText {0};
CC608PerMode m_lastClr {0};
std::array<QString,8> m_ccBuf;

// translation table
QChar m_stdChar[128];
std::array<QChar,128> m_stdChar;

// temporary buffer
unsigned char *m_rbuf {nullptr};
int m_lastFormatTc[2] {0, 0};
int m_lastFormatData[2] {0, 0};
std::array<int,2> m_lastFormatTc {0, 0};
std::array<int,2> m_lastFormatData {0, 0};

// VPS data
char m_vpsPrLabel[20] {0};
char m_vpsLabel[20] {0};
std::array<char,20> m_vpsPrLabel {0};
std::array<char,20> m_vpsLabel {0};
int m_vpsL {0};

// WSS data
uint m_wssFlags {0};
bool m_wssValid {false};

int m_xdsCurService {-1};
vector<unsigned char> m_xdsBuf[7];
std::array<vector<unsigned char>,7> m_xdsBuf;
uint m_xdsCrcPassed {0};
uint m_xdsCrcFailed {0};

mutable QMutex m_xdsLock {QMutex::Recursive};
uint m_xdsRatingSystems[2] {0};
uint m_xdsRating[2][4] {{0}};
QString m_xdsProgramName[2];
vector<uint> m_xdsProgramType[2];
std::array<uint,2> m_xdsRatingSystems {0};
std::array<std::array<uint,4>,2> m_xdsRating {{}};
std::array<QString,2> m_xdsProgramName;
std::array<vector<uint>,2> m_xdsProgramType;

QString m_xdsNetCall;
QString m_xdsNetName;
uint m_xdsTsid {0};

QString m_xdsProgramTypeString[96];
CC608ProgramType m_xdsProgramTypeString;
};

#endif
4 changes: 2 additions & 2 deletions mythtv/libs/libmythtv/captions/cc608reader.h
Expand Up @@ -109,11 +109,11 @@ class MTV_PUBLIC CC608Reader : public CC608Input
int m_writePosition {0};
QMutex m_inputBufLock;
int m_maxTextSize {0};
TextContainer m_inputBuffers[MAXTBUFFER+1] {};
std::array<TextContainer,MAXTBUFFER+1> m_inputBuffers {};
int m_ccMode {CC_CC1};
int m_ccPageNum {0x888};
// Output buffers
CC608StateTracker m_state[MAXOUTBUFFERS];
std::array<CC608StateTracker,MAXOUTBUFFERS> m_state;
};

#endif // CC608READER_H
8 changes: 4 additions & 4 deletions mythtv/libs/libmythtv/captions/cc708decoder.cpp
Expand Up @@ -35,7 +35,7 @@ const std::array<const std::string, 4> cc_types =
};

static void parse_cc_packet(CC708Reader *cb_cbs, CaptionPacket *pkt,
time_t last_seen[64]);
cc708_seen_times last_seen);

void CC708Decoder::decode_cc_data(uint cc_type, uint data1, uint data2)
{
Expand Down Expand Up @@ -73,7 +73,7 @@ void CC708Decoder::decode_cc_null(void)
m_partialPacket.size = 0;
}

void CC708Decoder::services(uint seconds, bool seen[64]) const
void CC708Decoder::services(uint seconds, cc708_seen_flags & seen) const
{
time_t now = time(nullptr);
time_t then = now - seconds;
Expand Down Expand Up @@ -620,9 +620,9 @@ static void append_cc(CC708Reader* cc, uint service_num,
}

static void parse_cc_packet(CC708Reader* cb_cbs, CaptionPacket* pkt,
time_t last_seen[64])
cc708_seen_times last_seen)
{
const unsigned char* pkt_buf = pkt->data;
const unsigned char* pkt_buf = pkt->data.data();
const int pkt_size = pkt->size;
int off = 1;
int len = ((((int)pkt_buf[0]) & 0x3f)<<1) - 1;
Expand Down
15 changes: 7 additions & 8 deletions mythtv/libs/libmythtv/captions/cc708decoder.h
Expand Up @@ -10,11 +10,14 @@
#include "format.h"
#include "compat.h"

using cc708_seen_flags = std::array<bool,64>;
using cc708_seen_times = std::array<time_t,64>;

#ifndef __CC_CALLBACKS_H__
/** EIA-708-A closed caption packet */
struct CaptionPacket
{
unsigned char data[128+16];
std::array<unsigned char,128+16> data;
int size;
};
#endif
Expand All @@ -24,23 +27,19 @@ class CC708Reader;
class CC708Decoder
{
public:
explicit CC708Decoder(CC708Reader *ccr) : m_reader(ccr)
{
memset(&m_partialPacket, 0, sizeof(CaptionPacket));
memset(m_lastSeen, 0, sizeof(m_lastSeen));
}
explicit CC708Decoder(CC708Reader *ccr) : m_reader(ccr) {}
~CC708Decoder() = default;

void decode_cc_data(uint cc_type, uint data1, uint data2);
void decode_cc_null(void);

/// \return Services seen in last few seconds as specified.
void services(uint seconds, bool seen[64]) const;
void services(uint seconds, cc708_seen_flags & seen) const;

private:
CaptionPacket m_partialPacket {};
CC708Reader *m_reader {nullptr};
time_t m_lastSeen[64] {};
cc708_seen_times m_lastSeen {};
};

#endif // CC708DECODER_H_
22 changes: 11 additions & 11 deletions mythtv/libs/libmythtv/captions/cc708reader.cpp
Expand Up @@ -23,9 +23,9 @@ CC708Reader::CC708Reader(MythPlayer *owner)

m_tempStrAlloc[i] = 512;
m_tempStrSize[i] = 0;
m_tempStr[i] = (short*) malloc(m_tempStrAlloc[i] * sizeof(short));
m_tempStr[i] = (int16_t*) malloc(m_tempStrAlloc[i] * sizeof(int16_t));
}
memset(&CC708DelayedDeletes, 0, sizeof(CC708DelayedDeletes));
m_cc708DelayedDeletes.fill(0);
}

CC708Reader::~CC708Reader()
Expand All @@ -48,7 +48,7 @@ void CC708Reader::SetCurrentWindow(uint service_num, int window_id)
CHECKENABLED;
LOG(VB_VBI, LOG_DEBUG, LOC + QString("SetCurrentWindow(%1, %2)")
.arg(service_num).arg(window_id));
CC708services[service_num].m_currentWindow = window_id;
m_cc708services[service_num].m_currentWindow = window_id;
}

void CC708Reader::DefineWindow(
Expand All @@ -68,7 +68,7 @@ void CC708Reader::DefineWindow(

CHECKENABLED;

CC708DelayedDeletes[service_num & 63] &= ~(1 << window_id);
m_cc708DelayedDeletes[service_num & 63] &= ~(1 << window_id);

LOG(VB_VBI, LOG_DEBUG, LOC +
QString("DefineWindow(%1, %2,\n\t\t\t\t\t")
Expand All @@ -91,7 +91,7 @@ void CC708Reader::DefineWindow(
row_lock, column_lock,
pen_style, window_style);

CC708services[service_num].m_currentWindow = window_id;
m_cc708services[service_num].m_currentWindow = window_id;
}

void CC708Reader::DeleteWindows(uint service_num, int window_map)
Expand All @@ -103,7 +103,7 @@ void CC708Reader::DeleteWindows(uint service_num, int window_map)
for (uint i = 0; i < 8; i++)
if ((1 << i) & window_map)
GetCCWin(service_num, i).Clear();
CC708DelayedDeletes[service_num&63] |= window_map;
m_cc708DelayedDeletes[service_num&63] |= window_map;
}

void CC708Reader::DisplayWindows(uint service_num, int window_map)
Expand All @@ -114,7 +114,7 @@ void CC708Reader::DisplayWindows(uint service_num, int window_map)

for (uint i = 0; i < 8; i++)
{
if ((1 << i) & CC708DelayedDeletes[service_num & 63])
if ((1 << i) & m_cc708DelayedDeletes[service_num & 63])
{
CC708Window &win = GetCCWin(service_num, i);
QMutexLocker locker(&win.m_lock);
Expand All @@ -126,7 +126,7 @@ void CC708Reader::DisplayWindows(uint service_num, int window_map)
win.m_text = nullptr;
}
}
CC708DelayedDeletes[service_num & 63] = 0;
m_cc708DelayedDeletes[service_num & 63] = 0;
}

for (uint i = 0; i < 8; i++)
Expand Down Expand Up @@ -219,7 +219,7 @@ void CC708Reader::SetPenAttributes(
{
CHECKENABLED;
LOG(VB_VBI, LOG_DEBUG, LOC + QString("SetPenAttributes(%1, %2,")
.arg(service_num).arg(CC708services[service_num].m_currentWindow) +
.arg(service_num).arg(m_cc708services[service_num].m_currentWindow) +
QString("\n\t\t\t\t\t pen_size %1, offset %2, text_tag %3, "
"font_tag %4,"
"\n\t\t\t\t\t edge_type %5, underline %6, italics %7")
Expand Down Expand Up @@ -281,7 +281,7 @@ void CC708Reader::Reset(uint service_num)
}

void CC708Reader::TextWrite(uint service_num,
short* unicode_string, short len)
int16_t* unicode_string, int16_t len)
{
CHECKENABLED;
QString debug = QString();
Expand All @@ -291,5 +291,5 @@ void CC708Reader::TextWrite(uint service_num,
debug += QChar(unicode_string[i]);
}
LOG(VB_VBI, LOG_DEBUG, LOC + QString("AddText to %1->%2 |%3|")
.arg(service_num).arg(CC708services[service_num].m_currentWindow).arg(debug));
.arg(service_num).arg(m_cc708services[service_num].m_currentWindow).arg(debug));
}

0 comments on commit 2348f5d

Please sign in to comment.