2 * Copyright (c) 2011 Sveriges Television AB <info@casparcg.com>
\r
4 * This file is part of CasparCG (www.casparcg.com).
\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
19 * Author: Robert Nagy, ronag89@gmail.com
\r
22 #include "../stdafx.h"
\r
26 #include "frame_producer.h"
\r
27 #include "frame/basic_frame.h"
\r
29 #include <boost/property_tree/ptree.hpp>
\r
31 namespace caspar { namespace core {
\r
33 struct layer::implementation
\r
35 safe_ptr<frame_producer> foreground_;
\r
36 safe_ptr<frame_producer> background_;
\r
37 int64_t frame_number_;
\r
38 int32_t auto_play_delta_;
\r
43 : foreground_(frame_producer::empty())
\r
44 , background_(frame_producer::empty())
\r
46 , auto_play_delta_(-1)
\r
61 void load(const safe_ptr<frame_producer>& producer, bool preview, int auto_play_delta)
\r
63 background_ = producer;
\r
64 auto_play_delta_ = auto_play_delta;
\r
66 if(auto_play_delta_ > -1 && foreground_ == frame_producer::empty())
\r
69 if(preview) // Play the first frame and pause.
\r
72 receive(frame_producer::NO_HINT);
\r
79 if(background_ != frame_producer::empty())
\r
81 background_->set_leading_producer(foreground_);
\r
83 foreground_ = background_;
\r
84 background_ = frame_producer::empty();
\r
86 auto_play_delta_ = -1;
\r
94 foreground_ = frame_producer::empty();
\r
95 background_ = background_;
\r
97 auto_play_delta_ = -1;
\r
102 safe_ptr<basic_frame> receive(int hints)
\r
107 return disable_audio(foreground_->last_frame());
\r
109 auto frame = receive_and_follow(foreground_, hints);
\r
110 if(frame == core::basic_frame::late())
\r
111 return foreground_->last_frame();
\r
113 auto frames_left = static_cast<int64_t>(foreground_->nb_frames()) - static_cast<int64_t>(++frame_number_) - static_cast<int64_t>(auto_play_delta_);
\r
114 if(auto_play_delta_ > -1 && frames_left < 1)
\r
117 return receive(hints);
\r
124 CASPAR_LOG_CURRENT_EXCEPTION();
\r
126 return core::basic_frame::empty();
\r
130 boost::unique_future<std::wstring> call(bool foreground, const std::wstring& param)
\r
132 return (foreground ? foreground_ : background_)->call(param);
\r
137 return background_ == core::frame_producer::empty() && foreground_ == core::frame_producer::empty();
\r
140 boost::property_tree::wptree info() const
\r
142 boost::property_tree::wptree info;
\r
143 info.add(L"status", is_paused_ ? L"paused" : (foreground_ == frame_producer::empty() ? L"stopped" : L"playing"));
\r
144 info.add(L"auto_delta", auto_play_delta_);
\r
145 info.add(L"frame-number", frame_number_);
\r
147 auto nb_frames = foreground_->nb_frames();
\r
149 info.add(L"nb_frames", nb_frames == std::numeric_limits<int64_t>::max() ? -1 : nb_frames);
\r
150 info.add(L"frames-left", nb_frames == std::numeric_limits<int64_t>::max() ? -1 : (foreground_->nb_frames() - frame_number_ - auto_play_delta_));
\r
151 info.add_child(L"foreground", foreground_->info());
\r
152 info.add_child(L"background", background_->info());
\r
157 layer::layer() : impl_(new implementation()){}
\r
158 layer::layer(layer&& other) : impl_(std::move(other.impl_)){}
\r
159 layer& layer::operator=(layer&& other)
\r
161 impl_ = std::move(other.impl_);
\r
164 layer::layer(const layer& other) : impl_(new implementation(*other.impl_)){}
\r
165 layer& layer::operator=(const layer& other)
\r
171 void layer::swap(layer& other)
\r
173 impl_.swap(other.impl_);
\r
175 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
176 void layer::play(){impl_->play();}
\r
177 void layer::pause(){impl_->pause();}
\r
178 void layer::stop(){impl_->stop();}
\r
179 bool layer::is_paused() const{return impl_->is_paused_;}
\r
180 int64_t layer::frame_number() const{return impl_->frame_number_;}
\r
181 safe_ptr<basic_frame> layer::receive(int hints) {return impl_->receive(hints);}
\r
182 safe_ptr<frame_producer> layer::foreground() const { return impl_->foreground_;}
\r
183 safe_ptr<frame_producer> layer::background() const { return impl_->background_;}
\r
184 bool layer::empty() const {return impl_->empty();}
\r
185 boost::unique_future<std::wstring> layer::call(bool foreground, const std::wstring& param){return impl_->call(foreground, param);}
\r
186 boost::property_tree::wptree layer::info() const{return impl_->info();}
\r