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
23 #include "video_channel.h"
\r
25 #include "video_channel_context.h"
\r
27 #include "video_format.h"
\r
28 #include "producer/layer.h"
\r
30 #include <common/concurrency/executor.h>
\r
31 #include <common/diagnostics/graph.h>
\r
33 #include <boost/range/algorithm_ext/erase.hpp>
\r
34 #include <boost/timer.hpp>
\r
37 #pragma warning(disable : 4355)
\r
40 namespace caspar { namespace core {
\r
42 struct video_channel::implementation : boost::noncopyable
\r
44 video_channel_context context_;
\r
46 safe_ptr<frame_consumer_device> consumer_;
\r
47 safe_ptr<frame_mixer_device> mixer_;
\r
48 safe_ptr<frame_producer_device> producer_;
\r
50 safe_ptr<diagnostics::graph> diag_;
\r
51 boost::timer frame_timer_;
\r
52 boost::timer tick_timer_;
\r
55 implementation(int index, const video_format_desc& format_desc, ogl_device& ogl)
\r
56 : context_(index, ogl, format_desc)
\r
57 , diag_(diagnostics::create_graph(narrow(print())))
\r
58 , consumer_(new frame_consumer_device(context_))
\r
59 , mixer_(new frame_mixer_device(context_))
\r
60 , producer_(new frame_producer_device(context_))
\r
62 diag_->add_guide("produce-time", 0.5f);
\r
63 diag_->set_color("produce-time", diagnostics::color(1.0f, 0.0f, 0.0f));
\r
64 diag_->add_guide("mix-time", 0.5f);
\r
65 diag_->set_color("mix-time", diagnostics::color(1.0f, 0.0f, 1.0f));
\r
66 diag_->add_guide("consume-time", 0.5f);
\r
67 diag_->set_color("consume-time", diagnostics::color(1.0f, 1.0f, 0.0f));
\r
68 diag_->set_color("tick-time", diagnostics::color(0.1f, 0.7f, 0.8f));
\r
70 CASPAR_LOG(info) << print() << " Successfully Initialized.";
\r
71 context_.execution().begin_invoke([this]{tick();});
\r
76 // Stop context before destroying devices.
\r
77 context_.execution().stop();
\r
78 context_.execution().join();
\r
79 context_.destruction().stop();
\r
80 context_.destruction().join();
\r
87 frame_timer_.restart();
\r
89 auto simple_frames = producer_->execute();
\r
91 diag_->update_value("produce-time", frame_timer_.elapsed()*context_.get_format_desc().fps*0.5);
\r
95 frame_timer_.restart();
\r
97 auto finished_frame = mixer_->execute(simple_frames);
\r
99 diag_->update_value("mix-time", frame_timer_.elapsed()*context_.get_format_desc().fps*0.5);
\r
103 frame_timer_.restart();
\r
105 consumer_->execute(finished_frame);
\r
107 diag_->update_value("consume-time", frame_timer_.elapsed()*context_.get_format_desc().fps*0.5);
\r
111 diag_->update_value("tick-time", tick_timer_.elapsed()*context_.get_format_desc().fps*0.5);
\r
112 tick_timer_.restart();
\r
114 context_.execution().begin_invoke([this]{tick();});
\r
117 std::wstring print() const
\r
119 return context_.print();
\r
122 void set_video_format_desc(const video_format_desc& format_desc)
\r
124 context_.execution().begin_invoke([=]
\r
126 context_.set_format_desc(format_desc);
\r
131 video_channel::video_channel(int index, const video_format_desc& format_desc, ogl_device& ogl) : impl_(new implementation(index, format_desc, ogl)){}
\r
132 video_channel::video_channel(video_channel&& other) : impl_(std::move(other.impl_)){}
\r
133 safe_ptr<frame_producer_device> video_channel::producer() { return impl_->producer_;}
\r
134 safe_ptr<frame_mixer_device> video_channel::mixer() { return impl_->mixer_;}
\r
135 safe_ptr<frame_consumer_device> video_channel::consumer() { return impl_->consumer_;}
\r
136 video_format_desc video_channel::get_video_format_desc() const{return impl_->context_.get_format_desc();}
\r
137 void video_channel::set_video_format_desc(const video_format_desc& format_desc){impl_->set_video_format_desc(format_desc);}
\r
138 std::wstring video_channel::print() const { return impl_->print();}
\r