1 #ifndef MF_FLOW_NODE_H_
2 #define MF_FLOW_NODE_H_
5 #include "../queue/frame.h"
11 namespace mf {
namespace flow {
22 std::vector<std::unique_ptr<node_output>> outputs_;
23 std::vector<std::unique_ptr<node_input>> inputs_;
25 bool was_setup_ =
false;
29 bool seekable_ =
false;
32 std::atomic<time_unit> current_time_ {-1};
33 std::atomic<time_unit> end_time_ {-1};
36 void propagate_setup_();
37 void deduce_stream_properties_();
47 void mark_end() { end_time_ = current_time_ + 1; }
52 template<
typename Input>
54 Input* input =
new Input(*
this, inputs_.size(), past_window, future_window);
55 inputs_.emplace_back(input);
59 template<
typename Output>
61 Output* output =
new Output(*
this, outputs_.size(), format);
62 outputs_.emplace_back(output);
76 const auto&
inputs() noexcept {
return inputs_; }
77 const auto&
outputs() noexcept {
return outputs_; }
79 bool is_source() const noexcept {
return inputs_.empty(); }
80 bool is_sink() const noexcept {
return outputs_.empty(); }
84 virtual void stop() = 0;
91 bool was_setup() const noexcept {
return was_setup_; }
111 std::ptrdiff_t index_ = -1;
115 std::size_t frame_length_;
127 std::ptrdiff_t
index() const noexcept {
return index_; }
136 bool is_connected() const noexcept {
return (connected_input_ !=
nullptr); }
141 virtual void setup() = 0;
169 std::ptrdiff_t index_ = -1;
175 bool activated_ =
true;
183 std::ptrdiff_t
index() const noexcept {
return index_; }
193 bool is_connected() const noexcept {
return (connected_output_ !=
nullptr); }
Generic ndarray_view where lower dimension(s) are type-erased.
Definition: ndarray_view_generic.h:25
Output port of node in flow graph.
Definition: node.h:108
time_unit stream_duration() const noexcept
Definition: node.h:96
std::size_t frame_length() const noexcept
Definition: node.h:131
std::ptrdiff_t time_unit
Discrete time unit type.
Definition: common.h:52
node_output(const node_output &)=delete
virtual void internal_setup()=0
Called by propagate_setup_.
node_input & connected_input() const noexcept
Definition: node.h:137
virtual ~node()
Definition: node.h:69
Output & add_output_(const frame_format &format)
Definition: node.h:60
virtual timed_frame_array_view begin_read(time_unit duration)=0
virtual void end_write_frame(bool was_last_frame)=0
bool reached_end() const noexcept
Definition: node.cc:141
void input_has_connected(node_input &)
Definition: node.cc:154
Node in flow graph, base class.
Definition: node.h:19
std::ptrdiff_t index() const noexcept
Definition: node.h:127
node & operator=(const node &)=delete
bool is_active() const noexcept
Definition: node.h:143
virtual time_unit end_time() const =0
virtual bool process_next_frame()=0
std::string name
Definition: node.h:67
virtual void end_read(time_unit duration)=0
bool is_source() const noexcept
Definition: node.h:79
void mark_end()
Definition: node.h:47
virtual frame_view begin_write_frame(time_unit &t)=0
node_job make_job()
Definition: node.cc:130
const auto & inputs() noexcept
Definition: node.h:76
bool stream_duration_is_defined() const noexcept
Definition: node.h:95
const auto & outputs() noexcept
Definition: node.h:77
bool was_setup() const noexcept
Definition: node.h:91
void cancel_job(node_job &)
Definition: node.cc:135
bool is_bounded() const
Definition: node.cc:102
Input & add_input_(time_unit past_window, time_unit future_window)
Definition: node.h:53
time_unit prefetch_duration() const noexcept
Definition: node.h:93
bool is_active() const noexcept
Definition: node.h:100
void set_current_time(time_unit t) noexcept
Definition: node.h:46
time_unit end_time() const noexcept
Definition: node.h:88
virtual void launch()=0
Called by graph for all nodes, before any frame is pulled from sink.
void set_prefetch_duration(time_unit)
Definition: node.cc:83
void define_source_stream_properties(bool seekable, time_unit stream_duration=-1)
Definition: node.cc:70
bool is_sink() const noexcept
Definition: node.h:80
void propagate_activation(bool active)
Definition: node.cc:159
void define_format(const frame_format &format)
Definition: node.h:133
virtual void stop()=0
Called by graph for all node, before destruction of any node.
bool is_seekable() const noexcept
Definition: node.h:97
Work unit of flow graph node.
Definition: node_job.h:13
#define MF_EXPECTS(condition)
Definition: common.h:27
bool is_connected() const noexcept
Definition: node.h:136
const frame_format & format() const noexcept
Definition: node.h:134
virtual void cancel_write_frame()=0
graph & this_graph() noexcept
Definition: node.h:71
node & this_node() const noexcept
Definition: node.h:128
One-dimensional time span.
Definition: common.h:61
time_unit offset() const noexcept
Definition: node.h:94
time_unit current_time() const noexcept
Definition: node.h:103
virtual void pull(time_span span)=0
void define_frame_length(std::size_t len)
Definition: node.h:130
Generic ndarray_timed_view where lower dimension(s) are type-erased.
Definition: ndarray_timed_view_generic.h:12
Graph containing interconnected nodes through which media frames flow.
Definition: graph.h:23
void setup_sink()
Called by sink node, runs set up procedure for all node in graph.
Definition: node.cc:91
node(graph &gr)
Definition: node.h:40
void update_activation()
Called by output, propagates to preceding nodes.
Definition: node.cc:110
virtual ~node_output()
Definition: node.h:125