]> git.sesse.net Git - casparcg/commitdiff
git-svn-id: https://casparcg.svn.sourceforge.net/svnroot/casparcg/server/branches...
authorronag <ronag@362d55ac-95cf-4e76-9f9a-cbaa9c17b72d>
Fri, 10 Feb 2012 13:30:56 +0000 (13:30 +0000)
committerronag <ronag@362d55ac-95cf-4e76-9f9a-cbaa9c17b72d>
Fri, 10 Feb 2012 13:30:56 +0000 (13:30 +0000)
accelerator/cpu/image/image_mixer.cpp

index e7fd98cd502bf059f86a1dd822dfc7f79259ccb1..b8e7605f02c8e99652b225c8c7db48ccd80a4d9c 100644 (file)
@@ -212,15 +212,29 @@ private:
        \r
        void convert(std::vector<item>& items, int width, int height)\r
        {\r
+               typedef std::map<std::vector<spl::shared_ptr<host_buffer>>, std::shared_ptr<host_buffer>>       buffer_map_t;\r
+               typedef std::map<std::vector<spl::shared_ptr<host_buffer>>, core::pixel_format_desc>            pix_desc_map_t;\r
+\r
+               buffer_map_t     buffer_map;\r
+               pix_desc_map_t   pix_desc_map;\r
+               BOOST_FOREACH(auto& item, items)\r
+               {\r
+                       buffer_map[item.buffers] = nullptr;\r
+                       pix_desc_map[item.buffers] = item.pix_desc;\r
+               }\r
+\r
                // TODO: Don't convert buffers multiple times just because they are in different items due to e.g. interlacing.\r
-               tbb::parallel_for_each(items.begin(), items.end(), [&](item& item)\r
+               tbb::parallel_for_each(buffer_map.begin(), buffer_map.end(), [&](buffer_map_t::value_type& pair)\r
                {\r
-                       if(item.pix_desc.format == core::pixel_format::bgra && \r
-                          item.pix_desc.planes.at(0).width == width &&\r
-                          item.pix_desc.planes.at(0).height == height)\r
+                       auto buffers   = pair.first;\r
+                       auto pix_desc  = pix_desc_map[buffers];\r
+\r
+                       if(pix_desc.format == core::pixel_format::bgra && \r
+                          pix_desc.planes.at(0).width == width &&\r
+                          pix_desc.planes.at(0).height == height)\r
                                return;\r
 \r
-                       auto input_av_frame = ffmpeg::make_av_frame(item.buffers, item.pix_desc);\r
+                       auto input_av_frame = ffmpeg::make_av_frame(buffers, pix_desc);\r
                                                                \r
                        int key = ((input_av_frame->width << 22) & 0xFFC00000) | ((input_av_frame->height << 6) & 0x003FC000) | ((input_av_frame->format << 7) & 0x00007F00);\r
                                                \r
@@ -238,20 +252,24 @@ private:
                \r
                        auto dest = spl::make_shared<host_buffer>(width*height*4);\r
 \r
-                       spl::shared_ptr<AVFrame> av_frame(avcodec_alloc_frame(), av_free);      \r
-                       avcodec_get_frame_defaults(av_frame.get());                     \r
-                       avpicture_fill(reinterpret_cast<AVPicture*>(av_frame.get()), dest->data(), PIX_FMT_BGRA, width, height);\r
+                       {\r
+                               spl::shared_ptr<AVFrame> av_frame(avcodec_alloc_frame(), av_free);      \r
+                               avcodec_get_frame_defaults(av_frame.get());                     \r
+                               avpicture_fill(reinterpret_cast<AVPicture*>(av_frame.get()), dest->data(), PIX_FMT_BGRA, width, height);\r
                                \r
-                       sws_scale(sws_context.get(), input_av_frame->data, input_av_frame->linesize, 0, input_av_frame->height, av_frame->data, av_frame->linesize);    \r
-                       \r
-                       item.buffers.clear();\r
-                       item.buffers.push_back(dest);\r
-                       item.pix_desc = core::pixel_format_desc(core::pixel_format::bgra);\r
-                       item.pix_desc.planes.clear();\r
-                       item.pix_desc.planes.push_back(core::pixel_format_desc::plane(width, height, 4));\r
+                               sws_scale(sws_context.get(), input_av_frame->data, input_av_frame->linesize, 0, input_av_frame->height, av_frame->data, av_frame->linesize);                            \r
+                               pool.push(sws_context);\r
+                       }\r
 \r
-                       pool.push(sws_context);\r
+                       pair.second = dest;\r
                });\r
+               \r
+               BOOST_FOREACH(auto& item, items)\r
+               {               \r
+                       item.buffers                    = boost::assign::list_of(spl::make_shared_ptr(buffer_map[item.buffers]));\r
+                       item.pix_desc                   = core::pixel_format_desc(core::pixel_format::bgra);\r
+                       item.pix_desc.planes    = boost::assign::list_of(core::pixel_format_desc::plane(width, height, 4));\r
+               }\r
        }\r
 };\r
                \r