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;
22 typedef struct AVIOInterruptCB AVIOInterruptCB;
25 struct avformat_close_input_unique {
26 void operator() (AVFormatContext *format_ctx) const;
29 typedef std::unique_ptr<AVFormatContext, avformat_close_input_unique>
30 AVFormatContextWithCloser;
32 AVFormatContextWithCloser avformat_open_input_unique(
33 const char *pathname, AVInputFormat *fmt,
34 AVDictionary **options);
36 AVFormatContextWithCloser avformat_open_input_unique(
37 const char *pathname, AVInputFormat *fmt,
38 AVDictionary **options,
39 const AVIOInterruptCB &interrupt_cb);
43 struct avcodec_free_context_unique {
44 void operator() (AVCodecContext *ctx) const;
47 typedef std::unique_ptr<AVCodecContext, avcodec_free_context_unique>
48 AVCodecContextWithDeleter;
50 AVCodecContextWithDeleter avcodec_alloc_context3_unique(const AVCodec *codec);
54 struct avcodec_parameters_free_unique {
55 void operator() (AVCodecParameters *codec_par) const;
58 typedef std::unique_ptr<AVCodecParameters, avcodec_parameters_free_unique>
59 AVCodecParametersWithDeleter;
63 struct av_frame_free_unique {
64 void operator() (AVFrame *frame) const;
67 typedef std::unique_ptr<AVFrame, av_frame_free_unique>
70 AVFrameWithDeleter av_frame_alloc_unique();
73 struct sws_free_context_unique {
74 void operator() (SwsContext *context) const;
77 typedef std::unique_ptr<SwsContext, sws_free_context_unique>
78 SwsContextWithDeleter;
80 #endif // !defined(_FFMPEG_RAII_H)