summaryrefslogtreecommitdiff
path: root/src/decoder/plugins/FfmpegDecoderPlugin.cxx
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2016-07-29 09:08:14 +0200
committerMax Kellermann <max@duempel.org>2016-07-29 09:08:14 +0200
commita9edb4de28c2d34b051e84558e09fe3d497900e7 (patch)
tree5416fb22bc1f63c36294bee545f233c436203a73 /src/decoder/plugins/FfmpegDecoderPlugin.cxx
parenta076ddf38c83a83aa6bfe3ef0f7cf420445e9f58 (diff)
decoder/ffmpeg: use AtScopeExit() for safe cleanup
Diffstat (limited to 'src/decoder/plugins/FfmpegDecoderPlugin.cxx')
-rw-r--r--src/decoder/plugins/FfmpegDecoderPlugin.cxx39
1 files changed, 24 insertions, 15 deletions
diff --git a/src/decoder/plugins/FfmpegDecoderPlugin.cxx b/src/decoder/plugins/FfmpegDecoderPlugin.cxx
index b1cb32bed..9300d44f8 100644
--- a/src/decoder/plugins/FfmpegDecoderPlugin.cxx
+++ b/src/decoder/plugins/FfmpegDecoderPlugin.cxx
@@ -35,6 +35,7 @@
#include "tag/TagHandler.hxx"
#include "input/InputStream.hxx"
#include "CheckAudioFormat.hxx"
+#include "util/ScopeExit.hxx"
#include "util/ConstBuffer.hxx"
#include "util/Error.hxx"
#include "LogV.hxx"
@@ -473,6 +474,10 @@ FfmpegDecode(Decoder &decoder, InputStream &input,
return;
}
+ AtScopeExit(codec_context) {
+ avcodec_close(codec_context);
+ };
+
const SignedSongTime total_time =
FromFfmpegTimeChecked(av_stream.duration, av_stream.time_base);
@@ -489,6 +494,16 @@ FfmpegDecode(Decoder &decoder, InputStream &input,
return;
}
+ AtScopeExit(&frame) {
+#if LIBAVUTIL_VERSION_MAJOR >= 53
+ av_frame_free(&frame);
+#elif LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(54, 28, 0)
+ avcodec_free_frame(&frame);
+#else
+ av_free(frame);
+#endif
+ };
+
FfmpegBuffer interleaved_buffer;
uint64_t min_frame = 0;
@@ -537,16 +552,6 @@ FfmpegDecode(Decoder &decoder, InputStream &input,
av_free_packet(&packet);
#endif
}
-
-#if LIBAVUTIL_VERSION_MAJOR >= 53
- av_frame_free(&frame);
-#elif LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(54, 28, 0)
- avcodec_free_frame(&frame);
-#else
- av_free(frame);
-#endif
-
- avcodec_close(codec_context);
}
static void
@@ -572,9 +577,11 @@ ffmpeg_decode(Decoder &decoder, InputStream &input)
return;
}
- FfmpegDecode(decoder, input, *format_context);
+ AtScopeExit(&format_context) {
+ avformat_close_input(&format_context);
+ };
- avformat_close_input(&format_context);
+ FfmpegDecode(decoder, input, *format_context);
}
static bool
@@ -619,9 +626,11 @@ ffmpeg_scan_stream(InputStream &is,
if (f == nullptr)
return false;
- bool result = FfmpegScanStream(*f, *handler, handler_ctx);
- avformat_close_input(&f);
- return result;
+ AtScopeExit(&f) {
+ avformat_close_input(&f);
+ };
+
+ return FfmpegScanStream(*f, *handler, handler_ctx);
}
/**