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 "transition_producer.h"
\r
24 #include <core/video_format.h>
\r
26 #include <core/producer/frame/basic_frame.h>
\r
27 #include <core/producer/frame/frame_transform.h>
\r
29 #include <tbb/parallel_invoke.h>
\r
31 #include <boost/assign.hpp>
\r
33 using namespace boost::assign;
\r
35 namespace caspar { namespace core {
\r
37 struct transition_producer : public frame_producer
\r
39 const field_mode::type mode_;
\r
40 unsigned int current_frame_;
\r
42 const transition_info info_;
\r
44 safe_ptr<frame_producer> dest_producer_;
\r
45 safe_ptr<frame_producer> source_producer_;
\r
47 safe_ptr<basic_frame> last_frame_;
\r
49 explicit transition_producer(const field_mode::type& mode, const safe_ptr<frame_producer>& dest, const transition_info& info)
\r
53 , dest_producer_(dest)
\r
54 , source_producer_(frame_producer::empty())
\r
55 , last_frame_(basic_frame::empty()){}
\r
59 virtual safe_ptr<frame_producer> get_following_producer() const override
\r
61 return dest_producer_;
\r
64 virtual void set_leading_producer(const safe_ptr<frame_producer>& producer) override
\r
66 source_producer_ = producer;
\r
69 virtual safe_ptr<basic_frame> receive(int hints) override
\r
71 if(++current_frame_ >= info_.duration)
\r
72 return basic_frame::eof();
\r
74 auto dest = basic_frame::empty();
\r
75 auto source = basic_frame::empty();
\r
77 tbb::parallel_invoke(
\r
80 dest = receive_and_follow(dest_producer_, hints);
\r
81 if(dest == core::basic_frame::late())
\r
82 dest = dest_producer_->last_frame();
\r
86 source = receive_and_follow(source_producer_, hints);
\r
87 if(source == core::basic_frame::late())
\r
88 source = source_producer_->last_frame();
\r
91 return compose(dest, source);
\r
94 virtual safe_ptr<core::basic_frame> last_frame() const override
\r
96 return disable_audio(last_frame_);
\r
99 virtual int64_t nb_frames() const override
\r
101 return get_following_producer()->nb_frames();
\r
104 virtual std::wstring print() const override
\r
106 return L"transition[" + source_producer_->print() + L"|" + dest_producer_->print() + L"]";
\r
109 boost::property_tree::wptree info() const override
\r
111 boost::property_tree::wptree info;
\r
112 info.add(L"type", L"transition-producer");
\r
113 info.add_child(L"source.producer", source_producer_->info());
\r
114 info.add_child(L"destination.producer", dest_producer_->info());
\r
118 // transition_producer
\r
120 safe_ptr<basic_frame> compose(const safe_ptr<basic_frame>& dest_frame, const safe_ptr<basic_frame>& src_frame)
\r
122 if(info_.type == transition::cut)
\r
125 const double delta1 = info_.tweener(current_frame_*2-1, 0.0, 1.0, info_.duration*2);
\r
126 const double delta2 = info_.tweener(current_frame_*2, 0.0, 1.0, info_.duration*2);
\r
128 const double dir = info_.direction == transition_direction::from_left ? 1.0 : -1.0;
\r
130 // For interlaced transitions. Seperate fields into seperate frames which are transitioned accordingly.
\r
132 auto s_frame1 = make_safe<basic_frame>(src_frame);
\r
133 auto s_frame2 = make_safe<basic_frame>(src_frame);
\r
135 s_frame1->get_frame_transform().volume = 0.0;
\r
136 s_frame2->get_frame_transform().volume = 1.0-delta2;
\r
138 auto d_frame1 = make_safe<basic_frame>(dest_frame);
\r
139 auto d_frame2 = make_safe<basic_frame>(dest_frame);
\r
141 d_frame1->get_frame_transform().volume = 0.0;
\r
142 d_frame2->get_frame_transform().volume = delta2;
\r
144 if(info_.type == transition::mix)
\r
146 d_frame1->get_frame_transform().opacity = delta1;
\r
147 d_frame1->get_frame_transform().is_mix = true;
\r
148 d_frame2->get_frame_transform().opacity = delta2;
\r
149 d_frame2->get_frame_transform().is_mix = true;
\r
151 s_frame1->get_frame_transform().opacity = 1.0-delta1;
\r
152 s_frame1->get_frame_transform().is_mix = true;
\r
153 s_frame2->get_frame_transform().opacity = 1.0-delta2;
\r
154 s_frame2->get_frame_transform().is_mix = true;
\r
156 if(info_.type == transition::slide)
\r
158 d_frame1->get_frame_transform().fill_translation[0] = (-1.0+delta1)*dir;
\r
159 d_frame2->get_frame_transform().fill_translation[0] = (-1.0+delta2)*dir;
\r
161 else if(info_.type == transition::push)
\r
163 d_frame1->get_frame_transform().fill_translation[0] = (-1.0+delta1)*dir;
\r
164 d_frame2->get_frame_transform().fill_translation[0] = (-1.0+delta2)*dir;
\r
166 s_frame1->get_frame_transform().fill_translation[0] = (0.0+delta1)*dir;
\r
167 s_frame2->get_frame_transform().fill_translation[0] = (0.0+delta2)*dir;
\r
169 else if(info_.type == transition::wipe)
\r
171 d_frame1->get_frame_transform().clip_scale[0] = delta1;
\r
172 d_frame2->get_frame_transform().clip_scale[0] = delta2;
\r
175 const auto s_frame = s_frame1->get_frame_transform() == s_frame2->get_frame_transform() ? s_frame2 : basic_frame::interlace(s_frame1, s_frame2, mode_);
\r
176 const auto d_frame = d_frame1->get_frame_transform() == d_frame2->get_frame_transform() ? d_frame2 : basic_frame::interlace(d_frame1, d_frame2, mode_);
\r
178 last_frame_ = basic_frame::combine(s_frame2, d_frame2);
\r
180 return basic_frame::combine(s_frame, d_frame);
\r
184 safe_ptr<frame_producer> create_transition_producer(const field_mode::type& mode, const safe_ptr<frame_producer>& destination, const transition_info& info)
\r
186 return make_safe<transition_producer>(mode, destination, info);
\r