From 5c3afd020a2194ca96182c52a2cb1a70543871ee Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Thu, 18 Dec 2014 23:41:08 +0100 Subject: [PATCH] decoder/ffmpeg: copy_interleave_frame() returns ConstBuffer --- src/decoder/plugins/FfmpegDecoderPlugin.cxx | 24 ++++++++++----------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/decoder/plugins/FfmpegDecoderPlugin.cxx b/src/decoder/plugins/FfmpegDecoderPlugin.cxx index 7d2532371..d73c2ebea 100644 --- a/src/decoder/plugins/FfmpegDecoderPlugin.cxx +++ b/src/decoder/plugins/FfmpegDecoderPlugin.cxx @@ -34,6 +34,7 @@ #include "tag/MixRamp.hxx" #include "input/InputStream.hxx" #include "CheckAudioFormat.hxx" +#include "util/ConstBuffer.hxx" #include "util/Error.hxx" #include "util/Domain.hxx" #include "LogV.hxx" @@ -273,10 +274,9 @@ copy_interleave_frame2(uint8_t *dest, uint8_t **src, /** * Copy PCM data from a AVFrame to an interleaved buffer. */ -static size_t +static ConstBuffer copy_interleave_frame(const AVCodecContext &codec_context, const AVFrame &frame, - uint8_t **output_buffer, FfmpegBuffer &global_buffer, Error &error) { @@ -294,24 +294,26 @@ copy_interleave_frame(const AVCodecContext &codec_context, return 0; } + void *output_buffer; if (av_sample_fmt_is_planar(codec_context.sample_fmt) && codec_context.channels > 1) { - *output_buffer = global_buffer.GetT(data_size); - if (*output_buffer == nullptr) { + output_buffer = global_buffer.GetT(data_size); + if (output_buffer == nullptr) { /* Not enough memory - shouldn't happen */ error.SetErrno(ENOMEM); return 0; } - copy_interleave_frame2(*output_buffer, frame.extended_data, + copy_interleave_frame2((uint8_t *)output_buffer, + frame.extended_data, frame.nb_samples, codec_context.channels, av_get_bytes_per_sample(codec_context.sample_fmt)); } else { - *output_buffer = frame.extended_data[0]; + output_buffer = frame.extended_data[0]; } - return data_size; + return { output_buffer, (size_t)data_size }; } static DecoderCommand @@ -350,12 +352,10 @@ ffmpeg_send_packet(Decoder &decoder, InputStream &is, if (!got_frame || frame.nb_samples <= 0) continue; - uint8_t *output_buffer = nullptr; - size_t audio_size = + auto output_buffer = copy_interleave_frame(codec_context, frame, - &output_buffer, buffer, error); - if (audio_size == 0) { + if (output_buffer.IsNull()) { /* this must be a serious error, e.g. OOM */ LogError(error); @@ -363,7 +363,7 @@ ffmpeg_send_packet(Decoder &decoder, InputStream &is, } cmd = decoder_data(decoder, is, - output_buffer, audio_size, + output_buffer.data, output_buffer.size, codec_context.bit_rate / 1000); } return cmd;