]> 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) 2010 Sveriges Television AB <info@casparcg.com>\r
3 *\r
4 *  This file is part of CasparCG.\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 */\r
20 \r
21 #include "StdAfx.h"\r
22 \r
23 #include "video_channel.h"\r
24 \r
25 #include "video_format.h"\r
26 \r
27 #include "consumer/output.h"\r
28 #include "mixer/mixer.h"\r
29 #include "producer/stage.h"\r
30 \r
31 #include <common/concurrency/executor.h>\r
32 #include <common/diagnostics/graph.h>\r
33 \r
34 #include "mixer/gpu/ogl_device.h"\r
35 \r
36 #include <agents_extras.h>\r
37 \r
38 #include <boost/timer.hpp>\r
39 \r
40 #ifdef _MSC_VER\r
41 #pragma warning(disable : 4355)\r
42 #endif\r
43 \r
44 namespace caspar { namespace core {\r
45 \r
46 struct video_channel::implementation : boost::noncopyable\r
47 {\r
48         Concurrency::unbounded_buffer<safe_ptr<message<std::map<int, safe_ptr<basic_frame>>>>>  stage_frames_;\r
49         Concurrency::unbounded_buffer<safe_ptr<message<safe_ptr<read_frame>>>>                                  mixer_frames_;\r
50         \r
51         const video_format_desc format_desc_;\r
52 \r
53         safe_ptr<caspar::core::output>                  output_;\r
54         std::shared_ptr<caspar::core::mixer>    mixer_;\r
55         safe_ptr<caspar::core::stage>                   stage_;\r
56 \r
57         safe_ptr<diagnostics::graph>    graph_;\r
58         boost::timer                                    frame_timer_;\r
59         boost::timer                                    tick_timer_;\r
60         boost::timer                                    output_timer_;\r
61         \r
62 public:\r
63         implementation(int index, const video_format_desc& format_desc, ogl_device& ogl)  \r
64                 : graph_(diagnostics::create_graph(narrow(print()), false))\r
65                 , format_desc_(format_desc)\r
66                 , output_(new caspar::core::output(mixer_frames_, format_desc))\r
67                 , mixer_(new caspar::core::mixer(stage_frames_, mixer_frames_, format_desc, ogl))\r
68                 , stage_(new caspar::core::stage(stage_frames_))        \r
69         {\r
70                 graph_->add_guide("produce-time", 0.5f);        \r
71                 graph_->set_color("produce-time", diagnostics::color(0.0f, 1.0f, 0.0f));\r
72                 graph_->set_color("tick-time", diagnostics::color(0.0f, 0.6f, 0.9f));   \r
73                 graph_->set_color("output-time", diagnostics::color(1.0f, 0.5f, 0.0f));\r
74                 graph_->set_color("mix-time", diagnostics::color(1.0f, 1.0f, 0.9f));\r
75                 graph_->start();\r
76 \r
77                 CASPAR_LOG(info) << print() << " Successfully Initialized.";\r
78         }\r
79         \r
80         //void tick()\r
81         //{\r
82         //      try\r
83         //      {\r
84         //              // Produce\r
85 \r
86         //              frame_timer_.restart();\r
87 \r
88         //              auto simple_frames = stage_->execute();\r
89 \r
90         //              graph_->update_value("produce-time", frame_timer_.elapsed()*context_.get_format_desc().fps*0.5);\r
91         //      \r
92         //              // Mix\r
93 \r
94         //              frame_timer_.restart();\r
95 \r
96         //              auto finished_frame = mixer_->execute(simple_frames);\r
97         //      \r
98         //              graph_->update_value("mix-time", frame_timer_.elapsed()*context_.get_format_desc().fps*0.5);\r
99         //      \r
100         //              // Consume\r
101         //      \r
102         //              output_timer_.restart();\r
103 \r
104         //              output_->execute(finished_frame);\r
105         //      \r
106         //              graph_->update_value("output-time", frame_timer_.elapsed()*context_.get_format_desc().fps*0.5);\r
107 \r
108         //      \r
109         //              graph_->update_value("tick-time", tick_timer_.elapsed()*context_.get_format_desc().fps*0.5);\r
110         //              tick_timer_.restart();\r
111         //      }\r
112         //      catch(...)\r
113         //      {\r
114         //              CASPAR_LOG_CURRENT_EXCEPTION();\r
115         //              CASPAR_LOG(error) << context_.print() << L" Unexpected exception. Clearing stage and freeing memory";\r
116         //              restart();\r
117         //      }\r
118 \r
119         //      context_.execution().begin_invoke([this]{tick();});\r
120         //}\r
121 \r
122         //void restart()\r
123         //{\r
124         //      stage_->clear();\r
125         //      context_.ogl().gc().wait();\r
126 \r
127         //      mixer_ = nullptr;\r
128         //      mixer_.reset(new caspar::core::mixer(context_));\r
129         //}\r
130                 \r
131         std::wstring print() const\r
132         {\r
133                 return L"video_channel";\r
134         }\r
135 \r
136         //void set_video_format_desc(const video_format_desc& format_desc)\r
137         //{\r
138         //      context_.execution().begin_invoke([=]\r
139         //      {\r
140         //              stage_->clear();\r
141         //              context_.ogl().gc().wait();\r
142         //              context_.set_format_desc(format_desc);\r
143         //      });\r
144         //}\r
145 };\r
146 \r
147 video_channel::video_channel(int index, const video_format_desc& format_desc, ogl_device& ogl) : impl_(new implementation(index, format_desc, ogl)){}\r
148 video_channel::video_channel(video_channel&& other) : impl_(std::move(other.impl_)){}\r
149 safe_ptr<stage> video_channel::stage() { return impl_->stage_;} \r
150 safe_ptr<mixer> video_channel::mixer() { return make_safe_ptr(impl_->mixer_);} \r
151 safe_ptr<output> video_channel::output() { return impl_->output_;} \r
152 video_format_desc video_channel::get_video_format_desc() const{return impl_->format_desc_;}\r
153 std::wstring video_channel::print() const { return impl_->print();}\r
154 \r
155 }}