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/image_transform.h>
\r
28 #include <core/producer/frame/audio_transform.h>
\r
30 namespace caspar { namespace core {
\r
32 struct transition_producer : public frame_producer
\r
34 const video_format_desc format_desc_;
\r
35 uint32_t current_frame_;
\r
37 const transition_info info_;
\r
39 safe_ptr<frame_producer> dest_producer_;
\r
40 safe_ptr<frame_producer> source_producer_;
\r
42 transition_producer(const video_format_desc& format_desc, const safe_ptr<frame_producer>& dest, const transition_info& info)
\r
43 : format_desc_(format_desc)
\r
46 , dest_producer_(dest)
\r
47 , source_producer_(frame_producer::empty()){}
\r
49 safe_ptr<frame_producer> get_following_producer() const
\r
51 return dest_producer_;
\r
54 void set_leading_producer(const safe_ptr<frame_producer>& producer)
\r
56 source_producer_ = producer;
\r
59 safe_ptr<basic_frame> receive()
\r
61 if(current_frame_++ >= info_.duration)
\r
62 return basic_frame::eof();
\r
64 auto source = basic_frame::empty();
\r
65 auto dest = basic_frame::empty();
\r
67 tbb::parallel_invoke
\r
69 [&]{dest = receive_and_follow(dest_producer_);},
\r
70 [&]{source = receive_and_follow(source_producer_);}
\r
73 return compose(dest, source);
\r
76 safe_ptr<basic_frame> compose(const safe_ptr<basic_frame>& dest_frame, const safe_ptr<basic_frame>& src_frame)
\r
78 if(dest_frame == basic_frame::eof() && src_frame == basic_frame::eof())
\r
79 return basic_frame::eof();
\r
81 if(info_.type == transition::cut)
\r
84 double delta1 = info_.tweener(current_frame_*2-1, 0.0, 1.0, info_.duration*2);
\r
85 double delta2 = info_.tweener(current_frame_*2, 0.0, 1.0, info_.duration*2);
\r
87 double dir = info_.direction == transition_direction::from_left ? 1.0 : -1.0;
\r
89 // For interlaced transitions. Seperate fields into seperate frames which are transitioned accordingly.
\r
91 auto s_frame1 = make_safe<basic_frame>(src_frame);
\r
92 auto s_frame2 = make_safe<basic_frame>(src_frame);
\r
94 s_frame1->get_audio_transform().set_has_audio(false);
\r
95 s_frame2->get_audio_transform().set_gain(1.0-delta2);
\r
97 auto d_frame1 = make_safe<basic_frame>(dest_frame);
\r
98 auto d_frame2 = make_safe<basic_frame>(dest_frame);
\r
100 d_frame1->get_audio_transform().set_has_audio(false);
\r
101 d_frame2->get_audio_transform().set_gain(delta2);
\r
103 if(info_.type == transition::mix)
\r
105 d_frame1->get_image_transform().set_opacity(delta1);
\r
106 d_frame2->get_image_transform().set_opacity(delta2);
\r
108 else if(info_.type == transition::slide)
\r
110 d_frame1->get_image_transform().set_fill_translation((-1.0+delta1)*dir, 0.0);
\r
111 d_frame2->get_image_transform().set_fill_translation((-1.0+delta2)*dir, 0.0);
\r
113 else if(info_.type == transition::push)
\r
115 d_frame1->get_image_transform().set_fill_translation((-1.0+delta1)*dir, 0.0);
\r
116 d_frame2->get_image_transform().set_fill_translation((-1.0+delta2)*dir, 0.0);
\r
118 s_frame1->get_image_transform().set_fill_translation((0.0+delta1)*dir, 0.0);
\r
119 s_frame2->get_image_transform().set_fill_translation((0.0+delta2)*dir, 0.0);
\r
121 else if(info_.type == transition::wipe)
\r
123 d_frame1->get_image_transform().set_key_scale(delta1, 1.0);
\r
124 d_frame2->get_image_transform().set_key_scale(delta2, 1.0);
\r
127 auto s_frame = s_frame1->get_image_transform() == s_frame2->get_image_transform() ? s_frame2 : basic_frame::interlace(s_frame1, s_frame2, format_desc_.mode);
\r
128 auto d_frame = basic_frame::interlace(d_frame1, d_frame2, format_desc_.mode);
\r
130 return basic_frame(s_frame, d_frame);
\r
133 std::wstring print() const
\r
135 return L"transition";
\r
139 safe_ptr<frame_producer> create_transition_producer(const video_format_desc& format_desc, const safe_ptr<frame_producer>& destination, const transition_info& info)
\r
141 return make_safe<transition_producer>(format_desc, destination, info);
\r