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