30 changes: 15 additions & 15 deletions mythtv/libs/libmythtv/captions/cc708reader.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,16 @@ class CC708Reader
virtual ~CC708Reader();

void SetCurrentService(int service) { m_currentService = service; }
CC708Service* GetCurrentService(void) { return &CC708services[m_currentService]; }
CC708Service* GetCurrentService(void) { return &m_cc708services[m_currentService]; }
void SetEnabled(bool enable) { m_enabled = enable; }
void ClearBuffers(void);

CC708Service* GetService(uint service_num)
{ return &(CC708services[service_num]); }
{ return &(m_cc708services[service_num]); }
CC708Window &GetCCWin(uint service_num, uint window_id)
{ return CC708services[service_num].m_windows[window_id]; }
{ return m_cc708services[service_num].m_windows[window_id]; }
CC708Window &GetCCWin(uint svc_num)
{ return GetCCWin(svc_num, CC708services[svc_num].m_currentWindow); }
{ return GetCCWin(svc_num, m_cc708services[svc_num].m_currentWindow); }

// Window settings
virtual void SetCurrentWindow(uint service_num, int window_id);
Expand Down Expand Up @@ -72,21 +72,21 @@ class CC708Reader

// Text
virtual void TextWrite(uint service_num,
short* unicode_string, short len);
int16_t* unicode_string, int16_t len);

// Data
unsigned char *m_buf[k708MaxServices] {};
uint m_bufAlloc[k708MaxServices] {};
uint m_bufSize[k708MaxServices] {};
bool m_delayed[k708MaxServices] {};
std::array<unsigned char *,k708MaxServices> m_buf {};
std::array<uint,k708MaxServices> m_bufAlloc {};
std::array<uint,k708MaxServices> m_bufSize {};
std::array<bool,k708MaxServices> m_delayed {};

short *m_tempStr[k708MaxServices] {};
int m_tempStrAlloc[k708MaxServices] {};
int m_tempStrSize[k708MaxServices] {};
std::array<int16_t *,k708MaxServices> m_tempStr {};
std::array<int,k708MaxServices> m_tempStrAlloc {};
std::array<int,k708MaxServices> m_tempStrSize {};

int m_currentService {1};
CC708Service CC708services[k708MaxServices];
int CC708DelayedDeletes[k708MaxServices] {};
int m_currentService {1};
std::array<CC708Service,k708MaxServices> m_cc708services;
std::array<int,k708MaxServices> m_cc708DelayedDeletes {};

MythPlayer *m_parent {nullptr};
bool m_enabled {false};
Expand Down
2 changes: 1 addition & 1 deletion mythtv/libs/libmythtv/captions/cc708window.h
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ class CC708Service

public:
uint m_currentWindow {0};
CC708Window m_windows[k708MaxWindows];
std::array<CC708Window,k708MaxWindows> m_windows;
};

#endif // CC708_WINDOW_H
34 changes: 16 additions & 18 deletions mythtv/libs/libmythtv/captions/teletextextractorreader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ void TeletextExtractorReader::PageUpdated(int page, int subpage)
}

