2 * copyright (c) 2010 Sveriges Television AB <info@casparcg.com>
\r
4 * This file is part of CasparCG.
\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
20 #include "../../stdafx.h"
\r
22 #include "separated_producer.h"
\r
24 #include <core/producer/frame/basic_frame.h>
\r
26 namespace caspar { namespace core {
\r
28 struct separated_producer : public frame_producer
\r
30 safe_ptr<frame_producer> fill_producer_;
\r
31 safe_ptr<frame_producer> key_producer_;
\r
32 safe_ptr<basic_frame> fill_;
\r
33 safe_ptr<basic_frame> key_;
\r
34 safe_ptr<basic_frame> last_frame_;
\r
37 explicit separated_producer(const safe_ptr<frame_producer>& fill, const safe_ptr<frame_producer>& key)
\r
38 : fill_producer_(fill)
\r
39 , key_producer_(key)
\r
40 , fill_(core::basic_frame::late())
\r
41 , key_(core::basic_frame::late())
\r
42 , last_frame_(core::basic_frame::empty())
\r
47 virtual safe_ptr<basic_frame> receive(int hints)
\r
49 if(fill_ == core::basic_frame::late())
\r
50 fill_ = receive_and_follow(fill_producer_, hints);
\r
52 if(key_ == core::basic_frame::late())
\r
53 key_ = receive_and_follow(key_producer_, hints | ALPHA_HINT);
\r
55 if(fill_ == basic_frame::eof() || key_ == basic_frame::eof())
\r
56 return basic_frame::eof();
\r
58 if(fill_ == core::basic_frame::late() || key_ == core::basic_frame::late()) // One of the producers is lagging, keep them in sync.
\r
59 return core::basic_frame::late();
\r
61 auto frame = basic_frame::fill_and_key(fill_, key_);
\r
63 fill_ = basic_frame::late();
\r
64 key_ = basic_frame::late();
\r
66 return last_frame_ = frame;
\r
69 virtual safe_ptr<core::basic_frame> last_frame() const
\r
74 virtual std::wstring print() const
\r
76 return L"separated";
\r
79 virtual int64_t nb_frames() const
\r
81 return std::min(fill_producer_->nb_frames() > 0 ? fill_producer_->nb_frames() : std::numeric_limits<int64_t>::max(),
\r
82 key_producer_->nb_frames() > 0 ? key_producer_->nb_frames() : std::numeric_limits<int64_t>::max());
\r
86 safe_ptr<frame_producer> create_separated_producer(const safe_ptr<frame_producer>& fill, const safe_ptr<frame_producer>& key)
\r
88 return make_safe<separated_producer>(fill, key);
\r