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