8 #include <condition_variable> 37 return std::make_pair(stream, index) <
52 template<
class Stream_Profile>
53 static bool match(
const Stream_Profile&
a,
const Stream_Profile&
b)
57 if (a.stream_index() != -1 && b.stream_index() != -1 && (a.stream_index() != b.stream_index()))
61 if (a.fps() != 0 && b.fps() != 0 && (a.fps() != b.fps()))
64 if (
auto vid_a = dynamic_cast<video_stream_profile_interface*>(a))
66 if (
auto vid_b = dynamic_cast<video_stream_profile_interface*>(b))
68 if (vid_a->get_width() != 0 && vid_b->get_width() != 0 && (vid_a->get_width() != vid_b->get_width()))
70 if (vid_a->get_height() != 0 && vid_b->get_height() != 0 && (vid_a->get_height() != vid_b->get_height()))
89 if (
auto vid_a = dynamic_cast<const video_stream_profile_interface*>(a))
91 if (vid_a->get_width() != 0 && b.
width != 0 && (vid_a->get_width() != b.
width))
93 if (vid_a->get_height() != 0 && b.
height != 0 && (vid_a->get_height() != b.
height))
103 if (
auto vid_a = dynamic_cast<const video_stream_profile_interface*>(a))
105 if (vid_a->get_width() == 0 || vid_a->get_height() == 0)
return true;
114 if (a.
index == -1)
return true;
130 std::map<int, stream_profiles> dev_to_profiles)
132 _dev_to_profiles(
std::
move(dev_to_profiles)),
138 for (
auto &&
kvp : _dev_to_profiles) {
139 auto&& sub = _results.at(
kvp.first);
140 sub->open(
kvp.second);
147 for (
auto&&
sensor : _results)
148 sensor.second->start(callback);
153 for (
auto&&
sensor : _results)
159 for (
auto&&
sensor : _results)
162 std::map<index_type, std::shared_ptr<stream_profile_interface>>
get_profiles()
const 169 return _dev_to_profiles;
174 std::map<index_type, std::shared_ptr<stream_profile_interface>>
_profiles;
184 std::map<std::tuple<int, int>, std::vector<std::shared_ptr<stream_profile_interface>>> profiles_map;
188 profiles_map[std::make_tuple(
profile->get_unique_id(),
profile->get_stream_index())].push_back(
profile);
191 for (
auto profs : profiles_map)
194 auto p = profs.second.front().get();
198 enable_stream(vp->get_stream_type(), vp->get_stream_index(), vp->get_width(), vp->get_height(), vp->get_format(), vp->get_framerate());
201 enable_stream(
p->get_stream_type(),
p->get_stream_index(), 0, 0,
p->get_format(),
p->get_framerate());
221 if(itr->first.stream == stream)
259 if (
kvp.second->get_stream_type() == stream &&
kvp.second->get_stream_index() ==
index)
274 std::set<index_type> all_streams;
276 all_streams.insert({
kvp.second->get_stream_type(),
kvp.second->get_stream_index() });
285 throw std::runtime_error(
"Config couldn't configure all streams");
290 std::map<int, stream_profiles> dev_to_profiles;
291 std::map<index_type, std::shared_ptr<stream_profile_interface>> stream_to_profile;
293 std::map<int, sensor_interface*> sensors_map;
303 dev_to_profiles[
kvp.first].push_back(
kvp.second);
305 stream_to_profile[
idx] =
kvp.second;
313 static bool sort_highest_framerate(
const std::shared_ptr<stream_profile_interface>
lhs,
const std::shared_ptr<stream_profile_interface> rhs) {
314 return lhs->get_framerate() < rhs->get_framerate();
317 static bool sort_largest_image(std::shared_ptr<stream_profile_interface>
lhs, std::shared_ptr<stream_profile_interface> rhs) {
318 if (
auto a = dynamic_cast<video_stream_profile_interface*>(lhs.get()))
319 if (
auto b = dynamic_cast<video_stream_profile_interface*>(rhs.get()))
320 return a->get_width()*
a->get_height() >
b->get_width()*
b->get_height();
335 static bool sort_best_quality(std::shared_ptr<stream_profile_interface>
lhs, std::shared_ptr<stream_profile_interface> rhs) {
336 if (
auto a = dynamic_cast<video_stream_profile_interface*>(lhs.get()))
338 if (
auto b = dynamic_cast<video_stream_profile_interface*>(rhs.get()))
340 return std::make_tuple(
a->get_width() == 640 &&
a->get_height() == 480,
a->get_framerate() == 30,
is_best_format(
a->get_stream_type(),
a->get_format()))
341 > std::make_tuple(
b->get_width() == 640 &&
b->get_height() == 480,
b->get_framerate() == 30,
is_best_format(
b->get_stream_type(),
b->get_format()));
349 for (
auto & request : requests)
352 for (
auto candidate : candidates)
354 if (
match(candidate.get(), request) && !dev->
contradicts(candidate.get(), requests))
361 throw std::runtime_error(
std::string(
"Couldn't autocomplete request for subdevice"));
372 if (
auto vid = dynamic_cast<video_stream_profile_interface*>(profile))
374 r.
width = vid->get_width();
375 r.
height = vid->get_height();
390 std::vector<stream_profile> targets;
395 if (satisfied_streams.count(
kvp.first))
continue;
398 auto it = std::find_if(
begin(profiles),
end(profiles), [&
kvp](
const std::shared_ptr<stream_profile_interface>&
profile)
400 return match(profile.get(),
kvp.second);
402 if (
it !=
end(profiles))
404 targets.push_back(
kvp.second);
405 satisfied_streams.insert(
kvp.first);
409 if (targets.size() > 0)
413 for (
auto &&
t : targets)
415 for (
auto &&
p : profiles)
426 catch (std::exception
e)
435 std::multimap<int, std::shared_ptr<stream_profile_interface>>
out;
436 std::set<index_type> satisfied_streams;
448 auto profiles = default_profiles.size() == any_profiles.size() ? default_profiles : any_profiles;
450 for (
auto p : profiles)
451 out.emplace((
int)
i,
p);
455 throw std::runtime_error(
std::string(
"Couldn't resolve requests"));
virtual rs2_format get_format() const =0
virtual rs2_stream get_stream_type() const =0
void close(multistream stream)
GLboolean GLboolean GLboolean b
static stream_profile to_request(stream_profile_interface *profile)
void disable_stream(rs2_stream stream)
virtual size_t get_sensors_count() const =0
std::map< index_type, stream_profile > _requests
std::map< index_type, std::shared_ptr< stream_profile_interface > > get_profiles() const
void enable_streams(stream_profiles profiles)
static bool is_best_format(rs2_stream stream, rs2_format format)
multistream(std::map< int, sensor_interface * > results, std::map< index_type, std::shared_ptr< stream_profile_interface >> profiles, std::map< int, stream_profiles > dev_to_profiles)
std::map< index_type, stream_profile > get_requests()
std::map< int, sensor_interface * > _results
static bool sort_highest_framerate(const std::shared_ptr< stream_profile_interface > lhs, const std::shared_ptr< stream_profile_interface > rhs)
static void auto_complete(std::vector< stream_profile > &requests, stream_profiles candidates, const device_interface *dev)
GLsizei const GLchar *const * string
void sort(sort_type m_sort_type, const std::string &in, const std::string &out)
GLboolean GLboolean GLboolean GLboolean a
bool can_enable_stream(const device_interface *dev, rs2_stream stream, int index, int width, int height, rs2_format format, int fps)
static bool match(const Stream_Profile &a, const Stream_Profile &b)
virtual sensor_interface & get_sensor(size_t i)=0
std::map< int, stream_profiles > get_profiles_per_sensor() const
GLint GLsizei GLsizei height
GLint GLint GLsizei GLint GLenum format
virtual bool contradicts(const stream_profile_interface *a, const std::vector< stream_profile > &others) const =0
multistream resolve(device_interface *dev)
std::multimap< int, std::shared_ptr< stream_profile_interface > > map_streams(const device_interface *dev) const
GLenum GLenum GLenum GLenum mapping
rs2_format
A stream's format identifies how binary data is encoded within a frame.
std::vector< std::shared_ptr< stream_profile_interface >> stream_profiles
rs2_stream
Streams are different types of data provided by RealSense devices.
static bool sort_best_quality(std::shared_ptr< stream_profile_interface > lhs, std::shared_ptr< stream_profile_interface > rhs)
std::map< int, stream_profiles > _dev_to_profiles
void enable_stream(rs2_stream stream, int index, uint32_t width, uint32_t height, rs2_format format, uint32_t fps)
stream_profiles map_sub_device(stream_profiles profiles, std::set< index_type > satisfied_streams, const device_interface *dev) const
static bool has_wildcards(const stream_profile_interface *a)
static bool match_stream(const index_type &a, const index_type &b)
std::map< index_type, std::shared_ptr< stream_profile_interface > > _profiles
virtual int get_stream_index() const =0
typename::boost::move_detail::remove_reference< T >::type && move(T &&t) BOOST_NOEXCEPT
static bool match(const stream_profile_interface *a, const stream_profile &b)
virtual uint32_t get_framerate() const =0
bool operator<(const index_type &other) const
static bool has_wildcards(const stream_profile &a)
static bool sort_largest_image(std::shared_ptr< stream_profile_interface > lhs, std::shared_ptr< stream_profile_interface > rhs)
GeneratorWrapper< T > map(Func &&function, GeneratorWrapper< U > &&generator)
std::map< index_type, sensor_interface * > _devices