-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathframetrimset.h
291 lines (263 loc) · 13.6 KB
/
frametrimset.h
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
/**************************************************************************************************************************************************************
frametrimset.h
Copyright © 2023 Maksim Kryukov <fagear@mail.ru>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Created: 2020-05
**************************************************************************************************************************************************************/
#ifndef FRAMETRIMSET_H
#define FRAMETRIMSET_H
#include <stdint.h>
#include <string>
//------------------------ Coordinate pair handler.
class CoordinatePair
{
public:
// Bad data coordinates markers.
enum
{
NO_COORD_LEFT = -32768, // No history for good left data coordinate.
NO_COORD_RIGHT = 32767 // No history for good right data coordinate.
};
public:
uint8_t reference; // General purpose field.
int16_t data_start; // Pixel coordinate of PCM data start.
int16_t data_stop; // Pixel coordinate of PCM data stop.
bool from_doubled; // Was source of these coordinates a doubled-width [VideoLine]?
bool not_sure; // Do these coordinates produce valid results?
public:
CoordinatePair();
CoordinatePair(const CoordinatePair &in_object);
CoordinatePair& operator= (const CoordinatePair &in_object);
bool operator== (const CoordinatePair &in_object);
bool operator!= (const CoordinatePair &in_object);
CoordinatePair& operator- (const CoordinatePair &in_object);
bool operator< (const CoordinatePair &in_object);
void clear();
bool setCoordinates(int16_t in_start, int16_t in_stop);
void setToZero();
void setDoubledState(bool in_flag = false);
void substract(int16_t in_start, int16_t in_stop);
int16_t getDelta();
bool isSourceDoubleWidth();
bool areValid();
bool areZeroed();
bool hasDeltaWarning(uint8_t in_delta);
};
//------------------------ Video "tracking" information.
class FrameBinDescriptor
{
public:
uint32_t frame_id; // Frame number.
uint16_t line_length; // Number of pixels in a single line of the frame.
uint16_t lines_odd; // Number of lines in the odd field with video data.
uint16_t lines_even; // Number of lines in the even field with video data.
uint16_t lines_pcm_odd; // Number of lines in the odd field, containing PCM data (has valid CRC or has markers).
uint16_t lines_pcm_even; // Number of lines in the even field, containing PCM data (has valid CRC or has markers).
uint16_t lines_bad_odd; // Number of lines in the odd field, containing PCM data with bad CRC (damaged data).
uint16_t lines_bad_even; // Number of lines in the even field, containing PCM data with bad CRC (damaged data).
uint16_t lines_dup_odd; // Number of lines in the odd field, containing duplicated lines.
uint16_t lines_dup_even; // Number of lines in the even field, containing duplicated lines.
CoordinatePair data_coord; // Average PCM data starting and ending pixels in source frame.
uint32_t time_odd; // Time (in us) spent on processing odd field.
uint32_t time_even; // Time (in us) spent on processing even field.
public:
FrameBinDescriptor();
FrameBinDescriptor(const FrameBinDescriptor &);
FrameBinDescriptor& operator= (const FrameBinDescriptor &);
void clear();
uint16_t totalLines();
uint16_t totalWithPCM();
uint16_t totalWithBadCRCs();
uint16_t totalDuplicated();
uint32_t totalProcessTime();
};
//------------------------ Frame assembling attempt statistics.
class FieldStitchStats
{
public:
uint16_t index; // Index in the padding runs.
uint16_t valid; // How many valid blocks were assembled during the run.
uint16_t silent; // How many silent blocks were found during the run.
uint16_t unchecked; // How many unchecked blocks were found during the run.
uint16_t broken; // How many BROKEN blocks were found during the run.
public:
FieldStitchStats();
FieldStitchStats(const FieldStitchStats &);
FieldStitchStats& operator= (const FieldStitchStats &);
bool operator!= (const FieldStitchStats &);
bool operator== (const FieldStitchStats &);
bool operator< (const FieldStitchStats &);
void clear();
};
//------------------------ Frame assembling information (base class).
class FrameAsmDescriptor
{
public:
// Video standards (number of lines in the frame).
enum
{
VID_UNKNOWN, // Video standard is not detected.
VID_PAL, // Video standard detected to be PAL.
VID_NTSC, // Video standard detected to be NTSC.
VID_MAX
};
// Field order for the frame.
enum
{
ORDER_UNK, // Unknown.
ORDER_TFF, // Top Field First (Odd Field First).
ORDER_BFF, // Bottom Field First (Even Field First).
ORDER_MAX
};
// Service tags for [service_type].
enum
{
SRV_NO, // Regular PCM line with audio data.
SRV_NEW_FILE, // New file opened (with path in [file_path]).
SRV_END_FILE, // File ended.
};
public:
uint32_t frame_number; // Frame number.
uint16_t odd_std_lines; // Number of lines by the standard in the odd field.
uint16_t even_std_lines; // Number of lines by the standard in the even field.
uint16_t odd_data_lines; // Number of lines with some PCM data in the odd field.
uint16_t even_data_lines; // Number of lines with some PCM data in the even field.
uint16_t odd_valid_lines; // Number of lines with valid CRC in the odd field.
uint16_t even_valid_lines; // Number of lines with valid CRC in the even field.
uint16_t odd_top_data; // # of line in the odd field that PCM data starts from.
uint16_t odd_bottom_data; // # of line in the odd field that PCM data ends on.
uint16_t even_top_data; // # of line in the even field that PCM data starts from.
uint16_t even_bottom_data; // # of line in the even field that PCM data ends on.
uint16_t odd_sample_rate; // Sample rate of audio data in the odd field.
uint16_t even_sample_rate; // Sample rate of audio data in the even field.
uint8_t field_order; // Field order of this frame (order to assemble the frame).
bool odd_emphasis; // Are audio samples processed with emphasis in the odd field?
bool even_emphasis; // Are audio samples processed with emphasis in the even field?
uint8_t odd_ref; // Average binarization reference level for lines in the odd field.
uint8_t even_ref; // Average binarization reference level for lines in the even field.
uint16_t blocks_total; // Total number of data blocks in the assembled frame.
uint16_t blocks_drop; // Number of data blocks that carry uncorrected errors.
uint16_t samples_drop; // Number of samples with damaged data.
bool drawn; // Is data in this set already visualized?
private:
bool order_preset; // Is field order preset externally?
bool order_guessed; // Is field order not detected and is guessed (by stats or other)?
uint8_t service_type; // Type of the service tag.
std::string file_path; // Path of decoded file (set with [SRV_NEW_FILE]).
public:
FrameAsmDescriptor();
FrameAsmDescriptor(const FrameAsmDescriptor &);
FrameAsmDescriptor& operator= (const FrameAsmDescriptor &);
void clear();
void clearMisc();
void clearAsmStats();
void setServNewFile(std::string path);
void setServEndFile();
void presetOrderClear();
void presetTFF();
void presetBFF();
void setOrderUnknown();
void setOrderTFF();
void setOrderBFF();
void setOrderGuessed(bool);
std::string getServFileName();
bool hasServiceTag();
bool isServNewFile();
bool isServEndFile();
bool isOrderSet();
bool isOrderPreset();
bool isOrderGuessed();
bool isOrderBFF();
bool isOrderTFF();
uint8_t getAvgRef();
private:
void setServiceTag();
};
//------------------------ Frame assembling information for PCM-1.
class FrameAsmPCM1 : public FrameAsmDescriptor
{
public:
uint16_t odd_top_padding; // Number of lines to put before odd field to correctly assemble blocks.
uint16_t odd_bottom_padding; // Number of lines to put after odd field to correctly assemble blocks.
uint16_t even_top_padding; // Number of lines to put before even field to correctly assemble blocks.
uint16_t even_bottom_padding; // Number of lines to put after even field to correctly assemble blocks.
uint16_t blocks_fix_bp; // Number of data blocks that were fixed with help of Bit Picker.
public:
FrameAsmPCM1();
FrameAsmPCM1(const FrameAsmPCM1 &);
FrameAsmPCM1& operator= (const FrameAsmPCM1 &);
void clear();
void clearMisc();
void clearAsmStats();
};
//------------------------ Frame assembling information for PCM-16x0.
class FrameAsmPCM16x0 : public FrameAsmDescriptor
{
public:
uint16_t odd_top_padding; // Number of lines to put before odd field to correctly assemble blocks.
uint16_t odd_bottom_padding; // Number of lines to put after odd field to correctly assemble blocks.
uint16_t even_top_padding; // Number of lines to put before even field to correctly assemble blocks.
uint16_t even_bottom_padding; // Number of lines to put after even field to correctly assemble blocks.
bool silence; // Is reason for invalid padding - silence in audio?
bool padding_ok; // Is padding valid?
bool ei_format; // Is data in EI format?
uint16_t blocks_broken; // Number of "BROKEN" data blocks, which have no CRC errors, but non-zero ECC syndromes.
uint16_t blocks_fix_bp; // Number of data blocks that were fixed with help of Bit Picker.
uint16_t blocks_fix_p; // Number of data blocks that were fixed with P-code.
uint16_t blocks_fix_cwd; // Number of data blocks that were fixed with help of CWD.
public:
FrameAsmPCM16x0();
FrameAsmPCM16x0(const FrameAsmPCM16x0 &);
FrameAsmPCM16x0& operator= (const FrameAsmPCM16x0 &);
void clear();
void clearMisc();
void clearAsmStats();
};
// TODO: introduce "M2" flag
//------------------------ Frame assembling information for STC-007.
class FrameAsmSTC007 : public FrameAsmDescriptor
{
public:
uint8_t video_standard; // Video standard for this frame (tells how many lines should be in a field).
uint8_t tff_cnt; // Probability of this frame to have TFF field order (# of successfull padding runs in TFF).
uint8_t bff_cnt; // Probability of this frame to have BFF field order (# of successfull padding runs in BFF).
uint8_t odd_resolution; // Audio resolution in odd field;
uint8_t even_resolution; // Audio resolution in even field;
uint16_t inner_padding; // Number of lines to put between fields of this frame to correctly assemble data blocks.
uint16_t outer_padding; // Number of lines to put between last field of this frame and first field of the next frame.
bool trim_ok; // Is trim data complete?
bool inner_padding_ok; // Is inner padding valid? ([inner_padding] is set)
bool outer_padding_ok; // Is outer padding valid? ([outer_padding] is set)
bool inner_silence; // Is reason for invalid inner padding - silence in audio?
bool outer_silence; // Is reason for invalid outer padding - silence in audio?
bool vid_std_preset; // Is video standard preset by user?
bool vid_std_guessed; // Is video standard not detected and is guessed (by stats or other)?
uint16_t blocks_broken_field; // Number of "BROKEN" data blocks, which have no CRC errors, but non-zero ECC syndromes, in fields.
uint16_t blocks_broken_seam; // Number of "BROKEN" data blocks, which have no CRC errors, but non-zero ECC syndromes, in fields.
uint16_t blocks_fix_p; // Number of data blocks that were fixed with P-code.
uint16_t blocks_fix_q; // Number of data blocks that were fixed with Q-code.
uint16_t blocks_fix_cwd; // Number of data blocks that were fixed with help of CWD.
int8_t ctrl_index; // Index code from address word of Control Block.
int8_t ctrl_hour; // Hour (time code) from address word of Control Block.
int8_t ctrl_minute; // Minute (time code) from address word of Control Block.
int8_t ctrl_second; // Second (time code) from address word of Control Block.
int8_t ctrl_field; // Field code from address word of Control Block.
public:
FrameAsmSTC007();
FrameAsmSTC007(const FrameAsmSTC007 &);
FrameAsmSTC007& operator= (const FrameAsmSTC007 &);
void clear();
void clearMisc();
void clearAsmStats();
void updateVidStdSoft(uint8_t in_std);
bool isAddressSet();
};
#endif // FRAMETRIMSET_H