]> git.sesse.net Git - nageru/blob - ffmpeg_raii.cpp
Let settings follow buses when editing the mapping.
[nageru] / ffmpeg_raii.cpp
1 #include "ffmpeg_raii.h"
2
3 extern "C" {
4 #include <libavcodec/avcodec.h>
5 #include <libavformat/avformat.h>
6 }
7
8 using namespace std;
9
10 // AVFormatContext
11
12 void avformat_close_input_unique(AVFormatContext *format_ctx)
13 {
14         avformat_close_input(&format_ctx);
15 }
16
17 AVFormatContextWithCloser avformat_open_input_unique(
18         const char *pathname, AVInputFormat *fmt, AVDictionary **options)
19 {
20         AVFormatContext *format_ctx = nullptr;
21         if (avformat_open_input(&format_ctx, pathname, fmt, options) != 0) {
22                 format_ctx = nullptr;
23         }
24         return AVFormatContextWithCloser(format_ctx, avformat_close_input_unique);
25 }
26
27
28 // AVCodecContext
29
30 void avcodec_free_context_unique(AVCodecContext *codec_ctx)
31 {
32         avcodec_free_context(&codec_ctx);
33 }
34
35 AVCodecContextWithDeleter avcodec_alloc_context3_unique(const AVCodec *codec)
36 {
37         return AVCodecContextWithDeleter(avcodec_alloc_context3(codec), avcodec_free_context_unique);
38 }
39
40
41 // AVCodecParameters
42
43 void avcodec_parameters_free_unique(AVCodecParameters *codec_par)
44 {
45         avcodec_parameters_free(&codec_par);
46 }
47
48
49 // AVFrame
50
51 void av_frame_free_unique(AVFrame *frame)
52 {
53         av_frame_free(&frame);
54 }
55
56 AVFrameWithDeleter av_frame_alloc_unique()
57 {
58         return AVFrameWithDeleter(av_frame_alloc(), av_frame_free_unique);
59 }
60