From fb9289c1be4e5cc522a150f10cc517ae9414ce47 Mon Sep 17 00:00:00 2001 From: oyvindln Date: Mon, 15 Jan 2024 02:14:51 +0100 Subject: [PATCH 1/2] Change fileLoc to be 64-bit to allow larger values and avoid borking the value if saving levels --- tools/ld-disc-stacker/stackingpool.cpp | 1 + tools/ld-dropout-correct/correctorpool.cpp | 1 + tools/library/tbc/jsonio.cpp | 16 +++++++++++----- tools/library/tbc/jsonio.h | 9 +++++++++ tools/library/tbc/lddecodemetadata.h | 3 +-- 5 files changed, 23 insertions(+), 7 deletions(-) diff --git a/tools/ld-disc-stacker/stackingpool.cpp b/tools/ld-disc-stacker/stackingpool.cpp index 4440530a5..ad4256d31 100644 --- a/tools/ld-disc-stacker/stackingpool.cpp +++ b/tools/ld-disc-stacker/stackingpool.cpp @@ -23,6 +23,7 @@ ************************************************************************/ #include "stackingpool.h" +#include "vbidecoder.h" StackingPool::StackingPool(QString _outputFilename, QString _outputJsonFilename, qint32 _maxThreads, QVector &_ldDecodeMetaData, QVector &_sourceVideos, diff --git a/tools/ld-dropout-correct/correctorpool.cpp b/tools/ld-dropout-correct/correctorpool.cpp index ee98b5e15..81317eef5 100644 --- a/tools/ld-dropout-correct/correctorpool.cpp +++ b/tools/ld-dropout-correct/correctorpool.cpp @@ -24,6 +24,7 @@ ************************************************************************/ #include "correctorpool.h" +#include "vbidecoder.h" CorrectorPool::CorrectorPool(QString _outputFilename, QString _outputJsonFilename, qint32 _maxThreads, QVector &_ldDecodeMetaData, QVector &_sourceVideos, diff --git a/tools/library/tbc/jsonio.cpp b/tools/library/tbc/jsonio.cpp index 451c69473..4533a36dd 100644 --- a/tools/library/tbc/jsonio.cpp +++ b/tools/library/tbc/jsonio.cpp @@ -24,7 +24,6 @@ #include "jsonio.h" -#include #include // Recognise JSON space characters @@ -46,10 +45,12 @@ JsonReader::JsonReader(std::istream &_input) void JsonReader::read(int &value) { - // Round to the nearest integer - double d; - readNumber(d); - value = static_cast(std::lround(d)); + readSignedInteger(value); +} + +void JsonReader::read(qint64 &value) +{ + readSignedInteger(value); } void JsonReader::read(double &value) @@ -351,6 +352,11 @@ void JsonWriter::write(int value) output << value; } +void JsonWriter::write(qint64 value) +{ + output << value; +} + void JsonWriter::write(double value) { output << value; diff --git a/tools/library/tbc/jsonio.h b/tools/library/tbc/jsonio.h index 24b1d529d..87e30c991 100644 --- a/tools/library/tbc/jsonio.h +++ b/tools/library/tbc/jsonio.h @@ -32,6 +32,7 @@ #include #include #include +#include class JsonReader { @@ -51,6 +52,7 @@ class JsonReader } // Numbers + void read(qint64 &value); void read(int &value); void read(double &value); @@ -81,6 +83,12 @@ class JsonReader void readString(std::string &value); void readNumber(double &value); + template void readSignedInteger(T& value) { + // Round to the nearest integer + double d; + readNumber(d); + value = static_cast(std::llround(d)); + } // The input stream std::istream &input; @@ -101,6 +109,7 @@ class JsonWriter // Numbers void write(int value); + void write(qint64 value); void write(double value); // Booleans diff --git a/tools/library/tbc/lddecodemetadata.h b/tools/library/tbc/lddecodemetadata.h index 7a3102b49..83173eacb 100644 --- a/tools/library/tbc/lddecodemetadata.h +++ b/tools/library/tbc/lddecodemetadata.h @@ -33,7 +33,6 @@ #include #include -#include "vbidecoder.h" #include "dropouts.h" class JsonReader; @@ -203,7 +202,7 @@ class LdDecodeMetaData bool pad = false; qint32 diskLoc = -1; - qint32 fileLoc = -1; + qint64 fileLoc = -1; qint32 decodeFaults = -1; qint32 efmTValues = -1; From aad4190effdcdc716445a5f777b1f70b4d3ae1ea Mon Sep 17 00:00:00 2001 From: oyvindln Date: Mon, 15 Jan 2024 17:49:15 +0100 Subject: [PATCH 2/2] Read double values correctly and store diskLoc as double --- tools/library/tbc/jsonio.cpp | 14 ++++++++++++-- tools/library/tbc/lddecodemetadata.h | 2 +- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/tools/library/tbc/jsonio.cpp b/tools/library/tbc/jsonio.cpp index 4533a36dd..45f6c30a9 100644 --- a/tools/library/tbc/jsonio.cpp +++ b/tools/library/tbc/jsonio.cpp @@ -25,6 +25,11 @@ #include "jsonio.h" #include +#if ((defined(_MSVC_LANG) && _MSVC_LANG >= 201703L) || __cplusplus >= 201703L) +#include +#else +#include +#endif // Recognise JSON space characters static bool isAsciiSpace(char c) @@ -332,8 +337,13 @@ void JsonReader::readNumber(double &value) } } - // XXX In C++17 we could use std::from_chars instead, which is slightly more efficient - value = std::stod(buf); +#if ((defined(_MSVC_LANG) && _MSVC_LANG >= 201703L) || __cplusplus >= 201703L) + // Use the faster C++17 method if available. + std::from_chars(buf.data(), buf.data() + buf.size(), value); +#else + std::istringstream(buf) >> value; +#endif + // We've read one character beyond the end of the number (there's no way to // tell where the end is otherwise), so we must unget the last char diff --git a/tools/library/tbc/lddecodemetadata.h b/tools/library/tbc/lddecodemetadata.h index 83173eacb..c6930fe48 100644 --- a/tools/library/tbc/lddecodemetadata.h +++ b/tools/library/tbc/lddecodemetadata.h @@ -201,7 +201,7 @@ class LdDecodeMetaData DropOuts dropOuts; bool pad = false; - qint32 diskLoc = -1; + double diskLoc = -1; qint64 fileLoc = -1; qint32 decodeFaults = -1; qint32 efmTValues = -1;