Skip to content

Commit

Permalink
filter/ffmpeg: implement method Flush()
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxKellermann committed Nov 2, 2024
1 parent 2c881c6 commit fa29693
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/filter/plugins/FfmpegFilter.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ FfmpegFilter::ReadOutput()
std::span<const std::byte>
FfmpegFilter::FilterPCM(std::span<const std::byte> src)
{
assert(!flushed);

/* submit source data into the FFmpeg audio buffer source */

frame.Unref();
Expand All @@ -78,3 +80,16 @@ FfmpegFilter::FilterPCM(std::span<const std::byte> src)

return ReadOutput();
}

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

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

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

0 comments on commit fa29693

Please sign in to comment.