]> git.sesse.net Git - casparcg/blob - core/channel.cpp
80e2d02d6e2e4004abcd81d1b211d5668d4c48c4
[casparcg] / core / 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 "channel.h"\r
24 \r
25 #include "channel_context.h"\r
26 \r
27 #include "video_format.h"\r
28 #include "producer/layer.h"\r
29 \r
30 #include <common/concurrency/executor.h>\r
31 \r
32 #include <boost/range/algorithm_ext/erase.hpp>\r
33 \r
34 #ifdef _MSC_VER\r
35 #pragma warning(disable : 4355)\r
36 #endif\r
37 \r
38 namespace caspar { namespace core {\r
39 \r
40 struct channel::implementation : boost::noncopyable\r
41 {\r
42         channel_context                                                 context_;\r
43 \r
44         safe_ptr<frame_consumer_device> consumer_;\r
45         safe_ptr<frame_mixer_device>    mixer_;\r
46         safe_ptr<frame_producer_device> producer_;\r
47         \r
48 public:\r
49         implementation(int index, const video_format_desc& format_desc, ogl_device& ogl)  \r
50                 : context_(index, ogl, format_desc)\r
51                 , consumer_(new frame_consumer_device(context_))\r
52                 , mixer_(new frame_mixer_device(context_))\r
53                 , producer_(new frame_producer_device(context_))        \r
54         {\r
55                 CASPAR_LOG(info) << print() << " Successfully Initialized.";\r
56                 context_.execution.begin_invoke([this]{tick();});\r
57         }\r
58 \r
59         ~implementation()\r
60         {\r
61                 // Stop context before destroying devices.\r
62                 context_.execution.stop();\r
63                 context_.execution.join();\r
64                 context_.destruction.stop();\r
65                 context_.destruction.join();\r
66         }\r
67 \r
68         void tick()\r
69         {\r
70                 auto simple_frames = producer_->receive();\r
71                 mixer_->send(simple_frames);\r
72                 auto finished_frame = mixer_->receive();\r
73                 consumer_->send(finished_frame);\r
74 \r
75                 context_.execution.begin_invoke([this]{tick();});\r
76         }\r
77                 \r
78         std::wstring print() const\r
79         {\r
80                 return context_.print();\r
81         }\r
82 \r
83         void set_video_format_desc(const video_format_desc& format_desc)\r
84         {\r
85                 context_.execution.begin_invoke([=]\r
86                 {\r
87                         context_.format_desc = format_desc;\r
88                 });\r
89         }\r
90 };\r
91 \r
92 channel::channel(int index, const video_format_desc& format_desc, ogl_device& ogl) : impl_(new implementation(index, format_desc, ogl)){}\r
93 channel::channel(channel&& other) : impl_(std::move(other.impl_)){}\r
94 safe_ptr<frame_producer_device> channel::producer() { return impl_->producer_;} \r
95 safe_ptr<frame_mixer_device> channel::mixer() { return impl_->mixer_;} \r
96 safe_ptr<frame_consumer_device> channel::consumer() { return impl_->consumer_;} \r
97 const video_format_desc& channel::get_video_format_desc() const{return impl_->context_.format_desc;}\r
98 void channel::set_video_format_desc(const video_format_desc& format_desc){impl_->set_video_format_desc(format_desc);}\r
99 std::wstring channel::print() const { return impl_->print();}\r
100 \r
101 }}