MythTV  master
cc608decoder.h
Go to the documentation of this file.
1 // -*- Mode: c++ -*-
2 
3 #ifndef CCDECODER_H_
4 #define CCDECODER_H_
5 
6 #include <cstdint>
7 #include <ctime>
8 
9 #include <array>
10 #include <vector>
11 
12 #include <QString>
13 #if QT_VERSION < QT_VERSION_CHECK(5,14,0)
14 #include <QMutex>
15 #else
16 #include <QRecursiveMutex>
17 #endif
18 #include <QChar>
19 
20 #include "libmythtv/format.h"
21 #include "libmythbase/mythchrono.h"
22 
23 using CC608Seen = std::array<bool,4>;
24 using CC608ProgramType = std::array<QString,96>;
25 using CC608PerField = std::array<int,2>;
26 using CC608PerFieldTc = std::array<std::chrono::milliseconds,2>;
27 using CC608PerMode = std::array<int,8>;
28 using CC608PerModeTc = std::array<std::chrono::milliseconds,8>;
29 
31 {
32  public:
33  virtual ~CC608Input() = default;
34  virtual void AddTextData(unsigned char *buf, int len,
35  std::chrono::milliseconds timecode, char type) = 0;
36 };
37 
38 enum
39 {
40  kHasMPAA = 0x1,
41  kHasTPG = 0x2,
44 };
45 enum
46 {
51 };
52 
54 {
55  public:
56  explicit CC608Decoder(CC608Input *ccr);
57  CC608Decoder(const CC608Decoder& rhs);
58  ~CC608Decoder();
59 
60  void FormatCC(std::chrono::milliseconds tc, int code1, int code2);
61  void FormatCCField(std::chrono::milliseconds tc, size_t field, int data);
62  bool FalseDup(std::chrono::milliseconds tc, int field, int data);
63 
64  void DecodeVPS(const unsigned char *buf);
65  void DecodeWSS(const unsigned char *buf);
66 
67  void SetIgnoreTimecode(bool val) { m_ignoreTimeCode = val; }
68 
69  uint GetRatingSystems(bool future) const;
70  uint GetRating(uint i, bool future) const;
71  QString GetRatingString(uint i, bool future) const;
72  QString GetProgramName(bool future) const;
73  QString GetProgramType(bool future) const;
74  QString GetXDS(const QString &key) const;
75 
77  void GetServices(std::chrono::seconds seconds, CC608Seen& seen) const;
78 
79  static QString ToASCII(const QString &cc608, bool suppress_unknown);
80 
81  private:
82  QChar CharCC(int code) const { return m_stdChar[code]; }
83  void ResetCC(size_t mode);
84  void BufferCC(size_t mode, int len, int clr);
85  int NewRowCC(size_t mode, int len);
86 
87  QString XDSDecodeString(const std::vector<unsigned char>&buf,
88  uint start, uint end) const;
89  bool XDSDecode(int field, int b1, int b2);
90 
91  bool XDSPacketParseProgram(const std::vector<unsigned char> &xds_buf,
92  bool future);
93  bool XDSPacketParseChannel(const std::vector<unsigned char> &xds_buf);
94  void XDSPacketParse(const std::vector<unsigned char> &xds_buf);
95  bool XDSPacketCRC(const std::vector<unsigned char> &xds_buf);
96 
97  CC608Input *m_reader {nullptr};
98 
99  bool m_ignoreTimeCode {false};
100 
101  std::array<SystemTime,4> m_lastSeen {};
102 
103  // per-field
108  CC608PerField m_ccMode {-1, -1}; // 0=cc1/txt1, 1=cc2/txt2
110  std::array<int,4> m_txtMode { 0, 0, 0, 0};
111 
112  // per-mode state
116  CC608PerMode m_newAttr {0}; // color+italic+underline
125  std::array<QString,8> m_ccBuf;
126 
127  // translation table
128  std::array<QChar,128> m_stdChar;
129 
130  // temporary buffer
131  unsigned char *m_rbuf {nullptr};
134 
135  // VPS data
136  std::array<char,20> m_vpsPrLabel {0};
137  std::array<char,20> m_vpsLabel {0};
138  int m_vpsL {0};
139 
140  // WSS data
142  bool m_wssValid {false};
143 
144  int m_xdsCurService {-1};
145  std::array<std::vector<unsigned char>,7> m_xdsBuf;
148 
149 #if QT_VERSION < QT_VERSION_CHECK(5,14,0)
150  mutable QMutex m_xdsLock {QMutex::Recursive};
151 #else
152  mutable QRecursiveMutex m_xdsLock;
153 #endif
154  std::array<uint,2> m_xdsRatingSystems {0};
155  std::array<std::array<uint,4>,2> m_xdsRating {{}};
156  std::array<QString,2> m_xdsProgramName;
157  std::array<std::vector<uint>,2> m_xdsProgramType;
158 
159  QString m_xdsNetCall;
160  QString m_xdsNetName;
162 
164 };
165 
166 #endif
CC608Decoder::m_rbuf
unsigned char * m_rbuf
Definition: cc608decoder.h:131
CC608Decoder::m_lastClr
CC608PerModeTc m_lastClr
Definition: cc608decoder.h:124
CC608Decoder::m_lastCodeTc
CC608PerFieldTc m_lastCodeTc
Definition: cc608decoder.h:107
CC608Decoder::SetIgnoreTimecode
void SetIgnoreTimecode(bool val)
Definition: cc608decoder.h:67
CC608Decoder::m_newCol
CC608PerMode m_newCol
Definition: cc608decoder.h:115
CC608Decoder::m_xdsRatingSystems
std::array< uint, 2 > m_xdsRatingSystems
Definition: cc608decoder.h:154
CC608Decoder::m_ccMode
CC608PerField m_ccMode
Definition: cc608decoder.h:108
CC608Decoder::m_xdsCurService
int m_xdsCurService
Definition: cc608decoder.h:144
CC608Decoder::GetRating
uint GetRating(uint i, bool future) const
Definition: cc608decoder.cpp:1004
CC608PerMode
std::array< int, 8 > CC608PerMode
Definition: cc608decoder.h:27
CC608Decoder::FormatCC
void FormatCC(std::chrono::milliseconds tc, int code1, int code2)
Definition: cc608decoder.cpp:50
CC608Decoder::m_vpsLabel
std::array< char, 20 > m_vpsLabel
Definition: cc608decoder.h:137
kRatingTPG
@ kRatingTPG
Definition: cc608decoder.h:48
CC608Decoder
Definition: cc608decoder.h:53
format.h
CC608Decoder::m_xdsNetName
QString m_xdsNetName
Definition: cc608decoder.h:160
CC608Input::~CC608Input
virtual ~CC608Input()=default
CC608Decoder::m_vpsL
int m_vpsL
Definition: cc608decoder.h:138
CC608Decoder::m_badVbi
CC608PerField m_badVbi
Definition: cc608decoder.h:104
kRatingCanFrench
@ kRatingCanFrench
Definition: cc608decoder.h:50
CC608Input
Definition: cc608decoder.h:30
CC608Decoder::m_xdsProgramTypeString
CC608ProgramType m_xdsProgramTypeString
Definition: cc608decoder.h:163
CC608Decoder::m_rowCount
CC608PerMode m_rowCount
Definition: cc608decoder.h:120
CC608Decoder::GetProgramName
QString GetProgramName(bool future) const
Definition: cc608decoder.cpp:1046
CC608Decoder::BufferCC
void BufferCC(size_t mode, int len, int clr)
Definition: cc608decoder.cpp:664
CC608Seen
std::array< bool, 4 > CC608Seen
Definition: cc608decoder.h:23
CC608Decoder::m_wssValid
bool m_wssValid
Definition: cc608decoder.h:142
CC608Decoder::XDSDecode
bool XDSDecode(int field, int b1, int b2)
Definition: cc608decoder.cpp:1118
CC608Decoder::m_ignoreTimeCode
bool m_ignoreTimeCode
Definition: cc608decoder.h:99
CC608Decoder::m_newAttr
CC608PerMode m_newAttr
Definition: cc608decoder.h:116
CC608Decoder::ToASCII
static QString ToASCII(const QString &cc608, bool suppress_unknown)
Definition: cc608decoder.cpp:625
CC608Decoder::m_col
CC608PerMode m_col
Definition: cc608decoder.h:119
CC608Decoder::FalseDup
bool FalseDup(std::chrono::milliseconds tc, int field, int data)
Definition: cc608decoder.cpp:543
CC608Decoder::m_lastTc
CC608PerFieldTc m_lastTc
Definition: cc608decoder.h:105
CC608Decoder::m_vpsPrLabel
std::array< char, 20 > m_vpsPrLabel
Definition: cc608decoder.h:136
CC608Decoder::m_txtMode
std::array< int, 4 > m_txtMode
Definition: cc608decoder.h:110
CC608Decoder::m_newRow
CC608PerMode m_newRow
Definition: cc608decoder.h:114
CC608Decoder::m_style
CC608PerMode m_style
Definition: cc608decoder.h:121
CC608Decoder::m_xdsCrcPassed
uint m_xdsCrcPassed
Definition: cc608decoder.h:146
CC608Decoder::DecodeWSS
void DecodeWSS(const unsigned char *buf)
Definition: cc608decoder.cpp:914
kRatingMPAA
@ kRatingMPAA
Definition: cc608decoder.h:47
CC608ProgramType
std::array< QString, 96 > CC608ProgramType
Definition: cc608decoder.h:24
CC608Decoder::m_xdsProgramName
std::array< QString, 2 > m_xdsProgramName
Definition: cc608decoder.h:156
CC608Decoder::~CC608Decoder
~CC608Decoder()
Definition: cc608decoder.cpp:45
CC608Decoder::GetRatingString
QString GetRatingString(uint i, bool future) const
Definition: cc608decoder.cpp:1010
CC608Decoder::m_resumeText
CC608PerMode m_resumeText
Definition: cc608decoder.h:123
kRatingCanEnglish
@ kRatingCanEnglish
Definition: cc608decoder.h:49
CC608Decoder::m_timeCode
CC608PerModeTc m_timeCode
Definition: cc608decoder.h:117
CC608Decoder::m_lastFormatTc
CC608PerFieldTc m_lastFormatTc
Definition: cc608decoder.h:132
kHasTPG
@ kHasTPG
Definition: cc608decoder.h:41
CC608Decoder::GetRatingSystems
uint GetRatingSystems(bool future) const
Definition: cc608decoder.cpp:998
CC608PerModeTc
std::array< std::chrono::milliseconds, 8 > CC608PerModeTc
Definition: cc608decoder.h:28
CC608Decoder::m_row
CC608PerMode m_row
Definition: cc608decoder.h:118
CC608Decoder::m_xds
CC608PerField m_xds
Definition: cc608decoder.h:109
CC608Decoder::m_xdsNetCall
QString m_xdsNetCall
Definition: cc608decoder.h:159
CC608PerField
std::array< int, 2 > CC608PerField
Definition: cc608decoder.h:25
CC608Decoder::NewRowCC
int NewRowCC(size_t mode, int len)
Definition: cc608decoder.cpp:726
CC608Decoder::m_reader
CC608Input * m_reader
Definition: cc608decoder.h:97
uint
unsigned int uint
Definition: compat.h:81
CC608Decoder::m_lineCont
CC608PerMode m_lineCont
Definition: cc608decoder.h:122
CC608Input::AddTextData
virtual void AddTextData(unsigned char *buf, int len, std::chrono::milliseconds timecode, char type)=0
CC608Decoder::m_ccBuf
std::array< QString, 8 > m_ccBuf
Definition: cc608decoder.h:125
CC608Decoder::m_lastRow
CC608PerMode m_lastRow
Definition: cc608decoder.h:113
CC608Decoder::CharCC
QChar CharCC(int code) const
Definition: cc608decoder.h:82
CC608Decoder::FormatCCField
void FormatCCField(std::chrono::milliseconds tc, size_t field, int data)
Definition: cc608decoder.cpp:101
CC608Decoder::m_xdsCrcFailed
uint m_xdsCrcFailed
Definition: cc608decoder.h:147
CC608Decoder::m_lastFormatData
CC608PerField m_lastFormatData
Definition: cc608decoder.h:133
CC608Decoder::m_xdsRating
std::array< std::array< uint, 4 >, 2 > m_xdsRating
Definition: cc608decoder.h:155
CC608Decoder::m_xdsTsid
uint m_xdsTsid
Definition: cc608decoder.h:161
CC608Decoder::m_xdsLock
QRecursiveMutex m_xdsLock
Definition: cc608decoder.h:152
kHasCanEnglish
@ kHasCanEnglish
Definition: cc608decoder.h:42
CC608Decoder::ResetCC
void ResetCC(size_t mode)
Definition: cc608decoder.cpp:609
mythchrono.h
CC608Decoder::XDSPacketCRC
bool XDSPacketCRC(const std::vector< unsigned char > &xds_buf)
Definition: cc608decoder.cpp:1220
kHasCanFrench
@ kHasCanFrench
Definition: cc608decoder.h:43
CC608Decoder::DecodeVPS
void DecodeVPS(const unsigned char *buf)
Definition: cc608decoder.cpp:876
CC608Decoder::GetXDS
QString GetXDS(const QString &key) const
Definition: cc608decoder.cpp:1068
CC608Decoder::XDSPacketParse
void XDSPacketParse(const std::vector< unsigned char > &xds_buf)
Definition: cc608decoder.cpp:1187
CC608PerFieldTc
std::array< std::chrono::milliseconds, 2 > CC608PerFieldTc
Definition: cc608decoder.h:26
CC608Decoder::m_stdChar
std::array< QChar, 128 > m_stdChar
Definition: cc608decoder.h:128
CC608Decoder::XDSPacketParseChannel
bool XDSPacketParseChannel(const std::vector< unsigned char > &xds_buf)
Definition: cc608decoder.cpp:1402
CC608Decoder::m_lastSeen
std::array< SystemTime, 4 > m_lastSeen
Definition: cc608decoder.h:101
CC608Decoder::XDSDecodeString
QString XDSDecodeString(const std::vector< unsigned char > &buf, uint start, uint end) const
Definition: cc608decoder.cpp:955
CC608Decoder::GetServices
void GetServices(std::chrono::seconds seconds, CC608Seen &seen) const
Definition: cc608decoder.cpp:56
CC608Decoder::m_xdsBuf
std::array< std::vector< unsigned char >, 7 > m_xdsBuf
Definition: cc608decoder.h:145
CC608Decoder::XDSPacketParseProgram
bool XDSPacketParseProgram(const std::vector< unsigned char > &xds_buf, bool future)
Definition: cc608decoder.cpp:1241
CC608Decoder::m_xdsProgramType
std::array< std::vector< uint >, 2 > m_xdsProgramType
Definition: cc608decoder.h:157
CC608Decoder::m_wssFlags
uint m_wssFlags
Definition: cc608decoder.h:141
CC608Decoder::CC608Decoder
CC608Decoder(CC608Input *ccr)
Definition: cc608decoder.cpp:24
kHasMPAA
@ kHasMPAA
Definition: cc608decoder.h:40
CC608Decoder::GetProgramType
QString GetProgramType(bool future) const
Definition: cc608decoder.cpp:1052
CC608Decoder::m_lastCode
CC608PerField m_lastCode
Definition: cc608decoder.h:106