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