]> git.sesse.net Git - casparcg/commitdiff
2.0.0.2: core: Destroy producers on asynchronous thread to avoid blocking rendering...
authorronag <ronag@362d55ac-95cf-4e76-9f9a-cbaa9c17b72d>
Sun, 22 May 2011 21:33:45 +0000 (21:33 +0000)
committerronag <ronag@362d55ac-95cf-4e76-9f9a-cbaa9c17b72d>
Sun, 22 May 2011 21:33:45 +0000 (21:33 +0000)
git-svn-id: https://casparcg.svn.sourceforge.net/svnroot/casparcg/server/branches/2.0.0.2@802 362d55ac-95cf-4e76-9f9a-cbaa9c17b72d

core/core.vcxproj
core/core.vcxproj.filters
core/producer/destroy_producer_proxy.cpp [new file with mode: 0644]
core/producer/destroy_producer_proxy.h [new file with mode: 0644]
core/producer/frame_producer_device.cpp
modules/decklink/interop/DeckLinkAPI_h.h
modules/decklink/interop/DeckLinkAPI_i.c
modules/flash/producer/cg_producer.cpp
modules/flash/producer/cg_producer.h

index 4cc4c541f862a55e42180661db4c20d3878da542..eaaab1179e67c36bed937bd1e6bb0415932ab79e 100644 (file)
     <ClInclude Include="mixer\image\image_mixer.h" />\r
     <ClInclude Include="mixer\read_frame.h" />\r
     <ClInclude Include="mixer\write_frame.h" />\r
+    <ClInclude Include="producer\destroy_producer_proxy.h" />\r
     <ClInclude Include="producer\color\color_producer.h" />\r
     <ClInclude Include="producer\frame\audio_transform.h" />\r
     <ClInclude Include="producer\frame\basic_frame.h" />\r
       <PrecompiledHeaderFile Condition="'$(Configuration)|$(Platform)'=='Develop|Win32'">../StdAfx.h</PrecompiledHeaderFile>\r
       <PrecompiledHeaderFile Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">../StdAfx.h</PrecompiledHeaderFile>\r
     </ClCompile>\r
+    <ClCompile Include="producer\destroy_producer_proxy.cpp">\r
+      <PrecompiledHeaderFile Condition="'$(Configuration)|$(Platform)'=='Profile|Win32'">../StdAfx.h</PrecompiledHeaderFile>\r
+      <PrecompiledHeaderFile Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">../StdAfx.h</PrecompiledHeaderFile>\r
+      <PrecompiledHeaderFile Condition="'$(Configuration)|$(Platform)'=='Develop|Win32'">../StdAfx.h</PrecompiledHeaderFile>\r
+      <PrecompiledHeaderFile Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">../StdAfx.h</PrecompiledHeaderFile>\r
+    </ClCompile>\r
     <ClCompile Include="producer\color\color_producer.cpp">\r
       <PrecompiledHeaderFile Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">../../StdAfx.h</PrecompiledHeaderFile>\r
       <PrecompiledHeaderFile Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">../../StdAfx.h</PrecompiledHeaderFile>\r
index 3ae4332ea4e1ad5b02152cbbcf6b1b7164133eef..72bd0b4a7d93ed774db4b41e4b36ae6b0163babe 100644 (file)
     <ClInclude Include="mixer\frame_mixer_device.h">\r
       <Filter>mixer</Filter>\r
     </ClInclude>\r
+    <ClInclude Include="producer\destroy_producer_proxy.h">\r
+      <Filter>producer</Filter>\r
+    </ClInclude>\r
   </ItemGroup>\r
   <ItemGroup>\r
     <ClCompile Include="producer\transition\transition_producer.cpp">\r
     <ClCompile Include="mixer\write_frame.cpp">\r
       <Filter>mixer</Filter>\r
     </ClCompile>\r
+    <ClCompile Include="producer\destroy_producer_proxy.cpp">\r
+      <Filter>producer</Filter>\r
+    </ClCompile>\r
   </ItemGroup>\r
 </Project>
