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 : foreground_(frame_producer::empty())
\r
26 , background_(frame_producer::empty())
\r
27 , last_frame_(draw_frame::empty())
\r
28 , is_paused_(false){}
\r
30 void load(const safe_ptr<frame_producer>& frame_producer, bool play_on_load)
\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
59 background_->set_leading_producer(foreground_);
\r
60 foreground_ = background_;
\r
61 background_ = frame_producer::empty();
\r
62 CASPAR_LOG(info) << print() << L" background => foreground";
\r
74 last_frame_ = draw_frame::empty();
\r
75 foreground_ = frame_producer::empty();
\r
76 CASPAR_LOG(warning) << print() << L" empty => foreground";
\r
82 background_ = frame_producer::empty();
\r
83 CASPAR_LOG(warning) << print() << L" empty => background";
\r
86 safe_ptr<draw_frame> receive()
\r
93 last_frame_ = foreground_->receive();
\r
94 if(last_frame_ == draw_frame::eof())
\r
96 CASPAR_ASSERT(foreground_ != frame_producer::empty());
\r
98 auto following = foreground_->get_following_producer();
\r
99 following->set_leading_producer(foreground_);
\r
100 foreground_ = following;
\r
102 CASPAR_LOG(info) << print() << L" [EOF] " << foreground_->print() << " => foreground";
\r
104 last_frame_ = receive();
\r
109 CASPAR_LOG_CURRENT_EXCEPTION();
\r
113 return last_frame_;
\r
116 std::wstring print() const { return L"layer[]"; }
\r
121 impl_ = new implementation();
\r
123 layer::layer(layer&& other) : impl_(std::move(other.impl_)){other.impl_ = nullptr;}
\r
126 delete impl_.fetch_and_store(nullptr);
\r
128 layer& layer::operator=(layer&& other)
\r
130 impl_ = std::move(other.impl_);
\r
131 other.impl_ = nullptr;
\r
134 void layer::swap(layer& other)
\r
136 impl_ = other.impl_.compare_and_swap(impl_, other.impl_);
\r
138 void layer::load(const safe_ptr<frame_producer>& frame_producer, bool play_on_load){return impl_->load(frame_producer, play_on_load);}
\r
139 void layer::preview(const safe_ptr<frame_producer>& frame_producer){return impl_->preview(frame_producer);}
\r
140 void layer::play(){impl_->play();}
\r
141 void layer::pause(){impl_->pause();}
\r
142 void layer::stop(){impl_->stop();}
\r
143 void layer::clear(){impl_->clear();}
\r
144 safe_ptr<draw_frame> layer::receive() {return impl_->receive();}
\r
145 safe_ptr<frame_producer> layer::foreground() const { return impl_->foreground_;}
\r
146 safe_ptr<frame_producer> layer::background() const { return impl_->background_;}
\r