blob: 1610f8b9aaebdb551be766ff63fe6095d12740b0 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
|
/* -*- c++ -*- */
/*
* Copyright 2001,2006,2014 Free Software Foundation, Inc.
*
* This file is part of GNU Radio
*
* SPDX-License-Identifier: GPL-3.0-or-later
*
*/
#include <gnuradio/dtv/atsc_plinfo.h>
namespace gr {
namespace dtv {
plinfo::plinfo() : d_flags(0), d_segno(0){};
plinfo::plinfo(uint16_t flags, int16_t segno) : d_flags(flags), d_segno(segno){};
void plinfo::reset()
{
d_flags = 0;
d_segno = 0;
}
// accessors
bool plinfo::field_sync1_p() const { return (d_flags & fl_field_sync1) != 0; }
bool plinfo::field_sync2_p() const { return (d_flags & fl_field_sync2) != 0; }
bool plinfo::field_sync_p() const { return field_sync1_p() || field_sync2_p(); }
bool plinfo::regular_seg_p() const { return (d_flags & fl_regular_seg) != 0; }
bool plinfo::in_field1_p() const { return (d_flags & fl_field2) == 0; }
bool plinfo::in_field2_p() const { return (d_flags & fl_field2) != 0; }
bool plinfo::first_regular_seg_p() const { return (d_flags & fl_first_regular_seg) != 0; }
bool plinfo::transport_error_p() const { return (d_flags & fl_transport_error) != 0; }
unsigned int plinfo::segno() const { return d_segno; }
unsigned int plinfo::flags() const { return d_flags; }
// setters
void plinfo::set_field_sync1()
{
d_segno = 0;
d_flags = fl_field_sync1;
}
void plinfo::set_field_sync2()
{
d_segno = 0;
d_flags = fl_field_sync2 | fl_field2;
}
void plinfo::set_regular_seg(bool field2, int segno)
{
d_segno = segno;
d_flags = fl_regular_seg;
if (segno == 0)
d_flags |= fl_first_regular_seg;
if (segno >= ATSC_DSEGS_PER_FIELD)
d_flags |= fl_transport_error;
if (field2)
d_flags |= fl_field2;
}
void plinfo::set_transport_error(bool error)
{
if (error)
d_flags |= fl_transport_error;
else
d_flags &= ~fl_transport_error;
}
void plinfo::delay(plinfo& out, const plinfo& in, int nsegs_of_delay)
{
assert(in.regular_seg_p());
assert(nsegs_of_delay >= 0);
int s = in.segno();
if (in.in_field2_p())
s += ATSC_DSEGS_PER_FIELD;
s -= nsegs_of_delay;
if (s < 0)
s += 2 * ATSC_DSEGS_PER_FIELD;
if (s < ATSC_DSEGS_PER_FIELD)
out.set_regular_seg(false, s); // field 1
else
out.set_regular_seg(true, s - ATSC_DSEGS_PER_FIELD); // field 2
}
} /* namespace dtv */
} /* namespace gr */
|