TMC3.cpp 41.2 KB
Newer Older
Khaled Mammou's avatar
TMC3v0    
Khaled Mammou committed
1
/* The copyright in this software is being made available under the BSD
David Flynn's avatar
David Flynn committed
2
3
4
 * Licence, included below.  This software may be subject to other third
 * party and contributor rights, including patent rights, and no such
 * rights are granted under this licence.
Khaled Mammou's avatar
TMC3v0    
Khaled Mammou committed
5
 *
David Flynn's avatar
David Flynn committed
6
 * Copyright (c) 2017-2018, ISO/IEC
Khaled Mammou's avatar
TMC3v0    
Khaled Mammou committed
7
8
9
10
11
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
David Flynn's avatar
David Flynn committed
12
13
14
15
16
17
18
19
20
21
 * * Redistributions of source code must retain the above copyright
 *   notice, this list of conditions and the following disclaimer.
 *
 * * Redistributions in binary form must reproduce the above copyright
 *   notice, this list of conditions and the following disclaimer in the
 *   documentation and/or other materials provided with the distribution.
 *
 * * Neither the name of the ISO/IEC nor the names of its contributors
 *   may be used to endorse or promote products derived from this
 *   software without specific prior written permission.
Khaled Mammou's avatar
TMC3v0    
Khaled Mammou committed
22
23
24
25
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
David Flynn's avatar
David Flynn committed
26
27
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
Khaled Mammou's avatar
TMC3v0    
Khaled Mammou committed
28
29
30
31
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
David Flynn's avatar
David Flynn committed
32
33
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
Khaled Mammou's avatar
TMC3v0    
Khaled Mammou committed
34
35
36
 */

#include "TMC3.h"
David Flynn's avatar
David Flynn committed
37
38
39
40
41

#include <memory>

#include "PCCTMC3Encoder.h"
#include "PCCTMC3Decoder.h"
42
#include "constants.h"
43
#include "ply.h"
44
#include "pointset_processing.h"
45
#include "program_options_lite.h"
46
#include "io_tlv.h"
47
#include "version.h"
Khaled Mammou's avatar
TMC3v0    
Khaled Mammou committed
48
49
50
51

using namespace std;
using namespace pcc;

52
53
54
55
56
//============================================================================

struct Parameters {
  bool isDecoder;

57
58
59
  // command line parsing should adjust dist2 values according to PQS
  bool positionQuantizationScaleAdjustsDist2;

60
61
62
  // output mode for ply writing (binary or ascii)
  bool outputBinaryPly;

63
64
65
  // when true, configure the encoder as if no attributes are specified
  bool disableAttributeCoding;

66
67
68
69
70
71
  // Frame number of first file in input sequence.
  int firstFrameNum;

  // Number of frames to process.
  int frameCount;

72
73
74
75
  std::string uncompressedDataPath;
  std::string compressedStreamPath;
  std::string reconstructedDataPath;

76
77
78
79
  // Filename for saving recoloured point cloud (encoder).
  std::string postRecolorPath;

  // Filename for saving pre inverse scaled point cloud (decoder).
80
81
  std::string preInvScalePath;

82
83
84
  pcc::EncoderParams encoder;
  pcc::DecoderParams decoder;

85
86
  // perform attribute colourspace conversion on ply input/output.
  bool convertColourspace;
87
88
89

  // todo(df): this should be per-attribute
  int reflectanceScale;
90
91
};

92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
//----------------------------------------------------------------------------

class SequenceEncoder : public PCCTMC3Encoder3::Callbacks {
public:
  // NB: params must outlive the lifetime of the decoder.
  SequenceEncoder(Parameters* params);

  int compress(Stopwatch* clock);

protected:
  int compressOneFrame(Stopwatch* clock);

  void onOutputBuffer(const PayloadBuffer& buf) override;
  void onPostRecolour(const PCCPointSet3& cloud) override;

private:
108
109
  ply::PropertyNameMap _plyAttrNames;

110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
  Parameters* params;
  PCCTMC3Encoder3 encoder;

  std::ofstream bytestreamFile;

  int frameNum;
};

//----------------------------------------------------------------------------

class SequenceDecoder : public PCCTMC3Decoder3::Callbacks {
public:
  // NB: params must outlive the lifetime of the decoder.
  SequenceDecoder(const Parameters* params);

  int decompress(Stopwatch* clock);

protected:
128
129
130
  void onOutputCloud(
    const SequenceParameterSet& sps,
    const PCCPointSet3& decodedPointCloud) override;
131
132
133
134
135
136
137
138
139
140
141

private:
  const Parameters* params;
  PCCTMC3Decoder3 decoder;

  std::ofstream bytestreamFile;

  int frameNum;
  Stopwatch* clock;
};

142
143
//============================================================================

144
145
146
147
148
void convertToGbr(const SequenceParameterSet& sps, PCCPointSet3& cloud);
void convertFromGbr(const SequenceParameterSet& sps, PCCPointSet3& cloud);

//============================================================================

149
150
151
int
main(int argc, char* argv[])
{
152
  cout << "MPEG PCC tmc3 version " << ::pcc::version << endl;
153

Khaled Mammou's avatar
TMC3v0    
Khaled Mammou committed
154
155
156
157
  Parameters params;
  if (!ParseParameters(argc, argv, params)) {
    return -1;
  }
158
159
160
161
162
163
164

  // Timers to count elapsed wall/user time
  pcc::chrono::Stopwatch<std::chrono::steady_clock> clock_wall;
  pcc::chrono::Stopwatch<pcc::chrono::utime_inc_children_clock> clock_user;

  clock_wall.start();

Khaled Mammou's avatar
TMC3v0    
Khaled Mammou committed
165
  int ret = 0;
166
  if (params.isDecoder) {
167
    ret = SequenceDecoder(&params).decompress(&clock_user);
168
  } else {
169
    ret = SequenceEncoder(&params).compress(&clock_user);
Khaled Mammou's avatar
TMC3v0    
Khaled Mammou committed
170
171
  }

172
173
174
175
176
177
178
179
  clock_wall.stop();

  using namespace std::chrono;
  auto total_wall = duration_cast<milliseconds>(clock_wall.count()).count();
  auto total_user = duration_cast<milliseconds>(clock_user.count()).count();
  std::cout << "Processing time (wall): " << total_wall / 1000.0 << " s\n";
  std::cout << "Processing time (user): " << total_user / 1000.0 << " s\n";

Khaled Mammou's avatar
TMC3v0    
Khaled Mammou committed
180
181
182
  return ret;
}

