7 #include <libavutil/avutil.h>
8 #include <libavutil/parseutils.h>
9 #include <libavutil/mathematics.h>
10 #include <libavutil/opt.h>
11 #include <libavutil/pixdesc.h>
12 #include <libavdevice/avdevice.h>
13 #include <libswscale/swscale.h>
14 #include <libswresample/swresample.h>
15 #include <libavformat/version.h>
16 #include <libavcodec/version.h>
20 #include <libavfilter/avfilter.h>
21 #if LIBAVFILTER_VERSION_INT < AV_VERSION_INT(7,0,0)
22 # include <libavfilter/avfiltergraph.h>
24 #include <libavfilter/buffersink.h>
25 #include <libavfilter/buffersrc.h>
26 #if LIBAVFILTER_VERSION_INT <= AV_VERSION_INT(2,77,100) // 0.11.1
27 # include <libavfilter/vsrc_buffer.h>
29 #if LIBAVFILTER_VERSION_INT < AV_VERSION_INT(6,31,100) // 3.0
30 #include <libavfilter/avcodec.h>
37 #if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(54,59,100) // 1.0
38 inline void avcodec_free_frame(AVFrame **frame)
45 #if LIBAVFILTER_VERSION_INT < AV_VERSION_INT(3,17,100) // 1.0
46 inline const char *avfilter_pad_get_name(AVFilterPad *pads,
int pad_idx)
48 return pads[pad_idx].name;
51 inline AVMediaType avfilter_pad_get_type(AVFilterPad *pads,
int pad_idx)
53 return pads[pad_idx].type;
59 #if LIBAVFORMAT_VERSION_INT < AV_VERSION_INT(6,31,100) // < 3.0
60 #define avpacket_unref(p) av_free_packet(p)
62 #define avpacket_unref(p) av_packet_unref(p)
77 void _log(
int level,
const char *fmt)
const
79 av_log(
m_raw, level, fmt);
82 template<
typename... Args>
83 void _log(
int level,
const char* fmt,
const Args&... args)
const
85 av_log(
m_raw, level, fmt, args...);
92 #define RAW_GET(field, def) (m_raw ? m_raw->field : (def))
93 #define RAW_SET(field, val) if(m_raw) m_raw->field = (val)
95 #define RAW_GET2(cond, field, def) (m_raw && (cond) ? m_raw->field : def)
96 #define RAW_SET2(cond, field, val) if(m_raw && (cond)) m_raw->field = (val)
98 #define IF_GET(ptr, field, def) ((ptr) ? ptr->field : def)
99 #define IF_SET(ptr, field, val) (if(ptr) ptr->field = (val))
101 #define IF_GET2(cond, ptr, field, def) (ptr && (cond) ? ptr->field : def)
102 #define IF_SET2(cond, ptr, field, val) (if(ptr && (cond)) ptr->field = (val))
104 #if !DEPRECATED_INIT_PACKET
116 static const T empty = T();
117 auto res = memcmp(&
m_raw, &empty,
sizeof(empty));
121 void _log(
int level,
const char *fmt)
const
123 av_log(&
m_raw, level, fmt);
126 template<
typename... Args>
127 void _log(
int level,
const char* fmt,
const Args&... args)
const
129 av_log(&
m_raw, level, fmt, args...);
137 template<typename WrapperClass, typename T, T NoneValue = static_cast<T>(-1)>
144 operator T() const noexcept
154 operator T&() noexcept
171 friend std::ostream&
operator<<(std::ostream& ost, WrapperClass fmt)
182 #ifdef __cpp_lib_format
187 template <
typename B>
188 concept has_name_method_with_ec = requires(
const B& type, std::error_code ec) {
189 { type.name(ec) } -> std::convertible_to<std::string_view>;
192 template <
typename B>
193 concept has_name_method_without_ec = requires(
const B& type) {
194 { type.name() } -> std::convertible_to<std::string_view>;
197 template <
typename B>
198 concept has_long_name_method_with_ec = requires(
const B& type, std::error_code ec) {
199 { type.longName(ec) } -> std::convertible_to<std::string_view>;
202 template <
typename B>
203 concept has_long_name_method_without_ec = requires(
const B& type) {
204 { type.longName() } -> std::convertible_to<std::string_view>;
208 template <
class T,
class CharT>
209 requires av::has_name_method_with_ec<T> || av::has_name_method_without_ec<T>
210 struct std::formatter<T, CharT>
212 bool longName =
false;
214 template<
typename ParseContext>
215 constexpr ParseContext::iterator parse(ParseContext& ctx)
217 auto it = ctx.begin();
218 if constexpr (requires { requires av::has_long_name_method_with_ec<T> || av::has_long_name_method_without_ec<T>; }) {
225 if (it != ctx.end() && *it !=
'}')
226 throw std::format_error(
"Invalid format args");
231 template<
typename ParseContext>
232 auto format(
const T& value, ParseContext& ctx)
const
235 if constexpr (requires { requires av::has_long_name_method_with_ec<T>; }) {
236 std::error_code dummy;
237 return std::format_to(ctx.out(),
"{}", value.longName(dummy));
238 }
else if constexpr (requires { requires av::has_long_name_method_without_ec<T>; }) {
239 return std::format_to(ctx.out(),
"{}", value.longName());
242 if constexpr (requires { requires av::has_name_method_with_ec<T>; }) {
243 std::error_code dummy;
244 return std::format_to(ctx.out(),
"{}", value.name(dummy));
246 return std::format_to(ctx.out(),
"{}", value.name());