1 #ifndef MF_FLOW_GRAPH_H_
2 #define MF_FLOW_GRAPH_H_
5 #include "../os/event.h"
12 #include <type_traits>
15 namespace mf {
namespace flow {
28 std::vector<std::unique_ptr<node>> nodes_;
30 bool was_setup_ =
false;
31 bool running_ =
false;
34 template<
typename Node,
typename... Args>
35 Node& add_node_(Args&&... args) {
36 static_assert(std::is_base_of<node, Node>::value,
"");
37 if(was_setup_)
throw std::logic_error(
"cannot add node after graph already set up");
38 Node* nd =
new Node(*
this, std::forward<Args>(args)...);
39 nodes_.emplace_back(nd);
43 template<
typename Node,
typename... Args>
44 Node& add_sink_(Args&&... args) {
45 static_assert(std::is_base_of<sink_node, Node>::value,
"");
46 Node& sink = add_node_<Node>(std::forward<Args>(args)...);
51 void pull_next_frame_();
59 template<
typename Filter,
typename Node =
sync_node,
typename... Args>
61 static_assert(std::is_base_of<filter, Filter>::value,
"");
62 static_assert(std::is_base_of<filter_node, Node>::value,
"");
64 return nd.
set_filter<Filter>(std::forward<Args>(args)...);
67 template<
typename Filter,
typename... Args>
69 static_assert(std::is_base_of<sink_filter, Filter>::value,
"");
71 return nd.
set_filter<Filter>(std::forward<Args>(args)...);
Filter & add_sink_filter(Args &&...args)
Definition: graph.h:68
bool was_setup() const
Definition: graph.h:74
Synchronous node base class.
Definition: sync_node.h:44
time_unit current_time() const
Definition: graph.cc:47
std::ptrdiff_t time_unit
Discrete time unit type.
Definition: common.h:52
Filter & add_filter(Args &&...args)
Definition: graph.h:60
void setup()
Definition: graph.cc:23
std::function< frame_callback_function_type > callback_function
Definition: graph.h:55
void run_until(time_unit last_frame)
Definition: graph.cc:52
void(time_unit t) frame_callback_function_type
Definition: graph.h:25
Node which delegates concrete frame processing to associated filter object.
Definition: filter_node.h:15
void launch()
Definition: graph.cc:31
Sink node base class.
Definition: sink_node.h:12
Event which is repeatedly received after having been notified once.
Definition: event.h:65
void run_for(time_unit duration)
Definition: graph.cc:62
bool run()
Definition: graph.cc:67
void stop()
Definition: graph.cc:38
bool is_running() const
Definition: graph.h:75
event & stop_event()
Definition: graph.h:77
~graph()
Definition: graph.cc:18
Filter & set_filter(Args &&...args)
Definition: filter_node.h:30
Graph containing interconnected nodes through which media frames flow.
Definition: graph.h:23
void seek(time_unit target_time)
Definition: graph.cc:76