|
|
@@ -231,15 +231,12 @@ void PlayerController::stopPlay()
|
|
|
qCDebug(playerControllerLog) << "Stopping playback...";
|
|
|
m_state = PlayerState::Stopping;
|
|
|
|
|
|
- if (m_videoState) {
|
|
|
- m_videoState->delete_video_state();
|
|
|
- }
|
|
|
- // 清理视频状态
|
|
|
- m_videoState.reset();
|
|
|
-
|
|
|
// 停止并重置所有线程
|
|
|
stopAndResetThreads();
|
|
|
|
|
|
+ // 清理视频状态
|
|
|
+ m_videoState.reset();
|
|
|
+
|
|
|
m_currentFile.clear();
|
|
|
m_state = PlayerState::Idle;
|
|
|
|
|
|
@@ -491,20 +488,30 @@ void PlayerController::stopAndResetThreads()
|
|
|
}
|
|
|
std::this_thread::sleep_for(std::chrono::milliseconds(10));
|
|
|
}
|
|
|
- threadPtr->join();
|
|
|
- qCDebug(playerControllerLog) << "[stopAndReset] [" << threadName << "] thread joined and will reset.";
|
|
|
+ // 只有线程已停止才join
|
|
|
+ if (!threadPtr->isRunning()) {
|
|
|
+ threadPtr->join();
|
|
|
+ qCDebug(playerControllerLog)
|
|
|
+ << "[stopAndReset] [" << threadName << "] thread joined and will reset.";
|
|
|
+ }
|
|
|
threadPtr.reset();
|
|
|
}
|
|
|
};
|
|
|
|
|
|
// 按依赖顺序停止线程
|
|
|
stopAndReset(m_beforePlayThread, "BeforePlay");
|
|
|
- stopAndReset(m_packetReadThread, "PacketRead");
|
|
|
+ stopAndReset(m_videoPlayThread, "VideoPlay");
|
|
|
+ stopAndReset(m_audioPlayThread, "AudioPlay");
|
|
|
+
|
|
|
+ // 解码前先 关闭流 不然会卡死异常
|
|
|
+ if (m_videoState) {
|
|
|
+ m_videoState->delete_video_state();
|
|
|
+ }
|
|
|
+
|
|
|
stopAndReset(m_decodeVideoThread, "DecodeVideo");
|
|
|
stopAndReset(m_decodeAudioThread, "DecodeAudio");
|
|
|
stopAndReset(m_decodeSubtitleThread, "DecodeSubtitle");
|
|
|
- stopAndReset(m_videoPlayThread, "VideoPlay");
|
|
|
- stopAndReset(m_audioPlayThread, "AudioPlay");
|
|
|
+ stopAndReset(m_packetReadThread, "PacketRead");
|
|
|
}
|
|
|
|
|
|
bool PlayerController::areAllThreadsStopped() const
|