1 #include "../stdafx.h"
\r
5 #include "../processor/draw_frame.h"
\r
6 #include "../producer/frame_producer.h"
\r
8 #include "../format/video_format.h"
\r
10 namespace caspar { namespace core {
\r
12 struct layer::implementation
\r
14 implementation(size_t index) : foreground_(frame_producer::empty()), background_(frame_producer::empty()), last_frame_(draw_frame::empty()), index_(index) {}
\r
16 void load(const safe_ptr<frame_producer>& frame_producer, bool autoplay)
\r
18 background_ = frame_producer;
\r
23 void preview(const safe_ptr<frame_producer>& frame_producer)
\r
25 background_ = frame_producer;
\r
26 foreground_ = frame_producer::empty();
\r
29 last_frame_ = frame_producer->receive();
\r
33 CASPAR_LOG_CURRENT_EXCEPTION();
\r
34 CASPAR_LOG(warning) << L"layer[" << index_ << L"] Error. Removed " << foreground_->print() << L" from layer.";
\r
35 background_ = frame_producer::empty();
\r
36 last_frame_ = draw_frame::empty();
\r
42 background_->set_leading_producer(foreground_);
\r
43 foreground_ = background_;
\r
44 background_ = frame_producer::empty();
\r
46 CASPAR_LOG(info) << L"layer[" << index_ << L"] Started: " << foreground_->print();
\r
56 foreground_ = frame_producer::empty();
\r
57 last_frame_ = draw_frame::empty();
\r
62 foreground_ = frame_producer::empty();
\r
63 background_ = frame_producer::empty();
\r
64 last_frame_ = draw_frame::empty();
\r
67 safe_ptr<draw_frame> receive()
\r
69 if(foreground_ == frame_producer::empty() || is_paused_)
\r
74 last_frame_ = foreground_->receive();
\r
76 if(last_frame_ == draw_frame::eof())
\r
78 CASPAR_LOG(info) << L"layer[" << index_ << L"] Ended:" << foreground_->print();
\r
79 auto following = foreground_->get_following_producer();
\r
80 following->set_leading_producer(foreground_);
\r
81 foreground_ = following;
\r
82 if(foreground_ != frame_producer::empty())
\r
83 CASPAR_LOG(info) << L"layer[" << index_ << L"] Started:" << foreground_->print();
\r
84 last_frame_ = receive();
\r
89 CASPAR_LOG_CURRENT_EXCEPTION();
\r
90 CASPAR_LOG(warning) << L"layer[" << index_ << L"] Error. Removed " << foreground_->print() << L" from layer.";
\r
91 foreground_ = frame_producer::empty();
\r
92 last_frame_ = draw_frame::empty();
\r
98 tbb::atomic<bool> is_paused_;
\r
99 safe_ptr<draw_frame> last_frame_;
\r
100 safe_ptr<frame_producer> foreground_;
\r
101 safe_ptr<frame_producer> background_;
\r
105 layer::layer(size_t index) : impl_(new implementation(index)){}
\r
106 layer::layer(layer&& other) : impl_(std::move(other.impl_)){other.impl_ = nullptr;}
\r
107 layer& layer::operator=(layer&& other)
\r
109 impl_ = std::move(other.impl_);
\r
110 other.impl_ = nullptr;
\r
113 void layer::load(const safe_ptr<frame_producer>& frame_producer, bool autoplay){return impl_->load(frame_producer, autoplay);}
\r
114 void layer::preview(const safe_ptr<frame_producer>& frame_producer){return impl_->preview(frame_producer);}
\r
115 void layer::play(){impl_->play();}
\r
116 void layer::pause(){impl_->pause();}
\r
117 void layer::stop(){impl_->stop();}
\r
118 void layer::clear(){impl_->clear();}
\r
119 bool layer::empty() const { return impl_->foreground_ == frame_producer::empty() && impl_->background_ == frame_producer::empty();}
\r
120 safe_ptr<draw_frame> layer::receive() {return impl_->receive();}
\r
121 safe_ptr<frame_producer> layer::foreground() const { return impl_->foreground_;}
\r
122 safe_ptr<frame_producer> layer::background() const { return impl_->background_;}
\r