]> git.sesse.net Git - casparcg/blob - core/producer/separated/separated_producer.cpp
2.1.0: -Simplified by removing auto deinterlacing for MIXER transforms.
[casparcg] / core / producer / separated / separated_producer.cpp
1 /*\r
2 * Copyright (c) 2011 Sveriges Television AB <info@casparcg.com>\r
3 *\r
4 * This file is part of CasparCG (www.casparcg.com).\r
5 *\r
6 * CasparCG is free software: you can redistribute it and/or modify\r
7 * it under the terms of the GNU General Public License as published by\r
8 * the Free Software Foundation, either version 3 of the License, or\r
9 * (at your option) any later version.\r
10 *\r
11 * CasparCG is distributed in the hope that it will be useful,\r
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
14 * GNU General Public License for more details.\r
15 *\r
16 * You should have received a copy of the GNU General Public License\r
17 * along with CasparCG. If not, see <http://www.gnu.org/licenses/>.\r
18 *\r
19 * Author: Robert Nagy, ronag89@gmail.com\r
20 */\r
21 \r
22 #include "../../stdafx.h"\r
23 \r
24 #include "separated_producer.h"\r
25 \r
26 #include <core/producer/frame_producer.h>\r
27 #include <core/frame/draw_frame.h>\r
28 #include <core/monitor/monitor.h>\r
29 \r
30 #include <tbb/parallel_invoke.h>\r
31 \r
32 namespace caspar { namespace core {     \r
33 \r
34 class separated_producer : public frame_producer\r
35 {               \r
36         monitor::basic_subject                  event_subject_;\r
37         monitor::basic_subject                  key_event_subject_;\r
38 \r
39         spl::shared_ptr<frame_producer> fill_producer_;\r
40         spl::shared_ptr<frame_producer> key_producer_;\r
41         draw_frame                                              fill_;\r
42         draw_frame                                              key_;\r
43         draw_frame                                              last_frame_;\r
44                         \r
45 public:\r
46         explicit separated_producer(const spl::shared_ptr<frame_producer>& fill, const spl::shared_ptr<frame_producer>& key) \r
47                 : key_event_subject_("keyer")           \r
48                 , fill_producer_(fill)\r
49                 , key_producer_(key)\r
50                 , fill_(core::draw_frame::late())\r
51                 , key_(core::draw_frame::late())\r
52                 , last_frame_(core::draw_frame::empty())\r
53         {\r
54                 CASPAR_LOG(info) << print() << L" Initialized";\r
55 \r
56                 key_event_subject_.subscribe(event_subject_);\r
57 \r
58                 key_producer_->subscribe(key_event_subject_);\r
59                 fill_producer_->subscribe(event_subject_);\r
60         }\r
61 \r
62         // frame_producer\r
63         \r
64         draw_frame receive() override\r
65         {\r
66                 tbb::parallel_invoke(\r
67                 [&]\r
68                 {\r
69                         if(fill_ == core::draw_frame::late())\r
70                                 fill_ = fill_producer_->receive();\r
71                 },\r
72                 [&]\r
73                 {\r
74                         if(key_ == core::draw_frame::late())\r
75                                 key_ = key_producer_->receive();\r
76                 });\r
77 \r
78                 if(fill_ == draw_frame::eof() || key_ == draw_frame::eof())\r
79                         return draw_frame::eof();\r
80 \r
81                 if(fill_ == core::draw_frame::late() || key_ == core::draw_frame::late()) // One of the producers is lagging, keep them in sync.\r
82                         return core::draw_frame::late();\r
83                 \r
84                 auto frame = draw_frame::mask(fill_, key_);\r
85 \r
86                 fill_ = draw_frame::late();\r
87                 key_  = draw_frame::late();\r
88                 \r
89                 if(frame != core::draw_frame::late())\r
90                         last_frame_ = frame;\r
91 \r
92                 return frame;\r
93         }\r
94 \r
95         draw_frame last_frame() const override\r
96         {\r
97                 return draw_frame::still(last_frame_);\r
98         }\r
99                 \r
100         uint32_t nb_frames() const override\r
101         {\r
102                 return std::min(fill_producer_->nb_frames(), key_producer_->nb_frames());\r
103         }\r
104 \r
105         std::wstring print() const override\r
106         {\r
107                 return L"separated[fill:" + fill_producer_->print() + L"|key[" + key_producer_->print() + L"]]";\r
108         }       \r
109 \r
110         boost::unique_future<std::wstring> call(const std::wstring& str) override\r
111         {\r
112                 key_producer_->call(str);\r
113                 return fill_producer_->call(str);\r
114         }\r
115 \r
116         std::wstring name() const override\r
117         {\r
118                 return L"separated";\r
119         }\r
120 \r
121         boost::property_tree::wptree info() const override\r
122         {\r
123                 return fill_producer_->info();;\r
124         }\r
125 \r
126         void subscribe(const monitor::observable::observer_ptr& o) override                                                                                                                     \r
127         {\r
128                 return event_subject_.subscribe(o);\r
129         }\r
130 \r
131         void unsubscribe(const monitor::observable::observer_ptr& o) override           \r
132         {\r
133                 return event_subject_.unsubscribe(o);\r
134         }\r
135 };\r
136 \r
137 spl::shared_ptr<frame_producer> create_separated_producer(const spl::shared_ptr<frame_producer>& fill, const spl::shared_ptr<frame_producer>& key)\r
138 {\r
139         return spl::make_shared<separated_producer>(fill, key);\r
140 }\r
141 \r
142 }}\r
143 \r