zhuizhu hace 8 meses
padre
commit
e4a73adbf6

+ 0 - 2
AvPlayer2/AvPlayer2.pri

@@ -53,8 +53,6 @@ SOURCES += \
     $$PWD/video_play_thread.cpp \
     $$PWD/video_play_thread.cpp \
     $$PWD/video_state.cpp
     $$PWD/video_state.cpp
 
 
-RESOURCES += \
-    $$PWD/qmake_qmake_qm_files.qrc
 
 
 FORMS += \
 FORMS += \
     $$PWD/network_url_dlg.ui \
     $$PWD/network_url_dlg.ui \

BIN
AvPlayer2/VideoPlayer_en_001.qm


+ 0 - 3
AvPlayer2/VideoPlayer_en_001.ts

@@ -1,3 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!DOCTYPE TS>
-<TS version="2.1" language="en_001"></TS>

+ 6 - 7
AvPlayer2/playercontroller.cpp

@@ -386,15 +386,14 @@ void PlayerController::readPacketStopped()
 {
 {
     dump();
     dump();
     qCDebug(playerControllerLog) << "************* Read packets thread stopped signal received.";
     qCDebug(playerControllerLog) << "************* Read packets thread stopped signal received.";
-    //m_packetReadThread.reset();
 
 
     auto state = m_videoState->get_state();
     auto state = m_videoState->get_state();
-    if (state) {
-        state->abort_request = 1;
-    }
-    // if (m_videoState) {
-    //     m_videoState->delete_video_state();
+    // if (state) {
+    //     state->abort_request = 1;
     // }
     // }
+    if (m_videoState && m_videoState->get_state()) {
+        m_videoState->delete_video_state(); // stream_close
+    }
 
 
     emit audioStopped();
     emit audioStopped();
 }
 }
@@ -644,7 +643,7 @@ void PlayerController::stopAndResetThreads()
     stopAndReset(m_audioPlayThread, "AudioPlay");
     stopAndReset(m_audioPlayThread, "AudioPlay");
 
 
     // 解码前先 关闭流 不然会卡死异常
     // 解码前先 关闭流 不然会卡死异常
-    if (m_videoState) {
+    if (m_videoState && m_videoState->get_state()) {
         m_videoState->delete_video_state();
         m_videoState->delete_video_state();
     }
     }
     // auto state = m_videoState->get_state();
     // auto state = m_videoState->get_state();

+ 25 - 8
AvPlayer2/read_thread.cpp

@@ -41,7 +41,6 @@ int ReadThread::loop_read()
     if (!pkt) {
     if (!pkt) {
         av_log(nullptr, AV_LOG_FATAL, "Could not allocate packet.\n");
         av_log(nullptr, AV_LOG_FATAL, "Could not allocate packet.\n");
         ret = AVERROR(ENOMEM);
         ret = AVERROR(ENOMEM);
-        qCWarning(playerControllerReadThread) << "[ReadThread] av_packet_alloc failed!";
         return ret;
         return ret;
     }
     }
     qCDebug(playerControllerReadThread) << "[ReadThread] loop_read start, file:"
     qCDebug(playerControllerReadThread) << "[ReadThread] loop_read start, file:"
@@ -132,6 +131,21 @@ int ReadThread::loop_read()
             continue;
             continue;
         }
         }
 
 
+        if (!is->paused
+            && (!is->audio_st
+                || (is->auddec.finished == is->audioq.serial
+                    && frame_queue_nb_remaining(&is->sampq) == 0))
+            && (!is->video_st
+                || (is->viddec.finished == is->videoq.serial
+                    && frame_queue_nb_remaining(&is->pictq) == 0))) {
+            if (is->loop) {
+                stream_seek(is, 0, 0, 0);
+            } else {
+                // autoexit
+                break;
+            }
+        }
+
         ret = av_read_frame(is->ic, pkt);
         ret = av_read_frame(is->ic, pkt);
         if (ret < 0) {
         if (ret < 0) {
             char buf[256] = {0};
             char buf[256] = {0};
@@ -150,13 +164,14 @@ int ReadThread::loop_read()
                     packet_queue_put_nullpacket(&is->audioq, pkt, is->audio_stream);
                     packet_queue_put_nullpacket(&is->audioq, pkt, is->audio_stream);
                 if (is->subtitle_stream >= 0)
                 if (is->subtitle_stream >= 0)
                     packet_queue_put_nullpacket(&is->subtitleq, pkt, is->subtitle_stream);
                     packet_queue_put_nullpacket(&is->subtitleq, pkt, is->subtitle_stream);
-
-                if (is->loop) {
-                    stream_seek(is, 0, 0, 0);
-                } else {
-                    is->eof = 1;
-                    break; // added for auto exit read thread
-                }
+                is->eof = 1;
+
+                // if (is->loop) {
+                //     stream_seek(is, 0, 0, 0);
+                // } else {
+                //     is->eof = 1;
+                //     break; // added for auto exit read thread
+                // }
             }
             }
             if (is->ic->pb && is->ic->pb->error) {
             if (is->ic->pb && is->ic->pb->error) {
                 qCWarning(playerControllerReadThread) << "[ReadThread] IO error detected.";
                 qCWarning(playerControllerReadThread) << "[ReadThread] IO error detected.";
@@ -207,6 +222,8 @@ int ReadThread::loop_read()
     qCDebug(playerControllerReadThread) << "[ReadThread] loop_read exit, set read_thread_exit = -1";
     qCDebug(playerControllerReadThread) << "[ReadThread] loop_read exit, set read_thread_exit = -1";
     is->read_thread_exit = -1;
     is->read_thread_exit = -1;
 
 
+    if (!is->ic)
+        avformat_close_input(&is->ic);
     av_packet_free(&pkt);
     av_packet_free(&pkt);
     return 0;
     return 0;
 }
 }

