X-Git-Url: https://git.sesse.net/?p=nageru;a=blobdiff_plain;f=ffmpeg_raii.cpp;h=746e03d19122da0cd11ad70735670b9b9d318af5;hp=042959780c0c5a05f55570c45717b1371430d723;hb=4e3c52ba57c4552a969e71ccdefd9941ce8d6290;hpb=cd319a6f4b11d888d8e9f996a2ec487668777e13 diff --git a/ffmpeg_raii.cpp b/ffmpeg_raii.cpp index 0429597..746e03d 100644 --- a/ffmpeg_raii.cpp +++ b/ffmpeg_raii.cpp @@ -3,58 +3,75 @@ extern "C" { #include #include +#include +#include +#include } 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); } AVFormatContextWithCloser avformat_open_input_unique( - const char *pathname, AVInputFormat *fmt, AVDictionary **options) + const char *pathname, AVInputFormat *fmt, + AVDictionary **options) { - AVFormatContext *format_ctx = nullptr; + return avformat_open_input_unique(pathname, fmt, options, AVIOInterruptCB{ nullptr, nullptr }); +} + +AVFormatContextWithCloser avformat_open_input_unique( + const char *pathname, AVInputFormat *fmt, + AVDictionary **options, + const AVIOInterruptCB &interrupt_cb) +{ + AVFormatContext *format_ctx = avformat_alloc_context(); + format_ctx->interrupt_callback = interrupt_cb; 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()); } +// SwsContext + +void sws_free_context_unique::operator() (SwsContext *context) const +{ + sws_freeContext(context); +}