Debian Codegraph @

src/filter/delay0r/delay0r.cpp

raw symbols SCIP
1 #include "frei0r.hpp"
2
3 #include <algorithm>
4 #include <vector>
5 #include <utility>
6 #include <cassert>
7
8 class delay0r : public frei0r::filter
9 {
10 public:
11 delay0r(unsigned int width, unsigned int height)
12 {
13 delay = 0.0;
14 register_param(delay,"DelayTime","the delay time");
15 }
16
17 ~delay0r()
18 {
19 for (std::list< std::pair< double, unsigned int* > >::iterator i=buffer.begin(); i != buffer.end(); )
20 {
21 delete[] i->second;
22 i=buffer.erase(i);
23 }
24 }
25
26 virtual void update(double time,
27 uint32_t* out,
28 const uint32_t* in)
29 {
30 unsigned int* reusable = 0;
31 // remove old frames
32 for (std::list< std::pair< double, unsigned int* > >::iterator i=buffer.begin(); i != buffer.end(); )
33 {
34 if (i->first < (time - delay) || i->first >= time)
35 {
36 // remove me
37 if (reusable != 0)
38 delete[] i->second;
39 else
40 reusable = i->second;
41
42 i=buffer.erase(i);
43 }
44 else
45 {
46 ++i;
47 }
48 }
49
50 // add new frame
51 if (reusable == 0)
52 reusable = new unsigned int[width*height];
53
54 std::copy(in, in+width*height,reusable);
55 buffer.push_back(std::make_pair(time,reusable));
56
57 // copy best
58 unsigned int* best_data=0;
59 double best_time=0;
60
61 assert (buffer.size() >0);
62 for (std::list< std::pair< double, unsigned int* > >::iterator i=buffer.begin(); i != buffer.end(); ++i)
63 {
64 if (best_data==0 || (i->first < best_time))
65 {
66 best_time=i->first;
67 best_data=i->second;
68 }
69 }
70
71 assert(best_data != 0);
72 std::copy(best_data,best_data+width*height,out);
73 }
74
75 private:
76 double delay;
77 std::list< std::pair< double, unsigned int* > > buffer;
78 };
79
80
81 frei0r::construct<delay0r> plugin("delay0r",
82 "video delay",
83 "Martin Bayer",
84 0,2);
85