]> git.sesse.net Git - casparcg/commitdiff
Misc refactoring and fixes
authorHelge Norberg <helge.norberg@gmail.com>
Fri, 31 May 2013 18:28:55 +0000 (20:28 +0200)
committerHelge Norberg <helge.norberg@gmail.com>
Fri, 31 May 2013 18:28:55 +0000 (20:28 +0200)
13 files changed:
common/concurrency/executor.h
common/filesystem/polling_filesystem_monitor.cpp
common/filesystem/polling_filesystem_monitor.h
core/mixer/audio/audio_mixer.cpp
core/mixer/audio/audio_util.cpp
core/mixer/audio/audio_util.h
core/producer/frame/frame_factory.h
core/thumbnail_generator.cpp
modules/bluefish/consumer/bluefish_consumer.cpp
modules/decklink/consumer/decklink_consumer.cpp
modules/ffmpeg/consumer/ffmpeg_consumer.cpp
modules/ffmpeg/producer/ffmpeg_producer.cpp
shell/server.cpp

index 6deec6fcda3415451f1987fe6763ddded225efee..7cdc742d61c641fece644c8157a1a71d92f64666 100644 (file)
@@ -86,7 +86,6 @@ class executor : boost::noncopyable
        const std::string name_;
        boost::thread thread_;
        tbb::atomic<bool> is_running_;
-       tbb::atomic<bool> execute_rest_;
        
        typedef tbb::concurrent_bounded_queue<std::function<void()>> function_queue;
        function_queue execution_queue_[priority_count];
@@ -154,17 +153,9 @@ public:
                                
        void stop() // noexcept
        {
-               execute_rest_ = false;
                is_running_ = false;    
                execution_queue_[normal_priority].try_push([]{}); // Wake the execution thread.
        }
-                               
-       void stop_execute_rest() // noexcept
-       {
-               execute_rest_ = true;
-               is_running_ = false;
-               execution_queue_[normal_priority].try_push([]{}); // Wake the execution thread.
-       }
 
        void wait() // noexcept
        {
@@ -274,11 +265,8 @@ private:
                        }
                }
 
-               if (execute_rest_)
-               {
-                       execute_rest(high_priority);
-                       execute_rest(normal_priority);
-               }
+               execute_rest(high_priority);
+               execute_rest(normal_priority);
        }       
 };
 
index 84103718d7ce11943c63bd7aa4dbd64977c8ea5d..1037869d8d4b2a6200fd10463fa7e81eae08b945 100644 (file)
@@ -27,7 +27,7 @@
 #include <set>\r
 #include <iostream>\r
 \r
-#include <boost/thread.hpp>\r
+#include <boost/asio.hpp>\r
 #include <boost/foreach.hpp>\r
 #include <boost/range/adaptor/map.hpp>\r
 #include <boost/range/algorithm/copy.hpp>\r
