]> git.sesse.net Git - casparcg/commitdiff
Fixed bug where av_lockmgr unregistration occurred before avcodec_close at server...
authorHelge Norberg <helge.norberg@gmail.com>
Wed, 4 Sep 2013 13:36:43 +0000 (15:36 +0200)
committerHelge Norberg <helge.norberg@gmail.com>
Wed, 4 Sep 2013 13:36:43 +0000 (15:36 +0200)
core/producer/frame_producer.cpp
core/producer/frame_producer.h
shell/server.cpp

index 066f7fce618b4764c2b4e39fb6d034adde925be1..b2dce74eca8beb640be806130713cebe831249b6 100644 (file)
@@ -39,6 +39,18 @@ namespace caspar { namespace core {
        \r
 std::vector<const producer_factory_t> g_factories;\r
 std::vector<const producer_factory_t> g_thumbnail_factories;\r
+\r
+tbb::atomic<bool>& destroy_producers_in_separate_thread()\r
+{\r
+       static tbb::atomic<bool> state;\r
+\r
+       return state;\r
+}\r
+\r
+void destroy_producers_synchronously()\r
+{\r
+       destroy_producers_in_separate_thread() = false;\r
+}\r
        \r
 class destroy_producer_proxy : public frame_producer\r
 {      \r
@@ -47,13 +59,34 @@ public:
        destroy_producer_proxy(safe_ptr<frame_producer>&& producer) \r
                : producer_(new std::shared_ptr<frame_producer>(std::move(producer)))\r
        {\r
+               destroy_producers_in_separate_thread() = true;\r
        }\r
 \r
        ~destroy_producer_proxy()\r
-       {               \r
+       {\r
                static auto destroyers = std::make_shared<tbb::concurrent_bounded_queue<std::shared_ptr<executor>>>();\r
                static tbb::atomic<int> destroyer_count;\r
 \r
+               if (!destroy_producers_in_separate_thread())\r
+               {\r
+                       try\r
+                       {\r
+                               producer_.reset();\r
+\r
+                               std::shared_ptr<executor> destroyer;\r
+\r
+                               // Destruct any executors, causing them to execute pending tasks\r
+                               while (destroyers->try_pop(destroyer))\r
+                                       --destroyer_count;\r
+                       }\r
+                       catch (...)\r
+                       {\r
+                               CASPAR_LOG_CURRENT_EXCEPTION();\r
+                       }\r
+\r
+                       return;\r
+               }\r
+\r
                try\r
                {\r
                        std::shared_ptr<executor> destroyer;\r
index 678ddbd2a8dde895e8b4bc0a814ef70799574a3d..1e07ecde6390fd801e42c9b816b0d7ef0ab07f3d 100644 (file)
@@ -92,5 +92,6 @@ safe_ptr<core::frame_producer> create_producer(const safe_ptr<frame_factory>&, c
 safe_ptr<core::frame_producer> create_producer_destroy_proxy(safe_ptr<core::frame_producer> producer);\r
 safe_ptr<core::frame_producer> create_producer_print_proxy(safe_ptr<core::frame_producer> producer);\r
 safe_ptr<core::frame_producer> create_thumbnail_producer(const safe_ptr<frame_factory>& factory, const std::wstring& media_file);\r
+void destroy_producers_synchronously();\r
 \r
 }}\r
index b93351790ffa1d1d4d72aba8e211486874ba8e67..a1233df136b6ce964f563274ea7155eb2e8d3877 100644 (file)
@@ -129,12 +129,13 @@ struct server::implementation : boost::noncopyable
 \r
        ~implementation()\r
        {               \r
-               ffmpeg::uninit();\r
-\r
                thumbnail_generator_.reset();\r
                primary_amcp_server_.reset();\r
                async_servers_.clear();\r
+               destroy_producers_synchronously();\r
                channels_.clear();\r
+\r
+               ffmpeg::uninit();\r
        }\r
 \r
        void setup_audio(const boost::property_tree::wptree& pt)\r