#pragma once extern "C" { #include #include typedef struct AVDictionary AVDictionary; typedef struct AVFormatContext AVFormatContext; typedef struct AVInputFormat AVInputFormat; typedef struct AVCodecContext AVCodecContext; typedef struct AVCodec AVCodec; typedef struct AVPacket AVPacket; typedef struct AVFrame AVFrame; } #include #include namespace av { // Generic error class struct error : public std::runtime_error { using std::runtime_error::runtime_error; }; // Type of a free function (for unique_ptr) template using deleter = void(*)(T*); // AVFormatContext related using format_context = std::unique_ptr>; format_context format_open_input(std::string const & filename, AVInputFormat* format, AVDictionary** options); format_context format_alloc_context(); // AVCodec related using open_codec = std::unique_ptr>; open_codec codec_open(AVCodecContext* ctx, AVCodec* codec, AVDictionary** options); // AVPacket related (this is somewhat strange, but matches the usecase) // I need to rethink this using packet_buffer = AVPacket; using packet = std::unique_ptr>; packet read_frame(format_context & ctx, packet_buffer & p); // AVFrame related using frame = std::unique_ptr>; frame frame_alloc(); frame frame_clone(frame const & f); AVPixelFormat get_format(frame const & f); // Allocator template struct allocator { using value_type = T; using size_type = size_t; T* allocate(size_type n) const { auto ptr = av_malloc(n * sizeof(T)); if(!ptr) throw std::bad_alloc(); return static_cast(ptr); } void deallocate(T* ptr, size_type /*n*/) const noexcept { av_free(ptr); } }; template bool operator==(allocator const &, allocator const &) noexcept { return true; } template bool operator!=(allocator const &, allocator const &) noexcept { return false; } }