3 * Copyright 2001,2006 Free Software Foundation, Inc.
5 * This file is part of GNU Radio
7 * GNU Radio is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3, or (at your option)
12 * GNU Radio is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with GNU Radio; see the file COPYING. If not, write to
19 * the Free Software Foundation, Inc., 51 Franklin Street,
20 * Boston, MA 02110-1301, USA.
23 #ifndef _ATSC_TYPES_H_
24 #define _ATSC_TYPES_H_
26 #include <atsc_consts.h>
32 * \brief pipeline info that flows with data
34 * Not all modules need all the info
38 plinfo () : _flags (0), _segno (0) { }
42 bool field_sync1_p () const { return (_flags & fl_field_sync1) != 0; }
43 bool field_sync2_p () const { return (_flags & fl_field_sync2) != 0; }
44 bool field_sync_p () const { return field_sync1_p () || field_sync2_p (); }
46 bool regular_seg_p () const { return (_flags & fl_regular_seg) != 0; }
48 bool in_field1_p () const { return (_flags & fl_field2) == 0; }
49 bool in_field2_p () const { return (_flags & fl_field2) != 0; }
51 bool first_regular_seg_p () const { return (_flags & fl_first_regular_seg) != 0; }
53 bool transport_error_p () const { return (_flags & fl_transport_error) != 0; }
55 unsigned int segno () const { return _segno; }
56 unsigned int flags () const { return _flags; }
60 void set_field_sync1 ()
63 _flags = fl_field_sync1;
66 void set_field_sync2 ()
69 _flags = fl_field_sync2 | fl_field2;
72 void set_regular_seg (bool field2, int segno)
74 assert (0 <= segno && segno < ATSC_DSEGS_PER_FIELD);
76 _flags = fl_regular_seg;
78 _flags |= fl_first_regular_seg;
79 if (segno >= ATSC_DSEGS_PER_FIELD)
80 _flags |= fl_transport_error;
85 void set_transport_error (bool error){
87 _flags |= fl_transport_error;
89 _flags &= ~fl_transport_error;
92 // overload equality operator
93 bool operator== (const plinfo &other) const {
94 return (_flags == other._flags && _segno == other._segno);
97 bool operator!= (const plinfo &other) const {
98 return !(_flags == other._flags && _segno == other._segno);
102 * Set \p OUT such that it reflects a \p NSEGS_OF_DELAY
103 * pipeline delay from \p IN.
105 static void delay (plinfo &out, const plinfo &in, int nsegs_of_delay);
108 * confirm that \p X is plausible
110 static void sanity_check (const plinfo &in);
114 unsigned short _flags; // bitmask
115 unsigned short _segno; // segment number [0,311]
117 // these three are mutually exclusive
118 // This is a regular data segment.
119 static const int fl_regular_seg = 0x0001;
120 // This is a field sync segment, for 1st half of a field.
121 static const int fl_field_sync1 = 0x0002;
122 // This is a field sync segment, for 2nd half of a field.
123 static const int fl_field_sync2 = 0x0004;
125 // This bit is on ONLY when fl_regular_seg is set AND when this is
126 // the first regular data segment AFTER a field sync segment. This
127 // segment causes various processing modules to reset.
128 static const int fl_first_regular_seg = 0x0008;
130 // which field are we in?
131 static const int fl_field2 = 0x0010; // else field 1
133 // This bit is set when Reed-Solomon decoding detects an error that it
134 // can't correct. Note that other error detection (e.g. Viterbi) do not
135 // set it, since Reed-Solomon will correct many of those. This bit is
136 // then copied into the final Transport Stream packet so that MPEG
137 // software can see that the 188-byte data segment has been corrupted.
138 static const int fl_transport_error = 0x0020;
144 class atsc_mpeg_packet {
146 static const int NPAD = 68;
147 unsigned char data[ATSC_MPEG_DATA_LENGTH + 1]; // first byte is sync
148 unsigned char _pad_[NPAD]; // pad to power of 2 (256)
150 // overload equality operator
151 bool operator== (const atsc_mpeg_packet &other) const {
152 return std::memcmp (data, other.data, sizeof (data)) == 0;
155 bool operator!= (const atsc_mpeg_packet &other) const {
156 return !(std::memcmp (data, other.data, sizeof (data)) == 0);
160 class atsc_mpeg_packet_no_sync {
162 static const int NPAD = 65;
164 unsigned char data[ATSC_MPEG_DATA_LENGTH];
165 unsigned char _pad_[NPAD]; // pad to power of 2 (256)
167 // overload equality operator
168 bool operator== (const atsc_mpeg_packet_no_sync &other) const {
169 return std::memcmp (data, other.data, sizeof (data)) == 0;
172 bool operator!= (const atsc_mpeg_packet_no_sync &other) const {
173 return !(std::memcmp (data, other.data, sizeof (data)) == 0);
177 class atsc_mpeg_packet_rs_encoded {
179 static const int NPAD = 45;
181 unsigned char data[ATSC_MPEG_RS_ENCODED_LENGTH];
182 unsigned char _pad_[NPAD]; // pad to power of 2 (256)
184 // overload equality operator
185 bool operator== (const atsc_mpeg_packet_rs_encoded &other) const {
186 return std::memcmp (data, other.data, sizeof (data)) == 0;
189 bool operator!= (const atsc_mpeg_packet_rs_encoded &other) const {
190 return !(std::memcmp (data, other.data, sizeof (data)) == 0);
195 //! contains 832 3 bit symbols. The low 3 bits in the byte hold the symbol.
197 class atsc_data_segment {
199 static const int NPAD = 188;
201 unsigned char data[ATSC_DATA_SEGMENT_LENGTH];
202 unsigned char _pad_[NPAD]; // pad to power of 2 (1024)
204 // overload equality operator
205 bool operator== (const atsc_data_segment &other) const {
206 return std::memcmp (data, other.data, sizeof (data)) == 0;
209 bool operator!= (const atsc_data_segment &other) const {
210 return !(std::memcmp (data, other.data, sizeof (data)) == 0);
215 * Contains 832 bipolar floating point symbols.
216 * Nominal values are +/- {1, 3, 5, 7}.
217 * This data type represents the input to the viterbi decoder.
220 class atsc_soft_data_segment {
222 static const int NPAD = 764;
224 float data[ATSC_DATA_SEGMENT_LENGTH];
225 unsigned char _pad_[NPAD]; // pad to power of 2 (4096)
227 // overload equality operator
228 bool operator== (const atsc_data_segment &other) const {
229 return std::memcmp (data, other.data, sizeof (data)) == 0;
232 bool operator!= (const atsc_data_segment &other) const {
233 return !(std::memcmp (data, other.data, sizeof (data)) == 0);
238 #endif /* _ATSC_TYPES_H_ */