1 #ifndef MF_FLOW_FILTER_H_
2 #define MF_FLOW_FILTER_H_
4 #include "../flow/node.h"
5 #include "../flow/node_job.h"
6 #include "../flow/filter_node.h"
7 #include "../queue/frame.h"
11 namespace mf {
namespace flow {
17 template<std::
size_t Dim,
typename Elem>
class port;
18 template<std::
size_t Dim,
typename Elem>
class input_port;
19 template<std::
size_t Dim,
typename Elem>
class output_port;
24 template<std::
size_t Dim,
typename Elem>
using input_type = input_port<Dim, Elem>;
25 template<std::
size_t Dim,
typename Elem>
using output_type = output_port<Dim, Elem>;
70 template<std::
size_t Dim,
typename Elem>
73 using elem_type = Elem;
74 constexpr
static std::size_t dimension = Dim;
80 static frame_format default_format() {
return frame_format::default_format<Elem>(); }
82 explicit port(
filter& filt) : filter_(filt) { }
83 port(
const port&) =
delete;
86 const filter& this_filter()
const {
return filter_; }
87 filter& this_filter() {
return filter_; }
91 template<std::
size_t Dim,
typename Elem>
92 class filter::output_port :
public filter::port<Dim, Elem> {
93 using base = filter::port<Dim, Elem>;
96 using frame_shape_type = ndsize<Dim>;
99 flow::node_output& node_output_;
100 frame_shape_type frame_shape_;
103 explicit output_port(
filter& filt) :
105 node_output_(filt.
this_node().add_output(base::default_format())) { }
107 node_output& this_node_output() {
return node_output_; }
108 std::ptrdiff_t index()
const {
return node_output_.index(); }
110 void define_frame_shape(
const frame_shape_type& shp) {
112 node_output_.define_frame_length(shp.product());
115 const frame_shape_type& frame_shape()
const {
return frame_shape_; }
119 template<std::
size_t Dim,
typename Elem>
120 class filter::input_port :
public filter::port<Dim, Elem> {
121 using base = filter::port<Dim, Elem>;
124 using frame_shape_type = ndsize<Dim>;
127 flow::node_input& node_input_;
128 const frame_shape_type* shp_=
nullptr;
133 node_input_(filt.
this_node().add_input(past_window, future_window)) { }
135 node_input& this_node_input() {
return node_input_; }
136 std::ptrdiff_t index()
const {
return node_input_.index(); }
138 void set_activated(
bool activated) {
139 node_input_.set_activated(activated);
142 bool is_activated() {
143 return node_input_.is_activated();
151 void connect(output_port<Dim, Elem>& output) {
152 node_input_.connect(output.this_node_output());
153 shp_ = &output.frame_shape();
157 const frame_shape_type& frame_shape()
const {
return *shp_; }
virtual void pre_process(node_job &)
Prepare for processing a frame.
Definition: filter.h:44
std::ptrdiff_t time_unit
Discrete time unit type.
Definition: common.h:52
bool reached_end() const noexcept
Definition: node.cc:141
const filter_node & this_node() const noexcept
Definition: filter.h:34
sink_filter(filter_node &nd)
Definition: filter.h:66
filter_node & this_node() noexcept
Definition: filter.h:33
input_port< Dim, Elem > input_type
Definition: filter.h:24
filter(filter_node &nd)
Definition: filter.h:28
Filter which performs concrete processing, base class.
Definition: filter.h:15
bool reached_end() const
Definition: filter.h:36
Node which delegates concrete frame processing to associated filter object.
Definition: filter_node.h:15
Source filter.
Definition: filter.h:53
source_filter(filter_node &nd, bool seekable=false, time_unit stream_duration=-1)
Definition: filter.h:55
void define_source_stream_properties(bool seekable, time_unit stream_duration=-1)
Definition: node.cc:70
filter & operator=(const filter &)=delete
Work unit of flow graph node.
Definition: node_job.h:13
Definition: filter_parameter.h:11
virtual ~filter()
Definition: filter.h:38
virtual void setup()
Set up the filter, called prior to any frame being processed.
Definition: filter.h:41
output_port< Dim, Elem > output_type
Definition: filter.h:25
Sink filter.
Definition: filter.h:64
virtual void process(node_job &)=0
Process a frame.