From 7a132dfd4c4ea85538892c501dd1111bc52acaef Mon Sep 17 00:00:00 2001 From: wang-bin Date: Mon, 21 Sep 2015 18:25:14 +0800 Subject: [PATCH] compat: fix old pixfmt. compatible with latest ffmpeg --- src/AVCompat.cpp | 11 ++++++++ src/ImageConverter_p.h | 4 +-- src/QtAV/private/AVCompat.h | 32 +++++++++++++++++------- src/codec/video/VideoDecoderFFmpegHW.cpp | 2 +- src/filter/LibAVFilter.cpp | 14 ++++------- 5 files changed, 42 insertions(+), 21 deletions(-) diff --git a/src/AVCompat.cpp b/src/AVCompat.cpp index 254ec7aa..eb90e968 100644 --- a/src/AVCompat.cpp +++ b/src/AVCompat.cpp @@ -313,3 +313,14 @@ const char *get_codec_long_name(enum AVCodecID id) return "unknown_codec"; } +#if !AV_MODULE_CHECK(LIBAVFILTER, 2, 22, 0, 79, 100) //FF_API_AVFILTERPAD_PUBLIC +const char *avfilter_pad_get_name(const AVFilterPad *pads, int pad_idx) +{ + return pads[pad_idx].name; +} + +enum AVMediaType avfilter_pad_get_type(const AVFilterPad *pads, int pad_idx) +{ + return pads[pad_idx].type; +} +#endif diff --git a/src/ImageConverter_p.h b/src/ImageConverter_p.h index 2768124c..ffc338b0 100644 --- a/src/ImageConverter_p.h +++ b/src/ImageConverter_p.h @@ -36,8 +36,8 @@ public: : interlaced(false) , w_in(0),h_in(0) , w_out(0),h_out(0) - , fmt_in(PIX_FMT_YUV420P) - , fmt_out(PIX_FMT_RGB32) + , fmt_in(QTAV_PIX_FMT_C(YUV420P)) + , fmt_out(QTAV_PIX_FMT_C(RGB32)) , brightness(0) , contrast(0) , saturation(0) diff --git a/src/QtAV/private/AVCompat.h b/src/QtAV/private/AVCompat.h index e55a1f86..32f2848c 100644 --- a/src/QtAV/private/AVCompat.h +++ b/src/QtAV/private/AVCompat.h @@ -81,10 +81,6 @@ extern "C" #include #include #include -#if QTAV_USE_FFMPEG(LIBAVFILTER) -/* used ffmpeg's by avfilter_copy_buf_props (now in avfilter.h). all deprecated in new versions*/ -#include -#endif #endif //QTAV_HAVE(AVFILTER) #if QTAV_HAVE(AVDEVICE) @@ -394,11 +390,29 @@ void av_packet_free_side_data(AVPacket *pkt); void avcodec_free_context(AVCodecContext **avctx); #endif -#ifndef FF_API_OLD_GRAPH_PARSE -#define avfilter_graph_parse_ptr(...) avfilter_graph_parse(__VA_ARGS__) -#endif //FF_API_OLD_GRAPH_PARSE - -// helper functions +// ffmpeg2.0 2013-07-03 - 838bd73 - lavfi 3.78.100 - avfilter.h +#if QTAV_USE_LIBAV(LIBAVFILTER) +#define avfilter_graph_parse_ptr(pGraph, pFilters, ppInputs, ppOutputs, pLog) avfilter_graph_parse(pGraph, pFilters, *ppInputs, *ppOutputs, pLog) +#elif !FFMPEG_MODULE_CHECK(LIBAVFILTER, 3, 78, 100) +#define avfilter_graph_parse_ptr(pGraph, pFilters, ppInputs, ppOutputs, pLog) avfilter_graph_parse(pGraph, pFilters, ppInputs, ppOutputs, pLog) +#endif +//ffmpeg1.0 2012-06-12 - c7b9eab / 84b9fbe - lavfi 2.79.100 / 2.22.0 - avfilter.h +#if !AV_MODULE_CHECK(LIBAVFILTER, 2, 22, 0, 79, 100) //FF_API_AVFILTERPAD_PUBLIC +const char *avfilter_pad_get_name(const AVFilterPad *pads, int pad_idx); +enum AVMediaType avfilter_pad_get_type(const AVFilterPad *pads, int pad_idx); +#endif +///ffmpeg1.0 lavfi 2.74.100 / 2.17.0. was in ffmpeg in old ffmpeg and now are in avfilter.h and deprecated. declare here to avoid version check +#if QTAV_USE_FFMPEG(LIBAVFILTER) +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ +struct AVFilterBufferRef; +int avfilter_copy_buf_props(AVFrame *dst, const AVFilterBufferRef *src); +#ifdef __cplusplus +} +#endif /* __cplusplus */ +#endif +/* helper functions */ const char *get_codec_long_name(AVCodecID id); #define AV_RUN_CHECK(FUNC, RETURN, ...) do { \ diff --git a/src/codec/video/VideoDecoderFFmpegHW.cpp b/src/codec/video/VideoDecoderFFmpegHW.cpp index 47502dc9..104e683b 100644 --- a/src/codec/video/VideoDecoderFFmpegHW.cpp +++ b/src/codec/video/VideoDecoderFFmpegHW.cpp @@ -168,7 +168,7 @@ AVPixelFormat VideoDecoderFFmpegHWPrivate::getFormat(struct AVCodecContext *p_co } if (!can_hwaccel) goto end; - for (size_t i = 0; pi_fmt[i] != PIX_FMT_NONE; i++) { + for (size_t i = 0; pi_fmt[i] != QTAV_PIX_FMT_C(NONE); i++) { if (vaPixelFormat() != pi_fmt[i]) continue; /* We try to call setup when possible to detect errors when possible (later is too late) */ diff --git a/src/filter/LibAVFilter.cpp b/src/filter/LibAVFilter.cpp index efcafe38..f1c61f69 100644 --- a/src/filter/LibAVFilter.cpp +++ b/src/filter/LibAVFilter.cpp @@ -156,11 +156,7 @@ public: } } scoped_in(&inputs), scoped_out(&outputs); //avfilter_graph_parse, avfilter_graph_parse2? -#if QTAV_USE_FFMPEG(LIBAVFILTER) AV_ENSURE_OK(avfilter_graph_parse_ptr(filter_graph, options.toUtf8().constData(), &inputs, &outputs, NULL), false); -#else - AV_ENSURE_OK(avfilter_graph_parse(filter_graph, options.toUtf8().constData(), inputs, outputs, NULL), false); -#endif //QTAV_USE_FFMPEG(LIBAVFILTER) AV_ENSURE_OK(avfilter_graph_config(filter_graph, NULL), false); avframe = av_frame_alloc(); status = LibAVFilter::ConfigureOk; @@ -275,7 +271,7 @@ QStringList LibAVFilter::registeredFilters(int type) #if QTAV_HAVE(AVFILTER) avfilter_register_all(); const AVFilter* f = NULL; - const AVFilterPad* fp = NULL; + AVFilterPad* fp = NULL; // no const in avfilter_pad_get_name() for ffmpeg<=1.2 libav<=9 #if AV_MODULE_CHECK(LIBAVFILTER, 3, 8, 0, 53, 100) while ((f = avfilter_next(f))) { #else @@ -283,13 +279,13 @@ QStringList LibAVFilter::registeredFilters(int type) while ((ff = av_filter_next(ff)) && *ff) { f = (*ff); #endif - fp = f->inputs; + fp = (AVFilterPad*)f->inputs; // only check the 1st pad - if (!fp || !fp[0].name || fp[0].type != (AVMediaType)type) + if (!fp || !avfilter_pad_get_name(fp, 0) || avfilter_pad_get_type(fp, 0) != (AVMediaType)type) continue; - fp = f->outputs; + fp = (AVFilterPad*)f->outputs; // only check the 1st pad - if (!fp || !fp[0].name || fp[0].type != (AVMediaType)type) + if (!fp || !avfilter_pad_get_name(fp, 0) || avfilter_pad_get_type(fp, 0) != (AVMediaType)type) continue; filters.append(QLatin1String(f->name)); }