]> git.sesse.net Git - casparcg/commitdiff
2.0. flash_producer: Improved error handling.
authorronag <ronag@362d55ac-95cf-4e76-9f9a-cbaa9c17b72d>
Mon, 15 Aug 2011 08:48:51 +0000 (08:48 +0000)
committerronag <ronag@362d55ac-95cf-4e76-9f9a-cbaa9c17b72d>
Mon, 15 Aug 2011 08:48:51 +0000 (08:48 +0000)
     decklink_consumer: Fixed exception_ptr data-race.

git-svn-id: https://casparcg.svn.sourceforge.net/svnroot/casparcg/server/branches/2.0.0.2@1179 362d55ac-95cf-4e76-9f9a-cbaa9c17b72d

modules/decklink/consumer/decklink_consumer.cpp
modules/flash/producer/flash_producer.cpp
shell/casparcg.config

index e8de3b3b8dc6e6a9fb4dcb8192cd86b519ca128d..b4c63c6552044f5b34117cc96049fb802b8bb57f 100644 (file)
@@ -103,6 +103,7 @@ struct decklink_consumer : public IDeckLinkVideoOutputCallback, public IDeckLink
        CComQIPtr<IDeckLinkConfiguration>       configuration_;\r
        CComQIPtr<IDeckLinkKeyer>                       keyer_;\r
 \r
+       tbb::spin_mutex                                         exception_mutex_;\r
        std::exception_ptr                                      exception_;\r
 \r
        tbb::atomic<bool>                                       is_running_;\r
@@ -296,6 +297,7 @@ public:
                }\r
                catch(...)\r
                {\r
+                       tbb::spin_mutex::scoped_lock lock(exception_mutex_);\r
                        exception_ = std::current_exception();\r
                        return E_FAIL;\r
                }\r
@@ -329,6 +331,7 @@ public:
                }\r
                catch(...)\r
                {\r
+                       tbb::spin_mutex::scoped_lock lock(exception_mutex_);\r
                        exception_ = std::current_exception();\r
                        return E_FAIL;\r
                }\r
