syncer-processing-block.cpp
Go to the documentation of this file.
1 // License: Apache 2.0. See LICENSE file in root directory.
2 // Copyright(c) 2015 Intel Corporation. All Rights Reserved.
3 
4 #include <functional>
5 #include "source.h"
6 #include "sync.h"
9 
10 
11 namespace librealsense
12 {
13  syncer_process_unit::syncer_process_unit(std::initializer_list< bool_option::ptr > enable_opts, bool log)
14  : processing_block("syncer"), _matcher((new composite_identity_matcher({})))
15  , _enable_opts(enable_opts.begin(), enable_opts.end())
16  {
17  _matcher->set_callback([this](frame_holder f, syncronization_environment env)
18  {
19  if (env.log)
20  {
21  LOG_DEBUG("SYNCED: " << frame_holder_to_string(f));
22  }
23 
24  // We get here from within a dispatch() call, already protected by a mutex -- so only one thread can enqueue!
25  env.matches.enqueue(std::move(f));
26  });
27 
28  // This callback gets called by the previous processing block when it is done with a frame. We
29  // call the matchers with the frame and eventually call the next callback in the list using frame_ready().
30  // This callback can get called from multiple threads, one thread per stream -- but always in the correct
31  // frame order per stream.
33  {
34  // if the syncer is disabled passthrough the frame
35  bool enabled = false;
36  size_t n_opts = 0;
37  for (auto& wopt : _enable_opts)
38  {
39  auto opt = wopt.lock();
40  if (opt)
41  {
42  ++n_opts;
43  if (opt->is_true())
44  {
45  enabled = true;
46  break;
47  }
48  }
49  }
50  if (n_opts && !enabled)
51  {
53  return;
54  }
55 
56  {
57  std::lock_guard<std::mutex> lock(_mutex);
58  _matcher->dispatch(std::move(frame), { source, _matches, log });
59  }
60 
62  {
63  // Another thread has the lock, meaning will get into the following loop and dequeue all
64  // the frames. So there's nothing for us to do...
65  std::unique_lock< std::mutex > lock(_callback_mutex, std::try_to_lock);
66  if (!lock.owns_lock())
67  return;
68 
69  while (_matches.try_dequeue(&f))
70  {
72  }
73  }
74 
75  };
76 
77  set_processing_callback(std::shared_ptr<rs2_frame_processor_callback>(
78  new internal_frame_processor_callback<decltype(f)>(f)));
79  }
80 }
static const textual_icon lock
Definition: model-views.h:218
virtual void frame_ready(frame_holder result)=0
std::vector< std::weak_ptr< bool_option > > _enable_opts
syncer_process_unit(std::initializer_list< bool_option::ptr > enable_opts, bool log=true)
GLdouble f
single_consumer_frame_queue< frame_holder > & matches
Definition: sync.h:69
synthetic_source_interface & get_source() override
GLenum GLenum GLsizei const GLuint GLboolean enabled
void set_processing_callback(frame_processor_callback_ptr callback) override
single_consumer_frame_queue< frame_holder > _matches
void log(std::string message)
typename::boost::move_detail::remove_reference< T >::type && move(T &&t) BOOST_NOEXCEPT
GLsizei GLsizei GLchar * source


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