zhuizhu пре 8 месеци
родитељ
комит
49d64dd0d6

+ 4 - 3
AvPlayer2/PlayWidget.cpp

@@ -94,11 +94,12 @@ void PlayWidget::setPlayerController(PlayerController* controller)
         &PlayerController::frameReady,
         this,
         [this](AVFrame* frame) {
+            AVFrame* copiedFrame = av_frame_clone(frame);
             // 添加空指针检查和frame有效性检查
-            if (m_videoWidget && frame && frame->data[0] && frame->width > 0 && frame->height > 0) {
-                m_videoWidget->Render(frame);
+            if (m_videoWidget && copiedFrame && copiedFrame->data[0] && copiedFrame->width > 0
+                && copiedFrame->height > 0) {
+                m_videoWidget->Render(copiedFrame);
             }
-         
         },
         Qt::DirectConnection);
     // 音频可视化信号

+ 16 - 9
AvPlayer2/video_play_thread.cpp

@@ -27,39 +27,46 @@ void VideoPlayThread::run()
     //qCDebug(playerControllerVideoPlayThread) << "[VideoPlayThread] run start, m_pState:" << (void*)m_pState;
     assert(m_pState);
     VideoState* is = m_pState;
-    // qCDebug(playerControllerVideoPlayThread) << "[VideoPlayThread] VideoState* is:" << (void*)is << ", abort_request:" << is->abort_request;
+    qCDebug(playerControllerVideoPlayThread) << "[VideoPlayThread] VideoState* is:" << (void*) is
+                                             << ", abort_request:" << is->abort_request;
     double remaining_time = 0.0;
     int loop_count = 0;
     for (;;) {
         if (isExit()) {
-            // qCDebug(playerControllerVideoPlayThread) << "[VideoPlayThread] m_exit set, exit.";
+            qCDebug(playerControllerVideoPlayThread) << "[VideoPlayThread] m_exit set, exit.";
             break;
         }
         if (is->abort_request) {
-            // qCDebug(playerControllerVideoPlayThread) << "[VideoPlayThread] abort_request set, exit.";
+            qCDebug(playerControllerVideoPlayThread)
+                << "[VideoPlayThread] abort_request set, exit.";
             break;
         }
         if (is->eof && frame_queue_nb_remaining(&is->pictq) == 0) {
-            //  qCDebug(playerControllerVideoPlayThread) << "[VideoPlayThread] eof且队列空,退出线程";
+            qCDebug(playerControllerVideoPlayThread) << "[VideoPlayThread] eof且队列空,退出线程";
             break; // 线程退出
         }
         if (is->paused) {
-            // qCDebug(playerControllerVideoPlayThread) << "[VideoPlayThread] paused, wait.";
+            qCDebug(playerControllerVideoPlayThread) << "[VideoPlayThread] paused, wait.";
             std::unique_lock<std::mutex> lock(m_mutex);
             m_cv.wait_for(lock, std::chrono::milliseconds(10), [this] { return isExit(); });
             continue;
         }
-        // qCDebug(playerControllerVideoPlayThread) << "[VideoPlayThread] call video_refresh, loop:" << loop_count << ", pictq size:" << (is ? is->pictq.size : -1) << ", remaining_time:" << remaining_time;
+        qCDebug(playerControllerVideoPlayThread)
+            << "[VideoPlayThread] call video_refresh, loop:" << loop_count
+            << ", pictq size:" << (is ? is->pictq.size : -1)
+            << ", remaining_time:" << remaining_time;
         if (remaining_time > 0.0)
             av_usleep((int64_t) (remaining_time * 1000000.0));
         remaining_time = REFRESH_RATE;
         if ((!is->paused || is->force_refresh)) {
-            // qCDebug(playerControllerVideoPlayThread) << "[VideoPlayThread] call video_refresh, loop:" << loop_count++;
+            qCDebug(playerControllerVideoPlayThread)
+                << "[VideoPlayThread] call video_refresh, loop:" << loop_count++;
             video_refresh(is, &remaining_time);
         }
     }
