OpenPose  1.7.0
The first real-time multi-person system to jointly detect human body, hand, facial, and foot keypoints
subThreadQueueOut.hpp
Go to the documentation of this file.
1 #ifndef OPENPOSE_THREAD_THREAD_QUEUE_OUT_HPP
2 #define OPENPOSE_THREAD_THREAD_QUEUE_OUT_HPP
3 
8 
9 namespace op
10 {
11  template<typename TDatums, typename TWorker = std::shared_ptr<Worker<TDatums>>, typename TQueue = Queue<TDatums>>
12  class SubThreadQueueOut : public SubThread<TDatums, TWorker>
13  {
14  public:
15  SubThreadQueueOut(const std::vector<TWorker>& tWorkers, const std::shared_ptr<TQueue>& tQueueOut);
16 
17  virtual ~SubThreadQueueOut();
18 
19  bool work();
20 
21  private:
22  std::shared_ptr<TQueue> spTQueueOut;
23 
24  DELETE_COPY(SubThreadQueueOut);
25  };
26 }
27 
28 
29 
30 
31 
32 // Implementation
33 namespace op
34 {
35  template<typename TDatums, typename TWorker, typename TQueue>
37  const std::shared_ptr<TQueue>& tQueueOut) :
38  SubThread<TDatums, TWorker>{tWorkers},
39  spTQueueOut{tQueueOut}
40  {
41  spTQueueOut->addPusher();
42  }
43 
44  template<typename TDatums, typename TWorker, typename TQueue>
46  {
47  }
48 
49  template<typename TDatums, typename TWorker, typename TQueue>
51  {
52  try
53  {
54  // If output queue is closed -> close input queue
55  if (!spTQueueOut->isRunning())
56  return false;
57  else
58  {
59  // Don't work until next queue is not full
60  // This reduces latency to half
61  if (!spTQueueOut->isFull())
62  {
63  // Process TDatums
64  TDatums tDatums;
65  const auto workersAreRunning = this->workTWorkers(tDatums, true);
66  // Push/emplace tDatums if successfully processed
67  if (workersAreRunning)
68  {
69  if (tDatums != nullptr)
70  spTQueueOut->waitAndEmplace(tDatums);
71  }
72  // Close queue otherwise
73  else
74  spTQueueOut->stopPusher();
75  return workersAreRunning;
76  }
77  else
78  {
79  std::this_thread::sleep_for(std::chrono::microseconds{100});
80  return true;
81  }
82  }
83  }
84  catch (const std::exception& e)
85  {
86  error(e.what(), __LINE__, __FUNCTION__, __FILE__);
87  spTQueueOut->stop();
88  return false;
89  }
90  }
91 
93 }
94 
95 #endif // OPENPOSE_THREAD_THREAD_QUEUE_OUT_HPP
SubThreadQueueOut(const std::vector< TWorker > &tWorkers, const std::shared_ptr< TQueue > &tQueueOut)
COMPILE_TEMPLATE_DATUM(WPoseTriangulation)
OP_API void error(const std::string &message, const int line=-1, const std::string &function="", const std::string &file="")