2 * Copyright 2013 Sveriges Television AB http://casparcg.com/
\r
4 * This file is part of CasparCG (www.casparcg.com).
\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
19 * Author: Robert Nagy, ronag89@gmail.com
\r
24 #include "video_channel.h"
\r
26 #include "video_format.h"
\r
28 #include "consumer/output.h"
\r
29 #include "mixer/mixer.h"
\r
30 #include "mixer/gpu/ogl_device.h"
\r
31 #include "mixer/audio/audio_util.h"
\r
32 #include "producer/stage.h"
\r
34 #include <common/diagnostics/graph.h>
\r
35 #include <common/env.h>
\r
37 #include <boost/property_tree/ptree.hpp>
\r
41 namespace caspar { namespace core {
\r
43 struct video_channel::implementation : boost::noncopyable
\r
45 video_channel& self_;
\r
47 video_format_desc format_desc_;
\r
48 const safe_ptr<ogl_device> ogl_;
\r
49 const safe_ptr<diagnostics::graph> graph_;
\r
51 const safe_ptr<caspar::core::output> output_;
\r
52 const safe_ptr<caspar::core::mixer> mixer_;
\r
53 const safe_ptr<caspar::core::stage> stage_;
\r
55 safe_ptr<monitor::subject> monitor_subject_;
\r
58 implementation(video_channel& self, int index, const video_format_desc& format_desc, const safe_ptr<ogl_device>& ogl, const channel_layout& audio_channel_layout)
\r
61 , format_desc_(format_desc)
\r
63 , output_(new caspar::core::output(graph_, format_desc, index))
\r
64 , mixer_(new caspar::core::mixer(graph_, output_, format_desc, ogl, audio_channel_layout))
\r
65 , stage_(new caspar::core::stage(graph_, mixer_, format_desc))
\r
66 , monitor_subject_(make_safe<monitor::subject>("/channel/" + boost::lexical_cast<std::string>(index)))
\r
68 graph_->set_text(print());
\r
69 diagnostics::register_graph(graph_);
\r
71 for(int n = 0; n < std::max(1, env::properties().get(L"configuration.pipeline-tokens", 2)); ++n)
\r
72 stage_->spawn_token();
\r
74 stage_->monitor_output().attach_parent(monitor_subject_);
\r
76 CASPAR_LOG(info) << print() << " Successfully Initialized.";
\r
79 void set_video_format_desc(const video_format_desc& format_desc)
\r
81 if(format_desc.format == core::video_format::invalid)
\r
82 BOOST_THROW_EXCEPTION(invalid_argument() << msg_info("Invalid video-format"));
\r
86 output_->set_video_format_desc(format_desc);
\r
87 mixer_->set_video_format_desc(format_desc);
\r
88 stage_->set_video_format_desc(format_desc);
\r
93 output_->set_video_format_desc(format_desc_);
\r
94 mixer_->set_video_format_desc(format_desc_);
\r
95 stage_->set_video_format_desc(format_desc_);
\r
98 format_desc_ = format_desc;
\r
101 std::wstring print() const
\r
103 return L"video_channel[" + boost::lexical_cast<std::wstring>(index_) + L"|" + format_desc_.name + L"]";
\r
106 boost::property_tree::wptree info() const
\r
108 boost::property_tree::wptree info;
\r
110 auto stage_info = stage_->info();
\r
111 auto mixer_info = mixer_->info();
\r
112 auto output_info = output_->info();
\r
114 info.add(L"video-mode", format_desc_.name);
\r
116 if (stage_info.timed_wait(boost::posix_time::seconds(2)))
\r
117 info.add_child(L"stage", stage_info.get());
\r
119 if (mixer_info.timed_wait(boost::posix_time::seconds(2)))
\r
120 info.add_child(L"mixer", mixer_info.get());
\r
122 if (output_info.timed_wait(boost::posix_time::seconds(2)))
\r
123 info.add_child(L"output", output_info.get());
\r
128 boost::property_tree::wptree delay_info() const
\r
130 boost::property_tree::wptree info;
\r
132 auto stage_info = stage_->delay_info();
\r
133 auto mixer_info = mixer_->delay_info();
\r
134 auto output_info = output_->delay_info();
\r
136 if (stage_info.timed_wait(boost::posix_time::seconds(2)))
\r
137 info.add_child(L"layers", stage_info.get());
\r
139 if (mixer_info.timed_wait(boost::posix_time::seconds(2)))
\r
140 info.add_child(L"mix-time", mixer_info.get());
\r
142 if (output_info.timed_wait(boost::posix_time::seconds(2)))
\r
143 info.add_child(L"consumers", output_info.get());
\r
149 video_channel::video_channel(int index, const video_format_desc& format_desc, const safe_ptr<ogl_device>& ogl, const channel_layout& audio_channel_layout)
\r
150 : impl_(new implementation(*this, index, format_desc, ogl, audio_channel_layout)){}
\r
151 safe_ptr<stage> video_channel::stage() { return impl_->stage_;}
\r
152 safe_ptr<mixer> video_channel::mixer() { return impl_->mixer_;}
\r
153 safe_ptr<output> video_channel::output() { return impl_->output_;}
\r
154 video_format_desc video_channel::get_video_format_desc() const{return impl_->format_desc_;}
\r
155 void video_channel::set_video_format_desc(const video_format_desc& format_desc){impl_->set_video_format_desc(format_desc);}
\r
156 boost::property_tree::wptree video_channel::info() const{return impl_->info();}
\r
157 int video_channel::index() const {return impl_->index_;}
\r
158 monitor::subject& video_channel::monitor_output(){return *impl_->monitor_subject_;}
\r
159 boost::property_tree::wptree video_channel::delay_info() const { return impl_->delay_info(); }
\r