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