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_ignore_time_code = 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[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>&,
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_ignore_time_code {false};
88 
89  time_t m_last_seen[4];
90 
91  // per-field
92  int m_badvbi[2];
93  int m_lasttc[2];
94  int m_lastcode[2];
95  int m_lastcodetc[2];
96  int m_ccmode[2]; // 0=cc1/txt1, 1=cc2/txt2
97  int m_xds[2];
98  int m_txtmode[4];
99 
100  // per-mode state
101  int m_lastrow[8];
102  int m_newrow[8];
103  int m_newcol[8];
104  int m_newattr[8]; // color+italic+underline
105  int m_timecode[8];
106  int m_row[8];
107  int m_col[8];
108  int m_rowcount[8];
109  int m_style[8];
110  int m_linecont[8];
111  int m_resumetext[8];
112  int m_lastclr[8];
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_last_format_tc[2];
121  int m_last_format_data[2];
122 
123  // VPS data
124  char m_vps_pr_label[20];
125  char m_vps_label[20];
126  int m_vps_l {0};
127 
128  // WSS data
129  uint m_wss_flags {0};
130  bool m_wss_valid {false};
131 
132  int m_xds_cur_service {-1};
133  vector<unsigned char> m_xds_buf[7];
134  uint m_xds_crc_passed {0};
135  uint m_xds_crc_failed {0};
136 
137  mutable QMutex m_xds_lock {QMutex::Recursive};
138  uint m_xds_rating_systems[2];
139  uint m_xds_rating[2][4];
140  QString m_xds_program_name[2];
141  vector<uint> m_xds_program_type[2];
142 
143  QString m_xds_net_call;
144  QString m_xds_net_name;
145  uint m_xds_tsid {0};
146 
147  QString m_xds_program_type_string[96];
148 };
149 
150 #endif
QChar CharCC(int code) const
Definition: cc608decoder.h:70
unsigned int uint
Definition: compat.h:140
QString m_xds_net_name
Definition: cc608decoder.h:144
QString m_xds_net_call
Definition: cc608decoder.h:143
void SetIgnoreTimecode(bool val)
Definition: cc608decoder.h:55