]> git.sesse.net Git - casparcg/blob - core/producer/frame/basic_frame.cpp
git-svn-id: https://casparcg.svn.sourceforge.net/svnroot/casparcg/server/branches...
[casparcg] / core / producer / frame / basic_frame.cpp
1 /*\r
2 * copyright (c) 2010 Sveriges Television AB <info@casparcg.com>\r
3 *\r
4 *  This file is part of CasparCG.\r
5 *\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
10 *\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
15 \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
18 *\r
19 */\r
20 #include "../../stdafx.h"\r
21 \r
22 #include "basic_frame.h"\r
23 \r
24 #include "image_transform.h"\r
25 #include "audio_transform.h"\r
26 #include "../../video_format.h"\r
27 \r
28 #include <boost/foreach.hpp>\r
29 \r
30 namespace caspar { namespace core {\r
31                                                                                                                                                                                                                                                                                                                 \r
32 struct basic_frame::implementation\r
33 {               \r
34         std::vector<safe_ptr<basic_frame>> frames_;\r
35 \r
36         image_transform image_transform_;       \r
37         audio_transform audio_transform_;\r
38 \r
39         core::video_mode::type mode_;\r
40         \r
41 public:\r
42         implementation(const std::vector<safe_ptr<basic_frame>>& frames) \r
43                 : mode_(core::video_mode::progressive), frames_(frames) \r
44         {\r
45         }\r
46         implementation(std::vector<safe_ptr<basic_frame>>&& frames) \r
47                 : mode_(core::video_mode::progressive), frames_(std::move(frames))\r
48         {\r
49         }\r
50         implementation(safe_ptr<basic_frame>&& frame) \r
51                 : mode_(core::video_mode::progressive)\r
52         {\r
53                 frames_.push_back(std::move(frame));\r
54         }\r
55         implementation(const safe_ptr<basic_frame>& frame) \r
56                 : mode_(core::video_mode::progressive)          \r
57         { \r
58                 frames_.push_back(frame);\r
59         }\r
60         \r
61         void accept(basic_frame& self, frame_visitor& visitor)\r
62         {\r
63                 visitor.begin(self);\r
64                 BOOST_FOREACH(auto frame, frames_)\r
65                         frame->accept(visitor);\r
66                 visitor.end();\r
67         }       \r
68 \r
69         std::wstring print() const\r
70         {\r
71                 std::wstring str = L"\tbasic_frame[\n";\r
72                 BOOST_FOREACH(auto& frame, frames_)\r
73                         str += frame->print() + L"\n";\r
74                 str += L"\n]";\r
75                 return str;\r
76         }\r
77 };\r
78         \r
79 basic_frame::basic_frame() : impl_(new implementation(std::vector<safe_ptr<basic_frame>>())){}\r
80 basic_frame::basic_frame(const std::vector<safe_ptr<basic_frame>>& frames) : impl_(new implementation(frames)){}\r
81 basic_frame::basic_frame(const basic_frame& other) : impl_(new implementation(*other.impl_)){}\r
82 basic_frame::basic_frame(std::vector<safe_ptr<basic_frame>>&& frames) : impl_(new implementation(frames)){}\r
83 basic_frame::basic_frame(const safe_ptr<basic_frame>& frame) : impl_(new implementation(frame)){}\r
84 basic_frame::basic_frame(safe_ptr<basic_frame>&& frame)  : impl_(new implementation(std::move(frame))){}\r
85 basic_frame::basic_frame(basic_frame&& other) : impl_(std::move(other.impl_)){}\r
86 basic_frame& basic_frame::operator=(const basic_frame& other)\r
87 {\r
88         basic_frame temp(other);\r
89         temp.swap(*this);\r
90         return *this;\r
91 }\r
92 basic_frame& basic_frame::operator=(basic_frame&& other)\r
93 {\r
94         basic_frame temp(std::move(other));\r
95         temp.swap(*this);\r
96         return *this;\r
97 }\r
98 void basic_frame::swap(basic_frame& other){impl_.swap(other.impl_);}\r
99 \r
100 core::video_mode::type basic_frame::get_mode() const{return impl_->mode_;}\r
101 const image_transform& basic_frame::get_image_transform() const { return impl_->image_transform_;}\r
102 image_transform& basic_frame::get_image_transform() { return impl_->image_transform_;}\r
103 const audio_transform& basic_frame::get_audio_transform() const { return impl_->audio_transform_;}\r
104 audio_transform& basic_frame::get_audio_transform() { return impl_->audio_transform_;}\r
105 \r
106 std::wstring basic_frame::print() const{return impl_->print();}\r
107 void basic_frame::accept(frame_visitor& visitor){impl_->accept(*this, visitor);}\r
108 \r
109 safe_ptr<basic_frame> basic_frame::interlace(const safe_ptr<basic_frame>& frame1, const safe_ptr<basic_frame>& frame2, video_mode::type mode)\r
110 {                       \r
111         if(frame1 == basic_frame::empty() && frame2 == basic_frame::empty())\r
112                 return basic_frame::empty();\r
113         \r
114         if(frame1 == basic_frame::eof() || frame2 == basic_frame::eof())\r
115                 return basic_frame::eof();\r
116         \r
117         if(frame1 == frame2 || mode == video_mode::progressive)\r
118                 return frame2;\r
119 \r
120         auto my_frame1 = make_safe<basic_frame>(frame1);\r
121         auto my_frame2 = make_safe<basic_frame>(frame2);\r
122         if(mode == video_mode::upper)\r
123         {\r
124                 my_frame1->impl_->mode_ = video_mode::upper;    \r
125                 my_frame2->impl_->mode_ = video_mode::lower;    \r
126         }                                                                                        \r
127         else                                                                             \r
128         {                                                                                        \r
129                 my_frame1->impl_->mode_ = video_mode::lower;    \r
130                 my_frame2->impl_->mode_ = video_mode::upper;    \r
131         }\r
132 \r
133         std::vector<safe_ptr<basic_frame>> frames;\r
134         frames.push_back(my_frame1);\r
135         frames.push_back(my_frame2);\r
136         return basic_frame(std::move(frames));\r
137 }\r
138 \r
139 safe_ptr<basic_frame> basic_frame::combine(const safe_ptr<basic_frame>& frame1, const safe_ptr<basic_frame>& frame2)\r
140 {\r
141         if(frame1 == basic_frame::empty() && frame2 == basic_frame::empty())\r
142                 return basic_frame::empty();\r
143         \r
144         if(frame1 == basic_frame::eof() && frame2 == basic_frame::eof())\r
145                 return basic_frame::eof();\r
146         \r
147         std::vector<safe_ptr<basic_frame>> frames;\r
148         frames.push_back(frame1);\r
149         frames.push_back(frame2);\r
150         return basic_frame(std::move(frames));\r
151 }\r
152 \r
153 safe_ptr<basic_frame> basic_frame::fill_and_key(const safe_ptr<basic_frame>& fill, const safe_ptr<basic_frame>& key)\r
154 {       \r
155         if(fill == basic_frame::eof() || key == basic_frame::eof())\r
156                 return basic_frame::eof();\r
157 \r
158         if(fill == basic_frame::empty() || key == basic_frame::empty())\r
159                 return basic_frame::empty();\r
160 \r
161         std::vector<safe_ptr<basic_frame>> frames;\r
162         key->get_image_transform().set_is_key(true);\r
163         frames.push_back(key);\r
164         frames.push_back(fill);\r
165         return basic_frame(std::move(frames));\r
166 }\r
167 \r
168 safe_ptr<basic_frame> disable_audio(const safe_ptr<basic_frame>& frame)\r
169 {\r
170         basic_frame frame2 = frame;\r
171         frame2.get_audio_transform().set_has_audio(false);\r
172         return std::move(frame2);\r
173 }\r
174         \r
175 }}