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 <avcpp/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 // AVSideDataDescriptor exisits
53 #define AVCPP_API_HAS_AVSIDEDATADESCRIPTOR (AVCPP_AVUTIL_VERSION_INT >= AV_VERSION_INT(59, 10, 100))
54 
55 // Send/Receive API for the Codecs
56 #define AVCPP_NEW_CODEC_API (AVCPP_AVCODEC_VERSION_INT >= AV_VERSION_INT(57,37,100))
57 
58 #if defined(__ICL) || defined (__INTEL_COMPILER)
59 # define FF_DISABLE_DEPRECATION_WARNINGS __pragma(warning(push)) __pragma(warning(disable:1478))
60 # define FF_ENABLE_DEPRECATION_WARNINGS __pragma(warning(pop))
61 #elif defined(_MSC_VER)
62 # define FF_DISABLE_DEPRECATION_WARNINGS __pragma(warning(push)) __pragma(warning(disable:4996))
63 # define FF_ENABLE_DEPRECATION_WARNINGS __pragma(warning(pop))
64 #elif defined(__GNUC__) || defined(__clang__)
65 # define FF_DISABLE_DEPRECATION_WARNINGS _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"")
66 # define FF_ENABLE_DEPRECATION_WARNINGS _Pragma("GCC diagnostic warning \"-Wdeprecated-declarations\"")
67 #else
68 # define FF_DISABLE_DEPRECATION_WARNINGS
69 # define FF_ENABLE_DEPRECATION_WARNINGS
70 #endif
71 
72 // Allow to use spece-ship operator, whem possible
73 #define AVCPP_USE_SPACESHIP_OPERATOR 0
74 #if __has_include(<compare>)
75 # include <compare>
76 # if defined(__cpp_lib_three_way_comparison) && __cpp_lib_three_way_comparison >= 201907
77 # undef AVCPP_USE_SPACESHIP_OPERATOR
78 # define AVCPP_USE_SPACESHIP_OPERATOR 1
79 # endif
80 #endif
81 
82 
83 // avcodec
84 #if AVCPP_AVCODEC_VERSION_INT < AV_VERSION_INT(54,59,100) // 1.0
85 inline void avcodec_free_frame(AVFrame **frame)
86 {
87  av_freep(frame);
88 }
89 #endif
90 
91 // avfilter
92 #if AVCPP_HAS_AVFILTER
93 #if AVCPP_AVFILTER_VERSION_INT < AV_VERSION_INT(3,17,100) // 1.0
94 inline const char *avfilter_pad_get_name(AVFilterPad *pads, int pad_idx)
95 {
96  return pads[pad_idx].name;
97 }
98 
99 inline AVMediaType avfilter_pad_get_type(AVFilterPad *pads, int pad_idx)
100 {
101  return pads[pad_idx].type;
102 }
103 #endif
104 #endif // if AVCPP_HAS_AVFILTER
105 
106 // Wrapper around av_free_packet()/av_packet_unref()
107 #if AVCPP_AVCODEC_VERSION_INT < AV_VERSION_INT(58,8,100) // < 3.0
108 #define avpacket_unref(p) av_free_packet(p)
109 #else
110 #define avpacket_unref(p) av_packet_unref(p)
111 #endif