1 #include "../stdafx.h"
\r
5 #include "../mixer/frame/draw_frame.h"
\r
6 #include "../mixer/image/image_mixer.h"
\r
7 #include "../mixer/audio/audio_mixer.h"
\r
8 #include "../producer/frame_producer.h"
\r
10 #include "../video_format.h"
\r
12 #include <common/utility/assert.h>
\r
14 namespace caspar { namespace core {
\r
16 struct layer::implementation : boost::noncopyable
\r
18 safe_ptr<frame_producer> foreground_;
\r
19 safe_ptr<frame_producer> background_;
\r
20 safe_ptr<draw_frame> last_frame_;
\r
25 implementation(int index)
\r
26 : foreground_(frame_producer::empty())
\r
27 , background_(frame_producer::empty())
\r
28 , last_frame_(draw_frame::empty())
\r
30 , is_paused_(false){}
\r
32 void load(const safe_ptr<frame_producer>& frame_producer, bool play_on_load)
\r
34 background_ = frame_producer;
\r
35 CASPAR_LOG(info) << print() << " " << frame_producer->print() << " => background";
\r
40 void preview(const safe_ptr<frame_producer>& frame_producer)
\r
43 load(frame_producer, false);
\r
46 last_frame_ = frame_producer->receive();
\r
50 CASPAR_LOG_CURRENT_EXCEPTION();
\r
61 background_->set_leading_producer(foreground_);
\r
62 foreground_ = background_;
\r
63 background_ = frame_producer::empty();
\r
64 CASPAR_LOG(info) << print() << L" background => foreground";
\r
76 last_frame_ = draw_frame::empty();
\r
77 foreground_ = frame_producer::empty();
\r
78 CASPAR_LOG(warning) << print() << L" empty => foreground";
\r
84 background_ = frame_producer::empty();
\r
85 CASPAR_LOG(warning) << print() << L" empty => background";
\r
88 safe_ptr<draw_frame> receive()
\r
95 last_frame_ = foreground_->receive();
\r
96 last_frame_->set_layer_index(index_);
\r
97 if(last_frame_ == draw_frame::eof())
\r
99 CASPAR_ASSERT(foreground_ != frame_producer::empty());
\r
101 auto following = foreground_->get_following_producer();
\r
102 following->set_leading_producer(foreground_);
\r
103 foreground_ = following;
\r
105 CASPAR_LOG(info) << print() << L" [EOF] " << foreground_->print() << " => foreground";
\r
107 last_frame_ = receive();
\r
112 CASPAR_LOG_CURRENT_EXCEPTION();
\r
116 return last_frame_;
\r
119 std::wstring print() const { return L"layer[" + boost::lexical_cast<std::wstring>(index_) + L"]"; }
\r
122 layer::layer(int index)
\r
124 impl_ = new implementation(index);
\r
126 layer::layer(layer&& other) : impl_(std::move(other.impl_)){other.impl_ = nullptr;}
\r
129 delete impl_.fetch_and_store(nullptr);
\r
131 layer& layer::operator=(layer&& other)
\r
133 impl_ = std::move(other.impl_);
\r
134 other.impl_ = nullptr;
\r
137 void layer::swap(layer& other)
\r
139 impl_ = other.impl_.compare_and_swap(impl_, other.impl_);
\r
141 void layer::load(const safe_ptr<frame_producer>& frame_producer, bool play_on_load){return impl_->load(frame_producer, play_on_load);}
\r
142 void layer::preview(const safe_ptr<frame_producer>& frame_producer){return impl_->preview(frame_producer);}
\r
143 void layer::play(){impl_->play();}
\r
144 void layer::pause(){impl_->pause();}
\r
145 void layer::stop(){impl_->stop();}
\r
146 void layer::clear(){impl_->clear();}
\r
147 safe_ptr<draw_frame> layer::receive() {return impl_->receive();}
\r
148 safe_ptr<frame_producer> layer::foreground() const { return impl_->foreground_;}
\r
149 safe_ptr<frame_producer> layer::background() const { return impl_->background_;}
\r