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 : boost::noncopyable
\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
19 CASPAR_LOG(info) << print() << " " << frame_producer->print() << " => background";
\r
24 void preview(const safe_ptr<frame_producer>& frame_producer)
\r
27 load(frame_producer, false);
\r
30 last_frame_ = frame_producer->receive();
\r
34 CASPAR_LOG_CURRENT_EXCEPTION();
\r
35 CASPAR_LOG(warning) << print() << L" empty => background";
\r
36 background_ = frame_producer::empty();
\r
42 background_->set_leading_producer(foreground_);
\r
43 foreground_ = background_;
\r
44 background_ = frame_producer::empty();
\r
46 CASPAR_LOG(info) << print() << L" background => foreground";
\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
75 if(last_frame_ == draw_frame::eof())
\r
77 auto following = foreground_->get_following_producer();
\r
78 following->set_leading_producer(foreground_);
\r
79 foreground_ = following;
\r
80 if(foreground_ != frame_producer::empty())
\r
81 CASPAR_LOG(info) << print() << L" [EOF] " << foreground_->print() << " => foreground";
\r
83 CASPAR_LOG(info) << print() << L" [EOF] empty => foreground";
\r
84 last_frame_ = receive();
\r
89 CASPAR_LOG_CURRENT_EXCEPTION();
\r
90 CASPAR_LOG(warning) << print() << L" empty => foreground";
\r
91 foreground_ = frame_producer::empty();
\r
92 last_frame_ = draw_frame::empty();
\r
98 std::wstring print() const { return L"layer[" + boost::lexical_cast<std::wstring>(index_) + L"]"; }
\r
100 tbb::atomic<bool> is_paused_;
\r
101 safe_ptr<draw_frame> last_frame_;
\r
102 safe_ptr<frame_producer> foreground_;
\r
103 safe_ptr<frame_producer> background_;
\r
104 const size_t index_;
\r
107 layer::layer(size_t index) : impl_(new implementation(index)){}
\r
108 layer::layer(layer&& other) : impl_(std::move(other.impl_)){other.impl_ = nullptr;}
\r
109 layer& layer::operator=(layer&& other)
\r
111 impl_ = std::move(other.impl_);
\r
112 other.impl_ = nullptr;
\r
115 void layer::load(const safe_ptr<frame_producer>& frame_producer, bool autoplay){return impl_->load(frame_producer, autoplay);}
\r
116 void layer::preview(const safe_ptr<frame_producer>& frame_producer){return impl_->preview(frame_producer);}
\r
117 void layer::play(){impl_->play();}
\r
118 void layer::pause(){impl_->pause();}
\r
119 void layer::stop(){impl_->stop();}
\r
120 void layer::clear(){impl_->clear();}
\r
121 bool layer::empty() const { return impl_->foreground_ == frame_producer::empty() && impl_->background_ == frame_producer::empty();}
\r
122 safe_ptr<draw_frame> layer::receive() {return impl_->receive();}
\r
123 safe_ptr<frame_producer> layer::foreground() const { return impl_->foreground_;}
\r
124 safe_ptr<frame_producer> layer::background() const { return impl_->background_;}
\r