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

Miscellaneous tidying in ld-decode-vbi #403

Merged
merged 3 commits into from
Jan 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions tools/ld-process-vbi/closedcaption.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,6 @@

#include "closedcaption.h"

ClosedCaption::ClosedCaption(QObject *parent) : QObject(parent)
{

}

// Public method to read CEA-608 Closed Captioning data (NTSC only)
ClosedCaption::CcData ClosedCaption::getData(QByteArray lineData, LdDecodeMetaData::VideoParameters videoParameters)
{
Expand Down
8 changes: 1 addition & 7 deletions tools/ld-process-vbi/closedcaption.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,12 @@
#ifndef CLOSEDCAPTION_H
#define CLOSEDCAPTION_H

#include <QObject>

#include "sourcevideo.h"
#include "lddecodemetadata.h"

class ClosedCaption : public QObject
class ClosedCaption
{
Q_OBJECT

public:
explicit ClosedCaption(QObject *parent = nullptr);

struct CcData {
uchar byte0;
uchar byte1;
Expand Down
8 changes: 4 additions & 4 deletions tools/ld-process-vbi/decoderpool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
#include "decoderpool.h"

DecoderPool::DecoderPool(QString _inputFilename, QString _outputJsonFilename,
qint32 _maxThreads, LdDecodeMetaData &_ldDecodeMetaData, QObject *parent)
: QObject(parent), inputFilename(_inputFilename), outputJsonFilename(_outputJsonFilename),
qint32 _maxThreads, LdDecodeMetaData &_ldDecodeMetaData)
: inputFilename(_inputFilename), outputJsonFilename(_outputJsonFilename),
maxThreads(_maxThreads), ldDecodeMetaData(_ldDecodeMetaData)
{
}
Expand Down Expand Up @@ -116,8 +116,8 @@ bool DecoderPool::getInputField(qint32 &fieldNumber, QByteArray& fieldVideoData,
// Show what we are about to process
qDebug() << "DecoderPool::process(): Processing field number" << fieldNumber;

// Fetch the input data (we require only lines 10 to 21 from the field)
fieldVideoData = sourceVideo.getVideoField(fieldNumber, 10, 21);
// Fetch the input data
fieldVideoData = sourceVideo.getVideoField(fieldNumber, VbiLineDecoder::startFieldLine, VbiLineDecoder::endFieldLine);
fieldMetadata = ldDecodeMetaData.getField(fieldNumber);
videoParameters = ldDecodeMetaData.getVideoParameters();

Expand Down
7 changes: 2 additions & 5 deletions tools/ld-process-vbi/decoderpool.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
#ifndef DECODERPOOL_H
#define DECODERPOOL_H

#include <QObject>
#include <QAtomicInt>
#include <QByteArray>
#include <QElapsedTimer>
Expand All @@ -36,14 +35,12 @@
#include "lddecodemetadata.h"
#include "vbilinedecoder.h"

class DecoderPool : public QObject
class DecoderPool
{
Q_OBJECT
public:
// Public methods
explicit DecoderPool(QString _inputFilename, QString _outputJsonFilename,
qint32 _maxThreads, LdDecodeMetaData &_ldDecodeMetaData,
QObject *parent = nullptr);
qint32 _maxThreads, LdDecodeMetaData &_ldDecodeMetaData);
bool process();

// Member functions used by worker threads
Expand Down
5 changes: 0 additions & 5 deletions tools/ld-process-vbi/fmcode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,6 @@

#include "fmcode.h"

FmCode::FmCode(QObject *parent) : QObject(parent)
{

}

// Public method to read a 40-bit FM coded signal from a field line
FmCode::FmDecode FmCode::fmDecoder(QByteArray lineData, LdDecodeMetaData::VideoParameters videoParameters)
{
Expand Down
11 changes: 1 addition & 10 deletions tools/ld-process-vbi/fmcode.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,11 @@
#ifndef FMCODE_H
#define FMCODE_H

#include <QObject>

#include "sourcevideo.h"
#include "lddecodemetadata.h"

class FmCode : public QObject
class FmCode
{
Q_OBJECT
public:
struct FmDecode {
quint64 receiverClockSyncBits;
Expand All @@ -43,14 +40,8 @@ class FmCode : public QObject
quint64 trailingDataRecognitionBits;
};

explicit FmCode(QObject *parent = nullptr);

FmCode::FmDecode fmDecoder(QByteArray lineData, LdDecodeMetaData::VideoParameters videoParameters);

signals:

public slots:

private:
bool isEvenParity(quint64 data);
QVector<bool> getTransitionMap(QByteArray lineData, qint32 zcPoint);
Expand Down
34 changes: 19 additions & 15 deletions tools/ld-process-vbi/vbilinedecoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@
#include "vbilinedecoder.h"
#include "decoderpool.h"

// Definitions of static constexpr data members, for compatibility with
// pre-C++17 compilers
constexpr qint32 VbiLineDecoder::startFieldLine;
constexpr qint32 VbiLineDecoder::endFieldLine;

VbiLineDecoder::VbiLineDecoder(QAtomicInt& _abort, DecoderPool& _decoderPool, QObject *parent)
: QThread(parent), abort(_abort), decoderPool(_decoderPool)
{
Expand All @@ -41,6 +46,7 @@ void VbiLineDecoder::run()
LdDecodeMetaData::Field fieldMetadata;
LdDecodeMetaData::VideoParameters videoParameters;


while(!abort) {
// Get the next field to process from the input file
if (!decoderPool.getInputField(fieldNumber, sourceFieldData, fieldMetadata, videoParameters)) {
Expand All @@ -63,15 +69,13 @@ void VbiLineDecoder::run()
// Determine the 16-bit zero-crossing point
qint32 zcPoint = videoParameters.white16bIre - videoParameters.black16bIre;

// Get the VBI data from the field lines (we only read field lines 10-21, so the real field line number is -9)
// Get the VBI data from field lines 16-18
qDebug() << "VbiDecoder::process(): Getting field-lines for field" << fieldNumber;
fieldMetadata.vbi.vbiData[0] = manchesterDecoder(getActiveVideoLine(&sourceFieldData, 16 - 9, videoParameters), zcPoint, videoParameters);
fieldMetadata.vbi.vbiData[1] = manchesterDecoder(getActiveVideoLine(&sourceFieldData, 17 - 9, videoParameters), zcPoint, videoParameters);
fieldMetadata.vbi.vbiData[2] = manchesterDecoder(getActiveVideoLine(&sourceFieldData, 18 - 9, videoParameters), zcPoint, videoParameters);

if (fieldMetadata.vbi.vbiData[0] == 0) qDebug() << "VbiDecoder::process(): No VBI present on line 16";
if (fieldMetadata.vbi.vbiData[1] == 0) qDebug() << "VbiDecoder::process(): No VBI present on line 17";
if (fieldMetadata.vbi.vbiData[2] == 0) qDebug() << "VbiDecoder::process(): No VBI present on line 18";
for (qint32 i = 0; i < 3; i++) {
fieldMetadata.vbi.vbiData[i] = manchesterDecoder(getActiveVideoLine(&sourceFieldData, i + 16 - startFieldLine, videoParameters),
zcPoint, videoParameters);
if (fieldMetadata.vbi.vbiData[i] == 0) qDebug() << "VbiDecoder::process(): No VBI present on line" << i + 16;
}

// Show the VBI data as hexadecimal (for every 1000th field)
if (fieldNumber % 1000 == 0) {
Expand All @@ -80,14 +84,14 @@ void VbiLineDecoder::run()

// Process NTSC specific data if source type is NTSC
if (!videoParameters.isSourcePal) {
// Get the 40-bit FM coded data from the field lines
fmDecode = fmCode.fmDecoder(getActiveVideoLine(&sourceFieldData, 10 - 9, videoParameters), videoParameters);
// Get the 40-bit FM coded data from field line 10
fmDecode = fmCode.fmDecoder(getActiveVideoLine(&sourceFieldData, 10 - startFieldLine, videoParameters), videoParameters);

// Get the white flag from the field lines
isWhiteFlag = whiteFlag.getWhiteFlag(getActiveVideoLine(&sourceFieldData, 11 - 9, videoParameters), videoParameters);
// Get the white flag from field line 11
isWhiteFlag = whiteFlag.getWhiteFlag(getActiveVideoLine(&sourceFieldData, 11 - startFieldLine, videoParameters), videoParameters);

// Get the closed captioning from field line 21
ccData = closedCaption.getData(getActiveVideoLine(&sourceFieldData, 21 - 9, videoParameters), videoParameters);
ccData = closedCaption.getData(getActiveVideoLine(&sourceFieldData, 21 - startFieldLine, videoParameters), videoParameters);

// Update the metadata
if (fmDecode.receiverClockSyncBits != 0) {
Expand Down Expand Up @@ -129,12 +133,12 @@ QByteArray VbiLineDecoder::getActiveVideoLine(QByteArray *sourceField, qint32 fi
LdDecodeMetaData::VideoParameters videoParameters)
{
// Range-check the scan line
if (fieldLine > videoParameters.fieldHeight || fieldLine < 1) {
if (fieldLine < 0 || fieldLine >= videoParameters.fieldHeight) {
qWarning() << "Cannot generate field-line data, line number is out of bounds! Scan line =" << fieldLine;
return QByteArray();
}

qint32 startPointer = ((fieldLine - 1) * videoParameters.fieldWidth * 2) + (videoParameters.activeVideoStart * 2);
qint32 startPointer = (fieldLine * videoParameters.fieldWidth * 2) + (videoParameters.activeVideoStart * 2);
qint32 length = (videoParameters.activeVideoEnd - videoParameters.activeVideoStart) * 2;

return sourceField->mid(startPointer, length);
Expand Down
4 changes: 4 additions & 0 deletions tools/ld-process-vbi/vbilinedecoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ class VbiLineDecoder : public QThread {
public:
explicit VbiLineDecoder(QAtomicInt& _abort, DecoderPool& _decoderPool, QObject *parent = nullptr);

// The range of field lines needed from the input file (inclusive)
static constexpr qint32 startFieldLine = 10;
static constexpr qint32 endFieldLine = 21;

protected:
void run() override;

Expand Down
5 changes: 0 additions & 5 deletions tools/ld-process-vbi/whiteflag.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,6 @@

#include "whiteflag.h"

WhiteFlag::WhiteFlag(QObject *parent) : QObject(parent)
{

}

// Public method to read the white flag status from a field-line
bool WhiteFlag::getWhiteFlag(QByteArray lineData, LdDecodeMetaData::VideoParameters videoParameters)
{
Expand Down
11 changes: 1 addition & 10 deletions tools/ld-process-vbi/whiteflag.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,10 @@
#include "sourcevideo.h"
#include "lddecodemetadata.h"

#include <QObject>

class WhiteFlag : public QObject
class WhiteFlag
{
Q_OBJECT
public:
explicit WhiteFlag(QObject *parent = nullptr);

bool getWhiteFlag(QByteArray lineData, LdDecodeMetaData::VideoParameters videoParameters);

signals:

public slots:
};

#endif // WHITEFLAG_H
5 changes: 0 additions & 5 deletions tools/library/tbc/lddecodemetadata.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
#ifndef LDDECODEMETADATA_H
#define LDDECODEMETADATA_H

#include <QObject>
#include <QVector>
#include <QTemporaryFile>
#include <QDebug>
Expand Down Expand Up @@ -182,10 +181,6 @@ class LdDecodeMetaData
qint32 convertClvTimecodeToFrameNumber(LdDecodeMetaData::ClvTimecode clvTimeCode);
LdDecodeMetaData::ClvTimecode convertFrameNumberToClvTimecode(qint32 clvFrameNumber);

signals:

public slots:

private:
JsonWax json;
bool isFirstFieldFirst;
Expand Down
2 changes: 0 additions & 2 deletions tools/library/tbc/sourcevideo.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,12 @@
#ifndef SOURCEVIDEO_H
#define SOURCEVIDEO_H

#include <QObject>
#include <QFile>
#include <QCache>
#include <QDebug>

class SourceVideo
{

public:
SourceVideo();
~SourceVideo();
Expand Down
1 change: 0 additions & 1 deletion tools/library/tbc/vbidecoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
#ifndef VBIDECODER_H
#define VBIDECODER_H

#include <QObject>
#include <QDebug>

class VbiDecoder
Expand Down