]> git.sesse.net Git - nageru/blob - ffmpeg_raii.cpp
In FFmpegCapture, frame decoding into its own function.
[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::operator() (AVFormatContext *format_ctx) const
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);
27 }
28
29
30 // AVCodecContext
31
32 void avcodec_free_context_unique::operator() (AVCodecContext *codec_ctx) const
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));
40 }
41
42
43 // AVCodecParameters
44
45 void avcodec_parameters_free_unique::operator() (AVCodecParameters *codec_par) const
46 {
47         avcodec_parameters_free(&codec_par);
48 }
49
50 // AVFrame
51
52 void av_frame_free_unique::operator() (AVFrame *frame) const
53 {
54         av_frame_free(&frame);
55 }
56
57 AVFrameWithDeleter av_frame_alloc_unique()
58 {
59         return AVFrameWithDeleter(av_frame_alloc());
60 }
61