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 "../../monitor/monitor.h"
\r
26 #include "separated_producer.h"
\r
28 #include <core/producer/frame/basic_frame.h>
\r
30 #include <tbb/parallel_invoke.h>
\r
32 namespace caspar { namespace core {
\r
34 struct separated_producer : public frame_producer
\r
36 monitor::subject monitor_subject_;
\r
37 monitor::subject key_monitor_subject_;
\r
39 safe_ptr<frame_producer> fill_producer_;
\r
40 safe_ptr<frame_producer> key_producer_;
\r
41 safe_ptr<basic_frame> fill_;
\r
42 safe_ptr<basic_frame> key_;
\r
43 safe_ptr<basic_frame> last_frame_;
\r
45 explicit separated_producer(const safe_ptr<frame_producer>& fill, const safe_ptr<frame_producer>& key)
\r
46 : monitor_subject_("")
\r
47 , key_monitor_subject_("/keyer")
\r
48 , fill_producer_(fill)
\r
49 , key_producer_(key)
\r
50 , fill_(core::basic_frame::late())
\r
51 , key_(core::basic_frame::late())
\r
52 , last_frame_(core::basic_frame::empty())
\r
54 key_monitor_subject_.link_target(&monitor_subject_);
\r
56 key_producer_->monitor_output().link_target(&key_monitor_subject_);
\r
57 fill_producer_->monitor_output().link_target(&monitor_subject_);
\r
62 virtual safe_ptr<basic_frame> receive(int hints) override
\r
64 tbb::parallel_invoke(
\r
67 if(fill_ == core::basic_frame::late())
\r
68 fill_ = receive_and_follow(fill_producer_, hints);
\r
72 if(key_ == core::basic_frame::late())
\r
73 key_ = receive_and_follow(key_producer_, hints | ALPHA_HINT);
\r
76 if(fill_ == basic_frame::eof() || key_ == basic_frame::eof())
\r
77 return basic_frame::eof();
\r
79 if(fill_ == core::basic_frame::late() || key_ == core::basic_frame::late()) // One of the producers is lagging, keep them in sync.
\r
80 return core::basic_frame::late();
\r
82 auto frame = basic_frame::fill_and_key(fill_, key_);
\r
84 fill_ = basic_frame::late();
\r
85 key_ = basic_frame::late();
\r
87 return last_frame_ = frame;
\r
90 virtual safe_ptr<core::basic_frame> last_frame() const override
\r
92 return disable_audio(last_frame_);
\r
95 virtual safe_ptr<basic_frame> create_thumbnail_frame() override
\r
97 auto fill_frame = fill_producer_->create_thumbnail_frame();
\r
98 auto key_frame = key_producer_->create_thumbnail_frame();
\r
100 if (fill_frame == basic_frame::empty() || key_frame == basic_frame::empty())
\r
101 return basic_frame::empty();
\r
103 if (fill_frame == basic_frame::eof() || key_frame == basic_frame::eof())
\r
104 return basic_frame::eof();
\r
106 if (fill_frame == basic_frame::late() || key_frame == basic_frame::late())
\r
107 return basic_frame::late();
\r
109 return basic_frame::fill_and_key(fill_frame, key_frame);
\r
112 virtual uint32_t nb_frames() const override
\r
114 return std::min(fill_producer_->nb_frames(), key_producer_->nb_frames());
\r
117 virtual std::wstring print() const override
\r
119 return L"separated[fill:" + fill_producer_->print() + L"|key[" + key_producer_->print() + L"]]";
\r
122 boost::property_tree::wptree info() const override
\r
124 boost::property_tree::wptree info;
\r
125 info.add(L"type", L"separated-producer");
\r
126 info.add_child(L"fill.producer", fill_producer_->info());
\r
127 info.add_child(L"key.producer", key_producer_->info());
\r
131 monitor::source& monitor_output()
\r
133 return monitor_subject_;
\r
137 safe_ptr<frame_producer> create_separated_producer(const safe_ptr<frame_producer>& fill, const safe_ptr<frame_producer>& key)
\r
139 return create_producer_print_proxy(
\r
140 make_safe<separated_producer>(fill, key));
\r
143 safe_ptr<frame_producer> create_separated_thumbnail_producer(const safe_ptr<frame_producer>& fill, const safe_ptr<frame_producer>& key)
\r
145 return make_safe<separated_producer>(fill, key);
\r