1 #include "../stdafx.h"
\r
4 #include "frame_producer.h"
\r
6 #include "../video_format.h"
\r
8 #include <common/concurrency/executor.h>
\r
9 #include <common/utility/assert.h>
\r
11 #include <mixer/frame/draw_frame.h>
\r
12 #include <mixer/image/image_mixer.h>
\r
13 #include <mixer/audio/audio_mixer.h>
\r
14 #include <mixer/audio/audio_transform.h>
\r
16 namespace caspar { namespace core {
\r
18 class frame_producer_remover
\r
22 void do_remove(safe_ptr<frame_producer>& producer)
\r
24 auto name = producer->print();
\r
25 CASPAR_LOG(info) << "removing: " << name;
\r
26 producer = frame_producer::empty();
\r
27 CASPAR_LOG(info) << "removed: " << name;
\r
31 frame_producer_remover()
\r
36 void remove(safe_ptr<frame_producer>&& producer)
\r
38 CASPAR_ASSERT(producer.unique());
\r
39 CASPAR_ASSERT(executor_.empty());
\r
40 executor_.begin_invoke(std::bind(&frame_producer_remover::do_remove, this, std::move(producer)));
\r
44 frame_producer_remover g_remover;
\r
46 struct layer::implementation : boost::noncopyable
\r
48 safe_ptr<frame_producer> foreground_;
\r
49 safe_ptr<frame_producer> background_;
\r
50 safe_ptr<draw_frame> last_frame_;
\r
55 : foreground_(frame_producer::empty())
\r
56 , background_(frame_producer::empty())
\r
57 , last_frame_(draw_frame::empty())
\r
58 , is_paused_(false){}
\r
60 void load(const safe_ptr<frame_producer>& frame_producer, bool play_on_load)
\r
62 background_ = frame_producer;
\r
67 void preview(const safe_ptr<frame_producer>& frame_producer)
\r
69 load(frame_producer, true);
\r
74 void play(bool force = false)
\r
76 if(!is_paused_ || force)
\r
78 background_->set_leading_producer(foreground_);
\r
79 foreground_ = background_;
\r
80 background_ = frame_producer::empty();
\r
93 last_frame_ = draw_frame::empty();
\r
94 foreground_ = frame_producer::empty();
\r
100 background_ = frame_producer::empty();
\r
103 safe_ptr<draw_frame> receive()
\r
107 last_frame_->get_audio_transform().set_gain(0.0);
\r
108 return last_frame_;
\r
113 last_frame_ = foreground_->receive();
\r
114 if(last_frame_ == draw_frame::eof())
\r
116 CASPAR_ASSERT(foreground_ != frame_producer::empty());
\r
118 auto following = foreground_->get_following_producer();
\r
119 following->set_leading_producer(foreground_);
\r
120 g_remover.remove(std::move(foreground_));
\r
121 foreground_ = following;
\r
123 last_frame_ = receive();
\r
128 CASPAR_LOG_CURRENT_EXCEPTION();
\r
132 return last_frame_;
\r
138 impl_ = new implementation();
\r
140 layer::layer(layer&& other)
\r
142 impl_ = other.impl_.compare_and_swap(nullptr, other.impl_);
\r
146 delete impl_.fetch_and_store(nullptr);
\r
148 layer& layer::operator=(layer&& other)
\r
150 impl_ = other.impl_.compare_and_swap(nullptr, other.impl_);
\r
153 void layer::swap(layer& other)
\r
155 impl_ = other.impl_.compare_and_swap(impl_, other.impl_);
\r
157 void layer::load(const safe_ptr<frame_producer>& frame_producer, bool play_on_load){return impl_->load(frame_producer, play_on_load);}
\r
158 void layer::preview(const safe_ptr<frame_producer>& frame_producer){return impl_->preview(frame_producer);}
\r
159 void layer::play(){impl_->play();}
\r
160 void layer::pause(){impl_->pause();}
\r
161 void layer::stop(){impl_->stop();}
\r
162 void layer::clear(){impl_->clear();}
\r
163 safe_ptr<draw_frame> layer::receive() {return impl_->receive();}
\r
164 safe_ptr<frame_producer> layer::foreground() const { return impl_->foreground_;}
\r
165 safe_ptr<frame_producer> layer::background() const { return impl_->background_;}
\r