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 "basic_frame.h"
\r
24 #include "image_transform.h"
\r
25 #include "audio_transform.h"
\r
26 #include "pixel_format.h"
\r
27 #include "../../video_format.h"
\r
29 #include <boost/range/algorithm.hpp>
\r
31 namespace caspar { namespace core {
\r
33 struct basic_frame::implementation
\r
35 std::vector<safe_ptr<basic_frame>> frames_;
\r
37 image_transform image_transform_;
\r
38 audio_transform audio_transform_;
\r
40 core::video_mode::type mode_;
\r
43 implementation(const std::vector<safe_ptr<basic_frame>>& frames)
\r
44 : mode_(core::video_mode::progressive), frames_(frames) {}
\r
45 implementation(std::vector<safe_ptr<basic_frame>>&& frames)
\r
46 : mode_(core::video_mode::progressive), frames_(std::move(frames)){}
\r
47 implementation(safe_ptr<basic_frame>&& frame)
\r
48 : mode_(core::video_mode::progressive)
\r
49 { frames_.push_back(std::move(frame));}
\r
50 implementation(const safe_ptr<basic_frame>& frame)
\r
51 : mode_(core::video_mode::progressive)
\r
52 { frames_.push_back(frame);}
\r
54 void accept(basic_frame& self, frame_visitor& visitor)
\r
56 visitor.begin(self);
\r
57 BOOST_FOREACH(auto frame, frames_)
\r
58 frame->accept(visitor);
\r
62 std::wstring print() const
\r
64 std::wstring str = L"\tbasic_frame[\n";
\r
65 BOOST_FOREACH(auto& frame, frames_)
\r
66 str += frame->print() + L"\n";
\r
72 basic_frame::basic_frame() : impl_(new implementation(std::vector<safe_ptr<basic_frame>>())){}
\r
73 basic_frame::basic_frame(const std::vector<safe_ptr<basic_frame>>& frames) : impl_(new implementation(frames)){}
\r
74 basic_frame::basic_frame(const basic_frame& other) : impl_(new implementation(*other.impl_)){}
\r
75 basic_frame::basic_frame(std::vector<safe_ptr<basic_frame>>&& frames) : impl_(new implementation(frames)){}
\r
76 basic_frame::basic_frame(const safe_ptr<basic_frame>& frame) : impl_(new implementation(frame)){}
\r
77 basic_frame::basic_frame(safe_ptr<basic_frame>&& frame) : impl_(new implementation(std::move(frame))){}
\r
78 core::video_mode::type basic_frame::get_mode() const{return impl_->mode_;}
\r
79 void basic_frame::swap(basic_frame& other){impl_.swap(other.impl_);}
\r
80 basic_frame& basic_frame::operator=(const basic_frame& other)
\r
82 basic_frame temp(other);
\r
86 basic_frame::basic_frame(basic_frame&& other) : impl_(std::move(other.impl_)){}
\r
87 basic_frame& basic_frame::operator=(basic_frame&& other)
\r
89 basic_frame temp(std::move(other));
\r
93 void basic_frame::accept(frame_visitor& visitor){impl_->accept(*this, visitor);}
\r
95 const image_transform& basic_frame::get_image_transform() const { return impl_->image_transform_;}
\r
96 image_transform& basic_frame::get_image_transform() { return impl_->image_transform_;}
\r
97 const audio_transform& basic_frame::get_audio_transform() const { return impl_->audio_transform_;}
\r
98 audio_transform& basic_frame::get_audio_transform() { return impl_->audio_transform_;}
\r
100 std::wstring basic_frame::print() const{return impl_->print();}
\r
102 safe_ptr<basic_frame> basic_frame::interlace(const safe_ptr<basic_frame>& frame1, const safe_ptr<basic_frame>& frame2, video_mode::type mode)
\r
104 if(frame1 == basic_frame::empty() && frame2 == basic_frame::empty())
\r
105 return basic_frame::empty();
\r
107 if(frame1 == basic_frame::eof() || frame2 == basic_frame::eof())
\r
108 return basic_frame::eof();
\r
110 if(frame1 == frame2 || mode == video_mode::progressive)
\r
113 auto my_frame1 = make_safe<basic_frame>(frame1);
\r
114 auto my_frame2 = make_safe<basic_frame>(frame2);
\r
115 if(mode == video_mode::upper)
\r
117 my_frame1->impl_->mode_ = video_mode::upper;
\r
118 my_frame2->impl_->mode_ = video_mode::lower;
\r
122 my_frame1->impl_->mode_ = video_mode::lower;
\r
123 my_frame2->impl_->mode_ = video_mode::upper;
\r
126 std::vector<safe_ptr<basic_frame>> frames;
\r
127 frames.push_back(my_frame1);
\r
128 frames.push_back(my_frame2);
\r
129 return basic_frame(std::move(frames));
\r
132 safe_ptr<basic_frame> basic_frame::combine(const safe_ptr<basic_frame>& frame1, const safe_ptr<basic_frame>& frame2)
\r
134 if(frame1 == basic_frame::empty() && frame2 == basic_frame::empty())
\r
135 return basic_frame::empty();
\r
137 if(frame1 == basic_frame::eof() && frame2 == basic_frame::eof())
\r
138 return basic_frame::eof();
\r
140 std::vector<safe_ptr<basic_frame>> frames;
\r
141 frames.push_back(frame1);
\r
142 frames.push_back(frame2);
\r
143 return basic_frame(std::move(frames));
\r
146 safe_ptr<basic_frame> basic_frame::fill_and_key(const safe_ptr<basic_frame>& fill, const safe_ptr<basic_frame>& key)
\r
148 if(fill == basic_frame::empty() && key == basic_frame::empty())
\r
149 return basic_frame::empty();
\r
151 if(fill == basic_frame::eof() && key == basic_frame::eof())
\r
152 return basic_frame::eof();
\r
154 if(key == basic_frame::empty() || key == basic_frame::eof())
\r
157 std::vector<safe_ptr<basic_frame>> frames;
\r
158 key->get_image_transform().set_is_key(true);
\r
159 frames.push_back(key);
\r
160 frames.push_back(fill);
\r
161 return basic_frame(std::move(frames));
\r
164 safe_ptr<basic_frame> disable_audio(const safe_ptr<basic_frame>& frame)
\r
166 basic_frame frame2 = frame;
\r
167 frame2.get_audio_transform().set_has_audio(false);
\r
168 return std::move(frame2);
\r