\ No newline at end of file
diff --git a/core/producer/destroy_producer_proxy.cpp b/core/producer/destroy_producer_proxy.cpp
new file mode 100644 (file)
index 0000000..f85d378
--- /dev/null
@@ -0,0 +1,67 @@
+/*\r
+* copyright (c) 2010 Sveriges Television AB <info@casparcg.com>\r
+*\r
+*  This file is part of CasparCG.\r
+*\r
+*    CasparCG is free software: you can redistribute it and/or modify\r
+*    it under the terms of the GNU General Public License as published by\r
+*    the Free Software Foundation, either version 3 of the License, or\r
+*    (at your option) any later version.\r
+*\r
+*    CasparCG is distributed in the hope that it will be useful,\r
+*    but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+*    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+*    GNU General Public License for more details.\r
+\r
+*    You should have received a copy of the GNU General Public License\r
+*    along with CasparCG.  If not, see <http://www.gnu.org/licenses/>.\r
+*\r
+*/\r
+#include "../StdAfx.h"\r
+\r
+#include "destroy_producer_proxy.h"\r
+\r
+#include <common/concurrency/executor.h>\r
+#include <common/utility/assert.h>\r
+\r
+namespace caspar { namespace core {\r
+       \r
+struct destroyer\r
+{\r
+       executor executor_;\r
+\r
+       destroyer() : executor_(L"destroyer", true){}\r
+       \r
+       void destroy(safe_ptr<frame_producer>&& producer)\r
+       {\r
+               executor_.begin_invoke(std::bind(&destroyer::do_destroy, this, std::move(producer)));\r
+       }\r
+\r
+       void do_destroy(safe_ptr<frame_producer>& producer)\r
+       {\r
+               if(!producer.unique())\r
+                       CASPAR_LOG(warning) << producer->print() << L" Not destroyed on safe asynchronous destruction thread.";\r
+               \r
+               if(executor_.size() > 4)\r
+                       CASPAR_LOG(error) << L" Potential destroyer deadlock.";\r
+\r
+               producer = frame_producer::empty();\r
+       }\r
+\r
+} g_destroyer;\r
+\r
+destroy_producer_proxy::destroy_producer_proxy(const safe_ptr<frame_producer>& producer) : producer_(producer){}\r
+destroy_producer_proxy::~destroy_producer_proxy()\r
+{\r
+       g_destroyer.destroy(std::move(producer_));\r
+}\r
+\r
+safe_ptr<basic_frame> destroy_producer_proxy::receive(){return producer_->receive();}  \r
+std::wstring destroy_producer_proxy::print() const {return producer_->print();}   \r
+\r
+void destroy_producer_proxy::param(const std::wstring& param){producer_->param(param);}  \r
+\r
+safe_ptr<frame_producer> destroy_producer_proxy::get_following_producer() const {return producer_->get_following_producer();}  \r
+void destroy_producer_proxy::set_leading_producer(const safe_ptr<frame_producer>& producer) {producer_->set_leading_producer(producer);} \r
+               \r
+}}\r
diff --git a/core/producer/destroy_producer_proxy.h b/core/producer/destroy_producer_proxy.h
new file mode 100644 (file)
index 0000000..de1d71c
--- /dev/null
@@ -0,0 +1,44 @@
+/*\r
+* copyright (c) 2010 Sveriges Television AB <info@casparcg.com>\r
+*\r
+*  This file is part of CasparCG.\r
+*\r
+*    CasparCG is free software: you can redistribute it and/or modify\r
+*    it under the terms of the GNU General Public License as published by\r
+*    the Free Software Foundation, either version 3 of the License, or\r
+*    (at your option) any later version.\r
+*\r
+*    CasparCG is distributed in the hope that it will be useful,\r
+*    but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+*    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+*    GNU General Public License for more details.\r
+\r
+*    You should have received a copy of the GNU General Public License\r
+*    along with CasparCG.  If not, see <http://www.gnu.org/licenses/>.\r
+*\r
+*/\r
+#pragma once\r
+\r
+#include "frame_producer.h"\r
+\r
+namespace caspar { namespace core {\r
+       \r
+class destroy_producer_proxy : public frame_producer\r
+{\r
+public:\r
+       destroy_producer_proxy(const safe_ptr<frame_producer>& producer);\r
+       ~destroy_producer_proxy();\r
+\r
+       virtual safe_ptr<basic_frame> receive();\r
+       virtual std::wstring print() const; // nothrow\r
+\r
+       virtual void param(const std::wstring&);\r
+\r
+       virtual safe_ptr<frame_producer> get_following_producer() const;  // nothrow\r
+       virtual void set_leading_producer(const safe_ptr<frame_producer>&);  // nothrow\r
+private:\r
+       safe_ptr<frame_producer> producer_;\r
+};\r
+\r
+\r
+}}\r
index 64854b33c4bb68ac85764cfb3274a0e0671fcab1..f856a26c34c94e39c66b1bed5a799dff1ad3cdd8 100644 (file)
@@ -21,6 +21,7 @@
 #include "../StdAfx.h"\r
 \r
 #include "frame_producer_device.h"\r
+#include "destroy_producer_proxy.h"\r
 \r
 #include <core/producer/frame/basic_frame.h>\r
 #include <core/producer/frame/frame_factory.h>\r
@@ -128,7 +129,7 @@ public:
 \r
        void load(int index, const safe_ptr<frame_producer>& producer, bool preview)\r
        {\r
-               executor_.invoke([&]{layers_[index].load(producer, preview);});\r
+               executor_.invoke([&]{layers_[index].load(make_safe<destroy_producer_proxy>(producer), preview);});\r
        }\r
 \r
        void pause(int index)\r
index 1d634ba94b6e9017b59ef9cf6190fa2c44dc9a28..c8e8ed2b88d5df36590fe334ed82f7fb9fc84b3b 100644 (file)
@@ -4,7 +4,7 @@
 \r
 \r
  /* File created by MIDL compiler version 7.00.0555 */\r
