diff --git a/src/filter/plugins/FfmpegFilter.cxx b/src/filter/plugins/FfmpegFilter.cxx index 816f56648..392fee22e 100644 --- a/src/filter/plugins/FfmpegFilter.cxx +++ b/src/filter/plugins/FfmpegFilter.cxx @@ -34,6 +34,21 @@ FfmpegFilter::FfmpegFilter(const AudioFormat &in_audio_format, #endif } +inline std::span +FfmpegFilter::ReadOutput() +{ + frame.Unref(); + + if (int err = av_buffersink_get_frame(&buffer_sink, frame.get()); err < 0) { + if (err == AVERROR(EAGAIN) || err == AVERROR_EOF) + return {}; + + throw MakeFfmpegError(err, "av_buffersink_get_frame() failed"); + } + + return Ffmpeg::InterleaveFrame(*frame, interleave_buffer); +} + std::span FfmpegFilter::FilterPCM(std::span src) { @@ -58,17 +73,8 @@ FfmpegFilter::FilterPCM(std::span src) /* collect filtered data from the FFmpeg audio buffer sink */ - frame.Unref(); - - if (int err = av_buffersink_get_frame(&buffer_sink, frame.get()); err < 0) { - if (err == AVERROR(EAGAIN) || err == AVERROR_EOF) - return {}; - - throw MakeFfmpegError(err, "av_buffersink_get_frame() failed"); - } - /* TODO: call av_buffersink_get_frame() repeatedly? Not possible with MPD's current Filter API */ - return Ffmpeg::InterleaveFrame(*frame, interleave_buffer); + return ReadOutput(); } diff --git a/src/filter/plugins/FfmpegFilter.hxx b/src/filter/plugins/FfmpegFilter.hxx index 09f1b77ed..7885850e6 100644 --- a/src/filter/plugins/FfmpegFilter.hxx +++ b/src/filter/plugins/FfmpegFilter.hxx @@ -46,6 +46,9 @@ public: /* virtual methods from class Filter */ std::span FilterPCM(std::span src) override; + +private: + std::span ReadOutput(); }; #endif