Skip to content

Commit

Permalink
Merge pull request #543 from happycube/issue-541
Browse files Browse the repository at this point in the history
Fix for issue #541
  • Loading branch information
Simon Inns committed Aug 29, 2020
2 parents f081df4 + f5c89f0 commit 105f483
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 23 deletions.
53 changes: 44 additions & 9 deletions tools/ld-dropout-correct/correctorpool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
ld-dropout-correct - Dropout correction for ld-decode
Copyright (C) 2018-2020 Simon Inns
Copyright (C) 2019-2020 Adam Sampson
This file is part of ld-decode-tools.
Expand All @@ -24,8 +25,6 @@

#include "correctorpool.h"

#include <cstdio>

CorrectorPool::CorrectorPool(QString _outputFilename, QString _outputJsonFilename,
qint32 _maxThreads, QVector<LdDecodeMetaData *> &_ldDecodeMetaData, QVector<SourceVideo *> &_sourceVideos,
bool _reverse, bool _intraField, bool _overCorrect, QObject *parent)
Expand Down Expand Up @@ -83,6 +82,11 @@ bool CorrectorPool::process()
// Show some information for the user
qInfo() << "Using" << maxThreads << "threads to process" << ldDecodeMetaData[0]->getNumberOfFrames() << "frames";

// Initialise reporting
sameSourceConcealmentTotal = 0;
multiSourceConcealmentTotal = 0;
multiSourceCorrectionTotal = 0;