-/* at Fri May 20 15:23:50 2011\r
+/* at Sun May 22 21:42:51 2011\r
  */\r
 /* Compiler settings for interop\DeckLinkAPI.idl:\r
     Oicf, W1, Zp8, env=Win32 (32b run), target_arch=X86 7.00.0555 \r
index 327207bceccde4b541ed6760aefb08b91a2637a6..a890e662cd9ff070d0f5baa3f0e5fe0b3f041765 100644 (file)
@@ -6,7 +6,7 @@
 \r
 \r
  /* File created by MIDL compiler version 7.00.0555 */\r
-/* at Fri May 20 15:23:50 2011\r
+/* at Sun May 22 21:42:51 2011\r
  */\r
 /* Compiler settings for interop\DeckLinkAPI.idl:\r
     Oicf, W1, Zp8, env=Win32 (32b run), target_arch=X86 7.00.0555 \r
index f5ac48954bec1ce4421facbb9e7c82e2a7f04725..6a8adb7cc8796f07bcc69b1cd627ad32f06530cf 100644 (file)
@@ -32,12 +32,10 @@ namespace caspar {
        \r
 struct cg_producer::implementation : boost::noncopyable\r
 {\r
-       safe_ptr<core::frame_factory> frame_factory_;\r
        safe_ptr<core::frame_producer> flash_producer_;\r
 public:\r
-       implementation(const safe_ptr<core::frame_factory>& frame_factory) \r
-               : frame_factory_(frame_factory)\r
-               , flash_producer_(create_flash_producer(frame_factory_, boost::assign::list_of(env::template_host())))\r
+       implementation(const safe_ptr<core::frame_producer>& frame_producer) \r
+               : flash_producer_(frame_producer)\r
        {}\r
        \r
        void add(int layer, const std::wstring& filename,  bool play_on_load, const std::wstring& label, const std::wstring& data)\r
@@ -95,18 +93,16 @@ public:
        \r
 safe_ptr<cg_producer> get_default_cg_producer(const safe_ptr<core::channel>& channel, int render_layer)\r
 {      \r
-       try\r
-       {\r
-               return dynamic_pointer_cast<cg_producer>(channel->producer()->foreground(render_layer).get());\r
-       }\r
-       catch(std::bad_cast&)\r
+       auto flash_producer = channel->producer()->foreground(render_layer).get();\r
+\r
+       if(flash_producer->print().find(L"flash") == std::string::npos)\r
        {\r
-               safe_ptr<core::frame_factory> factory = channel->mixer();\r
-               auto producer = make_safe<cg_producer>(factory);                \r
-               channel->producer()->load(render_layer, producer, true); \r
+               flash_producer = create_flash_producer(channel->mixer(), boost::assign::list_of(env::template_host())); \r
+               channel->producer()->load(render_layer, flash_producer, true); \r
                channel->producer()->play(render_layer);\r
-               return producer;\r
        }\r
+\r
+       return make_safe<cg_producer>(flash_producer);\r
 }\r
 \r
 safe_ptr<core::frame_producer> create_ct_producer(const safe_ptr<core::frame_factory> frame_factory, const std::vector<std::wstring>& params) \r
@@ -114,14 +110,15 @@ safe_ptr<core::frame_producer> create_ct_producer(const safe_ptr<core::frame_fac
        std::wstring filename = env::media_folder() + L"\\" + params[0] + L".ct";\r
        if(!boost::filesystem::exists(filename))\r
                return core::frame_producer::empty();\r
-\r
-       auto producer = make_safe<cg_producer>(frame_factory);\r
+       \r
+       auto flash_producer = create_flash_producer(frame_factory, boost::assign::list_of(env::template_host()));       \r
+       auto producer = make_safe<cg_producer>(flash_producer);\r
        producer->add(0, filename, 1);\r
 \r
        return producer;\r
 }\r
 \r
-cg_producer::cg_producer(const safe_ptr<core::frame_factory>& frame_factory) : impl_(new implementation(frame_factory)){}\r
+cg_producer::cg_producer(const safe_ptr<core::frame_producer>& frame_producer) : impl_(new implementation(frame_producer)){}\r
 cg_producer::cg_producer(cg_producer&& other) : impl_(std::move(other.impl_)){}\r
 safe_ptr<core::basic_frame> cg_producer::receive(){return impl_->receive();}\r
 void cg_producer::add(int layer, const std::wstring& template_name,  bool play_on_load, const std::wstring& startFromLabel, const std::wstring& data){impl_->add(layer, template_name, play_on_load, startFromLabel, data);}\r
index 32e0af47f6dbdddbc5f4d9b0aad9a96e2001ec6a..f3f05da98e92bb28683c9c161ea100d5a068cf07 100644 (file)
@@ -33,7 +33,7 @@ class cg_producer : public core::frame_producer
 public:\r
        static const unsigned int DEFAULT_LAYER = 9999;\r
 \r
-       explicit cg_producer(const safe_ptr<core::frame_factory>& frame_factory);\r
+       explicit cg_producer(const safe_ptr<core::frame_producer>& producer);\r
        cg_producer(cg_producer&& other);\r
        \r
        // frame_producer\r