From d54bfd1df31ef73d8e18f2603cf7bbcf5354d344 Mon Sep 17 00:00:00 2001
From: peijiankang <peijiankang@kylinos.cn>
Date: Mon, 8 Apr 2024 14:42:03 +0800
Subject: [PATCH] fix build error of kylin-video about ffmpeg-6.1

---
 src/core/ffutil.cpp  |  2 ++
 src/core/ffutil.h    | 10 ++++++++-
 src/core/mpvcore.cpp | 53 ++++++++++++++++++++++----------------------
 3 files changed, 38 insertions(+), 27 deletions(-)

diff --git a/src/core/ffutil.cpp b/src/core/ffutil.cpp
index 5297a31..9549b14 100644
--- a/src/core/ffutil.cpp
+++ b/src/core/ffutil.cpp
@@ -21,7 +21,9 @@ extern "C"
 
 FFUtil::FFUtil(QObject *parent) : QObject(parent)
 {
+#if !AVFORMAT_STATIC_REGISTER
     av_register_all();
+#endif
     m_videoTbr = new VideoThumbnailer;
     m_videoTbr->setThumbnailSize(176);
     pFormatCtx = nullptr;
diff --git a/src/core/ffutil.h b/src/core/ffutil.h
index cf3de29..4b4754c 100644
--- a/src/core/ffutil.h
+++ b/src/core/ffutil.h
@@ -4,6 +4,14 @@
 #include <QObject>
 
 #include <libffmpegthumbnailer/videothumbnailer.h>
+
+#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)
+
 using namespace ffmpegthumbnailer;
 
 struct AVCodec;
@@ -26,7 +34,7 @@ private:
     VideoThumbnailer *m_videoTbr;
     AVFormatContext *pFormatCtx;
     AVCodecContext  *pCodecCtx;
-    AVCodec         *pCodec;
+    const AVCodec         *pCodec;
     int videoStream;
     int videoDuration;
 
diff --git a/src/core/mpvcore.cpp b/src/core/mpvcore.cpp
index 378db64..60dec98 100644
--- a/src/core/mpvcore.cpp
+++ b/src/core/mpvcore.cpp
@@ -1577,6 +1577,7 @@ bool MpvCore::event(QEvent *event)
                 Play();
                 ShowText("");
                 // 不要 break 有莫名其妙的问题，待查
+            //case MPV_EVENT_UNPAUSE:
             case MPV_EVENT_UNPAUSE:
                 KyInfo() << "[mpv event] MPV_EVENT_UNPAUSE";
                 // 防止重复设置状态
@@ -1627,32 +1628,32 @@ bool MpvCore::event(QEvent *event)
 //                mpv_event_log_message *message = static_cast<mpv_event_log_message*>(event->data);
                 break;
             }
-            case MPV_EVENT_TRACK_SWITCHED:
-                KyInfo() << "[mpv event] MPV_EVENT_TRACK_SWITCHED";
-                // 轨道id改变
-                mpv_get_property(m_mpvHandle, "sid", MPV_FORMAT_INT64, &sid);
-                if (sid > m_stracks)
-                    sid = 0;
-
-                g_core_signal->notifySubId(sid);
-                if(sid != m_sid && sid >= 0)
-                {
-                    m_sid = sid;
-                    if (sid == 0) {
-                        ShowText(tr("subtitle : ").append("no"));
-                    }
-                    // 字幕改变
-                    for(Mpv::Track tck : m_fileInfo.stracks)
-                        if(tck.id == sid)
-                            ShowText(tr("subtitle : ").append(tck.title));
-                }
-                mpv_get_property(m_mpvHandle, "aid", MPV_FORMAT_INT64, &aid);
-                g_core_signal->notifyAudioId(aid);
-                mpv_get_property(m_mpvHandle, "vid", MPV_FORMAT_INT64, &vid);
-                g_core_signal->notifyVideoId(vid);
-                m_vid = vid;
-                m_aid = aid;
-                break;
+//            case MPV_EVENT_TRACK_SWITCHED:
+//                KyInfo() << "[mpv event] MPV_EVENT_TRACK_SWITCHED";
+//                // 轨道id改变
+//                mpv_get_property(m_mpvHandle, "sid", MPV_FORMAT_INT64, &sid);
+//                if (sid > m_stracks)
+//                    sid = 0;
+//
+//                g_core_signal->notifySubId(sid);
+//                if(sid != m_sid && sid >= 0)
+//                {
+//                    m_sid = sid;
+//                    if (sid == 0) {
+//                        ShowText(tr("subtitle : ").append("no"));
+//                    }
+//                    // 字幕改变
+//                    for(Mpv::Track tck : m_fileInfo.stracks)
+//                        if(tck.id == sid)
+//                            ShowText(tr("subtitle : ").append(tck.title));
+//                }
+//                mpv_get_property(m_mpvHandle, "aid", MPV_FORMAT_INT64, &aid);
+//                g_core_signal->notifyAudioId(aid);
+//                mpv_get_property(m_mpvHandle, "vid", MPV_FORMAT_INT64, &vid);
+//                g_core_signal->notifyVideoId(vid);
+//                m_vid = vid;
+//                m_aid = aid;
+//                break;
             default: // unhandled events
                 break;
             }
-- 
2.43.0

