]> git.sesse.net Git - casparcg/blobdiff - core/mixer/frame_mixer_device.cpp
2.0.0.2: - ogl_device: No longer monostate.
[casparcg] / core / mixer / frame_mixer_device.cpp
index b1f69eeb0fab9592cb446d5060df329f48293c39..2810132487170310973f809938e7506821bf86c3 100644 (file)
@@ -21,8 +21,8 @@
 \r
 #include "frame_mixer_device.h"\r
 \r
-#include "gpu/gpu_read_frame.h"\r
-#include "gpu/gpu_write_frame.h"\r
+#include "read_frame.h"\r
+#include "write_frame.h"\r
 \r
 #include "audio/audio_mixer.h"\r
 #include "image/image_mixer.h"\r
 #include <common/exception/exceptions.h>\r
 #include <common/concurrency/executor.h>\r
 #include <common/diagnostics/graph.h>\r
-#include <common/utility/assert.h>\r
-#include <common/utility/timer.h>\r
 #include <common/utility/tweener.h>\r
 \r
+\r
+#include <core/mixer/read_frame.h>\r
+#include <core/mixer/write_frame.h>\r
+#include <core/producer/frame/basic_frame.h>\r
+#include <core/producer/frame/frame_factory.h>\r
+#include <core/producer/frame/pixel_format.h>\r
 #include <core/producer/frame/audio_transform.h>\r
 #include <core/producer/frame/image_transform.h>\r
 \r
@@ -45,7 +49,7 @@
 \r
 #include <unordered_map>\r
 \r
