Skip to content

Commit

Permalink
Add constants for the range of lines read.
Browse files Browse the repository at this point in the history
These are in VbiLineDecoder, since it makes the most use of them.

It's not necessary to subtract 1 from the field line again here -- the
1-based numbering is handled in SourceVideo, and subtracting 1 and
starting from 9 instead of 10 cancelled each other out.
  • Loading branch information
atsampson authored and Simon Inns committed Jan 9, 2020
1 parent f92f7bf commit 9c2e1c9
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 17 deletions.
4 changes: 2 additions & 2 deletions tools/ld-process-vbi/decoderpool.cpp
Original file line number Diff line number Diff line change
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
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

0 comments on commit 9c2e1c9

Please sign in to comment.