From f30bed9e983be7aa406349db351442bb33b2c5f1 Mon Sep 17 00:00:00 2001
From: peijiankang <peijiankang@kylinos.cn>
Date: Fri, 29 Mar 2024 17:21:37 +0800
Subject: [PATCH] fix build error of kylin-recorder

---
 src/ffutil.cpp | 4 ++++
 src/ffutil.h   | 9 ++++++++-
 2 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/src/ffutil.cpp b/src/ffutil.cpp
index f824db5..2b0cd77 100644
--- a/src/ffutil.cpp
+++ b/src/ffutil.cpp
@@ -17,14 +17,18 @@ extern "C"
 
 FFUtil::FFUtil(QObject *parent) : QObject(parent)
 {
+#if !AVFORMAT_STATIC_REGISTER
     av_register_all();
+#endif
 }
 
 int FFUtil::getDuration(QString path)
 {
     int64_t duration = 0;
 
+#if !AVFORMAT_STATIC_REGISTER
     av_register_all();
+#endif
     AVFormatContext *pFormatCtx = avformat_alloc_context();
     avformat_open_input(&pFormatCtx, path.toStdString().c_str(), NULL, NULL);
 
diff --git a/src/ffutil.h b/src/ffutil.h
index 65461a5..12473a8 100644
--- a/src/ffutil.h
+++ b/src/ffutil.h
@@ -3,6 +3,13 @@
 
 #include <QObject>
 
+#define QTAV_USE_FFMPEG(MODULE) (MODULE##_VERSION_MICRO >= 100)
+#define QTAV_USE_LIBAV(MODULE)  !QTAV_USE_FFMPEG(MODULE)
+#define FFMPEG_MODULE_CHECK(MODULE, MAJOR, MINOR, MICRO) \
+    (QTAV_USE_FFMPEG(MODULE) && MODULE##_VERSION_INT >= AV_VERSION_INT(MAJOR, MINOR, MICRO))
+
+#define AVFORMAT_STATIC_REGISTER FFMPEG_MODULE_CHECK(LIBAVFORMAT, 58, 9, 100)
+
 struct AVCodec;
 struct AVCodecContext;
 struct AVFormatContext;
@@ -32,7 +39,7 @@ private:
     AVOutputFormat  *pOutputFormat = nullptr;
     AVFormatContext *pFormatCtx = nullptr;
     AVCodecContext  *pCodecCtx = nullptr;
-    AVCodec         *pCodec = nullptr;
+    const AVCodec         *pCodec = nullptr;
     int audioStream;
     int audioDuration;
 
-- 
2.25.1