183
184
185
186
187
188
189
190
191
192
193
194
195
//---------------------------------------------------------------------------

std::array<const char*, 3>
axisOrderToPropertyNames(AxisOrder order)
{
  static const std::array<const char*, 3> kAxisOrderToPropertyNames[] = {
    {"z", "y", "x"}, {"x", "y", "z"}, {"x", "z", "y"}, {"y", "z", "x"},
    {"z", "y", "x"}, {"z", "x", "y"}, {"y", "x", "z"}, {"x", "y", "z"},
  };

  return kAxisOrderToPropertyNames[int(order)];
}

196
197
198
//---------------------------------------------------------------------------
// :: Command line / config parsing helpers

199
200
201
202
template<typename T>
static std::istream&
readUInt(std::istream& in, T& val)
{
203
204
205
206
207
208
  unsigned int tmp;
  in >> tmp;
  val = T(tmp);
  return in;
}

209
210
namespace pcc {
static std::istream&
211
operator>>(std::istream& in, ColourMatrix& val)
212
213
214
215
216
{
  return readUInt(in, val);
}
}  // namespace pcc

217
namespace pcc {
218
static std::istream&
219
operator>>(std::istream& in, AxisOrder& val)
220
{
221
222
  return readUInt(in, val);
}
223
}  // namespace pcc
224

225
namespace pcc {
226
static std::istream&
227
operator>>(std::istream& in, AttributeEncoding& val)
228
{
229
  return readUInt(in, val);
230
231
}
}  // namespace pcc
232

233
234
235
236
237
238
239
240
namespace pcc {
static std::istream&
operator>>(std::istream& in, PartitionMethod& val)
{
  return readUInt(in, val);
}
}  // namespace pcc

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
namespace pcc {
static std::ostream&
operator<<(std::ostream& out, const ColourMatrix& val)
{
  switch (val) {
  case ColourMatrix::kIdentity: out << "0 (Identity)"; break;
  case ColourMatrix::kBt709: out << "1 (Bt709)"; break;
  case ColourMatrix::kUnspecified: out << "2 (Unspecified)"; break;
  case ColourMatrix::kReserved_3: out << "3 (Reserved)"; break;
  case ColourMatrix::kUsa47Cfr73dot682a20:
    out << "4 (Usa47Cfr73dot682a20)";
    break;
  case ColourMatrix::kBt601: out << "5 (Bt601)"; break;
  case ColourMatrix::kSmpte170M: out << "6 (Smpte170M)"; break;
  case ColourMatrix::kSmpte240M: out << "7 (Smpte240M)"; break;
  case ColourMatrix::kYCgCo: out << "8 (kYCgCo)"; break;
  case ColourMatrix::kBt2020Ncl: out << "9 (Bt2020Ncl)"; break;
  case ColourMatrix::kBt2020Cl: out << "10 (Bt2020Cl)"; break;
  case ColourMatrix::kSmpte2085: out << "11 (Smpte2085)"; break;
  default: out << "Unknown"; break;
  }
  return out;
}
}  // namespace pcc

266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
namespace pcc {
static std::ostream&
operator<<(std::ostream& out, const AxisOrder& val)
{
  switch (val) {
  case AxisOrder::kZYX: out << "0 (zyx)"; break;
  case AxisOrder::kXYZ: out << "1 (xyz)"; break;
  case AxisOrder::kXZY: out << "2 (xzy)"; break;
  case AxisOrder::kYZX: out << "3 (yzx)"; break;
  case AxisOrder::kZYX_4: out << "4 (zyx)"; break;
  case AxisOrder::kZXY: out << "5 (zxy)"; break;
  case AxisOrder::kYXZ: out << "6 (yxz)"; break;
  case AxisOrder::kXYZ_7: out << "7 (xyz)"; break;
  }
  return out;
}
}  // namespace pcc

284
namespace pcc {
285
static std::ostream&
286
operator<<(std::ostream& out, const AttributeEncoding& val)
287
{
288
  switch (val) {
289
290
291
  case AttributeEncoding::kPredictingTransform: out << "0 (Pred)"; break;
  case AttributeEncoding::kRAHTransform: out << "1 (RAHT)"; break;
  case AttributeEncoding::kLiftingTransform: out << "2 (Lift)"; break;
292
293
  }
  return out;
294
295
}
}  // namespace pcc
296

297
298
299
300
301
302
namespace pcc {
static std::ostream&
operator<<(std::ostream& out, const PartitionMethod& val)
{
  switch (val) {
  case PartitionMethod::kNone: out << "0 (None)"; break;
303
304
  case PartitionMethod::kUniformGeom: out << "2 (UniformGeom)"; break;
  case PartitionMethod::kOctreeUniform: out << "3 (UniformOctree)"; break;
305
  default: out << int(val) << " (Unknown)"; break;
306
307
308
309
310
  }
  return out;
}
}  // namespace pcc

311
312
313
namespace df {
namespace program_options_lite {
  template<typename T>
314
  struct option_detail<pcc::Vec3<T>> {
315
316
317
318
    static constexpr bool is_container = true;
    static constexpr bool is_fixed_size = true;
    typedef T* output_iterator;

319
320
    static void clear(pcc::Vec3<T>& container){};
    static output_iterator make_output_iterator(pcc::Vec3<T>& container)
321
322
323
324
325
326
327
    {
      return &container[0];
    }
  };
}  // namespace program_options_lite
}  // namespace df

328
329
330
//---------------------------------------------------------------------------
// :: Command line / config parsing

