GNU Radio 3.6.5 C++ API
|
00001 /* -*- c++ -*- */ 00002 /* 00003 * Copyright 2001,2006 Free Software Foundation, Inc. 00004 * 00005 * This file is part of GNU Radio 00006 * 00007 * GNU Radio is free software; you can redistribute it and/or modify 00008 * it under the terms of the GNU General Public License as published by 00009 * the Free Software Foundation; either version 3, or (at your option) 00010 * any later version. 00011 * 00012 * GNU Radio is distributed in the hope that it will be useful, 00013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 * GNU General Public License for more details. 00016 * 00017 * You should have received a copy of the GNU General Public License 00018 * along with GNU Radio; see the file COPYING. If not, write to 00019 * the Free Software Foundation, Inc., 51 Franklin Street, 00020 * Boston, MA 02110-1301, USA. 00021 */ 00022 00023 #ifndef _ATSC_TYPES_H_ 00024 #define _ATSC_TYPES_H_ 00025 00026 #include <atsc_consts.h> 00027 #include <cstring> 00028 #include <cassert> 00029 00030 00031 /*! 00032 * \brief pipeline info that flows with data 00033 * 00034 * Not all modules need all the info 00035 */ 00036 class plinfo { 00037 public: 00038 plinfo () : _flags (0), _segno (0) { } 00039 00040 // accessors 00041 00042 bool field_sync1_p () const { return (_flags & fl_field_sync1) != 0; } 00043 bool field_sync2_p () const { return (_flags & fl_field_sync2) != 0; } 00044 bool field_sync_p () const { return field_sync1_p () || field_sync2_p (); } 00045 00046 bool regular_seg_p () const { return (_flags & fl_regular_seg) != 0; } 00047 00048 bool in_field1_p () const { return (_flags & fl_field2) == 0; } 00049 bool in_field2_p () const { return (_flags & fl_field2) != 0; } 00050 00051 bool first_regular_seg_p () const { return (_flags & fl_first_regular_seg) != 0; } 00052 00053 bool transport_error_p () const { return (_flags & fl_transport_error) != 0; } 00054 00055 unsigned int segno () const { return _segno; } 00056 unsigned int flags () const { return _flags; } 00057 00058 // setters 00059 00060 void set_field_sync1 () 00061 { 00062 _segno = 0; 00063 _flags = fl_field_sync1; 00064 } 00065 00066 void set_field_sync2 () 00067 { 00068 _segno = 0; 00069 _flags = fl_field_sync2 | fl_field2; 00070 } 00071 00072 void set_regular_seg (bool field2, int segno) 00073 { 00074 assert (0 <= segno && segno < ATSC_DSEGS_PER_FIELD); 00075 _segno = segno; 00076 _flags = fl_regular_seg; 00077 if (segno == 0) 00078 _flags |= fl_first_regular_seg; 00079 if (segno >= ATSC_DSEGS_PER_FIELD) 00080 _flags |= fl_transport_error; 00081 if (field2) 00082 _flags |= fl_field2; 00083 } 00084 00085 void set_transport_error (bool error){ 00086 if (error) 00087 _flags |= fl_transport_error; 00088 else 00089 _flags &= ~fl_transport_error; 00090 } 00091 00092 // overload equality operator 00093 bool operator== (const plinfo &other) const { 00094 return (_flags == other._flags && _segno == other._segno); 00095 } 00096 00097 bool operator!= (const plinfo &other) const { 00098 return !(_flags == other._flags && _segno == other._segno); 00099 } 00100 00101 /*! 00102 * Set \p OUT such that it reflects a \p NSEGS_OF_DELAY 00103 * pipeline delay from \p IN. 00104 */ 00105 static void delay (plinfo &out, const plinfo &in, int nsegs_of_delay); 00106 00107 /*! 00108 * confirm that \p X is plausible 00109 */ 00110 static void sanity_check (const plinfo &in); 00111 00112 00113 protected: 00114 unsigned short _flags; // bitmask 00115 unsigned short _segno; // segment number [0,311] 00116 00117 // these three are mutually exclusive 00118 // This is a regular data segment. 00119 static const int fl_regular_seg = 0x0001; 00120 // This is a field sync segment, for 1st half of a field. 00121 static const int fl_field_sync1 = 0x0002; 00122 // This is a field sync segment, for 2nd half of a field. 00123 static const int fl_field_sync2 = 0x0004; 00124 00125 // This bit is on ONLY when fl_regular_seg is set AND when this is 00126 // the first regular data segment AFTER a field sync segment. This 00127 // segment causes various processing modules to reset. 00128 static const int fl_first_regular_seg = 0x0008; 00129 00130 // which field are we in? 00131 static const int fl_field2 = 0x0010; // else field 1 00132 00133 // This bit is set when Reed-Solomon decoding detects an error that it 00134 // can't correct. Note that other error detection (e.g. Viterbi) do not 00135 // set it, since Reed-Solomon will correct many of those. This bit is 00136 // then copied into the final Transport Stream packet so that MPEG 00137 // software can see that the 188-byte data segment has been corrupted. 00138 static const int fl_transport_error = 0x0020; 00139 }; 00140 00141 00142 00143 00144 class atsc_mpeg_packet { 00145 public: 00146 static const int NPAD = 68; 00147 unsigned char data[ATSC_MPEG_DATA_LENGTH + 1]; // first byte is sync 00148 unsigned char _pad_[NPAD]; // pad to power of 2 (256) 00149 00150 // overload equality operator 00151 bool operator== (const atsc_mpeg_packet &other) const { 00152 return std::memcmp (data, other.data, sizeof (data)) == 0; 00153 }; 00154 00155 bool operator!= (const atsc_mpeg_packet &other) const { 00156 return !(std::memcmp (data, other.data, sizeof (data)) == 0); 00157 }; 00158 }; 00159 00160 class atsc_mpeg_packet_no_sync { 00161 public: 00162 static const int NPAD = 65; 00163 plinfo pli; 00164 unsigned char data[ATSC_MPEG_DATA_LENGTH]; 00165 unsigned char _pad_[NPAD]; // pad to power of 2 (256) 00166 00167 // overload equality operator 00168 bool operator== (const atsc_mpeg_packet_no_sync &other) const { 00169 return std::memcmp (data, other.data, sizeof (data)) == 0; 00170 } 00171 00172 bool operator!= (const atsc_mpeg_packet_no_sync &other) const { 00173 return !(std::memcmp (data, other.data, sizeof (data)) == 0); 00174 } 00175 }; 00176 00177 class atsc_mpeg_packet_rs_encoded { 00178 public: 00179 static const int NPAD = 45; 00180 plinfo pli; 00181 unsigned char data[ATSC_MPEG_RS_ENCODED_LENGTH]; 00182 unsigned char _pad_[NPAD]; // pad to power of 2 (256) 00183 00184 // overload equality operator 00185 bool operator== (const atsc_mpeg_packet_rs_encoded &other) const { 00186 return std::memcmp (data, other.data, sizeof (data)) == 0; 00187 } 00188 00189 bool operator!= (const atsc_mpeg_packet_rs_encoded &other) const { 00190 return !(std::memcmp (data, other.data, sizeof (data)) == 0); 00191 } 00192 }; 00193 00194 00195 //! contains 832 3 bit symbols. The low 3 bits in the byte hold the symbol. 00196 00197 class atsc_data_segment { 00198 public: 00199 static const int NPAD = 188; 00200 plinfo pli; 00201 unsigned char data[ATSC_DATA_SEGMENT_LENGTH]; 00202 unsigned char _pad_[NPAD]; // pad to power of 2 (1024) 00203 00204 // overload equality operator 00205 bool operator== (const atsc_data_segment &other) const { 00206 return std::memcmp (data, other.data, sizeof (data)) == 0; 00207 } 00208 00209 bool operator!= (const atsc_data_segment &other) const { 00210 return !(std::memcmp (data, other.data, sizeof (data)) == 0); 00211 } 00212 }; 00213 00214 /*! 00215 * Contains 832 bipolar floating point symbols. 00216 * Nominal values are +/- {1, 3, 5, 7}. 00217 * This data type represents the input to the viterbi decoder. 00218 */ 00219 00220 class atsc_soft_data_segment { 00221 public: 00222 static const int NPAD = 764; 00223 plinfo pli; 00224 float data[ATSC_DATA_SEGMENT_LENGTH]; 00225 unsigned char _pad_[NPAD]; // pad to power of 2 (4096) 00226 00227 // overload equality operator 00228 bool operator== (const atsc_data_segment &other) const { 00229 return std::memcmp (data, other.data, sizeof (data)) == 0; 00230 } 00231 00232 bool operator!= (const atsc_data_segment &other) const { 00233 return !(std::memcmp (data, other.data, sizeof (data)) == 0); 00234 } 00235 }; 00236 00237 00238 #endif /* _ATSC_TYPES_H_ */