filter/ffmpeg: use only one AVFrame
The two were never used at the same time, and merging them saves one allocation.
This commit is contained in:
@@ -50,25 +50,25 @@ FfmpegFilter::FilterPCM(ConstBuffer<void> src)
|
|||||||
{
|
{
|
||||||
/* submit source data into the FFmpeg audio buffer source */
|
/* submit source data into the FFmpeg audio buffer source */
|
||||||
|
|
||||||
in_frame.Unref();
|
frame.Unref();
|
||||||
in_frame->format = in_format;
|
frame->format = in_format;
|
||||||
in_frame->sample_rate = in_sample_rate;
|
frame->sample_rate = in_sample_rate;
|
||||||
in_frame->channels = in_channels;
|
frame->channels = in_channels;
|
||||||
in_frame->nb_samples = src.size / in_audio_frame_size;
|
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)
|
if (err < 0)
|
||||||
throw MakeFfmpegError(err, "av_buffersrc_write_frame() failed");
|
throw MakeFfmpegError(err, "av_buffersrc_write_frame() failed");
|
||||||
|
|
||||||
/* collect filtered data from the FFmpeg audio buffer sink */
|
/* 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 < 0) {
|
||||||
if (err == AVERROR(EAGAIN) || err == AVERROR_EOF)
|
if (err == AVERROR(EAGAIN) || err == AVERROR_EOF)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
@@ -79,5 +79,5 @@ FfmpegFilter::FilterPCM(ConstBuffer<void> src)
|
|||||||
/* 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 {out_frame.GetData(0), out_frame->nb_samples * GetOutAudioFormat().GetFrameSize()};
|
return {frame.GetData(0), frame->nb_samples * GetOutAudioFormat().GetFrameSize()};
|
||||||
}
|
}
|
||||||
|
@@ -30,7 +30,7 @@
|
|||||||
class FfmpegFilter final : public Filter {
|
class FfmpegFilter final : public Filter {
|
||||||
Ffmpeg::FilterGraph graph;
|
Ffmpeg::FilterGraph graph;
|
||||||
Ffmpeg::FilterContext buffer_src, buffer_sink;
|
Ffmpeg::FilterContext buffer_src, buffer_sink;
|
||||||
Ffmpeg::Frame in_frame, out_frame;
|
Ffmpeg::Frame frame;
|
||||||
|
|
||||||
const int in_format, in_sample_rate, in_channels;
|
const int in_format, in_sample_rate, in_channels;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user