post-processing-worker-filter.h
Go to the documentation of this file.
1 // License: Apache 2.0. See LICENSE file in root directory.
2 // Copyright(c) 2019 Intel Corporation. All Rights Reserved.
3 
4 #pragma once
5 
7 
8 
9 /*
10  A post-processing filter that employs a separate thread to do its work.
11 */
13 {
14  std::atomic_bool _alive { true };
15  std::thread _worker;
17 
18 protected:
20  : post_processing_filter( name )
21  {
22  }
24  {
26  }
27 
28  // Worker thread uses resources of classes that inherit from this class (e.g openvino_face_detection),
29  // so it should be released from inherited classes.
30  // This should be called from dtor of inherited classes!
32  {
33  _alive = false;
34  if (_worker.joinable())
35  _worker.join();
36  }
37 
38 public:
39  void start( rs2::subdevice_model & model ) override
40  {
42  _worker = std::thread( [&]()
43  {
44  try
45  {
46  worker_start();
47  }
48  catch( std::exception const & e )
49  {
50  // Most likely file not found, if the user didn't set up his .xml/.bin files right
51  LOG( ERROR ) << "Cannot start " << get_name() << ": " << e.what();
52  return;
53  }
54  while( _alive )
55  {
56  rs2::frame f;
57  if( !_queue.try_wait_for_frame( &f ) )
58  continue;
59  if (!f)
60  continue;
61 
62  worker_body(f);
63  }
64  LOG(DEBUG) << "End of worker loop in " + get_name();
65  worker_end();
66  } );
67  }
68 
69 protected:
71  {
72  _queue.enqueue(fs);
73  return fs;
74  }
75 
76  virtual void worker_start() {}
77  virtual void worker_end() {}
78 
79  virtual void worker_body( rs2::frame fs ) = 0;
80 };
post_processing_worker_filter(std::string const &name)
GLuint const GLchar * name
void enqueue(frame f) const
LOG(INFO)<< "Log message to default logger"
GLsizei const GLchar *const * string
e
Definition: rmse.py:177
GLdouble f
rs2::frame process_frame(rs2::frame fs) override
virtual void worker_body(rs2::frame fs)=0
std::enable_if< std::is_base_of< rs2::frame, T >::value, bool >::type try_wait_for_frame(T *output, unsigned int timeout_ms=5000) const
void start(rs2::subdevice_model &model) override
virtual void start(rs2::subdevice_model &model)
std::string const & get_name() const


librealsense2
Author(s): Sergey Dorodnicov , Doron Hirshberg , Mark Horn , Reagan Lopez , Itay Carpis
autogenerated on Mon May 3 2021 02:47:39