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
37 void preview(const safe_ptr<frame_producer>& frame_producer)
\r
40 load(frame_producer, false);
\r
43 last_frame_ = frame_producer->receive();
\r
47 CASPAR_LOG_CURRENT_EXCEPTION();
\r
58 background_->set_leading_producer(foreground_);
\r
59 foreground_ = background_;
\r
60 background_ = frame_producer::empty();
\r
72 last_frame_ = draw_frame::empty();
\r
73 foreground_ = frame_producer::empty();
\r
79 background_ = frame_producer::empty();
\r
82 safe_ptr<draw_frame> receive()
\r
89 last_frame_ = foreground_->receive();
\r
90 if(last_frame_ == draw_frame::eof())
\r
92 CASPAR_ASSERT(foreground_ != frame_producer::empty());
\r
94 auto following = foreground_->get_following_producer();
\r
95 following->set_leading_producer(foreground_);
\r
96 foreground_ = following;
\r
98 last_frame_ = receive();
\r
103 CASPAR_LOG_CURRENT_EXCEPTION();
\r
107 return last_frame_;
\r
113 impl_ = new implementation();
\r
115 layer::layer(layer&& other)
\r
117 impl_ = other.impl_.compare_and_swap(nullptr, other.impl_);
\r
121 delete impl_.fetch_and_store(nullptr);
\r
123 layer& layer::operator=(layer&& other)
\r
125 impl_ = other.impl_.compare_and_swap(nullptr, other.impl_);
\r
128 void layer::swap(layer& other)
\r
130 impl_ = other.impl_.compare_and_swap(impl_, other.impl_);
\r
132 void layer::load(const safe_ptr<frame_producer>& frame_producer, bool play_on_load){return impl_->load(frame_producer, play_on_load);}
\r
133 void layer::preview(const safe_ptr<frame_producer>& frame_producer){return impl_->preview(frame_producer);}
\r
134 void layer::play(){impl_->play();}
\r
135 void layer::pause(){impl_->pause();}
\r
136 void layer::stop(){impl_->stop();}
\r
137 void layer::clear(){impl_->clear();}
\r
138 safe_ptr<draw_frame> layer::receive() {return impl_->receive();}
\r
139 safe_ptr<frame_producer> layer::foreground() const { return impl_->foreground_;}
\r
140 safe_ptr<frame_producer> layer::background() const { return impl_->background_;}
\r