]> git.sesse.net Git - casparcg/commitdiff
2.0. image_mixer: Refactored.
authorronag <ronag@362d55ac-95cf-4e76-9f9a-cbaa9c17b72d>
Fri, 24 Jun 2011 23:25:58 +0000 (23:25 +0000)
committerronag <ronag@362d55ac-95cf-4e76-9f9a-cbaa9c17b72d>
Fri, 24 Jun 2011 23:25:58 +0000 (23:25 +0000)
git-svn-id: https://casparcg.svn.sourceforge.net/svnroot/casparcg/server/branches/2.0.0.2@952 362d55ac-95cf-4e76-9f9a-cbaa9c17b72d

core/mixer/image/image_mixer.cpp
core/mixer/write_frame.cpp
modules/ffmpeg/ffmpeg.vcxproj
shell/casparcg.config

index 5f9ace0c9748d80f768bfa6a7e2f12813173e8fb..8e9c05f88c061b7367fe2ba9d4c35dc0f16d6482 100644 (file)
 \r
 namespace caspar { namespace core {\r
                \r
+struct render_item\r
+{\r
+       pixel_format_desc                                        desc;\r
+       std::vector<safe_ptr<device_buffer>> textures;\r
+       core::image_transform                            transform;\r
+       int                                                                      tag;\r
+};\r
+\r
 struct image_mixer::implementation : boost::noncopyable\r
 {      \r
        static const size_t LOCAL_KEY_INDEX = 3;\r
        static const size_t LAYER_KEY_INDEX = 4;\r
-\r
-       struct render_item\r
-       {\r
-               pixel_format_desc                                        desc;\r
-               std::vector<safe_ptr<device_buffer>> textures;\r
-               int                                                                      tag;\r
-               core::image_transform                            transform;\r
-       };\r
-\r
+       \r
        video_channel_context&                                  channel_;\r
        \r
        std::stack<core::image_transform>               transform_stack_;\r
-       std::queue<std::queue<render_item>>             render_queue_;\r
+\r
+       std::queue<std::queue<std::queue<render_item>>> render_queue_; // layer/stream/items\r
        \r
        image_kernel                                                    kernel_;\r
                \r
        safe_ptr<device_buffer>                                 draw_buffer_;\r
        safe_ptr<device_buffer>                                 write_buffer_;\r
 \r
-       safe_ptr<device_buffer>                                 local_key_buffer_;\r
+       safe_ptr<device_buffer>                                 stream_key_buffer_;\r
        safe_ptr<device_buffer>                                 layer_key_buffer_;\r
 \r
        bool                                                                    local_key_;\r
@@ -78,7 +79,7 @@ public:
                : channel_(video_channel)\r
                , draw_buffer_(video_channel.ogl().create_device_buffer(video_channel.get_format_desc().width, channel_.get_format_desc().height, 4))\r
                , write_buffer_ (video_channel.ogl().create_device_buffer(video_channel.get_format_desc().width, channel_.get_format_desc().height, 4))\r
-               , local_key_buffer_(video_channel.ogl().create_device_buffer(video_channel.get_format_desc().width, channel_.get_format_desc().height, 1))\r
+               , stream_key_buffer_(video_channel.ogl().create_device_buffer(video_channel.get_format_desc().width, channel_.get_format_desc().height, 1))\r
                , layer_key_buffer_(video_channel.ogl().create_device_buffer(video_channel.get_format_desc().width, channel_.get_format_desc().height, 1))\r
                , local_key_(false)\r
                , layer_key_(false)\r
@@ -99,8 +100,14 @@ public:
                \r
        void visit(core::write_frame& frame)\r
        {                       \r
-               render_item item = {frame.get_pixel_format_desc(), frame.get_textures(), frame.tag(), transform_stack_.top()*frame.get_image_transform()};      \r
-               render_queue_.back().push(item);\r
+               render_item item = {frame.get_pixel_format_desc(), frame.get_textures(), transform_stack_.top()*frame.get_image_transform(), frame.tag()};      \r
+\r
+               auto& layer = render_queue_.back();\r
+\r
+               if(layer.empty() || (!layer.back().empty() && layer.back().back().tag != frame.tag()))\r
+                       layer.push(std::queue<render_item>());\r
+               \r
+               layer.back().push(item);\r
        }\r
 \r
        void end()\r
@@ -110,7 +117,7 @@ public:
 \r
        void begin_layer()\r
        {\r
-               render_queue_.push(std::queue<render_item>());\r
+               render_queue_.push(std::queue<std::queue<render_item>>());\r
        }\r
 \r
        void end_layer()\r
@@ -119,121 +126,94 @@ public:
 \r
        void reinitialize_buffers()\r
        {\r
-               draw_buffer_      = channel_.ogl().create_device_buffer(channel_.get_format_desc().width, channel_.get_format_desc().height, 4);\r
-               write_buffer_     = channel_.ogl().create_device_buffer(channel_.get_format_desc().width, channel_.get_format_desc().height, 4);\r
-               local_key_buffer_ = channel_.ogl().create_device_buffer(channel_.get_format_desc().width, channel_.get_format_desc().height, 1);\r
-               layer_key_buffer_ = channel_.ogl().create_device_buffer(channel_.get_format_desc().width, channel_.get_format_desc().height, 1);\r
+               draw_buffer_       = channel_.ogl().create_device_buffer(channel_.get_format_desc().width, channel_.get_format_desc().height, 4);\r
+               write_buffer_      = channel_.ogl().create_device_buffer(channel_.get_format_desc().width, channel_.get_format_desc().height, 4);\r
+               stream_key_buffer_ = channel_.ogl().create_device_buffer(channel_.get_format_desc().width, channel_.get_format_desc().height, 1);\r
+               layer_key_buffer_  = channel_.ogl().create_device_buffer(channel_.get_format_desc().width, channel_.get_format_desc().height, 1);\r
                channel_.ogl().gc();\r
        }\r
 \r
        safe_ptr<host_buffer> render()\r
        {               \r
-               auto read_buffer = channel_.ogl().create_host_buffer(channel_.get_format_desc().size, host_buffer::read_only);          \r
-\r
                auto render_queue = std::move(render_queue_);\r
 \r
-               channel_.ogl().invoke([=]() mutable\r
+               return channel_.ogl().invoke([=]() mutable -> safe_ptr<host_buffer>\r
                {\r
                        if(draw_buffer_->width() != channel_.get_format_desc().width || draw_buffer_->height() != channel_.get_format_desc().height)\r
                                reinitialize_buffers();\r
+                       \r
+                       return do_render(std::move(render_queue));\r
+               });\r
+       }\r
+       \r
+       safe_ptr<host_buffer> do_render(std::queue<std::queue<std::queue<render_item>>>&& render_queue)\r
+       {\r
+               auto read_buffer = channel_.ogl().create_host_buffer(channel_.get_format_desc().size, host_buffer::read_only);\r
 \r
-                       local_key_ = false;\r
-                       layer_key_ = false;\r
-\r
-                       // Clear buffers.\r
-                       local_key_buffer_->clear();\r
-                       layer_key_buffer_->clear();\r
-                       draw_buffer_->clear();\r
+               layer_key_buffer_->clear();\r
+               draw_buffer_->clear();\r
 \r
-                       // Draw items in device.\r
+               while(!render_queue.empty())\r
+               {                       \r
+                       stream_key_buffer_->clear();\r
 \r
-                       while(!render_queue.empty())\r
+                       auto layer = std::move(render_queue.front());\r
+                       render_queue.pop();\r
+                                                                                       \r
+                       while(!layer.empty())\r
                        {\r
-                               auto layer = render_queue.front();\r
-                               render_queue.pop();\r
-                               \r
-                               draw_buffer_->attach(); \r
-                               \r
-                               while(!layer.empty())\r
+                               auto stream = std::move(layer.front());\r
+                               layer.pop();\r
+\r
+                               bool last_is_key = stream.empty() ? false : stream.back().transform.get_is_key();\r
+\r
+                               while(!stream.empty())\r
                                {\r
-                                       // Split layer into streams\r
-                                       std::vector<render_item> stream;\r
-                                       do\r
-                                       {\r
-                                               stream.push_back(layer.front());\r
-                                               layer.pop();\r
-                                       }\r
-                                       while(!layer.empty() && layer.front().tag == stream.front().tag);\r
+                                       auto item = std::move(stream.front());\r
+                                       stream.pop();\r
 \r
-                                       draw(stream);\r
+                                       render(item);\r
 \r
                                        channel_.ogl().yield(); // Allow quick buffer allocation to execute.\r
-                               }\r
-\r
-                               layer_key_ = local_key_; // If there was only key in last layer then use it as key for the entire next layer.\r
-                               local_key_ = false;\r
+                               }               \r
 \r
-                               std::swap(local_key_buffer_, layer_key_buffer_);\r
+                               if(!last_is_key)\r
+                                       stream_key_buffer_->clear();\r
                        }\r
 \r
-                       std::swap(draw_buffer_, write_buffer_);\r
+                       std::swap(stream_key_buffer_, layer_key_buffer_);\r
+               }\r
 \r
-                       // Start transfer from device to host.                          \r
-                       write_buffer_->write(*read_buffer);\r
-               });\r
+               std::swap(draw_buffer_, write_buffer_);\r
+\r
+               // Start transfer from device to host.                          \r
+               write_buffer_->write(*read_buffer);\r
 \r
                return read_buffer;\r
        }\r
-       \r
-       void draw(const std::vector<render_item>& stream)\r
-       {       \r
-               if(stream.empty())\r
-                       return;                         \r
-               \r
-               BOOST_FOREACH(auto item, stream)\r
-               {\r
-                       bool local_key = false;\r
-                       bool layer_key = false;\r
-\r
-                       // Setup key and kernel\r
-                                       \r
-                       if(item.transform.get_is_key()) // This is a key frame, render it to the local_key buffer for later use.\r
-                       {\r
-                               if(!local_key_) // Initialize local-key if it is not active.\r
-                               {\r
-                                       local_key_buffer_->clear();\r
-                                       local_key_buffer_->attach();\r
-                                       local_key_ = true;\r
-                               }\r
-                       }               \r
-                       else // This is a normal frame. Use key buffers if they are active.\r
-                       {               \r
-                               local_key = local_key_;\r
-                               layer_key = layer_key_;\r
-\r
-                               if(local_key_) // Use local key if we have it.\r
-                               {\r
-                                       local_key_buffer_->bind(LOCAL_KEY_INDEX);\r
-                                       draw_buffer_->attach(); \r
-                               }               \r
 \r
-                               if(layer_key_) // Use layer key if we have it.\r
-                                       layer_key_buffer_->bind(LAYER_KEY_INDEX);\r
-                       }       \r
-\r
-                       // Bind textures\r
-\r
-                       for(size_t n = 0; n < item.textures.size(); ++n)\r
-                               item.textures[n]->bind(n);              \r
-                       \r
-                       // Draw\r
+       void render(render_item& item)\r
+       {\r
+               for(size_t n = 0; n < item.textures.size(); ++n)\r
+                       item.textures[n]->bind(n);      \r
+                               \r
+               if(item.transform.get_is_key())\r
+               {\r
+                       stream_key_buffer_->attach();\r
 \r
-                       kernel_.draw(channel_.get_format_desc().width, channel_.get_format_desc().height, item.desc, item.transform, local_key, layer_key);     \r
+                       kernel_.draw(channel_.get_format_desc().width, channel_.get_format_desc().height, item.desc, item.transform, false, false);     \r
                }\r
+               else\r
+               {\r
+                       stream_key_buffer_->bind(LOCAL_KEY_INDEX);      \r
+                       layer_key_buffer_->bind(LAYER_KEY_INDEX);\r
+                               \r
+                       draw_buffer_->attach(); \r
 \r
-               local_key_ = stream.back().transform.get_is_key(); // Keep for next layer if last frame is key\r
+                       kernel_.draw(channel_.get_format_desc().width, channel_.get_format_desc().height, item.desc, item.transform, !stream_key_buffer_->empty(), !layer_key_buffer_->empty());        \r
+               }\r
        }\r
-                       \r
+                               \r
        safe_ptr<write_frame> create_frame(const void* tag, const core::pixel_format_desc& desc)\r
        {\r
                return make_safe<write_frame>(channel_.ogl(), reinterpret_cast<int>(tag), desc);\r
index 9fcb0fc68f9a03e49dbc6efbd6b404eecc40bac3..d38511017202389763317213fdfdb294192ba552 100644 (file)
@@ -103,7 +103,7 @@ struct write_frame::implementation : boost::noncopyable
                ogl_.begin_invoke([=]\r
                {\r
                        texture->read(*buffer);\r
-               });\r
+               }, high_priority);\r
        }\r
 };\r
        \r
