]> git.sesse.net Git - nageru/blob - ffmpeg_raii.h
Write 1.4.0 changelog.
[nageru] / ffmpeg_raii.h
1 #ifndef _FFMPEG_RAII_H
2 #define _FFMPEG_RAII_H 1
3
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.
8 //
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.
11
12 #include <memory>
13
14 struct AVCodec;
15 struct AVCodecContext;
16 struct AVCodecParameters;
17 struct AVDictionary;
18 struct AVFormatContext;
19 struct AVFrame;
20 struct AVInputFormat;
21
22
23 // AVFormatContext
24 void avformat_close_input_unique(AVFormatContext *format_ctx);
25
26 typedef std::unique_ptr<AVFormatContext, decltype(avformat_close_input_unique)*>
27         AVFormatContextWithCloser;
28
29 AVFormatContextWithCloser avformat_open_input_unique(
30         const char *pathname, AVInputFormat *fmt, AVDictionary **options);
31
32
33 // AVCodecContext
34 void avcodec_free_context_unique(AVCodecContext *codec_ctx);
35
36 typedef std::unique_ptr<AVCodecContext, decltype(avcodec_free_context_unique)*>
37         AVCodecContextWithDeleter;
38
39 AVCodecContextWithDeleter avcodec_alloc_context3_unique(const AVCodec *codec);
40
41
42 // AVCodecParameters
43 void avcodec_parameters_free_unique(AVCodecParameters *codec_par);
44
45 typedef std::unique_ptr<AVCodecParameters, decltype(avcodec_parameters_free_unique)*>
46         AVCodecParametersWithDeleter;
47
48
49 // AVFrame
50 void av_frame_free_unique(AVFrame *frame);
51
52 typedef std::unique_ptr<AVFrame, decltype(av_frame_free_unique)*>
53         AVFrameWithDeleter;
54
55 AVFrameWithDeleter av_frame_alloc_unique();
56
57 #endif  // !defined(_FFMPEG_RAII_H)