avcpp 3.2.1
Wrapper for the FFmpeg that simplify usage from C++ projects.
Loading...
Searching...
No Matches
avcompat.h
Go to the documentation of this file.
1#pragma once
2
9
10#include <avcpp/avconfig.h>
11
12extern "C" {
13#ifdef AVCPP_AVCODEC_VERSION_MAJOR
14# include <libavcodec/avcodec.h>
15#endif
16#if AVCPP_HAS_AVFILTER
17# include <libavfilter/avfilter.h>
18#if AVCPP_AVFILTER_VERSION_INT < AV_VERSION_INT(7,0,0)
19# include <libavfilter/avfiltergraph.h>
20#endif
21#include <libavfilter/buffersink.h>
22#include <libavfilter/buffersrc.h>
23#if AVCPP_AVFILTER_VERSION_INT <= AV_VERSION_INT(2,77,100) // 0.11.1
24# include <libavfilter/vsrc_buffer.h>
25#endif
26#if AVCPP_AVFILTER_VERSION_INT < AV_VERSION_INT(6,31,100) // 3.0
27#include <libavfilter/avcodec.h>
28#endif
29#endif // if AVCPP_HAS_AVFILTER
30} // extern "C"
31
32
33// Codec parameters interface
37#define AVCPP_USE_CODECPAR ((AVCPP_AVCODEC_VERSION_MAJOR) >= 59) // FFmpeg 5.0
38
39// New Audio Channel Layout API
43#define AVCPP_API_NEW_CHANNEL_LAYOUT ((AVCPP_AVUTIL_VERSION_MAJOR > 57) || (AVCPP_AVUTIL_VERSION_MAJOR == 57 && (AVCPP_AVUTIL_VERSION_MINOR >= 24)))
44// `int64_t frame_num` has been added in the 60.2, in the 61.0 it should be removed
48#define AVCPP_API_FRAME_NUM ((AVCPP_AVCODEC_VERSION_MAJOR > 60) || (AVCPP_AVCODEC_VERSION_MAJOR == 60 && AVCPP_AVCODEC_VERSION_MINOR >= 2))
49// use AVFormatContext::url
50#if AVCPP_HAS_AVFORMAT
54# define AVCPP_API_AVFORMAT_URL ((AVCPP_AVFORMAT_VERSION_MAJOR > 58) || (AVCPP_AVFORMAT_VERSION_MAJOR == 58 && AVCPP_AVFORMAT_VERSION_MINOR >= 7))
55#endif // if AVCPP_HAS_AVFORMAT
56// net key frame flags: AV_FRAME_FLAG_KEY (FFmpeg 6.1)
60#define AVCPP_API_FRAME_KEY ((AVCPP_AVUTIL_VERSION_MAJOR > 58) || (AVCPP_AVUTIL_VERSION_MAJOR == 58 && AVCPP_AVUTIL_VERSION_MINOR >= 29))
61// avcodec_close() support
65#define AVCPP_API_AVCODEC_CLOSE (AVCPP_AVCODEC_VERSION_MAJOR < 61)
66
67// sizeof(AVPacket) is no part of the public ABI, packet must be allocated in heap
71#define AVCPP_API_AVCODEC_NEW_INIT_PACKET (AVCPP_AVCODEC_VERSION_MAJOR >= 58)
72// some fields in the AVCodec structure deprecard and replaced by the call of avcodec_get_supported_config()
76#define AVCPP_API_AVCODEC_GET_SUPPORTED_CONFIG (AVCPP_AVCODEC_VERSION_INT >= AV_VERSION_INT(61, 13, 100))
77#if AVCPP_HAS_AVFORMAT
78// av_stream_get_codec_timebase() deprecard now without replacement
82# define AVCPP_API_AVFORMAT_AV_STREAM_GET_CODEC_TIMEBASE (AVCPP_AVFORMAT_VERSION_INT < AV_VERSION_INT(61, 5, 101))
83#endif // if AVCPP_HAS_AVFORMAT
84// AVBuffer API switch to size_t
88#define AVCPP_API_AVBUFFER_SIZE_T (AVCPP_AVUTIL_VERSION_MAJOR >= 57)
89// AVSideDataDescriptor exisits
93#define AVCPP_API_HAS_AVSIDEDATADESCRIPTOR (AVCPP_AVUTIL_VERSION_INT >= AV_VERSION_INT(59, 10, 100))
94
95// Hardware device and frames contexts (libavutil/hwcontext.h)
99#define AVCPP_HAS_HWCONTEXT AVCPP_HAS_AVUTIL
100// av_hwdevice_ctx_create_derived_opts() was added in FFmpeg 4.3
104#define AVCPP_API_HWDEVICE_DERIVED_OPTS (AVCPP_AVUTIL_VERSION_INT >= AV_VERSION_INT(56, 48, 100))
105
106// Send/Receive API for the Codecs
110#define AVCPP_NEW_CODEC_API (AVCPP_AVCODEC_VERSION_INT >= AV_VERSION_INT(57,37,100))
111
112#if defined(__ICL) || defined (__INTEL_COMPILER)
113# define FF_DISABLE_DEPRECATION_WARNINGS __pragma(warning(push)) __pragma(warning(disable:1478))
114# define FF_ENABLE_DEPRECATION_WARNINGS __pragma(warning(pop))
115#elif defined(_MSC_VER)
116# define FF_DISABLE_DEPRECATION_WARNINGS __pragma(warning(push)) __pragma(warning(disable:4996))
117# define FF_ENABLE_DEPRECATION_WARNINGS __pragma(warning(pop))
118#elif defined(__GNUC__) || defined(__clang__)
119# define FF_DISABLE_DEPRECATION_WARNINGS _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"")
120# define FF_ENABLE_DEPRECATION_WARNINGS _Pragma("GCC diagnostic warning \"-Wdeprecated-declarations\"")
121#else
122# define FF_DISABLE_DEPRECATION_WARNINGS
123# define FF_ENABLE_DEPRECATION_WARNINGS
124#endif
125
126// Allow to use spece-ship operator, whem possible
130#define AVCPP_USE_SPACESHIP_OPERATOR 0
131#if __has_include(<compare>)
132# include <compare>
133# if defined(__cpp_lib_three_way_comparison) && __cpp_lib_three_way_comparison >= 201907
134# undef AVCPP_USE_SPACESHIP_OPERATOR
135# define AVCPP_USE_SPACESHIP_OPERATOR 1
136# endif
137#endif
138
139
140// avcodec
141#if AVCPP_AVCODEC_VERSION_INT < AV_VERSION_INT(54,59,100) // 1.0
142inline void avcodec_free_frame(AVFrame **frame)
143{
144 av_freep(frame);
145}
146#endif
147
148// avfilter
149#if AVCPP_HAS_AVFILTER
150#if AVCPP_AVFILTER_VERSION_INT < AV_VERSION_INT(3,17,100) // 1.0
151inline const char *avfilter_pad_get_name(AVFilterPad *pads, int pad_idx)
152{
153 return pads[pad_idx].name;
154}
155
156inline AVMediaType avfilter_pad_get_type(AVFilterPad *pads, int pad_idx)
157{
158 return pads[pad_idx].type;
159}
160#endif
161#endif // if AVCPP_HAS_AVFILTER
162
163// Wrapper around av_free_packet()/av_packet_unref()
164#if AVCPP_AVCODEC_VERSION_INT < AV_VERSION_INT(58,8,100) // < 3.0
171#define avpacket_unref(p) av_free_packet(p)
172#else
173#define avpacket_unref(p) av_packet_unref(p)
174#endif