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
\r
61 return dest_producer_;
\r
64 virtual void set_leading_producer(const safe_ptr<frame_producer>& producer)
\r
66 source_producer_ = producer;
\r
69 virtual safe_ptr<basic_frame> receive(int hints)
\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
\r
96 return disable_audio(last_frame_);
\r
99 virtual int64_t nb_frames() const
\r
101 return get_following_producer()->nb_frames();
\r
104 virtual std::wstring print() const
\r
106 return L"transition[" + source_producer_->print() + L"|" + dest_producer_->print() + L"]";
\r
109 // transition_producer
\r
111 safe_ptr<basic_frame> compose(const safe_ptr<basic_frame>& dest_frame, const safe_ptr<basic_frame>& src_frame)
\r
113 if(info_.type == transition::cut)
\r
116 const double delta1 = info_.tweener(current_frame_*2-1, 0.0, 1.0, info_.duration*2);
\r
117 const double delta2 = info_.tweener(current_frame_*2, 0.0, 1.0, info_.duration*2);
\r
119 const double dir = info_.direction == transition_direction::from_left ? 1.0 : -1.0;
\r
121 // For interlaced transitions. Seperate fields into seperate frames which are transitioned accordingly.
\r
123 auto s_frame1 = make_safe<basic_frame>(src_frame);
\r
124 auto s_frame2 = make_safe<basic_frame>(src_frame);
\r
126 s_frame1->get_frame_transform().volume = 0.0;
\r
127 s_frame2->get_frame_transform().volume = 1.0-delta2;
\r
129 auto d_frame1 = make_safe<basic_frame>(dest_frame);
\r
130 auto d_frame2 = make_safe<basic_frame>(dest_frame);
\r
132 d_frame1->get_frame_transform().volume = 0.0;
\r
133 d_frame2->get_frame_transform().volume = delta2;
\r
135 //if(info_.type == transition::mix)
\r
137 // d_frame1->get_frame_transform().set_opacity(delta1);
\r
138 // d_frame2->get_frame_transform().set_opacity(delta2);
\r
140 // s_frame1->get_frame_transform().set_opacity(1.0-delta1);
\r
141 // s_frame2->get_frame_transform().set_opacity(1.0-delta2);
\r
143 if(info_.type == transition::slide)
\r
145 d_frame1->get_frame_transform().fill_translation[0] = (-1.0+delta1)*dir;
\r
146 d_frame2->get_frame_transform().fill_translation[0] = (-1.0+delta2)*dir;
\r
148 else if(info_.type == transition::push)
\r
150 d_frame1->get_frame_transform().fill_translation[0] = (-1.0+delta1)*dir;
\r
151 d_frame2->get_frame_transform().fill_translation[0] = (-1.0+delta2)*dir;
\r
153 s_frame1->get_frame_transform().fill_translation[0] = (0.0+delta1)*dir;
\r
154 s_frame2->get_frame_transform().fill_translation[0] = (0.0+delta2)*dir;
\r
156 else if(info_.type == transition::wipe)
\r
158 d_frame1->get_frame_transform().clip_scale[0] = delta1;
\r
159 d_frame2->get_frame_transform().clip_scale[0] = delta2;
\r
162 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
163 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
165 last_frame_ = basic_frame::combine(s_frame2, d_frame2);
\r
167 return basic_frame::combine(s_frame, d_frame);
\r
171 safe_ptr<frame_producer> create_transition_producer(const field_mode::type& mode, const safe_ptr<frame_producer>& destination, const transition_info& info)
\r
173 return make_safe<transition_producer>(mode, destination, info);
\r