diff --git a/camhandler.cpp b/camhandler.cpp index 0bfb9aa..5b2be2a 100644 --- a/camhandler.cpp +++ b/camhandler.cpp @@ -24,7 +24,41 @@ CamHandler::~CamHandler() { // 确保在销毁对象时清理资源 if (mStream) { - stopAcquisition(); // 确保流和缓冲区已清理 + if (!mDevice || !mStream) + return; + + // 1. 停止计时器 + if (mAcquireTimer.isActive()) { + mAcquireTimer.stop(); + // emit logMsg("Acquisition timer stopped."); + } + + // 2. 获取 AcquisitionStop 命令 + PvGenParameterArray *lDeviceParams = mDevice->GetParameters(); + PvGenCommand *lStop = dynamic_cast(lDeviceParams->Get("AcquisitionStop")); + + // 3. 停止采集和禁用流 + if (lStop != nullptr) { + // emit logMsg("Sending AcquisitionStop command to the device"); + lStop->Execute(); + } + // emit logMsg("Disable streaming on the controller."); + mDevice->StreamDisable(); + + // 4. 清理缓冲区:终止队列中的所有缓冲区并将它们移到输出队列 + // emit logMsg("Aborting buffers still in stream"); + mStream->AbortQueuedBuffers(); + + // 5. 从输出队列中检索剩余的缓冲区,丢弃它们 + PvBuffer *lBuffer = NULL; + PvResult lOperationResult; + // 必须清空队列,防止下次采集时使用错误的旧缓冲区 + while (mStream->GetQueuedBufferCount() > 0) { + mStream->RetrieveBuffer(&lBuffer, &lOperationResult); + // 注意:这里没有释放 lBuffer,因为缓冲区资源将在析构或断开时处理 + } + + // emit logMsg("Acquisition stopped and buffers cleaned up."); mStream->Close(); PvStream::Free(mStream); mStream = nullptr;