Commit 21e20012 authored by Alejandro Homs Puron's avatar Alejandro Homs Puron
Browse files

Fix issue on remaining PacketBlocks in Camera::AcqThread & Reconstruction

parent f9b7b38c
...@@ -73,14 +73,14 @@ public: ...@@ -73,14 +73,14 @@ public:
virtual void prepare(); virtual void prepare();
void addFramePackets(DetFrameImagePackets det_frame_packets); bool addFramePackets(DetFrameImagePackets det_frame_packets);
Data getRawData(Data& data); Data getRawData(Data& data);
virtual Data process(Data& data); virtual Data process(Data& data);
virtual Data processModel(Data& data) = 0; virtual Data processModel(Data& data) = 0;
virtual void cleanUp(); virtual void stop();
private: private:
struct ThreadData { struct ThreadData {
...@@ -98,6 +98,7 @@ private: ...@@ -98,6 +98,7 @@ private:
FrameDim m_raw_frame_dim; FrameDim m_raw_frame_dim;
Mutex m_mutex; Mutex m_mutex;
FramePacketMap m_frame_packet_map; FramePacketMap m_frame_packet_map;
bool m_stopped;
}; };
} // namespace SlsDetector } // namespace SlsDetector
......
...@@ -191,7 +191,8 @@ void Camera::AcqThread::threadFunction() ...@@ -191,7 +191,8 @@ void Camera::AcqThread::threadFunction()
auto get_next_frame = [&]() { auto get_next_frame = [&]() {
DetFrameImagePackets packets = readRecvPackets(next_frame++); DetFrameImagePackets packets = readRecvPackets(next_frame++);
FrameType frame = packets.first; FrameType frame = packets.first;
reconstruct->addFramePackets(std::move(packets)); if (!reconstruct->addFramePackets(std::move(packets)))
frame = -1;
return frame; return frame;
}; };
...@@ -203,6 +204,8 @@ void Camera::AcqThread::threadFunction() ...@@ -203,6 +204,8 @@ void Camera::AcqThread::threadFunction()
frame = get_next_frame(); frame = get_next_frame();
DEB_TRACE() << DEB_VAR2(next_frame, frame); DEB_TRACE() << DEB_VAR2(next_frame, frame);
} }
if ((frame == -1) || (m_state == StopReq))
break;
m_cam->m_buffer.waitLimaFrame(frame, l); m_cam->m_buffer.waitLimaFrame(frame, l);
{ {
AutoMutexUnlock u(l); AutoMutexUnlock u(l);
...@@ -212,6 +215,10 @@ void Camera::AcqThread::threadFunction() ...@@ -212,6 +215,10 @@ void Camera::AcqThread::threadFunction()
had_frames = true; had_frames = true;
} }
} }
{
AutoMutexUnlock u(l);
m_frame_packet_map.clear();
}
AcqState prev_state = m_state; AcqState prev_state = m_state;
...@@ -294,11 +301,6 @@ DetFrameImagePackets Camera::AcqThread::readRecvPackets(FrameType frame) ...@@ -294,11 +301,6 @@ DetFrameImagePackets Camera::AcqThread::readRecvPackets(FrameType frame)
} }
} }
if (stopped()) {
det_frame_packets.second.clear();
m_frame_packet_map.clear();
}
return det_frame_packets; return det_frame_packets;
} }
...@@ -957,7 +959,7 @@ void Camera::stopAcq() ...@@ -957,7 +959,7 @@ void Camera::stopAcq()
Reconstruction *r = m_model ? m_model->getReconstruction() : NULL; Reconstruction *r = m_model ? m_model->getReconstruction() : NULL;
if (r) if (r)
r->cleanUp(); r->stop();
m_global_cpu_affinity_mgr.stopAcq(); m_global_cpu_affinity_mgr.stopAcq();
AutoMutex l = lock(); AutoMutex l = lock();
......
...@@ -110,7 +110,12 @@ void Reconstruction::prepare() ...@@ -110,7 +110,12 @@ void Reconstruction::prepare()
model->getAcqFrameDim(m_raw_frame_dim, m_cam->m_raw_mode); model->getAcqFrameDim(m_raw_frame_dim, m_cam->m_raw_mode);
AutoMutex l(m_mutex); AutoMutex l(m_mutex);
m_frame_packet_map.clear(); m_stopped = false;
if (!m_frame_packet_map.empty()) {
DEB_ERROR() << "m_frame_packet_map not empty!";
AutoMutexUnlock u(l);
m_frame_packet_map.clear();
}
} }
Data Reconstruction::getRawData(Data& data) Data Reconstruction::getRawData(Data& data)
...@@ -150,26 +155,35 @@ void Reconstruction::releaseThreadData(void *thread_data) ...@@ -150,26 +155,35 @@ void Reconstruction::releaseThreadData(void *thread_data)
delete d; delete d;
} }
void Reconstruction::cleanUp() void Reconstruction::stop()
{ {
DEB_MEMBER_FUNCT(); DEB_MEMBER_FUNCT();
AutoMutex l(m_mutex); AutoMutex l(m_mutex);
if (m_stopped)
return;
m_stopped = true;
l.unlock();
m_frame_packet_map.clear(); m_frame_packet_map.clear();
} }
void Reconstruction::addFramePackets(DetFrameImagePackets det_frame_packets) bool Reconstruction::addFramePackets(DetFrameImagePackets det_frame_packets)
{ {
DEB_MEMBER_FUNCT(); DEB_MEMBER_FUNCT();
AutoMutex l(m_mutex); AutoMutex l(m_mutex);
if (m_stopped)
return false;
m_frame_packet_map.emplace(std::move(det_frame_packets)); m_frame_packet_map.emplace(std::move(det_frame_packets));
return true;
} }
Data Reconstruction::process(Data& data) Data Reconstruction::process(Data& data)
{ {
DEB_MEMBER_FUNCT(); DEB_MEMBER_FUNCT();
FrameType frame = data.frameNumber;
AutoMutex l(m_mutex); AutoMutex l(m_mutex);
if (m_stopped)
return data;
FrameType frame = data.frameNumber;
FramePacketMap::iterator it = m_frame_packet_map.find(frame); FramePacketMap::iterator it = m_frame_packet_map.find(frame);
if (it == m_frame_packet_map.end()) if (it == m_frame_packet_map.end())
return data; return data;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment