2 * copyright (c) 2010 Sveriges Television AB <info@casparcg.com>
\r
4 * This file is part of CasparCG.
\r
6 * CasparCG is free software: you can redistribute it and/or modify
\r
7 * it under the terms of the GNU General Public License as published by
\r
8 * the Free Software Foundation, either version 3 of the License, or
\r
9 * (at your option) any later version.
\r
11 * CasparCG is distributed in the hope that it will be useful,
\r
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
14 * GNU General Public License for more details.
\r
16 * You should have received a copy of the GNU General Public License
\r
17 * along with CasparCG. If not, see <http://www.gnu.org/licenses/>.
\r
21 #include "../stdafx.h"
\r
25 #include "frame_producer.h"
\r
26 #include "frame/basic_frame.h"
\r
28 namespace caspar { namespace core {
\r
30 struct layer::implementation
\r
32 safe_ptr<frame_producer> foreground_;
\r
33 safe_ptr<frame_producer> background_;
\r
35 int auto_play_delta_;
\r
36 int64_t frame_number_;
\r
39 : foreground_(frame_producer::empty())
\r
40 , background_(frame_producer::empty())
\r
42 , auto_play_delta_(-1)
\r
43 , frame_number_(0){}
\r
55 void load(const safe_ptr<frame_producer>& producer, bool preview, int auto_play_delta)
\r
57 background_ = producer;
\r
58 auto_play_delta_ = auto_play_delta;
\r
60 if(preview) // Play the first frame and pause.
\r
70 if(background_ != frame_producer::empty())
\r
72 background_->set_leading_producer(foreground_);
\r
73 foreground_ = background_;
\r
75 auto_play_delta_ = -1;
\r
76 background_ = frame_producer::empty();
\r
83 foreground_ = frame_producer::empty();
\r
87 safe_ptr<basic_frame> receive()
\r
92 return foreground_->last_frame();
\r
94 const auto frames_left = foreground_->nb_frames() - (++frame_number_) - auto_play_delta_;
\r
96 auto frame = receive_and_follow(foreground_, frame_producer::NO_HINT);
\r
97 if(frame == core::basic_frame::late())
\r
98 return foreground_->last_frame();
\r
100 if(auto_play_delta_ >= 0)
\r
102 if(frames_left <= 0 || frame == core::basic_frame::eof())
\r
104 //CASPAR_ASSERT(frame != core::basic_frame::eof() && "Received early EOF. Media duration metadata incorrect.");
\r
106 CASPAR_LOG(info) << L"Automatically playing next clip with " << auto_play_delta_ << " frames offset. Frames left: " << frames_left;
\r
117 CASPAR_LOG_CURRENT_EXCEPTION();
\r
119 return core::basic_frame::empty();
\r
125 return background_ == core::frame_producer::empty() && foreground_ == core::frame_producer::empty();
\r
129 layer::layer() : impl_(new implementation()){}
\r
130 layer::layer(layer&& other) : impl_(std::move(other.impl_)){}
\r
131 layer& layer::operator=(layer&& other)
\r
133 impl_ = std::move(other.impl_);
\r
136 layer::layer(const layer& other) : impl_(new implementation(*other.impl_)){}
\r
137 layer& layer::operator=(const layer& other)
\r
143 void layer::swap(layer& other)
\r
145 impl_.swap(other.impl_);
\r
147 void layer::load(const safe_ptr<frame_producer>& frame_producer, bool preview, int auto_play_delta){return impl_->load(frame_producer, preview, auto_play_delta);}
\r
148 void layer::play(){impl_->play();}
\r
149 void layer::pause(){impl_->pause();}
\r
150 void layer::stop(){impl_->stop();}
\r
151 safe_ptr<basic_frame> layer::receive() {return impl_->receive();}
\r
152 safe_ptr<frame_producer> layer::foreground() const { return impl_->foreground_;}
\r
153 safe_ptr<frame_producer> layer::background() const { return impl_->background_;}
\r
154 bool layer::empty() const {return impl_->empty();}
\r