X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=core%2Fproducer%2Ftransition%2Ftransition_producer.cpp;h=24cf9287533810a4854657b8f5cab816ac344fb8;hb=116e09a218cf056e4de868454b0fe26dc4db1413;hp=03b599ba8a71d328d155f7e9fa5a218f91b1870e;hpb=89a83b868463e2b917748d6af14538d0f3bb97c9;p=casparcg diff --git a/core/producer/transition/transition_producer.cpp b/core/producer/transition/transition_producer.cpp index 03b599ba8..24cf92875 100644 --- a/core/producer/transition/transition_producer.cpp +++ b/core/producer/transition/transition_producer.cpp @@ -21,151 +21,161 @@ #include "transition_producer.h" -#include "../../video_format.h" -#include "../../mixer/frame/draw_frame.h" -#include "../../mixer/frame_mixer_device.h" -#include "../../mixer/image/image_transform.h" -#include "../../mixer/audio/audio_mixer.h" -#include "../../mixer/audio/audio_transform.h" +#include -#include +#include +#include + +#include + +#include + +using namespace boost::assign; namespace caspar { namespace core { -struct transition_producer::implementation : boost::noncopyable +struct transition_producer : public frame_producer { - unsigned short current_frame_; + const field_mode::type mode_; + unsigned int current_frame_; const transition_info info_; safe_ptr dest_producer_; safe_ptr source_producer_; - std::shared_ptr frame_factory_; - - implementation(const safe_ptr& dest, const transition_info& info) - : current_frame_(0) + safe_ptr last_frame_; + + explicit transition_producer(const field_mode::type& mode, const safe_ptr& dest, const transition_info& info) + : mode_(mode) + , current_frame_(0) , info_(info) , dest_producer_(dest) - , source_producer_(frame_producer::empty()){} - - void initialize(const safe_ptr& frame_factory) - { - dest_producer_->initialize(frame_factory); - frame_factory_ = frame_factory; - } + , source_producer_(frame_producer::empty()) + , last_frame_(basic_frame::empty()){} + + // frame_producer - safe_ptr get_following_producer() const + virtual safe_ptr get_following_producer() const { return dest_producer_; } - void set_leading_producer(const safe_ptr& producer) + virtual void set_leading_producer(const safe_ptr& producer) { source_producer_ = producer; } - - safe_ptr receive() - { - if(current_frame_++ >= info_.duration) - return draw_frame::eof(); - auto source = draw_frame::empty(); - auto dest = draw_frame::empty(); + virtual safe_ptr receive(int hints) + { + if(++current_frame_ >= info_.duration) + return basic_frame::eof(); + + auto dest = basic_frame::empty(); + auto source = basic_frame::empty(); - tbb::parallel_invoke - ( - [&]{dest = render_sub_frame(dest_producer_);}, - [&]{source = render_sub_frame(source_producer_);} - ); + tbb::parallel_invoke( + [&] + { + dest = receive_and_follow(dest_producer_, hints); + if(dest == core::basic_frame::late()) + dest = dest_producer_->last_frame(); + }, + [&] + { + source = receive_and_follow(source_producer_, hints); + if(source == core::basic_frame::late()) + source = source_producer_->last_frame(); + }); return compose(dest, source); } - - safe_ptr render_sub_frame(safe_ptr& producer) + + virtual safe_ptr last_frame() const { - if(producer == frame_producer::empty()) - return draw_frame::eof(); + return disable_audio(last_frame_); + } - auto frame = draw_frame::eof(); - try - { - frame = producer->receive(); - } - catch(...) - { - CASPAR_LOG_CURRENT_EXCEPTION(); - producer = frame_producer::empty(); - CASPAR_LOG(warning) << "Failed to receive frame. Removed producer from transition."; - } + virtual int64_t nb_frames() const + { + return get_following_producer()->nb_frames(); + } - if(frame == draw_frame::eof()) - { - try - { - auto following = producer->get_following_producer(); - following->initialize(safe_ptr(frame_factory_)); - following->set_leading_producer(producer); - producer = std::move(following); - } - catch(...) - { - CASPAR_LOG_CURRENT_EXCEPTION(); - producer = frame_producer::empty(); - CASPAR_LOG(warning) << "Failed to initialize following producer."; - } - - return render_sub_frame(producer); - } - return frame; + virtual std::wstring print() const + { + return L"transition[" + source_producer_->print() + L"|" + dest_producer_->print() + L"]"; } - - safe_ptr compose(const safe_ptr& dest_frame, const safe_ptr& src_frame) + + // transition_producer + + safe_ptr compose(const safe_ptr& dest_frame, const safe_ptr& src_frame) { - if(dest_frame == draw_frame::eof() && src_frame == draw_frame::eof()) - return draw_frame::eof(); - if(info_.type == transition::cut) - return src_frame != draw_frame::eof() ? src_frame : draw_frame::empty(); + return src_frame; - double alpha = static_cast(current_frame_)/static_cast(info_.duration); + const double delta1 = info_.tweener(current_frame_*2-1, 0.0, 1.0, info_.duration*2); + const double delta2 = info_.tweener(current_frame_*2, 0.0, 1.0, info_.duration*2); - auto my_src_frame = draw_frame(src_frame); - auto my_dest_frame = draw_frame(dest_frame); + const double dir = info_.direction == transition_direction::from_left ? 1.0 : -1.0; + + // For interlaced transitions. Seperate fields into seperate frames which are transitioned accordingly. + + auto s_frame1 = make_safe(src_frame); + auto s_frame2 = make_safe(src_frame); - my_src_frame.get_audio_transform().set_gain(1.0-alpha); - my_dest_frame.get_audio_transform().set_gain(alpha); + s_frame1->get_frame_transform().volume = 0.0; + s_frame2->get_frame_transform().volume = 1.0-delta2; - double dir = info_.direction == transition_direction::from_left ? 1.0 : -1.0; + auto d_frame1 = make_safe(dest_frame); + auto d_frame2 = make_safe(dest_frame); + d_frame1->get_frame_transform().volume = 0.0; + d_frame2->get_frame_transform().volume = delta2; + if(info_.type == transition::mix) - my_dest_frame.get_image_transform().set_opacity(alpha); - else if(info_.type == transition::slide) - my_dest_frame.get_image_transform().set_image_translation((-1.0+alpha)*dir, 0.0); + { + d_frame1->get_frame_transform().opacity = delta1; + d_frame1->get_frame_transform().is_mix = true; + d_frame2->get_frame_transform().opacity = delta2; + d_frame2->get_frame_transform().is_mix = true; + + s_frame1->get_frame_transform().opacity = 1.0-delta1; + s_frame1->get_frame_transform().is_mix = true; + s_frame2->get_frame_transform().opacity = 1.0-delta2; + s_frame2->get_frame_transform().is_mix = true; + } + if(info_.type == transition::slide) + { + d_frame1->get_frame_transform().fill_translation[0] = (-1.0+delta1)*dir; + d_frame2->get_frame_transform().fill_translation[0] = (-1.0+delta2)*dir; + } else if(info_.type == transition::push) { - my_dest_frame.get_image_transform().set_image_translation((-1.0+alpha)*dir, 0.0); - my_src_frame.get_image_transform().set_image_translation((0.0+alpha)*dir, 0.0); + d_frame1->get_frame_transform().fill_translation[0] = (-1.0+delta1)*dir; + d_frame2->get_frame_transform().fill_translation[0] = (-1.0+delta2)*dir; + + s_frame1->get_frame_transform().fill_translation[0] = (0.0+delta1)*dir; + s_frame2->get_frame_transform().fill_translation[0] = (0.0+delta2)*dir; } else if(info_.type == transition::wipe) - my_dest_frame.get_image_transform().set_mask_scale(alpha, 1.0); - - return draw_frame(std::move(my_src_frame), std::move(my_dest_frame)); - } + { + d_frame1->get_frame_transform().clip_scale[0] = delta1; + d_frame2->get_frame_transform().clip_scale[0] = delta2; + } + + const auto s_frame = s_frame1->get_frame_transform() == s_frame2->get_frame_transform() ? s_frame2 : basic_frame::interlace(s_frame1, s_frame2, mode_); + const auto d_frame = d_frame1->get_frame_transform() == d_frame2->get_frame_transform() ? d_frame2 : basic_frame::interlace(d_frame1, d_frame2, mode_); + + last_frame_ = basic_frame::combine(s_frame2, d_frame2); - std::wstring print() const - { - return L"transition[" + (source_producer_->print()) + L" -> " + (dest_producer_->print()) + L"]"; + return basic_frame::combine(s_frame, d_frame); } }; -transition_producer::transition_producer(transition_producer&& other) : impl_(std::move(other.impl_)){} -transition_producer::transition_producer(const safe_ptr& dest, const transition_info& info) : impl_(new implementation(dest, info)){} -safe_ptr transition_producer::receive(){return impl_->receive();} -safe_ptr transition_producer::get_following_producer() const{return impl_->get_following_producer();} -void transition_producer::set_leading_producer(const safe_ptr& producer) { impl_->set_leading_producer(producer); } -void transition_producer::initialize(const safe_ptr& frame_factory) { impl_->initialize(frame_factory);} -std::wstring transition_producer::print() const { return impl_->print();} +safe_ptr create_transition_producer(const field_mode::type& mode, const safe_ptr& destination, const transition_info& info) +{ + return make_safe(mode, destination, info); +} }}