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 <core/producer/frame_producer.h>
\r
27 #include <core/frame/draw_frame.h>
\r
28 #include <core/monitor/monitor.h>
\r
30 #include <tbb/parallel_invoke.h>
\r
32 namespace caspar { namespace core {
\r
34 class separated_producer : public frame_producer
\r
36 monitor::basic_subject event_subject_;
\r
37 monitor::basic_subject key_event_subject_;
\r
39 spl::shared_ptr<frame_producer> fill_producer_;
\r
40 spl::shared_ptr<frame_producer> key_producer_;
\r
43 draw_frame last_frame_;
\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
54 CASPAR_LOG(info) << print() << L" Initialized";
\r
56 key_event_subject_.subscribe(event_subject_);
\r
58 key_producer_->subscribe(key_event_subject_);
\r
59 fill_producer_->subscribe(event_subject_);
\r
64 draw_frame receive() override
\r
66 tbb::parallel_invoke(
\r
69 if(fill_ == core::draw_frame::late())
\r
70 fill_ = fill_producer_->receive();
\r
74 if(key_ == core::draw_frame::late())
\r
75 key_ = key_producer_->receive();
\r
78 if(fill_ == draw_frame::eof() || key_ == draw_frame::eof())
\r
79 return draw_frame::eof();
\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
84 auto frame = draw_frame::mask(fill_, key_);
\r
86 fill_ = draw_frame::late();
\r
87 key_ = draw_frame::late();
\r
89 if(frame != core::draw_frame::late())
\r
90 last_frame_ = frame;
\r
95 draw_frame last_frame() const override
\r
97 return draw_frame::still(last_frame_);
\r
100 uint32_t nb_frames() const override
\r
102 return std::min(fill_producer_->nb_frames(), key_producer_->nb_frames());
\r
105 std::wstring print() const override
\r
107 return L"separated[fill:" + fill_producer_->print() + L"|key[" + key_producer_->print() + L"]]";
\r
110 boost::unique_future<std::wstring> call(const std::wstring& str) override
\r
112 key_producer_->call(str);
\r
113 return fill_producer_->call(str);
\r
116 std::wstring name() const override
\r
118 return L"separated";
\r
121 boost::property_tree::wptree info() const override
\r
123 return fill_producer_->info();;
\r
126 void subscribe(const monitor::observable::observer_ptr& o) override
\r
128 return event_subject_.subscribe(o);
\r
131 void unsubscribe(const monitor::observable::observer_ptr& o) override
\r
133 return event_subject_.unsubscribe(o);
\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
139 return spl::make_shared<separated_producer>(fill, key);
\r