2 * Copyright (c) 2011 Sveriges Television AB <info@casparcg.com>
\r
4 * This file is part of CasparCG (www.casparcg.com).
\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
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
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
19 * Author: Robert Nagy, ronag89@gmail.com
\r
22 #include "../../stdafx.h"
\r
24 #include "separated_producer.h"
\r
26 #include "../frame_producer.h"
\r
27 #include "../../frame/draw_frame.h"
\r
29 #include <tbb/parallel_invoke.h>
\r
31 namespace caspar { namespace core {
\r
33 struct separated_producer : public frame_producer
\r
35 safe_ptr<frame_producer> fill_producer_;
\r
36 safe_ptr<frame_producer> key_producer_;
\r
37 safe_ptr<draw_frame> fill_;
\r
38 safe_ptr<draw_frame> key_;
\r
39 safe_ptr<draw_frame> last_frame_;
\r
41 explicit separated_producer(const safe_ptr<frame_producer>& fill, const safe_ptr<frame_producer>& key)
\r
42 : fill_producer_(fill)
\r
43 , key_producer_(key)
\r
44 , fill_(core::draw_frame::late())
\r
45 , key_(core::draw_frame::late())
\r
46 , last_frame_(core::draw_frame::empty())
\r
52 virtual safe_ptr<draw_frame> receive(int flags) override
\r
54 tbb::parallel_invoke(
\r
57 if(fill_ == core::draw_frame::late())
\r
58 fill_ = receive_and_follow(fill_producer_, flags);
\r
62 if(key_ == core::draw_frame::late())
\r
63 key_ = receive_and_follow(key_producer_, flags | frame_producer::flags::alpha_only);
\r
66 if(fill_ == draw_frame::eof() || key_ == draw_frame::eof())
\r
67 return draw_frame::eof();
\r
69 if(fill_ == core::draw_frame::late() || key_ == core::draw_frame::late()) // One of the producers is lagging, keep them in sync.
\r
70 return core::draw_frame::late();
\r
72 auto frame = draw_frame::mask(fill_, key_);
\r
74 fill_ = draw_frame::late();
\r
75 key_ = draw_frame::late();
\r
77 return last_frame_ = frame;
\r
80 virtual safe_ptr<core::draw_frame> last_frame() const override
\r
85 virtual uint32_t nb_frames() const override
\r
87 return std::min(fill_producer_->nb_frames(), key_producer_->nb_frames());
\r
90 virtual std::wstring print() const override
\r
92 return L"separated[fill:" + fill_producer_->print() + L"|key[" + key_producer_->print() + L"]]";
\r
95 boost::property_tree::wptree info() const override
\r
97 boost::property_tree::wptree info;
\r
98 info.add(L"type", L"separated-producer");
\r
99 info.add_child(L"fill.producer", fill_producer_->info());
\r
100 info.add_child(L"key.producer", key_producer_->info());
\r
105 safe_ptr<frame_producer> create_separated_producer(const safe_ptr<frame_producer>& fill, const safe_ptr<frame_producer>& key)
\r
107 return make_safe<separated_producer>(fill, key);
\r