index 45b098809246db155e47dbc7111ca3f8439775b9..60dd01e20248006337c262d25203a0fde76ae3d8 100644 (file)
     </ClCompile>\r
     <ClCompile Include="producer\filter_producer.cpp">\r
       <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>\r
+      <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Profile|Win32'">true</ExcludedFromBuild>\r
+      <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Develop|Win32'">true</ExcludedFromBuild>\r
+      <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>\r
     </ClCompile>\r
     <ClCompile Include="producer\input.cpp">\r
       <PrecompiledHeaderFile Condition="'$(Configuration)|$(Platform)'=='Profile|Win32'">../StdAfx.h</PrecompiledHeaderFile>\r
     <ClInclude Include="producer\filter\filter.h" />\r
     <ClInclude Include="producer\filter_producer.h">\r
       <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>\r
+      <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Profile|Win32'">true</ExcludedFromBuild>\r
+      <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Develop|Win32'">true</ExcludedFromBuild>\r
+      <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>\r
     </ClInclude>\r
     <ClInclude Include="producer\input.h" />\r
     <ClInclude Include="producer\util.h" />\r
index d19572fc34148822e66cbfcf22b6358924189f8e..a502744aa154d22fe3ba94d83a903d1b2fd0fad6 100644 (file)
@@ -4,7 +4,7 @@
     <media-path>C:\\Casparcg\\_media\\</media-path>\r
     <log-path>C:\\Casparcg\\_log\\</log-path>\r
     <data-path>C:\\Casparcg\\_data\\</data-path>\r
-    <template-path>C:\\Casparcg\\_templates\\</template-path>\r
+    <template-path>C:\\Casparcg\\</template-path>\r
     <template-host>cg.fth.18</template-host>\r
   </paths>\r
   <diagnostics>\r
@@ -14,7 +14,8 @@
     <channel>\r
       <video-mode>PAL</video-mode>\r
       <consumers>\r
-        <screen>                      \r
+        <screen>\r
+          <stretch>uniform</stretch>\r
         </screen>\r
       </consumers>\r
     </channel>\r