]> git.sesse.net Git - casparcg/blob - core/mixer/gpu/gpu_write_frame.cpp
2.0.0.2: Merged mixer into core/mixer.
[casparcg] / core / mixer / gpu / gpu_write_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 "gpu_write_frame.h"\r
23 \r
24 #include <core/producer/frame/pixel_format.h>\r
25 \r
26 #include "../image/image_mixer.h"\r
27 #include "../audio/audio_mixer.h"\r
28 \r
29 #include "../gpu/host_buffer.h"\r
30 \r
31 #include <common/gl/gl_check.h>\r
32 \r
33 #include <boost/range/algorithm.hpp>\r
34 \r
35 namespace caspar { namespace mixer {\r
36                                                                                                                                                                                                                                                                                                                         \r
37 struct gpu_write_frame::implementation : boost::noncopyable\r
38 {                               \r
39         std::vector<safe_ptr<host_buffer>> buffers_;\r
40         std::vector<short> audio_data_;\r
41         const core::pixel_format_desc desc_;\r
42         int tag_;\r
43 \r
44 public:\r
45         implementation(int tag, const core::pixel_format_desc& desc, const std::vector<safe_ptr<host_buffer>>& buffers) \r
46                 : desc_(desc)\r
47                 , buffers_(buffers)\r
48                 , tag_(tag){}\r
49         \r
50         void accept(gpu_write_frame& self, core::frame_visitor& visitor)\r
51         {\r
52                 visitor.begin(self);\r
53                 visitor.visit(self);\r
54                 visitor.end();\r
55         }\r
56 \r
57         boost::iterator_range<unsigned char*> image_data(size_t index)\r
58         {\r
59                 if(index >= buffers_.size() || !buffers_[index]->data())\r
60                         return boost::iterator_range<const unsigned char*>();\r
61                 auto ptr = static_cast<unsigned char*>(buffers_[index]->data());\r
62                 return boost::iterator_range<unsigned char*>(ptr, ptr+buffers_[index]->size());\r
63         }\r
64 \r
65         const boost::iterator_range<const unsigned char*> image_data(size_t index) const\r
66         {\r
67                 if(index >= buffers_.size() || !buffers_[index]->data())\r
68                         return boost::iterator_range<const unsigned char*>();\r
69                 auto ptr = static_cast<const unsigned char*>(buffers_[index]->data());\r
70                 return boost::iterator_range<const unsigned char*>(ptr, ptr+buffers_[index]->size());\r
71         }\r
72 };\r
73         \r
74 gpu_write_frame::gpu_write_frame(int tag, const core::pixel_format_desc& desc, const std::vector<safe_ptr<host_buffer>>& buffers) : impl_(new implementation(tag, desc, buffers)){}\r
75 gpu_write_frame::gpu_write_frame(gpu_write_frame&& other) : impl_(std::move(other.impl_)){}\r
76 void gpu_write_frame::swap(gpu_write_frame& other){impl_.swap(other.impl_);}\r
77 gpu_write_frame& gpu_write_frame::operator=(gpu_write_frame&& other)\r
78 {\r
79         gpu_write_frame temp(std::move(other));\r
80         temp.swap(*this);\r
81         return *this;\r
82 }\r
83 void gpu_write_frame::accept(core::frame_visitor& visitor){impl_->accept(*this, visitor);}\r
84 boost::iterator_range<unsigned char*> gpu_write_frame::image_data(size_t index){return impl_->image_data(index);}\r
85 std::vector<short>& gpu_write_frame::audio_data() { return impl_->audio_data_; }\r
86 const boost::iterator_range<const unsigned char*> gpu_write_frame::image_data(size_t index) const\r
87 {\r
88         return boost::iterator_range<const unsigned char*>(impl_->image_data(index).begin(), impl_->image_data(index).end());\r
89 }\r
90 const boost::iterator_range<const short*> gpu_write_frame::audio_data() const\r
91 {\r
92         return boost::iterator_range<const short*>(impl_->audio_data_.data(), impl_->audio_data_.data() + impl_->audio_data_.size());\r
93 }\r
94 int gpu_write_frame::tag() const {return impl_->tag_;}\r
95 const core::pixel_format_desc& gpu_write_frame::get_pixel_format_desc() const{return impl_->desc_;}\r
96 std::vector<safe_ptr<host_buffer>>& gpu_write_frame::get_plane_buffers(){return impl_->buffers_;}\r
97 }}