summaryrefslogtreecommitdiff
path: root/src/decoder
diff options
context:
space:
mode:
authorMax Kellermann <max@musicpd.org>2019-03-13 09:41:52 +0100
committerMax Kellermann <max@musicpd.org>2019-03-13 09:41:52 +0100
commit0009d53b3f24068604a6c323243427c0b5a3d2b4 (patch)
tree8a9abc7d69d0829262cca0c1fba00871e7b4799b /src/decoder
parent05f7a6d1ffc1be13be5e7e8dec2aed33556b64f0 (diff)
decoder/ffmpeg: add AVCodecContext wrapper class
Diffstat (limited to 'src/decoder')
-rw-r--r--src/decoder/plugins/FfmpegDecoderPlugin.cxx23
1 files changed, 5 insertions, 18 deletions
diff --git a/src/decoder/plugins/FfmpegDecoderPlugin.cxx b/src/decoder/plugins/FfmpegDecoderPlugin.cxx
index 109e86b97..41ed4bb16 100644
--- a/src/decoder/plugins/FfmpegDecoderPlugin.cxx
+++ b/src/decoder/plugins/FfmpegDecoderPlugin.cxx
@@ -29,6 +29,7 @@
#include "lib/ffmpeg/Buffer.hxx"
#include "lib/ffmpeg/Frame.hxx"
#include "lib/ffmpeg/Format.hxx"
+#include "lib/ffmpeg/Codec.hxx"
#include "../DecoderAPI.hxx"
#include "FfmpegMetaData.hxx"
#include "FfmpegIo.hxx"
@@ -524,23 +525,9 @@ FfmpegDecode(DecoderClient &client, InputStream &input,
return;
}
- AVCodecContext *codec_context = avcodec_alloc_context3(codec);
- if (codec_context == nullptr) {
- LogError(ffmpeg_domain, "avcodec_alloc_context3() failed");
- return;
- }
-
- AtScopeExit(&codec_context) {
- avcodec_free_context(&codec_context);
- };
-
- avcodec_parameters_to_context(codec_context, av_stream.codecpar);
-
- const int open_result = avcodec_open2(codec_context, codec, nullptr);
- if (open_result < 0) {
- LogError(ffmpeg_domain, "Could not open codec");
- return;
- }
+ Ffmpeg::CodecContext codec_context(*codec);
+ codec_context.FillFromParameters(*av_stream.codecpar);
+ codec_context.Open(*codec, nullptr);
const SampleFormat sample_format =
ffmpeg_sample_format(codec_context->sample_fmt);
@@ -583,7 +570,7 @@ FfmpegDecode(DecoderClient &client, InputStream &input,
AVSEEK_FLAG_ANY|AVSEEK_FLAG_BACKWARD) < 0)
client.SeekError();
else {
- avcodec_flush_buffers(codec_context);
+ codec_context.FlushBuffers();
min_frame = client.GetSeekFrame();
client.CommandFinished();
}