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