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 tbb::atomic<bool> is_paused_;
\r
15 safe_ptr<draw_frame> last_frame_;
\r
16 safe_ptr<frame_producer> foreground_;
\r
17 safe_ptr<frame_producer> background_;
\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
30 void load(const safe_ptr<frame_producer>& frame_producer, bool autoplay)
\r
32 background_ = frame_producer;
\r
33 CASPAR_LOG(info) << print() << " " << frame_producer->print() << " => background";
\r
38 void preview(const safe_ptr<frame_producer>& frame_producer)
\r
41 load(frame_producer, false);
\r
44 last_frame_ = frame_producer->receive();
\r
48 CASPAR_LOG_CURRENT_EXCEPTION();
\r
49 CASPAR_LOG(warning) << print() << L" empty => background";
\r
50 background_ = frame_producer::empty();
\r
56 background_->set_leading_producer(foreground_);
\r
57 foreground_ = background_;
\r
58 background_ = frame_producer::empty();
\r
60 CASPAR_LOG(info) << print() << L" background => foreground";
\r
71 last_frame_ = draw_frame::empty();
\r
72 foreground_ = frame_producer::empty();
\r
78 last_frame_ = draw_frame::empty();
\r
79 foreground_ = frame_producer::empty();
\r
80 background_ = frame_producer::empty();
\r
83 safe_ptr<draw_frame> receive()
\r
90 last_frame_ = foreground_->receive();
\r
91 if(last_frame_ == draw_frame::eof())
\r
93 assert(foreground_ != frame_producer::empty());
\r
95 auto following = foreground_->get_following_producer();
\r
96 following->set_leading_producer(foreground_);
\r
97 foreground_ = following;
\r
99 CASPAR_LOG(info) << print() << L" [EOF] " << foreground_->print() << " => foreground";
\r
101 last_frame_ = receive();
\r
106 CASPAR_LOG_CURRENT_EXCEPTION();
\r
107 foreground_ = frame_producer::empty();
\r
108 last_frame_ = draw_frame::empty();
\r
109 CASPAR_LOG(warning) << print() << L" empty => foreground";
\r
112 return last_frame_;
\r
115 std::wstring print() const { return L"layer[" + boost::lexical_cast<std::wstring>(index_) + L"]"; }
\r
118 layer::layer(int index) : impl_(new implementation(index)){}
\r
119 layer::layer(layer&& other) : impl_(std::move(other.impl_)){other.impl_ = nullptr;}
\r
120 layer& layer::operator=(layer&& other)
\r
122 impl_ = std::move(other.impl_);
\r
123 other.impl_ = nullptr;
\r
126 void layer::load(const safe_ptr<frame_producer>& frame_producer, bool autoplay){return impl_->load(frame_producer, autoplay);}
\r
127 void layer::preview(const safe_ptr<frame_producer>& frame_producer){return impl_->preview(frame_producer);}
\r
128 void layer::play(){impl_->play();}
\r
129 void layer::pause(){impl_->pause();}
\r
130 void layer::stop(){impl_->stop();}
\r
131 void layer::clear(){impl_->clear();}
\r
132 bool layer::empty() const { return impl_->foreground_ == frame_producer::empty() && impl_->background_ == frame_producer::empty();}
\r
133 safe_ptr<draw_frame> layer::receive() {return impl_->receive();}
\r
134 safe_ptr<frame_producer> layer::foreground() const { return impl_->foreground_;}
\r
135 safe_ptr<frame_producer> layer::background() const { return impl_->background_;}
\r