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

Fix some compiler warnings #734

Merged
merged 3 commits into from
Jun 4, 2022
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
29 changes: 18 additions & 11 deletions ld-ldf-reader.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
{
Expand All @@ -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;
}
Expand Down Expand Up @@ -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);
}
Expand Down
13 changes: 7 additions & 6 deletions tools/ld-chroma-decoder/comb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@

#include "deemp.h"

#include <QScopedPointer>
#include <cmath>
#include <memory>
#include <utility>

// Definitions of static constexpr data members, for compatibility with
// pre-C++17 compilers
Expand Down Expand Up @@ -143,7 +144,7 @@ void Comb::decodeFrames(const QVector<SourceField> &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<FrameBuffer> nextFrameBuffer, currentFrameBuffer, previousFrameBuffer;
std::unique_ptr<FrameBuffer> nextFrameBuffer, currentFrameBuffer, previousFrameBuffer;
nextFrameBuffer.reset(new FrameBuffer(videoParameters, configuration));
currentFrameBuffer.reset(new FrameBuffer(videoParameters, configuration));
previousFrameBuffer.reset(new FrameBuffer(videoParameters, configuration));
Expand All @@ -158,10 +159,10 @@ void Comb::decodeFrames(const QVector<SourceField> &inputFields, qint32 startInd

// Rotate the buffers
{
QScopedPointer<FrameBuffer> 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
Expand Down
8 changes: 0 additions & 8 deletions tools/ld-chroma-decoder/encoder/palencoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -298,14 +298,6 @@ static constexpr auto uvFilter = makeFIRFilter(uvFilterCoeffs);
void PALEncoder::encodeLine(qint32 fieldNo, qint32 frameLine, const quint16 *rgbData, QVector<quint16> &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) {
Expand Down
4 changes: 2 additions & 2 deletions tools/ld-chroma-decoder/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@
#include <QDebug>
#include <QtGlobal>
#include <QCommandLineParser>
#include <QScopedPointer>
#include <QThread>
#include <fstream>
#include <memory>

#include "decoderpool.h"
#include "lddecodemetadata.h"
Expand Down Expand Up @@ -490,7 +490,7 @@ int main(int argc, char *argv[])
}

// Select the decoder
QScopedPointer<Decoder> decoder;
std::unique_ptr<Decoder> decoder;
if (decoderName == "pal2d") {
decoder.reset(new PalDecoder(palConfig));
} else if (decoderName == "transform2d") {
Expand Down
4 changes: 2 additions & 2 deletions tools/ld-chroma-decoder/palcolour.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@

#include <QtGlobal>
#include <QDebug>
#include <QScopedPointer>
#include <QVector>
#include <QtMath>
#include <memory>

#include "lddecodemetadata.h"

Expand Down Expand Up @@ -109,7 +109,7 @@ class PalColour
LdDecodeMetaData::VideoParameters videoParameters;

// Transform PAL filter
QScopedPointer<TransformPal> transformPal;
std::unique_ptr<TransformPal> transformPal;

// The subcarrier reference signal
double sine[MAX_WIDTH], cosine[MAX_WIDTH];
Expand Down