X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=core%2Fproducer%2Flayer.cpp;h=a8b498c32640b1b84dcac165f3519bfc6b28990e;hb=e2708d544da3e402cfe3be32f798c85f447d10de;hp=4f6c6b3bfce4d1a3965e26add0eb144a0693a2c3;hpb=55110c0728cb06e98c37d0abfab7b0b26d2b7ab9;p=casparcg diff --git a/core/producer/layer.cpp b/core/producer/layer.cpp index 4f6c6b3bf..a8b498c32 100644 --- a/core/producer/layer.cpp +++ b/core/producer/layer.cpp @@ -1,21 +1,22 @@ /* -* copyright (c) 2010 Sveriges Television AB +* Copyright (c) 2011 Sveriges Television AB * -* This file is part of CasparCG. +* This file is part of CasparCG (www.casparcg.com). * -* 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 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 . +* 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 . * +* Author: Robert Nagy, ronag89@gmail.com */ #include "../stdafx.h" @@ -24,49 +25,55 @@ #include "frame_producer.h" -#include "frame/basic_frame.h" +#include "../frame/draw_frame.h" +#include "../frame/frame_transform.h" +#include +#include namespace caspar { namespace core { - -struct layer::implementation + +struct layer::impl { safe_ptr foreground_; safe_ptr background_; - bool is_paused_; - int auto_play_delta_; int64_t frame_number_; + boost::optional auto_play_delta_; + bool is_paused_; + public: - implementation() + impl() : foreground_(frame_producer::empty()) , background_(frame_producer::empty()) + , frame_number_(0) , is_paused_(false) - , auto_play_delta_(-1){} + { + } - void pause(){is_paused_ = true;} - void resume(){is_paused_ = false;} + void pause() + { + is_paused_ = true; + } - void load(const safe_ptr& producer, bool preview, int auto_play_delta) + void resume() + { + is_paused_ = false; + } + + void load(const safe_ptr& producer, bool preview, const boost::optional& auto_play_delta) { - background_ = producer; + background_ = producer; + auto_play_delta_ = auto_play_delta; - if(auto_play_delta > -1) - { - if(producer->nb_frames() > 0) - auto_play_delta_ = auto_play_delta; - else - CASPAR_LOG(warning) << producer->print() << L" Does not support auto-play."; - } + if(auto_play_delta_ && foreground_ == frame_producer::empty()) + play(); if(preview) // Play the first frame and pause. { play(); - receive(); + receive(frame_producer::flags::none); pause(); } - - if(auto_play_delta >= 0 && foreground_ == frame_producer::empty()) - play(); } void play() @@ -74,67 +81,92 @@ public: if(background_ != frame_producer::empty()) { background_->set_leading_producer(foreground_); - foreground_ = background_; - frame_number_ = 0; - auto_play_delta_ = -1; - background_ = frame_producer::empty(); + + foreground_ = background_; + background_ = frame_producer::empty(); + frame_number_ = 0; + auto_play_delta_.reset(); } - resume(); + + is_paused_ = false; } void stop() { - foreground_ = frame_producer::empty(); + foreground_ = frame_producer::empty(); + background_ = background_; + frame_number_ = 0; + auto_play_delta_.reset(); + + is_paused_ = true; } - safe_ptr receive() + safe_ptr receive(int flags) { - if(is_paused_) - return foreground_->last_frame(); + try + { + if(is_paused_) + return draw_frame::silence(foreground_->last_frame()); - const auto frames_left = foreground_->nb_frames() - (++frame_number_) - auto_play_delta_; + auto frame = receive_and_follow(foreground_, flags); + if(frame == core::draw_frame::late()) + return draw_frame::silence(foreground_->last_frame()); - auto frame = receive_and_follow(foreground_); - if(frame == core::basic_frame::late()) - return foreground_->last_frame(); - - if(auto_play_delta_ == 0) - { - if(frame == core::basic_frame::eof()) + if(auto_play_delta_) { - CASPAR_ASSERT(frames_left == 0); - - CASPAR_LOG(info) << L"Automatically playing next clip with " << auto_play_delta_ << " frames offset."; - - play(); - frame = receive(); + auto frames_left = static_cast(foreground_->nb_frames()) - static_cast(++frame_number_) - static_cast(*auto_play_delta_); + if(frames_left < 1) + { + play(); + return receive(flags); + } } + + return frame; } - else if(auto_play_delta_ > 0) + catch(...) { - if(frames_left <= 0 || frame == core::basic_frame::eof()) - { - CASPAR_VERIFY(frame != core::basic_frame::eof() && "Received early EOF. Media duration metadata incorrect."); - - CASPAR_LOG(info) << L"Automatically playing next clip with " << auto_play_delta_ << " frames offset."; - - play(); - frame = receive(); - } + CASPAR_LOG_CURRENT_EXCEPTION(); + stop(); + return core::draw_frame::empty(); } - - return frame; + } + + boost::unique_future call(bool foreground, const std::wstring& param) + { + return (foreground ? foreground_ : background_)->call(param); + } + + bool empty() const + { + return background_ == core::frame_producer::empty() && foreground_ == core::frame_producer::empty(); + } + + boost::property_tree::wptree info() const + { + boost::property_tree::wptree info; + info.add(L"status", is_paused_ ? L"paused" : (foreground_ == frame_producer::empty() ? L"stopped" : L"playing")); + info.add(L"auto_delta", (auto_play_delta_ ? boost::lexical_cast(*auto_play_delta_) : L"null")); + info.add(L"frame-number", frame_number_); + + auto nb_frames = foreground_->nb_frames(); + + info.add(L"nb_frames", nb_frames == std::numeric_limits::max() ? -1 : nb_frames); + info.add(L"frames-left", nb_frames == std::numeric_limits::max() ? -1 : (foreground_->nb_frames() - frame_number_ - (auto_play_delta_ ? *auto_play_delta_ : 0))); + info.add_child(L"foreground.producer", foreground_->info()); + info.add_child(L"background.producer", background_->info()); + return info; } }; -layer::layer() : impl_(new implementation()){} +layer::layer() : impl_(new impl()){} layer::layer(layer&& other) : impl_(std::move(other.impl_)){} layer& layer::operator=(layer&& other) { impl_ = std::move(other.impl_); return *this; } -layer::layer(const layer& other) : impl_(new implementation(*other.impl_)){} +layer::layer(const layer& other) : impl_(new impl(*other.impl_)){} layer& layer::operator=(const layer& other) { layer temp(other); @@ -145,11 +177,16 @@ void layer::swap(layer& other) { impl_.swap(other.impl_); } -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::load(const safe_ptr& frame_producer, bool preview, const boost::optional& 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();} -safe_ptr layer::receive() {return impl_->receive();} +bool layer::is_paused() const{return impl_->is_paused_;} +int64_t layer::frame_number() const{return impl_->frame_number_;} +safe_ptr layer::receive(int flags) {return impl_->receive(flags);} safe_ptr layer::foreground() const { return impl_->foreground_;} safe_ptr layer::background() const { return impl_->background_;} +bool layer::empty() const {return impl_->empty();} +boost::unique_future layer::call(bool foreground, const std::wstring& param){return impl_->call(foreground, param);} +boost::property_tree::wptree layer::info() const{return impl_->info();} }} \ No newline at end of file