Skip to content

Commit 8cc2ba9

Browse files
committed
Reorganize API compatibility defines
1 parent 251d97e commit 8cc2ba9

File tree

6 files changed

+26
-36
lines changed

6 files changed

+26
-36
lines changed

src/avutils.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,21 @@ extern "C" {
4545
# define FF_ENABLE_DEPRECATION_WARNINGS
4646
#endif
4747

48+
// sizeof(AVPacket) is no part of the public ABI, packet must be allocated in heap
49+
#define API_AVCODEC_NEW_INIT_PACKET (LIBAVCODEC_VERSION_MAJOR >= 58)
50+
// some fields in the AVCodec structure deprecard and replaced by the call of avcodec_get_supported_config()
51+
#define API_AVCODEC_GET_SUPPORTED_CONFIG (LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(61, 13, 100))
52+
// av_stream_get_codec_timebase() deprecard now without replacement
53+
#define API_AVFORMAT_AV_STREAM_GET_CODEC_TIMEBASE (LIBAVFORMAT_VERSION_INT < AV_VERSION_INT(61, 5, 101))
54+
55+
// Allow to use spece-ship operator, whem possible
4856
#if __has_include(<compare>)
4957
# include <compare>
5058
# if defined(__cpp_lib_three_way_comparison) && __cpp_lib_three_way_comparison >= 201907
5159
# define AVCPP_USE_SPACESHIP_OPERATOR 1
5260
# endif
5361
#endif
5462

55-
5663
//
5764
// Functions
5865
//

src/codec.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ std::deque<Rational> Codec::supportedFramerates() const
6868
return {};
6969
deque<Rational> frameRates;
7070
const AVRational *frameRatesRaw = nullptr;
71-
#if USE_AVCODEC_GET_SUPPORTED_CONFIG
71+
#if API_AVCODEC_GET_SUPPORTED_CONFIG
7272
avcodec_get_supported_config(nullptr, m_raw, AV_CODEC_CONFIG_FRAME_RATE, 0, reinterpret_cast<const void**>(&frameRatesRaw), nullptr);
7373
#else
7474
frameRatesRaw = m_raw->supported_framerates;
@@ -91,7 +91,7 @@ std::deque<PixelFormat> Codec::supportedPixelFormats() const
9191
deque<PixelFormat> pixFmts;
9292
const enum AVPixelFormat *pixFmtsRaw = nullptr;
9393

94-
#if USE_AVCODEC_GET_SUPPORTED_CONFIG
94+
#if API_AVCODEC_GET_SUPPORTED_CONFIG
9595
avcodec_get_supported_config(nullptr, m_raw, AV_CODEC_CONFIG_PIX_FORMAT, 0, reinterpret_cast<const void**>(&pixFmtsRaw), nullptr);
9696
#else
9797
pixFmtsRaw = m_raw->pix_fmts;
@@ -115,7 +115,7 @@ std::deque<int> Codec::supportedSamplerates() const
115115
deque<int> sampleRates;
116116
const int *sampleRatesRaw = nullptr;
117117

118-
#if USE_AVCODEC_GET_SUPPORTED_CONFIG
118+
#if API_AVCODEC_GET_SUPPORTED_CONFIG
119119
avcodec_get_supported_config(nullptr, m_raw, AV_CODEC_CONFIG_SAMPLE_RATE, 0, reinterpret_cast<const void**>(&sampleRatesRaw), nullptr);
120120
#else
121121
sampleRatesRaw = m_raw->supported_samplerates;
@@ -139,7 +139,7 @@ std::deque<SampleFormat> Codec::supportedSampleFormats() const
139139
deque<SampleFormat> sampleFmts;
140140
const enum AVSampleFormat *sampleFmtsRaw = nullptr;
141141

142-
#if USE_AVCODEC_GET_SUPPORTED_CONFIG
142+
#if API_AVCODEC_GET_SUPPORTED_CONFIG
143143
avcodec_get_supported_config(nullptr, m_raw, AV_CODEC_CONFIG_SAMPLE_FORMAT, 0, reinterpret_cast<const void**>(&sampleFmtsRaw), nullptr);
144144
#else
145145
sampleFmtsRaw = m_raw->sample_fmts;
@@ -165,7 +165,7 @@ std::deque<uint64_t> Codec::supportedChannelLayouts() const
165165
#if API_NEW_CHANNEL_LAYOUT
166166
const AVChannelLayout *channelLayoutsRaw = nullptr;
167167

168-
#if USE_AVCODEC_GET_SUPPORTED_CONFIG
168+
#if API_AVCODEC_GET_SUPPORTED_CONFIG
169169
avcodec_get_supported_config(nullptr, m_raw, AV_CODEC_CONFIG_CHANNEL_LAYOUT, 0, reinterpret_cast<const void**>(&channelLayoutsRaw), nullptr);
170170
#else
171171
channelLayoutsRaw = m_raw->ch_layouts;
@@ -198,7 +198,7 @@ std::deque<ChannelLayoutView> Codec::supportedChannelLayouts2() const
198198
deque<ChannelLayoutView> channelLayouts;
199199
const AVChannelLayout *channelLayoutsRaw = nullptr;
200200

201-
#if USE_AVCODEC_GET_SUPPORTED_CONFIG
201+
#if API_AVCODEC_GET_SUPPORTED_CONFIG
202202
avcodec_get_supported_config(nullptr, m_raw, AV_CODEC_CONFIG_CHANNEL_LAYOUT, 0, reinterpret_cast<const void**>(&channelLayoutsRaw), nullptr);
203203
#else
204204
channelLayoutsRaw = m_raw->ch_layouts;

src/codeccontext.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ const int *get_supported_samplerates(const struct AVCodec *codec)
173173
{
174174
const int *sampleRates = nullptr;
175175

176-
#if USE_AVCODEC_GET_SUPPORTED_CONFIG
176+
#if API_AVCODEC_GET_SUPPORTED_CONFIG
177177
avcodec_get_supported_config(nullptr, codec,
178178
AV_CODEC_CONFIG_SAMPLE_RATE, 0,
179179
reinterpret_cast<const void**>(&sampleRates), nullptr);
@@ -403,7 +403,7 @@ void CodecContext2::setCodec(const Codec &codec, bool resetDefaults, Direction d
403403
const enum AVPixelFormat *pixFmts = nullptr;
404404
const enum AVSampleFormat *sampleFmts = nullptr;
405405

406-
#if USE_AVCODEC_GET_SUPPORTED_CONFIG
406+
#if API_AVCODEC_GET_SUPPORTED_CONFIG
407407
avcodec_get_supported_config(nullptr, codec.raw(),
408408
AV_CODEC_CONFIG_PIX_FORMAT, 0,
409409
reinterpret_cast<const void**>(&pixFmts), nullptr);
@@ -1049,7 +1049,7 @@ CodecContext2::encodeCommon(Packet &outPacket,
10491049
outPacket.setStreamIndex(inFrame.streamIndex());
10501050
} else if (m_stream.isValid()) {
10511051
#if USE_CODECPAR
1052-
#if USE_AV_STREAM_GET_CODEC_TIMEBASE
1052+
#if API_AVFORMAT_AV_STREAM_GET_CODEC_TIMEBASE
10531053
outPacket.setTimeBase(av_stream_get_codec_timebase(m_stream.raw()));
10541054
#else
10551055
// TBD: additional checking are needed

src/ffmpeg.h

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,6 @@ inline AVMediaType avfilter_pad_get_type(AVFilterPad *pads, int pad_idx)
6262
#define avpacket_unref(p) av_packet_unref(p)
6363
#endif
6464

65-
#define NO_INIT_PACKET (LIBAVCODEC_VERSION_MAJOR >= 60)
66-
#define DEPRECATED_INIT_PACKET (LIBAVCODEC_VERSION_MAJOR >= 58)
67-
68-
#define USE_AVCODEC_GET_SUPPORTED_CONFIG (LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(61, 13, 100))
69-
#define USE_AV_STREAM_GET_CODEC_TIMEBASE (LIBAVFORMAT_VERSION_INT < AV_VERSION_INT(61, 5, 101))
70-
7165
template<typename T>
7266
struct FFWrapperPtr
7367
{
@@ -183,13 +177,3 @@ struct PixSampleFmtWrapper
183177
protected:
184178
T m_fmt = NoneValue;
185179
};
186-
187-
// Extended attributes
188-
#if AV_GCC_VERSION_AT_LEAST(3,1)
189-
# define attribute_deprecated2(x) __attribute__((deprecated(x)))
190-
#elif defined(_MSC_VER)
191-
# define attribute_deprecated2(x) __declspec(deprecated(x))
192-
#else
193-
# define attribute_deprecated2(x)
194-
#endif
195-

src/packet.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
#include "packet.h"
2-
#include "avutils.h"
32

43
using namespace std;
54

65
namespace av {
76

87
Packet::Packet()
98
{
10-
#if DEPRECATED_INIT_PACKET
9+
#if API_AVCODEC_NEW_INIT_PACKET
1110
m_raw = av_packet_alloc();
1211
#else
1312
av_init_packet(raw());
@@ -100,7 +99,7 @@ Packet::Packet(uint8_t *data, size_t size, Packet::wrap_data_static, OptionalErr
10099

101100
Packet::~Packet()
102101
{
103-
#if DEPRECATED_INIT_PACKET
102+
#if API_AVCODEC_NEW_INIT_PACKET
104103
av_packet_free(&m_raw);
105104
#else
106105
avpacket_unref(&m_raw);
@@ -121,7 +120,7 @@ void Packet::initFromAVPacket(const AVPacket *src, bool deepCopy, OptionalErrorC
121120
avpacket_unref(raw());
122121

123122
if (deepCopy) {
124-
#if DEPRECATED_INIT_PACKET
123+
#if API_AVCODEC_NEW_INIT_PACKET
125124
if (!m_raw)
126125
m_raw = av_packet_alloc();
127126

@@ -349,7 +348,7 @@ int Packet::refCount() const
349348
return 0;
350349
}
351350

352-
#if DEPRECATED_INIT_PACKET
351+
#if API_AVCODEC_NEW_INIT_PACKET
353352
AVPacket *Packet::makeRef(OptionalErrorCode ec) const
354353
{
355354
clear_if(ec);
@@ -416,7 +415,7 @@ Packet &Packet::operator=(Packet &&rhs)
416415
return *this;
417416
}
418417

419-
#if DEPRECATED_INIT_PACKET
418+
#if API_AVCODEC_NEW_INIT_PACKET
420419
Packet &Packet::operator=(const AVPacket *rhs)
421420
{
422421
if (rhs == raw())

src/packet.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
#pragma once
22

3-
#include <iostream>
43
#include <vector>
54

65
#include "ffmpeg.h"
6+
#include "avutils.h"
77
#include "rational.h"
88
#include "stream.h"
99
#include "averror.h"
@@ -16,7 +16,7 @@ extern "C" {
1616
namespace av {
1717

1818
class Packet :
19-
#if DEPRECATED_INIT_PACKET
19+
#if API_AVCODEC_NEW_INIT_PACKET
2020
public FFWrapperPtr<AVPacket>
2121
#else
2222
public FFWrapperRef<AVPacket>
@@ -98,7 +98,7 @@ class Packet :
9898
bool isReferenced() const;
9999
int refCount() const;
100100

101-
#if DEPRECATED_INIT_PACKET
101+
#if API_AVCODEC_NEW_INIT_PACKET
102102
AVPacket* makeRef(OptionalErrorCode ec) const;
103103
#else
104104
AVPacket makeRef(OptionalErrorCode ec = throws()) const;
@@ -109,7 +109,7 @@ class Packet :
109109
Packet &operator=(const Packet &rhs);
110110
Packet &operator=(Packet &&rhs);
111111

112-
#if DEPRECATED_INIT_PACKET
112+
#if API_AVCODEC_NEW_INIT_PACKET
113113
Packet &operator=(const AVPacket *rhs);
114114
#else
115115
Packet &operator=(const AVPacket &rhs);

0 commit comments

Comments
 (0)