-// Some helpers to make RAII versions of FFmpeg objects.
-// The cleanup functions don't interact all that well with unique_ptr,
-// so things get a bit messy and verbose, but overall it's worth it to ensure
-// we never leak things by accident in error paths.
-
-namespace {
-
-void avformat_close_input_unique(AVFormatContext *format_ctx)
-{
- avformat_close_input(&format_ctx);
-}
-
-unique_ptr<AVFormatContext, decltype(avformat_close_input_unique)*>
-avformat_open_input_unique(const char *pathname,
- AVInputFormat *fmt, AVDictionary **options)
-{
- AVFormatContext *format_ctx = nullptr;
- if (avformat_open_input(&format_ctx, pathname, fmt, options) != 0) {
- format_ctx = nullptr;
- }
- return unique_ptr<AVFormatContext, decltype(avformat_close_input_unique)*>(
- format_ctx, avformat_close_input_unique);
-}
-
-void av_frame_free_unique(AVFrame *frame)
-{
- av_frame_free(&frame);
-}
-
-unique_ptr<AVFrame, decltype(av_frame_free_unique)*>
-av_frame_alloc_unique()
-{
- AVFrame *frame = av_frame_alloc();
- return unique_ptr<AVFrame, decltype(av_frame_free_unique)*>(
- frame, av_frame_free_unique);
-}
-
-void avcodec_free_context_unique(AVCodecContext *codec_ctx)
-{
- avcodec_free_context(&codec_ctx);
-}
-
-} // namespace
-