1 #include "../stdafx.h"
\r
5 #include "../processor/draw_frame.h"
\r
6 #include "../producer/frame_producer.h"
\r
8 #include "../video_format.h"
\r
10 namespace caspar { namespace core {
\r
12 struct layer::implementation : boost::noncopyable
\r
14 safe_ptr<frame_producer> foreground_;
\r
15 safe_ptr<frame_producer> background_;
\r
16 safe_ptr<draw_frame> last_frame_;
\r
21 implementation(int index)
\r
22 : foreground_(frame_producer::empty())
\r
23 , background_(frame_producer::empty())
\r
24 , last_frame_(draw_frame::empty())
\r
26 , is_paused_(false){}
\r
28 void load(const safe_ptr<frame_producer>& frame_producer, bool play_on_load)
\r
30 background_ = frame_producer;
\r
31 CASPAR_LOG(info) << print() << " " << frame_producer->print() << " => background";
\r
36 void preview(const safe_ptr<frame_producer>& frame_producer)
\r
39 load(frame_producer, false);
\r
42 last_frame_ = frame_producer->receive();
\r
46 CASPAR_LOG_CURRENT_EXCEPTION();
\r
53 background_->set_leading_producer(foreground_);
\r
54 foreground_ = background_;
\r
55 background_ = frame_producer::empty();
\r
57 CASPAR_LOG(info) << print() << L" background => foreground";
\r
68 last_frame_ = draw_frame::empty();
\r
69 foreground_ = frame_producer::empty();
\r
70 CASPAR_LOG(warning) << print() << L" empty => foreground";
\r
76 background_ = frame_producer::empty();
\r
77 CASPAR_LOG(warning) << print() << L" empty => background";
\r
80 safe_ptr<draw_frame> receive()
\r
87 last_frame_ = foreground_->receive();
\r
88 if(last_frame_ == draw_frame::eof())
\r
90 assert(foreground_ != frame_producer::empty());
\r
92 auto following = foreground_->get_following_producer();
\r
93 following->set_leading_producer(foreground_);
\r
94 foreground_ = following;
\r
96 CASPAR_LOG(info) << print() << L" [EOF] " << foreground_->print() << " => foreground";
\r
98 last_frame_ = receive();
\r
103 CASPAR_LOG_CURRENT_EXCEPTION();
\r
107 return last_frame_;
\r
110 std::wstring print() const { return L"layer[" + boost::lexical_cast<std::wstring>(index_) + L"]"; }
\r
113 layer::layer(int index) : impl_(new implementation(index)){}
\r
114 layer::layer(layer&& other) : impl_(std::move(other.impl_)){other.impl_ = nullptr;}
\r
115 layer& layer::operator=(layer&& other)
\r
117 impl_ = std::move(other.impl_);
\r
118 other.impl_ = nullptr;
\r
121 void layer::load(const safe_ptr<frame_producer>& frame_producer, bool play_on_load){return impl_->load(frame_producer, play_on_load);}
\r
122 void layer::preview(const safe_ptr<frame_producer>& frame_producer){return impl_->preview(frame_producer);}
\r
123 void layer::play(){impl_->play();}
\r
124 void layer::pause(){impl_->pause();}
\r
125 void layer::stop(){impl_->stop();}
\r
126 void layer::clear(){impl_->clear();}
\r
127 bool layer::empty() const { return impl_->foreground_ == frame_producer::empty() && impl_->background_ == frame_producer::empty();}
\r
128 safe_ptr<draw_frame> layer::receive() {return impl_->receive();}
\r
129 safe_ptr<frame_producer> layer::foreground() const { return impl_->foreground_;}
\r
130 safe_ptr<frame_producer> layer::background() const { return impl_->background_;}
\r