]> git.sesse.net Git - casparcg/commitdiff
2.0.0.2: executor: Lazy autostart. "start" method deprecated.
authorronag <ronag@362d55ac-95cf-4e76-9f9a-cbaa9c17b72d>
Fri, 29 Apr 2011 06:53:57 +0000 (06:53 +0000)
committerronag <ronag@362d55ac-95cf-4e76-9f9a-cbaa9c17b72d>
Fri, 29 Apr 2011 06:53:57 +0000 (06:53 +0000)
git-svn-id: https://casparcg.svn.sourceforge.net/svnroot/casparcg/server/branches/2.0.0.2@668 362d55ac-95cf-4e76-9f9a-cbaa9c17b72d

16 files changed:
common/concurrency/executor.h
common/diagnostics/graph.cpp
core/consumer/frame_consumer_device.cpp
core/mixer/frame_mixer_device.cpp
core/mixer/gpu/ogl_device.cpp
core/producer/frame_producer_device.cpp
modules/bluefish/consumer/bluefish_consumer.cpp
modules/decklink/consumer/decklink_consumer.cpp
modules/decklink/producer/decklink_producer.cpp
modules/ffmpeg/consumer/ffmpeg_consumer.cpp
modules/ffmpeg/producer/ffmpeg_producer.cpp
modules/ffmpeg/producer/input.cpp
modules/flash/producer/flash_producer.cpp
modules/ogl/consumer/ogl_consumer.cpp
modules/silverlight/producer/silverlight_producer.cpp
protocol/cii/CIIProtocolStrategy.cpp

index 8b3d087a74dfa21042925f2679122daf0edc9b37..45e4b1b9325f8cd35c677b0578b0e98ef1cee4a1 100644 (file)
@@ -69,11 +69,9 @@ class executor : boost::noncopyable
        tbb::concurrent_bounded_queue<std::function<void()>> execution_queue_;\r
 public:\r
                \r
-       explicit executor(const std::wstring& name, bool auto_start = false) : name_(narrow(name)) // noexcept\r
+       explicit executor(const std::wstring& name) : name_(narrow(name)) // noexcept\r
        {\r
                is_running_ = false;\r
-               if(auto_start)\r
-                       start();\r
        }\r
        \r
        virtual ~executor() // noexcept\r
@@ -88,14 +86,6 @@ public:
        {\r
                execution_queue_.set_capacity(capacity);\r
        }\r