void TeletextExtractorReader::HeaderUpdated(
int page, int subpage, uint8_t *page_ptr, int lang)
int page, int subpage, tt_line_array& page_ptr, int lang)
{
m_updatedPages.insert(qMakePair(page, subpage));
TeletextReader::HeaderUpdated(page, subpage, page_ptr, lang);
Expand Down Expand Up @@ -53,8 +53,9 @@ void TeletextExtractorReader::HeaderUpdated(
* 0x08 0x09 0x0a 0x0b 0x0c 0x0d (apparently a control character) 0x0e 0x0f
*/

static const uint16_t ppi_national_subsets[][20] =
{
using ppi_natl_array = std::array<const uint16_t,20>;
static const std::array<const ppi_natl_array,13> ppi_national_subsets
{{
{ 0x00a3, 0x0024, 0x0040, 0x00ab, 0x00bd, 0x00bb, 0x005e, 0x0023,
0x002d, 0x00bc, 0x00a6, 0x00be, 0x00f7 }, /* english, 000 */

Expand Down Expand Up @@ -97,46 +98,43 @@ static const uint16_t ppi_national_subsets[][20] =

{ 0x0054, 0x011f, 0x0130, 0x015e, 0x00d6, 0x00c7, 0x00dc, 0x011e,
0x0131, 0x015f, 0x00f6, 0x00e7, 0x00fc }, /* turkish, 1100 */
};
}};

// utc-2 --> utf-8
// this is not a general function, but it's enough for what we do here
// the result buffer need to be at least 4 bytes long
static void to_utf8(char *res, uint16_t ch)
static void to_utf8(std::string &res, uint16_t ch)
{
if(ch >= 0x80)
{
if(ch >= 0x800)
{
res[0] = (ch >> 12) | 0xE0;
res[1] = ((ch >> 6) & 0x3F) | 0x80;
res[2] = (ch & 0x3F) | 0x80;
res[3] = 0;
res = { static_cast<char>( (ch >> 12) | 0xE0),
static_cast<char>(((ch >> 6) & 0x3F) | 0x80),
static_cast<char>( (ch & 0x3F) | 0x80) };
}
else
{
res[0] = (ch >> 6) | 0xC0;
res[1] = (ch & 0x3F) | 0x80;
res[2] = 0;
res = { static_cast<char>((ch >> 6) | 0xC0),
static_cast<char>((ch & 0x3F) | 0x80) } ;
}
}
else
{
res[0] = ch;
res[1] = 0;
res = { static_cast<char>(ch) };
}
}

/**
* Get decoded ttx as a string.
*/

QString decode_teletext(int codePage, const uint8_t data[40])
QString decode_teletext(int codePage, const tt_line_array& data)
{
QString res;
char utf8[7];
std::string utf8 {};

const uint16_t *pi_active_national_set = ppi_national_subsets[codePage];
const ppi_natl_array pi_active_national_set = ppi_national_subsets[codePage];

for (int i = 0; i < 40; ++i)
{
Expand Down Expand Up @@ -213,7 +211,7 @@ QString decode_teletext(int codePage, const uint8_t data[40])

/* convert to utf-8 */
to_utf8(utf8, out);
res += QString::fromUtf8(utf8, strlen(utf8));
res += QString::fromUtf8(utf8.c_str());
}

return res;
Expand Down
4 changes: 2 additions & 2 deletions mythtv/libs/libmythtv/captions/teletextextractorreader.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include "mythtvexp.h"
#include "captions/teletextreader.h"

QString decode_teletext(int codePage, const uint8_t data[40]);
QString decode_teletext(int codePage, const tt_line_array& data);

class MTV_PUBLIC TeletextExtractorReader : public TeletextReader
{
Expand All @@ -28,7 +28,7 @@ class MTV_PUBLIC TeletextExtractorReader : public TeletextReader

protected:
void PageUpdated(int page, int subpage) override; // TeletextReader
void HeaderUpdated(int page, int subpage, uint8_t *page_ptr, int lang) override; // TeletextReader
void HeaderUpdated(int page, int subpage, tt_line_array& page_ptr, int lang) override; // TeletextReader

private:
QSet<QPair<int, int> > m_updatedPages;
Expand Down
26 changes: 11 additions & 15 deletions mythtv/libs/libmythtv/captions/teletextreader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@

TeletextReader::TeletextReader()
{
m_bitswap.fill(0);
for (int i = 0; i < 256; i++)
{
m_bitswap[i] = 0;
for (int bit = 0; bit < 8; bit++)
if (i & (1 << bit))
m_bitswap[i] |= (1 << (7-bit));
Expand Down Expand Up @@ -280,7 +280,7 @@ void TeletextReader::Reset(void)
mag.current_subpage = 0;
mag.loadingpage.active = false;
}
memset(m_header, ' ', 40);
m_header.fill(' ');

m_curpage = 0x100;
m_cursubpage = -1;
Expand Down Expand Up @@ -358,21 +358,19 @@ void TeletextReader::AddPageHeader(int page, int subpage, const uint8_t *buf,
m_magazines[magazine - 1].current_page = page;
m_magazines[magazine - 1].current_subpage = subpage;

memset(ttpage->data, ' ', sizeof(ttpage->data));
for (auto & line : ttpage->data)
line.fill(' ');

ttpage->active = true;
ttpage->subpagenum = subpage;

for (int & flof : ttpage->floflink)
flof = 0;

ttpage->floflink.fill(0);
ttpage->lang = lang;
ttpage->flags = flags;
ttpage->flof = 0;

ttpage->subtitle = (vbimode == VBI_DVB_SUBTITLE);

memset(ttpage->data[0], ' ', 8 * sizeof(uint8_t));
std::fill_n(ttpage->data[0].data(), 8, ' ');

if (vbimode == VBI_DVB || vbimode == VBI_DVB_SUBTITLE)
{
Expand All @@ -381,12 +379,12 @@ void TeletextReader::AddPageHeader(int page, int subpage, const uint8_t *buf,
}
else
{
memcpy(ttpage->data[0]+0, buf, 40);
std::copy(buf, buf + 40, ttpage->data[0].data());
}

if ( !(ttpage->flags & TP_INTERRUPTED_SEQ))
{
memcpy(m_header, ttpage->data[0], 40);
std::copy(ttpage->data[0].cbegin(), ttpage->data[0].cend(), m_header.data());
HeaderUpdated(page, subpage, ttpage->data[0],ttpage->lang);
}
}
Expand Down Expand Up @@ -493,7 +491,7 @@ void TeletextReader::AddTeletextData(int magazine, int row,
}
else
{
memcpy(ttpage->data[row], buf, 40);
std::copy(buf, buf + 40, ttpage->data[row].data());
}
}

Expand All @@ -511,15 +509,13 @@ void TeletextReader::PageUpdated(int page, int subpage)
}

void TeletextReader::HeaderUpdated(
int page, int subpage, uint8_t *page_ptr, int lang)
int page, int subpage, tt_line_array& page_ptr, int lang)
{
(void)page;
(void)subpage;
(void)page_ptr;
(void)lang;

if (page_ptr == nullptr)
return;

if (!m_curpageShowHeader)
return;

Expand Down
20 changes: 12 additions & 8 deletions mythtv/libs/libmythtv/captions/teletextreader.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
#ifndef TELETEXTREADER_H
#define TELETEXTREADER_H

#include <array>
#include <cstdint>
#include <map>
#include <vector>

#include <QString>
#include <QMutex>
Expand Down Expand Up @@ -33,16 +35,18 @@ enum TTColor
#define TP_NEWSFLASH 0x40
#define TP_SUBTITLE 0x80

using tt_line_array = std::array<uint8_t,40>;

class TeletextSubPage
{
public:
int pagenum; ///< the wanted page
int subpagenum; ///< the wanted subpage
int lang; ///< language code
int flags; ///< misc flags
uint8_t data[25][40]; ///< page data
std::array<tt_line_array,25> data; ///< page data
int flof; ///< page has FastText links
int floflink[6]; ///< FastText links (FLOF)
std::array<int,6> floflink; ///< FastText links (FLOF)
bool subtitle; ///< page is subtitle page
bool active; ///< data has arrived since page last cleared
};
Expand Down Expand Up @@ -93,7 +97,7 @@ class TeletextReader
int GetPageInput(uint num) const { return m_pageinput[num]; }
TeletextSubPage* FindSubPage(void)
{ return FindSubPage(m_curpage, m_cursubpage); }
uint8_t* GetHeader(void) { return m_header; }
tt_line_array GetHeader(void) { return m_header; }

// Decoder methods
void AddPageHeader(int page, int subpage, const uint8_t *buf,
Expand All @@ -104,7 +108,7 @@ class TeletextReader
protected:
virtual void PageUpdated(int page, int subpage);
virtual void HeaderUpdated(
int page, int subpage, uint8_t *page_ptr, int lang);
int page, int subpage, tt_line_array& page_ptr, int lang);

const TeletextSubPage *FindSubPage(int page, int subpage, int dir=0) const
{ return FindSubPageInternal(page, subpage, dir); }
Expand All @@ -128,14 +132,14 @@ class TeletextReader
int m_cursubpage {-1};
bool m_curpageShowHeader {true};
bool m_curpageIsSubtitle {false};
int m_pageinput[3] {0};
std::array<int,3> m_pageinput {0};
bool m_transparent {false};
bool m_revealHidden {false};
uint8_t m_header[40] {0};
tt_line_array m_header {0};
bool m_headerChanged {false};
bool m_pageChanged {false};
TeletextMagazine m_magazines[8] { };
unsigned char m_bitswap[256] {};
std::array<TeletextMagazine,8> m_magazines {};
std::array<uint8_t,256> m_bitswap {};
int m_fetchpage {0};
int m_fetchsubpage {0};
};
Expand Down
8 changes: 4 additions & 4 deletions mythtv/libs/libmythtv/captions/teletextscreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ void TeletextScreen::Pulse(void)
if (!ttpage)
{
// no page selected so show the header and a list of available pages
DrawHeader(nullptr, 0);
DrawHeader({}, 0);
m_teletextReader->SetPageChanged(false);
OptimiseDisplayedArea();
return;
Expand Down Expand Up @@ -253,12 +253,12 @@ void TeletextScreen::Reset(void)
m_teletextReader->Reset();
}

void TeletextScreen::DrawHeader(const uint8_t *page, int lang)
void TeletextScreen::DrawHeader(const tt_line_array& page, int lang)
{
if (!m_displaying)
return;

if (page != nullptr)
if (!page.empty())
DrawLine(page, 1, lang);

DrawStatus();
Expand Down Expand Up @@ -317,7 +317,7 @@ void TeletextScreen::SetBackgroundColor(int ttcolor)
0x00 : gTTBackgroundAlpha);
}

void TeletextScreen::DrawLine(const uint8_t *page, uint row, int lang)
void TeletextScreen::DrawLine(const tt_line_array& page, uint row, int lang)
{
unsigned char last_ch = ' ';

Expand Down
4 changes: 2 additions & 2 deletions mythtv/libs/libmythtv/captions/teletextscreen.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ class TeletextScreen: public MythScreenType
void DrawRect(int row, QRect rect);
void DrawCharacter(int x, int y, QChar ch, bool doubleheight = false);
void DrawMosaic(int x, int y, int code, bool doubleheight);
void DrawLine(const uint8_t *page, uint row, int lang);
void DrawHeader(const uint8_t *page, int lang);
void DrawLine(const tt_line_array& page, uint row, int lang);
void DrawHeader(const tt_line_array &page, int lang);
void DrawStatus(void);
void DrawPage(void);

Expand Down
2 changes: 1 addition & 1 deletion mythtv/libs/libmythtv/captions/vbi608extractor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ bool VBI608Extractor::ExtractCC34(const unsigned char *buf, uint width)
return false;
}

uint VBI608Extractor::FillCCData(uint8_t cc_data[8]) const
uint VBI608Extractor::FillCCData(cc608_data &cc_data) const
{
uint cc_count = 0;
if (m_code[0] != UINT16_MAX)
Expand Down
7 changes: 5 additions & 2 deletions mythtv/libs/libmythtv/captions/vbi608extractor.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,15 @@
#ifndef VBI_608_EXTRACTOR_H
#define VBI_608_EXTRACTOR_H

#include <array>
#include <cstdint>

#include <QList>

#include "mythframe.h"

using cc608_data = std::array<uint8_t,8>;

class VBI608Extractor
{
public:
Expand All @@ -38,7 +41,7 @@ class VBI608Extractor
bool ExtractCC12(const unsigned char *buf, uint width);
bool ExtractCC34(const unsigned char *buf, uint width);

uint FillCCData(uint8_t cc_data[8]) const;
uint FillCCData(cc608_data &cc_data) const;

private:
float GetClockStart(void) const { return m_start; }
Expand All @@ -51,7 +54,7 @@ class VBI608Extractor
QList<float> m_minimas;
float m_start {0.0F};
float m_rate {0.0F};
uint16_t m_code[2] {UINT16_MAX, UINT16_MAX};
std::array<uint16_t,2> m_code {UINT16_MAX, UINT16_MAX};
};

#endif // VBI_608_EXTRACTOR_H
7 changes: 4 additions & 3 deletions mythtv/libs/libmythtv/captions/xine_demux_sputext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include "config.h"
#endif

#include <array>
#include <cctype>
#include <cstdio>
#include <cstdlib>
Expand Down Expand Up @@ -121,7 +122,7 @@ static char *read_line_from_input(demux_sputext_t *demuxstr, char *line, off_t l

static subtitle_t *sub_read_line_sami(demux_sputext_t *demuxstr, subtitle_t *current) {

static char s_line[LINE_LEN + 1];
static std::array<char,LINE_LEN + 1> s_line;
static char *s_s = nullptr;
char text[LINE_LEN + 1];

Expand All @@ -132,7 +133,7 @@ static subtitle_t *sub_read_line_sami(demux_sputext_t *demuxstr, subtitle_t *cur

/* read the first line */
if (!s_s)
if (!(s_s = read_line_from_input(demuxstr, s_line, LINE_LEN))) return nullptr;
if (!(s_s = read_line_from_input(demuxstr, s_line.data(), LINE_LEN))) return nullptr;

do {
switch (state) {
Expand Down Expand Up @@ -183,7 +184,7 @@ static subtitle_t *sub_read_line_sami(demux_sputext_t *demuxstr, subtitle_t *cur
}

/* read next line */
if (state != 99 && !(s_s = read_line_from_input (demuxstr, s_line, LINE_LEN)))
if (state != 99 && !(s_s = read_line_from_input (demuxstr, s_line.data(), LINE_LEN)))
return nullptr;

} while (state != 99);
Expand Down
4 changes: 2 additions & 2 deletions mythtv/libs/libmythtv/decoders/avformatdecoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2927,7 +2927,7 @@ void AvFormatDecoder::UpdateCaptionTracksFromStreams(
bool check_608, bool check_708)
{
bool need_change_608 = false;
bool seen_608[4];
CC608Seen seen_608;
if (check_608)
{
m_ccd608->GetServices(15/*seconds*/, seen_608);
Expand All @@ -2939,7 +2939,7 @@ void AvFormatDecoder::UpdateCaptionTracksFromStreams(
}

bool need_change_708 = false;
bool seen_708[64];
cc708_seen_flags seen_708;
if (check_708 || need_change_608)
{
m_ccd708->services(15/*seconds*/, seen_708);
Expand Down
2 changes: 1 addition & 1 deletion mythtv/libs/libmythtv/mythccextractorplayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,7 @@ static QStringList to_string_list(const TeletextSubPage &subPage)
{
QStringList content;
// Skip the page header (line 0)
for (int i = 1; i < 25; ++i)
for (size_t i = 1; i < subPage.data.size(); ++i)
{
QString str = decode_teletext(subPage.lang, subPage.data[i]).trimmed();
if (!str.isEmpty())
Expand Down