-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathffmpeg_raii.h
73 lines (53 loc) · 1.86 KB
/
ffmpeg_raii.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#ifndef _FFMPEG_RAII_H
#define _FFMPEG_RAII_H 1
// 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.
//
// This does not cover any of the types that can actually be declared as
// a unique_ptr with no helper functions for deleter.
#include <memory>
struct AVCodec;
struct AVCodecContext;
struct AVCodecParameters;
struct AVDictionary;
struct AVFormatContext;
struct AVFrame;
struct AVInputFormat;
struct SwsContext;
// AVFormatContext
struct avformat_close_input_unique {
void operator() (AVFormatContext *format_ctx) const;
};
typedef std::unique_ptr<AVFormatContext, avformat_close_input_unique>
AVFormatContextWithCloser;
AVFormatContextWithCloser avformat_open_input_unique(
const char *pathname, AVInputFormat *fmt, AVDictionary **options);
// AVCodecContext
struct avcodec_free_context_unique {
void operator() (AVCodecContext *ctx) const;
};
typedef std::unique_ptr<AVCodecContext, avcodec_free_context_unique>
AVCodecContextWithDeleter;
AVCodecContextWithDeleter avcodec_alloc_context3_unique(const AVCodec *codec);
// AVCodecParameters
struct avcodec_parameters_free_unique {
void operator() (AVCodecParameters *codec_par) const;
};
typedef std::unique_ptr<AVCodecParameters, avcodec_parameters_free_unique>
AVCodecParametersWithDeleter;
// AVFrame
struct av_frame_free_unique {
void operator() (AVFrame *frame) const;
};
typedef std::unique_ptr<AVFrame, av_frame_free_unique>
AVFrameWithDeleter;
AVFrameWithDeleter av_frame_alloc_unique();
// SwsContext
struct sws_free_context_unique {
void operator() (SwsContext *context) const;
};
typedef std::unique_ptr<SwsContext, sws_free_context_unique>
SwsContextWithDeleter;
#endif // !defined(_FFMPEG_RAII_H)