-    //qCDebug(playerControllerVideoPlayThread) << "[VideoPlayThread] run end, abort_request:" << is->abort_request
-    //                             << ", m_exit:" << (m_exit ? m_exit->load() : -1);
+    qCDebug(playerControllerVideoPlayThread)
+        << "[VideoPlayThread] run end, abort_request:" << is->abort_request
+        << ", m_exit:" << (m_exit ? m_exit->load() : -1);
 }
 
 void VideoPlayThread::video_refresh(VideoState* is, double* remaining_time)

+ 1 - 1
AvRecorder/recorder/audio_recorder.cpp

@@ -33,7 +33,7 @@ bool AudioRecorder::Open(const std::vector<AudioCapturer::Type>& deviceTypes,
         if (deviceTypes[index] == AudioCapturer::Type::Speaker) {
             m_audioCapturers.push_back(new WASAPILoopbackCapturer());
         } else {
-            m_audioCapturers.push_back(new QtAudioCapturer());
+            m_audioCapturers.push_back(new WASAPILoopbackCapturer());
         }
     }
 

+ 1 - 1
AvRecorder/ui/opengl_video_widget.cpp

@@ -591,7 +591,7 @@ bool OpenGLVideoWidget::Render(AVFrame* frame)
     // 释放传入的AVFrame,因为现在使用QueuedConnection异步调用
     // 需要在这里释放内存,避免内存泄漏
     av_frame_free(&frame);
-    
+
     return result;
 }
 

+ 3 - 1
LearningSmartClient.pro

@@ -27,6 +27,7 @@ SOURCES += \
     thardware/thardware.cpp \
     thememanager.cpp \
     themesettingswidget.cpp \
+    tlogger.cpp \
     util/asynchelper.cpp \
     util/layoutbuilder.cpp \
     util/qformatter.cpp \
@@ -57,6 +58,7 @@ HEADERS += \
     thardware/thardware.h \
     thememanager.h \
     themesettingswidget.h \
+    tlogger.h \
     util/asynchelper.h \
     util/jsonmapper.h \
     util/layoutbuilder.h \
@@ -88,7 +90,7 @@ include($$PWD/fmt.pri)
 include($$PWD/qtpromise/qtpromise.pri)
 include($$PWD/jsonserializer/jsonserializer.pri)
 
-include($$PWD/AV/AV.pri)
+# include($$PWD/AV/AV.pri)
 
 
 INCLUDEPATH+="E:/AAA/ffmpeg-7.0.2-full_build-shared/include"

+ 29 - 8
MainPanel.cpp

@@ -28,6 +28,11 @@ MainPanel::MainPanel(QWidget *parent)
     , userProfile(nullptr)
     , chatView(nullptr)
 {
+    // 初始化防抖定时器
+    m_debounceTimer = new QTimer(this);
+    m_debounceTimer->setSingleShot(true);
+    m_debounceTimer->setInterval(500); // 500ms防抖延迟
+    connect(m_debounceTimer, &QTimer::timeout, this, &MainPanel::handleDebouncedPlay);
     // setupUI
     userProfile = new UserProfileWidget(this);
     webSocketClient = new WebSocketClient(this);
@@ -77,14 +82,10 @@ MainPanel::MainPanel(QWidget *parent)
             qDebug() << "[MainPanel] liveStatus: 直播中" << chatView;
             if (chatView) {
                 const QString id = webSocketClient->roomId();
-
-                if (PlayWidget *playWidget = qobject_cast<PlayWidget *>(playerWidget)) {
-                    if (!m_isStartingPlay) {
-                        m_isStartingPlay = true;
-                        playWidget->startToPlay("rtmp://106.55.186.74:1935/stream/V1/" + id);
-                        m_isStartingPlay = false; // 如果 startToPlay 是同步的
-                    }
-                }
+                
+                // 使用防抖机制处理频繁的请求
+                m_pendingRoomId = id;
+                m_debounceTimer->start(); // 重新开始计时,如果在500ms内再次收到请求,会重置定时器
             }
 
             // 你的处理逻辑
@@ -209,3 +210,23 @@ void MainPanel::roomItemChanged(QListWidgetItem *item)
         }
     }
 }