331
332
333
bool
ParseParameters(int argc, char* argv[], Parameters& params)
{
334
335
  namespace po = df::program_options_lite;

336
337
338
  struct {
    AttributeDescription desc;
    AttributeParameterSet aps;
339
    EncoderAttributeParams encoder;
340
341
  } params_attr;

342
343
344
345
346
347
348
349
350
351
352
353
354
  bool print_help = false;

  // a helper to set the attribute
  std::function<po::OptionFunc::Func> attribute_setter =
    [&](po::Options&, const std::string& name, po::ErrorReporter) {
      // copy the current state of parsed attribute parameters
      //
      // NB: this does not cause the default values of attr to be restored
      // for the next attribute block.  A side-effect of this is that the
      // following is allowed leading to attribute foo having both X=1 and
      // Y=2:
      //   "--attr.X=1 --attribute foo --attr.Y=2 --attribute foo"
      //
355
356
357
358
359
360
361
362

      // NB: insert returns any existing element
      const auto& it = params.encoder.attributeIdxMap.insert(
        {name, int(params.encoder.attributeIdxMap.size())});

      if (it.second) {
        params.encoder.sps.attributeSets.push_back(params_attr.desc);
        params.encoder.aps.push_back(params_attr.aps);
363
        params.encoder.attr.push_back(params_attr.encoder);
364
365
366
367
368
369
        return;
      }

      // update existing entry
      params.encoder.sps.attributeSets[it.first->second] = params_attr.desc;
      params.encoder.aps[it.first->second] = params_attr.aps;
370
      params.encoder.attr[it.first->second] = params_attr.encoder;
371
372
    };

373
  /* clang-format off */
374
375
376
377
378
379
380
381
382
383
384
  // The definition of the program/config options, along with default values.
  //
  // NB: when updating the following tables:
  //      (a) please keep to 80-columns for easier reading at a glance,
  //      (b) do not vertically align values -- it breaks quickly
  //
  po::Options opts;
  opts.addOptions()
  ("help", print_help, false, "this help text")
  ("config,c", po::parseConfigFile, "configuration file name")

385
386
  (po::Section("General"))

387
  ("mode", params.isDecoder, false,
388
389
    "The encoding/decoding mode:\n"
    "  0: encode\n"
390
    "  1: decode")
391
392

  // i/o parameters
393
394
395
396
397
398
399
400
401
  ("firstFrameNum",
     params.firstFrameNum, 0,
     "Frame number for use with interpolating %d format specifiers"
     "in input/output filenames")

  ("frameCount",
     params.frameCount, 1,
     "Number of frames to encode")

402
  ("reconstructedDataPath",
403
404
    params.reconstructedDataPath, {},
    "The ouput reconstructed pointcloud file path (decoder only)")
405
406

  ("uncompressedDataPath",
407
408
    params.uncompressedDataPath, {},
    "The input pointcloud file path")
409
410

  ("compressedStreamPath",
411
412
    params.compressedStreamPath, {},
    "The compressed bitstream path (encoder=output, decoder=input)")
413

414
  ("postRecolorPath",
415
    params.postRecolorPath, {},
416
    "Recolored pointcloud file path (encoder only)")
417
418

  ("preInvScalePath",
419
    params.preInvScalePath, {},
420
    "Pre inverse scaled pointcloud file path (decoder only)")
421

422
423
424
425
  ("outputBinaryPly",
    params.outputBinaryPly, false,
    "Output ply files using binary (or otherwise ascii) format")

426
427
428
  ("convertPlyColourspace",
    params.convertColourspace, true,
    "Convert ply colourspace according to attribute colourMatrix")
429

430
  // general
431
432
433
434
435
436
  // todo(df): this should be per-attribute
  ("hack.reflectanceScale",
    params.reflectanceScale, 1,
    "scale factor to be applied to reflectance "
    "pre encoding / post reconstruction")

437
438
439
440
441
442
443
  (po::Section("Decoder"))

  ("skipOctreeLayers",
    params.decoder.minGeomNodeSizeLog2, 0,
    " 0   : Full decode. \n"
    " N>0 : Skip the bottom N layers in decoding process.\n"
    " skipLayerNum indicates the number of skipped lod layers from leaf lod.")
444
445
446

  (po::Section("Encoder"))

447
448
449
450
451
452
453
  ("geometry_axis_order",
    params.encoder.sps.geometry_axis_order, AxisOrder::kXYZ,
    "Sets the geometry axis coding order:\n"
    "  0: (zyx)\n  1: (xyz)\n  2: (xzy)\n"
    "  3: (yzx)\n  4: (zyx)\n  5: (zxy)\n"
    "  6: (yxz)\n  7: (xyz)")

454
455
456
457
458
459
460
461
462
  ("seq_bounding_box_xyz0",
    params.encoder.sps.seq_bounding_box_xyz0, {0},
    "seq_bounding_box_xyz0.  NB: seq_bounding_box_whd must be set for this "
    "parameter to have an effect")

  ("seq_bounding_box_whd",
    params.encoder.sps.seq_bounding_box_whd, {0},
    "seq_bounding_box_whd")

463
  ("positionQuantizationScale",
464
    params.encoder.sps.seq_source_geom_scale_factor, 1.f,
465
    "Scale factor to be applied to point positions during quantization process")
466

467
468
469
470
  ("positionQuantizationScaleAdjustsDist2",
    params.positionQuantizationScaleAdjustsDist2, false,
    "Scale dist2 values by squared positionQuantizationScale")

471
  ("mergeDuplicatedPoints",
472
    params.encoder.gps.geom_unique_points_flag, true,
473
    "Enables removal of duplicated points")
474

475
  ("partitionMethod",
476
    params.encoder.partition.method, PartitionMethod::kUniformGeom,
477
    "Method used to partition input point cloud into slices/tiles:\n"
478
479
    "  0: none\n"
    "  1: none (deprecated)\n"
480
481
    "  2: n Uniform-Geometry partition bins along the longest edge\n"
    "  3: Uniform Geometry partition at n octree depth")
482

483
  ("partitionOctreeDepth",
484
485
486
487
488
489
490
491
492
493
494
495
496
497
    params.encoder.partition.octreeDepth, 1,
    "Depth of octree partition for partitionMethod=4")

  ("sliceMaxPoints",
    params.encoder.partition.sliceMaxPoints, 1100000,
    "Maximum number of points per slice")

  ("sliceMinPoints",
    params.encoder.partition.sliceMinPoints, 550000,
    "Minimum number of points per slice (soft limit)")

  ("tileSize",
    params.encoder.partition.tileSize, 0,
    "Partition input into cubic tiles of given size")
498

499
500
501
502
  ("cabac_bypass_stream_enabled_flag",
    params.encoder.sps.cabac_bypass_stream_enabled_flag, false,
    "Controls coding method for ep(bypass) bins")

503
504
505
506
  ("disableAttributeCoding",
    params.disableAttributeCoding, false,
    "Ignore attribute coding configuration")

507
  (po::Section("Geometry"))
508

509
510
511
512
513
514
515
516
517
518
519
520
  ("implicitQtBtEnabled",
    params.encoder.gps.implicit_qtbt_enabled_flag, true,
    "Enables non-cubic geometry bounding box")

  ("max_num_implicit_qtbt_before_ot",
    params.encoder.gps.max_num_implicit_qtbt_before_ot, 4,
    "Max number of implicit qtbt before ot")

  ("min_implicit_qtbt_size_log2",
    params.encoder.gps.min_implicit_qtbt_size_log2, 0,
    "Minimum size of implicit qtbt")

521
  // tools
522
523
524
525
526
527
  ("bitwiseOccupancyCoding",
    params.encoder.gps.bitwise_occupancy_coding_flag, true,
    "Selects between bitwise and bytewise occupancy coding:\n"
    "  0: bytewise\n"
    "  1: bitwise")

528
  ("neighbourContextRestriction",
529
    params.encoder.gps.neighbour_context_restriction_flag, false,
530
    "Limit geometry octree occupancy contextualisation to sibling nodes")
531

532
  ("neighbourAvailBoundaryLog2",
533
    params.encoder.gps.neighbour_avail_boundary_log2, 0,
534
535
536
    "Defines the avaliability volume for neighbour occupancy lookups."
    " 0: unconstrained")

537
  ("inferredDirectCodingMode",
538
    params.encoder.gps.inferred_direct_coding_mode_enabled_flag, true,
539
    "Permits early termination of the geometry octree for isolated points")
540

541
542
543
544
  ("adjacentChildContextualization",
    params.encoder.gps.adjacent_child_contextualization_enabled_flag, true,
    "Occupancy contextualization using neighbouring adjacent children")

545
546
547
548
  ("intra_pred_max_node_size_log2",
    params.encoder.gps.intra_pred_max_node_size_log2, 0,
    "octree nodesizes eligible for occupancy intra prediction")

549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
  ("planarEnabled",
    params.encoder.gps.geom_planar_mode_enabled_flag, true,
    "Use planar mode for geometry coding")

  ("planarModeThreshold0",
    params.encoder.gps.geom_planar_threshold0, 77,
    "Activation threshold (0-127) of first planar mode. "
    "Lower values imply more use of the first planar mode")

  ("planarModeThreshold1",
    params.encoder.gps.geom_planar_threshold1, 99,
    "Activation threshold (0-127) of second planar mode. "
    "Lower values imply more use of the first planar mode")

  ("planarModeThreshold2",
    params.encoder.gps.geom_planar_threshold2, 113,
    "Activation threshold (0-127) of third planar mode. "
    "Lower values imply more use of the third planar mode")

   ("planarModeIdcmUse",
    params.encoder.gps.geom_planar_idcm_threshold, 0,
    "Degree (0-127) of IDCM activation when planar mode is enabled.\n"
    "  0 => never, 127 => always")

573
574
575
576
  ("ctxOccupancyReductionFactor",
     params.encoder.gps.geom_occupancy_ctx_reduction_factor, 3,
     "Adjusts the number of contexts used in occupancy coding")

577
578
579
580
  ("trisoup_node_size_log2",
    params.encoder.gps.trisoup_node_size_log2, 0,
    "Size of nodes for surface triangulation.\n"
    "  0: disabled\n")
581

582
583
584
585
586
587
588
589
  ("positionQuantisationEnabled",
    params.encoder.gps.geom_scaling_enabled_flag, false,
    "Enable in-loop quantisation of positions")

  ("positionBaseQp",
    params.encoder.gps.geom_base_qp, 4,
    "Base QP used in position quantisation")

590
591
592
593
  ("positionSliceQpOffset",
    params.encoder.gbh.geom_slice_qp_offset, 0,
    "Per-slice QP offset used in position quantisation")

594
  ("positionQuantisationOctreeDepth",
595
596
    params.encoder.gbh.geom_octree_qp_offset_depth, -1,
    "Octree depth used for signalling position QP offsets (-1 => disabled)")
597

598
599
  (po::Section("Attributes"))

600
601
602
  // attribute processing
  //   NB: Attribute options are special in the way they are applied (see above)
  ("attribute",
603
604
605
    attribute_setter,
    "Encode the given attribute (NB, must appear after the"
    "following attribute parameters)")
606

607
608
609
610
  ("bitdepth",
    params_attr.desc.attr_bitdepth, 8,
    "Attribute bitdepth")

611
612
613
614
615
  // todo(df): this should be per-attribute
  ("colourMatrix",
    params_attr.desc.cicp_matrix_coefficients_idx, ColourMatrix::kBt709,
    "Matrix used in colourspace conversion\n"
    "  0: none (identity)\n"
616
617
    "  1: ITU-T BT.709\n"
    "  8: YCgCo")
618

619
  ("transformType",
620
    params_attr.aps.attr_encoding, AttributeEncoding::kPredictingTransform,
621
    "Coding method to use for attribute:\n"
622
    "  0: Hierarchical neighbourhood prediction\n"
623
    "  1: Region Adaptive Hierarchical Transform (RAHT)\n"
624
    "  2: Hierarichical neighbourhood prediction as lifting transform")
625
626

  ("rahtDepth",
627
    params_attr.aps.raht_depth, 21,
628
629
    "Number of bits for morton representation of an RAHT co-ordinate"
    "component")
630

631
632
633
634
  ("rahtPredictionEnabled",
    params_attr.aps.raht_prediction_enabled_flag, true,
    "Controls the use of transform-domain prediction")

635
  ("numberOfNearestNeighborsInPrediction",
636
    params_attr.aps.num_pred_nearest_neighbours, 3,
637
    "Attribute's maximum number of nearest neighbors to be used for prediction")
638

639
640
641
642
643
644
  ("adaptivePredictionThreshold",
    params_attr.aps.adaptive_prediction_threshold, -1,
    "Neighbouring attribute value difference that enables choice of "
    "single|multi predictors. Applies to transformType=2 only.\n"
    "  -1: auto = 2**(bitdepth-2)")

645
646
647
648
  ("attributeSearchRange",
    params_attr.aps.search_range, 128,
    "Range for nearest neighbor search")

649
650
651
652
  ("lod_neigh_bias",
    params_attr.aps.lod_neigh_bias, {1, 1, 1},
    "Attribute's intra prediction weight for Z axis")

653
654
655
656
657
658
  ("lodDecimation",
    params_attr.aps.lod_decimation_enabled_flag, false,
    "Controls LoD generation method:\n"
    " 0: distance based subsampling\n"
    " 1: decimation by 1:3")

659
660
661
662
663
  ("max_num_direct_predictors",
    params_attr.aps.max_num_direct_predictors, 3,
    "Maximum number of nearest neighbour candidates used in direct"
    "attribute prediction")

664
  ("levelOfDetailCount",
665
    params_attr.aps.num_detail_levels, 1,
666
    "Attribute's number of levels of detail")
667

668
669
  ("dist2",
    params_attr.aps.dist2, {},
670
671
    "Attribute's list of squared distances, or initial value for automatic"
    "derivation")
672

673
674
675
676
  ("intraLodPredictionEnabled",
    params_attr.aps.intra_lod_prediction_enabled_flag, false,
    "Permits referring to points in same LoD")

677
678
679
680
681
  ("interComponentPredictionEnabled",
    params_attr.aps.inter_component_prediction_enabled_flag, false,
    "Use primary attribute component to predict values of subsequent "
    "components")

682
683
684
685
  ("aps_scalable_enable_flag",
    params_attr.aps.scalable_lifting_enabled_flag, false,
    "Enable scalable attritube coding")

686
687
688
689
690
691
692
  ("qp",
    params_attr.aps.init_qp, 4,
    "Attribute's luma quantisation parameter")

  ("qpChromaOffset",
    params_attr.aps.aps_chroma_qp_offset, 0,
    "Attribute's chroma quantisation parameter offset (relative to luma)")
693
694
695
696

  ("aps_slice_qp_deltas_present_flag",
    params_attr.aps.aps_slice_qp_deltas_present_flag, false,
    "Enable signalling of per-slice QP values")
697

698
  ("qpLayerOffsetsLuma",
699
700
    params_attr.encoder.abh.attr_layer_qp_delta_luma, {},
      "Attribute's per layer luma QP offsets")
701
702

  ("qpLayerOffsetsChroma",
703
704
      params_attr.encoder.abh.attr_layer_qp_delta_chroma, {},
      "Attribute's per layer chroma QP offsets")
705

706
707
708
709
710
  // This section is just dedicated to attribute recolouring (encoder only).
  // parameters are common to all attributes.
  (po::Section("Recolouring"))

  ("recolourSearchRange",
711
    params.encoder.recolour.searchRange, 1,
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
    "")

  ("recolourNumNeighboursFwd",
    params.encoder.recolour.numNeighboursFwd, 8,
    "")

  ("recolourNumNeighboursBwd",
    params.encoder.recolour.numNeighboursBwd, 1,
    "")

  ("recolourUseDistWeightedAvgFwd",
    params.encoder.recolour.useDistWeightedAvgFwd, true,
    "")

  ("recolourUseDistWeightedAvgBwd",
    params.encoder.recolour.useDistWeightedAvgBwd, true,
    "")

  ("recolourSkipAvgIfIdenticalSourcePointPresentFwd",
    params.encoder.recolour.skipAvgIfIdenticalSourcePointPresentFwd, true,
    "")

  ("recolourSkipAvgIfIdenticalSourcePointPresentBwd",
    params.encoder.recolour.skipAvgIfIdenticalSourcePointPresentBwd, false,
    "")

  ("recolourDistOffsetFwd",
    params.encoder.recolour.distOffsetFwd, 4.,
    "")

  ("recolourDistOffsetBwd",
    params.encoder.recolour.distOffsetBwd, 4.,
    "")

  ("recolourMaxGeometryDist2Fwd",
    params.encoder.recolour.maxGeometryDist2Fwd, 1000.,
    "")

  ("recolourMaxGeometryDist2Bwd",
    params.encoder.recolour.maxGeometryDist2Bwd, 1000.,
    "")

  ("recolourMaxAttributeDist2Fwd",
    params.encoder.recolour.maxAttributeDist2Fwd, 1000.,
    "")

  ("recolourMaxAttributeDist2Bwd",
    params.encoder.recolour.maxAttributeDist2Bwd, 1000.,
    "")

762
  ;
763
  /* clang-format on */
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778

  po::setDefaults(opts);
  po::ErrorReporter err;
  const list<const char*>& argv_unhandled =
    po::scanArgv(opts, argc, (const char**)argv, err);

  for (const auto arg : argv_unhandled) {
    err.warn() << "Unhandled argument ignored: " << arg << "\n";
  }

  if (argc == 1 || print_help) {
    po::doHelp(std::cout, opts, 78);
    return false;
  }

779
780
  // Certain coding modes are not available when trisoup is enabled.
  // Disable them, and warn if set (they may be set as defaults).
781
  if (params.encoder.gps.trisoup_node_size_log2 > 0) {
782
783
784
785
786
787
788
789
790
791
    if (!params.encoder.gps.geom_unique_points_flag)
      err.warn() << "TriSoup geometry does not preserve duplicated points\n";

    if (params.encoder.gps.inferred_direct_coding_mode_enabled_flag)
      err.warn() << "TriSoup geometry is incompatable with IDCM\n";

    params.encoder.gps.geom_unique_points_flag = true;
    params.encoder.gps.inferred_direct_coding_mode_enabled_flag = false;
  }

792
793
794
795
796
797
798
  // Planar coding mode is not available for bytewise coding
  if (!params.encoder.gps.bitwise_occupancy_coding_flag) {
    if (params.encoder.gps.geom_planar_mode_enabled_flag)
      err.warn() << "Bytewise geometry coding does not support planar mode\n";
    params.encoder.gps.geom_planar_mode_enabled_flag = false;
  }

799
800
801
802
803
804
805
  // support disabling attribute coding (simplifies configuration)
  if (params.disableAttributeCoding) {
    params.encoder.attributeIdxMap.clear();
    params.encoder.sps.attributeSets.clear();
    params.encoder.aps.clear();
  }

806
  // fixup any per-attribute settings
807
  for (const auto& it : params.encoder.attributeIdxMap) {
808
    auto& attr_sps = params.encoder.sps.attributeSets[it.second];
809
    auto& attr_aps = params.encoder.aps[it.second];
810
    auto& attr_enc = params.encoder.attr[it.second];
811

812
813
814
815
816
    // default values for attribute
    attr_sps.cicp_colour_primaries_idx = 2;
    attr_sps.cicp_transfer_characteristics_idx = 2;
    attr_sps.cicp_video_full_range_flag = true;

817
    if (it.first == "reflectance") {
818
      // Avoid wasting bits signalling chroma quant step size for reflectance
819
      attr_aps.aps_chroma_qp_offset = 0;
820
      attr_enc.abh.attr_layer_qp_delta_chroma.clear();
821
822
823
824
825
826
827
828
829
830

      // There is no matrix for reflectace
      attr_sps.cicp_matrix_coefficients_idx = ColourMatrix::kUnspecified;
      attr_sps.attr_num_dimensions = 1;
      attr_sps.attributeLabel = KnownAttributeLabel::kReflectance;
    }

    if (it.first == "color") {
      attr_sps.attr_num_dimensions = 3;
      attr_sps.attributeLabel = KnownAttributeLabel::kColour;
831
832
    }

833
834
835
836
837
    // Derive the secondary bitdepth
    // todo(df): this needs to be a command line argument
    //  -- but there are a few edge cases to handle
    attr_sps.attr_bitdepth_secondary = attr_sps.attr_bitdepth;

838
839
840
841
    // Assume that YCgCo is actually YCgCoR for now
    if (attr_sps.cicp_matrix_coefficients_idx == ColourMatrix::kYCgCo)
      attr_sps.attr_bitdepth_secondary++;

842
843
844
845
846
    bool isLifting =
      attr_aps.attr_encoding == AttributeEncoding::kPredictingTransform
      || attr_aps.attr_encoding == AttributeEncoding::kLiftingTransform;

    // derive the dist2 values based on an initial value
847
848
    if (isLifting) {
      if (attr_aps.dist2.size() > attr_aps.num_detail_levels) {
849
        attr_aps.dist2.resize(attr_aps.num_detail_levels);
850
851
852
853
854
855
856
857
858
859
860
      } else if (
        attr_aps.dist2.size() < attr_aps.num_detail_levels
        && !attr_aps.dist2.empty()) {
        if (attr_aps.dist2.size() < attr_aps.num_detail_levels) {
          attr_aps.dist2.resize(attr_aps.num_detail_levels);
          const double distRatio = 4.0;
          uint64_t d2 = attr_aps.dist2[0];
          for (int i = 0; i < attr_aps.num_detail_levels; ++i) {
            attr_aps.dist2[i] = d2;
            d2 = uint64_t(std::round(distRatio * d2));
          }
861
862
863
        }
      }
    }
864
865
866
867
868
869
870
871
872
873
874
    // In order to simplify specification of dist2 values, which are
    // depending on the scale of the coded point cloud, the following
    // adjust the dist2 values according to PQS.  The user need only
    // specify the unquantised PQS value.
    if (params.positionQuantizationScaleAdjustsDist2) {
      double pqs = params.encoder.sps.seq_source_geom_scale_factor;
      double pqs2 = pqs * pqs;
      for (auto& dist2 : attr_aps.dist2)
        dist2 = int64_t(std::round(pqs2 * dist2));
    }

875
876
877
878
879
880
881
882
    // Set default threshold based on bitdepth
    if (attr_aps.adaptive_prediction_threshold == -1) {
      attr_aps.adaptive_prediction_threshold = 1
        << (attr_sps.attr_bitdepth - 2);
    }

    if (attr_aps.attr_encoding == AttributeEncoding::kLiftingTransform) {
      attr_aps.adaptive_prediction_threshold = 0;
883
      attr_aps.intra_lod_prediction_enabled_flag = false;
884
885
886
    }

    // For RAHT, ensure that the unused lod count = 0 (prevents mishaps)
887
    if (attr_aps.attr_encoding == AttributeEncoding::kRAHTransform) {
888
      attr_aps.num_detail_levels = 0;
889
      attr_aps.adaptive_prediction_threshold = 0;
890
891
892
    }
  }

893
  // sanity checks
894

895
896
897
898
899
900
  if (
    params.encoder.partition.sliceMaxPoints
    < params.encoder.partition.sliceMinPoints)
    err.error()
      << "sliceMaxPoints must be greater than or equal to sliceMinPoints\n";

901
902
903
904
905
  if (params.encoder.gps.intra_pred_max_node_size_log2)
    if (!params.encoder.gps.neighbour_avail_boundary_log2)
      err.error() << "Geometry intra prediction requires finite"
                     "neighbour_avail_boundary_log2\n";

906
907
908
  for (const auto& it : params.encoder.attributeIdxMap) {
    const auto& attr_sps = params.encoder.sps.attributeSets[it.second];
    const auto& attr_aps = params.encoder.aps[it.second];
909
910
911
912
913
914
915
916
917
918
    auto& attr_enc = params.encoder.attr[it.second];

    if (it.first == "color") {
      if (
        attr_enc.abh.attr_layer_qp_delta_luma.size()
        != attr_enc.abh.attr_layer_qp_delta_chroma.size()) {
        err.error() << it.first
                    << ".qpLayerOffsetsLuma length != .qpLayerOffsetsChroma\n";
      }
    }
919
920
921
922
923

    bool isLifting =
      attr_aps.attr_encoding == AttributeEncoding::kPredictingTransform
      || attr_aps.attr_encoding == AttributeEncoding::kLiftingTransform;

924
925
    if (attr_sps.attr_bitdepth > 16)
      err.error() << it.first << ".bitdepth must be less than 17\n";
926

927
928
    if (attr_sps.attr_bitdepth_secondary > 16)
      err.error() << it.first << ".bitdepth_secondary must be less than 17\n";
929

930
    if (isLifting) {
931
      int lod = attr_aps.num_detail_levels;
932
      if (lod > 255 || lod < 0) {
933
        err.error() << it.first
934
                    << ".levelOfDetailCount must be in the range [0,255]\n";
935
      }
936
937
      if (attr_aps.dist2.size() != lod) {
        err.error() << it.first << ".dist2 does not have " << lod
938
                    << " entries\n";
939
      }
940

941
942
943
944
945
      if (attr_aps.adaptive_prediction_threshold < 0) {
        err.error() << it.first
                    << ".adaptivePredictionThreshold must be positive\n";
      }

946
      if (
947
        attr_aps.num_pred_nearest_neighbours
948
        > kAttributePredictionMaxNeighbourCount) {
949
950
        err.error() << it.first
                    << ".numberOfNearestNeighborsInPrediction must be <= "
951
                    << kAttributePredictionMaxNeighbourCount << "\n";
952
      }
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
      if (attr_aps.scalable_lifting_enabled_flag) {
        if (attr_aps.attr_encoding != AttributeEncoding::kLiftingTransform) {
          err.error() << it.first << "AttributeEncoding must be "
                      << (int)AttributeEncoding::kLiftingTransform << "\n";
        }

        if (attr_aps.lod_decimation_enabled_flag) {
          err.error() << it.first
                      << ".lod_decimation_enabled_flag must be = 0 \n";
        }

        if (params.encoder.gps.trisoup_node_size_log2 > 0) {
          err.error() << it.first
                      << "trisoup_node_size_log2 must be disabled \n";
        }
      }
969
    }
970
971
972
973
974
975
976
977

    if (attr_aps.init_qp < 4)
      err.error() << it.first << ".qp must be greater than 3\n";

    if (attr_aps.init_qp + attr_aps.aps_chroma_qp_offset < 4) {
      err.error() << it.first << ".qpChromaOffset must be greater than "
                  << attr_aps.init_qp - 5 << "\n";
    }
Khaled Mammou's avatar
TMC3v0    
Khaled Mammou committed
978
979
  }

980
981
  // check required arguments are specified

982
  if (!params.isDecoder && params.uncompressedDataPath.empty())
983
984
    err.error() << "uncompressedDataPath not set\n";

985
  if (params.isDecoder && params.reconstructedDataPath.empty())
986
987
988
989
990
991
992
993
994
995
    err.error() << "reconstructedDataPath not set\n";

  if (params.compressedStreamPath.empty())
    err.error() << "compressedStreamPath not set\n";

  // report the current configuration (only in the absence of errors so
  // that errors/warnings are more obvious and in the same place).
  if (err.is_errored)
    return false;

996
997
  // Dump the complete derived configuration
  cout << "+ Effective configuration parameters\n";
998

999
  po::dumpCfg(cout, opts, "General", 4);
1000
  if (params.isDecoder) {
1001
    po::dumpCfg(cout, opts, "Decoder", 4);
1002
  } else {
1003
1004
    po::dumpCfg(cout, opts, "Encoder", 4);
    po::dumpCfg(cout, opts, "Geometry", 4);
1005
    po::dumpCfg(cout, opts, "Recolouring", 4);
1006

1007
    for (const auto& it : params.encoder.attributeIdxMap) {
1008
      // NB: when dumping the config, opts references params_attr
1009
1010
      params_attr.desc = params.encoder.sps.attributeSets[it.second];
      params_attr.aps = params.encoder.aps[it.second];
1011
      params_attr.encoder = params.encoder.attr[it.second];
1012
1013
1014
      cout << "    " << it.first << "\n";
      po::dumpCfg(cout, opts, "Attributes", 8);
    }
Khaled Mammou's avatar
TMC3v0    
Khaled Mammou committed
1015
1016
  }

1017
1018
  cout << endl;

Khaled Mammou's avatar
TMC3v0    
Khaled Mammou committed
1019
1020
  return true;
}
1021

