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