avcpp  2.0
Wrapper for the FFmpeg that simplify usage from C++ projects.
avcompat.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "avconfig.h"
4 
5 extern "C" {
6 #ifdef AVCPP_AVCODEC_VERSION_MAJOR
7 # include <libavcodec/avcodec.h>
8 #endif
9 #if AVCPP_HAS_AVFILTER
10 # include <libavfilter/avfilter.h>
11 #if AVCPP_AVFILTER_VERSION_INT < AV_VERSION_INT(7,0,0)
12 # include <libavfilter/avfiltergraph.h>
13 #endif
14 #include <libavfilter/buffersink.h>
15 #include <libavfilter/buffersrc.h>
16 #if AVCPP_AVFILTER_VERSION_INT <= AV_VERSION_INT(2,77,100) // 0.11.1
17 # include <libavfilter/vsrc_buffer.h>
18 #endif
19 #if AVCPP_AVFILTER_VERSION_INT < AV_VERSION_INT(6,31,100) // 3.0
20 #include <libavfilter/avcodec.h>
21 #endif
22 #endif // if AVCPP_HAS_AVFILTER
23 } // extern "C"
24 
25 
26 // Codec parameters interface
27 #define AVCPP_USE_CODECPAR ((AVCPP_AVCODEC_VERSION_MAJOR) >= 59) // FFmpeg 5.0
28 
29 // New Audio Channel Layout API
30 #define AVCPP_API_NEW_CHANNEL_LAYOUT ((AVCPP_AVUTIL_VERSION_MAJOR > 57) || (AVCPP_AVUTIL_VERSION_MAJOR == 57 && (AVCPP_AVUTIL_VERSION_MINOR >= 24)))
31 // `int64_t frame_num` has been added in the 60.2, in the 61.0 it should be removed
32 #define AVCPP_API_FRAME_NUM ((AVCPP_AVCODEC_VERSION_MAJOR > 60) || (AVCPP_AVCODEC_VERSION_MAJOR == 60 && AVCPP_AVCODEC_VERSION_MINOR >= 2))
33 // use AVFormatContext::url
34 #if AVCPP_HAS_AVFORMAT
35 # define AVCPP_API_AVFORMAT_URL ((AVCPP_AVFORMAT_VERSION_MAJOR > 58) || (AVCPP_AVFORMAT_VERSION_MAJOR == 58 && AVCPP_AVFORMAT_VERSION_MINOR >= 7))
36 #endif // if AVCPP_HAS_AVFORMAT
37 // net key frame flags: AV_FRAME_FLAG_KEY (FFmpeg 6.1)
38 #define AVCPP_API_FRAME_KEY ((AVCPP_AVUTIL_VERSION_MAJOR > 58) || (AVCPP_AVUTIL_VERSION_MAJOR == 58 && AVCPP_AVUTIL_VERSION_MINOR >= 29))
39 // avcodec_close() support
40 #define AVCPP_API_AVCODEC_CLOSE (AVCPP_AVCODEC_VERSION_MAJOR < 61)
41 
42 // sizeof(AVPacket) is no part of the public ABI, packet must be allocated in heap
43 #define AVCPP_API_AVCODEC_NEW_INIT_PACKET (AVCPP_AVCODEC_VERSION_MAJOR >= 58)
44 // some fields in the AVCodec structure deprecard and replaced by the call of avcodec_get_supported_config()
45 #define AVCPP_API_AVCODEC_GET_SUPPORTED_CONFIG (AVCPP_AVCODEC_VERSION_INT >= AV_VERSION_INT(61, 13, 100))
46 #if AVCPP_HAS_AVFORMAT
47 // av_stream_get_codec_timebase() deprecard now without replacement
48 # define AVCPP_API_AVFORMAT_AV_STREAM_GET_CODEC_TIMEBASE (AVCPP_AVFORMAT_VERSION_INT < AV_VERSION_INT(61, 5, 101))
49 #endif // if AVCPP_HAS_AVFORMAT
50 // AVBuffer API switch to size_t
51 #define AVCPP_API_AVBUFFER_SIZE_T (AVCPP_AVUTIL_VERSION_MAJOR >= 57)
52 
53 #if defined(__ICL) || defined (__INTEL_COMPILER)
54 # define FF_DISABLE_DEPRECATION_WARNINGS __pragma(warning(push)) __pragma(warning(disable:1478))
55 # define FF_ENABLE_DEPRECATION_WARNINGS __pragma(warning(pop))
56 #elif defined(_MSC_VER)
57 # define FF_DISABLE_DEPRECATION_WARNINGS __pragma(warning(push)) __pragma(warning(disable:4996))
58 # define FF_ENABLE_DEPRECATION_WARNINGS __pragma(warning(pop))
59 #elif defined(__GNUC__) || defined(__clang__)
60 # define FF_DISABLE_DEPRECATION_WARNINGS _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"")
61 # define FF_ENABLE_DEPRECATION_WARNINGS _Pragma("GCC diagnostic warning \"-Wdeprecated-declarations\"")
62 #else
63 # define FF_DISABLE_DEPRECATION_WARNINGS
64 # define FF_ENABLE_DEPRECATION_WARNINGS
65 #endif
66 
67 // Allow to use spece-ship operator, whem possible
68 #define AVCPP_USE_SPACESHIP_OPERATOR 0
69 #if __has_include(<compare>)
70 # include <compare>
71 # if defined(__cpp_lib_three_way_comparison) && __cpp_lib_three_way_comparison >= 201907
72 # undef AVCPP_USE_SPACESHIP_OPERATOR
73 # define AVCPP_USE_SPACESHIP_OPERATOR 1
74 # endif
75 #endif
76 
77 
78 // avcodec
79 #if AVCPP_AVCODEC_VERSION_INT < AV_VERSION_INT(54,59,100) // 1.0
80 inline void avcodec_free_frame(AVFrame **frame)
81 {
82  av_freep(frame);
83 }
84 #endif
85 
86 // avfilter
87 #if AVCPP_HAS_AVFILTER
88 #if AVCPP_AVFILTER_VERSION_INT < AV_VERSION_INT(3,17,100) // 1.0
89 inline const char *avfilter_pad_get_name(AVFilterPad *pads, int pad_idx)
90 {
91  return pads[pad_idx].name;
92 }
93 
94 inline AVMediaType avfilter_pad_get_type(AVFilterPad *pads, int pad_idx)
95 {
96  return pads[pad_idx].type;
97 }
98 #endif
99 #endif // if AVCPP_HAS_AVFILTER
100 
101 // Wrapper around av_free_packet()/av_packet_unref()
102 #if AVCPP_AVCODEC_VERSION_INT < AV_VERSION_INT(58,8,100) // < 3.0
103 #define avpacket_unref(p) av_free_packet(p)
104 #else
105 #define avpacket_unref(p) av_packet_unref(p)
106 #endif