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 double video_opacity_;
\r
30 implementation(int index)
\r
31 : foreground_(frame_producer::empty())
\r
32 , background_(frame_producer::empty())
\r
33 , last_frame_(draw_frame::empty())
\r
37 , video_opacity_(1.0)
\r
38 , audio_gain_(1.0){}
\r
40 void load(const safe_ptr<frame_producer>& frame_producer, bool play_on_load)
\r
42 background_ = frame_producer;
\r
43 CASPAR_LOG(info) << print() << " " << frame_producer->print() << " => background";
\r
48 void preview(const safe_ptr<frame_producer>& frame_producer)
\r
51 load(frame_producer, false);
\r
54 last_frame_ = frame_producer->receive();
\r
58 CASPAR_LOG_CURRENT_EXCEPTION();
\r
69 background_->set_leading_producer(foreground_);
\r
70 foreground_ = background_;
\r
71 background_ = frame_producer::empty();
\r
72 CASPAR_LOG(info) << print() << L" background => foreground";
\r
84 last_frame_ = draw_frame::empty();
\r
85 foreground_ = frame_producer::empty();
\r
86 CASPAR_LOG(warning) << print() << L" empty => foreground";
\r
92 background_ = frame_producer::empty();
\r
93 CASPAR_LOG(warning) << print() << L" empty => background";
\r
96 safe_ptr<draw_frame> receive()
\r
103 last_frame_ = foreground_->receive();
\r
104 if(last_frame_ == draw_frame::eof())
\r
106 CASPAR_ASSERT(foreground_ != frame_producer::empty());
\r
108 auto following = foreground_->get_following_producer();
\r
109 following->set_leading_producer(foreground_);
\r
110 foreground_ = following;
\r
112 CASPAR_LOG(info) << print() << L" [EOF] " << foreground_->print() << " => foreground";
\r
114 last_frame_ = receive();
\r
118 last_frame_ = draw_frame(last_frame_);
\r
119 last_frame_->get_image_transform().gain *= video_gain_;
\r
120 last_frame_->get_image_transform().alpha *= video_opacity_;
\r
121 last_frame_->get_audio_transform().gain *= audio_gain_;
\r
126 CASPAR_LOG_CURRENT_EXCEPTION();
\r
130 return last_frame_;
\r
133 std::wstring print() const { return L"layer[" + boost::lexical_cast<std::wstring>(index_) + L"]"; }
\r
136 layer::layer(int index) : impl_(new implementation(index)){}
\r
137 layer::layer(layer&& other) : impl_(std::move(other.impl_)){other.impl_ = nullptr;}
\r
138 layer& layer::operator=(layer&& other)
\r
140 impl_ = std::move(other.impl_);
\r
141 other.impl_ = nullptr;
\r
144 void layer::load(const safe_ptr<frame_producer>& frame_producer, bool play_on_load){return impl_->load(frame_producer, play_on_load);}
\r
145 void layer::preview(const safe_ptr<frame_producer>& frame_producer){return impl_->preview(frame_producer);}
\r
146 void layer::set_video_gain(double value) { impl_->video_gain_ = value;}
\r
147 void layer::set_video_opacity(double value) { impl_->video_opacity_ = value;}
\r
148 void layer::set_audio_gain(double value) { impl_->audio_gain_ = value;}
\r
149 void layer::play(){impl_->play();}
\r
150 void layer::pause(){impl_->pause();}
\r
151 void layer::stop(){impl_->stop();}
\r
152 void layer::clear(){impl_->clear();}
\r
153 safe_ptr<draw_frame> layer::receive() {return impl_->receive();}
\r
154 safe_ptr<frame_producer> layer::foreground() const { return impl_->foreground_;}
\r
155 safe_ptr<frame_producer> layer::background() const { return impl_->background_;}
\r