GNU Radio Manual and C++ API Reference  3.7.13.4
The Free & Open Software Radio Ecosystem
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 <cstring>
28 #include <cassert>
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 public:
38  plinfo () : _flags (0), _segno (0) { }
39 
40  // accessors
41 
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 (); }
45 
46  bool regular_seg_p () const { return (_flags & fl_regular_seg) != 0; }
47 
48  bool in_field1_p () const { return (_flags & fl_field2) == 0; }
49  bool in_field2_p () const { return (_flags & fl_field2) != 0; }
50 
51  bool first_regular_seg_p () const { return (_flags & fl_first_regular_seg) != 0; }
52 
53  bool transport_error_p () const { return (_flags & fl_transport_error) != 0; }
54 
55  unsigned int segno () const { return _segno; }
56  unsigned int flags () const { return _flags; }
57 
58  // setters
59 
61  {
62  _segno = 0;
64  }
65 
67  {
68  _segno = 0;
70  }
71 
72  void set_regular_seg (bool field2, int segno)
73  {
74  assert (0 <= segno && segno < ATSC_DSEGS_PER_FIELD);
75  _segno = segno;
77  if (segno == 0)
79  if (segno >= ATSC_DSEGS_PER_FIELD)
81  if (field2)
82  _flags |= fl_field2;
83  }
84 
85  void set_transport_error (bool error){
86  if (error)
88  else
90  }
91 
92  // overload equality operator
93  bool operator== (const plinfo &other) const {
94  return (_flags == other._flags && _segno == other._segno);
95  }
96 
97  bool operator!= (const plinfo &other) const {
98  return !(_flags == other._flags && _segno == other._segno);
99  }
100 
101  /*!
102  * Set \p OUT such that it reflects a \p NSEGS_OF_DELAY
103  * pipeline delay from \p IN.
104  */
105  static void delay (plinfo &out, const plinfo &in, int nsegs_of_delay);
106 
107  /*!
108  * confirm that \p X is plausible
109  */
110  static void sanity_check (const plinfo &in);
111 
112 
113 protected:
114  unsigned short _flags; // bitmask
115  unsigned short _segno; // segment number [0,311]
116 
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;
124 
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;
129 
130  // which field are we in?
131  static const int fl_field2 = 0x0010; // else field 1
132 
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;
139 };
140 
141 
142 
143 
145  public:
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)
149 
150  // overload equality operator
151  bool operator== (const atsc_mpeg_packet &other) const {
152  return std::memcmp (data, other.data, sizeof (data)) == 0;
153  };
154 
155  bool operator!= (const atsc_mpeg_packet &other) const {
156  return !(std::memcmp (data, other.data, sizeof (data)) == 0);
157  };
158 };
159 
161  public:
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)
166 
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;
170  }
171 
172  bool operator!= (const atsc_mpeg_packet_no_sync &other) const {
173  return !(std::memcmp (data, other.data, sizeof (data)) == 0);
174  }
175 };
176 
178  public:
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)
183 
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;
187  }
188 
189  bool operator!= (const atsc_mpeg_packet_rs_encoded &other) const {
190  return !(std::memcmp (data, other.data, sizeof (data)) == 0);
191  }
192 };
193 
194 
195 //! contains 832 3 bit symbols. The low 3 bits in the byte hold the symbol.
196 
198  public:
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)
203 
204  // overload equality operator
205  bool operator== (const atsc_data_segment &other) const {
206  return std::memcmp (data, other.data, sizeof (data)) == 0;
207  }
208 
209  bool operator!= (const atsc_data_segment &other) const {
210  return !(std::memcmp (data, other.data, sizeof (data)) == 0);
211  }
212 };
213 
214 /*!
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.
218  */
219 
221  public:
222  static const int NPAD = 764;
225  unsigned char _pad_[NPAD]; // pad to power of 2 (4096)
226 
227  // overload equality operator
228  bool operator== (const atsc_data_segment &other) const {
229  return std::memcmp (data, other.data, sizeof (data)) == 0;
230  }
231 
232  bool operator!= (const atsc_data_segment &other) const {
233  return !(std::memcmp (data, other.data, sizeof (data)) == 0);
234  }
235 };
236 
237 
238 #endif /* _ATSC_TYPES_H_ */
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:121
bool regular_seg_p() const
Definition: gr-atsc/include/gnuradio/atsc/types.h:46
bool in_field2_p() const
Definition: gr-atsc/include/gnuradio/atsc/types.h:49
bool first_regular_seg_p() const
Definition: gr-atsc/include/gnuradio/atsc/types.h:51
unsigned int flags() const
Definition: gr-atsc/include/gnuradio/atsc/types.h:56
unsigned char data[ATSC_DATA_SEGMENT_LENGTH]
Definition: gr-atsc/include/gnuradio/atsc/types.h:201
unsigned char data[ATSC_MPEG_RS_ENCODED_LENGTH]
Definition: gr-atsc/include/gnuradio/atsc/types.h:181
unsigned char data[ATSC_MPEG_DATA_LENGTH]
Definition: gr-atsc/include/gnuradio/atsc/types.h:164
static const int fl_field_sync2
Definition: gr-atsc/include/gnuradio/atsc/types.h:123
static void delay(plinfo &out, const plinfo &in, int nsegs_of_delay)
unsigned int segno() const
Definition: gr-atsc/include/gnuradio/atsc/types.h:55
static const int fl_field2
Definition: gr-atsc/include/gnuradio/atsc/types.h:131
bool field_sync1_p() const
Definition: gr-atsc/include/gnuradio/atsc/types.h:42
Definition: gr-atsc/include/gnuradio/atsc/types.h:160
bool in_field1_p() const
Definition: gr-atsc/include/gnuradio/atsc/types.h:48
static const int fl_transport_error
Definition: gr-atsc/include/gnuradio/atsc/types.h:138
Definition: gr-atsc/include/gnuradio/atsc/types.h:220
void set_regular_seg(bool field2, int segno)
Definition: gr-atsc/include/gnuradio/atsc/types.h:72
Definition: gr-atsc/include/gnuradio/atsc/types.h:177
plinfo pli
Definition: gr-atsc/include/gnuradio/atsc/types.h:223
bool field_sync2_p() const
Definition: gr-atsc/include/gnuradio/atsc/types.h:43
Definition: gr-atsc/include/gnuradio/atsc/types.h:144
plinfo pli
Definition: gr-atsc/include/gnuradio/atsc/types.h:180
unsigned short _segno
Definition: gr-atsc/include/gnuradio/atsc/types.h:115
bool operator==(const plinfo &other) const
Definition: gr-atsc/include/gnuradio/atsc/types.h:93
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:128
unsigned char data[ATSC_MPEG_DATA_LENGTH+1]
Definition: gr-atsc/include/gnuradio/atsc/types.h:147
static const int ATSC_DSEGS_PER_FIELD
Definition: consts.h:34
unsigned short _flags
Definition: gr-atsc/include/gnuradio/atsc/types.h:114
void set_field_sync2()
Definition: gr-atsc/include/gnuradio/atsc/types.h:66
bool transport_error_p() const
Definition: gr-atsc/include/gnuradio/atsc/types.h:53
plinfo()
Definition: gr-atsc/include/gnuradio/atsc/types.h:38
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:60
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:119
contains 832 3 bit symbols. The low 3 bits in the byte hold the symbol.
Definition: gr-atsc/include/gnuradio/atsc/types.h:197
bool operator!=(const plinfo &other) const
Definition: gr-atsc/include/gnuradio/atsc/types.h:97
plinfo pli
Definition: gr-atsc/include/gnuradio/atsc/types.h:163
void set_transport_error(bool error)
Definition: gr-atsc/include/gnuradio/atsc/types.h:85
plinfo pli
Definition: gr-atsc/include/gnuradio/atsc/types.h:200
bool field_sync_p() const
Definition: gr-atsc/include/gnuradio/atsc/types.h:44