// Initialise processing state
inputFrameNumber = 1;
outputFrameNumber = 1;
Expand Down Expand Up @@ -246,7 +250,8 @@ bool CorrectorPool::getInputFrame(qint32& frameNumber,
bool CorrectorPool::setOutputFrame(qint32 frameNumber,
SourceVideo::Data firstTargetFieldData, SourceVideo::Data secondTargetFieldData,
qint32 firstFieldSeqNo, qint32 secondFieldSeqNo,
qint32 sameSourceReplacement, qint32 multiSourceReplacement, qint32 totalReplacementDistance)
qint32 sameSourceConcealment, qint32 multiSourceConcealment,
qint32 multiSourceCorrection, qint32 totalReplacementDistance)
{
QMutexLocker locker(&outputMutex);

Expand All @@ -258,8 +263,9 @@ bool CorrectorPool::setOutputFrame(qint32 frameNumber,
pendingFrame.secondFieldSeqNo = secondFieldSeqNo;

// Get statistics
pendingFrame.sameSourceReplacement = sameSourceReplacement;
pendingFrame.multiSourceReplacement = multiSourceReplacement;
pendingFrame.sameSourceConcealment = sameSourceConcealment;
pendingFrame.multiSourceConcealment = multiSourceConcealment;
pendingFrame.multiSourceCorrection = multiSourceCorrection;
pendingFrame.totalReplacementDistance = totalReplacementDistance;

pendingOutputFrames[frameNumber] = pendingFrame;
Expand Down Expand Up @@ -290,12 +296,25 @@ bool CorrectorPool::setOutputFrame(qint32 frameNumber,

// Show debug
qreal avgReplacementDistance = 0;
if (outputFrame.sameSourceReplacement + outputFrame.multiSourceReplacement > 0) {
if (outputFrame.sameSourceConcealment + outputFrame.multiSourceConcealment + outputFrame.multiSourceCorrection > 0) {
avgReplacementDistance = static_cast<qreal>(outputFrame.totalReplacementDistance) /
static_cast<qreal>(outputFrame.sameSourceReplacement + outputFrame.multiSourceReplacement);
static_cast<qreal>(outputFrame.sameSourceConcealment + outputFrame.multiSourceConcealment +
outputFrame.multiSourceCorrection);
qDebug().nospace() << "Processed frame " << outputFrameNumber << " with " << outputFrame.sameSourceConcealment +
outputFrame.multiSourceConcealment +
outputFrame.multiSourceCorrection << " changes (" <<
outputFrame.sameSourceConcealment << ", " <<
outputFrame.multiSourceConcealment << ", " <<
outputFrame.multiSourceCorrection << " - avg dist. " <<
avgReplacementDistance << ")";
} else {
qDebug() << "Processed frame" << outputFrameNumber << "- no dropouts";
}
qDebug() << "Processed frame" << outputFrameNumber << "- Replacements" << outputFrame.sameSourceReplacement << "same source," <<
outputFrame.multiSourceReplacement << "multi-source - Average replacement distance of" << avgReplacementDistance;

// Tally the statistics
multiSourceConcealmentTotal += outputFrame.multiSourceConcealment;
multiSourceCorrectionTotal += outputFrame.multiSourceCorrection;
sameSourceConcealmentTotal += outputFrame.sameSourceConcealment;

if (outputFrameNumber % 100 == 0) {
qInfo() << "Processed and written frame" << outputFrameNumber;
Expand Down Expand Up @@ -438,3 +457,19 @@ bool CorrectorPool::writeOutputField(const SourceVideo::Data &fieldData)
{
return targetVideo.write(reinterpret_cast<const char *>(fieldData.data()), 2 * fieldData.size());
}

// Getters for reporting
qint32 CorrectorPool::getSameSourceConcealmentTotal()
{
return sameSourceConcealmentTotal;
}

qint32 CorrectorPool::getMultiSourceConcealmentTotal()
{
return multiSourceConcealmentTotal;
}

qint32 CorrectorPool::getMultiSourceCorrectionTotal()
{
return multiSourceCorrectionTotal;
}
18 changes: 15 additions & 3 deletions tools/ld-dropout-correct/correctorpool.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
ld-dropout-correct - Dropout correction for ld-decode
Copyright (C) 2018-2020 Simon Inns
Copyright (C) 2019-2020 Adam Sampson
This file is part of ld-decode-tools.
Expand Down Expand Up @@ -55,7 +56,12 @@ class CorrectorPool : public QObject
bool setOutputFrame(qint32 frameNumber,
SourceVideo::Data firstTargetFieldData, SourceVideo::Data secondTargetFieldData,
qint32 firstFieldSeqNo, qint32 secondFieldSeqNo,
qint32 sameSourceReplacement, qint32 multiSourceReplacement, qint32 totalReplacementDistance);
qint32 sameSourceReplacement, qint32 multiSourceReplacement, qint32 multiSourceCorrection, qint32 totalReplacementDistance);

// Reporting methods
qint32 getSameSourceConcealmentTotal();
qint32 getMultiSourceConcealmentTotal();
qint32 getMultiSourceCorrectionTotal();

private:
QString outputFilename;
Expand Down Expand Up @@ -87,8 +93,9 @@ class CorrectorPool : public QObject
qint32 secondFieldSeqNo;

// Statistics
qint32 sameSourceReplacement;
qint32 multiSourceReplacement;
qint32 sameSourceConcealment;
qint32 multiSourceConcealment;
qint32 multiSourceCorrection;
qint32 totalReplacementDistance;
};

Expand All @@ -101,6 +108,11 @@ class CorrectorPool : public QObject
QVector<qint32> sourceMinimumVbiFrame;
QVector<qint32> sourceMaximumVbiFrame;

// Reporting information
qint32 sameSourceConcealmentTotal;
qint32 multiSourceConcealmentTotal;
qint32 multiSourceCorrectionTotal;

bool setMinAndMaxVbiFrames();
qint32 convertSequentialFrameNumberToVbi(qint32 sequentialFrameNumber, qint32 sourceNumber);
qint32 convertVbiFrameNumberToSequential(qint32 vbiFrameNumber, qint32 sourceNumber);
Expand Down
19 changes: 12 additions & 7 deletions tools/ld-dropout-correct/dropoutcorrect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
ld-dropout-correct - Dropout correction for ld-decode
Copyright (C) 2018-2020 Simon Inns
Copyright (C) 2019 Adam Sampson
Copyright (C) 2019-2020 Adam Sampson
This file is part of ld-decode-tools.
Expand Down Expand Up @@ -60,8 +60,9 @@ void DropOutCorrect::run()
}

// Reset statistics
statistics.sameSourceReplacement = 0;
statistics.multiSourceReplacement = 0;
statistics.sameSourceConcealment = 0;
statistics.multiSourceConcealment = 0;
statistics.multiSourceCorrection = 0;
statistics.totalReplacementDistance = 0;

qint32 totalAvailableSources = firstFieldSeqNo.size();
Expand Down Expand Up @@ -113,7 +114,7 @@ void DropOutCorrect::run()

// Return the processed fields
correctorPool.setOutputFrame(frameNumber, firstFieldData[0], secondFieldData[0], firstFieldSeqNo[0], secondFieldSeqNo[0],
statistics.sameSourceReplacement, statistics.multiSourceReplacement, statistics.totalReplacementDistance);
statistics.sameSourceConcealment, statistics.multiSourceConcealment, statistics.multiSourceCorrection ,statistics.totalReplacementDistance);
}
}