1022
1023
1024
//============================================================================

SequenceEncoder::SequenceEncoder(Parameters* params) : params(params)
1025
1026
1027
1028
1029
{
  // determine the naming (ordering) of ply properties
  _plyAttrNames.position =
    axisOrderToPropertyNames(params->encoder.sps.geometry_axis_order);
}
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054

//----------------------------------------------------------------------------

int
SequenceEncoder::compress(Stopwatch* clock)
{
  bytestreamFile.open(params->compressedStreamPath, ios::binary);
  if (!bytestreamFile.is_open()) {
    return -1;
  }

  const int lastFrameNum = params->firstFrameNum + params->frameCount;
  for (frameNum = params->firstFrameNum; frameNum < lastFrameNum; frameNum++) {
    if (compressOneFrame(clock))
      return -1;
  }

  std::cout << "Total bitstream size " << bytestreamFile.tellp() << " B\n";
  bytestreamFile.close();

  return 0;
}

//----------------------------------------------------------------------------

1055
int
1056
SequenceEncoder::compressOneFrame(Stopwatch* clock)
1057
{
1058
  std::string srcName{expandNum(params->uncompressedDataPath, frameNum)};
Khaled Mammou's avatar
TMC3v0    
Khaled Mammou committed
1059
  PCCPointSet3 pointCloud;
1060
1061
1062
  if (
    !ply::read(srcName, _plyAttrNames, pointCloud)
    || pointCloud.getPointCount() == 0) {
Khaled Mammou's avatar
TMC3v0    
Khaled Mammou committed
1063
1064
1065
1066
    cout << "Error: can't open input file!" << endl;
    return -1;
  }

1067
1068
  // Sanitise the input point cloud
  // todo(df): remove the following with generic handling of properties
1069
  bool codeColour = params->encoder.attributeIdxMap.count("color");
1070
1071
1072
1073
  if (!codeColour)
    pointCloud.removeColors();
  assert(codeColour == pointCloud.hasColors());

1074
  bool codeReflectance = params->encoder.attributeIdxMap.count("reflectance");
1075
1076
1077
1078
  if (!codeReflectance)
    pointCloud.removeReflectances();
  assert(codeReflectance == pointCloud.hasReflectances());

1079
  clock->start();
1080

1081
1082
  if (params->convertColourspace)
    convertFromGbr(params->encoder.sps, pointCloud);
1083

1084
  if (params->reflectanceScale > 1 && pointCloud.hasReflectances()) {
1085
1086
    const auto pointCount = pointCloud.getPointCount();
    for (size_t i = 0; i < pointCount; ++i) {
1087
      int val = pointCloud.getReflectance(i) / params->reflectanceScale;
1088
1089
1090
1091
1092
1093
      pointCloud.setReflectance(i, val);
    }
  }

  // The reconstructed point cloud
  std::unique_ptr<PCCPointSet3> reconPointCloud;
1094
  if (!params->reconstructedDataPath.empty()) {
1095
    reconPointCloud.reset(new PCCPointSet3);
Khaled Mammou's avatar
TMC3v0    
Khaled Mammou committed
1096
1097
  }

1098
1099
  auto bytestreamLenFrameStart = bytestreamFile.tellp();

1100
  int ret = encoder.compress(
1101
    pointCloud, &params->encoder, this, reconPointCloud.get());
1102
  if (ret) {
Khaled Mammou's avatar
TMC3v0    
Khaled Mammou committed
1103
1104
1105
    cout << "Error: can't compress point cloud!" << endl;
    return -1;
  }
1106

1107
1108
  auto bytestreamLenFrameEnd = bytestreamFile.tellp();
  int frameLen = bytestreamLenFrameEnd - bytestreamLenFrameStart;
Khaled Mammou's avatar
TMC3v0    
Khaled Mammou committed
1109

1110
  std::cout << "Total frame size " << frameLen << " B" << std::endl;
1111

1112
1113
1114
  clock->stop();

  if (!params->reconstructedDataPath.empty()) {
1115
1116
    if (params->convertColourspace)
      convertToGbr(params->encoder.sps, *reconPointCloud);
1117

1118
    if (params->reflectanceScale > 1 && reconPointCloud->hasReflectances()) {
1119
1120
      const auto pointCount = reconPointCloud->getPointCount();
      for (size_t i = 0; i < pointCount; ++i) {
1121
1122
        int val =
          reconPointCloud->getReflectance(i) * params->reflectanceScale;
1123
1124
        reconPointCloud->setReflectance(i, val);
      }
Khaled Mammou's avatar
TMC3v0    
Khaled Mammou committed
1125
    }
1126

1127
    std::string recName{expandNum(params->reconstructedDataPath, frameNum)};
1128
    ply::write(
1129
1130
1131
1132
      *reconPointCloud, _plyAttrNames,
      1.0 / params->encoder.sps.seq_source_geom_scale_factor,
      params->encoder.sps.seq_bounding_box_xyz0, recName,
      !params->outputBinaryPly);
Khaled Mammou's avatar
TMC3v0    
Khaled Mammou committed
1133
1134
1135
1136
  }

  return 0;
}
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157

