]> git.sesse.net Git - casparcg/blob - core/producer/frame/basic_frame.cpp
Updated CHANGES.txt
[casparcg] / core / producer / frame / basic_frame.cpp
1 /*\r
2 * Copyright 2013 Sveriges Television AB http://casparcg.com/\r
3 *\r
4 * This file is part of CasparCG (www.casparcg.com).\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 * Author: Robert Nagy, ronag89@gmail.com\r
20 */\r
21 \r
22 #include "../../stdafx.h"\r
23 \r
24 #include "basic_frame.h"\r
25 \r
26 #include "frame_transform.h"\r
27 #include "../../video_format.h"\r
28 \r
29 #include <boost/foreach.hpp>\r
30 \r
31 namespace caspar { namespace core {\r
32                                                                                                                                                                                                                                                                                                                 \r
33 struct basic_frame::implementation\r
34 {               \r
35         std::vector<safe_ptr<basic_frame>> frames_;\r
36 \r
37         frame_transform frame_transform_;       \r
38 public:\r
39         implementation(const std::vector<safe_ptr<basic_frame>>& frames) : frames_(frames) \r
40         {\r
41         }\r
42         implementation(std::vector<safe_ptr<basic_frame>>&& frames) : frames_(std::move(frames))\r
43         {\r
44         }\r
45         implementation(safe_ptr<basic_frame>&& frame) \r
46         {\r
47                 frames_.push_back(std::move(frame));\r
48         }\r
49         implementation(const safe_ptr<basic_frame>& frame)              \r
50         { \r
51                 frames_.push_back(frame);\r
52         }\r
53 \r
54         int64_t get_and_record_age_millis(const basic_frame& self)\r
55         {\r
56                 int64_t result = 0;\r
57 \r
58                 BOOST_FOREACH(auto& frame, frames_)\r
59                 {\r
60                         if (is_concrete_frame(frame) && frame.get() != &self)\r
61                                 result = std::max(result, frame->get_and_record_age_millis());\r
62                 }\r
63 \r
64                 return result;\r
65         }\r
66         \r
67         void accept(basic_frame& self, frame_visitor& visitor)\r
68         {\r
69                 visitor.begin(self);\r
70                 BOOST_FOREACH(auto frame, frames_)\r
71                         frame->accept(visitor);\r
72                 visitor.end();\r
73         }       \r
74 };\r
75         \r
76 basic_frame::basic_frame() : impl_(new implementation(std::vector<safe_ptr<basic_frame>>())){}\r
77 basic_frame::basic_frame(const std::vector<safe_ptr<basic_frame>>& frames) : impl_(new implementation(frames)){}\r
78 basic_frame::basic_frame(const basic_frame& other) : impl_(new implementation(*other.impl_)){}\r
79 basic_frame::basic_frame(std::vector<safe_ptr<basic_frame>>&& frames) : impl_(new implementation(frames)){}\r
80 basic_frame::basic_frame(const safe_ptr<basic_frame>& frame) : impl_(new implementation(frame)){}\r
81 basic_frame::basic_frame(safe_ptr<basic_frame>&& frame)  : impl_(new implementation(std::move(frame))){}\r
82 basic_frame::basic_frame(basic_frame&& other) : impl_(std::move(other.impl_)){}\r
83 basic_frame& basic_frame::operator=(const basic_frame& other)\r
84 {\r
85         basic_frame temp(other);\r
86         temp.swap(*this);\r
87         return *this;\r
88 }\r
89 basic_frame& basic_frame::operator=(basic_frame&& other)\r
90 {\r
91         basic_frame temp(std::move(other));\r
92         temp.swap(*this);\r
93         return *this;\r
94 }\r
95 void basic_frame::swap(basic_frame& other){impl_.swap(other.impl_);}\r
96 \r
97 const frame_transform& basic_frame::get_frame_transform() const { return impl_->frame_transform_;}\r
98 frame_transform& basic_frame::get_frame_transform() { return impl_->frame_transform_;}\r
99 int64_t basic_frame::get_and_record_age_millis() { return impl_->get_and_record_age_millis(*this); }\r
100 void basic_frame::accept(frame_visitor& visitor){impl_->accept(*this, visitor);}\r
101 \r
102 safe_ptr<basic_frame> basic_frame::interlace(const safe_ptr<basic_frame>& frame1, const safe_ptr<basic_frame>& frame2, field_mode::type mode)\r
103 {                               \r
104         if(frame1 == basic_frame::eof() || frame2 == basic_frame::eof())\r
105                 return basic_frame::eof();\r
106 \r
107         if(frame1 == basic_frame::empty() && frame2 == basic_frame::empty())\r
108                 return basic_frame::empty();\r
109         \r
110         if(frame1 == frame2 || mode == field_mode::progressive)\r
111                 return frame2;\r
112 \r
113         auto my_frame1 = make_safe<basic_frame>(frame1);\r
114         auto my_frame2 = make_safe<basic_frame>(frame2);\r
115         if(mode == field_mode::upper)\r
116         {\r
117                 my_frame1->get_frame_transform().field_mode = field_mode::upper;        \r
118                 my_frame2->get_frame_transform().field_mode = field_mode::lower;        \r
119         }                                                                        \r
120         else                                                             \r
121         {                                                                        \r
122                 my_frame1->get_frame_transform().field_mode = field_mode::lower;        \r
123                 my_frame2->get_frame_transform().field_mode = field_mode::upper;        \r
124         }\r
125 \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 make_safe<basic_frame>(std::move(frames));\r
130 }\r
131 \r
132 safe_ptr<basic_frame> basic_frame::combine(const safe_ptr<basic_frame>& frame1, const safe_ptr<basic_frame>& frame2)\r
133 {       \r
134         if(frame1 == basic_frame::eof() || frame2 == basic_frame::eof())\r
135                 return basic_frame::eof();\r
136         \r
137         if(frame1 == basic_frame::empty() && frame2 == basic_frame::empty())\r
138                 return basic_frame::empty();\r
139 \r
140         std::vector<safe_ptr<basic_frame>> frames;\r
141         frames.push_back(frame1);\r
142         frames.push_back(frame2);\r
143         return make_safe<basic_frame>(std::move(frames));\r
144 }\r
145 \r
146 safe_ptr<basic_frame> basic_frame::fill_and_key(const safe_ptr<basic_frame>& fill, const safe_ptr<basic_frame>& key)\r
147 {       \r
148         if(fill == basic_frame::eof() || key == basic_frame::eof())\r
149                 return basic_frame::eof();\r
150 \r
151         if(fill == basic_frame::empty() || key == basic_frame::empty())\r
152                 return basic_frame::empty();\r
153 \r
154         std::vector<safe_ptr<basic_frame>> frames;\r
155         key->get_frame_transform().is_key = true;\r
156         frames.push_back(key);\r
157         frames.push_back(fill);\r
158         return make_safe<basic_frame>(std::move(frames));\r
159 }\r
160 \r
161 safe_ptr<basic_frame> disable_audio(const safe_ptr<basic_frame>& frame)\r
162 {\r
163         if(frame == basic_frame::empty())\r
164                 return frame;\r
165 \r
166         basic_frame frame2 = frame;\r
167         frame2.get_frame_transform().volume = 0.0;\r
168         return make_safe<basic_frame>(std::move(frame2));\r
169 }\r
170         \r
171 }}