diff options
author | Max Kellermann <max@duempel.org> | 2014-12-18 21:28:50 +0100 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2014-12-18 22:24:28 +0100 |
commit | a142f93dca24e9bdfafaa5030a245b29d6207679 (patch) | |
tree | de1e9d0bbbede5863227dbb3926e760373ebb2ef /src/decoder/plugins/FfmpegDecoderPlugin.cxx | |
parent | 2dfe2fb22c332e15f9a45d5a3ad548d6a602ceda (diff) | |
download | mpd-a142f93dca24e9bdfafaa5030a245b29d6207679.tar.gz mpd-a142f93dca24e9bdfafaa5030a245b29d6207679.tar.xz mpd-a142f93dca24e9bdfafaa5030a245b29d6207679.zip |
decoder/ffmpeg: move code to class FfmpegBuffer
Diffstat (limited to 'src/decoder/plugins/FfmpegDecoderPlugin.cxx')
-rw-r--r-- | src/decoder/plugins/FfmpegDecoderPlugin.cxx | 27 |
1 files changed, 10 insertions, 17 deletions
diff --git a/src/decoder/plugins/FfmpegDecoderPlugin.cxx b/src/decoder/plugins/FfmpegDecoderPlugin.cxx index 60c49800d..c0eadfb55 100644 --- a/src/decoder/plugins/FfmpegDecoderPlugin.cxx +++ b/src/decoder/plugins/FfmpegDecoderPlugin.cxx @@ -24,6 +24,7 @@ #include "FfmpegDecoderPlugin.hxx" #include "lib/ffmpeg/Domain.hxx" #include "lib/ffmpeg/LogError.hxx" +#include "lib/ffmpeg/Buffer.hxx" #include "../DecoderAPI.hxx" #include "FfmpegMetaData.hxx" #include "tag/TagBuilder.hxx" @@ -275,7 +276,7 @@ static int copy_interleave_frame(const AVCodecContext *codec_context, const AVFrame *frame, uint8_t **output_buffer, - uint8_t **global_buffer, int *global_buffer_size) + FfmpegBuffer &global_buffer) { int plane_size; const int data_size = @@ -288,17 +289,11 @@ copy_interleave_frame(const AVCodecContext *codec_context, if (av_sample_fmt_is_planar(codec_context->sample_fmt) && codec_context->channels > 1) { - if(*global_buffer_size < data_size) { - av_freep(global_buffer); + *output_buffer = global_buffer.GetT<uint8_t>(data_size); + if (*output_buffer == nullptr) + /* Not enough memory - shouldn't happen */ + return AVERROR(ENOMEM); - *global_buffer = (uint8_t*)av_malloc(data_size); - - if (!*global_buffer) - /* Not enough memory - shouldn't happen */ - return AVERROR(ENOMEM); - *global_buffer_size = data_size; - } - *output_buffer = *global_buffer; copy_interleave_frame2(*output_buffer, frame->extended_data, frame->nb_samples, codec_context->channels, @@ -316,7 +311,7 @@ ffmpeg_send_packet(Decoder &decoder, InputStream &is, AVCodecContext *codec_context, const AVStream *stream, AVFrame *frame, - uint8_t **buffer, int *buffer_size) + FfmpegBuffer &buffer) { if (packet->pts >= 0 && packet->pts != (int64_t)AV_NOPTS_VALUE) { auto start = start_time_fallback(*stream); @@ -346,7 +341,7 @@ ffmpeg_send_packet(Decoder &decoder, InputStream &is, audio_size = copy_interleave_frame(codec_context, frame, &output_buffer, - buffer, buffer_size); + buffer); if (audio_size < 0) { /* this must be a serious error, e.g. OOM */ @@ -667,8 +662,7 @@ ffmpeg_decode(Decoder &decoder, InputStream &input) return; } - uint8_t *interleaved_buffer = nullptr; - int interleaved_buffer_size = 0; + FfmpegBuffer interleaved_buffer; DecoderCommand cmd; do { @@ -686,7 +680,7 @@ ffmpeg_decode(Decoder &decoder, InputStream &input) &packet, codec_context, av_stream, frame, - &interleaved_buffer, &interleaved_buffer_size); + interleaved_buffer); else cmd = decoder_get_command(decoder); @@ -715,7 +709,6 @@ ffmpeg_decode(Decoder &decoder, InputStream &input) #else av_freep(&frame); #endif - av_freep(&interleaved_buffer); avcodec_close(codec_context); avformat_close_input(&format_context); |