]> git.sesse.net Git - casparcg/blob - core/video_channel.cpp
2.0.2: - Updated to use std::wstring more consistently.
[casparcg] / core / video_channel.cpp
1 /*\r
2 * Copyright (c) 2011 Sveriges Television AB <info@casparcg.com>\r
3 *\r
4 * This file is part of CasparCG (www.casparcg.com).\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 * Author: Robert Nagy, ronag89@gmail.com\r
20 */\r
21 \r
22 #include "StdAfx.h"\r
23 \r
24 #include "video_channel.h"\r
25 \r
26 #include "video_format.h"\r
27 \r
28 #include "consumer/output.h"\r
29 #include "mixer/mixer.h"\r
30 #include "mixer/gpu/ogl_device.h"\r
31 #include "producer/stage.h"\r
32 \r
33 #include <common/diagnostics/graph.h>\r
34 #include <common/env.h>\r
35 \r
36 #include <boost/property_tree/ptree.hpp>\r
37 \r
38 #include <string>\r
39 \r
40 namespace caspar { namespace core {\r
41 \r
42 struct video_channel::implementation : boost::noncopyable\r
43 {\r
44         const int                                               index_;\r
45         video_format_desc                               format_desc_;\r
46         const safe_ptr<ogl_device>              ogl_;\r
47         safe_ptr<diagnostics::graph>    graph_;\r
48 \r
49         safe_ptr<caspar::core::output>  output_;\r
50         safe_ptr<caspar::core::mixer>   mixer_;\r
51         safe_ptr<caspar::core::stage>   stage_;\r
52         \r
53 public:\r
54         implementation(int index, const video_format_desc& format_desc, const safe_ptr<ogl_device>& ogl)  \r
55                 : index_(index)\r
56                 , format_desc_(format_desc)\r
57                 , ogl_(ogl)\r
58                 , output_(new caspar::core::output(graph_, format_desc, index))\r
59                 , mixer_(new caspar::core::mixer(graph_, output_, format_desc, ogl))\r
60                 , stage_(new caspar::core::stage(graph_, mixer_, format_desc))  \r
61         {\r
62                 graph_->set_text(print());\r
63                 diagnostics::register_graph(graph_);\r
64 \r
65                 for(int n = 0; n < std::max(1, env::properties().get(L"configuration.pipeline-tokens", 2)); ++n)\r
66                         stage_->spawn_token();\r
67 \r
68                 CASPAR_LOG(info) << print() << " Successfully Initialized.";\r
69         }\r
70         \r
71         void set_video_format_desc(const video_format_desc& format_desc)\r
72         {\r
73                 try\r
74                 {\r
75                         output_->set_video_format_desc(format_desc);\r
76                         mixer_->set_video_format_desc(format_desc);\r
77                         ogl_->gc();\r
78                 }\r
79                 catch(...)\r
80                 {\r
81                         output_->set_video_format_desc(format_desc_);\r
82                         mixer_->set_video_format_desc(format_desc_);\r
83                         throw;\r
84                 }\r
85                 format_desc_ = format_desc;\r
86         }\r
87                 \r
88         std::wstring print() const\r
89         {\r
90                 return L"video_channel[" + boost::lexical_cast<std::wstring>(index_) + L"|" +  format_desc_.name + L"]";\r
91         }\r
92 \r
93         boost::property_tree::wptree info() const\r
94         {\r
95                 boost::property_tree::wptree info;\r
96 \r
97                 auto stage_info  = stage_->info();\r
98                 auto mixer_info  = mixer_->info();\r
99                 auto output_info = output_->info();\r
100 \r
101                 stage_info.timed_wait(boost::posix_time::seconds(2));\r
102                 mixer_info.timed_wait(boost::posix_time::seconds(2));\r
103                 output_info.timed_wait(boost::posix_time::seconds(2));\r
104                 \r
105                 info.add(L"video-mode", format_desc_.name);\r
106                 info.add_child(L"stage", stage_info.get());\r
107                 info.add_child(L"mixer", mixer_info.get());\r
108                 info.add_child(L"output", output_info.get());\r
109    \r
110                 return info;                       \r
111         }\r
112 };\r
113 \r
114 video_channel::video_channel(int index, const video_format_desc& format_desc, const safe_ptr<ogl_device>& ogl) : impl_(new implementation(index, format_desc, ogl)){}\r
115 safe_ptr<stage> video_channel::stage() { return impl_->stage_;} \r
116 safe_ptr<mixer> video_channel::mixer() { return impl_->mixer_;} \r
117 safe_ptr<output> video_channel::output() { return impl_->output_;} \r
118 video_format_desc video_channel::get_video_format_desc() const{return impl_->format_desc_;}\r
119 void video_channel::set_video_format_desc(const video_format_desc& format_desc){impl_->set_video_format_desc(format_desc);}\r
120 boost::property_tree::wptree video_channel::info() const{return impl_->info();}\r
121 \r
122 }}