GNU Radio Manual and C++ API Reference
3.7.5
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
26
#include <
gnuradio/dtv/atsc_consts.h
>
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
62
void
set_field_sync1
()
63
{
64
_segno
= 0;
65
_flags
=
fl_field_sync1
;
66
}
67
68
void
set_field_sync2
()
69
{
70
_segno
= 0;
71
_flags
=
fl_field_sync2
|
fl_field2
;
72
}
73
74
void
set_regular_seg
(
bool
field2,
int
segno
)
75
{
76
//assert (0 <= segno && segno < ATSC_DSEGS_PER_FIELD);
77
_segno
=
segno
;
78
_flags
=
fl_regular_seg
;
79
if
(segno == 0)
80
_flags
|=
fl_first_regular_seg
;
81
if
(segno >=
ATSC_DSEGS_PER_FIELD
)
82
_flags
|=
fl_transport_error
;
83
if
(field2)
84
_flags
|=
fl_field2
;
85
}
86
87
void
set_transport_error
(
bool
error){
88
if
(error)
89
_flags
|=
fl_transport_error
;
90
else
91
_flags
&= ~
fl_transport_error
;
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
())
114
s +=
ATSC_DSEGS_PER_FIELD
;
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
173
class
atsc_mpeg_packet
{
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
189
class
atsc_mpeg_packet_no_sync
{
190
public
:
191
static
const
int
NPAD
= 65;
192
plinfo
pli
;
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
206
class
atsc_mpeg_packet_rs_encoded
{
207
public
:
208
static
const
int
NPAD
= 45;
209
plinfo
pli
;
210
unsigned
char
data
[
ATSC_MPEG_RS_ENCODED_LENGTH
];
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
226
class
atsc_data_segment
{
227
public
:
228
static
const
int
NPAD
= 188;
229
plinfo
pli
;
230
unsigned
char
data
[
ATSC_DATA_SEGMENT_LENGTH
];
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
249
class
atsc_soft_data_segment
{
250
public
:
251
static
const
int
NPAD
= 764;
252
plinfo
pli
;
253
float
data
[
ATSC_DATA_SEGMENT_LENGTH
];
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_ */
gr-dtv
lib
atsc
atsc_types.h
Generated on Fri Oct 3 2014 00:33:50 for GNU Radio Manual and C++ API Reference by
1.8.1.2