]> git.sesse.net Git - casparcg/blob - core/consumer/port.cpp
39cd2721225244b43e484ae7eaab971631e744ec
[casparcg] / core / consumer / port.cpp
1 #include "../StdAfx.h"\r
2 \r
3 #include "port.h"\r
4 \r
5 #include "frame_consumer.h"\r
6 #include "../frame/frame.h"\r
7 \r
8 namespace caspar { namespace core {\r
9 \r
10 struct port::impl\r
11 {\r
12         monitor::basic_subject                          event_subject_;\r
13         std::shared_ptr<frame_consumer>         consumer_;\r
14         int                                                                     index_;\r
15         int                                                                     channel_index_;\r
16 public:\r
17         impl(int index, int channel_index, spl::shared_ptr<frame_consumer> consumer)\r
18                 : event_subject_(monitor::path("port") % index)\r
19                 , consumer_(std::move(consumer))\r
20                 , index_(index)\r
21                 , channel_index_(channel_index)\r
22         {\r
23                 consumer_->subscribe(event_subject_);\r
24         }\r
25         \r
26         void video_format_desc(const struct video_format_desc& format_desc)\r
27         {\r
28                 consumer_->initialize(format_desc, channel_index_);\r
29         }\r
30                 \r
31         bool send(const_frame frame)\r
32         {\r
33                 event_subject_ << monitor::event("type") % consumer_->name();\r
34                 return consumer_->send(std::move(frame));\r
35         }\r
36         \r
37         int index() const\r
38         {\r
39                 return index_;\r
40         }\r
41 \r
42         int buffer_depth() const\r
43         {\r
44                 return consumer_->buffer_depth();\r
45         }\r
46 \r
47         bool has_synchronization_clock() const\r
48         {\r
49                 return consumer_->has_synchronization_clock();\r
50         }\r
51 \r
52         boost::property_tree::wptree info() const\r
53         {\r
54                 return consumer_->info();\r
55         }\r
56 };\r
57 \r
58 port::port(int index, int channel_index, spl::shared_ptr<frame_consumer> consumer) : impl_(new impl(index, channel_index, std::move(consumer))){}\r
59 port::port(port&& other) : impl_(std::move(other.impl_)){}\r
60 port::~port(){}\r
61 port& port::operator=(port&& other){impl_ = std::move(other.impl_); return *this;}\r
62 bool port::send(const_frame frame){return impl_->send(std::move(frame));}       \r
63 void port::subscribe(const monitor::observable::observer_ptr& o){impl_->event_subject_.subscribe(o);}\r
64 void port::unsubscribe(const monitor::observable::observer_ptr& o){impl_->event_subject_.unsubscribe(o);}\r
65 void port::video_format_desc(const struct video_format_desc& format_desc){impl_->video_format_desc(format_desc);}\r
66 int port::buffer_depth() const{return impl_->buffer_depth();}\r
67 bool port::has_synchronization_clock() const{return impl_->has_synchronization_clock();}\r
68 boost::property_tree::wptree port::info() const{return impl_->info();}\r
69 }}