mf
Media Framework
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
importer.h
Go to the documentation of this file.
1 #ifndef MF_IMPORTER_FILTER_H_
2 #define MF_IMPORTER_FILTER_H_
3 
4 #include <utility>
5 #include "filter.h"
6 #include "../io/frame_importer.h"
7 #include "../io/seekable_frame_importer.h"
8 
9 namespace mf { namespace flow {
10 
12 template<typename Importer, typename = void>
14  static_assert(! Importer::is_seekable, "Importer must not be seekable");
15 
16 private:
17  Importer importer_;
18 
19 public:
21 
22  template<typename... Args>
23  explicit importer_filter(filter_node& nd, Args&&... args) :
24  source_filter(nd, false),
25  importer_(std::forward<Args>(args)...),
26  output(*this) { }
27 
28  void setup() override {
29  output.define_frame_shape(importer_.frame_shape());
30  }
31 
32  void process(node_job& job) override {
33  auto out = job.out(output);
34  return importer_.read_frame(out);
35  if(importer_.reached_end()) job.mark_end();
36  }
37 };
38 
39 
41 template<typename Importer>
42 class importer_filter<Importer, std::enable_if_t<Importer::is_seekable>> : public source_filter {
43  static_assert(Importer::is_seekable, "Importer must be seekable");
44 
45 private:
46  Importer importer_;
47 
48 public:
50 
51  template<typename... Args>
52  explicit importer_filter(filter_node& nd, Args&&... args) :
53  source_filter(nd, false),
54  importer_(std::forward<Args>(args)...),
55  output(*this)
56  {
57  set_seekable(true);
58  }
59 
60  void set_seekable(bool seekable) {
61  if(seekable) this_node().define_source_stream_properties(true, importer_.total_duration());
63  }
64 
65  void setup() override {
66  output.define_frame_shape(importer_.frame_shape());
67  }
68 
69  void pre_process(node_job& job) override {
70  time_unit t = job.time();
71  if(importer_.current_time() != t) importer_.seek(t);
72  }
73 
74  void process(node_job& job) override {
75  MF_ASSERT(importer_.current_time() == t);
76  auto out = job.out(output);
77  return importer_.read_frame(out);
78  }
79 };
80 
81 
82 }}
83 
84 #endif
importer_filter(filter_node &nd, Args &&...args)
Definition: importer.h:23
void pre_process(node_job &job) override
Prepare for processing a frame.
Definition: importer.h:69
std::ptrdiff_t time_unit
Discrete time unit type.
Definition: common.h:52
decltype(auto) out(Output &)
filter_node & this_node() noexcept
Definition: filter.h:33
void setup() override
Set up the filter, called prior to any frame being processed.
Definition: importer.h:28
Node which delegates concrete frame processing to associated filter object.
Definition: filter_node.h:15
Source filter.
Definition: filter.h:53
output_type< Importer::dimension, typename Importer::elem_type > output
Definition: importer.h:20
importer_filter(filter_node &nd, Args &&...args)
Definition: importer.h:52
void setup() override
Set up the filter, called prior to any frame being processed.
Definition: importer.h:65
time_unit time() const noexcept
Definition: node_job.h:42
void define_source_stream_properties(bool seekable, time_unit stream_duration=-1)
Definition: node.cc:70
Work unit of flow graph node.
Definition: node_job.h:13
Importer source filter, reads frames from associated frame_importer.
Definition: importer.h:13
void mark_end()
Definition: node_job.h:43
output_type< Importer::dimension, typename Importer::elem_type > output
Definition: importer.h:49
output_port< Dim, Elem > output_type
Definition: filter.h:25
#define MF_ASSERT(condition)
Definition: common.h:24
void process(node_job &job) override
Process a frame.
Definition: importer.h:32
void process(node_job &job) override
Process a frame.
Definition: importer.h:74