mf
Media Framework
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
async_node.h
Go to the documentation of this file.
1 #ifndef MF_FLOW_ASYNC_NODE_H_
2 #define MF_FLOW_ASYNC_NODE_H_
3 
4 #include "filter_node.h"
5 #include "../queue/shared_ring.h"
6 #include <thread>
7 
8 namespace mf { namespace flow {
9 
10 class graph;
11 class async_node;
12 
13 
15 private:
16  std::unique_ptr<shared_ring> ring_;
17 
18 public:
20 
22 
23  void setup() override;
24 
27  void pull(time_span span) override;
28  timed_frame_array_view begin_read(time_unit duration) override;
29  void end_read(time_unit duration) override;
30  time_unit end_time() const override;
32 
36  void end_write_frame(bool was_last_frame) override;
37  void cancel_write_frame() override;
39 };
40 
41 
42 
44 
47 class async_node final : public filter_node {
48 private:
49  bool running_ = false;
50  std::thread thread_;
51 
52  void thread_main_();
53 
54 public:
55  explicit async_node(graph&);
56  ~async_node();
57 
58  void internal_setup() final override;
59  void launch() final override;
60  void stop() final override;
61  bool process_next_frame() override;
62 
63  node_input& add_input(time_unit past_window, time_unit future_window) override {
64  return add_input_<node_input>(past_window, future_window);
65  }
66 
67  async_node_output& add_output(const frame_format& format) override {
68  return add_output_<async_node_output>(format);
69  }
70 };
71 
72 }}
73 
74 #endif
Input port of node in flow graph.
Definition: node.h:166
void setup() override
Definition: async_node.cc:124
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
Asynchronous node base class.
Definition: async_node.h:47
timed_frame_array_view begin_read(time_unit duration) override
Definition: async_node.cc:146
void pull(time_span span) override
Definition: async_node.cc:135
std::ptrdiff_t time_unit
Discrete time unit type.
Definition: common.h:52
node_output(const node_output &)=delete
void stop() finaloverride
Called by graph for all node, before destruction of any node.
Definition: async_node.cc:116
void launch() finaloverride
Called by graph for all nodes, before any frame is pulled from sink.
Definition: async_node.cc:107
void cancel_write_frame() override
Definition: async_node.cc:199
Node which delegates concrete frame processing to associated filter object.
Definition: filter_node.h:15
node_input & add_input(time_unit past_window, time_unit future_window) override
Definition: async_node.h:63
frame_view begin_write_frame(time_unit &t) override
Definition: async_node.cc:173
bool process_next_frame() override
Definition: async_node.cc:7
async_node_output & add_output(const frame_format &format) override
Definition: async_node.h:67
void end_write_frame(bool was_last_frame) override
Definition: async_node.cc:193
void end_read(time_unit duration) override
Definition: async_node.cc:163
time_unit end_time() const override
Definition: async_node.cc:168
One-dimensional time span.
Definition: common.h:61
void internal_setup() finaloverride
Called by propagate_setup_.
Definition: async_node.cc:101
~async_node()
Definition: async_node.cc:96
async_node(graph &)
Definition: async_node.cc:91
Definition: async_node.h:14
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
Format information of type-erased frame of ndarray_view_generic.
Definition: frame_format.h:14