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 "gpu_write_frame.h"
\r
24 #include <core/producer/frame/pixel_format.h>
\r
26 #include "../image/image_mixer.h"
\r
27 #include "../audio/audio_mixer.h"
\r
29 #include "../gpu/host_buffer.h"
\r
31 #include <common/gl/gl_check.h>
\r
33 #include <boost/range/algorithm.hpp>
\r
35 namespace caspar { namespace mixer {
\r
37 struct gpu_write_frame::implementation : boost::noncopyable
\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
45 implementation(int tag, const core::pixel_format_desc& desc, const std::vector<safe_ptr<host_buffer>>& buffers)
\r
50 void accept(gpu_write_frame& self, core::frame_visitor& visitor)
\r
52 visitor.begin(self);
\r
53 visitor.visit(self);
\r
57 boost::iterator_range<unsigned char*> image_data(size_t index)
\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
65 const boost::iterator_range<const unsigned char*> image_data(size_t index) const
\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
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
79 gpu_write_frame temp(std::move(other));
\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
88 return boost::iterator_range<const unsigned char*>(impl_->image_data(index).begin(), impl_->image_data(index).end());
\r
90 const boost::iterator_range<const short*> gpu_write_frame::audio_data() const
\r
92 return boost::iterator_range<const short*>(impl_->audio_data_.data(), impl_->audio_data_.data() + impl_->audio_data_.size());
\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