diff options
author | Max Kellermann <max@musicpd.org> | 2019-03-24 22:29:57 +0100 |
---|---|---|
committer | Max Kellermann <max@musicpd.org> | 2019-03-24 22:29:57 +0100 |
commit | 61120d205921cf52ef2e44753f4c8786086b0fbe (patch) | |
tree | 895442d4e3e0d3c5f799c89f58b83fdb75640e72 | |
parent | cc1822810fc3251e373c2a8690afde1de3633109 (diff) |
filter/ffmpeg: use only one AVFrame
The two were never used at the same time, and merging them saves one allocation.
-rw-r--r-- | src/filter/plugins/FfmpegFilter.cxx | 22 | ||||
-rw-r--r-- | src/filter/plugins/FfmpegFilter.hxx | 2 |
2 files changed, 12 insertions, 12 deletions
diff --git a/src/filter/plugins/FfmpegFilter.cxx b/src/filter/plugins/FfmpegFilter.cxx index d188da0fc..fa4f9cc91 100644 --- a/src/filter/plugins/FfmpegFilter.cxx +++ b/src/filter/plugins/FfmpegFilter.cxx @@ -50,25 +50,25 @@ FfmpegFilter::FilterPCM(ConstBuffer<void> src) { /* submit source data into the FFmpeg audio buffer source */ - in_frame.Unref(); - in_frame->format = in_format; - in_frame->sample_rate = in_sample_rate; - in_frame->channels = in_channels; - in_frame->nb_samples = src.size / in_audio_frame_size; + frame.Unref(); + frame->format = in_format; + frame->sample_rate = in_sample_rate; + frame->channels = in_channels; + frame->nb_samples = src.size / in_audio_frame_size; - in_frame.GetBuffer(); + frame.GetBuffer(); - memcpy(in_frame.GetData(0), src.data, src.size); + memcpy(frame.GetData(0), src.data, src.size); - int err = av_buffersrc_add_frame(buffer_src.get(), in_frame.get()); + int err = av_buffersrc_add_frame(buffer_src.get(), frame.get()); if (err < 0) throw MakeFfmpegError(err, "av_buffersrc_write_frame() failed"); /* collect filtered data from the FFmpeg audio buffer sink */ - out_frame.Unref(); + frame.Unref(); - err = av_buffersink_get_frame(buffer_sink.get(), out_frame.get()); + err = av_buffersink_get_frame(buffer_sink.get(), frame.get()); if (err < 0) { if (err == AVERROR(EAGAIN) || err == AVERROR_EOF) return nullptr; @@ -79,5 +79,5 @@ FfmpegFilter::FilterPCM(ConstBuffer<void> src) /* TODO: call av_buffersink_get_frame() repeatedly? Not possible with MPD's current Filter API */ - return {out_frame.GetData(0), out_frame->nb_samples * GetOutAudioFormat().GetFrameSize()}; + return {frame.GetData(0), frame->nb_samples * GetOutAudioFormat().GetFrameSize()}; } diff --git a/src/filter/plugins/FfmpegFilter.hxx b/src/filter/plugins/FfmpegFilter.hxx index 0c6612a8b..9a7ffb48a 100644 --- a/src/filter/plugins/FfmpegFilter.hxx +++ b/src/filter/plugins/FfmpegFilter.hxx @@ -30,7 +30,7 @@ class FfmpegFilter final : public Filter { Ffmpeg::FilterGraph graph; Ffmpeg::FilterContext buffer_src, buffer_sink; - Ffmpeg::Frame in_frame, out_frame; + Ffmpeg::Frame frame; const int in_format, in_sample_rate, in_channels; |