+ 5 - 24
AvPlayer2/video_state.cpp

@@ -1,5 +1,7 @@
 #include "video_state.h"
 #include "video_state.h"
 
 
+#include <QDebug>
+
 int infinite_buffer = -1;
 int infinite_buffer = -1;
 int64_t start_time = AV_NOPTS_VALUE;
 int64_t start_time = AV_NOPTS_VALUE;
 static enum AVPixelFormat hw_pix_fmt;
 static enum AVPixelFormat hw_pix_fmt;
@@ -17,7 +19,8 @@ VideoStateData::~VideoStateData()
 
 
 void VideoStateData::delete_video_state()
 void VideoStateData::delete_video_state()
 {
 {
-    if (m_pState) {
+    qDebug() << "9887777" << m_pState;
+    if (m_pState != nullptr) {
         stream_close(m_pState);
         stream_close(m_pState);
         m_pState = nullptr;
         m_pState = nullptr;
     }
     }
@@ -114,7 +117,7 @@ int VideoStateData::open_media(VideoState* is)
     is->ic = ic;
     is->ic = ic;
 
 
     // if (genpts)
     // if (genpts)
-    // ic->flags |= AVFMT_FLAG_GENPTS;
+    ic->flags |= AVFMT_FLAG_GENPTS;
 
 
     // if (find_stream_info) {
     // if (find_stream_info) {
     //     AVDictionary **opts;
     //     AVDictionary **opts;
@@ -350,26 +353,6 @@ void VideoStateData::threads_setting(VideoState* is, const Threads& threads)
     is->threads.subtitle_decode_tid = threads.subtitle_decode_tid;
     is->threads.subtitle_decode_tid = threads.subtitle_decode_tid;
 }
 }
 
 
-void VideoStateData::threads_exit_wait(VideoState* is)
-{
-    if (!is)
-        return;
-
-    auto try_stop_and_join = [](ThreadBase* t) {
-        if (t) {
-            t->stop(); // 通知线程退出
-            t->join(); // 等待线程结束
-            // 注意:不要delete,线程对象由PlayerController的unique_ptr管理
-        }
-    };
-
-    try_stop_and_join(is->threads.video_play_tid);
-    try_stop_and_join(is->threads.audio_play_tid);
-    try_stop_and_join(is->threads.video_decode_tid);
-    try_stop_and_join(is->threads.audio_decode_tid);
-    try_stop_and_join(is->threads.subtitle_decode_tid);
-}
-
 void VideoStateData::stream_close(VideoState* is)
 void VideoStateData::stream_close(VideoState* is)
 {
 {
     assert(is);
     assert(is);
@@ -396,8 +379,6 @@ void VideoStateData::stream_close(VideoState* is)
     if (is->subtitle_stream >= 0)
     if (is->subtitle_stream >= 0)
         stream_component_close(is, is->subtitle_stream);
         stream_component_close(is, is->subtitle_stream);
 
 
-    //threads_exit_wait(is); // 等待所有线程退出
-
     avformat_close_input(&is->ic);
     avformat_close_input(&is->ic);
 
 
     packet_queue_destroy(&is->videoq);
     packet_queue_destroy(&is->videoq);

+ 1 - 3
AvPlayer2/video_state.h

@@ -42,8 +42,6 @@ private:
     void close_hardware();
     void close_hardware();
     int hw_decoder_init(AVCodecContext* ctx, const enum AVHWDeviceType type);
     int hw_decoder_init(AVCodecContext* ctx, const enum AVHWDeviceType type);
 
 
-    void threads_exit_wait(VideoState* is);
-
 private:
 private:
     VideoState* m_pState{nullptr};
     VideoState* m_pState{nullptr};
 
 
@@ -60,7 +58,7 @@ private:
     bool m_bHardwareSuccess{false};
     bool m_bHardwareSuccess{false};
     AVBufferRef* m_hw_device_ctx{nullptr};
     AVBufferRef* m_hw_device_ctx{nullptr};
     //enum AVPixelFormat m_hw_pix_fmt;
     //enum AVPixelFormat m_hw_pix_fmt;
-    bool m_bLoopPlay{false};
+    bool m_bLoopPlay{true};
 
 
     int seek_by_bytes = -1;
     int seek_by_bytes = -1;
 };
 };