From 2a97081a7806e1d14a733d087aa17c3dc631c20f Mon Sep 17 00:00:00 2001 From: Adam Sampson Date: Sat, 28 May 2022 14:08:34 +0100 Subject: [PATCH 1/3] Use std::unique_ptr rather than QScopedPtr. Qt 6.1 deprecates some of QScopedPtr's API, and recommends using unique_ptr instead. (Note that since this code is built as C++11 with Qt 5, we can't use C++14's std::make_unique yet, but that would be worthwhile in the future.) --- tools/ld-chroma-decoder/comb.cpp | 13 +++++++------ tools/ld-chroma-decoder/main.cpp | 4 ++-- tools/ld-chroma-decoder/palcolour.h | 4 ++-- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/tools/ld-chroma-decoder/comb.cpp b/tools/ld-chroma-decoder/comb.cpp index 61be2784a..aaf2c4918 100644 --- a/tools/ld-chroma-decoder/comb.cpp +++ b/tools/ld-chroma-decoder/comb.cpp @@ -31,8 +31,9 @@ #include "deemp.h" -#include #include +#include +#include // Definitions of static constexpr data members, for compatibility with // pre-C++17 compilers @@ -143,7 +144,7 @@ void Comb::decodeFrames(const QVector &inputFields, qint32 startInd // Buffers for the next, current and previous frame. // Because we only need three of these, we allocate them upfront then // rotate the pointers below. - QScopedPointer nextFrameBuffer, currentFrameBuffer, previousFrameBuffer; + std::unique_ptr nextFrameBuffer, currentFrameBuffer, previousFrameBuffer; nextFrameBuffer.reset(new FrameBuffer(videoParameters, configuration)); currentFrameBuffer.reset(new FrameBuffer(videoParameters, configuration)); previousFrameBuffer.reset(new FrameBuffer(videoParameters, configuration)); @@ -158,10 +159,10 @@ void Comb::decodeFrames(const QVector &inputFields, qint32 startInd // Rotate the buffers { - QScopedPointer recycle(previousFrameBuffer.take()); - previousFrameBuffer.reset(currentFrameBuffer.take()); - currentFrameBuffer.reset(nextFrameBuffer.take()); - nextFrameBuffer.reset(recycle.take()); + auto recycle = std::move(previousFrameBuffer); + previousFrameBuffer = std::move(currentFrameBuffer); + currentFrameBuffer = std::move(nextFrameBuffer); + nextFrameBuffer = std::move(recycle); } // If there's another input field, bring it into nextFrameBuffer diff --git a/tools/ld-chroma-decoder/main.cpp b/tools/ld-chroma-decoder/main.cpp index a5886319a..94b2d71c8 100644 --- a/tools/ld-chroma-decoder/main.cpp +++ b/tools/ld-chroma-decoder/main.cpp @@ -29,9 +29,9 @@ #include #include #include -#include #include #include +#include #include "decoderpool.h" #include "lddecodemetadata.h" @@ -490,7 +490,7 @@ int main(int argc, char *argv[]) } // Select the decoder - QScopedPointer decoder; + std::unique_ptr decoder; if (decoderName == "pal2d") { decoder.reset(new PalDecoder(palConfig)); } else if (decoderName == "transform2d") { diff --git a/tools/ld-chroma-decoder/palcolour.h b/tools/ld-chroma-decoder/palcolour.h index b1912258e..956d53aa0 100644 --- a/tools/ld-chroma-decoder/palcolour.h +++ b/tools/ld-chroma-decoder/palcolour.h @@ -28,9 +28,9 @@ #include #include -#include #include #include +#include #include "lddecodemetadata.h" @@ -109,7 +109,7 @@ class PalColour LdDecodeMetaData::VideoParameters videoParameters; // Transform PAL filter - QScopedPointer transformPal; + std::unique_ptr transformPal; // The subcarrier reference signal double sine[MAX_WIDTH], cosine[MAX_WIDTH]; From 293a963df1a273cbd77e993801684e35a13e3099 Mon Sep 17 00:00:00 2001 From: Adam Sampson Date: Sat, 28 May 2022 14:36:17 +0100 Subject: [PATCH 2/3] Correct offset logic in ld-ldf-reader. GCC warned about an signed/unsigned comparison here. After testing, this revealed that the logic to work out how much of a frame to skip when seeking wasn't correct, meaning it always output the whole frame (although fortunately this doesn't make much difference for ld-decode/ld-cut's purposes!). Rewrite the code to avoid the signed/unsigned confusion and skip the right amount of data. --- ld-ldf-reader.c | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/ld-ldf-reader.c b/ld-ldf-reader.c index a912e69f9..e3bc4b453 100644 --- a/ld-ldf-reader.c +++ b/ld-ldf-reader.c @@ -2,7 +2,7 @@ * Decode 16-bit samples from a compressed file using ffmpeg's libraries. * * Copyright (c) 2019-2021 Chad Page - * Copyright (c) 2020-2021 Adam Sampson + * Copyright (c) 2020-2022 Adam Sampson * * Adapted from ffmpeg's doc/examples/demuxing_decoding.c, which is: * Copyright (c) 2012 Stefano Sabatini @@ -44,7 +44,7 @@ static int audio_stream_idx = -1; static AVFrame *frame = NULL; static AVPacket *pkt = NULL; -static uint64_t seekto = 0; +static int64_t seekto = 0; static int decode_packet(AVCodecContext *dec, const AVPacket *pkt) { @@ -70,18 +70,25 @@ static int decode_packet(AVCodecContext *dec, const AVPacket *pkt) return ret; } - // If we haven't reached the start position, don't output anything - if ((frame->pts + frame->nb_samples) < seekto) { + // If we won't reach the start position during this frame, don't output anything + if ((frame->pts + frame->nb_samples) <= seekto) { av_frame_unref(frame); continue; } - // Write the raw audio data samples to stdout, skipping any data that's - // before the start position - int64_t offset = FFMIN((seekto - frame->pts), 0); - size_t unpadded_linesize = frame->nb_samples * av_get_bytes_per_sample(frame->format); - size_t rv = write(1, frame->extended_data[0] + (offset * av_get_bytes_per_sample(frame->format)), unpadded_linesize); - if (rv != unpadded_linesize) { + // The start position may be in the middle of a frame -- work out how + // much data to skip at the start + size_t bytes_per_sample = av_get_bytes_per_sample(frame->format); + int64_t offset = (seekto - frame->pts) * bytes_per_sample; + if (offset < 0) { + // None -- output the whole frame + offset = 0; + } + size_t length = (frame->nb_samples * bytes_per_sample) - offset; + + // Write the raw audio data samples to stdout + size_t rv = write(1, frame->extended_data[0] + offset, length); + if (rv != length) { fprintf(stderr, "write error %ld", offset); return -1; } @@ -215,7 +222,7 @@ int main (int argc, char **argv) } if (seekto) { - uint64_t seeksec = seekto / audio_dec_ctx->sample_rate; + int64_t seeksec = seekto / audio_dec_ctx->sample_rate; avformat_seek_file(fmt_ctx, -1, (seeksec - 1) * 1000000, seeksec * 1000000, seeksec * 1000000, AVSEEK_FLAG_ANY); } From 6bdd26bbdf53b37dc31c4902e9aa803fdc9b2c61 Mon Sep 17 00:00:00 2001 From: Adam Sampson Date: Sat, 28 May 2022 14:45:53 +0100 Subject: [PATCH 3/3] Remove dead code in PALEncoder. lineLen wasn't being used, and isn't needed (checked by comparison with BBC subcarrier-locked samples). --- tools/ld-chroma-decoder/encoder/palencoder.cpp | 8 -------- 1 file changed, 8 deletions(-) diff --git a/tools/ld-chroma-decoder/encoder/palencoder.cpp b/tools/ld-chroma-decoder/encoder/palencoder.cpp index 70b02aab5..d0de988cc 100644 --- a/tools/ld-chroma-decoder/encoder/palencoder.cpp +++ b/tools/ld-chroma-decoder/encoder/palencoder.cpp @@ -298,14 +298,6 @@ static constexpr auto uvFilter = makeFIRFilter(uvFilterCoeffs); void PALEncoder::encodeLine(qint32 fieldNo, qint32 frameLine, const quint16 *rgbData, QVector &outputLine) { // Resize the output line and fill with black - qint32 lineLen = videoParameters.fieldWidth; - if (!videoParameters.isSubcarrierLocked) { - // Line-locked -- all lines are the same length - } else if (frameLine == 625) { - lineLen -= 4; - } else if (frameLine == 623 || frameLine == 624) { - lineLen += 2; - } outputLine.resize(videoParameters.fieldWidth); outputLine.fill(videoParameters.black16bIre); if (frameLine == 625) {