Expand Down Expand Up @@ -514,8 +515,12 @@ void DropOutCorrect::correctDropOut(const DropOutLocation &dropOut,
}
}

// Statistics
if (replacement.sourceNumber == 0) statistics.sameSourceReplacement++;
else statistics.multiSourceReplacement++;
// Update statistics
if (replacement.sourceNumber == 0) statistics.sameSourceConcealment++;
else {
if (replacement.distance == 0) statistics.multiSourceCorrection++;
else statistics.multiSourceConcealment++;
}
statistics.totalReplacementDistance += replacement.distance;
}

6 changes: 4 additions & 2 deletions tools/ld-dropout-correct/dropoutcorrect.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
ld-dropout-correct - Dropout correction for ld-decode
Copyright (C) 2018-2020 Simon Inns
Copyright (C) 2019-2020 Adam Sampson
This file is part of ld-decode-tools.
Expand Down Expand Up @@ -74,8 +75,9 @@ class DropOutCorrect : public QThread

// Statistics
struct Statistics {
qint32 sameSourceReplacement;
qint32 multiSourceReplacement;
qint32 sameSourceConcealment;
qint32 multiSourceConcealment;
qint32 multiSourceCorrection;
qint32 totalReplacementDistance;
};

Expand Down
23 changes: 21 additions & 2 deletions tools/ld-dropout-correct/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
ld-dropout-correct - Dropout correction for ld-decode
Copyright (C) 2018-2020 Simon Inns
Copyright (C) 2019-2020 Adam Sampson
This file is part of ld-decode-tools.
Expand Down Expand Up @@ -77,7 +78,7 @@ int main(int argc, char *argv[])

// Option to select over correct mode (-o)
QCommandLineOption setOverCorrectOption(QStringList() << "o" << "overcorrect",
QCoreApplication::translate("main", "Over correct mode (use on heavily damaged sources)"));
QCoreApplication::translate("main", "Over correct mode (use on heavily damaged single sources)"));
parser.addOption(setOverCorrectOption);

// Force intra-field correction only
Expand Down Expand Up @@ -293,7 +294,7 @@ int main(int argc, char *argv[])
}

if (!videoParameters.isMapped) {
qInfo() << "Source video" << i << "has not been mapped - run ld-discmap on all source video and try again";
qInfo() << "Source video" << i << "has not been mapped - run ld-discmap on all source videos and try again";
qInfo() << "Multi-source dropout correction relies on accurate VBI frame numbering to match source frames together";
return 1;
}
Expand All @@ -308,6 +309,24 @@ int main(int argc, char *argv[])
reverse, intraField, overCorrect);
if (!correctorPool.process()) result = 1;

// Report on the result of the correction process
if (totalNumberOfInputFiles > 1) {
// Multisource correction report
qInfo() << "Multi-source correction from" << totalNumberOfInputFiles << "sources:";
qInfo() << " Corrections (same source):" << correctorPool.getSameSourceConcealmentTotal();
qInfo() << " Concealments (multi-source):" << correctorPool.getMultiSourceConcealmentTotal();
qInfo() << " Corrections (multi-source):" << correctorPool.getMultiSourceCorrectionTotal();
qInfo() << " Total:" << correctorPool.getSameSourceConcealmentTotal() +
correctorPool.getMultiSourceConcealmentTotal() +
correctorPool.getMultiSourceCorrectionTotal();
} else {
// Single source correction report
qInfo() << "Single source correction:";
qInfo() << " Total concealments:" << correctorPool.getSameSourceConcealmentTotal() +
correctorPool.getMultiSourceConcealmentTotal() +
correctorPool.getMultiSourceCorrectionTotal();
}

// Close open source video files
for (qint32 i = 0; i < totalNumberOfInputFiles; i++) sourceVideos[i]->close();

Expand Down

0 comments on commit 105f483

Please sign in to comment.