X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=core%2Fproducer%2Ftransition%2Ftransition_producer.cpp;h=6a24c1384ff82ff0eaddb380a3e64e6dba1cc7ef;hb=e3002fb4a4cfead3a5e9372a680b72772a671b9e;hp=d8e4c3a33e3cb94f936ed73b00bc74a4666e9dc6;hpb=305ab9dc5560156b1c9591e780d50e0b6ff9a35e;p=casparcg diff --git a/core/producer/transition/transition_producer.cpp b/core/producer/transition/transition_producer.cpp index d8e4c3a33..6a24c1384 100644 --- a/core/producer/transition/transition_producer.cpp +++ b/core/producer/transition/transition_producer.cpp @@ -21,13 +21,13 @@ #include "transition_producer.h" -#include "../../frame/frame_format.h" -#include "../../frame/gpu_frame.h" -#include "../../frame/gpu_composite_frame.h" -#include "../../frame/frame_factory.h" +#include "../../video/video_format.h" +#include "../../processor/frame.h" +#include "../../processor/composite_frame.h" +#include "../../processor/frame_processor_device.h" #include "../../../common/utility/memory.h" -#include "../../renderer/render_device.h" +#include "../../producer/frame_producer_device.h" #include @@ -35,8 +35,8 @@ namespace caspar { namespace core { struct transition_producer::implementation : boost::noncopyable { - implementation(const frame_producer_ptr& dest, const transition_info& info, const frame_format_desc& format_desc) - : current_frame_(0), info_(info), format_desc_(format_desc), dest_producer_(dest) + implementation(const frame_producer_ptr& dest, const transition_info& info) + : current_frame_(0), info_(info), dest_producer_(dest) { if(!dest) BOOST_THROW_EXCEPTION(null_argument() << arg_name_info("dest")); @@ -52,29 +52,40 @@ struct transition_producer::implementation : boost::noncopyable source_producer_ = producer; } - gpu_frame_ptr render_frame() + frame_ptr render_frame() { - if(current_frame_++ >= info_.duration) - return nullptr; + if(current_frame_ == 0) + CASPAR_LOG(info) << "Transition started."; - gpu_frame_ptr source; - gpu_frame_ptr dest; + frame_ptr result = [&]() -> frame_ptr + { + if(current_frame_++ >= info_.duration) + return nullptr; - tbb::parallel_invoke - ( - [&]{dest = render_frame(dest_producer_);}, - [&]{source = render_frame(source_producer_);} - ); + frame_ptr source; + frame_ptr dest; + + tbb::parallel_invoke + ( + [&]{dest = render_frame(dest_producer_);}, + [&]{source = render_frame(source_producer_);} + ); - return compose(dest, source); + return compose(dest, source); + }(); + + if(result == nullptr) + CASPAR_LOG(info) << "Transition ended."; + + return result; } - gpu_frame_ptr render_frame(frame_producer_ptr& producer) + frame_ptr render_frame(frame_producer_ptr& producer) { if(producer == nullptr) return nullptr; - gpu_frame_ptr frame; + frame_ptr frame; try { frame = producer->render_frame(); @@ -90,7 +101,7 @@ struct transition_producer::implementation : boost::noncopyable producer->get_following_producer() != nullptr) { auto following = producer->get_following_producer(); - following->initialize(factory_); + following->initialize(frame_processor_); following->set_leading_producer(producer); producer = following; return render_frame(producer); @@ -98,7 +109,7 @@ struct transition_producer::implementation : boost::noncopyable return frame; } - void set_volume(const gpu_frame_ptr& frame, int volume) + void set_volume(const frame_ptr& frame, int volume) { if(!frame) return; @@ -107,16 +118,16 @@ struct transition_producer::implementation : boost::noncopyable frame->audio_data()[n] = static_cast((static_cast(frame->audio_data()[n])*volume)>>8); } - gpu_frame_ptr compose(const gpu_frame_ptr& dest_frame, gpu_frame_ptr src_frame) + frame_ptr compose(const frame_ptr& dest_frame, frame_ptr src_frame) { - if(info_.type == transition_type::cut) + if(info_.type == transition::cut) return src_frame; if(!dest_frame) return nullptr; double alpha = static_cast(current_frame_)/static_cast(info_.duration); - int volume = static_cast(static_cast(current_frame_)/static_cast(info_.duration)*256.0); + int volume = static_cast(alpha*256.0); tbb::parallel_invoke ( @@ -124,16 +135,16 @@ struct transition_producer::implementation : boost::noncopyable [&]{set_volume(src_frame, 256-volume);} ); - if(info_.type == transition_type::mix) + if(info_.type == transition::mix) dest_frame->alpha(alpha); - else if(info_.type == transition_type::slide) + else if(info_.type == transition::slide) { if(info_.direction == transition_direction::from_left) dest_frame->translate(-1.0+alpha, 0.0); else if(info_.direction == transition_direction::from_right) dest_frame->translate(1.0-alpha, 0.0); } - else if(info_.type == transition_type::push) + else if(info_.type == transition::push) { if(info_.direction == transition_direction::from_left) { @@ -148,51 +159,48 @@ struct transition_producer::implementation : boost::noncopyable src_frame->translate(0.0-alpha, 0.0); } } - else if(info_.type == transition_type::wipe) + else if(info_.type == transition::wipe) { if(info_.direction == transition_direction::from_left) { dest_frame->translate(-1.0+alpha, 0.0); - dest_frame->texcoords(rectangle(-1.0+alpha, 1.0, alpha, 0.0)); + dest_frame->texcoords(-1.0+alpha, 1.0, alpha, 0.0); } else if(info_.direction == transition_direction::from_right) { dest_frame->translate(1.0-alpha, 0.0); - dest_frame->texcoords(rectangle(1.0-alpha, 1.0, 2.0-alpha, 0.0)); + dest_frame->texcoords(1.0-alpha, 1.0, 2.0-alpha, 0.0); } } - auto composite = std::make_shared(); + auto composite = std::make_shared(); if(src_frame) composite->add(src_frame); composite->add(dest_frame); return composite; } - void initialize(const frame_factory_ptr& factory) + void initialize(const frame_processor_device_ptr& frame_processor) { - dest_producer_->initialize(factory); - factory_ = factory; + dest_producer_->initialize(frame_processor); + frame_processor_ = frame_processor; } - - const frame_format_desc format_desc_; - + frame_producer_ptr source_producer_; frame_producer_ptr dest_producer_; unsigned short current_frame_; const transition_info info_; - frame_factory_ptr factory_; + frame_processor_device_ptr frame_processor_; }; -transition_producer::transition_producer(const frame_producer_ptr& dest, const transition_info& info, const frame_format_desc& format_desc) - : impl_(new implementation(dest, info, format_desc)){} -gpu_frame_ptr transition_producer::render_frame(){return impl_->render_frame();} +transition_producer::transition_producer(const frame_producer_ptr& dest, const transition_info& info) + : impl_(new implementation(dest, info)){} +frame_ptr transition_producer::render_frame(){return impl_->render_frame();} frame_producer_ptr transition_producer::get_following_producer() const{return impl_->get_following_producer();} void transition_producer::set_leading_producer(const frame_producer_ptr& producer) { impl_->set_leading_producer(producer); } -const frame_format_desc& transition_producer::get_frame_format_desc() const { return impl_->format_desc_; } -void transition_producer::initialize(const frame_factory_ptr& factory) { impl_->initialize(factory);} +void transition_producer::initialize(const frame_processor_device_ptr& frame_processor) { impl_->initialize(frame_processor);} }}