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;
23 typedef struct AVIOInterruptCB AVIOInterruptCB;
26 struct avformat_close_input_unique {
27 void operator() (AVFormatContext *format_ctx) const;
30 typedef std::unique_ptr<AVFormatContext, avformat_close_input_unique>
31 AVFormatContextWithCloser;
33 AVFormatContextWithCloser avformat_open_input_unique(
34 const char *pathname, const AVInputFormat *fmt,
35 AVDictionary **options);
37 AVFormatContextWithCloser avformat_open_input_unique(
38 const char *pathname, const AVInputFormat *fmt,
39 AVDictionary **options,
40 const AVIOInterruptCB &interrupt_cb);
42 AVFormatContextWithCloser avformat_open_input_unique(
43 int (*read_packet)(void *opaque, uint8_t *buf, int buf_size),
44 void *opaque, const AVInputFormat *fmt, AVDictionary **options,
45 const AVIOInterruptCB &interrupt_cb);
49 struct avcodec_free_context_unique {
50 void operator() (AVCodecContext *ctx) const;
53 typedef std::unique_ptr<AVCodecContext, avcodec_free_context_unique>
54 AVCodecContextWithDeleter;
56 AVCodecContextWithDeleter avcodec_alloc_context3_unique(const AVCodec *codec);
60 struct avcodec_parameters_free_unique {
61 void operator() (AVCodecParameters *codec_par) const;
64 typedef std::unique_ptr<AVCodecParameters, avcodec_parameters_free_unique>
65 AVCodecParametersWithDeleter;
69 struct av_frame_free_unique {
70 void operator() (AVFrame *frame) const;
73 typedef std::unique_ptr<AVFrame, av_frame_free_unique>
76 AVFrameWithDeleter av_frame_alloc_unique();
79 // Not really unique from FFmpeg's point of view, but it is from ours
80 struct av_packet_free_unique {
81 void operator() (AVPacket *packet) const;
84 typedef std::unique_ptr<AVPacket, av_packet_free_unique>
87 AVPacketWithDeleter av_packet_alloc_unique();
90 struct sws_free_context_unique {
91 void operator() (SwsContext *context) const;
94 typedef std::unique_ptr<SwsContext, sws_free_context_unique>
95 SwsContextWithDeleter;
97 #endif // !defined(_FFMPEG_RAII_H)