]> 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>
Thu, 27 Oct 2011 20:25:33 +0000 (20:25 +0000)
committerronag <ronag@362d55ac-95cf-4e76-9f9a-cbaa9c17b72d>
Thu, 27 Oct 2011 20:25:33 +0000 (20:25 +0000)
common/concurrency/governor.h
modules/ffmpeg/producer/audio/audio_decoder.cpp
modules/ffmpeg/producer/ffmpeg_producer.cpp
modules/ffmpeg/producer/frame_muxer.cpp
modules/ffmpeg/producer/video/video_decoder.cpp

index 10bb311a47e0243263d3b5c8c2b3dd13cc2aa002..89a15e3e6732e0e815e49ab20c4682dd77f2f1d9 100644 (file)
@@ -85,10 +85,14 @@ typedef std::vector<safe_ptr<int>> ticket_t;
 class governor : boost::noncopyable\r
 {\r
        tbb::atomic<int> count_;\r
+       tbb::atomic<int> is_running_;\r
        Concurrency::concurrent_queue<Concurrency::Context*> waiting_contexts_;\r
 \r
        void acquire_ticket()\r
        {\r
+               if(!is_running_)\r
+                       return;\r
+\r
                if(count_ < 1)\r
                        Concurrency::Context::Yield();\r
 \r
@@ -102,6 +106,9 @@ class governor : boost::noncopyable
 \r
        void release_ticket()\r
        {\r
+               if(!is_running_)\r
+                       return;\r
+\r
                if(++count_ <= 0)\r
                {\r
                        Concurrency:: Context* waiting = NULL;\r
@@ -115,6 +122,7 @@ public:
 \r
        governor(size_t capacity) \r
        {\r
+               is_running_ = true;\r
                count_ = capacity;\r
        }\r
        \r
@@ -133,8 +141,10 @@ public:
 \r
        void cancel()\r
        {\r
-               while(count_ < 0)\r
-                       release_ticket();\r
+               is_running_ = false;\r
+               Concurrency::Context* waiting = NULL;\r
+               while(waiting_contexts_.try_pop(waiting))\r
+                       waiting->Unblock();\r
        }\r
 };\r
 \r
index ec3bea9e8d34a3979d55bd7c189e4e91f2dec441..2fb83bce9a5f11185c80c9bdc94da09fd2dda005 100644 (file)
@@ -83,6 +83,7 @@ public:
 \r
        ~implementation()\r
        {\r
+               governor_.cancel();\r
                agent::wait(this);\r
        }\r
 \r
@@ -90,7 +91,6 @@ public:
        {\r
                try\r
                {\r
-                       win32_exception::install_handler();\r
                        while(true)\r
                        {               \r
                                auto ticket = governor_.acquire();\r
index d42a0cd93eb0813a91188b43c1317e9958dc60f0..b0da64e3b1fa409e0a39000a3448bfe87decf029 100644 (file)
@@ -46,8 +46,8 @@
 #include <boost/range/algorithm/find.hpp>\r
 \r
 #include <agents.h>\r
+#include <concrt.h>\r
 \r
-#include <iterator>\r
 #include <vector>\r
 #include <string>\r
 \r
@@ -62,7 +62,8 @@ struct ffmpeg_producer : public core::frame_producer
        const bool                                                                                                                              loop_;\r
        const size_t                                                                                                                    length_;\r
        \r
-       call<input::target_element_t>                                                                                   throw_away_;\r
+       call<input::target_element_t>                                                                                   throw_away_packets_;\r
+       call<frame_muxer2::target_element_t>                                                                    throw_away_frames_;\r
        unbounded_buffer<input::target_element_t>                                                               packets_;\r
        std::shared_ptr<unbounded_buffer<frame_muxer2::video_source_element_t>> video_;\r
        std::shared_ptr<unbounded_buffer<frame_muxer2::audio_source_element_t>> audio_;\r
@@ -83,7 +84,8 @@ public:
                , start_(start)\r
                , loop_(loop)\r
                , length_(length)\r
-               , throw_away_([](const input::target_element_t&){})\r
+               , throw_away_packets_([](const input::target_element_t&){})\r
+               , throw_away_frames_([](const frame_muxer2::target_element_t&){})\r
                , input_(packets_, graph_, filename_, loop, start, length)\r
                , last_frame_(core::basic_frame::empty())\r
        {               \r
@@ -121,7 +123,7 @@ public:
 \r
                CASPAR_VERIFY(video_decoder_ || audio_decoder_, ffmpeg_error());\r
                \r
-               packets_.link_target(&throw_away_);\r
+               packets_.link_target(&throw_away_packets_);\r
                muxer_.reset(new frame_muxer2(video_.get(), audio_.get(), frames_, video_decoder_ ? video_decoder_->fps() : frame_factory->get_video_format_desc().fps, frame_factory));\r
                                \r
                graph_->set_color("underflow", diagnostics::color(0.6f, 0.3f, 0.9f));   \r
@@ -134,7 +136,7 @@ public:
        ~ffmpeg_producer()\r
        {\r
                input_.stop();  \r
-               while(Concurrency::receive(frames_).first != core::basic_frame::eof()){}\r
+               frames_.link_target(&throw_away_frames_);\r
        }\r
                                                \r
        virtual safe_ptr<core::basic_frame> receive(int hints)\r
index 3b4c45043b47949437f4886fa1e8b4a5cbcdfd30..990689581f5cd7bddafbcd480af3b9cf180a5f5a 100644 (file)
@@ -80,6 +80,7 @@ struct frame_muxer2::implementation : public Concurrency::agent, boost::noncopya
 \r
        ~implementation()\r
        {\r
+               governor_.cancel();\r
                agent::wait(this);\r
        }\r
                                \r
@@ -151,7 +152,6 @@ struct frame_muxer2::implementation : public Concurrency::agent, boost::noncopya
        {\r
                try\r
                {\r
-                       win32_exception::install_handler();\r
                        while(display())\r
                        {       \r
                        }\r
index d0438e7e8f1c2da9519e7044a390e421e28c9887..de2334ed21e6d961b27596a9384ece264410f9bb 100644 (file)
@@ -87,6 +87,7 @@ public:
 \r
        ~implementation()\r
        {\r
+               governor_.cancel();\r
                agent::wait(this);\r
        }\r
 \r
@@ -94,7 +95,6 @@ public:
        {\r
                try\r
                {\r
-                       win32_exception::install_handler();\r
                        while(true)\r
                        {\r
                                auto ticket = governor_.acquire();\r