2 #define _FFMPEG_RAII_H 1
4 // Some helpers to make RAII versions of FFmpeg objects.
5 // The cleanup functions don't interact all that well with unique_ptr,
6 // so things get a bit messy and verbose, but overall it's worth it to ensure
7 // we never leak things by accident in error paths.
9 // This does not cover any of the types that can actually be declared as
10 // a unique_ptr with no helper functions for deleter.
15 struct AVCodecContext;
16 struct AVCodecParameters;
18 struct AVFormatContext;
24 void avformat_close_input_unique(AVFormatContext *format_ctx);
26 typedef std::unique_ptr<AVFormatContext, decltype(avformat_close_input_unique)*>
27 AVFormatContextWithCloser;
29 AVFormatContextWithCloser avformat_open_input_unique(
30 const char *pathname, AVInputFormat *fmt, AVDictionary **options);
34 void avcodec_free_context_unique(AVCodecContext *codec_ctx);
36 typedef std::unique_ptr<AVCodecContext, decltype(avcodec_free_context_unique)*>
37 AVCodecContextWithDeleter;
39 AVCodecContextWithDeleter avcodec_alloc_context3_unique(const AVCodec *codec);
43 void avcodec_parameters_free_unique(AVCodecParameters *codec_par);
45 typedef std::unique_ptr<AVCodecParameters, decltype(avcodec_parameters_free_unique)*>
46 AVCodecParametersWithDeleter;
50 void av_frame_free_unique(AVFrame *frame);
52 typedef std::unique_ptr<AVFrame, decltype(av_frame_free_unique)*>
55 AVFrameWithDeleter av_frame_alloc_unique();
57 #endif // !defined(_FFMPEG_RAII_H)