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
111 auto keep_alive = foreground_;
\r
112 last_frame_ = core::receive(foreground_);
\r
114 if(keep_alive != foreground_)
\r
115 g_remover.remove(std::move(keep_alive));
\r
117 return last_frame_;
\r
120 std::wstring print() const
\r
122 return L"layer[" + boost::lexical_cast<std::wstring>(index_) + L"]";
\r
126 layer::layer(int index) : impl_(new implementation(index)){}
\r
127 layer::layer(layer&& other) : impl_(std::move(other.impl_)){}
\r
128 layer& layer::operator=(layer&& other)
\r
130 impl_ = std::move(other.impl_);
\r
133 void layer::swap(layer& other)
\r
135 impl_.swap(other.impl_);
\r
136 // Printer state is not swapped.
\r
137 std::swap(impl_->index_, other.impl_->index_);
\r
139 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
140 void layer::play(){impl_->play();}
\r
141 void layer::pause(){impl_->pause();}
\r
142 void layer::stop(){impl_->stop();}
\r
143 safe_ptr<basic_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
146 std::wstring layer::print() const { return impl_->print();}
\r