Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Diffdod dev #455

Merged
merged 14 commits into from
Feb 6, 2020
409 changes: 361 additions & 48 deletions tools/ld-diffdod/diffdod.cpp

Large diffs are not rendered by default.

44 changes: 36 additions & 8 deletions tools/ld-diffdod/diffdod.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,24 +26,52 @@
#define DIFFDOD_H

#include <QObject>
#include <QElapsedTimer>
#include <QAtomicInt>
#include <QThread>
#include <QDebug>
#include <QFile>
#include <QtMath>

#include "tbcsources.h"
// TBC library includes
#include "sourcevideo.h"
#include "lddecodemetadata.h"
#include "vbidecoder.h"
#include "filters.h"

class Diffdod : public QObject
class Sources;

class DiffDod : public QThread
{
Q_OBJECT
public:
explicit Diffdod(QObject *parent = nullptr);
explicit DiffDod(QAtomicInt& abort, Sources& sources, QObject *parent = nullptr);

bool process(QVector<QString> inputFilenames, bool reverse,
qint32 dodThreshold, bool lumaClip, qint32 startVbi, qint32 lengthVbi);
protected:
void run() override;

private:
TbcSources tbcSources;
// Decoder pool
QAtomicInt& m_abort;
Sources& m_sources;

// Processing methods
void performClipCheck(QVector<SourceVideo::Data> &fields, QVector<QByteArray> &fieldDiff,
LdDecodeMetaData::VideoParameters videoParameters,
QVector<qint32> availableSourcesForFrame);
void performLumaFilter(QVector<SourceVideo::Data> &fields,
LdDecodeMetaData::VideoParameters videoParameters,
QVector<qint32> availableSourcesForFrame);
void getFieldErrorByMedian(QVector<SourceVideo::Data> &fields, QVector<QByteArray> &fieldDiff, qint32 dodThreshold,
LdDecodeMetaData::VideoParameters videoParameters,
QVector<qint32> availableSourcesForFrame);
QVector<LdDecodeMetaData::DropOuts> getFieldDropouts(QVector<QByteArray> &fieldDiff,
LdDecodeMetaData::VideoParameters videoParameters,
QVector<qint32> availableSourcesForFrame);

void concatenateFieldDropouts(QVector<LdDecodeMetaData::DropOuts> &dropouts, QVector<qint32> availableSourcesForFrame);

bool loadInputTbcFiles(QVector<QString> inputFilenames, bool reverse);
qint32 median(QVector<qint32> v);
float convertLinearToBrightness(quint16 value, quint16 black16bIre, quint16 white16bIre, bool isSourcePal);
};

#endif // DIFFDOD_H
4 changes: 2 additions & 2 deletions tools/ld-diffdod/ld-diffdod.pro
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ SOURCES += \
../library/tbc/logging.cpp \
diffdod.cpp \
main.cpp \
tbcsources.cpp
sources.cpp

HEADERS += \
../library/filter/firfilter.h \
Expand All @@ -32,7 +32,7 @@ HEADERS += \
../library/tbc/filters.h \
../library/tbc/logging.h \
diffdod.h \
tbcsources.h
sources.h

# Add external includes to the include path
INCLUDEPATH += ../library/filter
Expand Down
44 changes: 32 additions & 12 deletions tools/ld-diffdod/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
#include <QCommandLineParser>

#include "logging.h"
#include "diffdod.h"
#include "sources.h"

int main(int argc, char *argv[])
{
Expand Down Expand Up @@ -61,14 +61,14 @@ int main(int argc, char *argv[])
QCoreApplication::translate("main", "Reverse the field order to second/first (default first/second)"));
parser.addOption(setReverseOption);

// Option to turn off luma clip detection (-n / --lumaclip)
QCommandLineOption setLumaOption(QStringList() << "n" << "lumaclip",
QCoreApplication::translate("main", "Perform luma clip signal dropout detection"));
parser.addOption(setLumaOption);
// Option to turn off signal clip detection (-n / --noclip)
QCommandLineOption setNoClipOption(QStringList() << "n" << "noclip",
QCoreApplication::translate("main", "Do not perform signal clip dropout detection"));
parser.addOption(setNoClipOption);

// Option to select DOD threshold (-x / --dod-threshold)
QCommandLineOption dodThresholdOption(QStringList() << "x" << "dod-threshold",
QCoreApplication::translate("main", "Specify the DOD threshold (100-65435 default: 400"),
QCoreApplication::translate("main", "Specify the DOD threshold percent (1 to 100% default: 7%"),
QCoreApplication::translate("main", "number"));
parser.addOption(dodThresholdOption);

Expand All @@ -84,6 +84,13 @@ int main(int argc, char *argv[])
QCoreApplication::translate("main", "number"));
parser.addOption(lengthVbiOption);

// Option to select the number of threads (-t)
QCommandLineOption threadsOption(QStringList() << "t" << "threads",
QCoreApplication::translate(
"main", "Specify the number of concurrent threads (default is the number of logical CPUs)"),
QCoreApplication::translate("main", "number"));
parser.addOption(threadsOption);

// Positional argument to specify input TBC files
parser.addPositionalArgument("input", QCoreApplication::translate("main", "Specify input TBC files (minimum of 3)"));

Expand All @@ -95,7 +102,8 @@ int main(int argc, char *argv[])

// Get the options from the parser
bool reverse = parser.isSet(setReverseOption);
bool lumaClip = parser.isSet(setLumaOption);
bool signalClip = true;
if (parser.isSet(setNoClipOption)) signalClip = false;

QVector<QString> inputFilenames;
QStringList positionalArguments = parser.positionalArguments();
Expand All @@ -116,13 +124,13 @@ int main(int argc, char *argv[])
return -1;
}

qint32 dodThreshold = 400;
qint32 dodThreshold = 7;
if (parser.isSet(dodThresholdOption)) {
dodThreshold = parser.value(dodThresholdOption).toInt();

if (dodThreshold < 100 || dodThreshold > 65435) {
if (dodThreshold < 1 || dodThreshold > 100) {
// Quit with error
qCritical("DOD threshold must be between 100 and 65435");
qCritical("DOD threshold must be between 1 and 100 percent");
return -1;
}
}
Expand All @@ -149,9 +157,21 @@ int main(int argc, char *argv[])
}
}

qint32 maxThreads = QThread::idealThreadCount();
if (parser.isSet(threadsOption)) {
maxThreads = parser.value(threadsOption).toInt();

if (maxThreads < 1) {
// Quit with error
qCritical("Specified number of threads must be greater than zero");
return -1;
}
}

// Process the TBC file
Diffdod diffdod;
if (!diffdod.process(inputFilenames, reverse, dodThreshold, lumaClip, vbiFrameStart, vbiFrameLength)) {
Sources sources(inputFilenames, reverse, dodThreshold, signalClip,
vbiFrameStart, vbiFrameLength, maxThreads);
if (!sources.process()) {
return 1;
}

Expand Down
Loading