Skip to content

Commit

Permalink
filter/ffmpeg: move code to ReadOutput()
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxKellermann committed Oct 30, 2024
1 parent 3d99f1d commit acb9ee9
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
26 changes: 16 additions & 10 deletions src/filter/plugins/FfmpegFilter.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,21 @@ FfmpegFilter::FfmpegFilter(const AudioFormat &in_audio_format,
#endif
}

inline std::span<const std::byte>
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<const std::byte>
FfmpegFilter::FilterPCM(std::span<const std::byte> src)
{
Expand All @@ -58,17 +73,8 @@ FfmpegFilter::FilterPCM(std::span<const std::byte> 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();
}
3 changes: 3 additions & 0 deletions src/filter/plugins/FfmpegFilter.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ public:

/* virtual methods from class Filter */
std::span<const std::byte> FilterPCM(std::span<const std::byte> src) override;

private:
std::span<const std::byte> ReadOutput();
};

#endif

0 comments on commit acb9ee9

Please sign in to comment.