]> git.sesse.net Git - nageru/commitdiff
Redo the FFmpeg RAII helpers to not store function pointers.
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Sun, 28 May 2017 14:12:04 +0000 (16:12 +0200)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Sun, 28 May 2017 14:12:21 +0000 (16:12 +0200)
audio_encoder.cpp
ffmpeg_raii.cpp
ffmpeg_raii.h

index aa343dabf40bdc4a59da2a8fc48b715e45dc58ce..378f748a279a9430a7c5d888de9b8d29006f9267 100644 (file)
@@ -193,5 +193,5 @@ AVCodecParametersWithDeleter AudioEncoder::get_codec_parameters()
 {
        AVCodecParameters *codecpar = avcodec_parameters_alloc();
        avcodec_parameters_from_context(codecpar, ctx);
-       return AVCodecParametersWithDeleter(codecpar, avcodec_parameters_free_unique);
+       return AVCodecParametersWithDeleter(codecpar);
 }
index 74ea3fd6cd345eea3e12b2bfa73f479d24d1bd49..b57de95124b18d2951263e489703592c2f0ae62a 100644 (file)
@@ -11,7 +11,7 @@ using namespace std;
 
 // AVFormatContext
 
-void avformat_close_input_unique(AVFormatContext *format_ctx)
+void avformat_close_input_unique::operator() (AVFormatContext *format_ctx) const
 {
        avformat_close_input(&format_ctx);
 }
@@ -23,40 +23,39 @@ AVFormatContextWithCloser avformat_open_input_unique(
        if (avformat_open_input(&format_ctx, pathname, fmt, options) != 0) {
                format_ctx = nullptr;
        }
-       return AVFormatContextWithCloser(format_ctx, avformat_close_input_unique);
+       return AVFormatContextWithCloser(format_ctx);
 }
 
 
 // AVCodecContext
 
-void avcodec_free_context_unique(AVCodecContext *codec_ctx)
+void avcodec_free_context_unique::operator() (AVCodecContext *codec_ctx) const
 {
        avcodec_free_context(&codec_ctx);
 }
 
 AVCodecContextWithDeleter avcodec_alloc_context3_unique(const AVCodec *codec)
 {
-       return AVCodecContextWithDeleter(avcodec_alloc_context3(codec), avcodec_free_context_unique);
+       return AVCodecContextWithDeleter(avcodec_alloc_context3(codec));
 }
 
 
 // AVCodecParameters
 
-void avcodec_parameters_free_unique(AVCodecParameters *codec_par)
+void avcodec_parameters_free_unique::operator() (AVCodecParameters *codec_par) const
 {
        avcodec_parameters_free(&codec_par);
 }
 
-
 // AVFrame
 
-void av_frame_free_unique(AVFrame *frame)
+void av_frame_free_unique::operator() (AVFrame *frame) const
 {
        av_frame_free(&frame);
 }
 
 AVFrameWithDeleter av_frame_alloc_unique()
 {
-       return AVFrameWithDeleter(av_frame_alloc(), av_frame_free_unique);
+       return AVFrameWithDeleter(av_frame_alloc());
 }
 
index d27c20d3b298ec866a6450c6067b404966d6dff8..0b112345d59727ca83728e638135bb3a0ab41159 100644 (file)
@@ -21,9 +21,11 @@ struct AVInputFormat;
 
 
 // AVFormatContext
-void avformat_close_input_unique(AVFormatContext *format_ctx);
+struct avformat_close_input_unique {
+       void operator() (AVFormatContext *format_ctx) const;
+};
 
-typedef std::unique_ptr<AVFormatContext, decltype(avformat_close_input_unique)*>
+typedef std::unique_ptr<AVFormatContext, avformat_close_input_unique>
        AVFormatContextWithCloser;
 
 AVFormatContextWithCloser avformat_open_input_unique(
@@ -31,25 +33,31 @@ AVFormatContextWithCloser avformat_open_input_unique(
 
 
 // AVCodecContext
-void avcodec_free_context_unique(AVCodecContext *codec_ctx);
+struct avcodec_free_context_unique {
+       void operator() (AVCodecContext *ctx) const;
+};
 
-typedef std::unique_ptr<AVCodecContext, decltype(avcodec_free_context_unique)*>
+typedef std::unique_ptr<AVCodecContext, avcodec_free_context_unique>
        AVCodecContextWithDeleter;
 
 AVCodecContextWithDeleter avcodec_alloc_context3_unique(const AVCodec *codec);
 
 
 // AVCodecParameters
-void avcodec_parameters_free_unique(AVCodecParameters *codec_par);
+struct avcodec_parameters_free_unique {
+       void operator() (AVCodecParameters *codec_par) const;
+};
 
-typedef std::unique_ptr<AVCodecParameters, decltype(avcodec_parameters_free_unique)*>
+typedef std::unique_ptr<AVCodecParameters, avcodec_parameters_free_unique>
        AVCodecParametersWithDeleter;
 
 
 // AVFrame
-void av_frame_free_unique(AVFrame *frame);
+struct av_frame_free_unique {
+       void operator() (AVFrame *frame) const;
+};
 
-typedef std::unique_ptr<AVFrame, decltype(av_frame_free_unique)*>
+typedef std::unique_ptr<AVFrame, av_frame_free_unique>
        AVFrameWithDeleter;
 
 AVFrameWithDeleter av_frame_alloc_unique();