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