Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion src/dfm-io/dfm-io/utils/dmediainfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@
#include <QQueue>
#include <QMutex>
#include <QPointer>
#include <QDebug>

Check warning on line 13 in src/dfm-io/dfm-io/utils/dmediainfo.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QDebug> not found. Please note: Cppcheck does not need standard library headers to get proper results.

Check warning on line 13 in src/dfm-io/dfm-io/utils/dmediainfo.cpp

View workflow job for this annotation

GitHub Actions / static-check / static-check

Include file: <QDebug> not found. Please note: Cppcheck does not need standard library headers to get proper results.

#include <thread>

Check warning on line 15 in src/dfm-io/dfm-io/utils/dmediainfo.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <thread> not found. Please note: Cppcheck does not need standard library headers to get proper results.

Check warning on line 15 in src/dfm-io/dfm-io/utils/dmediainfo.cpp

View workflow job for this annotation

GitHub Actions / static-check / static-check

Include file: <thread> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <chrono>

Check warning on line 16 in src/dfm-io/dfm-io/utils/dmediainfo.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <chrono> not found. Please note: Cppcheck does not need standard library headers to get proper results.

Check warning on line 16 in src/dfm-io/dfm-io/utils/dmediainfo.cpp

View workflow job for this annotation

GitHub Actions / static-check / static-check

Include file: <chrono> not found. Please note: Cppcheck does not need standard library headers to get proper results.

static constexpr size_t kMediaInfoStateFinished { 10000 }; // read finished and no error

Expand Down Expand Up @@ -76,12 +77,20 @@

QPointer<DMediaInfoPrivate> me = this;
std::thread thread([me]() {
auto startTime = std::chrono::steady_clock::now();
const int kTimeoutMs = 3000; // 3秒超时

while (1) {
if (!me)
break;
if (me->isStopState.load())
break;
if (me->mediaInfo->State_Get() == kMediaInfoStateFinished) {

auto currentTime = std::chrono::steady_clock::now();
auto elapsed = std::chrono::duration_cast<std::chrono::milliseconds>(currentTime - startTime).count();

// 达到完成状态或超时
if (me->mediaInfo->State_Get() == kMediaInfoStateFinished || elapsed > kTimeoutMs) {
// 使用 QMetaObject::invokeMethod 切换到主线程执行 callback
// 避免从后台线程直接调用 Qt 对象方法导致的崩溃
QMetaObject::invokeMethod(
Expand Down
Loading