@@ -53,13 +53,7 @@ public:
        {\r
                try\r
                {\r
-                       boost::this_thread::interruption_point();\r
                        handler_(event, file);\r
-                       boost::this_thread::interruption_point();\r
-               }\r
-               catch (const boost::thread_interrupted&)\r
-               {\r
-                       throw;\r
                }\r
                catch (...)\r
                {\r
@@ -210,7 +204,9 @@ private:
 class polling_filesystem_monitor : public filesystem_monitor\r
 {\r
        directory_monitor root_monitor_;\r
-       boost::thread scanning_thread_;\r
+       executor executor_;\r
+       boost::asio::io_service& scheduler_;\r
+       boost::asio::deadline_timer timer_;\r
        tbb::atomic<bool> running_;\r
        int scan_interval_millis_;\r
        boost::promise<void> initial_scan_completion_;\r
@@ -222,21 +218,35 @@ public:
                        filesystem_event events_of_interest_mask,\r
                        bool report_already_existing,\r
                        int scan_interval_millis,\r
+                       boost::asio::io_service& scheduler,\r
                        const filesystem_monitor_handler& handler,\r
                        const initial_files_handler& initial_files_handler)\r
-               : root_monitor_(report_already_existing, folder_to_watch, events_of_interest_mask, handler, initial_files_handler)\r
+               : root_monitor_(\r
+                               report_already_existing,\r
+                               folder_to_watch,\r
+                               events_of_interest_mask,\r
+                               handler,\r
+                               initial_files_handler)\r
+               , executor_(L"polling_filesystem_monitor")\r
+               , scheduler_(scheduler)\r
+               , timer_(scheduler)\r
                , scan_interval_millis_(scan_interval_millis)\r
        {\r
                running_ = true;\r
                reemmit_all_ = false;\r
-               scanning_thread_ = boost::thread([this] { scanner(); });\r
+               executor_.begin_invoke([this]\r
+               {\r
+                       scan();\r
+                       initial_scan_completion_.set_value();\r
+                       schedule_next();\r
+               });\r
        }\r
 \r
        virtual ~polling_filesystem_monitor()\r
        {\r
                running_ = false;\r
-               scanning_thread_.interrupt();\r
-               scanning_thread_.join();\r
+               boost::system::error_code e;\r
+               timer_.cancel(e);\r
        }\r
 \r
        virtual boost::unique_future<void> initial_files_processed()\r
@@ -254,25 +264,27 @@ public:
                to_reemmit_.push(file);\r
        }\r
 private:\r
-       void scanner()\r
+       void schedule_next()\r
        {\r
-               win32_exception::install_handler();\r
-               detail::SetThreadName(GetCurrentThreadId(), "polling_filesystem_monitor");\r
-\r
-               bool running = scan(false);\r
-               initial_scan_completion_.set_value();\r
+               if (!running_)\r
+                       return;\r
 \r
-               if (running)\r
-                       while (scan(true));\r
+               timer_.expires_from_now(\r
+                       boost::posix_time::milliseconds(scan_interval_millis_));\r
+               timer_.async_wait([this](const boost::system::error_code& e)\r
+               {\r
+                       scan();\r
+                       schedule_next();\r
+               });\r
        }\r
 \r
-       bool scan(bool sleep)\r
+       void scan()\r
        {\r
+               if (!running_)\r
+                       return;\r
+\r
                try\r
                {\r
-                       if (sleep)\r
-                               boost::this_thread::sleep(boost::posix_time::milliseconds(scan_interval_millis_));\r
-\r
                        if (reemmit_all_.fetch_and_store(false))\r
                                root_monitor_.reemmit_all();\r
                        else\r
@@ -285,30 +297,29 @@ private:
 \r
                        root_monitor_.scan([=] { return !running_; });\r
                }\r
-               catch (const boost::thread_interrupted&)\r
-               {\r
-               }\r
                catch (...)\r
                {\r
                        CASPAR_LOG_CURRENT_EXCEPTION();\r
                }\r
-\r
-               return running_;\r
        }\r
 };\r
 \r
 struct polling_filesystem_monitor_factory::implementation\r
 {\r
+       boost::asio::io_service& scheduler_;\r
        int scan_interval_millis;\r
 \r
-       implementation(int scan_interval_millis)\r
-               : scan_interval_millis(scan_interval_millis)\r
+       implementation(\r
+                       boost::asio::io_service& scheduler, int scan_interval_millis)\r
+               : scheduler_(scheduler), scan_interval_millis(scan_interval_millis)\r
        {\r
        }\r
 };\r
 \r
-polling_filesystem_monitor_factory::polling_filesystem_monitor_factory(int scan_interval_millis)\r
-       : impl_(new implementation(scan_interval_millis))\r
+polling_filesystem_monitor_factory::polling_filesystem_monitor_factory(\r
+               boost::asio::io_service& scheduler,\r
+               int scan_interval_millis)\r
+       : impl_(new implementation(scheduler, scan_interval_millis))\r
 {\r
 }\r
 \r
@@ -328,6 +339,7 @@ filesystem_monitor::ptr polling_filesystem_monitor_factory::create(
                        events_of_interest_mask,\r
                        report_already_existing,\r
                        impl_->scan_interval_millis,\r
+                       impl_->scheduler_,\r
                        handler,\r
                        initial_files_handler);\r
 }\r
index 09b872418013d14ca112c13fb71dd87d95d616e1..fd3298ef7eda584cb17a7467815cccea9c3c359e 100644 (file)
 \r
 #include "filesystem_monitor.h"\r
 \r