//----------------------------------------------------------------------------

void
SequenceEncoder::onOutputBuffer(const PayloadBuffer& buf)
{
  writeTlv(buf, bytestreamFile);
}

//----------------------------------------------------------------------------

void
SequenceEncoder::onPostRecolour(const PCCPointSet3& cloud)
{
  if (params->postRecolorPath.empty()) {
    return;
  }

  std::string plyName{expandNum(params->postRecolorPath, frameNum)};

  // todo(df): stop the clock
1158
  if (!params->convertColourspace) {
1159
1160
1161
1162
1163
    ply::write(
      cloud, _plyAttrNames,
      1.0 / params->encoder.sps.seq_source_geom_scale_factor,
      params->encoder.sps.seq_bounding_box_xyz0, plyName,
      !params->outputBinaryPly);
1164
1165
1166
1167
    return;
  }

  PCCPointSet3 tmpCloud(cloud);
1168
  convertToGbr(params->encoder.sps, tmpCloud);
1169
1170
1171
1172
1173
  ply::write(
    tmpCloud, _plyAttrNames,
    1.0 / params->encoder.sps.seq_source_geom_scale_factor,
    params->encoder.sps.seq_bounding_box_xyz0, plyName,
    !params->outputBinaryPly);
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
}

//============================================================================

SequenceDecoder::SequenceDecoder(const Parameters* params)
  : params(params), decoder(params->decoder)
{}

//----------------------------------------------------------------------------

1184
int
1185
SequenceDecoder::decompress(Stopwatch* clock)
1186
{
1187
  ifstream fin(params->compressedStreamPath, ios::binary);
Khaled Mammou's avatar
TMC3v0    
Khaled Mammou committed
1188
1189
1190
1191
  if (!fin.is_open()) {
    return -1;
  }

1192
1193
  frameNum = params->firstFrameNum;
  this->clock = clock;
1194

1195
  PayloadBuffer buf;
1196
1197

  clock->start();
1198

1199
1200
1201
  while (true) {
    PayloadBuffer* buf_ptr = &buf;
    readTlv(fin, &buf);
Khaled Mammou's avatar
TMC3v0    
Khaled Mammou committed
1202

1203
1204
1205
    // at end of file (or other error), flush decoder
    if (!fin)
      buf_ptr = nullptr;