-namespace caspar { namespace mixer {\r
+namespace caspar { namespace core {\r
                \r
 template<typename T>\r
 class tweened_transform\r
@@ -101,13 +105,17 @@ struct frame_mixer_device::implementation : boost::noncopyable
        boost::fusion::map<boost::fusion::pair<core::image_transform, tweened_transform<core::image_transform>>,\r
                                        boost::fusion::pair<core::audio_transform, tweened_transform<core::audio_transform>>> root_transforms_;\r
 \r
+       safe_ptr<ogl_device> ogl_;\r
+\r
        executor executor_;\r
 public:\r
-       implementation(const core::video_format_desc& format_desc) \r
+       implementation(const core::video_format_desc& format_desc, const output_t& output, const safe_ptr<ogl_device>& ogl\r
                : format_desc_(format_desc)\r
                , diag_(diagnostics::create_graph(narrow(print())))\r
-               , image_mixer_(format_desc)\r
-               , executor_(L"frame_mixer_device", true)\r
+               , image_mixer_(format_desc, ogl)\r
+               , output_(output)\r
+               , ogl_(ogl)\r
+               , executor_(L"frame_mixer_device")\r
        {\r
                diag_->add_guide("frame-time", 0.5f);   \r
                diag_->set_color("frame-time", diagnostics::color(1.0f, 0.0f, 0.0f));\r
@@ -121,20 +129,16 @@ public:
 \r
                CASPAR_LOG(info) << print() << L" Successfully initialized.";   \r
        }\r
-\r
-       boost::signals2::connection connect(const output_t::slot_type& subscriber)\r
-       {\r
-               return output_.connect(subscriber);\r
-       }\r
-\r
-       boost::unique_future<safe_ptr<const host_buffer>> mix_image(std::map<int, safe_ptr<core::basic_frame>> frames)\r
+       \r
+       boost::unique_future<safe_ptr<host_buffer>> mix_image(std::map<int, safe_ptr<core::basic_frame>> frames)\r
        {               \r
                auto& root_image_transform = boost::fusion::at_key<core::image_transform>(root_transforms_);\r
                auto& image_transforms = boost::fusion::at_key<core::image_transform>(transforms_);\r
-\r
-               auto image = image_mixer_.begin_pass();\r
+               \r
                BOOST_FOREACH(auto& frame, frames)\r
                {\r
+                       image_mixer_.begin_layer();\r
+                       \r
                        if(format_desc_.mode != core::video_mode::progressive)\r
                        {\r
                                auto frame1 = make_safe<core::basic_frame>(frame.second);\r
@@ -154,43 +158,43 @@ public:
                                frame1->get_image_transform() = root_image_transform.fetch_and_tick(1)*image_transforms[frame.first].fetch_and_tick(1);\r
                                frame1->accept(image_mixer_);\r
                        }\r
+\r
+                       image_mixer_.end_layer();\r
                }\r
-               image_mixer_.end_pass();\r
-               return std::move(image);\r
+\r
+               return image_mixer_.render();\r
        }\r
 \r
-       std::vector<short> mix_audio(const std::map<int, safe_ptr<core::basic_frame>>& frames)\r
+       std::vector<int16_t> mix_audio(const std::map<int, safe_ptr<core::basic_frame>>& frames)\r
        {\r
                auto& root_audio_transform = boost::fusion::at_key<core::audio_transform>(root_transforms_);\r
                auto& audio_transforms = boost::fusion::at_key<core::audio_transform>(transforms_);\r
 \r
-               auto audio = audio_mixer_.begin_pass();\r
                BOOST_FOREACH(auto& frame, frames)\r
                {\r
-                       int num = format_desc_.mode == core::video_mode::progressive ? 1 : 2;\r
+                       const unsigned int num = format_desc_.mode == core::video_mode::progressive ? 1 : 2;\r
 \r
                        auto frame1 = make_safe<core::basic_frame>(frame.second);\r
                        frame1->get_audio_transform() = root_audio_transform.fetch_and_tick(num)*audio_transforms[frame.first].fetch_and_tick(num);\r
                        frame1->accept(audio_mixer_);\r
                }\r
-               audio_mixer_.end_pass();\r
-               return audio;\r
+\r
+               return audio_mixer_.mix();\r
        }\r
                \r
        void send(const std::map<int, safe_ptr<core::basic_frame>>& frames)\r
        {                       \r
-               executor_.begin_invoke([=]\r
+               executor_.invoke([=]\r
                {               \r
                        diag_->set_value("input-buffer", static_cast<float>(executor_.size())/static_cast<float>(executor_.capacity()));        \r
                        frame_timer_.restart();\r
 \r
-                       auto image_future = mix_image(frames);\r
+                       auto image = mix_image(frames);\r
                        auto audio = mix_audio(frames);\r
-                       auto image = image_future.get();\r
-\r
+                       \r
                        diag_->update_value("frame-time", static_cast<float>(frame_timer_.elapsed()*format_desc_.fps*0.5));\r
 \r
-                       output_(make_safe<const gpu_read_frame>(std::move(image), std::move(audio)));\r
+                       output_(make_safe<read_frame>(std::move(image), std::move(audio)));\r
 \r
                        diag_->update_value("tick-time", static_cast<float>(tick_timer_.elapsed()*format_desc_.fps*0.5));\r
                        tick_timer_.restart();\r
@@ -199,12 +203,12 @@ public:
        }\r
                \r
        safe_ptr<core::write_frame> create_frame(void* tag, const core::pixel_format_desc& desc)\r
-       {\r
-               return make_safe<gpu_write_frame>(reinterpret_cast<int>(tag), desc, image_mixer_.create_buffers(desc));\r
+       {               \r
+               return image_mixer_.create_frame(tag, desc);\r
        }\r
                        \r
        template<typename T>    \r
-       void set_transform(const T& transform, int mix_duration, const std::wstring& tween)\r
+       void set_transform(const T& transform, unsigned int mix_duration, const std::wstring& tween)\r
        {\r
                executor_.invoke([&]\r
                {\r
@@ -217,7 +221,7 @@ public:
        }\r
                \r
        template<typename T>\r
-       void set_transform(int index, const T& transform, int mix_duration, const std::wstring& tween)\r
+       void set_transform(int index, const T& transform, unsigned int mix_duration, const std::wstring& tween)\r
        {\r
                executor_.invoke([&]\r
                {\r
@@ -230,7 +234,7 @@ public:
        }\r
                \r
        template<typename T>\r
-       void apply_transform(const std::function<T(const T&)>& transform, int mix_duration, const std::wstring& tween)\r
+       void apply_transform(const std::function<T(const T&)>& transform, unsigned int mix_duration, const std::wstring& tween)\r
        {\r
                return executor_.invoke([&]\r
                {\r
@@ -243,7 +247,7 @@ public:
        }\r
                \r
        template<typename T>\r
-       void apply_transform(int index, const std::function<T(T)>& transform, int mix_duration, const std::wstring& tween)\r
+       void apply_transform(int index, const std::function<T(T)>& transform, unsigned int mix_duration, const std::wstring& tween)\r
        {\r
                executor_.invoke([&]\r
                {\r
@@ -256,7 +260,7 @@ public:
        }\r
 \r
        template<typename T>\r
-       void reset_transform(int mix_duration, const std::wstring& tween)\r
+       void reset_transform(unsigned int mix_duration, const std::wstring& tween)\r
        {\r
                executor_.invoke([&]\r
                {\r
@@ -269,7 +273,7 @@ public:
        }\r
 \r
        template<typename T>\r
-       void reset_transform(int index, int mix_duration, const std::wstring& tween)\r
+       void reset_transform(int index, unsigned int mix_duration, const std::wstring& tween)\r
        {\r
                executor_.invoke([&]\r
                {               \r
@@ -283,9 +287,9 @@ public:
        }\r
 };\r
        \r
-frame_mixer_device::frame_mixer_device(const core::video_format_desc& format_desc) : impl_(new implementation(format_desc)){}\r
+frame_mixer_device::frame_mixer_device(const core::video_format_desc& format_desc, const output_t& output, const safe_ptr<ogl_device>& ogl)\r
+       : impl_(new implementation(format_desc, output, ogl)){}\r
 frame_mixer_device::frame_mixer_device(frame_mixer_device&& other) : impl_(std::move(other.impl_)){}\r
-boost::signals2::connection frame_mixer_device::connect(const output_t::slot_type& subscriber){return impl_->connect(subscriber);}\r
 void frame_mixer_device::send(const std::map<int, safe_ptr<core::basic_frame>>& frames){impl_->send(frames);}\r
 const core::video_format_desc& frame_mixer_device::get_video_format_desc() const { return impl_->format_desc_; }\r
 safe_ptr<core::write_frame> frame_mixer_device::create_frame(void* tag, const core::pixel_format_desc& desc){ return impl_->create_frame(tag, desc); }         \r
@@ -306,17 +310,17 @@ safe_ptr<core::write_frame> frame_mixer_device::create_frame(void* tag, core::pi
        desc.planes.push_back( core::pixel_format_desc::plane(get_video_format_desc().width, get_video_format_desc().height, 4));\r
        return create_frame(tag, desc);\r
 }\r
-void frame_mixer_device::set_image_transform(const core::image_transform& transform, int mix_duration, const std::wstring& tween){impl_->set_transform<core::image_transform>(transform, mix_duration, tween);}\r
-void frame_mixer_device::set_image_transform(int index, const core::image_transform& transform, int mix_duration, const std::wstring& tween){impl_->set_transform<core::image_transform>(index, transform, mix_duration, tween);}\r
-void frame_mixer_device::set_audio_transform(const core::audio_transform& transform, int mix_duration, const std::wstring& tween){impl_->set_transform<core::audio_transform>(transform, mix_duration, tween);}\r
-void frame_mixer_device::set_audio_transform(int index, const core::audio_transform& transform, int mix_duration, const std::wstring& tween){impl_->set_transform<core::audio_transform>(index, transform, mix_duration, tween);}\r
-void frame_mixer_device::apply_image_transform(const std::function<core::image_transform(core::image_transform)>& transform, int mix_duration, const std::wstring& tween){impl_->apply_transform<core::image_transform>(transform, mix_duration, tween);}\r
-void frame_mixer_device::apply_image_transform(int index, const std::function<core::image_transform(core::image_transform)>& transform, int mix_duration, const std::wstring& tween){impl_->apply_transform<core::image_transform>(index, transform, mix_duration, tween);}\r
-void frame_mixer_device::apply_audio_transform(const std::function<core::audio_transform(core::audio_transform)>& transform, int mix_duration, const std::wstring& tween){impl_->apply_transform<core::audio_transform>(transform, mix_duration, tween);}\r
-void frame_mixer_device::apply_audio_transform(int index, const std::function<core::audio_transform(core::audio_transform)>& transform, int mix_duration, const std::wstring& tween){impl_->apply_transform<core::audio_transform>(index, transform, mix_duration, tween);}\r
-void frame_mixer_device::reset_image_transform(int mix_duration, const std::wstring& tween){impl_->reset_transform<core::image_transform>(mix_duration, tween);}\r
-void frame_mixer_device::reset_image_transform(int index, int mix_duration, const std::wstring& tween){impl_->reset_transform<core::image_transform>(index, mix_duration, tween);}\r
-void frame_mixer_device::reset_audio_transform(int mix_duration, const std::wstring& tween){impl_->reset_transform<core::audio_transform>(mix_duration, tween);}\r
-void frame_mixer_device::reset_audio_transform(int index, int mix_duration, const std::wstring& tween){impl_->reset_transform<core::audio_transform>(index, mix_duration, tween);}\r
+void frame_mixer_device::set_image_transform(const core::image_transform& transform, unsigned int mix_duration, const std::wstring& tween){impl_->set_transform<core::image_transform>(transform, mix_duration, tween);}\r
+void frame_mixer_device::set_image_transform(int index, const core::image_transform& transform, unsigned int mix_duration, const std::wstring& tween){impl_->set_transform<core::image_transform>(index, transform, mix_duration, tween);}\r
+void frame_mixer_device::set_audio_transform(const core::audio_transform& transform, unsigned int mix_duration, const std::wstring& tween){impl_->set_transform<core::audio_transform>(transform, mix_duration, tween);}\r
+void frame_mixer_device::set_audio_transform(int index, const core::audio_transform& transform, unsigned int mix_duration, const std::wstring& tween){impl_->set_transform<core::audio_transform>(index, transform, mix_duration, tween);}\r
+void frame_mixer_device::apply_image_transform(const std::function<core::image_transform(core::image_transform)>& transform, unsigned int mix_duration, const std::wstring& tween){impl_->apply_transform<core::image_transform>(transform, mix_duration, tween);}\r
+void frame_mixer_device::apply_image_transform(int index, const std::function<core::image_transform(core::image_transform)>& transform, unsigned int mix_duration, const std::wstring& tween){impl_->apply_transform<core::image_transform>(index, transform, mix_duration, tween);}\r
+void frame_mixer_device::apply_audio_transform(const std::function<core::audio_transform(core::audio_transform)>& transform, unsigned int mix_duration, const std::wstring& tween){impl_->apply_transform<core::audio_transform>(transform, mix_duration, tween);}\r
+void frame_mixer_device::apply_audio_transform(int index, const std::function<core::audio_transform(core::audio_transform)>& transform, unsigned int mix_duration, const std::wstring& tween){impl_->apply_transform<core::audio_transform>(index, transform, mix_duration, tween);}\r
+void frame_mixer_device::reset_image_transform(unsigned int mix_duration, const std::wstring& tween){impl_->reset_transform<core::image_transform>(mix_duration, tween);}\r
+void frame_mixer_device::reset_image_transform(int index, unsigned int mix_duration, const std::wstring& tween){impl_->reset_transform<core::image_transform>(index, mix_duration, tween);}\r
+void frame_mixer_device::reset_audio_transform(unsigned int mix_duration, const std::wstring& tween){impl_->reset_transform<core::audio_transform>(mix_duration, tween);}\r
+void frame_mixer_device::reset_audio_transform(int index, unsigned int mix_duration, const std::wstring& tween){impl_->reset_transform<core::audio_transform>(index, mix_duration, tween);}\r
 \r
 }}
\ No newline at end of file