00001
00002
00003 #ifndef CCDECODER_H_
00004 #define CCDECODER_H_
00005
00006 #include <time.h>
00007 #include <stdint.h>
00008
00009 #include <vector>
00010 using namespace std;
00011
00012 #include <QString>
00013 #include <QMutex>
00014 #include <QChar>
00015
00016 #include "format.h"
00017
00018 class CC608Input
00019 {
00020 public:
00021 virtual ~CC608Input() { }
00022 virtual void AddTextData(unsigned char *buf, int len,
00023 int64_t timecode, char type) = 0;
00024 };
00025
00026 enum
00027 {
00028 kHasMPAA = 0x1,
00029 kHasTPG = 0x2,
00030 kHasCanEnglish = 0x4,
00031 kHasCanFrench = 0x8,
00032 };
00033 enum
00034 {
00035 kRatingMPAA = 0,
00036 kRatingTPG,
00037 kRatingCanEnglish,
00038 kRatingCanFrench,
00039 };
00040
00041 class CC608Decoder
00042 {
00043 public:
00044 CC608Decoder(CC608Input *ccr);
00045 ~CC608Decoder();
00046
00047 void FormatCC(int tc, int code1, int code2);
00048 void FormatCCField(int tc, int field, int data);
00049 int FalseDup(int tc, int field, int data);
00050
00051 void DecodeVPS(const unsigned char *buf);
00052 void DecodeWSS(const unsigned char *buf);
00053
00054 void SetIgnoreTimecode(bool val) { ignore_time_code = val; }
00055
00056 uint GetRatingSystems(bool future) const;
00057 uint GetRating(uint i, bool future) const;
00058 QString GetRatingString(uint i, bool future) const;
00059 QString GetProgramName(bool future) const;
00060 QString GetProgramType(bool future) const;
00061 QString GetXDS(const QString &key) const;
00062
00064 void GetServices(uint seconds, bool[4]) const;
00065
00066 static QString ToASCII(const QString &cc608, bool suppress_unknown);
00067
00068 private:
00069 QChar CharCC(int code) const { return stdchar[code]; }
00070 void ResetCC(int mode);
00071 void BufferCC(int mode, int len, int clr);
00072 int NewRowCC(int mode, int len);
00073
00074 QString XDSDecodeString(const vector<unsigned char>&,
00075 uint string, uint end) const;
00076 void XDSDecode(int field, int b1, int b2);
00077
00078 bool XDSPacketParseProgram(const vector<unsigned char> &xds_buf,
00079 bool future);
00080 bool XDSPacketParseChannel(const vector<unsigned char> &xds_buf);
00081 void XDSPacketParse(const vector<unsigned char> &xds_buf);
00082 bool XDSPacketCRC(const vector<unsigned char> &xds_buf);
00083
00084 CC608Input *reader;
00085
00086 bool ignore_time_code;
00087
00088 time_t last_seen[4];
00089
00090
00091 int badvbi[2];
00092 int lasttc[2];
00093 int lastcode[2];
00094 int lastcodetc[2];
00095 int ccmode[2];
00096 int xds[2];
00097 int txtmode[4];
00098
00099
00100 int lastrow[8];
00101 int newrow[8];
00102 int newcol[8];
00103 int newattr[8];
00104 int timecode[8];
00105 int row[8];
00106 int col[8];
00107 int rowcount[8];
00108 int style[8];
00109 int linecont[8];
00110 int resumetext[8];
00111 int lastclr[8];
00112 QString ccbuf[8];
00113
00114
00115 QChar stdchar[128];
00116
00117
00118 unsigned char *rbuf;
00119 int last_format_tc[2];
00120 int last_format_data[2];
00121
00122
00123 char vps_pr_label[20];
00124 char vps_label[20];
00125 int vps_l;
00126
00127
00128 uint wss_flags;
00129 bool wss_valid;
00130
00131 vector<unsigned char> xds_buf;
00132 uint xds_crc_passed;
00133 uint xds_crc_failed;
00134
00135 mutable QMutex xds_lock;
00136 uint xds_rating_systems[2];
00137 uint xds_rating[2][4];
00138 QString xds_program_name[2];
00139 vector<uint> xds_program_type[2];
00140
00141 QString xds_net_call;
00142 QString xds_net_name;
00143 uint xds_tsid;
00144
00145 QString xds_program_type_string[96];
00146 };
00147
00148 #endif