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