]> git.sesse.net Git - casparcg/blob - core/video_channel_context.h
2.0.0.2: Fixed data race in video_channel_context.
[casparcg] / core / video_channel_context.h
1 #pragma once\r
2 \r
3 #include <common/concurrency/executor.h>\r
4 \r
5 #include <core/mixer/gpu/ogl_device.h>\r
6 #include <core/video_format.h>\r
7 \r
8 #include <tbb/spin_rw_mutex.h>\r
9 \r
10 #include <boost/noncopyable.hpp>\r
11 #include <boost/lexical_cast.hpp>\r
12 \r
13 #include <string>\r
14 \r
15 namespace caspar { namespace core {\r
16 \r
17 class video_channel_context\r
18 {\r
19         mutable tbb::spin_rw_mutex      mutex_;\r
20         const int                                       index_;\r
21         video_format_desc                       format_desc_;\r
22         executor                                        execution_;\r
23         executor                                        destruction_;\r
24         ogl_device&                                     ogl_;\r
25 \r
26 public:\r
27         video_channel_context(int index,  ogl_device& ogl, const video_format_desc& format_desc) \r
28                 : index_(index)\r
29                 , format_desc_(format_desc)\r
30                 , execution_(print() + L"/execution")\r
31                 , destruction_(print() + L"/destruction")\r
32                 , ogl_(ogl)\r
33         {\r
34                 execution_.set_priority_class(above_normal_priority_class);\r
35                 destruction_.set_priority_class(below_normal_priority_class);\r
36         }\r
37 \r
38         const int index() const {return index_;}\r
39 \r
40         video_format_desc get_format_desc()\r
41         {\r
42                 tbb::spin_rw_mutex::scoped_lock lock(mutex_, false);\r
43                 return format_desc_;\r
44         }\r
45 \r
46         void set_format_desc(const video_format_desc& format_desc)\r
47         {\r
48                 tbb::spin_rw_mutex::scoped_lock lock(mutex_, true);\r
49                 format_desc_ = format_desc;\r
50         }\r
51 \r
52         executor& execution() {return execution_;}\r
53         executor& destruction() {return destruction_;}\r
54         ogl_device& ogl() { return ogl_;}\r
55 \r
56         std::wstring print() const\r
57         {\r
58                 return L"video_channel[" + boost::lexical_cast<std::wstring>(index_+1) + L"-" +  format_desc_.name + L"]";\r
59         }\r
60 };\r
61         \r
62 }}