]> git.sesse.net Git - casparcg/blob - core/consumer/port.cpp
db3c68fa890b9ee28303eb68c4b6565ec73abf4b
[casparcg] / core / consumer / port.cpp
1 #include "../StdAfx.h"
2
3 #include "port.h"
4
5 #include "frame_consumer.h"
6 #include "../frame/frame.h"
7 #include <boost/lexical_cast.hpp>
8
9 #include <future>
10
11 namespace caspar { namespace core {
12
13 struct port::impl
14 {
15         int                                                                     index_;
16         spl::shared_ptr<monitor::subject>       monitor_subject_ = spl::make_shared<monitor::subject>("/port/" + boost::lexical_cast<std::string>(index_));
17         std::shared_ptr<frame_consumer>         consumer_;
18         int                                                                     channel_index_;
19 public:
20         impl(int index, int channel_index, spl::shared_ptr<frame_consumer> consumer)
21                 : index_(index)
22                 , consumer_(std::move(consumer))
23                 , channel_index_(channel_index)
24         {
25                 consumer_->monitor_output().attach_parent(monitor_subject_);
26         }
27         
28         void change_channel_format(const core::video_format_desc& format_desc, const audio_channel_layout& channel_layout)
29         {
30                 consumer_->initialize(format_desc, channel_layout, channel_index_);
31         }
32                 
33         std::future<bool> send(const_frame frame)
34         {
35                 *monitor_subject_ << monitor::message("/type") % consumer_->name();
36                 return consumer_->send(std::move(frame));
37         }
38         std::wstring print() const
39         {
40                 return consumer_->print();
41         }
42
43         int index() const
44         {
45                 return index_;
46         }
47
48         int buffer_depth() const
49         {
50                 return consumer_->buffer_depth();
51         }
52
53         bool has_synchronization_clock() const
54         {
55                 return consumer_->has_synchronization_clock();
56         }
57
58         boost::property_tree::wptree info() const
59         {
60                 return consumer_->info();
61         }
62
63         int64_t presentation_frame_age_millis() const
64         {
65                 return consumer_->presentation_frame_age_millis();
66         }
67 };
68
69 port::port(int index, int channel_index, spl::shared_ptr<frame_consumer> consumer) : impl_(new impl(index, channel_index, std::move(consumer))){}
70 port::port(port&& other) : impl_(std::move(other.impl_)){}
71 port::~port(){}
72 port& port::operator=(port&& other){impl_ = std::move(other.impl_); return *this;}
73 std::future<bool> port::send(const_frame frame){return impl_->send(std::move(frame));}  
74 monitor::subject& port::monitor_output() {return *impl_->monitor_subject_;}
75 void port::change_channel_format(const core::video_format_desc& format_desc, const audio_channel_layout& channel_layout){impl_->change_channel_format(format_desc, channel_layout);}
76 int port::buffer_depth() const{return impl_->buffer_depth();}
77 std::wstring port::print() const{ return impl_->print();}
78 bool port::has_synchronization_clock() const{return impl_->has_synchronization_clock();}
79 boost::property_tree::wptree port::info() const{return impl_->info();}
80 int64_t port::presentation_frame_age_millis() const{ return impl_->presentation_frame_age_millis(); }
81 }}