GNU Radio Manual and C++ API Reference  3.7.5.1
The Free & Open Software Radio Ecosystem
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
atsc_types.h
Go to the documentation of this file.
1 /* -*- c++ -*- */
2 /*
3  * Copyright 2001,2006,2014 Free Software Foundation, Inc.
4  *
5  * This file is part of GNU Radio
6  *
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)
10  * any later version.
11  *
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.
16  *
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.
21  */
22 
23 #ifndef DTV_INCLUDED_ATSC_TYPES_H
24 #define DTV_INCLUDED_ATSC_TYPES_H
25 
27 #include <cstring>
28 #include <cassert>
29 
30 namespace gr {
31  namespace dtv {
32 
33  /*!
34  * \brief pipeline info that flows with data
35  *
36  * Not all modules need all the info
37  */
38  class plinfo {
39  public:
40  plinfo () : _flags (0), _segno (0) { }
41 
42  // accessors
43 
44  bool field_sync1_p () const { return (_flags & fl_field_sync1) != 0; }
45  bool field_sync2_p () const { return (_flags & fl_field_sync2) != 0; }
46  bool field_sync_p () const { return field_sync1_p () || field_sync2_p (); }
47 
48  bool regular_seg_p () const { return (_flags & fl_regular_seg) != 0; }
49 
50  bool in_field1_p () const { return (_flags & fl_field2) == 0; }
51  bool in_field2_p () const { return (_flags & fl_field2) != 0; }
52 
53  bool first_regular_seg_p () const { return (_flags & fl_first_regular_seg) != 0; }
54 
55  bool transport_error_p () const { return (_flags & fl_transport_error) != 0; }
56 
57  unsigned int segno () const { return _segno; }
58  unsigned int flags () const { return _flags; }
59 
60  // setters
61 
63  {
64  _segno = 0;
66  }
67 
69  {
70  _segno = 0;
72  }
73 
74  void set_regular_seg (bool field2, int segno)
75  {
76  //assert (0 <= segno && segno < ATSC_DSEGS_PER_FIELD);
77  _segno = segno;
79  if (segno == 0)
81  if (segno >= ATSC_DSEGS_PER_FIELD)
83  if (field2)
84  _flags |= fl_field2;
85  }
86 
87  void set_transport_error (bool error){
88  if (error)
90  else
92  }
93 
94  // overload equality operator
95  bool operator== (const plinfo &other) const {
96  return (_flags == other._flags && _segno == other._segno);
97  }
98 
99  bool operator!= (const plinfo &other) const {
100  return !(_flags == other._flags && _segno == other._segno);
101  }
102 
103  /*!
104  * Set \p OUT such that it reflects a \p NSEGS_OF_DELAY
105  * pipeline delay from \p IN.
106  */
107  static void delay (plinfo &out, const plinfo &in, int nsegs_of_delay)
108  {
109  assert (in.regular_seg_p ());
110  assert (nsegs_of_delay >= 0);
111 
112  int s = in.segno ();
113  if (in.in_field2_p ())
115 
116  s -= nsegs_of_delay;
117  if (s < 0)
118  s += 2 * ATSC_DSEGS_PER_FIELD;
119 
120  //assert (0 <= s && s < 2 * ATSC_DSEGS_PER_FIELD);
121 
122  if (s < ATSC_DSEGS_PER_FIELD)
123  out.set_regular_seg (false, s); // field 1
124  else
125  out.set_regular_seg (true, s - ATSC_DSEGS_PER_FIELD); // field 2
126  }
127 
128  /*!
129  * confirm that \p X is plausible
130  */
131  static void sanity_check (const plinfo &in)
132  {
133  // basic sanity checks...
134  //assert (x.segno () >= 0);
135  //assert (x.segno () < (unsigned) ATSC_DSEGS_PER_FIELD);
136  //assert ((x.flags () & ~0x3f) == 0);
137 
138  //assert (x.regular_seg_p () ^ x.field_sync_p ());
139  //assert ((x.segno () != 0) ^ x.first_regular_seg_p ());
140  }
141 
142  unsigned short _flags; // bitmask
143  short _segno; // segment number [-1,311] -1 is the field sync segment
144 
145  protected:
146  // these three are mutually exclusive
147  // This is a regular data segment.
148  static const int fl_regular_seg = 0x0001;
149  // This is a field sync segment, for 1st half of a field.
150  static const int fl_field_sync1 = 0x0002;
151  // This is a field sync segment, for 2nd half of a field.
152  static const int fl_field_sync2 = 0x0004;
153 
154  // This bit is on ONLY when fl_regular_seg is set AND when this is
155  // the first regular data segment AFTER a field sync segment. This
156  // segment causes various processing modules to reset.
157  static const int fl_first_regular_seg = 0x0008;
158 
159  // which field are we in?
160  static const int fl_field2 = 0x0010; // else field 1
161 
162  // This bit is set when Reed-Solomon decoding detects an error that it
163  // can't correct. Note that other error detection (e.g. Viterbi) do not
164  // set it, since Reed-Solomon will correct many of those. This bit is
165  // then copied into the final Transport Stream packet so that MPEG
166  // software can see that the 188-byte data segment has been corrupted.
167  static const int fl_transport_error = 0x0020;
168  };
169 
170 
171 
172 
174  public:
175  static const int NPAD = 68;
176  unsigned char data[ATSC_MPEG_DATA_LENGTH + 1]; // first byte is sync
177  unsigned char _pad_[NPAD]; // pad to power of 2 (256)
178 
179  // overload equality operator
180  bool operator== (const atsc_mpeg_packet &other) const {
181  return std::memcmp (data, other.data, sizeof (data)) == 0;
182  };
183 
184  bool operator!= (const atsc_mpeg_packet &other) const {
185  return !(std::memcmp (data, other.data, sizeof (data)) == 0);
186  };
187  };
188 
190  public:
191  static const int NPAD = 65;
193  unsigned char data[ATSC_MPEG_DATA_LENGTH];
194  unsigned char _pad_[NPAD]; // pad to power of 2 (256)
195 
196  // overload equality operator
197  bool operator== (const atsc_mpeg_packet_no_sync &other) const {
198  return std::memcmp (data, other.data, sizeof (data)) == 0;
199  }
200 
201  bool operator!= (const atsc_mpeg_packet_no_sync &other) const {
202  return !(std::memcmp (data, other.data, sizeof (data)) == 0);
203  }
204  };
205 
207  public:
208  static const int NPAD = 45;
211  unsigned char _pad_[NPAD]; // pad to power of 2 (256)
212 
213  // overload equality operator
214  bool operator== (const atsc_mpeg_packet_rs_encoded &other) const {
215  return std::memcmp (data, other.data, sizeof (data)) == 0;
216  }
217 
218  bool operator!= (const atsc_mpeg_packet_rs_encoded &other) const {
219  return !(std::memcmp (data, other.data, sizeof (data)) == 0);
220  }
221  };
222 
223 
224  //! contains 832 3 bit symbols. The low 3 bits in the byte hold the symbol.
225 
227  public:
228  static const int NPAD = 188;
231  unsigned char _pad_[NPAD]; // pad to power of 2 (1024)
232 
233  // overload equality operator
234  bool operator== (const atsc_data_segment &other) const {
235  return std::memcmp (data, other.data, sizeof (data)) == 0;
236  }
237 
238  bool operator!= (const atsc_data_segment &other) const {
239  return !(std::memcmp (data, other.data, sizeof (data)) == 0);
240  }
241  };
242 
243  /*!
244  * Contains 832 bipolar floating point symbols.
245  * Nominal values are +/- {1, 3, 5, 7}.
246  * This data type represents the input to the viterbi decoder.
247  */
248 
250  public:
251  static const int NPAD = 764;
254  unsigned char _pad_[NPAD]; // pad to power of 2 (4096)
255 
256  // overload equality operator
257  bool operator== (const atsc_data_segment &other) const {
258  return std::memcmp (data, other.data, sizeof (data)) == 0;
259  }
260 
261  bool operator!= (const atsc_data_segment &other) const {
262  return !(std::memcmp (data, other.data, sizeof (data)) == 0);
263  }
264  };
265 
266  } /* namespace dtv */
267 } /* namespace gr */
268 
269 #endif /* _ATSC_TYPES_H_ */
plinfo()
Definition: atsc_types.h:40
float data[ATSC_DATA_SEGMENT_LENGTH]
Definition: atsc_types.h:253
static const int ATSC_DSEGS_PER_FIELD
Definition: atsc_consts.h:42
bool operator!=(const atsc_mpeg_packet_rs_encoded &other) const
Definition: atsc_types.h:218
Definition: atsc_types.h:206
unsigned char _pad_[NPAD]
Definition: atsc_types.h:231
static const int NPAD
Definition: atsc_types.h:228
unsigned int segno() const
Definition: atsc_types.h:57
bool operator==(const atsc_mpeg_packet_rs_encoded &other) const
Definition: atsc_types.h:214
bool operator!=(const atsc_data_segment &other) const
Definition: atsc_types.h:261
Definition: atsc_types.h:189
static const int fl_field_sync2
Definition: atsc_types.h:152
unsigned char data[ATSC_MPEG_DATA_LENGTH+1]
Definition: atsc_types.h:176
unsigned char _pad_[NPAD]
Definition: atsc_types.h:194
bool operator!=(const atsc_mpeg_packet_no_sync &other) const
Definition: atsc_types.h:201
unsigned int flags() const
Definition: atsc_types.h:58
Definition: atsc_types.h:249
static const int NPAD
Definition: atsc_types.h:251
bool operator==(const atsc_data_segment &other) const
Definition: atsc_types.h:257
bool operator==(const atsc_data_segment &other) const
Definition: atsc_types.h:234
pipeline info that flows with data
Definition: atsc_types.h:38
bool first_regular_seg_p() const
Definition: atsc_types.h:53
bool transport_error_p() const
Definition: atsc_types.h:55
void set_field_sync2()
Definition: atsc_types.h:68
short _segno
Definition: atsc_types.h:143
static const int ATSC_DATA_SEGMENT_LENGTH
Definition: atsc_consts.h:41
unsigned char data[ATSC_MPEG_DATA_LENGTH]
Definition: atsc_types.h:193
static const int fl_field_sync1
Definition: atsc_types.h:150
bool operator!=(const atsc_mpeg_packet &other) const
Definition: atsc_types.h:184
static void delay(plinfo &out, const plinfo &in, int nsegs_of_delay)
Definition: atsc_types.h:107
bool operator!=(const plinfo &other) const
Definition: atsc_types.h:99
void set_field_sync1()
Definition: atsc_types.h:62
bool operator==(const atsc_mpeg_packet_no_sync &other) const
Definition: atsc_types.h:197
static const int NPAD
Definition: atsc_types.h:191
bool regular_seg_p() const
Definition: atsc_types.h:48
static const int fl_regular_seg
Definition: atsc_types.h:148
static const int NPAD
Definition: atsc_types.h:208
static const int fl_field2
Definition: atsc_types.h:160
bool operator==(const atsc_mpeg_packet &other) const
Definition: atsc_types.h:180
bool field_sync_p() const
Definition: atsc_types.h:46
static const int ATSC_MPEG_RS_ENCODED_LENGTH
Definition: atsc_consts.h:34
plinfo pli
Definition: atsc_types.h:229
contains 832 3 bit symbols. The low 3 bits in the byte hold the symbol.
Definition: atsc_types.h:226
unsigned char _pad_[NPAD]
Definition: atsc_types.h:177
Definition: atsc_types.h:173
unsigned short _flags
Definition: atsc_types.h:142
plinfo pli
Definition: atsc_types.h:209
bool field_sync2_p() const
Definition: atsc_types.h:45
static void sanity_check(const plinfo &in)
Definition: atsc_types.h:131
void set_regular_seg(bool field2, int segno)
Definition: atsc_types.h:74
bool operator==(const plinfo &other) const
Definition: atsc_types.h:95
void set_transport_error(bool error)
Definition: atsc_types.h:87
bool in_field1_p() const
Definition: atsc_types.h:50
unsigned char data[ATSC_MPEG_RS_ENCODED_LENGTH]
Definition: atsc_types.h:210
bool field_sync1_p() const
Definition: atsc_types.h:44
unsigned char _pad_[NPAD]
Definition: atsc_types.h:254
bool in_field2_p() const
Definition: atsc_types.h:51
static const int fl_first_regular_seg
Definition: atsc_types.h:157
static const int NPAD
Definition: atsc_types.h:175
plinfo pli
Definition: atsc_types.h:252
unsigned char data[ATSC_DATA_SEGMENT_LENGTH]
Definition: atsc_types.h:230
unsigned char _pad_[NPAD]
Definition: atsc_types.h:211
plinfo pli
Definition: atsc_types.h:192
bool operator!=(const atsc_data_segment &other) const
Definition: atsc_types.h:238
static const int fl_transport_error
Definition: atsc_types.h:167
static const int ATSC_MPEG_DATA_LENGTH
Definition: atsc_consts.h:32