]> git.sesse.net Git - casparcg/commitdiff
2.1.0: Don't use separate opengl allocation context as this seems to cause long block...
authorronag <ronag@362d55ac-95cf-4e76-9f9a-cbaa9c17b72d>
Fri, 6 Apr 2012 16:50:30 +0000 (16:50 +0000)
committerronag <ronag@362d55ac-95cf-4e76-9f9a-cbaa9c17b72d>
Fri, 6 Apr 2012 16:50:30 +0000 (16:50 +0000)
git-svn-id: https://casparcg.svn.sourceforge.net/svnroot/casparcg/server/branches/2.1.0@2801 362d55ac-95cf-4e76-9f9a-cbaa9c17b72d

accelerator/ogl/util/buffer.cpp
accelerator/ogl/util/device.cpp
core/consumer/output.cpp
core/mixer/mixer.cpp
core/producer/layer.cpp
core/producer/stage.cpp
core/video_channel.cpp
shell/casparcg.config

index 3d9e5a81e443959570119ac5a03c4e7e1a8cf643..5efdd2f4c3f1379505082a4e9b8edc151fe3ea5f 100644 (file)
@@ -67,6 +67,7 @@ public:
                \r
                if(timer.elapsed() > 0.02)\r
                        CASPAR_LOG(debug) << L"[buffer] Performance warning. Buffer allocation blocked more than 20 ms: " << timer.elapsed();\r
+       \r
                //CASPAR_LOG(trace) << "[buffer] [" << ++(usage_ == buffer::usage::write_only ? g_w_total_count : g_r_total_count) << L"] allocated size:" << size_ << " usage: " << (usage == buffer::usage::write_only ? "write_only" : "read_only");\r
        }       \r
 \r
index 9b463ea45e0f8525a6053d7768a0a30062f3577a..f09c0ad9a9449740be2f4a38f1d8e290f154064f 100644 (file)
@@ -63,26 +63,22 @@ struct device::impl : public std::enable_shared_from_this<impl>
        tbb::concurrent_hash_map<buffer*, std::shared_ptr<texture>> texture_cache_;\r
 \r
        std::unique_ptr<sf::Context> device_;\r
-       std::unique_ptr<sf::Context> host_alloc_device_;\r
        \r
        std::array<tbb::concurrent_unordered_map<std::size_t, tbb::concurrent_bounded_queue<std::shared_ptr<texture>>>, 4>      device_pools_;\r
        std::array<tbb::concurrent_unordered_map<std::size_t, tbb::concurrent_bounded_queue<std::shared_ptr<buffer>>>, 2>       host_pools_;\r
        \r
        GLuint fbo_;\r
 \r
-       executor& render_executor_;\r
-       executor  alloc_executor_;\r
+       executor& executor_;\r
                                \r
        impl(executor& executor) \r
