]> git.sesse.net Git - casparcg/blob - core/video_channel.cpp
2.0.0.2: Fixed data race in video_channel_context.
[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_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 video_channel::implementation : boost::noncopyable\r
41 {\r
42         video_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_)();\r
71                 auto finished_frame = (*mixer_)(simple_frames);\r
72                 (*consumer_)(finished_frame);\r
73 \r
74                 context_.execution().begin_invoke([this]{tick();});\r
75         }\r
76                 \r
77         std::wstring print() const\r
78         {\r
79                 return context_.print();\r
80         }\r
81 \r
82         void set_video_format_desc(const video_format_desc& format_desc)\r
83         {\r
84                 context_.execution().begin_invoke([=]\r
85                 {\r
86                         context_.set_format_desc(format_desc);\r
87                 });\r
88         }\r
89 };\r
90 \r
91 video_channel::video_channel(int index, const video_format_desc& format_desc, ogl_device& ogl) : impl_(new implementation(index, format_desc, ogl)){}\r
92 video_channel::video_channel(video_channel&& other) : impl_(std::move(other.impl_)){}\r
93 safe_ptr<frame_producer_device> video_channel::producer() { return impl_->producer_;} \r
94 safe_ptr<frame_mixer_device> video_channel::mixer() { return impl_->mixer_;} \r
95 safe_ptr<frame_consumer_device> video_channel::consumer() { return impl_->consumer_;} \r
96 video_format_desc video_channel::get_video_format_desc() const{return impl_->context_.get_format_desc();}\r
97 void video_channel::set_video_format_desc(const video_format_desc& format_desc){impl_->set_video_format_desc(format_desc);}\r
98 std::wstring video_channel::print() const { return impl_->print();}\r
99 \r
100 }}