+
+void MainPanel::handleDebouncedPlay()
+{
+    // 防抖处理后的播放逻辑
+    if (m_pendingRoomId.isEmpty() || !chatView) {
+        return;
+    }
+    
+    if (PlayWidget *playWidget = qobject_cast<PlayWidget *>(playerWidget)) {
+        if (!m_isStartingPlay) {
+            m_isStartingPlay = true;
+            qDebug() << "[MainPanel] 防抖处理后开始播放:" << m_pendingRoomId;
+            playWidget->startToPlay("rtmp://106.55.186.74:1935/stream/V1/" + m_pendingRoomId);
+            m_isStartingPlay = false; // 如果 startToPlay 是同步的
+        }
+    }
+    
+    // 清空待处理的房间ID
+    m_pendingRoomId.clear();
+}

+ 4 - 0
MainPanel.h

@@ -4,6 +4,7 @@
 #include "qobjectdefs.h"
 #include <QMutex>
 #include <QWaitCondition>
+#include <QTimer>
 
 class QSplitter;
 class QListWidget;
@@ -30,6 +31,7 @@ signals:
 private:
     void setPlayerWidget(QWidget *newPlayer);
     void roomItemChanged(QListWidgetItem *item);
+    void handleDebouncedPlay(); // 防抖处理函数
 
 private:
     QSplitter *splitter = nullptr;
@@ -42,4 +44,6 @@ private:
     bool m_isStartingPlay = false;
     QMutex m_playMutex;
     QWaitCondition m_playCond;
+    QTimer *m_debounceTimer = nullptr;
+    QString m_pendingRoomId;
 };

+ 52 - 10
main.cpp

@@ -1,10 +1,6 @@
 // #include "AVPlayer2/mainwindowa.h"
 
-#include "ui/av_recorder.h"
-
 #include <QApplication>
-#include <QAudioDeviceInfo>
-#include <QAudioOutput>
 #include <QDateTime>
 #include <QDebug>
 #include <QFile>
@@ -15,17 +11,55 @@
 #include <qendian.h>
 #include <qmath.h>
 
+#include <AvPlayer2/PlayWidget.h>
+
 #include "mainwindow.h"
 #include "thememanager.h"
 #include "themesettingswidget.h"
 
+#include "tlogger.h"
+
+#include "ui/av_recorder.h"
+
 namespace avrecorder::video {
 void InitWinRTCapture();
 }
+
+#undef ERROR
+// Qt输出(用于兼容现有Qt日志系统)
+
+namespace TC {
+class QtOutput : public LogOutput
+{
+public:
+    void write(LogLevel level, const std::string &message) override;
+};
+
+void QtOutput::write(LogLevel level, const std::string &message)
+{
+    QString qmsg = QString::fromUtf8(message.c_str());
+    switch (level) {
+    case LogLevel::DEBUG:
+        qDebug() << qmsg;
+        break;
+    case LogLevel::INFO:
+        qInfo() << qmsg;
+        break;
+    case LogLevel::WARNING:
+        qWarning() << qmsg;
+        break;
+    case LogLevel::ERROR:
+        qCritical() << qmsg;
+        break;
+    }
+}
+} // namespace TC
+
 int main(int argc, char *argv[])
 {
-    QLoggingCategory::setFilterRules(QStringLiteral("player.controller.ReadThread=false\n"
-                                                    "player.controller.AudioPlayThread=false\n"));
+    // "player.controller.ReadThread=false\n"
+    QLoggingCategory::setFilterRules(QStringLiteral("player.controller.AudioPlayThread=false\n"
+                                                    "player.controller.AudioDecodeThread=false\n"));
     // QLoggingCategory::setFilterRules("*.debug=false\n"
     //                                  "*.info=false\n"
     //                                  "*.warning=false\n"
@@ -74,11 +108,19 @@ docker run -itd  --name zlmediakit --restart=always
 -v /data/zlmediakit/media/conf:/opt/media/conf
 zlmediakit/zlmediakit:master
 */
-    // MainWindow w;
-    // w.show();
+    MainWindow w;
+    w.show();
+
+    // PlayWidget playWidget;
+    // playWidget.resize(960, 540);
+    // playWidget.show();
+
+    // for (int var = 0; var < 20; ++var) {
+    //     playWidget.startToPlay("C:/Users/zhuizhu/Videos/2.mp4");
+    // }
 
-    AvRecorder avRecorder;
-    avRecorder.show();
+    // AvRecorder avRecorder;
+    // avRecorder.show();
     // ThemeSettingsWidget ThemeSettingsWidget;
     // ThemeSettingsWidget.show();