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 "write_frame.h"
\r
24 #include <core/producer/frame/pixel_format.h>
\r
26 #include <common/gl/gl_check.h>
\r
28 #include <boost/range/algorithm.hpp>
\r
30 namespace caspar { namespace core {
\r
32 struct write_frame::implementation : boost::noncopyable
\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
40 implementation(int tag, const core::pixel_format_desc& desc, const std::vector<safe_ptr<host_buffer>>& buffers)
\r
45 void accept(write_frame& self, core::frame_visitor& visitor)
\r
47 visitor.begin(self);
\r
48 visitor.visit(self);
\r
52 boost::iterator_range<unsigned char*> image_data(size_t index)
\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
60 const boost::iterator_range<const unsigned char*> image_data(size_t index) const
\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
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
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
76 return boost::iterator_range<const unsigned char*>(impl_->image_data(index).begin(), impl_->image_data(index).end());
\r
78 const boost::iterator_range<const short*> write_frame::audio_data() const
\r
80 return boost::iterator_range<const short*>(impl_->audio_data_.data(), impl_->audio_data_.data() + impl_->audio_data_.size());
\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 std::vector<safe_ptr<host_buffer>>& write_frame::get_plane_buffers(){return impl_->buffers_;}
\r