]> git.sesse.net Git - casparcg/blob - core/video_channel.cpp
git-svn-id: https://casparcg.svn.sourceforge.net/svnroot/casparcg/server/branches...
[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 "mixer/write_frame.h"\r
32 #include "producer/stage.h"\r
33 #include "producer/frame/frame_factory.h"\r
34 \r
35 #include <common/diagnostics/graph.h>\r
36 #include <common/env.h>\r
37 \r
38 #include <boost/property_tree/ptree.hpp>\r
39 \r
40 #include <string>\r
41 \r
42 namespace caspar { namespace core {\r
43 \r
44 struct video_channel::impl sealed : public frame_factory\r
45 {\r
46         const int                                                               index_;\r
47         video_format_desc                                               format_desc_;\r
48         const safe_ptr<ogl_device>                              ogl_;\r
49         const safe_ptr<diagnostics::graph>              graph_;\r
50 \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
54         \r
55 public:\r
56         impl(int index, const video_format_desc& format_desc, const safe_ptr<ogl_device>& ogl)  \r
57                 : index_(index)\r
58                 , format_desc_(format_desc)\r
59                 , ogl_(ogl)\r
60                 , output_(new caspar::core::output(graph_, format_desc, index))\r
61                 , mixer_(new caspar::core::mixer(output_, graph_, format_desc, ogl))\r
62                 , stage_(new caspar::core::stage(mixer_, graph_, format_desc))  \r
63         {\r
64                 graph_->set_text(print());\r
65                 diagnostics::register_graph(graph_);\r
66 \r
67                 for(int n = 0; n < std::max(1, env::properties().get(L"configuration.pipeline-tokens", 2)); ++n)\r
68                         stage_->spawn_token();\r
69 \r
70                 CASPAR_LOG(info) << print() << " Successfully Initialized.";\r
71         }\r
72 \r
73         // frame_factory\r
74                                                 \r
75         virtual safe_ptr<write_frame> create_frame(const void* tag, const core::pixel_format_desc& desc) override\r
76         {               \r
77                 return make_safe<write_frame>(ogl_, tag, desc);\r
78         }\r
79         \r
80         virtual core::video_format_desc get_video_format_desc() const override\r
81         {\r
82                 return format_desc_;\r
83         }\r
84         \r
85         // video_channel\r
86 \r
87         void set_video_format_desc(const video_format_desc& format_desc)\r
88         {\r
89                 if(format_desc.format == core::video_format::invalid)\r
90                         BOOST_THROW_EXCEPTION(invalid_argument() << msg_info("Invalid video-format"));\r
91 \r
92                 try\r
93                 {\r
94                         output_->set_video_format_desc(format_desc);\r
95                         mixer_->set_video_format_desc(format_desc);\r
96                         stage_->set_video_format_desc(format_desc);\r
97                         ogl_->gc();\r
98                 }\r
99                 catch(...)\r
100                 {\r
101                         output_->set_video_format_desc(format_desc_);\r
102                         mixer_->set_video_format_desc(format_desc_);\r
103                         stage_->set_video_format_desc(format_desc_);\r
104                         throw;\r
105                 }\r
106                 format_desc_ = format_desc;\r
107         }\r
108                 \r
109         std::wstring print() const\r
110         {\r
111                 return L"video_channel[" + boost::lexical_cast<std::wstring>(index_) + L"|" +  format_desc_.name + L"]";\r
112         }\r
113 \r
114         boost::property_tree::wptree info() const\r
115         {\r
116                 boost::property_tree::wptree info;\r
117 \r
118                 auto stage_info  = stage_->info();\r
119                 auto mixer_info  = mixer_->info();\r
120                 auto output_info = output_->info();\r
121 \r
122                 stage_info.timed_wait(boost::posix_time::seconds(2));\r
123                 mixer_info.timed_wait(boost::posix_time::seconds(2));\r
124                 output_info.timed_wait(boost::posix_time::seconds(2));\r
125                 \r
126                 info.add(L"video-mode", format_desc_.name);\r
127                 info.add_child(L"stage", stage_info.get());\r
128                 info.add_child(L"mixer", mixer_info.get());\r
129                 info.add_child(L"output", output_info.get());\r
130    \r
131                 return info;                       \r
132         }\r
133 };\r
134 \r
135 video_channel::video_channel(int index, const video_format_desc& format_desc, const safe_ptr<ogl_device>& ogl) : impl_(new impl(index, format_desc, ogl)){}\r
136 safe_ptr<stage> video_channel::stage() { return impl_->stage_;} \r
137 safe_ptr<mixer> video_channel::mixer() { return impl_->mixer_;} \r
138 safe_ptr<frame_factory> video_channel::frame_factory() { return impl_;} \r
139 safe_ptr<output> video_channel::output() { return impl_->output_;} \r
140 video_format_desc video_channel::get_video_format_desc() const{return impl_->format_desc_;}\r
141 void video_channel::set_video_format_desc(const video_format_desc& format_desc){impl_->set_video_format_desc(format_desc);}\r
142 boost::property_tree::wptree video_channel::info() const{return impl_->info();}\r
143 int video_channel::index() const {return impl_->index_;}\r
144 \r
145 }}