X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=core%2Fproducer%2Flayer.cpp;h=9ef35a0d00fe2721f398a5504304794a07dd52dc;hb=56c7f363b3a444da24bd1c6a1b877891e4f774a4;hp=698aa4931a0eda999920374a9017f3b7a5fb97bc;hpb=af040261b1e1ba27fbcfd13c6950d28ce01e783e;p=casparcg diff --git a/core/producer/layer.cpp b/core/producer/layer.cpp index 698aa4931..9ef35a0d0 100644 --- a/core/producer/layer.cpp +++ b/core/producer/layer.cpp @@ -1,141 +1,137 @@ +/* +* copyright (c) 2010 Sveriges Television AB +* +* This file is part of CasparCG. +* +* CasparCG is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* CasparCG is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. + +* You should have received a copy of the GNU General Public License +* along with CasparCG. If not, see . +* +*/ + #include "../stdafx.h" #include "layer.h" -#include "../mixer/frame/draw_frame.h" -#include "../mixer/image/image_mixer.h" -#include "../mixer/audio/audio_mixer.h" -#include "../producer/frame_producer.h" +#include "frame_producer.h" -#include "../video_format.h" +#include "frame/basic_frame.h" -#include namespace caspar { namespace core { - -struct layer::implementation : boost::noncopyable -{ + +struct layer::implementation +{ safe_ptr foreground_; safe_ptr background_; - safe_ptr last_frame_; bool is_paused_; - + int auto_play_delta_; + int64_t frame_number_; public: implementation() : foreground_(frame_producer::empty()) , background_(frame_producer::empty()) - , last_frame_(draw_frame::empty()) - , is_paused_(false){} + , is_paused_(false) + , auto_play_delta_(-1){} - void load(const safe_ptr& frame_producer, bool play_on_load) - { - background_ = frame_producer; - if(play_on_load) - play(); - } + void pause(){is_paused_ = true;} + void resume(){is_paused_ = false;} - void preview(const safe_ptr& frame_producer) - { - stop(); - load(frame_producer, false); - try - { - last_frame_ = frame_producer->receive(); - } - catch(...) - { - CASPAR_LOG_CURRENT_EXCEPTION(); - clear(); + void load(const safe_ptr& producer, bool preview, int auto_play_delta) + { + auto_play_delta_ = auto_play_delta; + + background_ = producer; + + if(preview) // Play the first frame and pause. + { + play(); + receive(); + pause(); } } void play() { - if(is_paused_) - is_paused_ = false; - else + if(background_ != frame_producer::empty()) { background_->set_leading_producer(foreground_); foreground_ = background_; + frame_number_ = 0; background_ = frame_producer::empty(); } + resume(); } - - void pause() - { - is_paused_ = true; - } - + void stop() { - pause(); - last_frame_ = draw_frame::empty(); foreground_ = frame_producer::empty(); } - - void clear() - { - stop(); - background_ = frame_producer::empty(); - } - - safe_ptr receive() + + safe_ptr receive() { if(is_paused_) - return last_frame_; - - try + return foreground_->last_frame(); + + auto frame = receive_and_follow(foreground_); + if(frame == core::basic_frame::late()) + return foreground_->last_frame(); + + ++frame_number_; + + if(auto_play_delta_ >= 0) { - last_frame_ = foreground_->receive(); - if(last_frame_ == draw_frame::eof()) - { - CASPAR_ASSERT(foreground_ != frame_producer::empty()); + const auto frames_left = foreground_->nb_frames() - frame_number_ - auto_play_delta_; - auto following = foreground_->get_following_producer(); - following->set_leading_producer(foreground_); - foreground_ = following; + if(frames_left <= 0 || frame == core::basic_frame::eof()) + { + CASPAR_VERIFY(auto_play_delta_ != 0 || frame == core::basic_frame::eof()) - last_frame_ = receive(); + CASPAR_LOG(info) << L"Automatically playing next clip with " << auto_play_delta_ << " frames offset."; + + auto_play_delta_ = -1; + play(); + frame = receive(); } - } - catch(...) - { - CASPAR_LOG_CURRENT_EXCEPTION(); - stop(); - } - return last_frame_; + } + + return frame; } }; -layer::layer() -{ - impl_ = new implementation(); -} -layer::layer(layer&& other) -{ - impl_ = other.impl_.compare_and_swap(nullptr, other.impl_); -} -layer::~layer() +layer::layer() : impl_(new implementation()){} +layer::layer(layer&& other) : impl_(std::move(other.impl_)){} +layer& layer::operator=(layer&& other) { - delete impl_.fetch_and_store(nullptr); + impl_ = std::move(other.impl_); + return *this; } -layer& layer::operator=(layer&& other) +layer::layer(const layer& other) : impl_(new implementation(*other.impl_)){} +layer& layer::operator=(const layer& other) { - impl_ = other.impl_.compare_and_swap(nullptr, other.impl_); + layer temp(other); + temp.swap(*this); return *this; } void layer::swap(layer& other) -{ - impl_ = other.impl_.compare_and_swap(impl_, other.impl_); +{ + impl_.swap(other.impl_); } -void layer::load(const safe_ptr& frame_producer, bool play_on_load){return impl_->load(frame_producer, play_on_load);} -void layer::preview(const safe_ptr& frame_producer){return impl_->preview(frame_producer);} +void layer::load(const safe_ptr& frame_producer, bool preview, int auto_play_delta){return impl_->load(frame_producer, preview, auto_play_delta);} void layer::play(){impl_->play();} void layer::pause(){impl_->pause();} void layer::stop(){impl_->stop();} -void layer::clear(){impl_->clear();} -safe_ptr layer::receive() {return impl_->receive();} +safe_ptr layer::receive() {return impl_->receive();} safe_ptr layer::foreground() const { return impl_->foreground_;} safe_ptr layer::background() const { return impl_->background_;} }} \ No newline at end of file