-               : render_executor_(executor)\r
-               , alloc_executor_(L"OpenGL allocation context")\r
+               : executor_(executor)\r
        {\r
-               render_executor_.set_capacity(128);\r
-               alloc_executor_.set_capacity(256);\r
+               executor_.set_capacity(256);\r
 \r
                CASPAR_LOG(info) << L"Initializing OpenGL Device.";\r
                \r
-               auto ctx1 = render_executor_.invoke([=]() -> HGLRC \r
+               executor_.invoke([=]\r
                {\r
                        device_.reset(new sf::Context());\r
                        device_->SetActive(true);               \r
@@ -95,27 +91,6 @@ struct device::impl : public std::enable_shared_from_this<impl>
        \r
                        glGenFramebuffers(1, &fbo_);                            \r
                        glBindFramebuffer(GL_FRAMEBUFFER, fbo_);\r
-                       \r
-                       auto ctx1 = wglGetCurrentContext();\r
-                       \r
-                       device_->SetActive(false);\r
-\r
-                       return ctx1;\r
-               });\r
-\r
-               alloc_executor_.invoke([=]\r
-               {\r
-                       host_alloc_device_.reset(new sf::Context());\r
-                       host_alloc_device_->SetActive(true);    \r
-                       auto ctx2 = wglGetCurrentContext();\r
-\r
-                       if(!wglShareLists(ctx1, ctx2))\r
-                               CASPAR_THROW_EXCEPTION(gl::ogl_exception() << msg_info("Failed to share OpenGL devices."));\r
-               });\r
-\r
-               render_executor_.invoke([=]\r
-               {               \r
-                       device_->SetActive(true);\r
                });\r
                                \r
                CASPAR_LOG(info) << L"Successfully initialized OpenGL " << version();\r
@@ -123,14 +98,7 @@ struct device::impl : public std::enable_shared_from_this<impl>
 \r
        ~impl()\r
        {\r
-               alloc_executor_.invoke([=]\r
-               {\r
-                       host_alloc_device_.reset();\r
-                       BOOST_FOREACH(auto& pool, host_pools_)\r
-                               pool.clear();\r
-               });\r
-\r
-               render_executor_.invoke([=]\r
+               executor_.invoke([=]\r
                {\r
                        BOOST_FOREACH(auto& pool, device_pools_)\r
                                pool.clear();\r
@@ -144,7 +112,7 @@ struct device::impl : public std::enable_shared_from_this<impl>
        {       \r
                try\r
                {\r
-                       return alloc_executor_.invoke([]\r
+                       return executor_.invoke([]\r
                        {\r
                                return u16(reinterpret_cast<const char*>(GL2(glGetString(GL_VERSION)))) + L" " + u16(reinterpret_cast<const char*>(GL2(glGetString(GL_VENDOR))));\r
                        });     \r
@@ -160,7 +128,7 @@ struct device::impl : public std::enable_shared_from_this<impl>
                CASPAR_VERIFY(stride > 0 && stride < 5);\r
                CASPAR_VERIFY(width > 0 && height > 0);\r
 \r
-               if(!render_executor_.is_current())\r
+               if(!executor_.is_current())\r
                        CASPAR_THROW_EXCEPTION(invalid_operation() << msg_info("Operation only valid in an OpenGL Context."));\r
                                        \r
                auto pool = &device_pools_[stride-1][((width << 16) & 0xFFFF0000) | (height & 0x0000FFFF)];\r
@@ -187,7 +155,7 @@ struct device::impl : public std::enable_shared_from_this<impl>
                std::shared_ptr<buffer> buf;\r
                if(!pool->try_pop(buf)) \r
                {\r
-                       buf = alloc_executor_.invoke([&]\r
+                       buf = executor_.invoke([&]\r
                        {\r
                                return spl::make_shared<buffer>(size, usage);\r
                        }, task_priority::high_priority);\r
@@ -232,7 +200,7 @@ struct device::impl : public std::enable_shared_from_this<impl>
        {\r
                std::shared_ptr<buffer> buf = copy_to_buf(source);\r
                                \r
-               return render_executor_.begin_invoke([=]() -> spl::shared_ptr<texture>\r
+               return executor_.begin_invoke([=]() -> spl::shared_ptr<texture>\r
                {\r
                        tbb::concurrent_hash_map<buffer*, std::shared_ptr<texture>>::const_accessor a;\r
                        if(texture_cache_.find(a, buf.get()))\r
@@ -251,7 +219,7 @@ struct device::impl : public std::enable_shared_from_this<impl>
        {\r
                std::shared_ptr<buffer> buf = copy_to_buf(source);\r
 \r
-               return render_executor_.begin_invoke([=]() -> spl::shared_ptr<texture>\r
+               return executor_.begin_invoke([=]() -> spl::shared_ptr<texture>\r
                {\r
                        auto texture = create_texture(width, height, stride, false);\r
                        texture->copy_from(*buf);                               \r
@@ -261,7 +229,7 @@ struct device::impl : public std::enable_shared_from_this<impl>
 \r
        boost::unique_future<array<const std::uint8_t>> copy_async(const spl::shared_ptr<texture>& source)\r
        {\r
-               if(!render_executor_.is_current())\r
+               if(!executor_.is_current())\r
                        CASPAR_THROW_EXCEPTION(invalid_operation() << msg_info("Operation only valid in an OpenGL Context."));\r
 \r
                auto buffer = create_buffer(source->size(), buffer::usage::read_only); \r
@@ -270,7 +238,7 @@ struct device::impl : public std::enable_shared_from_this<impl>
                auto self = shared_from_this();\r
                return async(launch::deferred, [self, buffer]() mutable -> array<const std::uint8_t>\r
                {\r
-                       self->alloc_executor_.invoke(std::bind(&buffer::map, std::ref(buffer))); // Defer blocking "map" call until data is needed.\r
+                       self->executor_.invoke(std::bind(&buffer::map, std::ref(buffer))); // Defer blocking "map" call until data is needed.\r
                        return array<const std::uint8_t>(buffer->data(), buffer->size(), true, buffer);\r
                });\r
        }\r
index 6aaaa61be8aa9da8888cc757ec011a4e93ce2977..59f749d969216515bb42c13e9af5786d4dc29baf 100644 (file)
@@ -153,11 +153,12 @@ public:
                \r
        void operator()(const_frame input_frame, const core::video_format_desc& format_desc)\r
        {\r
-               video_format_desc(format_desc);\r
+               boost::timer frame_timer;\r
+\r
+               video_format_desc(format_desc);         \r
 \r
                executor_.invoke([=]\r
                {                       \r
-                       boost::timer frame_timer;\r
 \r
                        if(!has_synchronization_clock())\r
                                sync_timer_.tick(1.0/format_desc_.fps);\r
@@ -194,9 +195,9 @@ public:
                                        ports_.erase(it++);\r
                                }\r
                        }\r
-\r
-                       graph_->set_value("consume-time", frame_timer.elapsed()*format_desc.fps*0.5);\r
                });\r
+\r
+               graph_->set_value("consume-time", frame_timer.elapsed()*format_desc.fps*0.5);\r
        }\r
 \r
        std::wstring print() const\r
index 2a0adbd62af9ede0f3cde51eacbe3ba7eaff31c5..0a423fb20dc799e519ac68b91f49e9c6900632d4 100644 (file)
@@ -75,12 +75,12 @@ public:
        \r
        const_frame operator()(std::map<int, draw_frame> frames, const video_format_desc& format_desc)\r
        {               \r
-               return executor_.invoke([=]() mutable -> const_frame\r
+               boost::timer frame_timer;\r
+\r
+               auto frame = executor_.invoke([=]() mutable -> const_frame\r
                {               \r
                        try\r
                        {       \r
-                               boost::timer frame_timer;\r
-\r
                                BOOST_FOREACH(auto& frame, frames)\r
                                {\r
                                        auto blend_it = blend_modes_.find(frame.first);\r
@@ -94,8 +94,6 @@ public:
                                \r
                                auto image = (*image_mixer_)(format_desc);\r
                                auto audio = audio_mixer_(format_desc);\r
-                               \r
-                               graph_->set_value("mix-time", frame_timer.elapsed()*format_desc.fps*0.5);\r
 \r
                                auto desc = core::pixel_format_desc(core::pixel_format::bgra);\r
                                desc.planes.push_back(core::pixel_format_desc::plane(format_desc.width, format_desc.height, 4));\r
@@ -107,6 +105,10 @@ public:
                                return const_frame::empty();\r
                        }       \r
                });             \r
+                               \r
+               graph_->set_value("mix-time", frame_timer.elapsed()*format_desc.fps*0.5);\r
+\r
+               return frame;\r
        }\r
                                        \r
        void set_blend_mode(int index, blend_mode value)\r
index 40defdbc3e9f6a3171c9242aae1fb289b217d197..d53f28242bc3334742b438bbe4cc7c756b348a17 100644 (file)
@@ -111,8 +111,13 @@ public:
        {               \r
                try\r
                {               \r
+                       boost::timer timer;\r
+\r
                        auto frame = foreground_->receive();\r
 \r
+                       if(timer.elapsed() > 1.0/format_desc.fps*0.9)\r
+                               CASPAR_LOG(trace) << foreground_->print() << L" Is slowing down channel.";\r
+\r
                        if(frame == core::draw_frame::late())\r
                                return foreground_->last_frame();\r
                                                \r
index b1ed3461d5e1e20cf9bb240f3e2136ae5b3db56a..bfc83750b7a6be137b43441e0a6dd07af33ec6ec 100644 (file)
@@ -66,9 +66,10 @@ public:
                \r
        std::map<int, draw_frame> operator()(const struct video_format_desc& format_desc)\r
        {               \r
+               boost::timer frame_timer;\r
+\r
                auto frames = executor_.invoke([=]() -> std::map<int, draw_frame>\r
                {\r
-                       boost::timer frame_timer;\r
 \r
                        std::map<int, class draw_frame> frames;\r
                        \r
@@ -91,13 +92,15 @@ public:
                                CASPAR_LOG_CURRENT_EXCEPTION();\r
                        }       \r
                        \r
-                       graph_->set_value("produce-time", frame_timer.elapsed()*format_desc.fps*0.5);\r
-                       event_subject_ << monitor::event("profiler/time") % frame_timer.elapsed() % (1.0/format_desc.fps);\r
 \r
                        return frames;\r
                });\r
                \r
                frames_subject_ << frames;\r
+               \r
+               graph_->set_value("produce-time", frame_timer.elapsed()*format_desc.fps*0.5);\r
+               event_subject_ << monitor::event("profiler/time") % frame_timer.elapsed() % (1.0/format_desc.fps);\r
+\r
                return frames;\r
        }\r
 \r
index 7ef5787c6b4ac61bc0544c8b5ff5a054ee9f0d04..57753c07764b2db41557e8c10caf54bbdb81cf9b 100644 (file)
@@ -108,26 +108,43 @@ public:
        {\r
                try\r
                {\r
-                       auto format_desc = video_format_desc();\r
+                       boost::timer t;\r
 \r
+                       auto format_desc = video_format_desc();\r
+                       \r
                        boost::timer frame_timer;\r
 \r
                        // Produce\r
                        \r
                        auto stage_frames = stage_(format_desc);\r
 \r
+                       if(t.elapsed() > 1.0/format_desc.fps*0.9)\r
+                               CASPAR_LOG(trace) << print() << L" Stage is slowing down channel: " << t.elapsed();\r
+\r
+                       t.restart();\r
                        // Mix\r
                        \r
                        auto mixed_frame  = mixer_(std::move(stage_frames), format_desc);\r
+                       \r
+                       if(t.elapsed() > 1.0/format_desc.fps*0.9)\r
+                               CASPAR_LOG(trace) << print() << L"Mixer is slowing down channel: " << t.elapsed();\r
 \r
+                       t.restart();\r
                        // Consume\r
                                                \r
                        output_(std::move(mixed_frame), format_desc);\r
                \r
+                       t.restart();\r
+\r
                        graph_->set_value("tick-time", frame_timer.elapsed()*format_desc.fps*0.5);\r
 \r
                        event_subject_  << monitor::event("profiler/time")      % frame_timer.elapsed() % (1.0/format_desc_.fps)\r
                                                        << monitor::event("format")                     % format_desc.name;\r
+                       \r
+                       if(t.elapsed() > 0.001)\r
+                               CASPAR_LOG(trace) << L"4## " << t.elapsed();\r
+\r
+                       t.restart();\r
                }\r
                catch(...)\r
                {\r
index 76bbffeebdbb8c9ebe377b5fe7afd91b17b39f6d..30f5f5b6acc50630c7f507526322b681664c6414 100644 (file)
@@ -13,7 +13,7 @@
   </flash>\r
   <channels>\r
     <channel>\r
-      <video-mode>NTSC</video-mode>\r
+      <video-mode>720p5000</video-mode>\r
       <consumers>\r
         <screen>\r
           <device>1</device>\r