+namespace boost { namespace asio {\r
+       class io_service;\r
+}}\r
+\r
 namespace caspar {\r
 \r
 /**\r
@@ -38,11 +42,15 @@ public:
        /**\r
         * Constructor.\r
         *\r
+        * @param scheduler            The io_service that will be used for\r
+        *                             scheduling periodic scans.\r
         * @param scan_interval_millis The number of milliseconds between each\r
-        *                             scheduled scan. Lower values lowers the reaction\r
-        *                             time but causes more I/O.\r
+        *                             scheduled scan. Lower values lowers the\r
+        *                             reaction time but causes more I/O.\r
         */\r
-       polling_filesystem_monitor_factory(int scan_interval_millis = 5000);\r
+       polling_filesystem_monitor_factory(\r
+                       boost::asio::io_service& scheduler,\r
+                       int scan_interval_millis = 5000);\r
        virtual ~polling_filesystem_monitor_factory();\r
        virtual filesystem_monitor::ptr create(\r
                        const boost::filesystem::wpath& folder_to_watch,\r
index ab5d8830ae23500140be82ea8e29011a12282e6b..8959bf4f9d28833511d50b6fcced6c5ba8e7a58b 100644 (file)
@@ -81,7 +81,7 @@ public:
        implementation(const safe_ptr<diagnostics::graph>& graph)\r
                : graph_(graph)\r
                , format_desc_(video_format_desc::get(video_format::invalid))\r
-               , channel_layout_(default_channel_layout_repository().get_by_name(L"STEREO"))\r
+               , channel_layout_(channel_layout::stereo())\r
                , master_volume_(1.0f)\r
                , previous_master_volume_(master_volume_)\r
        {\r
index 36d9d46295b570dfb965118fbaf88f327447661a..2fd14fe3e353f828fb24ce023521915c826ffd2a 100644 (file)
@@ -65,6 +65,14 @@ bool channel_layout::no_channel_names() const
        return channel_names.empty();
 }
 
+const channel_layout& channel_layout::stereo()
+{
+       static channel_layout layout = create_layout_from_string(
+                       L"stereo", L"2.0", 2, L"L R");
+
+       return layout;
+}
+
 mix_config::mix_config()
        : strategy(add)
 {
@@ -158,8 +166,7 @@ void register_default_channel_layouts(channel_layout_repository& repository)
 {
        repository.register_layout(create_layout_from_string(
                        L"mono",         L"1.0",           1, L"C"));
-       repository.register_layout(create_layout_from_string(
-                       L"stereo",       L"2.0",           2, L"L R"));
+       repository.register_layout(channel_layout::stereo());
        repository.register_layout(create_layout_from_string(
                        L"dts",          L"5.1",           6, L"C L R Ls Rs LFE"));
        repository.register_layout(create_layout_from_string(
index b17f1f07d907102fffe6b746095a27df146c3530..c8dbe37b468dd55c6f3d399eb9dc239fe6a0c68b 100644 (file)
@@ -90,6 +90,8 @@ struct channel_layout
        int channel_index(const std::wstring& channel_name) const;\r
        bool has_channel(const std::wstring& channel_name) const;\r
        bool no_channel_names() const;\r
+\r
+       static const channel_layout& stereo();\r
 };\r
 \r
 /**\r
index 5e2d5eb2521fa796e5a405cef81d2982393539a1..36ed90c9f8f4a259ef2f097269984bcdadc92982 100644 (file)
@@ -40,7 +40,7 @@ struct frame_factory : boost::noncopyable
        virtual safe_ptr<write_frame> create_frame(\r
                        const void* video_stream_tag,\r
                        const pixel_format_desc& desc,\r
-                       const channel_layout& audio_channel_layout = default_channel_layout_repository().get_by_name(L"STEREO")) = 0;   \r
+                       const channel_layout& audio_channel_layout = channel_layout::stereo()) = 0;     \r
 \r
        virtual video_format_desc get_video_format_desc() const = 0; // nothrow\r
 };\r
index 9e8ce0edd2970da021c316e62307d55672cfa2b9..ba832de9758b28eaf90ed04d2ca0dca1a39cf583 100644 (file)
@@ -126,7 +126,7 @@ public:
                                output_,\r
                                format_desc_,\r
                                ogl,\r
-                               default_channel_layout_repository().get_by_name(L"STEREO")))\r
+                               channel_layout::stereo()))\r
                , thumbnail_creator_(thumbnail_creator)\r
                , monitor_(monitor_factory.create(\r
                                media_path,\r
index 6da748c8cb0aa9a8c40aca9c1d8f0d6b074a55ec..e3107e1a9c761bad208712a7e99608c65ed0d5c7 100644 (file)
@@ -25,7 +25,7 @@
 #include "../util/blue_velvet.h"\r
 #include "../util/memory.h"\r
 \r
-#include <core/parameters/parameters.h>
+#include <core/parameters/parameters.h>\r
 #include <core/video_format.h>\r
 #include <core/mixer/read_frame.h>\r
 \r
@@ -437,7 +437,7 @@ public:
        }\r
 };     \r
 \r
-safe_ptr<core::frame_consumer> create_consumer(const core::parameters& params)
+safe_ptr<core::frame_consumer> create_consumer(const core::parameters& params)\r
 {\r
        if(params.size() < 1 || params[0] != L"BLUEFISH")\r
                return core::frame_consumer::empty();\r
index cf42170c7bf87ee9ef425034cbd15d767ff91bad..55903c3704fbeb124ce4f0cb0bad2823c532be70 100644 (file)
@@ -37,7 +37,7 @@
 #include <common/memory/memclr.h>\r
 #include <common/memory/memshfl.h>\r
 \r
-#include <core/parameters/parameters.h>
+#include <core/parameters/parameters.h>\r
 #include <core/consumer/frame_consumer.h>\r
 #include <core/mixer/audio/audio_util.h>\r
 \r
@@ -660,7 +660,7 @@ public:
        }\r
 };     \r
 \r
-safe_ptr<core::frame_consumer> create_consumer(const core::parameters& params) 
+safe_ptr<core::frame_consumer> create_consumer(const core::parameters& params) \r
 {\r
        if(params.size() < 1 || params[0] != L"DECKLINK")\r
                return core::frame_consumer::empty();\r
index 746ce87d50b757a9193f6f7e48ccb18f0e75722b..75094136a73b9cbb5ddf0e216694aca153ae467d 100644 (file)
@@ -302,7 +302,7 @@ public:
 \r
        ~ffmpeg_consumer()\r
        {    \r
-               encode_executor_.stop_execute_rest();\r
+               encode_executor_.stop();\r
                encode_executor_.join();\r
 \r
                // Flush\r
index 7e4f702c8610da1e0603efba11d00fa8b503b847..57411482b5a69eabd0af45c6d2648b91974b6349 100644 (file)
@@ -534,7 +534,7 @@ safe_ptr<core::frame_producer> create_thumbnail_producer(
                \r
        ffmpeg_params vid_params;\r
 \r
-       return create_producer_destroy_proxy(make_safe<ffmpeg_producer>(frame_factory, filename, FFMPEG_FILE, filter_str, loop, start, length, true, L"", vid_params));\r
+       return make_safe<ffmpeg_producer>(frame_factory, filename, FFMPEG_FILE, filter_str, loop, start, length, true, L"", vid_params);\r
 }\r
 \r
 }}
\ No newline at end of file
index 87000acb8a6baa67f8f3ccdf4a2f458a72a29d6f..d03c39f77715996f2c7dd86eff24c21cbcee77b6 100644 (file)
@@ -128,6 +128,7 @@ struct server::implementation : boost::noncopyable
        {               \r
                ffmpeg::uninit();\r
 \r
+               thumbnail_generator_.reset();\r
                primary_amcp_server_.reset();\r
                async_servers_.clear();\r
                channels_.clear();\r
@@ -298,7 +299,9 @@ struct server::implementation : boost::noncopyable
 \r
                auto scan_interval_millis = pt.get(L"configuration.thumbnails.scan-interval-millis", 5000);\r
 \r
-               polling_filesystem_monitor_factory monitor_factory(scan_interval_millis);\r
+               polling_filesystem_monitor_factory monitor_factory(\r
+                               io_service_manager_.service(),\r
+                               scan_interval_millis);\r
                thumbnail_generator_.reset(new thumbnail_generator(\r
                                monitor_factory, \r
                                env::media_folder(),\r