filter/ffmpeg: move code to ReadOutput()

This commit is contained in:
Max Kellermann 2024-10-30 22:48:34 +01:00
parent 3d99f1d8a6
commit acb9ee9792
2 changed files with 19 additions and 10 deletions

View File

@ -34,6 +34,21 @@ FfmpegFilter::FfmpegFilter(const AudioFormat &in_audio_format,
#endif #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> std::span<const std::byte>
FfmpegFilter::FilterPCM(std::span<const std::byte> src) FfmpegFilter::FilterPCM(std::span<const std::byte> src)
{ {
@ -58,17 +73,8 @@ FfmpegFilter::FilterPCM(std::span<const std::byte> src)
/* collect filtered data from the FFmpeg audio buffer sink */ /* 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 /* TODO: call av_buffersink_get_frame() repeatedly? Not
possible with MPD's current Filter API */ possible with MPD's current Filter API */
return Ffmpeg::InterleaveFrame(*frame, interleave_buffer); return ReadOutput();
} }

View File

@ -46,6 +46,9 @@ public:
/* virtual methods from class Filter */ /* virtual methods from class Filter */
std::span<const std::byte> FilterPCM(std::span<const std::byte> src) override; std::span<const std::byte> FilterPCM(std::span<const std::byte> src) override;
private:
std::span<const std::byte> ReadOutput();
}; };
#endif #endif