-\r
-       void start() // noexcept\r
-       {\r
-               if(is_running_.fetch_and_store(true))\r
-                       return;\r
-               clear();\r
-               thread_ = boost::thread([this]{run();});\r
-       }\r
                        \r
        void stop() // noexcept\r
        {\r
@@ -121,6 +111,9 @@ public:
        template<typename Func>\r
        auto begin_invoke(Func&& func) -> boost::unique_future<decltype(func())> // noexcept\r
        {       \r
+               if(!is_running_)\r
+                       start();\r
+\r
                typedef boost::packaged_task<decltype(func())> task_type;\r
                                \r
                auto task = task_type(std::forward<Func>(func));\r
@@ -158,9 +151,6 @@ public:
        template<typename Func>\r
        auto invoke(Func&& func) -> decltype(func())\r
        {\r
-               if(!is_running_)\r
-                       start();\r
-\r
                if(boost::this_thread::get_id() == thread_.get_id())  // Avoids potential deadlock.\r
                        return func();\r
                \r
@@ -173,6 +163,14 @@ public:
        bool is_running() const { return is_running_;                           }       \r
                \r
 private:\r
+\r
+       void start() // noexcept\r
+       {\r
+               if(is_running_.fetch_and_store(true))\r
+                       return;\r
+               clear();\r
+               thread_ = boost::thread([this]{run();});\r
+       }\r
        \r
        void execute() // noexcept\r
        {\r
index 18fc10a13b0c0f177b95e38258288213db60eed9..0cd1941f65988680346d0ca1cf0febe2f1f96ab8 100644 (file)
@@ -75,7 +75,6 @@ public:
 private:\r
        context() : executor_(L"diagnostics")\r
        {\r
-               executor_.start();\r
                executor_.begin_invoke([this]\r
                {\r
                        window_.Create(sf::VideoMode(600, 1000), "CasparCG Diagnostics");\r
index c69ba3fa4b3e11bda1b6e4ad1830cacb272a9e5e..dd2b99587f1fa2160afa8f50c1af3503f4b4d28e 100644 (file)
@@ -52,7 +52,6 @@ public:
                , executor_(L"frame_consumer_device")\r
        {               \r
                executor_.set_capacity(2);\r
-               executor_.start();\r
        }\r
 \r
        void add(int index, safe_ptr<frame_consumer>&& consumer)\r
index af789e3d616af0d9616b5c7725723c48e74df0f5..2b254637364c637348b095e3e7be3bd0c97e672a 100644 (file)
@@ -114,7 +114,6 @@ public:
                diag_->set_color("tick-time", diagnostics::color(0.1f, 0.7f, 0.8f));\r
                diag_->set_color("input-buffer", diagnostics::color(1.0f, 1.0f, 0.0f)); \r
                executor_.set_capacity(2);      \r
-               executor_.start();\r
                CASPAR_LOG(info) << print() << L" Successfully initialized.";   \r
        }\r
 \r
index 692bb3a53424c64c90050b57a7bbf8f6414cfeec..fcf8f14828dc50b72dfeed3df081cbba4b3ca798 100644 (file)
@@ -32,7 +32,6 @@ namespace caspar { namespace mixer {
 \r
 ogl_device::ogl_device() : executor_(L"ogl_device")\r
 {\r
-       executor_.start();\r
        invoke([=]\r
        {\r
                context_.reset(new sf::Context());\r
index 23db41cd9a97ca080432943104ada0ec27e6ee4f..9372c40e64335dac9d4e15d80a8e5fa15df87d8f 100644 (file)
@@ -54,10 +54,7 @@ struct frame_producer_device::implementation : boost::noncopyable
 public:\r
        implementation(const video_format_desc& format_desc)  \r
                : format_desc_(format_desc)\r
-               , executor_(L"frame_producer_device")\r
-       {\r
-               executor_.start();\r
-       }\r
+               , executor_(L"frame_producer_device"){}\r
 \r
        boost::signals2::connection connect(const output_t::slot_type& subscriber)\r
        {\r
index 1b4a874bcbeb9646b4bed13b7993a3fa502c03aa..3fd1318d52cd05fb4e296e4caf78129c53e170c2 100644 (file)
@@ -241,7 +241,6 @@ public:
                for(size_t n = 0; n < reserved_frames_.size(); ++n)\r
                        reserved_frames_[n] = std::make_shared<blue_dma_buffer>(format_desc_.size, n);          \r
                                \r
-               executor_.start();\r
                active_ = executor_.begin_invoke([]{});\r
 \r
                CASPAR_LOG(info) << print() << TEXT(" Successfully initialized for ") << format_desc_ << TEXT(".");\r
index 5a56633736832e2834bd69ca58b2948dc9522e25..13be196ac2a277f1a8a19a0fd7188612f9f9f2f6 100644 (file)
@@ -288,7 +288,7 @@ public:
 \r
 struct decklink_consumer::implementation\r
 {\r
-       std::unique_ptr<decklink_output> input_;\r
+       std::unique_ptr<decklink_output> output_;\r
        size_t device_index_;\r
        bool embed_audio_;\r
        bool internal_key_;\r
@@ -300,16 +300,13 @@ public:
                : device_index_(device_index)\r
                , embed_audio_(embed_audio)\r
                , internal_key_(internal_key)\r
-               , executor_(L"DECKLINK[" + boost::lexical_cast<std::wstring>(device_index) + L"]")\r
-       {\r
-               executor_.start();\r
-       }\r
+               , executor_(L"DECKLINK[" + boost::lexical_cast<std::wstring>(device_index) + L"]"){}\r
 \r
        ~implementation()\r
        {\r
                executor_.invoke([&]\r
                {\r
-                       input_ = nullptr;\r
+                       output_ = nullptr;\r
                });\r
        }\r
 \r
@@ -317,13 +314,13 @@ public:
        {\r
                executor_.invoke([&]\r
                {\r
-                       input_.reset(new decklink_output(format_desc, device_index_, embed_audio_, internal_key_));\r
+                       output_.reset(new decklink_output(format_desc, device_index_, embed_audio_, internal_key_));\r
                });\r
        }\r
        \r
        void send(const safe_ptr<const core::read_frame>& frame)\r
        {\r
-               input_->send(frame);\r
+               output_->send(frame);\r
        }\r
 \r
        size_t buffer_depth() const\r
@@ -333,7 +330,7 @@ public:
 \r
        std::wstring print() const\r
        {\r
-               return input_->print();\r
+               return output_->print();\r
        }\r
 };\r
 \r
index dee5881da0a1a2d4962be7f29cf08881a6257bde..fcc0f5680ef61340b286482141cfc0bdc7f6d1eb 100644 (file)
@@ -37,6 +37,7 @@
 #include <tbb/atomic.h>\r
 \r
 #include <boost/algorithm/string.hpp>\r
+#include <boost/timer.hpp>\r
 \r
 #pragma warning(push)\r
 #pragma warning(disable : 4996)\r
@@ -65,7 +66,7 @@ class decklink_input : public IDeckLinkInputCallback
        const size_t device_index_;\r
 \r
        std::shared_ptr<diagnostics::graph> graph_;\r
-       timer perf_timer_;\r
+       boost::timer perf_timer_;\r
 \r
        CComPtr<IDeckLink>                      decklink_;\r
        CComQIPtr<IDeckLinkInput>       input_;\r
@@ -159,7 +160,7 @@ public:
        virtual HRESULT STDMETHODCALLTYPE VideoInputFrameArrived(IDeckLinkVideoInputFrame* video, IDeckLinkAudioInputPacket* audio)\r
        {       \r
                graph_->update_value("tick-time", static_cast<float>(perf_timer_.elapsed()/format_desc_.interval*0.5));\r
-               perf_timer_.reset();\r
+               perf_timer_.restart();\r
 \r
                if(!video)\r
                        return S_OK;            \r
@@ -255,7 +256,7 @@ public:
        explicit decklink_producer(const safe_ptr<core::frame_factory>& frame_factory, const core::video_format_desc& format_desc, size_t device_index)\r
                : format_desc_(format_desc) \r
                , device_index_(device_index)\r
-               , executor_(L"decklink_producer", true)\r
+               , executor_(L"decklink_producer")\r
        {\r
                executor_.invoke([=]\r
                {\r
index bdbda90edce275e113cb7af8750cc03af8b1b97f..bc5f7632773426da7c654ee944b42b95b0d616f1 100644 (file)
@@ -116,7 +116,6 @@ public:
        void initialize(const core::video_format_desc& format_desc)\r
        {\r
                format_desc_ = format_desc;\r
-               executor_.start();\r
                active_ = executor_.begin_invoke([]{});\r
 \r
                fmt_ = av_guess_format(nullptr, filename_.c_str(), nullptr);\r
index 11254790dde34cc980b922e626443576811be5dc..3e61711228706364cbf99c49997daab912d2133e 100644 (file)
@@ -37,6 +37,8 @@
 #include <common/utility/timer.h>\r
 #include <common/utility/assert.h>\r
 \r
+#include <boost/timer.hpp>\r
+\r
 #include <tbb/parallel_invoke.h>\r
 \r
 #include <deque>\r
@@ -50,7 +52,7 @@ struct ffmpeg_producer : public core::frame_producer
        const bool                                                      loop_;\r
        \r
        std::shared_ptr<diagnostics::graph>     graph_;\r
-       timer                                                           perf_timer_;\r
+       boost::timer                                                            perf_timer_;\r
                \r
        std::unique_ptr<audio_decoder>          audio_decoder_;\r
        std::unique_ptr<video_decoder>          video_decoder_;\r
@@ -88,7 +90,7 @@ public:
                        \r
        virtual safe_ptr<core::basic_frame> receive()\r
        {\r
-               perf_timer_.reset();\r
+               perf_timer_.restart();\r
 \r
                while(ouput_channel_.size() < 2 && !input_->is_eof())\r
                {       \r
index 08283991b5f9ea03de4e000cb8bdfae4f8452b40..07c46a02ed1486c39a39d3a0a0b51559d7cf5088 100644 (file)
@@ -124,7 +124,6 @@ public:
                                source_info(narrow(print())) << \r
                                msg_info("No video or audio codec context found."));            \r
                        \r
-               executor_.start();\r
                executor_.begin_invoke([this]{read_file();});\r
                CASPAR_LOG(info) << print() << " Started.";\r
        }\r
index 9decd746c9e1754a2bfa4691e136cee2a8821122..e890088e2091ada0bdc16ca66b4f80af2e8bddc1 100644 (file)
@@ -223,7 +223,7 @@ public:
                , tail_(core::basic_frame::empty())             \r
                , frame_factory_(frame_factory)\r
                , format_desc_(frame_factory->get_video_format_desc())\r
-               , executor_(L"flash_producer", true)\r
+               , executor_(L"flash_producer")\r
        {       \r
                if(!boost::filesystem::exists(filename))\r
                        BOOST_THROW_EXCEPTION(file_not_found() << boost::errinfo_file_name(narrow(filename)));  \r
index e52674152f47c5777791a11cf788a67b474e3256..edc8297de5fd4224a9868fa969aa2c308ae44970 100644 (file)
@@ -144,7 +144,6 @@ public:
                if(screen_index != 0)\r
                        CASPAR_LOG(warning) << print() << " only supports screen_index=0 for non-Win32";\r
 #endif         \r
-               executor_.start();\r
                executor_.invoke([=]\r
                {\r
                        window_.Create(sf::VideoMode(screen_width_, screen_height_, 32), narrow(print()), windowed_ ? sf::Style::Resize : sf::Style::Fullscreen);\r
index cef09fd3fb9d498e03a73d680d5f8057a7c32553..663167e55dc0bd2ce86e3fc8bb042e538a29b10f 100644 (file)
@@ -142,7 +142,6 @@ public:
 \r
        silverlight_producer(const safe_ptr<core::frame_factory>& frame_factory) : executor_(L"silverlight")\r
        {\r
-               executor_.start();\r
                executor_.invoke([=]\r
                {\r
                        renderer_.reset(new silverlight_renderer(frame_factory));\r
index d37a457f1ce83abc0fbe707e40e4000a8a5a90e4..80363827abb86c719406d6b1733dca9270f0e45c 100644 (file)
@@ -42,9 +42,7 @@ const std::wstring CIIProtocolStrategy::MessageDelimiter = TEXT("\r\n");
 const TCHAR CIIProtocolStrategy::TokenDelimiter = TEXT('\\');\r
 \r
 CIIProtocolStrategy::CIIProtocolStrategy(const std::vector<safe_ptr<core::channel>>& channels) : pChannel_(channels.at(0)), executor_(L"CIIProtocolStrategy")\r
-{\r
-       executor_.start();\r
-}\r
+{}\r
 \r
 void CIIProtocolStrategy::Parse(const TCHAR* pData, int charCount, IO::ClientInfoPtr pClientInfo) \r
 {\r