@@ -358,8 +361,11 @@ public:
 \r
        void send(const safe_ptr<core::read_frame>& frame)\r
        {\r
-               if(exception_ != nullptr)\r
-                       std::rethrow_exception(exception_);\r
+               {\r
+                       tbb::spin_mutex::scoped_lock lock(exception_mutex_);\r
+                       if(exception_ != nullptr)\r
+                               std::rethrow_exception(exception_);\r
+               }\r
 \r
                if(!is_running_)\r
                        BOOST_THROW_EXCEPTION(caspar_exception() << msg_info(narrow(print()) + " Is not running."));\r
index aa21c1232e91d194277032cce17109baf0417e82..f24d6ef2fb03b1de414963cdd799f8ad4bab6961 100644 (file)
@@ -45,6 +45,8 @@
 #include <boost/thread.hpp>\r
 #include <boost/timer.hpp>\r
 \r
+#include <tbb/spin_mutex.h>\r
+\r
 #include <functional>\r
 \r
 namespace caspar {\r
@@ -262,6 +264,9 @@ struct flash_producer : public core::frame_producer
                                \r
        com_context<flash_renderer> context_;   \r
 \r
+       tbb::spin_mutex    exception_mutex_;\r
+       std::exception_ptr exception_;\r
+\r
        int width_;\r
        int height_;\r
 public:\r
@@ -282,8 +287,10 @@ public:
                graph_->set_color("output-buffer", diagnostics::color(0.0f, 1.0f, 0.0f));\r
                \r
                frame_buffer_.set_capacity(1);\r
-\r
-               initialize();                           \r
+               \r
+               context_.reset([&]{return new flash_renderer(safe_ptr<diagnostics::graph>(graph_), frame_factory_, filename_, width_, height_);});\r
+               while(frame_buffer_.try_push(core::basic_frame::empty())){}             \r
+               render();                       \r
        }\r
 \r
        ~flash_producer()\r
@@ -294,7 +301,13 @@ public:
        // frame_producer\r
                \r
        virtual safe_ptr<core::basic_frame> receive(int)\r
-       {                               \r
+       {               \r
+               {                       \r
+                       tbb::spin_mutex::scoped_lock lock(exception_mutex_);\r
+                       if(exception_ != nullptr)\r
+                               std::rethrow_exception(exception_);\r
+               }\r
+\r
                graph_->set_value("output-buffer", static_cast<float>(frame_buffer_.size())/static_cast<float>(frame_buffer_.capacity()));\r
 \r
                auto frame = core::basic_frame::late();\r
@@ -311,11 +324,14 @@ public:
        \r
        virtual void param(const std::wstring& param) \r
        {       \r
+               {                       \r
+                       tbb::spin_mutex::scoped_lock lock(exception_mutex_);\r
+                       if(exception_ != nullptr)\r
+                               std::rethrow_exception(exception_);\r
+               }\r
+\r
                context_.begin_invoke([=]\r
                {\r
-                       if(!context_)\r
-                               initialize();\r
-\r
                        try\r
                        {\r
                                context_->param(param); \r
@@ -328,33 +344,24 @@ public:
                        {\r
                                CASPAR_LOG_CURRENT_EXCEPTION();\r
                                context_.reset(nullptr);\r
-                               frame_buffer_.push(core::basic_frame::empty());\r
+\r
+                               tbb::spin_mutex::scoped_lock lock(exception_mutex_);\r
+                               exception_ = std::current_exception();\r
                        }\r
                });\r
        }\r
                \r
        virtual std::wstring print() const\r
        { \r
-               return L"flash[" + boost::filesystem::wpath(filename_).filename() + L", " + \r
-                                       boost::lexical_cast<std::wstring>(fps_) + L"]";         \r
+               return L"flash[" + boost::filesystem::wpath(filename_).filename() + L", " + boost::lexical_cast<std::wstring>(fps_) + L"]";             \r
        }       \r
 \r
        // flash_producer\r
 \r
-       void initialize()\r
-       {\r
-               context_.reset([&]{return new flash_renderer(safe_ptr<diagnostics::graph>(graph_), frame_factory_, filename_, width_, height_);});\r
-               while(frame_buffer_.try_push(core::basic_frame::empty())){}             \r
-               render(context_.get());\r
-       }\r
-\r
-       void render(const flash_renderer* renderer)\r
-       {               \r
+       void render()\r
+       {       \r
                context_.begin_invoke([=]\r
                {\r
-                       if(context_.get() != renderer) // Since initialize will start a new recursive call make sure the recursive calls are only for a specific instance.\r
-                               return;\r
-\r
                        try\r
                        {               \r
                                const auto& format_desc = frame_factory_->get_video_format_desc();\r
@@ -380,13 +387,15 @@ public:
                                graph_->set_value("output-buffer", static_cast<float>(frame_buffer_.size())/static_cast<float>(frame_buffer_.capacity()));      \r
                                fps_.fetch_and_store(static_cast<int>(context_->fps()*100.0));\r
 \r
-                               render(renderer);\r
+                               render();\r
                        }\r
                        catch(...)\r
                        {\r
                                CASPAR_LOG_CURRENT_EXCEPTION();\r
                                context_.reset(nullptr);\r
-                               frame_buffer_.push(core::basic_frame::empty());\r
+                               \r
+                               tbb::spin_mutex::scoped_lock lock(exception_mutex_);\r
+                               exception_ = std::current_exception();\r
                        }\r
                });\r
        }\r
index 01a5d11cf2b572b3555cd2b4ecfb6d913fc8979c..2c911b64c3ea596a06ea03dc84cef414412da59f 100644 (file)
@@ -13,7 +13,7 @@
     <buffer-depth>6</buffer-depth>\r
   </consumers>\r
   <producers>\r
-    <buffer-depth>2</buffer-depth>\r
+    <buffer-depth>3</buffer-depth>\r
     <auto-transcode>true</auto-transcode>\r
     <template-hosts>\r
       <template-host>\r
         <width>1280</width>\r
         <height>720</height>\r
       </template-host>\r
+      <template-host>\r
+        <video-mode>720p5000</video-mode>\r
+        <filename>cg.fth.18</filename>\r
+        <width>1280</width>\r
+        <height>720</height>\r
+      </template-host>\r
       <template-host>\r
         <video-mode>1080i5000</video-mode>\r
         <filename>cg.fth.18</filename>\r