From fa2969355054abbf1586684f712eda9468351118 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Wed, 30 Oct 2024 22:46:07 +0100 Subject: [PATCH] filter/ffmpeg: implement method Flush() --- src/filter/plugins/FfmpegFilter.cxx | 15 +++++++++++++++ src/filter/plugins/FfmpegFilter.hxx | 3 +++ 2 files changed, 18 insertions(+) diff --git a/src/filter/plugins/FfmpegFilter.cxx b/src/filter/plugins/FfmpegFilter.cxx index 392fee22e..afec2455b 100644 --- a/src/filter/plugins/FfmpegFilter.cxx +++ b/src/filter/plugins/FfmpegFilter.cxx @@ -52,6 +52,8 @@ FfmpegFilter::ReadOutput() std::span FfmpegFilter::FilterPCM(std::span src) { + assert(!flushed); + /* submit source data into the FFmpeg audio buffer source */ frame.Unref(); @@ -78,3 +80,16 @@ FfmpegFilter::FilterPCM(std::span src) return ReadOutput(); } + +std::span +FfmpegFilter::Flush() +{ + if (!flushed) { + if (int err = av_buffersrc_add_frame(&buffer_src, nullptr); err < 0) + throw MakeFfmpegError(err, "av_buffersrc_write_frame() failed"); + + flushed = true; + } + + return ReadOutput(); +} diff --git a/src/filter/plugins/FfmpegFilter.hxx b/src/filter/plugins/FfmpegFilter.hxx index 7885850e6..eeac8b76a 100644 --- a/src/filter/plugins/FfmpegFilter.hxx +++ b/src/filter/plugins/FfmpegFilter.hxx @@ -30,6 +30,8 @@ class FfmpegFilter final : public Filter { const size_t in_audio_frame_size; const size_t out_audio_frame_size; + bool flushed = false; + public: /** * @param _graph a checked and configured AVFilterGraph @@ -46,6 +48,7 @@ public: /* virtual methods from class Filter */ std::span FilterPCM(std::span src) override; + std::span Flush() override; private: std::span ReadOutput();