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, load_option::type option)
\r
18 background_ = frame_producer;
\r
19 if(option == load_option::preview)
\r
21 foreground_ = frame_producer::empty();
\r
22 last_frame_ = frame_producer->receive();
\r
24 else if(option == load_option::auto_play)
\r
30 background_->set_leading_producer(foreground_);
\r
31 foreground_ = background_;
\r
32 background_ = frame_producer::empty();
\r
34 CASPAR_LOG(info) << L"layer[" << index_ << L"] Started: " << foreground_->print();
\r
44 foreground_ = frame_producer::empty();
\r
45 last_frame_ = draw_frame::empty();
\r
50 foreground_ = frame_producer::empty();
\r
51 background_ = frame_producer::empty();
\r
52 last_frame_ = draw_frame::empty();
\r
55 safe_ptr<draw_frame> receive()
\r
57 if(foreground_ == frame_producer::empty() || is_paused_)
\r
62 last_frame_ = foreground_->receive();
\r
64 if(last_frame_ == draw_frame::eof())
\r
66 CASPAR_LOG(info) << L"layer[" << index_ << L"] Ended:" << foreground_->print();
\r
67 auto following = foreground_->get_following_producer();
\r
68 following->set_leading_producer(foreground_);
\r
69 foreground_ = following;
\r
70 if(foreground_ != frame_producer::empty())
\r
71 CASPAR_LOG(info) << L"layer[" << index_ << L"] Started:" << foreground_->print();
\r
72 last_frame_ = receive();
\r
79 CASPAR_LOG_CURRENT_EXCEPTION();
\r
80 CASPAR_LOG(warning) << L"layer[" << index_ << L"] Error. Removed " << foreground_->print() << L" from layer.";
\r
81 foreground_ = frame_producer::empty();
\r
82 last_frame_ = draw_frame::empty();
\r
90 tbb::atomic<bool> is_paused_;
\r
91 safe_ptr<draw_frame> last_frame_;
\r
92 safe_ptr<frame_producer> foreground_;
\r
93 safe_ptr<frame_producer> background_;
\r
97 layer::layer(size_t index) : impl_(new implementation(index)){}
\r
98 layer::layer(layer&& other) : impl_(std::move(other.impl_)){other.impl_ = nullptr;}
\r
99 layer& layer::operator=(layer&& other)
\r
101 impl_ = std::move(other.impl_);
\r
102 other.impl_ = nullptr;
\r
105 void layer::load(const safe_ptr<frame_producer>& frame_producer, load_option::type option){return impl_->load(frame_producer, option);}
\r
106 void layer::play(){impl_->play();}
\r
107 void layer::pause(){impl_->pause();}
\r
108 void layer::stop(){impl_->stop();}
\r
109 void layer::clear(){impl_->clear();}
\r
110 bool layer::empty() const { return impl_->foreground_ == frame_producer::empty() && impl_->background_ == frame_producer::empty();}
\r
111 safe_ptr<draw_frame> layer::receive() {return impl_->receive();}
\r
112 safe_ptr<frame_producer> layer::foreground() const { return impl_->foreground_;}
\r
113 safe_ptr<frame_producer> layer::background() const { return impl_->background_;}
\r