zhuizhu 8 月之前
父節點
當前提交
599d80aed2
共有 5 個文件被更改,包括 35 次插入23 次删除
  1. 2 1
      AvPlayer2/mainwindowa.cpp
  2. 16 13
      AvPlayer2/playercontroller.cpp
  3. 9 1
      AvRecorder/ui/opengl_video_widget.cpp
  4. 2 3
      MainPanel.cpp
  5. 6 5
      main.cpp

+ 2 - 1
AvPlayer2/mainwindowa.cpp

@@ -304,7 +304,8 @@ MainWindowA::MainWindowA(QWidget* parent)
 
     hide_play_control(false);
 
-    m_playerController->startToPlay("C:/Users/zhuizhu/Videos/2.mp4");
+    m_playerController->startToPlay(
+        "rtmp://106.55.186.74:1935/stream/V1/01982b9b-f82c-7632-8283-8e60695b10d0");
 }
 
 MainWindowA::~MainWindowA()

+ 16 - 13
AvPlayer2/playercontroller.cpp

@@ -71,10 +71,12 @@ void PlayerController::startToPlay(const QString& file)
 
     // 正在播放中,检查是否需要切换文件
     if (currentState == PlayerState::Playing) {
-        if (currentFile == file) {
-            qCDebug(playerControllerLog) << "Already playing the same file. Ignoring request.";
-            return;
-        } else {
+        // if (currentFile == file) {
+        //     qCDebug(playerControllerLog) << "Already playing the same file. Ignoring request.";
+        //     return;
+        // } else
+
+        {
             qCDebug(playerControllerLog)
                 << "Player is busy with another file, stopping and switching to:" << file;
             // 在锁外调用stopPlay,避免死锁
@@ -129,15 +131,16 @@ void PlayerController::asyncInit(const QString& file)
         success = false;
     } else {
         // 检查文件是否存在和可访问
-        QFileInfo fileInfo(file);
-        if (!fileInfo.exists() || !fileInfo.isReadable()) {
-            qCWarning(playerControllerLog)
-                << "File does not exist or is not readable:" << toNativePath(file);
-            success = false;
-        } else {
-            qCInfo(playerControllerLog) << "File check passed:" << toNativePath(file);
-            success = true;
-        }
+        // QFileInfo fileInfo(file);
+        // if (!fileInfo.exists() || !fileInfo.isReadable()) {
+        //     qCWarning(playerControllerLog)
+        //         << "File does not exist or is not readable:" << toNativePath(file);
+        //     success = false;
+        // } else {
+        //     qCInfo(playerControllerLog) << "File check passed:" << toNativePath(file);
+        //     success = true;
+        // }
+        success = true;
     }
 
     m_initSuccess = success;

+ 9 - 1
AvRecorder/ui/opengl_video_widget.cpp

@@ -358,7 +358,7 @@ void OpenGLVideoWidget::updateFrame(const VideoFrame& frame)
 
 bool OpenGLVideoWidget::convertFromAVFrame(AVFrame* frame)
 {
-    if (!frame || frame->width <= 0 || frame->height <= 0)
+    if (!frame || frame->width <= 0 || frame->height <= 0 || !frame->data[0])
         return false;
 
     QMutexLocker locker(&m_mutex);
@@ -438,6 +438,10 @@ bool OpenGLVideoWidget::convertFromAVFrame(AVFrame* frame)
     } break;
     case AV_PIX_FMT_YUV420P: // 添加对YUV420P格式的支持
     {
+        // 检查YUV平面数据是否有效
+        if (!frame->data[1] || !frame->data[2])
+            return false;
+            
         // YUV420P转RGBA
         for (int y = 0; y < frame->height; y++) {
             uint8_t* dst = m_frameData + y * m_frameWidth * 4;
@@ -469,6 +473,10 @@ bool OpenGLVideoWidget::convertFromAVFrame(AVFrame* frame)
         }
     } break;
     case AV_PIX_FMT_NV12: {
+        // 检查NV12平面数据是否有效
+        if (!frame->data[1])
+            return false;
+            
         // NV12转RGBA
         for (int y = 0; y < frame->height; y++) {
             uint8_t* dst = m_frameData + y * m_frameWidth * 4;

+ 2 - 3
MainPanel.cpp

@@ -74,16 +74,15 @@ MainPanel::MainPanel(QWidget *parent)
         QJsonObject obj = doc.object();
         int liveStatus = obj.value("liveStatus").toInt(0); // 默认-1
         if (liveStatus == 1) {
-            qDebug() << "[MainPanel] liveStatus: 直播中";
+            qDebug() << "[MainPanel] liveStatus: 直播中" << chatView;
             if (chatView) {
                 const QString id = webSocketClient->roomId();
 
                 if (PlayWidget *playWidget = qobject_cast<PlayWidget *>(playerWidget)) {
-                    if (!playWidget->isPlaying() && !m_isStartingPlay) {
+                    if (!m_isStartingPlay) {
                         m_isStartingPlay = true;
                         playWidget->startToPlay("rtmp://106.55.186.74:1935/stream/V1/" + id);
                         m_isStartingPlay = false; // 如果 startToPlay 是同步的
-                        // 如果 startToPlay 是异步的,建议在播放真正开始/结束的回调里重置 m_isStartingPlay
                     }
                 }
             }

+ 6 - 5
main.cpp

@@ -104,8 +104,12 @@ 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();
+
+    // 视频播放测试
+    // MainWindowA aa;
+    // aa.show();
 
     // ThemeSettingsWidget ThemeSettingsWidget;
     // ThemeSettingsWidget.show();
@@ -114,9 +118,6 @@ zlmediakit/zlmediakit:master
     // w.resize(960, 540);
     // w.show();
 
-    MainWindowA aa;
-    aa.show();
-
     // // 这里填你的流地址
     // // w.startPlay("http://vd3.bdstatic.com/mda-jennyc5ci1ugrxzi/mda-jennyc5ci1ugrxzi.mp4");