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 <mixer/audio/audio_transform.h>
\r
9 #include "../producer/frame_producer.h"
\r
11 #include "../video_format.h"
\r
13 #include <common/utility/assert.h>
\r
15 namespace caspar { namespace core {
\r
17 struct layer::implementation : boost::noncopyable
\r
19 safe_ptr<frame_producer> foreground_;
\r
20 safe_ptr<frame_producer> background_;
\r
21 safe_ptr<draw_frame> last_frame_;
\r
26 : foreground_(frame_producer::empty())
\r
27 , background_(frame_producer::empty())
\r
28 , last_frame_(draw_frame::empty())
\r
29 , is_paused_(false){}
\r
31 void load(const safe_ptr<frame_producer>& frame_producer, bool play_on_load)
\r
33 background_ = frame_producer;
\r
38 void preview(const safe_ptr<frame_producer>& frame_producer)
\r
41 foreground_ = frame_producer;
\r
42 background_ = frame_producer::empty();
\r
45 last_frame_ = frame_producer->receive();
\r
49 CASPAR_LOG_CURRENT_EXCEPTION();
\r
60 background_->set_leading_producer(foreground_);
\r
61 foreground_ = background_;
\r
62 background_ = frame_producer::empty();
\r
74 last_frame_ = draw_frame::empty();
\r
75 foreground_ = frame_producer::empty();
\r
81 background_ = frame_producer::empty();
\r
84 safe_ptr<draw_frame> receive()
\r
88 last_frame_->get_audio_transform().set_gain(0.0);
\r
94 last_frame_ = foreground_->receive();
\r
95 if(last_frame_ == draw_frame::eof())
\r
97 CASPAR_ASSERT(foreground_ != frame_producer::empty());
\r
99 auto following = foreground_->get_following_producer();
\r
100 following->set_leading_producer(foreground_);
\r
101 foreground_ = following;
\r
103 last_frame_ = receive();
\r
108 CASPAR_LOG_CURRENT_EXCEPTION();
\r
112 return last_frame_;
\r
118 impl_ = new implementation();
\r
120 layer::layer(layer&& other)
\r
122 impl_ = other.impl_.compare_and_swap(nullptr, other.impl_);
\r
126 delete impl_.fetch_and_store(nullptr);
\r
128 layer& layer::operator=(layer&& other)
\r
130 impl_ = other.impl_.compare_and_swap(nullptr, other.impl_);
\r
133 void layer::swap(layer& other)
\r
135 impl_ = other.impl_.compare_and_swap(impl_, other.impl_);
\r
137 void layer::load(const safe_ptr<frame_producer>& frame_producer, bool play_on_load){return impl_->load(frame_producer, play_on_load);}
\r
138 void layer::preview(const safe_ptr<frame_producer>& frame_producer){return impl_->preview(frame_producer);}
\r
139 void layer::play(){impl_->play();}
\r
140 void layer::pause(){impl_->pause();}
\r
141 void layer::stop(){impl_->stop();}
\r
142 void layer::clear(){impl_->clear();}
\r
143 safe_ptr<draw_frame> layer::receive() {return impl_->receive();}
\r
144 safe_ptr<frame_producer> layer::foreground() const { return impl_->foreground_;}
\r
145 safe_ptr<frame_producer> layer::background() const { return impl_->background_;}
\r