1 #include "../stdafx.h"
\r
4 #include "frame_producer.h"
\r
6 #include <common/concurrency/executor.h>
\r
7 #include <common/exception/exceptions.h>
\r
8 #include <common/utility/assert.h>
\r
10 #include "../producer/frame/basic_frame.h"
\r
11 #include "../producer/frame/audio_transform.h"
\r
13 #include <tbb/spin_mutex.h>
\r
15 namespace caspar { namespace core {
\r
17 class frame_producer_remover
\r
21 void do_remove(safe_ptr<frame_producer>& producer)
\r
23 auto name = producer->print();
\r
24 producer = frame_producer::empty();
\r
25 CASPAR_LOG(info) << name << L" Removed.";
\r
30 frame_producer_remover() : executor_(L"frame_producer_remover")
\r
35 void remove(safe_ptr<frame_producer>&& producer)
\r
37 if(producer != frame_producer::empty() && !producer.unique())
\r
38 CASPAR_LOG(debug) << producer->print() << L" was not destroyed on dedicated destruction thread.";
\r
39 executor_.begin_invoke(std::bind(&frame_producer_remover::do_remove, this, std::move(producer)));
\r
43 frame_producer_remover g_remover;
\r
45 struct layer::implementation : boost::noncopyable
\r
47 tbb::atomic<int> index_;
\r
49 safe_ptr<frame_producer> foreground_;
\r
50 safe_ptr<frame_producer> background_;
\r
51 safe_ptr<basic_frame> last_frame_;
\r
54 implementation(int index)
\r
55 : foreground_(frame_producer::empty())
\r
56 , background_(frame_producer::empty())
\r
57 , last_frame_(basic_frame::empty())
\r
63 void load(const safe_ptr<frame_producer>& frame_producer, bool play_on_load, bool preview)
\r
65 background_ = frame_producer;
\r
83 background_->set_leading_producer(foreground_);
\r
84 foreground_ = background_;
\r
85 CASPAR_LOG(info) << foreground_->print() << L" Added.";
\r
86 background_ = frame_producer::empty();
\r
99 last_frame_ = basic_frame::empty();
\r
100 foreground_ = frame_producer::empty();
\r
103 safe_ptr<basic_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_ == basic_frame::eof())
\r
116 CASPAR_VERIFY(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
122 CASPAR_LOG(info) << foreground_->print() << L" Added.";
\r
124 last_frame_ = receive();
\r
129 CASPAR_LOG(error) << print() << L" Unhandled Exception: ";
\r
130 CASPAR_LOG_CURRENT_EXCEPTION();
\r
134 return last_frame_;
\r
137 std::wstring print() const
\r
139 return L"layer[" + boost::lexical_cast<std::wstring>(index_) + L"]";
\r
143 layer::layer(int index) : impl_(new implementation(index)){}
\r
144 layer::layer(layer&& other) : impl_(std::move(other.impl_)){}
\r
145 layer& layer::operator=(layer&& other)
\r
147 impl_ = std::move(other.impl_);
\r
150 void layer::swap(layer& other)
\r
152 impl_.swap(other.impl_);
\r
153 // Printer state is not swapped.
\r
154 std::swap(impl_->index_, other.impl_->index_);
\r
156 void layer::load(const safe_ptr<frame_producer>& frame_producer, bool play_on_load, bool preview){return impl_->load(frame_producer, play_on_load, preview);}
\r
157 void layer::play(){impl_->play();}
\r
158 void layer::pause(){impl_->pause();}
\r
159 void layer::stop(){impl_->stop();}
\r
160 safe_ptr<basic_frame> layer::receive() {return impl_->receive();}
\r
161 safe_ptr<frame_producer> layer::foreground() const { return impl_->foreground_;}
\r
162 safe_ptr<frame_producer> layer::background() const { return impl_->background_;}
\r
163 std::wstring layer::print() const { return impl_->print();}
\r