]> git.sesse.net Git - nageru/blob - ffmpeg_raii.cpp
Fix an issue where the mixer lagging too much behind CEF would cause us to display...
[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 #include <libswscale/swscale.h>
9 }
10
11 using namespace std;
12
13 // AVFormatContext
14
15 void avformat_close_input_unique::operator() (AVFormatContext *format_ctx) const
16 {
17         avformat_close_input(&format_ctx);
18 }
19
20 AVFormatContextWithCloser avformat_open_input_unique(
21         const char *pathname, AVInputFormat *fmt, AVDictionary **options)
22 {
23         AVFormatContext *format_ctx = nullptr;
24         if (avformat_open_input(&format_ctx, pathname, fmt, options) != 0) {
25                 format_ctx = nullptr;
26         }
27         return AVFormatContextWithCloser(format_ctx);
28 }
29
30
31 // AVCodecContext
32
33 void avcodec_free_context_unique::operator() (AVCodecContext *codec_ctx) const
34 {
35         avcodec_free_context(&codec_ctx);
36 }
37
38 AVCodecContextWithDeleter avcodec_alloc_context3_unique(const AVCodec *codec)
39 {
40         return AVCodecContextWithDeleter(avcodec_alloc_context3(codec));
41 }
42
43
44 // AVCodecParameters
45
46 void avcodec_parameters_free_unique::operator() (AVCodecParameters *codec_par) const
47 {
48         avcodec_parameters_free(&codec_par);
49 }
50
51 // AVFrame
52
53 void av_frame_free_unique::operator() (AVFrame *frame) const
54 {
55         av_frame_free(&frame);
56 }
57
58 AVFrameWithDeleter av_frame_alloc_unique()
59 {
60         return AVFrameWithDeleter(av_frame_alloc());
61 }
62
63 // SwsContext
64
65 void sws_free_context_unique::operator() (SwsContext *context) const
66 {
67         sws_freeContext(context);
68 }